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_params
.bcast_sta_id
;
403 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.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_params
.bcast_sta_id
;
445 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.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_params
.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 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(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 ret
= 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
;
600 * iwl4965_rxon_add_station - add station into station table.
602 * there is only one AP station with id= IWL_AP_ID
603 * NOTE: mutex must be held before calling this fnction
605 static int iwl4965_rxon_add_station(struct iwl_priv
*priv
,
606 const u8
*addr
, int is_ap
)
610 /* Add station to device's station table */
611 #ifdef CONFIG_IWL4965_HT
612 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
613 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
616 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
617 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
618 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
621 #endif /* CONFIG_IWL4965_HT */
622 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
625 /* Set up default rate scaling table in device's station table */
626 iwl4965_add_station(priv
, addr
, is_ap
);
632 * iwl4965_check_rxon_cmd - validate RXON structure is valid
634 * NOTE: This is really only useful during development and can eventually
635 * be #ifdef'd out once the driver is stable and folks aren't actively
638 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
643 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
644 error
|= le32_to_cpu(rxon
->flags
&
645 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
646 RXON_FLG_RADAR_DETECT_MSK
));
648 IWL_WARNING("check 24G fields %d | %d\n",
651 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
652 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
654 IWL_WARNING("check 52 fields %d | %d\n",
656 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
658 IWL_WARNING("check 52 CCK %d | %d\n",
661 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
663 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
665 /* make sure basic rates 6Mbps and 1Mbps are supported */
666 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
667 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
669 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
671 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
673 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
675 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
676 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
678 IWL_WARNING("check CCK and short slot %d | %d\n",
681 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
682 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
684 IWL_WARNING("check CCK & auto detect %d | %d\n",
687 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
688 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
690 IWL_WARNING("check TGG and auto detect %d | %d\n",
694 IWL_WARNING("Tuning to channel %d\n",
695 le16_to_cpu(rxon
->channel
));
698 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
705 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
706 * @priv: staging_rxon is compared to active_rxon
708 * If the RXON structure is changing enough to require a new tune,
709 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
710 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
712 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
715 /* These items are only settable from the full RXON command */
716 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
717 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
718 priv
->active_rxon
.bssid_addr
) ||
719 compare_ether_addr(priv
->staging_rxon
.node_addr
,
720 priv
->active_rxon
.node_addr
) ||
721 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
722 priv
->active_rxon
.wlap_bssid_addr
) ||
723 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
724 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
725 (priv
->staging_rxon
.air_propagation
!=
726 priv
->active_rxon
.air_propagation
) ||
727 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
728 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
729 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
730 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
731 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
732 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
735 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
736 * be updated with the RXON_ASSOC command -- however only some
737 * flag transitions are allowed using RXON_ASSOC */
739 /* Check if we are not switching bands */
740 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
741 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
744 /* Check if we are switching association toggle */
745 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
746 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
753 * iwl4965_commit_rxon - commit staging_rxon to hardware
755 * The RXON command in staging_rxon is committed to the hardware and
756 * the active_rxon structure is updated with the new data. This
757 * function correctly transitions out of the RXON_ASSOC_MSK state if
758 * a HW tune is required based on the RXON structure changes.
760 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
762 /* cast away the const for active_rxon in this function */
763 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
764 DECLARE_MAC_BUF(mac
);
767 if (!iwl_is_alive(priv
))
770 /* always get timestamp with Rx frame */
771 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
773 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
775 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
779 /* If we don't need to send a full RXON, we can use
780 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
781 * and other flags for the current radio configuration. */
782 if (!iwl4965_full_rxon_required(priv
)) {
783 rc
= iwl_send_rxon_assoc(priv
);
785 IWL_ERROR("Error setting RXON_ASSOC "
786 "configuration (%d).\n", rc
);
790 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
795 /* station table will be cleared */
796 priv
->assoc_station_added
= 0;
798 #ifdef CONFIG_IWL4965_SENSITIVITY
799 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
800 if (!priv
->error_recovering
)
801 priv
->start_calib
= 0;
803 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
804 #endif /* CONFIG_IWL4965_SENSITIVITY */
806 /* If we are currently associated and the new config requires
807 * an RXON_ASSOC and the new config wants the associated mask enabled,
808 * we must clear the associated from the active configuration
809 * before we apply the new config */
810 if (iwl_is_associated(priv
) &&
811 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
812 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
813 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
815 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
816 sizeof(struct iwl4965_rxon_cmd
),
819 /* If the mask clearing failed then we set
820 * active_rxon back to what it was previously */
822 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
823 IWL_ERROR("Error clearing ASSOC_MSK on current "
824 "configuration (%d).\n", rc
);
829 IWL_DEBUG_INFO("Sending RXON\n"
830 "* with%s RXON_FILTER_ASSOC_MSK\n"
833 ((priv
->staging_rxon
.filter_flags
&
834 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
835 le16_to_cpu(priv
->staging_rxon
.channel
),
836 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
838 iwl4965_set_rxon_hwcrypto(priv
, !priv
->cfg
->mod_params
->sw_crypto
);
839 /* Apply the new configuration */
840 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
841 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
843 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
847 iwlcore_clear_stations_table(priv
);
849 #ifdef CONFIG_IWL4965_SENSITIVITY
850 if (!priv
->error_recovering
)
851 priv
->start_calib
= 0;
853 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
854 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
855 #endif /* CONFIG_IWL4965_SENSITIVITY */
857 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
859 /* If we issue a new RXON command which required a tune then we must
860 * send a new TXPOWER command or we won't be able to Tx any frames */
861 rc
= iwl4965_hw_reg_send_txpower(priv
);
863 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
867 /* Add the broadcast address so we can send broadcast frames */
868 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
869 IWL_INVALID_STATION
) {
870 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
874 /* If we have set the ASSOC_MSK and we are in BSS mode then
875 * add the IWL_AP_ID to the station rate table */
876 if (iwl_is_associated(priv
) &&
877 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
878 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
879 == IWL_INVALID_STATION
) {
880 IWL_ERROR("Error adding AP address for transmit.\n");
883 priv
->assoc_station_added
= 1;
884 if (priv
->default_wep_key
&&
885 iwl_send_static_wepkey_cmd(priv
, 0))
886 IWL_ERROR("Could not send WEP static key.\n");
892 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
894 struct iwl4965_bt_cmd bt_cmd
= {
902 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
903 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
906 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
909 struct iwl4965_rx_packet
*res
;
910 struct iwl_host_cmd cmd
= {
911 .id
= REPLY_SCAN_ABORT_CMD
,
912 .meta
.flags
= CMD_WANT_SKB
,
915 /* If there isn't a scan actively going on in the hardware
916 * then we are in between scan bands and not actually
917 * actively scanning, so don't send the abort command */
918 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
919 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
923 rc
= iwl_send_cmd_sync(priv
, &cmd
);
925 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
929 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
930 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
931 /* The scan abort will return 1 for success or
932 * 2 for "failure". A failure condition can be
933 * due to simply not being in an active scan which
934 * can occur if we send the scan abort before we
935 * the microcode has notified us that a scan is
937 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
938 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
939 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
942 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
947 static int iwl4965_card_state_sync_callback(struct iwl_priv
*priv
,
957 * Use: Sets the device's internal card state to enable, disable, or halt
959 * When in the 'enable' state the card operates as normal.
960 * When in the 'disable' state, the card enters into a low power mode.
961 * When in the 'halt' state, the card is shut down and must be fully
962 * restarted to come back on.
964 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
966 struct iwl_host_cmd cmd
= {
967 .id
= REPLY_CARD_STATE_CMD
,
970 .meta
.flags
= meta_flag
,
973 if (meta_flag
& CMD_ASYNC
)
974 cmd
.meta
.u
.callback
= iwl4965_card_state_sync_callback
;
976 return iwl_send_cmd(priv
, &cmd
);
979 static int iwl4965_add_sta_sync_callback(struct iwl_priv
*priv
,
980 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
982 struct iwl4965_rx_packet
*res
= NULL
;
985 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
989 res
= (struct iwl4965_rx_packet
*)skb
->data
;
990 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
991 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
996 switch (res
->u
.add_sta
.status
) {
997 case ADD_STA_SUCCESS_MSK
:
1003 /* We didn't cache the SKB; let the caller free it */
1007 int iwl4965_send_add_station(struct iwl_priv
*priv
,
1008 struct iwl4965_addsta_cmd
*sta
, u8 flags
)
1010 struct iwl4965_rx_packet
*res
= NULL
;
1012 struct iwl_host_cmd cmd
= {
1013 .id
= REPLY_ADD_STA
,
1014 .len
= sizeof(struct iwl4965_addsta_cmd
),
1015 .meta
.flags
= flags
,
1019 if (flags
& CMD_ASYNC
)
1020 cmd
.meta
.u
.callback
= iwl4965_add_sta_sync_callback
;
1022 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1024 rc
= iwl_send_cmd(priv
, &cmd
);
1026 if (rc
|| (flags
& CMD_ASYNC
))
1029 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1030 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1031 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1037 switch (res
->u
.add_sta
.status
) {
1038 case ADD_STA_SUCCESS_MSK
:
1039 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1043 IWL_WARNING("REPLY_ADD_STA failed\n");
1048 priv
->alloc_rxb_skb
--;
1049 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1054 static void iwl4965_clear_free_frames(struct iwl_priv
*priv
)
1056 struct list_head
*element
;
1058 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1059 priv
->frames_count
);
1061 while (!list_empty(&priv
->free_frames
)) {
1062 element
= priv
->free_frames
.next
;
1064 kfree(list_entry(element
, struct iwl4965_frame
, list
));
1065 priv
->frames_count
--;
1068 if (priv
->frames_count
) {
1069 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1070 priv
->frames_count
);
1071 priv
->frames_count
= 0;
1075 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl_priv
*priv
)
1077 struct iwl4965_frame
*frame
;
1078 struct list_head
*element
;
1079 if (list_empty(&priv
->free_frames
)) {
1080 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1082 IWL_ERROR("Could not allocate frame!\n");
1086 priv
->frames_count
++;
1090 element
= priv
->free_frames
.next
;
1092 return list_entry(element
, struct iwl4965_frame
, list
);
1095 static void iwl4965_free_frame(struct iwl_priv
*priv
, struct iwl4965_frame
*frame
)
1097 memset(frame
, 0, sizeof(*frame
));
1098 list_add(&frame
->list
, &priv
->free_frames
);
1101 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
1102 struct ieee80211_hdr
*hdr
,
1103 const u8
*dest
, int left
)
1106 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
1107 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1108 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1111 if (priv
->ibss_beacon
->len
> left
)
1114 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1116 return priv
->ibss_beacon
->len
;
1119 static u8
iwl4965_rate_get_lowest_plcp(int rate_mask
)
1123 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1124 i
= iwl4965_rates
[i
].next_ieee
) {
1125 if (rate_mask
& (1 << i
))
1126 return iwl4965_rates
[i
].plcp
;
1129 return IWL_RATE_INVALID
;
1132 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
1134 struct iwl4965_frame
*frame
;
1135 unsigned int frame_size
;
1139 frame
= iwl4965_get_free_frame(priv
);
1142 IWL_ERROR("Could not obtain free frame buffer for beacon "
1147 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1148 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
&
1150 if (rate
== IWL_INVALID_RATE
)
1151 rate
= IWL_RATE_6M_PLCP
;
1153 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1154 if (rate
== IWL_INVALID_RATE
)
1155 rate
= IWL_RATE_1M_PLCP
;
1158 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
1160 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1163 iwl4965_free_frame(priv
, frame
);
1168 /******************************************************************************
1170 * Misc. internal state and helper functions
1172 ******************************************************************************/
1174 static void iwl4965_unset_hw_params(struct iwl_priv
*priv
)
1176 if (priv
->shared_virt
)
1177 pci_free_consistent(priv
->pci_dev
,
1178 sizeof(struct iwl4965_shared
),
1184 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1186 * return : set the bit for each supported rate insert in ie
1188 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1189 u16 basic_rate
, int *left
)
1191 u16 ret_rates
= 0, bit
;
1196 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1197 if (bit
& supported_rate
) {
1199 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
1200 ((bit
& basic_rate
) ? 0x80 : 0x00);
1204 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1213 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1215 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
1216 enum ieee80211_band band
,
1217 struct ieee80211_mgmt
*frame
,
1218 int left
, int is_direct
)
1222 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1223 #ifdef CONFIG_IWL4965_HT
1224 const struct ieee80211_supported_band
*sband
=
1225 iwl4965_get_hw_mode(priv
, band
);
1226 #endif /* CONFIG_IWL4965_HT */
1228 /* Make sure there is enough space for the probe request,
1229 * two mandatory IEs and the data */
1235 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1236 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1237 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1238 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1239 frame
->seq_ctrl
= 0;
1241 /* fill in our indirect SSID IE */
1248 pos
= &(frame
->u
.probe_req
.variable
[0]);
1249 *pos
++ = WLAN_EID_SSID
;
1252 /* fill in our direct SSID IE... */
1255 left
-= 2 + priv
->essid_len
;
1258 /* ... fill it in... */
1259 *pos
++ = WLAN_EID_SSID
;
1260 *pos
++ = priv
->essid_len
;
1261 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1262 pos
+= priv
->essid_len
;
1263 len
+= 2 + priv
->essid_len
;
1266 /* fill in supported rate */
1272 /* ... fill it in... */
1273 *pos
++ = WLAN_EID_SUPP_RATES
;
1276 /* exclude 60M rate */
1277 active_rates
= priv
->rates_mask
;
1278 active_rates
&= ~IWL_RATE_60M_MASK
;
1280 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1282 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1283 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1284 active_rate_basic
, &left
);
1285 active_rates
&= ~ret_rates
;
1287 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1288 active_rate_basic
, &left
);
1289 active_rates
&= ~ret_rates
;
1293 if (active_rates
== 0)
1296 /* fill in supported extended rate */
1301 /* ... fill it in... */
1302 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1304 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1305 active_rate_basic
, &left
);
1309 #ifdef CONFIG_IWL4965_HT
1310 if (sband
&& sband
->ht_info
.ht_supported
) {
1311 struct ieee80211_ht_cap
*ht_cap
;
1313 *pos
++ = WLAN_EID_HT_CAPABILITY
;
1314 *pos
++ = sizeof(struct ieee80211_ht_cap
);
1315 ht_cap
= (struct ieee80211_ht_cap
*)pos
;
1316 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
1317 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
1318 ht_cap
->ampdu_params_info
=(sband
->ht_info
.ampdu_factor
&
1319 IEEE80211_HT_CAP_AMPDU_FACTOR
) |
1320 ((sband
->ht_info
.ampdu_density
<< 2) &
1321 IEEE80211_HT_CAP_AMPDU_DENSITY
);
1322 len
+= 2 + sizeof(struct ieee80211_ht_cap
);
1324 #endif /*CONFIG_IWL4965_HT */
1333 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
1334 struct iwl4965_qosparam_cmd
*qos
)
1337 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1338 sizeof(struct iwl4965_qosparam_cmd
), qos
);
1341 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
1343 unsigned long flags
;
1345 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1348 if (!priv
->qos_data
.qos_enable
)
1351 spin_lock_irqsave(&priv
->lock
, flags
);
1352 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1354 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1355 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1356 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1357 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1358 if (priv
->qos_data
.qos_active
)
1359 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1360 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1362 #ifdef CONFIG_IWL4965_HT
1363 if (priv
->current_ht_config
.is_ht
)
1364 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
1365 #endif /* CONFIG_IWL4965_HT */
1367 spin_unlock_irqrestore(&priv
->lock
, flags
);
1369 if (force
|| iwl_is_associated(priv
)) {
1370 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1371 priv
->qos_data
.qos_active
,
1372 priv
->qos_data
.def_qos_parm
.qos_flags
);
1374 iwl4965_send_qos_params_command(priv
,
1375 &(priv
->qos_data
.def_qos_parm
));
1380 * Power management (not Tx power!) functions
1382 #define MSEC_TO_USEC 1024
1384 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1385 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1386 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1387 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1388 __constant_cpu_to_le32(X1), \
1389 __constant_cpu_to_le32(X2), \
1390 __constant_cpu_to_le32(X3), \
1391 __constant_cpu_to_le32(X4)}
1394 /* default power management (not Tx power) table values */
1396 static struct iwl4965_power_vec_entry range_0
[IWL_POWER_AC
] = {
1397 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1398 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1399 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1400 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1401 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1402 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1406 static struct iwl4965_power_vec_entry range_1
[IWL_POWER_AC
] = {
1407 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1408 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1409 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1410 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1411 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1412 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1413 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1414 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1415 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1416 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1419 int iwl4965_power_init_handle(struct iwl_priv
*priv
)
1422 struct iwl4965_power_mgr
*pow_data
;
1423 int size
= sizeof(struct iwl4965_power_vec_entry
) * IWL_POWER_AC
;
1426 IWL_DEBUG_POWER("Initialize power \n");
1428 pow_data
= &(priv
->power_data
);
1430 memset(pow_data
, 0, sizeof(*pow_data
));
1432 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1433 pow_data
->dtim_val
= 0xffff;
1435 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1436 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1438 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1442 struct iwl4965_powertable_cmd
*cmd
;
1444 IWL_DEBUG_POWER("adjust power command flags\n");
1446 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
1447 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1450 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1452 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1458 static int iwl4965_update_power_cmd(struct iwl_priv
*priv
,
1459 struct iwl4965_powertable_cmd
*cmd
, u32 mode
)
1464 struct iwl4965_power_vec_entry
*range
;
1466 struct iwl4965_power_mgr
*pow_data
;
1468 if (mode
> IWL_POWER_INDEX_5
) {
1469 IWL_DEBUG_POWER("Error invalid power mode \n");
1472 pow_data
= &(priv
->power_data
);
1474 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1475 range
= &pow_data
->pwr_range_0
[0];
1477 range
= &pow_data
->pwr_range_1
[1];
1479 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl4965_powertable_cmd
));
1481 #ifdef IWL_MAC80211_DISABLE
1482 if (priv
->assoc_network
!= NULL
) {
1483 unsigned long flags
;
1485 period
= priv
->assoc_network
->tim
.tim_period
;
1487 #endif /*IWL_MAC80211_DISABLE */
1488 skip
= range
[mode
].no_dtim
;
1497 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1499 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1500 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1501 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1504 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
1505 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1506 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1509 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1510 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1511 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1512 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1513 le32_to_cpu(cmd
->sleep_interval
[0]),
1514 le32_to_cpu(cmd
->sleep_interval
[1]),
1515 le32_to_cpu(cmd
->sleep_interval
[2]),
1516 le32_to_cpu(cmd
->sleep_interval
[3]),
1517 le32_to_cpu(cmd
->sleep_interval
[4]));
1522 static int iwl4965_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
1524 u32
uninitialized_var(final_mode
);
1526 struct iwl4965_powertable_cmd cmd
;
1528 /* If on battery, set to 3,
1529 * if plugged into AC power, set to CAM ("continuously aware mode"),
1530 * else user level */
1532 case IWL_POWER_BATTERY
:
1533 final_mode
= IWL_POWER_INDEX_3
;
1536 final_mode
= IWL_POWER_MODE_CAM
;
1543 cmd
.keep_alive_beacons
= 0;
1545 iwl4965_update_power_cmd(priv
, &cmd
, final_mode
);
1547 rc
= iwl_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
1549 if (final_mode
== IWL_POWER_MODE_CAM
)
1550 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
1552 set_bit(STATUS_POWER_PMI
, &priv
->status
);
1557 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1559 /* Filter incoming packets to determine if they are targeted toward
1560 * this network, discarding packets coming from ourselves */
1561 switch (priv
->iw_mode
) {
1562 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
1563 /* packets from our adapter are dropped (echo) */
1564 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
1566 /* {broad,multi}cast packets to our IBSS go through */
1567 if (is_multicast_ether_addr(header
->addr1
))
1568 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
1569 /* packets to our adapter go through */
1570 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1571 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
1572 /* packets from our adapter are dropped (echo) */
1573 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
1575 /* {broad,multi}cast packets to our BSS go through */
1576 if (is_multicast_ether_addr(header
->addr1
))
1577 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
1578 /* packets to our adapter go through */
1579 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1587 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1589 static const char *iwl4965_get_tx_fail_reason(u32 status
)
1591 switch (status
& TX_STATUS_MSK
) {
1592 case TX_STATUS_SUCCESS
:
1594 TX_STATUS_ENTRY(SHORT_LIMIT
);
1595 TX_STATUS_ENTRY(LONG_LIMIT
);
1596 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
1597 TX_STATUS_ENTRY(MGMNT_ABORT
);
1598 TX_STATUS_ENTRY(NEXT_FRAG
);
1599 TX_STATUS_ENTRY(LIFE_EXPIRE
);
1600 TX_STATUS_ENTRY(DEST_PS
);
1601 TX_STATUS_ENTRY(ABORTED
);
1602 TX_STATUS_ENTRY(BT_RETRY
);
1603 TX_STATUS_ENTRY(STA_INVALID
);
1604 TX_STATUS_ENTRY(FRAG_DROPPED
);
1605 TX_STATUS_ENTRY(TID_DISABLE
);
1606 TX_STATUS_ENTRY(FRAME_FLUSHED
);
1607 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
1608 TX_STATUS_ENTRY(TX_LOCKED
);
1609 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
1616 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1618 * NOTE: priv->mutex is not required before calling this function
1620 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
1622 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1623 clear_bit(STATUS_SCANNING
, &priv
->status
);
1627 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1628 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1629 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1630 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1631 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1634 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1636 return test_bit(STATUS_SCANNING
, &priv
->status
);
1643 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1644 * @ms: amount of time to wait (in milliseconds) for scan to abort
1646 * NOTE: priv->mutex must be held before calling this function
1648 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1650 unsigned long now
= jiffies
;
1653 ret
= iwl4965_scan_cancel(priv
);
1655 mutex_unlock(&priv
->mutex
);
1656 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1657 test_bit(STATUS_SCANNING
, &priv
->status
))
1659 mutex_lock(&priv
->mutex
);
1661 return test_bit(STATUS_SCANNING
, &priv
->status
);
1667 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
1669 /* Reset ieee stats */
1671 /* We don't reset the net_device_stats (ieee->stats) on
1674 priv
->last_seq_num
= -1;
1675 priv
->last_frag_num
= -1;
1676 priv
->last_packet_time
= 0;
1678 iwl4965_scan_cancel(priv
);
1681 #define MAX_UCODE_BEACON_INTERVAL 4096
1682 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1684 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
1687 u16 beacon_factor
= 0;
1690 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1691 / MAX_UCODE_BEACON_INTERVAL
;
1692 new_val
= beacon_val
/ beacon_factor
;
1694 return cpu_to_le16(new_val
);
1697 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
1699 u64 interval_tm_unit
;
1701 unsigned long flags
;
1702 struct ieee80211_conf
*conf
= NULL
;
1705 conf
= ieee80211_get_hw_conf(priv
->hw
);
1707 spin_lock_irqsave(&priv
->lock
, flags
);
1708 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
1709 priv
->rxon_timing
.timestamp
.dw
[0] =
1710 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
1712 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1714 tsf
= priv
->timestamp
;
1716 beacon_int
= priv
->beacon_int
;
1717 spin_unlock_irqrestore(&priv
->lock
, flags
);
1719 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1720 if (beacon_int
== 0) {
1721 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1722 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1724 priv
->rxon_timing
.beacon_interval
=
1725 cpu_to_le16(beacon_int
);
1726 priv
->rxon_timing
.beacon_interval
=
1727 iwl4965_adjust_beacon_interval(
1728 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1731 priv
->rxon_timing
.atim_window
= 0;
1733 priv
->rxon_timing
.beacon_interval
=
1734 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1735 /* TODO: we need to get atim_window from upper stack
1736 * for now we set to 0 */
1737 priv
->rxon_timing
.atim_window
= 0;
1741 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1742 result
= do_div(tsf
, interval_tm_unit
);
1743 priv
->rxon_timing
.beacon_init_val
=
1744 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1747 ("beacon interval %d beacon timer %d beacon tim %d\n",
1748 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1749 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1750 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1753 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1755 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1756 IWL_ERROR("APs don't scan.\n");
1760 if (!iwl_is_ready_rf(priv
)) {
1761 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1765 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1766 IWL_DEBUG_SCAN("Scan already in progress.\n");
1770 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1771 IWL_DEBUG_SCAN("Scan request while abort pending. "
1776 IWL_DEBUG_INFO("Starting scan...\n");
1777 if (priv
->cfg
->sku
& IWL_SKU_G
)
1778 priv
->scan_bands
|= BIT(IEEE80211_BAND_2GHZ
);
1779 if (priv
->cfg
->sku
& IWL_SKU_A
)
1780 priv
->scan_bands
|= BIT(IEEE80211_BAND_5GHZ
);
1781 set_bit(STATUS_SCANNING
, &priv
->status
);
1782 priv
->scan_start
= jiffies
;
1783 priv
->scan_pass_start
= priv
->scan_start
;
1785 queue_work(priv
->workqueue
, &priv
->request_scan
);
1791 static void iwl4965_set_flags_for_phymode(struct iwl_priv
*priv
,
1792 enum ieee80211_band band
)
1794 if (band
== IEEE80211_BAND_5GHZ
) {
1795 priv
->staging_rxon
.flags
&=
1796 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1797 | RXON_FLG_CCK_MSK
);
1798 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1800 /* Copied from iwl4965_post_associate() */
1801 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1802 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1804 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1806 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
1807 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1809 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1810 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1811 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1816 * initialize rxon structure with default values from eeprom
1818 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
1820 const struct iwl_channel_info
*ch_info
;
1822 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
1824 switch (priv
->iw_mode
) {
1825 case IEEE80211_IF_TYPE_AP
:
1826 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1829 case IEEE80211_IF_TYPE_STA
:
1830 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
1831 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
1834 case IEEE80211_IF_TYPE_IBSS
:
1835 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
1836 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
1837 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
1838 RXON_FILTER_ACCEPT_GRP_MSK
;
1841 case IEEE80211_IF_TYPE_MNTR
:
1842 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
1843 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
1844 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
1847 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
1852 /* TODO: Figure out when short_preamble would be set and cache from
1854 if (!hw_to_local(priv
->hw
)->short_preamble
)
1855 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1857 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1860 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
1861 le16_to_cpu(priv
->staging_rxon
.channel
));
1864 ch_info
= &priv
->channel_info
[0];
1867 * in some case A channels are all non IBSS
1868 * in this case force B/G channel
1870 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
1871 !(is_channel_ibss(ch_info
)))
1872 ch_info
= &priv
->channel_info
[0];
1874 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
1875 priv
->band
= ch_info
->band
;
1877 iwl4965_set_flags_for_phymode(priv
, priv
->band
);
1879 priv
->staging_rxon
.ofdm_basic_rates
=
1880 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1881 priv
->staging_rxon
.cck_basic_rates
=
1882 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1884 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
1885 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
1886 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1887 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
1888 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
1889 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
1890 iwl4965_set_rxon_chain(priv
);
1893 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
1895 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
1896 const struct iwl_channel_info
*ch_info
;
1898 ch_info
= iwl_get_channel_info(priv
,
1900 le16_to_cpu(priv
->staging_rxon
.channel
));
1902 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
1903 IWL_ERROR("channel %d not IBSS channel\n",
1904 le16_to_cpu(priv
->staging_rxon
.channel
));
1909 priv
->iw_mode
= mode
;
1911 iwl4965_connection_init_rx_config(priv
);
1912 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1914 iwlcore_clear_stations_table(priv
);
1916 /* dont commit rxon if rf-kill is on*/
1917 if (!iwl_is_ready_rf(priv
))
1920 cancel_delayed_work(&priv
->scan_check
);
1921 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
1922 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1923 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1927 iwl4965_commit_rxon(priv
);
1932 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
1933 struct ieee80211_tx_control
*ctl
,
1934 struct iwl_cmd
*cmd
,
1935 struct sk_buff
*skb_frag
,
1938 struct iwl4965_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
1939 struct iwl_wep_key
*wepkey
;
1942 BUG_ON(ctl
->key_idx
> 3);
1944 switch (keyinfo
->alg
) {
1946 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
1947 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
1948 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
1949 cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_AGG_CCMP_MSK
;
1950 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
1954 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
1955 ieee80211_get_tkip_key(keyinfo
->conf
, skb_frag
,
1956 IEEE80211_TKIP_P2_KEY
, cmd
->cmd
.tx
.key
);
1957 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
1961 wepkey
= &priv
->wep_keys
[ctl
->key_idx
];
1962 cmd
->cmd
.tx
.sec_ctl
= 0;
1963 if (priv
->default_wep_key
) {
1964 /* the WEP key was sent as static */
1965 keyidx
= ctl
->key_idx
;
1966 memcpy(&cmd
->cmd
.tx
.key
[3], wepkey
->key
,
1968 if (wepkey
->key_size
== WEP_KEY_LEN_128
)
1969 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
1971 /* the WEP key was sent as dynamic */
1972 keyidx
= keyinfo
->keyidx
;
1973 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
,
1975 if (keyinfo
->keylen
== WEP_KEY_LEN_128
)
1976 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
1979 cmd
->cmd
.tx
.sec_ctl
|= (TX_CMD_SEC_WEP
|
1980 (keyidx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
);
1982 IWL_DEBUG_TX("Configuring packet for WEP encryption "
1983 "with key %d\n", keyidx
);
1987 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
1993 * handle build REPLY_TX command notification.
1995 static void iwl4965_build_tx_cmd_basic(struct iwl_priv
*priv
,
1996 struct iwl_cmd
*cmd
,
1997 struct ieee80211_tx_control
*ctrl
,
1998 struct ieee80211_hdr
*hdr
,
1999 int is_unicast
, u8 std_id
)
2002 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2003 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2005 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2006 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2007 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2008 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2009 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2010 if (ieee80211_is_probe_response(fc
) &&
2011 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2012 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2014 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2015 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2018 if (ieee80211_is_back_request(fc
))
2019 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
2022 cmd
->cmd
.tx
.sta_id
= std_id
;
2023 if (ieee80211_get_morefrag(hdr
))
2024 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2026 qc
= ieee80211_get_qos_ctrl(hdr
);
2028 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2029 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2031 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2033 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2034 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2035 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2036 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2037 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2038 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2041 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2042 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2044 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2045 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2046 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2047 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2048 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2050 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2052 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2055 cmd
->cmd
.tx
.driver_txop
= 0;
2056 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2057 cmd
->cmd
.tx
.next_frame_len
= 0;
2059 static void iwl_update_tx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
2061 /* 0 - mgmt, 1 - cnt, 2 - data */
2062 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
2063 priv
->tx_stats
[idx
].cnt
++;
2064 priv
->tx_stats
[idx
].bytes
+= len
;
2067 * iwl4965_get_sta_id - Find station's index within station table
2069 * If new IBSS station, create new entry in station table
2071 static int iwl4965_get_sta_id(struct iwl_priv
*priv
,
2072 struct ieee80211_hdr
*hdr
)
2075 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2076 DECLARE_MAC_BUF(mac
);
2078 /* If this frame is broadcast or management, use broadcast station id */
2079 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2080 is_multicast_ether_addr(hdr
->addr1
))
2081 return priv
->hw_params
.bcast_sta_id
;
2083 switch (priv
->iw_mode
) {
2085 /* If we are a client station in a BSS network, use the special
2086 * AP station entry (that's the only station we communicate with) */
2087 case IEEE80211_IF_TYPE_STA
:
2090 /* If we are an AP, then find the station, or use BCAST */
2091 case IEEE80211_IF_TYPE_AP
:
2092 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2093 if (sta_id
!= IWL_INVALID_STATION
)
2095 return priv
->hw_params
.bcast_sta_id
;
2097 /* If this frame is going out to an IBSS network, find the station,
2098 * or create a new station table entry */
2099 case IEEE80211_IF_TYPE_IBSS
:
2100 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2101 if (sta_id
!= IWL_INVALID_STATION
)
2104 /* Create new station table entry */
2105 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
2106 0, CMD_ASYNC
, NULL
);
2108 if (sta_id
!= IWL_INVALID_STATION
)
2111 IWL_DEBUG_DROP("Station %s not in station map. "
2112 "Defaulting to broadcast...\n",
2113 print_mac(mac
, hdr
->addr1
));
2114 iwl_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2115 return priv
->hw_params
.bcast_sta_id
;
2118 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
2119 return priv
->hw_params
.bcast_sta_id
;
2124 * start REPLY_TX command process
2126 static int iwl4965_tx_skb(struct iwl_priv
*priv
,
2127 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2129 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2130 struct iwl4965_tfd_frame
*tfd
;
2132 int txq_id
= ctl
->queue
;
2133 struct iwl4965_tx_queue
*txq
= NULL
;
2134 struct iwl4965_queue
*q
= NULL
;
2135 dma_addr_t phys_addr
;
2136 dma_addr_t txcmd_phys
;
2137 dma_addr_t scratch_phys
;
2138 struct iwl_cmd
*out_cmd
= NULL
;
2139 u16 len
, idx
, len_org
;
2140 u8 id
, hdr_len
, unicast
;
2145 u8 wait_write_ptr
= 0;
2146 unsigned long flags
;
2149 spin_lock_irqsave(&priv
->lock
, flags
);
2150 if (iwl_is_rfkill(priv
)) {
2151 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2156 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2160 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2161 IWL_ERROR("ERROR: No TX rate available.\n");
2165 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2168 fc
= le16_to_cpu(hdr
->frame_control
);
2170 #ifdef CONFIG_IWLWIFI_DEBUG
2171 if (ieee80211_is_auth(fc
))
2172 IWL_DEBUG_TX("Sending AUTH frame\n");
2173 else if (ieee80211_is_assoc_request(fc
))
2174 IWL_DEBUG_TX("Sending ASSOC frame\n");
2175 else if (ieee80211_is_reassoc_request(fc
))
2176 IWL_DEBUG_TX("Sending REASSOC frame\n");
2179 /* drop all data frame if we are not associated */
2180 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
2181 (!iwl_is_associated(priv
) ||
2182 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
2183 !priv
->assoc_station_added
)) {
2184 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2188 spin_unlock_irqrestore(&priv
->lock
, flags
);
2190 hdr_len
= ieee80211_get_hdrlen(fc
);
2192 /* Find (or create) index into station table for destination station */
2193 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
2194 if (sta_id
== IWL_INVALID_STATION
) {
2195 DECLARE_MAC_BUF(mac
);
2197 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2198 print_mac(mac
, hdr
->addr1
));
2202 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2204 qc
= ieee80211_get_qos_ctrl(hdr
);
2206 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2207 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2209 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2211 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2213 #ifdef CONFIG_IWL4965_HT
2214 /* aggregation is on for this <sta,tid> */
2215 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2216 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
2217 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
2218 #endif /* CONFIG_IWL4965_HT */
2221 /* Descriptor for chosen Tx queue */
2222 txq
= &priv
->txq
[txq_id
];
2225 spin_lock_irqsave(&priv
->lock
, flags
);
2227 /* Set up first empty TFD within this queue's circular TFD buffer */
2228 tfd
= &txq
->bd
[q
->write_ptr
];
2229 memset(tfd
, 0, sizeof(*tfd
));
2230 control_flags
= (u32
*) tfd
;
2231 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2233 /* Set up driver data for this TFD */
2234 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
2235 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2236 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2237 ctl
, sizeof(struct ieee80211_tx_control
));
2239 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2240 out_cmd
= &txq
->cmd
[idx
];
2241 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2242 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2245 * Set up the Tx-command (not MAC!) header.
2246 * Store the chosen Tx queue and TFD index within the sequence field;
2247 * after Tx, uCode's Tx response will return this value so driver can
2248 * locate the frame within the tx queue and do post-tx processing.
2250 out_cmd
->hdr
.cmd
= REPLY_TX
;
2251 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2252 INDEX_TO_SEQ(q
->write_ptr
)));
2254 /* Copy MAC header from skb into command buffer */
2255 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2258 * Use the first empty entry in this queue's command buffer array
2259 * to contain the Tx command and MAC header concatenated together
2260 * (payload data will be in another buffer).
2261 * Size of this varies, due to varying MAC header length.
2262 * If end is not dword aligned, we'll have 2 extra bytes at the end
2263 * of the MAC header (device reads on dword boundaries).
2264 * We'll tell device about this padding later.
2266 len
= priv
->hw_params
.tx_cmd_len
+
2267 sizeof(struct iwl_cmd_header
) + hdr_len
;
2270 len
= (len
+ 3) & ~3;
2277 /* Physical address of this Tx command's header (not MAC header!),
2278 * within command buffer array. */
2279 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2280 offsetof(struct iwl_cmd
, hdr
);
2282 /* Add buffer containing Tx command and MAC(!) header to TFD's
2284 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2286 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2287 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, sta_id
);
2289 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2290 * if any (802.11 null frames have no payload). */
2291 len
= skb
->len
- hdr_len
;
2293 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2294 len
, PCI_DMA_TODEVICE
);
2295 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2298 /* Tell 4965 about any 2-byte padding after MAC header */
2300 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
2302 /* Total # bytes to be transmitted */
2303 len
= (u16
)skb
->len
;
2304 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2306 /* TODO need this for burst mode later on */
2307 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2309 /* set is_hcca to 0; it probably will never be implemented */
2310 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2312 iwl_update_tx_stats(priv
, fc
, len
);
2314 scratch_phys
= txcmd_phys
+ sizeof(struct iwl_cmd_header
) +
2315 offsetof(struct iwl4965_tx_cmd
, scratch
);
2316 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
2317 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
2319 if (!ieee80211_get_morefrag(hdr
)) {
2320 txq
->need_update
= 1;
2322 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2323 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2327 txq
->need_update
= 0;
2330 iwl_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2331 sizeof(out_cmd
->cmd
.tx
));
2333 iwl_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2334 ieee80211_get_hdrlen(fc
));
2336 /* Set up entry for this TFD in Tx byte-count array */
2337 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, len
);
2339 /* Tell device the write index *just past* this latest filled TFD */
2340 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2341 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2342 spin_unlock_irqrestore(&priv
->lock
, flags
);
2347 if ((iwl4965_queue_space(q
) < q
->high_mark
)
2348 && priv
->mac80211_registered
) {
2349 if (wait_write_ptr
) {
2350 spin_lock_irqsave(&priv
->lock
, flags
);
2351 txq
->need_update
= 1;
2352 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2353 spin_unlock_irqrestore(&priv
->lock
, flags
);
2356 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2362 spin_unlock_irqrestore(&priv
->lock
, flags
);
2367 static void iwl4965_set_rate(struct iwl_priv
*priv
)
2369 const struct ieee80211_supported_band
*hw
= NULL
;
2370 struct ieee80211_rate
*rate
;
2373 hw
= iwl4965_get_hw_mode(priv
, priv
->band
);
2375 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2379 priv
->active_rate
= 0;
2380 priv
->active_rate_basic
= 0;
2382 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
2383 rate
= &(hw
->bitrates
[i
]);
2384 if (rate
->hw_value
< IWL_RATE_COUNT
)
2385 priv
->active_rate
|= (1 << rate
->hw_value
);
2388 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2389 priv
->active_rate
, priv
->active_rate_basic
);
2392 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2393 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2396 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2397 priv
->staging_rxon
.cck_basic_rates
=
2398 ((priv
->active_rate_basic
&
2399 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2401 priv
->staging_rxon
.cck_basic_rates
=
2402 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2404 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2405 priv
->staging_rxon
.ofdm_basic_rates
=
2406 ((priv
->active_rate_basic
&
2407 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2408 IWL_FIRST_OFDM_RATE
) & 0xFF;
2410 priv
->staging_rxon
.ofdm_basic_rates
=
2411 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2414 void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2416 unsigned long flags
;
2418 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2421 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2422 disable_radio
? "OFF" : "ON");
2424 if (disable_radio
) {
2425 iwl4965_scan_cancel(priv
);
2426 /* FIXME: This is a workaround for AP */
2427 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2428 spin_lock_irqsave(&priv
->lock
, flags
);
2429 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2430 CSR_UCODE_SW_BIT_RFKILL
);
2431 spin_unlock_irqrestore(&priv
->lock
, flags
);
2432 /* call the host command only if no hw rf-kill set */
2433 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
) &&
2435 iwl4965_send_card_state(priv
,
2436 CARD_STATE_CMD_DISABLE
,
2438 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2440 /* make sure mac80211 stop sending Tx frame */
2441 if (priv
->mac80211_registered
)
2442 ieee80211_stop_queues(priv
->hw
);
2447 spin_lock_irqsave(&priv
->lock
, flags
);
2448 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2450 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2451 spin_unlock_irqrestore(&priv
->lock
, flags
);
2456 spin_lock_irqsave(&priv
->lock
, flags
);
2457 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2458 if (!iwl_grab_nic_access(priv
))
2459 iwl_release_nic_access(priv
);
2460 spin_unlock_irqrestore(&priv
->lock
, flags
);
2462 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2463 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2464 "disabled by HW switch\n");
2468 queue_work(priv
->workqueue
, &priv
->restart
);
2472 void iwl4965_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
2473 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2476 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2478 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2481 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2484 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2485 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2486 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2487 /* The uCode has got a bad phase 1 Key, pushes the packet.
2488 * Decryption will be done in SW. */
2489 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2490 RX_RES_STATUS_BAD_KEY_TTAK
)
2493 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2494 RX_RES_STATUS_BAD_ICV_MIC
)
2495 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2496 case RX_RES_STATUS_SEC_TYPE_WEP
:
2497 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2498 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2499 RX_RES_STATUS_DECRYPT_OK
) {
2500 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2501 stats
->flag
|= RX_FLAG_DECRYPTED
;
2511 #define IWL_PACKET_RETRY_TIME HZ
2513 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2515 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2516 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2517 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2518 u16
*last_seq
, *last_frag
;
2519 unsigned long *last_time
;
2521 switch (priv
->iw_mode
) {
2522 case IEEE80211_IF_TYPE_IBSS
:{
2523 struct list_head
*p
;
2524 struct iwl4965_ibss_seq
*entry
= NULL
;
2525 u8
*mac
= header
->addr2
;
2526 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2528 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2529 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
2530 if (!compare_ether_addr(entry
->mac
, mac
))
2533 if (p
== &priv
->ibss_mac_hash
[index
]) {
2534 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2536 IWL_ERROR("Cannot malloc new mac entry\n");
2539 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2540 entry
->seq_num
= seq
;
2541 entry
->frag_num
= frag
;
2542 entry
->packet_time
= jiffies
;
2543 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2546 last_seq
= &entry
->seq_num
;
2547 last_frag
= &entry
->frag_num
;
2548 last_time
= &entry
->packet_time
;
2551 case IEEE80211_IF_TYPE_STA
:
2552 last_seq
= &priv
->last_seq_num
;
2553 last_frag
= &priv
->last_frag_num
;
2554 last_time
= &priv
->last_packet_time
;
2559 if ((*last_seq
== seq
) &&
2560 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
2561 if (*last_frag
== frag
)
2563 if (*last_frag
+ 1 != frag
)
2564 /* out-of-order fragment */
2570 *last_time
= jiffies
;
2577 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2579 #include "iwl-spectrum.h"
2581 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2582 #define BEACON_TIME_MASK_HIGH 0xFF000000
2583 #define TIME_UNIT 1024
2586 * extended beacon time format
2587 * time in usec will be changed into a 32-bit value in 8:24 format
2588 * the high 1 byte is the beacon counts
2589 * the lower 3 bytes is the time in usec within one beacon interval
2592 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2596 u32 interval
= beacon_interval
* 1024;
2598 if (!interval
|| !usec
)
2601 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2602 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2604 return (quot
<< 24) + rem
;
2607 /* base is usually what we get from ucode with each received frame,
2608 * the same as HW timer counter counting down
2611 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2613 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2614 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2615 u32 interval
= beacon_interval
* TIME_UNIT
;
2616 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2617 (addon
& BEACON_TIME_MASK_HIGH
);
2619 if (base_low
> addon_low
)
2620 res
+= base_low
- addon_low
;
2621 else if (base_low
< addon_low
) {
2622 res
+= interval
+ base_low
- addon_low
;
2627 return cpu_to_le32(res
);
2630 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
2631 struct ieee80211_measurement_params
*params
,
2634 struct iwl4965_spectrum_cmd spectrum
;
2635 struct iwl4965_rx_packet
*res
;
2636 struct iwl_host_cmd cmd
= {
2637 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2638 .data
= (void *)&spectrum
,
2639 .meta
.flags
= CMD_WANT_SKB
,
2641 u32 add_time
= le64_to_cpu(params
->start_time
);
2643 int spectrum_resp_status
;
2644 int duration
= le16_to_cpu(params
->duration
);
2646 if (iwl_is_associated(priv
))
2648 iwl4965_usecs_to_beacons(
2649 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2650 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2652 memset(&spectrum
, 0, sizeof(spectrum
));
2654 spectrum
.channel_count
= cpu_to_le16(1);
2656 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2657 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2658 cmd
.len
= sizeof(spectrum
);
2659 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2661 if (iwl_is_associated(priv
))
2662 spectrum
.start_time
=
2663 iwl4965_add_beacon_time(priv
->last_beacon_time
,
2665 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2667 spectrum
.start_time
= 0;
2669 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2670 spectrum
.channels
[0].channel
= params
->channel
;
2671 spectrum
.channels
[0].type
= type
;
2672 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2673 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2674 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2676 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2680 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2681 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2682 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2686 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2687 switch (spectrum_resp_status
) {
2688 case 0: /* Command will be handled */
2689 if (res
->u
.spectrum
.id
!= 0xff) {
2691 ("Replaced existing measurement: %d\n",
2692 res
->u
.spectrum
.id
);
2693 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2695 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2699 case 1: /* Command will not be handled */
2704 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2710 static void iwl4965_txstatus_to_ieee(struct iwl_priv
*priv
,
2711 struct iwl4965_tx_info
*tx_sta
)
2714 tx_sta
->status
.ack_signal
= 0;
2715 tx_sta
->status
.excessive_retries
= 0;
2716 tx_sta
->status
.queue_length
= 0;
2717 tx_sta
->status
.queue_number
= 0;
2720 ieee80211_tx_status_irqsafe(priv
->hw
,
2721 tx_sta
->skb
[0], &(tx_sta
->status
));
2723 ieee80211_tx_status(priv
->hw
,
2724 tx_sta
->skb
[0], &(tx_sta
->status
));
2726 tx_sta
->skb
[0] = NULL
;
2730 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2732 * When FW advances 'R' index, all entries between old and new 'R' index
2733 * need to be reclaimed. As result, some free space forms. If there is
2734 * enough free space (> low mark), wake the stack that feeds us.
2736 int iwl4965_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
2738 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2739 struct iwl4965_queue
*q
= &txq
->q
;
2742 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
2743 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2744 "is out of range [0-%d] %d %d.\n", txq_id
,
2745 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2749 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
2750 q
->read_ptr
!= index
;
2751 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2752 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
2753 iwl4965_txstatus_to_ieee(priv
,
2754 &(txq
->txb
[txq
->q
.read_ptr
]));
2755 iwl4965_hw_txq_free_tfd(priv
, txq
);
2756 } else if (nfreed
> 1) {
2757 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
2758 q
->write_ptr
, q
->read_ptr
);
2759 queue_work(priv
->workqueue
, &priv
->restart
);
2764 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2765 (txq_id != IWL_CMD_QUEUE_NUM) &&
2766 priv->mac80211_registered)
2767 ieee80211_wake_queue(priv->hw, txq_id); */
2773 static int iwl4965_is_tx_success(u32 status
)
2775 status
&= TX_STATUS_MSK
;
2776 return (status
== TX_STATUS_SUCCESS
)
2777 || (status
== TX_STATUS_DIRECT_DONE
);
2780 /******************************************************************************
2782 * Generic RX handler implementations
2784 ******************************************************************************/
2785 #ifdef CONFIG_IWL4965_HT
2787 static inline int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
,
2788 struct ieee80211_hdr
*hdr
)
2790 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
2793 u8
*da
= ieee80211_get_DA(hdr
);
2794 return iwl4965_hw_find_station(priv
, da
);
2798 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
2799 struct iwl_priv
*priv
, int txq_id
, int idx
)
2801 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
2802 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
2803 txb
[idx
].skb
[0]->data
;
2807 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
2809 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
2810 tx_resp
->frame_count
);
2811 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
2816 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2818 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
2819 struct iwl4965_ht_agg
*agg
,
2820 struct iwl4965_tx_resp_agg
*tx_resp
,
2824 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
2825 struct ieee80211_tx_status
*tx_status
= NULL
;
2826 struct ieee80211_hdr
*hdr
= NULL
;
2831 if (agg
->wait_for_ba
)
2832 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2834 agg
->frame_count
= tx_resp
->frame_count
;
2835 agg
->start_idx
= start_idx
;
2836 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2839 /* # frames attempted by Tx command */
2840 if (agg
->frame_count
== 1) {
2841 /* Only one frame was attempted; no block-ack will arrive */
2842 status
= le16_to_cpu(frame_status
[0].status
);
2843 seq
= le16_to_cpu(frame_status
[0].sequence
);
2844 idx
= SEQ_TO_INDEX(seq
);
2845 txq_id
= SEQ_TO_QUEUE(seq
);
2847 /* FIXME: code repetition */
2848 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2849 agg
->frame_count
, agg
->start_idx
, idx
);
2851 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
2852 tx_status
->retry_count
= tx_resp
->failure_frame
;
2853 tx_status
->queue_number
= status
& 0xff;
2854 tx_status
->queue_length
= tx_resp
->failure_rts
;
2855 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
2856 tx_status
->flags
= iwl4965_is_tx_success(status
)?
2857 IEEE80211_TX_STATUS_ACK
: 0;
2858 iwl4965_hwrate_to_tx_control(priv
,
2859 le32_to_cpu(tx_resp
->rate_n_flags
),
2860 &tx_status
->control
);
2861 /* FIXME: code repetition end */
2863 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2864 status
& 0xff, tx_resp
->failure_frame
);
2865 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
2866 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
2868 agg
->wait_for_ba
= 0;
2870 /* Two or more frames were attempted; expect block-ack */
2872 int start
= agg
->start_idx
;
2874 /* Construct bit-map of pending frames within Tx window */
2875 for (i
= 0; i
< agg
->frame_count
; i
++) {
2877 status
= le16_to_cpu(frame_status
[i
].status
);
2878 seq
= le16_to_cpu(frame_status
[i
].sequence
);
2879 idx
= SEQ_TO_INDEX(seq
);
2880 txq_id
= SEQ_TO_QUEUE(seq
);
2882 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
2883 AGG_TX_STATE_ABORT_MSK
))
2886 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2887 agg
->frame_count
, txq_id
, idx
);
2889 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
2891 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2892 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
2893 IWL_ERROR("BUG_ON idx doesn't match seq control"
2894 " idx=%d, seq_idx=%d, seq=%d\n",
2900 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2901 i
, idx
, SEQ_TO_SN(sc
));
2905 sh
= (start
- idx
) + 0xff;
2906 bitmap
= bitmap
<< sh
;
2909 } else if (sh
< -64)
2910 sh
= 0xff - (start
- idx
);
2914 bitmap
= bitmap
<< sh
;
2917 bitmap
|= (1 << sh
);
2918 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
2919 start
, (u32
)(bitmap
& 0xFFFFFFFF));
2922 agg
->bitmap
= bitmap
;
2923 agg
->start_idx
= start
;
2924 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2925 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2926 agg
->frame_count
, agg
->start_idx
,
2927 (unsigned long long)agg
->bitmap
);
2930 agg
->wait_for_ba
= 1;
2937 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
2939 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
2940 struct iwl4965_rx_mem_buffer
*rxb
)
2942 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2943 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
2944 int txq_id
= SEQ_TO_QUEUE(sequence
);
2945 int index
= SEQ_TO_INDEX(sequence
);
2946 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2947 struct ieee80211_tx_status
*tx_status
;
2948 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
2949 u32 status
= le32_to_cpu(tx_resp
->status
);
2950 #ifdef CONFIG_IWL4965_HT
2951 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
2952 struct ieee80211_hdr
*hdr
;
2956 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
2957 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
2958 "is out of range [0-%d] %d %d\n", txq_id
,
2959 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
2964 #ifdef CONFIG_IWL4965_HT
2965 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
2966 qc
= ieee80211_get_qos_ctrl(hdr
);
2969 tid
= le16_to_cpu(*qc
) & 0xf;
2971 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
2972 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
2973 IWL_ERROR("Station not known\n");
2977 if (txq
->sched_retry
) {
2978 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
2979 struct iwl4965_ht_agg
*agg
= NULL
;
2984 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
2986 iwl4965_tx_status_reply_tx(priv
, agg
,
2987 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
2989 if ((tx_resp
->frame_count
== 1) &&
2990 !iwl4965_is_tx_success(status
)) {
2991 /* TODO: send BAR */
2994 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
2996 index
= iwl_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
2997 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
2998 "%d index %d\n", scd_ssn
, index
);
2999 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3000 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3002 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3003 txq_id
>= 0 && priv
->mac80211_registered
&&
3004 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
3005 ieee80211_wake_queue(priv
->hw
, txq_id
);
3007 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3010 #endif /* CONFIG_IWL4965_HT */
3011 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
3013 tx_status
->retry_count
= tx_resp
->failure_frame
;
3014 tx_status
->queue_number
= status
;
3015 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3016 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3018 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3019 iwl4965_hwrate_to_tx_control(priv
, le32_to_cpu(tx_resp
->rate_n_flags
),
3020 &tx_status
->control
);
3022 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3023 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
3024 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
3025 tx_resp
->failure_frame
);
3027 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3029 #ifdef CONFIG_IWL4965_HT
3030 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3032 if (tid
!= MAX_TID_COUNT
)
3033 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3034 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3036 priv
->mac80211_registered
)
3037 ieee80211_wake_queue(priv
->hw
, txq_id
);
3038 if (tid
!= MAX_TID_COUNT
)
3039 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3042 #ifdef CONFIG_IWL4965_HT
3044 #endif /* CONFIG_IWL4965_HT */
3046 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3047 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3051 static void iwl4965_rx_reply_alive(struct iwl_priv
*priv
,
3052 struct iwl4965_rx_mem_buffer
*rxb
)
3054 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3055 struct iwl4965_alive_resp
*palive
;
3056 struct delayed_work
*pwork
;
3058 palive
= &pkt
->u
.alive_frame
;
3060 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3062 palive
->is_valid
, palive
->ver_type
,
3063 palive
->ver_subtype
);
3065 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3066 IWL_DEBUG_INFO("Initialization Alive received.\n");
3067 memcpy(&priv
->card_alive_init
,
3068 &pkt
->u
.alive_frame
,
3069 sizeof(struct iwl4965_init_alive_resp
));
3070 pwork
= &priv
->init_alive_start
;
3072 IWL_DEBUG_INFO("Runtime Alive received.\n");
3073 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3074 sizeof(struct iwl4965_alive_resp
));
3075 pwork
= &priv
->alive_start
;
3078 /* We delay the ALIVE response by 5ms to
3079 * give the HW RF Kill time to activate... */
3080 if (palive
->is_valid
== UCODE_VALID_OK
)
3081 queue_delayed_work(priv
->workqueue
, pwork
,
3082 msecs_to_jiffies(5));
3084 IWL_WARNING("uCode did not respond OK.\n");
3087 static void iwl4965_rx_reply_add_sta(struct iwl_priv
*priv
,
3088 struct iwl4965_rx_mem_buffer
*rxb
)
3090 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3092 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3096 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
3097 struct iwl4965_rx_mem_buffer
*rxb
)
3099 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3101 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3102 "seq 0x%04X ser 0x%08X\n",
3103 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3104 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3105 pkt
->u
.err_resp
.cmd_id
,
3106 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3107 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3110 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3112 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
3114 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3115 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3116 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3117 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3118 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3119 rxon
->channel
= csa
->channel
;
3120 priv
->staging_rxon
.channel
= csa
->channel
;
3123 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
3124 struct iwl4965_rx_mem_buffer
*rxb
)
3126 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3127 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3128 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3130 if (!report
->state
) {
3131 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3132 "Spectrum Measure Notification: Start\n");
3136 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3137 priv
->measurement_status
|= MEASUREMENT_READY
;
3141 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
3142 struct iwl4965_rx_mem_buffer
*rxb
)
3144 #ifdef CONFIG_IWLWIFI_DEBUG
3145 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3146 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3147 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3148 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3152 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
3153 struct iwl4965_rx_mem_buffer
*rxb
)
3155 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3156 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3157 "notification for %s:\n",
3158 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3159 iwl_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3162 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
3164 struct iwl_priv
*priv
=
3165 container_of(work
, struct iwl_priv
, beacon_update
);
3166 struct sk_buff
*beacon
;
3168 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3169 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
3172 IWL_ERROR("update beacon failed\n");
3176 mutex_lock(&priv
->mutex
);
3177 /* new beacon skb is allocated every time; dispose previous.*/
3178 if (priv
->ibss_beacon
)
3179 dev_kfree_skb(priv
->ibss_beacon
);
3181 priv
->ibss_beacon
= beacon
;
3182 mutex_unlock(&priv
->mutex
);
3184 iwl4965_send_beacon_cmd(priv
);
3187 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
3188 struct iwl4965_rx_mem_buffer
*rxb
)
3190 #ifdef CONFIG_IWLWIFI_DEBUG
3191 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3192 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3193 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
3195 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3196 "tsf %d %d rate %d\n",
3197 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3198 beacon
->beacon_notify_hdr
.failure_frame
,
3199 le32_to_cpu(beacon
->ibss_mgr_status
),
3200 le32_to_cpu(beacon
->high_tsf
),
3201 le32_to_cpu(beacon
->low_tsf
), rate
);
3204 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3205 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3206 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3209 /* Service response to REPLY_SCAN_CMD (0x80) */
3210 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
3211 struct iwl4965_rx_mem_buffer
*rxb
)
3213 #ifdef CONFIG_IWLWIFI_DEBUG
3214 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3215 struct iwl4965_scanreq_notification
*notif
=
3216 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
3218 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3222 /* Service SCAN_START_NOTIFICATION (0x82) */
3223 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
3224 struct iwl4965_rx_mem_buffer
*rxb
)
3226 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3227 struct iwl4965_scanstart_notification
*notif
=
3228 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
3229 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3230 IWL_DEBUG_SCAN("Scan start: "
3232 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3234 notif
->band
? "bg" : "a",
3236 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3239 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3240 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
3241 struct iwl4965_rx_mem_buffer
*rxb
)
3243 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3244 struct iwl4965_scanresults_notification
*notif
=
3245 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
3247 IWL_DEBUG_SCAN("Scan ch.res: "
3249 "(TSF: 0x%08X:%08X) - %d "
3250 "elapsed=%lu usec (%dms since last)\n",
3252 notif
->band
? "bg" : "a",
3253 le32_to_cpu(notif
->tsf_high
),
3254 le32_to_cpu(notif
->tsf_low
),
3255 le32_to_cpu(notif
->statistics
[0]),
3256 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3257 jiffies_to_msecs(elapsed_jiffies
3258 (priv
->last_scan_jiffies
, jiffies
)));
3260 priv
->last_scan_jiffies
= jiffies
;
3261 priv
->next_scan_jiffies
= 0;
3264 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3265 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
3266 struct iwl4965_rx_mem_buffer
*rxb
)
3268 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3269 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3271 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3272 scan_notif
->scanned_channels
,
3273 scan_notif
->tsf_low
,
3274 scan_notif
->tsf_high
, scan_notif
->status
);
3276 /* The HW is no longer scanning */
3277 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3279 /* The scan completion notification came in, so kill that timer... */
3280 cancel_delayed_work(&priv
->scan_check
);
3282 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3283 (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) ?
3285 jiffies_to_msecs(elapsed_jiffies
3286 (priv
->scan_pass_start
, jiffies
)));
3288 /* Remove this scanned band from the list of pending
3289 * bands to scan, band G precedes A in order of scanning
3290 * as seen in iwl_bg_request_scan */
3291 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
))
3292 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_2GHZ
);
3293 else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
))
3294 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_5GHZ
);
3296 /* If a request to abort was given, or the scan did not succeed
3297 * then we reset the scan state machine and terminate,
3298 * re-queuing another scan if one has been requested */
3299 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3300 IWL_DEBUG_INFO("Aborted scan completed.\n");
3301 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3303 /* If there are more bands on this scan pass reschedule */
3304 if (priv
->scan_bands
)
3308 priv
->last_scan_jiffies
= jiffies
;
3309 priv
->next_scan_jiffies
= 0;
3310 IWL_DEBUG_INFO("Setting scan to off\n");
3312 clear_bit(STATUS_SCANNING
, &priv
->status
);
3314 IWL_DEBUG_INFO("Scan took %dms\n",
3315 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3317 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3322 priv
->scan_pass_start
= jiffies
;
3323 queue_work(priv
->workqueue
, &priv
->request_scan
);
3326 /* Handle notification from uCode that card's power state is changing
3327 * due to software, hardware, or critical temperature RFKILL */
3328 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
3329 struct iwl4965_rx_mem_buffer
*rxb
)
3331 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3332 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3333 unsigned long status
= priv
->status
;
3335 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3336 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3337 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3339 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
3340 RF_CARD_DISABLED
)) {
3342 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3343 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3345 if (!iwl_grab_nic_access(priv
)) {
3347 priv
, HBUS_TARG_MBX_C
,
3348 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3350 iwl_release_nic_access(priv
);
3353 if (!(flags
& RXON_CARD_DISABLED
)) {
3354 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
3355 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3356 if (!iwl_grab_nic_access(priv
)) {
3358 priv
, HBUS_TARG_MBX_C
,
3359 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3361 iwl_release_nic_access(priv
);
3365 if (flags
& RF_CARD_DISABLED
) {
3366 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3367 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
3368 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3369 if (!iwl_grab_nic_access(priv
))
3370 iwl_release_nic_access(priv
);
3374 if (flags
& HW_CARD_DISABLED
)
3375 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3377 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3380 if (flags
& SW_CARD_DISABLED
)
3381 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3383 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3385 if (!(flags
& RXON_CARD_DISABLED
))
3386 iwl4965_scan_cancel(priv
);
3388 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3389 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3390 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3391 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3392 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3394 wake_up_interruptible(&priv
->wait_command_queue
);
3398 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3400 * Setup the RX handlers for each of the reply types sent from the uCode
3403 * This function chains into the hardware specific files for them to setup
3404 * any hardware specific handlers as well.
3406 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
3408 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
3409 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
3410 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
3411 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
3412 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3413 iwl4965_rx_spectrum_measure_notif
;
3414 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
3415 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3416 iwl4965_rx_pm_debug_statistics_notif
;
3417 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
3420 * The same handler is used for both the REPLY to a discrete
3421 * statistics request from the host as well as for the periodic
3422 * statistics notifications (after received beacons) from the uCode.
3424 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
3425 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
3427 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
3428 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
3429 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3430 iwl4965_rx_scan_results_notif
;
3431 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3432 iwl4965_rx_scan_complete_notif
;
3433 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
3434 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
3436 /* Set up hardware specific Rx handlers */
3437 iwl4965_hw_rx_handler_setup(priv
);
3441 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3442 * @rxb: Rx buffer to reclaim
3444 * If an Rx buffer has an async callback associated with it the callback
3445 * will be executed. The attached skb (if present) will only be freed
3446 * if the callback returns 1
3448 static void iwl4965_tx_cmd_complete(struct iwl_priv
*priv
,
3449 struct iwl4965_rx_mem_buffer
*rxb
)
3451 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3452 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3453 int txq_id
= SEQ_TO_QUEUE(sequence
);
3454 int index
= SEQ_TO_INDEX(sequence
);
3455 int huge
= sequence
& SEQ_HUGE_FRAME
;
3457 struct iwl_cmd
*cmd
;
3459 /* If a Tx command is being handled and it isn't in the actual
3460 * command queue then there a command routing bug has been introduced
3461 * in the queue management code. */
3462 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3463 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3464 txq_id
, pkt
->hdr
.cmd
);
3465 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3467 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3468 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3470 /* Input error checking is done when commands are added to queue. */
3471 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3472 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3474 } else if (cmd
->meta
.u
.callback
&&
3475 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3478 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3480 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3481 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3482 wake_up_interruptible(&priv
->wait_command_queue
);
3486 /************************** RX-FUNCTIONS ****************************/
3488 * Rx theory of operation
3490 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3491 * each of which point to Receive Buffers to be filled by 4965. These get
3492 * used not only for Rx frames, but for any command response or notification
3493 * from the 4965. The driver and 4965 manage the Rx buffers by means
3494 * of indexes into the circular buffer.
3497 * The host/firmware share two index registers for managing the Rx buffers.
3499 * The READ index maps to the first position that the firmware may be writing
3500 * to -- the driver can read up to (but not including) this position and get
3502 * The READ index is managed by the firmware once the card is enabled.
3504 * The WRITE index maps to the last position the driver has read from -- the
3505 * position preceding WRITE is the last slot the firmware can place a packet.
3507 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3510 * During initialization, the host sets up the READ queue position to the first
3511 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3513 * When the firmware places a packet in a buffer, it will advance the READ index
3514 * and fire the RX interrupt. The driver can then query the READ index and
3515 * process as many packets as possible, moving the WRITE index forward as it
3516 * resets the Rx queue buffers with new memory.
3518 * The management in the driver is as follows:
3519 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3520 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3521 * to replenish the iwl->rxq->rx_free.
3522 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3523 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3524 * 'processed' and 'read' driver indexes as well)
3525 * + A received packet is processed and handed to the kernel network stack,
3526 * detached from the iwl->rxq. The driver 'processed' index is updated.
3527 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3528 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3529 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3530 * were enough free buffers and RX_STALLED is set it is cleared.
3535 * iwl4965_rx_queue_alloc() Allocates rx_free
3536 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3537 * iwl4965_rx_queue_restock
3538 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3539 * queue, updates firmware pointers, and updates
3540 * the WRITE index. If insufficient rx_free buffers
3541 * are available, schedules iwl4965_rx_replenish
3543 * -- enable interrupts --
3544 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3545 * READ INDEX, detaching the SKB from the pool.
3546 * Moves the packet buffer from queue to rx_used.
3547 * Calls iwl4965_rx_queue_restock to refill any empty
3554 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3556 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue
*q
)
3558 int s
= q
->read
- q
->write
;
3561 /* keep some buffer to not confuse full and empty queue */
3569 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3571 int iwl4965_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*q
)
3575 unsigned long flags
;
3577 spin_lock_irqsave(&q
->lock
, flags
);
3579 if (q
->need_update
== 0)
3582 /* If power-saving is in use, make sure device is awake */
3583 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3584 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3586 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3587 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3588 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3592 rc
= iwl_grab_nic_access(priv
);
3596 /* Device expects a multiple of 8 */
3597 iwl_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3599 iwl_release_nic_access(priv
);
3601 /* Else device is assumed to be awake */
3603 /* Device expects a multiple of 8 */
3604 iwl_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3610 spin_unlock_irqrestore(&q
->lock
, flags
);
3615 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3617 static inline __le32
iwl4965_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3618 dma_addr_t dma_addr
)
3620 return cpu_to_le32((u32
)(dma_addr
>> 8));
3625 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3627 * If there are slots in the RX queue that need to be restocked,
3628 * and we have free pre-allocated buffers, fill the ranks as much
3629 * as we can, pulling from rx_free.
3631 * This moves the 'write' index forward to catch up with 'processed', and
3632 * also updates the memory address in the firmware to reference the new
3635 static int iwl4965_rx_queue_restock(struct iwl_priv
*priv
)
3637 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3638 struct list_head
*element
;
3639 struct iwl4965_rx_mem_buffer
*rxb
;
3640 unsigned long flags
;
3643 spin_lock_irqsave(&rxq
->lock
, flags
);
3644 write
= rxq
->write
& ~0x7;
3645 while ((iwl4965_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3646 /* Get next free Rx buffer, remove from free list */
3647 element
= rxq
->rx_free
.next
;
3648 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3651 /* Point to Rx buffer via next RBD in circular buffer */
3652 rxq
->bd
[rxq
->write
] = iwl4965_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3653 rxq
->queue
[rxq
->write
] = rxb
;
3654 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3657 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3658 /* If the pre-allocated buffer pool is dropping low, schedule to
3660 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3661 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3664 /* If we've added more space for the firmware to place data, tell it.
3665 * Increment device's write pointer in multiples of 8. */
3666 if ((write
!= (rxq
->write
& ~0x7))
3667 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3668 spin_lock_irqsave(&rxq
->lock
, flags
);
3669 rxq
->need_update
= 1;
3670 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3671 rc
= iwl4965_rx_queue_update_write_ptr(priv
, rxq
);
3680 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3682 * When moving to rx_free an SKB is allocated for the slot.
3684 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3685 * This is called as a scheduled work item (except for during initialization)
3687 static void iwl4965_rx_allocate(struct iwl_priv
*priv
)
3689 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3690 struct list_head
*element
;
3691 struct iwl4965_rx_mem_buffer
*rxb
;
3692 unsigned long flags
;
3693 spin_lock_irqsave(&rxq
->lock
, flags
);
3694 while (!list_empty(&rxq
->rx_used
)) {
3695 element
= rxq
->rx_used
.next
;
3696 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3698 /* Alloc a new receive buffer */
3700 alloc_skb(priv
->hw_params
.rx_buf_size
,
3701 __GFP_NOWARN
| GFP_ATOMIC
);
3703 if (net_ratelimit())
3704 printk(KERN_CRIT DRV_NAME
3705 ": Can not allocate SKB buffers\n");
3706 /* We don't reschedule replenish work here -- we will
3707 * call the restock method and if it still needs
3708 * more buffers it will schedule replenish */
3711 priv
->alloc_rxb_skb
++;
3714 /* Get physical address of RB/SKB */
3716 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3717 priv
->hw_params
.rx_buf_size
, PCI_DMA_FROMDEVICE
);
3718 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3721 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3725 * this should be called while priv->lock is locked
3727 static void __iwl4965_rx_replenish(void *data
)
3729 struct iwl_priv
*priv
= data
;
3731 iwl4965_rx_allocate(priv
);
3732 iwl4965_rx_queue_restock(priv
);
3736 void iwl4965_rx_replenish(void *data
)
3738 struct iwl_priv
*priv
= data
;
3739 unsigned long flags
;
3741 iwl4965_rx_allocate(priv
);
3743 spin_lock_irqsave(&priv
->lock
, flags
);
3744 iwl4965_rx_queue_restock(priv
);
3745 spin_unlock_irqrestore(&priv
->lock
, flags
);
3748 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3749 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3750 * This free routine walks the list of POOL entries and if SKB is set to
3751 * non NULL it is unmapped and freed
3753 static void iwl4965_rx_queue_free(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3756 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3757 if (rxq
->pool
[i
].skb
!= NULL
) {
3758 pci_unmap_single(priv
->pci_dev
,
3759 rxq
->pool
[i
].dma_addr
,
3760 priv
->hw_params
.rx_buf_size
,
3761 PCI_DMA_FROMDEVICE
);
3762 dev_kfree_skb(rxq
->pool
[i
].skb
);
3766 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3771 int iwl4965_rx_queue_alloc(struct iwl_priv
*priv
)
3773 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3774 struct pci_dev
*dev
= priv
->pci_dev
;
3777 spin_lock_init(&rxq
->lock
);
3778 INIT_LIST_HEAD(&rxq
->rx_free
);
3779 INIT_LIST_HEAD(&rxq
->rx_used
);
3781 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3782 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3786 /* Fill the rx_used queue with _all_ of the Rx buffers */
3787 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3788 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3790 /* Set us so that we have processed and used all buffers, but have
3791 * not restocked the Rx queue with fresh buffers */
3792 rxq
->read
= rxq
->write
= 0;
3793 rxq
->free_count
= 0;
3794 rxq
->need_update
= 0;
3798 void iwl4965_rx_queue_reset(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3800 unsigned long flags
;
3802 spin_lock_irqsave(&rxq
->lock
, flags
);
3803 INIT_LIST_HEAD(&rxq
->rx_free
);
3804 INIT_LIST_HEAD(&rxq
->rx_used
);
3805 /* Fill the rx_used queue with _all_ of the Rx buffers */
3806 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3807 /* In the reset function, these buffers may have been allocated
3808 * to an SKB, so we need to unmap and free potential storage */
3809 if (rxq
->pool
[i
].skb
!= NULL
) {
3810 pci_unmap_single(priv
->pci_dev
,
3811 rxq
->pool
[i
].dma_addr
,
3812 priv
->hw_params
.rx_buf_size
,
3813 PCI_DMA_FROMDEVICE
);
3814 priv
->alloc_rxb_skb
--;
3815 dev_kfree_skb(rxq
->pool
[i
].skb
);
3816 rxq
->pool
[i
].skb
= NULL
;
3818 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3821 /* Set us so that we have processed and used all buffers, but have
3822 * not restocked the Rx queue with fresh buffers */
3823 rxq
->read
= rxq
->write
= 0;
3824 rxq
->free_count
= 0;
3825 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3828 /* Convert linear signal-to-noise ratio into dB */
3829 static u8 ratio2dB
[100] = {
3830 /* 0 1 2 3 4 5 6 7 8 9 */
3831 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3832 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3833 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3834 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3835 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3836 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3837 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3838 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3839 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3840 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3843 /* Calculates a relative dB value from a ratio of linear
3844 * (i.e. not dB) signal levels.
3845 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3846 int iwl4965_calc_db_from_ratio(int sig_ratio
)
3848 /* 1000:1 or higher just report as 60 dB */
3849 if (sig_ratio
>= 1000)
3852 /* 100:1 or higher, divide by 10 and use table,
3853 * add 20 dB to make up for divide by 10 */
3854 if (sig_ratio
>= 100)
3855 return (20 + (int)ratio2dB
[sig_ratio
/10]);
3857 /* We shouldn't see this */
3861 /* Use table for ratios 1:1 - 99:1 */
3862 return (int)ratio2dB
[sig_ratio
];
3865 #define PERFECT_RSSI (-20) /* dBm */
3866 #define WORST_RSSI (-95) /* dBm */
3867 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3869 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3870 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3871 * about formulas used below. */
3872 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
3875 int degradation
= PERFECT_RSSI
- rssi_dbm
;
3877 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3878 * as indicator; formula is (signal dbm - noise dbm).
3879 * SNR at or above 40 is a great signal (100%).
3880 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3881 * Weakest usable signal is usually 10 - 15 dB SNR. */
3883 if (rssi_dbm
- noise_dbm
>= 40)
3885 else if (rssi_dbm
< noise_dbm
)
3887 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
3889 /* Else use just the signal level.
3890 * This formula is a least squares fit of data points collected and
3891 * compared with a reference system that had a percentage (%) display
3892 * for signal quality. */
3894 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
3895 (15 * RSSI_RANGE
+ 62 * degradation
)) /
3896 (RSSI_RANGE
* RSSI_RANGE
);
3900 else if (sig_qual
< 1)
3907 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
3909 * Uses the priv->rx_handlers callback function array to invoke
3910 * the appropriate handlers, including command responses,
3911 * frame-received notifications, and other notifications.
3913 static void iwl4965_rx_handle(struct iwl_priv
*priv
)
3915 struct iwl4965_rx_mem_buffer
*rxb
;
3916 struct iwl4965_rx_packet
*pkt
;
3917 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3920 unsigned long flags
;
3924 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3925 * buffer that the driver may process (last buffer filled by ucode). */
3926 r
= iwl4965_hw_get_rx_read(priv
);
3929 /* Rx interrupt, but nothing sent from uCode */
3931 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
3933 if (iwl4965_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
3937 rxb
= rxq
->queue
[i
];
3939 /* If an RXB doesn't have a Rx queue slot associated with it,
3940 * then a bug has been introduced in the queue refilling
3941 * routines -- catch it here */
3942 BUG_ON(rxb
== NULL
);
3944 rxq
->queue
[i
] = NULL
;
3946 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
3947 priv
->hw_params
.rx_buf_size
,
3948 PCI_DMA_FROMDEVICE
);
3949 pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3951 /* Reclaim a command buffer only if this packet is a response
3952 * to a (driver-originated) command.
3953 * If the packet (e.g. Rx frame) originated from uCode,
3954 * there is no command buffer to reclaim.
3955 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3956 * but apparently a few don't get set; catch them here. */
3957 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
3958 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
3959 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
3960 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
3961 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
3962 (pkt
->hdr
.cmd
!= REPLY_TX
);
3964 /* Based on type of command response or notification,
3965 * handle those that need handling via function in
3966 * rx_handlers table. See iwl4965_setup_rx_handlers() */
3967 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
3968 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3969 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
3970 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
3971 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
3973 /* No handling needed */
3974 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3975 "r %d i %d No handler needed for %s, 0x%02x\n",
3976 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
3981 /* Invoke any callbacks, transfer the skb to caller, and
3982 * fire off the (possibly) blocking iwl_send_cmd()
3983 * as we reclaim the driver command queue */
3984 if (rxb
&& rxb
->skb
)
3985 iwl4965_tx_cmd_complete(priv
, rxb
);
3987 IWL_WARNING("Claim null rxb?\n");
3990 /* For now we just don't re-use anything. We can tweak this
3991 * later to try and re-use notification packets and SKBs that
3992 * fail to Rx correctly */
3993 if (rxb
->skb
!= NULL
) {
3994 priv
->alloc_rxb_skb
--;
3995 dev_kfree_skb_any(rxb
->skb
);
3999 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4000 priv
->hw_params
.rx_buf_size
,
4001 PCI_DMA_FROMDEVICE
);
4002 spin_lock_irqsave(&rxq
->lock
, flags
);
4003 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4004 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4005 i
= (i
+ 1) & RX_QUEUE_MASK
;
4006 /* If there are a lot of unused frames,
4007 * restock the Rx queue so ucode wont assert. */
4012 __iwl4965_rx_replenish(priv
);
4018 /* Backtrack one entry */
4020 iwl4965_rx_queue_restock(priv
);
4024 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4026 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
4027 struct iwl4965_tx_queue
*txq
)
4031 int txq_id
= txq
->q
.id
;
4033 if (txq
->need_update
== 0)
4036 /* if we're trying to save power */
4037 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4038 /* wake up nic if it's powered down ...
4039 * uCode will wake up, and interrupt us again, so next
4040 * time we'll skip this part. */
4041 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
4043 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4044 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4045 iwl_set_bit(priv
, CSR_GP_CNTRL
,
4046 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4050 /* restore this queue's parameters in nic hardware. */
4051 rc
= iwl_grab_nic_access(priv
);
4054 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
4055 txq
->q
.write_ptr
| (txq_id
<< 8));
4056 iwl_release_nic_access(priv
);
4058 /* else not in power-save mode, uCode will never sleep when we're
4059 * trying to tx (during RFKILL, we're not trying to tx). */
4061 iwl_write32(priv
, HBUS_TARG_WRPTR
,
4062 txq
->q
.write_ptr
| (txq_id
<< 8));
4064 txq
->need_update
= 0;
4069 #ifdef CONFIG_IWLWIFI_DEBUG
4070 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd
*rxon
)
4072 DECLARE_MAC_BUF(mac
);
4074 IWL_DEBUG_RADIO("RX CONFIG:\n");
4075 iwl_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4076 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4077 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4078 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4079 le32_to_cpu(rxon
->filter_flags
));
4080 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4081 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4082 rxon
->ofdm_basic_rates
);
4083 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4084 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4085 print_mac(mac
, rxon
->node_addr
));
4086 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4087 print_mac(mac
, rxon
->bssid_addr
));
4088 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4092 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
4094 IWL_DEBUG_ISR("Enabling interrupts\n");
4095 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4096 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4099 /* call this function to flush any scheduled tasklet */
4100 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
4102 /* wait to make sure we flush pedding tasklet*/
4103 synchronize_irq(priv
->pci_dev
->irq
);
4104 tasklet_kill(&priv
->irq_tasklet
);
4107 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
4109 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4111 /* disable interrupts from uCode/NIC to host */
4112 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4114 /* acknowledge/clear/reset any interrupts still pending
4115 * from uCode or flow handler (Rx/Tx DMA) */
4116 iwl_write32(priv
, CSR_INT
, 0xffffffff);
4117 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4118 IWL_DEBUG_ISR("Disabled interrupts\n");
4121 static const char *desc_lookup(int i
)
4129 return "BAD_CHECKSUM";
4131 return "NMI_INTERRUPT";
4135 return "FATAL_ERROR";
4141 #define ERROR_START_OFFSET (1 * sizeof(u32))
4142 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4144 static void iwl4965_dump_nic_error_log(struct iwl_priv
*priv
)
4147 u32 desc
, time
, count
, base
, data1
;
4148 u32 blink1
, blink2
, ilink1
, ilink2
;
4151 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4153 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4154 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4158 rc
= iwl_grab_nic_access(priv
);
4160 IWL_WARNING("Can not read from adapter at this time.\n");
4164 count
= iwl_read_targ_mem(priv
, base
);
4166 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4167 IWL_ERROR("Start IWL Error Log Dump:\n");
4168 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
4171 desc
= iwl_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
4172 blink1
= iwl_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
4173 blink2
= iwl_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
4174 ilink1
= iwl_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
4175 ilink2
= iwl_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
4176 data1
= iwl_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
4177 data2
= iwl_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
4178 line
= iwl_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
4179 time
= iwl_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
4181 IWL_ERROR("Desc Time "
4182 "data1 data2 line\n");
4183 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4184 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
4185 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4186 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
4189 iwl_release_nic_access(priv
);
4192 #define EVENT_START_OFFSET (4 * sizeof(u32))
4195 * iwl4965_print_event_log - Dump error event log to syslog
4197 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4199 static void iwl4965_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4200 u32 num_events
, u32 mode
)
4203 u32 base
; /* SRAM byte address of event log header */
4204 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4205 u32 ptr
; /* SRAM byte address of log data */
4206 u32 ev
, time
, data
; /* event log data */
4208 if (num_events
== 0)
4211 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4214 event_size
= 2 * sizeof(u32
);
4216 event_size
= 3 * sizeof(u32
);
4218 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4220 /* "time" is actually "data" for mode 0 (no timestamp).
4221 * place event id # at far right for easier visual parsing. */
4222 for (i
= 0; i
< num_events
; i
++) {
4223 ev
= iwl_read_targ_mem(priv
, ptr
);
4225 time
= iwl_read_targ_mem(priv
, ptr
);
4228 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4230 data
= iwl_read_targ_mem(priv
, ptr
);
4232 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4237 static void iwl4965_dump_nic_event_log(struct iwl_priv
*priv
)
4240 u32 base
; /* SRAM byte address of event log header */
4241 u32 capacity
; /* event log capacity in # entries */
4242 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4243 u32 num_wraps
; /* # times uCode wrapped to top of log */
4244 u32 next_entry
; /* index of next entry to be written by uCode */
4245 u32 size
; /* # entries that we'll print */
4247 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4248 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4249 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4253 rc
= iwl_grab_nic_access(priv
);
4255 IWL_WARNING("Can not read from adapter at this time.\n");
4259 /* event log header */
4260 capacity
= iwl_read_targ_mem(priv
, base
);
4261 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4262 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4263 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4265 size
= num_wraps
? capacity
: next_entry
;
4267 /* bail out if nothing in log */
4269 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4270 iwl_release_nic_access(priv
);
4274 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4277 /* if uCode has wrapped back to top of log, start at the oldest entry,
4278 * i.e the next one that uCode would fill. */
4280 iwl4965_print_event_log(priv
, next_entry
,
4281 capacity
- next_entry
, mode
);
4283 /* (then/else) start at top of log */
4284 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
4286 iwl_release_nic_access(priv
);
4290 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4292 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
4294 /* Set the FW error flag -- cleared on iwl4965_down */
4295 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4297 /* Cancel currently queued command. */
4298 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4300 #ifdef CONFIG_IWLWIFI_DEBUG
4301 if (iwl_debug_level
& IWL_DL_FW_ERRORS
) {
4302 iwl4965_dump_nic_error_log(priv
);
4303 iwl4965_dump_nic_event_log(priv
);
4304 iwl4965_print_rx_config_cmd(&priv
->staging_rxon
);
4308 wake_up_interruptible(&priv
->wait_command_queue
);
4310 /* Keep the restart process from trying to send host
4311 * commands by clearing the INIT status bit */
4312 clear_bit(STATUS_READY
, &priv
->status
);
4314 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4315 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4316 "Restarting adapter due to uCode error.\n");
4318 if (iwl_is_associated(priv
)) {
4319 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4320 sizeof(priv
->recovery_rxon
));
4321 priv
->error_recovering
= 1;
4323 queue_work(priv
->workqueue
, &priv
->restart
);
4327 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
4329 unsigned long flags
;
4331 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4332 sizeof(priv
->staging_rxon
));
4333 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4334 iwl4965_commit_rxon(priv
);
4336 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
4338 spin_lock_irqsave(&priv
->lock
, flags
);
4339 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4340 priv
->error_recovering
= 0;
4341 spin_unlock_irqrestore(&priv
->lock
, flags
);
4344 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
4346 u32 inta
, handled
= 0;
4348 unsigned long flags
;
4349 #ifdef CONFIG_IWLWIFI_DEBUG
4353 spin_lock_irqsave(&priv
->lock
, flags
);
4355 /* Ack/clear/reset pending uCode interrupts.
4356 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4357 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4358 inta
= iwl_read32(priv
, CSR_INT
);
4359 iwl_write32(priv
, CSR_INT
, inta
);
4361 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4362 * Any new interrupts that happen after this, either while we're
4363 * in this tasklet, or later, will show up in next ISR/tasklet. */
4364 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4365 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4367 #ifdef CONFIG_IWLWIFI_DEBUG
4368 if (iwl_debug_level
& IWL_DL_ISR
) {
4369 /* just for debug */
4370 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4371 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4372 inta
, inta_mask
, inta_fh
);
4376 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4377 * atomic, make sure that inta covers all the interrupts that
4378 * we've discovered, even if FH interrupt came in just after
4379 * reading CSR_INT. */
4380 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
4381 inta
|= CSR_INT_BIT_FH_RX
;
4382 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
4383 inta
|= CSR_INT_BIT_FH_TX
;
4385 /* Now service all interrupt bits discovered above. */
4386 if (inta
& CSR_INT_BIT_HW_ERR
) {
4387 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4389 /* Tell the device to stop sending interrupts */
4390 iwl4965_disable_interrupts(priv
);
4392 iwl4965_irq_handle_error(priv
);
4394 handled
|= CSR_INT_BIT_HW_ERR
;
4396 spin_unlock_irqrestore(&priv
->lock
, flags
);
4401 #ifdef CONFIG_IWLWIFI_DEBUG
4402 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4403 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4404 if (inta
& CSR_INT_BIT_SCD
)
4405 IWL_DEBUG_ISR("Scheduler finished to transmit "
4406 "the frame/frames.\n");
4408 /* Alive notification via Rx interrupt will do the real work */
4409 if (inta
& CSR_INT_BIT_ALIVE
)
4410 IWL_DEBUG_ISR("Alive interrupt\n");
4413 /* Safely ignore these bits for debug checks below */
4414 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4416 /* HW RF KILL switch toggled */
4417 if (inta
& CSR_INT_BIT_RF_KILL
) {
4419 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
4420 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4423 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4424 "RF_KILL bit toggled to %s.\n",
4425 hw_rf_kill
? "disable radio":"enable radio");
4427 /* Queue restart only if RF_KILL switch was set to "kill"
4428 * when we loaded driver, and is now set to "enable".
4429 * After we're Alive, RF_KILL gets handled by
4430 * iwl4965_rx_card_state_notif() */
4431 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4432 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4433 queue_work(priv
->workqueue
, &priv
->restart
);
4436 handled
|= CSR_INT_BIT_RF_KILL
;
4439 /* Chip got too hot and stopped itself */
4440 if (inta
& CSR_INT_BIT_CT_KILL
) {
4441 IWL_ERROR("Microcode CT kill error detected.\n");
4442 handled
|= CSR_INT_BIT_CT_KILL
;
4445 /* Error detected by uCode */
4446 if (inta
& CSR_INT_BIT_SW_ERR
) {
4447 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4449 iwl4965_irq_handle_error(priv
);
4450 handled
|= CSR_INT_BIT_SW_ERR
;
4453 /* uCode wakes up after power-down sleep */
4454 if (inta
& CSR_INT_BIT_WAKEUP
) {
4455 IWL_DEBUG_ISR("Wakeup interrupt\n");
4456 iwl4965_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4457 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4458 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4459 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4460 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4461 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4462 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4464 handled
|= CSR_INT_BIT_WAKEUP
;
4467 /* All uCode command responses, including Tx command responses,
4468 * Rx "responses" (frame-received notification), and other
4469 * notifications from uCode come through here*/
4470 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4471 iwl4965_rx_handle(priv
);
4472 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4475 if (inta
& CSR_INT_BIT_FH_TX
) {
4476 IWL_DEBUG_ISR("Tx interrupt\n");
4477 handled
|= CSR_INT_BIT_FH_TX
;
4480 if (inta
& ~handled
)
4481 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4483 if (inta
& ~CSR_INI_SET_MASK
) {
4484 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4485 inta
& ~CSR_INI_SET_MASK
);
4486 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4489 /* Re-enable all interrupts */
4490 /* only Re-enable if diabled by irq */
4491 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4492 iwl4965_enable_interrupts(priv
);
4494 #ifdef CONFIG_IWLWIFI_DEBUG
4495 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4496 inta
= iwl_read32(priv
, CSR_INT
);
4497 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4498 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4499 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4500 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4503 spin_unlock_irqrestore(&priv
->lock
, flags
);
4506 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
4508 struct iwl_priv
*priv
= data
;
4509 u32 inta
, inta_mask
;
4514 spin_lock(&priv
->lock
);
4516 /* Disable (but don't clear!) interrupts here to avoid
4517 * back-to-back ISRs and sporadic interrupts from our NIC.
4518 * If we have something to service, the tasklet will re-enable ints.
4519 * If we *don't* have something, we'll re-enable before leaving here. */
4520 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4521 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4523 /* Discover which interrupts are active/pending */
4524 inta
= iwl_read32(priv
, CSR_INT
);
4525 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4527 /* Ignore interrupt if there's nothing in NIC to service.
4528 * This may be due to IRQ shared with another device,
4529 * or due to sporadic interrupts thrown from our NIC. */
4530 if (!inta
&& !inta_fh
) {
4531 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4535 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4536 /* Hardware disappeared. It might have already raised
4538 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4542 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4543 inta
, inta_mask
, inta_fh
);
4545 inta
&= ~CSR_INT_BIT_SCD
;
4547 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4548 if (likely(inta
|| inta_fh
))
4549 tasklet_schedule(&priv
->irq_tasklet
);
4552 spin_unlock(&priv
->lock
);
4556 /* re-enable interrupts here since we don't have anything to service. */
4557 /* only Re-enable if diabled by irq */
4558 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4559 iwl4965_enable_interrupts(priv
);
4560 spin_unlock(&priv
->lock
);
4564 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4565 * sending probe req. This should be set long enough to hear probe responses
4566 * from more than one AP. */
4567 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4568 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4570 /* For faster active scanning, scan will move to the next channel if fewer than
4571 * PLCP_QUIET_THRESH packets are heard on this channel within
4572 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4573 * time if it's a quiet channel (nothing responded to our probe, and there's
4574 * no other traffic).
4575 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4576 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4577 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4579 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4580 * Must be set longer than active dwell time.
4581 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4582 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4583 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4584 #define IWL_PASSIVE_DWELL_BASE (100)
4585 #define IWL_CHANNEL_TUNE_TIME 5
4587 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
4588 enum ieee80211_band band
)
4590 if (band
== IEEE80211_BAND_5GHZ
)
4591 return IWL_ACTIVE_DWELL_TIME_52
;
4593 return IWL_ACTIVE_DWELL_TIME_24
;
4596 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
4597 enum ieee80211_band band
)
4599 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
4600 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
4601 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4602 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4604 if (iwl_is_associated(priv
)) {
4605 /* If we're associated, we clamp the maximum passive
4606 * dwell time to be 98% of the beacon interval (minus
4607 * 2 * channel tune time) */
4608 passive
= priv
->beacon_int
;
4609 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4610 passive
= IWL_PASSIVE_DWELL_BASE
;
4611 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4614 if (passive
<= active
)
4615 passive
= active
+ 1;
4620 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
4621 enum ieee80211_band band
,
4622 u8 is_active
, u8 direct_mask
,
4623 struct iwl4965_scan_channel
*scan_ch
)
4625 const struct ieee80211_channel
*channels
= NULL
;
4626 const struct ieee80211_supported_band
*sband
;
4627 const struct iwl_channel_info
*ch_info
;
4628 u16 passive_dwell
= 0;
4629 u16 active_dwell
= 0;
4632 sband
= iwl4965_get_hw_mode(priv
, band
);
4636 channels
= sband
->channels
;
4638 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
4639 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
4641 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4642 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
4645 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
4647 ch_info
= iwl_get_channel_info(priv
, band
, scan_ch
->channel
);
4648 if (!is_channel_valid(ch_info
)) {
4649 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
4654 if (!is_active
|| is_channel_passive(ch_info
) ||
4655 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
4656 scan_ch
->type
= 0; /* passive */
4658 scan_ch
->type
= 1; /* active */
4660 if (scan_ch
->type
& 1)
4661 scan_ch
->type
|= (direct_mask
<< 1);
4663 if (is_channel_narrow(ch_info
))
4664 scan_ch
->type
|= (1 << 7);
4666 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4667 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4669 /* Set txpower levels to defaults */
4670 scan_ch
->tpc
.dsp_atten
= 110;
4671 /* scan_pwr_info->tpc.dsp_atten; */
4673 /*scan_pwr_info->tpc.tx_gain; */
4674 if (band
== IEEE80211_BAND_5GHZ
)
4675 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4677 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4678 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4680 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4684 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4686 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4687 (scan_ch
->type
& 1) ?
4688 active_dwell
: passive_dwell
);
4694 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4698 static void iwl4965_init_hw_rates(struct iwl_priv
*priv
,
4699 struct ieee80211_rate
*rates
)
4703 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
4704 rates
[i
].bitrate
= iwl4965_rates
[i
].ieee
* 5;
4705 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
4706 rates
[i
].hw_value_short
= i
;
4708 if ((i
> IWL_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
4710 * If CCK != 1M then set short preamble rate flag.
4713 (iwl4965_rates
[i
].plcp
== IWL_RATE_1M_PLCP
) ?
4714 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
4720 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4722 int iwl4965_init_geos(struct iwl_priv
*priv
)
4724 struct iwl_channel_info
*ch
;
4725 struct ieee80211_supported_band
*sband
;
4726 struct ieee80211_channel
*channels
;
4727 struct ieee80211_channel
*geo_ch
;
4728 struct ieee80211_rate
*rates
;
4731 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
4732 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
4733 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4734 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4738 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
4739 priv
->channel_count
, GFP_KERNEL
);
4743 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
4750 /* 5.2GHz channels start after the 2.4GHz channels */
4751 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4752 sband
->channels
= &channels
[ARRAY_SIZE(iwl_eeprom_band_1
)];
4754 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
4755 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
4757 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_5GHZ
);
4759 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4760 sband
->channels
= channels
;
4762 sband
->bitrates
= rates
;
4763 sband
->n_bitrates
= IWL_RATE_COUNT
;
4765 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_2GHZ
);
4767 priv
->ieee_channels
= channels
;
4768 priv
->ieee_rates
= rates
;
4770 iwl4965_init_hw_rates(priv
, rates
);
4772 for (i
= 0; i
< priv
->channel_count
; i
++) {
4773 ch
= &priv
->channel_info
[i
];
4775 /* FIXME: might be removed if scan is OK */
4776 if (!is_channel_valid(ch
))
4779 if (is_channel_a_band(ch
))
4780 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4782 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4784 geo_ch
= &sband
->channels
[sband
->n_channels
++];
4786 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
4787 geo_ch
->max_power
= ch
->max_power_avg
;
4788 geo_ch
->max_antenna_gain
= 0xff;
4789 geo_ch
->hw_value
= ch
->channel
;
4791 if (is_channel_valid(ch
)) {
4792 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
4793 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
4795 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
4796 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
4798 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
4799 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
4801 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
4802 priv
->max_channel_txpower_limit
=
4805 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
4808 /* Save flags for reg domain usage */
4809 geo_ch
->orig_flags
= geo_ch
->flags
;
4811 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4812 ch
->channel
, geo_ch
->center_freq
,
4813 is_channel_a_band(ch
) ? "5.2" : "2.4",
4814 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
4815 "restricted" : "valid",
4819 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
4820 priv
->cfg
->sku
& IWL_SKU_A
) {
4821 printk(KERN_INFO DRV_NAME
4822 ": Incorrectly detected BG card as ABG. Please send "
4823 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
4824 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
4825 priv
->cfg
->sku
&= ~IWL_SKU_A
;
4828 printk(KERN_INFO DRV_NAME
4829 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4830 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
4831 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
4833 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
4834 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
4835 &priv
->bands
[IEEE80211_BAND_2GHZ
];
4836 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
4837 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
4838 &priv
->bands
[IEEE80211_BAND_5GHZ
];
4840 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4846 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
4848 void iwl4965_free_geos(struct iwl_priv
*priv
)
4850 kfree(priv
->ieee_channels
);
4851 kfree(priv
->ieee_rates
);
4852 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4855 /******************************************************************************
4857 * uCode download functions
4859 ******************************************************************************/
4861 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
4863 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4864 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4865 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4866 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4867 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4868 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4872 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
4873 * looking at all data.
4875 static int iwl4965_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
,
4883 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4885 rc
= iwl_grab_nic_access(priv
);
4889 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
4892 for (; len
> 0; len
-= sizeof(u32
), image
++) {
4893 /* read data comes through single port, auto-incr addr */
4894 /* NOTE: Use the debugless read so we don't flood kernel log
4895 * if IWL_DL_IO is set */
4896 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
4897 if (val
!= le32_to_cpu(*image
)) {
4898 IWL_ERROR("uCode INST section is invalid at "
4899 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4900 save_len
- len
, val
, le32_to_cpu(*image
));
4908 iwl_release_nic_access(priv
);
4912 ("ucode image in INSTRUCTION memory is good\n");
4919 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
4920 * using sample data 100 bytes apart. If these sample points are good,
4921 * it's a pretty good bet that everything between them is good, too.
4923 static int iwl4965_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
4930 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4932 rc
= iwl_grab_nic_access(priv
);
4936 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
4937 /* read data comes through single port, auto-incr addr */
4938 /* NOTE: Use the debugless read so we don't flood kernel log
4939 * if IWL_DL_IO is set */
4940 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
4941 i
+ RTC_INST_LOWER_BOUND
);
4942 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
4943 if (val
!= le32_to_cpu(*image
)) {
4944 #if 0 /* Enable this if you want to see details */
4945 IWL_ERROR("uCode INST section is invalid at "
4946 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4956 iwl_release_nic_access(priv
);
4963 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
4964 * and verify its contents
4966 static int iwl4965_verify_ucode(struct iwl_priv
*priv
)
4973 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
4974 len
= priv
->ucode_boot
.len
;
4975 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
4977 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
4981 /* Try initialize */
4982 image
= (__le32
*)priv
->ucode_init
.v_addr
;
4983 len
= priv
->ucode_init
.len
;
4984 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
4986 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
4990 /* Try runtime/protocol */
4991 image
= (__le32
*)priv
->ucode_code
.v_addr
;
4992 len
= priv
->ucode_code
.len
;
4993 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
4995 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
4999 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5001 /* Since nothing seems to match, show first several data entries in
5002 * instruction SRAM, so maybe visual inspection will give a clue.
5003 * Selection of bootstrap image (vs. other images) is arbitrary. */
5004 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5005 len
= priv
->ucode_boot
.len
;
5006 rc
= iwl4965_verify_inst_full(priv
, image
, len
);
5011 static void iwl4965_nic_start(struct iwl_priv
*priv
)
5013 /* Remove all resets to allow NIC to operate */
5014 iwl_write32(priv
, CSR_RESET
, 0);
5019 * iwl4965_read_ucode - Read uCode images from disk file.
5021 * Copy into buffers for card to fetch via bus-mastering
5023 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
5025 struct iwl4965_ucode
*ucode
;
5027 const struct firmware
*ucode_raw
;
5028 const char *name
= priv
->cfg
->fw_name
;
5031 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5033 /* Ask kernel firmware_class module to get the boot firmware off disk.
5034 * request_firmware() is synchronous, file is in memory on return. */
5035 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5037 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5042 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5043 name
, ucode_raw
->size
);
5045 /* Make sure that we got at least our header! */
5046 if (ucode_raw
->size
< sizeof(*ucode
)) {
5047 IWL_ERROR("File size way too small!\n");
5052 /* Data from ucode file: header followed by uCode images */
5053 ucode
= (void *)ucode_raw
->data
;
5055 ver
= le32_to_cpu(ucode
->ver
);
5056 inst_size
= le32_to_cpu(ucode
->inst_size
);
5057 data_size
= le32_to_cpu(ucode
->data_size
);
5058 init_size
= le32_to_cpu(ucode
->init_size
);
5059 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5060 boot_size
= le32_to_cpu(ucode
->boot_size
);
5062 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5063 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5065 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5067 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5069 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5071 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5074 /* Verify size of file vs. image size info in file's header */
5075 if (ucode_raw
->size
< sizeof(*ucode
) +
5076 inst_size
+ data_size
+ init_size
+
5077 init_data_size
+ boot_size
) {
5079 IWL_DEBUG_INFO("uCode file size %d too small\n",
5080 (int)ucode_raw
->size
);
5085 /* Verify that uCode images will fit in card's SRAM */
5086 if (inst_size
> IWL_MAX_INST_SIZE
) {
5087 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5093 if (data_size
> IWL_MAX_DATA_SIZE
) {
5094 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5099 if (init_size
> IWL_MAX_INST_SIZE
) {
5101 ("uCode init instr len %d too large to fit in\n",
5106 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5108 ("uCode init data len %d too large to fit in\n",
5113 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5115 ("uCode boot instr len %d too large to fit in\n",
5121 /* Allocate ucode buffers for card's bus-master loading ... */
5123 /* Runtime instructions and 2 copies of data:
5124 * 1) unmodified from disk
5125 * 2) backup cache for save/restore during power-downs */
5126 priv
->ucode_code
.len
= inst_size
;
5127 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5129 priv
->ucode_data
.len
= data_size
;
5130 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5132 priv
->ucode_data_backup
.len
= data_size
;
5133 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5135 /* Initialization instructions and data */
5136 if (init_size
&& init_data_size
) {
5137 priv
->ucode_init
.len
= init_size
;
5138 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5140 priv
->ucode_init_data
.len
= init_data_size
;
5141 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5143 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5147 /* Bootstrap (instructions only, no data) */
5149 priv
->ucode_boot
.len
= boot_size
;
5150 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5152 if (!priv
->ucode_boot
.v_addr
)
5156 /* Copy images into buffers for card's bus-master reads ... */
5158 /* Runtime instructions (first block of data in file) */
5159 src
= &ucode
->data
[0];
5160 len
= priv
->ucode_code
.len
;
5161 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5162 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5163 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5164 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5166 /* Runtime data (2nd block)
5167 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
5168 src
= &ucode
->data
[inst_size
];
5169 len
= priv
->ucode_data
.len
;
5170 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5171 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5172 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5174 /* Initialization instructions (3rd block) */
5176 src
= &ucode
->data
[inst_size
+ data_size
];
5177 len
= priv
->ucode_init
.len
;
5178 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5180 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5183 /* Initialization data (4th block) */
5184 if (init_data_size
) {
5185 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5186 len
= priv
->ucode_init_data
.len
;
5187 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5189 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5192 /* Bootstrap instructions (5th block) */
5193 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5194 len
= priv
->ucode_boot
.len
;
5195 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
5196 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5198 /* We have our copies now, allow OS release its copies */
5199 release_firmware(ucode_raw
);
5203 IWL_ERROR("failed to allocate pci memory\n");
5205 iwl4965_dealloc_ucode_pci(priv
);
5208 release_firmware(ucode_raw
);
5216 * iwl4965_set_ucode_ptrs - Set uCode address location
5218 * Tell initialization uCode where to find runtime uCode.
5220 * BSM registers initially contain pointers to initialization uCode.
5221 * We need to replace them to load runtime uCode inst and data,
5222 * and to save runtime data when powering down.
5224 static int iwl4965_set_ucode_ptrs(struct iwl_priv
*priv
)
5229 unsigned long flags
;
5231 /* bits 35:4 for 4965 */
5232 pinst
= priv
->ucode_code
.p_addr
>> 4;
5233 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
5235 spin_lock_irqsave(&priv
->lock
, flags
);
5236 rc
= iwl_grab_nic_access(priv
);
5238 spin_unlock_irqrestore(&priv
->lock
, flags
);
5242 /* Tell bootstrap uCode where to find image to load */
5243 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5244 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5245 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5246 priv
->ucode_data
.len
);
5248 /* Inst bytecount must be last to set up, bit 31 signals uCode
5249 * that all new ptr/size info is in place */
5250 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5251 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5253 iwl_release_nic_access(priv
);
5255 spin_unlock_irqrestore(&priv
->lock
, flags
);
5257 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5263 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
5265 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5267 * The 4965 "initialize" ALIVE reply contains calibration data for:
5268 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5269 * (3945 does not contain this data).
5271 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5273 static void iwl4965_init_alive_start(struct iwl_priv
*priv
)
5275 /* Check alive response for "valid" sign from uCode */
5276 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5277 /* We had an error bringing up the hardware, so take it
5278 * all the way back down so we can try again */
5279 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5283 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5284 * This is a paranoid check, because we would not have gotten the
5285 * "initialize" alive if code weren't properly loaded. */
5286 if (iwl4965_verify_ucode(priv
)) {
5287 /* Runtime instruction load was bad;
5288 * take it all the way back down so we can try again */
5289 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5293 /* Calculate temperature */
5294 priv
->temperature
= iwl4965_get_temperature(priv
);
5296 /* Send pointers to protocol/runtime uCode image ... init code will
5297 * load and launch runtime uCode, which will send us another "Alive"
5299 IWL_DEBUG_INFO("Initialization Alive received.\n");
5300 if (iwl4965_set_ucode_ptrs(priv
)) {
5301 /* Runtime instruction load won't happen;
5302 * take it all the way back down so we can try again */
5303 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5309 queue_work(priv
->workqueue
, &priv
->restart
);
5314 * iwl4965_alive_start - called after REPLY_ALIVE notification received
5315 * from protocol/runtime uCode (initialization uCode's
5316 * Alive gets handled by iwl4965_init_alive_start()).
5318 static void iwl4965_alive_start(struct iwl_priv
*priv
)
5322 IWL_DEBUG_INFO("Runtime Alive received.\n");
5324 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5325 /* We had an error bringing up the hardware, so take it
5326 * all the way back down so we can try again */
5327 IWL_DEBUG_INFO("Alive failed.\n");
5331 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5332 * This is a paranoid check, because we would not have gotten the
5333 * "runtime" alive if code weren't properly loaded. */
5334 if (iwl4965_verify_ucode(priv
)) {
5335 /* Runtime instruction load was bad;
5336 * take it all the way back down so we can try again */
5337 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5341 iwlcore_clear_stations_table(priv
);
5343 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
5345 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5350 /* After the ALIVE response, we can send host commands to 4965 uCode */
5351 set_bit(STATUS_ALIVE
, &priv
->status
);
5353 /* Clear out the uCode error bit if it is set */
5354 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5356 if (iwl_is_rfkill(priv
))
5359 ieee80211_start_queues(priv
->hw
);
5361 priv
->active_rate
= priv
->rates_mask
;
5362 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5364 iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5366 if (iwl_is_associated(priv
)) {
5367 struct iwl4965_rxon_cmd
*active_rxon
=
5368 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
5370 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
5371 sizeof(priv
->staging_rxon
));
5372 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5374 /* Initialize our rx_config data */
5375 iwl4965_connection_init_rx_config(priv
);
5376 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5379 /* Configure Bluetooth device coexistence support */
5380 iwl4965_send_bt_config(priv
);
5382 /* Configure the adapter for unassociated operation */
5383 iwl4965_commit_rxon(priv
);
5385 /* At this point, the NIC is initialized and operational */
5386 priv
->notif_missed_beacons
= 0;
5388 iwl4965_rf_kill_ct_config(priv
);
5390 iwl_leds_register(priv
);
5392 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5393 set_bit(STATUS_READY
, &priv
->status
);
5394 wake_up_interruptible(&priv
->wait_command_queue
);
5396 if (priv
->error_recovering
)
5397 iwl4965_error_recovery(priv
);
5399 iwlcore_low_level_notify(priv
, IWLCORE_START_EVT
);
5400 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
5404 queue_work(priv
->workqueue
, &priv
->restart
);
5407 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
5409 static void __iwl4965_down(struct iwl_priv
*priv
)
5411 unsigned long flags
;
5412 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5413 struct ieee80211_conf
*conf
= NULL
;
5415 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
5417 conf
= ieee80211_get_hw_conf(priv
->hw
);
5420 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5422 iwl_leds_unregister(priv
);
5424 iwlcore_low_level_notify(priv
, IWLCORE_STOP_EVT
);
5426 iwlcore_clear_stations_table(priv
);
5428 /* Unblock any waiting calls */
5429 wake_up_interruptible_all(&priv
->wait_command_queue
);
5431 /* Wipe out the EXIT_PENDING status bit if we are not actually
5432 * exiting the module */
5434 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5436 /* stop and reset the on-board processor */
5437 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
5439 /* tell the device to stop sending interrupts */
5440 spin_lock_irqsave(&priv
->lock
, flags
);
5441 iwl4965_disable_interrupts(priv
);
5442 spin_unlock_irqrestore(&priv
->lock
, flags
);
5443 iwl_synchronize_irq(priv
);
5445 if (priv
->mac80211_registered
)
5446 ieee80211_stop_queues(priv
->hw
);
5448 /* If we have not previously called iwl4965_init() then
5449 * clear all bits but the RF Kill and SUSPEND bits and return */
5450 if (!iwl_is_init(priv
)) {
5451 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5453 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5455 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5456 STATUS_GEO_CONFIGURED
|
5457 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5462 /* ...otherwise clear out all the status bits but the RF Kill and
5463 * SUSPEND bits and continue taking the NIC down. */
5464 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5466 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5468 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5469 STATUS_GEO_CONFIGURED
|
5470 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5472 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
5475 spin_lock_irqsave(&priv
->lock
, flags
);
5476 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
5477 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
5478 spin_unlock_irqrestore(&priv
->lock
, flags
);
5480 iwl4965_hw_txq_ctx_stop(priv
);
5481 iwl4965_hw_rxq_stop(priv
);
5483 spin_lock_irqsave(&priv
->lock
, flags
);
5484 if (!iwl_grab_nic_access(priv
)) {
5485 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
5486 APMG_CLK_VAL_DMA_CLK_RQT
);
5487 iwl_release_nic_access(priv
);
5489 spin_unlock_irqrestore(&priv
->lock
, flags
);
5493 iwl4965_hw_nic_stop_master(priv
);
5494 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
5495 iwl4965_hw_nic_reset(priv
);
5498 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
5500 if (priv
->ibss_beacon
)
5501 dev_kfree_skb(priv
->ibss_beacon
);
5502 priv
->ibss_beacon
= NULL
;
5504 /* clear out any free frames */
5505 iwl4965_clear_free_frames(priv
);
5508 static void iwl4965_down(struct iwl_priv
*priv
)
5510 mutex_lock(&priv
->mutex
);
5511 __iwl4965_down(priv
);
5512 mutex_unlock(&priv
->mutex
);
5514 iwl4965_cancel_deferred_work(priv
);
5517 #define MAX_HW_RESTARTS 5
5519 static int __iwl4965_up(struct iwl_priv
*priv
)
5524 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5525 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5529 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5530 IWL_WARNING("Radio disabled by SW RF kill (module "
5532 iwl_rfkill_set_hw_state(priv
);
5536 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5537 IWL_ERROR("ucode not available for device bringup\n");
5541 /* If platform's RF_KILL switch is NOT set to KILL */
5542 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
5543 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5544 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5546 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5547 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5548 iwl_rfkill_set_hw_state(priv
);
5549 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5554 iwl_rfkill_set_hw_state(priv
);
5555 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5557 ret
= priv
->cfg
->ops
->lib
->hw_nic_init(priv
);
5559 IWL_ERROR("Unable to init nic\n");
5563 /* make sure rfkill handshake bits are cleared */
5564 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5565 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5566 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5568 /* clear (again), then enable host interrupts */
5569 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5570 iwl4965_enable_interrupts(priv
);
5572 /* really make sure rfkill handshake bits are cleared */
5573 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5574 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5576 /* Copy original ucode data image from disk into backup cache.
5577 * This will be used to initialize the on-board processor's
5578 * data SRAM for a clean start when the runtime program first loads. */
5579 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5580 priv
->ucode_data
.len
);
5582 /* We return success when we resume from suspend and rf_kill is on. */
5583 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5586 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5588 iwlcore_clear_stations_table(priv
);
5590 /* load bootstrap state machine,
5591 * load bootstrap program into processor's memory,
5592 * prepare to load the "initialize" uCode */
5593 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
5596 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
5600 /* start card; "initialize" will load runtime ucode */
5601 iwl4965_nic_start(priv
);
5603 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5608 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5609 __iwl4965_down(priv
);
5611 /* tried to restart and config the device for as long as our
5612 * patience could withstand */
5613 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
5618 /*****************************************************************************
5620 * Workqueue callbacks
5622 *****************************************************************************/
5624 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
5626 struct iwl_priv
*priv
=
5627 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
5629 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5632 mutex_lock(&priv
->mutex
);
5633 iwl4965_init_alive_start(priv
);
5634 mutex_unlock(&priv
->mutex
);
5637 static void iwl4965_bg_alive_start(struct work_struct
*data
)
5639 struct iwl_priv
*priv
=
5640 container_of(data
, struct iwl_priv
, alive_start
.work
);
5642 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5645 mutex_lock(&priv
->mutex
);
5646 iwl4965_alive_start(priv
);
5647 mutex_unlock(&priv
->mutex
);
5650 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
5652 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
5654 wake_up_interruptible(&priv
->wait_command_queue
);
5656 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5659 mutex_lock(&priv
->mutex
);
5661 if (!iwl_is_rfkill(priv
)) {
5662 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
5663 "HW and/or SW RF Kill no longer active, restarting "
5665 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5666 queue_work(priv
->workqueue
, &priv
->restart
);
5668 /* make sure mac80211 stop sending Tx frame */
5669 if (priv
->mac80211_registered
)
5670 ieee80211_stop_queues(priv
->hw
);
5672 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5673 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5674 "disabled by SW switch\n");
5676 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5677 "Kill switch must be turned off for "
5678 "wireless networking to work.\n");
5680 iwl_rfkill_set_hw_state(priv
);
5682 mutex_unlock(&priv
->mutex
);
5685 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5687 static void iwl4965_bg_scan_check(struct work_struct
*data
)
5689 struct iwl_priv
*priv
=
5690 container_of(data
, struct iwl_priv
, scan_check
.work
);
5692 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5695 mutex_lock(&priv
->mutex
);
5696 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
5697 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5698 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
5699 "Scan completion watchdog resetting adapter (%dms)\n",
5700 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
5702 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5703 iwl4965_send_scan_abort(priv
);
5705 mutex_unlock(&priv
->mutex
);
5708 static void iwl4965_bg_request_scan(struct work_struct
*data
)
5710 struct iwl_priv
*priv
=
5711 container_of(data
, struct iwl_priv
, request_scan
);
5712 struct iwl_host_cmd cmd
= {
5713 .id
= REPLY_SCAN_CMD
,
5714 .len
= sizeof(struct iwl4965_scan_cmd
),
5715 .meta
.flags
= CMD_SIZE_HUGE
,
5717 struct iwl4965_scan_cmd
*scan
;
5718 struct ieee80211_conf
*conf
= NULL
;
5720 enum ieee80211_band band
;
5724 conf
= ieee80211_get_hw_conf(priv
->hw
);
5726 mutex_lock(&priv
->mutex
);
5728 if (!iwl_is_ready(priv
)) {
5729 IWL_WARNING("request scan called when driver not ready.\n");
5733 /* Make sure the scan wasn't cancelled before this queued work
5734 * was given the chance to run... */
5735 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
5738 /* This should never be called or scheduled if there is currently
5739 * a scan active in the hardware. */
5740 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
5741 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5742 "Ignoring second request.\n");
5747 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5748 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5752 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5753 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5757 if (iwl_is_rfkill(priv
)) {
5758 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5762 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5763 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5767 if (!priv
->scan_bands
) {
5768 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5773 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
5774 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
5781 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
5783 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
5784 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
5786 if (iwl_is_associated(priv
)) {
5789 u32 suspend_time
= 100;
5790 u32 scan_suspend_time
= 100;
5791 unsigned long flags
;
5793 IWL_DEBUG_INFO("Scanning while associated...\n");
5795 spin_lock_irqsave(&priv
->lock
, flags
);
5796 interval
= priv
->beacon_int
;
5797 spin_unlock_irqrestore(&priv
->lock
, flags
);
5799 scan
->suspend_time
= 0;
5800 scan
->max_out_time
= cpu_to_le32(200 * 1024);
5802 interval
= suspend_time
;
5804 extra
= (suspend_time
/ interval
) << 22;
5805 scan_suspend_time
= (extra
|
5806 ((suspend_time
% interval
) * 1024));
5807 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
5808 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5809 scan_suspend_time
, interval
);
5812 /* We should add the ability for user to lock to PASSIVE ONLY */
5813 if (priv
->one_direct_scan
) {
5815 ("Kicking off one direct scan for '%s'\n",
5816 iwl4965_escape_essid(priv
->direct_ssid
,
5817 priv
->direct_ssid_len
));
5818 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5819 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
5820 memcpy(scan
->direct_scan
[0].ssid
,
5821 priv
->direct_ssid
, priv
->direct_ssid_len
);
5823 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
5825 ("Kicking off one direct scan for '%s' when not associated\n",
5826 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
5827 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5828 scan
->direct_scan
[0].len
= priv
->essid_len
;
5829 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
5832 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
5836 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
5837 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
5838 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
5841 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
5842 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
5843 scan
->tx_cmd
.rate_n_flags
=
5844 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
5845 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
5847 scan
->good_CRC_th
= 0;
5848 band
= IEEE80211_BAND_2GHZ
;
5849 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
5850 scan
->tx_cmd
.rate_n_flags
=
5851 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
5852 RATE_MCS_ANT_B_MSK
);
5853 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
5854 band
= IEEE80211_BAND_5GHZ
;
5856 IWL_WARNING("Invalid scan band count\n");
5860 /* We don't build a direct scan probe request; the uCode will do
5861 * that based on the direct_mask added to each channel entry */
5862 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
5863 (struct ieee80211_mgmt
*)scan
->data
,
5864 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
5866 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
5867 /* select Rx chains */
5869 /* Force use of chains B and C (0x6) for scan Rx.
5870 * Avoid A (0x1) because of its off-channel reception on A-band.
5871 * MIMO is not used here, but value is required to make uCode happy. */
5872 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
5873 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
5874 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
5875 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
5877 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
5878 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
5881 scan
->channel_count
=
5882 iwl4965_get_channels_for_scan(
5883 priv
, band
, 1, /* active */
5885 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5887 scan
->channel_count
=
5888 iwl4965_get_channels_for_scan(
5889 priv
, band
, 0, /* passive */
5891 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5893 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
5894 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
5896 scan
->len
= cpu_to_le16(cmd
.len
);
5898 set_bit(STATUS_SCAN_HW
, &priv
->status
);
5899 ret
= iwl_send_cmd_sync(priv
, &cmd
);
5903 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
5904 IWL_SCAN_CHECK_WATCHDOG
);
5906 mutex_unlock(&priv
->mutex
);
5910 /* inform mac80211 scan aborted */
5911 queue_work(priv
->workqueue
, &priv
->scan_completed
);
5912 mutex_unlock(&priv
->mutex
);
5915 static void iwl4965_bg_up(struct work_struct
*data
)
5917 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
5919 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5922 mutex_lock(&priv
->mutex
);
5924 mutex_unlock(&priv
->mutex
);
5927 static void iwl4965_bg_restart(struct work_struct
*data
)
5929 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
5931 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5935 queue_work(priv
->workqueue
, &priv
->up
);
5938 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
5940 struct iwl_priv
*priv
=
5941 container_of(data
, struct iwl_priv
, rx_replenish
);
5943 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5946 mutex_lock(&priv
->mutex
);
5947 iwl4965_rx_replenish(priv
);
5948 mutex_unlock(&priv
->mutex
);
5951 #define IWL_DELAY_NEXT_SCAN (HZ*2)
5953 static void iwl4965_post_associate(struct iwl_priv
*priv
)
5955 struct ieee80211_conf
*conf
= NULL
;
5957 DECLARE_MAC_BUF(mac
);
5959 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
5960 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
5964 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
5966 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
5969 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5973 if (!priv
->vif
|| !priv
->is_open
)
5976 iwl4965_scan_cancel_timeout(priv
, 200);
5978 conf
= ieee80211_get_hw_conf(priv
->hw
);
5980 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5981 iwl4965_commit_rxon(priv
);
5983 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
5984 iwl4965_setup_rxon_timing(priv
);
5985 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
5986 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
5988 IWL_WARNING("REPLY_RXON_TIMING failed - "
5989 "Attempting to continue.\n");
5991 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
5993 #ifdef CONFIG_IWL4965_HT
5994 if (priv
->current_ht_config
.is_ht
)
5995 iwl4965_set_rxon_ht(priv
, &priv
->current_ht_config
);
5996 #endif /* CONFIG_IWL4965_HT*/
5997 iwl4965_set_rxon_chain(priv
);
5998 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6000 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6001 priv
->assoc_id
, priv
->beacon_int
);
6003 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6004 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6006 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6008 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6009 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6010 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6012 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6014 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6015 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6019 iwl4965_commit_rxon(priv
);
6021 switch (priv
->iw_mode
) {
6022 case IEEE80211_IF_TYPE_STA
:
6023 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6026 case IEEE80211_IF_TYPE_IBSS
:
6028 /* clear out the station table */
6029 iwlcore_clear_stations_table(priv
);
6031 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6032 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
6033 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6034 iwl4965_send_beacon_cmd(priv
);
6039 IWL_ERROR("%s Should not be called in %d mode\n",
6040 __FUNCTION__
, priv
->iw_mode
);
6044 iwl4965_sequence_reset(priv
);
6046 #ifdef CONFIG_IWL4965_SENSITIVITY
6047 /* Enable Rx differential gain and sensitivity calibrations */
6048 iwl4965_chain_noise_reset(priv
);
6049 priv
->start_calib
= 1;
6050 #endif /* CONFIG_IWL4965_SENSITIVITY */
6052 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6053 priv
->assoc_station_added
= 1;
6055 iwl4965_activate_qos(priv
, 0);
6057 /* we have just associated, don't start scan too early */
6058 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6062 static void iwl4965_bg_post_associate(struct work_struct
*data
)
6064 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
6065 post_associate
.work
);
6067 mutex_lock(&priv
->mutex
);
6068 iwl4965_post_associate(priv
);
6069 mutex_unlock(&priv
->mutex
);
6073 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
6075 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
6077 if (!iwl_is_ready(priv
))
6080 mutex_lock(&priv
->mutex
);
6082 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6083 iwl4965_send_scan_abort(priv
);
6085 mutex_unlock(&priv
->mutex
);
6088 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
6090 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
6092 struct iwl_priv
*priv
=
6093 container_of(work
, struct iwl_priv
, scan_completed
);
6095 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6097 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6100 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6101 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
6103 ieee80211_scan_completed(priv
->hw
);
6105 /* Since setting the TXPOWER may have been deferred while
6106 * performing the scan, fire one off */
6107 mutex_lock(&priv
->mutex
);
6108 iwl4965_hw_reg_send_txpower(priv
);
6109 mutex_unlock(&priv
->mutex
);
6112 /*****************************************************************************
6114 * mac80211 entry point functions
6116 *****************************************************************************/
6118 #define UCODE_READY_TIMEOUT (2 * HZ)
6120 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
6122 struct iwl_priv
*priv
= hw
->priv
;
6125 IWL_DEBUG_MAC80211("enter\n");
6127 if (pci_enable_device(priv
->pci_dev
)) {
6128 IWL_ERROR("Fail to pci_enable_device\n");
6131 pci_restore_state(priv
->pci_dev
);
6132 pci_enable_msi(priv
->pci_dev
);
6134 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
6137 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6138 goto out_disable_msi
;
6141 /* we should be verifying the device is ready to be opened */
6142 mutex_lock(&priv
->mutex
);
6144 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
6145 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6146 * ucode filename and max sizes are card-specific. */
6148 if (!priv
->ucode_code
.len
) {
6149 ret
= iwl4965_read_ucode(priv
);
6151 IWL_ERROR("Could not read microcode: %d\n", ret
);
6152 mutex_unlock(&priv
->mutex
);
6153 goto out_release_irq
;
6157 ret
= __iwl4965_up(priv
);
6159 mutex_unlock(&priv
->mutex
);
6162 goto out_release_irq
;
6164 IWL_DEBUG_INFO("Start UP work done.\n");
6166 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6169 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6170 * mac80211 will not be run successfully. */
6171 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6172 test_bit(STATUS_READY
, &priv
->status
),
6173 UCODE_READY_TIMEOUT
);
6175 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6176 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6177 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6179 goto out_release_irq
;
6184 IWL_DEBUG_MAC80211("leave\n");
6188 free_irq(priv
->pci_dev
->irq
, priv
);
6190 pci_disable_msi(priv
->pci_dev
);
6191 pci_disable_device(priv
->pci_dev
);
6193 IWL_DEBUG_MAC80211("leave - failed\n");
6197 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
6199 struct iwl_priv
*priv
= hw
->priv
;
6201 IWL_DEBUG_MAC80211("enter\n");
6203 if (!priv
->is_open
) {
6204 IWL_DEBUG_MAC80211("leave - skip\n");
6210 if (iwl_is_ready_rf(priv
)) {
6211 /* stop mac, cancel any scan request and clear
6212 * RXON_FILTER_ASSOC_MSK BIT
6214 mutex_lock(&priv
->mutex
);
6215 iwl4965_scan_cancel_timeout(priv
, 100);
6216 cancel_delayed_work(&priv
->post_associate
);
6217 mutex_unlock(&priv
->mutex
);
6222 flush_workqueue(priv
->workqueue
);
6223 free_irq(priv
->pci_dev
->irq
, priv
);
6224 pci_disable_msi(priv
->pci_dev
);
6225 pci_save_state(priv
->pci_dev
);
6226 pci_disable_device(priv
->pci_dev
);
6228 IWL_DEBUG_MAC80211("leave\n");
6231 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6232 struct ieee80211_tx_control
*ctl
)
6234 struct iwl_priv
*priv
= hw
->priv
;
6236 IWL_DEBUG_MAC80211("enter\n");
6238 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
6239 IWL_DEBUG_MAC80211("leave - monitor\n");
6243 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6244 ctl
->tx_rate
->bitrate
);
6246 if (iwl4965_tx_skb(priv
, skb
, ctl
))
6247 dev_kfree_skb_any(skb
);
6249 IWL_DEBUG_MAC80211("leave\n");
6253 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
6254 struct ieee80211_if_init_conf
*conf
)
6256 struct iwl_priv
*priv
= hw
->priv
;
6257 unsigned long flags
;
6258 DECLARE_MAC_BUF(mac
);
6260 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6263 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6267 spin_lock_irqsave(&priv
->lock
, flags
);
6268 priv
->vif
= conf
->vif
;
6270 spin_unlock_irqrestore(&priv
->lock
, flags
);
6272 mutex_lock(&priv
->mutex
);
6274 if (conf
->mac_addr
) {
6275 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
6276 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6279 if (iwl_is_ready(priv
))
6280 iwl4965_set_mode(priv
, conf
->type
);
6282 mutex_unlock(&priv
->mutex
);
6284 IWL_DEBUG_MAC80211("leave\n");
6289 * iwl4965_mac_config - mac80211 config callback
6291 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6292 * be set inappropriately and the driver currently sets the hardware up to
6293 * use it whenever needed.
6295 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6297 struct iwl_priv
*priv
= hw
->priv
;
6298 const struct iwl_channel_info
*ch_info
;
6299 unsigned long flags
;
6302 mutex_lock(&priv
->mutex
);
6303 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6305 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
6307 if (!iwl_is_ready(priv
)) {
6308 IWL_DEBUG_MAC80211("leave - not ready\n");
6313 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
6314 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6315 IWL_DEBUG_MAC80211("leave - scanning\n");
6316 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6317 mutex_unlock(&priv
->mutex
);
6321 spin_lock_irqsave(&priv
->lock
, flags
);
6323 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
,
6324 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6325 if (!is_channel_valid(ch_info
)) {
6326 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6327 spin_unlock_irqrestore(&priv
->lock
, flags
);
6332 #ifdef CONFIG_IWL4965_HT
6333 /* if we are switching from ht to 2.4 clear flags
6334 * from any ht related info since 2.4 does not
6336 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
->hw_value
)
6337 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6338 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
6341 priv
->staging_rxon
.flags
= 0;
6342 #endif /* CONFIG_IWL4965_HT */
6344 iwlcore_set_rxon_channel(priv
, conf
->channel
->band
,
6345 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6347 iwl4965_set_flags_for_phymode(priv
, conf
->channel
->band
);
6349 /* The list of supported rates and rate mask can be different
6350 * for each band; since the band may have changed, reset
6351 * the rate mask to what mac80211 lists */
6352 iwl4965_set_rate(priv
);
6354 spin_unlock_irqrestore(&priv
->lock
, flags
);
6356 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6357 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6358 iwl4965_hw_channel_switch(priv
, conf
->channel
);
6363 if (priv
->cfg
->ops
->lib
->radio_kill_sw
)
6364 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, !conf
->radio_enabled
);
6366 if (!conf
->radio_enabled
) {
6367 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6371 if (iwl_is_rfkill(priv
)) {
6372 IWL_DEBUG_MAC80211("leave - RF kill\n");
6377 iwl4965_set_rate(priv
);
6379 if (memcmp(&priv
->active_rxon
,
6380 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
6381 iwl4965_commit_rxon(priv
);
6383 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6385 IWL_DEBUG_MAC80211("leave\n");
6388 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6389 mutex_unlock(&priv
->mutex
);
6393 static void iwl4965_config_ap(struct iwl_priv
*priv
)
6397 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6400 /* The following should be done only at AP bring up */
6401 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
6403 /* RXON - unassoc (to set timing command) */
6404 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6405 iwl4965_commit_rxon(priv
);
6408 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6409 iwl4965_setup_rxon_timing(priv
);
6410 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6411 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6413 IWL_WARNING("REPLY_RXON_TIMING failed - "
6414 "Attempting to continue.\n");
6416 iwl4965_set_rxon_chain(priv
);
6418 /* FIXME: what should be the assoc_id for AP? */
6419 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6420 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6421 priv
->staging_rxon
.flags
|=
6422 RXON_FLG_SHORT_PREAMBLE_MSK
;
6424 priv
->staging_rxon
.flags
&=
6425 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6427 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6428 if (priv
->assoc_capability
&
6429 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6430 priv
->staging_rxon
.flags
|=
6431 RXON_FLG_SHORT_SLOT_MSK
;
6433 priv
->staging_rxon
.flags
&=
6434 ~RXON_FLG_SHORT_SLOT_MSK
;
6436 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6437 priv
->staging_rxon
.flags
&=
6438 ~RXON_FLG_SHORT_SLOT_MSK
;
6440 /* restore RXON assoc */
6441 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6442 iwl4965_commit_rxon(priv
);
6443 iwl4965_activate_qos(priv
, 1);
6444 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6446 iwl4965_send_beacon_cmd(priv
);
6448 /* FIXME - we need to add code here to detect a totally new
6449 * configuration, reset the AP, unassoc, rxon timing, assoc,
6450 * clear sta table, add BCAST sta... */
6453 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
6454 struct ieee80211_vif
*vif
,
6455 struct ieee80211_if_conf
*conf
)
6457 struct iwl_priv
*priv
= hw
->priv
;
6458 DECLARE_MAC_BUF(mac
);
6459 unsigned long flags
;
6465 if (priv
->vif
!= vif
) {
6466 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6470 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
6471 (!conf
->beacon
|| !conf
->ssid_len
)) {
6473 ("Leaving in AP mode because HostAPD is not ready.\n");
6477 if (!iwl_is_alive(priv
))
6480 mutex_lock(&priv
->mutex
);
6483 IWL_DEBUG_MAC80211("bssid: %s\n",
6484 print_mac(mac
, conf
->bssid
));
6487 * very dubious code was here; the probe filtering flag is never set:
6489 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6490 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6493 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6495 conf
->bssid
= priv
->mac_addr
;
6496 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6497 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6498 print_mac(mac
, conf
->bssid
));
6500 if (priv
->ibss_beacon
)
6501 dev_kfree_skb(priv
->ibss_beacon
);
6503 priv
->ibss_beacon
= conf
->beacon
;
6506 if (iwl_is_rfkill(priv
))
6509 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6510 !is_multicast_ether_addr(conf
->bssid
)) {
6511 /* If there is currently a HW scan going on in the background
6512 * then we need to cancel it else the RXON below will fail. */
6513 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
6514 IWL_WARNING("Aborted scan still in progress "
6516 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6517 mutex_unlock(&priv
->mutex
);
6520 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6522 /* TODO: Audit driver for usage of these members and see
6523 * if mac80211 deprecates them (priv->bssid looks like it
6524 * shouldn't be there, but I haven't scanned the IBSS code
6525 * to verify) - jpk */
6526 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6528 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6529 iwl4965_config_ap(priv
);
6531 rc
= iwl4965_commit_rxon(priv
);
6532 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
6533 iwl4965_rxon_add_station(
6534 priv
, priv
->active_rxon
.bssid_addr
, 1);
6538 iwl4965_scan_cancel_timeout(priv
, 100);
6539 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6540 iwl4965_commit_rxon(priv
);
6544 spin_lock_irqsave(&priv
->lock
, flags
);
6545 if (!conf
->ssid_len
)
6546 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6548 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
6550 priv
->essid_len
= conf
->ssid_len
;
6551 spin_unlock_irqrestore(&priv
->lock
, flags
);
6553 IWL_DEBUG_MAC80211("leave\n");
6554 mutex_unlock(&priv
->mutex
);
6559 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
6560 unsigned int changed_flags
,
6561 unsigned int *total_flags
,
6562 int mc_count
, struct dev_addr_list
*mc_list
)
6566 * see also iwl4965_connection_init_rx_config
6571 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
6572 struct ieee80211_if_init_conf
*conf
)
6574 struct iwl_priv
*priv
= hw
->priv
;
6576 IWL_DEBUG_MAC80211("enter\n");
6578 mutex_lock(&priv
->mutex
);
6580 if (iwl_is_ready_rf(priv
)) {
6581 iwl4965_scan_cancel_timeout(priv
, 100);
6582 cancel_delayed_work(&priv
->post_associate
);
6583 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6584 iwl4965_commit_rxon(priv
);
6586 if (priv
->vif
== conf
->vif
) {
6588 memset(priv
->bssid
, 0, ETH_ALEN
);
6589 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6590 priv
->essid_len
= 0;
6592 mutex_unlock(&priv
->mutex
);
6594 IWL_DEBUG_MAC80211("leave\n");
6599 #ifdef CONFIG_IWL4965_HT
6600 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
6601 struct ieee80211_bss_conf
*bss_conf
)
6603 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
6604 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
6605 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
6607 IWL_DEBUG_MAC80211("enter: \n");
6609 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
6611 if (!iwl_conf
->is_ht
)
6614 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
6616 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
6617 iwl_conf
->sgf
|= 0x1;
6618 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
6619 iwl_conf
->sgf
|= 0x2;
6621 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
6622 iwl_conf
->max_amsdu_size
=
6623 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
6625 iwl_conf
->supported_chan_width
=
6626 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
6627 iwl_conf
->extension_chan_offset
=
6628 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
6629 /* If no above or below channel supplied disable FAT channel */
6630 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
6631 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
6632 iwl_conf
->supported_chan_width
= 0;
6634 iwl_conf
->tx_mimo_ps_mode
=
6635 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
6636 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
6638 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
6639 iwl_conf
->tx_chan_width
=
6640 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
6641 iwl_conf
->ht_protection
=
6642 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
6643 iwl_conf
->non_GF_STA_present
=
6644 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
6646 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
6647 IWL_DEBUG_MAC80211("leave\n");
6650 static inline void iwl4965_ht_conf(struct iwl_priv
*priv
,
6651 struct ieee80211_bss_conf
*bss_conf
)
6656 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6657 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
6658 struct ieee80211_vif
*vif
,
6659 struct ieee80211_bss_conf
*bss_conf
,
6662 struct iwl_priv
*priv
= hw
->priv
;
6664 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
6666 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
6667 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6668 bss_conf
->use_short_preamble
);
6669 if (bss_conf
->use_short_preamble
)
6670 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6672 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6675 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
6676 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
6677 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
6678 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
6680 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
6683 if (changes
& BSS_CHANGED_HT
) {
6684 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
6685 iwl4965_ht_conf(priv
, bss_conf
);
6686 iwl4965_set_rxon_chain(priv
);
6689 if (changes
& BSS_CHANGED_ASSOC
) {
6690 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
6691 /* This should never happen as this function should
6692 * never be called from interrupt context. */
6693 if (WARN_ON_ONCE(in_interrupt()))
6695 if (bss_conf
->assoc
) {
6696 priv
->assoc_id
= bss_conf
->aid
;
6697 priv
->beacon_int
= bss_conf
->beacon_int
;
6698 priv
->timestamp
= bss_conf
->timestamp
;
6699 priv
->assoc_capability
= bss_conf
->assoc_capability
;
6700 priv
->next_scan_jiffies
= jiffies
+
6701 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
6702 mutex_lock(&priv
->mutex
);
6703 iwl4965_post_associate(priv
);
6704 mutex_unlock(&priv
->mutex
);
6707 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
6709 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
6710 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
6711 iwl_send_rxon_assoc(priv
);
6716 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6719 unsigned long flags
;
6720 struct iwl_priv
*priv
= hw
->priv
;
6722 IWL_DEBUG_MAC80211("enter\n");
6724 mutex_lock(&priv
->mutex
);
6725 spin_lock_irqsave(&priv
->lock
, flags
);
6727 if (!iwl_is_ready_rf(priv
)) {
6729 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6733 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
6735 IWL_ERROR("ERROR: APs don't scan\n");
6739 /* we don't schedule scan within next_scan_jiffies period */
6740 if (priv
->next_scan_jiffies
&&
6741 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6745 /* if we just finished scan ask for delay */
6746 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
6747 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
6752 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6753 iwl4965_escape_essid(ssid
, len
), (int)len
);
6755 priv
->one_direct_scan
= 1;
6756 priv
->direct_ssid_len
= (u8
)
6757 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6758 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6760 priv
->one_direct_scan
= 0;
6762 rc
= iwl4965_scan_initiate(priv
);
6764 IWL_DEBUG_MAC80211("leave\n");
6767 spin_unlock_irqrestore(&priv
->lock
, flags
);
6768 mutex_unlock(&priv
->mutex
);
6773 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
6774 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
6775 u32 iv32
, u16
*phase1key
)
6777 struct iwl_priv
*priv
= hw
->priv
;
6778 u8 sta_id
= IWL_INVALID_STATION
;
6779 unsigned long flags
;
6780 __le16 key_flags
= 0;
6782 DECLARE_MAC_BUF(mac
);
6784 IWL_DEBUG_MAC80211("enter\n");
6786 sta_id
= iwl4965_hw_find_station(priv
, addr
);
6787 if (sta_id
== IWL_INVALID_STATION
) {
6788 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6789 print_mac(mac
, addr
));
6793 iwl4965_scan_cancel_timeout(priv
, 100);
6795 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
6796 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
6797 key_flags
&= ~STA_KEY_FLG_INVALID
;
6799 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
6800 key_flags
|= STA_KEY_MULTICAST_MSK
;
6802 spin_lock_irqsave(&priv
->sta_lock
, flags
);
6804 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
6805 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
6807 for (i
= 0; i
< 5; i
++)
6808 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
6809 cpu_to_le16(phase1key
[i
]);
6811 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
6812 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
6814 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
6816 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
6818 IWL_DEBUG_MAC80211("leave\n");
6821 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6822 const u8
*local_addr
, const u8
*addr
,
6823 struct ieee80211_key_conf
*key
)
6825 struct iwl_priv
*priv
= hw
->priv
;
6826 DECLARE_MAC_BUF(mac
);
6828 u8 sta_id
= IWL_INVALID_STATION
;
6829 u8 is_default_wep_key
= 0;
6831 IWL_DEBUG_MAC80211("enter\n");
6833 if (priv
->cfg
->mod_params
->sw_crypto
) {
6834 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6838 if (is_zero_ether_addr(addr
))
6839 /* only support pairwise keys */
6842 sta_id
= iwl4965_hw_find_station(priv
, addr
);
6843 if (sta_id
== IWL_INVALID_STATION
) {
6844 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6845 print_mac(mac
, addr
));
6850 mutex_lock(&priv
->mutex
);
6851 iwl4965_scan_cancel_timeout(priv
, 100);
6852 mutex_unlock(&priv
->mutex
);
6854 /* If we are getting WEP group key and we didn't receive any key mapping
6855 * so far, we are in legacy wep mode (group key only), otherwise we are
6857 * In legacy wep mode, we use another host command to the uCode */
6858 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_params
.bcast_sta_id
&&
6859 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
6861 is_default_wep_key
= !priv
->key_mapping_key
;
6863 is_default_wep_key
= priv
->default_wep_key
;
6868 if (is_default_wep_key
)
6869 ret
= iwl_set_default_wep_key(priv
, key
);
6871 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
6873 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
6876 if (is_default_wep_key
)
6877 ret
= iwl_remove_default_wep_key(priv
, key
);
6879 ret
= iwl_remove_dynamic_key(priv
, sta_id
);
6881 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6887 IWL_DEBUG_MAC80211("leave\n");
6892 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
6893 const struct ieee80211_tx_queue_params
*params
)
6895 struct iwl_priv
*priv
= hw
->priv
;
6896 unsigned long flags
;
6899 IWL_DEBUG_MAC80211("enter\n");
6901 if (!iwl_is_ready_rf(priv
)) {
6902 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6906 if (queue
>= AC_NUM
) {
6907 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
6911 if (!priv
->qos_data
.qos_enable
) {
6912 priv
->qos_data
.qos_active
= 0;
6913 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
6916 q
= AC_NUM
- 1 - queue
;
6918 spin_lock_irqsave(&priv
->lock
, flags
);
6920 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
6921 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
6922 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
6923 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
6924 cpu_to_le16((params
->txop
* 32));
6926 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
6927 priv
->qos_data
.qos_active
= 1;
6929 spin_unlock_irqrestore(&priv
->lock
, flags
);
6931 mutex_lock(&priv
->mutex
);
6932 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6933 iwl4965_activate_qos(priv
, 1);
6934 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
6935 iwl4965_activate_qos(priv
, 0);
6937 mutex_unlock(&priv
->mutex
);
6939 IWL_DEBUG_MAC80211("leave\n");
6943 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
6944 struct ieee80211_tx_queue_stats
*stats
)
6946 struct iwl_priv
*priv
= hw
->priv
;
6948 struct iwl4965_tx_queue
*txq
;
6949 struct iwl4965_queue
*q
;
6950 unsigned long flags
;
6952 IWL_DEBUG_MAC80211("enter\n");
6954 if (!iwl_is_ready_rf(priv
)) {
6955 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6959 spin_lock_irqsave(&priv
->lock
, flags
);
6961 for (i
= 0; i
< AC_NUM
; i
++) {
6962 txq
= &priv
->txq
[i
];
6964 avail
= iwl4965_queue_space(q
);
6966 stats
->data
[i
].len
= q
->n_window
- avail
;
6967 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
6968 stats
->data
[i
].count
= q
->n_window
;
6971 spin_unlock_irqrestore(&priv
->lock
, flags
);
6973 IWL_DEBUG_MAC80211("leave\n");
6978 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
6979 struct ieee80211_low_level_stats
*stats
)
6981 IWL_DEBUG_MAC80211("enter\n");
6982 IWL_DEBUG_MAC80211("leave\n");
6987 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
6989 IWL_DEBUG_MAC80211("enter\n");
6990 IWL_DEBUG_MAC80211("leave\n");
6995 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
6997 struct iwl_priv
*priv
= hw
->priv
;
6998 unsigned long flags
;
7000 mutex_lock(&priv
->mutex
);
7001 IWL_DEBUG_MAC80211("enter\n");
7003 priv
->lq_mngr
.lq_ready
= 0;
7004 #ifdef CONFIG_IWL4965_HT
7005 spin_lock_irqsave(&priv
->lock
, flags
);
7006 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
7007 spin_unlock_irqrestore(&priv
->lock
, flags
);
7008 #endif /* CONFIG_IWL4965_HT */
7010 iwlcore_reset_qos(priv
);
7012 cancel_delayed_work(&priv
->post_associate
);
7014 spin_lock_irqsave(&priv
->lock
, flags
);
7016 priv
->assoc_capability
= 0;
7017 priv
->assoc_station_added
= 0;
7019 /* new association get rid of ibss beacon skb */
7020 if (priv
->ibss_beacon
)
7021 dev_kfree_skb(priv
->ibss_beacon
);
7023 priv
->ibss_beacon
= NULL
;
7025 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7026 priv
->timestamp
= 0;
7027 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7028 priv
->beacon_int
= 0;
7030 spin_unlock_irqrestore(&priv
->lock
, flags
);
7032 if (!iwl_is_ready_rf(priv
)) {
7033 IWL_DEBUG_MAC80211("leave - not ready\n");
7034 mutex_unlock(&priv
->mutex
);
7038 /* we are restarting association process
7039 * clear RXON_FILTER_ASSOC_MSK bit
7041 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7042 iwl4965_scan_cancel_timeout(priv
, 100);
7043 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7044 iwl4965_commit_rxon(priv
);
7047 /* Per mac80211.h: This is only used in IBSS mode... */
7048 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7050 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7051 mutex_unlock(&priv
->mutex
);
7055 iwl4965_set_rate(priv
);
7057 mutex_unlock(&priv
->mutex
);
7059 IWL_DEBUG_MAC80211("leave\n");
7062 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7063 struct ieee80211_tx_control
*control
)
7065 struct iwl_priv
*priv
= hw
->priv
;
7066 unsigned long flags
;
7068 mutex_lock(&priv
->mutex
);
7069 IWL_DEBUG_MAC80211("enter\n");
7071 if (!iwl_is_ready_rf(priv
)) {
7072 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7073 mutex_unlock(&priv
->mutex
);
7077 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7078 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7079 mutex_unlock(&priv
->mutex
);
7083 spin_lock_irqsave(&priv
->lock
, flags
);
7085 if (priv
->ibss_beacon
)
7086 dev_kfree_skb(priv
->ibss_beacon
);
7088 priv
->ibss_beacon
= skb
;
7092 IWL_DEBUG_MAC80211("leave\n");
7093 spin_unlock_irqrestore(&priv
->lock
, flags
);
7095 iwlcore_reset_qos(priv
);
7097 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7099 mutex_unlock(&priv
->mutex
);
7104 /*****************************************************************************
7108 *****************************************************************************/
7110 #ifdef CONFIG_IWLWIFI_DEBUG
7113 * The following adds a new attribute to the sysfs representation
7114 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7115 * used for controlling the debug level.
7117 * See the level definitions in iwl for details.
7120 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7122 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
7124 static ssize_t
store_debug_level(struct device_driver
*d
,
7125 const char *buf
, size_t count
)
7127 char *p
= (char *)buf
;
7130 val
= simple_strtoul(p
, &p
, 0);
7132 printk(KERN_INFO DRV_NAME
7133 ": %s is not in hex or decimal form.\n", buf
);
7135 iwl_debug_level
= val
;
7137 return strnlen(buf
, count
);
7140 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7141 show_debug_level
, store_debug_level
);
7143 #endif /* CONFIG_IWLWIFI_DEBUG */
7146 static ssize_t
show_temperature(struct device
*d
,
7147 struct device_attribute
*attr
, char *buf
)
7149 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7151 if (!iwl_is_alive(priv
))
7154 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
7157 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7159 static ssize_t
show_rs_window(struct device
*d
,
7160 struct device_attribute
*attr
,
7163 struct iwl_priv
*priv
= d
->driver_data
;
7164 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7166 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7168 static ssize_t
show_tx_power(struct device
*d
,
7169 struct device_attribute
*attr
, char *buf
)
7171 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7172 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7175 static ssize_t
store_tx_power(struct device
*d
,
7176 struct device_attribute
*attr
,
7177 const char *buf
, size_t count
)
7179 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7180 char *p
= (char *)buf
;
7183 val
= simple_strtoul(p
, &p
, 10);
7185 printk(KERN_INFO DRV_NAME
7186 ": %s is not in decimal form.\n", buf
);
7188 iwl4965_hw_reg_set_txpower(priv
, val
);
7193 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7195 static ssize_t
show_flags(struct device
*d
,
7196 struct device_attribute
*attr
, char *buf
)
7198 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7200 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7203 static ssize_t
store_flags(struct device
*d
,
7204 struct device_attribute
*attr
,
7205 const char *buf
, size_t count
)
7207 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7208 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7210 mutex_lock(&priv
->mutex
);
7211 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7212 /* Cancel any currently running scans... */
7213 if (iwl4965_scan_cancel_timeout(priv
, 100))
7214 IWL_WARNING("Could not cancel scan.\n");
7216 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7218 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7219 iwl4965_commit_rxon(priv
);
7222 mutex_unlock(&priv
->mutex
);
7227 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7229 static ssize_t
show_filter_flags(struct device
*d
,
7230 struct device_attribute
*attr
, char *buf
)
7232 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7234 return sprintf(buf
, "0x%04X\n",
7235 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7238 static ssize_t
store_filter_flags(struct device
*d
,
7239 struct device_attribute
*attr
,
7240 const char *buf
, size_t count
)
7242 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7243 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7245 mutex_lock(&priv
->mutex
);
7246 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7247 /* Cancel any currently running scans... */
7248 if (iwl4965_scan_cancel_timeout(priv
, 100))
7249 IWL_WARNING("Could not cancel scan.\n");
7251 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7252 "0x%04X\n", filter_flags
);
7253 priv
->staging_rxon
.filter_flags
=
7254 cpu_to_le32(filter_flags
);
7255 iwl4965_commit_rxon(priv
);
7258 mutex_unlock(&priv
->mutex
);
7263 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7264 store_filter_flags
);
7266 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7268 static ssize_t
show_measurement(struct device
*d
,
7269 struct device_attribute
*attr
, char *buf
)
7271 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7272 struct iwl4965_spectrum_notification measure_report
;
7273 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7274 u8
*data
= (u8
*) & measure_report
;
7275 unsigned long flags
;
7277 spin_lock_irqsave(&priv
->lock
, flags
);
7278 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7279 spin_unlock_irqrestore(&priv
->lock
, flags
);
7282 memcpy(&measure_report
, &priv
->measure_report
, size
);
7283 priv
->measurement_status
= 0;
7284 spin_unlock_irqrestore(&priv
->lock
, flags
);
7286 while (size
&& (PAGE_SIZE
- len
)) {
7287 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7288 PAGE_SIZE
- len
, 1);
7290 if (PAGE_SIZE
- len
)
7294 size
-= min(size
, 16U);
7300 static ssize_t
store_measurement(struct device
*d
,
7301 struct device_attribute
*attr
,
7302 const char *buf
, size_t count
)
7304 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7305 struct ieee80211_measurement_params params
= {
7306 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7307 .start_time
= cpu_to_le64(priv
->last_tsf
),
7308 .duration
= cpu_to_le16(1),
7310 u8 type
= IWL_MEASURE_BASIC
;
7316 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7317 channel
= simple_strtoul(p
, NULL
, 0);
7319 params
.channel
= channel
;
7322 while (*p
&& *p
!= ' ')
7325 type
= simple_strtoul(p
+ 1, NULL
, 0);
7328 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7329 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7330 iwl4965_get_measurement(priv
, ¶ms
, type
);
7335 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7336 show_measurement
, store_measurement
);
7337 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
7339 static ssize_t
store_retry_rate(struct device
*d
,
7340 struct device_attribute
*attr
,
7341 const char *buf
, size_t count
)
7343 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7345 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7346 if (priv
->retry_rate
<= 0)
7347 priv
->retry_rate
= 1;
7352 static ssize_t
show_retry_rate(struct device
*d
,
7353 struct device_attribute
*attr
, char *buf
)
7355 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7356 return sprintf(buf
, "%d", priv
->retry_rate
);
7359 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7362 static ssize_t
store_power_level(struct device
*d
,
7363 struct device_attribute
*attr
,
7364 const char *buf
, size_t count
)
7366 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7370 mode
= simple_strtoul(buf
, NULL
, 0);
7371 mutex_lock(&priv
->mutex
);
7373 if (!iwl_is_ready(priv
)) {
7378 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7379 mode
= IWL_POWER_AC
;
7381 mode
|= IWL_POWER_ENABLED
;
7383 if (mode
!= priv
->power_mode
) {
7384 rc
= iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7386 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7389 priv
->power_mode
= mode
;
7395 mutex_unlock(&priv
->mutex
);
7399 #define MAX_WX_STRING 80
7401 /* Values are in microsecond */
7402 static const s32 timeout_duration
[] = {
7409 static const s32 period_duration
[] = {
7417 static ssize_t
show_power_level(struct device
*d
,
7418 struct device_attribute
*attr
, char *buf
)
7420 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7421 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7424 p
+= sprintf(p
, "%d ", level
);
7426 case IWL_POWER_MODE_CAM
:
7428 p
+= sprintf(p
, "(AC)");
7430 case IWL_POWER_BATTERY
:
7431 p
+= sprintf(p
, "(BATTERY)");
7435 "(Timeout %dms, Period %dms)",
7436 timeout_duration
[level
- 1] / 1000,
7437 period_duration
[level
- 1] / 1000);
7440 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7441 p
+= sprintf(p
, " OFF\n");
7443 p
+= sprintf(p
, " \n");
7445 return (p
- buf
+ 1);
7449 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7452 static ssize_t
show_channels(struct device
*d
,
7453 struct device_attribute
*attr
, char *buf
)
7455 /* all this shit doesn't belong into sysfs anyway */
7459 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7461 static ssize_t
show_statistics(struct device
*d
,
7462 struct device_attribute
*attr
, char *buf
)
7464 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7465 u32 size
= sizeof(struct iwl4965_notif_statistics
);
7466 u32 len
= 0, ofs
= 0;
7467 u8
*data
= (u8
*) & priv
->statistics
;
7470 if (!iwl_is_alive(priv
))
7473 mutex_lock(&priv
->mutex
);
7474 rc
= iwl_send_statistics_request(priv
, 0);
7475 mutex_unlock(&priv
->mutex
);
7479 "Error sending statistics request: 0x%08X\n", rc
);
7483 while (size
&& (PAGE_SIZE
- len
)) {
7484 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7485 PAGE_SIZE
- len
, 1);
7487 if (PAGE_SIZE
- len
)
7491 size
-= min(size
, 16U);
7497 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7499 static ssize_t
show_antenna(struct device
*d
,
7500 struct device_attribute
*attr
, char *buf
)
7502 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7504 if (!iwl_is_alive(priv
))
7507 return sprintf(buf
, "%d\n", priv
->antenna
);
7510 static ssize_t
store_antenna(struct device
*d
,
7511 struct device_attribute
*attr
,
7512 const char *buf
, size_t count
)
7515 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7520 if (sscanf(buf
, "%1i", &ant
) != 1) {
7521 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7525 if ((ant
>= 0) && (ant
<= 2)) {
7526 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7527 priv
->antenna
= (enum iwl4965_antenna
)ant
;
7529 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7535 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7537 static ssize_t
show_status(struct device
*d
,
7538 struct device_attribute
*attr
, char *buf
)
7540 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7541 if (!iwl_is_alive(priv
))
7543 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7546 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7548 static ssize_t
dump_error_log(struct device
*d
,
7549 struct device_attribute
*attr
,
7550 const char *buf
, size_t count
)
7552 char *p
= (char *)buf
;
7555 iwl4965_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
7557 return strnlen(buf
, count
);
7560 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7562 static ssize_t
dump_event_log(struct device
*d
,
7563 struct device_attribute
*attr
,
7564 const char *buf
, size_t count
)
7566 char *p
= (char *)buf
;
7569 iwl4965_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
7571 return strnlen(buf
, count
);
7574 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7576 /*****************************************************************************
7578 * driver setup and teardown
7580 *****************************************************************************/
7582 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
7584 priv
->workqueue
= create_workqueue(DRV_NAME
);
7586 init_waitqueue_head(&priv
->wait_command_queue
);
7588 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
7589 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
7590 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
7591 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
7592 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
7593 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
7594 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
7595 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
7596 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
7597 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
7598 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
7599 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
7601 iwl4965_hw_setup_deferred_work(priv
);
7603 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7604 iwl4965_irq_tasklet
, (unsigned long)priv
);
7607 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
7609 iwl4965_hw_cancel_deferred_work(priv
);
7611 cancel_delayed_work_sync(&priv
->init_alive_start
);
7612 cancel_delayed_work(&priv
->scan_check
);
7613 cancel_delayed_work(&priv
->alive_start
);
7614 cancel_delayed_work(&priv
->post_associate
);
7615 cancel_work_sync(&priv
->beacon_update
);
7618 static struct attribute
*iwl4965_sysfs_entries
[] = {
7619 &dev_attr_antenna
.attr
,
7620 &dev_attr_channels
.attr
,
7621 &dev_attr_dump_errors
.attr
,
7622 &dev_attr_dump_events
.attr
,
7623 &dev_attr_flags
.attr
,
7624 &dev_attr_filter_flags
.attr
,
7625 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7626 &dev_attr_measurement
.attr
,
7628 &dev_attr_power_level
.attr
,
7629 &dev_attr_retry_rate
.attr
,
7630 &dev_attr_rs_window
.attr
,
7631 &dev_attr_statistics
.attr
,
7632 &dev_attr_status
.attr
,
7633 &dev_attr_temperature
.attr
,
7634 &dev_attr_tx_power
.attr
,
7639 static struct attribute_group iwl4965_attribute_group
= {
7640 .name
= NULL
, /* put in device directory */
7641 .attrs
= iwl4965_sysfs_entries
,
7644 static struct ieee80211_ops iwl4965_hw_ops
= {
7645 .tx
= iwl4965_mac_tx
,
7646 .start
= iwl4965_mac_start
,
7647 .stop
= iwl4965_mac_stop
,
7648 .add_interface
= iwl4965_mac_add_interface
,
7649 .remove_interface
= iwl4965_mac_remove_interface
,
7650 .config
= iwl4965_mac_config
,
7651 .config_interface
= iwl4965_mac_config_interface
,
7652 .configure_filter
= iwl4965_configure_filter
,
7653 .set_key
= iwl4965_mac_set_key
,
7654 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
7655 .get_stats
= iwl4965_mac_get_stats
,
7656 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
7657 .conf_tx
= iwl4965_mac_conf_tx
,
7658 .get_tsf
= iwl4965_mac_get_tsf
,
7659 .reset_tsf
= iwl4965_mac_reset_tsf
,
7660 .beacon_update
= iwl4965_mac_beacon_update
,
7661 .bss_info_changed
= iwl4965_bss_info_changed
,
7662 #ifdef CONFIG_IWL4965_HT
7663 .ampdu_action
= iwl4965_mac_ampdu_action
,
7664 #endif /* CONFIG_IWL4965_HT */
7665 .hw_scan
= iwl4965_mac_hw_scan
7668 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7671 struct iwl_priv
*priv
;
7672 struct ieee80211_hw
*hw
;
7673 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
7674 unsigned long flags
;
7675 DECLARE_MAC_BUF(mac
);
7677 /************************
7678 * 1. Allocating HW data
7679 ************************/
7681 /* Disabling hardware scan means that mac80211 will perform scans
7682 * "the hard way", rather than using device's scan. */
7683 if (cfg
->mod_params
->disable_hw_scan
) {
7684 IWL_DEBUG_INFO("Disabling hw_scan\n");
7685 iwl4965_hw_ops
.hw_scan
= NULL
;
7688 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
7694 /* At this point both hw and priv are allocated. */
7696 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
7698 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7700 priv
->pci_dev
= pdev
;
7702 #ifdef CONFIG_IWLWIFI_DEBUG
7703 iwl_debug_level
= priv
->cfg
->mod_params
->debug
;
7704 atomic_set(&priv
->restrict_refcnt
, 0);
7707 /**************************
7708 * 2. Initializing PCI bus
7709 **************************/
7710 if (pci_enable_device(pdev
)) {
7712 goto out_ieee80211_free_hw
;
7715 pci_set_master(pdev
);
7717 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
7719 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
7721 printk(KERN_WARNING DRV_NAME
7722 ": No suitable DMA available.\n");
7723 goto out_pci_disable_device
;
7726 err
= pci_request_regions(pdev
, DRV_NAME
);
7728 goto out_pci_disable_device
;
7730 pci_set_drvdata(pdev
, priv
);
7732 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7733 * PCI Tx retries from interfering with C3 CPU state */
7734 pci_write_config_byte(pdev
, 0x41, 0x00);
7736 /***********************
7737 * 3. Read REV register
7738 ***********************/
7739 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
7740 if (!priv
->hw_base
) {
7742 goto out_pci_release_regions
;
7745 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7746 (unsigned long long) pci_resource_len(pdev
, 0));
7747 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
7749 printk(KERN_INFO DRV_NAME
7750 ": Detected Intel Wireless WiFi Link %s\n", priv
->cfg
->name
);
7756 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
7757 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
7759 iwl_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
7760 err
= iwl_poll_bit(priv
, CSR_GP_CNTRL
,
7761 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
7762 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
7764 IWL_DEBUG_INFO("Failed to init the card\n");
7767 /* Read the EEPROM */
7768 err
= iwl_eeprom_init(priv
);
7770 IWL_ERROR("Unable to init EEPROM\n");
7773 /* MAC Address location in EEPROM same for 3945/4965 */
7774 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
7775 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
7776 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
7778 /************************
7779 * 5. Setup HW constants
7780 ************************/
7781 /* Device-specific setup */
7782 if (priv
->cfg
->ops
->lib
->set_hw_params(priv
)) {
7783 IWL_ERROR("failed to set hw parameters\n");
7787 /*******************
7789 *******************/
7791 err
= iwl_setup(priv
);
7793 goto out_unset_hw_params
;
7794 /* At this point both hw and priv are initialized. */
7796 /**********************************
7797 * 7. Initialize module parameters
7798 **********************************/
7800 /* Disable radio (SW RF KILL) via parameter when loading driver */
7801 if (priv
->cfg
->mod_params
->disable
) {
7802 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
7803 IWL_DEBUG_INFO("Radio disabled.\n");
7806 if (priv
->cfg
->mod_params
->enable_qos
)
7807 priv
->qos_data
.qos_enable
= 1;
7809 /********************
7811 ********************/
7812 spin_lock_irqsave(&priv
->lock
, flags
);
7813 iwl4965_disable_interrupts(priv
);
7814 spin_unlock_irqrestore(&priv
->lock
, flags
);
7816 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7818 IWL_ERROR("failed to create sysfs device attributes\n");
7819 goto out_unset_hw_params
;
7822 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
7824 IWL_ERROR("failed to create debugfs files\n");
7825 goto out_remove_sysfs
;
7828 iwl4965_setup_deferred_work(priv
);
7829 iwl4965_setup_rx_handlers(priv
);
7831 /********************
7833 ********************/
7834 pci_save_state(pdev
);
7835 pci_disable_device(pdev
);
7837 /* notify iwlcore to init */
7838 iwlcore_low_level_notify(priv
, IWLCORE_INIT_EVT
);
7842 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7843 out_unset_hw_params
:
7844 iwl4965_unset_hw_params(priv
);
7846 pci_iounmap(pdev
, priv
->hw_base
);
7847 out_pci_release_regions
:
7848 pci_release_regions(pdev
);
7849 pci_set_drvdata(pdev
, NULL
);
7850 out_pci_disable_device
:
7851 pci_disable_device(pdev
);
7852 out_ieee80211_free_hw
:
7853 ieee80211_free_hw(priv
->hw
);
7858 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
7860 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7861 struct list_head
*p
, *q
;
7863 unsigned long flags
;
7868 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
7870 if (priv
->mac80211_registered
) {
7871 ieee80211_unregister_hw(priv
->hw
);
7872 priv
->mac80211_registered
= 0;
7875 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
7879 /* make sure we flush any pending irq or
7880 * tasklet for the driver
7882 spin_lock_irqsave(&priv
->lock
, flags
);
7883 iwl4965_disable_interrupts(priv
);
7884 spin_unlock_irqrestore(&priv
->lock
, flags
);
7886 iwl_synchronize_irq(priv
);
7888 /* Free MAC hash list for ADHOC */
7889 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
7890 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
7892 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
7896 iwlcore_low_level_notify(priv
, IWLCORE_REMOVE_EVT
);
7897 iwl_dbgfs_unregister(priv
);
7898 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7900 iwl4965_dealloc_ucode_pci(priv
);
7903 iwl4965_rx_queue_free(priv
, &priv
->rxq
);
7904 iwl4965_hw_txq_ctx_free(priv
);
7906 iwl4965_unset_hw_params(priv
);
7907 iwlcore_clear_stations_table(priv
);
7910 /*netif_stop_queue(dev); */
7911 flush_workqueue(priv
->workqueue
);
7913 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
7914 * priv->workqueue... so we can't take down the workqueue
7916 destroy_workqueue(priv
->workqueue
);
7917 priv
->workqueue
= NULL
;
7919 pci_iounmap(pdev
, priv
->hw_base
);
7920 pci_release_regions(pdev
);
7921 pci_disable_device(pdev
);
7922 pci_set_drvdata(pdev
, NULL
);
7924 iwl_free_channel_map(priv
);
7925 iwl4965_free_geos(priv
);
7927 if (priv
->ibss_beacon
)
7928 dev_kfree_skb(priv
->ibss_beacon
);
7930 ieee80211_free_hw(priv
->hw
);
7935 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7937 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7939 if (priv
->is_open
) {
7940 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
7941 iwl4965_mac_stop(priv
->hw
);
7945 pci_set_power_state(pdev
, PCI_D3hot
);
7950 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
7952 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7954 pci_set_power_state(pdev
, PCI_D0
);
7957 iwl4965_mac_start(priv
->hw
);
7959 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
7963 #endif /* CONFIG_PM */
7965 /*****************************************************************************
7967 * driver and module entry point
7969 *****************************************************************************/
7971 /* Hardware specific file defines the PCI IDs table for that hardware module */
7972 static struct pci_device_id iwl_hw_card_ids
[] = {
7973 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID
, iwl4965_agn_cfg
)},
7974 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID
, iwl4965_agn_cfg
)},
7977 MODULE_DEVICE_TABLE(pci
, iwl_hw_card_ids
);
7979 static struct pci_driver iwl_driver
= {
7981 .id_table
= iwl_hw_card_ids
,
7982 .probe
= iwl4965_pci_probe
,
7983 .remove
= __devexit_p(iwl4965_pci_remove
),
7985 .suspend
= iwl4965_pci_suspend
,
7986 .resume
= iwl4965_pci_resume
,
7990 static int __init
iwl4965_init(void)
7994 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
7995 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
7997 ret
= iwl4965_rate_control_register();
7999 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
8003 ret
= pci_register_driver(&iwl_driver
);
8005 IWL_ERROR("Unable to initialize PCI module\n");
8006 goto error_register
;
8008 #ifdef CONFIG_IWLWIFI_DEBUG
8009 ret
= driver_create_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
8011 IWL_ERROR("Unable to create driver sysfs file\n");
8018 #ifdef CONFIG_IWLWIFI_DEBUG
8020 pci_unregister_driver(&iwl_driver
);
8023 iwl4965_rate_control_unregister();
8027 static void __exit
iwl4965_exit(void)
8029 #ifdef CONFIG_IWLWIFI_DEBUG
8030 driver_remove_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
8032 pci_unregister_driver(&iwl_driver
);
8033 iwl4965_rate_control_unregister();
8036 module_exit(iwl4965_exit
);
8037 module_init(iwl4965_init
);