1 /******************************************************************************
3 * Copyright(c) 2003 - 2007 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>
49 #include "iwl-helpers.h"
51 #ifdef CONFIG_IWL4965_DEBUG
52 u32 iwl4965_debug_level
;
55 static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv
*priv
,
56 struct iwl4965_tx_queue
*txq
);
58 /******************************************************************************
62 ******************************************************************************/
64 /* module parameters */
65 static int iwl4965_param_disable_hw_scan
; /* def: 0 = use 4965's h/w scan */
66 static int iwl4965_param_debug
; /* def: 0 = minimal debug log messages */
67 static int iwl4965_param_disable
; /* def: enable radio */
68 static int iwl4965_param_antenna
; /* def: 0 = both antennas (use diversity) */
69 int iwl4965_param_hwcrypto
; /* def: using software encryption */
70 static int iwl4965_param_qos_enable
= 1; /* def: 1 = use quality of service */
71 int iwl4965_param_queues_num
= IWL_MAX_NUM_QUEUES
; /* def: 16 Tx queues */
72 int iwl4965_param_amsdu_size_8K
; /* def: enable 8K amsdu size */
75 * module name, copyright, version, etc.
76 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
79 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
81 #ifdef CONFIG_IWL4965_DEBUG
87 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
93 #define IWLWIFI_VERSION "1.2.23k" VD VS
94 #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
95 #define DRV_VERSION IWLWIFI_VERSION
97 /* Change firmware file name, using "-" and incrementing number,
98 * *only* when uCode interface or architecture changes so that it
99 * is not compatible with earlier drivers.
100 * This number will also appear in << 8 position of 1st dword of uCode file */
101 #define IWL4965_UCODE_API "-1"
103 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
104 MODULE_VERSION(DRV_VERSION
);
105 MODULE_AUTHOR(DRV_COPYRIGHT
);
106 MODULE_LICENSE("GPL");
108 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
110 u16 fc
= le16_to_cpu(hdr
->frame_control
);
111 int hdr_len
= ieee80211_get_hdrlen(fc
);
113 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
114 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
118 static const struct ieee80211_hw_mode
*iwl4965_get_hw_mode(
119 struct iwl4965_priv
*priv
, int mode
)
123 for (i
= 0; i
< 3; i
++)
124 if (priv
->modes
[i
].mode
== mode
)
125 return &priv
->modes
[i
];
130 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
132 /* Single white space is for Linksys APs */
133 if (essid_len
== 1 && essid
[0] == ' ')
136 /* Otherwise, if the entire essid is 0, we assume it is hidden */
139 if (essid
[essid_len
] != '\0')
146 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
148 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
149 const char *s
= essid
;
152 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
153 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
157 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
158 while (essid_len
--) {
170 static void iwl4965_print_hex_dump(int level
, void *p
, u32 len
)
172 #ifdef CONFIG_IWL4965_DEBUG
173 if (!(iwl4965_debug_level
& level
))
176 print_hex_dump(KERN_DEBUG
, "iwl data: ", DUMP_PREFIX_OFFSET
, 16, 1,
181 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
184 * Theory of operation
186 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
187 * of buffer descriptors, each of which points to one or more data buffers for
188 * the device to read from or fill. Driver and device exchange status of each
189 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
190 * entries in each circular buffer, to protect against confusing empty and full
193 * The device reads or writes the data in the queues via the device's several
194 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
196 * For Tx queue, there are low mark and high mark limits. If, after queuing
197 * the packet for Tx, free space become < low mark, Tx queue stopped. When
198 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
201 * The 4965 operates with up to 17 queues: One receive queue, one transmit
202 * queue (#4) for sending commands to the device firmware, and 15 other
203 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
205 * See more detailed info in iwl-4965-hw.h.
206 ***************************************************/
208 int iwl4965_queue_space(const struct iwl4965_queue
*q
)
210 int s
= q
->read_ptr
- q
->write_ptr
;
212 if (q
->read_ptr
> q
->write_ptr
)
217 /* keep some reserve to not confuse empty and full situations */
225 * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning
226 * @index -- current index
227 * @n_bd -- total number of entries in queue (must be power of 2)
229 static inline int iwl4965_queue_inc_wrap(int index
, int n_bd
)
231 return ++index
& (n_bd
- 1);
235 * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end
236 * @index -- current index
237 * @n_bd -- total number of entries in queue (must be power of 2)
239 static inline int iwl4965_queue_dec_wrap(int index
, int n_bd
)
241 return --index
& (n_bd
- 1);
244 static inline int x2_queue_used(const struct iwl4965_queue
*q
, int i
)
246 return q
->write_ptr
> q
->read_ptr
?
247 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
248 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
251 static inline u8
get_cmd_index(struct iwl4965_queue
*q
, u32 index
, int is_huge
)
253 /* This is for scan command, the big buffer at end of command array */
255 return q
->n_window
; /* must be power of 2 */
257 /* Otherwise, use normal size buffers */
258 return index
& (q
->n_window
- 1);
262 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
264 static int iwl4965_queue_init(struct iwl4965_priv
*priv
, struct iwl4965_queue
*q
,
265 int count
, int slots_num
, u32 id
)
268 q
->n_window
= slots_num
;
271 /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap
272 * and iwl4965_queue_dec_wrap are broken. */
273 BUG_ON(!is_power_of_2(count
));
275 /* slots_num must be power-of-two size, otherwise
276 * get_cmd_index is broken. */
277 BUG_ON(!is_power_of_2(slots_num
));
279 q
->low_mark
= q
->n_window
/ 4;
283 q
->high_mark
= q
->n_window
/ 8;
284 if (q
->high_mark
< 2)
287 q
->write_ptr
= q
->read_ptr
= 0;
293 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
295 static int iwl4965_tx_queue_alloc(struct iwl4965_priv
*priv
,
296 struct iwl4965_tx_queue
*txq
, u32 id
)
298 struct pci_dev
*dev
= priv
->pci_dev
;
300 /* Driver private data, only for Tx (not command) queues,
301 * not shared with device. */
302 if (id
!= IWL_CMD_QUEUE_NUM
) {
303 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
304 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
306 IWL_ERROR("kmalloc for auxiliary BD "
307 "structures failed\n");
313 /* Circular buffer of transmit frame descriptors (TFDs),
314 * shared with device */
315 txq
->bd
= pci_alloc_consistent(dev
,
316 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
320 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
321 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
338 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
340 int iwl4965_tx_queue_init(struct iwl4965_priv
*priv
,
341 struct iwl4965_tx_queue
*txq
, int slots_num
, u32 txq_id
)
343 struct pci_dev
*dev
= priv
->pci_dev
;
348 * Alloc buffer array for commands (Tx or other types of commands).
349 * For the command queue (#4), allocate command space + one big
350 * command for scan, since scan command is very huge; the system will
351 * not have two scans at the same time, so only one is needed.
352 * For normal Tx queues (all other queues), no super-size command
355 len
= sizeof(struct iwl4965_cmd
) * slots_num
;
356 if (txq_id
== IWL_CMD_QUEUE_NUM
)
357 len
+= IWL_MAX_SCAN_SIZE
;
358 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
362 /* Alloc driver data array and TFD circular buffer */
363 rc
= iwl4965_tx_queue_alloc(priv
, txq
, txq_id
);
365 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
369 txq
->need_update
= 0;
371 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
372 * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */
373 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
375 /* Initialize queue's high/low-water marks, and head/tail indexes */
376 iwl4965_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
378 /* Tell device where to find queue */
379 iwl4965_hw_tx_queue_init(priv
, txq
);
385 * iwl4965_tx_queue_free - Deallocate DMA queue.
386 * @txq: Transmit queue to deallocate.
388 * Empty queue by removing and destroying all BD's.
390 * 0-fill, but do not free "txq" descriptor structure.
392 void iwl4965_tx_queue_free(struct iwl4965_priv
*priv
, struct iwl4965_tx_queue
*txq
)
394 struct iwl4965_queue
*q
= &txq
->q
;
395 struct pci_dev
*dev
= priv
->pci_dev
;
401 /* first, empty all BD's */
402 for (; q
->write_ptr
!= q
->read_ptr
;
403 q
->read_ptr
= iwl4965_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
404 iwl4965_hw_txq_free_tfd(priv
, txq
);
406 len
= sizeof(struct iwl4965_cmd
) * q
->n_window
;
407 if (q
->id
== IWL_CMD_QUEUE_NUM
)
408 len
+= IWL_MAX_SCAN_SIZE
;
410 /* De-alloc array of command/tx buffers */
411 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
413 /* De-alloc circular buffer of TFDs */
415 pci_free_consistent(dev
, sizeof(struct iwl4965_tfd_frame
) *
416 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
418 /* De-alloc array of per-TFD driver data */
424 /* 0-fill queue descriptor structure */
425 memset(txq
, 0, sizeof(*txq
));
428 const u8 iwl4965_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
430 /*************** STATION TABLE MANAGEMENT ****
431 * mac80211 should be examined to determine if sta_info is duplicating
432 * the functionality provided here
435 /**************************************************************/
437 #if 0 /* temporary disable till we add real remove station */
439 * iwl4965_remove_station - Remove driver's knowledge of station.
441 * NOTE: This does not remove station from device's station table.
443 static u8
iwl4965_remove_station(struct iwl4965_priv
*priv
, const u8
*addr
, int is_ap
)
445 int index
= IWL_INVALID_STATION
;
449 spin_lock_irqsave(&priv
->sta_lock
, flags
);
453 else if (is_broadcast_ether_addr(addr
))
454 index
= priv
->hw_setting
.bcast_sta_id
;
456 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
457 if (priv
->stations
[i
].used
&&
458 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
464 if (unlikely(index
== IWL_INVALID_STATION
))
467 if (priv
->stations
[index
].used
) {
468 priv
->stations
[index
].used
= 0;
469 priv
->num_stations
--;
472 BUG_ON(priv
->num_stations
< 0);
475 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
481 * iwl4965_clear_stations_table - Clear the driver's station table
483 * NOTE: This does not clear or otherwise alter the device's station table.
485 static void iwl4965_clear_stations_table(struct iwl4965_priv
*priv
)
489 spin_lock_irqsave(&priv
->sta_lock
, flags
);
491 priv
->num_stations
= 0;
492 memset(priv
->stations
, 0, sizeof(priv
->stations
));
494 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
498 * iwl4965_add_station_flags - Add station to tables in driver and device
500 u8
iwl4965_add_station_flags(struct iwl4965_priv
*priv
, const u8
*addr
,
501 int is_ap
, u8 flags
, void *ht_data
)
504 int index
= IWL_INVALID_STATION
;
505 struct iwl4965_station_entry
*station
;
506 unsigned long flags_spin
;
507 DECLARE_MAC_BUF(mac
);
509 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
512 else if (is_broadcast_ether_addr(addr
))
513 index
= priv
->hw_setting
.bcast_sta_id
;
515 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
516 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
522 if (!priv
->stations
[i
].used
&&
523 index
== IWL_INVALID_STATION
)
528 /* These two conditions have the same outcome, but keep them separate
529 since they have different meanings */
530 if (unlikely(index
== IWL_INVALID_STATION
)) {
531 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
535 if (priv
->stations
[index
].used
&&
536 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
537 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
542 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
543 station
= &priv
->stations
[index
];
545 priv
->num_stations
++;
547 /* Set up the REPLY_ADD_STA command to send to device */
548 memset(&station
->sta
, 0, sizeof(struct iwl4965_addsta_cmd
));
549 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
550 station
->sta
.mode
= 0;
551 station
->sta
.sta
.sta_id
= index
;
552 station
->sta
.station_flags
= 0;
554 #ifdef CONFIG_IWL4965_HT
555 /* BCAST station and IBSS stations do not work in HT mode */
556 if (index
!= priv
->hw_setting
.bcast_sta_id
&&
557 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
558 iwl4965_set_ht_add_station(priv
, index
,
559 (struct ieee80211_ht_info
*) ht_data
);
560 #endif /*CONFIG_IWL4965_HT*/
562 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
564 /* Add station to device's station table */
565 iwl4965_send_add_station(priv
, &station
->sta
, flags
);
570 /*************** DRIVER STATUS FUNCTIONS *****/
572 static inline int iwl4965_is_ready(struct iwl4965_priv
*priv
)
574 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
575 * set but EXIT_PENDING is not */
576 return test_bit(STATUS_READY
, &priv
->status
) &&
577 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) &&
578 !test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
581 static inline int iwl4965_is_alive(struct iwl4965_priv
*priv
)
583 return test_bit(STATUS_ALIVE
, &priv
->status
);
586 static inline int iwl4965_is_init(struct iwl4965_priv
*priv
)
588 return test_bit(STATUS_INIT
, &priv
->status
);
591 static inline int iwl4965_is_rfkill(struct iwl4965_priv
*priv
)
593 return test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ||
594 test_bit(STATUS_RF_KILL_SW
, &priv
->status
);
597 static inline int iwl4965_is_ready_rf(struct iwl4965_priv
*priv
)
600 if (iwl4965_is_rfkill(priv
))
603 return iwl4965_is_ready(priv
);
606 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
608 #define IWL_CMD(x) case x : return #x
610 static const char *get_cmd_string(u8 cmd
)
613 IWL_CMD(REPLY_ALIVE
);
614 IWL_CMD(REPLY_ERROR
);
616 IWL_CMD(REPLY_RXON_ASSOC
);
617 IWL_CMD(REPLY_QOS_PARAM
);
618 IWL_CMD(REPLY_RXON_TIMING
);
619 IWL_CMD(REPLY_ADD_STA
);
620 IWL_CMD(REPLY_REMOVE_STA
);
621 IWL_CMD(REPLY_REMOVE_ALL_STA
);
623 IWL_CMD(REPLY_RATE_SCALE
);
624 IWL_CMD(REPLY_LEDS_CMD
);
625 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD
);
626 IWL_CMD(RADAR_NOTIFICATION
);
627 IWL_CMD(REPLY_QUIET_CMD
);
628 IWL_CMD(REPLY_CHANNEL_SWITCH
);
629 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION
);
630 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD
);
631 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION
);
632 IWL_CMD(POWER_TABLE_CMD
);
633 IWL_CMD(PM_SLEEP_NOTIFICATION
);
634 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC
);
635 IWL_CMD(REPLY_SCAN_CMD
);
636 IWL_CMD(REPLY_SCAN_ABORT_CMD
);
637 IWL_CMD(SCAN_START_NOTIFICATION
);
638 IWL_CMD(SCAN_RESULTS_NOTIFICATION
);
639 IWL_CMD(SCAN_COMPLETE_NOTIFICATION
);
640 IWL_CMD(BEACON_NOTIFICATION
);
641 IWL_CMD(REPLY_TX_BEACON
);
642 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION
);
643 IWL_CMD(QUIET_NOTIFICATION
);
644 IWL_CMD(REPLY_TX_PWR_TABLE_CMD
);
645 IWL_CMD(MEASURE_ABORT_NOTIFICATION
);
646 IWL_CMD(REPLY_BT_CONFIG
);
647 IWL_CMD(REPLY_STATISTICS_CMD
);
648 IWL_CMD(STATISTICS_NOTIFICATION
);
649 IWL_CMD(REPLY_CARD_STATE_CMD
);
650 IWL_CMD(CARD_STATE_NOTIFICATION
);
651 IWL_CMD(MISSED_BEACONS_NOTIFICATION
);
652 IWL_CMD(REPLY_CT_KILL_CONFIG_CMD
);
653 IWL_CMD(SENSITIVITY_CMD
);
654 IWL_CMD(REPLY_PHY_CALIBRATION_CMD
);
655 IWL_CMD(REPLY_RX_PHY_CMD
);
656 IWL_CMD(REPLY_RX_MPDU_CMD
);
657 IWL_CMD(REPLY_4965_RX
);
658 IWL_CMD(REPLY_COMPRESSED_BA
);
665 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
668 * iwl4965_enqueue_hcmd - enqueue a uCode command
669 * @priv: device private data point
670 * @cmd: a point to the ucode command structure
672 * The function returns < 0 values to indicate the operation is
673 * failed. On success, it turns the index (> 0) of command in the
676 static int iwl4965_enqueue_hcmd(struct iwl4965_priv
*priv
, struct iwl4965_host_cmd
*cmd
)
678 struct iwl4965_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
679 struct iwl4965_queue
*q
= &txq
->q
;
680 struct iwl4965_tfd_frame
*tfd
;
682 struct iwl4965_cmd
*out_cmd
;
684 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
685 dma_addr_t phys_addr
;
689 /* If any of the command structures end up being larger than
690 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
691 * we will need to increase the size of the TFD entries */
692 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
693 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
695 if (iwl4965_is_rfkill(priv
)) {
696 IWL_DEBUG_INFO("Not sending command - RF KILL");
700 if (iwl4965_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
701 IWL_ERROR("No space for Tx\n");
705 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
707 tfd
= &txq
->bd
[q
->write_ptr
];
708 memset(tfd
, 0, sizeof(*tfd
));
710 control_flags
= (u32
*) tfd
;
712 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
713 out_cmd
= &txq
->cmd
[idx
];
715 out_cmd
->hdr
.cmd
= cmd
->id
;
716 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
717 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
719 /* At this point, the out_cmd now has all of the incoming cmd
722 out_cmd
->hdr
.flags
= 0;
723 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
724 INDEX_TO_SEQ(q
->write_ptr
));
725 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
726 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
728 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
729 offsetof(struct iwl4965_cmd
, hdr
);
730 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
732 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
733 "%d bytes at %d[%d]:%d\n",
734 get_cmd_string(out_cmd
->hdr
.cmd
),
735 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
736 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
738 txq
->need_update
= 1;
740 /* Set up entry in queue's byte count circular buffer */
741 ret
= iwl4965_tx_queue_update_wr_ptr(priv
, txq
, 0);
743 /* Increment and update queue's write index */
744 q
->write_ptr
= iwl4965_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
745 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
747 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
748 return ret
? ret
: idx
;
751 static int iwl4965_send_cmd_async(struct iwl4965_priv
*priv
, struct iwl4965_host_cmd
*cmd
)
755 BUG_ON(!(cmd
->meta
.flags
& CMD_ASYNC
));
757 /* An asynchronous command can not expect an SKB to be set. */
758 BUG_ON(cmd
->meta
.flags
& CMD_WANT_SKB
);
760 /* An asynchronous command MUST have a callback. */
761 BUG_ON(!cmd
->meta
.u
.callback
);
763 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
766 ret
= iwl4965_enqueue_hcmd(priv
, cmd
);
768 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
769 get_cmd_string(cmd
->id
), ret
);
775 static int iwl4965_send_cmd_sync(struct iwl4965_priv
*priv
, struct iwl4965_host_cmd
*cmd
)
779 static atomic_t entry
= ATOMIC_INIT(0); /* reentrance protection */
781 BUG_ON(cmd
->meta
.flags
& CMD_ASYNC
);
783 /* A synchronous command can not have a callback set. */
784 BUG_ON(cmd
->meta
.u
.callback
!= NULL
);
786 if (atomic_xchg(&entry
, 1)) {
787 IWL_ERROR("Error sending %s: Already sending a host command\n",
788 get_cmd_string(cmd
->id
));
792 set_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
794 if (cmd
->meta
.flags
& CMD_WANT_SKB
)
795 cmd
->meta
.source
= &cmd
->meta
;
797 cmd_idx
= iwl4965_enqueue_hcmd(priv
, cmd
);
800 IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n",
801 get_cmd_string(cmd
->id
), ret
);
805 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
806 !test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
),
807 HOST_COMPLETE_TIMEOUT
);
809 if (test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
)) {
810 IWL_ERROR("Error sending %s: time out after %dms.\n",
811 get_cmd_string(cmd
->id
),
812 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT
));
814 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
820 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
821 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
822 get_cmd_string(cmd
->id
));
826 if (test_bit(STATUS_FW_ERROR
, &priv
->status
)) {
827 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
828 get_cmd_string(cmd
->id
));
832 if ((cmd
->meta
.flags
& CMD_WANT_SKB
) && !cmd
->meta
.u
.skb
) {
833 IWL_ERROR("Error: Response NULL in '%s'\n",
834 get_cmd_string(cmd
->id
));
843 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
844 struct iwl4965_cmd
*qcmd
;
846 /* Cancel the CMD_WANT_SKB flag for the cmd in the
847 * TX cmd queue. Otherwise in case the cmd comes
848 * in later, it will possibly set an invalid
849 * address (cmd->meta.source). */
850 qcmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_idx
];
851 qcmd
->meta
.flags
&= ~CMD_WANT_SKB
;
854 if (cmd
->meta
.u
.skb
) {
855 dev_kfree_skb_any(cmd
->meta
.u
.skb
);
856 cmd
->meta
.u
.skb
= NULL
;
859 atomic_set(&entry
, 0);
863 int iwl4965_send_cmd(struct iwl4965_priv
*priv
, struct iwl4965_host_cmd
*cmd
)
865 if (cmd
->meta
.flags
& CMD_ASYNC
)
866 return iwl4965_send_cmd_async(priv
, cmd
);
868 return iwl4965_send_cmd_sync(priv
, cmd
);
871 int iwl4965_send_cmd_pdu(struct iwl4965_priv
*priv
, u8 id
, u16 len
, const void *data
)
873 struct iwl4965_host_cmd cmd
= {
879 return iwl4965_send_cmd_sync(priv
, &cmd
);
882 static int __must_check
iwl4965_send_cmd_u32(struct iwl4965_priv
*priv
, u8 id
, u32 val
)
884 struct iwl4965_host_cmd cmd
= {
890 return iwl4965_send_cmd_sync(priv
, &cmd
);
893 int iwl4965_send_statistics_request(struct iwl4965_priv
*priv
)
895 return iwl4965_send_cmd_u32(priv
, REPLY_STATISTICS_CMD
, 0);
899 * iwl4965_rxon_add_station - add station into station table.
901 * there is only one AP station with id= IWL_AP_ID
902 * NOTE: mutex must be held before calling this fnction
904 static int iwl4965_rxon_add_station(struct iwl4965_priv
*priv
,
905 const u8
*addr
, int is_ap
)
909 /* Add station to device's station table */
910 #ifdef CONFIG_IWL4965_HT
911 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
912 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
915 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
916 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
917 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
920 #endif /* CONFIG_IWL4965_HT */
921 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
924 /* Set up default rate scaling table in device's station table */
925 iwl4965_add_station(priv
, addr
, is_ap
);
931 * iwl4965_set_rxon_channel - Set the phymode and channel values in staging RXON
932 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
933 * @channel: Any channel valid for the requested phymode
935 * In addition to setting the staging RXON, priv->phymode is also set.
937 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
938 * in the staging RXON flag structure based on the phymode
940 static int iwl4965_set_rxon_channel(struct iwl4965_priv
*priv
, u8 phymode
,
943 if (!iwl4965_get_channel_info(priv
, phymode
, channel
)) {
944 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
949 if ((le16_to_cpu(priv
->staging_rxon
.channel
) == channel
) &&
950 (priv
->phymode
== phymode
))
953 priv
->staging_rxon
.channel
= cpu_to_le16(channel
);
954 if (phymode
== MODE_IEEE80211A
)
955 priv
->staging_rxon
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
957 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
959 priv
->phymode
= phymode
;
961 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel
, phymode
);
967 * iwl4965_check_rxon_cmd - validate RXON structure is valid
969 * NOTE: This is really only useful during development and can eventually
970 * be #ifdef'd out once the driver is stable and folks aren't actively
973 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
978 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
979 error
|= le32_to_cpu(rxon
->flags
&
980 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
981 RXON_FLG_RADAR_DETECT_MSK
));
983 IWL_WARNING("check 24G fields %d | %d\n",
986 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
987 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
989 IWL_WARNING("check 52 fields %d | %d\n",
991 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
993 IWL_WARNING("check 52 CCK %d | %d\n",
996 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
998 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
1000 /* make sure basic rates 6Mbps and 1Mbps are supported */
1001 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
1002 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
1004 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
1006 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
1008 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
1010 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
1011 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
1013 IWL_WARNING("check CCK and short slot %d | %d\n",
1016 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
1017 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
1019 IWL_WARNING("check CCK & auto detect %d | %d\n",
1022 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
1023 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
1025 IWL_WARNING("check TGG and auto detect %d | %d\n",
1029 IWL_WARNING("Tuning to channel %d\n",
1030 le16_to_cpu(rxon
->channel
));
1033 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
1040 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
1041 * @priv: staging_rxon is compared to active_rxon
1043 * If the RXON structure is changing enough to require a new tune,
1044 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
1045 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
1047 static int iwl4965_full_rxon_required(struct iwl4965_priv
*priv
)
1050 /* These items are only settable from the full RXON command */
1051 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
1052 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
1053 priv
->active_rxon
.bssid_addr
) ||
1054 compare_ether_addr(priv
->staging_rxon
.node_addr
,
1055 priv
->active_rxon
.node_addr
) ||
1056 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
1057 priv
->active_rxon
.wlap_bssid_addr
) ||
1058 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
1059 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
1060 (priv
->staging_rxon
.air_propagation
!=
1061 priv
->active_rxon
.air_propagation
) ||
1062 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
1063 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
1064 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
1065 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
1066 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
1067 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
1070 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
1071 * be updated with the RXON_ASSOC command -- however only some
1072 * flag transitions are allowed using RXON_ASSOC */
1074 /* Check if we are not switching bands */
1075 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
1076 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
1079 /* Check if we are switching association toggle */
1080 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
1081 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
1087 static int iwl4965_send_rxon_assoc(struct iwl4965_priv
*priv
)
1090 struct iwl4965_rx_packet
*res
= NULL
;
1091 struct iwl4965_rxon_assoc_cmd rxon_assoc
;
1092 struct iwl4965_host_cmd cmd
= {
1093 .id
= REPLY_RXON_ASSOC
,
1094 .len
= sizeof(rxon_assoc
),
1095 .meta
.flags
= CMD_WANT_SKB
,
1096 .data
= &rxon_assoc
,
1098 const struct iwl4965_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
1099 const struct iwl4965_rxon_cmd
*rxon2
= &priv
->active_rxon
;
1101 if ((rxon1
->flags
== rxon2
->flags
) &&
1102 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
1103 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
1104 (rxon1
->ofdm_ht_single_stream_basic_rates
==
1105 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
1106 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
1107 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
1108 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
1109 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
1110 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1114 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
1115 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
1116 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
1117 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
1118 rxon_assoc
.reserved
= 0;
1119 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
1120 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
;
1121 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
1122 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
;
1123 rxon_assoc
.rx_chain_select_flags
= priv
->staging_rxon
.rx_chain
;
1125 rc
= iwl4965_send_cmd_sync(priv
, &cmd
);
1129 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1130 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1131 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1135 priv
->alloc_rxb_skb
--;
1136 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1142 * iwl4965_commit_rxon - commit staging_rxon to hardware
1144 * The RXON command in staging_rxon is committed to the hardware and
1145 * the active_rxon structure is updated with the new data. This
1146 * function correctly transitions out of the RXON_ASSOC_MSK state if
1147 * a HW tune is required based on the RXON structure changes.
1149 static int iwl4965_commit_rxon(struct iwl4965_priv
*priv
)
1151 /* cast away the const for active_rxon in this function */
1152 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
1153 DECLARE_MAC_BUF(mac
);
1156 if (!iwl4965_is_alive(priv
))
1159 /* always get timestamp with Rx frame */
1160 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1162 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
1164 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1168 /* If we don't need to send a full RXON, we can use
1169 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
1170 * and other flags for the current radio configuration. */
1171 if (!iwl4965_full_rxon_required(priv
)) {
1172 rc
= iwl4965_send_rxon_assoc(priv
);
1174 IWL_ERROR("Error setting RXON_ASSOC "
1175 "configuration (%d).\n", rc
);
1179 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1184 /* station table will be cleared */
1185 priv
->assoc_station_added
= 0;
1187 #ifdef CONFIG_IWL4965_SENSITIVITY
1188 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
1189 if (!priv
->error_recovering
)
1190 priv
->start_calib
= 0;
1192 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
1193 #endif /* CONFIG_IWL4965_SENSITIVITY */
1195 /* If we are currently associated and the new config requires
1196 * an RXON_ASSOC and the new config wants the associated mask enabled,
1197 * we must clear the associated from the active configuration
1198 * before we apply the new config */
1199 if (iwl4965_is_associated(priv
) &&
1200 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
1201 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1202 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1204 rc
= iwl4965_send_cmd_pdu(priv
, REPLY_RXON
,
1205 sizeof(struct iwl4965_rxon_cmd
),
1206 &priv
->active_rxon
);
1208 /* If the mask clearing failed then we set
1209 * active_rxon back to what it was previously */
1211 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1212 IWL_ERROR("Error clearing ASSOC_MSK on current "
1213 "configuration (%d).\n", rc
);
1218 IWL_DEBUG_INFO("Sending RXON\n"
1219 "* with%s RXON_FILTER_ASSOC_MSK\n"
1222 ((priv
->staging_rxon
.filter_flags
&
1223 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
1224 le16_to_cpu(priv
->staging_rxon
.channel
),
1225 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
1227 /* Apply the new configuration */
1228 rc
= iwl4965_send_cmd_pdu(priv
, REPLY_RXON
,
1229 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
1231 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
1235 iwl4965_clear_stations_table(priv
);
1237 #ifdef CONFIG_IWL4965_SENSITIVITY
1238 if (!priv
->error_recovering
)
1239 priv
->start_calib
= 0;
1241 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
1242 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
1243 #endif /* CONFIG_IWL4965_SENSITIVITY */
1245 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1247 /* If we issue a new RXON command which required a tune then we must
1248 * send a new TXPOWER command or we won't be able to Tx any frames */
1249 rc
= iwl4965_hw_reg_send_txpower(priv
);
1251 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
1255 /* Add the broadcast address so we can send broadcast frames */
1256 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
1257 IWL_INVALID_STATION
) {
1258 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1262 /* If we have set the ASSOC_MSK and we are in BSS mode then
1263 * add the IWL_AP_ID to the station rate table */
1264 if (iwl4965_is_associated(priv
) &&
1265 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
1266 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
1267 == IWL_INVALID_STATION
) {
1268 IWL_ERROR("Error adding AP address for transmit.\n");
1271 priv
->assoc_station_added
= 1;
1277 static int iwl4965_send_bt_config(struct iwl4965_priv
*priv
)
1279 struct iwl4965_bt_cmd bt_cmd
= {
1287 return iwl4965_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1288 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
1291 static int iwl4965_send_scan_abort(struct iwl4965_priv
*priv
)
1294 struct iwl4965_rx_packet
*res
;
1295 struct iwl4965_host_cmd cmd
= {
1296 .id
= REPLY_SCAN_ABORT_CMD
,
1297 .meta
.flags
= CMD_WANT_SKB
,
1300 /* If there isn't a scan actively going on in the hardware
1301 * then we are in between scan bands and not actually
1302 * actively scanning, so don't send the abort command */
1303 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1304 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1308 rc
= iwl4965_send_cmd_sync(priv
, &cmd
);
1310 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1314 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1315 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
1316 /* The scan abort will return 1 for success or
1317 * 2 for "failure". A failure condition can be
1318 * due to simply not being in an active scan which
1319 * can occur if we send the scan abort before we
1320 * the microcode has notified us that a scan is
1322 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
1323 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1324 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1327 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1332 static int iwl4965_card_state_sync_callback(struct iwl4965_priv
*priv
,
1333 struct iwl4965_cmd
*cmd
,
1334 struct sk_buff
*skb
)
1342 * Use: Sets the device's internal card state to enable, disable, or halt
1344 * When in the 'enable' state the card operates as normal.
1345 * When in the 'disable' state, the card enters into a low power mode.
1346 * When in the 'halt' state, the card is shut down and must be fully
1347 * restarted to come back on.
1349 static int iwl4965_send_card_state(struct iwl4965_priv
*priv
, u32 flags
, u8 meta_flag
)
1351 struct iwl4965_host_cmd cmd
= {
1352 .id
= REPLY_CARD_STATE_CMD
,
1355 .meta
.flags
= meta_flag
,
1358 if (meta_flag
& CMD_ASYNC
)
1359 cmd
.meta
.u
.callback
= iwl4965_card_state_sync_callback
;
1361 return iwl4965_send_cmd(priv
, &cmd
);
1364 static int iwl4965_add_sta_sync_callback(struct iwl4965_priv
*priv
,
1365 struct iwl4965_cmd
*cmd
, struct sk_buff
*skb
)
1367 struct iwl4965_rx_packet
*res
= NULL
;
1370 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1374 res
= (struct iwl4965_rx_packet
*)skb
->data
;
1375 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1376 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1381 switch (res
->u
.add_sta
.status
) {
1382 case ADD_STA_SUCCESS_MSK
:
1388 /* We didn't cache the SKB; let the caller free it */
1392 int iwl4965_send_add_station(struct iwl4965_priv
*priv
,
1393 struct iwl4965_addsta_cmd
*sta
, u8 flags
)
1395 struct iwl4965_rx_packet
*res
= NULL
;
1397 struct iwl4965_host_cmd cmd
= {
1398 .id
= REPLY_ADD_STA
,
1399 .len
= sizeof(struct iwl4965_addsta_cmd
),
1400 .meta
.flags
= flags
,
1404 if (flags
& CMD_ASYNC
)
1405 cmd
.meta
.u
.callback
= iwl4965_add_sta_sync_callback
;
1407 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1409 rc
= iwl4965_send_cmd(priv
, &cmd
);
1411 if (rc
|| (flags
& CMD_ASYNC
))
1414 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1415 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1416 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1422 switch (res
->u
.add_sta
.status
) {
1423 case ADD_STA_SUCCESS_MSK
:
1424 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1428 IWL_WARNING("REPLY_ADD_STA failed\n");
1433 priv
->alloc_rxb_skb
--;
1434 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1439 static int iwl4965_update_sta_key_info(struct iwl4965_priv
*priv
,
1440 struct ieee80211_key_conf
*keyconf
,
1443 unsigned long flags
;
1444 __le16 key_flags
= 0;
1446 switch (keyconf
->alg
) {
1448 key_flags
|= STA_KEY_FLG_CCMP
;
1449 key_flags
|= cpu_to_le16(
1450 keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1451 key_flags
&= ~STA_KEY_FLG_INVALID
;
1458 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1459 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1460 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1461 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
1464 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
1466 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
1467 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1468 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1470 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1472 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1473 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1477 static int iwl4965_clear_sta_key_info(struct iwl4965_priv
*priv
, u8 sta_id
)
1479 unsigned long flags
;
1481 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1482 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl4965_hw_key
));
1483 memset(&priv
->stations
[sta_id
].sta
.key
, 0, sizeof(struct iwl4965_keyinfo
));
1484 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1485 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1486 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1487 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1489 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1490 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1494 static void iwl4965_clear_free_frames(struct iwl4965_priv
*priv
)
1496 struct list_head
*element
;
1498 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1499 priv
->frames_count
);
1501 while (!list_empty(&priv
->free_frames
)) {
1502 element
= priv
->free_frames
.next
;
1504 kfree(list_entry(element
, struct iwl4965_frame
, list
));
1505 priv
->frames_count
--;
1508 if (priv
->frames_count
) {
1509 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1510 priv
->frames_count
);
1511 priv
->frames_count
= 0;
1515 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl4965_priv
*priv
)
1517 struct iwl4965_frame
*frame
;
1518 struct list_head
*element
;
1519 if (list_empty(&priv
->free_frames
)) {
1520 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1522 IWL_ERROR("Could not allocate frame!\n");
1526 priv
->frames_count
++;
1530 element
= priv
->free_frames
.next
;
1532 return list_entry(element
, struct iwl4965_frame
, list
);
1535 static void iwl4965_free_frame(struct iwl4965_priv
*priv
, struct iwl4965_frame
*frame
)
1537 memset(frame
, 0, sizeof(*frame
));
1538 list_add(&frame
->list
, &priv
->free_frames
);
1541 unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv
*priv
,
1542 struct ieee80211_hdr
*hdr
,
1543 const u8
*dest
, int left
)
1546 if (!iwl4965_is_associated(priv
) || !priv
->ibss_beacon
||
1547 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1548 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1551 if (priv
->ibss_beacon
->len
> left
)
1554 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1556 return priv
->ibss_beacon
->len
;
1559 int iwl4965_rate_index_from_plcp(int plcp
)
1563 /* 4965 HT rate format */
1564 if (plcp
& RATE_MCS_HT_MSK
) {
1567 if (i
>= IWL_RATE_MIMO_6M_PLCP
)
1568 i
= i
- IWL_RATE_MIMO_6M_PLCP
;
1570 i
+= IWL_FIRST_OFDM_RATE
;
1571 /* skip 9M not supported in ht*/
1572 if (i
>= IWL_RATE_9M_INDEX
)
1574 if ((i
>= IWL_FIRST_OFDM_RATE
) &&
1575 (i
<= IWL_LAST_OFDM_RATE
))
1578 /* 4965 legacy rate format, search for match in table */
1580 for (i
= 0; i
< ARRAY_SIZE(iwl4965_rates
); i
++)
1581 if (iwl4965_rates
[i
].plcp
== (plcp
&0xFF))
1587 static u8
iwl4965_rate_get_lowest_plcp(int rate_mask
)
1591 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1592 i
= iwl4965_rates
[i
].next_ieee
) {
1593 if (rate_mask
& (1 << i
))
1594 return iwl4965_rates
[i
].plcp
;
1597 return IWL_RATE_INVALID
;
1600 static int iwl4965_send_beacon_cmd(struct iwl4965_priv
*priv
)
1602 struct iwl4965_frame
*frame
;
1603 unsigned int frame_size
;
1607 frame
= iwl4965_get_free_frame(priv
);
1610 IWL_ERROR("Could not obtain free frame buffer for beacon "
1615 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1616 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
&
1618 if (rate
== IWL_INVALID_RATE
)
1619 rate
= IWL_RATE_6M_PLCP
;
1621 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1622 if (rate
== IWL_INVALID_RATE
)
1623 rate
= IWL_RATE_1M_PLCP
;
1626 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
1628 rc
= iwl4965_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1631 iwl4965_free_frame(priv
, frame
);
1636 /******************************************************************************
1638 * EEPROM related functions
1640 ******************************************************************************/
1642 static void get_eeprom_mac(struct iwl4965_priv
*priv
, u8
*mac
)
1644 memcpy(mac
, priv
->eeprom
.mac_address
, 6);
1647 static inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv
*priv
)
1649 iwl4965_clear_bit(priv
, CSR_HW_IF_CONFIG_REG
,
1650 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM
);
1654 * iwl4965_eeprom_init - read EEPROM contents
1656 * Load the EEPROM contents from adapter into priv->eeprom
1658 * NOTE: This routine uses the non-debug IO access functions.
1660 int iwl4965_eeprom_init(struct iwl4965_priv
*priv
)
1662 u16
*e
= (u16
*)&priv
->eeprom
;
1663 u32 gp
= iwl4965_read32(priv
, CSR_EEPROM_GP
);
1665 int sz
= sizeof(priv
->eeprom
);
1670 /* The EEPROM structure has several padding buffers within it
1671 * and when adding new EEPROM maps is subject to programmer errors
1672 * which may be very difficult to identify without explicitly
1673 * checking the resulting size of the eeprom map. */
1674 BUILD_BUG_ON(sizeof(priv
->eeprom
) != IWL_EEPROM_IMAGE_SIZE
);
1676 if ((gp
& CSR_EEPROM_GP_VALID_MSK
) == CSR_EEPROM_GP_BAD_SIGNATURE
) {
1677 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp
);
1681 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
1682 rc
= iwl4965_eeprom_acquire_semaphore(priv
);
1684 IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
1688 /* eeprom is an array of 16bit values */
1689 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
1690 _iwl4965_write32(priv
, CSR_EEPROM_REG
, addr
<< 1);
1691 _iwl4965_clear_bit(priv
, CSR_EEPROM_REG
, CSR_EEPROM_REG_BIT_CMD
);
1693 for (i
= 0; i
< IWL_EEPROM_ACCESS_TIMEOUT
;
1694 i
+= IWL_EEPROM_ACCESS_DELAY
) {
1695 r
= _iwl4965_read_direct32(priv
, CSR_EEPROM_REG
);
1696 if (r
& CSR_EEPROM_REG_READ_VALID_MSK
)
1698 udelay(IWL_EEPROM_ACCESS_DELAY
);
1701 if (!(r
& CSR_EEPROM_REG_READ_VALID_MSK
)) {
1702 IWL_ERROR("Time out reading EEPROM[%d]", addr
);
1706 e
[addr
/ 2] = le16_to_cpu((__force __le16
)(r
>> 16));
1711 iwl4965_eeprom_release_semaphore(priv
);
1715 /******************************************************************************
1717 * Misc. internal state and helper functions
1719 ******************************************************************************/
1720 #ifdef CONFIG_IWL4965_DEBUG
1723 * iwl4965_report_frame - dump frame to syslog during debug sessions
1725 * You may hack this function to show different aspects of received frames,
1726 * including selective frame dumps.
1727 * group100 parameter selects whether to show 1 out of 100 good frames.
1729 * TODO: This was originally written for 3945, need to audit for
1730 * proper operation with 4965.
1732 void iwl4965_report_frame(struct iwl4965_priv
*priv
,
1733 struct iwl4965_rx_packet
*pkt
,
1734 struct ieee80211_hdr
*header
, int group100
)
1737 u32 print_summary
= 0;
1738 u32 print_dump
= 0; /* set to 1 to dump all frames' contents */
1755 struct iwl4965_rx_frame_stats
*rx_stats
= IWL_RX_STATS(pkt
);
1756 struct iwl4965_rx_frame_hdr
*rx_hdr
= IWL_RX_HDR(pkt
);
1757 struct iwl4965_rx_frame_end
*rx_end
= IWL_RX_END(pkt
);
1758 u8
*data
= IWL_RX_DATA(pkt
);
1761 fc
= le16_to_cpu(header
->frame_control
);
1762 seq_ctl
= le16_to_cpu(header
->seq_ctrl
);
1765 channel
= le16_to_cpu(rx_hdr
->channel
);
1766 phy_flags
= le16_to_cpu(rx_hdr
->phy_flags
);
1767 rate_sym
= rx_hdr
->rate
;
1768 length
= le16_to_cpu(rx_hdr
->len
);
1770 /* end-of-frame status and timestamp */
1771 status
= le32_to_cpu(rx_end
->status
);
1772 bcn_tmr
= le32_to_cpu(rx_end
->beacon_timestamp
);
1773 tsf_low
= le64_to_cpu(rx_end
->timestamp
) & 0x0ffffffff;
1774 tsf
= le64_to_cpu(rx_end
->timestamp
);
1776 /* signal statistics */
1777 rssi
= rx_stats
->rssi
;
1778 agc
= rx_stats
->agc
;
1779 sig_avg
= le16_to_cpu(rx_stats
->sig_avg
);
1780 noise_diff
= le16_to_cpu(rx_stats
->noise_diff
);
1782 to_us
= !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1784 /* if data frame is to us and all is good,
1785 * (optionally) print summary for only 1 out of every 100 */
1786 if (to_us
&& (fc
& ~IEEE80211_FCTL_PROTECTED
) ==
1787 (IEEE80211_FCTL_FROMDS
| IEEE80211_FTYPE_DATA
)) {
1790 print_summary
= 1; /* print each frame */
1791 else if (priv
->framecnt_to_us
< 100) {
1792 priv
->framecnt_to_us
++;
1795 priv
->framecnt_to_us
= 0;
1800 /* print summary for all other frames */
1804 if (print_summary
) {
1809 title
= "100Frames";
1810 else if (fc
& IEEE80211_FCTL_RETRY
)
1812 else if (ieee80211_is_assoc_response(fc
))
1814 else if (ieee80211_is_reassoc_response(fc
))
1816 else if (ieee80211_is_probe_response(fc
)) {
1818 print_dump
= 1; /* dump frame contents */
1819 } else if (ieee80211_is_beacon(fc
)) {
1821 print_dump
= 1; /* dump frame contents */
1822 } else if (ieee80211_is_atim(fc
))
1824 else if (ieee80211_is_auth(fc
))
1826 else if (ieee80211_is_deauth(fc
))
1828 else if (ieee80211_is_disassoc(fc
))
1833 rate
= iwl4965_rate_index_from_plcp(rate_sym
);
1837 rate
= iwl4965_rates
[rate
].ieee
/ 2;
1839 /* print frame summary.
1840 * MAC addresses show just the last byte (for brevity),
1841 * but you can hack it to show more, if you'd like to. */
1843 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1844 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1845 title
, fc
, header
->addr1
[5],
1846 length
, rssi
, channel
, rate
);
1848 /* src/dst addresses assume managed mode */
1849 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1850 "src=0x%02x, rssi=%u, tim=%lu usec, "
1851 "phy=0x%02x, chnl=%d\n",
1852 title
, fc
, header
->addr1
[5],
1853 header
->addr3
[5], rssi
,
1854 tsf_low
- priv
->scan_start_tsf
,
1855 phy_flags
, channel
);
1859 iwl4965_print_hex_dump(IWL_DL_RX
, data
, length
);
1863 static void iwl4965_unset_hw_setting(struct iwl4965_priv
*priv
)
1865 if (priv
->hw_setting
.shared_virt
)
1866 pci_free_consistent(priv
->pci_dev
,
1867 sizeof(struct iwl4965_shared
),
1868 priv
->hw_setting
.shared_virt
,
1869 priv
->hw_setting
.shared_phys
);
1873 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1875 * return : set the bit for each supported rate insert in ie
1877 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1878 u16 basic_rate
, int *left
)
1880 u16 ret_rates
= 0, bit
;
1885 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1886 if (bit
& supported_rate
) {
1888 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
1889 ((bit
& basic_rate
) ? 0x80 : 0x00);
1893 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1901 #ifdef CONFIG_IWL4965_HT
1902 void static iwl4965_set_ht_capab(struct ieee80211_hw
*hw
,
1903 struct ieee80211_ht_cap
*ht_cap
,
1904 u8 use_current_config
);
1908 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1910 static u16
iwl4965_fill_probe_req(struct iwl4965_priv
*priv
,
1911 struct ieee80211_mgmt
*frame
,
1912 int left
, int is_direct
)
1916 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1917 #ifdef CONFIG_IWL4965_HT
1918 struct ieee80211_hw_mode
*mode
;
1919 #endif /* CONFIG_IWL4965_HT */
1921 /* Make sure there is enough space for the probe request,
1922 * two mandatory IEs and the data */
1928 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1929 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1930 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1931 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1932 frame
->seq_ctrl
= 0;
1934 /* fill in our indirect SSID IE */
1941 pos
= &(frame
->u
.probe_req
.variable
[0]);
1942 *pos
++ = WLAN_EID_SSID
;
1945 /* fill in our direct SSID IE... */
1948 left
-= 2 + priv
->essid_len
;
1951 /* ... fill it in... */
1952 *pos
++ = WLAN_EID_SSID
;
1953 *pos
++ = priv
->essid_len
;
1954 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1955 pos
+= priv
->essid_len
;
1956 len
+= 2 + priv
->essid_len
;
1959 /* fill in supported rate */
1965 /* ... fill it in... */
1966 *pos
++ = WLAN_EID_SUPP_RATES
;
1969 /* exclude 60M rate */
1970 active_rates
= priv
->rates_mask
;
1971 active_rates
&= ~IWL_RATE_60M_MASK
;
1973 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1975 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1976 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1977 active_rate_basic
, &left
);
1978 active_rates
&= ~ret_rates
;
1980 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1981 active_rate_basic
, &left
);
1982 active_rates
&= ~ret_rates
;
1986 if (active_rates
== 0)
1989 /* fill in supported extended rate */
1994 /* ... fill it in... */
1995 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1997 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1998 active_rate_basic
, &left
);
2002 #ifdef CONFIG_IWL4965_HT
2003 mode
= priv
->hw
->conf
.mode
;
2004 if (mode
->ht_info
.ht_supported
) {
2006 *pos
++ = WLAN_EID_HT_CAPABILITY
;
2007 *pos
++ = sizeof(struct ieee80211_ht_cap
);
2008 iwl4965_set_ht_capab(priv
->hw
,
2009 (struct ieee80211_ht_cap
*)pos
, 0);
2010 len
+= 2 + sizeof(struct ieee80211_ht_cap
);
2012 #endif /*CONFIG_IWL4965_HT */
2021 #ifdef CONFIG_IWL4965_QOS
2022 static int iwl4965_send_qos_params_command(struct iwl4965_priv
*priv
,
2023 struct iwl4965_qosparam_cmd
*qos
)
2026 return iwl4965_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
2027 sizeof(struct iwl4965_qosparam_cmd
), qos
);
2030 static void iwl4965_reset_qos(struct iwl4965_priv
*priv
)
2036 unsigned long flags
;
2039 spin_lock_irqsave(&priv
->lock
, flags
);
2040 priv
->qos_data
.qos_active
= 0;
2042 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) {
2043 if (priv
->qos_data
.qos_enable
)
2044 priv
->qos_data
.qos_active
= 1;
2045 if (!(priv
->active_rate
& 0xfff0)) {
2049 } else if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2050 if (priv
->qos_data
.qos_enable
)
2051 priv
->qos_data
.qos_active
= 1;
2052 } else if (!(priv
->staging_rxon
.flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
2057 if (priv
->qos_data
.qos_active
)
2060 priv
->qos_data
.def_qos_parm
.ac
[0].cw_min
= cpu_to_le16(cw_min
);
2061 priv
->qos_data
.def_qos_parm
.ac
[0].cw_max
= cpu_to_le16(cw_max
);
2062 priv
->qos_data
.def_qos_parm
.ac
[0].aifsn
= aifs
;
2063 priv
->qos_data
.def_qos_parm
.ac
[0].edca_txop
= 0;
2064 priv
->qos_data
.def_qos_parm
.ac
[0].reserved1
= 0;
2066 if (priv
->qos_data
.qos_active
) {
2068 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
= cpu_to_le16(cw_min
);
2069 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
= cpu_to_le16(cw_max
);
2070 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 7;
2071 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
2072 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
2075 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
2076 cpu_to_le16((cw_min
+ 1) / 2 - 1);
2077 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
2078 cpu_to_le16(cw_max
);
2079 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
2081 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
2084 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
2086 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
2089 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
2090 cpu_to_le16((cw_min
+ 1) / 4 - 1);
2091 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
2092 cpu_to_le16((cw_max
+ 1) / 2 - 1);
2093 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
2094 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
2096 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
2099 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
2102 for (i
= 1; i
< 4; i
++) {
2103 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
2104 cpu_to_le16(cw_min
);
2105 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
2106 cpu_to_le16(cw_max
);
2107 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= aifs
;
2108 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
2109 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
2112 IWL_DEBUG_QOS("set QoS to default \n");
2114 spin_unlock_irqrestore(&priv
->lock
, flags
);
2117 static void iwl4965_activate_qos(struct iwl4965_priv
*priv
, u8 force
)
2119 unsigned long flags
;
2121 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2124 if (!priv
->qos_data
.qos_enable
)
2127 spin_lock_irqsave(&priv
->lock
, flags
);
2128 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
2130 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
2131 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
2132 priv
->qos_data
.def_qos_parm
.qos_flags
|=
2133 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
2134 if (priv
->qos_data
.qos_active
)
2135 priv
->qos_data
.def_qos_parm
.qos_flags
|=
2136 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
2138 #ifdef CONFIG_IWL4965_HT
2139 if (priv
->current_ht_config
.is_ht
)
2140 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
2141 #endif /* CONFIG_IWL4965_HT */
2143 spin_unlock_irqrestore(&priv
->lock
, flags
);
2145 if (force
|| iwl4965_is_associated(priv
)) {
2146 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
2147 priv
->qos_data
.qos_active
,
2148 priv
->qos_data
.def_qos_parm
.qos_flags
);
2150 iwl4965_send_qos_params_command(priv
,
2151 &(priv
->qos_data
.def_qos_parm
));
2155 #endif /* CONFIG_IWL4965_QOS */
2157 * Power management (not Tx power!) functions
2159 #define MSEC_TO_USEC 1024
2161 #define NOSLP __constant_cpu_to_le16(0), 0, 0
2162 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
2163 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2164 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2165 __constant_cpu_to_le32(X1), \
2166 __constant_cpu_to_le32(X2), \
2167 __constant_cpu_to_le32(X3), \
2168 __constant_cpu_to_le32(X4)}
2171 /* default power management (not Tx power) table values */
2173 static struct iwl4965_power_vec_entry range_0
[IWL_POWER_AC
] = {
2174 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2175 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2176 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2177 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2178 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2179 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2183 static struct iwl4965_power_vec_entry range_1
[IWL_POWER_AC
] = {
2184 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2185 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2186 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2187 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2188 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2189 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2190 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2191 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2192 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2193 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2196 int iwl4965_power_init_handle(struct iwl4965_priv
*priv
)
2199 struct iwl4965_power_mgr
*pow_data
;
2200 int size
= sizeof(struct iwl4965_power_vec_entry
) * IWL_POWER_AC
;
2203 IWL_DEBUG_POWER("Initialize power \n");
2205 pow_data
= &(priv
->power_data
);
2207 memset(pow_data
, 0, sizeof(*pow_data
));
2209 pow_data
->active_index
= IWL_POWER_RANGE_0
;
2210 pow_data
->dtim_val
= 0xffff;
2212 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
2213 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
2215 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
2219 struct iwl4965_powertable_cmd
*cmd
;
2221 IWL_DEBUG_POWER("adjust power command flags\n");
2223 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
2224 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
2227 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
2229 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
2235 static int iwl4965_update_power_cmd(struct iwl4965_priv
*priv
,
2236 struct iwl4965_powertable_cmd
*cmd
, u32 mode
)
2241 struct iwl4965_power_vec_entry
*range
;
2243 struct iwl4965_power_mgr
*pow_data
;
2245 if (mode
> IWL_POWER_INDEX_5
) {
2246 IWL_DEBUG_POWER("Error invalid power mode \n");
2249 pow_data
= &(priv
->power_data
);
2251 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
2252 range
= &pow_data
->pwr_range_0
[0];
2254 range
= &pow_data
->pwr_range_1
[1];
2256 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl4965_powertable_cmd
));
2258 #ifdef IWL_MAC80211_DISABLE
2259 if (priv
->assoc_network
!= NULL
) {
2260 unsigned long flags
;
2262 period
= priv
->assoc_network
->tim
.tim_period
;
2264 #endif /*IWL_MAC80211_DISABLE */
2265 skip
= range
[mode
].no_dtim
;
2274 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
2276 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
2277 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
2278 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
2281 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
2282 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
2283 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
2286 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
2287 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
2288 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
2289 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2290 le32_to_cpu(cmd
->sleep_interval
[0]),
2291 le32_to_cpu(cmd
->sleep_interval
[1]),
2292 le32_to_cpu(cmd
->sleep_interval
[2]),
2293 le32_to_cpu(cmd
->sleep_interval
[3]),
2294 le32_to_cpu(cmd
->sleep_interval
[4]));
2299 static int iwl4965_send_power_mode(struct iwl4965_priv
*priv
, u32 mode
)
2301 u32
uninitialized_var(final_mode
);
2303 struct iwl4965_powertable_cmd cmd
;
2305 /* If on battery, set to 3,
2306 * if plugged into AC power, set to CAM ("continuously aware mode"),
2307 * else user level */
2309 case IWL_POWER_BATTERY
:
2310 final_mode
= IWL_POWER_INDEX_3
;
2313 final_mode
= IWL_POWER_MODE_CAM
;
2320 cmd
.keep_alive_beacons
= 0;
2322 iwl4965_update_power_cmd(priv
, &cmd
, final_mode
);
2324 rc
= iwl4965_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
2326 if (final_mode
== IWL_POWER_MODE_CAM
)
2327 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
2329 set_bit(STATUS_POWER_PMI
, &priv
->status
);
2334 int iwl4965_is_network_packet(struct iwl4965_priv
*priv
, struct ieee80211_hdr
*header
)
2336 /* Filter incoming packets to determine if they are targeted toward
2337 * this network, discarding packets coming from ourselves */
2338 switch (priv
->iw_mode
) {
2339 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
2340 /* packets from our adapter are dropped (echo) */
2341 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
2343 /* {broad,multi}cast packets to our IBSS go through */
2344 if (is_multicast_ether_addr(header
->addr1
))
2345 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
2346 /* packets to our adapter go through */
2347 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
2348 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
2349 /* packets from our adapter are dropped (echo) */
2350 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
2352 /* {broad,multi}cast packets to our BSS go through */
2353 if (is_multicast_ether_addr(header
->addr1
))
2354 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
2355 /* packets to our adapter go through */
2356 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
2362 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2364 static const char *iwl4965_get_tx_fail_reason(u32 status
)
2366 switch (status
& TX_STATUS_MSK
) {
2367 case TX_STATUS_SUCCESS
:
2369 TX_STATUS_ENTRY(SHORT_LIMIT
);
2370 TX_STATUS_ENTRY(LONG_LIMIT
);
2371 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
2372 TX_STATUS_ENTRY(MGMNT_ABORT
);
2373 TX_STATUS_ENTRY(NEXT_FRAG
);
2374 TX_STATUS_ENTRY(LIFE_EXPIRE
);
2375 TX_STATUS_ENTRY(DEST_PS
);
2376 TX_STATUS_ENTRY(ABORTED
);
2377 TX_STATUS_ENTRY(BT_RETRY
);
2378 TX_STATUS_ENTRY(STA_INVALID
);
2379 TX_STATUS_ENTRY(FRAG_DROPPED
);
2380 TX_STATUS_ENTRY(TID_DISABLE
);
2381 TX_STATUS_ENTRY(FRAME_FLUSHED
);
2382 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
2383 TX_STATUS_ENTRY(TX_LOCKED
);
2384 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
2391 * iwl4965_scan_cancel - Cancel any currently executing HW scan
2393 * NOTE: priv->mutex is not required before calling this function
2395 static int iwl4965_scan_cancel(struct iwl4965_priv
*priv
)
2397 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
2398 clear_bit(STATUS_SCANNING
, &priv
->status
);
2402 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2403 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2404 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2405 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
2406 queue_work(priv
->workqueue
, &priv
->abort_scan
);
2409 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2411 return test_bit(STATUS_SCANNING
, &priv
->status
);
2418 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
2419 * @ms: amount of time to wait (in milliseconds) for scan to abort
2421 * NOTE: priv->mutex must be held before calling this function
2423 static int iwl4965_scan_cancel_timeout(struct iwl4965_priv
*priv
, unsigned long ms
)
2425 unsigned long now
= jiffies
;
2428 ret
= iwl4965_scan_cancel(priv
);
2430 mutex_unlock(&priv
->mutex
);
2431 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
2432 test_bit(STATUS_SCANNING
, &priv
->status
))
2434 mutex_lock(&priv
->mutex
);
2436 return test_bit(STATUS_SCANNING
, &priv
->status
);
2442 static void iwl4965_sequence_reset(struct iwl4965_priv
*priv
)
2444 /* Reset ieee stats */
2446 /* We don't reset the net_device_stats (ieee->stats) on
2449 priv
->last_seq_num
= -1;
2450 priv
->last_frag_num
= -1;
2451 priv
->last_packet_time
= 0;
2453 iwl4965_scan_cancel(priv
);
2456 #define MAX_UCODE_BEACON_INTERVAL 4096
2457 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2459 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
2462 u16 beacon_factor
= 0;
2465 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
2466 / MAX_UCODE_BEACON_INTERVAL
;
2467 new_val
= beacon_val
/ beacon_factor
;
2469 return cpu_to_le16(new_val
);
2472 static void iwl4965_setup_rxon_timing(struct iwl4965_priv
*priv
)
2474 u64 interval_tm_unit
;
2476 unsigned long flags
;
2477 struct ieee80211_conf
*conf
= NULL
;
2480 conf
= ieee80211_get_hw_conf(priv
->hw
);
2482 spin_lock_irqsave(&priv
->lock
, flags
);
2483 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp1
);
2484 priv
->rxon_timing
.timestamp
.dw
[0] = cpu_to_le32(priv
->timestamp0
);
2486 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
2488 tsf
= priv
->timestamp1
;
2489 tsf
= ((tsf
<< 32) | priv
->timestamp0
);
2491 beacon_int
= priv
->beacon_int
;
2492 spin_unlock_irqrestore(&priv
->lock
, flags
);
2494 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
2495 if (beacon_int
== 0) {
2496 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
2497 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
2499 priv
->rxon_timing
.beacon_interval
=
2500 cpu_to_le16(beacon_int
);
2501 priv
->rxon_timing
.beacon_interval
=
2502 iwl4965_adjust_beacon_interval(
2503 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2506 priv
->rxon_timing
.atim_window
= 0;
2508 priv
->rxon_timing
.beacon_interval
=
2509 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
2510 /* TODO: we need to get atim_window from upper stack
2511 * for now we set to 0 */
2512 priv
->rxon_timing
.atim_window
= 0;
2516 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
2517 result
= do_div(tsf
, interval_tm_unit
);
2518 priv
->rxon_timing
.beacon_init_val
=
2519 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
2522 ("beacon interval %d beacon timer %d beacon tim %d\n",
2523 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
2524 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
2525 le16_to_cpu(priv
->rxon_timing
.atim_window
));
2528 static int iwl4965_scan_initiate(struct iwl4965_priv
*priv
)
2530 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2531 IWL_ERROR("APs don't scan.\n");
2535 if (!iwl4965_is_ready_rf(priv
)) {
2536 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2540 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2541 IWL_DEBUG_SCAN("Scan already in progress.\n");
2545 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2546 IWL_DEBUG_SCAN("Scan request while abort pending. "
2551 IWL_DEBUG_INFO("Starting scan...\n");
2552 priv
->scan_bands
= 2;
2553 set_bit(STATUS_SCANNING
, &priv
->status
);
2554 priv
->scan_start
= jiffies
;
2555 priv
->scan_pass_start
= priv
->scan_start
;
2557 queue_work(priv
->workqueue
, &priv
->request_scan
);
2562 static int iwl4965_set_rxon_hwcrypto(struct iwl4965_priv
*priv
, int hw_decrypt
)
2564 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
2567 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
2569 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
2574 static void iwl4965_set_flags_for_phymode(struct iwl4965_priv
*priv
, u8 phymode
)
2576 if (phymode
== MODE_IEEE80211A
) {
2577 priv
->staging_rxon
.flags
&=
2578 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
2579 | RXON_FLG_CCK_MSK
);
2580 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2582 /* Copied from iwl4965_bg_post_associate() */
2583 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2584 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2586 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2588 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2589 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2591 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
2592 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
2593 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
2598 * initialize rxon structure with default values from eeprom
2600 static void iwl4965_connection_init_rx_config(struct iwl4965_priv
*priv
)
2602 const struct iwl4965_channel_info
*ch_info
;
2604 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
2606 switch (priv
->iw_mode
) {
2607 case IEEE80211_IF_TYPE_AP
:
2608 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
2611 case IEEE80211_IF_TYPE_STA
:
2612 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2613 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2616 case IEEE80211_IF_TYPE_IBSS
:
2617 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2618 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2619 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2620 RXON_FILTER_ACCEPT_GRP_MSK
;
2623 case IEEE80211_IF_TYPE_MNTR
:
2624 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2625 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2626 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2631 /* TODO: Figure out when short_preamble would be set and cache from
2633 if (!hw_to_local(priv
->hw
)->short_preamble
)
2634 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2636 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2639 ch_info
= iwl4965_get_channel_info(priv
, priv
->phymode
,
2640 le16_to_cpu(priv
->staging_rxon
.channel
));
2643 ch_info
= &priv
->channel_info
[0];
2646 * in some case A channels are all non IBSS
2647 * in this case force B/G channel
2649 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
2650 !(is_channel_ibss(ch_info
)))
2651 ch_info
= &priv
->channel_info
[0];
2653 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2654 if (is_channel_a_band(ch_info
))
2655 priv
->phymode
= MODE_IEEE80211A
;
2657 priv
->phymode
= MODE_IEEE80211G
;
2659 iwl4965_set_flags_for_phymode(priv
, priv
->phymode
);
2661 priv
->staging_rxon
.ofdm_basic_rates
=
2662 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2663 priv
->staging_rxon
.cck_basic_rates
=
2664 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2666 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
2667 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
2668 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2669 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
2670 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
2671 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
2672 iwl4965_set_rxon_chain(priv
);
2675 static int iwl4965_set_mode(struct iwl4965_priv
*priv
, int mode
)
2677 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
2678 const struct iwl4965_channel_info
*ch_info
;
2680 ch_info
= iwl4965_get_channel_info(priv
,
2682 le16_to_cpu(priv
->staging_rxon
.channel
));
2684 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2685 IWL_ERROR("channel %d not IBSS channel\n",
2686 le16_to_cpu(priv
->staging_rxon
.channel
));
2691 priv
->iw_mode
= mode
;
2693 iwl4965_connection_init_rx_config(priv
);
2694 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2696 iwl4965_clear_stations_table(priv
);
2698 /* dont commit rxon if rf-kill is on*/
2699 if (!iwl4965_is_ready_rf(priv
))
2702 cancel_delayed_work(&priv
->scan_check
);
2703 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
2704 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2705 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2709 iwl4965_commit_rxon(priv
);
2714 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv
*priv
,
2715 struct ieee80211_tx_control
*ctl
,
2716 struct iwl4965_cmd
*cmd
,
2717 struct sk_buff
*skb_frag
,
2720 struct iwl4965_hw_key
*keyinfo
= &priv
->stations
[ctl
->key_idx
].keyinfo
;
2722 switch (keyinfo
->alg
) {
2724 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2725 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2726 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2731 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2734 memcpy(cmd
->cmd
.tx
.tkip_mic
.byte
, skb_frag
->tail
- 8,
2737 memset(cmd
->cmd
.tx
.tkip_mic
.byte
, 0, 8);
2742 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_WEP
|
2743 (ctl
->key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
2745 if (keyinfo
->keylen
== 13)
2746 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2748 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
, keyinfo
->keylen
);
2750 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2751 "with key %d\n", ctl
->key_idx
);
2755 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2761 * handle build REPLY_TX command notification.
2763 static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv
*priv
,
2764 struct iwl4965_cmd
*cmd
,
2765 struct ieee80211_tx_control
*ctrl
,
2766 struct ieee80211_hdr
*hdr
,
2767 int is_unicast
, u8 std_id
)
2770 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2771 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2773 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2774 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2775 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2776 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2777 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2778 if (ieee80211_is_probe_response(fc
) &&
2779 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2780 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2782 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2783 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2786 if (ieee80211_is_back_request(fc
))
2787 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
2790 cmd
->cmd
.tx
.sta_id
= std_id
;
2791 if (ieee80211_get_morefrag(hdr
))
2792 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2794 qc
= ieee80211_get_qos_ctrl(hdr
);
2796 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2797 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2799 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2801 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2802 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2803 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2804 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2805 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2806 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2809 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2810 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2812 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2813 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2814 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2815 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2816 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2818 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2820 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2822 cmd
->cmd
.tx
.driver_txop
= 0;
2823 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2824 cmd
->cmd
.tx
.next_frame_len
= 0;
2828 * iwl4965_get_sta_id - Find station's index within station table
2830 * If new IBSS station, create new entry in station table
2832 static int iwl4965_get_sta_id(struct iwl4965_priv
*priv
,
2833 struct ieee80211_hdr
*hdr
)
2836 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2837 DECLARE_MAC_BUF(mac
);
2839 /* If this frame is broadcast or management, use broadcast station id */
2840 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2841 is_multicast_ether_addr(hdr
->addr1
))
2842 return priv
->hw_setting
.bcast_sta_id
;
2844 switch (priv
->iw_mode
) {
2846 /* If we are a client station in a BSS network, use the special
2847 * AP station entry (that's the only station we communicate with) */
2848 case IEEE80211_IF_TYPE_STA
:
2851 /* If we are an AP, then find the station, or use BCAST */
2852 case IEEE80211_IF_TYPE_AP
:
2853 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2854 if (sta_id
!= IWL_INVALID_STATION
)
2856 return priv
->hw_setting
.bcast_sta_id
;
2858 /* If this frame is going out to an IBSS network, find the station,
2859 * or create a new station table entry */
2860 case IEEE80211_IF_TYPE_IBSS
:
2861 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2862 if (sta_id
!= IWL_INVALID_STATION
)
2865 /* Create new station table entry */
2866 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
2867 0, CMD_ASYNC
, NULL
);
2869 if (sta_id
!= IWL_INVALID_STATION
)
2872 IWL_DEBUG_DROP("Station %s not in station map. "
2873 "Defaulting to broadcast...\n",
2874 print_mac(mac
, hdr
->addr1
));
2875 iwl4965_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2876 return priv
->hw_setting
.bcast_sta_id
;
2879 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
2880 return priv
->hw_setting
.bcast_sta_id
;
2885 * start REPLY_TX command process
2887 static int iwl4965_tx_skb(struct iwl4965_priv
*priv
,
2888 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2890 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2891 struct iwl4965_tfd_frame
*tfd
;
2893 int txq_id
= ctl
->queue
;
2894 struct iwl4965_tx_queue
*txq
= NULL
;
2895 struct iwl4965_queue
*q
= NULL
;
2896 dma_addr_t phys_addr
;
2897 dma_addr_t txcmd_phys
;
2898 dma_addr_t scratch_phys
;
2899 struct iwl4965_cmd
*out_cmd
= NULL
;
2900 u16 len
, idx
, len_org
;
2901 u8 id
, hdr_len
, unicast
;
2906 u8 wait_write_ptr
= 0;
2907 unsigned long flags
;
2910 spin_lock_irqsave(&priv
->lock
, flags
);
2911 if (iwl4965_is_rfkill(priv
)) {
2912 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2917 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2921 if ((ctl
->tx_rate
& 0xFF) == IWL_INVALID_RATE
) {
2922 IWL_ERROR("ERROR: No TX rate available.\n");
2926 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2929 fc
= le16_to_cpu(hdr
->frame_control
);
2931 #ifdef CONFIG_IWL4965_DEBUG
2932 if (ieee80211_is_auth(fc
))
2933 IWL_DEBUG_TX("Sending AUTH frame\n");
2934 else if (ieee80211_is_assoc_request(fc
))
2935 IWL_DEBUG_TX("Sending ASSOC frame\n");
2936 else if (ieee80211_is_reassoc_request(fc
))
2937 IWL_DEBUG_TX("Sending REASSOC frame\n");
2940 /* drop all data frame if we are not associated */
2941 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
2942 (!iwl4965_is_associated(priv
) ||
2943 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
2944 !priv
->assoc_station_added
)) {
2945 IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n");
2949 spin_unlock_irqrestore(&priv
->lock
, flags
);
2951 hdr_len
= ieee80211_get_hdrlen(fc
);
2953 /* Find (or create) index into station table for destination station */
2954 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
2955 if (sta_id
== IWL_INVALID_STATION
) {
2956 DECLARE_MAC_BUF(mac
);
2958 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2959 print_mac(mac
, hdr
->addr1
));
2963 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2965 qc
= ieee80211_get_qos_ctrl(hdr
);
2967 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2968 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2970 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2972 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2974 #ifdef CONFIG_IWL4965_HT
2975 /* aggregation is on for this <sta,tid> */
2976 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2977 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
2978 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
2979 #endif /* CONFIG_IWL4965_HT */
2982 /* Descriptor for chosen Tx queue */
2983 txq
= &priv
->txq
[txq_id
];
2986 spin_lock_irqsave(&priv
->lock
, flags
);
2988 /* Set up first empty TFD within this queue's circular TFD buffer */
2989 tfd
= &txq
->bd
[q
->write_ptr
];
2990 memset(tfd
, 0, sizeof(*tfd
));
2991 control_flags
= (u32
*) tfd
;
2992 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2994 /* Set up driver data for this TFD */
2995 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
2996 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2997 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2998 ctl
, sizeof(struct ieee80211_tx_control
));
3000 /* Set up first empty entry in queue's array of Tx/cmd buffers */
3001 out_cmd
= &txq
->cmd
[idx
];
3002 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
3003 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
3006 * Set up the Tx-command (not MAC!) header.
3007 * Store the chosen Tx queue and TFD index within the sequence field;
3008 * after Tx, uCode's Tx response will return this value so driver can
3009 * locate the frame within the tx queue and do post-tx processing.
3011 out_cmd
->hdr
.cmd
= REPLY_TX
;
3012 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
3013 INDEX_TO_SEQ(q
->write_ptr
)));
3015 /* Copy MAC header from skb into command buffer */
3016 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
3019 * Use the first empty entry in this queue's command buffer array
3020 * to contain the Tx command and MAC header concatenated together
3021 * (payload data will be in another buffer).
3022 * Size of this varies, due to varying MAC header length.
3023 * If end is not dword aligned, we'll have 2 extra bytes at the end
3024 * of the MAC header (device reads on dword boundaries).
3025 * We'll tell device about this padding later.
3027 len
= priv
->hw_setting
.tx_cmd_len
+
3028 sizeof(struct iwl4965_cmd_header
) + hdr_len
;
3031 len
= (len
+ 3) & ~3;
3038 /* Physical address of this Tx command's header (not MAC header!),
3039 * within command buffer array. */
3040 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl4965_cmd
) * idx
+
3041 offsetof(struct iwl4965_cmd
, hdr
);
3043 /* Add buffer containing Tx command and MAC(!) header to TFD's
3045 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
3047 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
3048 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, 0);
3050 /* Set up TFD's 2nd entry to point directly to remainder of skb,
3051 * if any (802.11 null frames have no payload). */
3052 len
= skb
->len
- hdr_len
;
3054 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
3055 len
, PCI_DMA_TODEVICE
);
3056 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
3059 /* Tell 4965 about any 2-byte padding after MAC header */
3061 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
3063 /* Total # bytes to be transmitted */
3064 len
= (u16
)skb
->len
;
3065 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
3067 /* TODO need this for burst mode later on */
3068 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
3070 /* set is_hcca to 0; it probably will never be implemented */
3071 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
3073 scratch_phys
= txcmd_phys
+ sizeof(struct iwl4965_cmd_header
) +
3074 offsetof(struct iwl4965_tx_cmd
, scratch
);
3075 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
3076 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
3078 if (!ieee80211_get_morefrag(hdr
)) {
3079 txq
->need_update
= 1;
3081 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
3082 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
3086 txq
->need_update
= 0;
3089 iwl4965_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
3090 sizeof(out_cmd
->cmd
.tx
));
3092 iwl4965_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
3093 ieee80211_get_hdrlen(fc
));
3095 /* Set up entry for this TFD in Tx byte-count array */
3096 iwl4965_tx_queue_update_wr_ptr(priv
, txq
, len
);
3098 /* Tell device the write index *just past* this latest filled TFD */
3099 q
->write_ptr
= iwl4965_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
3100 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
3101 spin_unlock_irqrestore(&priv
->lock
, flags
);
3106 if ((iwl4965_queue_space(q
) < q
->high_mark
)
3107 && priv
->mac80211_registered
) {
3108 if (wait_write_ptr
) {
3109 spin_lock_irqsave(&priv
->lock
, flags
);
3110 txq
->need_update
= 1;
3111 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
3112 spin_unlock_irqrestore(&priv
->lock
, flags
);
3115 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
3121 spin_unlock_irqrestore(&priv
->lock
, flags
);
3126 static void iwl4965_set_rate(struct iwl4965_priv
*priv
)
3128 const struct ieee80211_hw_mode
*hw
= NULL
;
3129 struct ieee80211_rate
*rate
;
3132 hw
= iwl4965_get_hw_mode(priv
, priv
->phymode
);
3134 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
3138 priv
->active_rate
= 0;
3139 priv
->active_rate_basic
= 0;
3141 IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
3142 hw
->mode
== MODE_IEEE80211A
?
3143 'a' : ((hw
->mode
== MODE_IEEE80211B
) ? 'b' : 'g'));
3145 for (i
= 0; i
< hw
->num_rates
; i
++) {
3146 rate
= &(hw
->rates
[i
]);
3147 if ((rate
->val
< IWL_RATE_COUNT
) &&
3148 (rate
->flags
& IEEE80211_RATE_SUPPORTED
)) {
3149 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
3150 rate
->val
, iwl4965_rates
[rate
->val
].plcp
,
3151 (rate
->flags
& IEEE80211_RATE_BASIC
) ?
3153 priv
->active_rate
|= (1 << rate
->val
);
3154 if (rate
->flags
& IEEE80211_RATE_BASIC
)
3155 priv
->active_rate_basic
|= (1 << rate
->val
);
3157 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
3158 rate
->val
, iwl4965_rates
[rate
->val
].plcp
);
3161 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
3162 priv
->active_rate
, priv
->active_rate_basic
);
3165 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
3166 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
3169 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
3170 priv
->staging_rxon
.cck_basic_rates
=
3171 ((priv
->active_rate_basic
&
3172 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
3174 priv
->staging_rxon
.cck_basic_rates
=
3175 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
3177 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
3178 priv
->staging_rxon
.ofdm_basic_rates
=
3179 ((priv
->active_rate_basic
&
3180 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
3181 IWL_FIRST_OFDM_RATE
) & 0xFF;
3183 priv
->staging_rxon
.ofdm_basic_rates
=
3184 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
3187 static void iwl4965_radio_kill_sw(struct iwl4965_priv
*priv
, int disable_radio
)
3189 unsigned long flags
;
3191 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
3194 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
3195 disable_radio
? "OFF" : "ON");
3197 if (disable_radio
) {
3198 iwl4965_scan_cancel(priv
);
3199 /* FIXME: This is a workaround for AP */
3200 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
3201 spin_lock_irqsave(&priv
->lock
, flags
);
3202 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3203 CSR_UCODE_SW_BIT_RFKILL
);
3204 spin_unlock_irqrestore(&priv
->lock
, flags
);
3205 iwl4965_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
3206 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3211 spin_lock_irqsave(&priv
->lock
, flags
);
3212 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
3214 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3215 spin_unlock_irqrestore(&priv
->lock
, flags
);
3220 spin_lock_irqsave(&priv
->lock
, flags
);
3221 iwl4965_read32(priv
, CSR_UCODE_DRV_GP1
);
3222 if (!iwl4965_grab_nic_access(priv
))
3223 iwl4965_release_nic_access(priv
);
3224 spin_unlock_irqrestore(&priv
->lock
, flags
);
3226 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
3227 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3228 "disabled by HW switch\n");
3232 queue_work(priv
->workqueue
, &priv
->restart
);
3236 void iwl4965_set_decrypted_flag(struct iwl4965_priv
*priv
, struct sk_buff
*skb
,
3237 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
3240 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
3242 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
3245 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
3248 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
3249 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
3250 case RX_RES_STATUS_SEC_TYPE_TKIP
:
3251 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
3252 RX_RES_STATUS_BAD_ICV_MIC
)
3253 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
3254 case RX_RES_STATUS_SEC_TYPE_WEP
:
3255 case RX_RES_STATUS_SEC_TYPE_CCMP
:
3256 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
3257 RX_RES_STATUS_DECRYPT_OK
) {
3258 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3259 stats
->flag
|= RX_FLAG_DECRYPTED
;
3269 #define IWL_PACKET_RETRY_TIME HZ
3271 int iwl4965_is_duplicate_packet(struct iwl4965_priv
*priv
, struct ieee80211_hdr
*header
)
3273 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
3274 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
3275 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
3276 u16
*last_seq
, *last_frag
;
3277 unsigned long *last_time
;
3279 switch (priv
->iw_mode
) {
3280 case IEEE80211_IF_TYPE_IBSS
:{
3281 struct list_head
*p
;
3282 struct iwl4965_ibss_seq
*entry
= NULL
;
3283 u8
*mac
= header
->addr2
;
3284 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
3286 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
3287 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
3288 if (!compare_ether_addr(entry
->mac
, mac
))
3291 if (p
== &priv
->ibss_mac_hash
[index
]) {
3292 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
3294 IWL_ERROR("Cannot malloc new mac entry\n");
3297 memcpy(entry
->mac
, mac
, ETH_ALEN
);
3298 entry
->seq_num
= seq
;
3299 entry
->frag_num
= frag
;
3300 entry
->packet_time
= jiffies
;
3301 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
3304 last_seq
= &entry
->seq_num
;
3305 last_frag
= &entry
->frag_num
;
3306 last_time
= &entry
->packet_time
;
3309 case IEEE80211_IF_TYPE_STA
:
3310 last_seq
= &priv
->last_seq_num
;
3311 last_frag
= &priv
->last_frag_num
;
3312 last_time
= &priv
->last_packet_time
;
3317 if ((*last_seq
== seq
) &&
3318 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
3319 if (*last_frag
== frag
)
3321 if (*last_frag
+ 1 != frag
)
3322 /* out-of-order fragment */
3328 *last_time
= jiffies
;
3335 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3337 #include "iwl-spectrum.h"
3339 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
3340 #define BEACON_TIME_MASK_HIGH 0xFF000000
3341 #define TIME_UNIT 1024
3344 * extended beacon time format
3345 * time in usec will be changed into a 32-bit value in 8:24 format
3346 * the high 1 byte is the beacon counts
3347 * the lower 3 bytes is the time in usec within one beacon interval
3350 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
3354 u32 interval
= beacon_interval
* 1024;
3356 if (!interval
|| !usec
)
3359 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
3360 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
3362 return (quot
<< 24) + rem
;
3365 /* base is usually what we get from ucode with each received frame,
3366 * the same as HW timer counter counting down
3369 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
3371 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
3372 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
3373 u32 interval
= beacon_interval
* TIME_UNIT
;
3374 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
3375 (addon
& BEACON_TIME_MASK_HIGH
);
3377 if (base_low
> addon_low
)
3378 res
+= base_low
- addon_low
;
3379 else if (base_low
< addon_low
) {
3380 res
+= interval
+ base_low
- addon_low
;
3385 return cpu_to_le32(res
);
3388 static int iwl4965_get_measurement(struct iwl4965_priv
*priv
,
3389 struct ieee80211_measurement_params
*params
,
3392 struct iwl4965_spectrum_cmd spectrum
;
3393 struct iwl4965_rx_packet
*res
;
3394 struct iwl4965_host_cmd cmd
= {
3395 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
3396 .data
= (void *)&spectrum
,
3397 .meta
.flags
= CMD_WANT_SKB
,
3399 u32 add_time
= le64_to_cpu(params
->start_time
);
3401 int spectrum_resp_status
;
3402 int duration
= le16_to_cpu(params
->duration
);
3404 if (iwl4965_is_associated(priv
))
3406 iwl4965_usecs_to_beacons(
3407 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
3408 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
3410 memset(&spectrum
, 0, sizeof(spectrum
));
3412 spectrum
.channel_count
= cpu_to_le16(1);
3414 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
3415 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
3416 cmd
.len
= sizeof(spectrum
);
3417 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
3419 if (iwl4965_is_associated(priv
))
3420 spectrum
.start_time
=
3421 iwl4965_add_beacon_time(priv
->last_beacon_time
,
3423 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
3425 spectrum
.start_time
= 0;
3427 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
3428 spectrum
.channels
[0].channel
= params
->channel
;
3429 spectrum
.channels
[0].type
= type
;
3430 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
3431 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
3432 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
3434 rc
= iwl4965_send_cmd_sync(priv
, &cmd
);
3438 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
3439 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
3440 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3444 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
3445 switch (spectrum_resp_status
) {
3446 case 0: /* Command will be handled */
3447 if (res
->u
.spectrum
.id
!= 0xff) {
3449 ("Replaced existing measurement: %d\n",
3450 res
->u
.spectrum
.id
);
3451 priv
->measurement_status
&= ~MEASUREMENT_READY
;
3453 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
3457 case 1: /* Command will not be handled */
3462 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
3468 static void iwl4965_txstatus_to_ieee(struct iwl4965_priv
*priv
,
3469 struct iwl4965_tx_info
*tx_sta
)
3472 tx_sta
->status
.ack_signal
= 0;
3473 tx_sta
->status
.excessive_retries
= 0;
3474 tx_sta
->status
.queue_length
= 0;
3475 tx_sta
->status
.queue_number
= 0;
3478 ieee80211_tx_status_irqsafe(priv
->hw
,
3479 tx_sta
->skb
[0], &(tx_sta
->status
));
3481 ieee80211_tx_status(priv
->hw
,
3482 tx_sta
->skb
[0], &(tx_sta
->status
));
3484 tx_sta
->skb
[0] = NULL
;
3488 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
3490 * When FW advances 'R' index, all entries between old and new 'R' index
3491 * need to be reclaimed. As result, some free space forms. If there is
3492 * enough free space (> low mark), wake the stack that feeds us.
3494 int iwl4965_tx_queue_reclaim(struct iwl4965_priv
*priv
, int txq_id
, int index
)
3496 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
3497 struct iwl4965_queue
*q
= &txq
->q
;
3500 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
3501 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3502 "is out of range [0-%d] %d %d.\n", txq_id
,
3503 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
3507 for (index
= iwl4965_queue_inc_wrap(index
, q
->n_bd
);
3508 q
->read_ptr
!= index
;
3509 q
->read_ptr
= iwl4965_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
3510 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
3511 iwl4965_txstatus_to_ieee(priv
,
3512 &(txq
->txb
[txq
->q
.read_ptr
]));
3513 iwl4965_hw_txq_free_tfd(priv
, txq
);
3514 } else if (nfreed
> 1) {
3515 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
3516 q
->write_ptr
, q
->read_ptr
);
3517 queue_work(priv
->workqueue
, &priv
->restart
);
3522 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
3523 (txq_id != IWL_CMD_QUEUE_NUM) &&
3524 priv->mac80211_registered)
3525 ieee80211_wake_queue(priv->hw, txq_id); */
3531 static int iwl4965_is_tx_success(u32 status
)
3533 status
&= TX_STATUS_MSK
;
3534 return (status
== TX_STATUS_SUCCESS
)
3535 || (status
== TX_STATUS_DIRECT_DONE
);
3538 /******************************************************************************
3540 * Generic RX handler implementations
3542 ******************************************************************************/
3543 #ifdef CONFIG_IWL4965_HT
3545 static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv
*priv
,
3546 struct ieee80211_hdr
*hdr
)
3548 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
3551 u8
*da
= ieee80211_get_DA(hdr
);
3552 return iwl4965_hw_find_station(priv
, da
);
3556 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
3557 struct iwl4965_priv
*priv
, int txq_id
, int idx
)
3559 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
3560 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
3561 txb
[idx
].skb
[0]->data
;
3565 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
3567 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
3568 tx_resp
->frame_count
);
3569 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
3574 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3576 static int iwl4965_tx_status_reply_tx(struct iwl4965_priv
*priv
,
3577 struct iwl4965_ht_agg
*agg
,
3578 struct iwl4965_tx_resp_agg
*tx_resp
,
3582 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
3583 struct ieee80211_tx_status
*tx_status
= NULL
;
3584 struct ieee80211_hdr
*hdr
= NULL
;
3589 if (agg
->wait_for_ba
)
3590 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3592 agg
->frame_count
= tx_resp
->frame_count
;
3593 agg
->start_idx
= start_idx
;
3594 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
3597 /* # frames attempted by Tx command */
3598 if (agg
->frame_count
== 1) {
3599 /* Only one frame was attempted; no block-ack will arrive */
3600 status
= le16_to_cpu(frame_status
[0].status
);
3601 seq
= le16_to_cpu(frame_status
[0].sequence
);
3602 idx
= SEQ_TO_INDEX(seq
);
3603 txq_id
= SEQ_TO_QUEUE(seq
);
3605 /* FIXME: code repetition */
3606 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3607 agg
->frame_count
, agg
->start_idx
, idx
);
3609 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
3610 tx_status
->retry_count
= tx_resp
->failure_frame
;
3611 tx_status
->queue_number
= status
& 0xff;
3612 tx_status
->queue_length
= tx_resp
->failure_rts
;
3613 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
3614 tx_status
->flags
= iwl4965_is_tx_success(status
)?
3615 IEEE80211_TX_STATUS_ACK
: 0;
3616 tx_status
->control
.tx_rate
=
3617 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
);
3618 /* FIXME: code repetition end */
3620 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3621 status
& 0xff, tx_resp
->failure_frame
);
3622 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3623 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
3625 agg
->wait_for_ba
= 0;
3627 /* Two or more frames were attempted; expect block-ack */
3629 int start
= agg
->start_idx
;
3631 /* Construct bit-map of pending frames within Tx window */
3632 for (i
= 0; i
< agg
->frame_count
; i
++) {
3634 status
= le16_to_cpu(frame_status
[i
].status
);
3635 seq
= le16_to_cpu(frame_status
[i
].sequence
);
3636 idx
= SEQ_TO_INDEX(seq
);
3637 txq_id
= SEQ_TO_QUEUE(seq
);
3639 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
3640 AGG_TX_STATE_ABORT_MSK
))
3643 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3644 agg
->frame_count
, txq_id
, idx
);
3646 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
3648 sc
= le16_to_cpu(hdr
->seq_ctrl
);
3649 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
3650 IWL_ERROR("BUG_ON idx doesn't match seq control"
3651 " idx=%d, seq_idx=%d, seq=%d\n",
3657 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3658 i
, idx
, SEQ_TO_SN(sc
));
3662 sh
= (start
- idx
) + 0xff;
3663 bitmap
= bitmap
<< sh
;
3666 } else if (sh
< -64)
3667 sh
= 0xff - (start
- idx
);
3671 bitmap
= bitmap
<< sh
;
3674 bitmap
|= (1 << sh
);
3675 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3676 start
, (u32
)(bitmap
& 0xFFFFFFFF));
3679 agg
->bitmap
= bitmap
;
3680 agg
->start_idx
= start
;
3681 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
3682 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3683 agg
->frame_count
, agg
->start_idx
,
3687 agg
->wait_for_ba
= 1;
3694 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3696 static void iwl4965_rx_reply_tx(struct iwl4965_priv
*priv
,
3697 struct iwl4965_rx_mem_buffer
*rxb
)
3699 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3700 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3701 int txq_id
= SEQ_TO_QUEUE(sequence
);
3702 int index
= SEQ_TO_INDEX(sequence
);
3703 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
3704 struct ieee80211_tx_status
*tx_status
;
3705 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
3706 u32 status
= le32_to_cpu(tx_resp
->status
);
3707 #ifdef CONFIG_IWL4965_HT
3708 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
3709 struct ieee80211_hdr
*hdr
;
3713 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
3714 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3715 "is out of range [0-%d] %d %d\n", txq_id
,
3716 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
3721 #ifdef CONFIG_IWL4965_HT
3722 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
3723 qc
= ieee80211_get_qos_ctrl(hdr
);
3726 tid
= le16_to_cpu(*qc
) & 0xf;
3728 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
3729 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
3730 IWL_ERROR("Station not known\n");
3734 if (txq
->sched_retry
) {
3735 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
3736 struct iwl4965_ht_agg
*agg
= NULL
;
3741 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
3743 iwl4965_tx_status_reply_tx(priv
, agg
,
3744 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
3746 if ((tx_resp
->frame_count
== 1) &&
3747 !iwl4965_is_tx_success(status
)) {
3748 /* TODO: send BAR */
3751 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
3753 index
= iwl4965_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
3754 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3755 "%d index %d\n", scd_ssn
, index
);
3756 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3757 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3759 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3760 txq_id
>= 0 && priv
->mac80211_registered
&&
3761 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
3762 ieee80211_wake_queue(priv
->hw
, txq_id
);
3764 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3767 #endif /* CONFIG_IWL4965_HT */
3768 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
3770 tx_status
->retry_count
= tx_resp
->failure_frame
;
3771 tx_status
->queue_number
= status
;
3772 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3773 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3776 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3778 tx_status
->control
.tx_rate
=
3779 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
);
3781 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3782 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
3783 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
3784 tx_resp
->failure_frame
);
3786 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3788 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3789 #ifdef CONFIG_IWL4965_HT
3790 if (tid
!= MAX_TID_COUNT
)
3791 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3792 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3794 priv
->mac80211_registered
)
3795 ieee80211_wake_queue(priv
->hw
, txq_id
);
3796 if (tid
!= MAX_TID_COUNT
)
3797 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3800 #ifdef CONFIG_IWL4965_HT
3802 #endif /* CONFIG_IWL4965_HT */
3804 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3805 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3809 static void iwl4965_rx_reply_alive(struct iwl4965_priv
*priv
,
3810 struct iwl4965_rx_mem_buffer
*rxb
)
3812 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3813 struct iwl4965_alive_resp
*palive
;
3814 struct delayed_work
*pwork
;
3816 palive
= &pkt
->u
.alive_frame
;
3818 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3820 palive
->is_valid
, palive
->ver_type
,
3821 palive
->ver_subtype
);
3823 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3824 IWL_DEBUG_INFO("Initialization Alive received.\n");
3825 memcpy(&priv
->card_alive_init
,
3826 &pkt
->u
.alive_frame
,
3827 sizeof(struct iwl4965_init_alive_resp
));
3828 pwork
= &priv
->init_alive_start
;
3830 IWL_DEBUG_INFO("Runtime Alive received.\n");
3831 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3832 sizeof(struct iwl4965_alive_resp
));
3833 pwork
= &priv
->alive_start
;
3836 /* We delay the ALIVE response by 5ms to
3837 * give the HW RF Kill time to activate... */
3838 if (palive
->is_valid
== UCODE_VALID_OK
)
3839 queue_delayed_work(priv
->workqueue
, pwork
,
3840 msecs_to_jiffies(5));
3842 IWL_WARNING("uCode did not respond OK.\n");
3845 static void iwl4965_rx_reply_add_sta(struct iwl4965_priv
*priv
,
3846 struct iwl4965_rx_mem_buffer
*rxb
)
3848 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3850 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3854 static void iwl4965_rx_reply_error(struct iwl4965_priv
*priv
,
3855 struct iwl4965_rx_mem_buffer
*rxb
)
3857 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3859 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3860 "seq 0x%04X ser 0x%08X\n",
3861 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3862 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3863 pkt
->u
.err_resp
.cmd_id
,
3864 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3865 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3868 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3870 static void iwl4965_rx_csa(struct iwl4965_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
3872 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3873 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3874 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3875 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3876 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3877 rxon
->channel
= csa
->channel
;
3878 priv
->staging_rxon
.channel
= csa
->channel
;
3881 static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv
*priv
,
3882 struct iwl4965_rx_mem_buffer
*rxb
)
3884 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3885 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3886 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3888 if (!report
->state
) {
3889 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3890 "Spectrum Measure Notification: Start\n");
3894 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3895 priv
->measurement_status
|= MEASUREMENT_READY
;
3899 static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv
*priv
,
3900 struct iwl4965_rx_mem_buffer
*rxb
)
3902 #ifdef CONFIG_IWL4965_DEBUG
3903 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3904 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3905 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3906 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3910 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv
*priv
,
3911 struct iwl4965_rx_mem_buffer
*rxb
)
3913 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3914 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3915 "notification for %s:\n",
3916 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3917 iwl4965_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3920 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
3922 struct iwl4965_priv
*priv
=
3923 container_of(work
, struct iwl4965_priv
, beacon_update
);
3924 struct sk_buff
*beacon
;
3926 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3927 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
3930 IWL_ERROR("update beacon failed\n");
3934 mutex_lock(&priv
->mutex
);
3935 /* new beacon skb is allocated every time; dispose previous.*/
3936 if (priv
->ibss_beacon
)
3937 dev_kfree_skb(priv
->ibss_beacon
);
3939 priv
->ibss_beacon
= beacon
;
3940 mutex_unlock(&priv
->mutex
);
3942 iwl4965_send_beacon_cmd(priv
);
3945 static void iwl4965_rx_beacon_notif(struct iwl4965_priv
*priv
,
3946 struct iwl4965_rx_mem_buffer
*rxb
)
3948 #ifdef CONFIG_IWL4965_DEBUG
3949 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3950 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3951 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
3953 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3954 "tsf %d %d rate %d\n",
3955 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3956 beacon
->beacon_notify_hdr
.failure_frame
,
3957 le32_to_cpu(beacon
->ibss_mgr_status
),
3958 le32_to_cpu(beacon
->high_tsf
),
3959 le32_to_cpu(beacon
->low_tsf
), rate
);
3962 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3963 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3964 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3967 /* Service response to REPLY_SCAN_CMD (0x80) */
3968 static void iwl4965_rx_reply_scan(struct iwl4965_priv
*priv
,
3969 struct iwl4965_rx_mem_buffer
*rxb
)
3971 #ifdef CONFIG_IWL4965_DEBUG
3972 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3973 struct iwl4965_scanreq_notification
*notif
=
3974 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
3976 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3980 /* Service SCAN_START_NOTIFICATION (0x82) */
3981 static void iwl4965_rx_scan_start_notif(struct iwl4965_priv
*priv
,
3982 struct iwl4965_rx_mem_buffer
*rxb
)
3984 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3985 struct iwl4965_scanstart_notification
*notif
=
3986 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
3987 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3988 IWL_DEBUG_SCAN("Scan start: "
3990 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3992 notif
->band
? "bg" : "a",
3994 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3997 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3998 static void iwl4965_rx_scan_results_notif(struct iwl4965_priv
*priv
,
3999 struct iwl4965_rx_mem_buffer
*rxb
)
4001 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
4002 struct iwl4965_scanresults_notification
*notif
=
4003 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
4005 IWL_DEBUG_SCAN("Scan ch.res: "
4007 "(TSF: 0x%08X:%08X) - %d "
4008 "elapsed=%lu usec (%dms since last)\n",
4010 notif
->band
? "bg" : "a",
4011 le32_to_cpu(notif
->tsf_high
),
4012 le32_to_cpu(notif
->tsf_low
),
4013 le32_to_cpu(notif
->statistics
[0]),
4014 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
4015 jiffies_to_msecs(elapsed_jiffies
4016 (priv
->last_scan_jiffies
, jiffies
)));
4018 priv
->last_scan_jiffies
= jiffies
;
4019 priv
->next_scan_jiffies
= 0;
4022 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
4023 static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv
*priv
,
4024 struct iwl4965_rx_mem_buffer
*rxb
)
4026 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
4027 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
4029 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
4030 scan_notif
->scanned_channels
,
4031 scan_notif
->tsf_low
,
4032 scan_notif
->tsf_high
, scan_notif
->status
);
4034 /* The HW is no longer scanning */
4035 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
4037 /* The scan completion notification came in, so kill that timer... */
4038 cancel_delayed_work(&priv
->scan_check
);
4040 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
4041 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
4042 jiffies_to_msecs(elapsed_jiffies
4043 (priv
->scan_pass_start
, jiffies
)));
4045 /* Remove this scanned band from the list
4046 * of pending bands to scan */
4049 /* If a request to abort was given, or the scan did not succeed
4050 * then we reset the scan state machine and terminate,
4051 * re-queuing another scan if one has been requested */
4052 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
4053 IWL_DEBUG_INFO("Aborted scan completed.\n");
4054 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
4056 /* If there are more bands on this scan pass reschedule */
4057 if (priv
->scan_bands
> 0)
4061 priv
->last_scan_jiffies
= jiffies
;
4062 priv
->next_scan_jiffies
= 0;
4063 IWL_DEBUG_INFO("Setting scan to off\n");
4065 clear_bit(STATUS_SCANNING
, &priv
->status
);
4067 IWL_DEBUG_INFO("Scan took %dms\n",
4068 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
4070 queue_work(priv
->workqueue
, &priv
->scan_completed
);
4075 priv
->scan_pass_start
= jiffies
;
4076 queue_work(priv
->workqueue
, &priv
->request_scan
);
4079 /* Handle notification from uCode that card's power state is changing
4080 * due to software, hardware, or critical temperature RFKILL */
4081 static void iwl4965_rx_card_state_notif(struct iwl4965_priv
*priv
,
4082 struct iwl4965_rx_mem_buffer
*rxb
)
4084 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
4085 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
4086 unsigned long status
= priv
->status
;
4088 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
4089 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
4090 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
4092 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
4093 RF_CARD_DISABLED
)) {
4095 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
4096 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
4098 if (!iwl4965_grab_nic_access(priv
)) {
4099 iwl4965_write_direct32(
4100 priv
, HBUS_TARG_MBX_C
,
4101 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
4103 iwl4965_release_nic_access(priv
);
4106 if (!(flags
& RXON_CARD_DISABLED
)) {
4107 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
4108 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
4109 if (!iwl4965_grab_nic_access(priv
)) {
4110 iwl4965_write_direct32(
4111 priv
, HBUS_TARG_MBX_C
,
4112 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
4114 iwl4965_release_nic_access(priv
);
4118 if (flags
& RF_CARD_DISABLED
) {
4119 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
4120 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
4121 iwl4965_read32(priv
, CSR_UCODE_DRV_GP1
);
4122 if (!iwl4965_grab_nic_access(priv
))
4123 iwl4965_release_nic_access(priv
);
4127 if (flags
& HW_CARD_DISABLED
)
4128 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4130 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4133 if (flags
& SW_CARD_DISABLED
)
4134 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
4136 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
4138 if (!(flags
& RXON_CARD_DISABLED
))
4139 iwl4965_scan_cancel(priv
);
4141 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
4142 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
4143 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
4144 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
4145 queue_work(priv
->workqueue
, &priv
->rf_kill
);
4147 wake_up_interruptible(&priv
->wait_command_queue
);
4151 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
4153 * Setup the RX handlers for each of the reply types sent from the uCode
4156 * This function chains into the hardware specific files for them to setup
4157 * any hardware specific handlers as well.
4159 static void iwl4965_setup_rx_handlers(struct iwl4965_priv
*priv
)
4161 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
4162 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
4163 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
4164 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
4165 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
4166 iwl4965_rx_spectrum_measure_notif
;
4167 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
4168 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
4169 iwl4965_rx_pm_debug_statistics_notif
;
4170 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
4173 * The same handler is used for both the REPLY to a discrete
4174 * statistics request from the host as well as for the periodic
4175 * statistics notifications (after received beacons) from the uCode.
4177 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
4178 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
4180 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
4181 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
4182 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
4183 iwl4965_rx_scan_results_notif
;
4184 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
4185 iwl4965_rx_scan_complete_notif
;
4186 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
4187 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
4189 /* Set up hardware specific Rx handlers */
4190 iwl4965_hw_rx_handler_setup(priv
);
4194 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
4195 * @rxb: Rx buffer to reclaim
4197 * If an Rx buffer has an async callback associated with it the callback
4198 * will be executed. The attached skb (if present) will only be freed
4199 * if the callback returns 1
4201 static void iwl4965_tx_cmd_complete(struct iwl4965_priv
*priv
,
4202 struct iwl4965_rx_mem_buffer
*rxb
)
4204 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
4205 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
4206 int txq_id
= SEQ_TO_QUEUE(sequence
);
4207 int index
= SEQ_TO_INDEX(sequence
);
4208 int huge
= sequence
& SEQ_HUGE_FRAME
;
4210 struct iwl4965_cmd
*cmd
;
4212 /* If a Tx command is being handled and it isn't in the actual
4213 * command queue then there a command routing bug has been introduced
4214 * in the queue management code. */
4215 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
4216 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
4217 txq_id
, pkt
->hdr
.cmd
);
4218 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
4220 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
4221 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
4223 /* Input error checking is done when commands are added to queue. */
4224 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
4225 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
4227 } else if (cmd
->meta
.u
.callback
&&
4228 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
4231 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
4233 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
4234 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4235 wake_up_interruptible(&priv
->wait_command_queue
);
4239 /************************** RX-FUNCTIONS ****************************/
4241 * Rx theory of operation
4243 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
4244 * each of which point to Receive Buffers to be filled by 4965. These get
4245 * used not only for Rx frames, but for any command response or notification
4246 * from the 4965. The driver and 4965 manage the Rx buffers by means
4247 * of indexes into the circular buffer.
4250 * The host/firmware share two index registers for managing the Rx buffers.
4252 * The READ index maps to the first position that the firmware may be writing
4253 * to -- the driver can read up to (but not including) this position and get
4255 * The READ index is managed by the firmware once the card is enabled.
4257 * The WRITE index maps to the last position the driver has read from -- the
4258 * position preceding WRITE is the last slot the firmware can place a packet.
4260 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4263 * During initialization, the host sets up the READ queue position to the first
4264 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4266 * When the firmware places a packet in a buffer, it will advance the READ index
4267 * and fire the RX interrupt. The driver can then query the READ index and
4268 * process as many packets as possible, moving the WRITE index forward as it
4269 * resets the Rx queue buffers with new memory.
4271 * The management in the driver is as follows:
4272 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
4273 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4274 * to replenish the iwl->rxq->rx_free.
4275 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
4276 * iwl->rxq is replenished and the READ INDEX is updated (updating the
4277 * 'processed' and 'read' driver indexes as well)
4278 * + A received packet is processed and handed to the kernel network stack,
4279 * detached from the iwl->rxq. The driver 'processed' index is updated.
4280 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
4281 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
4282 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
4283 * were enough free buffers and RX_STALLED is set it is cleared.
4288 * iwl4965_rx_queue_alloc() Allocates rx_free
4289 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
4290 * iwl4965_rx_queue_restock
4291 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
4292 * queue, updates firmware pointers, and updates
4293 * the WRITE index. If insufficient rx_free buffers
4294 * are available, schedules iwl4965_rx_replenish
4296 * -- enable interrupts --
4297 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
4298 * READ INDEX, detaching the SKB from the pool.
4299 * Moves the packet buffer from queue to rx_used.
4300 * Calls iwl4965_rx_queue_restock to refill any empty
4307 * iwl4965_rx_queue_space - Return number of free slots available in queue.
4309 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue
*q
)
4311 int s
= q
->read
- q
->write
;
4314 /* keep some buffer to not confuse full and empty queue */
4322 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
4324 int iwl4965_rx_queue_update_write_ptr(struct iwl4965_priv
*priv
, struct iwl4965_rx_queue
*q
)
4328 unsigned long flags
;
4330 spin_lock_irqsave(&q
->lock
, flags
);
4332 if (q
->need_update
== 0)
4335 /* If power-saving is in use, make sure device is awake */
4336 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4337 reg
= iwl4965_read32(priv
, CSR_UCODE_DRV_GP1
);
4339 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4340 iwl4965_set_bit(priv
, CSR_GP_CNTRL
,
4341 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4345 rc
= iwl4965_grab_nic_access(priv
);
4349 /* Device expects a multiple of 8 */
4350 iwl4965_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
4352 iwl4965_release_nic_access(priv
);
4354 /* Else device is assumed to be awake */
4356 /* Device expects a multiple of 8 */
4357 iwl4965_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
4363 spin_unlock_irqrestore(&q
->lock
, flags
);
4368 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
4370 static inline __le32
iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv
*priv
,
4371 dma_addr_t dma_addr
)
4373 return cpu_to_le32((u32
)(dma_addr
>> 8));
4378 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
4380 * If there are slots in the RX queue that need to be restocked,
4381 * and we have free pre-allocated buffers, fill the ranks as much
4382 * as we can, pulling from rx_free.
4384 * This moves the 'write' index forward to catch up with 'processed', and
4385 * also updates the memory address in the firmware to reference the new
4388 static int iwl4965_rx_queue_restock(struct iwl4965_priv
*priv
)
4390 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
4391 struct list_head
*element
;
4392 struct iwl4965_rx_mem_buffer
*rxb
;
4393 unsigned long flags
;
4396 spin_lock_irqsave(&rxq
->lock
, flags
);
4397 write
= rxq
->write
& ~0x7;
4398 while ((iwl4965_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
4399 /* Get next free Rx buffer, remove from free list */
4400 element
= rxq
->rx_free
.next
;
4401 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
4404 /* Point to Rx buffer via next RBD in circular buffer */
4405 rxq
->bd
[rxq
->write
] = iwl4965_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
4406 rxq
->queue
[rxq
->write
] = rxb
;
4407 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
4410 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4411 /* If the pre-allocated buffer pool is dropping low, schedule to
4413 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
4414 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
4417 /* If we've added more space for the firmware to place data, tell it.
4418 * Increment device's write pointer in multiples of 8. */
4419 if ((write
!= (rxq
->write
& ~0x7))
4420 || (abs(rxq
->write
- rxq
->read
) > 7)) {
4421 spin_lock_irqsave(&rxq
->lock
, flags
);
4422 rxq
->need_update
= 1;
4423 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4424 rc
= iwl4965_rx_queue_update_write_ptr(priv
, rxq
);
4433 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
4435 * When moving to rx_free an SKB is allocated for the slot.
4437 * Also restock the Rx queue via iwl4965_rx_queue_restock.
4438 * This is called as a scheduled work item (except for during initialization)
4440 static void iwl4965_rx_allocate(struct iwl4965_priv
*priv
)
4442 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
4443 struct list_head
*element
;
4444 struct iwl4965_rx_mem_buffer
*rxb
;
4445 unsigned long flags
;
4446 spin_lock_irqsave(&rxq
->lock
, flags
);
4447 while (!list_empty(&rxq
->rx_used
)) {
4448 element
= rxq
->rx_used
.next
;
4449 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
4451 /* Alloc a new receive buffer */
4453 alloc_skb(priv
->hw_setting
.rx_buf_size
,
4454 __GFP_NOWARN
| GFP_ATOMIC
);
4456 if (net_ratelimit())
4457 printk(KERN_CRIT DRV_NAME
4458 ": Can not allocate SKB buffers\n");
4459 /* We don't reschedule replenish work here -- we will
4460 * call the restock method and if it still needs
4461 * more buffers it will schedule replenish */
4464 priv
->alloc_rxb_skb
++;
4467 /* Get physical address of RB/SKB */
4469 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
4470 priv
->hw_setting
.rx_buf_size
, PCI_DMA_FROMDEVICE
);
4471 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
4474 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4478 * this should be called while priv->lock is locked
4480 static void __iwl4965_rx_replenish(void *data
)
4482 struct iwl4965_priv
*priv
= data
;
4484 iwl4965_rx_allocate(priv
);
4485 iwl4965_rx_queue_restock(priv
);
4489 void iwl4965_rx_replenish(void *data
)
4491 struct iwl4965_priv
*priv
= data
;
4492 unsigned long flags
;
4494 iwl4965_rx_allocate(priv
);
4496 spin_lock_irqsave(&priv
->lock
, flags
);
4497 iwl4965_rx_queue_restock(priv
);
4498 spin_unlock_irqrestore(&priv
->lock
, flags
);
4501 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4502 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
4503 * This free routine walks the list of POOL entries and if SKB is set to
4504 * non NULL it is unmapped and freed
4506 static void iwl4965_rx_queue_free(struct iwl4965_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
4509 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
4510 if (rxq
->pool
[i
].skb
!= NULL
) {
4511 pci_unmap_single(priv
->pci_dev
,
4512 rxq
->pool
[i
].dma_addr
,
4513 priv
->hw_setting
.rx_buf_size
,
4514 PCI_DMA_FROMDEVICE
);
4515 dev_kfree_skb(rxq
->pool
[i
].skb
);
4519 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
4524 int iwl4965_rx_queue_alloc(struct iwl4965_priv
*priv
)
4526 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
4527 struct pci_dev
*dev
= priv
->pci_dev
;
4530 spin_lock_init(&rxq
->lock
);
4531 INIT_LIST_HEAD(&rxq
->rx_free
);
4532 INIT_LIST_HEAD(&rxq
->rx_used
);
4534 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
4535 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
4539 /* Fill the rx_used queue with _all_ of the Rx buffers */
4540 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
4541 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4543 /* Set us so that we have processed and used all buffers, but have
4544 * not restocked the Rx queue with fresh buffers */
4545 rxq
->read
= rxq
->write
= 0;
4546 rxq
->free_count
= 0;
4547 rxq
->need_update
= 0;
4551 void iwl4965_rx_queue_reset(struct iwl4965_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
4553 unsigned long flags
;
4555 spin_lock_irqsave(&rxq
->lock
, flags
);
4556 INIT_LIST_HEAD(&rxq
->rx_free
);
4557 INIT_LIST_HEAD(&rxq
->rx_used
);
4558 /* Fill the rx_used queue with _all_ of the Rx buffers */
4559 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
4560 /* In the reset function, these buffers may have been allocated
4561 * to an SKB, so we need to unmap and free potential storage */
4562 if (rxq
->pool
[i
].skb
!= NULL
) {
4563 pci_unmap_single(priv
->pci_dev
,
4564 rxq
->pool
[i
].dma_addr
,
4565 priv
->hw_setting
.rx_buf_size
,
4566 PCI_DMA_FROMDEVICE
);
4567 priv
->alloc_rxb_skb
--;
4568 dev_kfree_skb(rxq
->pool
[i
].skb
);
4569 rxq
->pool
[i
].skb
= NULL
;
4571 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4574 /* Set us so that we have processed and used all buffers, but have
4575 * not restocked the Rx queue with fresh buffers */
4576 rxq
->read
= rxq
->write
= 0;
4577 rxq
->free_count
= 0;
4578 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4581 /* Convert linear signal-to-noise ratio into dB */
4582 static u8 ratio2dB
[100] = {
4583 /* 0 1 2 3 4 5 6 7 8 9 */
4584 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4585 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4586 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4587 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4588 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4589 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4590 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4591 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4592 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4593 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4596 /* Calculates a relative dB value from a ratio of linear
4597 * (i.e. not dB) signal levels.
4598 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4599 int iwl4965_calc_db_from_ratio(int sig_ratio
)
4601 /* 1000:1 or higher just report as 60 dB */
4602 if (sig_ratio
>= 1000)
4605 /* 100:1 or higher, divide by 10 and use table,
4606 * add 20 dB to make up for divide by 10 */
4607 if (sig_ratio
>= 100)
4608 return (20 + (int)ratio2dB
[sig_ratio
/10]);
4610 /* We shouldn't see this */
4614 /* Use table for ratios 1:1 - 99:1 */
4615 return (int)ratio2dB
[sig_ratio
];
4618 #define PERFECT_RSSI (-20) /* dBm */
4619 #define WORST_RSSI (-95) /* dBm */
4620 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4622 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4623 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4624 * about formulas used below. */
4625 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
4628 int degradation
= PERFECT_RSSI
- rssi_dbm
;
4630 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4631 * as indicator; formula is (signal dbm - noise dbm).
4632 * SNR at or above 40 is a great signal (100%).
4633 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4634 * Weakest usable signal is usually 10 - 15 dB SNR. */
4636 if (rssi_dbm
- noise_dbm
>= 40)
4638 else if (rssi_dbm
< noise_dbm
)
4640 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
4642 /* Else use just the signal level.
4643 * This formula is a least squares fit of data points collected and
4644 * compared with a reference system that had a percentage (%) display
4645 * for signal quality. */
4647 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
4648 (15 * RSSI_RANGE
+ 62 * degradation
)) /
4649 (RSSI_RANGE
* RSSI_RANGE
);
4653 else if (sig_qual
< 1)
4660 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
4662 * Uses the priv->rx_handlers callback function array to invoke
4663 * the appropriate handlers, including command responses,
4664 * frame-received notifications, and other notifications.
4666 static void iwl4965_rx_handle(struct iwl4965_priv
*priv
)
4668 struct iwl4965_rx_mem_buffer
*rxb
;
4669 struct iwl4965_rx_packet
*pkt
;
4670 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
4673 unsigned long flags
;
4677 /* uCode's read index (stored in shared DRAM) indicates the last Rx
4678 * buffer that the driver may process (last buffer filled by ucode). */
4679 r
= iwl4965_hw_get_rx_read(priv
);
4682 /* Rx interrupt, but nothing sent from uCode */
4684 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
4686 if (iwl4965_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
4690 rxb
= rxq
->queue
[i
];
4692 /* If an RXB doesn't have a Rx queue slot associated with it,
4693 * then a bug has been introduced in the queue refilling
4694 * routines -- catch it here */
4695 BUG_ON(rxb
== NULL
);
4697 rxq
->queue
[i
] = NULL
;
4699 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
4700 priv
->hw_setting
.rx_buf_size
,
4701 PCI_DMA_FROMDEVICE
);
4702 pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
4704 /* Reclaim a command buffer only if this packet is a response
4705 * to a (driver-originated) command.
4706 * If the packet (e.g. Rx frame) originated from uCode,
4707 * there is no command buffer to reclaim.
4708 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4709 * but apparently a few don't get set; catch them here. */
4710 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
4711 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
4712 (pkt
->hdr
.cmd
!= REPLY_4965_RX
) &&
4713 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
4714 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
4715 (pkt
->hdr
.cmd
!= REPLY_TX
);
4717 /* Based on type of command response or notification,
4718 * handle those that need handling via function in
4719 * rx_handlers table. See iwl4965_setup_rx_handlers() */
4720 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
4721 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4722 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
4723 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
4724 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
4726 /* No handling needed */
4727 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4728 "r %d i %d No handler needed for %s, 0x%02x\n",
4729 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
4734 /* Invoke any callbacks, transfer the skb to caller, and
4735 * fire off the (possibly) blocking iwl4965_send_cmd()
4736 * as we reclaim the driver command queue */
4737 if (rxb
&& rxb
->skb
)
4738 iwl4965_tx_cmd_complete(priv
, rxb
);
4740 IWL_WARNING("Claim null rxb?\n");
4743 /* For now we just don't re-use anything. We can tweak this
4744 * later to try and re-use notification packets and SKBs that
4745 * fail to Rx correctly */
4746 if (rxb
->skb
!= NULL
) {
4747 priv
->alloc_rxb_skb
--;
4748 dev_kfree_skb_any(rxb
->skb
);
4752 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4753 priv
->hw_setting
.rx_buf_size
,
4754 PCI_DMA_FROMDEVICE
);
4755 spin_lock_irqsave(&rxq
->lock
, flags
);
4756 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4757 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4758 i
= (i
+ 1) & RX_QUEUE_MASK
;
4759 /* If there are a lot of unused frames,
4760 * restock the Rx queue so ucode wont assert. */
4765 __iwl4965_rx_replenish(priv
);
4771 /* Backtrack one entry */
4773 iwl4965_rx_queue_restock(priv
);
4777 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4779 static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv
*priv
,
4780 struct iwl4965_tx_queue
*txq
)
4784 int txq_id
= txq
->q
.id
;
4786 if (txq
->need_update
== 0)
4789 /* if we're trying to save power */
4790 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4791 /* wake up nic if it's powered down ...
4792 * uCode will wake up, and interrupt us again, so next
4793 * time we'll skip this part. */
4794 reg
= iwl4965_read32(priv
, CSR_UCODE_DRV_GP1
);
4796 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4797 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4798 iwl4965_set_bit(priv
, CSR_GP_CNTRL
,
4799 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4803 /* restore this queue's parameters in nic hardware. */
4804 rc
= iwl4965_grab_nic_access(priv
);
4807 iwl4965_write_direct32(priv
, HBUS_TARG_WRPTR
,
4808 txq
->q
.write_ptr
| (txq_id
<< 8));
4809 iwl4965_release_nic_access(priv
);
4811 /* else not in power-save mode, uCode will never sleep when we're
4812 * trying to tx (during RFKILL, we're not trying to tx). */
4814 iwl4965_write32(priv
, HBUS_TARG_WRPTR
,
4815 txq
->q
.write_ptr
| (txq_id
<< 8));
4817 txq
->need_update
= 0;
4822 #ifdef CONFIG_IWL4965_DEBUG
4823 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd
*rxon
)
4825 DECLARE_MAC_BUF(mac
);
4827 IWL_DEBUG_RADIO("RX CONFIG:\n");
4828 iwl4965_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4829 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4830 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4831 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4832 le32_to_cpu(rxon
->filter_flags
));
4833 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4834 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4835 rxon
->ofdm_basic_rates
);
4836 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4837 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4838 print_mac(mac
, rxon
->node_addr
));
4839 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4840 print_mac(mac
, rxon
->bssid_addr
));
4841 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4845 static void iwl4965_enable_interrupts(struct iwl4965_priv
*priv
)
4847 IWL_DEBUG_ISR("Enabling interrupts\n");
4848 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4849 iwl4965_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4852 static inline void iwl4965_disable_interrupts(struct iwl4965_priv
*priv
)
4854 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4856 /* disable interrupts from uCode/NIC to host */
4857 iwl4965_write32(priv
, CSR_INT_MASK
, 0x00000000);
4859 /* acknowledge/clear/reset any interrupts still pending
4860 * from uCode or flow handler (Rx/Tx DMA) */
4861 iwl4965_write32(priv
, CSR_INT
, 0xffffffff);
4862 iwl4965_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4863 IWL_DEBUG_ISR("Disabled interrupts\n");
4866 static const char *desc_lookup(int i
)
4874 return "BAD_CHECKSUM";
4876 return "NMI_INTERRUPT";
4880 return "FATAL_ERROR";
4886 #define ERROR_START_OFFSET (1 * sizeof(u32))
4887 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4889 static void iwl4965_dump_nic_error_log(struct iwl4965_priv
*priv
)
4892 u32 desc
, time
, count
, base
, data1
;
4893 u32 blink1
, blink2
, ilink1
, ilink2
;
4896 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4898 if (!iwl4965_hw_valid_rtc_data_addr(base
)) {
4899 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4903 rc
= iwl4965_grab_nic_access(priv
);
4905 IWL_WARNING("Can not read from adapter at this time.\n");
4909 count
= iwl4965_read_targ_mem(priv
, base
);
4911 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4912 IWL_ERROR("Start IWL Error Log Dump:\n");
4913 IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4914 priv
->status
, priv
->config
, count
);
4917 desc
= iwl4965_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
4918 blink1
= iwl4965_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
4919 blink2
= iwl4965_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
4920 ilink1
= iwl4965_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
4921 ilink2
= iwl4965_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
4922 data1
= iwl4965_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
4923 data2
= iwl4965_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
4924 line
= iwl4965_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
4925 time
= iwl4965_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
4927 IWL_ERROR("Desc Time "
4928 "data1 data2 line\n");
4929 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4930 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
4931 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4932 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
4935 iwl4965_release_nic_access(priv
);
4938 #define EVENT_START_OFFSET (4 * sizeof(u32))
4941 * iwl4965_print_event_log - Dump error event log to syslog
4943 * NOTE: Must be called with iwl4965_grab_nic_access() already obtained!
4945 static void iwl4965_print_event_log(struct iwl4965_priv
*priv
, u32 start_idx
,
4946 u32 num_events
, u32 mode
)
4949 u32 base
; /* SRAM byte address of event log header */
4950 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4951 u32 ptr
; /* SRAM byte address of log data */
4952 u32 ev
, time
, data
; /* event log data */
4954 if (num_events
== 0)
4957 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4960 event_size
= 2 * sizeof(u32
);
4962 event_size
= 3 * sizeof(u32
);
4964 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4966 /* "time" is actually "data" for mode 0 (no timestamp).
4967 * place event id # at far right for easier visual parsing. */
4968 for (i
= 0; i
< num_events
; i
++) {
4969 ev
= iwl4965_read_targ_mem(priv
, ptr
);
4971 time
= iwl4965_read_targ_mem(priv
, ptr
);
4974 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4976 data
= iwl4965_read_targ_mem(priv
, ptr
);
4978 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4983 static void iwl4965_dump_nic_event_log(struct iwl4965_priv
*priv
)
4986 u32 base
; /* SRAM byte address of event log header */
4987 u32 capacity
; /* event log capacity in # entries */
4988 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4989 u32 num_wraps
; /* # times uCode wrapped to top of log */
4990 u32 next_entry
; /* index of next entry to be written by uCode */
4991 u32 size
; /* # entries that we'll print */
4993 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4994 if (!iwl4965_hw_valid_rtc_data_addr(base
)) {
4995 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4999 rc
= iwl4965_grab_nic_access(priv
);
5001 IWL_WARNING("Can not read from adapter at this time.\n");
5005 /* event log header */
5006 capacity
= iwl4965_read_targ_mem(priv
, base
);
5007 mode
= iwl4965_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
5008 num_wraps
= iwl4965_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
5009 next_entry
= iwl4965_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
5011 size
= num_wraps
? capacity
: next_entry
;
5013 /* bail out if nothing in log */
5015 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
5016 iwl4965_release_nic_access(priv
);
5020 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
5023 /* if uCode has wrapped back to top of log, start at the oldest entry,
5024 * i.e the next one that uCode would fill. */
5026 iwl4965_print_event_log(priv
, next_entry
,
5027 capacity
- next_entry
, mode
);
5029 /* (then/else) start at top of log */
5030 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
5032 iwl4965_release_nic_access(priv
);
5036 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
5038 static void iwl4965_irq_handle_error(struct iwl4965_priv
*priv
)
5040 /* Set the FW error flag -- cleared on iwl4965_down */
5041 set_bit(STATUS_FW_ERROR
, &priv
->status
);
5043 /* Cancel currently queued command. */
5044 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
5046 #ifdef CONFIG_IWL4965_DEBUG
5047 if (iwl4965_debug_level
& IWL_DL_FW_ERRORS
) {
5048 iwl4965_dump_nic_error_log(priv
);
5049 iwl4965_dump_nic_event_log(priv
);
5050 iwl4965_print_rx_config_cmd(&priv
->staging_rxon
);
5054 wake_up_interruptible(&priv
->wait_command_queue
);
5056 /* Keep the restart process from trying to send host
5057 * commands by clearing the INIT status bit */
5058 clear_bit(STATUS_READY
, &priv
->status
);
5060 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5061 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
5062 "Restarting adapter due to uCode error.\n");
5064 if (iwl4965_is_associated(priv
)) {
5065 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
5066 sizeof(priv
->recovery_rxon
));
5067 priv
->error_recovering
= 1;
5069 queue_work(priv
->workqueue
, &priv
->restart
);
5073 static void iwl4965_error_recovery(struct iwl4965_priv
*priv
)
5075 unsigned long flags
;
5077 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
5078 sizeof(priv
->staging_rxon
));
5079 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5080 iwl4965_commit_rxon(priv
);
5082 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
5084 spin_lock_irqsave(&priv
->lock
, flags
);
5085 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
5086 priv
->error_recovering
= 0;
5087 spin_unlock_irqrestore(&priv
->lock
, flags
);
5090 static void iwl4965_irq_tasklet(struct iwl4965_priv
*priv
)
5092 u32 inta
, handled
= 0;
5094 unsigned long flags
;
5095 #ifdef CONFIG_IWL4965_DEBUG
5099 spin_lock_irqsave(&priv
->lock
, flags
);
5101 /* Ack/clear/reset pending uCode interrupts.
5102 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
5103 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
5104 inta
= iwl4965_read32(priv
, CSR_INT
);
5105 iwl4965_write32(priv
, CSR_INT
, inta
);
5107 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
5108 * Any new interrupts that happen after this, either while we're
5109 * in this tasklet, or later, will show up in next ISR/tasklet. */
5110 inta_fh
= iwl4965_read32(priv
, CSR_FH_INT_STATUS
);
5111 iwl4965_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
5113 #ifdef CONFIG_IWL4965_DEBUG
5114 if (iwl4965_debug_level
& IWL_DL_ISR
) {
5115 /* just for debug */
5116 inta_mask
= iwl4965_read32(priv
, CSR_INT_MASK
);
5117 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5118 inta
, inta_mask
, inta_fh
);
5122 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
5123 * atomic, make sure that inta covers all the interrupts that
5124 * we've discovered, even if FH interrupt came in just after
5125 * reading CSR_INT. */
5126 if (inta_fh
& CSR_FH_INT_RX_MASK
)
5127 inta
|= CSR_INT_BIT_FH_RX
;
5128 if (inta_fh
& CSR_FH_INT_TX_MASK
)
5129 inta
|= CSR_INT_BIT_FH_TX
;
5131 /* Now service all interrupt bits discovered above. */
5132 if (inta
& CSR_INT_BIT_HW_ERR
) {
5133 IWL_ERROR("Microcode HW error detected. Restarting.\n");
5135 /* Tell the device to stop sending interrupts */
5136 iwl4965_disable_interrupts(priv
);
5138 iwl4965_irq_handle_error(priv
);
5140 handled
|= CSR_INT_BIT_HW_ERR
;
5142 spin_unlock_irqrestore(&priv
->lock
, flags
);
5147 #ifdef CONFIG_IWL4965_DEBUG
5148 if (iwl4965_debug_level
& (IWL_DL_ISR
)) {
5149 /* NIC fires this, but we don't use it, redundant with WAKEUP */
5150 if (inta
& CSR_INT_BIT_SCD
)
5151 IWL_DEBUG_ISR("Scheduler finished to transmit "
5152 "the frame/frames.\n");
5154 /* Alive notification via Rx interrupt will do the real work */
5155 if (inta
& CSR_INT_BIT_ALIVE
)
5156 IWL_DEBUG_ISR("Alive interrupt\n");
5159 /* Safely ignore these bits for debug checks below */
5160 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
5162 /* HW RF KILL switch toggled */
5163 if (inta
& CSR_INT_BIT_RF_KILL
) {
5165 if (!(iwl4965_read32(priv
, CSR_GP_CNTRL
) &
5166 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
5169 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
5170 "RF_KILL bit toggled to %s.\n",
5171 hw_rf_kill
? "disable radio":"enable radio");
5173 /* Queue restart only if RF_KILL switch was set to "kill"
5174 * when we loaded driver, and is now set to "enable".
5175 * After we're Alive, RF_KILL gets handled by
5176 * iwl_rx_card_state_notif() */
5177 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
5178 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5179 queue_work(priv
->workqueue
, &priv
->restart
);
5182 handled
|= CSR_INT_BIT_RF_KILL
;
5185 /* Chip got too hot and stopped itself */
5186 if (inta
& CSR_INT_BIT_CT_KILL
) {
5187 IWL_ERROR("Microcode CT kill error detected.\n");
5188 handled
|= CSR_INT_BIT_CT_KILL
;
5191 /* Error detected by uCode */
5192 if (inta
& CSR_INT_BIT_SW_ERR
) {
5193 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
5195 iwl4965_irq_handle_error(priv
);
5196 handled
|= CSR_INT_BIT_SW_ERR
;
5199 /* uCode wakes up after power-down sleep */
5200 if (inta
& CSR_INT_BIT_WAKEUP
) {
5201 IWL_DEBUG_ISR("Wakeup interrupt\n");
5202 iwl4965_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
5203 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
5204 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
5205 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
5206 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
5207 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
5208 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
5210 handled
|= CSR_INT_BIT_WAKEUP
;
5213 /* All uCode command responses, including Tx command responses,
5214 * Rx "responses" (frame-received notification), and other
5215 * notifications from uCode come through here*/
5216 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
5217 iwl4965_rx_handle(priv
);
5218 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
5221 if (inta
& CSR_INT_BIT_FH_TX
) {
5222 IWL_DEBUG_ISR("Tx interrupt\n");
5223 handled
|= CSR_INT_BIT_FH_TX
;
5226 if (inta
& ~handled
)
5227 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
5229 if (inta
& ~CSR_INI_SET_MASK
) {
5230 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
5231 inta
& ~CSR_INI_SET_MASK
);
5232 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
5235 /* Re-enable all interrupts */
5236 iwl4965_enable_interrupts(priv
);
5238 #ifdef CONFIG_IWL4965_DEBUG
5239 if (iwl4965_debug_level
& (IWL_DL_ISR
)) {
5240 inta
= iwl4965_read32(priv
, CSR_INT
);
5241 inta_mask
= iwl4965_read32(priv
, CSR_INT_MASK
);
5242 inta_fh
= iwl4965_read32(priv
, CSR_FH_INT_STATUS
);
5243 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
5244 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
5247 spin_unlock_irqrestore(&priv
->lock
, flags
);
5250 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
5252 struct iwl4965_priv
*priv
= data
;
5253 u32 inta
, inta_mask
;
5258 spin_lock(&priv
->lock
);
5260 /* Disable (but don't clear!) interrupts here to avoid
5261 * back-to-back ISRs and sporadic interrupts from our NIC.
5262 * If we have something to service, the tasklet will re-enable ints.
5263 * If we *don't* have something, we'll re-enable before leaving here. */
5264 inta_mask
= iwl4965_read32(priv
, CSR_INT_MASK
); /* just for debug */
5265 iwl4965_write32(priv
, CSR_INT_MASK
, 0x00000000);
5267 /* Discover which interrupts are active/pending */
5268 inta
= iwl4965_read32(priv
, CSR_INT
);
5269 inta_fh
= iwl4965_read32(priv
, CSR_FH_INT_STATUS
);
5271 /* Ignore interrupt if there's nothing in NIC to service.
5272 * This may be due to IRQ shared with another device,
5273 * or due to sporadic interrupts thrown from our NIC. */
5274 if (!inta
&& !inta_fh
) {
5275 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
5279 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
5280 /* Hardware disappeared. It might have already raised
5282 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
5286 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
5287 inta
, inta_mask
, inta_fh
);
5289 inta
&= ~CSR_INT_BIT_SCD
;
5291 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
5292 if (likely(inta
|| inta_fh
))
5293 tasklet_schedule(&priv
->irq_tasklet
);
5296 spin_unlock(&priv
->lock
);
5300 /* re-enable interrupts here since we don't have anything to service. */
5301 iwl4965_enable_interrupts(priv
);
5302 spin_unlock(&priv
->lock
);
5306 /************************** EEPROM BANDS ****************************
5308 * The iwl4965_eeprom_band definitions below provide the mapping from the
5309 * EEPROM contents to the specific channel number supported for each
5312 * For example, iwl4965_priv->eeprom.band_3_channels[4] from the band_3
5313 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
5314 * The specific geography and calibration information for that channel
5315 * is contained in the eeprom map itself.
5317 * During init, we copy the eeprom information and channel map
5318 * information into priv->channel_info_24/52 and priv->channel_map_24/52
5320 * channel_map_24/52 provides the index in the channel_info array for a
5321 * given channel. We have to have two separate maps as there is channel
5322 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
5325 * A value of 0xff stored in the channel_map indicates that the channel
5326 * is not supported by the hardware at all.
5328 * A value of 0xfe in the channel_map indicates that the channel is not
5329 * valid for Tx with the current hardware. This means that
5330 * while the system can tune and receive on a given channel, it may not
5331 * be able to associate or transmit any frames on that
5332 * channel. There is no corresponding channel information for that
5335 *********************************************************************/
5338 static const u8 iwl4965_eeprom_band_1
[14] = {
5339 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
5343 static const u8 iwl4965_eeprom_band_2
[] = { /* 4915-5080MHz */
5344 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
5347 static const u8 iwl4965_eeprom_band_3
[] = { /* 5170-5320MHz */
5348 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
5351 static const u8 iwl4965_eeprom_band_4
[] = { /* 5500-5700MHz */
5352 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
5355 static const u8 iwl4965_eeprom_band_5
[] = { /* 5725-5825MHz */
5356 145, 149, 153, 157, 161, 165
5359 static u8 iwl4965_eeprom_band_6
[] = { /* 2.4 FAT channel */
5363 static u8 iwl4965_eeprom_band_7
[] = { /* 5.2 FAT channel */
5364 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
5367 static void iwl4965_init_band_reference(const struct iwl4965_priv
*priv
,
5369 int *eeprom_ch_count
,
5370 const struct iwl4965_eeprom_channel
5372 const u8
**eeprom_ch_index
)
5375 case 1: /* 2.4GHz band */
5376 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_1
);
5377 *eeprom_ch_info
= priv
->eeprom
.band_1_channels
;
5378 *eeprom_ch_index
= iwl4965_eeprom_band_1
;
5380 case 2: /* 4.9GHz band */
5381 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_2
);
5382 *eeprom_ch_info
= priv
->eeprom
.band_2_channels
;
5383 *eeprom_ch_index
= iwl4965_eeprom_band_2
;
5385 case 3: /* 5.2GHz band */
5386 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_3
);
5387 *eeprom_ch_info
= priv
->eeprom
.band_3_channels
;
5388 *eeprom_ch_index
= iwl4965_eeprom_band_3
;
5390 case 4: /* 5.5GHz band */
5391 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_4
);
5392 *eeprom_ch_info
= priv
->eeprom
.band_4_channels
;
5393 *eeprom_ch_index
= iwl4965_eeprom_band_4
;
5395 case 5: /* 5.7GHz band */
5396 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_5
);
5397 *eeprom_ch_info
= priv
->eeprom
.band_5_channels
;
5398 *eeprom_ch_index
= iwl4965_eeprom_band_5
;
5400 case 6: /* 2.4GHz FAT channels */
5401 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_6
);
5402 *eeprom_ch_info
= priv
->eeprom
.band_24_channels
;
5403 *eeprom_ch_index
= iwl4965_eeprom_band_6
;
5405 case 7: /* 5 GHz FAT channels */
5406 *eeprom_ch_count
= ARRAY_SIZE(iwl4965_eeprom_band_7
);
5407 *eeprom_ch_info
= priv
->eeprom
.band_52_channels
;
5408 *eeprom_ch_index
= iwl4965_eeprom_band_7
;
5417 * iwl4965_get_channel_info - Find driver's private channel info
5419 * Based on band and channel number.
5421 const struct iwl4965_channel_info
*iwl4965_get_channel_info(const struct iwl4965_priv
*priv
,
5422 int phymode
, u16 channel
)
5427 case MODE_IEEE80211A
:
5428 for (i
= 14; i
< priv
->channel_count
; i
++) {
5429 if (priv
->channel_info
[i
].channel
== channel
)
5430 return &priv
->channel_info
[i
];
5434 case MODE_IEEE80211B
:
5435 case MODE_IEEE80211G
:
5436 if (channel
>= 1 && channel
<= 14)
5437 return &priv
->channel_info
[channel
- 1];
5445 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
5449 * iwl4965_init_channel_map - Set up driver's info for all possible channels
5451 static int iwl4965_init_channel_map(struct iwl4965_priv
*priv
)
5453 int eeprom_ch_count
= 0;
5454 const u8
*eeprom_ch_index
= NULL
;
5455 const struct iwl4965_eeprom_channel
*eeprom_ch_info
= NULL
;
5457 struct iwl4965_channel_info
*ch_info
;
5459 if (priv
->channel_count
) {
5460 IWL_DEBUG_INFO("Channel map already initialized.\n");
5464 if (priv
->eeprom
.version
< 0x2f) {
5465 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
5466 priv
->eeprom
.version
);
5470 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5472 priv
->channel_count
=
5473 ARRAY_SIZE(iwl4965_eeprom_band_1
) +
5474 ARRAY_SIZE(iwl4965_eeprom_band_2
) +
5475 ARRAY_SIZE(iwl4965_eeprom_band_3
) +
5476 ARRAY_SIZE(iwl4965_eeprom_band_4
) +
5477 ARRAY_SIZE(iwl4965_eeprom_band_5
);
5479 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv
->channel_count
);
5481 priv
->channel_info
= kzalloc(sizeof(struct iwl4965_channel_info
) *
5482 priv
->channel_count
, GFP_KERNEL
);
5483 if (!priv
->channel_info
) {
5484 IWL_ERROR("Could not allocate channel_info\n");
5485 priv
->channel_count
= 0;
5489 ch_info
= priv
->channel_info
;
5491 /* Loop through the 5 EEPROM bands adding them in order to the
5492 * channel map we maintain (that contains additional information than
5493 * what just in the EEPROM) */
5494 for (band
= 1; band
<= 5; band
++) {
5496 iwl4965_init_band_reference(priv
, band
, &eeprom_ch_count
,
5497 &eeprom_ch_info
, &eeprom_ch_index
);
5499 /* Loop through each band adding each of the channels */
5500 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
5501 ch_info
->channel
= eeprom_ch_index
[ch
];
5502 ch_info
->phymode
= (band
== 1) ? MODE_IEEE80211B
:
5505 /* permanently store EEPROM's channel regulatory flags
5506 * and max power in channel info database. */
5507 ch_info
->eeprom
= eeprom_ch_info
[ch
];
5509 /* Copy the run-time flags so they are there even on
5510 * invalid channels */
5511 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
5513 if (!(is_channel_valid(ch_info
))) {
5514 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5518 is_channel_a_band(ch_info
) ?
5524 /* Initialize regulatory-based run-time data */
5525 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
5526 eeprom_ch_info
[ch
].max_power_avg
;
5527 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
5528 ch_info
->min_power
= 0;
5530 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5531 " %ddBm): Ad-Hoc %ssupported\n",
5533 is_channel_a_band(ch_info
) ?
5535 CHECK_AND_PRINT(IBSS
),
5536 CHECK_AND_PRINT(ACTIVE
),
5537 CHECK_AND_PRINT(RADAR
),
5538 CHECK_AND_PRINT(WIDE
),
5539 CHECK_AND_PRINT(NARROW
),
5540 CHECK_AND_PRINT(DFS
),
5541 eeprom_ch_info
[ch
].flags
,
5542 eeprom_ch_info
[ch
].max_power_avg
,
5543 ((eeprom_ch_info
[ch
].
5544 flags
& EEPROM_CHANNEL_IBSS
)
5545 && !(eeprom_ch_info
[ch
].
5546 flags
& EEPROM_CHANNEL_RADAR
))
5549 /* Set the user_txpower_limit to the highest power
5550 * supported by any channel */
5551 if (eeprom_ch_info
[ch
].max_power_avg
>
5552 priv
->user_txpower_limit
)
5553 priv
->user_txpower_limit
=
5554 eeprom_ch_info
[ch
].max_power_avg
;
5560 /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */
5561 for (band
= 6; band
<= 7; band
++) {
5563 u8 fat_extension_chan
;
5565 iwl4965_init_band_reference(priv
, band
, &eeprom_ch_count
,
5566 &eeprom_ch_info
, &eeprom_ch_index
);
5568 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
5569 phymode
= (band
== 6) ? MODE_IEEE80211B
: MODE_IEEE80211A
;
5571 /* Loop through each band adding each of the channels */
5572 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
5575 ((eeprom_ch_index
[ch
] == 5) ||
5576 (eeprom_ch_index
[ch
] == 6) ||
5577 (eeprom_ch_index
[ch
] == 7)))
5578 fat_extension_chan
= HT_IE_EXT_CHANNEL_MAX
;
5580 fat_extension_chan
= HT_IE_EXT_CHANNEL_ABOVE
;
5582 /* Set up driver's info for lower half */
5583 iwl4965_set_fat_chan_info(priv
, phymode
,
5584 eeprom_ch_index
[ch
],
5585 &(eeprom_ch_info
[ch
]),
5586 fat_extension_chan
);
5588 /* Set up driver's info for upper half */
5589 iwl4965_set_fat_chan_info(priv
, phymode
,
5590 (eeprom_ch_index
[ch
] + 4),
5591 &(eeprom_ch_info
[ch
]),
5592 HT_IE_EXT_CHANNEL_BELOW
);
5600 * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map
5602 static void iwl4965_free_channel_map(struct iwl4965_priv
*priv
)
5604 kfree(priv
->channel_info
);
5605 priv
->channel_count
= 0;
5608 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5609 * sending probe req. This should be set long enough to hear probe responses
5610 * from more than one AP. */
5611 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5612 #define IWL_ACTIVE_DWELL_TIME_52 (10)
5614 /* For faster active scanning, scan will move to the next channel if fewer than
5615 * PLCP_QUIET_THRESH packets are heard on this channel within
5616 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5617 * time if it's a quiet channel (nothing responded to our probe, and there's
5618 * no other traffic).
5619 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5620 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5621 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5623 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5624 * Must be set longer than active dwell time.
5625 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5626 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5627 #define IWL_PASSIVE_DWELL_TIME_52 (10)
5628 #define IWL_PASSIVE_DWELL_BASE (100)
5629 #define IWL_CHANNEL_TUNE_TIME 5
5631 static inline u16
iwl4965_get_active_dwell_time(struct iwl4965_priv
*priv
, int phymode
)
5633 if (phymode
== MODE_IEEE80211A
)
5634 return IWL_ACTIVE_DWELL_TIME_52
;
5636 return IWL_ACTIVE_DWELL_TIME_24
;
5639 static u16
iwl4965_get_passive_dwell_time(struct iwl4965_priv
*priv
, int phymode
)
5641 u16 active
= iwl4965_get_active_dwell_time(priv
, phymode
);
5642 u16 passive
= (phymode
!= MODE_IEEE80211A
) ?
5643 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
5644 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
5646 if (iwl4965_is_associated(priv
)) {
5647 /* If we're associated, we clamp the maximum passive
5648 * dwell time to be 98% of the beacon interval (minus
5649 * 2 * channel tune time) */
5650 passive
= priv
->beacon_int
;
5651 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
5652 passive
= IWL_PASSIVE_DWELL_BASE
;
5653 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
5656 if (passive
<= active
)
5657 passive
= active
+ 1;
5662 static int iwl4965_get_channels_for_scan(struct iwl4965_priv
*priv
, int phymode
,
5663 u8 is_active
, u8 direct_mask
,
5664 struct iwl4965_scan_channel
*scan_ch
)
5666 const struct ieee80211_channel
*channels
= NULL
;
5667 const struct ieee80211_hw_mode
*hw_mode
;
5668 const struct iwl4965_channel_info
*ch_info
;
5669 u16 passive_dwell
= 0;
5670 u16 active_dwell
= 0;
5673 hw_mode
= iwl4965_get_hw_mode(priv
, phymode
);
5677 channels
= hw_mode
->channels
;
5679 active_dwell
= iwl4965_get_active_dwell_time(priv
, phymode
);
5680 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, phymode
);
5682 for (i
= 0, added
= 0; i
< hw_mode
->num_channels
; i
++) {
5683 if (channels
[i
].chan
==
5684 le16_to_cpu(priv
->active_rxon
.channel
)) {
5685 if (iwl4965_is_associated(priv
)) {
5687 ("Skipping current channel %d\n",
5688 le16_to_cpu(priv
->active_rxon
.channel
));
5691 } else if (priv
->only_active_channel
)
5694 scan_ch
->channel
= channels
[i
].chan
;
5696 ch_info
= iwl4965_get_channel_info(priv
, phymode
,
5698 if (!is_channel_valid(ch_info
)) {
5699 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5704 if (!is_active
|| is_channel_passive(ch_info
) ||
5705 !(channels
[i
].flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
))
5706 scan_ch
->type
= 0; /* passive */
5708 scan_ch
->type
= 1; /* active */
5710 if (scan_ch
->type
& 1)
5711 scan_ch
->type
|= (direct_mask
<< 1);
5713 if (is_channel_narrow(ch_info
))
5714 scan_ch
->type
|= (1 << 7);
5716 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
5717 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
5719 /* Set txpower levels to defaults */
5720 scan_ch
->tpc
.dsp_atten
= 110;
5721 /* scan_pwr_info->tpc.dsp_atten; */
5723 /*scan_pwr_info->tpc.tx_gain; */
5724 if (phymode
== MODE_IEEE80211A
)
5725 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
5727 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
5728 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
5730 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
5734 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5736 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
5737 (scan_ch
->type
& 1) ?
5738 active_dwell
: passive_dwell
);
5744 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
5748 static void iwl4965_reset_channel_flag(struct iwl4965_priv
*priv
)
5751 for (i
= 0; i
< 3; i
++) {
5752 struct ieee80211_hw_mode
*hw_mode
= (void *)&priv
->modes
[i
];
5753 for (j
= 0; j
< hw_mode
->num_channels
; j
++)
5754 hw_mode
->channels
[j
].flag
= hw_mode
->channels
[j
].val
;
5758 static void iwl4965_init_hw_rates(struct iwl4965_priv
*priv
,
5759 struct ieee80211_rate
*rates
)
5763 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
5764 rates
[i
].rate
= iwl4965_rates
[i
].ieee
* 5;
5765 rates
[i
].val
= i
; /* Rate scaling will work on indexes */
5767 rates
[i
].flags
= IEEE80211_RATE_SUPPORTED
;
5768 /* Only OFDM have the bits-per-symbol set */
5769 if ((i
<= IWL_LAST_OFDM_RATE
) && (i
>= IWL_FIRST_OFDM_RATE
))
5770 rates
[i
].flags
|= IEEE80211_RATE_OFDM
;
5773 * If CCK 1M then set rate flag to CCK else CCK_2
5774 * which is CCK | PREAMBLE2
5776 rates
[i
].flags
|= (iwl4965_rates
[i
].plcp
== 10) ?
5777 IEEE80211_RATE_CCK
: IEEE80211_RATE_CCK_2
;
5780 /* Set up which ones are basic rates... */
5781 if (IWL_BASIC_RATES_MASK
& (1 << i
))
5782 rates
[i
].flags
|= IEEE80211_RATE_BASIC
;
5787 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
5789 static int iwl4965_init_geos(struct iwl4965_priv
*priv
)
5791 struct iwl4965_channel_info
*ch
;
5792 struct ieee80211_hw_mode
*modes
;
5793 struct ieee80211_channel
*channels
;
5794 struct ieee80211_channel
*geo_ch
;
5795 struct ieee80211_rate
*rates
;
5805 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5806 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5810 modes
= kzalloc(sizeof(struct ieee80211_hw_mode
) * mode_count
,
5815 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
5816 priv
->channel_count
, GFP_KERNEL
);
5822 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_MAX_RATES
+ 1)),
5835 /* 5.2GHz channels start after the 2.4GHz channels */
5836 modes
[A
].mode
= MODE_IEEE80211A
;
5837 modes
[A
].channels
= &channels
[ARRAY_SIZE(iwl4965_eeprom_band_1
)];
5838 modes
[A
].rates
= rates
;
5839 modes
[A
].num_rates
= 8; /* just OFDM */
5840 modes
[A
].rates
= &rates
[4];
5841 modes
[A
].num_channels
= 0;
5842 #ifdef CONFIG_IWL4965_HT
5843 iwl4965_init_ht_hw_capab(&modes
[A
].ht_info
, MODE_IEEE80211A
);
5846 modes
[B
].mode
= MODE_IEEE80211B
;
5847 modes
[B
].channels
= channels
;
5848 modes
[B
].rates
= rates
;
5849 modes
[B
].num_rates
= 4; /* just CCK */
5850 modes
[B
].num_channels
= 0;
5852 modes
[G
].mode
= MODE_IEEE80211G
;
5853 modes
[G
].channels
= channels
;
5854 modes
[G
].rates
= rates
;
5855 modes
[G
].num_rates
= 12; /* OFDM & CCK */
5856 modes
[G
].num_channels
= 0;
5857 #ifdef CONFIG_IWL4965_HT
5858 iwl4965_init_ht_hw_capab(&modes
[G
].ht_info
, MODE_IEEE80211G
);
5861 priv
->ieee_channels
= channels
;
5862 priv
->ieee_rates
= rates
;
5864 iwl4965_init_hw_rates(priv
, rates
);
5866 for (i
= 0, geo_ch
= channels
; i
< priv
->channel_count
; i
++) {
5867 ch
= &priv
->channel_info
[i
];
5869 if (!is_channel_valid(ch
)) {
5870 IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5872 ch
->channel
, is_channel_a_band(ch
) ?
5877 if (is_channel_a_band(ch
)) {
5878 geo_ch
= &modes
[A
].channels
[modes
[A
].num_channels
++];
5880 geo_ch
= &modes
[B
].channels
[modes
[B
].num_channels
++];
5881 modes
[G
].num_channels
++;
5884 geo_ch
->freq
= ieee80211chan2mhz(ch
->channel
);
5885 geo_ch
->chan
= ch
->channel
;
5886 geo_ch
->power_level
= ch
->max_power_avg
;
5887 geo_ch
->antenna_max
= 0xff;
5889 if (is_channel_valid(ch
)) {
5890 geo_ch
->flag
= IEEE80211_CHAN_W_SCAN
;
5891 if (ch
->flags
& EEPROM_CHANNEL_IBSS
)
5892 geo_ch
->flag
|= IEEE80211_CHAN_W_IBSS
;
5894 if (ch
->flags
& EEPROM_CHANNEL_ACTIVE
)
5895 geo_ch
->flag
|= IEEE80211_CHAN_W_ACTIVE_SCAN
;
5897 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
5898 geo_ch
->flag
|= IEEE80211_CHAN_W_RADAR_DETECT
;
5900 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
5901 priv
->max_channel_txpower_limit
=
5905 geo_ch
->val
= geo_ch
->flag
;
5908 if ((modes
[A
].num_channels
== 0) && priv
->is_abg
) {
5909 printk(KERN_INFO DRV_NAME
5910 ": Incorrectly detected BG card as ABG. Please send "
5911 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5912 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
5916 printk(KERN_INFO DRV_NAME
5917 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5918 modes
[G
].num_channels
, modes
[A
].num_channels
);
5921 * NOTE: We register these in preference of order -- the
5922 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5923 * a phymode based on rates or AP capabilities but seems to
5924 * configure it purely on if the channel being configured
5925 * is supported by a mode -- and the first match is taken
5928 if (modes
[G
].num_channels
)
5929 ieee80211_register_hwmode(priv
->hw
, &modes
[G
]);
5930 if (modes
[B
].num_channels
)
5931 ieee80211_register_hwmode(priv
->hw
, &modes
[B
]);
5932 if (modes
[A
].num_channels
)
5933 ieee80211_register_hwmode(priv
->hw
, &modes
[A
]);
5935 priv
->modes
= modes
;
5936 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5942 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
5944 static void iwl4965_free_geos(struct iwl4965_priv
*priv
)
5947 kfree(priv
->ieee_channels
);
5948 kfree(priv
->ieee_rates
);
5949 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5952 /******************************************************************************
5954 * uCode download functions
5956 ******************************************************************************/
5958 static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv
*priv
)
5960 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5961 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5962 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5963 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5964 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5965 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5969 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
5970 * looking at all data.
5972 static int iwl4965_verify_inst_full(struct iwl4965_priv
*priv
, __le32
*image
,
5980 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5982 rc
= iwl4965_grab_nic_access(priv
);
5986 iwl4965_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
5989 for (; len
> 0; len
-= sizeof(u32
), image
++) {
5990 /* read data comes through single port, auto-incr addr */
5991 /* NOTE: Use the debugless read so we don't flood kernel log
5992 * if IWL_DL_IO is set */
5993 val
= _iwl4965_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5994 if (val
!= le32_to_cpu(*image
)) {
5995 IWL_ERROR("uCode INST section is invalid at "
5996 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5997 save_len
- len
, val
, le32_to_cpu(*image
));
6005 iwl4965_release_nic_access(priv
);
6009 ("ucode image in INSTRUCTION memory is good\n");
6016 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
6017 * using sample data 100 bytes apart. If these sample points are good,
6018 * it's a pretty good bet that everything between them is good, too.
6020 static int iwl4965_verify_inst_sparse(struct iwl4965_priv
*priv
, __le32
*image
, u32 len
)
6027 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
6029 rc
= iwl4965_grab_nic_access(priv
);
6033 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
6034 /* read data comes through single port, auto-incr addr */
6035 /* NOTE: Use the debugless read so we don't flood kernel log
6036 * if IWL_DL_IO is set */
6037 iwl4965_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
6038 i
+ RTC_INST_LOWER_BOUND
);
6039 val
= _iwl4965_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
6040 if (val
!= le32_to_cpu(*image
)) {
6041 #if 0 /* Enable this if you want to see details */
6042 IWL_ERROR("uCode INST section is invalid at "
6043 "offset 0x%x, is 0x%x, s/b 0x%x\n",
6053 iwl4965_release_nic_access(priv
);
6060 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
6061 * and verify its contents
6063 static int iwl4965_verify_ucode(struct iwl4965_priv
*priv
)
6070 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
6071 len
= priv
->ucode_boot
.len
;
6072 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
6074 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
6078 /* Try initialize */
6079 image
= (__le32
*)priv
->ucode_init
.v_addr
;
6080 len
= priv
->ucode_init
.len
;
6081 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
6083 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
6087 /* Try runtime/protocol */
6088 image
= (__le32
*)priv
->ucode_code
.v_addr
;
6089 len
= priv
->ucode_code
.len
;
6090 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
6092 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
6096 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
6098 /* Since nothing seems to match, show first several data entries in
6099 * instruction SRAM, so maybe visual inspection will give a clue.
6100 * Selection of bootstrap image (vs. other images) is arbitrary. */
6101 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
6102 len
= priv
->ucode_boot
.len
;
6103 rc
= iwl4965_verify_inst_full(priv
, image
, len
);
6109 /* check contents of special bootstrap uCode SRAM */
6110 static int iwl4965_verify_bsm(struct iwl4965_priv
*priv
)
6112 __le32
*image
= priv
->ucode_boot
.v_addr
;
6113 u32 len
= priv
->ucode_boot
.len
;
6117 IWL_DEBUG_INFO("Begin verify bsm\n");
6119 /* verify BSM SRAM contents */
6120 val
= iwl4965_read_prph(priv
, BSM_WR_DWCOUNT_REG
);
6121 for (reg
= BSM_SRAM_LOWER_BOUND
;
6122 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
6123 reg
+= sizeof(u32
), image
++) {
6124 val
= iwl4965_read_prph(priv
, reg
);
6125 if (val
!= le32_to_cpu(*image
)) {
6126 IWL_ERROR("BSM uCode verification failed at "
6127 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
6128 BSM_SRAM_LOWER_BOUND
,
6129 reg
- BSM_SRAM_LOWER_BOUND
, len
,
6130 val
, le32_to_cpu(*image
));
6135 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
6141 * iwl4965_load_bsm - Load bootstrap instructions
6145 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
6146 * in special SRAM that does not power down during RFKILL. When powering back
6147 * up after power-saving sleeps (or during initial uCode load), the BSM loads
6148 * the bootstrap program into the on-board processor, and starts it.
6150 * The bootstrap program loads (via DMA) instructions and data for a new
6151 * program from host DRAM locations indicated by the host driver in the
6152 * BSM_DRAM_* registers. Once the new program is loaded, it starts
6155 * When initializing the NIC, the host driver points the BSM to the
6156 * "initialize" uCode image. This uCode sets up some internal data, then
6157 * notifies host via "initialize alive" that it is complete.
6159 * The host then replaces the BSM_DRAM_* pointer values to point to the
6160 * normal runtime uCode instructions and a backup uCode data cache buffer
6161 * (filled initially with starting data values for the on-board processor),
6162 * then triggers the "initialize" uCode to load and launch the runtime uCode,
6163 * which begins normal operation.
6165 * When doing a power-save shutdown, runtime uCode saves data SRAM into
6166 * the backup data cache in DRAM before SRAM is powered down.
6168 * When powering back up, the BSM loads the bootstrap program. This reloads
6169 * the runtime uCode instructions and the backup data cache into SRAM,
6170 * and re-launches the runtime uCode from where it left off.
6172 static int iwl4965_load_bsm(struct iwl4965_priv
*priv
)
6174 __le32
*image
= priv
->ucode_boot
.v_addr
;
6175 u32 len
= priv
->ucode_boot
.len
;
6185 IWL_DEBUG_INFO("Begin load bsm\n");
6187 /* make sure bootstrap program is no larger than BSM's SRAM size */
6188 if (len
> IWL_MAX_BSM_SIZE
)
6191 /* Tell bootstrap uCode where to find the "Initialize" uCode
6192 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
6193 * NOTE: iwl4965_initialize_alive_start() will replace these values,
6194 * after the "initialize" uCode has run, to point to
6195 * runtime/protocol instructions and backup data cache. */
6196 pinst
= priv
->ucode_init
.p_addr
>> 4;
6197 pdata
= priv
->ucode_init_data
.p_addr
>> 4;
6198 inst_len
= priv
->ucode_init
.len
;
6199 data_len
= priv
->ucode_init_data
.len
;
6201 rc
= iwl4965_grab_nic_access(priv
);
6205 iwl4965_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
6206 iwl4965_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
6207 iwl4965_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
6208 iwl4965_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
6210 /* Fill BSM memory with bootstrap instructions */
6211 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
6212 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
6213 reg_offset
+= sizeof(u32
), image
++)
6214 _iwl4965_write_prph(priv
, reg_offset
,
6215 le32_to_cpu(*image
));
6217 rc
= iwl4965_verify_bsm(priv
);
6219 iwl4965_release_nic_access(priv
);
6223 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
6224 iwl4965_write_prph(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
6225 iwl4965_write_prph(priv
, BSM_WR_MEM_DST_REG
,
6226 RTC_INST_LOWER_BOUND
);
6227 iwl4965_write_prph(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
6229 /* Load bootstrap code into instruction SRAM now,
6230 * to prepare to load "initialize" uCode */
6231 iwl4965_write_prph(priv
, BSM_WR_CTRL_REG
,
6232 BSM_WR_CTRL_REG_BIT_START
);
6234 /* Wait for load of bootstrap uCode to finish */
6235 for (i
= 0; i
< 100; i
++) {
6236 done
= iwl4965_read_prph(priv
, BSM_WR_CTRL_REG
);
6237 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
6242 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i
);
6244 IWL_ERROR("BSM write did not complete!\n");
6248 /* Enable future boot loads whenever power management unit triggers it
6249 * (e.g. when powering back up after power-save shutdown) */
6250 iwl4965_write_prph(priv
, BSM_WR_CTRL_REG
,
6251 BSM_WR_CTRL_REG_BIT_START_EN
);
6253 iwl4965_release_nic_access(priv
);
6258 static void iwl4965_nic_start(struct iwl4965_priv
*priv
)
6260 /* Remove all resets to allow NIC to operate */
6261 iwl4965_write32(priv
, CSR_RESET
, 0);
6266 * iwl4965_read_ucode - Read uCode images from disk file.
6268 * Copy into buffers for card to fetch via bus-mastering
6270 static int iwl4965_read_ucode(struct iwl4965_priv
*priv
)
6272 struct iwl4965_ucode
*ucode
;
6274 const struct firmware
*ucode_raw
;
6275 const char *name
= "iwlwifi-4965" IWL4965_UCODE_API
".ucode";
6278 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
6280 /* Ask kernel firmware_class module to get the boot firmware off disk.
6281 * request_firmware() is synchronous, file is in memory on return. */
6282 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
6284 IWL_ERROR("%s firmware file req failed: Reason %d\n",
6289 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
6290 name
, ucode_raw
->size
);
6292 /* Make sure that we got at least our header! */
6293 if (ucode_raw
->size
< sizeof(*ucode
)) {
6294 IWL_ERROR("File size way too small!\n");
6299 /* Data from ucode file: header followed by uCode images */
6300 ucode
= (void *)ucode_raw
->data
;
6302 ver
= le32_to_cpu(ucode
->ver
);
6303 inst_size
= le32_to_cpu(ucode
->inst_size
);
6304 data_size
= le32_to_cpu(ucode
->data_size
);
6305 init_size
= le32_to_cpu(ucode
->init_size
);
6306 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
6307 boot_size
= le32_to_cpu(ucode
->boot_size
);
6309 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
6310 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
6312 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
6314 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
6316 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
6318 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
6321 /* Verify size of file vs. image size info in file's header */
6322 if (ucode_raw
->size
< sizeof(*ucode
) +
6323 inst_size
+ data_size
+ init_size
+
6324 init_data_size
+ boot_size
) {
6326 IWL_DEBUG_INFO("uCode file size %d too small\n",
6327 (int)ucode_raw
->size
);
6332 /* Verify that uCode images will fit in card's SRAM */
6333 if (inst_size
> IWL_MAX_INST_SIZE
) {
6334 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
6340 if (data_size
> IWL_MAX_DATA_SIZE
) {
6341 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
6346 if (init_size
> IWL_MAX_INST_SIZE
) {
6348 ("uCode init instr len %d too large to fit in\n",
6353 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
6355 ("uCode init data len %d too large to fit in\n",
6360 if (boot_size
> IWL_MAX_BSM_SIZE
) {
6362 ("uCode boot instr len %d too large to fit in\n",
6368 /* Allocate ucode buffers for card's bus-master loading ... */
6370 /* Runtime instructions and 2 copies of data:
6371 * 1) unmodified from disk
6372 * 2) backup cache for save/restore during power-downs */
6373 priv
->ucode_code
.len
= inst_size
;
6374 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
6376 priv
->ucode_data
.len
= data_size
;
6377 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
6379 priv
->ucode_data_backup
.len
= data_size
;
6380 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
6382 /* Initialization instructions and data */
6383 if (init_size
&& init_data_size
) {
6384 priv
->ucode_init
.len
= init_size
;
6385 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
6387 priv
->ucode_init_data
.len
= init_data_size
;
6388 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
6390 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
6394 /* Bootstrap (instructions only, no data) */
6396 priv
->ucode_boot
.len
= boot_size
;
6397 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
6399 if (!priv
->ucode_boot
.v_addr
)
6403 /* Copy images into buffers for card's bus-master reads ... */
6405 /* Runtime instructions (first block of data in file) */
6406 src
= &ucode
->data
[0];
6407 len
= priv
->ucode_code
.len
;
6408 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
6409 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
6410 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
6411 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
6413 /* Runtime data (2nd block)
6414 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
6415 src
= &ucode
->data
[inst_size
];
6416 len
= priv
->ucode_data
.len
;
6417 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
6418 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
6419 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
6421 /* Initialization instructions (3rd block) */
6423 src
= &ucode
->data
[inst_size
+ data_size
];
6424 len
= priv
->ucode_init
.len
;
6425 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
6427 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
6430 /* Initialization data (4th block) */
6431 if (init_data_size
) {
6432 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
6433 len
= priv
->ucode_init_data
.len
;
6434 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
6436 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
6439 /* Bootstrap instructions (5th block) */
6440 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
6441 len
= priv
->ucode_boot
.len
;
6442 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
6443 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
6445 /* We have our copies now, allow OS release its copies */
6446 release_firmware(ucode_raw
);
6450 IWL_ERROR("failed to allocate pci memory\n");
6452 iwl4965_dealloc_ucode_pci(priv
);
6455 release_firmware(ucode_raw
);
6463 * iwl4965_set_ucode_ptrs - Set uCode address location
6465 * Tell initialization uCode where to find runtime uCode.
6467 * BSM registers initially contain pointers to initialization uCode.
6468 * We need to replace them to load runtime uCode inst and data,
6469 * and to save runtime data when powering down.
6471 static int iwl4965_set_ucode_ptrs(struct iwl4965_priv
*priv
)
6476 unsigned long flags
;
6478 /* bits 35:4 for 4965 */
6479 pinst
= priv
->ucode_code
.p_addr
>> 4;
6480 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
6482 spin_lock_irqsave(&priv
->lock
, flags
);
6483 rc
= iwl4965_grab_nic_access(priv
);
6485 spin_unlock_irqrestore(&priv
->lock
, flags
);
6489 /* Tell bootstrap uCode where to find image to load */
6490 iwl4965_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
6491 iwl4965_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
6492 iwl4965_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
6493 priv
->ucode_data
.len
);
6495 /* Inst bytecount must be last to set up, bit 31 signals uCode
6496 * that all new ptr/size info is in place */
6497 iwl4965_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
6498 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
6500 iwl4965_release_nic_access(priv
);
6502 spin_unlock_irqrestore(&priv
->lock
, flags
);
6504 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6510 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
6512 * Called after REPLY_ALIVE notification received from "initialize" uCode.
6514 * The 4965 "initialize" ALIVE reply contains calibration data for:
6515 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
6516 * (3945 does not contain this data).
6518 * Tell "initialize" uCode to go ahead and load the runtime uCode.
6520 static void iwl4965_init_alive_start(struct iwl4965_priv
*priv
)
6522 /* Check alive response for "valid" sign from uCode */
6523 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
6524 /* We had an error bringing up the hardware, so take it
6525 * all the way back down so we can try again */
6526 IWL_DEBUG_INFO("Initialize Alive failed.\n");
6530 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6531 * This is a paranoid check, because we would not have gotten the
6532 * "initialize" alive if code weren't properly loaded. */
6533 if (iwl4965_verify_ucode(priv
)) {
6534 /* Runtime instruction load was bad;
6535 * take it all the way back down so we can try again */
6536 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6540 /* Calculate temperature */
6541 priv
->temperature
= iwl4965_get_temperature(priv
);
6543 /* Send pointers to protocol/runtime uCode image ... init code will
6544 * load and launch runtime uCode, which will send us another "Alive"
6546 IWL_DEBUG_INFO("Initialization Alive received.\n");
6547 if (iwl4965_set_ucode_ptrs(priv
)) {
6548 /* Runtime instruction load won't happen;
6549 * take it all the way back down so we can try again */
6550 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6556 queue_work(priv
->workqueue
, &priv
->restart
);
6561 * iwl4965_alive_start - called after REPLY_ALIVE notification received
6562 * from protocol/runtime uCode (initialization uCode's
6563 * Alive gets handled by iwl4965_init_alive_start()).
6565 static void iwl4965_alive_start(struct iwl4965_priv
*priv
)
6569 IWL_DEBUG_INFO("Runtime Alive received.\n");
6571 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
6572 /* We had an error bringing up the hardware, so take it
6573 * all the way back down so we can try again */
6574 IWL_DEBUG_INFO("Alive failed.\n");
6578 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
6579 * This is a paranoid check, because we would not have gotten the
6580 * "runtime" alive if code weren't properly loaded. */
6581 if (iwl4965_verify_ucode(priv
)) {
6582 /* Runtime instruction load was bad;
6583 * take it all the way back down so we can try again */
6584 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6588 iwl4965_clear_stations_table(priv
);
6590 rc
= iwl4965_alive_notify(priv
);
6592 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
6597 /* After the ALIVE response, we can send host commands to 4965 uCode */
6598 set_bit(STATUS_ALIVE
, &priv
->status
);
6600 /* Clear out the uCode error bit if it is set */
6601 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
6603 if (iwl4965_is_rfkill(priv
))
6606 ieee80211_start_queues(priv
->hw
);
6608 priv
->active_rate
= priv
->rates_mask
;
6609 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
6611 iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
6613 if (iwl4965_is_associated(priv
)) {
6614 struct iwl4965_rxon_cmd
*active_rxon
=
6615 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
6617 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
6618 sizeof(priv
->staging_rxon
));
6619 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6621 /* Initialize our rx_config data */
6622 iwl4965_connection_init_rx_config(priv
);
6623 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
6626 /* Configure Bluetooth device coexistence support */
6627 iwl4965_send_bt_config(priv
);
6629 /* Configure the adapter for unassociated operation */
6630 iwl4965_commit_rxon(priv
);
6632 /* At this point, the NIC is initialized and operational */
6633 priv
->notif_missed_beacons
= 0;
6634 set_bit(STATUS_READY
, &priv
->status
);
6636 iwl4965_rf_kill_ct_config(priv
);
6638 IWL_DEBUG_INFO("ALIVE processing complete.\n");
6639 wake_up_interruptible(&priv
->wait_command_queue
);
6641 if (priv
->error_recovering
)
6642 iwl4965_error_recovery(priv
);
6647 queue_work(priv
->workqueue
, &priv
->restart
);
6650 static void iwl4965_cancel_deferred_work(struct iwl4965_priv
*priv
);
6652 static void __iwl4965_down(struct iwl4965_priv
*priv
)
6654 unsigned long flags
;
6655 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6656 struct ieee80211_conf
*conf
= NULL
;
6658 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
6660 conf
= ieee80211_get_hw_conf(priv
->hw
);
6663 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6665 iwl4965_clear_stations_table(priv
);
6667 /* Unblock any waiting calls */
6668 wake_up_interruptible_all(&priv
->wait_command_queue
);
6670 /* Wipe out the EXIT_PENDING status bit if we are not actually
6671 * exiting the module */
6673 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6675 /* stop and reset the on-board processor */
6676 iwl4965_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
6678 /* tell the device to stop sending interrupts */
6679 iwl4965_disable_interrupts(priv
);
6681 if (priv
->mac80211_registered
)
6682 ieee80211_stop_queues(priv
->hw
);
6684 /* If we have not previously called iwl4965_init() then
6685 * clear all bits but the RF Kill and SUSPEND bits and return */
6686 if (!iwl4965_is_init(priv
)) {
6687 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
6689 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
6691 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
6692 STATUS_GEO_CONFIGURED
|
6693 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
6698 /* ...otherwise clear out all the status bits but the RF Kill and
6699 * SUSPEND bits and continue taking the NIC down. */
6700 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
6702 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
6704 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
6705 STATUS_GEO_CONFIGURED
|
6706 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
6708 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
6711 spin_lock_irqsave(&priv
->lock
, flags
);
6712 iwl4965_clear_bit(priv
, CSR_GP_CNTRL
,
6713 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
6714 spin_unlock_irqrestore(&priv
->lock
, flags
);
6716 iwl4965_hw_txq_ctx_stop(priv
);
6717 iwl4965_hw_rxq_stop(priv
);
6719 spin_lock_irqsave(&priv
->lock
, flags
);
6720 if (!iwl4965_grab_nic_access(priv
)) {
6721 iwl4965_write_prph(priv
, APMG_CLK_DIS_REG
,
6722 APMG_CLK_VAL_DMA_CLK_RQT
);
6723 iwl4965_release_nic_access(priv
);
6725 spin_unlock_irqrestore(&priv
->lock
, flags
);
6729 iwl4965_hw_nic_stop_master(priv
);
6730 iwl4965_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
6731 iwl4965_hw_nic_reset(priv
);
6734 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
6736 if (priv
->ibss_beacon
)
6737 dev_kfree_skb(priv
->ibss_beacon
);
6738 priv
->ibss_beacon
= NULL
;
6740 /* clear out any free frames */
6741 iwl4965_clear_free_frames(priv
);
6744 static void iwl4965_down(struct iwl4965_priv
*priv
)
6746 mutex_lock(&priv
->mutex
);
6747 __iwl4965_down(priv
);
6748 mutex_unlock(&priv
->mutex
);
6750 iwl4965_cancel_deferred_work(priv
);
6753 #define MAX_HW_RESTARTS 5
6755 static int __iwl4965_up(struct iwl4965_priv
*priv
)
6759 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6760 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6764 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
6765 IWL_WARNING("Radio disabled by SW RF kill (module "
6770 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
6771 IWL_ERROR("ucode not available for device bringup\n");
6775 /* If platform's RF_KILL switch is NOT set to KILL */
6776 if (iwl4965_read32(priv
, CSR_GP_CNTRL
) &
6777 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
6778 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
6780 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
6781 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
6782 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
6787 iwl4965_write32(priv
, CSR_INT
, 0xFFFFFFFF);
6789 rc
= iwl4965_hw_nic_init(priv
);
6791 IWL_ERROR("Unable to int nic\n");
6795 /* make sure rfkill handshake bits are cleared */
6796 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6797 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
6798 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
6800 /* clear (again), then enable host interrupts */
6801 iwl4965_write32(priv
, CSR_INT
, 0xFFFFFFFF);
6802 iwl4965_enable_interrupts(priv
);
6804 /* really make sure rfkill handshake bits are cleared */
6805 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6806 iwl4965_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6808 /* Copy original ucode data image from disk into backup cache.
6809 * This will be used to initialize the on-board processor's
6810 * data SRAM for a clean start when the runtime program first loads. */
6811 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
6812 priv
->ucode_data
.len
);
6814 /* We return success when we resume from suspend and rf_kill is on. */
6815 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
6818 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
6820 iwl4965_clear_stations_table(priv
);
6822 /* load bootstrap state machine,
6823 * load bootstrap program into processor's memory,
6824 * prepare to load the "initialize" uCode */
6825 rc
= iwl4965_load_bsm(priv
);
6828 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc
);
6832 /* start card; "initialize" will load runtime ucode */
6833 iwl4965_nic_start(priv
);
6835 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
6840 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6841 __iwl4965_down(priv
);
6843 /* tried to restart and config the device for as long as our
6844 * patience could withstand */
6845 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
6850 /*****************************************************************************
6852 * Workqueue callbacks
6854 *****************************************************************************/
6856 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
6858 struct iwl4965_priv
*priv
=
6859 container_of(data
, struct iwl4965_priv
, init_alive_start
.work
);
6861 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6864 mutex_lock(&priv
->mutex
);
6865 iwl4965_init_alive_start(priv
);
6866 mutex_unlock(&priv
->mutex
);
6869 static void iwl4965_bg_alive_start(struct work_struct
*data
)
6871 struct iwl4965_priv
*priv
=
6872 container_of(data
, struct iwl4965_priv
, alive_start
.work
);
6874 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6877 mutex_lock(&priv
->mutex
);
6878 iwl4965_alive_start(priv
);
6879 mutex_unlock(&priv
->mutex
);
6882 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
6884 struct iwl4965_priv
*priv
= container_of(work
, struct iwl4965_priv
, rf_kill
);
6886 wake_up_interruptible(&priv
->wait_command_queue
);
6888 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6891 mutex_lock(&priv
->mutex
);
6893 if (!iwl4965_is_rfkill(priv
)) {
6894 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
6895 "HW and/or SW RF Kill no longer active, restarting "
6897 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6898 queue_work(priv
->workqueue
, &priv
->restart
);
6901 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
6902 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6903 "disabled by SW switch\n");
6905 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6906 "Kill switch must be turned off for "
6907 "wireless networking to work.\n");
6909 mutex_unlock(&priv
->mutex
);
6912 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6914 static void iwl4965_bg_scan_check(struct work_struct
*data
)
6916 struct iwl4965_priv
*priv
=
6917 container_of(data
, struct iwl4965_priv
, scan_check
.work
);
6919 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6922 mutex_lock(&priv
->mutex
);
6923 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
6924 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6925 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
6926 "Scan completion watchdog resetting adapter (%dms)\n",
6927 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
6929 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6930 iwl4965_send_scan_abort(priv
);
6932 mutex_unlock(&priv
->mutex
);
6935 static void iwl4965_bg_request_scan(struct work_struct
*data
)
6937 struct iwl4965_priv
*priv
=
6938 container_of(data
, struct iwl4965_priv
, request_scan
);
6939 struct iwl4965_host_cmd cmd
= {
6940 .id
= REPLY_SCAN_CMD
,
6941 .len
= sizeof(struct iwl4965_scan_cmd
),
6942 .meta
.flags
= CMD_SIZE_HUGE
,
6945 struct iwl4965_scan_cmd
*scan
;
6946 struct ieee80211_conf
*conf
= NULL
;
6950 conf
= ieee80211_get_hw_conf(priv
->hw
);
6952 mutex_lock(&priv
->mutex
);
6954 if (!iwl4965_is_ready(priv
)) {
6955 IWL_WARNING("request scan called when driver not ready.\n");
6959 /* Make sure the scan wasn't cancelled before this queued work
6960 * was given the chance to run... */
6961 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
6964 /* This should never be called or scheduled if there is currently
6965 * a scan active in the hardware. */
6966 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
6967 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6968 "Ignoring second request.\n");
6973 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6974 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6978 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6979 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6983 if (iwl4965_is_rfkill(priv
)) {
6984 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6988 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6989 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6993 if (!priv
->scan_bands
) {
6994 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6999 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
7000 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
7007 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
7009 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
7010 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
7012 if (iwl4965_is_associated(priv
)) {
7015 u32 suspend_time
= 100;
7016 u32 scan_suspend_time
= 100;
7017 unsigned long flags
;
7019 IWL_DEBUG_INFO("Scanning while associated...\n");
7021 spin_lock_irqsave(&priv
->lock
, flags
);
7022 interval
= priv
->beacon_int
;
7023 spin_unlock_irqrestore(&priv
->lock
, flags
);
7025 scan
->suspend_time
= 0;
7026 scan
->max_out_time
= cpu_to_le32(200 * 1024);
7028 interval
= suspend_time
;
7030 extra
= (suspend_time
/ interval
) << 22;
7031 scan_suspend_time
= (extra
|
7032 ((suspend_time
% interval
) * 1024));
7033 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
7034 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
7035 scan_suspend_time
, interval
);
7038 /* We should add the ability for user to lock to PASSIVE ONLY */
7039 if (priv
->one_direct_scan
) {
7041 ("Kicking off one direct scan for '%s'\n",
7042 iwl4965_escape_essid(priv
->direct_ssid
,
7043 priv
->direct_ssid_len
));
7044 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
7045 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
7046 memcpy(scan
->direct_scan
[0].ssid
,
7047 priv
->direct_ssid
, priv
->direct_ssid_len
);
7049 } else if (!iwl4965_is_associated(priv
) && priv
->essid_len
) {
7050 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
7051 scan
->direct_scan
[0].len
= priv
->essid_len
;
7052 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
7057 /* We don't build a direct scan probe request; the uCode will do
7058 * that based on the direct_mask added to each channel entry */
7059 scan
->tx_cmd
.len
= cpu_to_le16(
7060 iwl4965_fill_probe_req(priv
, (struct ieee80211_mgmt
*)scan
->data
,
7061 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0));
7062 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
7063 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
7064 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
7066 /* flags + rate selection */
7068 scan
->tx_cmd
.tx_flags
|= cpu_to_le32(0x200);
7070 switch (priv
->scan_bands
) {
7072 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
7073 scan
->tx_cmd
.rate_n_flags
=
7074 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
7075 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
7077 scan
->good_CRC_th
= 0;
7078 phymode
= MODE_IEEE80211G
;
7082 scan
->tx_cmd
.rate_n_flags
=
7083 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
7084 RATE_MCS_ANT_B_MSK
);
7085 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
7086 phymode
= MODE_IEEE80211A
;
7090 IWL_WARNING("Invalid scan band count\n");
7094 /* select Rx chains */
7096 /* Force use of chains B and C (0x6) for scan Rx.
7097 * Avoid A (0x1) because of its off-channel reception on A-band.
7098 * MIMO is not used here, but value is required to make uCode happy. */
7099 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
7100 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
7101 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
7102 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
7104 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
7105 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
7109 ("Initiating direct scan for %s.\n",
7110 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
7112 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
7114 scan
->channel_count
=
7115 iwl4965_get_channels_for_scan(
7116 priv
, phymode
, 1, /* active */
7118 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
7120 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
7121 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
7123 scan
->len
= cpu_to_le16(cmd
.len
);
7125 set_bit(STATUS_SCAN_HW
, &priv
->status
);
7126 rc
= iwl4965_send_cmd_sync(priv
, &cmd
);
7130 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
7131 IWL_SCAN_CHECK_WATCHDOG
);
7133 mutex_unlock(&priv
->mutex
);
7137 /* inform mac80211 scan aborted */
7138 queue_work(priv
->workqueue
, &priv
->scan_completed
);
7139 mutex_unlock(&priv
->mutex
);
7142 static void iwl4965_bg_up(struct work_struct
*data
)
7144 struct iwl4965_priv
*priv
= container_of(data
, struct iwl4965_priv
, up
);
7146 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
7149 mutex_lock(&priv
->mutex
);
7151 mutex_unlock(&priv
->mutex
);
7154 static void iwl4965_bg_restart(struct work_struct
*data
)
7156 struct iwl4965_priv
*priv
= container_of(data
, struct iwl4965_priv
, restart
);
7158 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
7162 queue_work(priv
->workqueue
, &priv
->up
);
7165 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
7167 struct iwl4965_priv
*priv
=
7168 container_of(data
, struct iwl4965_priv
, rx_replenish
);
7170 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
7173 mutex_lock(&priv
->mutex
);
7174 iwl4965_rx_replenish(priv
);
7175 mutex_unlock(&priv
->mutex
);
7178 #define IWL_DELAY_NEXT_SCAN (HZ*2)
7180 static void iwl4965_bg_post_associate(struct work_struct
*data
)
7182 struct iwl4965_priv
*priv
= container_of(data
, struct iwl4965_priv
,
7183 post_associate
.work
);
7186 struct ieee80211_conf
*conf
= NULL
;
7187 DECLARE_MAC_BUF(mac
);
7189 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
7190 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
7194 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
7196 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
7199 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
7202 mutex_lock(&priv
->mutex
);
7204 if (!priv
->vif
|| !priv
->is_open
) {
7205 mutex_unlock(&priv
->mutex
);
7208 iwl4965_scan_cancel_timeout(priv
, 200);
7210 conf
= ieee80211_get_hw_conf(priv
->hw
);
7212 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7213 iwl4965_commit_rxon(priv
);
7215 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
7216 iwl4965_setup_rxon_timing(priv
);
7217 rc
= iwl4965_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
7218 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
7220 IWL_WARNING("REPLY_RXON_TIMING failed - "
7221 "Attempting to continue.\n");
7223 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
7225 #ifdef CONFIG_IWL4965_HT
7226 if (priv
->current_ht_config
.is_ht
)
7227 iwl4965_set_rxon_ht(priv
, &priv
->current_ht_config
);
7228 #endif /* CONFIG_IWL4965_HT*/
7229 iwl4965_set_rxon_chain(priv
);
7230 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
7232 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
7233 priv
->assoc_id
, priv
->beacon_int
);
7235 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
7236 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
7238 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
7240 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
7241 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
7242 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
7244 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
7246 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
7247 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
7251 iwl4965_commit_rxon(priv
);
7253 switch (priv
->iw_mode
) {
7254 case IEEE80211_IF_TYPE_STA
:
7255 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
7258 case IEEE80211_IF_TYPE_IBSS
:
7260 /* clear out the station table */
7261 iwl4965_clear_stations_table(priv
);
7263 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
7264 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
7265 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
7266 iwl4965_send_beacon_cmd(priv
);
7271 IWL_ERROR("%s Should not be called in %d mode\n",
7272 __FUNCTION__
, priv
->iw_mode
);
7276 iwl4965_sequence_reset(priv
);
7278 #ifdef CONFIG_IWL4965_SENSITIVITY
7279 /* Enable Rx differential gain and sensitivity calibrations */
7280 iwl4965_chain_noise_reset(priv
);
7281 priv
->start_calib
= 1;
7282 #endif /* CONFIG_IWL4965_SENSITIVITY */
7284 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
7285 priv
->assoc_station_added
= 1;
7287 #ifdef CONFIG_IWL4965_QOS
7288 iwl4965_activate_qos(priv
, 0);
7289 #endif /* CONFIG_IWL4965_QOS */
7290 /* we have just associated, don't start scan too early */
7291 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
7292 mutex_unlock(&priv
->mutex
);
7295 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
7297 struct iwl4965_priv
*priv
= container_of(work
, struct iwl4965_priv
, abort_scan
);
7299 if (!iwl4965_is_ready(priv
))
7302 mutex_lock(&priv
->mutex
);
7304 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
7305 iwl4965_send_scan_abort(priv
);
7307 mutex_unlock(&priv
->mutex
);
7310 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
7312 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
7314 struct iwl4965_priv
*priv
=
7315 container_of(work
, struct iwl4965_priv
, scan_completed
);
7317 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
7319 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
7322 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
7323 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
7325 ieee80211_scan_completed(priv
->hw
);
7327 /* Since setting the TXPOWER may have been deferred while
7328 * performing the scan, fire one off */
7329 mutex_lock(&priv
->mutex
);
7330 iwl4965_hw_reg_send_txpower(priv
);
7331 mutex_unlock(&priv
->mutex
);
7334 /*****************************************************************************
7336 * mac80211 entry point functions
7338 *****************************************************************************/
7340 #define UCODE_READY_TIMEOUT (2 * HZ)
7342 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
7344 struct iwl4965_priv
*priv
= hw
->priv
;
7347 IWL_DEBUG_MAC80211("enter\n");
7349 if (pci_enable_device(priv
->pci_dev
)) {
7350 IWL_ERROR("Fail to pci_enable_device\n");
7353 pci_restore_state(priv
->pci_dev
);
7354 pci_enable_msi(priv
->pci_dev
);
7356 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
7359 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
7360 goto out_disable_msi
;
7363 /* we should be verifying the device is ready to be opened */
7364 mutex_lock(&priv
->mutex
);
7366 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
7367 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
7368 * ucode filename and max sizes are card-specific. */
7370 if (!priv
->ucode_code
.len
) {
7371 ret
= iwl4965_read_ucode(priv
);
7373 IWL_ERROR("Could not read microcode: %d\n", ret
);
7374 mutex_unlock(&priv
->mutex
);
7375 goto out_release_irq
;
7379 ret
= __iwl4965_up(priv
);
7381 mutex_unlock(&priv
->mutex
);
7384 goto out_release_irq
;
7386 IWL_DEBUG_INFO("Start UP work done.\n");
7388 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
7391 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
7392 * mac80211 will not be run successfully. */
7393 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
7394 test_bit(STATUS_READY
, &priv
->status
),
7395 UCODE_READY_TIMEOUT
);
7397 if (!test_bit(STATUS_READY
, &priv
->status
)) {
7398 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
7399 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
7401 goto out_release_irq
;
7406 IWL_DEBUG_MAC80211("leave\n");
7410 free_irq(priv
->pci_dev
->irq
, priv
);
7412 pci_disable_msi(priv
->pci_dev
);
7413 pci_disable_device(priv
->pci_dev
);
7415 IWL_DEBUG_MAC80211("leave - failed\n");
7419 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
7421 struct iwl4965_priv
*priv
= hw
->priv
;
7423 IWL_DEBUG_MAC80211("enter\n");
7425 if (!priv
->is_open
) {
7426 IWL_DEBUG_MAC80211("leave - skip\n");
7432 if (iwl4965_is_ready_rf(priv
)) {
7433 /* stop mac, cancel any scan request and clear
7434 * RXON_FILTER_ASSOC_MSK BIT
7436 mutex_lock(&priv
->mutex
);
7437 iwl4965_scan_cancel_timeout(priv
, 100);
7438 cancel_delayed_work(&priv
->post_associate
);
7439 mutex_unlock(&priv
->mutex
);
7444 flush_workqueue(priv
->workqueue
);
7445 free_irq(priv
->pci_dev
->irq
, priv
);
7446 pci_disable_msi(priv
->pci_dev
);
7447 pci_save_state(priv
->pci_dev
);
7448 pci_disable_device(priv
->pci_dev
);
7450 IWL_DEBUG_MAC80211("leave\n");
7453 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7454 struct ieee80211_tx_control
*ctl
)
7456 struct iwl4965_priv
*priv
= hw
->priv
;
7458 IWL_DEBUG_MAC80211("enter\n");
7460 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
7461 IWL_DEBUG_MAC80211("leave - monitor\n");
7465 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
7468 if (iwl4965_tx_skb(priv
, skb
, ctl
))
7469 dev_kfree_skb_any(skb
);
7471 IWL_DEBUG_MAC80211("leave\n");
7475 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
7476 struct ieee80211_if_init_conf
*conf
)
7478 struct iwl4965_priv
*priv
= hw
->priv
;
7479 unsigned long flags
;
7480 DECLARE_MAC_BUF(mac
);
7482 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
7485 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
7489 spin_lock_irqsave(&priv
->lock
, flags
);
7490 priv
->vif
= conf
->vif
;
7492 spin_unlock_irqrestore(&priv
->lock
, flags
);
7494 mutex_lock(&priv
->mutex
);
7496 if (conf
->mac_addr
) {
7497 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
7498 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
7501 if (iwl4965_is_ready(priv
))
7502 iwl4965_set_mode(priv
, conf
->type
);
7504 mutex_unlock(&priv
->mutex
);
7506 IWL_DEBUG_MAC80211("leave\n");
7511 * iwl4965_mac_config - mac80211 config callback
7513 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
7514 * be set inappropriately and the driver currently sets the hardware up to
7515 * use it whenever needed.
7517 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
7519 struct iwl4965_priv
*priv
= hw
->priv
;
7520 const struct iwl4965_channel_info
*ch_info
;
7521 unsigned long flags
;
7524 mutex_lock(&priv
->mutex
);
7525 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
);
7527 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
7529 if (!iwl4965_is_ready(priv
)) {
7530 IWL_DEBUG_MAC80211("leave - not ready\n");
7535 if (unlikely(!iwl4965_param_disable_hw_scan
&&
7536 test_bit(STATUS_SCANNING
, &priv
->status
))) {
7537 IWL_DEBUG_MAC80211("leave - scanning\n");
7538 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
7539 mutex_unlock(&priv
->mutex
);
7543 spin_lock_irqsave(&priv
->lock
, flags
);
7545 ch_info
= iwl4965_get_channel_info(priv
, conf
->phymode
, conf
->channel
);
7546 if (!is_channel_valid(ch_info
)) {
7547 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
7548 conf
->channel
, conf
->phymode
);
7549 IWL_DEBUG_MAC80211("leave - invalid channel\n");
7550 spin_unlock_irqrestore(&priv
->lock
, flags
);
7555 #ifdef CONFIG_IWL4965_HT
7556 /* if we are switching fron ht to 2.4 clear flags
7557 * from any ht related info since 2.4 does not
7559 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
)
7560 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
7561 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
7564 priv
->staging_rxon
.flags
= 0;
7565 #endif /* CONFIG_IWL4965_HT */
7567 iwl4965_set_rxon_channel(priv
, conf
->phymode
, conf
->channel
);
7569 iwl4965_set_flags_for_phymode(priv
, conf
->phymode
);
7571 /* The list of supported rates and rate mask can be different
7572 * for each phymode; since the phymode may have changed, reset
7573 * the rate mask to what mac80211 lists */
7574 iwl4965_set_rate(priv
);
7576 spin_unlock_irqrestore(&priv
->lock
, flags
);
7578 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
7579 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
7580 iwl4965_hw_channel_switch(priv
, conf
->channel
);
7585 iwl4965_radio_kill_sw(priv
, !conf
->radio_enabled
);
7587 if (!conf
->radio_enabled
) {
7588 IWL_DEBUG_MAC80211("leave - radio disabled\n");
7592 if (iwl4965_is_rfkill(priv
)) {
7593 IWL_DEBUG_MAC80211("leave - RF kill\n");
7598 iwl4965_set_rate(priv
);
7600 if (memcmp(&priv
->active_rxon
,
7601 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
7602 iwl4965_commit_rxon(priv
);
7604 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7606 IWL_DEBUG_MAC80211("leave\n");
7609 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
7610 mutex_unlock(&priv
->mutex
);
7614 static void iwl4965_config_ap(struct iwl4965_priv
*priv
)
7618 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
7621 /* The following should be done only at AP bring up */
7622 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
7624 /* RXON - unassoc (to set timing command) */
7625 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7626 iwl4965_commit_rxon(priv
);
7629 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
7630 iwl4965_setup_rxon_timing(priv
);
7631 rc
= iwl4965_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
7632 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
7634 IWL_WARNING("REPLY_RXON_TIMING failed - "
7635 "Attempting to continue.\n");
7637 iwl4965_set_rxon_chain(priv
);
7639 /* FIXME: what should be the assoc_id for AP? */
7640 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
7641 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
7642 priv
->staging_rxon
.flags
|=
7643 RXON_FLG_SHORT_PREAMBLE_MSK
;
7645 priv
->staging_rxon
.flags
&=
7646 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
7648 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
7649 if (priv
->assoc_capability
&
7650 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
7651 priv
->staging_rxon
.flags
|=
7652 RXON_FLG_SHORT_SLOT_MSK
;
7654 priv
->staging_rxon
.flags
&=
7655 ~RXON_FLG_SHORT_SLOT_MSK
;
7657 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
7658 priv
->staging_rxon
.flags
&=
7659 ~RXON_FLG_SHORT_SLOT_MSK
;
7661 /* restore RXON assoc */
7662 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
7663 iwl4965_commit_rxon(priv
);
7664 #ifdef CONFIG_IWL4965_QOS
7665 iwl4965_activate_qos(priv
, 1);
7667 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
7669 iwl4965_send_beacon_cmd(priv
);
7671 /* FIXME - we need to add code here to detect a totally new
7672 * configuration, reset the AP, unassoc, rxon timing, assoc,
7673 * clear sta table, add BCAST sta... */
7676 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
7677 struct ieee80211_vif
*vif
,
7678 struct ieee80211_if_conf
*conf
)
7680 struct iwl4965_priv
*priv
= hw
->priv
;
7681 DECLARE_MAC_BUF(mac
);
7682 unsigned long flags
;
7688 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
7689 (!conf
->beacon
|| !conf
->ssid_len
)) {
7691 ("Leaving in AP mode because HostAPD is not ready.\n");
7695 if (!iwl4965_is_alive(priv
))
7698 mutex_lock(&priv
->mutex
);
7701 IWL_DEBUG_MAC80211("bssid: %s\n",
7702 print_mac(mac
, conf
->bssid
));
7705 * very dubious code was here; the probe filtering flag is never set:
7707 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7708 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7710 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
7711 IWL_DEBUG_MAC80211("leave - scanning\n");
7712 mutex_unlock(&priv
->mutex
);
7716 if (priv
->vif
!= vif
) {
7717 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
7718 mutex_unlock(&priv
->mutex
);
7722 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
7724 conf
->bssid
= priv
->mac_addr
;
7725 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
7726 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7727 print_mac(mac
, conf
->bssid
));
7729 if (priv
->ibss_beacon
)
7730 dev_kfree_skb(priv
->ibss_beacon
);
7732 priv
->ibss_beacon
= conf
->beacon
;
7735 if (iwl4965_is_rfkill(priv
))
7738 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
7739 !is_multicast_ether_addr(conf
->bssid
)) {
7740 /* If there is currently a HW scan going on in the background
7741 * then we need to cancel it else the RXON below will fail. */
7742 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
7743 IWL_WARNING("Aborted scan still in progress "
7745 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7746 mutex_unlock(&priv
->mutex
);
7749 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
7751 /* TODO: Audit driver for usage of these members and see
7752 * if mac80211 deprecates them (priv->bssid looks like it
7753 * shouldn't be there, but I haven't scanned the IBSS code
7754 * to verify) - jpk */
7755 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
7757 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7758 iwl4965_config_ap(priv
);
7760 rc
= iwl4965_commit_rxon(priv
);
7761 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
7762 iwl4965_rxon_add_station(
7763 priv
, priv
->active_rxon
.bssid_addr
, 1);
7767 iwl4965_scan_cancel_timeout(priv
, 100);
7768 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7769 iwl4965_commit_rxon(priv
);
7773 spin_lock_irqsave(&priv
->lock
, flags
);
7774 if (!conf
->ssid_len
)
7775 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
7777 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
7779 priv
->essid_len
= conf
->ssid_len
;
7780 spin_unlock_irqrestore(&priv
->lock
, flags
);
7782 IWL_DEBUG_MAC80211("leave\n");
7783 mutex_unlock(&priv
->mutex
);
7788 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
7789 unsigned int changed_flags
,
7790 unsigned int *total_flags
,
7791 int mc_count
, struct dev_addr_list
*mc_list
)
7795 * see also iwl4965_connection_init_rx_config
7800 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
7801 struct ieee80211_if_init_conf
*conf
)
7803 struct iwl4965_priv
*priv
= hw
->priv
;
7805 IWL_DEBUG_MAC80211("enter\n");
7807 mutex_lock(&priv
->mutex
);
7809 if (iwl4965_is_ready_rf(priv
)) {
7810 iwl4965_scan_cancel_timeout(priv
, 100);
7811 cancel_delayed_work(&priv
->post_associate
);
7812 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7813 iwl4965_commit_rxon(priv
);
7815 if (priv
->vif
== conf
->vif
) {
7817 memset(priv
->bssid
, 0, ETH_ALEN
);
7818 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
7819 priv
->essid_len
= 0;
7821 mutex_unlock(&priv
->mutex
);
7823 IWL_DEBUG_MAC80211("leave\n");
7827 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
7828 struct ieee80211_vif
*vif
,
7829 struct ieee80211_bss_conf
*bss_conf
,
7832 struct iwl4965_priv
*priv
= hw
->priv
;
7834 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
7835 if (bss_conf
->use_short_preamble
)
7836 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
7838 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
7841 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
7842 if (bss_conf
->use_cts_prot
&& (priv
->phymode
!= MODE_IEEE80211A
))
7843 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
7845 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
7848 if (changes
& BSS_CHANGED_ASSOC
) {
7851 * do stuff instead of sniffing assoc resp
7855 if (iwl4965_is_associated(priv
))
7856 iwl4965_send_rxon_assoc(priv
);
7859 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
7862 unsigned long flags
;
7863 struct iwl4965_priv
*priv
= hw
->priv
;
7865 IWL_DEBUG_MAC80211("enter\n");
7867 mutex_lock(&priv
->mutex
);
7868 spin_lock_irqsave(&priv
->lock
, flags
);
7870 if (!iwl4965_is_ready_rf(priv
)) {
7872 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7876 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
7878 IWL_ERROR("ERROR: APs don't scan\n");
7882 /* we don't schedule scan within next_scan_jiffies period */
7883 if (priv
->next_scan_jiffies
&&
7884 time_after(priv
->next_scan_jiffies
, jiffies
)) {
7888 /* if we just finished scan ask for delay */
7889 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
7890 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
7895 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
7896 iwl4965_escape_essid(ssid
, len
), (int)len
);
7898 priv
->one_direct_scan
= 1;
7899 priv
->direct_ssid_len
= (u8
)
7900 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
7901 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
7903 priv
->one_direct_scan
= 0;
7905 rc
= iwl4965_scan_initiate(priv
);
7907 IWL_DEBUG_MAC80211("leave\n");
7910 spin_unlock_irqrestore(&priv
->lock
, flags
);
7911 mutex_unlock(&priv
->mutex
);
7916 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
7917 const u8
*local_addr
, const u8
*addr
,
7918 struct ieee80211_key_conf
*key
)
7920 struct iwl4965_priv
*priv
= hw
->priv
;
7921 DECLARE_MAC_BUF(mac
);
7925 IWL_DEBUG_MAC80211("enter\n");
7927 if (!iwl4965_param_hwcrypto
) {
7928 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7932 if (is_zero_ether_addr(addr
))
7933 /* only support pairwise keys */
7936 sta_id
= iwl4965_hw_find_station(priv
, addr
);
7937 if (sta_id
== IWL_INVALID_STATION
) {
7938 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7939 print_mac(mac
, addr
));
7943 mutex_lock(&priv
->mutex
);
7945 iwl4965_scan_cancel_timeout(priv
, 100);
7949 rc
= iwl4965_update_sta_key_info(priv
, key
, sta_id
);
7951 iwl4965_set_rxon_hwcrypto(priv
, 1);
7952 iwl4965_commit_rxon(priv
);
7953 key
->hw_key_idx
= sta_id
;
7954 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7955 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
7959 rc
= iwl4965_clear_sta_key_info(priv
, sta_id
);
7961 iwl4965_set_rxon_hwcrypto(priv
, 0);
7962 iwl4965_commit_rxon(priv
);
7963 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7970 IWL_DEBUG_MAC80211("leave\n");
7971 mutex_unlock(&priv
->mutex
);
7976 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
7977 const struct ieee80211_tx_queue_params
*params
)
7979 struct iwl4965_priv
*priv
= hw
->priv
;
7980 #ifdef CONFIG_IWL4965_QOS
7981 unsigned long flags
;
7983 #endif /* CONFIG_IWL4965_QOS */
7985 IWL_DEBUG_MAC80211("enter\n");
7987 if (!iwl4965_is_ready_rf(priv
)) {
7988 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7992 if (queue
>= AC_NUM
) {
7993 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7997 #ifdef CONFIG_IWL4965_QOS
7998 if (!priv
->qos_data
.qos_enable
) {
7999 priv
->qos_data
.qos_active
= 0;
8000 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
8003 q
= AC_NUM
- 1 - queue
;
8005 spin_lock_irqsave(&priv
->lock
, flags
);
8007 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
8008 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
8009 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
8010 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
8011 cpu_to_le16((params
->burst_time
* 100));
8013 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
8014 priv
->qos_data
.qos_active
= 1;
8016 spin_unlock_irqrestore(&priv
->lock
, flags
);
8018 mutex_lock(&priv
->mutex
);
8019 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
8020 iwl4965_activate_qos(priv
, 1);
8021 else if (priv
->assoc_id
&& iwl4965_is_associated(priv
))
8022 iwl4965_activate_qos(priv
, 0);
8024 mutex_unlock(&priv
->mutex
);
8026 #endif /*CONFIG_IWL4965_QOS */
8028 IWL_DEBUG_MAC80211("leave\n");
8032 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
8033 struct ieee80211_tx_queue_stats
*stats
)
8035 struct iwl4965_priv
*priv
= hw
->priv
;
8037 struct iwl4965_tx_queue
*txq
;
8038 struct iwl4965_queue
*q
;
8039 unsigned long flags
;
8041 IWL_DEBUG_MAC80211("enter\n");
8043 if (!iwl4965_is_ready_rf(priv
)) {
8044 IWL_DEBUG_MAC80211("leave - RF not ready\n");
8048 spin_lock_irqsave(&priv
->lock
, flags
);
8050 for (i
= 0; i
< AC_NUM
; i
++) {
8051 txq
= &priv
->txq
[i
];
8053 avail
= iwl4965_queue_space(q
);
8055 stats
->data
[i
].len
= q
->n_window
- avail
;
8056 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
8057 stats
->data
[i
].count
= q
->n_window
;
8060 spin_unlock_irqrestore(&priv
->lock
, flags
);
8062 IWL_DEBUG_MAC80211("leave\n");
8067 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
8068 struct ieee80211_low_level_stats
*stats
)
8070 IWL_DEBUG_MAC80211("enter\n");
8071 IWL_DEBUG_MAC80211("leave\n");
8076 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
8078 IWL_DEBUG_MAC80211("enter\n");
8079 IWL_DEBUG_MAC80211("leave\n");
8084 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
8086 struct iwl4965_priv
*priv
= hw
->priv
;
8087 unsigned long flags
;
8089 mutex_lock(&priv
->mutex
);
8090 IWL_DEBUG_MAC80211("enter\n");
8092 priv
->lq_mngr
.lq_ready
= 0;
8093 #ifdef CONFIG_IWL4965_HT
8094 spin_lock_irqsave(&priv
->lock
, flags
);
8095 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
8096 spin_unlock_irqrestore(&priv
->lock
, flags
);
8097 #endif /* CONFIG_IWL4965_HT */
8099 #ifdef CONFIG_IWL4965_QOS
8100 iwl4965_reset_qos(priv
);
8103 cancel_delayed_work(&priv
->post_associate
);
8105 spin_lock_irqsave(&priv
->lock
, flags
);
8107 priv
->assoc_capability
= 0;
8108 priv
->call_post_assoc_from_beacon
= 0;
8109 priv
->assoc_station_added
= 0;
8111 /* new association get rid of ibss beacon skb */
8112 if (priv
->ibss_beacon
)
8113 dev_kfree_skb(priv
->ibss_beacon
);
8115 priv
->ibss_beacon
= NULL
;
8117 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
8118 priv
->timestamp1
= 0;
8119 priv
->timestamp0
= 0;
8120 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
8121 priv
->beacon_int
= 0;
8123 spin_unlock_irqrestore(&priv
->lock
, flags
);
8125 if (!iwl4965_is_ready_rf(priv
)) {
8126 IWL_DEBUG_MAC80211("leave - not ready\n");
8127 mutex_unlock(&priv
->mutex
);
8131 /* we are restarting association process
8132 * clear RXON_FILTER_ASSOC_MSK bit
8134 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
8135 iwl4965_scan_cancel_timeout(priv
, 100);
8136 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
8137 iwl4965_commit_rxon(priv
);
8140 /* Per mac80211.h: This is only used in IBSS mode... */
8141 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
8143 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
8144 mutex_unlock(&priv
->mutex
);
8148 priv
->only_active_channel
= 0;
8150 iwl4965_set_rate(priv
);
8152 mutex_unlock(&priv
->mutex
);
8154 IWL_DEBUG_MAC80211("leave\n");
8157 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
8158 struct ieee80211_tx_control
*control
)
8160 struct iwl4965_priv
*priv
= hw
->priv
;
8161 unsigned long flags
;
8163 mutex_lock(&priv
->mutex
);
8164 IWL_DEBUG_MAC80211("enter\n");
8166 if (!iwl4965_is_ready_rf(priv
)) {
8167 IWL_DEBUG_MAC80211("leave - RF not ready\n");
8168 mutex_unlock(&priv
->mutex
);
8172 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
8173 IWL_DEBUG_MAC80211("leave - not IBSS\n");
8174 mutex_unlock(&priv
->mutex
);
8178 spin_lock_irqsave(&priv
->lock
, flags
);
8180 if (priv
->ibss_beacon
)
8181 dev_kfree_skb(priv
->ibss_beacon
);
8183 priv
->ibss_beacon
= skb
;
8187 IWL_DEBUG_MAC80211("leave\n");
8188 spin_unlock_irqrestore(&priv
->lock
, flags
);
8190 #ifdef CONFIG_IWL4965_QOS
8191 iwl4965_reset_qos(priv
);
8194 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
8196 mutex_unlock(&priv
->mutex
);
8201 #ifdef CONFIG_IWL4965_HT
8203 static void iwl4965_ht_info_fill(struct ieee80211_conf
*conf
,
8204 struct iwl4965_priv
*priv
)
8206 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
8207 struct ieee80211_ht_info
*ht_conf
= &conf
->ht_conf
;
8208 struct ieee80211_ht_bss_info
*ht_bss_conf
= &conf
->ht_bss_conf
;
8210 IWL_DEBUG_MAC80211("enter: \n");
8212 if (!(conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
)) {
8213 iwl_conf
->is_ht
= 0;
8217 iwl_conf
->is_ht
= 1;
8218 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
8220 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
8221 iwl_conf
->sgf
|= 0x1;
8222 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
8223 iwl_conf
->sgf
|= 0x2;
8225 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
8226 iwl_conf
->max_amsdu_size
=
8227 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
8228 iwl_conf
->supported_chan_width
=
8229 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
8230 iwl_conf
->tx_mimo_ps_mode
=
8231 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
8232 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
8234 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
8235 iwl_conf
->extension_chan_offset
=
8236 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
8237 iwl_conf
->tx_chan_width
=
8238 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
8239 iwl_conf
->ht_protection
=
8240 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
8241 iwl_conf
->non_GF_STA_present
=
8242 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
8244 IWL_DEBUG_MAC80211("control channel %d\n",
8245 iwl_conf
->control_channel
);
8246 IWL_DEBUG_MAC80211("leave\n");
8249 static int iwl4965_mac_conf_ht(struct ieee80211_hw
*hw
,
8250 struct ieee80211_conf
*conf
)
8252 struct iwl4965_priv
*priv
= hw
->priv
;
8254 IWL_DEBUG_MAC80211("enter: \n");
8256 iwl4965_ht_info_fill(conf
, priv
);
8257 iwl4965_set_rxon_chain(priv
);
8259 if (priv
&& priv
->assoc_id
&&
8260 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
8261 unsigned long flags
;
8263 spin_lock_irqsave(&priv
->lock
, flags
);
8264 if (priv
->beacon_int
)
8265 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
8267 priv
->call_post_assoc_from_beacon
= 1;
8268 spin_unlock_irqrestore(&priv
->lock
, flags
);
8271 IWL_DEBUG_MAC80211("leave:\n");
8275 static void iwl4965_set_ht_capab(struct ieee80211_hw
*hw
,
8276 struct ieee80211_ht_cap
*ht_cap
,
8277 u8 use_current_config
)
8279 struct ieee80211_conf
*conf
= &hw
->conf
;
8280 struct ieee80211_hw_mode
*mode
= conf
->mode
;
8282 if (use_current_config
) {
8283 ht_cap
->cap_info
= cpu_to_le16(conf
->ht_conf
.cap
);
8284 memcpy(ht_cap
->supp_mcs_set
,
8285 conf
->ht_conf
.supp_mcs_set
, 16);
8287 ht_cap
->cap_info
= cpu_to_le16(mode
->ht_info
.cap
);
8288 memcpy(ht_cap
->supp_mcs_set
,
8289 mode
->ht_info
.supp_mcs_set
, 16);
8291 ht_cap
->ampdu_params_info
=
8292 (mode
->ht_info
.ampdu_factor
& IEEE80211_HT_CAP_AMPDU_FACTOR
) |
8293 ((mode
->ht_info
.ampdu_density
<< 2) &
8294 IEEE80211_HT_CAP_AMPDU_DENSITY
);
8297 #endif /*CONFIG_IWL4965_HT*/
8299 /*****************************************************************************
8303 *****************************************************************************/
8305 #ifdef CONFIG_IWL4965_DEBUG
8308 * The following adds a new attribute to the sysfs representation
8309 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
8310 * used for controlling the debug level.
8312 * See the level definitions in iwl for details.
8315 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
8317 return sprintf(buf
, "0x%08X\n", iwl4965_debug_level
);
8319 static ssize_t
store_debug_level(struct device_driver
*d
,
8320 const char *buf
, size_t count
)
8322 char *p
= (char *)buf
;
8325 val
= simple_strtoul(p
, &p
, 0);
8327 printk(KERN_INFO DRV_NAME
8328 ": %s is not in hex or decimal form.\n", buf
);
8330 iwl4965_debug_level
= val
;
8332 return strnlen(buf
, count
);
8335 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
8336 show_debug_level
, store_debug_level
);
8338 #endif /* CONFIG_IWL4965_DEBUG */
8340 static ssize_t
show_rf_kill(struct device
*d
,
8341 struct device_attribute
*attr
, char *buf
)
8344 * 0 - RF kill not enabled
8345 * 1 - SW based RF kill active (sysfs)
8346 * 2 - HW based RF kill active
8347 * 3 - Both HW and SW based RF kill active
8349 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8350 int val
= (test_bit(STATUS_RF_KILL_SW
, &priv
->status
) ? 0x1 : 0x0) |
8351 (test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ? 0x2 : 0x0);
8353 return sprintf(buf
, "%i\n", val
);
8356 static ssize_t
store_rf_kill(struct device
*d
,
8357 struct device_attribute
*attr
,
8358 const char *buf
, size_t count
)
8360 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8362 mutex_lock(&priv
->mutex
);
8363 iwl4965_radio_kill_sw(priv
, buf
[0] == '1');
8364 mutex_unlock(&priv
->mutex
);
8369 static DEVICE_ATTR(rf_kill
, S_IWUSR
| S_IRUGO
, show_rf_kill
, store_rf_kill
);
8371 static ssize_t
show_temperature(struct device
*d
,
8372 struct device_attribute
*attr
, char *buf
)
8374 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8376 if (!iwl4965_is_alive(priv
))
8379 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
8382 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
8384 static ssize_t
show_rs_window(struct device
*d
,
8385 struct device_attribute
*attr
,
8388 struct iwl4965_priv
*priv
= d
->driver_data
;
8389 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
8391 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
8393 static ssize_t
show_tx_power(struct device
*d
,
8394 struct device_attribute
*attr
, char *buf
)
8396 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8397 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
8400 static ssize_t
store_tx_power(struct device
*d
,
8401 struct device_attribute
*attr
,
8402 const char *buf
, size_t count
)
8404 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8405 char *p
= (char *)buf
;
8408 val
= simple_strtoul(p
, &p
, 10);
8410 printk(KERN_INFO DRV_NAME
8411 ": %s is not in decimal form.\n", buf
);
8413 iwl4965_hw_reg_set_txpower(priv
, val
);
8418 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
8420 static ssize_t
show_flags(struct device
*d
,
8421 struct device_attribute
*attr
, char *buf
)
8423 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8425 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
8428 static ssize_t
store_flags(struct device
*d
,
8429 struct device_attribute
*attr
,
8430 const char *buf
, size_t count
)
8432 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8433 u32 flags
= simple_strtoul(buf
, NULL
, 0);
8435 mutex_lock(&priv
->mutex
);
8436 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
8437 /* Cancel any currently running scans... */
8438 if (iwl4965_scan_cancel_timeout(priv
, 100))
8439 IWL_WARNING("Could not cancel scan.\n");
8441 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
8443 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
8444 iwl4965_commit_rxon(priv
);
8447 mutex_unlock(&priv
->mutex
);
8452 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
8454 static ssize_t
show_filter_flags(struct device
*d
,
8455 struct device_attribute
*attr
, char *buf
)
8457 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8459 return sprintf(buf
, "0x%04X\n",
8460 le32_to_cpu(priv
->active_rxon
.filter_flags
));
8463 static ssize_t
store_filter_flags(struct device
*d
,
8464 struct device_attribute
*attr
,
8465 const char *buf
, size_t count
)
8467 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8468 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
8470 mutex_lock(&priv
->mutex
);
8471 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
8472 /* Cancel any currently running scans... */
8473 if (iwl4965_scan_cancel_timeout(priv
, 100))
8474 IWL_WARNING("Could not cancel scan.\n");
8476 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
8477 "0x%04X\n", filter_flags
);
8478 priv
->staging_rxon
.filter_flags
=
8479 cpu_to_le32(filter_flags
);
8480 iwl4965_commit_rxon(priv
);
8483 mutex_unlock(&priv
->mutex
);
8488 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
8489 store_filter_flags
);
8491 static ssize_t
show_tune(struct device
*d
,
8492 struct device_attribute
*attr
, char *buf
)
8494 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8496 return sprintf(buf
, "0x%04X\n",
8497 (priv
->phymode
<< 8) |
8498 le16_to_cpu(priv
->active_rxon
.channel
));
8501 static void iwl4965_set_flags_for_phymode(struct iwl4965_priv
*priv
, u8 phymode
);
8503 static ssize_t
store_tune(struct device
*d
,
8504 struct device_attribute
*attr
,
8505 const char *buf
, size_t count
)
8507 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8508 char *p
= (char *)buf
;
8509 u16 tune
= simple_strtoul(p
, &p
, 0);
8510 u8 phymode
= (tune
>> 8) & 0xff;
8511 u16 channel
= tune
& 0xff;
8513 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode
, channel
);
8515 mutex_lock(&priv
->mutex
);
8516 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != channel
) ||
8517 (priv
->phymode
!= phymode
)) {
8518 const struct iwl4965_channel_info
*ch_info
;
8520 ch_info
= iwl4965_get_channel_info(priv
, phymode
, channel
);
8522 IWL_WARNING("Requested invalid phymode/channel "
8523 "combination: %d %d\n", phymode
, channel
);
8524 mutex_unlock(&priv
->mutex
);
8528 /* Cancel any currently running scans... */
8529 if (iwl4965_scan_cancel_timeout(priv
, 100))
8530 IWL_WARNING("Could not cancel scan.\n");
8532 IWL_DEBUG_INFO("Committing phymode and "
8533 "rxon.channel = %d %d\n",
8536 iwl4965_set_rxon_channel(priv
, phymode
, channel
);
8537 iwl4965_set_flags_for_phymode(priv
, phymode
);
8539 iwl4965_set_rate(priv
);
8540 iwl4965_commit_rxon(priv
);
8543 mutex_unlock(&priv
->mutex
);
8548 static DEVICE_ATTR(tune
, S_IWUSR
| S_IRUGO
, show_tune
, store_tune
);
8550 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
8552 static ssize_t
show_measurement(struct device
*d
,
8553 struct device_attribute
*attr
, char *buf
)
8555 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8556 struct iwl4965_spectrum_notification measure_report
;
8557 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
8558 u8
*data
= (u8
*) & measure_report
;
8559 unsigned long flags
;
8561 spin_lock_irqsave(&priv
->lock
, flags
);
8562 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
8563 spin_unlock_irqrestore(&priv
->lock
, flags
);
8566 memcpy(&measure_report
, &priv
->measure_report
, size
);
8567 priv
->measurement_status
= 0;
8568 spin_unlock_irqrestore(&priv
->lock
, flags
);
8570 while (size
&& (PAGE_SIZE
- len
)) {
8571 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
8572 PAGE_SIZE
- len
, 1);
8574 if (PAGE_SIZE
- len
)
8578 size
-= min(size
, 16U);
8584 static ssize_t
store_measurement(struct device
*d
,
8585 struct device_attribute
*attr
,
8586 const char *buf
, size_t count
)
8588 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8589 struct ieee80211_measurement_params params
= {
8590 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
8591 .start_time
= cpu_to_le64(priv
->last_tsf
),
8592 .duration
= cpu_to_le16(1),
8594 u8 type
= IWL_MEASURE_BASIC
;
8600 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
8601 channel
= simple_strtoul(p
, NULL
, 0);
8603 params
.channel
= channel
;
8606 while (*p
&& *p
!= ' ')
8609 type
= simple_strtoul(p
+ 1, NULL
, 0);
8612 IWL_DEBUG_INFO("Invoking measurement of type %d on "
8613 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
8614 iwl4965_get_measurement(priv
, ¶ms
, type
);
8619 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
8620 show_measurement
, store_measurement
);
8621 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
8623 static ssize_t
store_retry_rate(struct device
*d
,
8624 struct device_attribute
*attr
,
8625 const char *buf
, size_t count
)
8627 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8629 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
8630 if (priv
->retry_rate
<= 0)
8631 priv
->retry_rate
= 1;
8636 static ssize_t
show_retry_rate(struct device
*d
,
8637 struct device_attribute
*attr
, char *buf
)
8639 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8640 return sprintf(buf
, "%d", priv
->retry_rate
);
8643 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
8646 static ssize_t
store_power_level(struct device
*d
,
8647 struct device_attribute
*attr
,
8648 const char *buf
, size_t count
)
8650 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8654 mode
= simple_strtoul(buf
, NULL
, 0);
8655 mutex_lock(&priv
->mutex
);
8657 if (!iwl4965_is_ready(priv
)) {
8662 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
8663 mode
= IWL_POWER_AC
;
8665 mode
|= IWL_POWER_ENABLED
;
8667 if (mode
!= priv
->power_mode
) {
8668 rc
= iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
8670 IWL_DEBUG_MAC80211("failed setting power mode.\n");
8673 priv
->power_mode
= mode
;
8679 mutex_unlock(&priv
->mutex
);
8683 #define MAX_WX_STRING 80
8685 /* Values are in microsecond */
8686 static const s32 timeout_duration
[] = {
8693 static const s32 period_duration
[] = {
8701 static ssize_t
show_power_level(struct device
*d
,
8702 struct device_attribute
*attr
, char *buf
)
8704 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8705 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
8708 p
+= sprintf(p
, "%d ", level
);
8710 case IWL_POWER_MODE_CAM
:
8712 p
+= sprintf(p
, "(AC)");
8714 case IWL_POWER_BATTERY
:
8715 p
+= sprintf(p
, "(BATTERY)");
8719 "(Timeout %dms, Period %dms)",
8720 timeout_duration
[level
- 1] / 1000,
8721 period_duration
[level
- 1] / 1000);
8724 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
8725 p
+= sprintf(p
, " OFF\n");
8727 p
+= sprintf(p
, " \n");
8729 return (p
- buf
+ 1);
8733 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
8736 static ssize_t
show_channels(struct device
*d
,
8737 struct device_attribute
*attr
, char *buf
)
8739 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8741 struct ieee80211_channel
*channels
= NULL
;
8742 const struct ieee80211_hw_mode
*hw_mode
= NULL
;
8745 if (!iwl4965_is_ready(priv
))
8748 hw_mode
= iwl4965_get_hw_mode(priv
, MODE_IEEE80211G
);
8750 hw_mode
= iwl4965_get_hw_mode(priv
, MODE_IEEE80211B
);
8752 channels
= hw_mode
->channels
;
8753 count
= hw_mode
->num_channels
;
8758 "Displaying %d channels in 2.4GHz band "
8759 "(802.11bg):\n", count
);
8761 for (i
= 0; i
< count
; i
++)
8762 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
8764 channels
[i
].power_level
,
8766 flag
& IEEE80211_CHAN_W_RADAR_DETECT
?
8767 " (IEEE 802.11h required)" : "",
8768 (!(channels
[i
].flag
& IEEE80211_CHAN_W_IBSS
)
8771 IEEE80211_CHAN_W_RADAR_DETECT
)) ? "" :
8774 flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
?
8775 "active/passive" : "passive only");
8777 hw_mode
= iwl4965_get_hw_mode(priv
, MODE_IEEE80211A
);
8779 channels
= hw_mode
->channels
;
8780 count
= hw_mode
->num_channels
;
8786 len
+= sprintf(&buf
[len
], "Displaying %d channels in 5.2GHz band "
8787 "(802.11a):\n", count
);
8789 for (i
= 0; i
< count
; i
++)
8790 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
8792 channels
[i
].power_level
,
8794 flag
& IEEE80211_CHAN_W_RADAR_DETECT
?
8795 " (IEEE 802.11h required)" : "",
8796 (!(channels
[i
].flag
& IEEE80211_CHAN_W_IBSS
)
8799 IEEE80211_CHAN_W_RADAR_DETECT
)) ? "" :
8802 flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
?
8803 "active/passive" : "passive only");
8808 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
8810 static ssize_t
show_statistics(struct device
*d
,
8811 struct device_attribute
*attr
, char *buf
)
8813 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8814 u32 size
= sizeof(struct iwl4965_notif_statistics
);
8815 u32 len
= 0, ofs
= 0;
8816 u8
*data
= (u8
*) & priv
->statistics
;
8819 if (!iwl4965_is_alive(priv
))
8822 mutex_lock(&priv
->mutex
);
8823 rc
= iwl4965_send_statistics_request(priv
);
8824 mutex_unlock(&priv
->mutex
);
8828 "Error sending statistics request: 0x%08X\n", rc
);
8832 while (size
&& (PAGE_SIZE
- len
)) {
8833 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
8834 PAGE_SIZE
- len
, 1);
8836 if (PAGE_SIZE
- len
)
8840 size
-= min(size
, 16U);
8846 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
8848 static ssize_t
show_antenna(struct device
*d
,
8849 struct device_attribute
*attr
, char *buf
)
8851 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8853 if (!iwl4965_is_alive(priv
))
8856 return sprintf(buf
, "%d\n", priv
->antenna
);
8859 static ssize_t
store_antenna(struct device
*d
,
8860 struct device_attribute
*attr
,
8861 const char *buf
, size_t count
)
8864 struct iwl4965_priv
*priv
= dev_get_drvdata(d
);
8869 if (sscanf(buf
, "%1i", &ant
) != 1) {
8870 IWL_DEBUG_INFO("not in hex or decimal form.\n");
8874 if ((ant
>= 0) && (ant
<= 2)) {
8875 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
8876 priv
->antenna
= (enum iwl4965_antenna
)ant
;
8878 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
8884 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
8886 static ssize_t
show_status(struct device
*d
,
8887 struct device_attribute
*attr
, char *buf
)
8889 struct iwl4965_priv
*priv
= (struct iwl4965_priv
*)d
->driver_data
;
8890 if (!iwl4965_is_alive(priv
))
8892 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
8895 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
8897 static ssize_t
dump_error_log(struct device
*d
,
8898 struct device_attribute
*attr
,
8899 const char *buf
, size_t count
)
8901 char *p
= (char *)buf
;
8904 iwl4965_dump_nic_error_log((struct iwl4965_priv
*)d
->driver_data
);
8906 return strnlen(buf
, count
);
8909 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
8911 static ssize_t
dump_event_log(struct device
*d
,
8912 struct device_attribute
*attr
,
8913 const char *buf
, size_t count
)
8915 char *p
= (char *)buf
;
8918 iwl4965_dump_nic_event_log((struct iwl4965_priv
*)d
->driver_data
);
8920 return strnlen(buf
, count
);
8923 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
8925 /*****************************************************************************
8927 * driver setup and teardown
8929 *****************************************************************************/
8931 static void iwl4965_setup_deferred_work(struct iwl4965_priv
*priv
)
8933 priv
->workqueue
= create_workqueue(DRV_NAME
);
8935 init_waitqueue_head(&priv
->wait_command_queue
);
8937 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
8938 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
8939 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
8940 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
8941 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
8942 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
8943 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
8944 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
8945 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
8946 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
8947 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
8948 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
8950 iwl4965_hw_setup_deferred_work(priv
);
8952 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
8953 iwl4965_irq_tasklet
, (unsigned long)priv
);
8956 static void iwl4965_cancel_deferred_work(struct iwl4965_priv
*priv
)
8958 iwl4965_hw_cancel_deferred_work(priv
);
8960 cancel_delayed_work_sync(&priv
->init_alive_start
);
8961 cancel_delayed_work(&priv
->scan_check
);
8962 cancel_delayed_work(&priv
->alive_start
);
8963 cancel_delayed_work(&priv
->post_associate
);
8964 cancel_work_sync(&priv
->beacon_update
);
8967 static struct attribute
*iwl4965_sysfs_entries
[] = {
8968 &dev_attr_antenna
.attr
,
8969 &dev_attr_channels
.attr
,
8970 &dev_attr_dump_errors
.attr
,
8971 &dev_attr_dump_events
.attr
,
8972 &dev_attr_flags
.attr
,
8973 &dev_attr_filter_flags
.attr
,
8974 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
8975 &dev_attr_measurement
.attr
,
8977 &dev_attr_power_level
.attr
,
8978 &dev_attr_retry_rate
.attr
,
8979 &dev_attr_rf_kill
.attr
,
8980 &dev_attr_rs_window
.attr
,
8981 &dev_attr_statistics
.attr
,
8982 &dev_attr_status
.attr
,
8983 &dev_attr_temperature
.attr
,
8984 &dev_attr_tune
.attr
,
8985 &dev_attr_tx_power
.attr
,
8990 static struct attribute_group iwl4965_attribute_group
= {
8991 .name
= NULL
, /* put in device directory */
8992 .attrs
= iwl4965_sysfs_entries
,
8995 static struct ieee80211_ops iwl4965_hw_ops
= {
8996 .tx
= iwl4965_mac_tx
,
8997 .start
= iwl4965_mac_start
,
8998 .stop
= iwl4965_mac_stop
,
8999 .add_interface
= iwl4965_mac_add_interface
,
9000 .remove_interface
= iwl4965_mac_remove_interface
,
9001 .config
= iwl4965_mac_config
,
9002 .config_interface
= iwl4965_mac_config_interface
,
9003 .configure_filter
= iwl4965_configure_filter
,
9004 .set_key
= iwl4965_mac_set_key
,
9005 .get_stats
= iwl4965_mac_get_stats
,
9006 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
9007 .conf_tx
= iwl4965_mac_conf_tx
,
9008 .get_tsf
= iwl4965_mac_get_tsf
,
9009 .reset_tsf
= iwl4965_mac_reset_tsf
,
9010 .beacon_update
= iwl4965_mac_beacon_update
,
9011 .bss_info_changed
= iwl4965_bss_info_changed
,
9012 #ifdef CONFIG_IWL4965_HT
9013 .conf_ht
= iwl4965_mac_conf_ht
,
9014 .ampdu_action
= iwl4965_mac_ampdu_action
,
9015 #endif /* CONFIG_IWL4965_HT */
9016 .hw_scan
= iwl4965_mac_hw_scan
9019 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
9022 struct iwl4965_priv
*priv
;
9023 struct ieee80211_hw
*hw
;
9025 DECLARE_MAC_BUF(mac
);
9027 /* Disabling hardware scan means that mac80211 will perform scans
9028 * "the hard way", rather than using device's scan. */
9029 if (iwl4965_param_disable_hw_scan
) {
9030 IWL_DEBUG_INFO("Disabling hw_scan\n");
9031 iwl4965_hw_ops
.hw_scan
= NULL
;
9034 if ((iwl4965_param_queues_num
> IWL_MAX_NUM_QUEUES
) ||
9035 (iwl4965_param_queues_num
< IWL_MIN_NUM_QUEUES
)) {
9036 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
9037 IWL_MIN_NUM_QUEUES
, IWL_MAX_NUM_QUEUES
);
9042 /* mac80211 allocates memory for this device instance, including
9043 * space for this driver's private structure */
9044 hw
= ieee80211_alloc_hw(sizeof(struct iwl4965_priv
), &iwl4965_hw_ops
);
9046 IWL_ERROR("Can not allocate network device\n");
9050 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
9052 hw
->rate_control_algorithm
= "iwl-4965-rs";
9054 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
9058 priv
->pci_dev
= pdev
;
9059 priv
->antenna
= (enum iwl4965_antenna
)iwl4965_param_antenna
;
9060 #ifdef CONFIG_IWL4965_DEBUG
9061 iwl4965_debug_level
= iwl4965_param_debug
;
9062 atomic_set(&priv
->restrict_refcnt
, 0);
9064 priv
->retry_rate
= 1;
9066 priv
->ibss_beacon
= NULL
;
9068 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
9069 * the range of signal quality values that we'll provide.
9070 * Negative values for level/noise indicate that we'll provide dBm.
9071 * For WE, at least, non-0 values here *enable* display of values
9072 * in app (iwconfig). */
9073 hw
->max_rssi
= -20; /* signal level, negative indicates dBm */
9074 hw
->max_noise
= -20; /* noise level, negative indicates dBm */
9075 hw
->max_signal
= 100; /* link quality indication (%) */
9077 /* Tell mac80211 our Tx characteristics */
9078 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
;
9080 /* Default value; 4 EDCA QOS priorities */
9082 #ifdef CONFIG_IWL4965_HT
9083 /* Enhanced value; more queues, to support 11n aggregation */
9085 #endif /* CONFIG_IWL4965_HT */
9087 spin_lock_init(&priv
->lock
);
9088 spin_lock_init(&priv
->power_data
.lock
);
9089 spin_lock_init(&priv
->sta_lock
);
9090 spin_lock_init(&priv
->hcmd_lock
);
9091 spin_lock_init(&priv
->lq_mngr
.lock
);
9093 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++)
9094 INIT_LIST_HEAD(&priv
->ibss_mac_hash
[i
]);
9096 INIT_LIST_HEAD(&priv
->free_frames
);
9098 mutex_init(&priv
->mutex
);
9099 if (pci_enable_device(pdev
)) {
9101 goto out_ieee80211_free_hw
;
9104 pci_set_master(pdev
);
9106 /* Clear the driver's (not device's) station table */
9107 iwl4965_clear_stations_table(priv
);
9109 priv
->data_retry_limit
= -1;
9110 priv
->ieee_channels
= NULL
;
9111 priv
->ieee_rates
= NULL
;
9114 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
9116 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
9118 printk(KERN_WARNING DRV_NAME
": No suitable DMA available.\n");
9119 goto out_pci_disable_device
;
9122 pci_set_drvdata(pdev
, priv
);
9123 err
= pci_request_regions(pdev
, DRV_NAME
);
9125 goto out_pci_disable_device
;
9127 /* We disable the RETRY_TIMEOUT register (0x41) to keep
9128 * PCI Tx retries from interfering with C3 CPU state */
9129 pci_write_config_byte(pdev
, 0x41, 0x00);
9131 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
9132 if (!priv
->hw_base
) {
9134 goto out_pci_release_regions
;
9137 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
9138 (unsigned long long) pci_resource_len(pdev
, 0));
9139 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
9141 /* Initialize module parameter values here */
9143 /* Disable radio (SW RF KILL) via parameter when loading driver */
9144 if (iwl4965_param_disable
) {
9145 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
9146 IWL_DEBUG_INFO("Radio disabled.\n");
9149 priv
->iw_mode
= IEEE80211_IF_TYPE_STA
;
9152 priv
->use_ant_b_for_management_frame
= 1; /* start with ant B */
9153 priv
->valid_antenna
= 0x7; /* assume all 3 connected */
9154 priv
->ps_mode
= IWL_MIMO_PS_NONE
;
9156 /* Choose which receivers/antennas to use */
9157 iwl4965_set_rxon_chain(priv
);
9159 printk(KERN_INFO DRV_NAME
9160 ": Detected Intel Wireless WiFi Link 4965AGN\n");
9162 /* Device-specific setup */
9163 if (iwl4965_hw_set_hw_setting(priv
)) {
9164 IWL_ERROR("failed to set hw settings\n");
9168 #ifdef CONFIG_IWL4965_QOS
9169 if (iwl4965_param_qos_enable
)
9170 priv
->qos_data
.qos_enable
= 1;
9172 iwl4965_reset_qos(priv
);
9174 priv
->qos_data
.qos_active
= 0;
9175 priv
->qos_data
.qos_cap
.val
= 0;
9176 #endif /* CONFIG_IWL4965_QOS */
9178 iwl4965_set_rxon_channel(priv
, MODE_IEEE80211G
, 6);
9179 iwl4965_setup_deferred_work(priv
);
9180 iwl4965_setup_rx_handlers(priv
);
9182 priv
->rates_mask
= IWL_RATES_MASK
;
9183 /* If power management is turned on, default to AC mode */
9184 priv
->power_mode
= IWL_POWER_AC
;
9185 priv
->user_txpower_limit
= IWL_DEFAULT_TX_POWER
;
9187 iwl4965_disable_interrupts(priv
);
9189 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
9191 IWL_ERROR("failed to create sysfs device attributes\n");
9192 goto out_release_irq
;
9196 iwl4965_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
9197 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
9199 iwl4965_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
9200 err
= iwl4965_poll_bit(priv
, CSR_GP_CNTRL
,
9201 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
9202 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
9204 IWL_DEBUG_INFO("Failed to init the card\n");
9205 goto out_remove_sysfs
;
9207 /* Read the EEPROM */
9208 err
= iwl4965_eeprom_init(priv
);
9210 IWL_ERROR("Unable to init EEPROM\n");
9211 goto out_remove_sysfs
;
9213 /* MAC Address location in EEPROM same for 3945/4965 */
9214 get_eeprom_mac(priv
, priv
->mac_addr
);
9215 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
9216 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
9218 err
= iwl4965_init_channel_map(priv
);
9220 IWL_ERROR("initializing regulatory failed: %d\n", err
);
9221 goto out_remove_sysfs
;
9224 err
= iwl4965_init_geos(priv
);
9226 IWL_ERROR("initializing geos failed: %d\n", err
);
9227 goto out_free_channel_map
;
9229 iwl4965_reset_channel_flag(priv
);
9231 iwl4965_rate_control_register(priv
->hw
);
9232 err
= ieee80211_register_hw(priv
->hw
);
9234 IWL_ERROR("Failed to register network device (error %d)\n", err
);
9238 priv
->hw
->conf
.beacon_int
= 100;
9239 priv
->mac80211_registered
= 1;
9240 pci_save_state(pdev
);
9241 pci_disable_device(pdev
);
9246 iwl4965_free_geos(priv
);
9247 out_free_channel_map
:
9248 iwl4965_free_channel_map(priv
);
9250 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
9253 destroy_workqueue(priv
->workqueue
);
9254 priv
->workqueue
= NULL
;
9255 iwl4965_unset_hw_setting(priv
);
9258 pci_iounmap(pdev
, priv
->hw_base
);
9259 out_pci_release_regions
:
9260 pci_release_regions(pdev
);
9261 out_pci_disable_device
:
9262 pci_disable_device(pdev
);
9263 pci_set_drvdata(pdev
, NULL
);
9264 out_ieee80211_free_hw
:
9265 ieee80211_free_hw(priv
->hw
);
9270 static void iwl4965_pci_remove(struct pci_dev
*pdev
)
9272 struct iwl4965_priv
*priv
= pci_get_drvdata(pdev
);
9273 struct list_head
*p
, *q
;
9279 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
9281 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
9285 /* Free MAC hash list for ADHOC */
9286 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
9287 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
9289 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
9293 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
9295 iwl4965_dealloc_ucode_pci(priv
);
9298 iwl4965_rx_queue_free(priv
, &priv
->rxq
);
9299 iwl4965_hw_txq_ctx_free(priv
);
9301 iwl4965_unset_hw_setting(priv
);
9302 iwl4965_clear_stations_table(priv
);
9304 if (priv
->mac80211_registered
) {
9305 ieee80211_unregister_hw(priv
->hw
);
9306 iwl4965_rate_control_unregister(priv
->hw
);
9309 /*netif_stop_queue(dev); */
9310 flush_workqueue(priv
->workqueue
);
9312 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
9313 * priv->workqueue... so we can't take down the workqueue
9315 destroy_workqueue(priv
->workqueue
);
9316 priv
->workqueue
= NULL
;
9318 pci_iounmap(pdev
, priv
->hw_base
);
9319 pci_release_regions(pdev
);
9320 pci_disable_device(pdev
);
9321 pci_set_drvdata(pdev
, NULL
);
9323 iwl4965_free_channel_map(priv
);
9324 iwl4965_free_geos(priv
);
9326 if (priv
->ibss_beacon
)
9327 dev_kfree_skb(priv
->ibss_beacon
);
9329 ieee80211_free_hw(priv
->hw
);
9334 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
9336 struct iwl4965_priv
*priv
= pci_get_drvdata(pdev
);
9338 if (priv
->is_open
) {
9339 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
9340 iwl4965_mac_stop(priv
->hw
);
9344 pci_set_power_state(pdev
, PCI_D3hot
);
9349 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
9351 struct iwl4965_priv
*priv
= pci_get_drvdata(pdev
);
9353 pci_set_power_state(pdev
, PCI_D0
);
9356 iwl4965_mac_start(priv
->hw
);
9358 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
9362 #endif /* CONFIG_PM */
9364 /*****************************************************************************
9366 * driver and module entry point
9368 *****************************************************************************/
9370 static struct pci_driver iwl4965_driver
= {
9372 .id_table
= iwl4965_hw_card_ids
,
9373 .probe
= iwl4965_pci_probe
,
9374 .remove
= __devexit_p(iwl4965_pci_remove
),
9376 .suspend
= iwl4965_pci_suspend
,
9377 .resume
= iwl4965_pci_resume
,
9381 static int __init
iwl4965_init(void)
9385 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
9386 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
9387 ret
= pci_register_driver(&iwl4965_driver
);
9389 IWL_ERROR("Unable to initialize PCI module\n");
9392 #ifdef CONFIG_IWL4965_DEBUG
9393 ret
= driver_create_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
9395 IWL_ERROR("Unable to create driver sysfs file\n");
9396 pci_unregister_driver(&iwl4965_driver
);
9404 static void __exit
iwl4965_exit(void)
9406 #ifdef CONFIG_IWL4965_DEBUG
9407 driver_remove_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
9409 pci_unregister_driver(&iwl4965_driver
);
9412 module_param_named(antenna
, iwl4965_param_antenna
, int, 0444);
9413 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
9414 module_param_named(disable
, iwl4965_param_disable
, int, 0444);
9415 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
9416 module_param_named(hwcrypto
, iwl4965_param_hwcrypto
, int, 0444);
9417 MODULE_PARM_DESC(hwcrypto
,
9418 "using hardware crypto engine (default 0 [software])\n");
9419 module_param_named(debug
, iwl4965_param_debug
, int, 0444);
9420 MODULE_PARM_DESC(debug
, "debug output mask");
9421 module_param_named(disable_hw_scan
, iwl4965_param_disable_hw_scan
, int, 0444);
9422 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
9424 module_param_named(queues_num
, iwl4965_param_queues_num
, int, 0444);
9425 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
9428 module_param_named(qos_enable
, iwl4965_param_qos_enable
, int, 0444);
9429 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionality");
9430 module_param_named(amsdu_size_8K
, iwl4965_param_amsdu_size_8K
, int, 0444);
9431 MODULE_PARM_DESC(amsdu_size_8K
, "enable 8K amsdu size");
9433 module_exit(iwl4965_exit
);
9434 module_init(iwl4965_init
);