1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/skbuff.h>
38 #include <linux/netdevice.h>
39 #include <linux/wireless.h>
40 #include <linux/firmware.h>
41 #include <linux/etherdevice.h>
42 #include <linux/if_arp.h>
44 #include <net/mac80211.h>
46 #include <asm/div64.h>
48 #include "iwl-eeprom.h"
52 #include "iwl-helpers.h"
54 #include "iwl-calib.h"
56 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
57 struct iwl4965_tx_queue
*txq
);
59 /******************************************************************************
63 ******************************************************************************/
66 * module name, copyright, version, etc.
67 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
70 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
72 #ifdef CONFIG_IWLWIFI_DEBUG
78 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
84 #define DRV_VERSION IWLWIFI_VERSION VD VS
87 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
88 MODULE_VERSION(DRV_VERSION
);
89 MODULE_AUTHOR(DRV_COPYRIGHT
);
90 MODULE_LICENSE("GPL");
92 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
94 u16 fc
= le16_to_cpu(hdr
->frame_control
);
95 int hdr_len
= ieee80211_get_hdrlen(fc
);
97 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
98 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
102 static const struct ieee80211_supported_band
*iwl_get_hw_mode(
103 struct iwl_priv
*priv
, enum ieee80211_band band
)
105 return priv
->hw
->wiphy
->bands
[band
];
108 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
110 /* Single white space is for Linksys APs */
111 if (essid_len
== 1 && essid
[0] == ' ')
114 /* Otherwise, if the entire essid is 0, we assume it is hidden */
117 if (essid
[essid_len
] != '\0')
124 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
126 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
127 const char *s
= essid
;
130 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
131 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
135 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
136 while (essid_len
--) {
149 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
152 * Theory of operation
154 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
155 * of buffer descriptors, each of which points to one or more data buffers for
156 * the device to read from or fill. Driver and device exchange status of each
157 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
158 * entries in each circular buffer, to protect against confusing empty and full
161 * The device reads or writes the data in the queues via the device's several
162 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
164 * For Tx queue, there are low mark and high mark limits. If, after queuing
165 * the packet for Tx, free space become < low mark, Tx queue stopped. When
166 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
169 * The 4965 operates with up to 17 queues: One receive queue, one transmit
170 * queue (#4) for sending commands to the device firmware, and 15 other
171 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
173 * See more detailed info in iwl-4965-hw.h.
174 ***************************************************/
176 int iwl4965_queue_space(const struct iwl4965_queue
*q
)
178 int s
= q
->read_ptr
- q
->write_ptr
;
180 if (q
->read_ptr
> q
->write_ptr
)
185 /* keep some reserve to not confuse empty and full situations */
193 static inline int x2_queue_used(const struct iwl4965_queue
*q
, int i
)
195 return q
->write_ptr
> q
->read_ptr
?
196 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
197 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
200 static inline u8
get_cmd_index(struct iwl4965_queue
*q
, u32 index
, int is_huge
)
202 /* This is for scan command, the big buffer at end of command array */
204 return q
->n_window
; /* must be power of 2 */
206 /* Otherwise, use normal size buffers */
207 return index
& (q
->n_window
- 1);
210 const u8 iwl4965_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
212 /*************** STATION TABLE MANAGEMENT ****
213 * mac80211 should be examined to determine if sta_info is duplicating
214 * the functionality provided here
217 /**************************************************************/
219 #if 0 /* temporary disable till we add real remove station */
221 * iwl4965_remove_station - Remove driver's knowledge of station.
223 * NOTE: This does not remove station from device's station table.
225 static u8
iwl4965_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
227 int index
= IWL_INVALID_STATION
;
231 spin_lock_irqsave(&priv
->sta_lock
, flags
);
235 else if (is_broadcast_ether_addr(addr
))
236 index
= priv
->hw_params
.bcast_sta_id
;
238 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++)
239 if (priv
->stations
[i
].used
&&
240 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
246 if (unlikely(index
== IWL_INVALID_STATION
))
249 if (priv
->stations
[index
].used
) {
250 priv
->stations
[index
].used
= 0;
251 priv
->num_stations
--;
254 BUG_ON(priv
->num_stations
< 0);
257 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
263 * iwl4965_add_station_flags - Add station to tables in driver and device
265 u8
iwl4965_add_station_flags(struct iwl_priv
*priv
, const u8
*addr
,
266 int is_ap
, u8 flags
, void *ht_data
)
269 int index
= IWL_INVALID_STATION
;
270 struct iwl_station_entry
*station
;
271 unsigned long flags_spin
;
272 DECLARE_MAC_BUF(mac
);
274 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
277 else if (is_broadcast_ether_addr(addr
))
278 index
= priv
->hw_params
.bcast_sta_id
;
280 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
281 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
287 if (!priv
->stations
[i
].used
&&
288 index
== IWL_INVALID_STATION
)
293 /* These two conditions have the same outcome, but keep them separate
294 since they have different meanings */
295 if (unlikely(index
== IWL_INVALID_STATION
)) {
296 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
300 if (priv
->stations
[index
].used
&&
301 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
302 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
307 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
308 station
= &priv
->stations
[index
];
310 priv
->num_stations
++;
312 /* Set up the REPLY_ADD_STA command to send to device */
313 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
314 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
315 station
->sta
.mode
= 0;
316 station
->sta
.sta
.sta_id
= index
;
317 station
->sta
.station_flags
= 0;
319 #ifdef CONFIG_IWL4965_HT
320 /* BCAST station and IBSS stations do not work in HT mode */
321 if (index
!= priv
->hw_params
.bcast_sta_id
&&
322 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
323 iwl4965_set_ht_add_station(priv
, index
,
324 (struct ieee80211_ht_info
*) ht_data
);
325 #endif /*CONFIG_IWL4965_HT*/
327 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
329 /* Add station to device's station table */
330 iwl_send_add_sta(priv
, &station
->sta
, flags
);
337 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
340 * iwl4965_enqueue_hcmd - enqueue a uCode command
341 * @priv: device private data point
342 * @cmd: a point to the ucode command structure
344 * The function returns < 0 values to indicate the operation is
345 * failed. On success, it turns the index (> 0) of command in the
348 int iwl4965_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
350 struct iwl4965_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
351 struct iwl4965_queue
*q
= &txq
->q
;
352 struct iwl_tfd_frame
*tfd
;
354 struct iwl_cmd
*out_cmd
;
356 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
357 dma_addr_t phys_addr
;
361 /* If any of the command structures end up being larger than
362 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
363 * we will need to increase the size of the TFD entries */
364 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
365 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
367 if (iwl_is_rfkill(priv
)) {
368 IWL_DEBUG_INFO("Not sending command - RF KILL");
372 if (iwl4965_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
373 IWL_ERROR("No space for Tx\n");
377 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
379 tfd
= &txq
->bd
[q
->write_ptr
];
380 memset(tfd
, 0, sizeof(*tfd
));
382 control_flags
= (u32
*) tfd
;
384 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
385 out_cmd
= &txq
->cmd
[idx
];
387 out_cmd
->hdr
.cmd
= cmd
->id
;
388 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
389 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
391 /* At this point, the out_cmd now has all of the incoming cmd
394 out_cmd
->hdr
.flags
= 0;
395 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
396 INDEX_TO_SEQ(q
->write_ptr
));
397 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
398 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
400 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
401 offsetof(struct iwl_cmd
, hdr
);
402 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
404 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
405 "%d bytes at %d[%d]:%d\n",
406 get_cmd_string(out_cmd
->hdr
.cmd
),
407 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
408 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
410 txq
->need_update
= 1;
412 /* Set up entry in queue's byte count circular buffer */
413 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, 0);
415 /* Increment and update queue's write index */
416 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
417 ret
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
419 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
420 return ret
? ret
: idx
;
423 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
425 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
428 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
430 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
435 * iwl4965_rxon_add_station - add station into station table.
437 * there is only one AP station with id= IWL_AP_ID
438 * NOTE: mutex must be held before calling this fnction
440 static int iwl4965_rxon_add_station(struct iwl_priv
*priv
,
441 const u8
*addr
, int is_ap
)
445 /* Add station to device's station table */
446 #ifdef CONFIG_IWL4965_HT
447 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
448 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
451 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
452 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
453 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
456 #endif /* CONFIG_IWL4965_HT */
457 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
460 /* Set up default rate scaling table in device's station table */
461 iwl4965_add_station(priv
, addr
, is_ap
);
467 * iwl4965_check_rxon_cmd - validate RXON structure is valid
469 * NOTE: This is really only useful during development and can eventually
470 * be #ifdef'd out once the driver is stable and folks aren't actively
473 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
478 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
479 error
|= le32_to_cpu(rxon
->flags
&
480 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
481 RXON_FLG_RADAR_DETECT_MSK
));
483 IWL_WARNING("check 24G fields %d | %d\n",
486 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
487 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
489 IWL_WARNING("check 52 fields %d | %d\n",
491 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
493 IWL_WARNING("check 52 CCK %d | %d\n",
496 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
498 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
500 /* make sure basic rates 6Mbps and 1Mbps are supported */
501 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
502 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
504 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
506 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
508 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
510 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
511 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
513 IWL_WARNING("check CCK and short slot %d | %d\n",
516 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
517 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
519 IWL_WARNING("check CCK & auto detect %d | %d\n",
522 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
523 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
525 IWL_WARNING("check TGG and auto detect %d | %d\n",
529 IWL_WARNING("Tuning to channel %d\n",
530 le16_to_cpu(rxon
->channel
));
533 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
540 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
541 * @priv: staging_rxon is compared to active_rxon
543 * If the RXON structure is changing enough to require a new tune,
544 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
545 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
547 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
550 /* These items are only settable from the full RXON command */
551 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
552 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
553 priv
->active_rxon
.bssid_addr
) ||
554 compare_ether_addr(priv
->staging_rxon
.node_addr
,
555 priv
->active_rxon
.node_addr
) ||
556 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
557 priv
->active_rxon
.wlap_bssid_addr
) ||
558 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
559 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
560 (priv
->staging_rxon
.air_propagation
!=
561 priv
->active_rxon
.air_propagation
) ||
562 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
563 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
564 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
565 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
566 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
567 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
570 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
571 * be updated with the RXON_ASSOC command -- however only some
572 * flag transitions are allowed using RXON_ASSOC */
574 /* Check if we are not switching bands */
575 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
576 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
579 /* Check if we are switching association toggle */
580 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
581 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
588 * iwl4965_commit_rxon - commit staging_rxon to hardware
590 * The RXON command in staging_rxon is committed to the hardware and
591 * the active_rxon structure is updated with the new data. This
592 * function correctly transitions out of the RXON_ASSOC_MSK state if
593 * a HW tune is required based on the RXON structure changes.
595 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
597 /* cast away the const for active_rxon in this function */
598 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
599 DECLARE_MAC_BUF(mac
);
602 if (!iwl_is_alive(priv
))
605 /* always get timestamp with Rx frame */
606 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
608 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
610 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
614 /* If we don't need to send a full RXON, we can use
615 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
616 * and other flags for the current radio configuration. */
617 if (!iwl4965_full_rxon_required(priv
)) {
618 rc
= iwl_send_rxon_assoc(priv
);
620 IWL_ERROR("Error setting RXON_ASSOC "
621 "configuration (%d).\n", rc
);
625 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
630 /* station table will be cleared */
631 priv
->assoc_station_added
= 0;
633 /* If we are currently associated and the new config requires
634 * an RXON_ASSOC and the new config wants the associated mask enabled,
635 * we must clear the associated from the active configuration
636 * before we apply the new config */
637 if (iwl_is_associated(priv
) &&
638 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
639 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
640 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
642 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
643 sizeof(struct iwl4965_rxon_cmd
),
646 /* If the mask clearing failed then we set
647 * active_rxon back to what it was previously */
649 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
650 IWL_ERROR("Error clearing ASSOC_MSK on current "
651 "configuration (%d).\n", rc
);
656 IWL_DEBUG_INFO("Sending RXON\n"
657 "* with%s RXON_FILTER_ASSOC_MSK\n"
660 ((priv
->staging_rxon
.filter_flags
&
661 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
662 le16_to_cpu(priv
->staging_rxon
.channel
),
663 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
665 iwl4965_set_rxon_hwcrypto(priv
, !priv
->hw_params
.sw_crypto
);
666 /* Apply the new configuration */
667 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
668 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
670 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
674 iwlcore_clear_stations_table(priv
);
676 if (!priv
->error_recovering
)
677 priv
->start_calib
= 0;
679 iwl_init_sensitivity(priv
);
681 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
683 /* If we issue a new RXON command which required a tune then we must
684 * send a new TXPOWER command or we won't be able to Tx any frames */
685 rc
= iwl4965_hw_reg_send_txpower(priv
);
687 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
691 /* Add the broadcast address so we can send broadcast frames */
692 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
693 IWL_INVALID_STATION
) {
694 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
698 /* If we have set the ASSOC_MSK and we are in BSS mode then
699 * add the IWL_AP_ID to the station rate table */
700 if (iwl_is_associated(priv
) &&
701 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
702 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
703 == IWL_INVALID_STATION
) {
704 IWL_ERROR("Error adding AP address for transmit.\n");
707 priv
->assoc_station_added
= 1;
708 if (priv
->default_wep_key
&&
709 iwl_send_static_wepkey_cmd(priv
, 0))
710 IWL_ERROR("Could not send WEP static key.\n");
716 void iwl4965_update_chain_flags(struct iwl_priv
*priv
)
719 iwl_set_rxon_chain(priv
);
720 iwl4965_commit_rxon(priv
);
723 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
725 struct iwl4965_bt_cmd bt_cmd
= {
733 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
734 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
737 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
740 struct iwl_rx_packet
*res
;
741 struct iwl_host_cmd cmd
= {
742 .id
= REPLY_SCAN_ABORT_CMD
,
743 .meta
.flags
= CMD_WANT_SKB
,
746 /* If there isn't a scan actively going on in the hardware
747 * then we are in between scan bands and not actually
748 * actively scanning, so don't send the abort command */
749 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
750 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
754 ret
= iwl_send_cmd_sync(priv
, &cmd
);
756 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
760 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
761 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
762 /* The scan abort will return 1 for success or
763 * 2 for "failure". A failure condition can be
764 * due to simply not being in an active scan which
765 * can occur if we send the scan abort before we
766 * the microcode has notified us that a scan is
768 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
769 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
770 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
773 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
781 * Use: Sets the device's internal card state to enable, disable, or halt
783 * When in the 'enable' state the card operates as normal.
784 * When in the 'disable' state, the card enters into a low power mode.
785 * When in the 'halt' state, the card is shut down and must be fully
786 * restarted to come back on.
788 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
790 struct iwl_host_cmd cmd
= {
791 .id
= REPLY_CARD_STATE_CMD
,
794 .meta
.flags
= meta_flag
,
797 return iwl_send_cmd(priv
, &cmd
);
800 static void iwl4965_clear_free_frames(struct iwl_priv
*priv
)
802 struct list_head
*element
;
804 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
807 while (!list_empty(&priv
->free_frames
)) {
808 element
= priv
->free_frames
.next
;
810 kfree(list_entry(element
, struct iwl4965_frame
, list
));
811 priv
->frames_count
--;
814 if (priv
->frames_count
) {
815 IWL_WARNING("%d frames still in use. Did we lose one?\n",
817 priv
->frames_count
= 0;
821 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl_priv
*priv
)
823 struct iwl4965_frame
*frame
;
824 struct list_head
*element
;
825 if (list_empty(&priv
->free_frames
)) {
826 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
828 IWL_ERROR("Could not allocate frame!\n");
832 priv
->frames_count
++;
836 element
= priv
->free_frames
.next
;
838 return list_entry(element
, struct iwl4965_frame
, list
);
841 static void iwl4965_free_frame(struct iwl_priv
*priv
, struct iwl4965_frame
*frame
)
843 memset(frame
, 0, sizeof(*frame
));
844 list_add(&frame
->list
, &priv
->free_frames
);
847 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
848 struct ieee80211_hdr
*hdr
,
849 const u8
*dest
, int left
)
852 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
853 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
854 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
857 if (priv
->ibss_beacon
->len
> left
)
860 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
862 return priv
->ibss_beacon
->len
;
865 static u8
iwl4965_rate_get_lowest_plcp(struct iwl_priv
*priv
)
871 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
872 rate_mask
= priv
->active_rate_basic
& 0xF;
874 rate_mask
= priv
->active_rate_basic
& 0xFF0;
876 /* Find lowest valid rate */
877 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
878 i
= iwl4965_rates
[i
].next_ieee
) {
879 if (rate_mask
& (1 << i
))
880 return iwl4965_rates
[i
].plcp
;
883 /* No valid rate was found. Assign the lowest one */
884 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
885 return IWL_RATE_1M_PLCP
;
887 return IWL_RATE_6M_PLCP
;
890 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
892 struct iwl4965_frame
*frame
;
893 unsigned int frame_size
;
897 frame
= iwl4965_get_free_frame(priv
);
900 IWL_ERROR("Could not obtain free frame buffer for beacon "
905 rate
= iwl4965_rate_get_lowest_plcp(priv
);
907 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
909 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
912 iwl4965_free_frame(priv
, frame
);
917 /******************************************************************************
919 * Misc. internal state and helper functions
921 ******************************************************************************/
924 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
926 * return : set the bit for each supported rate insert in ie
928 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
929 u16 basic_rate
, int *left
)
931 u16 ret_rates
= 0, bit
;
936 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
937 if (bit
& supported_rate
) {
939 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
940 ((bit
& basic_rate
) ? 0x80 : 0x00);
944 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
952 #ifdef CONFIG_IWL4965_HT
953 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
954 struct ieee80211_bss_conf
*bss_conf
)
956 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
957 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
958 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
960 IWL_DEBUG_MAC80211("enter: \n");
962 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
964 if (!iwl_conf
->is_ht
)
967 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
969 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
970 iwl_conf
->sgf
|= 0x1;
971 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
972 iwl_conf
->sgf
|= 0x2;
974 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
975 iwl_conf
->max_amsdu_size
=
976 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
978 iwl_conf
->supported_chan_width
=
979 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
980 iwl_conf
->extension_chan_offset
=
981 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
982 /* If no above or below channel supplied disable FAT channel */
983 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
984 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
985 iwl_conf
->supported_chan_width
= 0;
987 iwl_conf
->tx_mimo_ps_mode
=
988 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
989 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
991 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
992 iwl_conf
->tx_chan_width
=
993 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
994 iwl_conf
->ht_protection
=
995 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
996 iwl_conf
->non_GF_STA_present
=
997 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
999 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
1000 IWL_DEBUG_MAC80211("leave\n");
1003 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
1006 struct ieee80211_ht_cap
*ht_cap
;
1008 if (!sband
|| !sband
->ht_info
.ht_supported
)
1011 if (*left
< sizeof(struct ieee80211_ht_cap
))
1014 *pos
++ = sizeof(struct ieee80211_ht_cap
);
1015 ht_cap
= (struct ieee80211_ht_cap
*) pos
;
1017 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
1018 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
1019 ht_cap
->ampdu_params_info
=
1020 (sband
->ht_info
.ampdu_factor
& IEEE80211_HT_CAP_AMPDU_FACTOR
) |
1021 ((sband
->ht_info
.ampdu_density
<< 2) &
1022 IEEE80211_HT_CAP_AMPDU_DENSITY
);
1023 *left
-= sizeof(struct ieee80211_ht_cap
);
1026 static inline void iwl4965_ht_conf(struct iwl_priv
*priv
,
1027 struct ieee80211_bss_conf
*bss_conf
)
1030 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
1038 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1040 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
1041 enum ieee80211_band band
,
1042 struct ieee80211_mgmt
*frame
,
1043 int left
, int is_direct
)
1047 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1048 const struct ieee80211_supported_band
*sband
=
1049 iwl_get_hw_mode(priv
, band
);
1051 /* Make sure there is enough space for the probe request,
1052 * two mandatory IEs and the data */
1058 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1059 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1060 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1061 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1062 frame
->seq_ctrl
= 0;
1064 /* fill in our indirect SSID IE */
1071 pos
= &(frame
->u
.probe_req
.variable
[0]);
1072 *pos
++ = WLAN_EID_SSID
;
1075 /* fill in our direct SSID IE... */
1078 left
-= 2 + priv
->essid_len
;
1081 /* ... fill it in... */
1082 *pos
++ = WLAN_EID_SSID
;
1083 *pos
++ = priv
->essid_len
;
1084 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1085 pos
+= priv
->essid_len
;
1086 len
+= 2 + priv
->essid_len
;
1089 /* fill in supported rate */
1095 /* ... fill it in... */
1096 *pos
++ = WLAN_EID_SUPP_RATES
;
1099 /* exclude 60M rate */
1100 active_rates
= priv
->rates_mask
;
1101 active_rates
&= ~IWL_RATE_60M_MASK
;
1103 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1105 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1106 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1107 active_rate_basic
, &left
);
1108 active_rates
&= ~ret_rates
;
1110 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1111 active_rate_basic
, &left
);
1112 active_rates
&= ~ret_rates
;
1116 if (active_rates
== 0)
1119 /* fill in supported extended rate */
1124 /* ... fill it in... */
1125 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1127 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1128 active_rate_basic
, &left
);
1138 *pos
++ = WLAN_EID_HT_CAPABILITY
;
1141 iwl_ht_cap_to_ie(sband
, pos
, &left
);
1151 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
1152 struct iwl4965_qosparam_cmd
*qos
)
1155 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1156 sizeof(struct iwl4965_qosparam_cmd
), qos
);
1159 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
1161 unsigned long flags
;
1163 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1166 if (!priv
->qos_data
.qos_enable
)
1169 spin_lock_irqsave(&priv
->lock
, flags
);
1170 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1172 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1173 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1174 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1175 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1176 if (priv
->qos_data
.qos_active
)
1177 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1178 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1180 #ifdef CONFIG_IWL4965_HT
1181 if (priv
->current_ht_config
.is_ht
)
1182 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
1183 #endif /* CONFIG_IWL4965_HT */
1185 spin_unlock_irqrestore(&priv
->lock
, flags
);
1187 if (force
|| iwl_is_associated(priv
)) {
1188 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1189 priv
->qos_data
.qos_active
,
1190 priv
->qos_data
.def_qos_parm
.qos_flags
);
1192 iwl4965_send_qos_params_command(priv
,
1193 &(priv
->qos_data
.def_qos_parm
));
1197 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1199 /* Filter incoming packets to determine if they are targeted toward
1200 * this network, discarding packets coming from ourselves */
1201 switch (priv
->iw_mode
) {
1202 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
1203 /* packets from our adapter are dropped (echo) */
1204 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
1206 /* {broad,multi}cast packets to our IBSS go through */
1207 if (is_multicast_ether_addr(header
->addr1
))
1208 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
1209 /* packets to our adapter go through */
1210 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1211 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
1212 /* packets from our adapter are dropped (echo) */
1213 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
1215 /* {broad,multi}cast packets to our BSS go through */
1216 if (is_multicast_ether_addr(header
->addr1
))
1217 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
1218 /* packets to our adapter go through */
1219 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1227 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1229 static const char *iwl4965_get_tx_fail_reason(u32 status
)
1231 switch (status
& TX_STATUS_MSK
) {
1232 case TX_STATUS_SUCCESS
:
1234 TX_STATUS_ENTRY(SHORT_LIMIT
);
1235 TX_STATUS_ENTRY(LONG_LIMIT
);
1236 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
1237 TX_STATUS_ENTRY(MGMNT_ABORT
);
1238 TX_STATUS_ENTRY(NEXT_FRAG
);
1239 TX_STATUS_ENTRY(LIFE_EXPIRE
);
1240 TX_STATUS_ENTRY(DEST_PS
);
1241 TX_STATUS_ENTRY(ABORTED
);
1242 TX_STATUS_ENTRY(BT_RETRY
);
1243 TX_STATUS_ENTRY(STA_INVALID
);
1244 TX_STATUS_ENTRY(FRAG_DROPPED
);
1245 TX_STATUS_ENTRY(TID_DISABLE
);
1246 TX_STATUS_ENTRY(FRAME_FLUSHED
);
1247 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
1248 TX_STATUS_ENTRY(TX_LOCKED
);
1249 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
1256 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1258 * NOTE: priv->mutex is not required before calling this function
1260 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
1262 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1263 clear_bit(STATUS_SCANNING
, &priv
->status
);
1267 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1268 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1269 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1270 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1271 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1274 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1276 return test_bit(STATUS_SCANNING
, &priv
->status
);
1283 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1284 * @ms: amount of time to wait (in milliseconds) for scan to abort
1286 * NOTE: priv->mutex must be held before calling this function
1288 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1290 unsigned long now
= jiffies
;
1293 ret
= iwl4965_scan_cancel(priv
);
1295 mutex_unlock(&priv
->mutex
);
1296 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1297 test_bit(STATUS_SCANNING
, &priv
->status
))
1299 mutex_lock(&priv
->mutex
);
1301 return test_bit(STATUS_SCANNING
, &priv
->status
);
1307 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
1309 /* Reset ieee stats */
1311 /* We don't reset the net_device_stats (ieee->stats) on
1314 priv
->last_seq_num
= -1;
1315 priv
->last_frag_num
= -1;
1316 priv
->last_packet_time
= 0;
1318 iwl4965_scan_cancel(priv
);
1321 #define MAX_UCODE_BEACON_INTERVAL 4096
1322 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1324 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
1327 u16 beacon_factor
= 0;
1330 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1331 / MAX_UCODE_BEACON_INTERVAL
;
1332 new_val
= beacon_val
/ beacon_factor
;
1334 return cpu_to_le16(new_val
);
1337 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
1339 u64 interval_tm_unit
;
1341 unsigned long flags
;
1342 struct ieee80211_conf
*conf
= NULL
;
1345 conf
= ieee80211_get_hw_conf(priv
->hw
);
1347 spin_lock_irqsave(&priv
->lock
, flags
);
1348 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
1349 priv
->rxon_timing
.timestamp
.dw
[0] =
1350 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
1352 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1354 tsf
= priv
->timestamp
;
1356 beacon_int
= priv
->beacon_int
;
1357 spin_unlock_irqrestore(&priv
->lock
, flags
);
1359 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1360 if (beacon_int
== 0) {
1361 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1362 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1364 priv
->rxon_timing
.beacon_interval
=
1365 cpu_to_le16(beacon_int
);
1366 priv
->rxon_timing
.beacon_interval
=
1367 iwl4965_adjust_beacon_interval(
1368 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1371 priv
->rxon_timing
.atim_window
= 0;
1373 priv
->rxon_timing
.beacon_interval
=
1374 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1375 /* TODO: we need to get atim_window from upper stack
1376 * for now we set to 0 */
1377 priv
->rxon_timing
.atim_window
= 0;
1381 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1382 result
= do_div(tsf
, interval_tm_unit
);
1383 priv
->rxon_timing
.beacon_init_val
=
1384 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1387 ("beacon interval %d beacon timer %d beacon tim %d\n",
1388 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1389 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1390 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1393 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1395 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1396 IWL_ERROR("APs don't scan.\n");
1400 if (!iwl_is_ready_rf(priv
)) {
1401 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1405 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1406 IWL_DEBUG_SCAN("Scan already in progress.\n");
1410 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1411 IWL_DEBUG_SCAN("Scan request while abort pending. "
1416 IWL_DEBUG_INFO("Starting scan...\n");
1417 priv
->scan_bands
= 2;
1418 set_bit(STATUS_SCANNING
, &priv
->status
);
1419 priv
->scan_start
= jiffies
;
1420 priv
->scan_pass_start
= priv
->scan_start
;
1422 queue_work(priv
->workqueue
, &priv
->request_scan
);
1428 static void iwl4965_set_flags_for_phymode(struct iwl_priv
*priv
,
1429 enum ieee80211_band band
)
1431 if (band
== IEEE80211_BAND_5GHZ
) {
1432 priv
->staging_rxon
.flags
&=
1433 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1434 | RXON_FLG_CCK_MSK
);
1435 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1437 /* Copied from iwl4965_post_associate() */
1438 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1439 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1441 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1443 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
1444 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1446 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1447 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1448 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1453 * initialize rxon structure with default values from eeprom
1455 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
1457 const struct iwl_channel_info
*ch_info
;
1459 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
1461 switch (priv
->iw_mode
) {
1462 case IEEE80211_IF_TYPE_AP
:
1463 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1466 case IEEE80211_IF_TYPE_STA
:
1467 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
1468 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
1471 case IEEE80211_IF_TYPE_IBSS
:
1472 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
1473 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
1474 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
1475 RXON_FILTER_ACCEPT_GRP_MSK
;
1478 case IEEE80211_IF_TYPE_MNTR
:
1479 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
1480 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
1481 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
1484 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
1489 /* TODO: Figure out when short_preamble would be set and cache from
1491 if (!hw_to_local(priv
->hw
)->short_preamble
)
1492 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1494 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1497 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
1498 le16_to_cpu(priv
->staging_rxon
.channel
));
1501 ch_info
= &priv
->channel_info
[0];
1504 * in some case A channels are all non IBSS
1505 * in this case force B/G channel
1507 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
1508 !(is_channel_ibss(ch_info
)))
1509 ch_info
= &priv
->channel_info
[0];
1511 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
1512 priv
->band
= ch_info
->band
;
1514 iwl4965_set_flags_for_phymode(priv
, priv
->band
);
1516 priv
->staging_rxon
.ofdm_basic_rates
=
1517 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1518 priv
->staging_rxon
.cck_basic_rates
=
1519 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1521 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
1522 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
1523 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1524 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
1525 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
1526 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
1527 iwl_set_rxon_chain(priv
);
1530 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
1532 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
1533 const struct iwl_channel_info
*ch_info
;
1535 ch_info
= iwl_get_channel_info(priv
,
1537 le16_to_cpu(priv
->staging_rxon
.channel
));
1539 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
1540 IWL_ERROR("channel %d not IBSS channel\n",
1541 le16_to_cpu(priv
->staging_rxon
.channel
));
1546 priv
->iw_mode
= mode
;
1548 iwl4965_connection_init_rx_config(priv
);
1549 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1551 iwlcore_clear_stations_table(priv
);
1553 /* dont commit rxon if rf-kill is on*/
1554 if (!iwl_is_ready_rf(priv
))
1557 cancel_delayed_work(&priv
->scan_check
);
1558 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
1559 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1560 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1564 iwl4965_commit_rxon(priv
);
1569 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
1570 struct ieee80211_tx_control
*ctl
,
1571 struct iwl_cmd
*cmd
,
1572 struct sk_buff
*skb_frag
,
1575 struct iwl_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
1576 struct iwl_wep_key
*wepkey
;
1579 BUG_ON(ctl
->hw_key
->hw_key_idx
> 3);
1581 switch (keyinfo
->alg
) {
1583 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
1584 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
1585 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
1586 cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_AGG_CCMP_MSK
;
1587 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
1591 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
1592 ieee80211_get_tkip_key(keyinfo
->conf
, skb_frag
,
1593 IEEE80211_TKIP_P2_KEY
, cmd
->cmd
.tx
.key
);
1594 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
1598 wepkey
= &priv
->wep_keys
[ctl
->hw_key
->hw_key_idx
];
1599 cmd
->cmd
.tx
.sec_ctl
= 0;
1600 if (priv
->default_wep_key
) {
1601 /* the WEP key was sent as static */
1602 keyidx
= ctl
->hw_key
->hw_key_idx
;
1603 memcpy(&cmd
->cmd
.tx
.key
[3], wepkey
->key
,
1605 if (wepkey
->key_size
== WEP_KEY_LEN_128
)
1606 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
1608 /* the WEP key was sent as dynamic */
1609 keyidx
= keyinfo
->keyidx
;
1610 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
,
1612 if (keyinfo
->keylen
== WEP_KEY_LEN_128
)
1613 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
1616 cmd
->cmd
.tx
.sec_ctl
|= (TX_CMD_SEC_WEP
|
1617 (keyidx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
);
1619 IWL_DEBUG_TX("Configuring packet for WEP encryption "
1620 "with key %d\n", keyidx
);
1624 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
1630 * handle build REPLY_TX command notification.
1632 static void iwl4965_build_tx_cmd_basic(struct iwl_priv
*priv
,
1633 struct iwl_cmd
*cmd
,
1634 struct ieee80211_tx_control
*ctrl
,
1635 struct ieee80211_hdr
*hdr
,
1636 int is_unicast
, u8 std_id
)
1639 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1640 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
1642 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
1643 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
1644 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
1645 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
1646 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1647 if (ieee80211_is_probe_response(fc
) &&
1648 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
1649 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
1651 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
1652 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1655 if (ieee80211_is_back_request(fc
))
1656 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
1659 cmd
->cmd
.tx
.sta_id
= std_id
;
1660 if (ieee80211_get_morefrag(hdr
))
1661 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
1663 qc
= ieee80211_get_qos_ctrl(hdr
);
1665 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
1666 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
1668 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
1670 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
1671 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
1672 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
1673 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
1674 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
1675 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
1678 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
1679 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
1681 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
1682 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
1683 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
1684 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
1685 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
1687 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
1689 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
1692 cmd
->cmd
.tx
.driver_txop
= 0;
1693 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
1694 cmd
->cmd
.tx
.next_frame_len
= 0;
1696 static void iwl_update_tx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
1698 /* 0 - mgmt, 1 - cnt, 2 - data */
1699 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
1700 priv
->tx_stats
[idx
].cnt
++;
1701 priv
->tx_stats
[idx
].bytes
+= len
;
1704 * iwl4965_get_sta_id - Find station's index within station table
1706 * If new IBSS station, create new entry in station table
1708 static int iwl4965_get_sta_id(struct iwl_priv
*priv
,
1709 struct ieee80211_hdr
*hdr
)
1712 u16 fc
= le16_to_cpu(hdr
->frame_control
);
1713 DECLARE_MAC_BUF(mac
);
1715 /* If this frame is broadcast or management, use broadcast station id */
1716 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
1717 is_multicast_ether_addr(hdr
->addr1
))
1718 return priv
->hw_params
.bcast_sta_id
;
1720 switch (priv
->iw_mode
) {
1722 /* If we are a client station in a BSS network, use the special
1723 * AP station entry (that's the only station we communicate with) */
1724 case IEEE80211_IF_TYPE_STA
:
1727 /* If we are an AP, then find the station, or use BCAST */
1728 case IEEE80211_IF_TYPE_AP
:
1729 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
1730 if (sta_id
!= IWL_INVALID_STATION
)
1732 return priv
->hw_params
.bcast_sta_id
;
1734 /* If this frame is going out to an IBSS network, find the station,
1735 * or create a new station table entry */
1736 case IEEE80211_IF_TYPE_IBSS
:
1737 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
1738 if (sta_id
!= IWL_INVALID_STATION
)
1741 /* Create new station table entry */
1742 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
1743 0, CMD_ASYNC
, NULL
);
1745 if (sta_id
!= IWL_INVALID_STATION
)
1748 IWL_DEBUG_DROP("Station %s not in station map. "
1749 "Defaulting to broadcast...\n",
1750 print_mac(mac
, hdr
->addr1
));
1751 iwl_print_hex_dump(priv
, IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
1752 return priv
->hw_params
.bcast_sta_id
;
1755 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
1756 return priv
->hw_params
.bcast_sta_id
;
1761 * start REPLY_TX command process
1763 static int iwl4965_tx_skb(struct iwl_priv
*priv
,
1764 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
1766 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1767 struct iwl_tfd_frame
*tfd
;
1769 int txq_id
= ctl
->queue
;
1770 struct iwl4965_tx_queue
*txq
= NULL
;
1771 struct iwl4965_queue
*q
= NULL
;
1772 dma_addr_t phys_addr
;
1773 dma_addr_t txcmd_phys
;
1774 dma_addr_t scratch_phys
;
1775 struct iwl_cmd
*out_cmd
= NULL
;
1776 u16 len
, idx
, len_org
;
1777 u8 id
, hdr_len
, unicast
;
1782 u8 wait_write_ptr
= 0;
1783 unsigned long flags
;
1786 spin_lock_irqsave(&priv
->lock
, flags
);
1787 if (iwl_is_rfkill(priv
)) {
1788 IWL_DEBUG_DROP("Dropping - RF KILL\n");
1793 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
1797 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
1798 IWL_ERROR("ERROR: No TX rate available.\n");
1802 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
1805 fc
= le16_to_cpu(hdr
->frame_control
);
1807 #ifdef CONFIG_IWLWIFI_DEBUG
1808 if (ieee80211_is_auth(fc
))
1809 IWL_DEBUG_TX("Sending AUTH frame\n");
1810 else if (ieee80211_is_assoc_request(fc
))
1811 IWL_DEBUG_TX("Sending ASSOC frame\n");
1812 else if (ieee80211_is_reassoc_request(fc
))
1813 IWL_DEBUG_TX("Sending REASSOC frame\n");
1816 /* drop all data frame if we are not associated */
1817 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
1818 (!iwl_is_associated(priv
) ||
1819 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
1820 !priv
->assoc_station_added
)) {
1821 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
1825 spin_unlock_irqrestore(&priv
->lock
, flags
);
1827 hdr_len
= ieee80211_get_hdrlen(fc
);
1829 /* Find (or create) index into station table for destination station */
1830 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
1831 if (sta_id
== IWL_INVALID_STATION
) {
1832 DECLARE_MAC_BUF(mac
);
1834 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
1835 print_mac(mac
, hdr
->addr1
));
1839 IWL_DEBUG_TX("station Id %d\n", sta_id
);
1841 qc
= ieee80211_get_qos_ctrl(hdr
);
1843 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
1844 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
1846 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
1848 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
1850 #ifdef CONFIG_IWL4965_HT
1851 /* aggregation is on for this <sta,tid> */
1852 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
1853 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
1854 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
1855 #endif /* CONFIG_IWL4965_HT */
1858 /* Descriptor for chosen Tx queue */
1859 txq
= &priv
->txq
[txq_id
];
1862 spin_lock_irqsave(&priv
->lock
, flags
);
1864 /* Set up first empty TFD within this queue's circular TFD buffer */
1865 tfd
= &txq
->bd
[q
->write_ptr
];
1866 memset(tfd
, 0, sizeof(*tfd
));
1867 control_flags
= (u32
*) tfd
;
1868 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
1870 /* Set up driver data for this TFD */
1871 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
1872 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
1873 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
1874 ctl
, sizeof(struct ieee80211_tx_control
));
1876 /* Set up first empty entry in queue's array of Tx/cmd buffers */
1877 out_cmd
= &txq
->cmd
[idx
];
1878 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
1879 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
1882 * Set up the Tx-command (not MAC!) header.
1883 * Store the chosen Tx queue and TFD index within the sequence field;
1884 * after Tx, uCode's Tx response will return this value so driver can
1885 * locate the frame within the tx queue and do post-tx processing.
1887 out_cmd
->hdr
.cmd
= REPLY_TX
;
1888 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
1889 INDEX_TO_SEQ(q
->write_ptr
)));
1891 /* Copy MAC header from skb into command buffer */
1892 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
1895 * Use the first empty entry in this queue's command buffer array
1896 * to contain the Tx command and MAC header concatenated together
1897 * (payload data will be in another buffer).
1898 * Size of this varies, due to varying MAC header length.
1899 * If end is not dword aligned, we'll have 2 extra bytes at the end
1900 * of the MAC header (device reads on dword boundaries).
1901 * We'll tell device about this padding later.
1903 len
= priv
->hw_params
.tx_cmd_len
+
1904 sizeof(struct iwl_cmd_header
) + hdr_len
;
1907 len
= (len
+ 3) & ~3;
1914 /* Physical address of this Tx command's header (not MAC header!),
1915 * within command buffer array. */
1916 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
1917 offsetof(struct iwl_cmd
, hdr
);
1919 /* Add buffer containing Tx command and MAC(!) header to TFD's
1921 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
1923 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
1924 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, sta_id
);
1926 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1927 * if any (802.11 null frames have no payload). */
1928 len
= skb
->len
- hdr_len
;
1930 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
1931 len
, PCI_DMA_TODEVICE
);
1932 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
1935 /* Tell 4965 about any 2-byte padding after MAC header */
1937 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
1939 /* Total # bytes to be transmitted */
1940 len
= (u16
)skb
->len
;
1941 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
1943 /* TODO need this for burst mode later on */
1944 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
1946 /* set is_hcca to 0; it probably will never be implemented */
1947 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
1949 iwl_update_tx_stats(priv
, fc
, len
);
1951 scratch_phys
= txcmd_phys
+ sizeof(struct iwl_cmd_header
) +
1952 offsetof(struct iwl4965_tx_cmd
, scratch
);
1953 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
1954 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
1956 if (!ieee80211_get_morefrag(hdr
)) {
1957 txq
->need_update
= 1;
1959 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
1960 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
1964 txq
->need_update
= 0;
1967 iwl_print_hex_dump(priv
, IWL_DL_TX
, out_cmd
->cmd
.payload
,
1968 sizeof(out_cmd
->cmd
.tx
));
1970 iwl_print_hex_dump(priv
, IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
1971 ieee80211_get_hdrlen(fc
));
1973 /* Set up entry for this TFD in Tx byte-count array */
1974 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, len
);
1976 /* Tell device the write index *just past* this latest filled TFD */
1977 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
1978 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
1979 spin_unlock_irqrestore(&priv
->lock
, flags
);
1984 if ((iwl4965_queue_space(q
) < q
->high_mark
)
1985 && priv
->mac80211_registered
) {
1986 if (wait_write_ptr
) {
1987 spin_lock_irqsave(&priv
->lock
, flags
);
1988 txq
->need_update
= 1;
1989 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
1990 spin_unlock_irqrestore(&priv
->lock
, flags
);
1993 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
1999 spin_unlock_irqrestore(&priv
->lock
, flags
);
2004 static void iwl4965_set_rate(struct iwl_priv
*priv
)
2006 const struct ieee80211_supported_band
*hw
= NULL
;
2007 struct ieee80211_rate
*rate
;
2010 hw
= iwl_get_hw_mode(priv
, priv
->band
);
2012 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2016 priv
->active_rate
= 0;
2017 priv
->active_rate_basic
= 0;
2019 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
2020 rate
= &(hw
->bitrates
[i
]);
2021 if (rate
->hw_value
< IWL_RATE_COUNT
)
2022 priv
->active_rate
|= (1 << rate
->hw_value
);
2025 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2026 priv
->active_rate
, priv
->active_rate_basic
);
2029 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2030 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2033 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2034 priv
->staging_rxon
.cck_basic_rates
=
2035 ((priv
->active_rate_basic
&
2036 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2038 priv
->staging_rxon
.cck_basic_rates
=
2039 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2041 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2042 priv
->staging_rxon
.ofdm_basic_rates
=
2043 ((priv
->active_rate_basic
&
2044 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2045 IWL_FIRST_OFDM_RATE
) & 0xFF;
2047 priv
->staging_rxon
.ofdm_basic_rates
=
2048 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2051 void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2053 unsigned long flags
;
2055 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2058 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2059 disable_radio
? "OFF" : "ON");
2061 if (disable_radio
) {
2062 iwl4965_scan_cancel(priv
);
2063 /* FIXME: This is a workaround for AP */
2064 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2065 spin_lock_irqsave(&priv
->lock
, flags
);
2066 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2067 CSR_UCODE_SW_BIT_RFKILL
);
2068 spin_unlock_irqrestore(&priv
->lock
, flags
);
2069 /* call the host command only if no hw rf-kill set */
2070 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
) &&
2072 iwl4965_send_card_state(priv
,
2073 CARD_STATE_CMD_DISABLE
,
2075 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2077 /* make sure mac80211 stop sending Tx frame */
2078 if (priv
->mac80211_registered
)
2079 ieee80211_stop_queues(priv
->hw
);
2084 spin_lock_irqsave(&priv
->lock
, flags
);
2085 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2087 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2088 spin_unlock_irqrestore(&priv
->lock
, flags
);
2093 spin_lock_irqsave(&priv
->lock
, flags
);
2094 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2095 if (!iwl_grab_nic_access(priv
))
2096 iwl_release_nic_access(priv
);
2097 spin_unlock_irqrestore(&priv
->lock
, flags
);
2099 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2100 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2101 "disabled by HW switch\n");
2105 queue_work(priv
->workqueue
, &priv
->restart
);
2109 #define IWL_PACKET_RETRY_TIME HZ
2111 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2113 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2114 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2115 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2116 u16
*last_seq
, *last_frag
;
2117 unsigned long *last_time
;
2119 switch (priv
->iw_mode
) {
2120 case IEEE80211_IF_TYPE_IBSS
:{
2121 struct list_head
*p
;
2122 struct iwl4965_ibss_seq
*entry
= NULL
;
2123 u8
*mac
= header
->addr2
;
2124 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2126 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2127 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
2128 if (!compare_ether_addr(entry
->mac
, mac
))
2131 if (p
== &priv
->ibss_mac_hash
[index
]) {
2132 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2134 IWL_ERROR("Cannot malloc new mac entry\n");
2137 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2138 entry
->seq_num
= seq
;
2139 entry
->frag_num
= frag
;
2140 entry
->packet_time
= jiffies
;
2141 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2144 last_seq
= &entry
->seq_num
;
2145 last_frag
= &entry
->frag_num
;
2146 last_time
= &entry
->packet_time
;
2149 case IEEE80211_IF_TYPE_STA
:
2150 last_seq
= &priv
->last_seq_num
;
2151 last_frag
= &priv
->last_frag_num
;
2152 last_time
= &priv
->last_packet_time
;
2157 if ((*last_seq
== seq
) &&
2158 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
2159 if (*last_frag
== frag
)
2161 if (*last_frag
+ 1 != frag
)
2162 /* out-of-order fragment */
2168 *last_time
= jiffies
;
2175 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2177 #include "iwl-spectrum.h"
2179 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2180 #define BEACON_TIME_MASK_HIGH 0xFF000000
2181 #define TIME_UNIT 1024
2184 * extended beacon time format
2185 * time in usec will be changed into a 32-bit value in 8:24 format
2186 * the high 1 byte is the beacon counts
2187 * the lower 3 bytes is the time in usec within one beacon interval
2190 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2194 u32 interval
= beacon_interval
* 1024;
2196 if (!interval
|| !usec
)
2199 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2200 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2202 return (quot
<< 24) + rem
;
2205 /* base is usually what we get from ucode with each received frame,
2206 * the same as HW timer counter counting down
2209 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2211 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2212 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2213 u32 interval
= beacon_interval
* TIME_UNIT
;
2214 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2215 (addon
& BEACON_TIME_MASK_HIGH
);
2217 if (base_low
> addon_low
)
2218 res
+= base_low
- addon_low
;
2219 else if (base_low
< addon_low
) {
2220 res
+= interval
+ base_low
- addon_low
;
2225 return cpu_to_le32(res
);
2228 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
2229 struct ieee80211_measurement_params
*params
,
2232 struct iwl4965_spectrum_cmd spectrum
;
2233 struct iwl_rx_packet
*res
;
2234 struct iwl_host_cmd cmd
= {
2235 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2236 .data
= (void *)&spectrum
,
2237 .meta
.flags
= CMD_WANT_SKB
,
2239 u32 add_time
= le64_to_cpu(params
->start_time
);
2241 int spectrum_resp_status
;
2242 int duration
= le16_to_cpu(params
->duration
);
2244 if (iwl_is_associated(priv
))
2246 iwl4965_usecs_to_beacons(
2247 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2248 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2250 memset(&spectrum
, 0, sizeof(spectrum
));
2252 spectrum
.channel_count
= cpu_to_le16(1);
2254 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2255 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2256 cmd
.len
= sizeof(spectrum
);
2257 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2259 if (iwl_is_associated(priv
))
2260 spectrum
.start_time
=
2261 iwl4965_add_beacon_time(priv
->last_beacon_time
,
2263 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2265 spectrum
.start_time
= 0;
2267 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2268 spectrum
.channels
[0].channel
= params
->channel
;
2269 spectrum
.channels
[0].type
= type
;
2270 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2271 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2272 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2274 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2278 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2279 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2280 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2284 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2285 switch (spectrum_resp_status
) {
2286 case 0: /* Command will be handled */
2287 if (res
->u
.spectrum
.id
!= 0xff) {
2289 ("Replaced existing measurement: %d\n",
2290 res
->u
.spectrum
.id
);
2291 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2293 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2297 case 1: /* Command will not be handled */
2302 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2308 static void iwl4965_txstatus_to_ieee(struct iwl_priv
*priv
,
2309 struct iwl4965_tx_info
*tx_sta
)
2312 tx_sta
->status
.ack_signal
= 0;
2313 tx_sta
->status
.excessive_retries
= 0;
2316 ieee80211_tx_status_irqsafe(priv
->hw
,
2317 tx_sta
->skb
[0], &(tx_sta
->status
));
2319 ieee80211_tx_status(priv
->hw
,
2320 tx_sta
->skb
[0], &(tx_sta
->status
));
2322 tx_sta
->skb
[0] = NULL
;
2326 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2328 * When FW advances 'R' index, all entries between old and new 'R' index
2329 * need to be reclaimed. As result, some free space forms. If there is
2330 * enough free space (> low mark), wake the stack that feeds us.
2332 int iwl4965_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
2334 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2335 struct iwl4965_queue
*q
= &txq
->q
;
2338 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
2339 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2340 "is out of range [0-%d] %d %d.\n", txq_id
,
2341 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2345 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
2346 q
->read_ptr
!= index
;
2347 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2348 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
2349 iwl4965_txstatus_to_ieee(priv
,
2350 &(txq
->txb
[txq
->q
.read_ptr
]));
2351 iwl_hw_txq_free_tfd(priv
, txq
);
2352 } else if (nfreed
> 1) {
2353 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
2354 q
->write_ptr
, q
->read_ptr
);
2355 queue_work(priv
->workqueue
, &priv
->restart
);
2363 static int iwl4965_is_tx_success(u32 status
)
2365 status
&= TX_STATUS_MSK
;
2366 return (status
== TX_STATUS_SUCCESS
)
2367 || (status
== TX_STATUS_DIRECT_DONE
);
2370 /******************************************************************************
2372 * Generic RX handler implementations
2374 ******************************************************************************/
2375 #ifdef CONFIG_IWL4965_HT
2377 static inline int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
,
2378 struct ieee80211_hdr
*hdr
)
2380 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
2383 u8
*da
= ieee80211_get_DA(hdr
);
2384 return iwl_find_station(priv
, da
);
2388 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
2389 struct iwl_priv
*priv
, int txq_id
, int idx
)
2391 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
2392 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
2393 txb
[idx
].skb
[0]->data
;
2397 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
2399 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
2400 tx_resp
->frame_count
);
2401 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
2406 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2408 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
2409 struct iwl_ht_agg
*agg
,
2410 struct iwl4965_tx_resp_agg
*tx_resp
,
2414 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
2415 struct ieee80211_tx_status
*tx_status
= NULL
;
2416 struct ieee80211_hdr
*hdr
= NULL
;
2421 if (agg
->wait_for_ba
)
2422 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2424 agg
->frame_count
= tx_resp
->frame_count
;
2425 agg
->start_idx
= start_idx
;
2426 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2429 /* # frames attempted by Tx command */
2430 if (agg
->frame_count
== 1) {
2431 /* Only one frame was attempted; no block-ack will arrive */
2432 status
= le16_to_cpu(frame_status
[0].status
);
2433 seq
= le16_to_cpu(frame_status
[0].sequence
);
2434 idx
= SEQ_TO_INDEX(seq
);
2435 txq_id
= SEQ_TO_QUEUE(seq
);
2437 /* FIXME: code repetition */
2438 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2439 agg
->frame_count
, agg
->start_idx
, idx
);
2441 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
2442 tx_status
->retry_count
= tx_resp
->failure_frame
;
2443 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
2444 tx_status
->flags
= iwl4965_is_tx_success(status
)?
2445 IEEE80211_TX_STATUS_ACK
: 0;
2446 iwl4965_hwrate_to_tx_control(priv
,
2447 le32_to_cpu(tx_resp
->rate_n_flags
),
2448 &tx_status
->control
);
2449 /* FIXME: code repetition end */
2451 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2452 status
& 0xff, tx_resp
->failure_frame
);
2453 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
2454 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
2456 agg
->wait_for_ba
= 0;
2458 /* Two or more frames were attempted; expect block-ack */
2460 int start
= agg
->start_idx
;
2462 /* Construct bit-map of pending frames within Tx window */
2463 for (i
= 0; i
< agg
->frame_count
; i
++) {
2465 status
= le16_to_cpu(frame_status
[i
].status
);
2466 seq
= le16_to_cpu(frame_status
[i
].sequence
);
2467 idx
= SEQ_TO_INDEX(seq
);
2468 txq_id
= SEQ_TO_QUEUE(seq
);
2470 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
2471 AGG_TX_STATE_ABORT_MSK
))
2474 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2475 agg
->frame_count
, txq_id
, idx
);
2477 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
2479 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2480 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
2481 IWL_ERROR("BUG_ON idx doesn't match seq control"
2482 " idx=%d, seq_idx=%d, seq=%d\n",
2488 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2489 i
, idx
, SEQ_TO_SN(sc
));
2493 sh
= (start
- idx
) + 0xff;
2494 bitmap
= bitmap
<< sh
;
2497 } else if (sh
< -64)
2498 sh
= 0xff - (start
- idx
);
2502 bitmap
= bitmap
<< sh
;
2505 bitmap
|= (1 << sh
);
2506 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
2507 start
, (u32
)(bitmap
& 0xFFFFFFFF));
2510 agg
->bitmap
= bitmap
;
2511 agg
->start_idx
= start
;
2512 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2513 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2514 agg
->frame_count
, agg
->start_idx
,
2515 (unsigned long long)agg
->bitmap
);
2518 agg
->wait_for_ba
= 1;
2525 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
2527 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
2528 struct iwl_rx_mem_buffer
*rxb
)
2530 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2531 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
2532 int txq_id
= SEQ_TO_QUEUE(sequence
);
2533 int index
= SEQ_TO_INDEX(sequence
);
2534 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2535 struct ieee80211_tx_status
*tx_status
;
2536 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
2537 u32 status
= le32_to_cpu(tx_resp
->status
);
2538 #ifdef CONFIG_IWL4965_HT
2539 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
2540 struct ieee80211_hdr
*hdr
;
2544 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
2545 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
2546 "is out of range [0-%d] %d %d\n", txq_id
,
2547 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
2552 #ifdef CONFIG_IWL4965_HT
2553 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
2554 qc
= ieee80211_get_qos_ctrl(hdr
);
2557 tid
= le16_to_cpu(*qc
) & 0xf;
2559 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
2560 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
2561 IWL_ERROR("Station not known\n");
2565 if (txq
->sched_retry
) {
2566 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
2567 struct iwl_ht_agg
*agg
= NULL
;
2572 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
2574 iwl4965_tx_status_reply_tx(priv
, agg
,
2575 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
2577 if ((tx_resp
->frame_count
== 1) &&
2578 !iwl4965_is_tx_success(status
)) {
2579 /* TODO: send BAR */
2582 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
2584 index
= iwl_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
2585 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
2586 "%d index %d\n", scd_ssn
, index
);
2587 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
2588 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
2590 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
2591 txq_id
>= 0 && priv
->mac80211_registered
&&
2592 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
) {
2593 /* calculate mac80211 ampdu sw queue to wake */
2594 ampdu_q
= txq_id
- IWL_BACK_QUEUE_FIRST_ID
+
2596 if (agg
->state
== IWL_AGG_OFF
)
2597 ieee80211_wake_queue(priv
->hw
, txq_id
);
2599 ieee80211_wake_queue(priv
->hw
, ampdu_q
);
2601 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
2604 #endif /* CONFIG_IWL4965_HT */
2605 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
2607 tx_status
->retry_count
= tx_resp
->failure_frame
;
2609 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
2610 iwl4965_hwrate_to_tx_control(priv
, le32_to_cpu(tx_resp
->rate_n_flags
),
2611 &tx_status
->control
);
2613 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
2614 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
2615 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
2616 tx_resp
->failure_frame
);
2618 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
2619 #ifdef CONFIG_IWL4965_HT
2621 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
2622 if (tid
!= MAX_TID_COUNT
)
2623 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
2624 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
2625 (txq_id
>= 0) && priv
->mac80211_registered
)
2626 ieee80211_wake_queue(priv
->hw
, txq_id
);
2627 if (tid
!= MAX_TID_COUNT
)
2628 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
2631 #endif /* CONFIG_IWL4965_HT */
2633 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
2634 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
2638 static void iwl4965_rx_reply_alive(struct iwl_priv
*priv
,
2639 struct iwl_rx_mem_buffer
*rxb
)
2641 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2642 struct iwl4965_alive_resp
*palive
;
2643 struct delayed_work
*pwork
;
2645 palive
= &pkt
->u
.alive_frame
;
2647 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
2649 palive
->is_valid
, palive
->ver_type
,
2650 palive
->ver_subtype
);
2652 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
2653 IWL_DEBUG_INFO("Initialization Alive received.\n");
2654 memcpy(&priv
->card_alive_init
,
2655 &pkt
->u
.alive_frame
,
2656 sizeof(struct iwl4965_init_alive_resp
));
2657 pwork
= &priv
->init_alive_start
;
2659 IWL_DEBUG_INFO("Runtime Alive received.\n");
2660 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
2661 sizeof(struct iwl4965_alive_resp
));
2662 pwork
= &priv
->alive_start
;
2665 /* We delay the ALIVE response by 5ms to
2666 * give the HW RF Kill time to activate... */
2667 if (palive
->is_valid
== UCODE_VALID_OK
)
2668 queue_delayed_work(priv
->workqueue
, pwork
,
2669 msecs_to_jiffies(5));
2671 IWL_WARNING("uCode did not respond OK.\n");
2674 static void iwl4965_rx_reply_add_sta(struct iwl_priv
*priv
,
2675 struct iwl_rx_mem_buffer
*rxb
)
2677 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2679 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
2683 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
2684 struct iwl_rx_mem_buffer
*rxb
)
2686 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2688 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
2689 "seq 0x%04X ser 0x%08X\n",
2690 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
2691 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
2692 pkt
->u
.err_resp
.cmd_id
,
2693 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
2694 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
2697 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2699 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
2701 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2702 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
2703 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
2704 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2705 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
2706 rxon
->channel
= csa
->channel
;
2707 priv
->staging_rxon
.channel
= csa
->channel
;
2710 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
2711 struct iwl_rx_mem_buffer
*rxb
)
2713 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2714 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2715 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
2717 if (!report
->state
) {
2718 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
2719 "Spectrum Measure Notification: Start\n");
2723 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
2724 priv
->measurement_status
|= MEASUREMENT_READY
;
2728 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
2729 struct iwl_rx_mem_buffer
*rxb
)
2731 #ifdef CONFIG_IWLWIFI_DEBUG
2732 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2733 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
2734 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2735 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
2739 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
2740 struct iwl_rx_mem_buffer
*rxb
)
2742 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2743 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2744 "notification for %s:\n",
2745 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
2746 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
2749 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
2751 struct iwl_priv
*priv
=
2752 container_of(work
, struct iwl_priv
, beacon_update
);
2753 struct sk_buff
*beacon
;
2755 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
2756 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
2759 IWL_ERROR("update beacon failed\n");
2763 mutex_lock(&priv
->mutex
);
2764 /* new beacon skb is allocated every time; dispose previous.*/
2765 if (priv
->ibss_beacon
)
2766 dev_kfree_skb(priv
->ibss_beacon
);
2768 priv
->ibss_beacon
= beacon
;
2769 mutex_unlock(&priv
->mutex
);
2771 iwl4965_send_beacon_cmd(priv
);
2774 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
2775 struct iwl_rx_mem_buffer
*rxb
)
2777 #ifdef CONFIG_IWLWIFI_DEBUG
2778 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2779 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
2780 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
2782 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
2783 "tsf %d %d rate %d\n",
2784 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
2785 beacon
->beacon_notify_hdr
.failure_frame
,
2786 le32_to_cpu(beacon
->ibss_mgr_status
),
2787 le32_to_cpu(beacon
->high_tsf
),
2788 le32_to_cpu(beacon
->low_tsf
), rate
);
2791 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
2792 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
2793 queue_work(priv
->workqueue
, &priv
->beacon_update
);
2796 /* Service response to REPLY_SCAN_CMD (0x80) */
2797 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
2798 struct iwl_rx_mem_buffer
*rxb
)
2800 #ifdef CONFIG_IWLWIFI_DEBUG
2801 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2802 struct iwl4965_scanreq_notification
*notif
=
2803 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
2805 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
2809 /* Service SCAN_START_NOTIFICATION (0x82) */
2810 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
2811 struct iwl_rx_mem_buffer
*rxb
)
2813 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2814 struct iwl4965_scanstart_notification
*notif
=
2815 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
2816 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
2817 IWL_DEBUG_SCAN("Scan start: "
2819 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
2821 notif
->band
? "bg" : "a",
2823 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
2826 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
2827 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
2828 struct iwl_rx_mem_buffer
*rxb
)
2830 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2831 struct iwl4965_scanresults_notification
*notif
=
2832 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
2834 IWL_DEBUG_SCAN("Scan ch.res: "
2836 "(TSF: 0x%08X:%08X) - %d "
2837 "elapsed=%lu usec (%dms since last)\n",
2839 notif
->band
? "bg" : "a",
2840 le32_to_cpu(notif
->tsf_high
),
2841 le32_to_cpu(notif
->tsf_low
),
2842 le32_to_cpu(notif
->statistics
[0]),
2843 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
2844 jiffies_to_msecs(elapsed_jiffies
2845 (priv
->last_scan_jiffies
, jiffies
)));
2847 priv
->last_scan_jiffies
= jiffies
;
2848 priv
->next_scan_jiffies
= 0;
2851 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
2852 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
2853 struct iwl_rx_mem_buffer
*rxb
)
2855 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2856 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
2858 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2859 scan_notif
->scanned_channels
,
2860 scan_notif
->tsf_low
,
2861 scan_notif
->tsf_high
, scan_notif
->status
);
2863 /* The HW is no longer scanning */
2864 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
2866 /* The scan completion notification came in, so kill that timer... */
2867 cancel_delayed_work(&priv
->scan_check
);
2869 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
2870 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
2871 jiffies_to_msecs(elapsed_jiffies
2872 (priv
->scan_pass_start
, jiffies
)));
2874 /* Remove this scanned band from the list
2875 * of pending bands to scan */
2878 /* If a request to abort was given, or the scan did not succeed
2879 * then we reset the scan state machine and terminate,
2880 * re-queuing another scan if one has been requested */
2881 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2882 IWL_DEBUG_INFO("Aborted scan completed.\n");
2883 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
2885 /* If there are more bands on this scan pass reschedule */
2886 if (priv
->scan_bands
> 0)
2890 priv
->last_scan_jiffies
= jiffies
;
2891 priv
->next_scan_jiffies
= 0;
2892 IWL_DEBUG_INFO("Setting scan to off\n");
2894 clear_bit(STATUS_SCANNING
, &priv
->status
);
2896 IWL_DEBUG_INFO("Scan took %dms\n",
2897 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
2899 queue_work(priv
->workqueue
, &priv
->scan_completed
);
2904 priv
->scan_pass_start
= jiffies
;
2905 queue_work(priv
->workqueue
, &priv
->request_scan
);
2908 /* Handle notification from uCode that card's power state is changing
2909 * due to software, hardware, or critical temperature RFKILL */
2910 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
2911 struct iwl_rx_mem_buffer
*rxb
)
2913 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
2914 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
2915 unsigned long status
= priv
->status
;
2917 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
2918 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
2919 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
2921 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
2922 RF_CARD_DISABLED
)) {
2924 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2925 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2927 if (!iwl_grab_nic_access(priv
)) {
2929 priv
, HBUS_TARG_MBX_C
,
2930 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
2932 iwl_release_nic_access(priv
);
2935 if (!(flags
& RXON_CARD_DISABLED
)) {
2936 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
2937 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
2938 if (!iwl_grab_nic_access(priv
)) {
2940 priv
, HBUS_TARG_MBX_C
,
2941 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
2943 iwl_release_nic_access(priv
);
2947 if (flags
& RF_CARD_DISABLED
) {
2948 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2949 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
2950 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2951 if (!iwl_grab_nic_access(priv
))
2952 iwl_release_nic_access(priv
);
2956 if (flags
& HW_CARD_DISABLED
)
2957 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2959 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2962 if (flags
& SW_CARD_DISABLED
)
2963 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2965 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2967 if (!(flags
& RXON_CARD_DISABLED
))
2968 iwl4965_scan_cancel(priv
);
2970 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
2971 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
2972 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
2973 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
2974 queue_work(priv
->workqueue
, &priv
->rf_kill
);
2976 wake_up_interruptible(&priv
->wait_command_queue
);
2980 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
2982 * Setup the RX handlers for each of the reply types sent from the uCode
2985 * This function chains into the hardware specific files for them to setup
2986 * any hardware specific handlers as well.
2988 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
2990 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
2991 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
2992 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
2993 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
2994 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
2995 iwl4965_rx_spectrum_measure_notif
;
2996 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
2997 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
2998 iwl4965_rx_pm_debug_statistics_notif
;
2999 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
3002 * The same handler is used for both the REPLY to a discrete
3003 * statistics request from the host as well as for the periodic
3004 * statistics notifications (after received beacons) from the uCode.
3006 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
3007 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
3009 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
3010 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
3011 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3012 iwl4965_rx_scan_results_notif
;
3013 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3014 iwl4965_rx_scan_complete_notif
;
3015 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
3016 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
3018 /* Set up hardware specific Rx handlers */
3019 priv
->cfg
->ops
->lib
->rx_handler_setup(priv
);
3023 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3024 * @rxb: Rx buffer to reclaim
3026 * If an Rx buffer has an async callback associated with it the callback
3027 * will be executed. The attached skb (if present) will only be freed
3028 * if the callback returns 1
3030 static void iwl4965_tx_cmd_complete(struct iwl_priv
*priv
,
3031 struct iwl_rx_mem_buffer
*rxb
)
3033 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
3034 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3035 int txq_id
= SEQ_TO_QUEUE(sequence
);
3036 int index
= SEQ_TO_INDEX(sequence
);
3037 int huge
= sequence
& SEQ_HUGE_FRAME
;
3039 struct iwl_cmd
*cmd
;
3041 /* If a Tx command is being handled and it isn't in the actual
3042 * command queue then there a command routing bug has been introduced
3043 * in the queue management code. */
3044 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3045 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3046 txq_id
, pkt
->hdr
.cmd
);
3047 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3049 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3050 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3052 /* Input error checking is done when commands are added to queue. */
3053 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3054 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3056 } else if (cmd
->meta
.u
.callback
&&
3057 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3060 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3062 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3063 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3064 wake_up_interruptible(&priv
->wait_command_queue
);
3069 * this should be called while priv->lock is locked
3071 static void __iwl_rx_replenish(struct iwl_priv
*priv
)
3073 iwl_rx_allocate(priv
);
3074 iwl_rx_queue_restock(priv
);
3079 * iwl_rx_handle - Main entry function for receiving responses from uCode
3081 * Uses the priv->rx_handlers callback function array to invoke
3082 * the appropriate handlers, including command responses,
3083 * frame-received notifications, and other notifications.
3085 void iwl_rx_handle(struct iwl_priv
*priv
)
3087 struct iwl_rx_mem_buffer
*rxb
;
3088 struct iwl_rx_packet
*pkt
;
3089 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
3092 unsigned long flags
;
3096 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3097 * buffer that the driver may process (last buffer filled by ucode). */
3098 r
= iwl4965_hw_get_rx_read(priv
);
3101 /* Rx interrupt, but nothing sent from uCode */
3103 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
3105 if (iwl_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
3109 rxb
= rxq
->queue
[i
];
3111 /* If an RXB doesn't have a Rx queue slot associated with it,
3112 * then a bug has been introduced in the queue refilling
3113 * routines -- catch it here */
3114 BUG_ON(rxb
== NULL
);
3116 rxq
->queue
[i
] = NULL
;
3118 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
3119 priv
->hw_params
.rx_buf_size
,
3120 PCI_DMA_FROMDEVICE
);
3121 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
3123 /* Reclaim a command buffer only if this packet is a response
3124 * to a (driver-originated) command.
3125 * If the packet (e.g. Rx frame) originated from uCode,
3126 * there is no command buffer to reclaim.
3127 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3128 * but apparently a few don't get set; catch them here. */
3129 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
3130 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
3131 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
3132 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
3133 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
3134 (pkt
->hdr
.cmd
!= REPLY_TX
);
3136 /* Based on type of command response or notification,
3137 * handle those that need handling via function in
3138 * rx_handlers table. See iwl4965_setup_rx_handlers() */
3139 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
3140 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3141 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
3142 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
3143 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
3145 /* No handling needed */
3146 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
3147 "r %d i %d No handler needed for %s, 0x%02x\n",
3148 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
3153 /* Invoke any callbacks, transfer the skb to caller, and
3154 * fire off the (possibly) blocking iwl_send_cmd()
3155 * as we reclaim the driver command queue */
3156 if (rxb
&& rxb
->skb
)
3157 iwl4965_tx_cmd_complete(priv
, rxb
);
3159 IWL_WARNING("Claim null rxb?\n");
3162 /* For now we just don't re-use anything. We can tweak this
3163 * later to try and re-use notification packets and SKBs that
3164 * fail to Rx correctly */
3165 if (rxb
->skb
!= NULL
) {
3166 priv
->alloc_rxb_skb
--;
3167 dev_kfree_skb_any(rxb
->skb
);
3171 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
3172 priv
->hw_params
.rx_buf_size
,
3173 PCI_DMA_FROMDEVICE
);
3174 spin_lock_irqsave(&rxq
->lock
, flags
);
3175 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
3176 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3177 i
= (i
+ 1) & RX_QUEUE_MASK
;
3178 /* If there are a lot of unused frames,
3179 * restock the Rx queue so ucode wont assert. */
3184 __iwl_rx_replenish(priv
);
3190 /* Backtrack one entry */
3192 iwl_rx_queue_restock(priv
);
3194 /* Convert linear signal-to-noise ratio into dB */
3195 static u8 ratio2dB
[100] = {
3196 /* 0 1 2 3 4 5 6 7 8 9 */
3197 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3198 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3199 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3200 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3201 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3202 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3203 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3204 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3205 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3206 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3209 /* Calculates a relative dB value from a ratio of linear
3210 * (i.e. not dB) signal levels.
3211 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3212 int iwl4965_calc_db_from_ratio(int sig_ratio
)
3214 /* 1000:1 or higher just report as 60 dB */
3215 if (sig_ratio
>= 1000)
3218 /* 100:1 or higher, divide by 10 and use table,
3219 * add 20 dB to make up for divide by 10 */
3220 if (sig_ratio
>= 100)
3221 return (20 + (int)ratio2dB
[sig_ratio
/10]);
3223 /* We shouldn't see this */
3227 /* Use table for ratios 1:1 - 99:1 */
3228 return (int)ratio2dB
[sig_ratio
];
3231 #define PERFECT_RSSI (-20) /* dBm */
3232 #define WORST_RSSI (-95) /* dBm */
3233 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3235 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3236 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3237 * about formulas used below. */
3238 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
3241 int degradation
= PERFECT_RSSI
- rssi_dbm
;
3243 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3244 * as indicator; formula is (signal dbm - noise dbm).
3245 * SNR at or above 40 is a great signal (100%).
3246 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3247 * Weakest usable signal is usually 10 - 15 dB SNR. */
3249 if (rssi_dbm
- noise_dbm
>= 40)
3251 else if (rssi_dbm
< noise_dbm
)
3253 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
3255 /* Else use just the signal level.
3256 * This formula is a least squares fit of data points collected and
3257 * compared with a reference system that had a percentage (%) display
3258 * for signal quality. */
3260 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
3261 (15 * RSSI_RANGE
+ 62 * degradation
)) /
3262 (RSSI_RANGE
* RSSI_RANGE
);
3266 else if (sig_qual
< 1)
3273 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
3275 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
3276 struct iwl4965_tx_queue
*txq
)
3280 int txq_id
= txq
->q
.id
;
3282 if (txq
->need_update
== 0)
3285 /* if we're trying to save power */
3286 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3287 /* wake up nic if it's powered down ...
3288 * uCode will wake up, and interrupt us again, so next
3289 * time we'll skip this part. */
3290 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3292 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3293 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
3294 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3295 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3299 /* restore this queue's parameters in nic hardware. */
3300 rc
= iwl_grab_nic_access(priv
);
3303 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
3304 txq
->q
.write_ptr
| (txq_id
<< 8));
3305 iwl_release_nic_access(priv
);
3307 /* else not in power-save mode, uCode will never sleep when we're
3308 * trying to tx (during RFKILL, we're not trying to tx). */
3310 iwl_write32(priv
, HBUS_TARG_WRPTR
,
3311 txq
->q
.write_ptr
| (txq_id
<< 8));
3313 txq
->need_update
= 0;
3318 #ifdef CONFIG_IWLWIFI_DEBUG
3319 static void iwl4965_print_rx_config_cmd(struct iwl_priv
*priv
)
3321 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
3322 DECLARE_MAC_BUF(mac
);
3324 IWL_DEBUG_RADIO("RX CONFIG:\n");
3325 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
3326 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
3327 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
3328 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
3329 le32_to_cpu(rxon
->filter_flags
));
3330 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
3331 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
3332 rxon
->ofdm_basic_rates
);
3333 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
3334 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
3335 print_mac(mac
, rxon
->node_addr
));
3336 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
3337 print_mac(mac
, rxon
->bssid_addr
));
3338 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
3342 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
3344 IWL_DEBUG_ISR("Enabling interrupts\n");
3345 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
3346 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
3349 /* call this function to flush any scheduled tasklet */
3350 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
3352 /* wait to make sure we flush pedding tasklet*/
3353 synchronize_irq(priv
->pci_dev
->irq
);
3354 tasklet_kill(&priv
->irq_tasklet
);
3357 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
3359 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
3361 /* disable interrupts from uCode/NIC to host */
3362 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
3364 /* acknowledge/clear/reset any interrupts still pending
3365 * from uCode or flow handler (Rx/Tx DMA) */
3366 iwl_write32(priv
, CSR_INT
, 0xffffffff);
3367 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
3368 IWL_DEBUG_ISR("Disabled interrupts\n");
3371 static const char *desc_lookup(int i
)
3379 return "BAD_CHECKSUM";
3381 return "NMI_INTERRUPT";
3385 return "FATAL_ERROR";
3391 #define ERROR_START_OFFSET (1 * sizeof(u32))
3392 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
3394 static void iwl4965_dump_nic_error_log(struct iwl_priv
*priv
)
3397 u32 desc
, time
, count
, base
, data1
;
3398 u32 blink1
, blink2
, ilink1
, ilink2
;
3401 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
3403 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
3404 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
3408 rc
= iwl_grab_nic_access(priv
);
3410 IWL_WARNING("Can not read from adapter at this time.\n");
3414 count
= iwl_read_targ_mem(priv
, base
);
3416 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
3417 IWL_ERROR("Start IWL Error Log Dump:\n");
3418 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
3421 desc
= iwl_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
3422 blink1
= iwl_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
3423 blink2
= iwl_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
3424 ilink1
= iwl_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
3425 ilink2
= iwl_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
3426 data1
= iwl_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
3427 data2
= iwl_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
3428 line
= iwl_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
3429 time
= iwl_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
3431 IWL_ERROR("Desc Time "
3432 "data1 data2 line\n");
3433 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
3434 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
3435 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
3436 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
3439 iwl_release_nic_access(priv
);
3442 #define EVENT_START_OFFSET (4 * sizeof(u32))
3445 * iwl4965_print_event_log - Dump error event log to syslog
3447 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
3449 static void iwl4965_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
3450 u32 num_events
, u32 mode
)
3453 u32 base
; /* SRAM byte address of event log header */
3454 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
3455 u32 ptr
; /* SRAM byte address of log data */
3456 u32 ev
, time
, data
; /* event log data */
3458 if (num_events
== 0)
3461 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
3464 event_size
= 2 * sizeof(u32
);
3466 event_size
= 3 * sizeof(u32
);
3468 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
3470 /* "time" is actually "data" for mode 0 (no timestamp).
3471 * place event id # at far right for easier visual parsing. */
3472 for (i
= 0; i
< num_events
; i
++) {
3473 ev
= iwl_read_targ_mem(priv
, ptr
);
3475 time
= iwl_read_targ_mem(priv
, ptr
);
3478 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
3480 data
= iwl_read_targ_mem(priv
, ptr
);
3482 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
3487 static void iwl4965_dump_nic_event_log(struct iwl_priv
*priv
)
3490 u32 base
; /* SRAM byte address of event log header */
3491 u32 capacity
; /* event log capacity in # entries */
3492 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
3493 u32 num_wraps
; /* # times uCode wrapped to top of log */
3494 u32 next_entry
; /* index of next entry to be written by uCode */
3495 u32 size
; /* # entries that we'll print */
3497 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
3498 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
3499 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
3503 rc
= iwl_grab_nic_access(priv
);
3505 IWL_WARNING("Can not read from adapter at this time.\n");
3509 /* event log header */
3510 capacity
= iwl_read_targ_mem(priv
, base
);
3511 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
3512 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
3513 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
3515 size
= num_wraps
? capacity
: next_entry
;
3517 /* bail out if nothing in log */
3519 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
3520 iwl_release_nic_access(priv
);
3524 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
3527 /* if uCode has wrapped back to top of log, start at the oldest entry,
3528 * i.e the next one that uCode would fill. */
3530 iwl4965_print_event_log(priv
, next_entry
,
3531 capacity
- next_entry
, mode
);
3533 /* (then/else) start at top of log */
3534 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
3536 iwl_release_nic_access(priv
);
3540 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
3542 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
3544 /* Set the FW error flag -- cleared on iwl4965_down */
3545 set_bit(STATUS_FW_ERROR
, &priv
->status
);
3547 /* Cancel currently queued command. */
3548 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3550 #ifdef CONFIG_IWLWIFI_DEBUG
3551 if (priv
->debug_level
& IWL_DL_FW_ERRORS
) {
3552 iwl4965_dump_nic_error_log(priv
);
3553 iwl4965_dump_nic_event_log(priv
);
3554 iwl4965_print_rx_config_cmd(priv
);
3558 wake_up_interruptible(&priv
->wait_command_queue
);
3560 /* Keep the restart process from trying to send host
3561 * commands by clearing the INIT status bit */
3562 clear_bit(STATUS_READY
, &priv
->status
);
3564 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
3565 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
3566 "Restarting adapter due to uCode error.\n");
3568 if (iwl_is_associated(priv
)) {
3569 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
3570 sizeof(priv
->recovery_rxon
));
3571 priv
->error_recovering
= 1;
3573 queue_work(priv
->workqueue
, &priv
->restart
);
3577 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
3579 unsigned long flags
;
3581 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
3582 sizeof(priv
->staging_rxon
));
3583 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
3584 iwl4965_commit_rxon(priv
);
3586 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
3588 spin_lock_irqsave(&priv
->lock
, flags
);
3589 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
3590 priv
->error_recovering
= 0;
3591 spin_unlock_irqrestore(&priv
->lock
, flags
);
3594 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
3596 u32 inta
, handled
= 0;
3598 unsigned long flags
;
3599 #ifdef CONFIG_IWLWIFI_DEBUG
3603 spin_lock_irqsave(&priv
->lock
, flags
);
3605 /* Ack/clear/reset pending uCode interrupts.
3606 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
3607 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
3608 inta
= iwl_read32(priv
, CSR_INT
);
3609 iwl_write32(priv
, CSR_INT
, inta
);
3611 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
3612 * Any new interrupts that happen after this, either while we're
3613 * in this tasklet, or later, will show up in next ISR/tasklet. */
3614 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
3615 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
3617 #ifdef CONFIG_IWLWIFI_DEBUG
3618 if (priv
->debug_level
& IWL_DL_ISR
) {
3619 /* just for debug */
3620 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
3621 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3622 inta
, inta_mask
, inta_fh
);
3626 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
3627 * atomic, make sure that inta covers all the interrupts that
3628 * we've discovered, even if FH interrupt came in just after
3629 * reading CSR_INT. */
3630 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
3631 inta
|= CSR_INT_BIT_FH_RX
;
3632 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
3633 inta
|= CSR_INT_BIT_FH_TX
;
3635 /* Now service all interrupt bits discovered above. */
3636 if (inta
& CSR_INT_BIT_HW_ERR
) {
3637 IWL_ERROR("Microcode HW error detected. Restarting.\n");
3639 /* Tell the device to stop sending interrupts */
3640 iwl4965_disable_interrupts(priv
);
3642 iwl4965_irq_handle_error(priv
);
3644 handled
|= CSR_INT_BIT_HW_ERR
;
3646 spin_unlock_irqrestore(&priv
->lock
, flags
);
3651 #ifdef CONFIG_IWLWIFI_DEBUG
3652 if (priv
->debug_level
& (IWL_DL_ISR
)) {
3653 /* NIC fires this, but we don't use it, redundant with WAKEUP */
3654 if (inta
& CSR_INT_BIT_SCD
)
3655 IWL_DEBUG_ISR("Scheduler finished to transmit "
3656 "the frame/frames.\n");
3658 /* Alive notification via Rx interrupt will do the real work */
3659 if (inta
& CSR_INT_BIT_ALIVE
)
3660 IWL_DEBUG_ISR("Alive interrupt\n");
3663 /* Safely ignore these bits for debug checks below */
3664 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
3666 /* HW RF KILL switch toggled */
3667 if (inta
& CSR_INT_BIT_RF_KILL
) {
3669 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
3670 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
3673 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
3674 "RF_KILL bit toggled to %s.\n",
3675 hw_rf_kill
? "disable radio":"enable radio");
3677 /* Queue restart only if RF_KILL switch was set to "kill"
3678 * when we loaded driver, and is now set to "enable".
3679 * After we're Alive, RF_KILL gets handled by
3680 * iwl4965_rx_card_state_notif() */
3681 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
3682 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3683 queue_work(priv
->workqueue
, &priv
->restart
);
3686 handled
|= CSR_INT_BIT_RF_KILL
;
3689 /* Chip got too hot and stopped itself */
3690 if (inta
& CSR_INT_BIT_CT_KILL
) {
3691 IWL_ERROR("Microcode CT kill error detected.\n");
3692 handled
|= CSR_INT_BIT_CT_KILL
;
3695 /* Error detected by uCode */
3696 if (inta
& CSR_INT_BIT_SW_ERR
) {
3697 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
3699 iwl4965_irq_handle_error(priv
);
3700 handled
|= CSR_INT_BIT_SW_ERR
;
3703 /* uCode wakes up after power-down sleep */
3704 if (inta
& CSR_INT_BIT_WAKEUP
) {
3705 IWL_DEBUG_ISR("Wakeup interrupt\n");
3706 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
3707 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
3708 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
3709 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
3710 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
3711 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
3712 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
3714 handled
|= CSR_INT_BIT_WAKEUP
;
3717 /* All uCode command responses, including Tx command responses,
3718 * Rx "responses" (frame-received notification), and other
3719 * notifications from uCode come through here*/
3720 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
3721 iwl_rx_handle(priv
);
3722 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
3725 if (inta
& CSR_INT_BIT_FH_TX
) {
3726 IWL_DEBUG_ISR("Tx interrupt\n");
3727 handled
|= CSR_INT_BIT_FH_TX
;
3730 if (inta
& ~handled
)
3731 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
3733 if (inta
& ~CSR_INI_SET_MASK
) {
3734 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
3735 inta
& ~CSR_INI_SET_MASK
);
3736 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
3739 /* Re-enable all interrupts */
3740 /* only Re-enable if diabled by irq */
3741 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
3742 iwl4965_enable_interrupts(priv
);
3744 #ifdef CONFIG_IWLWIFI_DEBUG
3745 if (priv
->debug_level
& (IWL_DL_ISR
)) {
3746 inta
= iwl_read32(priv
, CSR_INT
);
3747 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
3748 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
3749 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
3750 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
3753 spin_unlock_irqrestore(&priv
->lock
, flags
);
3756 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
3758 struct iwl_priv
*priv
= data
;
3759 u32 inta
, inta_mask
;
3764 spin_lock(&priv
->lock
);
3766 /* Disable (but don't clear!) interrupts here to avoid
3767 * back-to-back ISRs and sporadic interrupts from our NIC.
3768 * If we have something to service, the tasklet will re-enable ints.
3769 * If we *don't* have something, we'll re-enable before leaving here. */
3770 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
3771 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
3773 /* Discover which interrupts are active/pending */
3774 inta
= iwl_read32(priv
, CSR_INT
);
3775 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
3777 /* Ignore interrupt if there's nothing in NIC to service.
3778 * This may be due to IRQ shared with another device,
3779 * or due to sporadic interrupts thrown from our NIC. */
3780 if (!inta
&& !inta_fh
) {
3781 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
3785 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
3786 /* Hardware disappeared. It might have already raised
3788 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
3792 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
3793 inta
, inta_mask
, inta_fh
);
3795 inta
&= ~CSR_INT_BIT_SCD
;
3797 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
3798 if (likely(inta
|| inta_fh
))
3799 tasklet_schedule(&priv
->irq_tasklet
);
3802 spin_unlock(&priv
->lock
);
3806 /* re-enable interrupts here since we don't have anything to service. */
3807 /* only Re-enable if diabled by irq */
3808 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
3809 iwl4965_enable_interrupts(priv
);
3810 spin_unlock(&priv
->lock
);
3814 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
3815 * sending probe req. This should be set long enough to hear probe responses
3816 * from more than one AP. */
3817 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
3818 #define IWL_ACTIVE_DWELL_TIME_52 (10)
3820 /* For faster active scanning, scan will move to the next channel if fewer than
3821 * PLCP_QUIET_THRESH packets are heard on this channel within
3822 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
3823 * time if it's a quiet channel (nothing responded to our probe, and there's
3824 * no other traffic).
3825 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
3826 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
3827 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
3829 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
3830 * Must be set longer than active dwell time.
3831 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
3832 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
3833 #define IWL_PASSIVE_DWELL_TIME_52 (10)
3834 #define IWL_PASSIVE_DWELL_BASE (100)
3835 #define IWL_CHANNEL_TUNE_TIME 5
3837 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
3838 enum ieee80211_band band
)
3840 if (band
== IEEE80211_BAND_5GHZ
)
3841 return IWL_ACTIVE_DWELL_TIME_52
;
3843 return IWL_ACTIVE_DWELL_TIME_24
;
3846 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
3847 enum ieee80211_band band
)
3849 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
3850 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
3851 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
3852 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
3854 if (iwl_is_associated(priv
)) {
3855 /* If we're associated, we clamp the maximum passive
3856 * dwell time to be 98% of the beacon interval (minus
3857 * 2 * channel tune time) */
3858 passive
= priv
->beacon_int
;
3859 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
3860 passive
= IWL_PASSIVE_DWELL_BASE
;
3861 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
3864 if (passive
<= active
)
3865 passive
= active
+ 1;
3870 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
3871 enum ieee80211_band band
,
3872 u8 is_active
, u8 direct_mask
,
3873 struct iwl4965_scan_channel
*scan_ch
)
3875 const struct ieee80211_channel
*channels
= NULL
;
3876 const struct ieee80211_supported_band
*sband
;
3877 const struct iwl_channel_info
*ch_info
;
3878 u16 passive_dwell
= 0;
3879 u16 active_dwell
= 0;
3882 sband
= iwl_get_hw_mode(priv
, band
);
3886 channels
= sband
->channels
;
3888 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
3889 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
3891 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
3892 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
3895 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
3897 ch_info
= iwl_get_channel_info(priv
, band
,
3899 if (!is_channel_valid(ch_info
)) {
3900 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
3905 if (!is_active
|| is_channel_passive(ch_info
) ||
3906 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
3907 scan_ch
->type
= 0; /* passive */
3909 scan_ch
->type
= 1; /* active */
3911 if (scan_ch
->type
& 1)
3912 scan_ch
->type
|= (direct_mask
<< 1);
3914 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
3915 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
3917 /* Set txpower levels to defaults */
3918 scan_ch
->tpc
.dsp_atten
= 110;
3919 /* scan_pwr_info->tpc.dsp_atten; */
3921 /*scan_pwr_info->tpc.tx_gain; */
3922 if (band
== IEEE80211_BAND_5GHZ
)
3923 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
3925 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
3926 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
3928 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
3932 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
3934 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
3935 (scan_ch
->type
& 1) ?
3936 active_dwell
: passive_dwell
);
3942 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
3946 /******************************************************************************
3948 * uCode download functions
3950 ******************************************************************************/
3952 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
3954 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
3955 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
3956 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
3957 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
3958 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
3959 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
3962 static void iwl4965_nic_start(struct iwl_priv
*priv
)
3964 /* Remove all resets to allow NIC to operate */
3965 iwl_write32(priv
, CSR_RESET
, 0);
3970 * iwl4965_read_ucode - Read uCode images from disk file.
3972 * Copy into buffers for card to fetch via bus-mastering
3974 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
3976 struct iwl4965_ucode
*ucode
;
3978 const struct firmware
*ucode_raw
;
3979 const char *name
= priv
->cfg
->fw_name
;
3982 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
3984 /* Ask kernel firmware_class module to get the boot firmware off disk.
3985 * request_firmware() is synchronous, file is in memory on return. */
3986 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
3988 IWL_ERROR("%s firmware file req failed: Reason %d\n",
3993 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
3994 name
, ucode_raw
->size
);
3996 /* Make sure that we got at least our header! */
3997 if (ucode_raw
->size
< sizeof(*ucode
)) {
3998 IWL_ERROR("File size way too small!\n");
4003 /* Data from ucode file: header followed by uCode images */
4004 ucode
= (void *)ucode_raw
->data
;
4006 ver
= le32_to_cpu(ucode
->ver
);
4007 inst_size
= le32_to_cpu(ucode
->inst_size
);
4008 data_size
= le32_to_cpu(ucode
->data_size
);
4009 init_size
= le32_to_cpu(ucode
->init_size
);
4010 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
4011 boot_size
= le32_to_cpu(ucode
->boot_size
);
4013 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
4014 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
4016 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
4018 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
4020 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
4022 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
4025 /* Verify size of file vs. image size info in file's header */
4026 if (ucode_raw
->size
< sizeof(*ucode
) +
4027 inst_size
+ data_size
+ init_size
+
4028 init_data_size
+ boot_size
) {
4030 IWL_DEBUG_INFO("uCode file size %d too small\n",
4031 (int)ucode_raw
->size
);
4036 /* Verify that uCode images will fit in card's SRAM */
4037 if (inst_size
> priv
->hw_params
.max_inst_size
) {
4038 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
4044 if (data_size
> priv
->hw_params
.max_data_size
) {
4045 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
4050 if (init_size
> priv
->hw_params
.max_inst_size
) {
4052 ("uCode init instr len %d too large to fit in\n",
4057 if (init_data_size
> priv
->hw_params
.max_data_size
) {
4059 ("uCode init data len %d too large to fit in\n",
4064 if (boot_size
> priv
->hw_params
.max_bsm_size
) {
4066 ("uCode boot instr len %d too large to fit in\n",
4072 /* Allocate ucode buffers for card's bus-master loading ... */
4074 /* Runtime instructions and 2 copies of data:
4075 * 1) unmodified from disk
4076 * 2) backup cache for save/restore during power-downs */
4077 priv
->ucode_code
.len
= inst_size
;
4078 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4080 priv
->ucode_data
.len
= data_size
;
4081 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4083 priv
->ucode_data_backup
.len
= data_size
;
4084 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4086 /* Initialization instructions and data */
4087 if (init_size
&& init_data_size
) {
4088 priv
->ucode_init
.len
= init_size
;
4089 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4091 priv
->ucode_init_data
.len
= init_data_size
;
4092 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4094 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
4098 /* Bootstrap (instructions only, no data) */
4100 priv
->ucode_boot
.len
= boot_size
;
4101 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4103 if (!priv
->ucode_boot
.v_addr
)
4107 /* Copy images into buffers for card's bus-master reads ... */
4109 /* Runtime instructions (first block of data in file) */
4110 src
= &ucode
->data
[0];
4111 len
= priv
->ucode_code
.len
;
4112 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
4113 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
4114 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
4115 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
4117 /* Runtime data (2nd block)
4118 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
4119 src
= &ucode
->data
[inst_size
];
4120 len
= priv
->ucode_data
.len
;
4121 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
4122 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
4123 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
4125 /* Initialization instructions (3rd block) */
4127 src
= &ucode
->data
[inst_size
+ data_size
];
4128 len
= priv
->ucode_init
.len
;
4129 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
4131 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
4134 /* Initialization data (4th block) */
4135 if (init_data_size
) {
4136 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
4137 len
= priv
->ucode_init_data
.len
;
4138 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
4140 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
4143 /* Bootstrap instructions (5th block) */
4144 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
4145 len
= priv
->ucode_boot
.len
;
4146 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
4147 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
4149 /* We have our copies now, allow OS release its copies */
4150 release_firmware(ucode_raw
);
4154 IWL_ERROR("failed to allocate pci memory\n");
4156 iwl4965_dealloc_ucode_pci(priv
);
4159 release_firmware(ucode_raw
);
4166 * iwl4965_alive_start - called after REPLY_ALIVE notification received
4167 * from protocol/runtime uCode (initialization uCode's
4168 * Alive gets handled by iwl4965_init_alive_start()).
4170 static void iwl4965_alive_start(struct iwl_priv
*priv
)
4174 IWL_DEBUG_INFO("Runtime Alive received.\n");
4176 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
4177 /* We had an error bringing up the hardware, so take it
4178 * all the way back down so we can try again */
4179 IWL_DEBUG_INFO("Alive failed.\n");
4183 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
4184 * This is a paranoid check, because we would not have gotten the
4185 * "runtime" alive if code weren't properly loaded. */
4186 if (iwl_verify_ucode(priv
)) {
4187 /* Runtime instruction load was bad;
4188 * take it all the way back down so we can try again */
4189 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
4193 iwlcore_clear_stations_table(priv
);
4195 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
4197 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
4202 /* After the ALIVE response, we can send host commands to 4965 uCode */
4203 set_bit(STATUS_ALIVE
, &priv
->status
);
4205 /* Clear out the uCode error bit if it is set */
4206 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
4208 if (iwl_is_rfkill(priv
))
4211 ieee80211_start_queues(priv
->hw
);
4213 priv
->active_rate
= priv
->rates_mask
;
4214 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
4216 if (iwl_is_associated(priv
)) {
4217 struct iwl4965_rxon_cmd
*active_rxon
=
4218 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
4220 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
4221 sizeof(priv
->staging_rxon
));
4222 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4224 /* Initialize our rx_config data */
4225 iwl4965_connection_init_rx_config(priv
);
4226 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
4229 /* Configure Bluetooth device coexistence support */
4230 iwl4965_send_bt_config(priv
);
4232 /* Configure the adapter for unassociated operation */
4233 iwl4965_commit_rxon(priv
);
4235 /* At this point, the NIC is initialized and operational */
4236 priv
->notif_missed_beacons
= 0;
4238 iwl4965_rf_kill_ct_config(priv
);
4240 iwl_leds_register(priv
);
4242 IWL_DEBUG_INFO("ALIVE processing complete.\n");
4243 set_bit(STATUS_READY
, &priv
->status
);
4244 wake_up_interruptible(&priv
->wait_command_queue
);
4246 if (priv
->error_recovering
)
4247 iwl4965_error_recovery(priv
);
4249 iwlcore_low_level_notify(priv
, IWLCORE_START_EVT
);
4250 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
4254 queue_work(priv
->workqueue
, &priv
->restart
);
4257 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
4259 static void __iwl4965_down(struct iwl_priv
*priv
)
4261 unsigned long flags
;
4262 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4263 struct ieee80211_conf
*conf
= NULL
;
4265 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
4267 conf
= ieee80211_get_hw_conf(priv
->hw
);
4270 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4272 iwl_leds_unregister(priv
);
4274 iwlcore_low_level_notify(priv
, IWLCORE_STOP_EVT
);
4276 iwlcore_clear_stations_table(priv
);
4278 /* Unblock any waiting calls */
4279 wake_up_interruptible_all(&priv
->wait_command_queue
);
4281 /* Wipe out the EXIT_PENDING status bit if we are not actually
4282 * exiting the module */
4284 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4286 /* stop and reset the on-board processor */
4287 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
4289 /* tell the device to stop sending interrupts */
4290 spin_lock_irqsave(&priv
->lock
, flags
);
4291 iwl4965_disable_interrupts(priv
);
4292 spin_unlock_irqrestore(&priv
->lock
, flags
);
4293 iwl_synchronize_irq(priv
);
4295 if (priv
->mac80211_registered
)
4296 ieee80211_stop_queues(priv
->hw
);
4298 /* If we have not previously called iwl4965_init() then
4299 * clear all bits but the RF Kill and SUSPEND bits and return */
4300 if (!iwl_is_init(priv
)) {
4301 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
4303 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
4305 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
4306 STATUS_GEO_CONFIGURED
|
4307 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
4312 /* ...otherwise clear out all the status bits but the RF Kill and
4313 * SUSPEND bits and continue taking the NIC down. */
4314 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
4316 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
4318 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
4319 STATUS_GEO_CONFIGURED
|
4320 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
4322 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
4325 spin_lock_irqsave(&priv
->lock
, flags
);
4326 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
4327 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4328 spin_unlock_irqrestore(&priv
->lock
, flags
);
4330 iwl4965_hw_txq_ctx_stop(priv
);
4331 iwl4965_hw_rxq_stop(priv
);
4333 spin_lock_irqsave(&priv
->lock
, flags
);
4334 if (!iwl_grab_nic_access(priv
)) {
4335 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
4336 APMG_CLK_VAL_DMA_CLK_RQT
);
4337 iwl_release_nic_access(priv
);
4339 spin_unlock_irqrestore(&priv
->lock
, flags
);
4343 iwl4965_hw_nic_stop_master(priv
);
4344 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
4345 iwl4965_hw_nic_reset(priv
);
4346 priv
->cfg
->ops
->lib
->free_shared_mem(priv
);
4349 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
4351 if (priv
->ibss_beacon
)
4352 dev_kfree_skb(priv
->ibss_beacon
);
4353 priv
->ibss_beacon
= NULL
;
4355 /* clear out any free frames */
4356 iwl4965_clear_free_frames(priv
);
4359 static void iwl4965_down(struct iwl_priv
*priv
)
4361 mutex_lock(&priv
->mutex
);
4362 __iwl4965_down(priv
);
4363 mutex_unlock(&priv
->mutex
);
4365 iwl4965_cancel_deferred_work(priv
);
4368 #define MAX_HW_RESTARTS 5
4370 static int __iwl4965_up(struct iwl_priv
*priv
)
4375 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4376 IWL_WARNING("Exit pending; will not bring the NIC up\n");
4380 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
4381 IWL_WARNING("Radio disabled by SW RF kill (module "
4383 iwl_rfkill_set_hw_state(priv
);
4387 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
4388 IWL_ERROR("ucode not available for device bringup\n");
4392 /* If platform's RF_KILL switch is NOT set to KILL */
4393 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
4394 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
4395 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4397 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4398 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
4399 iwl_rfkill_set_hw_state(priv
);
4400 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
4405 iwl_rfkill_set_hw_state(priv
);
4406 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
4408 ret
= priv
->cfg
->ops
->lib
->alloc_shared_mem(priv
);
4410 IWL_ERROR("Unable to allocate shared memory\n");
4414 ret
= iwl_hw_nic_init(priv
);
4416 IWL_ERROR("Unable to init nic\n");
4420 /* make sure rfkill handshake bits are cleared */
4421 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
4422 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
4423 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
4425 /* clear (again), then enable host interrupts */
4426 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
4427 iwl4965_enable_interrupts(priv
);
4429 /* really make sure rfkill handshake bits are cleared */
4430 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
4431 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
4433 /* Copy original ucode data image from disk into backup cache.
4434 * This will be used to initialize the on-board processor's
4435 * data SRAM for a clean start when the runtime program first loads. */
4436 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
4437 priv
->ucode_data
.len
);
4439 /* We return success when we resume from suspend and rf_kill is on. */
4440 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
4443 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
4445 iwlcore_clear_stations_table(priv
);
4447 /* load bootstrap state machine,
4448 * load bootstrap program into processor's memory,
4449 * prepare to load the "initialize" uCode */
4450 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
4453 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
4457 /* start card; "initialize" will load runtime ucode */
4458 iwl4965_nic_start(priv
);
4460 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
4465 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
4466 __iwl4965_down(priv
);
4468 /* tried to restart and config the device for as long as our
4469 * patience could withstand */
4470 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
4475 /*****************************************************************************
4477 * Workqueue callbacks
4479 *****************************************************************************/
4481 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
4483 struct iwl_priv
*priv
=
4484 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
4486 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4489 mutex_lock(&priv
->mutex
);
4490 priv
->cfg
->ops
->lib
->init_alive_start(priv
);
4491 mutex_unlock(&priv
->mutex
);
4494 static void iwl4965_bg_alive_start(struct work_struct
*data
)
4496 struct iwl_priv
*priv
=
4497 container_of(data
, struct iwl_priv
, alive_start
.work
);
4499 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4502 mutex_lock(&priv
->mutex
);
4503 iwl4965_alive_start(priv
);
4504 mutex_unlock(&priv
->mutex
);
4507 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
4509 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
4511 wake_up_interruptible(&priv
->wait_command_queue
);
4513 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4516 mutex_lock(&priv
->mutex
);
4518 if (!iwl_is_rfkill(priv
)) {
4519 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
4520 "HW and/or SW RF Kill no longer active, restarting "
4522 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4523 queue_work(priv
->workqueue
, &priv
->restart
);
4525 /* make sure mac80211 stop sending Tx frame */
4526 if (priv
->mac80211_registered
)
4527 ieee80211_stop_queues(priv
->hw
);
4529 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
4530 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
4531 "disabled by SW switch\n");
4533 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
4534 "Kill switch must be turned off for "
4535 "wireless networking to work.\n");
4537 iwl_rfkill_set_hw_state(priv
);
4539 mutex_unlock(&priv
->mutex
);
4542 static void iwl4965_bg_set_monitor(struct work_struct
*work
)
4544 struct iwl_priv
*priv
= container_of(work
,
4545 struct iwl_priv
, set_monitor
);
4547 IWL_DEBUG(IWL_DL_STATE
, "setting monitor mode\n");
4549 mutex_lock(&priv
->mutex
);
4551 if (!iwl_is_ready(priv
))
4552 IWL_DEBUG(IWL_DL_STATE
, "leave - not ready\n");
4554 if (iwl4965_set_mode(priv
, IEEE80211_IF_TYPE_MNTR
) != 0)
4555 IWL_ERROR("iwl4965_set_mode() failed\n");
4557 mutex_unlock(&priv
->mutex
);
4560 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
4562 static void iwl4965_bg_scan_check(struct work_struct
*data
)
4564 struct iwl_priv
*priv
=
4565 container_of(data
, struct iwl_priv
, scan_check
.work
);
4567 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4570 mutex_lock(&priv
->mutex
);
4571 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
4572 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
4573 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
4574 "Scan completion watchdog resetting adapter (%dms)\n",
4575 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
4577 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4578 iwl4965_send_scan_abort(priv
);
4580 mutex_unlock(&priv
->mutex
);
4583 static void iwl4965_bg_request_scan(struct work_struct
*data
)
4585 struct iwl_priv
*priv
=
4586 container_of(data
, struct iwl_priv
, request_scan
);
4587 struct iwl_host_cmd cmd
= {
4588 .id
= REPLY_SCAN_CMD
,
4589 .len
= sizeof(struct iwl4965_scan_cmd
),
4590 .meta
.flags
= CMD_SIZE_HUGE
,
4592 struct iwl4965_scan_cmd
*scan
;
4593 struct ieee80211_conf
*conf
= NULL
;
4595 enum ieee80211_band band
;
4599 conf
= ieee80211_get_hw_conf(priv
->hw
);
4601 mutex_lock(&priv
->mutex
);
4603 if (!iwl_is_ready(priv
)) {
4604 IWL_WARNING("request scan called when driver not ready.\n");
4608 /* Make sure the scan wasn't cancelled before this queued work
4609 * was given the chance to run... */
4610 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
4613 /* This should never be called or scheduled if there is currently
4614 * a scan active in the hardware. */
4615 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
4616 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
4617 "Ignoring second request.\n");
4622 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4623 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
4627 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
4628 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
4632 if (iwl_is_rfkill(priv
)) {
4633 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
4637 if (!test_bit(STATUS_READY
, &priv
->status
)) {
4638 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
4642 if (!priv
->scan_bands
) {
4643 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
4648 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
4649 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
4656 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
4658 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
4659 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
4661 if (iwl_is_associated(priv
)) {
4664 u32 suspend_time
= 100;
4665 u32 scan_suspend_time
= 100;
4666 unsigned long flags
;
4668 IWL_DEBUG_INFO("Scanning while associated...\n");
4670 spin_lock_irqsave(&priv
->lock
, flags
);
4671 interval
= priv
->beacon_int
;
4672 spin_unlock_irqrestore(&priv
->lock
, flags
);
4674 scan
->suspend_time
= 0;
4675 scan
->max_out_time
= cpu_to_le32(200 * 1024);
4677 interval
= suspend_time
;
4679 extra
= (suspend_time
/ interval
) << 22;
4680 scan_suspend_time
= (extra
|
4681 ((suspend_time
% interval
) * 1024));
4682 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
4683 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
4684 scan_suspend_time
, interval
);
4687 /* We should add the ability for user to lock to PASSIVE ONLY */
4688 if (priv
->one_direct_scan
) {
4690 ("Kicking off one direct scan for '%s'\n",
4691 iwl4965_escape_essid(priv
->direct_ssid
,
4692 priv
->direct_ssid_len
));
4693 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
4694 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
4695 memcpy(scan
->direct_scan
[0].ssid
,
4696 priv
->direct_ssid
, priv
->direct_ssid_len
);
4698 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
4700 ("Kicking off one direct scan for '%s' when not associated\n",
4701 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
4702 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
4703 scan
->direct_scan
[0].len
= priv
->essid_len
;
4704 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
4707 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
4711 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
4712 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
4713 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
4716 switch (priv
->scan_bands
) {
4718 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
4719 scan
->tx_cmd
.rate_n_flags
=
4720 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
4721 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
4723 scan
->good_CRC_th
= 0;
4724 band
= IEEE80211_BAND_2GHZ
;
4728 scan
->tx_cmd
.rate_n_flags
=
4729 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
4730 RATE_MCS_ANT_B_MSK
);
4731 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
4732 band
= IEEE80211_BAND_5GHZ
;
4736 IWL_WARNING("Invalid scan band count\n");
4740 /* We don't build a direct scan probe request; the uCode will do
4741 * that based on the direct_mask added to each channel entry */
4742 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
4743 (struct ieee80211_mgmt
*)scan
->data
,
4744 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
4746 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
4747 /* select Rx chains */
4749 /* Force use of chains B and C (0x6) for scan Rx.
4750 * Avoid A (0x1) because of its off-channel reception on A-band.
4751 * MIMO is not used here, but value is required to make uCode happy. */
4752 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
4753 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
4754 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
4755 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
4757 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
4758 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
4761 scan
->channel_count
=
4762 iwl4965_get_channels_for_scan(
4763 priv
, band
, 1, /* active */
4765 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
4767 scan
->channel_count
=
4768 iwl4965_get_channels_for_scan(
4769 priv
, band
, 0, /* passive */
4771 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
4773 scan
->filter_flags
|= (RXON_FILTER_ACCEPT_GRP_MSK
|
4774 RXON_FILTER_BCON_AWARE_MSK
);
4775 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
4776 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
4778 scan
->len
= cpu_to_le16(cmd
.len
);
4780 set_bit(STATUS_SCAN_HW
, &priv
->status
);
4781 ret
= iwl_send_cmd_sync(priv
, &cmd
);
4785 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
4786 IWL_SCAN_CHECK_WATCHDOG
);
4788 mutex_unlock(&priv
->mutex
);
4792 /* inform mac80211 scan aborted */
4793 queue_work(priv
->workqueue
, &priv
->scan_completed
);
4794 mutex_unlock(&priv
->mutex
);
4797 static void iwl4965_bg_up(struct work_struct
*data
)
4799 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
4801 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4804 mutex_lock(&priv
->mutex
);
4806 mutex_unlock(&priv
->mutex
);
4809 static void iwl4965_bg_restart(struct work_struct
*data
)
4811 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
4813 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4817 queue_work(priv
->workqueue
, &priv
->up
);
4820 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
4822 struct iwl_priv
*priv
=
4823 container_of(data
, struct iwl_priv
, rx_replenish
);
4825 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4828 mutex_lock(&priv
->mutex
);
4829 iwl_rx_replenish(priv
);
4830 mutex_unlock(&priv
->mutex
);
4833 #define IWL_DELAY_NEXT_SCAN (HZ*2)
4835 static void iwl4965_post_associate(struct iwl_priv
*priv
)
4837 struct ieee80211_conf
*conf
= NULL
;
4839 DECLARE_MAC_BUF(mac
);
4841 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
4842 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
4846 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
4848 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
4851 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4855 if (!priv
->vif
|| !priv
->is_open
)
4858 iwl4965_scan_cancel_timeout(priv
, 200);
4860 conf
= ieee80211_get_hw_conf(priv
->hw
);
4862 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4863 iwl4965_commit_rxon(priv
);
4865 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
4866 iwl4965_setup_rxon_timing(priv
);
4867 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
4868 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
4870 IWL_WARNING("REPLY_RXON_TIMING failed - "
4871 "Attempting to continue.\n");
4873 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
4875 #ifdef CONFIG_IWL4965_HT
4876 if (priv
->current_ht_config
.is_ht
)
4877 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
4878 #endif /* CONFIG_IWL4965_HT*/
4879 iwl_set_rxon_chain(priv
);
4880 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
4882 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
4883 priv
->assoc_id
, priv
->beacon_int
);
4885 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
4886 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
4888 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
4890 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
4891 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
4892 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
4894 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
4896 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
4897 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
4901 iwl4965_commit_rxon(priv
);
4903 switch (priv
->iw_mode
) {
4904 case IEEE80211_IF_TYPE_STA
:
4905 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
4908 case IEEE80211_IF_TYPE_IBSS
:
4910 /* clear out the station table */
4911 iwlcore_clear_stations_table(priv
);
4913 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
4914 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
4915 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
4916 iwl4965_send_beacon_cmd(priv
);
4921 IWL_ERROR("%s Should not be called in %d mode\n",
4922 __FUNCTION__
, priv
->iw_mode
);
4926 iwl4965_sequence_reset(priv
);
4928 /* Enable Rx differential gain and sensitivity calibrations */
4929 iwl_chain_noise_reset(priv
);
4930 priv
->start_calib
= 1;
4932 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
4933 priv
->assoc_station_added
= 1;
4935 iwl4965_activate_qos(priv
, 0);
4937 iwl_power_update_mode(priv
, 0);
4938 /* we have just associated, don't start scan too early */
4939 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
4943 static void iwl4965_bg_post_associate(struct work_struct
*data
)
4945 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
4946 post_associate
.work
);
4948 mutex_lock(&priv
->mutex
);
4949 iwl4965_post_associate(priv
);
4950 mutex_unlock(&priv
->mutex
);
4954 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
4956 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
4958 if (!iwl_is_ready(priv
))
4961 mutex_lock(&priv
->mutex
);
4963 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
4964 iwl4965_send_scan_abort(priv
);
4966 mutex_unlock(&priv
->mutex
);
4969 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
4971 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
4973 struct iwl_priv
*priv
=
4974 container_of(work
, struct iwl_priv
, scan_completed
);
4976 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
4978 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
4981 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
4982 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
4984 ieee80211_scan_completed(priv
->hw
);
4986 /* Since setting the TXPOWER may have been deferred while
4987 * performing the scan, fire one off */
4988 mutex_lock(&priv
->mutex
);
4989 iwl4965_hw_reg_send_txpower(priv
);
4990 mutex_unlock(&priv
->mutex
);
4993 /*****************************************************************************
4995 * mac80211 entry point functions
4997 *****************************************************************************/
4999 #define UCODE_READY_TIMEOUT (2 * HZ)
5001 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
5003 struct iwl_priv
*priv
= hw
->priv
;
5006 IWL_DEBUG_MAC80211("enter\n");
5008 if (pci_enable_device(priv
->pci_dev
)) {
5009 IWL_ERROR("Fail to pci_enable_device\n");
5012 pci_restore_state(priv
->pci_dev
);
5013 pci_enable_msi(priv
->pci_dev
);
5015 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
5018 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
5019 goto out_disable_msi
;
5022 /* we should be verifying the device is ready to be opened */
5023 mutex_lock(&priv
->mutex
);
5025 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
5026 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
5027 * ucode filename and max sizes are card-specific. */
5029 if (!priv
->ucode_code
.len
) {
5030 ret
= iwl4965_read_ucode(priv
);
5032 IWL_ERROR("Could not read microcode: %d\n", ret
);
5033 mutex_unlock(&priv
->mutex
);
5034 goto out_release_irq
;
5038 ret
= __iwl4965_up(priv
);
5040 mutex_unlock(&priv
->mutex
);
5043 goto out_release_irq
;
5045 IWL_DEBUG_INFO("Start UP work done.\n");
5047 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
5050 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
5051 * mac80211 will not be run successfully. */
5052 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
5053 test_bit(STATUS_READY
, &priv
->status
),
5054 UCODE_READY_TIMEOUT
);
5056 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5057 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
5058 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
5060 goto out_release_irq
;
5065 IWL_DEBUG_MAC80211("leave\n");
5069 free_irq(priv
->pci_dev
->irq
, priv
);
5071 pci_disable_msi(priv
->pci_dev
);
5072 pci_disable_device(priv
->pci_dev
);
5074 IWL_DEBUG_MAC80211("leave - failed\n");
5078 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
5080 struct iwl_priv
*priv
= hw
->priv
;
5082 IWL_DEBUG_MAC80211("enter\n");
5084 if (!priv
->is_open
) {
5085 IWL_DEBUG_MAC80211("leave - skip\n");
5091 if (iwl_is_ready_rf(priv
)) {
5092 /* stop mac, cancel any scan request and clear
5093 * RXON_FILTER_ASSOC_MSK BIT
5095 mutex_lock(&priv
->mutex
);
5096 iwl4965_scan_cancel_timeout(priv
, 100);
5097 cancel_delayed_work(&priv
->post_associate
);
5098 mutex_unlock(&priv
->mutex
);
5103 flush_workqueue(priv
->workqueue
);
5104 free_irq(priv
->pci_dev
->irq
, priv
);
5105 pci_disable_msi(priv
->pci_dev
);
5106 pci_save_state(priv
->pci_dev
);
5107 pci_disable_device(priv
->pci_dev
);
5109 IWL_DEBUG_MAC80211("leave\n");
5112 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
5113 struct ieee80211_tx_control
*ctl
)
5115 struct iwl_priv
*priv
= hw
->priv
;
5117 IWL_DEBUG_MAC80211("enter\n");
5119 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
5120 IWL_DEBUG_MAC80211("leave - monitor\n");
5124 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
5125 ctl
->tx_rate
->bitrate
);
5127 if (iwl4965_tx_skb(priv
, skb
, ctl
))
5128 dev_kfree_skb_any(skb
);
5130 IWL_DEBUG_MAC80211("leave\n");
5134 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
5135 struct ieee80211_if_init_conf
*conf
)
5137 struct iwl_priv
*priv
= hw
->priv
;
5138 unsigned long flags
;
5139 DECLARE_MAC_BUF(mac
);
5141 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
5144 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
5148 spin_lock_irqsave(&priv
->lock
, flags
);
5149 priv
->vif
= conf
->vif
;
5151 spin_unlock_irqrestore(&priv
->lock
, flags
);
5153 mutex_lock(&priv
->mutex
);
5155 if (conf
->mac_addr
) {
5156 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
5157 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
5160 if (iwl_is_ready(priv
))
5161 iwl4965_set_mode(priv
, conf
->type
);
5163 mutex_unlock(&priv
->mutex
);
5165 IWL_DEBUG_MAC80211("leave\n");
5170 * iwl4965_mac_config - mac80211 config callback
5172 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
5173 * be set inappropriately and the driver currently sets the hardware up to
5174 * use it whenever needed.
5176 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
5178 struct iwl_priv
*priv
= hw
->priv
;
5179 const struct iwl_channel_info
*ch_info
;
5180 unsigned long flags
;
5183 mutex_lock(&priv
->mutex
);
5184 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
5186 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
5188 if (!iwl_is_ready(priv
)) {
5189 IWL_DEBUG_MAC80211("leave - not ready\n");
5194 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
5195 test_bit(STATUS_SCANNING
, &priv
->status
))) {
5196 IWL_DEBUG_MAC80211("leave - scanning\n");
5197 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
5198 mutex_unlock(&priv
->mutex
);
5202 spin_lock_irqsave(&priv
->lock
, flags
);
5204 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
,
5205 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
5206 if (!is_channel_valid(ch_info
)) {
5207 IWL_DEBUG_MAC80211("leave - invalid channel\n");
5208 spin_unlock_irqrestore(&priv
->lock
, flags
);
5213 #ifdef CONFIG_IWL4965_HT
5214 /* if we are switching from ht to 2.4 clear flags
5215 * from any ht related info since 2.4 does not
5217 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
->hw_value
)
5218 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
5219 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
5222 priv
->staging_rxon
.flags
= 0;
5223 #endif /* CONFIG_IWL4965_HT */
5225 iwl_set_rxon_channel(priv
, conf
->channel
->band
,
5226 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
5228 iwl4965_set_flags_for_phymode(priv
, conf
->channel
->band
);
5230 /* The list of supported rates and rate mask can be different
5231 * for each band; since the band may have changed, reset
5232 * the rate mask to what mac80211 lists */
5233 iwl4965_set_rate(priv
);
5235 spin_unlock_irqrestore(&priv
->lock
, flags
);
5237 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
5238 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
5239 iwl4965_hw_channel_switch(priv
, conf
->channel
);
5244 if (priv
->cfg
->ops
->lib
->radio_kill_sw
)
5245 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, !conf
->radio_enabled
);
5247 if (!conf
->radio_enabled
) {
5248 IWL_DEBUG_MAC80211("leave - radio disabled\n");
5252 if (iwl_is_rfkill(priv
)) {
5253 IWL_DEBUG_MAC80211("leave - RF kill\n");
5258 iwl4965_set_rate(priv
);
5260 if (memcmp(&priv
->active_rxon
,
5261 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
5262 iwl4965_commit_rxon(priv
);
5264 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
5266 IWL_DEBUG_MAC80211("leave\n");
5269 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
5270 mutex_unlock(&priv
->mutex
);
5274 static void iwl4965_config_ap(struct iwl_priv
*priv
)
5278 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5281 /* The following should be done only at AP bring up */
5282 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
5284 /* RXON - unassoc (to set timing command) */
5285 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5286 iwl4965_commit_rxon(priv
);
5289 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
5290 iwl4965_setup_rxon_timing(priv
);
5291 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
5292 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
5294 IWL_WARNING("REPLY_RXON_TIMING failed - "
5295 "Attempting to continue.\n");
5297 iwl_set_rxon_chain(priv
);
5299 /* FIXME: what should be the assoc_id for AP? */
5300 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
5301 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
5302 priv
->staging_rxon
.flags
|=
5303 RXON_FLG_SHORT_PREAMBLE_MSK
;
5305 priv
->staging_rxon
.flags
&=
5306 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5308 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
5309 if (priv
->assoc_capability
&
5310 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
5311 priv
->staging_rxon
.flags
|=
5312 RXON_FLG_SHORT_SLOT_MSK
;
5314 priv
->staging_rxon
.flags
&=
5315 ~RXON_FLG_SHORT_SLOT_MSK
;
5317 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
5318 priv
->staging_rxon
.flags
&=
5319 ~RXON_FLG_SHORT_SLOT_MSK
;
5321 /* restore RXON assoc */
5322 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
5323 iwl4965_commit_rxon(priv
);
5324 iwl4965_activate_qos(priv
, 1);
5325 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
5327 iwl4965_send_beacon_cmd(priv
);
5329 /* FIXME - we need to add code here to detect a totally new
5330 * configuration, reset the AP, unassoc, rxon timing, assoc,
5331 * clear sta table, add BCAST sta... */
5334 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
5335 struct ieee80211_vif
*vif
,
5336 struct ieee80211_if_conf
*conf
)
5338 struct iwl_priv
*priv
= hw
->priv
;
5339 DECLARE_MAC_BUF(mac
);
5340 unsigned long flags
;
5346 if (priv
->vif
!= vif
) {
5347 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
5351 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
5352 (!conf
->beacon
|| !conf
->ssid_len
)) {
5354 ("Leaving in AP mode because HostAPD is not ready.\n");
5358 if (!iwl_is_alive(priv
))
5361 mutex_lock(&priv
->mutex
);
5364 IWL_DEBUG_MAC80211("bssid: %s\n",
5365 print_mac(mac
, conf
->bssid
));
5368 * very dubious code was here; the probe filtering flag is never set:
5370 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
5371 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
5374 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
5376 conf
->bssid
= priv
->mac_addr
;
5377 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
5378 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
5379 print_mac(mac
, conf
->bssid
));
5381 if (priv
->ibss_beacon
)
5382 dev_kfree_skb(priv
->ibss_beacon
);
5384 priv
->ibss_beacon
= conf
->beacon
;
5387 if (iwl_is_rfkill(priv
))
5390 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
5391 !is_multicast_ether_addr(conf
->bssid
)) {
5392 /* If there is currently a HW scan going on in the background
5393 * then we need to cancel it else the RXON below will fail. */
5394 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
5395 IWL_WARNING("Aborted scan still in progress "
5397 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
5398 mutex_unlock(&priv
->mutex
);
5401 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
5403 /* TODO: Audit driver for usage of these members and see
5404 * if mac80211 deprecates them (priv->bssid looks like it
5405 * shouldn't be there, but I haven't scanned the IBSS code
5406 * to verify) - jpk */
5407 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
5409 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
5410 iwl4965_config_ap(priv
);
5412 rc
= iwl4965_commit_rxon(priv
);
5413 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
5414 iwl4965_rxon_add_station(
5415 priv
, priv
->active_rxon
.bssid_addr
, 1);
5419 iwl4965_scan_cancel_timeout(priv
, 100);
5420 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5421 iwl4965_commit_rxon(priv
);
5425 spin_lock_irqsave(&priv
->lock
, flags
);
5426 if (!conf
->ssid_len
)
5427 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
5429 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
5431 priv
->essid_len
= conf
->ssid_len
;
5432 spin_unlock_irqrestore(&priv
->lock
, flags
);
5434 IWL_DEBUG_MAC80211("leave\n");
5435 mutex_unlock(&priv
->mutex
);
5440 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
5441 unsigned int changed_flags
,
5442 unsigned int *total_flags
,
5443 int mc_count
, struct dev_addr_list
*mc_list
)
5447 * see also iwl4965_connection_init_rx_config
5449 struct iwl_priv
*priv
= hw
->priv
;
5451 if (changed_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
)) {
5452 if (*total_flags
& (FIF_PROMISC_IN_BSS
| FIF_OTHER_BSS
)) {
5453 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
5454 IEEE80211_IF_TYPE_MNTR
,
5455 changed_flags
, *total_flags
);
5456 /* queue work 'cuz mac80211 is holding a lock which
5457 * prevents us from issuing (synchronous) f/w cmds */
5458 queue_work(priv
->workqueue
, &priv
->set_monitor
);
5459 new_flags
&= FIF_PROMISC_IN_BSS
|
5464 *total_flags
= new_flags
;
5467 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
5468 struct ieee80211_if_init_conf
*conf
)
5470 struct iwl_priv
*priv
= hw
->priv
;
5472 IWL_DEBUG_MAC80211("enter\n");
5474 mutex_lock(&priv
->mutex
);
5476 if (iwl_is_ready_rf(priv
)) {
5477 iwl4965_scan_cancel_timeout(priv
, 100);
5478 cancel_delayed_work(&priv
->post_associate
);
5479 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5480 iwl4965_commit_rxon(priv
);
5482 if (priv
->vif
== conf
->vif
) {
5484 memset(priv
->bssid
, 0, ETH_ALEN
);
5485 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
5486 priv
->essid_len
= 0;
5488 mutex_unlock(&priv
->mutex
);
5490 IWL_DEBUG_MAC80211("leave\n");
5494 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
5495 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
5496 struct ieee80211_vif
*vif
,
5497 struct ieee80211_bss_conf
*bss_conf
,
5500 struct iwl_priv
*priv
= hw
->priv
;
5502 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
5504 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
5505 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
5506 bss_conf
->use_short_preamble
);
5507 if (bss_conf
->use_short_preamble
)
5508 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
5510 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
5513 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
5514 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
5515 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
5516 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
5518 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
5521 if (changes
& BSS_CHANGED_HT
) {
5522 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
5523 iwl4965_ht_conf(priv
, bss_conf
);
5524 iwl_set_rxon_chain(priv
);
5527 if (changes
& BSS_CHANGED_ASSOC
) {
5528 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
5529 /* This should never happen as this function should
5530 * never be called from interrupt context. */
5531 if (WARN_ON_ONCE(in_interrupt()))
5533 if (bss_conf
->assoc
) {
5534 priv
->assoc_id
= bss_conf
->aid
;
5535 priv
->beacon_int
= bss_conf
->beacon_int
;
5536 priv
->timestamp
= bss_conf
->timestamp
;
5537 priv
->assoc_capability
= bss_conf
->assoc_capability
;
5538 priv
->next_scan_jiffies
= jiffies
+
5539 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
5540 mutex_lock(&priv
->mutex
);
5541 iwl4965_post_associate(priv
);
5542 mutex_unlock(&priv
->mutex
);
5545 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
5547 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
5548 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
5549 iwl_send_rxon_assoc(priv
);
5554 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
5557 unsigned long flags
;
5558 struct iwl_priv
*priv
= hw
->priv
;
5560 IWL_DEBUG_MAC80211("enter\n");
5562 mutex_lock(&priv
->mutex
);
5563 spin_lock_irqsave(&priv
->lock
, flags
);
5565 if (!iwl_is_ready_rf(priv
)) {
5567 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
5571 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
5573 IWL_ERROR("ERROR: APs don't scan\n");
5577 /* we don't schedule scan within next_scan_jiffies period */
5578 if (priv
->next_scan_jiffies
&&
5579 time_after(priv
->next_scan_jiffies
, jiffies
)) {
5583 /* if we just finished scan ask for delay */
5584 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
5585 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
5590 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
5591 iwl4965_escape_essid(ssid
, len
), (int)len
);
5593 priv
->one_direct_scan
= 1;
5594 priv
->direct_ssid_len
= (u8
)
5595 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
5596 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
5598 priv
->one_direct_scan
= 0;
5600 rc
= iwl4965_scan_initiate(priv
);
5602 IWL_DEBUG_MAC80211("leave\n");
5605 spin_unlock_irqrestore(&priv
->lock
, flags
);
5606 mutex_unlock(&priv
->mutex
);
5611 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
5612 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
5613 u32 iv32
, u16
*phase1key
)
5615 struct iwl_priv
*priv
= hw
->priv
;
5616 u8 sta_id
= IWL_INVALID_STATION
;
5617 unsigned long flags
;
5618 __le16 key_flags
= 0;
5620 DECLARE_MAC_BUF(mac
);
5622 IWL_DEBUG_MAC80211("enter\n");
5624 sta_id
= iwl_find_station(priv
, addr
);
5625 if (sta_id
== IWL_INVALID_STATION
) {
5626 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
5627 print_mac(mac
, addr
));
5631 iwl4965_scan_cancel_timeout(priv
, 100);
5633 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
5634 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
5635 key_flags
&= ~STA_KEY_FLG_INVALID
;
5637 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
5638 key_flags
|= STA_KEY_MULTICAST_MSK
;
5640 spin_lock_irqsave(&priv
->sta_lock
, flags
);
5642 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
5643 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
5645 for (i
= 0; i
< 5; i
++)
5646 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
5647 cpu_to_le16(phase1key
[i
]);
5649 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
5650 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
5652 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
5654 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
5656 IWL_DEBUG_MAC80211("leave\n");
5659 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
5660 const u8
*local_addr
, const u8
*addr
,
5661 struct ieee80211_key_conf
*key
)
5663 struct iwl_priv
*priv
= hw
->priv
;
5664 DECLARE_MAC_BUF(mac
);
5666 u8 sta_id
= IWL_INVALID_STATION
;
5667 u8 is_default_wep_key
= 0;
5669 IWL_DEBUG_MAC80211("enter\n");
5671 if (priv
->hw_params
.sw_crypto
) {
5672 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
5676 if (is_zero_ether_addr(addr
))
5677 /* only support pairwise keys */
5680 sta_id
= iwl_find_station(priv
, addr
);
5681 if (sta_id
== IWL_INVALID_STATION
) {
5682 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
5683 print_mac(mac
, addr
));
5688 mutex_lock(&priv
->mutex
);
5689 iwl4965_scan_cancel_timeout(priv
, 100);
5690 mutex_unlock(&priv
->mutex
);
5692 /* If we are getting WEP group key and we didn't receive any key mapping
5693 * so far, we are in legacy wep mode (group key only), otherwise we are
5695 * In legacy wep mode, we use another host command to the uCode */
5696 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_params
.bcast_sta_id
&&
5697 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
5699 is_default_wep_key
= !priv
->key_mapping_key
;
5701 is_default_wep_key
= priv
->default_wep_key
;
5706 if (is_default_wep_key
)
5707 ret
= iwl_set_default_wep_key(priv
, key
);
5709 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
5711 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
5714 if (is_default_wep_key
)
5715 ret
= iwl_remove_default_wep_key(priv
, key
);
5717 ret
= iwl_remove_dynamic_key(priv
, key
, sta_id
);
5719 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
5725 IWL_DEBUG_MAC80211("leave\n");
5730 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
5731 const struct ieee80211_tx_queue_params
*params
)
5733 struct iwl_priv
*priv
= hw
->priv
;
5734 unsigned long flags
;
5737 IWL_DEBUG_MAC80211("enter\n");
5739 if (!iwl_is_ready_rf(priv
)) {
5740 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5744 if (queue
>= AC_NUM
) {
5745 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
5749 if (!priv
->qos_data
.qos_enable
) {
5750 priv
->qos_data
.qos_active
= 0;
5751 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
5754 q
= AC_NUM
- 1 - queue
;
5756 spin_lock_irqsave(&priv
->lock
, flags
);
5758 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
5759 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
5760 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
5761 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
5762 cpu_to_le16((params
->txop
* 32));
5764 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
5765 priv
->qos_data
.qos_active
= 1;
5767 spin_unlock_irqrestore(&priv
->lock
, flags
);
5769 mutex_lock(&priv
->mutex
);
5770 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
5771 iwl4965_activate_qos(priv
, 1);
5772 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
5773 iwl4965_activate_qos(priv
, 0);
5775 mutex_unlock(&priv
->mutex
);
5777 IWL_DEBUG_MAC80211("leave\n");
5781 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
5782 struct ieee80211_tx_queue_stats
*stats
)
5784 struct iwl_priv
*priv
= hw
->priv
;
5786 struct iwl4965_tx_queue
*txq
;
5787 struct iwl4965_queue
*q
;
5788 unsigned long flags
;
5790 IWL_DEBUG_MAC80211("enter\n");
5792 if (!iwl_is_ready_rf(priv
)) {
5793 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5797 spin_lock_irqsave(&priv
->lock
, flags
);
5799 for (i
= 0; i
< AC_NUM
; i
++) {
5800 txq
= &priv
->txq
[i
];
5802 avail
= iwl4965_queue_space(q
);
5804 stats
[i
].len
= q
->n_window
- avail
;
5805 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
5806 stats
[i
].count
= q
->n_window
;
5809 spin_unlock_irqrestore(&priv
->lock
, flags
);
5811 IWL_DEBUG_MAC80211("leave\n");
5816 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
5817 struct ieee80211_low_level_stats
*stats
)
5819 struct iwl_priv
*priv
= hw
->priv
;
5822 IWL_DEBUG_MAC80211("enter\n");
5823 IWL_DEBUG_MAC80211("leave\n");
5828 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
5830 struct iwl_priv
*priv
;
5833 IWL_DEBUG_MAC80211("enter\n");
5834 IWL_DEBUG_MAC80211("leave\n");
5839 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
5841 struct iwl_priv
*priv
= hw
->priv
;
5842 unsigned long flags
;
5844 mutex_lock(&priv
->mutex
);
5845 IWL_DEBUG_MAC80211("enter\n");
5847 priv
->lq_mngr
.lq_ready
= 0;
5848 #ifdef CONFIG_IWL4965_HT
5849 spin_lock_irqsave(&priv
->lock
, flags
);
5850 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
5851 spin_unlock_irqrestore(&priv
->lock
, flags
);
5852 #endif /* CONFIG_IWL4965_HT */
5854 iwl_reset_qos(priv
);
5856 cancel_delayed_work(&priv
->post_associate
);
5858 spin_lock_irqsave(&priv
->lock
, flags
);
5860 priv
->assoc_capability
= 0;
5861 priv
->assoc_station_added
= 0;
5863 /* new association get rid of ibss beacon skb */
5864 if (priv
->ibss_beacon
)
5865 dev_kfree_skb(priv
->ibss_beacon
);
5867 priv
->ibss_beacon
= NULL
;
5869 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
5870 priv
->timestamp
= 0;
5871 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
5872 priv
->beacon_int
= 0;
5874 spin_unlock_irqrestore(&priv
->lock
, flags
);
5876 if (!iwl_is_ready_rf(priv
)) {
5877 IWL_DEBUG_MAC80211("leave - not ready\n");
5878 mutex_unlock(&priv
->mutex
);
5882 /* we are restarting association process
5883 * clear RXON_FILTER_ASSOC_MSK bit
5885 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
5886 iwl4965_scan_cancel_timeout(priv
, 100);
5887 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5888 iwl4965_commit_rxon(priv
);
5891 iwl_power_update_mode(priv
, 0);
5893 /* Per mac80211.h: This is only used in IBSS mode... */
5894 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
5896 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
5897 mutex_unlock(&priv
->mutex
);
5901 iwl4965_set_rate(priv
);
5903 mutex_unlock(&priv
->mutex
);
5905 IWL_DEBUG_MAC80211("leave\n");
5908 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
5909 struct ieee80211_tx_control
*control
)
5911 struct iwl_priv
*priv
= hw
->priv
;
5912 unsigned long flags
;
5914 mutex_lock(&priv
->mutex
);
5915 IWL_DEBUG_MAC80211("enter\n");
5917 if (!iwl_is_ready_rf(priv
)) {
5918 IWL_DEBUG_MAC80211("leave - RF not ready\n");
5919 mutex_unlock(&priv
->mutex
);
5923 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
5924 IWL_DEBUG_MAC80211("leave - not IBSS\n");
5925 mutex_unlock(&priv
->mutex
);
5929 spin_lock_irqsave(&priv
->lock
, flags
);
5931 if (priv
->ibss_beacon
)
5932 dev_kfree_skb(priv
->ibss_beacon
);
5934 priv
->ibss_beacon
= skb
;
5938 IWL_DEBUG_MAC80211("leave\n");
5939 spin_unlock_irqrestore(&priv
->lock
, flags
);
5941 iwl_reset_qos(priv
);
5943 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
5945 mutex_unlock(&priv
->mutex
);
5950 /*****************************************************************************
5954 *****************************************************************************/
5956 #ifdef CONFIG_IWLWIFI_DEBUG
5959 * The following adds a new attribute to the sysfs representation
5960 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
5961 * used for controlling the debug level.
5963 * See the level definitions in iwl for details.
5966 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
5968 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
5970 static ssize_t
store_debug_level(struct device_driver
*d
,
5971 const char *buf
, size_t count
)
5973 char *p
= (char *)buf
;
5976 val
= simple_strtoul(p
, &p
, 0);
5978 printk(KERN_INFO DRV_NAME
5979 ": %s is not in hex or decimal form.\n", buf
);
5981 iwl_debug_level
= val
;
5983 return strnlen(buf
, count
);
5986 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
5987 show_debug_level
, store_debug_level
);
5989 #endif /* CONFIG_IWLWIFI_DEBUG */
5992 static ssize_t
show_temperature(struct device
*d
,
5993 struct device_attribute
*attr
, char *buf
)
5995 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
5997 if (!iwl_is_alive(priv
))
6000 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
6003 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
6005 static ssize_t
show_rs_window(struct device
*d
,
6006 struct device_attribute
*attr
,
6009 struct iwl_priv
*priv
= d
->driver_data
;
6010 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
6012 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
6014 static ssize_t
show_tx_power(struct device
*d
,
6015 struct device_attribute
*attr
, char *buf
)
6017 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6018 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
6021 static ssize_t
store_tx_power(struct device
*d
,
6022 struct device_attribute
*attr
,
6023 const char *buf
, size_t count
)
6025 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6026 char *p
= (char *)buf
;
6029 val
= simple_strtoul(p
, &p
, 10);
6031 printk(KERN_INFO DRV_NAME
6032 ": %s is not in decimal form.\n", buf
);
6034 iwl4965_hw_reg_set_txpower(priv
, val
);
6039 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
6041 static ssize_t
show_flags(struct device
*d
,
6042 struct device_attribute
*attr
, char *buf
)
6044 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6046 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
6049 static ssize_t
store_flags(struct device
*d
,
6050 struct device_attribute
*attr
,
6051 const char *buf
, size_t count
)
6053 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6054 u32 flags
= simple_strtoul(buf
, NULL
, 0);
6056 mutex_lock(&priv
->mutex
);
6057 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
6058 /* Cancel any currently running scans... */
6059 if (iwl4965_scan_cancel_timeout(priv
, 100))
6060 IWL_WARNING("Could not cancel scan.\n");
6062 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
6064 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
6065 iwl4965_commit_rxon(priv
);
6068 mutex_unlock(&priv
->mutex
);
6073 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
6075 static ssize_t
show_filter_flags(struct device
*d
,
6076 struct device_attribute
*attr
, char *buf
)
6078 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6080 return sprintf(buf
, "0x%04X\n",
6081 le32_to_cpu(priv
->active_rxon
.filter_flags
));
6084 static ssize_t
store_filter_flags(struct device
*d
,
6085 struct device_attribute
*attr
,
6086 const char *buf
, size_t count
)
6088 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6089 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
6091 mutex_lock(&priv
->mutex
);
6092 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
6093 /* Cancel any currently running scans... */
6094 if (iwl4965_scan_cancel_timeout(priv
, 100))
6095 IWL_WARNING("Could not cancel scan.\n");
6097 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
6098 "0x%04X\n", filter_flags
);
6099 priv
->staging_rxon
.filter_flags
=
6100 cpu_to_le32(filter_flags
);
6101 iwl4965_commit_rxon(priv
);
6104 mutex_unlock(&priv
->mutex
);
6109 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
6110 store_filter_flags
);
6112 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
6114 static ssize_t
show_measurement(struct device
*d
,
6115 struct device_attribute
*attr
, char *buf
)
6117 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6118 struct iwl4965_spectrum_notification measure_report
;
6119 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
6120 u8
*data
= (u8
*) & measure_report
;
6121 unsigned long flags
;
6123 spin_lock_irqsave(&priv
->lock
, flags
);
6124 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
6125 spin_unlock_irqrestore(&priv
->lock
, flags
);
6128 memcpy(&measure_report
, &priv
->measure_report
, size
);
6129 priv
->measurement_status
= 0;
6130 spin_unlock_irqrestore(&priv
->lock
, flags
);
6132 while (size
&& (PAGE_SIZE
- len
)) {
6133 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
6134 PAGE_SIZE
- len
, 1);
6136 if (PAGE_SIZE
- len
)
6140 size
-= min(size
, 16U);
6146 static ssize_t
store_measurement(struct device
*d
,
6147 struct device_attribute
*attr
,
6148 const char *buf
, size_t count
)
6150 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6151 struct ieee80211_measurement_params params
= {
6152 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
6153 .start_time
= cpu_to_le64(priv
->last_tsf
),
6154 .duration
= cpu_to_le16(1),
6156 u8 type
= IWL_MEASURE_BASIC
;
6162 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
6163 channel
= simple_strtoul(p
, NULL
, 0);
6165 params
.channel
= channel
;
6168 while (*p
&& *p
!= ' ')
6171 type
= simple_strtoul(p
+ 1, NULL
, 0);
6174 IWL_DEBUG_INFO("Invoking measurement of type %d on "
6175 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
6176 iwl4965_get_measurement(priv
, ¶ms
, type
);
6181 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
6182 show_measurement
, store_measurement
);
6183 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
6185 static ssize_t
store_retry_rate(struct device
*d
,
6186 struct device_attribute
*attr
,
6187 const char *buf
, size_t count
)
6189 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6191 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
6192 if (priv
->retry_rate
<= 0)
6193 priv
->retry_rate
= 1;
6198 static ssize_t
show_retry_rate(struct device
*d
,
6199 struct device_attribute
*attr
, char *buf
)
6201 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6202 return sprintf(buf
, "%d", priv
->retry_rate
);
6205 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
6208 static ssize_t
store_power_level(struct device
*d
,
6209 struct device_attribute
*attr
,
6210 const char *buf
, size_t count
)
6212 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6216 mode
= simple_strtoul(buf
, NULL
, 0);
6217 mutex_lock(&priv
->mutex
);
6219 if (!iwl_is_ready(priv
)) {
6224 rc
= iwl_power_set_user_mode(priv
, mode
);
6226 IWL_DEBUG_MAC80211("failed setting power mode.\n");
6232 mutex_unlock(&priv
->mutex
);
6236 #define MAX_WX_STRING 80
6238 /* Values are in microsecond */
6239 static const s32 timeout_duration
[] = {
6246 static const s32 period_duration
[] = {
6254 static ssize_t
show_power_level(struct device
*d
,
6255 struct device_attribute
*attr
, char *buf
)
6257 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6258 int level
= priv
->power_data
.power_mode
;
6261 p
+= sprintf(p
, "%d ", level
);
6263 case IWL_POWER_MODE_CAM
:
6265 p
+= sprintf(p
, "(AC)");
6267 case IWL_POWER_BATTERY
:
6268 p
+= sprintf(p
, "(BATTERY)");
6272 "(Timeout %dms, Period %dms)",
6273 timeout_duration
[level
- 1] / 1000,
6274 period_duration
[level
- 1] / 1000);
6277 if (!(priv->power_mode & IWL_POWER_ENABLED))
6278 p += sprintf(p, " OFF\n");
6280 p += sprintf(p, " \n");
6282 p
+= sprintf(p
, " \n");
6283 return (p
- buf
+ 1);
6286 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
6289 static ssize_t
show_channels(struct device
*d
,
6290 struct device_attribute
*attr
, char *buf
)
6292 /* all this shit doesn't belong into sysfs anyway */
6296 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
6298 static ssize_t
show_statistics(struct device
*d
,
6299 struct device_attribute
*attr
, char *buf
)
6301 struct iwl_priv
*priv
= dev_get_drvdata(d
);
6302 u32 size
= sizeof(struct iwl4965_notif_statistics
);
6303 u32 len
= 0, ofs
= 0;
6304 u8
*data
= (u8
*) & priv
->statistics
;
6307 if (!iwl_is_alive(priv
))
6310 mutex_lock(&priv
->mutex
);
6311 rc
= iwl_send_statistics_request(priv
, 0);
6312 mutex_unlock(&priv
->mutex
);
6316 "Error sending statistics request: 0x%08X\n", rc
);
6320 while (size
&& (PAGE_SIZE
- len
)) {
6321 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
6322 PAGE_SIZE
- len
, 1);
6324 if (PAGE_SIZE
- len
)
6328 size
-= min(size
, 16U);
6334 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
6336 static ssize_t
show_status(struct device
*d
,
6337 struct device_attribute
*attr
, char *buf
)
6339 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
6340 if (!iwl_is_alive(priv
))
6342 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
6345 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
6347 static ssize_t
dump_error_log(struct device
*d
,
6348 struct device_attribute
*attr
,
6349 const char *buf
, size_t count
)
6351 char *p
= (char *)buf
;
6354 iwl4965_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
6356 return strnlen(buf
, count
);
6359 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
6361 static ssize_t
dump_event_log(struct device
*d
,
6362 struct device_attribute
*attr
,
6363 const char *buf
, size_t count
)
6365 char *p
= (char *)buf
;
6368 iwl4965_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
6370 return strnlen(buf
, count
);
6373 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
6375 /*****************************************************************************
6377 * driver setup and teardown
6379 *****************************************************************************/
6381 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
6383 priv
->workqueue
= create_workqueue(DRV_NAME
);
6385 init_waitqueue_head(&priv
->wait_command_queue
);
6387 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
6388 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
6389 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
6390 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
6391 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
6392 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
6393 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
6394 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
6395 INIT_WORK(&priv
->set_monitor
, iwl4965_bg_set_monitor
);
6396 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
6397 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
6398 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
6399 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
6401 iwl4965_hw_setup_deferred_work(priv
);
6403 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
6404 iwl4965_irq_tasklet
, (unsigned long)priv
);
6407 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
6409 iwl4965_hw_cancel_deferred_work(priv
);
6411 cancel_delayed_work_sync(&priv
->init_alive_start
);
6412 cancel_delayed_work(&priv
->scan_check
);
6413 cancel_delayed_work(&priv
->alive_start
);
6414 cancel_delayed_work(&priv
->post_associate
);
6415 cancel_work_sync(&priv
->beacon_update
);
6418 static struct attribute
*iwl4965_sysfs_entries
[] = {
6419 &dev_attr_channels
.attr
,
6420 &dev_attr_dump_errors
.attr
,
6421 &dev_attr_dump_events
.attr
,
6422 &dev_attr_flags
.attr
,
6423 &dev_attr_filter_flags
.attr
,
6424 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
6425 &dev_attr_measurement
.attr
,
6427 &dev_attr_power_level
.attr
,
6428 &dev_attr_retry_rate
.attr
,
6429 &dev_attr_rs_window
.attr
,
6430 &dev_attr_statistics
.attr
,
6431 &dev_attr_status
.attr
,
6432 &dev_attr_temperature
.attr
,
6433 &dev_attr_tx_power
.attr
,
6438 static struct attribute_group iwl4965_attribute_group
= {
6439 .name
= NULL
, /* put in device directory */
6440 .attrs
= iwl4965_sysfs_entries
,
6443 static struct ieee80211_ops iwl4965_hw_ops
= {
6444 .tx
= iwl4965_mac_tx
,
6445 .start
= iwl4965_mac_start
,
6446 .stop
= iwl4965_mac_stop
,
6447 .add_interface
= iwl4965_mac_add_interface
,
6448 .remove_interface
= iwl4965_mac_remove_interface
,
6449 .config
= iwl4965_mac_config
,
6450 .config_interface
= iwl4965_mac_config_interface
,
6451 .configure_filter
= iwl4965_configure_filter
,
6452 .set_key
= iwl4965_mac_set_key
,
6453 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
6454 .get_stats
= iwl4965_mac_get_stats
,
6455 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
6456 .conf_tx
= iwl4965_mac_conf_tx
,
6457 .get_tsf
= iwl4965_mac_get_tsf
,
6458 .reset_tsf
= iwl4965_mac_reset_tsf
,
6459 .beacon_update
= iwl4965_mac_beacon_update
,
6460 .bss_info_changed
= iwl4965_bss_info_changed
,
6461 #ifdef CONFIG_IWL4965_HT
6462 .ampdu_action
= iwl4965_mac_ampdu_action
,
6463 #endif /* CONFIG_IWL4965_HT */
6464 .hw_scan
= iwl4965_mac_hw_scan
6467 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
6470 struct iwl_priv
*priv
;
6471 struct ieee80211_hw
*hw
;
6472 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
6473 unsigned long flags
;
6474 DECLARE_MAC_BUF(mac
);
6476 /************************
6477 * 1. Allocating HW data
6478 ************************/
6480 /* Disabling hardware scan means that mac80211 will perform scans
6481 * "the hard way", rather than using device's scan. */
6482 if (cfg
->mod_params
->disable_hw_scan
) {
6483 if (cfg
->mod_params
->debug
& IWL_DL_INFO
)
6484 dev_printk(KERN_DEBUG
, &(pdev
->dev
),
6485 "Disabling hw_scan\n");
6486 iwl4965_hw_ops
.hw_scan
= NULL
;
6489 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
6495 /* At this point both hw and priv are allocated. */
6497 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
6499 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
6501 priv
->pci_dev
= pdev
;
6503 #ifdef CONFIG_IWLWIFI_DEBUG
6504 priv
->debug_level
= priv
->cfg
->mod_params
->debug
;
6505 atomic_set(&priv
->restrict_refcnt
, 0);
6508 /**************************
6509 * 2. Initializing PCI bus
6510 **************************/
6511 if (pci_enable_device(pdev
)) {
6513 goto out_ieee80211_free_hw
;
6516 pci_set_master(pdev
);
6518 err
= pci_set_dma_mask(pdev
, DMA_64BIT_MASK
);
6520 err
= pci_set_consistent_dma_mask(pdev
, DMA_64BIT_MASK
);
6522 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
6524 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
6525 /* both attempts failed: */
6527 printk(KERN_WARNING
"%s: No suitable DMA available.\n",
6529 goto out_pci_disable_device
;
6533 err
= pci_request_regions(pdev
, DRV_NAME
);
6535 goto out_pci_disable_device
;
6537 pci_set_drvdata(pdev
, priv
);
6539 /* We disable the RETRY_TIMEOUT register (0x41) to keep
6540 * PCI Tx retries from interfering with C3 CPU state */
6541 pci_write_config_byte(pdev
, 0x41, 0x00);
6543 /***********************
6544 * 3. Read REV register
6545 ***********************/
6546 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
6547 if (!priv
->hw_base
) {
6549 goto out_pci_release_regions
;
6552 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
6553 (unsigned long long) pci_resource_len(pdev
, 0));
6554 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
6556 iwl_hw_detect(priv
);
6557 printk(KERN_INFO DRV_NAME
6558 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
6559 priv
->cfg
->name
, priv
->hw_rev
);
6562 err
= priv
->cfg
->ops
->lib
->apm_ops
.init(priv
);
6564 IWL_DEBUG_INFO("Failed to init APMG\n");
6570 /* Read the EEPROM */
6571 err
= iwl_eeprom_init(priv
);
6573 IWL_ERROR("Unable to init EEPROM\n");
6576 err
= iwl_eeprom_check_version(priv
);
6580 /* MAC Address location in EEPROM same for 3945/4965 */
6581 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
6582 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
6583 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
6585 /************************
6586 * 5. Setup HW constants
6587 ************************/
6588 /* Device-specific setup */
6589 if (priv
->cfg
->ops
->lib
->set_hw_params(priv
)) {
6590 IWL_ERROR("failed to set hw parameters\n");
6591 goto out_free_eeprom
;
6594 /*******************
6596 *******************/
6598 err
= iwl_setup(priv
);
6600 goto out_free_eeprom
;
6601 /* At this point both hw and priv are initialized. */
6603 /**********************************
6604 * 7. Initialize module parameters
6605 **********************************/
6607 /* Disable radio (SW RF KILL) via parameter when loading driver */
6608 if (priv
->cfg
->mod_params
->disable
) {
6609 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
6610 IWL_DEBUG_INFO("Radio disabled.\n");
6613 if (priv
->cfg
->mod_params
->enable_qos
)
6614 priv
->qos_data
.qos_enable
= 1;
6616 /********************
6618 ********************/
6619 spin_lock_irqsave(&priv
->lock
, flags
);
6620 iwl4965_disable_interrupts(priv
);
6621 spin_unlock_irqrestore(&priv
->lock
, flags
);
6623 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
6625 IWL_ERROR("failed to create sysfs device attributes\n");
6626 goto out_free_eeprom
;
6629 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
6631 IWL_ERROR("failed to create debugfs files\n");
6632 goto out_remove_sysfs
;
6635 iwl4965_setup_deferred_work(priv
);
6636 iwl4965_setup_rx_handlers(priv
);
6638 /********************
6640 ********************/
6641 pci_save_state(pdev
);
6642 pci_disable_device(pdev
);
6644 /* notify iwlcore to init */
6645 iwlcore_low_level_notify(priv
, IWLCORE_INIT_EVT
);
6649 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
6651 iwl_eeprom_free(priv
);
6653 pci_iounmap(pdev
, priv
->hw_base
);
6654 out_pci_release_regions
:
6655 pci_release_regions(pdev
);
6656 pci_set_drvdata(pdev
, NULL
);
6657 out_pci_disable_device
:
6658 pci_disable_device(pdev
);
6659 out_ieee80211_free_hw
:
6660 ieee80211_free_hw(priv
->hw
);
6665 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
6667 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
6668 struct list_head
*p
, *q
;
6670 unsigned long flags
;
6675 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
6677 if (priv
->mac80211_registered
) {
6678 ieee80211_unregister_hw(priv
->hw
);
6679 priv
->mac80211_registered
= 0;
6682 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6686 /* make sure we flush any pending irq or
6687 * tasklet for the driver
6689 spin_lock_irqsave(&priv
->lock
, flags
);
6690 iwl4965_disable_interrupts(priv
);
6691 spin_unlock_irqrestore(&priv
->lock
, flags
);
6693 iwl_synchronize_irq(priv
);
6695 /* Free MAC hash list for ADHOC */
6696 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
6697 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
6699 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
6703 iwlcore_low_level_notify(priv
, IWLCORE_REMOVE_EVT
);
6704 iwl_dbgfs_unregister(priv
);
6705 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
6707 iwl4965_dealloc_ucode_pci(priv
);
6710 iwl_rx_queue_free(priv
, &priv
->rxq
);
6711 iwl_hw_txq_ctx_free(priv
);
6713 iwlcore_clear_stations_table(priv
);
6714 iwl_eeprom_free(priv
);
6717 /*netif_stop_queue(dev); */
6718 flush_workqueue(priv
->workqueue
);
6720 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
6721 * priv->workqueue... so we can't take down the workqueue
6723 destroy_workqueue(priv
->workqueue
);
6724 priv
->workqueue
= NULL
;
6726 pci_iounmap(pdev
, priv
->hw_base
);
6727 pci_release_regions(pdev
);
6728 pci_disable_device(pdev
);
6729 pci_set_drvdata(pdev
, NULL
);
6731 iwl_free_channel_map(priv
);
6732 iwlcore_free_geos(priv
);
6734 if (priv
->ibss_beacon
)
6735 dev_kfree_skb(priv
->ibss_beacon
);
6737 ieee80211_free_hw(priv
->hw
);
6742 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
6744 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
6746 if (priv
->is_open
) {
6747 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
6748 iwl4965_mac_stop(priv
->hw
);
6752 pci_set_power_state(pdev
, PCI_D3hot
);
6757 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
6759 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
6761 pci_set_power_state(pdev
, PCI_D0
);
6764 iwl4965_mac_start(priv
->hw
);
6766 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
6770 #endif /* CONFIG_PM */
6772 /*****************************************************************************
6774 * driver and module entry point
6776 *****************************************************************************/
6778 /* Hardware specific file defines the PCI IDs table for that hardware module */
6779 static struct pci_device_id iwl_hw_card_ids
[] = {
6780 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID
, iwl4965_agn_cfg
)},
6781 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID
, iwl4965_agn_cfg
)},
6782 #ifdef CONFIG_IWL5000
6783 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID
, iwl5300_agn_cfg
)},
6784 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID
, iwl5100_agn_cfg
)},
6785 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID
, iwl5350_agn_cfg
)},
6786 #endif /* CONFIG_IWL5000 */
6789 MODULE_DEVICE_TABLE(pci
, iwl_hw_card_ids
);
6791 static struct pci_driver iwl_driver
= {
6793 .id_table
= iwl_hw_card_ids
,
6794 .probe
= iwl4965_pci_probe
,
6795 .remove
= __devexit_p(iwl4965_pci_remove
),
6797 .suspend
= iwl4965_pci_suspend
,
6798 .resume
= iwl4965_pci_resume
,
6802 static int __init
iwl4965_init(void)
6806 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
6807 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
6809 ret
= iwl4965_rate_control_register();
6811 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
6815 ret
= pci_register_driver(&iwl_driver
);
6817 IWL_ERROR("Unable to initialize PCI module\n");
6818 goto error_register
;
6820 #ifdef CONFIG_IWLWIFI_DEBUG
6821 ret
= driver_create_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
6823 IWL_ERROR("Unable to create driver sysfs file\n");
6830 #ifdef CONFIG_IWLWIFI_DEBUG
6832 pci_unregister_driver(&iwl_driver
);
6835 iwl4965_rate_control_unregister();
6839 static void __exit
iwl4965_exit(void)
6841 #ifdef CONFIG_IWLWIFI_DEBUG
6842 driver_remove_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
6844 pci_unregister_driver(&iwl_driver
);
6845 iwl4965_rate_control_unregister();
6848 module_exit(iwl4965_exit
);
6849 module_init(iwl4965_init
);