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 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
55 struct iwl4965_tx_queue
*txq
);
57 /******************************************************************************
61 ******************************************************************************/
64 * module name, copyright, version, etc.
65 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
68 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
70 #ifdef CONFIG_IWLWIFI_DEBUG
76 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
82 #define DRV_VERSION IWLWIFI_VERSION VD VS
85 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
86 MODULE_VERSION(DRV_VERSION
);
87 MODULE_AUTHOR(DRV_COPYRIGHT
);
88 MODULE_LICENSE("GPL");
90 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
92 u16 fc
= le16_to_cpu(hdr
->frame_control
);
93 int hdr_len
= ieee80211_get_hdrlen(fc
);
95 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
96 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
100 static const struct ieee80211_supported_band
*iwl4965_get_hw_mode(
101 struct iwl_priv
*priv
, enum ieee80211_band band
)
103 return priv
->hw
->wiphy
->bands
[band
];
106 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
108 /* Single white space is for Linksys APs */
109 if (essid_len
== 1 && essid
[0] == ' ')
112 /* Otherwise, if the entire essid is 0, we assume it is hidden */
115 if (essid
[essid_len
] != '\0')
122 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
124 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
125 const char *s
= essid
;
128 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
129 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
133 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
134 while (essid_len
--) {
146 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
149 * Theory of operation
151 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
152 * of buffer descriptors, each of which points to one or more data buffers for
153 * the device to read from or fill. Driver and device exchange status of each
154 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
155 * entries in each circular buffer, to protect against confusing empty and full
158 * The device reads or writes the data in the queues via the device's several
159 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
161 * For Tx queue, there are low mark and high mark limits. If, after queuing
162 * the packet for Tx, free space become < low mark, Tx queue stopped. When
163 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
166 * The 4965 operates with up to 17 queues: One receive queue, one transmit
167 * queue (#4) for sending commands to the device firmware, and 15 other
168 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
170 * See more detailed info in iwl-4965-hw.h.
171 ***************************************************/
173 int iwl4965_queue_space(const struct iwl4965_queue
*q
)
175 int s
= q
->read_ptr
- q
->write_ptr
;
177 if (q
->read_ptr
> q
->write_ptr
)
182 /* keep some reserve to not confuse empty and full situations */
190 static inline int x2_queue_used(const struct iwl4965_queue
*q
, int i
)
192 return q
->write_ptr
> q
->read_ptr
?
193 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
194 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
197 static inline u8
get_cmd_index(struct iwl4965_queue
*q
, u32 index
, int is_huge
)
199 /* This is for scan command, the big buffer at end of command array */
201 return q
->n_window
; /* must be power of 2 */
203 /* Otherwise, use normal size buffers */
204 return index
& (q
->n_window
- 1);
208 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
210 static int iwl4965_queue_init(struct iwl_priv
*priv
, struct iwl4965_queue
*q
,
211 int count
, int slots_num
, u32 id
)
214 q
->n_window
= slots_num
;
217 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
218 * and iwl_queue_dec_wrap are broken. */
219 BUG_ON(!is_power_of_2(count
));
221 /* slots_num must be power-of-two size, otherwise
222 * get_cmd_index is broken. */
223 BUG_ON(!is_power_of_2(slots_num
));
225 q
->low_mark
= q
->n_window
/ 4;
229 q
->high_mark
= q
->n_window
/ 8;
230 if (q
->high_mark
< 2)
233 q
->write_ptr
= q
->read_ptr
= 0;
239 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
241 static int iwl4965_tx_queue_alloc(struct iwl_priv
*priv
,
242 struct iwl4965_tx_queue
*txq
, u32 id
)
244 struct pci_dev
*dev
= priv
->pci_dev
;
246 /* Driver private data, only for Tx (not command) queues,
247 * not shared with device. */
248 if (id
!= IWL_CMD_QUEUE_NUM
) {
249 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
250 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
252 IWL_ERROR("kmalloc for auxiliary BD "
253 "structures failed\n");
259 /* Circular buffer of transmit frame descriptors (TFDs),
260 * shared with device */
261 txq
->bd
= pci_alloc_consistent(dev
,
262 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
266 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
267 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
284 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
286 int iwl4965_tx_queue_init(struct iwl_priv
*priv
,
287 struct iwl4965_tx_queue
*txq
, int slots_num
, u32 txq_id
)
289 struct pci_dev
*dev
= priv
->pci_dev
;
294 * Alloc buffer array for commands (Tx or other types of commands).
295 * For the command queue (#4), allocate command space + one big
296 * command for scan, since scan command is very huge; the system will
297 * not have two scans at the same time, so only one is needed.
298 * For normal Tx queues (all other queues), no super-size command
301 len
= sizeof(struct iwl_cmd
) * slots_num
;
302 if (txq_id
== IWL_CMD_QUEUE_NUM
)
303 len
+= IWL_MAX_SCAN_SIZE
;
304 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
308 /* Alloc driver data array and TFD circular buffer */
309 rc
= iwl4965_tx_queue_alloc(priv
, txq
, txq_id
);
311 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
315 txq
->need_update
= 0;
317 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
318 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
319 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
321 /* Initialize queue's high/low-water marks, and head/tail indexes */
322 iwl4965_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
324 /* Tell device where to find queue */
325 iwl4965_hw_tx_queue_init(priv
, txq
);
331 * iwl4965_tx_queue_free - Deallocate DMA queue.
332 * @txq: Transmit queue to deallocate.
334 * Empty queue by removing and destroying all BD's.
336 * 0-fill, but do not free "txq" descriptor structure.
338 void iwl4965_tx_queue_free(struct iwl_priv
*priv
, struct iwl4965_tx_queue
*txq
)
340 struct iwl4965_queue
*q
= &txq
->q
;
341 struct pci_dev
*dev
= priv
->pci_dev
;
347 /* first, empty all BD's */
348 for (; q
->write_ptr
!= q
->read_ptr
;
349 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
350 iwl4965_hw_txq_free_tfd(priv
, txq
);
352 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
353 if (q
->id
== IWL_CMD_QUEUE_NUM
)
354 len
+= IWL_MAX_SCAN_SIZE
;
356 /* De-alloc array of command/tx buffers */
357 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
359 /* De-alloc circular buffer of TFDs */
361 pci_free_consistent(dev
, sizeof(struct iwl4965_tfd_frame
) *
362 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
364 /* De-alloc array of per-TFD driver data */
370 /* 0-fill queue descriptor structure */
371 memset(txq
, 0, sizeof(*txq
));
374 const u8 iwl4965_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
376 /*************** STATION TABLE MANAGEMENT ****
377 * mac80211 should be examined to determine if sta_info is duplicating
378 * the functionality provided here
381 /**************************************************************/
383 #if 0 /* temporary disable till we add real remove station */
385 * iwl4965_remove_station - Remove driver's knowledge of station.
387 * NOTE: This does not remove station from device's station table.
389 static u8
iwl4965_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
391 int index
= IWL_INVALID_STATION
;
395 spin_lock_irqsave(&priv
->sta_lock
, flags
);
399 else if (is_broadcast_ether_addr(addr
))
400 index
= priv
->hw_setting
.bcast_sta_id
;
402 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
403 if (priv
->stations
[i
].used
&&
404 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
410 if (unlikely(index
== IWL_INVALID_STATION
))
413 if (priv
->stations
[index
].used
) {
414 priv
->stations
[index
].used
= 0;
415 priv
->num_stations
--;
418 BUG_ON(priv
->num_stations
< 0);
421 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
427 * iwl4965_add_station_flags - Add station to tables in driver and device
429 u8
iwl4965_add_station_flags(struct iwl_priv
*priv
, const u8
*addr
,
430 int is_ap
, u8 flags
, void *ht_data
)
433 int index
= IWL_INVALID_STATION
;
434 struct iwl4965_station_entry
*station
;
435 unsigned long flags_spin
;
436 DECLARE_MAC_BUF(mac
);
438 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
441 else if (is_broadcast_ether_addr(addr
))
442 index
= priv
->hw_setting
.bcast_sta_id
;
444 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
445 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
451 if (!priv
->stations
[i
].used
&&
452 index
== IWL_INVALID_STATION
)
457 /* These two conditions have the same outcome, but keep them separate
458 since they have different meanings */
459 if (unlikely(index
== IWL_INVALID_STATION
)) {
460 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
464 if (priv
->stations
[index
].used
&&
465 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
466 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
471 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
472 station
= &priv
->stations
[index
];
474 priv
->num_stations
++;
476 /* Set up the REPLY_ADD_STA command to send to device */
477 memset(&station
->sta
, 0, sizeof(struct iwl4965_addsta_cmd
));
478 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
479 station
->sta
.mode
= 0;
480 station
->sta
.sta
.sta_id
= index
;
481 station
->sta
.station_flags
= 0;
483 #ifdef CONFIG_IWL4965_HT
484 /* BCAST station and IBSS stations do not work in HT mode */
485 if (index
!= priv
->hw_setting
.bcast_sta_id
&&
486 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
487 iwl4965_set_ht_add_station(priv
, index
,
488 (struct ieee80211_ht_info
*) ht_data
);
489 #endif /*CONFIG_IWL4965_HT*/
491 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
493 /* Add station to device's station table */
494 iwl4965_send_add_station(priv
, &station
->sta
, flags
);
499 /*************** DRIVER STATUS FUNCTIONS *****/
501 static inline int iwl4965_is_ready(struct iwl_priv
*priv
)
503 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
504 * set but EXIT_PENDING is not */
505 return test_bit(STATUS_READY
, &priv
->status
) &&
506 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) &&
507 !test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
510 static inline int iwl4965_is_alive(struct iwl_priv
*priv
)
512 return test_bit(STATUS_ALIVE
, &priv
->status
);
515 static inline int iwl4965_is_init(struct iwl_priv
*priv
)
517 return test_bit(STATUS_INIT
, &priv
->status
);
520 static inline int iwl4965_is_rfkill(struct iwl_priv
*priv
)
522 return test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ||
523 test_bit(STATUS_RF_KILL_SW
, &priv
->status
);
526 static inline int iwl4965_is_ready_rf(struct iwl_priv
*priv
)
529 if (iwl4965_is_rfkill(priv
))
532 return iwl4965_is_ready(priv
);
535 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
538 * iwl4965_enqueue_hcmd - enqueue a uCode command
539 * @priv: device private data point
540 * @cmd: a point to the ucode command structure
542 * The function returns < 0 values to indicate the operation is
543 * failed. On success, it turns the index (> 0) of command in the
546 int iwl4965_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
548 struct iwl4965_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
549 struct iwl4965_queue
*q
= &txq
->q
;
550 struct iwl4965_tfd_frame
*tfd
;
552 struct iwl_cmd
*out_cmd
;
554 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
555 dma_addr_t phys_addr
;
559 /* If any of the command structures end up being larger than
560 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
561 * we will need to increase the size of the TFD entries */
562 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
563 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
565 if (iwl4965_is_rfkill(priv
)) {
566 IWL_DEBUG_INFO("Not sending command - RF KILL");
570 if (iwl4965_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
571 IWL_ERROR("No space for Tx\n");
575 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
577 tfd
= &txq
->bd
[q
->write_ptr
];
578 memset(tfd
, 0, sizeof(*tfd
));
580 control_flags
= (u32
*) tfd
;
582 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
583 out_cmd
= &txq
->cmd
[idx
];
585 out_cmd
->hdr
.cmd
= cmd
->id
;
586 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
587 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
589 /* At this point, the out_cmd now has all of the incoming cmd
592 out_cmd
->hdr
.flags
= 0;
593 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
594 INDEX_TO_SEQ(q
->write_ptr
));
595 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
596 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
598 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
599 offsetof(struct iwl_cmd
, hdr
);
600 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
602 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
603 "%d bytes at %d[%d]:%d\n",
604 get_cmd_string(out_cmd
->hdr
.cmd
),
605 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
606 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
608 txq
->need_update
= 1;
610 /* Set up entry in queue's byte count circular buffer */
611 ret
= iwl4965_tx_queue_update_wr_ptr(priv
, txq
, 0);
613 /* Increment and update queue's write index */
614 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
615 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
617 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
618 return ret
? ret
: idx
;
621 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
623 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
626 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
628 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
632 int iwl4965_send_statistics_request(struct iwl_priv
*priv
)
635 return iwl_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
636 sizeof(flags
), &flags
);
640 * iwl4965_rxon_add_station - add station into station table.
642 * there is only one AP station with id= IWL_AP_ID
643 * NOTE: mutex must be held before calling this fnction
645 static int iwl4965_rxon_add_station(struct iwl_priv
*priv
,
646 const u8
*addr
, int is_ap
)
650 /* Add station to device's station table */
651 #ifdef CONFIG_IWL4965_HT
652 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
653 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
656 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
657 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
658 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
661 #endif /* CONFIG_IWL4965_HT */
662 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
665 /* Set up default rate scaling table in device's station table */
666 iwl4965_add_station(priv
, addr
, is_ap
);
672 * iwl4965_check_rxon_cmd - validate RXON structure is valid
674 * NOTE: This is really only useful during development and can eventually
675 * be #ifdef'd out once the driver is stable and folks aren't actively
678 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
683 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
684 error
|= le32_to_cpu(rxon
->flags
&
685 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
686 RXON_FLG_RADAR_DETECT_MSK
));
688 IWL_WARNING("check 24G fields %d | %d\n",
691 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
692 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
694 IWL_WARNING("check 52 fields %d | %d\n",
696 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
698 IWL_WARNING("check 52 CCK %d | %d\n",
701 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
703 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
705 /* make sure basic rates 6Mbps and 1Mbps are supported */
706 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
707 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
709 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
711 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
713 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
715 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
716 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
718 IWL_WARNING("check CCK and short slot %d | %d\n",
721 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
722 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
724 IWL_WARNING("check CCK & auto detect %d | %d\n",
727 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
728 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
730 IWL_WARNING("check TGG and auto detect %d | %d\n",
734 IWL_WARNING("Tuning to channel %d\n",
735 le16_to_cpu(rxon
->channel
));
738 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
745 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
746 * @priv: staging_rxon is compared to active_rxon
748 * If the RXON structure is changing enough to require a new tune,
749 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
750 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
752 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
755 /* These items are only settable from the full RXON command */
756 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
757 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
758 priv
->active_rxon
.bssid_addr
) ||
759 compare_ether_addr(priv
->staging_rxon
.node_addr
,
760 priv
->active_rxon
.node_addr
) ||
761 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
762 priv
->active_rxon
.wlap_bssid_addr
) ||
763 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
764 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
765 (priv
->staging_rxon
.air_propagation
!=
766 priv
->active_rxon
.air_propagation
) ||
767 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
768 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
769 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
770 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
771 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
772 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
775 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
776 * be updated with the RXON_ASSOC command -- however only some
777 * flag transitions are allowed using RXON_ASSOC */
779 /* Check if we are not switching bands */
780 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
781 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
784 /* Check if we are switching association toggle */
785 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
786 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
792 static int iwl4965_send_rxon_assoc(struct iwl_priv
*priv
)
795 struct iwl4965_rx_packet
*res
= NULL
;
796 struct iwl4965_rxon_assoc_cmd rxon_assoc
;
797 struct iwl_host_cmd cmd
= {
798 .id
= REPLY_RXON_ASSOC
,
799 .len
= sizeof(rxon_assoc
),
800 .meta
.flags
= CMD_WANT_SKB
,
803 const struct iwl4965_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
804 const struct iwl4965_rxon_cmd
*rxon2
= &priv
->active_rxon
;
806 if ((rxon1
->flags
== rxon2
->flags
) &&
807 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
808 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
809 (rxon1
->ofdm_ht_single_stream_basic_rates
==
810 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
811 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
812 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
813 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
814 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
815 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
819 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
820 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
821 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
822 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
823 rxon_assoc
.reserved
= 0;
824 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
825 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
;
826 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
827 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
;
828 rxon_assoc
.rx_chain_select_flags
= priv
->staging_rxon
.rx_chain
;
830 rc
= iwl_send_cmd_sync(priv
, &cmd
);
834 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
835 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
836 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
840 priv
->alloc_rxb_skb
--;
841 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
847 * iwl4965_commit_rxon - commit staging_rxon to hardware
849 * The RXON command in staging_rxon is committed to the hardware and
850 * the active_rxon structure is updated with the new data. This
851 * function correctly transitions out of the RXON_ASSOC_MSK state if
852 * a HW tune is required based on the RXON structure changes.
854 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
856 /* cast away the const for active_rxon in this function */
857 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
858 DECLARE_MAC_BUF(mac
);
861 if (!iwl4965_is_alive(priv
))
864 /* always get timestamp with Rx frame */
865 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
867 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
869 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
873 /* If we don't need to send a full RXON, we can use
874 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
875 * and other flags for the current radio configuration. */
876 if (!iwl4965_full_rxon_required(priv
)) {
877 rc
= iwl4965_send_rxon_assoc(priv
);
879 IWL_ERROR("Error setting RXON_ASSOC "
880 "configuration (%d).\n", rc
);
884 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
889 /* station table will be cleared */
890 priv
->assoc_station_added
= 0;
892 #ifdef CONFIG_IWL4965_SENSITIVITY
893 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
894 if (!priv
->error_recovering
)
895 priv
->start_calib
= 0;
897 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
898 #endif /* CONFIG_IWL4965_SENSITIVITY */
900 /* If we are currently associated and the new config requires
901 * an RXON_ASSOC and the new config wants the associated mask enabled,
902 * we must clear the associated from the active configuration
903 * before we apply the new config */
904 if (iwl4965_is_associated(priv
) &&
905 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
906 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
907 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
909 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
910 sizeof(struct iwl4965_rxon_cmd
),
913 /* If the mask clearing failed then we set
914 * active_rxon back to what it was previously */
916 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
917 IWL_ERROR("Error clearing ASSOC_MSK on current "
918 "configuration (%d).\n", rc
);
923 IWL_DEBUG_INFO("Sending RXON\n"
924 "* with%s RXON_FILTER_ASSOC_MSK\n"
927 ((priv
->staging_rxon
.filter_flags
&
928 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
929 le16_to_cpu(priv
->staging_rxon
.channel
),
930 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
932 iwl4965_set_rxon_hwcrypto(priv
, priv
->cfg
->mod_params
->hw_crypto
);
933 /* Apply the new configuration */
934 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
935 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
937 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
941 iwlcore_clear_stations_table(priv
);
943 #ifdef CONFIG_IWL4965_SENSITIVITY
944 if (!priv
->error_recovering
)
945 priv
->start_calib
= 0;
947 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
948 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
949 #endif /* CONFIG_IWL4965_SENSITIVITY */
951 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
953 /* If we issue a new RXON command which required a tune then we must
954 * send a new TXPOWER command or we won't be able to Tx any frames */
955 rc
= iwl4965_hw_reg_send_txpower(priv
);
957 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
961 /* Add the broadcast address so we can send broadcast frames */
962 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
963 IWL_INVALID_STATION
) {
964 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
968 /* If we have set the ASSOC_MSK and we are in BSS mode then
969 * add the IWL_AP_ID to the station rate table */
970 if (iwl4965_is_associated(priv
) &&
971 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
972 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
973 == IWL_INVALID_STATION
) {
974 IWL_ERROR("Error adding AP address for transmit.\n");
977 priv
->assoc_station_added
= 1;
983 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
985 struct iwl4965_bt_cmd bt_cmd
= {
993 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
994 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
997 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
1000 struct iwl4965_rx_packet
*res
;
1001 struct iwl_host_cmd cmd
= {
1002 .id
= REPLY_SCAN_ABORT_CMD
,
1003 .meta
.flags
= CMD_WANT_SKB
,
1006 /* If there isn't a scan actively going on in the hardware
1007 * then we are in between scan bands and not actually
1008 * actively scanning, so don't send the abort command */
1009 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1010 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1014 rc
= iwl_send_cmd_sync(priv
, &cmd
);
1016 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1020 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1021 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
1022 /* The scan abort will return 1 for success or
1023 * 2 for "failure". A failure condition can be
1024 * due to simply not being in an active scan which
1025 * can occur if we send the scan abort before we
1026 * the microcode has notified us that a scan is
1028 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
1029 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1030 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1033 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1038 static int iwl4965_card_state_sync_callback(struct iwl_priv
*priv
,
1039 struct iwl_cmd
*cmd
,
1040 struct sk_buff
*skb
)
1048 * Use: Sets the device's internal card state to enable, disable, or halt
1050 * When in the 'enable' state the card operates as normal.
1051 * When in the 'disable' state, the card enters into a low power mode.
1052 * When in the 'halt' state, the card is shut down and must be fully
1053 * restarted to come back on.
1055 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
1057 struct iwl_host_cmd cmd
= {
1058 .id
= REPLY_CARD_STATE_CMD
,
1061 .meta
.flags
= meta_flag
,
1064 if (meta_flag
& CMD_ASYNC
)
1065 cmd
.meta
.u
.callback
= iwl4965_card_state_sync_callback
;
1067 return iwl_send_cmd(priv
, &cmd
);
1070 static int iwl4965_add_sta_sync_callback(struct iwl_priv
*priv
,
1071 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
1073 struct iwl4965_rx_packet
*res
= NULL
;
1076 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1080 res
= (struct iwl4965_rx_packet
*)skb
->data
;
1081 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1082 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1087 switch (res
->u
.add_sta
.status
) {
1088 case ADD_STA_SUCCESS_MSK
:
1094 /* We didn't cache the SKB; let the caller free it */
1098 int iwl4965_send_add_station(struct iwl_priv
*priv
,
1099 struct iwl4965_addsta_cmd
*sta
, u8 flags
)
1101 struct iwl4965_rx_packet
*res
= NULL
;
1103 struct iwl_host_cmd cmd
= {
1104 .id
= REPLY_ADD_STA
,
1105 .len
= sizeof(struct iwl4965_addsta_cmd
),
1106 .meta
.flags
= flags
,
1110 if (flags
& CMD_ASYNC
)
1111 cmd
.meta
.u
.callback
= iwl4965_add_sta_sync_callback
;
1113 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1115 rc
= iwl_send_cmd(priv
, &cmd
);
1117 if (rc
|| (flags
& CMD_ASYNC
))
1120 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1121 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1122 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1128 switch (res
->u
.add_sta
.status
) {
1129 case ADD_STA_SUCCESS_MSK
:
1130 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1134 IWL_WARNING("REPLY_ADD_STA failed\n");
1139 priv
->alloc_rxb_skb
--;
1140 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1145 static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
1146 struct ieee80211_key_conf
*keyconf
,
1149 unsigned long flags
;
1150 __le16 key_flags
= 0;
1152 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
1153 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1155 if (sta_id
== priv
->hw_setting
.bcast_sta_id
)
1156 key_flags
|= STA_KEY_MULTICAST_MSK
;
1158 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1159 keyconf
->hw_key_idx
= keyconf
->keyidx
;
1161 key_flags
&= ~STA_KEY_FLG_INVALID
;
1163 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1164 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1165 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1167 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
1170 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
1173 priv
->stations
[sta_id
].sta
.key
.key_offset
1174 = (sta_id
% STA_KEY_MAX_NUM
);/*FIXME*/
1175 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
1176 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1177 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1179 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1181 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1182 return iwl4965_send_add_station(priv
,
1183 &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1186 static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
1187 struct ieee80211_key_conf
*keyconf
,
1190 unsigned long flags
;
1193 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1194 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1195 keyconf
->hw_key_idx
= keyconf
->keyidx
;
1197 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1199 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1200 priv
->stations
[sta_id
].keyinfo
.conf
= keyconf
;
1201 priv
->stations
[sta_id
].keyinfo
.keylen
= 16;
1203 /* This copy is acutally not needed: we get the key with each TX */
1204 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
, 16);
1206 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
, 16);
1208 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1213 static int iwl4965_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
1215 unsigned long flags
;
1217 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1218 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl4965_hw_key
));
1219 memset(&priv
->stations
[sta_id
].sta
.key
, 0, sizeof(struct iwl4965_keyinfo
));
1220 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1221 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1222 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1223 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1225 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1226 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1230 static int iwl4965_set_dynamic_key(struct iwl_priv
*priv
,
1231 struct ieee80211_key_conf
*key
, u8 sta_id
)
1237 ret
= iwl4965_set_ccmp_dynamic_key_info(priv
, key
, sta_id
);
1240 ret
= iwl4965_set_tkip_dynamic_key_info(priv
, key
, sta_id
);
1246 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__
, key
->alg
);
1253 static int iwl4965_remove_static_key(struct iwl_priv
*priv
)
1255 int ret
= -EOPNOTSUPP
;
1260 static int iwl4965_set_static_key(struct iwl_priv
*priv
,
1261 struct ieee80211_key_conf
*key
)
1263 if (key
->alg
== ALG_WEP
)
1266 IWL_ERROR("Static key invalid: alg %d\n", key
->alg
);
1270 static void iwl4965_clear_free_frames(struct iwl_priv
*priv
)
1272 struct list_head
*element
;
1274 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1275 priv
->frames_count
);
1277 while (!list_empty(&priv
->free_frames
)) {
1278 element
= priv
->free_frames
.next
;
1280 kfree(list_entry(element
, struct iwl4965_frame
, list
));
1281 priv
->frames_count
--;
1284 if (priv
->frames_count
) {
1285 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1286 priv
->frames_count
);
1287 priv
->frames_count
= 0;
1291 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl_priv
*priv
)
1293 struct iwl4965_frame
*frame
;
1294 struct list_head
*element
;
1295 if (list_empty(&priv
->free_frames
)) {
1296 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1298 IWL_ERROR("Could not allocate frame!\n");
1302 priv
->frames_count
++;
1306 element
= priv
->free_frames
.next
;
1308 return list_entry(element
, struct iwl4965_frame
, list
);
1311 static void iwl4965_free_frame(struct iwl_priv
*priv
, struct iwl4965_frame
*frame
)
1313 memset(frame
, 0, sizeof(*frame
));
1314 list_add(&frame
->list
, &priv
->free_frames
);
1317 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
1318 struct ieee80211_hdr
*hdr
,
1319 const u8
*dest
, int left
)
1322 if (!iwl4965_is_associated(priv
) || !priv
->ibss_beacon
||
1323 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1324 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1327 if (priv
->ibss_beacon
->len
> left
)
1330 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1332 return priv
->ibss_beacon
->len
;
1335 static u8
iwl4965_rate_get_lowest_plcp(int rate_mask
)
1339 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1340 i
= iwl4965_rates
[i
].next_ieee
) {
1341 if (rate_mask
& (1 << i
))
1342 return iwl4965_rates
[i
].plcp
;
1345 return IWL_RATE_INVALID
;
1348 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
1350 struct iwl4965_frame
*frame
;
1351 unsigned int frame_size
;
1355 frame
= iwl4965_get_free_frame(priv
);
1358 IWL_ERROR("Could not obtain free frame buffer for beacon "
1363 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1364 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
&
1366 if (rate
== IWL_INVALID_RATE
)
1367 rate
= IWL_RATE_6M_PLCP
;
1369 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1370 if (rate
== IWL_INVALID_RATE
)
1371 rate
= IWL_RATE_1M_PLCP
;
1374 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
1376 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1379 iwl4965_free_frame(priv
, frame
);
1384 /******************************************************************************
1386 * Misc. internal state and helper functions
1388 ******************************************************************************/
1390 static void iwl4965_unset_hw_setting(struct iwl_priv
*priv
)
1392 if (priv
->hw_setting
.shared_virt
)
1393 pci_free_consistent(priv
->pci_dev
,
1394 sizeof(struct iwl4965_shared
),
1395 priv
->hw_setting
.shared_virt
,
1396 priv
->hw_setting
.shared_phys
);
1400 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1402 * return : set the bit for each supported rate insert in ie
1404 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1405 u16 basic_rate
, int *left
)
1407 u16 ret_rates
= 0, bit
;
1412 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1413 if (bit
& supported_rate
) {
1415 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
1416 ((bit
& basic_rate
) ? 0x80 : 0x00);
1420 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1429 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1431 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
1432 enum ieee80211_band band
,
1433 struct ieee80211_mgmt
*frame
,
1434 int left
, int is_direct
)
1438 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1439 #ifdef CONFIG_IWL4965_HT
1440 const struct ieee80211_supported_band
*sband
=
1441 iwl4965_get_hw_mode(priv
, band
);
1442 #endif /* CONFIG_IWL4965_HT */
1444 /* Make sure there is enough space for the probe request,
1445 * two mandatory IEs and the data */
1451 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1452 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1453 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1454 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1455 frame
->seq_ctrl
= 0;
1457 /* fill in our indirect SSID IE */
1464 pos
= &(frame
->u
.probe_req
.variable
[0]);
1465 *pos
++ = WLAN_EID_SSID
;
1468 /* fill in our direct SSID IE... */
1471 left
-= 2 + priv
->essid_len
;
1474 /* ... fill it in... */
1475 *pos
++ = WLAN_EID_SSID
;
1476 *pos
++ = priv
->essid_len
;
1477 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1478 pos
+= priv
->essid_len
;
1479 len
+= 2 + priv
->essid_len
;
1482 /* fill in supported rate */
1488 /* ... fill it in... */
1489 *pos
++ = WLAN_EID_SUPP_RATES
;
1492 /* exclude 60M rate */
1493 active_rates
= priv
->rates_mask
;
1494 active_rates
&= ~IWL_RATE_60M_MASK
;
1496 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1498 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1499 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1500 active_rate_basic
, &left
);
1501 active_rates
&= ~ret_rates
;
1503 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1504 active_rate_basic
, &left
);
1505 active_rates
&= ~ret_rates
;
1509 if (active_rates
== 0)
1512 /* fill in supported extended rate */
1517 /* ... fill it in... */
1518 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1520 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1521 active_rate_basic
, &left
);
1525 #ifdef CONFIG_IWL4965_HT
1526 if (sband
&& sband
->ht_info
.ht_supported
) {
1527 struct ieee80211_ht_cap
*ht_cap
;
1529 *pos
++ = WLAN_EID_HT_CAPABILITY
;
1530 *pos
++ = sizeof(struct ieee80211_ht_cap
);
1531 ht_cap
= (struct ieee80211_ht_cap
*)pos
;
1532 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
1533 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
1534 ht_cap
->ampdu_params_info
=(sband
->ht_info
.ampdu_factor
&
1535 IEEE80211_HT_CAP_AMPDU_FACTOR
) |
1536 ((sband
->ht_info
.ampdu_density
<< 2) &
1537 IEEE80211_HT_CAP_AMPDU_DENSITY
);
1538 len
+= 2 + sizeof(struct ieee80211_ht_cap
);
1540 #endif /*CONFIG_IWL4965_HT */
1549 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
1550 struct iwl4965_qosparam_cmd
*qos
)
1553 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1554 sizeof(struct iwl4965_qosparam_cmd
), qos
);
1557 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
1559 unsigned long flags
;
1561 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1564 if (!priv
->qos_data
.qos_enable
)
1567 spin_lock_irqsave(&priv
->lock
, flags
);
1568 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1570 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1571 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1572 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1573 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1574 if (priv
->qos_data
.qos_active
)
1575 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1576 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1578 #ifdef CONFIG_IWL4965_HT
1579 if (priv
->current_ht_config
.is_ht
)
1580 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
1581 #endif /* CONFIG_IWL4965_HT */
1583 spin_unlock_irqrestore(&priv
->lock
, flags
);
1585 if (force
|| iwl4965_is_associated(priv
)) {
1586 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1587 priv
->qos_data
.qos_active
,
1588 priv
->qos_data
.def_qos_parm
.qos_flags
);
1590 iwl4965_send_qos_params_command(priv
,
1591 &(priv
->qos_data
.def_qos_parm
));
1596 * Power management (not Tx power!) functions
1598 #define MSEC_TO_USEC 1024
1600 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1601 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1602 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1603 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1604 __constant_cpu_to_le32(X1), \
1605 __constant_cpu_to_le32(X2), \
1606 __constant_cpu_to_le32(X3), \
1607 __constant_cpu_to_le32(X4)}
1610 /* default power management (not Tx power) table values */
1612 static struct iwl4965_power_vec_entry range_0
[IWL_POWER_AC
] = {
1613 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1614 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1615 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1616 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1617 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1618 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1622 static struct iwl4965_power_vec_entry range_1
[IWL_POWER_AC
] = {
1623 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1624 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1625 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1626 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1627 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1628 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1629 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1630 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1631 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1632 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1635 int iwl4965_power_init_handle(struct iwl_priv
*priv
)
1638 struct iwl4965_power_mgr
*pow_data
;
1639 int size
= sizeof(struct iwl4965_power_vec_entry
) * IWL_POWER_AC
;
1642 IWL_DEBUG_POWER("Initialize power \n");
1644 pow_data
= &(priv
->power_data
);
1646 memset(pow_data
, 0, sizeof(*pow_data
));
1648 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1649 pow_data
->dtim_val
= 0xffff;
1651 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1652 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1654 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1658 struct iwl4965_powertable_cmd
*cmd
;
1660 IWL_DEBUG_POWER("adjust power command flags\n");
1662 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
1663 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1666 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1668 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1674 static int iwl4965_update_power_cmd(struct iwl_priv
*priv
,
1675 struct iwl4965_powertable_cmd
*cmd
, u32 mode
)
1680 struct iwl4965_power_vec_entry
*range
;
1682 struct iwl4965_power_mgr
*pow_data
;
1684 if (mode
> IWL_POWER_INDEX_5
) {
1685 IWL_DEBUG_POWER("Error invalid power mode \n");
1688 pow_data
= &(priv
->power_data
);
1690 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1691 range
= &pow_data
->pwr_range_0
[0];
1693 range
= &pow_data
->pwr_range_1
[1];
1695 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl4965_powertable_cmd
));
1697 #ifdef IWL_MAC80211_DISABLE
1698 if (priv
->assoc_network
!= NULL
) {
1699 unsigned long flags
;
1701 period
= priv
->assoc_network
->tim
.tim_period
;
1703 #endif /*IWL_MAC80211_DISABLE */
1704 skip
= range
[mode
].no_dtim
;
1713 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1715 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1716 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1717 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1720 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
1721 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1722 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1725 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1726 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1727 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1728 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1729 le32_to_cpu(cmd
->sleep_interval
[0]),
1730 le32_to_cpu(cmd
->sleep_interval
[1]),
1731 le32_to_cpu(cmd
->sleep_interval
[2]),
1732 le32_to_cpu(cmd
->sleep_interval
[3]),
1733 le32_to_cpu(cmd
->sleep_interval
[4]));
1738 static int iwl4965_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
1740 u32
uninitialized_var(final_mode
);
1742 struct iwl4965_powertable_cmd cmd
;
1744 /* If on battery, set to 3,
1745 * if plugged into AC power, set to CAM ("continuously aware mode"),
1746 * else user level */
1748 case IWL_POWER_BATTERY
:
1749 final_mode
= IWL_POWER_INDEX_3
;
1752 final_mode
= IWL_POWER_MODE_CAM
;
1759 cmd
.keep_alive_beacons
= 0;
1761 iwl4965_update_power_cmd(priv
, &cmd
, final_mode
);
1763 rc
= iwl_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
1765 if (final_mode
== IWL_POWER_MODE_CAM
)
1766 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
1768 set_bit(STATUS_POWER_PMI
, &priv
->status
);
1773 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1775 /* Filter incoming packets to determine if they are targeted toward
1776 * this network, discarding packets coming from ourselves */
1777 switch (priv
->iw_mode
) {
1778 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
1779 /* packets from our adapter are dropped (echo) */
1780 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
1782 /* {broad,multi}cast packets to our IBSS go through */
1783 if (is_multicast_ether_addr(header
->addr1
))
1784 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
1785 /* packets to our adapter go through */
1786 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1787 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
1788 /* packets from our adapter are dropped (echo) */
1789 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
1791 /* {broad,multi}cast packets to our BSS go through */
1792 if (is_multicast_ether_addr(header
->addr1
))
1793 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
1794 /* packets to our adapter go through */
1795 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1803 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1805 static const char *iwl4965_get_tx_fail_reason(u32 status
)
1807 switch (status
& TX_STATUS_MSK
) {
1808 case TX_STATUS_SUCCESS
:
1810 TX_STATUS_ENTRY(SHORT_LIMIT
);
1811 TX_STATUS_ENTRY(LONG_LIMIT
);
1812 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
1813 TX_STATUS_ENTRY(MGMNT_ABORT
);
1814 TX_STATUS_ENTRY(NEXT_FRAG
);
1815 TX_STATUS_ENTRY(LIFE_EXPIRE
);
1816 TX_STATUS_ENTRY(DEST_PS
);
1817 TX_STATUS_ENTRY(ABORTED
);
1818 TX_STATUS_ENTRY(BT_RETRY
);
1819 TX_STATUS_ENTRY(STA_INVALID
);
1820 TX_STATUS_ENTRY(FRAG_DROPPED
);
1821 TX_STATUS_ENTRY(TID_DISABLE
);
1822 TX_STATUS_ENTRY(FRAME_FLUSHED
);
1823 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
1824 TX_STATUS_ENTRY(TX_LOCKED
);
1825 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
1832 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1834 * NOTE: priv->mutex is not required before calling this function
1836 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
1838 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1839 clear_bit(STATUS_SCANNING
, &priv
->status
);
1843 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1844 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1845 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1846 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1847 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1850 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1852 return test_bit(STATUS_SCANNING
, &priv
->status
);
1859 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1860 * @ms: amount of time to wait (in milliseconds) for scan to abort
1862 * NOTE: priv->mutex must be held before calling this function
1864 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1866 unsigned long now
= jiffies
;
1869 ret
= iwl4965_scan_cancel(priv
);
1871 mutex_unlock(&priv
->mutex
);
1872 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1873 test_bit(STATUS_SCANNING
, &priv
->status
))
1875 mutex_lock(&priv
->mutex
);
1877 return test_bit(STATUS_SCANNING
, &priv
->status
);
1883 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
1885 /* Reset ieee stats */
1887 /* We don't reset the net_device_stats (ieee->stats) on
1890 priv
->last_seq_num
= -1;
1891 priv
->last_frag_num
= -1;
1892 priv
->last_packet_time
= 0;
1894 iwl4965_scan_cancel(priv
);
1897 #define MAX_UCODE_BEACON_INTERVAL 4096
1898 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1900 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
1903 u16 beacon_factor
= 0;
1906 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1907 / MAX_UCODE_BEACON_INTERVAL
;
1908 new_val
= beacon_val
/ beacon_factor
;
1910 return cpu_to_le16(new_val
);
1913 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
1915 u64 interval_tm_unit
;
1917 unsigned long flags
;
1918 struct ieee80211_conf
*conf
= NULL
;
1921 conf
= ieee80211_get_hw_conf(priv
->hw
);
1923 spin_lock_irqsave(&priv
->lock
, flags
);
1924 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp1
);
1925 priv
->rxon_timing
.timestamp
.dw
[0] = cpu_to_le32(priv
->timestamp0
);
1927 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1929 tsf
= priv
->timestamp1
;
1930 tsf
= ((tsf
<< 32) | priv
->timestamp0
);
1932 beacon_int
= priv
->beacon_int
;
1933 spin_unlock_irqrestore(&priv
->lock
, flags
);
1935 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1936 if (beacon_int
== 0) {
1937 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1938 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1940 priv
->rxon_timing
.beacon_interval
=
1941 cpu_to_le16(beacon_int
);
1942 priv
->rxon_timing
.beacon_interval
=
1943 iwl4965_adjust_beacon_interval(
1944 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1947 priv
->rxon_timing
.atim_window
= 0;
1949 priv
->rxon_timing
.beacon_interval
=
1950 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1951 /* TODO: we need to get atim_window from upper stack
1952 * for now we set to 0 */
1953 priv
->rxon_timing
.atim_window
= 0;
1957 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1958 result
= do_div(tsf
, interval_tm_unit
);
1959 priv
->rxon_timing
.beacon_init_val
=
1960 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1963 ("beacon interval %d beacon timer %d beacon tim %d\n",
1964 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1965 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1966 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1969 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1971 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1972 IWL_ERROR("APs don't scan.\n");
1976 if (!iwl4965_is_ready_rf(priv
)) {
1977 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1981 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1982 IWL_DEBUG_SCAN("Scan already in progress.\n");
1986 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1987 IWL_DEBUG_SCAN("Scan request while abort pending. "
1992 IWL_DEBUG_INFO("Starting scan...\n");
1993 priv
->scan_bands
= 2;
1994 set_bit(STATUS_SCANNING
, &priv
->status
);
1995 priv
->scan_start
= jiffies
;
1996 priv
->scan_pass_start
= priv
->scan_start
;
1998 queue_work(priv
->workqueue
, &priv
->request_scan
);
2004 static void iwl4965_set_flags_for_phymode(struct iwl_priv
*priv
,
2005 enum ieee80211_band band
)
2007 if (band
== IEEE80211_BAND_5GHZ
) {
2008 priv
->staging_rxon
.flags
&=
2009 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
2010 | RXON_FLG_CCK_MSK
);
2011 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2013 /* Copied from iwl4965_bg_post_associate() */
2014 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2015 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2017 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2019 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2020 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2022 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
2023 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
2024 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
2029 * initialize rxon structure with default values from eeprom
2031 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
2033 const struct iwl_channel_info
*ch_info
;
2035 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
2037 switch (priv
->iw_mode
) {
2038 case IEEE80211_IF_TYPE_AP
:
2039 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
2042 case IEEE80211_IF_TYPE_STA
:
2043 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2044 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2047 case IEEE80211_IF_TYPE_IBSS
:
2048 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2049 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2050 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2051 RXON_FILTER_ACCEPT_GRP_MSK
;
2054 case IEEE80211_IF_TYPE_MNTR
:
2055 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2056 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2057 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2060 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
2065 /* TODO: Figure out when short_preamble would be set and cache from
2067 if (!hw_to_local(priv
->hw
)->short_preamble
)
2068 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2070 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2073 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
2074 le16_to_cpu(priv
->staging_rxon
.channel
));
2077 ch_info
= &priv
->channel_info
[0];
2080 * in some case A channels are all non IBSS
2081 * in this case force B/G channel
2083 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
2084 !(is_channel_ibss(ch_info
)))
2085 ch_info
= &priv
->channel_info
[0];
2087 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2088 priv
->band
= ch_info
->band
;
2090 iwl4965_set_flags_for_phymode(priv
, priv
->band
);
2092 priv
->staging_rxon
.ofdm_basic_rates
=
2093 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2094 priv
->staging_rxon
.cck_basic_rates
=
2095 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2097 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
2098 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
2099 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2100 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
2101 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
2102 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
2103 iwl4965_set_rxon_chain(priv
);
2106 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
2108 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
2109 const struct iwl_channel_info
*ch_info
;
2111 ch_info
= iwl_get_channel_info(priv
,
2113 le16_to_cpu(priv
->staging_rxon
.channel
));
2115 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2116 IWL_ERROR("channel %d not IBSS channel\n",
2117 le16_to_cpu(priv
->staging_rxon
.channel
));
2122 priv
->iw_mode
= mode
;
2124 iwl4965_connection_init_rx_config(priv
);
2125 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2127 iwlcore_clear_stations_table(priv
);
2129 /* dont commit rxon if rf-kill is on*/
2130 if (!iwl4965_is_ready_rf(priv
))
2133 cancel_delayed_work(&priv
->scan_check
);
2134 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
2135 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2136 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2140 iwl4965_commit_rxon(priv
);
2145 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
2146 struct ieee80211_tx_control
*ctl
,
2147 struct iwl_cmd
*cmd
,
2148 struct sk_buff
*skb_frag
,
2151 struct iwl4965_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
2153 switch (keyinfo
->alg
) {
2155 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2156 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2157 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2158 cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_AGG_CCMP_MSK
;
2159 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2163 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2164 ieee80211_get_tkip_key(keyinfo
->conf
, skb_frag
,
2165 IEEE80211_TKIP_P2_KEY
, cmd
->cmd
.tx
.key
);
2166 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
2170 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_WEP
|
2171 (ctl
->key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
2173 if (keyinfo
->keylen
== 13)
2174 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2176 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
, keyinfo
->keylen
);
2178 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2179 "with key %d\n", ctl
->key_idx
);
2183 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2189 * handle build REPLY_TX command notification.
2191 static void iwl4965_build_tx_cmd_basic(struct iwl_priv
*priv
,
2192 struct iwl_cmd
*cmd
,
2193 struct ieee80211_tx_control
*ctrl
,
2194 struct ieee80211_hdr
*hdr
,
2195 int is_unicast
, u8 std_id
)
2198 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2199 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2201 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2202 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2203 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2204 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2205 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2206 if (ieee80211_is_probe_response(fc
) &&
2207 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2208 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2210 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2211 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2214 if (ieee80211_is_back_request(fc
))
2215 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
2218 cmd
->cmd
.tx
.sta_id
= std_id
;
2219 if (ieee80211_get_morefrag(hdr
))
2220 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2222 qc
= ieee80211_get_qos_ctrl(hdr
);
2224 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2225 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2227 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2229 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2230 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2231 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2232 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2233 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2234 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2237 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2238 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2240 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2241 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2242 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2243 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2244 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2246 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2248 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2251 cmd
->cmd
.tx
.driver_txop
= 0;
2252 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2253 cmd
->cmd
.tx
.next_frame_len
= 0;
2255 static void iwl_update_tx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
2257 /* 0 - mgmt, 1 - cnt, 2 - data */
2258 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
2259 priv
->tx_stats
[idx
].cnt
++;
2260 priv
->tx_stats
[idx
].bytes
+= len
;
2263 * iwl4965_get_sta_id - Find station's index within station table
2265 * If new IBSS station, create new entry in station table
2267 static int iwl4965_get_sta_id(struct iwl_priv
*priv
,
2268 struct ieee80211_hdr
*hdr
)
2271 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2272 DECLARE_MAC_BUF(mac
);
2274 /* If this frame is broadcast or management, use broadcast station id */
2275 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2276 is_multicast_ether_addr(hdr
->addr1
))
2277 return priv
->hw_setting
.bcast_sta_id
;
2279 switch (priv
->iw_mode
) {
2281 /* If we are a client station in a BSS network, use the special
2282 * AP station entry (that's the only station we communicate with) */
2283 case IEEE80211_IF_TYPE_STA
:
2286 /* If we are an AP, then find the station, or use BCAST */
2287 case IEEE80211_IF_TYPE_AP
:
2288 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2289 if (sta_id
!= IWL_INVALID_STATION
)
2291 return priv
->hw_setting
.bcast_sta_id
;
2293 /* If this frame is going out to an IBSS network, find the station,
2294 * or create a new station table entry */
2295 case IEEE80211_IF_TYPE_IBSS
:
2296 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2297 if (sta_id
!= IWL_INVALID_STATION
)
2300 /* Create new station table entry */
2301 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
2302 0, CMD_ASYNC
, NULL
);
2304 if (sta_id
!= IWL_INVALID_STATION
)
2307 IWL_DEBUG_DROP("Station %s not in station map. "
2308 "Defaulting to broadcast...\n",
2309 print_mac(mac
, hdr
->addr1
));
2310 iwl_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2311 return priv
->hw_setting
.bcast_sta_id
;
2314 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
2315 return priv
->hw_setting
.bcast_sta_id
;
2320 * start REPLY_TX command process
2322 static int iwl4965_tx_skb(struct iwl_priv
*priv
,
2323 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2325 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2326 struct iwl4965_tfd_frame
*tfd
;
2328 int txq_id
= ctl
->queue
;
2329 struct iwl4965_tx_queue
*txq
= NULL
;
2330 struct iwl4965_queue
*q
= NULL
;
2331 dma_addr_t phys_addr
;
2332 dma_addr_t txcmd_phys
;
2333 dma_addr_t scratch_phys
;
2334 struct iwl_cmd
*out_cmd
= NULL
;
2335 u16 len
, idx
, len_org
;
2336 u8 id
, hdr_len
, unicast
;
2341 u8 wait_write_ptr
= 0;
2342 unsigned long flags
;
2345 spin_lock_irqsave(&priv
->lock
, flags
);
2346 if (iwl4965_is_rfkill(priv
)) {
2347 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2352 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2356 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2357 IWL_ERROR("ERROR: No TX rate available.\n");
2361 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2364 fc
= le16_to_cpu(hdr
->frame_control
);
2366 #ifdef CONFIG_IWLWIFI_DEBUG
2367 if (ieee80211_is_auth(fc
))
2368 IWL_DEBUG_TX("Sending AUTH frame\n");
2369 else if (ieee80211_is_assoc_request(fc
))
2370 IWL_DEBUG_TX("Sending ASSOC frame\n");
2371 else if (ieee80211_is_reassoc_request(fc
))
2372 IWL_DEBUG_TX("Sending REASSOC frame\n");
2375 /* drop all data frame if we are not associated */
2376 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
2377 (!iwl4965_is_associated(priv
) ||
2378 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
2379 !priv
->assoc_station_added
)) {
2380 IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
2384 spin_unlock_irqrestore(&priv
->lock
, flags
);
2386 hdr_len
= ieee80211_get_hdrlen(fc
);
2388 /* Find (or create) index into station table for destination station */
2389 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
2390 if (sta_id
== IWL_INVALID_STATION
) {
2391 DECLARE_MAC_BUF(mac
);
2393 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2394 print_mac(mac
, hdr
->addr1
));
2398 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2400 qc
= ieee80211_get_qos_ctrl(hdr
);
2402 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2403 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2405 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2407 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2409 #ifdef CONFIG_IWL4965_HT
2410 /* aggregation is on for this <sta,tid> */
2411 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2412 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
2413 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
2414 #endif /* CONFIG_IWL4965_HT */
2417 /* Descriptor for chosen Tx queue */
2418 txq
= &priv
->txq
[txq_id
];
2421 spin_lock_irqsave(&priv
->lock
, flags
);
2423 /* Set up first empty TFD within this queue's circular TFD buffer */
2424 tfd
= &txq
->bd
[q
->write_ptr
];
2425 memset(tfd
, 0, sizeof(*tfd
));
2426 control_flags
= (u32
*) tfd
;
2427 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2429 /* Set up driver data for this TFD */
2430 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
2431 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2432 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2433 ctl
, sizeof(struct ieee80211_tx_control
));
2435 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2436 out_cmd
= &txq
->cmd
[idx
];
2437 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2438 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2441 * Set up the Tx-command (not MAC!) header.
2442 * Store the chosen Tx queue and TFD index within the sequence field;
2443 * after Tx, uCode's Tx response will return this value so driver can
2444 * locate the frame within the tx queue and do post-tx processing.
2446 out_cmd
->hdr
.cmd
= REPLY_TX
;
2447 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2448 INDEX_TO_SEQ(q
->write_ptr
)));
2450 /* Copy MAC header from skb into command buffer */
2451 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2454 * Use the first empty entry in this queue's command buffer array
2455 * to contain the Tx command and MAC header concatenated together
2456 * (payload data will be in another buffer).
2457 * Size of this varies, due to varying MAC header length.
2458 * If end is not dword aligned, we'll have 2 extra bytes at the end
2459 * of the MAC header (device reads on dword boundaries).
2460 * We'll tell device about this padding later.
2462 len
= priv
->hw_setting
.tx_cmd_len
+
2463 sizeof(struct iwl_cmd_header
) + hdr_len
;
2466 len
= (len
+ 3) & ~3;
2473 /* Physical address of this Tx command's header (not MAC header!),
2474 * within command buffer array. */
2475 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2476 offsetof(struct iwl_cmd
, hdr
);
2478 /* Add buffer containing Tx command and MAC(!) header to TFD's
2480 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2482 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2483 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, sta_id
);
2485 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2486 * if any (802.11 null frames have no payload). */
2487 len
= skb
->len
- hdr_len
;
2489 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2490 len
, PCI_DMA_TODEVICE
);
2491 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2494 /* Tell 4965 about any 2-byte padding after MAC header */
2496 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
2498 /* Total # bytes to be transmitted */
2499 len
= (u16
)skb
->len
;
2500 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2502 /* TODO need this for burst mode later on */
2503 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2505 /* set is_hcca to 0; it probably will never be implemented */
2506 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2508 iwl_update_tx_stats(priv
, fc
, len
);
2510 scratch_phys
= txcmd_phys
+ sizeof(struct iwl_cmd_header
) +
2511 offsetof(struct iwl4965_tx_cmd
, scratch
);
2512 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
2513 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
2515 if (!ieee80211_get_morefrag(hdr
)) {
2516 txq
->need_update
= 1;
2518 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2519 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2523 txq
->need_update
= 0;
2526 iwl_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2527 sizeof(out_cmd
->cmd
.tx
));
2529 iwl_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2530 ieee80211_get_hdrlen(fc
));
2532 /* Set up entry for this TFD in Tx byte-count array */
2533 iwl4965_tx_queue_update_wr_ptr(priv
, txq
, len
);
2535 /* Tell device the write index *just past* this latest filled TFD */
2536 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2537 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2538 spin_unlock_irqrestore(&priv
->lock
, flags
);
2543 if ((iwl4965_queue_space(q
) < q
->high_mark
)
2544 && priv
->mac80211_registered
) {
2545 if (wait_write_ptr
) {
2546 spin_lock_irqsave(&priv
->lock
, flags
);
2547 txq
->need_update
= 1;
2548 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2549 spin_unlock_irqrestore(&priv
->lock
, flags
);
2552 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2558 spin_unlock_irqrestore(&priv
->lock
, flags
);
2563 static void iwl4965_set_rate(struct iwl_priv
*priv
)
2565 const struct ieee80211_supported_band
*hw
= NULL
;
2566 struct ieee80211_rate
*rate
;
2569 hw
= iwl4965_get_hw_mode(priv
, priv
->band
);
2571 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2575 priv
->active_rate
= 0;
2576 priv
->active_rate_basic
= 0;
2578 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
2579 rate
= &(hw
->bitrates
[i
]);
2580 if (rate
->hw_value
< IWL_RATE_COUNT
)
2581 priv
->active_rate
|= (1 << rate
->hw_value
);
2584 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2585 priv
->active_rate
, priv
->active_rate_basic
);
2588 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2589 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2592 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2593 priv
->staging_rxon
.cck_basic_rates
=
2594 ((priv
->active_rate_basic
&
2595 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2597 priv
->staging_rxon
.cck_basic_rates
=
2598 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2600 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2601 priv
->staging_rxon
.ofdm_basic_rates
=
2602 ((priv
->active_rate_basic
&
2603 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2604 IWL_FIRST_OFDM_RATE
) & 0xFF;
2606 priv
->staging_rxon
.ofdm_basic_rates
=
2607 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2610 static void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2612 unsigned long flags
;
2614 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2617 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2618 disable_radio
? "OFF" : "ON");
2620 if (disable_radio
) {
2621 iwl4965_scan_cancel(priv
);
2622 /* FIXME: This is a workaround for AP */
2623 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2624 spin_lock_irqsave(&priv
->lock
, flags
);
2625 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2626 CSR_UCODE_SW_BIT_RFKILL
);
2627 spin_unlock_irqrestore(&priv
->lock
, flags
);
2628 iwl4965_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
2629 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2634 spin_lock_irqsave(&priv
->lock
, flags
);
2635 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2637 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2638 spin_unlock_irqrestore(&priv
->lock
, flags
);
2643 spin_lock_irqsave(&priv
->lock
, flags
);
2644 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2645 if (!iwl_grab_nic_access(priv
))
2646 iwl_release_nic_access(priv
);
2647 spin_unlock_irqrestore(&priv
->lock
, flags
);
2649 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2650 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2651 "disabled by HW switch\n");
2655 queue_work(priv
->workqueue
, &priv
->restart
);
2659 void iwl4965_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
2660 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2663 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2665 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2668 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2671 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2672 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2673 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2674 /* The uCode has got a bad phase 1 Key, pushes the packet.
2675 * Decryption will be done in SW. */
2676 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2677 RX_RES_STATUS_BAD_KEY_TTAK
)
2680 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2681 RX_RES_STATUS_BAD_ICV_MIC
)
2682 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2683 case RX_RES_STATUS_SEC_TYPE_WEP
:
2684 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2685 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2686 RX_RES_STATUS_DECRYPT_OK
) {
2687 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2688 stats
->flag
|= RX_FLAG_DECRYPTED
;
2698 #define IWL_PACKET_RETRY_TIME HZ
2700 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2702 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2703 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2704 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2705 u16
*last_seq
, *last_frag
;
2706 unsigned long *last_time
;
2708 switch (priv
->iw_mode
) {
2709 case IEEE80211_IF_TYPE_IBSS
:{
2710 struct list_head
*p
;
2711 struct iwl4965_ibss_seq
*entry
= NULL
;
2712 u8
*mac
= header
->addr2
;
2713 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2715 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2716 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
2717 if (!compare_ether_addr(entry
->mac
, mac
))
2720 if (p
== &priv
->ibss_mac_hash
[index
]) {
2721 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2723 IWL_ERROR("Cannot malloc new mac entry\n");
2726 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2727 entry
->seq_num
= seq
;
2728 entry
->frag_num
= frag
;
2729 entry
->packet_time
= jiffies
;
2730 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2733 last_seq
= &entry
->seq_num
;
2734 last_frag
= &entry
->frag_num
;
2735 last_time
= &entry
->packet_time
;
2738 case IEEE80211_IF_TYPE_STA
:
2739 last_seq
= &priv
->last_seq_num
;
2740 last_frag
= &priv
->last_frag_num
;
2741 last_time
= &priv
->last_packet_time
;
2746 if ((*last_seq
== seq
) &&
2747 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
2748 if (*last_frag
== frag
)
2750 if (*last_frag
+ 1 != frag
)
2751 /* out-of-order fragment */
2757 *last_time
= jiffies
;
2764 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2766 #include "iwl-spectrum.h"
2768 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2769 #define BEACON_TIME_MASK_HIGH 0xFF000000
2770 #define TIME_UNIT 1024
2773 * extended beacon time format
2774 * time in usec will be changed into a 32-bit value in 8:24 format
2775 * the high 1 byte is the beacon counts
2776 * the lower 3 bytes is the time in usec within one beacon interval
2779 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2783 u32 interval
= beacon_interval
* 1024;
2785 if (!interval
|| !usec
)
2788 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2789 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2791 return (quot
<< 24) + rem
;
2794 /* base is usually what we get from ucode with each received frame,
2795 * the same as HW timer counter counting down
2798 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2800 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2801 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2802 u32 interval
= beacon_interval
* TIME_UNIT
;
2803 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2804 (addon
& BEACON_TIME_MASK_HIGH
);
2806 if (base_low
> addon_low
)
2807 res
+= base_low
- addon_low
;
2808 else if (base_low
< addon_low
) {
2809 res
+= interval
+ base_low
- addon_low
;
2814 return cpu_to_le32(res
);
2817 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
2818 struct ieee80211_measurement_params
*params
,
2821 struct iwl4965_spectrum_cmd spectrum
;
2822 struct iwl4965_rx_packet
*res
;
2823 struct iwl_host_cmd cmd
= {
2824 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2825 .data
= (void *)&spectrum
,
2826 .meta
.flags
= CMD_WANT_SKB
,
2828 u32 add_time
= le64_to_cpu(params
->start_time
);
2830 int spectrum_resp_status
;
2831 int duration
= le16_to_cpu(params
->duration
);
2833 if (iwl4965_is_associated(priv
))
2835 iwl4965_usecs_to_beacons(
2836 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2837 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2839 memset(&spectrum
, 0, sizeof(spectrum
));
2841 spectrum
.channel_count
= cpu_to_le16(1);
2843 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2844 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2845 cmd
.len
= sizeof(spectrum
);
2846 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2848 if (iwl4965_is_associated(priv
))
2849 spectrum
.start_time
=
2850 iwl4965_add_beacon_time(priv
->last_beacon_time
,
2852 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2854 spectrum
.start_time
= 0;
2856 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2857 spectrum
.channels
[0].channel
= params
->channel
;
2858 spectrum
.channels
[0].type
= type
;
2859 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2860 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2861 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2863 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2867 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2868 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2869 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2873 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2874 switch (spectrum_resp_status
) {
2875 case 0: /* Command will be handled */
2876 if (res
->u
.spectrum
.id
!= 0xff) {
2878 ("Replaced existing measurement: %d\n",
2879 res
->u
.spectrum
.id
);
2880 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2882 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2886 case 1: /* Command will not be handled */
2891 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2897 static void iwl4965_txstatus_to_ieee(struct iwl_priv
*priv
,
2898 struct iwl4965_tx_info
*tx_sta
)
2901 tx_sta
->status
.ack_signal
= 0;
2902 tx_sta
->status
.excessive_retries
= 0;
2903 tx_sta
->status
.queue_length
= 0;
2904 tx_sta
->status
.queue_number
= 0;
2907 ieee80211_tx_status_irqsafe(priv
->hw
,
2908 tx_sta
->skb
[0], &(tx_sta
->status
));
2910 ieee80211_tx_status(priv
->hw
,
2911 tx_sta
->skb
[0], &(tx_sta
->status
));
2913 tx_sta
->skb
[0] = NULL
;
2917 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2919 * When FW advances 'R' index, all entries between old and new 'R' index
2920 * need to be reclaimed. As result, some free space forms. If there is
2921 * enough free space (> low mark), wake the stack that feeds us.
2923 int iwl4965_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
2925 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2926 struct iwl4965_queue
*q
= &txq
->q
;
2929 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
2930 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2931 "is out of range [0-%d] %d %d.\n", txq_id
,
2932 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2936 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
2937 q
->read_ptr
!= index
;
2938 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2939 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
2940 iwl4965_txstatus_to_ieee(priv
,
2941 &(txq
->txb
[txq
->q
.read_ptr
]));
2942 iwl4965_hw_txq_free_tfd(priv
, txq
);
2943 } else if (nfreed
> 1) {
2944 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
2945 q
->write_ptr
, q
->read_ptr
);
2946 queue_work(priv
->workqueue
, &priv
->restart
);
2951 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2952 (txq_id != IWL_CMD_QUEUE_NUM) &&
2953 priv->mac80211_registered)
2954 ieee80211_wake_queue(priv->hw, txq_id); */
2960 static int iwl4965_is_tx_success(u32 status
)
2962 status
&= TX_STATUS_MSK
;
2963 return (status
== TX_STATUS_SUCCESS
)
2964 || (status
== TX_STATUS_DIRECT_DONE
);
2967 /******************************************************************************
2969 * Generic RX handler implementations
2971 ******************************************************************************/
2972 #ifdef CONFIG_IWL4965_HT
2974 static inline int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
,
2975 struct ieee80211_hdr
*hdr
)
2977 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
2980 u8
*da
= ieee80211_get_DA(hdr
);
2981 return iwl4965_hw_find_station(priv
, da
);
2985 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
2986 struct iwl_priv
*priv
, int txq_id
, int idx
)
2988 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
2989 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
2990 txb
[idx
].skb
[0]->data
;
2994 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
2996 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
2997 tx_resp
->frame_count
);
2998 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
3003 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3005 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
3006 struct iwl4965_ht_agg
*agg
,
3007 struct iwl4965_tx_resp_agg
*tx_resp
,
3011 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
3012 struct ieee80211_tx_status
*tx_status
= NULL
;
3013 struct ieee80211_hdr
*hdr
= NULL
;
3018 if (agg
->wait_for_ba
)
3019 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3021 agg
->frame_count
= tx_resp
->frame_count
;
3022 agg
->start_idx
= start_idx
;
3023 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
3026 /* # frames attempted by Tx command */
3027 if (agg
->frame_count
== 1) {
3028 /* Only one frame was attempted; no block-ack will arrive */
3029 status
= le16_to_cpu(frame_status
[0].status
);
3030 seq
= le16_to_cpu(frame_status
[0].sequence
);
3031 idx
= SEQ_TO_INDEX(seq
);
3032 txq_id
= SEQ_TO_QUEUE(seq
);
3034 /* FIXME: code repetition */
3035 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3036 agg
->frame_count
, agg
->start_idx
, idx
);
3038 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
3039 tx_status
->retry_count
= tx_resp
->failure_frame
;
3040 tx_status
->queue_number
= status
& 0xff;
3041 tx_status
->queue_length
= tx_resp
->failure_rts
;
3042 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
3043 tx_status
->flags
= iwl4965_is_tx_success(status
)?
3044 IEEE80211_TX_STATUS_ACK
: 0;
3045 iwl4965_hwrate_to_tx_control(priv
,
3046 le32_to_cpu(tx_resp
->rate_n_flags
),
3047 &tx_status
->control
);
3048 /* FIXME: code repetition end */
3050 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3051 status
& 0xff, tx_resp
->failure_frame
);
3052 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3053 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
3055 agg
->wait_for_ba
= 0;
3057 /* Two or more frames were attempted; expect block-ack */
3059 int start
= agg
->start_idx
;
3061 /* Construct bit-map of pending frames within Tx window */
3062 for (i
= 0; i
< agg
->frame_count
; i
++) {
3064 status
= le16_to_cpu(frame_status
[i
].status
);
3065 seq
= le16_to_cpu(frame_status
[i
].sequence
);
3066 idx
= SEQ_TO_INDEX(seq
);
3067 txq_id
= SEQ_TO_QUEUE(seq
);
3069 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
3070 AGG_TX_STATE_ABORT_MSK
))
3073 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3074 agg
->frame_count
, txq_id
, idx
);
3076 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
3078 sc
= le16_to_cpu(hdr
->seq_ctrl
);
3079 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
3080 IWL_ERROR("BUG_ON idx doesn't match seq control"
3081 " idx=%d, seq_idx=%d, seq=%d\n",
3087 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3088 i
, idx
, SEQ_TO_SN(sc
));
3092 sh
= (start
- idx
) + 0xff;
3093 bitmap
= bitmap
<< sh
;
3096 } else if (sh
< -64)
3097 sh
= 0xff - (start
- idx
);
3101 bitmap
= bitmap
<< sh
;
3104 bitmap
|= (1 << sh
);
3105 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3106 start
, (u32
)(bitmap
& 0xFFFFFFFF));
3109 agg
->bitmap
= bitmap
;
3110 agg
->start_idx
= start
;
3111 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
3112 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3113 agg
->frame_count
, agg
->start_idx
,
3117 agg
->wait_for_ba
= 1;
3124 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3126 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
3127 struct iwl4965_rx_mem_buffer
*rxb
)
3129 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3130 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3131 int txq_id
= SEQ_TO_QUEUE(sequence
);
3132 int index
= SEQ_TO_INDEX(sequence
);
3133 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
3134 struct ieee80211_tx_status
*tx_status
;
3135 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
3136 u32 status
= le32_to_cpu(tx_resp
->status
);
3137 #ifdef CONFIG_IWL4965_HT
3138 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
3139 struct ieee80211_hdr
*hdr
;
3143 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
3144 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3145 "is out of range [0-%d] %d %d\n", txq_id
,
3146 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
3151 #ifdef CONFIG_IWL4965_HT
3152 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
3153 qc
= ieee80211_get_qos_ctrl(hdr
);
3156 tid
= le16_to_cpu(*qc
) & 0xf;
3158 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
3159 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
3160 IWL_ERROR("Station not known\n");
3164 if (txq
->sched_retry
) {
3165 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
3166 struct iwl4965_ht_agg
*agg
= NULL
;
3171 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
3173 iwl4965_tx_status_reply_tx(priv
, agg
,
3174 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
3176 if ((tx_resp
->frame_count
== 1) &&
3177 !iwl4965_is_tx_success(status
)) {
3178 /* TODO: send BAR */
3181 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
3183 index
= iwl_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
3184 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3185 "%d index %d\n", scd_ssn
, index
);
3186 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3187 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3189 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3190 txq_id
>= 0 && priv
->mac80211_registered
&&
3191 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
3192 ieee80211_wake_queue(priv
->hw
, txq_id
);
3194 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3197 #endif /* CONFIG_IWL4965_HT */
3198 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
3200 tx_status
->retry_count
= tx_resp
->failure_frame
;
3201 tx_status
->queue_number
= status
;
3202 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3203 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3205 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3206 iwl4965_hwrate_to_tx_control(priv
, le32_to_cpu(tx_resp
->rate_n_flags
),
3207 &tx_status
->control
);
3209 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3210 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
3211 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
3212 tx_resp
->failure_frame
);
3214 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3216 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3217 #ifdef CONFIG_IWL4965_HT
3218 if (tid
!= MAX_TID_COUNT
)
3219 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3220 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3222 priv
->mac80211_registered
)
3223 ieee80211_wake_queue(priv
->hw
, txq_id
);
3224 if (tid
!= MAX_TID_COUNT
)
3225 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3228 #ifdef CONFIG_IWL4965_HT
3230 #endif /* CONFIG_IWL4965_HT */
3232 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3233 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3237 static void iwl4965_rx_reply_alive(struct iwl_priv
*priv
,
3238 struct iwl4965_rx_mem_buffer
*rxb
)
3240 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3241 struct iwl4965_alive_resp
*palive
;
3242 struct delayed_work
*pwork
;
3244 palive
= &pkt
->u
.alive_frame
;
3246 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3248 palive
->is_valid
, palive
->ver_type
,
3249 palive
->ver_subtype
);
3251 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3252 IWL_DEBUG_INFO("Initialization Alive received.\n");
3253 memcpy(&priv
->card_alive_init
,
3254 &pkt
->u
.alive_frame
,
3255 sizeof(struct iwl4965_init_alive_resp
));
3256 pwork
= &priv
->init_alive_start
;
3258 IWL_DEBUG_INFO("Runtime Alive received.\n");
3259 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3260 sizeof(struct iwl4965_alive_resp
));
3261 pwork
= &priv
->alive_start
;
3264 /* We delay the ALIVE response by 5ms to
3265 * give the HW RF Kill time to activate... */
3266 if (palive
->is_valid
== UCODE_VALID_OK
)
3267 queue_delayed_work(priv
->workqueue
, pwork
,
3268 msecs_to_jiffies(5));
3270 IWL_WARNING("uCode did not respond OK.\n");
3273 static void iwl4965_rx_reply_add_sta(struct iwl_priv
*priv
,
3274 struct iwl4965_rx_mem_buffer
*rxb
)
3276 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3278 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3282 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
3283 struct iwl4965_rx_mem_buffer
*rxb
)
3285 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3287 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3288 "seq 0x%04X ser 0x%08X\n",
3289 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3290 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3291 pkt
->u
.err_resp
.cmd_id
,
3292 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3293 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3296 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3298 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
3300 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3301 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3302 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3303 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3304 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3305 rxon
->channel
= csa
->channel
;
3306 priv
->staging_rxon
.channel
= csa
->channel
;
3309 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
3310 struct iwl4965_rx_mem_buffer
*rxb
)
3312 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3313 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3314 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3316 if (!report
->state
) {
3317 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3318 "Spectrum Measure Notification: Start\n");
3322 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3323 priv
->measurement_status
|= MEASUREMENT_READY
;
3327 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
3328 struct iwl4965_rx_mem_buffer
*rxb
)
3330 #ifdef CONFIG_IWLWIFI_DEBUG
3331 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3332 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3333 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3334 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3338 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
3339 struct iwl4965_rx_mem_buffer
*rxb
)
3341 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3342 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3343 "notification for %s:\n",
3344 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3345 iwl_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3348 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
3350 struct iwl_priv
*priv
=
3351 container_of(work
, struct iwl_priv
, beacon_update
);
3352 struct sk_buff
*beacon
;
3354 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3355 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
3358 IWL_ERROR("update beacon failed\n");
3362 mutex_lock(&priv
->mutex
);
3363 /* new beacon skb is allocated every time; dispose previous.*/
3364 if (priv
->ibss_beacon
)
3365 dev_kfree_skb(priv
->ibss_beacon
);
3367 priv
->ibss_beacon
= beacon
;
3368 mutex_unlock(&priv
->mutex
);
3370 iwl4965_send_beacon_cmd(priv
);
3373 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
3374 struct iwl4965_rx_mem_buffer
*rxb
)
3376 #ifdef CONFIG_IWLWIFI_DEBUG
3377 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3378 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3379 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
3381 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3382 "tsf %d %d rate %d\n",
3383 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3384 beacon
->beacon_notify_hdr
.failure_frame
,
3385 le32_to_cpu(beacon
->ibss_mgr_status
),
3386 le32_to_cpu(beacon
->high_tsf
),
3387 le32_to_cpu(beacon
->low_tsf
), rate
);
3390 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3391 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3392 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3395 /* Service response to REPLY_SCAN_CMD (0x80) */
3396 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
3397 struct iwl4965_rx_mem_buffer
*rxb
)
3399 #ifdef CONFIG_IWLWIFI_DEBUG
3400 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3401 struct iwl4965_scanreq_notification
*notif
=
3402 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
3404 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3408 /* Service SCAN_START_NOTIFICATION (0x82) */
3409 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
3410 struct iwl4965_rx_mem_buffer
*rxb
)
3412 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3413 struct iwl4965_scanstart_notification
*notif
=
3414 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
3415 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3416 IWL_DEBUG_SCAN("Scan start: "
3418 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3420 notif
->band
? "bg" : "a",
3422 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3425 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3426 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
3427 struct iwl4965_rx_mem_buffer
*rxb
)
3429 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3430 struct iwl4965_scanresults_notification
*notif
=
3431 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
3433 IWL_DEBUG_SCAN("Scan ch.res: "
3435 "(TSF: 0x%08X:%08X) - %d "
3436 "elapsed=%lu usec (%dms since last)\n",
3438 notif
->band
? "bg" : "a",
3439 le32_to_cpu(notif
->tsf_high
),
3440 le32_to_cpu(notif
->tsf_low
),
3441 le32_to_cpu(notif
->statistics
[0]),
3442 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3443 jiffies_to_msecs(elapsed_jiffies
3444 (priv
->last_scan_jiffies
, jiffies
)));
3446 priv
->last_scan_jiffies
= jiffies
;
3447 priv
->next_scan_jiffies
= 0;
3450 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3451 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
3452 struct iwl4965_rx_mem_buffer
*rxb
)
3454 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3455 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3457 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3458 scan_notif
->scanned_channels
,
3459 scan_notif
->tsf_low
,
3460 scan_notif
->tsf_high
, scan_notif
->status
);
3462 /* The HW is no longer scanning */
3463 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3465 /* The scan completion notification came in, so kill that timer... */
3466 cancel_delayed_work(&priv
->scan_check
);
3468 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3469 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
3470 jiffies_to_msecs(elapsed_jiffies
3471 (priv
->scan_pass_start
, jiffies
)));
3473 /* Remove this scanned band from the list
3474 * of pending bands to scan */
3477 /* If a request to abort was given, or the scan did not succeed
3478 * then we reset the scan state machine and terminate,
3479 * re-queuing another scan if one has been requested */
3480 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3481 IWL_DEBUG_INFO("Aborted scan completed.\n");
3482 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3484 /* If there are more bands on this scan pass reschedule */
3485 if (priv
->scan_bands
> 0)
3489 priv
->last_scan_jiffies
= jiffies
;
3490 priv
->next_scan_jiffies
= 0;
3491 IWL_DEBUG_INFO("Setting scan to off\n");
3493 clear_bit(STATUS_SCANNING
, &priv
->status
);
3495 IWL_DEBUG_INFO("Scan took %dms\n",
3496 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3498 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3503 priv
->scan_pass_start
= jiffies
;
3504 queue_work(priv
->workqueue
, &priv
->request_scan
);
3507 /* Handle notification from uCode that card's power state is changing
3508 * due to software, hardware, or critical temperature RFKILL */
3509 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
3510 struct iwl4965_rx_mem_buffer
*rxb
)
3512 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3513 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3514 unsigned long status
= priv
->status
;
3516 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3517 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3518 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3520 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
3521 RF_CARD_DISABLED
)) {
3523 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3524 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3526 if (!iwl_grab_nic_access(priv
)) {
3528 priv
, HBUS_TARG_MBX_C
,
3529 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3531 iwl_release_nic_access(priv
);
3534 if (!(flags
& RXON_CARD_DISABLED
)) {
3535 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
3536 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3537 if (!iwl_grab_nic_access(priv
)) {
3539 priv
, HBUS_TARG_MBX_C
,
3540 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3542 iwl_release_nic_access(priv
);
3546 if (flags
& RF_CARD_DISABLED
) {
3547 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3548 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
3549 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3550 if (!iwl_grab_nic_access(priv
))
3551 iwl_release_nic_access(priv
);
3555 if (flags
& HW_CARD_DISABLED
)
3556 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3558 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3561 if (flags
& SW_CARD_DISABLED
)
3562 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3564 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3566 if (!(flags
& RXON_CARD_DISABLED
))
3567 iwl4965_scan_cancel(priv
);
3569 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3570 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3571 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3572 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3573 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3575 wake_up_interruptible(&priv
->wait_command_queue
);
3579 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3581 * Setup the RX handlers for each of the reply types sent from the uCode
3584 * This function chains into the hardware specific files for them to setup
3585 * any hardware specific handlers as well.
3587 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
3589 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
3590 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
3591 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
3592 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
3593 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3594 iwl4965_rx_spectrum_measure_notif
;
3595 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
3596 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3597 iwl4965_rx_pm_debug_statistics_notif
;
3598 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
3601 * The same handler is used for both the REPLY to a discrete
3602 * statistics request from the host as well as for the periodic
3603 * statistics notifications (after received beacons) from the uCode.
3605 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
3606 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
3608 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
3609 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
3610 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3611 iwl4965_rx_scan_results_notif
;
3612 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3613 iwl4965_rx_scan_complete_notif
;
3614 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
3615 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
3617 /* Set up hardware specific Rx handlers */
3618 iwl4965_hw_rx_handler_setup(priv
);
3622 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3623 * @rxb: Rx buffer to reclaim
3625 * If an Rx buffer has an async callback associated with it the callback
3626 * will be executed. The attached skb (if present) will only be freed
3627 * if the callback returns 1
3629 static void iwl4965_tx_cmd_complete(struct iwl_priv
*priv
,
3630 struct iwl4965_rx_mem_buffer
*rxb
)
3632 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3633 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3634 int txq_id
= SEQ_TO_QUEUE(sequence
);
3635 int index
= SEQ_TO_INDEX(sequence
);
3636 int huge
= sequence
& SEQ_HUGE_FRAME
;
3638 struct iwl_cmd
*cmd
;
3640 /* If a Tx command is being handled and it isn't in the actual
3641 * command queue then there a command routing bug has been introduced
3642 * in the queue management code. */
3643 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3644 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3645 txq_id
, pkt
->hdr
.cmd
);
3646 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3648 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3649 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3651 /* Input error checking is done when commands are added to queue. */
3652 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3653 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3655 } else if (cmd
->meta
.u
.callback
&&
3656 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3659 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3661 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3662 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3663 wake_up_interruptible(&priv
->wait_command_queue
);
3667 /************************** RX-FUNCTIONS ****************************/
3669 * Rx theory of operation
3671 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3672 * each of which point to Receive Buffers to be filled by 4965. These get
3673 * used not only for Rx frames, but for any command response or notification
3674 * from the 4965. The driver and 4965 manage the Rx buffers by means
3675 * of indexes into the circular buffer.
3678 * The host/firmware share two index registers for managing the Rx buffers.
3680 * The READ index maps to the first position that the firmware may be writing
3681 * to -- the driver can read up to (but not including) this position and get
3683 * The READ index is managed by the firmware once the card is enabled.
3685 * The WRITE index maps to the last position the driver has read from -- the
3686 * position preceding WRITE is the last slot the firmware can place a packet.
3688 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3691 * During initialization, the host sets up the READ queue position to the first
3692 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3694 * When the firmware places a packet in a buffer, it will advance the READ index
3695 * and fire the RX interrupt. The driver can then query the READ index and
3696 * process as many packets as possible, moving the WRITE index forward as it
3697 * resets the Rx queue buffers with new memory.
3699 * The management in the driver is as follows:
3700 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3701 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3702 * to replenish the iwl->rxq->rx_free.
3703 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3704 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3705 * 'processed' and 'read' driver indexes as well)
3706 * + A received packet is processed and handed to the kernel network stack,
3707 * detached from the iwl->rxq. The driver 'processed' index is updated.
3708 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3709 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3710 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3711 * were enough free buffers and RX_STALLED is set it is cleared.
3716 * iwl4965_rx_queue_alloc() Allocates rx_free
3717 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3718 * iwl4965_rx_queue_restock
3719 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3720 * queue, updates firmware pointers, and updates
3721 * the WRITE index. If insufficient rx_free buffers
3722 * are available, schedules iwl4965_rx_replenish
3724 * -- enable interrupts --
3725 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3726 * READ INDEX, detaching the SKB from the pool.
3727 * Moves the packet buffer from queue to rx_used.
3728 * Calls iwl4965_rx_queue_restock to refill any empty
3735 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3737 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue
*q
)
3739 int s
= q
->read
- q
->write
;
3742 /* keep some buffer to not confuse full and empty queue */
3750 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3752 int iwl4965_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*q
)
3756 unsigned long flags
;
3758 spin_lock_irqsave(&q
->lock
, flags
);
3760 if (q
->need_update
== 0)
3763 /* If power-saving is in use, make sure device is awake */
3764 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3765 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3767 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3768 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3769 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3773 rc
= iwl_grab_nic_access(priv
);
3777 /* Device expects a multiple of 8 */
3778 iwl_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3780 iwl_release_nic_access(priv
);
3782 /* Else device is assumed to be awake */
3784 /* Device expects a multiple of 8 */
3785 iwl_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3791 spin_unlock_irqrestore(&q
->lock
, flags
);
3796 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3798 static inline __le32
iwl4965_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3799 dma_addr_t dma_addr
)
3801 return cpu_to_le32((u32
)(dma_addr
>> 8));
3806 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3808 * If there are slots in the RX queue that need to be restocked,
3809 * and we have free pre-allocated buffers, fill the ranks as much
3810 * as we can, pulling from rx_free.
3812 * This moves the 'write' index forward to catch up with 'processed', and
3813 * also updates the memory address in the firmware to reference the new
3816 static int iwl4965_rx_queue_restock(struct iwl_priv
*priv
)
3818 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3819 struct list_head
*element
;
3820 struct iwl4965_rx_mem_buffer
*rxb
;
3821 unsigned long flags
;
3824 spin_lock_irqsave(&rxq
->lock
, flags
);
3825 write
= rxq
->write
& ~0x7;
3826 while ((iwl4965_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3827 /* Get next free Rx buffer, remove from free list */
3828 element
= rxq
->rx_free
.next
;
3829 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3832 /* Point to Rx buffer via next RBD in circular buffer */
3833 rxq
->bd
[rxq
->write
] = iwl4965_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3834 rxq
->queue
[rxq
->write
] = rxb
;
3835 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3838 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3839 /* If the pre-allocated buffer pool is dropping low, schedule to
3841 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3842 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3845 /* If we've added more space for the firmware to place data, tell it.
3846 * Increment device's write pointer in multiples of 8. */
3847 if ((write
!= (rxq
->write
& ~0x7))
3848 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3849 spin_lock_irqsave(&rxq
->lock
, flags
);
3850 rxq
->need_update
= 1;
3851 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3852 rc
= iwl4965_rx_queue_update_write_ptr(priv
, rxq
);
3861 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3863 * When moving to rx_free an SKB is allocated for the slot.
3865 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3866 * This is called as a scheduled work item (except for during initialization)
3868 static void iwl4965_rx_allocate(struct iwl_priv
*priv
)
3870 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3871 struct list_head
*element
;
3872 struct iwl4965_rx_mem_buffer
*rxb
;
3873 unsigned long flags
;
3874 spin_lock_irqsave(&rxq
->lock
, flags
);
3875 while (!list_empty(&rxq
->rx_used
)) {
3876 element
= rxq
->rx_used
.next
;
3877 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3879 /* Alloc a new receive buffer */
3881 alloc_skb(priv
->hw_setting
.rx_buf_size
,
3882 __GFP_NOWARN
| GFP_ATOMIC
);
3884 if (net_ratelimit())
3885 printk(KERN_CRIT DRV_NAME
3886 ": Can not allocate SKB buffers\n");
3887 /* We don't reschedule replenish work here -- we will
3888 * call the restock method and if it still needs
3889 * more buffers it will schedule replenish */
3892 priv
->alloc_rxb_skb
++;
3895 /* Get physical address of RB/SKB */
3897 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3898 priv
->hw_setting
.rx_buf_size
, PCI_DMA_FROMDEVICE
);
3899 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3902 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3906 * this should be called while priv->lock is locked
3908 static void __iwl4965_rx_replenish(void *data
)
3910 struct iwl_priv
*priv
= data
;
3912 iwl4965_rx_allocate(priv
);
3913 iwl4965_rx_queue_restock(priv
);
3917 void iwl4965_rx_replenish(void *data
)
3919 struct iwl_priv
*priv
= data
;
3920 unsigned long flags
;
3922 iwl4965_rx_allocate(priv
);
3924 spin_lock_irqsave(&priv
->lock
, flags
);
3925 iwl4965_rx_queue_restock(priv
);
3926 spin_unlock_irqrestore(&priv
->lock
, flags
);
3929 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3930 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3931 * This free routine walks the list of POOL entries and if SKB is set to
3932 * non NULL it is unmapped and freed
3934 static void iwl4965_rx_queue_free(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3937 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3938 if (rxq
->pool
[i
].skb
!= NULL
) {
3939 pci_unmap_single(priv
->pci_dev
,
3940 rxq
->pool
[i
].dma_addr
,
3941 priv
->hw_setting
.rx_buf_size
,
3942 PCI_DMA_FROMDEVICE
);
3943 dev_kfree_skb(rxq
->pool
[i
].skb
);
3947 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3952 int iwl4965_rx_queue_alloc(struct iwl_priv
*priv
)
3954 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3955 struct pci_dev
*dev
= priv
->pci_dev
;
3958 spin_lock_init(&rxq
->lock
);
3959 INIT_LIST_HEAD(&rxq
->rx_free
);
3960 INIT_LIST_HEAD(&rxq
->rx_used
);
3962 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3963 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3967 /* Fill the rx_used queue with _all_ of the Rx buffers */
3968 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3969 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3971 /* Set us so that we have processed and used all buffers, but have
3972 * not restocked the Rx queue with fresh buffers */
3973 rxq
->read
= rxq
->write
= 0;
3974 rxq
->free_count
= 0;
3975 rxq
->need_update
= 0;
3979 void iwl4965_rx_queue_reset(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3981 unsigned long flags
;
3983 spin_lock_irqsave(&rxq
->lock
, flags
);
3984 INIT_LIST_HEAD(&rxq
->rx_free
);
3985 INIT_LIST_HEAD(&rxq
->rx_used
);
3986 /* Fill the rx_used queue with _all_ of the Rx buffers */
3987 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3988 /* In the reset function, these buffers may have been allocated
3989 * to an SKB, so we need to unmap and free potential storage */
3990 if (rxq
->pool
[i
].skb
!= NULL
) {
3991 pci_unmap_single(priv
->pci_dev
,
3992 rxq
->pool
[i
].dma_addr
,
3993 priv
->hw_setting
.rx_buf_size
,
3994 PCI_DMA_FROMDEVICE
);
3995 priv
->alloc_rxb_skb
--;
3996 dev_kfree_skb(rxq
->pool
[i
].skb
);
3997 rxq
->pool
[i
].skb
= NULL
;
3999 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4002 /* Set us so that we have processed and used all buffers, but have
4003 * not restocked the Rx queue with fresh buffers */
4004 rxq
->read
= rxq
->write
= 0;
4005 rxq
->free_count
= 0;
4006 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4009 /* Convert linear signal-to-noise ratio into dB */
4010 static u8 ratio2dB
[100] = {
4011 /* 0 1 2 3 4 5 6 7 8 9 */
4012 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4013 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4014 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4015 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4016 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4017 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4018 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4019 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4020 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4021 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4024 /* Calculates a relative dB value from a ratio of linear
4025 * (i.e. not dB) signal levels.
4026 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4027 int iwl4965_calc_db_from_ratio(int sig_ratio
)
4029 /* 1000:1 or higher just report as 60 dB */
4030 if (sig_ratio
>= 1000)
4033 /* 100:1 or higher, divide by 10 and use table,
4034 * add 20 dB to make up for divide by 10 */
4035 if (sig_ratio
>= 100)
4036 return (20 + (int)ratio2dB
[sig_ratio
/10]);
4038 /* We shouldn't see this */
4042 /* Use table for ratios 1:1 - 99:1 */
4043 return (int)ratio2dB
[sig_ratio
];
4046 #define PERFECT_RSSI (-20) /* dBm */
4047 #define WORST_RSSI (-95) /* dBm */
4048 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4050 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4051 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4052 * about formulas used below. */
4053 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
4056 int degradation
= PERFECT_RSSI
- rssi_dbm
;
4058 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4059 * as indicator; formula is (signal dbm - noise dbm).
4060 * SNR at or above 40 is a great signal (100%).
4061 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4062 * Weakest usable signal is usually 10 - 15 dB SNR. */
4064 if (rssi_dbm
- noise_dbm
>= 40)
4066 else if (rssi_dbm
< noise_dbm
)
4068 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
4070 /* Else use just the signal level.
4071 * This formula is a least squares fit of data points collected and
4072 * compared with a reference system that had a percentage (%) display
4073 * for signal quality. */
4075 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
4076 (15 * RSSI_RANGE
+ 62 * degradation
)) /
4077 (RSSI_RANGE
* RSSI_RANGE
);
4081 else if (sig_qual
< 1)
4088 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
4090 * Uses the priv->rx_handlers callback function array to invoke
4091 * the appropriate handlers, including command responses,
4092 * frame-received notifications, and other notifications.
4094 static void iwl4965_rx_handle(struct iwl_priv
*priv
)
4096 struct iwl4965_rx_mem_buffer
*rxb
;
4097 struct iwl4965_rx_packet
*pkt
;
4098 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
4101 unsigned long flags
;
4105 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4106 * buffer that the driver may process (last buffer filled by ucode). */
4107 r
= iwl4965_hw_get_rx_read(priv
);
4110 /* Rx interrupt, but nothing sent from uCode */
4112 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
4114 if (iwl4965_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
4118 rxb
= rxq
->queue
[i
];
4120 /* If an RXB doesn't have a Rx queue slot associated with it,
4121 * then a bug has been introduced in the queue refilling
4122 * routines -- catch it here */
4123 BUG_ON(rxb
== NULL
);
4125 rxq
->queue
[i
] = NULL
;
4127 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
4128 priv
->hw_setting
.rx_buf_size
,
4129 PCI_DMA_FROMDEVICE
);
4130 pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
4132 /* Reclaim a command buffer only if this packet is a response
4133 * to a (driver-originated) command.
4134 * If the packet (e.g. Rx frame) originated from uCode,
4135 * there is no command buffer to reclaim.
4136 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4137 * but apparently a few don't get set; catch them here. */
4138 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
4139 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
4140 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
4141 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
4142 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
4143 (pkt
->hdr
.cmd
!= REPLY_TX
);
4145 /* Based on type of command response or notification,
4146 * handle those that need handling via function in
4147 * rx_handlers table. See iwl4965_setup_rx_handlers() */
4148 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
4149 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4150 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
4151 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
4152 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
4154 /* No handling needed */
4155 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4156 "r %d i %d No handler needed for %s, 0x%02x\n",
4157 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
4162 /* Invoke any callbacks, transfer the skb to caller, and
4163 * fire off the (possibly) blocking iwl_send_cmd()
4164 * as we reclaim the driver command queue */
4165 if (rxb
&& rxb
->skb
)
4166 iwl4965_tx_cmd_complete(priv
, rxb
);
4168 IWL_WARNING("Claim null rxb?\n");
4171 /* For now we just don't re-use anything. We can tweak this
4172 * later to try and re-use notification packets and SKBs that
4173 * fail to Rx correctly */
4174 if (rxb
->skb
!= NULL
) {
4175 priv
->alloc_rxb_skb
--;
4176 dev_kfree_skb_any(rxb
->skb
);
4180 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4181 priv
->hw_setting
.rx_buf_size
,
4182 PCI_DMA_FROMDEVICE
);
4183 spin_lock_irqsave(&rxq
->lock
, flags
);
4184 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4185 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4186 i
= (i
+ 1) & RX_QUEUE_MASK
;
4187 /* If there are a lot of unused frames,
4188 * restock the Rx queue so ucode wont assert. */
4193 __iwl4965_rx_replenish(priv
);
4199 /* Backtrack one entry */
4201 iwl4965_rx_queue_restock(priv
);
4205 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4207 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
4208 struct iwl4965_tx_queue
*txq
)
4212 int txq_id
= txq
->q
.id
;
4214 if (txq
->need_update
== 0)
4217 /* if we're trying to save power */
4218 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4219 /* wake up nic if it's powered down ...
4220 * uCode will wake up, and interrupt us again, so next
4221 * time we'll skip this part. */
4222 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
4224 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4225 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4226 iwl_set_bit(priv
, CSR_GP_CNTRL
,
4227 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4231 /* restore this queue's parameters in nic hardware. */
4232 rc
= iwl_grab_nic_access(priv
);
4235 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
4236 txq
->q
.write_ptr
| (txq_id
<< 8));
4237 iwl_release_nic_access(priv
);
4239 /* else not in power-save mode, uCode will never sleep when we're
4240 * trying to tx (during RFKILL, we're not trying to tx). */
4242 iwl_write32(priv
, HBUS_TARG_WRPTR
,
4243 txq
->q
.write_ptr
| (txq_id
<< 8));
4245 txq
->need_update
= 0;
4250 #ifdef CONFIG_IWLWIFI_DEBUG
4251 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd
*rxon
)
4253 DECLARE_MAC_BUF(mac
);
4255 IWL_DEBUG_RADIO("RX CONFIG:\n");
4256 iwl_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4257 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4258 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4259 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4260 le32_to_cpu(rxon
->filter_flags
));
4261 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4262 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4263 rxon
->ofdm_basic_rates
);
4264 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4265 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4266 print_mac(mac
, rxon
->node_addr
));
4267 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4268 print_mac(mac
, rxon
->bssid_addr
));
4269 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4273 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
4275 IWL_DEBUG_ISR("Enabling interrupts\n");
4276 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4277 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4280 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
4282 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4284 /* disable interrupts from uCode/NIC to host */
4285 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4287 /* acknowledge/clear/reset any interrupts still pending
4288 * from uCode or flow handler (Rx/Tx DMA) */
4289 iwl_write32(priv
, CSR_INT
, 0xffffffff);
4290 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4291 IWL_DEBUG_ISR("Disabled interrupts\n");
4294 static const char *desc_lookup(int i
)
4302 return "BAD_CHECKSUM";
4304 return "NMI_INTERRUPT";
4308 return "FATAL_ERROR";
4314 #define ERROR_START_OFFSET (1 * sizeof(u32))
4315 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4317 static void iwl4965_dump_nic_error_log(struct iwl_priv
*priv
)
4320 u32 desc
, time
, count
, base
, data1
;
4321 u32 blink1
, blink2
, ilink1
, ilink2
;
4324 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4326 if (!iwl4965_hw_valid_rtc_data_addr(base
)) {
4327 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4331 rc
= iwl_grab_nic_access(priv
);
4333 IWL_WARNING("Can not read from adapter at this time.\n");
4337 count
= iwl_read_targ_mem(priv
, base
);
4339 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4340 IWL_ERROR("Start IWL Error Log Dump:\n");
4341 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
4344 desc
= iwl_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
4345 blink1
= iwl_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
4346 blink2
= iwl_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
4347 ilink1
= iwl_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
4348 ilink2
= iwl_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
4349 data1
= iwl_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
4350 data2
= iwl_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
4351 line
= iwl_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
4352 time
= iwl_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
4354 IWL_ERROR("Desc Time "
4355 "data1 data2 line\n");
4356 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4357 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
4358 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4359 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
4362 iwl_release_nic_access(priv
);
4365 #define EVENT_START_OFFSET (4 * sizeof(u32))
4368 * iwl4965_print_event_log - Dump error event log to syslog
4370 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4372 static void iwl4965_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4373 u32 num_events
, u32 mode
)
4376 u32 base
; /* SRAM byte address of event log header */
4377 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4378 u32 ptr
; /* SRAM byte address of log data */
4379 u32 ev
, time
, data
; /* event log data */
4381 if (num_events
== 0)
4384 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4387 event_size
= 2 * sizeof(u32
);
4389 event_size
= 3 * sizeof(u32
);
4391 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4393 /* "time" is actually "data" for mode 0 (no timestamp).
4394 * place event id # at far right for easier visual parsing. */
4395 for (i
= 0; i
< num_events
; i
++) {
4396 ev
= iwl_read_targ_mem(priv
, ptr
);
4398 time
= iwl_read_targ_mem(priv
, ptr
);
4401 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4403 data
= iwl_read_targ_mem(priv
, ptr
);
4405 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4410 static void iwl4965_dump_nic_event_log(struct iwl_priv
*priv
)
4413 u32 base
; /* SRAM byte address of event log header */
4414 u32 capacity
; /* event log capacity in # entries */
4415 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4416 u32 num_wraps
; /* # times uCode wrapped to top of log */
4417 u32 next_entry
; /* index of next entry to be written by uCode */
4418 u32 size
; /* # entries that we'll print */
4420 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4421 if (!iwl4965_hw_valid_rtc_data_addr(base
)) {
4422 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4426 rc
= iwl_grab_nic_access(priv
);
4428 IWL_WARNING("Can not read from adapter at this time.\n");
4432 /* event log header */
4433 capacity
= iwl_read_targ_mem(priv
, base
);
4434 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4435 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4436 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4438 size
= num_wraps
? capacity
: next_entry
;
4440 /* bail out if nothing in log */
4442 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4443 iwl_release_nic_access(priv
);
4447 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4450 /* if uCode has wrapped back to top of log, start at the oldest entry,
4451 * i.e the next one that uCode would fill. */
4453 iwl4965_print_event_log(priv
, next_entry
,
4454 capacity
- next_entry
, mode
);
4456 /* (then/else) start at top of log */
4457 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
4459 iwl_release_nic_access(priv
);
4463 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4465 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
4467 /* Set the FW error flag -- cleared on iwl4965_down */
4468 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4470 /* Cancel currently queued command. */
4471 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4473 #ifdef CONFIG_IWLWIFI_DEBUG
4474 if (iwl_debug_level
& IWL_DL_FW_ERRORS
) {
4475 iwl4965_dump_nic_error_log(priv
);
4476 iwl4965_dump_nic_event_log(priv
);
4477 iwl4965_print_rx_config_cmd(&priv
->staging_rxon
);
4481 wake_up_interruptible(&priv
->wait_command_queue
);
4483 /* Keep the restart process from trying to send host
4484 * commands by clearing the INIT status bit */
4485 clear_bit(STATUS_READY
, &priv
->status
);
4487 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4488 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4489 "Restarting adapter due to uCode error.\n");
4491 if (iwl4965_is_associated(priv
)) {
4492 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4493 sizeof(priv
->recovery_rxon
));
4494 priv
->error_recovering
= 1;
4496 queue_work(priv
->workqueue
, &priv
->restart
);
4500 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
4502 unsigned long flags
;
4504 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4505 sizeof(priv
->staging_rxon
));
4506 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4507 iwl4965_commit_rxon(priv
);
4509 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
4511 spin_lock_irqsave(&priv
->lock
, flags
);
4512 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4513 priv
->error_recovering
= 0;
4514 spin_unlock_irqrestore(&priv
->lock
, flags
);
4517 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
4519 u32 inta
, handled
= 0;
4521 unsigned long flags
;
4522 #ifdef CONFIG_IWLWIFI_DEBUG
4526 spin_lock_irqsave(&priv
->lock
, flags
);
4528 /* Ack/clear/reset pending uCode interrupts.
4529 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4530 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4531 inta
= iwl_read32(priv
, CSR_INT
);
4532 iwl_write32(priv
, CSR_INT
, inta
);
4534 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4535 * Any new interrupts that happen after this, either while we're
4536 * in this tasklet, or later, will show up in next ISR/tasklet. */
4537 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4538 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4540 #ifdef CONFIG_IWLWIFI_DEBUG
4541 if (iwl_debug_level
& IWL_DL_ISR
) {
4542 /* just for debug */
4543 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4544 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4545 inta
, inta_mask
, inta_fh
);
4549 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4550 * atomic, make sure that inta covers all the interrupts that
4551 * we've discovered, even if FH interrupt came in just after
4552 * reading CSR_INT. */
4553 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
4554 inta
|= CSR_INT_BIT_FH_RX
;
4555 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
4556 inta
|= CSR_INT_BIT_FH_TX
;
4558 /* Now service all interrupt bits discovered above. */
4559 if (inta
& CSR_INT_BIT_HW_ERR
) {
4560 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4562 /* Tell the device to stop sending interrupts */
4563 iwl4965_disable_interrupts(priv
);
4565 iwl4965_irq_handle_error(priv
);
4567 handled
|= CSR_INT_BIT_HW_ERR
;
4569 spin_unlock_irqrestore(&priv
->lock
, flags
);
4574 #ifdef CONFIG_IWLWIFI_DEBUG
4575 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4576 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4577 if (inta
& CSR_INT_BIT_SCD
)
4578 IWL_DEBUG_ISR("Scheduler finished to transmit "
4579 "the frame/frames.\n");
4581 /* Alive notification via Rx interrupt will do the real work */
4582 if (inta
& CSR_INT_BIT_ALIVE
)
4583 IWL_DEBUG_ISR("Alive interrupt\n");
4586 /* Safely ignore these bits for debug checks below */
4587 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4589 /* HW RF KILL switch toggled */
4590 if (inta
& CSR_INT_BIT_RF_KILL
) {
4592 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
4593 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4596 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4597 "RF_KILL bit toggled to %s.\n",
4598 hw_rf_kill
? "disable radio":"enable radio");
4600 /* Queue restart only if RF_KILL switch was set to "kill"
4601 * when we loaded driver, and is now set to "enable".
4602 * After we're Alive, RF_KILL gets handled by
4603 * iwl4965_rx_card_state_notif() */
4604 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4605 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4606 queue_work(priv
->workqueue
, &priv
->restart
);
4609 handled
|= CSR_INT_BIT_RF_KILL
;
4612 /* Chip got too hot and stopped itself */
4613 if (inta
& CSR_INT_BIT_CT_KILL
) {
4614 IWL_ERROR("Microcode CT kill error detected.\n");
4615 handled
|= CSR_INT_BIT_CT_KILL
;
4618 /* Error detected by uCode */
4619 if (inta
& CSR_INT_BIT_SW_ERR
) {
4620 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4622 iwl4965_irq_handle_error(priv
);
4623 handled
|= CSR_INT_BIT_SW_ERR
;
4626 /* uCode wakes up after power-down sleep */
4627 if (inta
& CSR_INT_BIT_WAKEUP
) {
4628 IWL_DEBUG_ISR("Wakeup interrupt\n");
4629 iwl4965_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4630 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4631 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4632 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4633 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4634 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4635 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4637 handled
|= CSR_INT_BIT_WAKEUP
;
4640 /* All uCode command responses, including Tx command responses,
4641 * Rx "responses" (frame-received notification), and other
4642 * notifications from uCode come through here*/
4643 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4644 iwl4965_rx_handle(priv
);
4645 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4648 if (inta
& CSR_INT_BIT_FH_TX
) {
4649 IWL_DEBUG_ISR("Tx interrupt\n");
4650 handled
|= CSR_INT_BIT_FH_TX
;
4653 if (inta
& ~handled
)
4654 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4656 if (inta
& ~CSR_INI_SET_MASK
) {
4657 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4658 inta
& ~CSR_INI_SET_MASK
);
4659 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4662 /* Re-enable all interrupts */
4663 iwl4965_enable_interrupts(priv
);
4665 #ifdef CONFIG_IWLWIFI_DEBUG
4666 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4667 inta
= iwl_read32(priv
, CSR_INT
);
4668 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4669 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4670 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4671 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4674 spin_unlock_irqrestore(&priv
->lock
, flags
);
4677 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
4679 struct iwl_priv
*priv
= data
;
4680 u32 inta
, inta_mask
;
4685 spin_lock(&priv
->lock
);
4687 /* Disable (but don't clear!) interrupts here to avoid
4688 * back-to-back ISRs and sporadic interrupts from our NIC.
4689 * If we have something to service, the tasklet will re-enable ints.
4690 * If we *don't* have something, we'll re-enable before leaving here. */
4691 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4692 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4694 /* Discover which interrupts are active/pending */
4695 inta
= iwl_read32(priv
, CSR_INT
);
4696 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4698 /* Ignore interrupt if there's nothing in NIC to service.
4699 * This may be due to IRQ shared with another device,
4700 * or due to sporadic interrupts thrown from our NIC. */
4701 if (!inta
&& !inta_fh
) {
4702 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4706 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4707 /* Hardware disappeared. It might have already raised
4709 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4713 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4714 inta
, inta_mask
, inta_fh
);
4716 inta
&= ~CSR_INT_BIT_SCD
;
4718 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4719 if (likely(inta
|| inta_fh
))
4720 tasklet_schedule(&priv
->irq_tasklet
);
4723 spin_unlock(&priv
->lock
);
4727 /* re-enable interrupts here since we don't have anything to service. */
4728 iwl4965_enable_interrupts(priv
);
4729 spin_unlock(&priv
->lock
);
4733 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4734 * sending probe req. This should be set long enough to hear probe responses
4735 * from more than one AP. */
4736 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4737 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4739 /* For faster active scanning, scan will move to the next channel if fewer than
4740 * PLCP_QUIET_THRESH packets are heard on this channel within
4741 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4742 * time if it's a quiet channel (nothing responded to our probe, and there's
4743 * no other traffic).
4744 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4745 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4746 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4748 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4749 * Must be set longer than active dwell time.
4750 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4751 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4752 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4753 #define IWL_PASSIVE_DWELL_BASE (100)
4754 #define IWL_CHANNEL_TUNE_TIME 5
4756 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
4757 enum ieee80211_band band
)
4759 if (band
== IEEE80211_BAND_5GHZ
)
4760 return IWL_ACTIVE_DWELL_TIME_52
;
4762 return IWL_ACTIVE_DWELL_TIME_24
;
4765 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
4766 enum ieee80211_band band
)
4768 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
4769 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
4770 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4771 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4773 if (iwl4965_is_associated(priv
)) {
4774 /* If we're associated, we clamp the maximum passive
4775 * dwell time to be 98% of the beacon interval (minus
4776 * 2 * channel tune time) */
4777 passive
= priv
->beacon_int
;
4778 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4779 passive
= IWL_PASSIVE_DWELL_BASE
;
4780 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4783 if (passive
<= active
)
4784 passive
= active
+ 1;
4789 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
4790 enum ieee80211_band band
,
4791 u8 is_active
, u8 direct_mask
,
4792 struct iwl4965_scan_channel
*scan_ch
)
4794 const struct ieee80211_channel
*channels
= NULL
;
4795 const struct ieee80211_supported_band
*sband
;
4796 const struct iwl_channel_info
*ch_info
;
4797 u16 passive_dwell
= 0;
4798 u16 active_dwell
= 0;
4801 sband
= iwl4965_get_hw_mode(priv
, band
);
4805 channels
= sband
->channels
;
4807 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
4808 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
4810 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4811 if (ieee80211_frequency_to_channel(channels
[i
].center_freq
) ==
4812 le16_to_cpu(priv
->active_rxon
.channel
)) {
4813 if (iwl4965_is_associated(priv
)) {
4815 ("Skipping current channel %d\n",
4816 le16_to_cpu(priv
->active_rxon
.channel
));
4819 } else if (priv
->only_active_channel
)
4822 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
4824 ch_info
= iwl_get_channel_info(priv
, band
,
4826 if (!is_channel_valid(ch_info
)) {
4827 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
4832 if (!is_active
|| is_channel_passive(ch_info
) ||
4833 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
4834 scan_ch
->type
= 0; /* passive */
4836 scan_ch
->type
= 1; /* active */
4838 if (scan_ch
->type
& 1)
4839 scan_ch
->type
|= (direct_mask
<< 1);
4841 if (is_channel_narrow(ch_info
))
4842 scan_ch
->type
|= (1 << 7);
4844 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4845 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4847 /* Set txpower levels to defaults */
4848 scan_ch
->tpc
.dsp_atten
= 110;
4849 /* scan_pwr_info->tpc.dsp_atten; */
4851 /*scan_pwr_info->tpc.tx_gain; */
4852 if (band
== IEEE80211_BAND_5GHZ
)
4853 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4855 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4856 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4858 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4862 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4864 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4865 (scan_ch
->type
& 1) ?
4866 active_dwell
: passive_dwell
);
4872 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4876 static void iwl4965_init_hw_rates(struct iwl_priv
*priv
,
4877 struct ieee80211_rate
*rates
)
4881 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
4882 rates
[i
].bitrate
= iwl4965_rates
[i
].ieee
* 5;
4883 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
4884 rates
[i
].hw_value_short
= i
;
4886 if ((i
> IWL_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
4888 * If CCK != 1M then set short preamble rate flag.
4891 (iwl4965_rates
[i
].plcp
== IWL_RATE_1M_PLCP
) ?
4892 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
4898 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4900 int iwl4965_init_geos(struct iwl_priv
*priv
)
4902 struct iwl_channel_info
*ch
;
4903 struct ieee80211_supported_band
*sband
;
4904 struct ieee80211_channel
*channels
;
4905 struct ieee80211_channel
*geo_ch
;
4906 struct ieee80211_rate
*rates
;
4909 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
4910 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
4911 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4912 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4916 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
4917 priv
->channel_count
, GFP_KERNEL
);
4921 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
4928 /* 5.2GHz channels start after the 2.4GHz channels */
4929 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4930 sband
->channels
= &channels
[ARRAY_SIZE(iwl_eeprom_band_1
)];
4932 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
4933 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
4935 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_5GHZ
);
4937 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4938 sband
->channels
= channels
;
4940 sband
->bitrates
= rates
;
4941 sband
->n_bitrates
= IWL_RATE_COUNT
;
4943 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_2GHZ
);
4945 priv
->ieee_channels
= channels
;
4946 priv
->ieee_rates
= rates
;
4948 iwl4965_init_hw_rates(priv
, rates
);
4950 for (i
= 0; i
< priv
->channel_count
; i
++) {
4951 ch
= &priv
->channel_info
[i
];
4953 /* FIXME: might be removed if scan is OK */
4954 if (!is_channel_valid(ch
))
4957 if (is_channel_a_band(ch
))
4958 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4960 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4962 geo_ch
= &sband
->channels
[sband
->n_channels
++];
4964 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
4965 geo_ch
->max_power
= ch
->max_power_avg
;
4966 geo_ch
->max_antenna_gain
= 0xff;
4967 geo_ch
->hw_value
= ch
->channel
;
4969 if (is_channel_valid(ch
)) {
4970 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
4971 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
4973 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
4974 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
4976 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
4977 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
4979 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
4980 priv
->max_channel_txpower_limit
=
4983 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
4986 /* Save flags for reg domain usage */
4987 geo_ch
->orig_flags
= geo_ch
->flags
;
4989 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4990 ch
->channel
, geo_ch
->center_freq
,
4991 is_channel_a_band(ch
) ? "5.2" : "2.4",
4992 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
4993 "restricted" : "valid",
4997 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
4998 priv
->cfg
->sku
& IWL_SKU_A
) {
4999 printk(KERN_INFO DRV_NAME
5000 ": Incorrectly detected BG card as ABG. Please send "
5001 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5002 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
5003 priv
->cfg
->sku
&= ~IWL_SKU_A
;
5006 printk(KERN_INFO DRV_NAME
5007 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5008 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
5009 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
5011 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
5012 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5013 &priv
->bands
[IEEE80211_BAND_2GHZ
];
5014 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
5015 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5016 &priv
->bands
[IEEE80211_BAND_5GHZ
];
5018 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5024 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
5026 void iwl4965_free_geos(struct iwl_priv
*priv
)
5028 kfree(priv
->ieee_channels
);
5029 kfree(priv
->ieee_rates
);
5030 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5033 /******************************************************************************
5035 * uCode download functions
5037 ******************************************************************************/
5039 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
5041 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5042 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5043 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5044 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5045 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5046 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5050 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
5051 * looking at all data.
5053 static int iwl4965_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
,
5061 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5063 rc
= iwl_grab_nic_access(priv
);
5067 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
5070 for (; len
> 0; len
-= sizeof(u32
), image
++) {
5071 /* read data comes through single port, auto-incr addr */
5072 /* NOTE: Use the debugless read so we don't flood kernel log
5073 * if IWL_DL_IO is set */
5074 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5075 if (val
!= le32_to_cpu(*image
)) {
5076 IWL_ERROR("uCode INST section is invalid at "
5077 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5078 save_len
- len
, val
, le32_to_cpu(*image
));
5086 iwl_release_nic_access(priv
);
5090 ("ucode image in INSTRUCTION memory is good\n");
5097 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
5098 * using sample data 100 bytes apart. If these sample points are good,
5099 * it's a pretty good bet that everything between them is good, too.
5101 static int iwl4965_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
5108 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5110 rc
= iwl_grab_nic_access(priv
);
5114 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
5115 /* read data comes through single port, auto-incr addr */
5116 /* NOTE: Use the debugless read so we don't flood kernel log
5117 * if IWL_DL_IO is set */
5118 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
5119 i
+ RTC_INST_LOWER_BOUND
);
5120 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5121 if (val
!= le32_to_cpu(*image
)) {
5122 #if 0 /* Enable this if you want to see details */
5123 IWL_ERROR("uCode INST section is invalid at "
5124 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5134 iwl_release_nic_access(priv
);
5141 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
5142 * and verify its contents
5144 static int iwl4965_verify_ucode(struct iwl_priv
*priv
)
5151 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5152 len
= priv
->ucode_boot
.len
;
5153 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5155 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5159 /* Try initialize */
5160 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5161 len
= priv
->ucode_init
.len
;
5162 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5164 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5168 /* Try runtime/protocol */
5169 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5170 len
= priv
->ucode_code
.len
;
5171 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5173 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5177 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5179 /* Since nothing seems to match, show first several data entries in
5180 * instruction SRAM, so maybe visual inspection will give a clue.
5181 * Selection of bootstrap image (vs. other images) is arbitrary. */
5182 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5183 len
= priv
->ucode_boot
.len
;
5184 rc
= iwl4965_verify_inst_full(priv
, image
, len
);
5190 /* check contents of special bootstrap uCode SRAM */
5191 static int iwl4965_verify_bsm(struct iwl_priv
*priv
)
5193 __le32
*image
= priv
->ucode_boot
.v_addr
;
5194 u32 len
= priv
->ucode_boot
.len
;
5198 IWL_DEBUG_INFO("Begin verify bsm\n");
5200 /* verify BSM SRAM contents */
5201 val
= iwl_read_prph(priv
, BSM_WR_DWCOUNT_REG
);
5202 for (reg
= BSM_SRAM_LOWER_BOUND
;
5203 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
5204 reg
+= sizeof(u32
), image
++) {
5205 val
= iwl_read_prph(priv
, reg
);
5206 if (val
!= le32_to_cpu(*image
)) {
5207 IWL_ERROR("BSM uCode verification failed at "
5208 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5209 BSM_SRAM_LOWER_BOUND
,
5210 reg
- BSM_SRAM_LOWER_BOUND
, len
,
5211 val
, le32_to_cpu(*image
));
5216 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5222 * iwl4965_load_bsm - Load bootstrap instructions
5226 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5227 * in special SRAM that does not power down during RFKILL. When powering back
5228 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5229 * the bootstrap program into the on-board processor, and starts it.
5231 * The bootstrap program loads (via DMA) instructions and data for a new
5232 * program from host DRAM locations indicated by the host driver in the
5233 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5236 * When initializing the NIC, the host driver points the BSM to the
5237 * "initialize" uCode image. This uCode sets up some internal data, then
5238 * notifies host via "initialize alive" that it is complete.
5240 * The host then replaces the BSM_DRAM_* pointer values to point to the
5241 * normal runtime uCode instructions and a backup uCode data cache buffer
5242 * (filled initially with starting data values for the on-board processor),
5243 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5244 * which begins normal operation.
5246 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5247 * the backup data cache in DRAM before SRAM is powered down.
5249 * When powering back up, the BSM loads the bootstrap program. This reloads
5250 * the runtime uCode instructions and the backup data cache into SRAM,
5251 * and re-launches the runtime uCode from where it left off.
5253 static int iwl4965_load_bsm(struct iwl_priv
*priv
)
5255 __le32
*image
= priv
->ucode_boot
.v_addr
;
5256 u32 len
= priv
->ucode_boot
.len
;
5266 IWL_DEBUG_INFO("Begin load bsm\n");
5268 /* make sure bootstrap program is no larger than BSM's SRAM size */
5269 if (len
> IWL_MAX_BSM_SIZE
)
5272 /* Tell bootstrap uCode where to find the "Initialize" uCode
5273 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
5274 * NOTE: iwl4965_initialize_alive_start() will replace these values,
5275 * after the "initialize" uCode has run, to point to
5276 * runtime/protocol instructions and backup data cache. */
5277 pinst
= priv
->ucode_init
.p_addr
>> 4;
5278 pdata
= priv
->ucode_init_data
.p_addr
>> 4;
5279 inst_len
= priv
->ucode_init
.len
;
5280 data_len
= priv
->ucode_init_data
.len
;
5282 rc
= iwl_grab_nic_access(priv
);
5286 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5287 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5288 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
5289 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
5291 /* Fill BSM memory with bootstrap instructions */
5292 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
5293 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
5294 reg_offset
+= sizeof(u32
), image
++)
5295 _iwl_write_prph(priv
, reg_offset
,
5296 le32_to_cpu(*image
));
5298 rc
= iwl4965_verify_bsm(priv
);
5300 iwl_release_nic_access(priv
);
5304 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5305 iwl_write_prph(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
5306 iwl_write_prph(priv
, BSM_WR_MEM_DST_REG
,
5307 RTC_INST_LOWER_BOUND
);
5308 iwl_write_prph(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
5310 /* Load bootstrap code into instruction SRAM now,
5311 * to prepare to load "initialize" uCode */
5312 iwl_write_prph(priv
, BSM_WR_CTRL_REG
,
5313 BSM_WR_CTRL_REG_BIT_START
);
5315 /* Wait for load of bootstrap uCode to finish */
5316 for (i
= 0; i
< 100; i
++) {
5317 done
= iwl_read_prph(priv
, BSM_WR_CTRL_REG
);
5318 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
5323 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i
);
5325 IWL_ERROR("BSM write did not complete!\n");
5329 /* Enable future boot loads whenever power management unit triggers it
5330 * (e.g. when powering back up after power-save shutdown) */
5331 iwl_write_prph(priv
, BSM_WR_CTRL_REG
,
5332 BSM_WR_CTRL_REG_BIT_START_EN
);
5334 iwl_release_nic_access(priv
);
5339 static void iwl4965_nic_start(struct iwl_priv
*priv
)
5341 /* Remove all resets to allow NIC to operate */
5342 iwl_write32(priv
, CSR_RESET
, 0);
5347 * iwl4965_read_ucode - Read uCode images from disk file.
5349 * Copy into buffers for card to fetch via bus-mastering
5351 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
5353 struct iwl4965_ucode
*ucode
;
5355 const struct firmware
*ucode_raw
;
5356 const char *name
= priv
->cfg
->fw_name
;
5359 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5361 /* Ask kernel firmware_class module to get the boot firmware off disk.
5362 * request_firmware() is synchronous, file is in memory on return. */
5363 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5365 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5370 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5371 name
, ucode_raw
->size
);
5373 /* Make sure that we got at least our header! */
5374 if (ucode_raw
->size
< sizeof(*ucode
)) {
5375 IWL_ERROR("File size way too small!\n");
5380 /* Data from ucode file: header followed by uCode images */
5381 ucode
= (void *)ucode_raw
->data
;
5383 ver
= le32_to_cpu(ucode
->ver
);
5384 inst_size
= le32_to_cpu(ucode
->inst_size
);
5385 data_size
= le32_to_cpu(ucode
->data_size
);
5386 init_size
= le32_to_cpu(ucode
->init_size
);
5387 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5388 boot_size
= le32_to_cpu(ucode
->boot_size
);
5390 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5391 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5393 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5395 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5397 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5399 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5402 /* Verify size of file vs. image size info in file's header */
5403 if (ucode_raw
->size
< sizeof(*ucode
) +
5404 inst_size
+ data_size
+ init_size
+
5405 init_data_size
+ boot_size
) {
5407 IWL_DEBUG_INFO("uCode file size %d too small\n",
5408 (int)ucode_raw
->size
);
5413 /* Verify that uCode images will fit in card's SRAM */
5414 if (inst_size
> IWL_MAX_INST_SIZE
) {
5415 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5421 if (data_size
> IWL_MAX_DATA_SIZE
) {
5422 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5427 if (init_size
> IWL_MAX_INST_SIZE
) {
5429 ("uCode init instr len %d too large to fit in\n",
5434 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5436 ("uCode init data len %d too large to fit in\n",
5441 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5443 ("uCode boot instr len %d too large to fit in\n",
5449 /* Allocate ucode buffers for card's bus-master loading ... */
5451 /* Runtime instructions and 2 copies of data:
5452 * 1) unmodified from disk
5453 * 2) backup cache for save/restore during power-downs */
5454 priv
->ucode_code
.len
= inst_size
;
5455 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5457 priv
->ucode_data
.len
= data_size
;
5458 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5460 priv
->ucode_data_backup
.len
= data_size
;
5461 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5463 /* Initialization instructions and data */
5464 if (init_size
&& init_data_size
) {
5465 priv
->ucode_init
.len
= init_size
;
5466 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5468 priv
->ucode_init_data
.len
= init_data_size
;
5469 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5471 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5475 /* Bootstrap (instructions only, no data) */
5477 priv
->ucode_boot
.len
= boot_size
;
5478 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5480 if (!priv
->ucode_boot
.v_addr
)
5484 /* Copy images into buffers for card's bus-master reads ... */
5486 /* Runtime instructions (first block of data in file) */
5487 src
= &ucode
->data
[0];
5488 len
= priv
->ucode_code
.len
;
5489 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5490 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5491 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5492 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5494 /* Runtime data (2nd block)
5495 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
5496 src
= &ucode
->data
[inst_size
];
5497 len
= priv
->ucode_data
.len
;
5498 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5499 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5500 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5502 /* Initialization instructions (3rd block) */
5504 src
= &ucode
->data
[inst_size
+ data_size
];
5505 len
= priv
->ucode_init
.len
;
5506 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5508 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5511 /* Initialization data (4th block) */
5512 if (init_data_size
) {
5513 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5514 len
= priv
->ucode_init_data
.len
;
5515 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5517 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5520 /* Bootstrap instructions (5th block) */
5521 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5522 len
= priv
->ucode_boot
.len
;
5523 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
5524 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5526 /* We have our copies now, allow OS release its copies */
5527 release_firmware(ucode_raw
);
5531 IWL_ERROR("failed to allocate pci memory\n");
5533 iwl4965_dealloc_ucode_pci(priv
);
5536 release_firmware(ucode_raw
);
5544 * iwl4965_set_ucode_ptrs - Set uCode address location
5546 * Tell initialization uCode where to find runtime uCode.
5548 * BSM registers initially contain pointers to initialization uCode.
5549 * We need to replace them to load runtime uCode inst and data,
5550 * and to save runtime data when powering down.
5552 static int iwl4965_set_ucode_ptrs(struct iwl_priv
*priv
)
5557 unsigned long flags
;
5559 /* bits 35:4 for 4965 */
5560 pinst
= priv
->ucode_code
.p_addr
>> 4;
5561 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
5563 spin_lock_irqsave(&priv
->lock
, flags
);
5564 rc
= iwl_grab_nic_access(priv
);
5566 spin_unlock_irqrestore(&priv
->lock
, flags
);
5570 /* Tell bootstrap uCode where to find image to load */
5571 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5572 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5573 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5574 priv
->ucode_data
.len
);
5576 /* Inst bytecount must be last to set up, bit 31 signals uCode
5577 * that all new ptr/size info is in place */
5578 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5579 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5581 iwl_release_nic_access(priv
);
5583 spin_unlock_irqrestore(&priv
->lock
, flags
);
5585 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5591 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
5593 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5595 * The 4965 "initialize" ALIVE reply contains calibration data for:
5596 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5597 * (3945 does not contain this data).
5599 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5601 static void iwl4965_init_alive_start(struct iwl_priv
*priv
)
5603 /* Check alive response for "valid" sign from uCode */
5604 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5605 /* We had an error bringing up the hardware, so take it
5606 * all the way back down so we can try again */
5607 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5611 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5612 * This is a paranoid check, because we would not have gotten the
5613 * "initialize" alive if code weren't properly loaded. */
5614 if (iwl4965_verify_ucode(priv
)) {
5615 /* Runtime instruction load was bad;
5616 * take it all the way back down so we can try again */
5617 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5621 /* Calculate temperature */
5622 priv
->temperature
= iwl4965_get_temperature(priv
);
5624 /* Send pointers to protocol/runtime uCode image ... init code will
5625 * load and launch runtime uCode, which will send us another "Alive"
5627 IWL_DEBUG_INFO("Initialization Alive received.\n");
5628 if (iwl4965_set_ucode_ptrs(priv
)) {
5629 /* Runtime instruction load won't happen;
5630 * take it all the way back down so we can try again */
5631 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5637 queue_work(priv
->workqueue
, &priv
->restart
);
5642 * iwl4965_alive_start - called after REPLY_ALIVE notification received
5643 * from protocol/runtime uCode (initialization uCode's
5644 * Alive gets handled by iwl4965_init_alive_start()).
5646 static void iwl4965_alive_start(struct iwl_priv
*priv
)
5650 IWL_DEBUG_INFO("Runtime Alive received.\n");
5652 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5653 /* We had an error bringing up the hardware, so take it
5654 * all the way back down so we can try again */
5655 IWL_DEBUG_INFO("Alive failed.\n");
5659 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5660 * This is a paranoid check, because we would not have gotten the
5661 * "runtime" alive if code weren't properly loaded. */
5662 if (iwl4965_verify_ucode(priv
)) {
5663 /* Runtime instruction load was bad;
5664 * take it all the way back down so we can try again */
5665 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5669 iwlcore_clear_stations_table(priv
);
5671 rc
= iwl4965_alive_notify(priv
);
5673 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5678 /* After the ALIVE response, we can send host commands to 4965 uCode */
5679 set_bit(STATUS_ALIVE
, &priv
->status
);
5681 /* Clear out the uCode error bit if it is set */
5682 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5684 if (iwl4965_is_rfkill(priv
))
5687 ieee80211_start_queues(priv
->hw
);
5689 priv
->active_rate
= priv
->rates_mask
;
5690 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5692 iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5694 if (iwl4965_is_associated(priv
)) {
5695 struct iwl4965_rxon_cmd
*active_rxon
=
5696 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
5698 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
5699 sizeof(priv
->staging_rxon
));
5700 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5702 /* Initialize our rx_config data */
5703 iwl4965_connection_init_rx_config(priv
);
5704 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5707 /* Configure Bluetooth device coexistence support */
5708 iwl4965_send_bt_config(priv
);
5710 /* Configure the adapter for unassociated operation */
5711 iwl4965_commit_rxon(priv
);
5713 /* At this point, the NIC is initialized and operational */
5714 priv
->notif_missed_beacons
= 0;
5715 set_bit(STATUS_READY
, &priv
->status
);
5717 iwl4965_rf_kill_ct_config(priv
);
5719 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5720 wake_up_interruptible(&priv
->wait_command_queue
);
5722 iwl_leds_register(priv
);
5724 if (priv
->error_recovering
)
5725 iwl4965_error_recovery(priv
);
5730 queue_work(priv
->workqueue
, &priv
->restart
);
5733 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
5735 static void __iwl4965_down(struct iwl_priv
*priv
)
5737 unsigned long flags
;
5738 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5739 struct ieee80211_conf
*conf
= NULL
;
5741 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
5743 conf
= ieee80211_get_hw_conf(priv
->hw
);
5746 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5748 iwl_leds_unregister(priv
);
5750 iwlcore_clear_stations_table(priv
);
5752 /* Unblock any waiting calls */
5753 wake_up_interruptible_all(&priv
->wait_command_queue
);
5755 /* Wipe out the EXIT_PENDING status bit if we are not actually
5756 * exiting the module */
5758 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5760 /* stop and reset the on-board processor */
5761 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
5763 /* tell the device to stop sending interrupts */
5764 iwl4965_disable_interrupts(priv
);
5766 if (priv
->mac80211_registered
)
5767 ieee80211_stop_queues(priv
->hw
);
5769 /* If we have not previously called iwl4965_init() then
5770 * clear all bits but the RF Kill and SUSPEND bits and return */
5771 if (!iwl4965_is_init(priv
)) {
5772 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5774 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5776 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5777 STATUS_GEO_CONFIGURED
|
5778 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5783 /* ...otherwise clear out all the status bits but the RF Kill and
5784 * SUSPEND bits and continue taking the NIC down. */
5785 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5787 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5789 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5790 STATUS_GEO_CONFIGURED
|
5791 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5793 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
5796 spin_lock_irqsave(&priv
->lock
, flags
);
5797 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
5798 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
5799 spin_unlock_irqrestore(&priv
->lock
, flags
);
5801 iwl4965_hw_txq_ctx_stop(priv
);
5802 iwl4965_hw_rxq_stop(priv
);
5804 spin_lock_irqsave(&priv
->lock
, flags
);
5805 if (!iwl_grab_nic_access(priv
)) {
5806 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
5807 APMG_CLK_VAL_DMA_CLK_RQT
);
5808 iwl_release_nic_access(priv
);
5810 spin_unlock_irqrestore(&priv
->lock
, flags
);
5814 iwl4965_hw_nic_stop_master(priv
);
5815 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
5816 iwl4965_hw_nic_reset(priv
);
5819 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
5821 if (priv
->ibss_beacon
)
5822 dev_kfree_skb(priv
->ibss_beacon
);
5823 priv
->ibss_beacon
= NULL
;
5825 /* clear out any free frames */
5826 iwl4965_clear_free_frames(priv
);
5829 static void iwl4965_down(struct iwl_priv
*priv
)
5831 mutex_lock(&priv
->mutex
);
5832 __iwl4965_down(priv
);
5833 mutex_unlock(&priv
->mutex
);
5835 iwl4965_cancel_deferred_work(priv
);
5838 #define MAX_HW_RESTARTS 5
5840 static int __iwl4965_up(struct iwl_priv
*priv
)
5844 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5845 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5849 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5850 IWL_WARNING("Radio disabled by SW RF kill (module "
5855 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5856 IWL_ERROR("ucode not available for device bringup\n");
5860 /* If platform's RF_KILL switch is NOT set to KILL */
5861 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
5862 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5863 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5865 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5866 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5867 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5872 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5874 rc
= iwl4965_hw_nic_init(priv
);
5876 IWL_ERROR("Unable to int nic\n");
5880 /* make sure rfkill handshake bits are cleared */
5881 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5882 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5883 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5885 /* clear (again), then enable host interrupts */
5886 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5887 iwl4965_enable_interrupts(priv
);
5889 /* really make sure rfkill handshake bits are cleared */
5890 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5891 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5893 /* Copy original ucode data image from disk into backup cache.
5894 * This will be used to initialize the on-board processor's
5895 * data SRAM for a clean start when the runtime program first loads. */
5896 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5897 priv
->ucode_data
.len
);
5899 /* We return success when we resume from suspend and rf_kill is on. */
5900 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5903 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5905 iwlcore_clear_stations_table(priv
);
5907 /* load bootstrap state machine,
5908 * load bootstrap program into processor's memory,
5909 * prepare to load the "initialize" uCode */
5910 rc
= iwl4965_load_bsm(priv
);
5913 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc
);
5917 /* start card; "initialize" will load runtime ucode */
5918 iwl4965_nic_start(priv
);
5920 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5925 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5926 __iwl4965_down(priv
);
5928 /* tried to restart and config the device for as long as our
5929 * patience could withstand */
5930 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
5935 /*****************************************************************************
5937 * Workqueue callbacks
5939 *****************************************************************************/
5941 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
5943 struct iwl_priv
*priv
=
5944 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
5946 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5949 mutex_lock(&priv
->mutex
);
5950 iwl4965_init_alive_start(priv
);
5951 mutex_unlock(&priv
->mutex
);
5954 static void iwl4965_bg_alive_start(struct work_struct
*data
)
5956 struct iwl_priv
*priv
=
5957 container_of(data
, struct iwl_priv
, alive_start
.work
);
5959 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5962 mutex_lock(&priv
->mutex
);
5963 iwl4965_alive_start(priv
);
5964 mutex_unlock(&priv
->mutex
);
5967 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
5969 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
5971 wake_up_interruptible(&priv
->wait_command_queue
);
5973 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5976 mutex_lock(&priv
->mutex
);
5978 if (!iwl4965_is_rfkill(priv
)) {
5979 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
5980 "HW and/or SW RF Kill no longer active, restarting "
5982 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5983 queue_work(priv
->workqueue
, &priv
->restart
);
5986 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5987 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5988 "disabled by SW switch\n");
5990 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5991 "Kill switch must be turned off for "
5992 "wireless networking to work.\n");
5994 mutex_unlock(&priv
->mutex
);
5997 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5999 static void iwl4965_bg_scan_check(struct work_struct
*data
)
6001 struct iwl_priv
*priv
=
6002 container_of(data
, struct iwl_priv
, scan_check
.work
);
6004 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6007 mutex_lock(&priv
->mutex
);
6008 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
6009 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6010 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
6011 "Scan completion watchdog resetting adapter (%dms)\n",
6012 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
6014 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6015 iwl4965_send_scan_abort(priv
);
6017 mutex_unlock(&priv
->mutex
);
6020 static void iwl4965_bg_request_scan(struct work_struct
*data
)
6022 struct iwl_priv
*priv
=
6023 container_of(data
, struct iwl_priv
, request_scan
);
6024 struct iwl_host_cmd cmd
= {
6025 .id
= REPLY_SCAN_CMD
,
6026 .len
= sizeof(struct iwl4965_scan_cmd
),
6027 .meta
.flags
= CMD_SIZE_HUGE
,
6029 struct iwl4965_scan_cmd
*scan
;
6030 struct ieee80211_conf
*conf
= NULL
;
6032 enum ieee80211_band band
;
6036 conf
= ieee80211_get_hw_conf(priv
->hw
);
6038 mutex_lock(&priv
->mutex
);
6040 if (!iwl4965_is_ready(priv
)) {
6041 IWL_WARNING("request scan called when driver not ready.\n");
6045 /* Make sure the scan wasn't cancelled before this queued work
6046 * was given the chance to run... */
6047 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
6050 /* This should never be called or scheduled if there is currently
6051 * a scan active in the hardware. */
6052 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
6053 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6054 "Ignoring second request.\n");
6059 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6060 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6064 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6065 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6069 if (iwl4965_is_rfkill(priv
)) {
6070 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6074 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6075 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6079 if (!priv
->scan_bands
) {
6080 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6085 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
6086 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
6093 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
6095 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
6096 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
6098 if (iwl4965_is_associated(priv
)) {
6101 u32 suspend_time
= 100;
6102 u32 scan_suspend_time
= 100;
6103 unsigned long flags
;
6105 IWL_DEBUG_INFO("Scanning while associated...\n");
6107 spin_lock_irqsave(&priv
->lock
, flags
);
6108 interval
= priv
->beacon_int
;
6109 spin_unlock_irqrestore(&priv
->lock
, flags
);
6111 scan
->suspend_time
= 0;
6112 scan
->max_out_time
= cpu_to_le32(200 * 1024);
6114 interval
= suspend_time
;
6116 extra
= (suspend_time
/ interval
) << 22;
6117 scan_suspend_time
= (extra
|
6118 ((suspend_time
% interval
) * 1024));
6119 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
6120 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6121 scan_suspend_time
, interval
);
6124 /* We should add the ability for user to lock to PASSIVE ONLY */
6125 if (priv
->one_direct_scan
) {
6127 ("Kicking off one direct scan for '%s'\n",
6128 iwl4965_escape_essid(priv
->direct_ssid
,
6129 priv
->direct_ssid_len
));
6130 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6131 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
6132 memcpy(scan
->direct_scan
[0].ssid
,
6133 priv
->direct_ssid
, priv
->direct_ssid_len
);
6135 } else if (!iwl4965_is_associated(priv
) && priv
->essid_len
) {
6136 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6137 scan
->direct_scan
[0].len
= priv
->essid_len
;
6138 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
6144 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
6145 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
6146 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
6149 switch (priv
->scan_bands
) {
6151 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
6152 scan
->tx_cmd
.rate_n_flags
=
6153 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
6154 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
6156 scan
->good_CRC_th
= 0;
6157 band
= IEEE80211_BAND_2GHZ
;
6161 scan
->tx_cmd
.rate_n_flags
=
6162 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
6163 RATE_MCS_ANT_B_MSK
);
6164 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
6165 band
= IEEE80211_BAND_5GHZ
;
6169 IWL_WARNING("Invalid scan band count\n");
6173 /* We don't build a direct scan probe request; the uCode will do
6174 * that based on the direct_mask added to each channel entry */
6175 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
6176 (struct ieee80211_mgmt
*)scan
->data
,
6177 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
6179 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
6180 /* select Rx chains */
6182 /* Force use of chains B and C (0x6) for scan Rx.
6183 * Avoid A (0x1) because of its off-channel reception on A-band.
6184 * MIMO is not used here, but value is required to make uCode happy. */
6185 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
6186 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
6187 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
6188 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
6190 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
6191 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
6195 ("Initiating direct scan for %s.\n",
6196 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
6197 scan
->channel_count
=
6198 iwl4965_get_channels_for_scan(
6199 priv
, band
, 1, /* active */
6201 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6203 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6204 scan
->channel_count
=
6205 iwl4965_get_channels_for_scan(
6206 priv
, band
, 0, /* passive */
6208 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6211 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
6212 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
6214 scan
->len
= cpu_to_le16(cmd
.len
);
6216 set_bit(STATUS_SCAN_HW
, &priv
->status
);
6217 ret
= iwl_send_cmd_sync(priv
, &cmd
);
6221 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6222 IWL_SCAN_CHECK_WATCHDOG
);
6224 mutex_unlock(&priv
->mutex
);
6228 /* inform mac80211 scan aborted */
6229 queue_work(priv
->workqueue
, &priv
->scan_completed
);
6230 mutex_unlock(&priv
->mutex
);
6233 static void iwl4965_bg_up(struct work_struct
*data
)
6235 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
6237 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6240 mutex_lock(&priv
->mutex
);
6242 mutex_unlock(&priv
->mutex
);
6245 static void iwl4965_bg_restart(struct work_struct
*data
)
6247 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
6249 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6253 queue_work(priv
->workqueue
, &priv
->up
);
6256 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
6258 struct iwl_priv
*priv
=
6259 container_of(data
, struct iwl_priv
, rx_replenish
);
6261 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6264 mutex_lock(&priv
->mutex
);
6265 iwl4965_rx_replenish(priv
);
6266 mutex_unlock(&priv
->mutex
);
6269 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6271 static void iwl4965_bg_post_associate(struct work_struct
*data
)
6273 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
6274 post_associate
.work
);
6275 struct ieee80211_conf
*conf
= NULL
;
6277 DECLARE_MAC_BUF(mac
);
6279 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6280 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
6284 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6286 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
6289 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6292 mutex_lock(&priv
->mutex
);
6294 if (!priv
->vif
|| !priv
->is_open
) {
6295 mutex_unlock(&priv
->mutex
);
6298 iwl4965_scan_cancel_timeout(priv
, 200);
6300 conf
= ieee80211_get_hw_conf(priv
->hw
);
6302 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6303 iwl4965_commit_rxon(priv
);
6305 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6306 iwl4965_setup_rxon_timing(priv
);
6307 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6308 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6310 IWL_WARNING("REPLY_RXON_TIMING failed - "
6311 "Attempting to continue.\n");
6313 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6315 #ifdef CONFIG_IWL4965_HT
6316 if (priv
->current_ht_config
.is_ht
)
6317 iwl4965_set_rxon_ht(priv
, &priv
->current_ht_config
);
6318 #endif /* CONFIG_IWL4965_HT*/
6319 iwl4965_set_rxon_chain(priv
);
6320 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6322 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6323 priv
->assoc_id
, priv
->beacon_int
);
6325 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6326 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6328 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6330 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6331 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6332 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6334 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6336 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6337 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6341 iwl4965_commit_rxon(priv
);
6343 switch (priv
->iw_mode
) {
6344 case IEEE80211_IF_TYPE_STA
:
6345 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6348 case IEEE80211_IF_TYPE_IBSS
:
6350 /* clear out the station table */
6351 iwlcore_clear_stations_table(priv
);
6353 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6354 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
6355 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6356 iwl4965_send_beacon_cmd(priv
);
6361 IWL_ERROR("%s Should not be called in %d mode\n",
6362 __FUNCTION__
, priv
->iw_mode
);
6366 iwl4965_sequence_reset(priv
);
6368 #ifdef CONFIG_IWL4965_SENSITIVITY
6369 /* Enable Rx differential gain and sensitivity calibrations */
6370 iwl4965_chain_noise_reset(priv
);
6371 priv
->start_calib
= 1;
6372 #endif /* CONFIG_IWL4965_SENSITIVITY */
6374 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6375 priv
->assoc_station_added
= 1;
6377 iwl4965_activate_qos(priv
, 0);
6379 /* we have just associated, don't start scan too early */
6380 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6381 mutex_unlock(&priv
->mutex
);
6384 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
6386 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
6388 if (!iwl4965_is_ready(priv
))
6391 mutex_lock(&priv
->mutex
);
6393 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6394 iwl4965_send_scan_abort(priv
);
6396 mutex_unlock(&priv
->mutex
);
6399 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
6401 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
6403 struct iwl_priv
*priv
=
6404 container_of(work
, struct iwl_priv
, scan_completed
);
6406 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6408 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6411 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6412 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
6414 ieee80211_scan_completed(priv
->hw
);
6416 /* Since setting the TXPOWER may have been deferred while
6417 * performing the scan, fire one off */
6418 mutex_lock(&priv
->mutex
);
6419 iwl4965_hw_reg_send_txpower(priv
);
6420 mutex_unlock(&priv
->mutex
);
6423 /*****************************************************************************
6425 * mac80211 entry point functions
6427 *****************************************************************************/
6429 #define UCODE_READY_TIMEOUT (2 * HZ)
6431 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
6433 struct iwl_priv
*priv
= hw
->priv
;
6436 IWL_DEBUG_MAC80211("enter\n");
6438 if (pci_enable_device(priv
->pci_dev
)) {
6439 IWL_ERROR("Fail to pci_enable_device\n");
6442 pci_restore_state(priv
->pci_dev
);
6443 pci_enable_msi(priv
->pci_dev
);
6445 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
6448 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6449 goto out_disable_msi
;
6452 /* we should be verifying the device is ready to be opened */
6453 mutex_lock(&priv
->mutex
);
6455 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
6456 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6457 * ucode filename and max sizes are card-specific. */
6459 if (!priv
->ucode_code
.len
) {
6460 ret
= iwl4965_read_ucode(priv
);
6462 IWL_ERROR("Could not read microcode: %d\n", ret
);
6463 mutex_unlock(&priv
->mutex
);
6464 goto out_release_irq
;
6468 ret
= __iwl4965_up(priv
);
6470 mutex_unlock(&priv
->mutex
);
6473 goto out_release_irq
;
6475 IWL_DEBUG_INFO("Start UP work done.\n");
6477 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6480 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6481 * mac80211 will not be run successfully. */
6482 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6483 test_bit(STATUS_READY
, &priv
->status
),
6484 UCODE_READY_TIMEOUT
);
6486 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6487 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6488 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6490 goto out_release_irq
;
6495 IWL_DEBUG_MAC80211("leave\n");
6499 free_irq(priv
->pci_dev
->irq
, priv
);
6501 pci_disable_msi(priv
->pci_dev
);
6502 pci_disable_device(priv
->pci_dev
);
6504 IWL_DEBUG_MAC80211("leave - failed\n");
6508 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
6510 struct iwl_priv
*priv
= hw
->priv
;
6512 IWL_DEBUG_MAC80211("enter\n");
6514 if (!priv
->is_open
) {
6515 IWL_DEBUG_MAC80211("leave - skip\n");
6521 if (iwl4965_is_ready_rf(priv
)) {
6522 /* stop mac, cancel any scan request and clear
6523 * RXON_FILTER_ASSOC_MSK BIT
6525 mutex_lock(&priv
->mutex
);
6526 iwl4965_scan_cancel_timeout(priv
, 100);
6527 cancel_delayed_work(&priv
->post_associate
);
6528 mutex_unlock(&priv
->mutex
);
6533 flush_workqueue(priv
->workqueue
);
6534 free_irq(priv
->pci_dev
->irq
, priv
);
6535 pci_disable_msi(priv
->pci_dev
);
6536 pci_save_state(priv
->pci_dev
);
6537 pci_disable_device(priv
->pci_dev
);
6539 IWL_DEBUG_MAC80211("leave\n");
6542 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6543 struct ieee80211_tx_control
*ctl
)
6545 struct iwl_priv
*priv
= hw
->priv
;
6547 IWL_DEBUG_MAC80211("enter\n");
6549 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
6550 IWL_DEBUG_MAC80211("leave - monitor\n");
6554 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6555 ctl
->tx_rate
->bitrate
);
6557 if (iwl4965_tx_skb(priv
, skb
, ctl
))
6558 dev_kfree_skb_any(skb
);
6560 IWL_DEBUG_MAC80211("leave\n");
6564 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
6565 struct ieee80211_if_init_conf
*conf
)
6567 struct iwl_priv
*priv
= hw
->priv
;
6568 unsigned long flags
;
6569 DECLARE_MAC_BUF(mac
);
6571 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6574 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6578 spin_lock_irqsave(&priv
->lock
, flags
);
6579 priv
->vif
= conf
->vif
;
6581 spin_unlock_irqrestore(&priv
->lock
, flags
);
6583 mutex_lock(&priv
->mutex
);
6585 if (conf
->mac_addr
) {
6586 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
6587 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6590 if (iwl4965_is_ready(priv
))
6591 iwl4965_set_mode(priv
, conf
->type
);
6593 mutex_unlock(&priv
->mutex
);
6595 IWL_DEBUG_MAC80211("leave\n");
6600 * iwl4965_mac_config - mac80211 config callback
6602 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6603 * be set inappropriately and the driver currently sets the hardware up to
6604 * use it whenever needed.
6606 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6608 struct iwl_priv
*priv
= hw
->priv
;
6609 const struct iwl_channel_info
*ch_info
;
6610 unsigned long flags
;
6613 mutex_lock(&priv
->mutex
);
6614 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6616 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
6618 if (!iwl4965_is_ready(priv
)) {
6619 IWL_DEBUG_MAC80211("leave - not ready\n");
6624 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
6625 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6626 IWL_DEBUG_MAC80211("leave - scanning\n");
6627 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6628 mutex_unlock(&priv
->mutex
);
6632 spin_lock_irqsave(&priv
->lock
, flags
);
6634 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
,
6635 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6636 if (!is_channel_valid(ch_info
)) {
6637 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6638 spin_unlock_irqrestore(&priv
->lock
, flags
);
6643 #ifdef CONFIG_IWL4965_HT
6644 /* if we are switching from ht to 2.4 clear flags
6645 * from any ht related info since 2.4 does not
6647 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
->hw_value
)
6648 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6649 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
6652 priv
->staging_rxon
.flags
= 0;
6653 #endif /* CONFIG_IWL4965_HT */
6655 iwlcore_set_rxon_channel(priv
, conf
->channel
->band
,
6656 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6658 iwl4965_set_flags_for_phymode(priv
, conf
->channel
->band
);
6660 /* The list of supported rates and rate mask can be different
6661 * for each band; since the band may have changed, reset
6662 * the rate mask to what mac80211 lists */
6663 iwl4965_set_rate(priv
);
6665 spin_unlock_irqrestore(&priv
->lock
, flags
);
6667 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6668 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6669 iwl4965_hw_channel_switch(priv
, conf
->channel
);
6674 iwl4965_radio_kill_sw(priv
, !conf
->radio_enabled
);
6676 if (!conf
->radio_enabled
) {
6677 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6681 if (iwl4965_is_rfkill(priv
)) {
6682 IWL_DEBUG_MAC80211("leave - RF kill\n");
6687 iwl4965_set_rate(priv
);
6689 if (memcmp(&priv
->active_rxon
,
6690 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
6691 iwl4965_commit_rxon(priv
);
6693 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6695 IWL_DEBUG_MAC80211("leave\n");
6698 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6699 mutex_unlock(&priv
->mutex
);
6703 static void iwl4965_config_ap(struct iwl_priv
*priv
)
6707 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6710 /* The following should be done only at AP bring up */
6711 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
6713 /* RXON - unassoc (to set timing command) */
6714 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6715 iwl4965_commit_rxon(priv
);
6718 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6719 iwl4965_setup_rxon_timing(priv
);
6720 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6721 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6723 IWL_WARNING("REPLY_RXON_TIMING failed - "
6724 "Attempting to continue.\n");
6726 iwl4965_set_rxon_chain(priv
);
6728 /* FIXME: what should be the assoc_id for AP? */
6729 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6730 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6731 priv
->staging_rxon
.flags
|=
6732 RXON_FLG_SHORT_PREAMBLE_MSK
;
6734 priv
->staging_rxon
.flags
&=
6735 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6737 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6738 if (priv
->assoc_capability
&
6739 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6740 priv
->staging_rxon
.flags
|=
6741 RXON_FLG_SHORT_SLOT_MSK
;
6743 priv
->staging_rxon
.flags
&=
6744 ~RXON_FLG_SHORT_SLOT_MSK
;
6746 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6747 priv
->staging_rxon
.flags
&=
6748 ~RXON_FLG_SHORT_SLOT_MSK
;
6750 /* restore RXON assoc */
6751 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6752 iwl4965_commit_rxon(priv
);
6753 iwl4965_activate_qos(priv
, 1);
6754 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6756 iwl4965_send_beacon_cmd(priv
);
6758 /* FIXME - we need to add code here to detect a totally new
6759 * configuration, reset the AP, unassoc, rxon timing, assoc,
6760 * clear sta table, add BCAST sta... */
6763 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
6764 struct ieee80211_vif
*vif
,
6765 struct ieee80211_if_conf
*conf
)
6767 struct iwl_priv
*priv
= hw
->priv
;
6768 DECLARE_MAC_BUF(mac
);
6769 unsigned long flags
;
6775 if (priv
->vif
!= vif
) {
6776 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6777 mutex_unlock(&priv
->mutex
);
6781 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
6782 (!conf
->beacon
|| !conf
->ssid_len
)) {
6784 ("Leaving in AP mode because HostAPD is not ready.\n");
6788 if (!iwl4965_is_alive(priv
))
6791 mutex_lock(&priv
->mutex
);
6794 IWL_DEBUG_MAC80211("bssid: %s\n",
6795 print_mac(mac
, conf
->bssid
));
6798 * very dubious code was here; the probe filtering flag is never set:
6800 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6801 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6804 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6806 conf
->bssid
= priv
->mac_addr
;
6807 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6808 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6809 print_mac(mac
, conf
->bssid
));
6811 if (priv
->ibss_beacon
)
6812 dev_kfree_skb(priv
->ibss_beacon
);
6814 priv
->ibss_beacon
= conf
->beacon
;
6817 if (iwl4965_is_rfkill(priv
))
6820 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6821 !is_multicast_ether_addr(conf
->bssid
)) {
6822 /* If there is currently a HW scan going on in the background
6823 * then we need to cancel it else the RXON below will fail. */
6824 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
6825 IWL_WARNING("Aborted scan still in progress "
6827 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6828 mutex_unlock(&priv
->mutex
);
6831 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6833 /* TODO: Audit driver for usage of these members and see
6834 * if mac80211 deprecates them (priv->bssid looks like it
6835 * shouldn't be there, but I haven't scanned the IBSS code
6836 * to verify) - jpk */
6837 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6839 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6840 iwl4965_config_ap(priv
);
6842 rc
= iwl4965_commit_rxon(priv
);
6843 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
6844 iwl4965_rxon_add_station(
6845 priv
, priv
->active_rxon
.bssid_addr
, 1);
6849 iwl4965_scan_cancel_timeout(priv
, 100);
6850 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6851 iwl4965_commit_rxon(priv
);
6855 spin_lock_irqsave(&priv
->lock
, flags
);
6856 if (!conf
->ssid_len
)
6857 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6859 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
6861 priv
->essid_len
= conf
->ssid_len
;
6862 spin_unlock_irqrestore(&priv
->lock
, flags
);
6864 IWL_DEBUG_MAC80211("leave\n");
6865 mutex_unlock(&priv
->mutex
);
6870 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
6871 unsigned int changed_flags
,
6872 unsigned int *total_flags
,
6873 int mc_count
, struct dev_addr_list
*mc_list
)
6877 * see also iwl4965_connection_init_rx_config
6882 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
6883 struct ieee80211_if_init_conf
*conf
)
6885 struct iwl_priv
*priv
= hw
->priv
;
6887 IWL_DEBUG_MAC80211("enter\n");
6889 mutex_lock(&priv
->mutex
);
6891 if (iwl4965_is_ready_rf(priv
)) {
6892 iwl4965_scan_cancel_timeout(priv
, 100);
6893 cancel_delayed_work(&priv
->post_associate
);
6894 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6895 iwl4965_commit_rxon(priv
);
6897 if (priv
->vif
== conf
->vif
) {
6899 memset(priv
->bssid
, 0, ETH_ALEN
);
6900 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6901 priv
->essid_len
= 0;
6903 mutex_unlock(&priv
->mutex
);
6905 IWL_DEBUG_MAC80211("leave\n");
6909 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
6910 struct ieee80211_vif
*vif
,
6911 struct ieee80211_bss_conf
*bss_conf
,
6914 struct iwl_priv
*priv
= hw
->priv
;
6916 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
6917 if (bss_conf
->use_short_preamble
)
6918 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6920 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6923 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
6924 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
6925 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
6927 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
6930 if (changes
& BSS_CHANGED_ASSOC
) {
6933 * do stuff instead of sniffing assoc resp
6937 if (iwl4965_is_associated(priv
))
6938 iwl4965_send_rxon_assoc(priv
);
6941 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6944 unsigned long flags
;
6945 struct iwl_priv
*priv
= hw
->priv
;
6947 IWL_DEBUG_MAC80211("enter\n");
6949 mutex_lock(&priv
->mutex
);
6950 spin_lock_irqsave(&priv
->lock
, flags
);
6952 if (!iwl4965_is_ready_rf(priv
)) {
6954 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6958 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
6960 IWL_ERROR("ERROR: APs don't scan\n");
6964 /* we don't schedule scan within next_scan_jiffies period */
6965 if (priv
->next_scan_jiffies
&&
6966 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6970 /* if we just finished scan ask for delay */
6971 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
6972 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
6977 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6978 iwl4965_escape_essid(ssid
, len
), (int)len
);
6980 priv
->one_direct_scan
= 1;
6981 priv
->direct_ssid_len
= (u8
)
6982 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6983 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6985 priv
->one_direct_scan
= 0;
6987 rc
= iwl4965_scan_initiate(priv
);
6989 IWL_DEBUG_MAC80211("leave\n");
6992 spin_unlock_irqrestore(&priv
->lock
, flags
);
6993 mutex_unlock(&priv
->mutex
);
6998 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
6999 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
7000 u32 iv32
, u16
*phase1key
)
7002 struct iwl_priv
*priv
= hw
->priv
;
7003 u8 sta_id
= IWL_INVALID_STATION
;
7004 unsigned long flags
;
7005 __le16 key_flags
= 0;
7007 DECLARE_MAC_BUF(mac
);
7009 IWL_DEBUG_MAC80211("enter\n");
7011 sta_id
= iwl4965_hw_find_station(priv
, addr
);
7012 if (sta_id
== IWL_INVALID_STATION
) {
7013 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7014 print_mac(mac
, addr
));
7018 iwl4965_scan_cancel_timeout(priv
, 100);
7020 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
7021 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
7022 key_flags
&= ~STA_KEY_FLG_INVALID
;
7024 if (sta_id
== priv
->hw_setting
.bcast_sta_id
)
7025 key_flags
|= STA_KEY_MULTICAST_MSK
;
7027 spin_lock_irqsave(&priv
->sta_lock
, flags
);
7029 priv
->stations
[sta_id
].sta
.key
.key_offset
=
7030 (sta_id
% STA_KEY_MAX_NUM
);/* FIXME */
7031 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
7032 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
7034 for (i
= 0; i
< 5; i
++)
7035 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
7036 cpu_to_le16(phase1key
[i
]);
7038 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
7039 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
7041 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
7043 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
7045 IWL_DEBUG_MAC80211("leave\n");
7048 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
7049 const u8
*local_addr
, const u8
*addr
,
7050 struct ieee80211_key_conf
*key
)
7052 struct iwl_priv
*priv
= hw
->priv
;
7053 DECLARE_MAC_BUF(mac
);
7055 u8 sta_id
= IWL_INVALID_STATION
;
7058 IWL_DEBUG_MAC80211("enter\n");
7060 if (!priv
->cfg
->mod_params
->hw_crypto
) {
7061 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7065 if (is_zero_ether_addr(addr
))
7066 /* only support pairwise keys */
7069 /* FIXME: need to differenciate between static and dynamic key
7070 * in the level of mac80211 */
7071 static_key
= !iwl4965_is_associated(priv
);
7074 sta_id
= iwl4965_hw_find_station(priv
, addr
);
7075 if (sta_id
== IWL_INVALID_STATION
) {
7076 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7077 print_mac(mac
, addr
));
7082 iwl4965_scan_cancel_timeout(priv
, 100);
7087 ret
= iwl4965_set_static_key(priv
, key
);
7089 ret
= iwl4965_set_dynamic_key(priv
, key
, sta_id
);
7091 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
7095 ret
= iwl4965_remove_static_key(priv
);
7097 ret
= iwl4965_clear_sta_key_info(priv
, sta_id
);
7099 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7105 IWL_DEBUG_MAC80211("leave\n");
7110 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
7111 const struct ieee80211_tx_queue_params
*params
)
7113 struct iwl_priv
*priv
= hw
->priv
;
7114 unsigned long flags
;
7117 IWL_DEBUG_MAC80211("enter\n");
7119 if (!iwl4965_is_ready_rf(priv
)) {
7120 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7124 if (queue
>= AC_NUM
) {
7125 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7129 if (!priv
->qos_data
.qos_enable
) {
7130 priv
->qos_data
.qos_active
= 0;
7131 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7134 q
= AC_NUM
- 1 - queue
;
7136 spin_lock_irqsave(&priv
->lock
, flags
);
7138 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
7139 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
7140 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
7141 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
7142 cpu_to_le16((params
->txop
* 32));
7144 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
7145 priv
->qos_data
.qos_active
= 1;
7147 spin_unlock_irqrestore(&priv
->lock
, flags
);
7149 mutex_lock(&priv
->mutex
);
7150 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7151 iwl4965_activate_qos(priv
, 1);
7152 else if (priv
->assoc_id
&& iwl4965_is_associated(priv
))
7153 iwl4965_activate_qos(priv
, 0);
7155 mutex_unlock(&priv
->mutex
);
7157 IWL_DEBUG_MAC80211("leave\n");
7161 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7162 struct ieee80211_tx_queue_stats
*stats
)
7164 struct iwl_priv
*priv
= hw
->priv
;
7166 struct iwl4965_tx_queue
*txq
;
7167 struct iwl4965_queue
*q
;
7168 unsigned long flags
;
7170 IWL_DEBUG_MAC80211("enter\n");
7172 if (!iwl4965_is_ready_rf(priv
)) {
7173 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7177 spin_lock_irqsave(&priv
->lock
, flags
);
7179 for (i
= 0; i
< AC_NUM
; i
++) {
7180 txq
= &priv
->txq
[i
];
7182 avail
= iwl4965_queue_space(q
);
7184 stats
->data
[i
].len
= q
->n_window
- avail
;
7185 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
7186 stats
->data
[i
].count
= q
->n_window
;
7189 spin_unlock_irqrestore(&priv
->lock
, flags
);
7191 IWL_DEBUG_MAC80211("leave\n");
7196 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
7197 struct ieee80211_low_level_stats
*stats
)
7199 IWL_DEBUG_MAC80211("enter\n");
7200 IWL_DEBUG_MAC80211("leave\n");
7205 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
7207 IWL_DEBUG_MAC80211("enter\n");
7208 IWL_DEBUG_MAC80211("leave\n");
7213 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
7215 struct iwl_priv
*priv
= hw
->priv
;
7216 unsigned long flags
;
7218 mutex_lock(&priv
->mutex
);
7219 IWL_DEBUG_MAC80211("enter\n");
7221 priv
->lq_mngr
.lq_ready
= 0;
7222 #ifdef CONFIG_IWL4965_HT
7223 spin_lock_irqsave(&priv
->lock
, flags
);
7224 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
7225 spin_unlock_irqrestore(&priv
->lock
, flags
);
7226 #endif /* CONFIG_IWL4965_HT */
7228 iwlcore_reset_qos(priv
);
7230 cancel_delayed_work(&priv
->post_associate
);
7232 spin_lock_irqsave(&priv
->lock
, flags
);
7234 priv
->assoc_capability
= 0;
7235 priv
->call_post_assoc_from_beacon
= 0;
7236 priv
->assoc_station_added
= 0;
7238 /* new association get rid of ibss beacon skb */
7239 if (priv
->ibss_beacon
)
7240 dev_kfree_skb(priv
->ibss_beacon
);
7242 priv
->ibss_beacon
= NULL
;
7244 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7245 priv
->timestamp1
= 0;
7246 priv
->timestamp0
= 0;
7247 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7248 priv
->beacon_int
= 0;
7250 spin_unlock_irqrestore(&priv
->lock
, flags
);
7252 if (!iwl4965_is_ready_rf(priv
)) {
7253 IWL_DEBUG_MAC80211("leave - not ready\n");
7254 mutex_unlock(&priv
->mutex
);
7258 /* we are restarting association process
7259 * clear RXON_FILTER_ASSOC_MSK bit
7261 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7262 iwl4965_scan_cancel_timeout(priv
, 100);
7263 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7264 iwl4965_commit_rxon(priv
);
7267 /* Per mac80211.h: This is only used in IBSS mode... */
7268 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7270 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7271 mutex_unlock(&priv
->mutex
);
7275 priv
->only_active_channel
= 0;
7277 iwl4965_set_rate(priv
);
7279 mutex_unlock(&priv
->mutex
);
7281 IWL_DEBUG_MAC80211("leave\n");
7284 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7285 struct ieee80211_tx_control
*control
)
7287 struct iwl_priv
*priv
= hw
->priv
;
7288 unsigned long flags
;
7290 mutex_lock(&priv
->mutex
);
7291 IWL_DEBUG_MAC80211("enter\n");
7293 if (!iwl4965_is_ready_rf(priv
)) {
7294 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7295 mutex_unlock(&priv
->mutex
);
7299 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7300 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7301 mutex_unlock(&priv
->mutex
);
7305 spin_lock_irqsave(&priv
->lock
, flags
);
7307 if (priv
->ibss_beacon
)
7308 dev_kfree_skb(priv
->ibss_beacon
);
7310 priv
->ibss_beacon
= skb
;
7314 IWL_DEBUG_MAC80211("leave\n");
7315 spin_unlock_irqrestore(&priv
->lock
, flags
);
7317 iwlcore_reset_qos(priv
);
7319 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7321 mutex_unlock(&priv
->mutex
);
7326 #ifdef CONFIG_IWL4965_HT
7328 static void iwl4965_ht_info_fill(struct ieee80211_conf
*conf
,
7329 struct iwl_priv
*priv
)
7331 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
7332 struct ieee80211_ht_info
*ht_conf
= &conf
->ht_conf
;
7333 struct ieee80211_ht_bss_info
*ht_bss_conf
= &conf
->ht_bss_conf
;
7335 IWL_DEBUG_MAC80211("enter: \n");
7337 if (!(conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
)) {
7338 iwl_conf
->is_ht
= 0;
7342 iwl_conf
->is_ht
= 1;
7343 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
7345 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
7346 iwl_conf
->sgf
|= 0x1;
7347 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
7348 iwl_conf
->sgf
|= 0x2;
7350 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
7351 iwl_conf
->max_amsdu_size
=
7352 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
7354 iwl_conf
->supported_chan_width
=
7355 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
7356 iwl_conf
->extension_chan_offset
=
7357 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
7358 /* If no above or below channel supplied disable FAT channel */
7359 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
7360 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
7361 iwl_conf
->supported_chan_width
= 0;
7363 iwl_conf
->tx_mimo_ps_mode
=
7364 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
7365 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
7367 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
7368 iwl_conf
->tx_chan_width
=
7369 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
7370 iwl_conf
->ht_protection
=
7371 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
7372 iwl_conf
->non_GF_STA_present
=
7373 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
7375 IWL_DEBUG_MAC80211("control channel %d\n",
7376 iwl_conf
->control_channel
);
7377 IWL_DEBUG_MAC80211("leave\n");
7380 static int iwl4965_mac_conf_ht(struct ieee80211_hw
*hw
,
7381 struct ieee80211_conf
*conf
)
7383 struct iwl_priv
*priv
= hw
->priv
;
7385 IWL_DEBUG_MAC80211("enter: \n");
7387 iwl4965_ht_info_fill(conf
, priv
);
7388 iwl4965_set_rxon_chain(priv
);
7390 if (priv
&& priv
->assoc_id
&&
7391 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
7392 unsigned long flags
;
7394 spin_lock_irqsave(&priv
->lock
, flags
);
7395 if (priv
->beacon_int
)
7396 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7398 priv
->call_post_assoc_from_beacon
= 1;
7399 spin_unlock_irqrestore(&priv
->lock
, flags
);
7402 IWL_DEBUG_MAC80211("leave:\n");
7406 #endif /*CONFIG_IWL4965_HT*/
7408 /*****************************************************************************
7412 *****************************************************************************/
7414 #ifdef CONFIG_IWLWIFI_DEBUG
7417 * The following adds a new attribute to the sysfs representation
7418 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7419 * used for controlling the debug level.
7421 * See the level definitions in iwl for details.
7424 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7426 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
7428 static ssize_t
store_debug_level(struct device_driver
*d
,
7429 const char *buf
, size_t count
)
7431 char *p
= (char *)buf
;
7434 val
= simple_strtoul(p
, &p
, 0);
7436 printk(KERN_INFO DRV_NAME
7437 ": %s is not in hex or decimal form.\n", buf
);
7439 iwl_debug_level
= val
;
7441 return strnlen(buf
, count
);
7444 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7445 show_debug_level
, store_debug_level
);
7447 #endif /* CONFIG_IWLWIFI_DEBUG */
7449 static ssize_t
show_rf_kill(struct device
*d
,
7450 struct device_attribute
*attr
, char *buf
)
7453 * 0 - RF kill not enabled
7454 * 1 - SW based RF kill active (sysfs)
7455 * 2 - HW based RF kill active
7456 * 3 - Both HW and SW based RF kill active
7458 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7459 int val
= (test_bit(STATUS_RF_KILL_SW
, &priv
->status
) ? 0x1 : 0x0) |
7460 (test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ? 0x2 : 0x0);
7462 return sprintf(buf
, "%i\n", val
);
7465 static ssize_t
store_rf_kill(struct device
*d
,
7466 struct device_attribute
*attr
,
7467 const char *buf
, size_t count
)
7469 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7471 mutex_lock(&priv
->mutex
);
7472 iwl4965_radio_kill_sw(priv
, buf
[0] == '1');
7473 mutex_unlock(&priv
->mutex
);
7478 static DEVICE_ATTR(rf_kill
, S_IWUSR
| S_IRUGO
, show_rf_kill
, store_rf_kill
);
7480 static ssize_t
show_temperature(struct device
*d
,
7481 struct device_attribute
*attr
, char *buf
)
7483 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7485 if (!iwl4965_is_alive(priv
))
7488 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
7491 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7493 static ssize_t
show_rs_window(struct device
*d
,
7494 struct device_attribute
*attr
,
7497 struct iwl_priv
*priv
= d
->driver_data
;
7498 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7500 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7502 static ssize_t
show_tx_power(struct device
*d
,
7503 struct device_attribute
*attr
, char *buf
)
7505 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7506 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7509 static ssize_t
store_tx_power(struct device
*d
,
7510 struct device_attribute
*attr
,
7511 const char *buf
, size_t count
)
7513 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7514 char *p
= (char *)buf
;
7517 val
= simple_strtoul(p
, &p
, 10);
7519 printk(KERN_INFO DRV_NAME
7520 ": %s is not in decimal form.\n", buf
);
7522 iwl4965_hw_reg_set_txpower(priv
, val
);
7527 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7529 static ssize_t
show_flags(struct device
*d
,
7530 struct device_attribute
*attr
, char *buf
)
7532 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7534 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7537 static ssize_t
store_flags(struct device
*d
,
7538 struct device_attribute
*attr
,
7539 const char *buf
, size_t count
)
7541 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7542 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7544 mutex_lock(&priv
->mutex
);
7545 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7546 /* Cancel any currently running scans... */
7547 if (iwl4965_scan_cancel_timeout(priv
, 100))
7548 IWL_WARNING("Could not cancel scan.\n");
7550 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7552 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7553 iwl4965_commit_rxon(priv
);
7556 mutex_unlock(&priv
->mutex
);
7561 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7563 static ssize_t
show_filter_flags(struct device
*d
,
7564 struct device_attribute
*attr
, char *buf
)
7566 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7568 return sprintf(buf
, "0x%04X\n",
7569 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7572 static ssize_t
store_filter_flags(struct device
*d
,
7573 struct device_attribute
*attr
,
7574 const char *buf
, size_t count
)
7576 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7577 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7579 mutex_lock(&priv
->mutex
);
7580 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7581 /* Cancel any currently running scans... */
7582 if (iwl4965_scan_cancel_timeout(priv
, 100))
7583 IWL_WARNING("Could not cancel scan.\n");
7585 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7586 "0x%04X\n", filter_flags
);
7587 priv
->staging_rxon
.filter_flags
=
7588 cpu_to_le32(filter_flags
);
7589 iwl4965_commit_rxon(priv
);
7592 mutex_unlock(&priv
->mutex
);
7597 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7598 store_filter_flags
);
7600 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7602 static ssize_t
show_measurement(struct device
*d
,
7603 struct device_attribute
*attr
, char *buf
)
7605 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7606 struct iwl4965_spectrum_notification measure_report
;
7607 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7608 u8
*data
= (u8
*) & measure_report
;
7609 unsigned long flags
;
7611 spin_lock_irqsave(&priv
->lock
, flags
);
7612 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7613 spin_unlock_irqrestore(&priv
->lock
, flags
);
7616 memcpy(&measure_report
, &priv
->measure_report
, size
);
7617 priv
->measurement_status
= 0;
7618 spin_unlock_irqrestore(&priv
->lock
, flags
);
7620 while (size
&& (PAGE_SIZE
- len
)) {
7621 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7622 PAGE_SIZE
- len
, 1);
7624 if (PAGE_SIZE
- len
)
7628 size
-= min(size
, 16U);
7634 static ssize_t
store_measurement(struct device
*d
,
7635 struct device_attribute
*attr
,
7636 const char *buf
, size_t count
)
7638 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7639 struct ieee80211_measurement_params params
= {
7640 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7641 .start_time
= cpu_to_le64(priv
->last_tsf
),
7642 .duration
= cpu_to_le16(1),
7644 u8 type
= IWL_MEASURE_BASIC
;
7650 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7651 channel
= simple_strtoul(p
, NULL
, 0);
7653 params
.channel
= channel
;
7656 while (*p
&& *p
!= ' ')
7659 type
= simple_strtoul(p
+ 1, NULL
, 0);
7662 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7663 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7664 iwl4965_get_measurement(priv
, ¶ms
, type
);
7669 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7670 show_measurement
, store_measurement
);
7671 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
7673 static ssize_t
store_retry_rate(struct device
*d
,
7674 struct device_attribute
*attr
,
7675 const char *buf
, size_t count
)
7677 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7679 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7680 if (priv
->retry_rate
<= 0)
7681 priv
->retry_rate
= 1;
7686 static ssize_t
show_retry_rate(struct device
*d
,
7687 struct device_attribute
*attr
, char *buf
)
7689 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7690 return sprintf(buf
, "%d", priv
->retry_rate
);
7693 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7696 static ssize_t
store_power_level(struct device
*d
,
7697 struct device_attribute
*attr
,
7698 const char *buf
, size_t count
)
7700 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7704 mode
= simple_strtoul(buf
, NULL
, 0);
7705 mutex_lock(&priv
->mutex
);
7707 if (!iwl4965_is_ready(priv
)) {
7712 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7713 mode
= IWL_POWER_AC
;
7715 mode
|= IWL_POWER_ENABLED
;
7717 if (mode
!= priv
->power_mode
) {
7718 rc
= iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7720 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7723 priv
->power_mode
= mode
;
7729 mutex_unlock(&priv
->mutex
);
7733 #define MAX_WX_STRING 80
7735 /* Values are in microsecond */
7736 static const s32 timeout_duration
[] = {
7743 static const s32 period_duration
[] = {
7751 static ssize_t
show_power_level(struct device
*d
,
7752 struct device_attribute
*attr
, char *buf
)
7754 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7755 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7758 p
+= sprintf(p
, "%d ", level
);
7760 case IWL_POWER_MODE_CAM
:
7762 p
+= sprintf(p
, "(AC)");
7764 case IWL_POWER_BATTERY
:
7765 p
+= sprintf(p
, "(BATTERY)");
7769 "(Timeout %dms, Period %dms)",
7770 timeout_duration
[level
- 1] / 1000,
7771 period_duration
[level
- 1] / 1000);
7774 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7775 p
+= sprintf(p
, " OFF\n");
7777 p
+= sprintf(p
, " \n");
7779 return (p
- buf
+ 1);
7783 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7786 static ssize_t
show_channels(struct device
*d
,
7787 struct device_attribute
*attr
, char *buf
)
7789 /* all this shit doesn't belong into sysfs anyway */
7793 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7795 static ssize_t
show_statistics(struct device
*d
,
7796 struct device_attribute
*attr
, char *buf
)
7798 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7799 u32 size
= sizeof(struct iwl4965_notif_statistics
);
7800 u32 len
= 0, ofs
= 0;
7801 u8
*data
= (u8
*) & priv
->statistics
;
7804 if (!iwl4965_is_alive(priv
))
7807 mutex_lock(&priv
->mutex
);
7808 rc
= iwl4965_send_statistics_request(priv
);
7809 mutex_unlock(&priv
->mutex
);
7813 "Error sending statistics request: 0x%08X\n", rc
);
7817 while (size
&& (PAGE_SIZE
- len
)) {
7818 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7819 PAGE_SIZE
- len
, 1);
7821 if (PAGE_SIZE
- len
)
7825 size
-= min(size
, 16U);
7831 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7833 static ssize_t
show_antenna(struct device
*d
,
7834 struct device_attribute
*attr
, char *buf
)
7836 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7838 if (!iwl4965_is_alive(priv
))
7841 return sprintf(buf
, "%d\n", priv
->antenna
);
7844 static ssize_t
store_antenna(struct device
*d
,
7845 struct device_attribute
*attr
,
7846 const char *buf
, size_t count
)
7849 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7854 if (sscanf(buf
, "%1i", &ant
) != 1) {
7855 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7859 if ((ant
>= 0) && (ant
<= 2)) {
7860 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7861 priv
->antenna
= (enum iwl4965_antenna
)ant
;
7863 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7869 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7871 static ssize_t
show_status(struct device
*d
,
7872 struct device_attribute
*attr
, char *buf
)
7874 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7875 if (!iwl4965_is_alive(priv
))
7877 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7880 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7882 static ssize_t
dump_error_log(struct device
*d
,
7883 struct device_attribute
*attr
,
7884 const char *buf
, size_t count
)
7886 char *p
= (char *)buf
;
7889 iwl4965_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
7891 return strnlen(buf
, count
);
7894 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7896 static ssize_t
dump_event_log(struct device
*d
,
7897 struct device_attribute
*attr
,
7898 const char *buf
, size_t count
)
7900 char *p
= (char *)buf
;
7903 iwl4965_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
7905 return strnlen(buf
, count
);
7908 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7910 /*****************************************************************************
7912 * driver setup and teardown
7914 *****************************************************************************/
7916 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
7918 priv
->workqueue
= create_workqueue(DRV_NAME
);
7920 init_waitqueue_head(&priv
->wait_command_queue
);
7922 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
7923 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
7924 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
7925 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
7926 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
7927 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
7928 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
7929 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
7930 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
7931 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
7932 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
7933 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
7935 iwl4965_hw_setup_deferred_work(priv
);
7937 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7938 iwl4965_irq_tasklet
, (unsigned long)priv
);
7941 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
7943 iwl4965_hw_cancel_deferred_work(priv
);
7945 cancel_delayed_work_sync(&priv
->init_alive_start
);
7946 cancel_delayed_work(&priv
->scan_check
);
7947 cancel_delayed_work(&priv
->alive_start
);
7948 cancel_delayed_work(&priv
->post_associate
);
7949 cancel_work_sync(&priv
->beacon_update
);
7952 static struct attribute
*iwl4965_sysfs_entries
[] = {
7953 &dev_attr_antenna
.attr
,
7954 &dev_attr_channels
.attr
,
7955 &dev_attr_dump_errors
.attr
,
7956 &dev_attr_dump_events
.attr
,
7957 &dev_attr_flags
.attr
,
7958 &dev_attr_filter_flags
.attr
,
7959 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7960 &dev_attr_measurement
.attr
,
7962 &dev_attr_power_level
.attr
,
7963 &dev_attr_retry_rate
.attr
,
7964 &dev_attr_rf_kill
.attr
,
7965 &dev_attr_rs_window
.attr
,
7966 &dev_attr_statistics
.attr
,
7967 &dev_attr_status
.attr
,
7968 &dev_attr_temperature
.attr
,
7969 &dev_attr_tx_power
.attr
,
7974 static struct attribute_group iwl4965_attribute_group
= {
7975 .name
= NULL
, /* put in device directory */
7976 .attrs
= iwl4965_sysfs_entries
,
7979 static struct ieee80211_ops iwl4965_hw_ops
= {
7980 .tx
= iwl4965_mac_tx
,
7981 .start
= iwl4965_mac_start
,
7982 .stop
= iwl4965_mac_stop
,
7983 .add_interface
= iwl4965_mac_add_interface
,
7984 .remove_interface
= iwl4965_mac_remove_interface
,
7985 .config
= iwl4965_mac_config
,
7986 .config_interface
= iwl4965_mac_config_interface
,
7987 .configure_filter
= iwl4965_configure_filter
,
7988 .set_key
= iwl4965_mac_set_key
,
7989 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
7990 .get_stats
= iwl4965_mac_get_stats
,
7991 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
7992 .conf_tx
= iwl4965_mac_conf_tx
,
7993 .get_tsf
= iwl4965_mac_get_tsf
,
7994 .reset_tsf
= iwl4965_mac_reset_tsf
,
7995 .beacon_update
= iwl4965_mac_beacon_update
,
7996 .bss_info_changed
= iwl4965_bss_info_changed
,
7997 #ifdef CONFIG_IWL4965_HT
7998 .conf_ht
= iwl4965_mac_conf_ht
,
7999 .ampdu_action
= iwl4965_mac_ampdu_action
,
8000 #endif /* CONFIG_IWL4965_HT */
8001 .hw_scan
= iwl4965_mac_hw_scan
8004 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
8007 struct iwl_priv
*priv
;
8008 struct ieee80211_hw
*hw
;
8009 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
8010 DECLARE_MAC_BUF(mac
);
8012 /************************
8013 * 1. Allocating HW data
8014 ************************/
8016 /* Disabling hardware scan means that mac80211 will perform scans
8017 * "the hard way", rather than using device's scan. */
8018 if (cfg
->mod_params
->disable_hw_scan
) {
8019 IWL_DEBUG_INFO("Disabling hw_scan\n");
8020 iwl4965_hw_ops
.hw_scan
= NULL
;
8023 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
8029 /* At this point both hw and priv are allocated. */
8031 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
8033 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8035 priv
->pci_dev
= pdev
;
8037 #ifdef CONFIG_IWLWIFI_DEBUG
8038 iwl_debug_level
= priv
->cfg
->mod_params
->debug
;
8039 atomic_set(&priv
->restrict_refcnt
, 0);
8042 /**************************
8043 * 2. Initializing PCI bus
8044 **************************/
8045 if (pci_enable_device(pdev
)) {
8047 goto out_ieee80211_free_hw
;
8050 pci_set_master(pdev
);
8052 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
8054 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
8056 printk(KERN_WARNING DRV_NAME
8057 ": No suitable DMA available.\n");
8058 goto out_pci_disable_device
;
8061 err
= pci_request_regions(pdev
, DRV_NAME
);
8063 goto out_pci_disable_device
;
8065 pci_set_drvdata(pdev
, priv
);
8067 /* We disable the RETRY_TIMEOUT register (0x41) to keep
8068 * PCI Tx retries from interfering with C3 CPU state */
8069 pci_write_config_byte(pdev
, 0x41, 0x00);
8071 /***********************
8072 * 3. Read REV register
8073 ***********************/
8074 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
8075 if (!priv
->hw_base
) {
8077 goto out_pci_release_regions
;
8080 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
8081 (unsigned long long) pci_resource_len(pdev
, 0));
8082 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
8084 printk(KERN_INFO DRV_NAME
8085 ": Detected Intel Wireless WiFi Link %s\n", priv
->cfg
->name
);
8091 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
8092 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
8094 iwl_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
8095 err
= iwl_poll_bit(priv
, CSR_GP_CNTRL
,
8096 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
8097 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
8099 IWL_DEBUG_INFO("Failed to init the card\n");
8102 /* Read the EEPROM */
8103 err
= iwl_eeprom_init(priv
);
8105 IWL_ERROR("Unable to init EEPROM\n");
8108 /* MAC Address location in EEPROM same for 3945/4965 */
8109 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
8110 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
8111 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
8113 /************************
8114 * 5. Setup HW constants
8115 ************************/
8116 /* Device-specific setup */
8117 if (iwl4965_hw_set_hw_setting(priv
)) {
8118 IWL_ERROR("failed to set hw settings\n");
8122 /*******************
8124 *******************/
8126 err
= iwl_setup(priv
);
8128 goto out_unset_hw_settings
;
8129 /* At this point both hw and priv are initialized. */
8131 /**********************************
8132 * 7. Initialize module parameters
8133 **********************************/
8135 /* Disable radio (SW RF KILL) via parameter when loading driver */
8136 if (priv
->cfg
->mod_params
->disable
) {
8137 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
8138 IWL_DEBUG_INFO("Radio disabled.\n");
8141 if (priv
->cfg
->mod_params
->enable_qos
)
8142 priv
->qos_data
.qos_enable
= 1;
8144 /********************
8146 ********************/
8147 iwl4965_disable_interrupts(priv
);
8149 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
8151 IWL_ERROR("failed to create sysfs device attributes\n");
8152 goto out_unset_hw_settings
;
8155 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
8157 IWL_ERROR("failed to create debugfs files\n");
8158 goto out_remove_sysfs
;
8161 iwl4965_setup_deferred_work(priv
);
8162 iwl4965_setup_rx_handlers(priv
);
8164 /********************
8166 ********************/
8167 pci_save_state(pdev
);
8168 pci_disable_device(pdev
);
8173 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
8174 out_unset_hw_settings
:
8175 iwl4965_unset_hw_setting(priv
);
8177 pci_iounmap(pdev
, priv
->hw_base
);
8178 out_pci_release_regions
:
8179 pci_release_regions(pdev
);
8180 pci_set_drvdata(pdev
, NULL
);
8181 out_pci_disable_device
:
8182 pci_disable_device(pdev
);
8183 out_ieee80211_free_hw
:
8184 ieee80211_free_hw(priv
->hw
);
8189 static void iwl4965_pci_remove(struct pci_dev
*pdev
)
8191 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8192 struct list_head
*p
, *q
;
8198 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8200 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
8204 /* Free MAC hash list for ADHOC */
8205 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
8206 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
8208 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
8212 iwl_dbgfs_unregister(priv
);
8213 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
8215 iwl4965_dealloc_ucode_pci(priv
);
8218 iwl4965_rx_queue_free(priv
, &priv
->rxq
);
8219 iwl4965_hw_txq_ctx_free(priv
);
8221 iwl4965_unset_hw_setting(priv
);
8222 iwlcore_clear_stations_table(priv
);
8224 if (priv
->mac80211_registered
) {
8225 ieee80211_unregister_hw(priv
->hw
);
8226 iwl4965_rate_control_unregister(priv
->hw
);
8229 /*netif_stop_queue(dev); */
8230 flush_workqueue(priv
->workqueue
);
8232 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
8233 * priv->workqueue... so we can't take down the workqueue
8235 destroy_workqueue(priv
->workqueue
);
8236 priv
->workqueue
= NULL
;
8238 pci_iounmap(pdev
, priv
->hw_base
);
8239 pci_release_regions(pdev
);
8240 pci_disable_device(pdev
);
8241 pci_set_drvdata(pdev
, NULL
);
8243 iwl_free_channel_map(priv
);
8244 iwl4965_free_geos(priv
);
8246 if (priv
->ibss_beacon
)
8247 dev_kfree_skb(priv
->ibss_beacon
);
8249 ieee80211_free_hw(priv
->hw
);
8254 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8256 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8258 if (priv
->is_open
) {
8259 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8260 iwl4965_mac_stop(priv
->hw
);
8264 pci_set_power_state(pdev
, PCI_D3hot
);
8269 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
8271 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8273 pci_set_power_state(pdev
, PCI_D0
);
8276 iwl4965_mac_start(priv
->hw
);
8278 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8282 #endif /* CONFIG_PM */
8284 /*****************************************************************************
8286 * driver and module entry point
8288 *****************************************************************************/
8290 static struct pci_driver iwl4965_driver
= {
8292 .id_table
= iwl4965_hw_card_ids
,
8293 .probe
= iwl4965_pci_probe
,
8294 .remove
= __devexit_p(iwl4965_pci_remove
),
8296 .suspend
= iwl4965_pci_suspend
,
8297 .resume
= iwl4965_pci_resume
,
8301 static int __init
iwl4965_init(void)
8305 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8306 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8307 ret
= pci_register_driver(&iwl4965_driver
);
8309 IWL_ERROR("Unable to initialize PCI module\n");
8312 #ifdef CONFIG_IWLWIFI_DEBUG
8313 ret
= driver_create_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
8315 IWL_ERROR("Unable to create driver sysfs file\n");
8316 pci_unregister_driver(&iwl4965_driver
);
8324 static void __exit
iwl4965_exit(void)
8326 #ifdef CONFIG_IWLWIFI_DEBUG
8327 driver_remove_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
8329 pci_unregister_driver(&iwl4965_driver
);
8332 module_exit(iwl4965_exit
);
8333 module_init(iwl4965_init
);