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"
54 #include "iwl-calib.h"
56 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
57 struct iwl4965_tx_queue
*txq
);
59 /******************************************************************************
63 ******************************************************************************/
66 * module name, copyright, version, etc.
67 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
70 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
72 #ifdef CONFIG_IWLWIFI_DEBUG
78 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
84 #define DRV_VERSION IWLWIFI_VERSION VD VS
87 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
88 MODULE_VERSION(DRV_VERSION
);
89 MODULE_AUTHOR(DRV_COPYRIGHT
);
90 MODULE_LICENSE("GPL");
92 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
94 u16 fc
= le16_to_cpu(hdr
->frame_control
);
95 int hdr_len
= ieee80211_get_hdrlen(fc
);
97 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
98 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
102 static const struct ieee80211_supported_band
*iwl_get_hw_mode(
103 struct iwl_priv
*priv
, enum ieee80211_band band
)
105 return priv
->hw
->wiphy
->bands
[band
];
108 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
110 /* Single white space is for Linksys APs */
111 if (essid_len
== 1 && essid
[0] == ' ')
114 /* Otherwise, if the entire essid is 0, we assume it is hidden */
117 if (essid
[essid_len
] != '\0')
124 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
126 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
127 const char *s
= essid
;
130 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
131 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
135 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
136 while (essid_len
--) {
148 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
151 * Theory of operation
153 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
154 * of buffer descriptors, each of which points to one or more data buffers for
155 * the device to read from or fill. Driver and device exchange status of each
156 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
157 * entries in each circular buffer, to protect against confusing empty and full
160 * The device reads or writes the data in the queues via the device's several
161 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
163 * For Tx queue, there are low mark and high mark limits. If, after queuing
164 * the packet for Tx, free space become < low mark, Tx queue stopped. When
165 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
168 * The 4965 operates with up to 17 queues: One receive queue, one transmit
169 * queue (#4) for sending commands to the device firmware, and 15 other
170 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
172 * See more detailed info in iwl-4965-hw.h.
173 ***************************************************/
175 int iwl4965_queue_space(const struct iwl4965_queue
*q
)
177 int s
= q
->read_ptr
- q
->write_ptr
;
179 if (q
->read_ptr
> q
->write_ptr
)
184 /* keep some reserve to not confuse empty and full situations */
192 static inline int x2_queue_used(const struct iwl4965_queue
*q
, int i
)
194 return q
->write_ptr
> q
->read_ptr
?
195 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
196 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
199 static inline u8
get_cmd_index(struct iwl4965_queue
*q
, u32 index
, int is_huge
)
201 /* This is for scan command, the big buffer at end of command array */
203 return q
->n_window
; /* must be power of 2 */
205 /* Otherwise, use normal size buffers */
206 return index
& (q
->n_window
- 1);
210 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
212 static int iwl4965_queue_init(struct iwl_priv
*priv
, struct iwl4965_queue
*q
,
213 int count
, int slots_num
, u32 id
)
216 q
->n_window
= slots_num
;
219 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
220 * and iwl_queue_dec_wrap are broken. */
221 BUG_ON(!is_power_of_2(count
));
223 /* slots_num must be power-of-two size, otherwise
224 * get_cmd_index is broken. */
225 BUG_ON(!is_power_of_2(slots_num
));
227 q
->low_mark
= q
->n_window
/ 4;
231 q
->high_mark
= q
->n_window
/ 8;
232 if (q
->high_mark
< 2)
235 q
->write_ptr
= q
->read_ptr
= 0;
241 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
243 static int iwl4965_tx_queue_alloc(struct iwl_priv
*priv
,
244 struct iwl4965_tx_queue
*txq
, u32 id
)
246 struct pci_dev
*dev
= priv
->pci_dev
;
248 /* Driver private data, only for Tx (not command) queues,
249 * not shared with device. */
250 if (id
!= IWL_CMD_QUEUE_NUM
) {
251 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
252 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
254 IWL_ERROR("kmalloc for auxiliary BD "
255 "structures failed\n");
261 /* Circular buffer of transmit frame descriptors (TFDs),
262 * shared with device */
263 txq
->bd
= pci_alloc_consistent(dev
,
264 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
268 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
269 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
286 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
288 int iwl4965_tx_queue_init(struct iwl_priv
*priv
,
289 struct iwl4965_tx_queue
*txq
, int slots_num
, u32 txq_id
)
291 struct pci_dev
*dev
= priv
->pci_dev
;
296 * Alloc buffer array for commands (Tx or other types of commands).
297 * For the command queue (#4), allocate command space + one big
298 * command for scan, since scan command is very huge; the system will
299 * not have two scans at the same time, so only one is needed.
300 * For normal Tx queues (all other queues), no super-size command
303 len
= sizeof(struct iwl_cmd
) * slots_num
;
304 if (txq_id
== IWL_CMD_QUEUE_NUM
)
305 len
+= IWL_MAX_SCAN_SIZE
;
306 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
310 /* Alloc driver data array and TFD circular buffer */
311 rc
= iwl4965_tx_queue_alloc(priv
, txq
, txq_id
);
313 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
317 txq
->need_update
= 0;
319 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
320 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
321 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
323 /* Initialize queue's high/low-water marks, and head/tail indexes */
324 iwl4965_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
326 /* Tell device where to find queue */
327 iwl4965_hw_tx_queue_init(priv
, txq
);
333 * iwl4965_tx_queue_free - Deallocate DMA queue.
334 * @txq: Transmit queue to deallocate.
336 * Empty queue by removing and destroying all BD's.
338 * 0-fill, but do not free "txq" descriptor structure.
340 void iwl4965_tx_queue_free(struct iwl_priv
*priv
, struct iwl4965_tx_queue
*txq
)
342 struct iwl4965_queue
*q
= &txq
->q
;
343 struct pci_dev
*dev
= priv
->pci_dev
;
349 /* first, empty all BD's */
350 for (; q
->write_ptr
!= q
->read_ptr
;
351 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
352 iwl4965_hw_txq_free_tfd(priv
, txq
);
354 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
355 if (q
->id
== IWL_CMD_QUEUE_NUM
)
356 len
+= IWL_MAX_SCAN_SIZE
;
358 /* De-alloc array of command/tx buffers */
359 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
361 /* De-alloc circular buffer of TFDs */
363 pci_free_consistent(dev
, sizeof(struct iwl4965_tfd_frame
) *
364 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
366 /* De-alloc array of per-TFD driver data */
372 /* 0-fill queue descriptor structure */
373 memset(txq
, 0, sizeof(*txq
));
376 const u8 iwl4965_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
378 /*************** STATION TABLE MANAGEMENT ****
379 * mac80211 should be examined to determine if sta_info is duplicating
380 * the functionality provided here
383 /**************************************************************/
385 #if 0 /* temporary disable till we add real remove station */
387 * iwl4965_remove_station - Remove driver's knowledge of station.
389 * NOTE: This does not remove station from device's station table.
391 static u8
iwl4965_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
393 int index
= IWL_INVALID_STATION
;
397 spin_lock_irqsave(&priv
->sta_lock
, flags
);
401 else if (is_broadcast_ether_addr(addr
))
402 index
= priv
->hw_params
.bcast_sta_id
;
404 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++)
405 if (priv
->stations
[i
].used
&&
406 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
412 if (unlikely(index
== IWL_INVALID_STATION
))
415 if (priv
->stations
[index
].used
) {
416 priv
->stations
[index
].used
= 0;
417 priv
->num_stations
--;
420 BUG_ON(priv
->num_stations
< 0);
423 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
429 * iwl4965_add_station_flags - Add station to tables in driver and device
431 u8
iwl4965_add_station_flags(struct iwl_priv
*priv
, const u8
*addr
,
432 int is_ap
, u8 flags
, void *ht_data
)
435 int index
= IWL_INVALID_STATION
;
436 struct iwl4965_station_entry
*station
;
437 unsigned long flags_spin
;
438 DECLARE_MAC_BUF(mac
);
440 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
443 else if (is_broadcast_ether_addr(addr
))
444 index
= priv
->hw_params
.bcast_sta_id
;
446 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
447 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
453 if (!priv
->stations
[i
].used
&&
454 index
== IWL_INVALID_STATION
)
459 /* These two conditions have the same outcome, but keep them separate
460 since they have different meanings */
461 if (unlikely(index
== IWL_INVALID_STATION
)) {
462 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
466 if (priv
->stations
[index
].used
&&
467 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
468 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
473 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
474 station
= &priv
->stations
[index
];
476 priv
->num_stations
++;
478 /* Set up the REPLY_ADD_STA command to send to device */
479 memset(&station
->sta
, 0, sizeof(struct iwl4965_addsta_cmd
));
480 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
481 station
->sta
.mode
= 0;
482 station
->sta
.sta
.sta_id
= index
;
483 station
->sta
.station_flags
= 0;
485 #ifdef CONFIG_IWL4965_HT
486 /* BCAST station and IBSS stations do not work in HT mode */
487 if (index
!= priv
->hw_params
.bcast_sta_id
&&
488 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
489 iwl4965_set_ht_add_station(priv
, index
,
490 (struct ieee80211_ht_info
*) ht_data
);
491 #endif /*CONFIG_IWL4965_HT*/
493 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
495 /* Add station to device's station table */
496 iwl4965_send_add_station(priv
, &station
->sta
, flags
);
503 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
506 * iwl4965_enqueue_hcmd - enqueue a uCode command
507 * @priv: device private data point
508 * @cmd: a point to the ucode command structure
510 * The function returns < 0 values to indicate the operation is
511 * failed. On success, it turns the index (> 0) of command in the
514 int iwl4965_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
516 struct iwl4965_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
517 struct iwl4965_queue
*q
= &txq
->q
;
518 struct iwl4965_tfd_frame
*tfd
;
520 struct iwl_cmd
*out_cmd
;
522 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
523 dma_addr_t phys_addr
;
527 /* If any of the command structures end up being larger than
528 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
529 * we will need to increase the size of the TFD entries */
530 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
531 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
533 if (iwl_is_rfkill(priv
)) {
534 IWL_DEBUG_INFO("Not sending command - RF KILL");
538 if (iwl4965_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
539 IWL_ERROR("No space for Tx\n");
543 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
545 tfd
= &txq
->bd
[q
->write_ptr
];
546 memset(tfd
, 0, sizeof(*tfd
));
548 control_flags
= (u32
*) tfd
;
550 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
551 out_cmd
= &txq
->cmd
[idx
];
553 out_cmd
->hdr
.cmd
= cmd
->id
;
554 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
555 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
557 /* At this point, the out_cmd now has all of the incoming cmd
560 out_cmd
->hdr
.flags
= 0;
561 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
562 INDEX_TO_SEQ(q
->write_ptr
));
563 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
564 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
566 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
567 offsetof(struct iwl_cmd
, hdr
);
568 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
570 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
571 "%d bytes at %d[%d]:%d\n",
572 get_cmd_string(out_cmd
->hdr
.cmd
),
573 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
574 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
576 txq
->need_update
= 1;
578 /* Set up entry in queue's byte count circular buffer */
579 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, 0);
581 /* Increment and update queue's write index */
582 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
583 ret
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
585 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
586 return ret
? ret
: idx
;
589 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
591 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
594 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
596 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
601 * iwl4965_rxon_add_station - add station into station table.
603 * there is only one AP station with id= IWL_AP_ID
604 * NOTE: mutex must be held before calling this fnction
606 static int iwl4965_rxon_add_station(struct iwl_priv
*priv
,
607 const u8
*addr
, int is_ap
)
611 /* Add station to device's station table */
612 #ifdef CONFIG_IWL4965_HT
613 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
614 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
617 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
618 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
619 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
622 #endif /* CONFIG_IWL4965_HT */
623 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
626 /* Set up default rate scaling table in device's station table */
627 iwl4965_add_station(priv
, addr
, is_ap
);
633 * iwl4965_check_rxon_cmd - validate RXON structure is valid
635 * NOTE: This is really only useful during development and can eventually
636 * be #ifdef'd out once the driver is stable and folks aren't actively
639 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
644 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
645 error
|= le32_to_cpu(rxon
->flags
&
646 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
647 RXON_FLG_RADAR_DETECT_MSK
));
649 IWL_WARNING("check 24G fields %d | %d\n",
652 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
653 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
655 IWL_WARNING("check 52 fields %d | %d\n",
657 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
659 IWL_WARNING("check 52 CCK %d | %d\n",
662 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
664 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
666 /* make sure basic rates 6Mbps and 1Mbps are supported */
667 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
668 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
670 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
672 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
674 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
676 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
677 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
679 IWL_WARNING("check CCK and short slot %d | %d\n",
682 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
683 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
685 IWL_WARNING("check CCK & auto detect %d | %d\n",
688 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
689 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
691 IWL_WARNING("check TGG and auto detect %d | %d\n",
695 IWL_WARNING("Tuning to channel %d\n",
696 le16_to_cpu(rxon
->channel
));
699 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
706 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
707 * @priv: staging_rxon is compared to active_rxon
709 * If the RXON structure is changing enough to require a new tune,
710 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
711 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
713 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
716 /* These items are only settable from the full RXON command */
717 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
718 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
719 priv
->active_rxon
.bssid_addr
) ||
720 compare_ether_addr(priv
->staging_rxon
.node_addr
,
721 priv
->active_rxon
.node_addr
) ||
722 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
723 priv
->active_rxon
.wlap_bssid_addr
) ||
724 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
725 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
726 (priv
->staging_rxon
.air_propagation
!=
727 priv
->active_rxon
.air_propagation
) ||
728 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
729 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
730 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
731 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
732 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
733 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
736 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
737 * be updated with the RXON_ASSOC command -- however only some
738 * flag transitions are allowed using RXON_ASSOC */
740 /* Check if we are not switching bands */
741 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
742 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
745 /* Check if we are switching association toggle */
746 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
747 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
754 * iwl4965_commit_rxon - commit staging_rxon to hardware
756 * The RXON command in staging_rxon is committed to the hardware and
757 * the active_rxon structure is updated with the new data. This
758 * function correctly transitions out of the RXON_ASSOC_MSK state if
759 * a HW tune is required based on the RXON structure changes.
761 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
763 /* cast away the const for active_rxon in this function */
764 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
765 DECLARE_MAC_BUF(mac
);
768 if (!iwl_is_alive(priv
))
771 /* always get timestamp with Rx frame */
772 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
774 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
776 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
780 /* If we don't need to send a full RXON, we can use
781 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
782 * and other flags for the current radio configuration. */
783 if (!iwl4965_full_rxon_required(priv
)) {
784 rc
= iwl_send_rxon_assoc(priv
);
786 IWL_ERROR("Error setting RXON_ASSOC "
787 "configuration (%d).\n", rc
);
791 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
796 /* station table will be cleared */
797 priv
->assoc_station_added
= 0;
799 /* If we are currently associated and the new config requires
800 * an RXON_ASSOC and the new config wants the associated mask enabled,
801 * we must clear the associated from the active configuration
802 * before we apply the new config */
803 if (iwl_is_associated(priv
) &&
804 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
805 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
806 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
808 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
809 sizeof(struct iwl4965_rxon_cmd
),
812 /* If the mask clearing failed then we set
813 * active_rxon back to what it was previously */
815 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
816 IWL_ERROR("Error clearing ASSOC_MSK on current "
817 "configuration (%d).\n", rc
);
822 IWL_DEBUG_INFO("Sending RXON\n"
823 "* with%s RXON_FILTER_ASSOC_MSK\n"
826 ((priv
->staging_rxon
.filter_flags
&
827 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
828 le16_to_cpu(priv
->staging_rxon
.channel
),
829 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
831 iwl4965_set_rxon_hwcrypto(priv
, !priv
->hw_params
.sw_crypto
);
832 /* Apply the new configuration */
833 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
834 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
836 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
840 iwlcore_clear_stations_table(priv
);
842 if (!priv
->error_recovering
)
843 priv
->start_calib
= 0;
845 iwl_init_sensitivity(priv
);
847 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
849 /* If we issue a new RXON command which required a tune then we must
850 * send a new TXPOWER command or we won't be able to Tx any frames */
851 rc
= iwl4965_hw_reg_send_txpower(priv
);
853 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
857 /* Add the broadcast address so we can send broadcast frames */
858 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
859 IWL_INVALID_STATION
) {
860 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
864 /* If we have set the ASSOC_MSK and we are in BSS mode then
865 * add the IWL_AP_ID to the station rate table */
866 if (iwl_is_associated(priv
) &&
867 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
868 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
869 == IWL_INVALID_STATION
) {
870 IWL_ERROR("Error adding AP address for transmit.\n");
873 priv
->assoc_station_added
= 1;
874 if (priv
->default_wep_key
&&
875 iwl_send_static_wepkey_cmd(priv
, 0))
876 IWL_ERROR("Could not send WEP static key.\n");
882 void iwl4965_update_chain_flags(struct iwl_priv
*priv
)
885 iwl_set_rxon_chain(priv
);
886 iwl4965_commit_rxon(priv
);
889 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
891 struct iwl4965_bt_cmd bt_cmd
= {
899 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
900 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
903 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
906 struct iwl4965_rx_packet
*res
;
907 struct iwl_host_cmd cmd
= {
908 .id
= REPLY_SCAN_ABORT_CMD
,
909 .meta
.flags
= CMD_WANT_SKB
,
912 /* If there isn't a scan actively going on in the hardware
913 * then we are in between scan bands and not actually
914 * actively scanning, so don't send the abort command */
915 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
916 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
920 rc
= iwl_send_cmd_sync(priv
, &cmd
);
922 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
926 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
927 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
928 /* The scan abort will return 1 for success or
929 * 2 for "failure". A failure condition can be
930 * due to simply not being in an active scan which
931 * can occur if we send the scan abort before we
932 * the microcode has notified us that a scan is
934 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
935 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
936 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
939 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
947 * Use: Sets the device's internal card state to enable, disable, or halt
949 * When in the 'enable' state the card operates as normal.
950 * When in the 'disable' state, the card enters into a low power mode.
951 * When in the 'halt' state, the card is shut down and must be fully
952 * restarted to come back on.
954 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
956 struct iwl_host_cmd cmd
= {
957 .id
= REPLY_CARD_STATE_CMD
,
960 .meta
.flags
= meta_flag
,
963 return iwl_send_cmd(priv
, &cmd
);
966 int iwl4965_send_add_station(struct iwl_priv
*priv
,
967 struct iwl4965_addsta_cmd
*sta
, u8 flags
)
969 struct iwl4965_rx_packet
*res
= NULL
;
971 struct iwl_host_cmd cmd
= {
973 .len
= sizeof(struct iwl4965_addsta_cmd
),
978 if (!(flags
& CMD_ASYNC
))
979 cmd
.meta
.flags
|= CMD_WANT_SKB
;
981 rc
= iwl_send_cmd(priv
, &cmd
);
983 if (rc
|| (flags
& CMD_ASYNC
))
986 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
987 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
988 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
994 switch (res
->u
.add_sta
.status
) {
995 case ADD_STA_SUCCESS_MSK
:
996 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1000 IWL_WARNING("REPLY_ADD_STA failed\n");
1005 priv
->alloc_rxb_skb
--;
1006 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1011 static void iwl4965_clear_free_frames(struct iwl_priv
*priv
)
1013 struct list_head
*element
;
1015 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1016 priv
->frames_count
);
1018 while (!list_empty(&priv
->free_frames
)) {
1019 element
= priv
->free_frames
.next
;
1021 kfree(list_entry(element
, struct iwl4965_frame
, list
));
1022 priv
->frames_count
--;
1025 if (priv
->frames_count
) {
1026 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1027 priv
->frames_count
);
1028 priv
->frames_count
= 0;
1032 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl_priv
*priv
)
1034 struct iwl4965_frame
*frame
;
1035 struct list_head
*element
;
1036 if (list_empty(&priv
->free_frames
)) {
1037 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1039 IWL_ERROR("Could not allocate frame!\n");
1043 priv
->frames_count
++;
1047 element
= priv
->free_frames
.next
;
1049 return list_entry(element
, struct iwl4965_frame
, list
);
1052 static void iwl4965_free_frame(struct iwl_priv
*priv
, struct iwl4965_frame
*frame
)
1054 memset(frame
, 0, sizeof(*frame
));
1055 list_add(&frame
->list
, &priv
->free_frames
);
1058 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
1059 struct ieee80211_hdr
*hdr
,
1060 const u8
*dest
, int left
)
1063 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
1064 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1065 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1068 if (priv
->ibss_beacon
->len
> left
)
1071 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1073 return priv
->ibss_beacon
->len
;
1076 static u8
iwl4965_rate_get_lowest_plcp(struct iwl_priv
*priv
)
1082 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1083 rate_mask
= priv
->active_rate_basic
& 0xF;
1085 rate_mask
= priv
->active_rate_basic
& 0xFF0;
1087 /* Find lowest valid rate */
1088 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1089 i
= iwl4965_rates
[i
].next_ieee
) {
1090 if (rate_mask
& (1 << i
))
1091 return iwl4965_rates
[i
].plcp
;
1094 /* No valid rate was found. Assign the lowest one */
1095 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1096 return IWL_RATE_1M_PLCP
;
1098 return IWL_RATE_6M_PLCP
;
1101 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
1103 struct iwl4965_frame
*frame
;
1104 unsigned int frame_size
;
1108 frame
= iwl4965_get_free_frame(priv
);
1111 IWL_ERROR("Could not obtain free frame buffer for beacon "
1116 rate
= iwl4965_rate_get_lowest_plcp(priv
);
1118 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
1120 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1123 iwl4965_free_frame(priv
, frame
);
1128 /******************************************************************************
1130 * Misc. internal state and helper functions
1132 ******************************************************************************/
1135 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1137 * return : set the bit for each supported rate insert in ie
1139 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1140 u16 basic_rate
, int *left
)
1142 u16 ret_rates
= 0, bit
;
1147 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1148 if (bit
& supported_rate
) {
1150 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
1151 ((bit
& basic_rate
) ? 0x80 : 0x00);
1155 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1163 #ifdef CONFIG_IWL4965_HT
1164 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
1165 struct ieee80211_bss_conf
*bss_conf
)
1167 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
1168 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
1169 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
1171 IWL_DEBUG_MAC80211("enter: \n");
1173 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
1175 if (!iwl_conf
->is_ht
)
1178 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
1180 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
1181 iwl_conf
->sgf
|= 0x1;
1182 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
1183 iwl_conf
->sgf
|= 0x2;
1185 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
1186 iwl_conf
->max_amsdu_size
=
1187 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
1189 iwl_conf
->supported_chan_width
=
1190 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
1191 iwl_conf
->extension_chan_offset
=
1192 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
1193 /* If no above or below channel supplied disable FAT channel */
1194 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
1195 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
1196 iwl_conf
->supported_chan_width
= 0;
1198 iwl_conf
->tx_mimo_ps_mode
=
1199 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
1200 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
1202 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
1203 iwl_conf
->tx_chan_width
=
1204 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
1205 iwl_conf
->ht_protection
=
1206 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
1207 iwl_conf
->non_GF_STA_present
=
1208 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
1210 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
1211 IWL_DEBUG_MAC80211("leave\n");
1214 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
1217 struct ieee80211_ht_cap
*ht_cap
;
1219 if (!sband
|| !sband
->ht_info
.ht_supported
)
1222 if (*left
< sizeof(struct ieee80211_ht_cap
))
1225 *pos
++ = sizeof(struct ieee80211_ht_cap
);
1226 ht_cap
= (struct ieee80211_ht_cap
*) pos
;
1228 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
1229 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
1230 ht_cap
->ampdu_params_info
=
1231 (sband
->ht_info
.ampdu_factor
& IEEE80211_HT_CAP_AMPDU_FACTOR
) |
1232 ((sband
->ht_info
.ampdu_density
<< 2) &
1233 IEEE80211_HT_CAP_AMPDU_DENSITY
);
1234 *left
-= sizeof(struct ieee80211_ht_cap
);
1237 static inline void iwl4965_ht_conf(struct iwl_priv
*priv
,
1238 struct ieee80211_bss_conf
*bss_conf
)
1241 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
1249 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1251 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
1252 enum ieee80211_band band
,
1253 struct ieee80211_mgmt
*frame
,
1254 int left
, int is_direct
)
1258 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1259 const struct ieee80211_supported_band
*sband
=
1260 iwl_get_hw_mode(priv
, band
);
1262 /* Make sure there is enough space for the probe request,
1263 * two mandatory IEs and the data */
1269 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1270 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1271 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1272 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1273 frame
->seq_ctrl
= 0;
1275 /* fill in our indirect SSID IE */
1282 pos
= &(frame
->u
.probe_req
.variable
[0]);
1283 *pos
++ = WLAN_EID_SSID
;
1286 /* fill in our direct SSID IE... */
1289 left
-= 2 + priv
->essid_len
;
1292 /* ... fill it in... */
1293 *pos
++ = WLAN_EID_SSID
;
1294 *pos
++ = priv
->essid_len
;
1295 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1296 pos
+= priv
->essid_len
;
1297 len
+= 2 + priv
->essid_len
;
1300 /* fill in supported rate */
1306 /* ... fill it in... */
1307 *pos
++ = WLAN_EID_SUPP_RATES
;
1310 /* exclude 60M rate */
1311 active_rates
= priv
->rates_mask
;
1312 active_rates
&= ~IWL_RATE_60M_MASK
;
1314 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1316 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1317 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1318 active_rate_basic
, &left
);
1319 active_rates
&= ~ret_rates
;
1321 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1322 active_rate_basic
, &left
);
1323 active_rates
&= ~ret_rates
;
1327 if (active_rates
== 0)
1330 /* fill in supported extended rate */
1335 /* ... fill it in... */
1336 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1338 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1339 active_rate_basic
, &left
);
1349 *pos
++ = WLAN_EID_HT_CAPABILITY
;
1352 iwl_ht_cap_to_ie(sband
, pos
, &left
);
1362 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
1363 struct iwl4965_qosparam_cmd
*qos
)
1366 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1367 sizeof(struct iwl4965_qosparam_cmd
), qos
);
1370 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
1372 unsigned long flags
;
1374 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1377 if (!priv
->qos_data
.qos_enable
)
1380 spin_lock_irqsave(&priv
->lock
, flags
);
1381 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1383 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1384 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1385 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1386 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1387 if (priv
->qos_data
.qos_active
)
1388 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1389 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1391 #ifdef CONFIG_IWL4965_HT
1392 if (priv
->current_ht_config
.is_ht
)
1393 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
1394 #endif /* CONFIG_IWL4965_HT */
1396 spin_unlock_irqrestore(&priv
->lock
, flags
);
1398 if (force
|| iwl_is_associated(priv
)) {
1399 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1400 priv
->qos_data
.qos_active
,
1401 priv
->qos_data
.def_qos_parm
.qos_flags
);
1403 iwl4965_send_qos_params_command(priv
,
1404 &(priv
->qos_data
.def_qos_parm
));
1408 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1410 /* Filter incoming packets to determine if they are targeted toward
1411 * this network, discarding packets coming from ourselves */
1412 switch (priv
->iw_mode
) {
1413 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
1414 /* packets from our adapter are dropped (echo) */
1415 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
1417 /* {broad,multi}cast packets to our IBSS go through */
1418 if (is_multicast_ether_addr(header
->addr1
))
1419 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
1420 /* packets to our adapter go through */
1421 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1422 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
1423 /* packets from our adapter are dropped (echo) */
1424 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
1426 /* {broad,multi}cast packets to our BSS go through */
1427 if (is_multicast_ether_addr(header
->addr1
))
1428 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
1429 /* packets to our adapter go through */
1430 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1438 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1440 static const char *iwl4965_get_tx_fail_reason(u32 status
)
1442 switch (status
& TX_STATUS_MSK
) {
1443 case TX_STATUS_SUCCESS
:
1445 TX_STATUS_ENTRY(SHORT_LIMIT
);
1446 TX_STATUS_ENTRY(LONG_LIMIT
);
1447 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
1448 TX_STATUS_ENTRY(MGMNT_ABORT
);
1449 TX_STATUS_ENTRY(NEXT_FRAG
);
1450 TX_STATUS_ENTRY(LIFE_EXPIRE
);
1451 TX_STATUS_ENTRY(DEST_PS
);
1452 TX_STATUS_ENTRY(ABORTED
);
1453 TX_STATUS_ENTRY(BT_RETRY
);
1454 TX_STATUS_ENTRY(STA_INVALID
);
1455 TX_STATUS_ENTRY(FRAG_DROPPED
);
1456 TX_STATUS_ENTRY(TID_DISABLE
);
1457 TX_STATUS_ENTRY(FRAME_FLUSHED
);
1458 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
1459 TX_STATUS_ENTRY(TX_LOCKED
);
1460 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
1467 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1469 * NOTE: priv->mutex is not required before calling this function
1471 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
1473 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1474 clear_bit(STATUS_SCANNING
, &priv
->status
);
1478 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1479 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1480 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1481 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1482 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1485 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1487 return test_bit(STATUS_SCANNING
, &priv
->status
);
1494 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1495 * @ms: amount of time to wait (in milliseconds) for scan to abort
1497 * NOTE: priv->mutex must be held before calling this function
1499 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1501 unsigned long now
= jiffies
;
1504 ret
= iwl4965_scan_cancel(priv
);
1506 mutex_unlock(&priv
->mutex
);
1507 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1508 test_bit(STATUS_SCANNING
, &priv
->status
))
1510 mutex_lock(&priv
->mutex
);
1512 return test_bit(STATUS_SCANNING
, &priv
->status
);
1518 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
1520 /* Reset ieee stats */
1522 /* We don't reset the net_device_stats (ieee->stats) on
1525 priv
->last_seq_num
= -1;
1526 priv
->last_frag_num
= -1;
1527 priv
->last_packet_time
= 0;
1529 iwl4965_scan_cancel(priv
);
1532 #define MAX_UCODE_BEACON_INTERVAL 4096
1533 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1535 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
1538 u16 beacon_factor
= 0;
1541 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1542 / MAX_UCODE_BEACON_INTERVAL
;
1543 new_val
= beacon_val
/ beacon_factor
;
1545 return cpu_to_le16(new_val
);
1548 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
1550 u64 interval_tm_unit
;
1552 unsigned long flags
;
1553 struct ieee80211_conf
*conf
= NULL
;
1556 conf
= ieee80211_get_hw_conf(priv
->hw
);
1558 spin_lock_irqsave(&priv
->lock
, flags
);
1559 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
1560 priv
->rxon_timing
.timestamp
.dw
[0] =
1561 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
1563 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1565 tsf
= priv
->timestamp
;
1567 beacon_int
= priv
->beacon_int
;
1568 spin_unlock_irqrestore(&priv
->lock
, flags
);
1570 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1571 if (beacon_int
== 0) {
1572 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1573 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1575 priv
->rxon_timing
.beacon_interval
=
1576 cpu_to_le16(beacon_int
);
1577 priv
->rxon_timing
.beacon_interval
=
1578 iwl4965_adjust_beacon_interval(
1579 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1582 priv
->rxon_timing
.atim_window
= 0;
1584 priv
->rxon_timing
.beacon_interval
=
1585 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1586 /* TODO: we need to get atim_window from upper stack
1587 * for now we set to 0 */
1588 priv
->rxon_timing
.atim_window
= 0;
1592 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1593 result
= do_div(tsf
, interval_tm_unit
);
1594 priv
->rxon_timing
.beacon_init_val
=
1595 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1598 ("beacon interval %d beacon timer %d beacon tim %d\n",
1599 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1600 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1601 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1604 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1606 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1607 IWL_ERROR("APs don't scan.\n");
1611 if (!iwl_is_ready_rf(priv
)) {
1612 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1616 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1617 IWL_DEBUG_SCAN("Scan already in progress.\n");
1621 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1622 IWL_DEBUG_SCAN("Scan request while abort pending. "
1627 IWL_DEBUG_INFO("Starting scan...\n");
1628 priv
->scan_bands
= 2;
1629 set_bit(STATUS_SCANNING
, &priv
->status
);
1630 priv
->scan_start
= jiffies
;
1631 priv
->scan_pass_start
= priv
->scan_start
;
1633 queue_work(priv
->workqueue
, &priv
->request_scan
);
1639 static void iwl4965_set_flags_for_phymode(struct iwl_priv
*priv
,
1640 enum ieee80211_band band
)
1642 if (band
== IEEE80211_BAND_5GHZ
) {
1643 priv
->staging_rxon
.flags
&=
1644 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1645 | RXON_FLG_CCK_MSK
);
1646 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1648 /* Copied from iwl4965_post_associate() */
1649 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1650 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1652 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1654 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
1655 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1657 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1658 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1659 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1664 * initialize rxon structure with default values from eeprom
1666 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
1668 const struct iwl_channel_info
*ch_info
;
1670 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
1672 switch (priv
->iw_mode
) {
1673 case IEEE80211_IF_TYPE_AP
:
1674 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1677 case IEEE80211_IF_TYPE_STA
:
1678 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
1679 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
1682 case IEEE80211_IF_TYPE_IBSS
:
1683 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
1684 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
1685 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
1686 RXON_FILTER_ACCEPT_GRP_MSK
;
1689 case IEEE80211_IF_TYPE_MNTR
:
1690 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
1691 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
1692 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
1695 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
1700 /* TODO: Figure out when short_preamble would be set and cache from
1702 if (!hw_to_local(priv
->hw
)->short_preamble
)
1703 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1705 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1708 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
1709 le16_to_cpu(priv
->staging_rxon
.channel
));
1712 ch_info
= &priv
->channel_info
[0];
1715 * in some case A channels are all non IBSS
1716 * in this case force B/G channel
1718 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
1719 !(is_channel_ibss(ch_info
)))
1720 ch_info
= &priv
->channel_info
[0];
1722 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
1723 priv
->band
= ch_info
->band
;
1725 iwl4965_set_flags_for_phymode(priv
, priv
->band
);
1727 priv
->staging_rxon
.ofdm_basic_rates
=
1728 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1729 priv
->staging_rxon
.cck_basic_rates
=
1730 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1732 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
1733 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
1734 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1735 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
1736 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
1737 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
1738 iwl_set_rxon_chain(priv
);
1741 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
1743 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
1744 const struct iwl_channel_info
*ch_info
;
1746 ch_info
= iwl_get_channel_info(priv
,
1748 le16_to_cpu(priv
->staging_rxon
.channel
));
1750 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
1751 IWL_ERROR("channel %d not IBSS channel\n",
1752 le16_to_cpu(priv
->staging_rxon
.channel
));
1757 priv
->iw_mode
= mode
;
1759 iwl4965_connection_init_rx_config(priv
);
1760 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1762 iwlcore_clear_stations_table(priv
);
1764 /* dont commit rxon if rf-kill is on*/
1765 if (!iwl_is_ready_rf(priv
))
1768 cancel_delayed_work(&priv
->scan_check
);
1769 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
1770 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1771 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1775 iwl4965_commit_rxon(priv
);
1780 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
1781 struct ieee80211_tx_control
*ctl
,
1782 struct iwl_cmd
*cmd
,
1783 struct sk_buff
*skb_frag
,
1786 struct iwl4965_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
1787 struct iwl_wep_key
*wepkey
;
1790 BUG_ON(ctl
->hw_key
->hw_key_idx
> 3);
1792 switch (keyinfo
->alg
) {
1794 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
1795 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
1796 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
1797 cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_AGG_CCMP_MSK
;
1798 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
1802 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
1803 ieee80211_get_tkip_key(keyinfo
->conf
, skb_frag
,
1804 IEEE80211_TKIP_P2_KEY
, cmd
->cmd
.tx
.key
);
1805 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
1809 wepkey
= &priv
->wep_keys
[ctl
->hw_key
->hw_key_idx
];
1810 cmd
->cmd
.tx
.sec_ctl
= 0;
1811 if (priv
->default_wep_key
) {
1812 /* the WEP key was sent as static */
1813 keyidx
= ctl
->hw_key
->hw_key_idx
;
1814 memcpy(&cmd
->cmd
.tx
.key
[3], wepkey
->key
,
1816 if (wepkey
->key_size
== WEP_KEY_LEN_128
)
1817 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
1819 /* the WEP key was sent as dynamic */
1820 keyidx
= keyinfo
->keyidx
;
1821 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
,
1823 if (keyinfo
->keylen
== WEP_KEY_LEN_128
)
1824 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
1827 cmd
->cmd
.tx
.sec_ctl
|= (TX_CMD_SEC_WEP
|
1828 (keyidx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
);
1830 IWL_DEBUG_TX("Configuring packet for WEP encryption "
1831 "with key %d\n", keyidx
);
1835 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
1841 * handle build REPLY_TX command notification.
1843 static void iwl4965_build_tx_cmd_basic(struct iwl_priv
*priv
,
1844 struct iwl_cmd
*cmd
,
1845 struct ieee80211_tx_control
*ctrl
,
1846 struct ieee80211_hdr
*hdr
,
1847 int is_unicast
, u8 std_id
)
1850 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1851 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
1853 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
1854 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
1855 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
1856 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
1857 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1858 if (ieee80211_is_probe_response(fc
) &&
1859 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
1860 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
1862 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
1863 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1866 if (ieee80211_is_back_request(fc
))
1867 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
1870 cmd
->cmd
.tx
.sta_id
= std_id
;
1871 if (ieee80211_get_morefrag(hdr
))
1872 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
1874 qc
= ieee80211_get_qos_ctrl(hdr
);
1876 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
1877 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
1879 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1881 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
1882 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
1883 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
1884 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
1885 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
1886 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
1889 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
1890 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
1892 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
1893 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
1894 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
1895 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
1896 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
1898 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
1900 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
1903 cmd
->cmd
.tx
.driver_txop
= 0;
1904 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
1905 cmd
->cmd
.tx
.next_frame_len
= 0;
1907 static void iwl_update_tx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
1909 /* 0 - mgmt, 1 - cnt, 2 - data */
1910 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
1911 priv
->tx_stats
[idx
].cnt
++;
1912 priv
->tx_stats
[idx
].bytes
+= len
;
1915 * iwl4965_get_sta_id - Find station's index within station table
1917 * If new IBSS station, create new entry in station table
1919 static int iwl4965_get_sta_id(struct iwl_priv
*priv
,
1920 struct ieee80211_hdr
*hdr
)
1923 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1924 DECLARE_MAC_BUF(mac
);
1926 /* If this frame is broadcast or management, use broadcast station id */
1927 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
1928 is_multicast_ether_addr(hdr
->addr1
))
1929 return priv
->hw_params
.bcast_sta_id
;
1931 switch (priv
->iw_mode
) {
1933 /* If we are a client station in a BSS network, use the special
1934 * AP station entry (that's the only station we communicate with) */
1935 case IEEE80211_IF_TYPE_STA
:
1938 /* If we are an AP, then find the station, or use BCAST */
1939 case IEEE80211_IF_TYPE_AP
:
1940 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
1941 if (sta_id
!= IWL_INVALID_STATION
)
1943 return priv
->hw_params
.bcast_sta_id
;
1945 /* If this frame is going out to an IBSS network, find the station,
1946 * or create a new station table entry */
1947 case IEEE80211_IF_TYPE_IBSS
:
1948 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
1949 if (sta_id
!= IWL_INVALID_STATION
)
1952 /* Create new station table entry */
1953 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
1954 0, CMD_ASYNC
, NULL
);
1956 if (sta_id
!= IWL_INVALID_STATION
)
1959 IWL_DEBUG_DROP("Station %s not in station map. "
1960 "Defaulting to broadcast...\n",
1961 print_mac(mac
, hdr
->addr1
));
1962 iwl_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
1963 return priv
->hw_params
.bcast_sta_id
;
1966 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
1967 return priv
->hw_params
.bcast_sta_id
;
1972 * start REPLY_TX command process
1974 static int iwl4965_tx_skb(struct iwl_priv
*priv
,
1975 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
1977 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1978 struct iwl4965_tfd_frame
*tfd
;
1980 int txq_id
= ctl
->queue
;
1981 struct iwl4965_tx_queue
*txq
= NULL
;
1982 struct iwl4965_queue
*q
= NULL
;
1983 dma_addr_t phys_addr
;
1984 dma_addr_t txcmd_phys
;
1985 dma_addr_t scratch_phys
;
1986 struct iwl_cmd
*out_cmd
= NULL
;
1987 u16 len
, idx
, len_org
;
1988 u8 id
, hdr_len
, unicast
;
1993 u8 wait_write_ptr
= 0;
1994 unsigned long flags
;
1997 spin_lock_irqsave(&priv
->lock
, flags
);
1998 if (iwl_is_rfkill(priv
)) {
1999 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2004 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2008 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2009 IWL_ERROR("ERROR: No TX rate available.\n");
2013 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2016 fc
= le16_to_cpu(hdr
->frame_control
);
2018 #ifdef CONFIG_IWLWIFI_DEBUG
2019 if (ieee80211_is_auth(fc
))
2020 IWL_DEBUG_TX("Sending AUTH frame\n");
2021 else if (ieee80211_is_assoc_request(fc
))
2022 IWL_DEBUG_TX("Sending ASSOC frame\n");
2023 else if (ieee80211_is_reassoc_request(fc
))
2024 IWL_DEBUG_TX("Sending REASSOC frame\n");
2027 /* drop all data frame if we are not associated */
2028 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
2029 (!iwl_is_associated(priv
) ||
2030 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
2031 !priv
->assoc_station_added
)) {
2032 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2036 spin_unlock_irqrestore(&priv
->lock
, flags
);
2038 hdr_len
= ieee80211_get_hdrlen(fc
);
2040 /* Find (or create) index into station table for destination station */
2041 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
2042 if (sta_id
== IWL_INVALID_STATION
) {
2043 DECLARE_MAC_BUF(mac
);
2045 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2046 print_mac(mac
, hdr
->addr1
));
2050 IWL_DEBUG_TX("station Id %d\n", sta_id
);
2052 qc
= ieee80211_get_qos_ctrl(hdr
);
2054 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2055 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2057 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2059 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2061 #ifdef CONFIG_IWL4965_HT
2062 /* aggregation is on for this <sta,tid> */
2063 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2064 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
2065 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
2066 #endif /* CONFIG_IWL4965_HT */
2069 /* Descriptor for chosen Tx queue */
2070 txq
= &priv
->txq
[txq_id
];
2073 spin_lock_irqsave(&priv
->lock
, flags
);
2075 /* Set up first empty TFD within this queue's circular TFD buffer */
2076 tfd
= &txq
->bd
[q
->write_ptr
];
2077 memset(tfd
, 0, sizeof(*tfd
));
2078 control_flags
= (u32
*) tfd
;
2079 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2081 /* Set up driver data for this TFD */
2082 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
2083 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2084 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2085 ctl
, sizeof(struct ieee80211_tx_control
));
2087 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2088 out_cmd
= &txq
->cmd
[idx
];
2089 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2090 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2093 * Set up the Tx-command (not MAC!) header.
2094 * Store the chosen Tx queue and TFD index within the sequence field;
2095 * after Tx, uCode's Tx response will return this value so driver can
2096 * locate the frame within the tx queue and do post-tx processing.
2098 out_cmd
->hdr
.cmd
= REPLY_TX
;
2099 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2100 INDEX_TO_SEQ(q
->write_ptr
)));
2102 /* Copy MAC header from skb into command buffer */
2103 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2106 * Use the first empty entry in this queue's command buffer array
2107 * to contain the Tx command and MAC header concatenated together
2108 * (payload data will be in another buffer).
2109 * Size of this varies, due to varying MAC header length.
2110 * If end is not dword aligned, we'll have 2 extra bytes at the end
2111 * of the MAC header (device reads on dword boundaries).
2112 * We'll tell device about this padding later.
2114 len
= priv
->hw_params
.tx_cmd_len
+
2115 sizeof(struct iwl_cmd_header
) + hdr_len
;
2118 len
= (len
+ 3) & ~3;
2125 /* Physical address of this Tx command's header (not MAC header!),
2126 * within command buffer array. */
2127 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2128 offsetof(struct iwl_cmd
, hdr
);
2130 /* Add buffer containing Tx command and MAC(!) header to TFD's
2132 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2134 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2135 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, sta_id
);
2137 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2138 * if any (802.11 null frames have no payload). */
2139 len
= skb
->len
- hdr_len
;
2141 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2142 len
, PCI_DMA_TODEVICE
);
2143 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2146 /* Tell 4965 about any 2-byte padding after MAC header */
2148 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
2150 /* Total # bytes to be transmitted */
2151 len
= (u16
)skb
->len
;
2152 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2154 /* TODO need this for burst mode later on */
2155 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2157 /* set is_hcca to 0; it probably will never be implemented */
2158 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2160 iwl_update_tx_stats(priv
, fc
, len
);
2162 scratch_phys
= txcmd_phys
+ sizeof(struct iwl_cmd_header
) +
2163 offsetof(struct iwl4965_tx_cmd
, scratch
);
2164 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
2165 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
2167 if (!ieee80211_get_morefrag(hdr
)) {
2168 txq
->need_update
= 1;
2170 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2171 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2175 txq
->need_update
= 0;
2178 iwl_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2179 sizeof(out_cmd
->cmd
.tx
));
2181 iwl_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2182 ieee80211_get_hdrlen(fc
));
2184 /* Set up entry for this TFD in Tx byte-count array */
2185 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, len
);
2187 /* Tell device the write index *just past* this latest filled TFD */
2188 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2189 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2190 spin_unlock_irqrestore(&priv
->lock
, flags
);
2195 if ((iwl4965_queue_space(q
) < q
->high_mark
)
2196 && priv
->mac80211_registered
) {
2197 if (wait_write_ptr
) {
2198 spin_lock_irqsave(&priv
->lock
, flags
);
2199 txq
->need_update
= 1;
2200 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2201 spin_unlock_irqrestore(&priv
->lock
, flags
);
2204 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2210 spin_unlock_irqrestore(&priv
->lock
, flags
);
2215 static void iwl4965_set_rate(struct iwl_priv
*priv
)
2217 const struct ieee80211_supported_band
*hw
= NULL
;
2218 struct ieee80211_rate
*rate
;
2221 hw
= iwl_get_hw_mode(priv
, priv
->band
);
2223 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2227 priv
->active_rate
= 0;
2228 priv
->active_rate_basic
= 0;
2230 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
2231 rate
= &(hw
->bitrates
[i
]);
2232 if (rate
->hw_value
< IWL_RATE_COUNT
)
2233 priv
->active_rate
|= (1 << rate
->hw_value
);
2236 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2237 priv
->active_rate
, priv
->active_rate_basic
);
2240 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2241 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2244 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2245 priv
->staging_rxon
.cck_basic_rates
=
2246 ((priv
->active_rate_basic
&
2247 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2249 priv
->staging_rxon
.cck_basic_rates
=
2250 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2252 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2253 priv
->staging_rxon
.ofdm_basic_rates
=
2254 ((priv
->active_rate_basic
&
2255 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2256 IWL_FIRST_OFDM_RATE
) & 0xFF;
2258 priv
->staging_rxon
.ofdm_basic_rates
=
2259 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2262 void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2264 unsigned long flags
;
2266 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2269 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2270 disable_radio
? "OFF" : "ON");
2272 if (disable_radio
) {
2273 iwl4965_scan_cancel(priv
);
2274 /* FIXME: This is a workaround for AP */
2275 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2276 spin_lock_irqsave(&priv
->lock
, flags
);
2277 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2278 CSR_UCODE_SW_BIT_RFKILL
);
2279 spin_unlock_irqrestore(&priv
->lock
, flags
);
2280 /* call the host command only if no hw rf-kill set */
2281 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
) &&
2283 iwl4965_send_card_state(priv
,
2284 CARD_STATE_CMD_DISABLE
,
2286 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2288 /* make sure mac80211 stop sending Tx frame */
2289 if (priv
->mac80211_registered
)
2290 ieee80211_stop_queues(priv
->hw
);
2295 spin_lock_irqsave(&priv
->lock
, flags
);
2296 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2298 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2299 spin_unlock_irqrestore(&priv
->lock
, flags
);
2304 spin_lock_irqsave(&priv
->lock
, flags
);
2305 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2306 if (!iwl_grab_nic_access(priv
))
2307 iwl_release_nic_access(priv
);
2308 spin_unlock_irqrestore(&priv
->lock
, flags
);
2310 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2311 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2312 "disabled by HW switch\n");
2316 queue_work(priv
->workqueue
, &priv
->restart
);
2320 #define IWL_PACKET_RETRY_TIME HZ
2322 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2324 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2325 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2326 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2327 u16
*last_seq
, *last_frag
;
2328 unsigned long *last_time
;
2330 switch (priv
->iw_mode
) {
2331 case IEEE80211_IF_TYPE_IBSS
:{
2332 struct list_head
*p
;
2333 struct iwl4965_ibss_seq
*entry
= NULL
;
2334 u8
*mac
= header
->addr2
;
2335 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2337 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2338 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
2339 if (!compare_ether_addr(entry
->mac
, mac
))
2342 if (p
== &priv
->ibss_mac_hash
[index
]) {
2343 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2345 IWL_ERROR("Cannot malloc new mac entry\n");
2348 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2349 entry
->seq_num
= seq
;
2350 entry
->frag_num
= frag
;
2351 entry
->packet_time
= jiffies
;
2352 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2355 last_seq
= &entry
->seq_num
;
2356 last_frag
= &entry
->frag_num
;
2357 last_time
= &entry
->packet_time
;
2360 case IEEE80211_IF_TYPE_STA
:
2361 last_seq
= &priv
->last_seq_num
;
2362 last_frag
= &priv
->last_frag_num
;
2363 last_time
= &priv
->last_packet_time
;
2368 if ((*last_seq
== seq
) &&
2369 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
2370 if (*last_frag
== frag
)
2372 if (*last_frag
+ 1 != frag
)
2373 /* out-of-order fragment */
2379 *last_time
= jiffies
;
2386 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2388 #include "iwl-spectrum.h"
2390 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2391 #define BEACON_TIME_MASK_HIGH 0xFF000000
2392 #define TIME_UNIT 1024
2395 * extended beacon time format
2396 * time in usec will be changed into a 32-bit value in 8:24 format
2397 * the high 1 byte is the beacon counts
2398 * the lower 3 bytes is the time in usec within one beacon interval
2401 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2405 u32 interval
= beacon_interval
* 1024;
2407 if (!interval
|| !usec
)
2410 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2411 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2413 return (quot
<< 24) + rem
;
2416 /* base is usually what we get from ucode with each received frame,
2417 * the same as HW timer counter counting down
2420 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2422 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2423 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2424 u32 interval
= beacon_interval
* TIME_UNIT
;
2425 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2426 (addon
& BEACON_TIME_MASK_HIGH
);
2428 if (base_low
> addon_low
)
2429 res
+= base_low
- addon_low
;
2430 else if (base_low
< addon_low
) {
2431 res
+= interval
+ base_low
- addon_low
;
2436 return cpu_to_le32(res
);
2439 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
2440 struct ieee80211_measurement_params
*params
,
2443 struct iwl4965_spectrum_cmd spectrum
;
2444 struct iwl4965_rx_packet
*res
;
2445 struct iwl_host_cmd cmd
= {
2446 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2447 .data
= (void *)&spectrum
,
2448 .meta
.flags
= CMD_WANT_SKB
,
2450 u32 add_time
= le64_to_cpu(params
->start_time
);
2452 int spectrum_resp_status
;
2453 int duration
= le16_to_cpu(params
->duration
);
2455 if (iwl_is_associated(priv
))
2457 iwl4965_usecs_to_beacons(
2458 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2459 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2461 memset(&spectrum
, 0, sizeof(spectrum
));
2463 spectrum
.channel_count
= cpu_to_le16(1);
2465 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2466 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2467 cmd
.len
= sizeof(spectrum
);
2468 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2470 if (iwl_is_associated(priv
))
2471 spectrum
.start_time
=
2472 iwl4965_add_beacon_time(priv
->last_beacon_time
,
2474 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2476 spectrum
.start_time
= 0;
2478 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2479 spectrum
.channels
[0].channel
= params
->channel
;
2480 spectrum
.channels
[0].type
= type
;
2481 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2482 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2483 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2485 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2489 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2490 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2491 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2495 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2496 switch (spectrum_resp_status
) {
2497 case 0: /* Command will be handled */
2498 if (res
->u
.spectrum
.id
!= 0xff) {
2500 ("Replaced existing measurement: %d\n",
2501 res
->u
.spectrum
.id
);
2502 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2504 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2508 case 1: /* Command will not be handled */
2513 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2519 static void iwl4965_txstatus_to_ieee(struct iwl_priv
*priv
,
2520 struct iwl4965_tx_info
*tx_sta
)
2523 tx_sta
->status
.ack_signal
= 0;
2524 tx_sta
->status
.excessive_retries
= 0;
2525 tx_sta
->status
.queue_length
= 0;
2526 tx_sta
->status
.queue_number
= 0;
2529 ieee80211_tx_status_irqsafe(priv
->hw
,
2530 tx_sta
->skb
[0], &(tx_sta
->status
));
2532 ieee80211_tx_status(priv
->hw
,
2533 tx_sta
->skb
[0], &(tx_sta
->status
));
2535 tx_sta
->skb
[0] = NULL
;
2539 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2541 * When FW advances 'R' index, all entries between old and new 'R' index
2542 * need to be reclaimed. As result, some free space forms. If there is
2543 * enough free space (> low mark), wake the stack that feeds us.
2545 int iwl4965_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
2547 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2548 struct iwl4965_queue
*q
= &txq
->q
;
2551 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
2552 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2553 "is out of range [0-%d] %d %d.\n", txq_id
,
2554 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2558 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
2559 q
->read_ptr
!= index
;
2560 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2561 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
2562 iwl4965_txstatus_to_ieee(priv
,
2563 &(txq
->txb
[txq
->q
.read_ptr
]));
2564 iwl4965_hw_txq_free_tfd(priv
, txq
);
2565 } else if (nfreed
> 1) {
2566 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
2567 q
->write_ptr
, q
->read_ptr
);
2568 queue_work(priv
->workqueue
, &priv
->restart
);
2573 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2574 (txq_id != IWL_CMD_QUEUE_NUM) &&
2575 priv->mac80211_registered)
2576 ieee80211_wake_queue(priv->hw, txq_id); */
2582 static int iwl4965_is_tx_success(u32 status
)
2584 status
&= TX_STATUS_MSK
;
2585 return (status
== TX_STATUS_SUCCESS
)
2586 || (status
== TX_STATUS_DIRECT_DONE
);
2589 /******************************************************************************
2591 * Generic RX handler implementations
2593 ******************************************************************************/
2594 #ifdef CONFIG_IWL4965_HT
2596 static inline int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
,
2597 struct ieee80211_hdr
*hdr
)
2599 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
2602 u8
*da
= ieee80211_get_DA(hdr
);
2603 return iwl_find_station(priv
, da
);
2607 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
2608 struct iwl_priv
*priv
, int txq_id
, int idx
)
2610 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
2611 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
2612 txb
[idx
].skb
[0]->data
;
2616 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
2618 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
2619 tx_resp
->frame_count
);
2620 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
2625 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2627 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
2628 struct iwl4965_ht_agg
*agg
,
2629 struct iwl4965_tx_resp_agg
*tx_resp
,
2633 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
2634 struct ieee80211_tx_status
*tx_status
= NULL
;
2635 struct ieee80211_hdr
*hdr
= NULL
;
2640 if (agg
->wait_for_ba
)
2641 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2643 agg
->frame_count
= tx_resp
->frame_count
;
2644 agg
->start_idx
= start_idx
;
2645 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2648 /* # frames attempted by Tx command */
2649 if (agg
->frame_count
== 1) {
2650 /* Only one frame was attempted; no block-ack will arrive */
2651 status
= le16_to_cpu(frame_status
[0].status
);
2652 seq
= le16_to_cpu(frame_status
[0].sequence
);
2653 idx
= SEQ_TO_INDEX(seq
);
2654 txq_id
= SEQ_TO_QUEUE(seq
);
2656 /* FIXME: code repetition */
2657 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2658 agg
->frame_count
, agg
->start_idx
, idx
);
2660 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
2661 tx_status
->retry_count
= tx_resp
->failure_frame
;
2662 tx_status
->queue_number
= status
& 0xff;
2663 tx_status
->queue_length
= tx_resp
->failure_rts
;
2664 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
2665 tx_status
->flags
= iwl4965_is_tx_success(status
)?
2666 IEEE80211_TX_STATUS_ACK
: 0;
2667 iwl4965_hwrate_to_tx_control(priv
,
2668 le32_to_cpu(tx_resp
->rate_n_flags
),
2669 &tx_status
->control
);
2670 /* FIXME: code repetition end */
2672 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2673 status
& 0xff, tx_resp
->failure_frame
);
2674 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
2675 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
2677 agg
->wait_for_ba
= 0;
2679 /* Two or more frames were attempted; expect block-ack */
2681 int start
= agg
->start_idx
;
2683 /* Construct bit-map of pending frames within Tx window */
2684 for (i
= 0; i
< agg
->frame_count
; i
++) {
2686 status
= le16_to_cpu(frame_status
[i
].status
);
2687 seq
= le16_to_cpu(frame_status
[i
].sequence
);
2688 idx
= SEQ_TO_INDEX(seq
);
2689 txq_id
= SEQ_TO_QUEUE(seq
);
2691 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
2692 AGG_TX_STATE_ABORT_MSK
))
2695 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2696 agg
->frame_count
, txq_id
, idx
);
2698 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
2700 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2701 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
2702 IWL_ERROR("BUG_ON idx doesn't match seq control"
2703 " idx=%d, seq_idx=%d, seq=%d\n",
2709 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2710 i
, idx
, SEQ_TO_SN(sc
));
2714 sh
= (start
- idx
) + 0xff;
2715 bitmap
= bitmap
<< sh
;
2718 } else if (sh
< -64)
2719 sh
= 0xff - (start
- idx
);
2723 bitmap
= bitmap
<< sh
;
2726 bitmap
|= (1 << sh
);
2727 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
2728 start
, (u32
)(bitmap
& 0xFFFFFFFF));
2731 agg
->bitmap
= bitmap
;
2732 agg
->start_idx
= start
;
2733 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2734 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2735 agg
->frame_count
, agg
->start_idx
,
2736 (unsigned long long)agg
->bitmap
);
2739 agg
->wait_for_ba
= 1;
2746 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
2748 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
2749 struct iwl4965_rx_mem_buffer
*rxb
)
2751 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2752 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
2753 int txq_id
= SEQ_TO_QUEUE(sequence
);
2754 int index
= SEQ_TO_INDEX(sequence
);
2755 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2756 struct ieee80211_tx_status
*tx_status
;
2757 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
2758 u32 status
= le32_to_cpu(tx_resp
->status
);
2759 #ifdef CONFIG_IWL4965_HT
2760 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
2761 struct ieee80211_hdr
*hdr
;
2765 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
2766 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
2767 "is out of range [0-%d] %d %d\n", txq_id
,
2768 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
2773 #ifdef CONFIG_IWL4965_HT
2774 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
2775 qc
= ieee80211_get_qos_ctrl(hdr
);
2778 tid
= le16_to_cpu(*qc
) & 0xf;
2780 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
2781 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
2782 IWL_ERROR("Station not known\n");
2786 if (txq
->sched_retry
) {
2787 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
2788 struct iwl4965_ht_agg
*agg
= NULL
;
2793 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
2795 iwl4965_tx_status_reply_tx(priv
, agg
,
2796 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
2798 if ((tx_resp
->frame_count
== 1) &&
2799 !iwl4965_is_tx_success(status
)) {
2800 /* TODO: send BAR */
2803 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
2805 index
= iwl_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
2806 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
2807 "%d index %d\n", scd_ssn
, index
);
2808 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
2809 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
2811 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
2812 txq_id
>= 0 && priv
->mac80211_registered
&&
2813 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
2814 ieee80211_wake_queue(priv
->hw
, txq_id
);
2816 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
2819 #endif /* CONFIG_IWL4965_HT */
2820 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
2822 tx_status
->retry_count
= tx_resp
->failure_frame
;
2823 tx_status
->queue_number
= status
;
2824 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
2825 tx_status
->queue_length
|= tx_resp
->failure_rts
;
2827 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
2828 iwl4965_hwrate_to_tx_control(priv
, le32_to_cpu(tx_resp
->rate_n_flags
),
2829 &tx_status
->control
);
2831 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
2832 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
2833 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
2834 tx_resp
->failure_frame
);
2836 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
2838 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
2839 #ifdef CONFIG_IWL4965_HT
2840 if (tid
!= MAX_TID_COUNT
)
2841 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
2842 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
2844 priv
->mac80211_registered
)
2845 ieee80211_wake_queue(priv
->hw
, txq_id
);
2846 if (tid
!= MAX_TID_COUNT
)
2847 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
2850 #ifdef CONFIG_IWL4965_HT
2852 #endif /* CONFIG_IWL4965_HT */
2854 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
2855 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
2859 static void iwl4965_rx_reply_alive(struct iwl_priv
*priv
,
2860 struct iwl4965_rx_mem_buffer
*rxb
)
2862 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2863 struct iwl4965_alive_resp
*palive
;
2864 struct delayed_work
*pwork
;
2866 palive
= &pkt
->u
.alive_frame
;
2868 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
2870 palive
->is_valid
, palive
->ver_type
,
2871 palive
->ver_subtype
);
2873 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
2874 IWL_DEBUG_INFO("Initialization Alive received.\n");
2875 memcpy(&priv
->card_alive_init
,
2876 &pkt
->u
.alive_frame
,
2877 sizeof(struct iwl4965_init_alive_resp
));
2878 pwork
= &priv
->init_alive_start
;
2880 IWL_DEBUG_INFO("Runtime Alive received.\n");
2881 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
2882 sizeof(struct iwl4965_alive_resp
));
2883 pwork
= &priv
->alive_start
;
2886 /* We delay the ALIVE response by 5ms to
2887 * give the HW RF Kill time to activate... */
2888 if (palive
->is_valid
== UCODE_VALID_OK
)
2889 queue_delayed_work(priv
->workqueue
, pwork
,
2890 msecs_to_jiffies(5));
2892 IWL_WARNING("uCode did not respond OK.\n");
2895 static void iwl4965_rx_reply_add_sta(struct iwl_priv
*priv
,
2896 struct iwl4965_rx_mem_buffer
*rxb
)
2898 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2900 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
2904 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
2905 struct iwl4965_rx_mem_buffer
*rxb
)
2907 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2909 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
2910 "seq 0x%04X ser 0x%08X\n",
2911 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
2912 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
2913 pkt
->u
.err_resp
.cmd_id
,
2914 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
2915 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
2918 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2920 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
2922 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2923 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
2924 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
2925 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2926 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
2927 rxon
->channel
= csa
->channel
;
2928 priv
->staging_rxon
.channel
= csa
->channel
;
2931 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
2932 struct iwl4965_rx_mem_buffer
*rxb
)
2934 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2935 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2936 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
2938 if (!report
->state
) {
2939 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
2940 "Spectrum Measure Notification: Start\n");
2944 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
2945 priv
->measurement_status
|= MEASUREMENT_READY
;
2949 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
2950 struct iwl4965_rx_mem_buffer
*rxb
)
2952 #ifdef CONFIG_IWLWIFI_DEBUG
2953 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2954 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
2955 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2956 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
2960 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
2961 struct iwl4965_rx_mem_buffer
*rxb
)
2963 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2964 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2965 "notification for %s:\n",
2966 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
2967 iwl_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
2970 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
2972 struct iwl_priv
*priv
=
2973 container_of(work
, struct iwl_priv
, beacon_update
);
2974 struct sk_buff
*beacon
;
2976 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
2977 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
2980 IWL_ERROR("update beacon failed\n");
2984 mutex_lock(&priv
->mutex
);
2985 /* new beacon skb is allocated every time; dispose previous.*/
2986 if (priv
->ibss_beacon
)
2987 dev_kfree_skb(priv
->ibss_beacon
);
2989 priv
->ibss_beacon
= beacon
;
2990 mutex_unlock(&priv
->mutex
);
2992 iwl4965_send_beacon_cmd(priv
);
2995 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
2996 struct iwl4965_rx_mem_buffer
*rxb
)
2998 #ifdef CONFIG_IWLWIFI_DEBUG
2999 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3000 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3001 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
3003 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3004 "tsf %d %d rate %d\n",
3005 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3006 beacon
->beacon_notify_hdr
.failure_frame
,
3007 le32_to_cpu(beacon
->ibss_mgr_status
),
3008 le32_to_cpu(beacon
->high_tsf
),
3009 le32_to_cpu(beacon
->low_tsf
), rate
);
3012 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3013 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3014 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3017 /* Service response to REPLY_SCAN_CMD (0x80) */
3018 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
3019 struct iwl4965_rx_mem_buffer
*rxb
)
3021 #ifdef CONFIG_IWLWIFI_DEBUG
3022 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3023 struct iwl4965_scanreq_notification
*notif
=
3024 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
3026 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3030 /* Service SCAN_START_NOTIFICATION (0x82) */
3031 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
3032 struct iwl4965_rx_mem_buffer
*rxb
)
3034 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3035 struct iwl4965_scanstart_notification
*notif
=
3036 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
3037 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3038 IWL_DEBUG_SCAN("Scan start: "
3040 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3042 notif
->band
? "bg" : "a",
3044 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3047 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3048 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
3049 struct iwl4965_rx_mem_buffer
*rxb
)
3051 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3052 struct iwl4965_scanresults_notification
*notif
=
3053 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
3055 IWL_DEBUG_SCAN("Scan ch.res: "
3057 "(TSF: 0x%08X:%08X) - %d "
3058 "elapsed=%lu usec (%dms since last)\n",
3060 notif
->band
? "bg" : "a",
3061 le32_to_cpu(notif
->tsf_high
),
3062 le32_to_cpu(notif
->tsf_low
),
3063 le32_to_cpu(notif
->statistics
[0]),
3064 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3065 jiffies_to_msecs(elapsed_jiffies
3066 (priv
->last_scan_jiffies
, jiffies
)));
3068 priv
->last_scan_jiffies
= jiffies
;
3069 priv
->next_scan_jiffies
= 0;
3072 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3073 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
3074 struct iwl4965_rx_mem_buffer
*rxb
)
3076 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3077 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3079 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3080 scan_notif
->scanned_channels
,
3081 scan_notif
->tsf_low
,
3082 scan_notif
->tsf_high
, scan_notif
->status
);
3084 /* The HW is no longer scanning */
3085 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3087 /* The scan completion notification came in, so kill that timer... */
3088 cancel_delayed_work(&priv
->scan_check
);
3090 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3091 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
3092 jiffies_to_msecs(elapsed_jiffies
3093 (priv
->scan_pass_start
, jiffies
)));
3095 /* Remove this scanned band from the list
3096 * of pending bands to scan */
3099 /* If a request to abort was given, or the scan did not succeed
3100 * then we reset the scan state machine and terminate,
3101 * re-queuing another scan if one has been requested */
3102 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3103 IWL_DEBUG_INFO("Aborted scan completed.\n");
3104 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3106 /* If there are more bands on this scan pass reschedule */
3107 if (priv
->scan_bands
> 0)
3111 priv
->last_scan_jiffies
= jiffies
;
3112 priv
->next_scan_jiffies
= 0;
3113 IWL_DEBUG_INFO("Setting scan to off\n");
3115 clear_bit(STATUS_SCANNING
, &priv
->status
);
3117 IWL_DEBUG_INFO("Scan took %dms\n",
3118 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3120 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3125 priv
->scan_pass_start
= jiffies
;
3126 queue_work(priv
->workqueue
, &priv
->request_scan
);
3129 /* Handle notification from uCode that card's power state is changing
3130 * due to software, hardware, or critical temperature RFKILL */
3131 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
3132 struct iwl4965_rx_mem_buffer
*rxb
)
3134 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3135 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3136 unsigned long status
= priv
->status
;
3138 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3139 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3140 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3142 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
3143 RF_CARD_DISABLED
)) {
3145 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3146 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3148 if (!iwl_grab_nic_access(priv
)) {
3150 priv
, HBUS_TARG_MBX_C
,
3151 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3153 iwl_release_nic_access(priv
);
3156 if (!(flags
& RXON_CARD_DISABLED
)) {
3157 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
3158 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3159 if (!iwl_grab_nic_access(priv
)) {
3161 priv
, HBUS_TARG_MBX_C
,
3162 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3164 iwl_release_nic_access(priv
);
3168 if (flags
& RF_CARD_DISABLED
) {
3169 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3170 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
3171 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3172 if (!iwl_grab_nic_access(priv
))
3173 iwl_release_nic_access(priv
);
3177 if (flags
& HW_CARD_DISABLED
)
3178 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3180 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3183 if (flags
& SW_CARD_DISABLED
)
3184 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3186 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3188 if (!(flags
& RXON_CARD_DISABLED
))
3189 iwl4965_scan_cancel(priv
);
3191 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3192 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3193 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3194 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3195 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3197 wake_up_interruptible(&priv
->wait_command_queue
);
3201 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3203 * Setup the RX handlers for each of the reply types sent from the uCode
3206 * This function chains into the hardware specific files for them to setup
3207 * any hardware specific handlers as well.
3209 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
3211 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
3212 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
3213 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
3214 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
3215 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3216 iwl4965_rx_spectrum_measure_notif
;
3217 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
3218 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3219 iwl4965_rx_pm_debug_statistics_notif
;
3220 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
3223 * The same handler is used for both the REPLY to a discrete
3224 * statistics request from the host as well as for the periodic
3225 * statistics notifications (after received beacons) from the uCode.
3227 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
3228 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
3230 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
3231 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
3232 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3233 iwl4965_rx_scan_results_notif
;
3234 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3235 iwl4965_rx_scan_complete_notif
;
3236 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
3237 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
3239 /* Set up hardware specific Rx handlers */
3240 priv
->cfg
->ops
->lib
->rx_handler_setup(priv
);
3244 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3245 * @rxb: Rx buffer to reclaim
3247 * If an Rx buffer has an async callback associated with it the callback
3248 * will be executed. The attached skb (if present) will only be freed
3249 * if the callback returns 1
3251 static void iwl4965_tx_cmd_complete(struct iwl_priv
*priv
,
3252 struct iwl4965_rx_mem_buffer
*rxb
)
3254 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3255 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3256 int txq_id
= SEQ_TO_QUEUE(sequence
);
3257 int index
= SEQ_TO_INDEX(sequence
);
3258 int huge
= sequence
& SEQ_HUGE_FRAME
;
3260 struct iwl_cmd
*cmd
;
3262 /* If a Tx command is being handled and it isn't in the actual
3263 * command queue then there a command routing bug has been introduced
3264 * in the queue management code. */
3265 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3266 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3267 txq_id
, pkt
->hdr
.cmd
);
3268 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3270 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3271 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3273 /* Input error checking is done when commands are added to queue. */
3274 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3275 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3277 } else if (cmd
->meta
.u
.callback
&&
3278 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3281 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3283 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3284 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3285 wake_up_interruptible(&priv
->wait_command_queue
);
3289 /************************** RX-FUNCTIONS ****************************/
3291 * Rx theory of operation
3293 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3294 * each of which point to Receive Buffers to be filled by 4965. These get
3295 * used not only for Rx frames, but for any command response or notification
3296 * from the 4965. The driver and 4965 manage the Rx buffers by means
3297 * of indexes into the circular buffer.
3300 * The host/firmware share two index registers for managing the Rx buffers.
3302 * The READ index maps to the first position that the firmware may be writing
3303 * to -- the driver can read up to (but not including) this position and get
3305 * The READ index is managed by the firmware once the card is enabled.
3307 * The WRITE index maps to the last position the driver has read from -- the
3308 * position preceding WRITE is the last slot the firmware can place a packet.
3310 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3313 * During initialization, the host sets up the READ queue position to the first
3314 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3316 * When the firmware places a packet in a buffer, it will advance the READ index
3317 * and fire the RX interrupt. The driver can then query the READ index and
3318 * process as many packets as possible, moving the WRITE index forward as it
3319 * resets the Rx queue buffers with new memory.
3321 * The management in the driver is as follows:
3322 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3323 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3324 * to replenish the iwl->rxq->rx_free.
3325 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3326 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3327 * 'processed' and 'read' driver indexes as well)
3328 * + A received packet is processed and handed to the kernel network stack,
3329 * detached from the iwl->rxq. The driver 'processed' index is updated.
3330 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3331 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3332 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3333 * were enough free buffers and RX_STALLED is set it is cleared.
3338 * iwl4965_rx_queue_alloc() Allocates rx_free
3339 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3340 * iwl4965_rx_queue_restock
3341 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3342 * queue, updates firmware pointers, and updates
3343 * the WRITE index. If insufficient rx_free buffers
3344 * are available, schedules iwl4965_rx_replenish
3346 * -- enable interrupts --
3347 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3348 * READ INDEX, detaching the SKB from the pool.
3349 * Moves the packet buffer from queue to rx_used.
3350 * Calls iwl4965_rx_queue_restock to refill any empty
3357 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3359 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue
*q
)
3361 int s
= q
->read
- q
->write
;
3364 /* keep some buffer to not confuse full and empty queue */
3372 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3374 int iwl4965_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*q
)
3378 unsigned long flags
;
3380 spin_lock_irqsave(&q
->lock
, flags
);
3382 if (q
->need_update
== 0)
3385 /* If power-saving is in use, make sure device is awake */
3386 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3387 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3389 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3390 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3391 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3395 rc
= iwl_grab_nic_access(priv
);
3399 /* Device expects a multiple of 8 */
3400 iwl_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3402 iwl_release_nic_access(priv
);
3404 /* Else device is assumed to be awake */
3406 /* Device expects a multiple of 8 */
3407 iwl_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3413 spin_unlock_irqrestore(&q
->lock
, flags
);
3418 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3420 static inline __le32
iwl4965_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3421 dma_addr_t dma_addr
)
3423 return cpu_to_le32((u32
)(dma_addr
>> 8));
3428 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3430 * If there are slots in the RX queue that need to be restocked,
3431 * and we have free pre-allocated buffers, fill the ranks as much
3432 * as we can, pulling from rx_free.
3434 * This moves the 'write' index forward to catch up with 'processed', and
3435 * also updates the memory address in the firmware to reference the new
3438 static int iwl4965_rx_queue_restock(struct iwl_priv
*priv
)
3440 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3441 struct list_head
*element
;
3442 struct iwl4965_rx_mem_buffer
*rxb
;
3443 unsigned long flags
;
3446 spin_lock_irqsave(&rxq
->lock
, flags
);
3447 write
= rxq
->write
& ~0x7;
3448 while ((iwl4965_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3449 /* Get next free Rx buffer, remove from free list */
3450 element
= rxq
->rx_free
.next
;
3451 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3454 /* Point to Rx buffer via next RBD in circular buffer */
3455 rxq
->bd
[rxq
->write
] = iwl4965_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3456 rxq
->queue
[rxq
->write
] = rxb
;
3457 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3460 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3461 /* If the pre-allocated buffer pool is dropping low, schedule to
3463 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3464 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3467 /* If we've added more space for the firmware to place data, tell it.
3468 * Increment device's write pointer in multiples of 8. */
3469 if ((write
!= (rxq
->write
& ~0x7))
3470 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3471 spin_lock_irqsave(&rxq
->lock
, flags
);
3472 rxq
->need_update
= 1;
3473 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3474 rc
= iwl4965_rx_queue_update_write_ptr(priv
, rxq
);
3483 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3485 * When moving to rx_free an SKB is allocated for the slot.
3487 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3488 * This is called as a scheduled work item (except for during initialization)
3490 static void iwl4965_rx_allocate(struct iwl_priv
*priv
)
3492 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3493 struct list_head
*element
;
3494 struct iwl4965_rx_mem_buffer
*rxb
;
3495 unsigned long flags
;
3496 spin_lock_irqsave(&rxq
->lock
, flags
);
3497 while (!list_empty(&rxq
->rx_used
)) {
3498 element
= rxq
->rx_used
.next
;
3499 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3501 /* Alloc a new receive buffer */
3503 alloc_skb(priv
->hw_params
.rx_buf_size
,
3504 __GFP_NOWARN
| GFP_ATOMIC
);
3506 if (net_ratelimit())
3507 printk(KERN_CRIT DRV_NAME
3508 ": Can not allocate SKB buffers\n");
3509 /* We don't reschedule replenish work here -- we will
3510 * call the restock method and if it still needs
3511 * more buffers it will schedule replenish */
3514 priv
->alloc_rxb_skb
++;
3517 /* Get physical address of RB/SKB */
3519 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3520 priv
->hw_params
.rx_buf_size
, PCI_DMA_FROMDEVICE
);
3521 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3524 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3528 * this should be called while priv->lock is locked
3530 static void __iwl4965_rx_replenish(void *data
)
3532 struct iwl_priv
*priv
= data
;
3534 iwl4965_rx_allocate(priv
);
3535 iwl4965_rx_queue_restock(priv
);
3539 void iwl4965_rx_replenish(void *data
)
3541 struct iwl_priv
*priv
= data
;
3542 unsigned long flags
;
3544 iwl4965_rx_allocate(priv
);
3546 spin_lock_irqsave(&priv
->lock
, flags
);
3547 iwl4965_rx_queue_restock(priv
);
3548 spin_unlock_irqrestore(&priv
->lock
, flags
);
3551 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3552 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3553 * This free routine walks the list of POOL entries and if SKB is set to
3554 * non NULL it is unmapped and freed
3556 static void iwl4965_rx_queue_free(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3559 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3560 if (rxq
->pool
[i
].skb
!= NULL
) {
3561 pci_unmap_single(priv
->pci_dev
,
3562 rxq
->pool
[i
].dma_addr
,
3563 priv
->hw_params
.rx_buf_size
,
3564 PCI_DMA_FROMDEVICE
);
3565 dev_kfree_skb(rxq
->pool
[i
].skb
);
3569 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3574 int iwl4965_rx_queue_alloc(struct iwl_priv
*priv
)
3576 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3577 struct pci_dev
*dev
= priv
->pci_dev
;
3580 spin_lock_init(&rxq
->lock
);
3581 INIT_LIST_HEAD(&rxq
->rx_free
);
3582 INIT_LIST_HEAD(&rxq
->rx_used
);
3584 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3585 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3589 /* Fill the rx_used queue with _all_ of the Rx buffers */
3590 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3591 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3593 /* Set us so that we have processed and used all buffers, but have
3594 * not restocked the Rx queue with fresh buffers */
3595 rxq
->read
= rxq
->write
= 0;
3596 rxq
->free_count
= 0;
3597 rxq
->need_update
= 0;
3601 void iwl4965_rx_queue_reset(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3603 unsigned long flags
;
3605 spin_lock_irqsave(&rxq
->lock
, flags
);
3606 INIT_LIST_HEAD(&rxq
->rx_free
);
3607 INIT_LIST_HEAD(&rxq
->rx_used
);
3608 /* Fill the rx_used queue with _all_ of the Rx buffers */
3609 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3610 /* In the reset function, these buffers may have been allocated
3611 * to an SKB, so we need to unmap and free potential storage */
3612 if (rxq
->pool
[i
].skb
!= NULL
) {
3613 pci_unmap_single(priv
->pci_dev
,
3614 rxq
->pool
[i
].dma_addr
,
3615 priv
->hw_params
.rx_buf_size
,
3616 PCI_DMA_FROMDEVICE
);
3617 priv
->alloc_rxb_skb
--;
3618 dev_kfree_skb(rxq
->pool
[i
].skb
);
3619 rxq
->pool
[i
].skb
= NULL
;
3621 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3624 /* Set us so that we have processed and used all buffers, but have
3625 * not restocked the Rx queue with fresh buffers */
3626 rxq
->read
= rxq
->write
= 0;
3627 rxq
->free_count
= 0;
3628 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3631 /* Convert linear signal-to-noise ratio into dB */
3632 static u8 ratio2dB
[100] = {
3633 /* 0 1 2 3 4 5 6 7 8 9 */
3634 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3635 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3636 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3637 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3638 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3639 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3640 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3641 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3642 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3643 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3646 /* Calculates a relative dB value from a ratio of linear
3647 * (i.e. not dB) signal levels.
3648 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3649 int iwl4965_calc_db_from_ratio(int sig_ratio
)
3651 /* 1000:1 or higher just report as 60 dB */
3652 if (sig_ratio
>= 1000)
3655 /* 100:1 or higher, divide by 10 and use table,
3656 * add 20 dB to make up for divide by 10 */
3657 if (sig_ratio
>= 100)
3658 return (20 + (int)ratio2dB
[sig_ratio
/10]);
3660 /* We shouldn't see this */
3664 /* Use table for ratios 1:1 - 99:1 */
3665 return (int)ratio2dB
[sig_ratio
];
3668 #define PERFECT_RSSI (-20) /* dBm */
3669 #define WORST_RSSI (-95) /* dBm */
3670 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3672 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3673 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3674 * about formulas used below. */
3675 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
3678 int degradation
= PERFECT_RSSI
- rssi_dbm
;
3680 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3681 * as indicator; formula is (signal dbm - noise dbm).
3682 * SNR at or above 40 is a great signal (100%).
3683 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3684 * Weakest usable signal is usually 10 - 15 dB SNR. */
3686 if (rssi_dbm
- noise_dbm
>= 40)
3688 else if (rssi_dbm
< noise_dbm
)
3690 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
3692 /* Else use just the signal level.
3693 * This formula is a least squares fit of data points collected and
3694 * compared with a reference system that had a percentage (%) display
3695 * for signal quality. */
3697 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
3698 (15 * RSSI_RANGE
+ 62 * degradation
)) /
3699 (RSSI_RANGE
* RSSI_RANGE
);
3703 else if (sig_qual
< 1)
3710 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
3712 * Uses the priv->rx_handlers callback function array to invoke
3713 * the appropriate handlers, including command responses,
3714 * frame-received notifications, and other notifications.
3716 static void iwl4965_rx_handle(struct iwl_priv
*priv
)
3718 struct iwl4965_rx_mem_buffer
*rxb
;
3719 struct iwl4965_rx_packet
*pkt
;
3720 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3723 unsigned long flags
;
3727 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3728 * buffer that the driver may process (last buffer filled by ucode). */
3729 r
= iwl4965_hw_get_rx_read(priv
);
3732 /* Rx interrupt, but nothing sent from uCode */
3734 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
3736 if (iwl4965_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
3740 rxb
= rxq
->queue
[i
];
3742 /* If an RXB doesn't have a Rx queue slot associated with it,
3743 * then a bug has been introduced in the queue refilling
3744 * routines -- catch it here */
3745 BUG_ON(rxb
== NULL
);
3747 rxq
->queue
[i
] = NULL
;
3749 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
3750 priv
->hw_params
.rx_buf_size
,
3751 PCI_DMA_FROMDEVICE
);
3752 pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3754 /* Reclaim a command buffer only if this packet is a response
3755 * to a (driver-originated) command.
3756 * If the packet (e.g. Rx frame) originated from uCode,
3757 * there is no command buffer to reclaim.
3758 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3759 * but apparently a few don't get set; catch them here. */
3760 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
3761 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
3762 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
3763 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
3764 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
3765 (pkt
->hdr
.cmd
!= REPLY_TX
);
3767 /* Based on type of command response or notification,
3768 * handle those that need handling via function in
3769 * rx_handlers table. See iwl4965_setup_rx_handlers() */
3770 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
3771 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3772 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
3773 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
3774 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
3776 /* No handling needed */
3777 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3778 "r %d i %d No handler needed for %s, 0x%02x\n",
3779 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
3784 /* Invoke any callbacks, transfer the skb to caller, and
3785 * fire off the (possibly) blocking iwl_send_cmd()
3786 * as we reclaim the driver command queue */
3787 if (rxb
&& rxb
->skb
)
3788 iwl4965_tx_cmd_complete(priv
, rxb
);
3790 IWL_WARNING("Claim null rxb?\n");
3793 /* For now we just don't re-use anything. We can tweak this
3794 * later to try and re-use notification packets and SKBs that
3795 * fail to Rx correctly */
3796 if (rxb
->skb
!= NULL
) {
3797 priv
->alloc_rxb_skb
--;
3798 dev_kfree_skb_any(rxb
->skb
);
3802 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
3803 priv
->hw_params
.rx_buf_size
,
3804 PCI_DMA_FROMDEVICE
);
3805 spin_lock_irqsave(&rxq
->lock
, flags
);
3806 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
3807 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3808 i
= (i
+ 1) & RX_QUEUE_MASK
;
3809 /* If there are a lot of unused frames,
3810 * restock the Rx queue so ucode wont assert. */
3815 __iwl4965_rx_replenish(priv
);
3821 /* Backtrack one entry */
3823 iwl4965_rx_queue_restock(priv
);
3827 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
3829 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
3830 struct iwl4965_tx_queue
*txq
)
3834 int txq_id
= txq
->q
.id
;
3836 if (txq
->need_update
== 0)
3839 /* if we're trying to save power */
3840 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3841 /* wake up nic if it's powered down ...
3842 * uCode will wake up, and interrupt us again, so next
3843 * time we'll skip this part. */
3844 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3846 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3847 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
3848 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3849 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3853 /* restore this queue's parameters in nic hardware. */
3854 rc
= iwl_grab_nic_access(priv
);
3857 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
3858 txq
->q
.write_ptr
| (txq_id
<< 8));
3859 iwl_release_nic_access(priv
);
3861 /* else not in power-save mode, uCode will never sleep when we're
3862 * trying to tx (during RFKILL, we're not trying to tx). */
3864 iwl_write32(priv
, HBUS_TARG_WRPTR
,
3865 txq
->q
.write_ptr
| (txq_id
<< 8));
3867 txq
->need_update
= 0;
3872 #ifdef CONFIG_IWLWIFI_DEBUG
3873 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd
*rxon
)
3875 DECLARE_MAC_BUF(mac
);
3877 IWL_DEBUG_RADIO("RX CONFIG:\n");
3878 iwl_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
3879 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
3880 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
3881 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
3882 le32_to_cpu(rxon
->filter_flags
));
3883 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
3884 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
3885 rxon
->ofdm_basic_rates
);
3886 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
3887 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
3888 print_mac(mac
, rxon
->node_addr
));
3889 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
3890 print_mac(mac
, rxon
->bssid_addr
));
3891 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
3895 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
3897 IWL_DEBUG_ISR("Enabling interrupts\n");
3898 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
3899 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
3902 /* call this function to flush any scheduled tasklet */
3903 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
3905 /* wait to make sure we flush pedding tasklet*/
3906 synchronize_irq(priv
->pci_dev
->irq
);
3907 tasklet_kill(&priv
->irq_tasklet
);
3910 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
3912 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
3914 /* disable interrupts from uCode/NIC to host */
3915 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
3917 /* acknowledge/clear/reset any interrupts still pending
3918 * from uCode or flow handler (Rx/Tx DMA) */
3919 iwl_write32(priv
, CSR_INT
, 0xffffffff);
3920 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
3921 IWL_DEBUG_ISR("Disabled interrupts\n");
3924 static const char *desc_lookup(int i
)
3932 return "BAD_CHECKSUM";
3934 return "NMI_INTERRUPT";
3938 return "FATAL_ERROR";
3944 #define ERROR_START_OFFSET (1 * sizeof(u32))
3945 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
3947 static void iwl4965_dump_nic_error_log(struct iwl_priv
*priv
)
3950 u32 desc
, time
, count
, base
, data1
;
3951 u32 blink1
, blink2
, ilink1
, ilink2
;
3954 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
3956 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
3957 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
3961 rc
= iwl_grab_nic_access(priv
);
3963 IWL_WARNING("Can not read from adapter at this time.\n");
3967 count
= iwl_read_targ_mem(priv
, base
);
3969 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
3970 IWL_ERROR("Start IWL Error Log Dump:\n");
3971 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
3974 desc
= iwl_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
3975 blink1
= iwl_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
3976 blink2
= iwl_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
3977 ilink1
= iwl_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
3978 ilink2
= iwl_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
3979 data1
= iwl_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
3980 data2
= iwl_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
3981 line
= iwl_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
3982 time
= iwl_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
3984 IWL_ERROR("Desc Time "
3985 "data1 data2 line\n");
3986 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
3987 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
3988 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
3989 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
3992 iwl_release_nic_access(priv
);
3995 #define EVENT_START_OFFSET (4 * sizeof(u32))
3998 * iwl4965_print_event_log - Dump error event log to syslog
4000 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4002 static void iwl4965_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4003 u32 num_events
, u32 mode
)
4006 u32 base
; /* SRAM byte address of event log header */
4007 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4008 u32 ptr
; /* SRAM byte address of log data */
4009 u32 ev
, time
, data
; /* event log data */
4011 if (num_events
== 0)
4014 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4017 event_size
= 2 * sizeof(u32
);
4019 event_size
= 3 * sizeof(u32
);
4021 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4023 /* "time" is actually "data" for mode 0 (no timestamp).
4024 * place event id # at far right for easier visual parsing. */
4025 for (i
= 0; i
< num_events
; i
++) {
4026 ev
= iwl_read_targ_mem(priv
, ptr
);
4028 time
= iwl_read_targ_mem(priv
, ptr
);
4031 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4033 data
= iwl_read_targ_mem(priv
, ptr
);
4035 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4040 static void iwl4965_dump_nic_event_log(struct iwl_priv
*priv
)
4043 u32 base
; /* SRAM byte address of event log header */
4044 u32 capacity
; /* event log capacity in # entries */
4045 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4046 u32 num_wraps
; /* # times uCode wrapped to top of log */
4047 u32 next_entry
; /* index of next entry to be written by uCode */
4048 u32 size
; /* # entries that we'll print */
4050 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4051 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4052 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4056 rc
= iwl_grab_nic_access(priv
);
4058 IWL_WARNING("Can not read from adapter at this time.\n");
4062 /* event log header */
4063 capacity
= iwl_read_targ_mem(priv
, base
);
4064 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4065 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4066 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4068 size
= num_wraps
? capacity
: next_entry
;
4070 /* bail out if nothing in log */
4072 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4073 iwl_release_nic_access(priv
);
4077 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4080 /* if uCode has wrapped back to top of log, start at the oldest entry,
4081 * i.e the next one that uCode would fill. */
4083 iwl4965_print_event_log(priv
, next_entry
,
4084 capacity
- next_entry
, mode
);
4086 /* (then/else) start at top of log */
4087 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
4089 iwl_release_nic_access(priv
);
4093 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4095 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
4097 /* Set the FW error flag -- cleared on iwl4965_down */
4098 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4100 /* Cancel currently queued command. */
4101 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4103 #ifdef CONFIG_IWLWIFI_DEBUG
4104 if (iwl_debug_level
& IWL_DL_FW_ERRORS
) {
4105 iwl4965_dump_nic_error_log(priv
);
4106 iwl4965_dump_nic_event_log(priv
);
4107 iwl4965_print_rx_config_cmd(&priv
->staging_rxon
);
4111 wake_up_interruptible(&priv
->wait_command_queue
);
4113 /* Keep the restart process from trying to send host
4114 * commands by clearing the INIT status bit */
4115 clear_bit(STATUS_READY
, &priv
->status
);
4117 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4118 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4119 "Restarting adapter due to uCode error.\n");
4121 if (iwl_is_associated(priv
)) {
4122 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4123 sizeof(priv
->recovery_rxon
));
4124 priv
->error_recovering
= 1;
4126 queue_work(priv
->workqueue
, &priv
->restart
);
4130 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
4132 unsigned long flags
;
4134 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4135 sizeof(priv
->staging_rxon
));
4136 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4137 iwl4965_commit_rxon(priv
);
4139 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
4141 spin_lock_irqsave(&priv
->lock
, flags
);
4142 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4143 priv
->error_recovering
= 0;
4144 spin_unlock_irqrestore(&priv
->lock
, flags
);
4147 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
4149 u32 inta
, handled
= 0;
4151 unsigned long flags
;
4152 #ifdef CONFIG_IWLWIFI_DEBUG
4156 spin_lock_irqsave(&priv
->lock
, flags
);
4158 /* Ack/clear/reset pending uCode interrupts.
4159 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4160 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4161 inta
= iwl_read32(priv
, CSR_INT
);
4162 iwl_write32(priv
, CSR_INT
, inta
);
4164 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4165 * Any new interrupts that happen after this, either while we're
4166 * in this tasklet, or later, will show up in next ISR/tasklet. */
4167 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4168 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4170 #ifdef CONFIG_IWLWIFI_DEBUG
4171 if (iwl_debug_level
& IWL_DL_ISR
) {
4172 /* just for debug */
4173 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4174 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4175 inta
, inta_mask
, inta_fh
);
4179 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4180 * atomic, make sure that inta covers all the interrupts that
4181 * we've discovered, even if FH interrupt came in just after
4182 * reading CSR_INT. */
4183 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
4184 inta
|= CSR_INT_BIT_FH_RX
;
4185 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
4186 inta
|= CSR_INT_BIT_FH_TX
;
4188 /* Now service all interrupt bits discovered above. */
4189 if (inta
& CSR_INT_BIT_HW_ERR
) {
4190 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4192 /* Tell the device to stop sending interrupts */
4193 iwl4965_disable_interrupts(priv
);
4195 iwl4965_irq_handle_error(priv
);
4197 handled
|= CSR_INT_BIT_HW_ERR
;
4199 spin_unlock_irqrestore(&priv
->lock
, flags
);
4204 #ifdef CONFIG_IWLWIFI_DEBUG
4205 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4206 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4207 if (inta
& CSR_INT_BIT_SCD
)
4208 IWL_DEBUG_ISR("Scheduler finished to transmit "
4209 "the frame/frames.\n");
4211 /* Alive notification via Rx interrupt will do the real work */
4212 if (inta
& CSR_INT_BIT_ALIVE
)
4213 IWL_DEBUG_ISR("Alive interrupt\n");
4216 /* Safely ignore these bits for debug checks below */
4217 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4219 /* HW RF KILL switch toggled */
4220 if (inta
& CSR_INT_BIT_RF_KILL
) {
4222 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
4223 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4226 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4227 "RF_KILL bit toggled to %s.\n",
4228 hw_rf_kill
? "disable radio":"enable radio");
4230 /* Queue restart only if RF_KILL switch was set to "kill"
4231 * when we loaded driver, and is now set to "enable".
4232 * After we're Alive, RF_KILL gets handled by
4233 * iwl4965_rx_card_state_notif() */
4234 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4235 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4236 queue_work(priv
->workqueue
, &priv
->restart
);
4239 handled
|= CSR_INT_BIT_RF_KILL
;
4242 /* Chip got too hot and stopped itself */
4243 if (inta
& CSR_INT_BIT_CT_KILL
) {
4244 IWL_ERROR("Microcode CT kill error detected.\n");
4245 handled
|= CSR_INT_BIT_CT_KILL
;
4248 /* Error detected by uCode */
4249 if (inta
& CSR_INT_BIT_SW_ERR
) {
4250 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4252 iwl4965_irq_handle_error(priv
);
4253 handled
|= CSR_INT_BIT_SW_ERR
;
4256 /* uCode wakes up after power-down sleep */
4257 if (inta
& CSR_INT_BIT_WAKEUP
) {
4258 IWL_DEBUG_ISR("Wakeup interrupt\n");
4259 iwl4965_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4260 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4261 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4262 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4263 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4264 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4265 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4267 handled
|= CSR_INT_BIT_WAKEUP
;
4270 /* All uCode command responses, including Tx command responses,
4271 * Rx "responses" (frame-received notification), and other
4272 * notifications from uCode come through here*/
4273 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4274 iwl4965_rx_handle(priv
);
4275 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4278 if (inta
& CSR_INT_BIT_FH_TX
) {
4279 IWL_DEBUG_ISR("Tx interrupt\n");
4280 handled
|= CSR_INT_BIT_FH_TX
;
4283 if (inta
& ~handled
)
4284 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4286 if (inta
& ~CSR_INI_SET_MASK
) {
4287 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4288 inta
& ~CSR_INI_SET_MASK
);
4289 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4292 /* Re-enable all interrupts */
4293 /* only Re-enable if diabled by irq */
4294 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4295 iwl4965_enable_interrupts(priv
);
4297 #ifdef CONFIG_IWLWIFI_DEBUG
4298 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4299 inta
= iwl_read32(priv
, CSR_INT
);
4300 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4301 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4302 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4303 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4306 spin_unlock_irqrestore(&priv
->lock
, flags
);
4309 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
4311 struct iwl_priv
*priv
= data
;
4312 u32 inta
, inta_mask
;
4317 spin_lock(&priv
->lock
);
4319 /* Disable (but don't clear!) interrupts here to avoid
4320 * back-to-back ISRs and sporadic interrupts from our NIC.
4321 * If we have something to service, the tasklet will re-enable ints.
4322 * If we *don't* have something, we'll re-enable before leaving here. */
4323 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4324 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4326 /* Discover which interrupts are active/pending */
4327 inta
= iwl_read32(priv
, CSR_INT
);
4328 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4330 /* Ignore interrupt if there's nothing in NIC to service.
4331 * This may be due to IRQ shared with another device,
4332 * or due to sporadic interrupts thrown from our NIC. */
4333 if (!inta
&& !inta_fh
) {
4334 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4338 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4339 /* Hardware disappeared. It might have already raised
4341 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4345 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4346 inta
, inta_mask
, inta_fh
);
4348 inta
&= ~CSR_INT_BIT_SCD
;
4350 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4351 if (likely(inta
|| inta_fh
))
4352 tasklet_schedule(&priv
->irq_tasklet
);
4355 spin_unlock(&priv
->lock
);
4359 /* re-enable interrupts here since we don't have anything to service. */
4360 /* only Re-enable if diabled by irq */
4361 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4362 iwl4965_enable_interrupts(priv
);
4363 spin_unlock(&priv
->lock
);
4367 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4368 * sending probe req. This should be set long enough to hear probe responses
4369 * from more than one AP. */
4370 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4371 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4373 /* For faster active scanning, scan will move to the next channel if fewer than
4374 * PLCP_QUIET_THRESH packets are heard on this channel within
4375 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4376 * time if it's a quiet channel (nothing responded to our probe, and there's
4377 * no other traffic).
4378 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4379 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4380 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4382 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4383 * Must be set longer than active dwell time.
4384 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4385 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4386 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4387 #define IWL_PASSIVE_DWELL_BASE (100)
4388 #define IWL_CHANNEL_TUNE_TIME 5
4390 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
4391 enum ieee80211_band band
)
4393 if (band
== IEEE80211_BAND_5GHZ
)
4394 return IWL_ACTIVE_DWELL_TIME_52
;
4396 return IWL_ACTIVE_DWELL_TIME_24
;
4399 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
4400 enum ieee80211_band band
)
4402 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
4403 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
4404 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4405 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4407 if (iwl_is_associated(priv
)) {
4408 /* If we're associated, we clamp the maximum passive
4409 * dwell time to be 98% of the beacon interval (minus
4410 * 2 * channel tune time) */
4411 passive
= priv
->beacon_int
;
4412 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4413 passive
= IWL_PASSIVE_DWELL_BASE
;
4414 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4417 if (passive
<= active
)
4418 passive
= active
+ 1;
4423 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
4424 enum ieee80211_band band
,
4425 u8 is_active
, u8 direct_mask
,
4426 struct iwl4965_scan_channel
*scan_ch
)
4428 const struct ieee80211_channel
*channels
= NULL
;
4429 const struct ieee80211_supported_band
*sband
;
4430 const struct iwl_channel_info
*ch_info
;
4431 u16 passive_dwell
= 0;
4432 u16 active_dwell
= 0;
4435 sband
= iwl_get_hw_mode(priv
, band
);
4439 channels
= sband
->channels
;
4441 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
4442 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
4444 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4445 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
4448 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
4450 ch_info
= iwl_get_channel_info(priv
, band
,
4452 if (!is_channel_valid(ch_info
)) {
4453 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
4458 if (!is_active
|| is_channel_passive(ch_info
) ||
4459 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
4460 scan_ch
->type
= 0; /* passive */
4462 scan_ch
->type
= 1; /* active */
4464 if (scan_ch
->type
& 1)
4465 scan_ch
->type
|= (direct_mask
<< 1);
4467 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4468 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4470 /* Set txpower levels to defaults */
4471 scan_ch
->tpc
.dsp_atten
= 110;
4472 /* scan_pwr_info->tpc.dsp_atten; */
4474 /*scan_pwr_info->tpc.tx_gain; */
4475 if (band
== IEEE80211_BAND_5GHZ
)
4476 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4478 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4479 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4481 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4485 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4487 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4488 (scan_ch
->type
& 1) ?
4489 active_dwell
: passive_dwell
);
4495 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4499 /******************************************************************************
4501 * uCode download functions
4503 ******************************************************************************/
4505 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
4507 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4508 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4509 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4510 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4511 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4512 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4515 static void iwl4965_nic_start(struct iwl_priv
*priv
)
4517 /* Remove all resets to allow NIC to operate */
4518 iwl_write32(priv
, CSR_RESET
, 0);
4523 * iwl4965_read_ucode - Read uCode images from disk file.
4525 * Copy into buffers for card to fetch via bus-mastering
4527 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
4529 struct iwl4965_ucode
*ucode
;
4531 const struct firmware
*ucode_raw
;
4532 const char *name
= priv
->cfg
->fw_name
;
4535 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
4537 /* Ask kernel firmware_class module to get the boot firmware off disk.
4538 * request_firmware() is synchronous, file is in memory on return. */
4539 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
4541 IWL_ERROR("%s firmware file req failed: Reason %d\n",
4546 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
4547 name
, ucode_raw
->size
);
4549 /* Make sure that we got at least our header! */
4550 if (ucode_raw
->size
< sizeof(*ucode
)) {
4551 IWL_ERROR("File size way too small!\n");
4556 /* Data from ucode file: header followed by uCode images */
4557 ucode
= (void *)ucode_raw
->data
;
4559 ver
= le32_to_cpu(ucode
->ver
);
4560 inst_size
= le32_to_cpu(ucode
->inst_size
);
4561 data_size
= le32_to_cpu(ucode
->data_size
);
4562 init_size
= le32_to_cpu(ucode
->init_size
);
4563 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
4564 boot_size
= le32_to_cpu(ucode
->boot_size
);
4566 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
4567 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
4569 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
4571 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
4573 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
4575 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
4578 /* Verify size of file vs. image size info in file's header */
4579 if (ucode_raw
->size
< sizeof(*ucode
) +
4580 inst_size
+ data_size
+ init_size
+
4581 init_data_size
+ boot_size
) {
4583 IWL_DEBUG_INFO("uCode file size %d too small\n",
4584 (int)ucode_raw
->size
);
4589 /* Verify that uCode images will fit in card's SRAM */
4590 if (inst_size
> priv
->hw_params
.max_inst_size
) {
4591 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
4597 if (data_size
> priv
->hw_params
.max_data_size
) {
4598 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
4603 if (init_size
> priv
->hw_params
.max_inst_size
) {
4605 ("uCode init instr len %d too large to fit in\n",
4610 if (init_data_size
> priv
->hw_params
.max_data_size
) {
4612 ("uCode init data len %d too large to fit in\n",
4617 if (boot_size
> priv
->hw_params
.max_bsm_size
) {
4619 ("uCode boot instr len %d too large to fit in\n",
4625 /* Allocate ucode buffers for card's bus-master loading ... */
4627 /* Runtime instructions and 2 copies of data:
4628 * 1) unmodified from disk
4629 * 2) backup cache for save/restore during power-downs */
4630 priv
->ucode_code
.len
= inst_size
;
4631 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4633 priv
->ucode_data
.len
= data_size
;
4634 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4636 priv
->ucode_data_backup
.len
= data_size
;
4637 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4639 /* Initialization instructions and data */
4640 if (init_size
&& init_data_size
) {
4641 priv
->ucode_init
.len
= init_size
;
4642 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4644 priv
->ucode_init_data
.len
= init_data_size
;
4645 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4647 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
4651 /* Bootstrap (instructions only, no data) */
4653 priv
->ucode_boot
.len
= boot_size
;
4654 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4656 if (!priv
->ucode_boot
.v_addr
)
4660 /* Copy images into buffers for card's bus-master reads ... */
4662 /* Runtime instructions (first block of data in file) */
4663 src
= &ucode
->data
[0];
4664 len
= priv
->ucode_code
.len
;
4665 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
4666 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
4667 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
4668 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
4670 /* Runtime data (2nd block)
4671 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
4672 src
= &ucode
->data
[inst_size
];
4673 len
= priv
->ucode_data
.len
;
4674 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
4675 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
4676 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
4678 /* Initialization instructions (3rd block) */
4680 src
= &ucode
->data
[inst_size
+ data_size
];
4681 len
= priv
->ucode_init
.len
;
4682 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
4684 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
4687 /* Initialization data (4th block) */
4688 if (init_data_size
) {
4689 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
4690 len
= priv
->ucode_init_data
.len
;
4691 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
4693 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
4696 /* Bootstrap instructions (5th block) */
4697 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
4698 len
= priv
->ucode_boot
.len
;
4699 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
4700 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
4702 /* We have our copies now, allow OS release its copies */
4703 release_firmware(ucode_raw
);
4707 IWL_ERROR("failed to allocate pci memory\n");
4709 iwl4965_dealloc_ucode_pci(priv
);
4712 release_firmware(ucode_raw
);
4720 * iwl4965_set_ucode_ptrs - Set uCode address location
4722 * Tell initialization uCode where to find runtime uCode.
4724 * BSM registers initially contain pointers to initialization uCode.
4725 * We need to replace them to load runtime uCode inst and data,
4726 * and to save runtime data when powering down.
4728 static int iwl4965_set_ucode_ptrs(struct iwl_priv
*priv
)
4733 unsigned long flags
;
4735 /* bits 35:4 for 4965 */
4736 pinst
= priv
->ucode_code
.p_addr
>> 4;
4737 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
4739 spin_lock_irqsave(&priv
->lock
, flags
);
4740 rc
= iwl_grab_nic_access(priv
);
4742 spin_unlock_irqrestore(&priv
->lock
, flags
);
4746 /* Tell bootstrap uCode where to find image to load */
4747 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
4748 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
4749 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
4750 priv
->ucode_data
.len
);
4752 /* Inst bytecount must be last to set up, bit 31 signals uCode
4753 * that all new ptr/size info is in place */
4754 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
4755 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
4757 iwl_release_nic_access(priv
);
4759 spin_unlock_irqrestore(&priv
->lock
, flags
);
4761 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
4767 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
4769 * Called after REPLY_ALIVE notification received from "initialize" uCode.
4771 * The 4965 "initialize" ALIVE reply contains calibration data for:
4772 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
4773 * (3945 does not contain this data).
4775 * Tell "initialize" uCode to go ahead and load the runtime uCode.
4777 static void iwl4965_init_alive_start(struct iwl_priv
*priv
)
4779 /* Check alive response for "valid" sign from uCode */
4780 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
4781 /* We had an error bringing up the hardware, so take it
4782 * all the way back down so we can try again */
4783 IWL_DEBUG_INFO("Initialize Alive failed.\n");
4787 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
4788 * This is a paranoid check, because we would not have gotten the
4789 * "initialize" alive if code weren't properly loaded. */
4790 if (iwl_verify_ucode(priv
)) {
4791 /* Runtime instruction load was bad;
4792 * take it all the way back down so we can try again */
4793 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
4797 /* Calculate temperature */
4798 priv
->temperature
= iwl4965_get_temperature(priv
);
4800 /* Send pointers to protocol/runtime uCode image ... init code will
4801 * load and launch runtime uCode, which will send us another "Alive"
4803 IWL_DEBUG_INFO("Initialization Alive received.\n");
4804 if (iwl4965_set_ucode_ptrs(priv
)) {
4805 /* Runtime instruction load won't happen;
4806 * take it all the way back down so we can try again */
4807 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
4813 queue_work(priv
->workqueue
, &priv
->restart
);
4818 * iwl4965_alive_start - called after REPLY_ALIVE notification received
4819 * from protocol/runtime uCode (initialization uCode's
4820 * Alive gets handled by iwl4965_init_alive_start()).
4822 static void iwl4965_alive_start(struct iwl_priv
*priv
)
4826 IWL_DEBUG_INFO("Runtime Alive received.\n");
4828 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
4829 /* We had an error bringing up the hardware, so take it
4830 * all the way back down so we can try again */
4831 IWL_DEBUG_INFO("Alive failed.\n");
4835 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
4836 * This is a paranoid check, because we would not have gotten the
4837 * "runtime" alive if code weren't properly loaded. */
4838 if (iwl_verify_ucode(priv
)) {
4839 /* Runtime instruction load was bad;
4840 * take it all the way back down so we can try again */
4841 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
4845 iwlcore_clear_stations_table(priv
);
4847 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
4849 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
4854 /* After the ALIVE response, we can send host commands to 4965 uCode */
4855 set_bit(STATUS_ALIVE
, &priv
->status
);
4857 /* Clear out the uCode error bit if it is set */
4858 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
4860 if (iwl_is_rfkill(priv
))
4863 ieee80211_start_queues(priv
->hw
);
4865 priv
->active_rate
= priv
->rates_mask
;
4866 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
4868 if (iwl_is_associated(priv
)) {
4869 struct iwl4965_rxon_cmd
*active_rxon
=
4870 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
4872 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
4873 sizeof(priv
->staging_rxon
));
4874 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4876 /* Initialize our rx_config data */
4877 iwl4965_connection_init_rx_config(priv
);
4878 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
4881 /* Configure Bluetooth device coexistence support */
4882 iwl4965_send_bt_config(priv
);
4884 /* Configure the adapter for unassociated operation */
4885 iwl4965_commit_rxon(priv
);
4887 /* At this point, the NIC is initialized and operational */
4888 priv
->notif_missed_beacons
= 0;
4890 iwl4965_rf_kill_ct_config(priv
);
4892 iwl_leds_register(priv
);
4894 IWL_DEBUG_INFO("ALIVE processing complete.\n");
4895 set_bit(STATUS_READY
, &priv
->status
);
4896 wake_up_interruptible(&priv
->wait_command_queue
);
4898 if (priv
->error_recovering
)
4899 iwl4965_error_recovery(priv
);
4901 iwlcore_low_level_notify(priv
, IWLCORE_START_EVT
);
4902 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
4906 queue_work(priv
->workqueue
, &priv
->restart
);
4909 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
4911 static void __iwl4965_down(struct iwl_priv
*priv
)
4913 unsigned long flags
;
4914 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4915 struct ieee80211_conf
*conf
= NULL
;
4917 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
4919 conf
= ieee80211_get_hw_conf(priv
->hw
);
4922 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4924 iwl_leds_unregister(priv
);
4926 iwlcore_low_level_notify(priv
, IWLCORE_STOP_EVT
);
4928 iwlcore_clear_stations_table(priv
);
4930 /* Unblock any waiting calls */
4931 wake_up_interruptible_all(&priv
->wait_command_queue
);
4933 /* Wipe out the EXIT_PENDING status bit if we are not actually
4934 * exiting the module */
4936 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4938 /* stop and reset the on-board processor */
4939 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
4941 /* tell the device to stop sending interrupts */
4942 spin_lock_irqsave(&priv
->lock
, flags
);
4943 iwl4965_disable_interrupts(priv
);
4944 spin_unlock_irqrestore(&priv
->lock
, flags
);
4945 iwl_synchronize_irq(priv
);
4947 if (priv
->mac80211_registered
)
4948 ieee80211_stop_queues(priv
->hw
);
4950 /* If we have not previously called iwl4965_init() then
4951 * clear all bits but the RF Kill and SUSPEND bits and return */
4952 if (!iwl_is_init(priv
)) {
4953 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
4955 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
4957 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
4958 STATUS_GEO_CONFIGURED
|
4959 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
4964 /* ...otherwise clear out all the status bits but the RF Kill and
4965 * SUSPEND bits and continue taking the NIC down. */
4966 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
4968 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
4970 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
4971 STATUS_GEO_CONFIGURED
|
4972 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
4974 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
4977 spin_lock_irqsave(&priv
->lock
, flags
);
4978 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
4979 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4980 spin_unlock_irqrestore(&priv
->lock
, flags
);
4982 iwl4965_hw_txq_ctx_stop(priv
);
4983 iwl4965_hw_rxq_stop(priv
);
4985 spin_lock_irqsave(&priv
->lock
, flags
);
4986 if (!iwl_grab_nic_access(priv
)) {
4987 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
4988 APMG_CLK_VAL_DMA_CLK_RQT
);
4989 iwl_release_nic_access(priv
);
4991 spin_unlock_irqrestore(&priv
->lock
, flags
);
4995 iwl4965_hw_nic_stop_master(priv
);
4996 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
4997 iwl4965_hw_nic_reset(priv
);
4998 priv
->cfg
->ops
->lib
->free_shared_mem(priv
);
5001 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
5003 if (priv
->ibss_beacon
)
5004 dev_kfree_skb(priv
->ibss_beacon
);
5005 priv
->ibss_beacon
= NULL
;
5007 /* clear out any free frames */
5008 iwl4965_clear_free_frames(priv
);
5011 static void iwl4965_down(struct iwl_priv
*priv
)
5013 mutex_lock(&priv
->mutex
);
5014 __iwl4965_down(priv
);
5015 mutex_unlock(&priv
->mutex
);
5017 iwl4965_cancel_deferred_work(priv
);
5020 #define MAX_HW_RESTARTS 5
5022 static int __iwl4965_up(struct iwl_priv
*priv
)
5027 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5028 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5032 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5033 IWL_WARNING("Radio disabled by SW RF kill (module "
5035 iwl_rfkill_set_hw_state(priv
);
5039 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5040 IWL_ERROR("ucode not available for device bringup\n");
5044 /* If platform's RF_KILL switch is NOT set to KILL */
5045 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
5046 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5047 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5049 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5050 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5051 iwl_rfkill_set_hw_state(priv
);
5052 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5057 iwl_rfkill_set_hw_state(priv
);
5058 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5060 ret
= priv
->cfg
->ops
->lib
->alloc_shared_mem(priv
);
5062 IWL_ERROR("Unable to allocate shared memory\n");
5066 ret
= priv
->cfg
->ops
->lib
->hw_nic_init(priv
);
5068 IWL_ERROR("Unable to init nic\n");
5072 /* make sure rfkill handshake bits are cleared */
5073 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5074 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5075 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5077 /* clear (again), then enable host interrupts */
5078 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5079 iwl4965_enable_interrupts(priv
);
5081 /* really make sure rfkill handshake bits are cleared */
5082 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5083 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5085 /* Copy original ucode data image from disk into backup cache.
5086 * This will be used to initialize the on-board processor's
5087 * data SRAM for a clean start when the runtime program first loads. */
5088 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5089 priv
->ucode_data
.len
);
5091 /* We return success when we resume from suspend and rf_kill is on. */
5092 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5095 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5097 iwlcore_clear_stations_table(priv
);
5099 /* load bootstrap state machine,
5100 * load bootstrap program into processor's memory,
5101 * prepare to load the "initialize" uCode */
5102 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
5105 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
5109 /* start card; "initialize" will load runtime ucode */
5110 iwl4965_nic_start(priv
);
5112 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5117 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5118 __iwl4965_down(priv
);
5120 /* tried to restart and config the device for as long as our
5121 * patience could withstand */
5122 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
5127 /*****************************************************************************
5129 * Workqueue callbacks
5131 *****************************************************************************/
5133 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
5135 struct iwl_priv
*priv
=
5136 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
5138 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5141 mutex_lock(&priv
->mutex
);
5142 iwl4965_init_alive_start(priv
);
5143 mutex_unlock(&priv
->mutex
);
5146 static void iwl4965_bg_alive_start(struct work_struct
*data
)
5148 struct iwl_priv
*priv
=
5149 container_of(data
, struct iwl_priv
, alive_start
.work
);
5151 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5154 mutex_lock(&priv
->mutex
);
5155 iwl4965_alive_start(priv
);
5156 mutex_unlock(&priv
->mutex
);
5159 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
5161 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
5163 wake_up_interruptible(&priv
->wait_command_queue
);
5165 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5168 mutex_lock(&priv
->mutex
);
5170 if (!iwl_is_rfkill(priv
)) {
5171 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
5172 "HW and/or SW RF Kill no longer active, restarting "
5174 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5175 queue_work(priv
->workqueue
, &priv
->restart
);
5177 /* make sure mac80211 stop sending Tx frame */
5178 if (priv
->mac80211_registered
)
5179 ieee80211_stop_queues(priv
->hw
);
5181 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5182 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5183 "disabled by SW switch\n");
5185 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5186 "Kill switch must be turned off for "
5187 "wireless networking to work.\n");
5189 iwl_rfkill_set_hw_state(priv
);
5191 mutex_unlock(&priv
->mutex
);
5194 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5196 static void iwl4965_bg_scan_check(struct work_struct
*data
)
5198 struct iwl_priv
*priv
=
5199 container_of(data
, struct iwl_priv
, scan_check
.work
);
5201 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5204 mutex_lock(&priv
->mutex
);
5205 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
5206 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5207 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
5208 "Scan completion watchdog resetting adapter (%dms)\n",
5209 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
5211 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5212 iwl4965_send_scan_abort(priv
);
5214 mutex_unlock(&priv
->mutex
);
5217 static void iwl4965_bg_request_scan(struct work_struct
*data
)
5219 struct iwl_priv
*priv
=
5220 container_of(data
, struct iwl_priv
, request_scan
);
5221 struct iwl_host_cmd cmd
= {
5222 .id
= REPLY_SCAN_CMD
,
5223 .len
= sizeof(struct iwl4965_scan_cmd
),
5224 .meta
.flags
= CMD_SIZE_HUGE
,
5226 struct iwl4965_scan_cmd
*scan
;
5227 struct ieee80211_conf
*conf
= NULL
;
5229 enum ieee80211_band band
;
5233 conf
= ieee80211_get_hw_conf(priv
->hw
);
5235 mutex_lock(&priv
->mutex
);
5237 if (!iwl_is_ready(priv
)) {
5238 IWL_WARNING("request scan called when driver not ready.\n");
5242 /* Make sure the scan wasn't cancelled before this queued work
5243 * was given the chance to run... */
5244 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
5247 /* This should never be called or scheduled if there is currently
5248 * a scan active in the hardware. */
5249 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
5250 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5251 "Ignoring second request.\n");
5256 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5257 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5261 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5262 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5266 if (iwl_is_rfkill(priv
)) {
5267 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5271 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5272 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5276 if (!priv
->scan_bands
) {
5277 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5282 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
5283 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
5290 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
5292 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
5293 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
5295 if (iwl_is_associated(priv
)) {
5298 u32 suspend_time
= 100;
5299 u32 scan_suspend_time
= 100;
5300 unsigned long flags
;
5302 IWL_DEBUG_INFO("Scanning while associated...\n");
5304 spin_lock_irqsave(&priv
->lock
, flags
);
5305 interval
= priv
->beacon_int
;
5306 spin_unlock_irqrestore(&priv
->lock
, flags
);
5308 scan
->suspend_time
= 0;
5309 scan
->max_out_time
= cpu_to_le32(200 * 1024);
5311 interval
= suspend_time
;
5313 extra
= (suspend_time
/ interval
) << 22;
5314 scan_suspend_time
= (extra
|
5315 ((suspend_time
% interval
) * 1024));
5316 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
5317 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5318 scan_suspend_time
, interval
);
5321 /* We should add the ability for user to lock to PASSIVE ONLY */
5322 if (priv
->one_direct_scan
) {
5324 ("Kicking off one direct scan for '%s'\n",
5325 iwl4965_escape_essid(priv
->direct_ssid
,
5326 priv
->direct_ssid_len
));
5327 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5328 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
5329 memcpy(scan
->direct_scan
[0].ssid
,
5330 priv
->direct_ssid
, priv
->direct_ssid_len
);
5332 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
5334 ("Kicking off one direct scan for '%s' when not associated\n",
5335 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
5336 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5337 scan
->direct_scan
[0].len
= priv
->essid_len
;
5338 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
5341 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
5345 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
5346 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
5347 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
5350 switch (priv
->scan_bands
) {
5352 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
5353 scan
->tx_cmd
.rate_n_flags
=
5354 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
5355 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
5357 scan
->good_CRC_th
= 0;
5358 band
= IEEE80211_BAND_2GHZ
;
5362 scan
->tx_cmd
.rate_n_flags
=
5363 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
5364 RATE_MCS_ANT_B_MSK
);
5365 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
5366 band
= IEEE80211_BAND_5GHZ
;
5370 IWL_WARNING("Invalid scan band count\n");
5374 /* We don't build a direct scan probe request; the uCode will do
5375 * that based on the direct_mask added to each channel entry */
5376 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
5377 (struct ieee80211_mgmt
*)scan
->data
,
5378 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
5380 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
5381 /* select Rx chains */
5383 /* Force use of chains B and C (0x6) for scan Rx.
5384 * Avoid A (0x1) because of its off-channel reception on A-band.
5385 * MIMO is not used here, but value is required to make uCode happy. */
5386 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
5387 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
5388 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
5389 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
5391 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
5392 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
5395 scan
->channel_count
=
5396 iwl4965_get_channels_for_scan(
5397 priv
, band
, 1, /* active */
5399 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5401 scan
->channel_count
=
5402 iwl4965_get_channels_for_scan(
5403 priv
, band
, 0, /* passive */
5405 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5407 scan
->filter_flags
|= (RXON_FILTER_ACCEPT_GRP_MSK
|
5408 RXON_FILTER_BCON_AWARE_MSK
);
5409 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
5410 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
5412 scan
->len
= cpu_to_le16(cmd
.len
);
5414 set_bit(STATUS_SCAN_HW
, &priv
->status
);
5415 ret
= iwl_send_cmd_sync(priv
, &cmd
);
5419 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
5420 IWL_SCAN_CHECK_WATCHDOG
);
5422 mutex_unlock(&priv
->mutex
);
5426 /* inform mac80211 scan aborted */
5427 queue_work(priv
->workqueue
, &priv
->scan_completed
);
5428 mutex_unlock(&priv
->mutex
);
5431 static void iwl4965_bg_up(struct work_struct
*data
)
5433 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
5435 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5438 mutex_lock(&priv
->mutex
);
5440 mutex_unlock(&priv
->mutex
);
5443 static void iwl4965_bg_restart(struct work_struct
*data
)
5445 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
5447 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5451 queue_work(priv
->workqueue
, &priv
->up
);
5454 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
5456 struct iwl_priv
*priv
=
5457 container_of(data
, struct iwl_priv
, rx_replenish
);
5459 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5462 mutex_lock(&priv
->mutex
);
5463 iwl4965_rx_replenish(priv
);
5464 mutex_unlock(&priv
->mutex
);
5467 #define IWL_DELAY_NEXT_SCAN (HZ*2)
5469 static void iwl4965_post_associate(struct iwl_priv
*priv
)
5471 struct ieee80211_conf
*conf
= NULL
;
5473 DECLARE_MAC_BUF(mac
);
5475 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
5476 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
5480 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
5482 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
5485 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5489 if (!priv
->vif
|| !priv
->is_open
)
5492 iwl4965_scan_cancel_timeout(priv
, 200);
5494 conf
= ieee80211_get_hw_conf(priv
->hw
);
5496 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5497 iwl4965_commit_rxon(priv
);
5499 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
5500 iwl4965_setup_rxon_timing(priv
);
5501 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
5502 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
5504 IWL_WARNING("REPLY_RXON_TIMING failed - "
5505 "Attempting to continue.\n");
5507 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
5509 #ifdef CONFIG_IWL4965_HT
5510 if (priv
->current_ht_config
.is_ht
)
5511 iwl4965_set_rxon_ht(priv
, &priv
->current_ht_config
);
5512 #endif /* CONFIG_IWL4965_HT*/
5513 iwl_set_rxon_chain(priv
);
5514 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
5516 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
5517 priv
->assoc_id
, priv
->beacon_int
);
5519 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
5520 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
5522 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5524 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
5525 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
5526 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
5528 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
5530 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
5531 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
5535 iwl4965_commit_rxon(priv
);
5537 switch (priv
->iw_mode
) {
5538 case IEEE80211_IF_TYPE_STA
:
5539 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
5542 case IEEE80211_IF_TYPE_IBSS
:
5544 /* clear out the station table */
5545 iwlcore_clear_stations_table(priv
);
5547 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
5548 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
5549 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
5550 iwl4965_send_beacon_cmd(priv
);
5555 IWL_ERROR("%s Should not be called in %d mode\n",
5556 __FUNCTION__
, priv
->iw_mode
);
5560 iwl4965_sequence_reset(priv
);
5562 /* Enable Rx differential gain and sensitivity calibrations */
5563 iwl_chain_noise_reset(priv
);
5564 priv
->start_calib
= 1;
5566 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
5567 priv
->assoc_station_added
= 1;
5569 iwl4965_activate_qos(priv
, 0);
5571 iwl_power_update_mode(priv
, 0);
5572 /* we have just associated, don't start scan too early */
5573 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
5577 static void iwl4965_bg_post_associate(struct work_struct
*data
)
5579 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
5580 post_associate
.work
);
5582 mutex_lock(&priv
->mutex
);
5583 iwl4965_post_associate(priv
);
5584 mutex_unlock(&priv
->mutex
);
5588 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
5590 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
5592 if (!iwl_is_ready(priv
))
5595 mutex_lock(&priv
->mutex
);
5597 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
5598 iwl4965_send_scan_abort(priv
);
5600 mutex_unlock(&priv
->mutex
);
5603 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
5605 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
5607 struct iwl_priv
*priv
=
5608 container_of(work
, struct iwl_priv
, scan_completed
);
5610 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
5612 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5615 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
5616 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
5618 ieee80211_scan_completed(priv
->hw
);
5620 /* Since setting the TXPOWER may have been deferred while
5621 * performing the scan, fire one off */
5622 mutex_lock(&priv
->mutex
);
5623 iwl4965_hw_reg_send_txpower(priv
);
5624 mutex_unlock(&priv
->mutex
);
5627 /*****************************************************************************
5629 * mac80211 entry point functions
5631 *****************************************************************************/
5633 #define UCODE_READY_TIMEOUT (2 * HZ)
5635 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
5637 struct iwl_priv
*priv
= hw
->priv
;
5640 IWL_DEBUG_MAC80211("enter\n");
5642 if (pci_enable_device(priv
->pci_dev
)) {
5643 IWL_ERROR("Fail to pci_enable_device\n");
5646 pci_restore_state(priv
->pci_dev
);
5647 pci_enable_msi(priv
->pci_dev
);
5649 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
5652 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
5653 goto out_disable_msi
;
5656 /* we should be verifying the device is ready to be opened */
5657 mutex_lock(&priv
->mutex
);
5659 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
5660 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
5661 * ucode filename and max sizes are card-specific. */
5663 if (!priv
->ucode_code
.len
) {
5664 ret
= iwl4965_read_ucode(priv
);
5666 IWL_ERROR("Could not read microcode: %d\n", ret
);
5667 mutex_unlock(&priv
->mutex
);
5668 goto out_release_irq
;
5672 ret
= __iwl4965_up(priv
);
5674 mutex_unlock(&priv
->mutex
);
5677 goto out_release_irq
;
5679 IWL_DEBUG_INFO("Start UP work done.\n");
5681 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
5684 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
5685 * mac80211 will not be run successfully. */
5686 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
5687 test_bit(STATUS_READY
, &priv
->status
),
5688 UCODE_READY_TIMEOUT
);
5690 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5691 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
5692 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
5694 goto out_release_irq
;
5699 IWL_DEBUG_MAC80211("leave\n");
5703 free_irq(priv
->pci_dev
->irq
, priv
);
5705 pci_disable_msi(priv
->pci_dev
);
5706 pci_disable_device(priv
->pci_dev
);
5708 IWL_DEBUG_MAC80211("leave - failed\n");
5712 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
5714 struct iwl_priv
*priv
= hw
->priv
;
5716 IWL_DEBUG_MAC80211("enter\n");
5718 if (!priv
->is_open
) {
5719 IWL_DEBUG_MAC80211("leave - skip\n");
5725 if (iwl_is_ready_rf(priv
)) {
5726 /* stop mac, cancel any scan request and clear
5727 * RXON_FILTER_ASSOC_MSK BIT
5729 mutex_lock(&priv
->mutex
);
5730 iwl4965_scan_cancel_timeout(priv
, 100);
5731 cancel_delayed_work(&priv
->post_associate
);
5732 mutex_unlock(&priv
->mutex
);
5737 flush_workqueue(priv
->workqueue
);
5738 free_irq(priv
->pci_dev
->irq
, priv
);
5739 pci_disable_msi(priv
->pci_dev
);
5740 pci_save_state(priv
->pci_dev
);
5741 pci_disable_device(priv
->pci_dev
);
5743 IWL_DEBUG_MAC80211("leave\n");
5746 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
5747 struct ieee80211_tx_control
*ctl
)
5749 struct iwl_priv
*priv
= hw
->priv
;
5751 IWL_DEBUG_MAC80211("enter\n");
5753 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
5754 IWL_DEBUG_MAC80211("leave - monitor\n");
5758 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
5759 ctl
->tx_rate
->bitrate
);
5761 if (iwl4965_tx_skb(priv
, skb
, ctl
))
5762 dev_kfree_skb_any(skb
);
5764 IWL_DEBUG_MAC80211("leave\n");
5768 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
5769 struct ieee80211_if_init_conf
*conf
)
5771 struct iwl_priv
*priv
= hw
->priv
;
5772 unsigned long flags
;
5773 DECLARE_MAC_BUF(mac
);
5775 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
5778 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
5782 spin_lock_irqsave(&priv
->lock
, flags
);
5783 priv
->vif
= conf
->vif
;
5785 spin_unlock_irqrestore(&priv
->lock
, flags
);
5787 mutex_lock(&priv
->mutex
);
5789 if (conf
->mac_addr
) {
5790 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
5791 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
5794 if (iwl_is_ready(priv
))
5795 iwl4965_set_mode(priv
, conf
->type
);
5797 mutex_unlock(&priv
->mutex
);
5799 IWL_DEBUG_MAC80211("leave\n");
5804 * iwl4965_mac_config - mac80211 config callback
5806 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
5807 * be set inappropriately and the driver currently sets the hardware up to
5808 * use it whenever needed.
5810 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
5812 struct iwl_priv
*priv
= hw
->priv
;
5813 const struct iwl_channel_info
*ch_info
;
5814 unsigned long flags
;
5817 mutex_lock(&priv
->mutex
);
5818 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
5820 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
5822 if (!iwl_is_ready(priv
)) {
5823 IWL_DEBUG_MAC80211("leave - not ready\n");
5828 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
5829 test_bit(STATUS_SCANNING
, &priv
->status
))) {
5830 IWL_DEBUG_MAC80211("leave - scanning\n");
5831 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
5832 mutex_unlock(&priv
->mutex
);
5836 spin_lock_irqsave(&priv
->lock
, flags
);
5838 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
,
5839 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
5840 if (!is_channel_valid(ch_info
)) {
5841 IWL_DEBUG_MAC80211("leave - invalid channel\n");
5842 spin_unlock_irqrestore(&priv
->lock
, flags
);
5847 #ifdef CONFIG_IWL4965_HT
5848 /* if we are switching from ht to 2.4 clear flags
5849 * from any ht related info since 2.4 does not
5851 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
->hw_value
)
5852 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
5853 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
5856 priv
->staging_rxon
.flags
= 0;
5857 #endif /* CONFIG_IWL4965_HT */
5859 iwl_set_rxon_channel(priv
, conf
->channel
->band
,
5860 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
5862 iwl4965_set_flags_for_phymode(priv
, conf
->channel
->band
);
5864 /* The list of supported rates and rate mask can be different
5865 * for each band; since the band may have changed, reset
5866 * the rate mask to what mac80211 lists */
5867 iwl4965_set_rate(priv
);
5869 spin_unlock_irqrestore(&priv
->lock
, flags
);
5871 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
5872 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
5873 iwl4965_hw_channel_switch(priv
, conf
->channel
);
5878 if (priv
->cfg
->ops
->lib
->radio_kill_sw
)
5879 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, !conf
->radio_enabled
);
5881 if (!conf
->radio_enabled
) {
5882 IWL_DEBUG_MAC80211("leave - radio disabled\n");
5886 if (iwl_is_rfkill(priv
)) {
5887 IWL_DEBUG_MAC80211("leave - RF kill\n");
5892 iwl4965_set_rate(priv
);
5894 if (memcmp(&priv
->active_rxon
,
5895 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
5896 iwl4965_commit_rxon(priv
);
5898 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
5900 IWL_DEBUG_MAC80211("leave\n");
5903 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
5904 mutex_unlock(&priv
->mutex
);
5908 static void iwl4965_config_ap(struct iwl_priv
*priv
)
5912 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5915 /* The following should be done only at AP bring up */
5916 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
5918 /* RXON - unassoc (to set timing command) */
5919 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5920 iwl4965_commit_rxon(priv
);
5923 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
5924 iwl4965_setup_rxon_timing(priv
);
5925 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
5926 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
5928 IWL_WARNING("REPLY_RXON_TIMING failed - "
5929 "Attempting to continue.\n");
5931 iwl_set_rxon_chain(priv
);
5933 /* FIXME: what should be the assoc_id for AP? */
5934 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
5935 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
5936 priv
->staging_rxon
.flags
|=
5937 RXON_FLG_SHORT_PREAMBLE_MSK
;
5939 priv
->staging_rxon
.flags
&=
5940 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5942 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
5943 if (priv
->assoc_capability
&
5944 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
5945 priv
->staging_rxon
.flags
|=
5946 RXON_FLG_SHORT_SLOT_MSK
;
5948 priv
->staging_rxon
.flags
&=
5949 ~RXON_FLG_SHORT_SLOT_MSK
;
5951 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
5952 priv
->staging_rxon
.flags
&=
5953 ~RXON_FLG_SHORT_SLOT_MSK
;
5955 /* restore RXON assoc */
5956 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
5957 iwl4965_commit_rxon(priv
);
5958 iwl4965_activate_qos(priv
, 1);
5959 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
5961 iwl4965_send_beacon_cmd(priv
);
5963 /* FIXME - we need to add code here to detect a totally new
5964 * configuration, reset the AP, unassoc, rxon timing, assoc,
5965 * clear sta table, add BCAST sta... */
5968 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
5969 struct ieee80211_vif
*vif
,
5970 struct ieee80211_if_conf
*conf
)
5972 struct iwl_priv
*priv
= hw
->priv
;
5973 DECLARE_MAC_BUF(mac
);
5974 unsigned long flags
;
5980 if (priv
->vif
!= vif
) {
5981 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
5985 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
5986 (!conf
->beacon
|| !conf
->ssid_len
)) {
5988 ("Leaving in AP mode because HostAPD is not ready.\n");
5992 if (!iwl_is_alive(priv
))
5995 mutex_lock(&priv
->mutex
);
5998 IWL_DEBUG_MAC80211("bssid: %s\n",
5999 print_mac(mac
, conf
->bssid
));
6002 * very dubious code was here; the probe filtering flag is never set:
6004 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6005 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6008 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6010 conf
->bssid
= priv
->mac_addr
;
6011 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6012 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6013 print_mac(mac
, conf
->bssid
));
6015 if (priv
->ibss_beacon
)
6016 dev_kfree_skb(priv
->ibss_beacon
);
6018 priv
->ibss_beacon
= conf
->beacon
;
6021 if (iwl_is_rfkill(priv
))
6024 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6025 !is_multicast_ether_addr(conf
->bssid
)) {
6026 /* If there is currently a HW scan going on in the background
6027 * then we need to cancel it else the RXON below will fail. */
6028 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
6029 IWL_WARNING("Aborted scan still in progress "
6031 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6032 mutex_unlock(&priv
->mutex
);
6035 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6037 /* TODO: Audit driver for usage of these members and see
6038 * if mac80211 deprecates them (priv->bssid looks like it
6039 * shouldn't be there, but I haven't scanned the IBSS code
6040 * to verify) - jpk */
6041 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6043 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6044 iwl4965_config_ap(priv
);
6046 rc
= iwl4965_commit_rxon(priv
);
6047 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
6048 iwl4965_rxon_add_station(
6049 priv
, priv
->active_rxon
.bssid_addr
, 1);
6053 iwl4965_scan_cancel_timeout(priv
, 100);
6054 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6055 iwl4965_commit_rxon(priv
);
6059 spin_lock_irqsave(&priv
->lock
, flags
);
6060 if (!conf
->ssid_len
)
6061 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6063 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
6065 priv
->essid_len
= conf
->ssid_len
;
6066 spin_unlock_irqrestore(&priv
->lock
, flags
);
6068 IWL_DEBUG_MAC80211("leave\n");
6069 mutex_unlock(&priv
->mutex
);
6074 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
6075 unsigned int changed_flags
,
6076 unsigned int *total_flags
,
6077 int mc_count
, struct dev_addr_list
*mc_list
)
6081 * see also iwl4965_connection_init_rx_config
6086 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
6087 struct ieee80211_if_init_conf
*conf
)
6089 struct iwl_priv
*priv
= hw
->priv
;
6091 IWL_DEBUG_MAC80211("enter\n");
6093 mutex_lock(&priv
->mutex
);
6095 if (iwl_is_ready_rf(priv
)) {
6096 iwl4965_scan_cancel_timeout(priv
, 100);
6097 cancel_delayed_work(&priv
->post_associate
);
6098 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6099 iwl4965_commit_rxon(priv
);
6101 if (priv
->vif
== conf
->vif
) {
6103 memset(priv
->bssid
, 0, ETH_ALEN
);
6104 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6105 priv
->essid_len
= 0;
6107 mutex_unlock(&priv
->mutex
);
6109 IWL_DEBUG_MAC80211("leave\n");
6113 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6114 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
6115 struct ieee80211_vif
*vif
,
6116 struct ieee80211_bss_conf
*bss_conf
,
6119 struct iwl_priv
*priv
= hw
->priv
;
6121 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
6123 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
6124 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6125 bss_conf
->use_short_preamble
);
6126 if (bss_conf
->use_short_preamble
)
6127 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6129 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6132 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
6133 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
6134 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
6135 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
6137 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
6140 if (changes
& BSS_CHANGED_HT
) {
6141 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
6142 iwl4965_ht_conf(priv
, bss_conf
);
6143 iwl_set_rxon_chain(priv
);
6146 if (changes
& BSS_CHANGED_ASSOC
) {
6147 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
6148 /* This should never happen as this function should
6149 * never be called from interrupt context. */
6150 if (WARN_ON_ONCE(in_interrupt()))
6152 if (bss_conf
->assoc
) {
6153 priv
->assoc_id
= bss_conf
->aid
;
6154 priv
->beacon_int
= bss_conf
->beacon_int
;
6155 priv
->timestamp
= bss_conf
->timestamp
;
6156 priv
->assoc_capability
= bss_conf
->assoc_capability
;
6157 priv
->next_scan_jiffies
= jiffies
+
6158 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
6159 mutex_lock(&priv
->mutex
);
6160 iwl4965_post_associate(priv
);
6161 mutex_unlock(&priv
->mutex
);
6164 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
6166 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
6167 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
6168 iwl_send_rxon_assoc(priv
);
6173 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6176 unsigned long flags
;
6177 struct iwl_priv
*priv
= hw
->priv
;
6179 IWL_DEBUG_MAC80211("enter\n");
6181 mutex_lock(&priv
->mutex
);
6182 spin_lock_irqsave(&priv
->lock
, flags
);
6184 if (!iwl_is_ready_rf(priv
)) {
6186 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6190 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
6192 IWL_ERROR("ERROR: APs don't scan\n");
6196 /* we don't schedule scan within next_scan_jiffies period */
6197 if (priv
->next_scan_jiffies
&&
6198 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6202 /* if we just finished scan ask for delay */
6203 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
6204 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
6209 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6210 iwl4965_escape_essid(ssid
, len
), (int)len
);
6212 priv
->one_direct_scan
= 1;
6213 priv
->direct_ssid_len
= (u8
)
6214 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6215 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6217 priv
->one_direct_scan
= 0;
6219 rc
= iwl4965_scan_initiate(priv
);
6221 IWL_DEBUG_MAC80211("leave\n");
6224 spin_unlock_irqrestore(&priv
->lock
, flags
);
6225 mutex_unlock(&priv
->mutex
);
6230 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
6231 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
6232 u32 iv32
, u16
*phase1key
)
6234 struct iwl_priv
*priv
= hw
->priv
;
6235 u8 sta_id
= IWL_INVALID_STATION
;
6236 unsigned long flags
;
6237 __le16 key_flags
= 0;
6239 DECLARE_MAC_BUF(mac
);
6241 IWL_DEBUG_MAC80211("enter\n");
6243 sta_id
= iwl_find_station(priv
, addr
);
6244 if (sta_id
== IWL_INVALID_STATION
) {
6245 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6246 print_mac(mac
, addr
));
6250 iwl4965_scan_cancel_timeout(priv
, 100);
6252 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
6253 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
6254 key_flags
&= ~STA_KEY_FLG_INVALID
;
6256 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
6257 key_flags
|= STA_KEY_MULTICAST_MSK
;
6259 spin_lock_irqsave(&priv
->sta_lock
, flags
);
6261 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
6262 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
6264 for (i
= 0; i
< 5; i
++)
6265 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
6266 cpu_to_le16(phase1key
[i
]);
6268 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
6269 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
6271 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
6273 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
6275 IWL_DEBUG_MAC80211("leave\n");
6278 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6279 const u8
*local_addr
, const u8
*addr
,
6280 struct ieee80211_key_conf
*key
)
6282 struct iwl_priv
*priv
= hw
->priv
;
6283 DECLARE_MAC_BUF(mac
);
6285 u8 sta_id
= IWL_INVALID_STATION
;
6286 u8 is_default_wep_key
= 0;
6288 IWL_DEBUG_MAC80211("enter\n");
6290 if (priv
->hw_params
.sw_crypto
) {
6291 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6295 if (is_zero_ether_addr(addr
))
6296 /* only support pairwise keys */
6299 sta_id
= iwl_find_station(priv
, addr
);
6300 if (sta_id
== IWL_INVALID_STATION
) {
6301 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6302 print_mac(mac
, addr
));
6307 mutex_lock(&priv
->mutex
);
6308 iwl4965_scan_cancel_timeout(priv
, 100);
6309 mutex_unlock(&priv
->mutex
);
6311 /* If we are getting WEP group key and we didn't receive any key mapping
6312 * so far, we are in legacy wep mode (group key only), otherwise we are
6314 * In legacy wep mode, we use another host command to the uCode */
6315 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_params
.bcast_sta_id
&&
6316 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
6318 is_default_wep_key
= !priv
->key_mapping_key
;
6320 is_default_wep_key
= priv
->default_wep_key
;
6325 if (is_default_wep_key
)
6326 ret
= iwl_set_default_wep_key(priv
, key
);
6328 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
6330 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
6333 if (is_default_wep_key
)
6334 ret
= iwl_remove_default_wep_key(priv
, key
);
6336 ret
= iwl_remove_dynamic_key(priv
, key
, sta_id
);
6338 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6344 IWL_DEBUG_MAC80211("leave\n");
6349 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
6350 const struct ieee80211_tx_queue_params
*params
)
6352 struct iwl_priv
*priv
= hw
->priv
;
6353 unsigned long flags
;
6356 IWL_DEBUG_MAC80211("enter\n");
6358 if (!iwl_is_ready_rf(priv
)) {
6359 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6363 if (queue
>= AC_NUM
) {
6364 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
6368 if (!priv
->qos_data
.qos_enable
) {
6369 priv
->qos_data
.qos_active
= 0;
6370 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
6373 q
= AC_NUM
- 1 - queue
;
6375 spin_lock_irqsave(&priv
->lock
, flags
);
6377 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
6378 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
6379 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
6380 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
6381 cpu_to_le16((params
->txop
* 32));
6383 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
6384 priv
->qos_data
.qos_active
= 1;
6386 spin_unlock_irqrestore(&priv
->lock
, flags
);
6388 mutex_lock(&priv
->mutex
);
6389 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6390 iwl4965_activate_qos(priv
, 1);
6391 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
6392 iwl4965_activate_qos(priv
, 0);
6394 mutex_unlock(&priv
->mutex
);
6396 IWL_DEBUG_MAC80211("leave\n");
6400 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
6401 struct ieee80211_tx_queue_stats
*stats
)
6403 struct iwl_priv
*priv
= hw
->priv
;
6405 struct iwl4965_tx_queue
*txq
;
6406 struct iwl4965_queue
*q
;
6407 unsigned long flags
;
6409 IWL_DEBUG_MAC80211("enter\n");
6411 if (!iwl_is_ready_rf(priv
)) {
6412 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6416 spin_lock_irqsave(&priv
->lock
, flags
);
6418 for (i
= 0; i
< AC_NUM
; i
++) {
6419 txq
= &priv
->txq
[i
];
6421 avail
= iwl4965_queue_space(q
);
6423 stats
->data
[i
].len
= q
->n_window
- avail
;
6424 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
6425 stats
->data
[i
].count
= q
->n_window
;
6428 spin_unlock_irqrestore(&priv
->lock
, flags
);
6430 IWL_DEBUG_MAC80211("leave\n");
6435 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
6436 struct ieee80211_low_level_stats
*stats
)
6438 IWL_DEBUG_MAC80211("enter\n");
6439 IWL_DEBUG_MAC80211("leave\n");
6444 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
6446 IWL_DEBUG_MAC80211("enter\n");
6447 IWL_DEBUG_MAC80211("leave\n");
6452 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
6454 struct iwl_priv
*priv
= hw
->priv
;
6455 unsigned long flags
;
6457 mutex_lock(&priv
->mutex
);
6458 IWL_DEBUG_MAC80211("enter\n");
6460 priv
->lq_mngr
.lq_ready
= 0;
6461 #ifdef CONFIG_IWL4965_HT
6462 spin_lock_irqsave(&priv
->lock
, flags
);
6463 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
6464 spin_unlock_irqrestore(&priv
->lock
, flags
);
6465 #endif /* CONFIG_IWL4965_HT */
6467 iwl_reset_qos(priv
);
6469 cancel_delayed_work(&priv
->post_associate
);
6471 spin_lock_irqsave(&priv
->lock
, flags
);
6473 priv
->assoc_capability
= 0;
6474 priv
->assoc_station_added
= 0;
6476 /* new association get rid of ibss beacon skb */
6477 if (priv
->ibss_beacon
)
6478 dev_kfree_skb(priv
->ibss_beacon
);
6480 priv
->ibss_beacon
= NULL
;
6482 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
6483 priv
->timestamp
= 0;
6484 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
6485 priv
->beacon_int
= 0;
6487 spin_unlock_irqrestore(&priv
->lock
, flags
);
6489 if (!iwl_is_ready_rf(priv
)) {
6490 IWL_DEBUG_MAC80211("leave - not ready\n");
6491 mutex_unlock(&priv
->mutex
);
6495 /* we are restarting association process
6496 * clear RXON_FILTER_ASSOC_MSK bit
6498 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
6499 iwl4965_scan_cancel_timeout(priv
, 100);
6500 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6501 iwl4965_commit_rxon(priv
);
6504 iwl_power_update_mode(priv
, 0);
6506 /* Per mac80211.h: This is only used in IBSS mode... */
6507 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
6509 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
6510 mutex_unlock(&priv
->mutex
);
6514 iwl4965_set_rate(priv
);
6516 mutex_unlock(&priv
->mutex
);
6518 IWL_DEBUG_MAC80211("leave\n");
6521 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6522 struct ieee80211_tx_control
*control
)
6524 struct iwl_priv
*priv
= hw
->priv
;
6525 unsigned long flags
;
6527 mutex_lock(&priv
->mutex
);
6528 IWL_DEBUG_MAC80211("enter\n");
6530 if (!iwl_is_ready_rf(priv
)) {
6531 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6532 mutex_unlock(&priv
->mutex
);
6536 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
6537 IWL_DEBUG_MAC80211("leave - not IBSS\n");
6538 mutex_unlock(&priv
->mutex
);
6542 spin_lock_irqsave(&priv
->lock
, flags
);
6544 if (priv
->ibss_beacon
)
6545 dev_kfree_skb(priv
->ibss_beacon
);
6547 priv
->ibss_beacon
= skb
;
6551 IWL_DEBUG_MAC80211("leave\n");
6552 spin_unlock_irqrestore(&priv
->lock
, flags
);
6554 iwl_reset_qos(priv
);
6556 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
6558 mutex_unlock(&priv
->mutex
);
6563 /*****************************************************************************
6567 *****************************************************************************/
6569 #ifdef CONFIG_IWLWIFI_DEBUG
6572 * The following adds a new attribute to the sysfs representation
6573 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
6574 * used for controlling the debug level.
6576 * See the level definitions in iwl for details.
6579 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
6581 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
6583 static ssize_t
store_debug_level(struct device_driver
*d
,
6584 const char *buf
, size_t count
)
6586 char *p
= (char *)buf
;
6589 val
= simple_strtoul(p
, &p
, 0);
6591 printk(KERN_INFO DRV_NAME
6592 ": %s is not in hex or decimal form.\n", buf
);
6594 iwl_debug_level
= val
;
6596 return strnlen(buf
, count
);
6599 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
6600 show_debug_level
, store_debug_level
);
6602 #endif /* CONFIG_IWLWIFI_DEBUG */
6605 static ssize_t
show_temperature(struct device
*d
,
6606 struct device_attribute
*attr
, char *buf
)
6608 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6610 if (!iwl_is_alive(priv
))
6613 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
6616 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
6618 static ssize_t
show_rs_window(struct device
*d
,
6619 struct device_attribute
*attr
,
6622 struct iwl_priv
*priv
= d
->driver_data
;
6623 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
6625 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
6627 static ssize_t
show_tx_power(struct device
*d
,
6628 struct device_attribute
*attr
, char *buf
)
6630 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6631 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
6634 static ssize_t
store_tx_power(struct device
*d
,
6635 struct device_attribute
*attr
,
6636 const char *buf
, size_t count
)
6638 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6639 char *p
= (char *)buf
;
6642 val
= simple_strtoul(p
, &p
, 10);
6644 printk(KERN_INFO DRV_NAME
6645 ": %s is not in decimal form.\n", buf
);
6647 iwl4965_hw_reg_set_txpower(priv
, val
);
6652 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
6654 static ssize_t
show_flags(struct device
*d
,
6655 struct device_attribute
*attr
, char *buf
)
6657 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6659 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
6662 static ssize_t
store_flags(struct device
*d
,
6663 struct device_attribute
*attr
,
6664 const char *buf
, size_t count
)
6666 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6667 u32 flags
= simple_strtoul(buf
, NULL
, 0);
6669 mutex_lock(&priv
->mutex
);
6670 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
6671 /* Cancel any currently running scans... */
6672 if (iwl4965_scan_cancel_timeout(priv
, 100))
6673 IWL_WARNING("Could not cancel scan.\n");
6675 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
6677 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
6678 iwl4965_commit_rxon(priv
);
6681 mutex_unlock(&priv
->mutex
);
6686 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
6688 static ssize_t
show_filter_flags(struct device
*d
,
6689 struct device_attribute
*attr
, char *buf
)
6691 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6693 return sprintf(buf
, "0x%04X\n",
6694 le32_to_cpu(priv
->active_rxon
.filter_flags
));
6697 static ssize_t
store_filter_flags(struct device
*d
,
6698 struct device_attribute
*attr
,
6699 const char *buf
, size_t count
)
6701 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6702 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
6704 mutex_lock(&priv
->mutex
);
6705 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
6706 /* Cancel any currently running scans... */
6707 if (iwl4965_scan_cancel_timeout(priv
, 100))
6708 IWL_WARNING("Could not cancel scan.\n");
6710 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
6711 "0x%04X\n", filter_flags
);
6712 priv
->staging_rxon
.filter_flags
=
6713 cpu_to_le32(filter_flags
);
6714 iwl4965_commit_rxon(priv
);
6717 mutex_unlock(&priv
->mutex
);
6722 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
6723 store_filter_flags
);
6725 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
6727 static ssize_t
show_measurement(struct device
*d
,
6728 struct device_attribute
*attr
, char *buf
)
6730 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6731 struct iwl4965_spectrum_notification measure_report
;
6732 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
6733 u8
*data
= (u8
*) & measure_report
;
6734 unsigned long flags
;
6736 spin_lock_irqsave(&priv
->lock
, flags
);
6737 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
6738 spin_unlock_irqrestore(&priv
->lock
, flags
);
6741 memcpy(&measure_report
, &priv
->measure_report
, size
);
6742 priv
->measurement_status
= 0;
6743 spin_unlock_irqrestore(&priv
->lock
, flags
);
6745 while (size
&& (PAGE_SIZE
- len
)) {
6746 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
6747 PAGE_SIZE
- len
, 1);
6749 if (PAGE_SIZE
- len
)
6753 size
-= min(size
, 16U);
6759 static ssize_t
store_measurement(struct device
*d
,
6760 struct device_attribute
*attr
,
6761 const char *buf
, size_t count
)
6763 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6764 struct ieee80211_measurement_params params
= {
6765 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
6766 .start_time
= cpu_to_le64(priv
->last_tsf
),
6767 .duration
= cpu_to_le16(1),
6769 u8 type
= IWL_MEASURE_BASIC
;
6775 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
6776 channel
= simple_strtoul(p
, NULL
, 0);
6778 params
.channel
= channel
;
6781 while (*p
&& *p
!= ' ')
6784 type
= simple_strtoul(p
+ 1, NULL
, 0);
6787 IWL_DEBUG_INFO("Invoking measurement of type %d on "
6788 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
6789 iwl4965_get_measurement(priv
, ¶ms
, type
);
6794 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
6795 show_measurement
, store_measurement
);
6796 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
6798 static ssize_t
store_retry_rate(struct device
*d
,
6799 struct device_attribute
*attr
,
6800 const char *buf
, size_t count
)
6802 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6804 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
6805 if (priv
->retry_rate
<= 0)
6806 priv
->retry_rate
= 1;
6811 static ssize_t
show_retry_rate(struct device
*d
,
6812 struct device_attribute
*attr
, char *buf
)
6814 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6815 return sprintf(buf
, "%d", priv
->retry_rate
);
6818 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
6821 static ssize_t
store_power_level(struct device
*d
,
6822 struct device_attribute
*attr
,
6823 const char *buf
, size_t count
)
6825 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6829 mode
= simple_strtoul(buf
, NULL
, 0);
6830 mutex_lock(&priv
->mutex
);
6832 if (!iwl_is_ready(priv
)) {
6837 rc
= iwl_power_set_user_mode(priv
, mode
);
6839 IWL_DEBUG_MAC80211("failed setting power mode.\n");
6845 mutex_unlock(&priv
->mutex
);
6849 #define MAX_WX_STRING 80
6851 /* Values are in microsecond */
6852 static const s32 timeout_duration
[] = {
6859 static const s32 period_duration
[] = {
6867 static ssize_t
show_power_level(struct device
*d
,
6868 struct device_attribute
*attr
, char *buf
)
6870 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6871 int level
= priv
->power_data
.power_mode
;
6874 p
+= sprintf(p
, "%d ", level
);
6876 case IWL_POWER_MODE_CAM
:
6878 p
+= sprintf(p
, "(AC)");
6880 case IWL_POWER_BATTERY
:
6881 p
+= sprintf(p
, "(BATTERY)");
6885 "(Timeout %dms, Period %dms)",
6886 timeout_duration
[level
- 1] / 1000,
6887 period_duration
[level
- 1] / 1000);
6890 if (!(priv->power_mode & IWL_POWER_ENABLED))
6891 p += sprintf(p, " OFF\n");
6893 p += sprintf(p, " \n");
6895 p
+= sprintf(p
, " \n");
6896 return (p
- buf
+ 1);
6899 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
6902 static ssize_t
show_channels(struct device
*d
,
6903 struct device_attribute
*attr
, char *buf
)
6905 /* all this shit doesn't belong into sysfs anyway */
6909 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
6911 static ssize_t
show_statistics(struct device
*d
,
6912 struct device_attribute
*attr
, char *buf
)
6914 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6915 u32 size
= sizeof(struct iwl4965_notif_statistics
);
6916 u32 len
= 0, ofs
= 0;
6917 u8
*data
= (u8
*) & priv
->statistics
;
6920 if (!iwl_is_alive(priv
))
6923 mutex_lock(&priv
->mutex
);
6924 rc
= iwl_send_statistics_request(priv
, 0);
6925 mutex_unlock(&priv
->mutex
);
6929 "Error sending statistics request: 0x%08X\n", rc
);
6933 while (size
&& (PAGE_SIZE
- len
)) {
6934 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
6935 PAGE_SIZE
- len
, 1);
6937 if (PAGE_SIZE
- len
)
6941 size
-= min(size
, 16U);
6947 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
6949 static ssize_t
show_status(struct device
*d
,
6950 struct device_attribute
*attr
, char *buf
)
6952 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6953 if (!iwl_is_alive(priv
))
6955 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
6958 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
6960 static ssize_t
dump_error_log(struct device
*d
,
6961 struct device_attribute
*attr
,
6962 const char *buf
, size_t count
)
6964 char *p
= (char *)buf
;
6967 iwl4965_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
6969 return strnlen(buf
, count
);
6972 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
6974 static ssize_t
dump_event_log(struct device
*d
,
6975 struct device_attribute
*attr
,
6976 const char *buf
, size_t count
)
6978 char *p
= (char *)buf
;
6981 iwl4965_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
6983 return strnlen(buf
, count
);
6986 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
6988 /*****************************************************************************
6990 * driver setup and teardown
6992 *****************************************************************************/
6994 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
6996 priv
->workqueue
= create_workqueue(DRV_NAME
);
6998 init_waitqueue_head(&priv
->wait_command_queue
);
7000 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
7001 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
7002 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
7003 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
7004 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
7005 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
7006 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
7007 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
7008 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
7009 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
7010 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
7011 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
7013 iwl4965_hw_setup_deferred_work(priv
);
7015 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7016 iwl4965_irq_tasklet
, (unsigned long)priv
);
7019 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
7021 iwl4965_hw_cancel_deferred_work(priv
);
7023 cancel_delayed_work_sync(&priv
->init_alive_start
);
7024 cancel_delayed_work(&priv
->scan_check
);
7025 cancel_delayed_work(&priv
->alive_start
);
7026 cancel_delayed_work(&priv
->post_associate
);
7027 cancel_work_sync(&priv
->beacon_update
);
7030 static struct attribute
*iwl4965_sysfs_entries
[] = {
7031 &dev_attr_channels
.attr
,
7032 &dev_attr_dump_errors
.attr
,
7033 &dev_attr_dump_events
.attr
,
7034 &dev_attr_flags
.attr
,
7035 &dev_attr_filter_flags
.attr
,
7036 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7037 &dev_attr_measurement
.attr
,
7039 &dev_attr_power_level
.attr
,
7040 &dev_attr_retry_rate
.attr
,
7041 &dev_attr_rs_window
.attr
,
7042 &dev_attr_statistics
.attr
,
7043 &dev_attr_status
.attr
,
7044 &dev_attr_temperature
.attr
,
7045 &dev_attr_tx_power
.attr
,
7050 static struct attribute_group iwl4965_attribute_group
= {
7051 .name
= NULL
, /* put in device directory */
7052 .attrs
= iwl4965_sysfs_entries
,
7055 static struct ieee80211_ops iwl4965_hw_ops
= {
7056 .tx
= iwl4965_mac_tx
,
7057 .start
= iwl4965_mac_start
,
7058 .stop
= iwl4965_mac_stop
,
7059 .add_interface
= iwl4965_mac_add_interface
,
7060 .remove_interface
= iwl4965_mac_remove_interface
,
7061 .config
= iwl4965_mac_config
,
7062 .config_interface
= iwl4965_mac_config_interface
,
7063 .configure_filter
= iwl4965_configure_filter
,
7064 .set_key
= iwl4965_mac_set_key
,
7065 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
7066 .get_stats
= iwl4965_mac_get_stats
,
7067 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
7068 .conf_tx
= iwl4965_mac_conf_tx
,
7069 .get_tsf
= iwl4965_mac_get_tsf
,
7070 .reset_tsf
= iwl4965_mac_reset_tsf
,
7071 .beacon_update
= iwl4965_mac_beacon_update
,
7072 .bss_info_changed
= iwl4965_bss_info_changed
,
7073 #ifdef CONFIG_IWL4965_HT
7074 .ampdu_action
= iwl4965_mac_ampdu_action
,
7075 #endif /* CONFIG_IWL4965_HT */
7076 .hw_scan
= iwl4965_mac_hw_scan
7079 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7082 struct iwl_priv
*priv
;
7083 struct ieee80211_hw
*hw
;
7084 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
7085 unsigned long flags
;
7086 DECLARE_MAC_BUF(mac
);
7088 /************************
7089 * 1. Allocating HW data
7090 ************************/
7092 /* Disabling hardware scan means that mac80211 will perform scans
7093 * "the hard way", rather than using device's scan. */
7094 if (cfg
->mod_params
->disable_hw_scan
) {
7095 IWL_DEBUG_INFO("Disabling hw_scan\n");
7096 iwl4965_hw_ops
.hw_scan
= NULL
;
7099 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
7105 /* At this point both hw and priv are allocated. */
7107 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
7109 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7111 priv
->pci_dev
= pdev
;
7113 #ifdef CONFIG_IWLWIFI_DEBUG
7114 iwl_debug_level
= priv
->cfg
->mod_params
->debug
;
7115 atomic_set(&priv
->restrict_refcnt
, 0);
7118 /**************************
7119 * 2. Initializing PCI bus
7120 **************************/
7121 if (pci_enable_device(pdev
)) {
7123 goto out_ieee80211_free_hw
;
7126 pci_set_master(pdev
);
7128 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
7130 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
7132 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
7134 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
7135 /* both attempts failed: */
7137 printk(KERN_WARNING
"%s: No suitable DMA available.\n",
7139 goto out_pci_disable_device
;
7143 err
= pci_request_regions(pdev
, DRV_NAME
);
7145 goto out_pci_disable_device
;
7147 pci_set_drvdata(pdev
, priv
);
7149 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7150 * PCI Tx retries from interfering with C3 CPU state */
7151 pci_write_config_byte(pdev
, 0x41, 0x00);
7153 /***********************
7154 * 3. Read REV register
7155 ***********************/
7156 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
7157 if (!priv
->hw_base
) {
7159 goto out_pci_release_regions
;
7162 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7163 (unsigned long long) pci_resource_len(pdev
, 0));
7164 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
7166 iwl_hw_detect(priv
);
7167 printk(KERN_INFO DRV_NAME
7168 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
7169 priv
->cfg
->name
, priv
->hw_rev
);
7172 err
= priv
->cfg
->ops
->lib
->apm_ops
.init(priv
);
7174 IWL_DEBUG_INFO("Failed to init APMG\n");
7180 /* Read the EEPROM */
7181 err
= iwl_eeprom_init(priv
);
7183 IWL_ERROR("Unable to init EEPROM\n");
7186 err
= iwl_eeprom_check_version(priv
);
7190 /* MAC Address location in EEPROM same for 3945/4965 */
7191 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
7192 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
7193 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
7195 /************************
7196 * 5. Setup HW constants
7197 ************************/
7198 /* Device-specific setup */
7199 if (priv
->cfg
->ops
->lib
->set_hw_params(priv
)) {
7200 IWL_ERROR("failed to set hw parameters\n");
7201 goto out_free_eeprom
;
7204 /*******************
7206 *******************/
7208 err
= iwl_setup(priv
);
7210 goto out_free_eeprom
;
7211 /* At this point both hw and priv are initialized. */
7213 /**********************************
7214 * 7. Initialize module parameters
7215 **********************************/
7217 /* Disable radio (SW RF KILL) via parameter when loading driver */
7218 if (priv
->cfg
->mod_params
->disable
) {
7219 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
7220 IWL_DEBUG_INFO("Radio disabled.\n");
7223 if (priv
->cfg
->mod_params
->enable_qos
)
7224 priv
->qos_data
.qos_enable
= 1;
7226 /********************
7228 ********************/
7229 spin_lock_irqsave(&priv
->lock
, flags
);
7230 iwl4965_disable_interrupts(priv
);
7231 spin_unlock_irqrestore(&priv
->lock
, flags
);
7233 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7235 IWL_ERROR("failed to create sysfs device attributes\n");
7236 goto out_free_eeprom
;
7239 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
7241 IWL_ERROR("failed to create debugfs files\n");
7242 goto out_remove_sysfs
;
7245 iwl4965_setup_deferred_work(priv
);
7246 iwl4965_setup_rx_handlers(priv
);
7248 /********************
7250 ********************/
7251 pci_save_state(pdev
);
7252 pci_disable_device(pdev
);
7254 /* notify iwlcore to init */
7255 iwlcore_low_level_notify(priv
, IWLCORE_INIT_EVT
);
7259 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7261 iwl_eeprom_free(priv
);
7263 pci_iounmap(pdev
, priv
->hw_base
);
7264 out_pci_release_regions
:
7265 pci_release_regions(pdev
);
7266 pci_set_drvdata(pdev
, NULL
);
7267 out_pci_disable_device
:
7268 pci_disable_device(pdev
);
7269 out_ieee80211_free_hw
:
7270 ieee80211_free_hw(priv
->hw
);
7275 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
7277 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7278 struct list_head
*p
, *q
;
7280 unsigned long flags
;
7285 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
7287 if (priv
->mac80211_registered
) {
7288 ieee80211_unregister_hw(priv
->hw
);
7289 priv
->mac80211_registered
= 0;
7292 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
7296 /* make sure we flush any pending irq or
7297 * tasklet for the driver
7299 spin_lock_irqsave(&priv
->lock
, flags
);
7300 iwl4965_disable_interrupts(priv
);
7301 spin_unlock_irqrestore(&priv
->lock
, flags
);
7303 iwl_synchronize_irq(priv
);
7305 /* Free MAC hash list for ADHOC */
7306 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
7307 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
7309 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
7313 iwlcore_low_level_notify(priv
, IWLCORE_REMOVE_EVT
);
7314 iwl_dbgfs_unregister(priv
);
7315 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7317 iwl4965_dealloc_ucode_pci(priv
);
7320 iwl4965_rx_queue_free(priv
, &priv
->rxq
);
7321 iwl4965_hw_txq_ctx_free(priv
);
7323 iwlcore_clear_stations_table(priv
);
7324 iwl_eeprom_free(priv
);
7327 /*netif_stop_queue(dev); */
7328 flush_workqueue(priv
->workqueue
);
7330 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
7331 * priv->workqueue... so we can't take down the workqueue
7333 destroy_workqueue(priv
->workqueue
);
7334 priv
->workqueue
= NULL
;
7336 pci_iounmap(pdev
, priv
->hw_base
);
7337 pci_release_regions(pdev
);
7338 pci_disable_device(pdev
);
7339 pci_set_drvdata(pdev
, NULL
);
7341 iwl_free_channel_map(priv
);
7342 iwlcore_free_geos(priv
);
7344 if (priv
->ibss_beacon
)
7345 dev_kfree_skb(priv
->ibss_beacon
);
7347 ieee80211_free_hw(priv
->hw
);
7352 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7354 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7356 if (priv
->is_open
) {
7357 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
7358 iwl4965_mac_stop(priv
->hw
);
7362 pci_set_power_state(pdev
, PCI_D3hot
);
7367 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
7369 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7371 pci_set_power_state(pdev
, PCI_D0
);
7374 iwl4965_mac_start(priv
->hw
);
7376 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
7380 #endif /* CONFIG_PM */
7382 /*****************************************************************************
7384 * driver and module entry point
7386 *****************************************************************************/
7388 /* Hardware specific file defines the PCI IDs table for that hardware module */
7389 static struct pci_device_id iwl_hw_card_ids
[] = {
7390 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID
, iwl4965_agn_cfg
)},
7391 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID
, iwl4965_agn_cfg
)},
7392 #ifdef CONFIG_IWL5000
7393 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID
, iwl5300_agn_cfg
)},
7394 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID
, iwl5100_agn_cfg
)},
7395 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID
, iwl5350_agn_cfg
)},
7396 #endif /* CONFIG_IWL5000 */
7399 MODULE_DEVICE_TABLE(pci
, iwl_hw_card_ids
);
7401 static struct pci_driver iwl_driver
= {
7403 .id_table
= iwl_hw_card_ids
,
7404 .probe
= iwl4965_pci_probe
,
7405 .remove
= __devexit_p(iwl4965_pci_remove
),
7407 .suspend
= iwl4965_pci_suspend
,
7408 .resume
= iwl4965_pci_resume
,
7412 static int __init
iwl4965_init(void)
7416 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
7417 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
7419 ret
= iwl4965_rate_control_register();
7421 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
7425 ret
= pci_register_driver(&iwl_driver
);
7427 IWL_ERROR("Unable to initialize PCI module\n");
7428 goto error_register
;
7430 #ifdef CONFIG_IWLWIFI_DEBUG
7431 ret
= driver_create_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
7433 IWL_ERROR("Unable to create driver sysfs file\n");
7440 #ifdef CONFIG_IWLWIFI_DEBUG
7442 pci_unregister_driver(&iwl_driver
);
7445 iwl4965_rate_control_unregister();
7449 static void __exit
iwl4965_exit(void)
7451 #ifdef CONFIG_IWLWIFI_DEBUG
7452 driver_remove_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
7454 pci_unregister_driver(&iwl_driver
);
7455 iwl4965_rate_control_unregister();
7458 module_exit(iwl4965_exit
);
7459 module_init(iwl4965_init
);