aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl4965-base.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl4965-base.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c439
1 files changed, 136 insertions, 303 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index f5911687671b..ba0f28945eb1 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -192,7 +192,7 @@ static int iwl4965_full_rxon_required(struct iwl_priv *priv)
192{ 192{
193 193
194 /* These items are only settable from the full RXON command */ 194 /* These items are only settable from the full RXON command */
195 if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || 195 if (!(iwl_is_associated(priv)) ||
196 compare_ether_addr(priv->staging_rxon.bssid_addr, 196 compare_ether_addr(priv->staging_rxon.bssid_addr,
197 priv->active_rxon.bssid_addr) || 197 priv->active_rxon.bssid_addr) ||
198 compare_ether_addr(priv->staging_rxon.node_addr, 198 compare_ether_addr(priv->staging_rxon.node_addr,
@@ -241,16 +241,18 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
241 /* cast away the const for active_rxon in this function */ 241 /* cast away the const for active_rxon in this function */
242 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 242 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
243 DECLARE_MAC_BUF(mac); 243 DECLARE_MAC_BUF(mac);
244 int rc = 0; 244 int ret;
245 bool new_assoc =
246 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
245 247
246 if (!iwl_is_alive(priv)) 248 if (!iwl_is_alive(priv))
247 return -1; 249 return -EBUSY;
248 250
249 /* always get timestamp with Rx frame */ 251 /* always get timestamp with Rx frame */
250 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; 252 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
251 253
252 rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); 254 ret = iwl4965_check_rxon_cmd(&priv->staging_rxon);
253 if (rc) { 255 if (ret) {
254 IWL_ERROR("Invalid RXON configuration. Not committing.\n"); 256 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
255 return -EINVAL; 257 return -EINVAL;
256 } 258 }
@@ -259,15 +261,13 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
259 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter 261 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
260 * and other flags for the current radio configuration. */ 262 * and other flags for the current radio configuration. */
261 if (!iwl4965_full_rxon_required(priv)) { 263 if (!iwl4965_full_rxon_required(priv)) {
262 rc = iwl_send_rxon_assoc(priv); 264 ret = iwl_send_rxon_assoc(priv);
263 if (rc) { 265 if (ret) {
264 IWL_ERROR("Error setting RXON_ASSOC " 266 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret);
265 "configuration (%d).\n", rc); 267 return ret;
266 return rc;
267 } 268 }
268 269
269 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 270 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
270
271 return 0; 271 return 0;
272 } 272 }
273 273
@@ -278,22 +278,20 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
278 * an RXON_ASSOC and the new config wants the associated mask enabled, 278 * an RXON_ASSOC and the new config wants the associated mask enabled,
279 * we must clear the associated from the active configuration 279 * we must clear the associated from the active configuration
280 * before we apply the new config */ 280 * before we apply the new config */
281 if (iwl_is_associated(priv) && 281 if (iwl_is_associated(priv) && new_assoc) {
282 (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
283 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); 282 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
284 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 283 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
285 284
286 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 285 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
287 sizeof(struct iwl_rxon_cmd), 286 sizeof(struct iwl_rxon_cmd),
288 &priv->active_rxon); 287 &priv->active_rxon);
289 288
290 /* If the mask clearing failed then we set 289 /* If the mask clearing failed then we set
291 * active_rxon back to what it was previously */ 290 * active_rxon back to what it was previously */
292 if (rc) { 291 if (ret) {
293 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; 292 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
294 IWL_ERROR("Error clearing ASSOC_MSK on current " 293 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret);
295 "configuration (%d).\n", rc); 294 return ret;
296 return rc;
297 } 295 }
298 } 296 }
299 297
@@ -301,58 +299,75 @@ static int iwl4965_commit_rxon(struct iwl_priv *priv)
301 "* with%s RXON_FILTER_ASSOC_MSK\n" 299 "* with%s RXON_FILTER_ASSOC_MSK\n"
302 "* channel = %d\n" 300 "* channel = %d\n"
303 "* bssid = %s\n", 301 "* bssid = %s\n",
304 ((priv->staging_rxon.filter_flags & 302 (new_assoc ? "" : "out"),
305 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
306 le16_to_cpu(priv->staging_rxon.channel), 303 le16_to_cpu(priv->staging_rxon.channel),
307 print_mac(mac, priv->staging_rxon.bssid_addr)); 304 print_mac(mac, priv->staging_rxon.bssid_addr));
308 305
309 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); 306 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
310 /* Apply the new configuration */ 307
311 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 308 /* Apply the new configuration
309 * RXON unassoc clears the station table in uCode, send it before
310 * we add the bcast station. If assoc bit is set, we will send RXON
311 * after having added the bcast and bssid station.
312 */
313 if (!new_assoc) {
314 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
312 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); 315 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
313 if (rc) { 316 if (ret) {
314 IWL_ERROR("Error setting new configuration (%d).\n", rc); 317 IWL_ERROR("Error setting new RXON (%d)\n", ret);
315 return rc; 318 return ret;
319 }
320 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
316 } 321 }
317 322
318 iwl_remove_station(priv, iwl_bcast_addr, 0); 323 iwl_clear_stations_table(priv);
319 iwlcore_clear_stations_table(priv);
320 324
321 if (!priv->error_recovering) 325 if (!priv->error_recovering)
322 priv->start_calib = 0; 326 priv->start_calib = 0;
323 327
324 iwl_init_sensitivity(priv); 328 iwl_init_sensitivity(priv);
325 329
326 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
327
328 /* If we issue a new RXON command which required a tune then we must 330 /* If we issue a new RXON command which required a tune then we must
329 * send a new TXPOWER command or we won't be able to Tx any frames */ 331 * send a new TXPOWER command or we won't be able to Tx any frames */
330 rc = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); 332 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
331 if (rc) { 333 if (ret) {
332 IWL_ERROR("Error sending TX power (%d).\n", rc); 334 IWL_ERROR("Error sending TX power (%d)\n", ret);
333 return rc; 335 return ret;
334 } 336 }
335 337
336 /* Add the broadcast address so we can send broadcast frames */ 338 /* Add the broadcast address so we can send broadcast frames */
337 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == 339 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
338 IWL_INVALID_STATION) { 340 IWL_INVALID_STATION) {
339 IWL_ERROR("Error adding BROADCAST address for transmit.\n"); 341 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
340 return -EIO; 342 return -EIO;
341 } 343 }
342 344
343 /* If we have set the ASSOC_MSK and we are in BSS mode then 345 /* If we have set the ASSOC_MSK and we are in BSS mode then
344 * add the IWL_AP_ID to the station rate table */ 346 * add the IWL_AP_ID to the station rate table */
345 if (iwl_is_associated(priv) && 347 if (new_assoc) {
346 (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { 348 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
347 if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) 349 ret = iwl_rxon_add_station(priv,
348 == IWL_INVALID_STATION) { 350 priv->active_rxon.bssid_addr, 1);
349 IWL_ERROR("Error adding AP address for transmit.\n"); 351 if (ret == IWL_INVALID_STATION) {
350 return -EIO; 352 IWL_ERROR("Error adding AP address for TX.\n");
353 return -EIO;
354 }
355 priv->assoc_station_added = 1;
356 if (priv->default_wep_key &&
357 iwl_send_static_wepkey_cmd(priv, 0))
358 IWL_ERROR("Could not send WEP static key.\n");
351 } 359 }
352 priv->assoc_station_added = 1; 360
353 if (priv->default_wep_key && 361 /* Apply the new configuration
354 iwl_send_static_wepkey_cmd(priv, 0)) 362 * RXON assoc doesn't clear the station table in uCode,
355 IWL_ERROR("Could not send WEP static key.\n"); 363 */
364 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
365 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
366 if (ret) {
367 IWL_ERROR("Error setting new RXON (%d)\n", ret);
368 return ret;
369 }
370 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
356 } 371 }
357 372
358 return 0; 373 return 0;
@@ -601,50 +616,6 @@ static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
601 } 616 }
602} 617}
603 618
604int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
605{
606 /* Filter incoming packets to determine if they are targeted toward
607 * this network, discarding packets coming from ourselves */
608 switch (priv->iw_mode) {
609 case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
610 /* packets from our adapter are dropped (echo) */
611 if (!compare_ether_addr(header->addr2, priv->mac_addr))
612 return 0;
613 /* {broad,multi}cast packets to our IBSS go through */
614 if (is_multicast_ether_addr(header->addr1))
615 return !compare_ether_addr(header->addr3, priv->bssid);
616 /* packets to our adapter go through */
617 return !compare_ether_addr(header->addr1, priv->mac_addr);
618 case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
619 /* packets from our adapter are dropped (echo) */
620 if (!compare_ether_addr(header->addr3, priv->mac_addr))
621 return 0;
622 /* {broad,multi}cast packets to our BSS go through */
623 if (is_multicast_ether_addr(header->addr1))
624 return !compare_ether_addr(header->addr2, priv->bssid);
625 /* packets to our adapter go through */
626 return !compare_ether_addr(header->addr1, priv->mac_addr);
627 default:
628 break;
629 }
630
631 return 1;
632}
633
634static void iwl4965_sequence_reset(struct iwl_priv *priv)
635{
636 /* Reset ieee stats */
637
638 /* We don't reset the net_device_stats (ieee->stats) on
639 * re-association */
640
641 priv->last_seq_num = -1;
642 priv->last_frag_num = -1;
643 priv->last_packet_time = 0;
644
645 iwl_scan_cancel(priv);
646}
647
648#define MAX_UCODE_BEACON_INTERVAL 4096 619#define MAX_UCODE_BEACON_INTERVAL 4096
649#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) 620#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
650 621
@@ -787,7 +758,7 @@ static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
787#endif 758#endif
788 759
789 ch_info = iwl_get_channel_info(priv, priv->band, 760 ch_info = iwl_get_channel_info(priv, priv->band,
790 le16_to_cpu(priv->staging_rxon.channel)); 761 le16_to_cpu(priv->active_rxon.channel));
791 762
792 if (!ch_info) 763 if (!ch_info)
793 ch_info = &priv->channel_info[0]; 764 ch_info = &priv->channel_info[0];
@@ -823,13 +794,10 @@ static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
823{ 794{
824 priv->iw_mode = mode; 795 priv->iw_mode = mode;
825 796
826 /* init channel/phymode to values given at driver init */
827 iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
828
829 iwl4965_connection_init_rx_config(priv); 797 iwl4965_connection_init_rx_config(priv);
830 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); 798 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
831 799
832 iwlcore_clear_stations_table(priv); 800 iwl_clear_stations_table(priv);
833 801
834 /* dont commit rxon if rf-kill is on*/ 802 /* dont commit rxon if rf-kill is on*/
835 if (!iwl_is_ready_rf(priv)) 803 if (!iwl_is_ready_rf(priv))
@@ -894,72 +862,6 @@ static void iwl4965_set_rate(struct iwl_priv *priv)
894 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 862 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
895} 863}
896 864
897#define IWL_PACKET_RETRY_TIME HZ
898
899int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
900{
901 u16 sc = le16_to_cpu(header->seq_ctrl);
902 u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
903 u16 frag = sc & IEEE80211_SCTL_FRAG;
904 u16 *last_seq, *last_frag;
905 unsigned long *last_time;
906
907 switch (priv->iw_mode) {
908 case IEEE80211_IF_TYPE_IBSS:{
909 struct list_head *p;
910 struct iwl4965_ibss_seq *entry = NULL;
911 u8 *mac = header->addr2;
912 int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
913
914 __list_for_each(p, &priv->ibss_mac_hash[index]) {
915 entry = list_entry(p, struct iwl4965_ibss_seq, list);
916 if (!compare_ether_addr(entry->mac, mac))
917 break;
918 }
919 if (p == &priv->ibss_mac_hash[index]) {
920 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
921 if (!entry) {
922 IWL_ERROR("Cannot malloc new mac entry\n");
923 return 0;
924 }
925 memcpy(entry->mac, mac, ETH_ALEN);
926 entry->seq_num = seq;
927 entry->frag_num = frag;
928 entry->packet_time = jiffies;
929 list_add(&entry->list, &priv->ibss_mac_hash[index]);
930 return 0;
931 }
932 last_seq = &entry->seq_num;
933 last_frag = &entry->frag_num;
934 last_time = &entry->packet_time;
935 break;
936 }
937 case IEEE80211_IF_TYPE_STA:
938 last_seq = &priv->last_seq_num;
939 last_frag = &priv->last_frag_num;
940 last_time = &priv->last_packet_time;
941 break;
942 default:
943 return 0;
944 }
945 if ((*last_seq == seq) &&
946 time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
947 if (*last_frag == frag)
948 goto drop;
949 if (*last_frag + 1 != frag)
950 /* out-of-order fragment */
951 goto drop;
952 } else
953 *last_seq = seq;
954
955 *last_frag = frag;
956 *last_time = jiffies;
957 return 0;
958
959 drop:
960 return 1;
961}
962
963#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT 865#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
964 866
965#include "iwl-spectrum.h" 867#include "iwl-spectrum.h"
@@ -1338,17 +1240,6 @@ static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
1338 wake_up_interruptible(&priv->wait_command_queue); 1240 wake_up_interruptible(&priv->wait_command_queue);
1339} 1241}
1340 1242
1341/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
1342 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
1343static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
1344 struct iwl_rx_mem_buffer *rxb)
1345{
1346 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
1347 priv->last_phy_res[0] = 1;
1348 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
1349 sizeof(struct iwl4965_rx_phy_res));
1350}
1351
1352/** 1243/**
1353 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks 1244 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
1354 * 1245 *
@@ -1358,7 +1249,7 @@ static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
1358 * This function chains into the hardware specific files for them to setup 1249 * This function chains into the hardware specific files for them to setup
1359 * any hardware specific handlers as well. 1250 * any hardware specific handlers as well.
1360 */ 1251 */
1361static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) 1252static void iwl_setup_rx_handlers(struct iwl_priv *priv)
1362{ 1253{
1363 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; 1254 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
1364 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; 1255 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
@@ -1375,8 +1266,8 @@ static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
1375 * statistics request from the host as well as for the periodic 1266 * statistics request from the host as well as for the periodic
1376 * statistics notifications (after received beacons) from the uCode. 1267 * statistics notifications (after received beacons) from the uCode.
1377 */ 1268 */
1378 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; 1269 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1379 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; 1270 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
1380 1271
1381 iwl_setup_rx_scan_handlers(priv); 1272 iwl_setup_rx_scan_handlers(priv);
1382 1273
@@ -1386,8 +1277,10 @@ static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
1386 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = 1277 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1387 iwl_rx_missed_beacon_notif; 1278 iwl_rx_missed_beacon_notif;
1388 /* Rx handlers */ 1279 /* Rx handlers */
1389 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy; 1280 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1390 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx; 1281 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
1282 /* block ack */
1283 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
1391 /* Set up hardware specific Rx handlers */ 1284 /* Set up hardware specific Rx handlers */
1392 priv->cfg->ops->lib->rx_handler_setup(priv); 1285 priv->cfg->ops->lib->rx_handler_setup(priv);
1393} 1286}
@@ -1518,47 +1411,6 @@ void iwl_rx_handle(struct iwl_priv *priv)
1518 iwl_rx_queue_restock(priv); 1411 iwl_rx_queue_restock(priv);
1519} 1412}
1520 1413
1521#define PERFECT_RSSI (-20) /* dBm */
1522#define WORST_RSSI (-95) /* dBm */
1523#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1524
1525/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1526 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1527 * about formulas used below. */
1528int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
1529{
1530 int sig_qual;
1531 int degradation = PERFECT_RSSI - rssi_dbm;
1532
1533 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1534 * as indicator; formula is (signal dbm - noise dbm).
1535 * SNR at or above 40 is a great signal (100%).
1536 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1537 * Weakest usable signal is usually 10 - 15 dB SNR. */
1538 if (noise_dbm) {
1539 if (rssi_dbm - noise_dbm >= 40)
1540 return 100;
1541 else if (rssi_dbm < noise_dbm)
1542 return 0;
1543 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1544
1545 /* Else use just the signal level.
1546 * This formula is a least squares fit of data points collected and
1547 * compared with a reference system that had a percentage (%) display
1548 * for signal quality. */
1549 } else
1550 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1551 (15 * RSSI_RANGE + 62 * degradation)) /
1552 (RSSI_RANGE * RSSI_RANGE);
1553
1554 if (sig_qual > 100)
1555 sig_qual = 100;
1556 else if (sig_qual < 1)
1557 sig_qual = 0;
1558
1559 return sig_qual;
1560}
1561
1562#ifdef CONFIG_IWLWIFI_DEBUG 1414#ifdef CONFIG_IWLWIFI_DEBUG
1563static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) 1415static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
1564{ 1416{
@@ -1751,14 +1603,12 @@ static void iwl4965_irq_tasklet(struct iwl_priv *priv)
1751 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n", 1603 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
1752 hw_rf_kill ? "disable radio":"enable radio"); 1604 hw_rf_kill ? "disable radio":"enable radio");
1753 1605
1754 /* Queue restart only if RF_KILL switch was set to "kill" 1606 /* driver only loads ucode once setting the interface up.
1755 * when we loaded driver, and is now set to "enable". 1607 * the driver as well won't allow loading if RFKILL is set
1756 * After we're Alive, RF_KILL gets handled by 1608 * therefore no need to restart the driver from this handler
1757 * iwl4965_rx_card_state_notif() */ 1609 */
1758 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { 1610 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status))
1759 clear_bit(STATUS_RF_KILL_HW, &priv->status); 1611 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1760 queue_work(priv->workqueue, &priv->restart);
1761 }
1762 1612
1763 handled |= CSR_INT_BIT_RF_KILL; 1613 handled |= CSR_INT_BIT_RF_KILL;
1764 } 1614 }
@@ -2138,7 +1988,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
2138 goto restart; 1988 goto restart;
2139 } 1989 }
2140 1990
2141 iwlcore_clear_stations_table(priv); 1991 iwl_clear_stations_table(priv);
2142 ret = priv->cfg->ops->lib->alive_notify(priv); 1992 ret = priv->cfg->ops->lib->alive_notify(priv);
2143 if (ret) { 1993 if (ret) {
2144 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", 1994 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
@@ -2216,7 +2066,7 @@ static void __iwl4965_down(struct iwl_priv *priv)
2216 2066
2217 iwl_leds_unregister(priv); 2067 iwl_leds_unregister(priv);
2218 2068
2219 iwlcore_clear_stations_table(priv); 2069 iwl_clear_stations_table(priv);
2220 2070
2221 /* Unblock any waiting calls */ 2071 /* Unblock any waiting calls */
2222 wake_up_interruptible_all(&priv->wait_command_queue); 2072 wake_up_interruptible_all(&priv->wait_command_queue);
@@ -2248,7 +2098,9 @@ static void __iwl4965_down(struct iwl_priv *priv)
2248 test_bit(STATUS_GEO_CONFIGURED, &priv->status) << 2098 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2249 STATUS_GEO_CONFIGURED | 2099 STATUS_GEO_CONFIGURED |
2250 test_bit(STATUS_IN_SUSPEND, &priv->status) << 2100 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2251 STATUS_IN_SUSPEND; 2101 STATUS_IN_SUSPEND |
2102 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2103 STATUS_EXIT_PENDING;
2252 goto exit; 2104 goto exit;
2253 } 2105 }
2254 2106
@@ -2263,7 +2115,9 @@ static void __iwl4965_down(struct iwl_priv *priv)
2263 test_bit(STATUS_IN_SUSPEND, &priv->status) << 2115 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2264 STATUS_IN_SUSPEND | 2116 STATUS_IN_SUSPEND |
2265 test_bit(STATUS_FW_ERROR, &priv->status) << 2117 test_bit(STATUS_FW_ERROR, &priv->status) <<
2266 STATUS_FW_ERROR; 2118 STATUS_FW_ERROR |
2119 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2120 STATUS_EXIT_PENDING;
2267 2121
2268 spin_lock_irqsave(&priv->lock, flags); 2122 spin_lock_irqsave(&priv->lock, flags);
2269 iwl_clear_bit(priv, CSR_GP_CNTRL, 2123 iwl_clear_bit(priv, CSR_GP_CNTRL,
@@ -2328,13 +2182,15 @@ static int __iwl4965_up(struct iwl_priv *priv)
2328 if (iwl_read32(priv, CSR_GP_CNTRL) & 2182 if (iwl_read32(priv, CSR_GP_CNTRL) &
2329 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) 2183 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2330 clear_bit(STATUS_RF_KILL_HW, &priv->status); 2184 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2331 else { 2185 else
2332 set_bit(STATUS_RF_KILL_HW, &priv->status); 2186 set_bit(STATUS_RF_KILL_HW, &priv->status);
2333 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { 2187
2334 iwl_rfkill_set_hw_state(priv); 2188 if (!test_bit(STATUS_IN_SUSPEND, &priv->status) &&
2335 IWL_WARNING("Radio disabled by HW RF Kill switch\n"); 2189 iwl_is_rfkill(priv)) {
2336 return -ENODEV; 2190 iwl_rfkill_set_hw_state(priv);
2337 } 2191 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2192 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2193 return -ENODEV;
2338 } 2194 }
2339 2195
2340 iwl_rfkill_set_hw_state(priv); 2196 iwl_rfkill_set_hw_state(priv);
@@ -2378,7 +2234,7 @@ static int __iwl4965_up(struct iwl_priv *priv)
2378 2234
2379 for (i = 0; i < MAX_HW_RESTARTS; i++) { 2235 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2380 2236
2381 iwlcore_clear_stations_table(priv); 2237 iwl_clear_stations_table(priv);
2382 2238
2383 /* load bootstrap state machine, 2239 /* load bootstrap state machine,
2384 * load bootstrap program into processor's memory, 2240 * load bootstrap program into processor's memory,
@@ -2631,7 +2487,6 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2631 2487
2632 switch (priv->iw_mode) { 2488 switch (priv->iw_mode) {
2633 case IEEE80211_IF_TYPE_STA: 2489 case IEEE80211_IF_TYPE_STA:
2634 iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
2635 break; 2490 break;
2636 2491
2637 case IEEE80211_IF_TYPE_IBSS: 2492 case IEEE80211_IF_TYPE_IBSS:
@@ -2640,7 +2495,6 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2640 priv->assoc_id = 1; 2495 priv->assoc_id = 1;
2641 2496
2642 iwl_rxon_add_station(priv, priv->bssid, 0); 2497 iwl_rxon_add_station(priv, priv->bssid, 0);
2643 iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
2644 iwl4965_send_beacon_cmd(priv); 2498 iwl4965_send_beacon_cmd(priv);
2645 2499
2646 break; 2500 break;
@@ -2651,8 +2505,6 @@ static void iwl4965_post_associate(struct iwl_priv *priv)
2651 break; 2505 break;
2652 } 2506 }
2653 2507
2654 iwl4965_sequence_reset(priv);
2655
2656 /* Enable Rx differential gain and sensitivity calibrations */ 2508 /* Enable Rx differential gain and sensitivity calibrations */
2657 iwl_chain_noise_reset(priv); 2509 iwl_chain_noise_reset(priv);
2658 priv->start_calib = 1; 2510 priv->start_calib = 1;
@@ -2709,7 +2561,7 @@ static void iwl_bg_scan_completed(struct work_struct *work)
2709 * 2561 *
2710 *****************************************************************************/ 2562 *****************************************************************************/
2711 2563
2712#define UCODE_READY_TIMEOUT (2 * HZ) 2564#define UCODE_READY_TIMEOUT (4 * HZ)
2713 2565
2714static int iwl4965_mac_start(struct ieee80211_hw *hw) 2566static int iwl4965_mac_start(struct ieee80211_hw *hw)
2715{ 2567{
@@ -2762,21 +2614,19 @@ static int iwl4965_mac_start(struct ieee80211_hw *hw)
2762 2614
2763 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from 2615 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2764 * mac80211 will not be run successfully. */ 2616 * mac80211 will not be run successfully. */
2765 if (priv->ucode_type == UCODE_RT) { 2617 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2766 ret = wait_event_interruptible_timeout(priv->wait_command_queue, 2618 test_bit(STATUS_READY, &priv->status),
2767 test_bit(STATUS_READY, &priv->status), 2619 UCODE_READY_TIMEOUT);
2768 UCODE_READY_TIMEOUT); 2620 if (!ret) {
2769 if (!ret) { 2621 if (!test_bit(STATUS_READY, &priv->status)) {
2770 if (!test_bit(STATUS_READY, &priv->status)) { 2622 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2771 IWL_ERROR("START_ALIVE timeout after %dms.\n", 2623 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2772 jiffies_to_msecs(UCODE_READY_TIMEOUT)); 2624 ret = -ETIMEDOUT;
2773 ret = -ETIMEDOUT; 2625 goto out_release_irq;
2774 goto out_release_irq;
2775 }
2776 } 2626 }
2777
2778 priv->is_open = 1;
2779 } 2627 }
2628
2629 priv->is_open = 1;
2780 IWL_DEBUG_MAC80211("leave\n"); 2630 IWL_DEBUG_MAC80211("leave\n");
2781 return 0; 2631 return 0;
2782 2632
@@ -3009,7 +2859,7 @@ static void iwl4965_config_ap(struct iwl_priv *priv)
3009 return; 2859 return;
3010 2860
3011 /* The following should be done only at AP bring up */ 2861 /* The following should be done only at AP bring up */
3012 if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { 2862 if (!(iwl_is_associated(priv))) {
3013 2863
3014 /* RXON - unassoc (to set timing command) */ 2864 /* RXON - unassoc (to set timing command) */
3015 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2865 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
@@ -3172,26 +3022,18 @@ static void iwl4965_configure_filter(struct ieee80211_hw *hw,
3172 unsigned int *total_flags, 3022 unsigned int *total_flags,
3173 int mc_count, struct dev_addr_list *mc_list) 3023 int mc_count, struct dev_addr_list *mc_list)
3174{ 3024{
3175 /*
3176 * XXX: dummy
3177 * see also iwl4965_connection_init_rx_config
3178 */
3179 struct iwl_priv *priv = hw->priv; 3025 struct iwl_priv *priv = hw->priv;
3180 int new_flags = 0; 3026
3181 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { 3027 if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
3182 if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { 3028 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3183 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", 3029 IEEE80211_IF_TYPE_MNTR,
3184 IEEE80211_IF_TYPE_MNTR, 3030 changed_flags, *total_flags);
3185 changed_flags, *total_flags); 3031 /* queue work 'cuz mac80211 is holding a lock which
3186 /* queue work 'cuz mac80211 is holding a lock which 3032 * prevents us from issuing (synchronous) f/w cmds */
3187 * prevents us from issuing (synchronous) f/w cmds */ 3033 queue_work(priv->workqueue, &priv->set_monitor);
3188 queue_work(priv->workqueue, &priv->set_monitor);
3189 new_flags &= FIF_PROMISC_IN_BSS |
3190 FIF_OTHER_BSS |
3191 FIF_ALLMULTI;
3192 }
3193 } 3034 }
3194 *total_flags = new_flags; 3035 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
3036 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
3195} 3037}
3196 3038
3197static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, 3039static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
@@ -3556,17 +3398,6 @@ static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
3556 return 0; 3398 return 0;
3557} 3399}
3558 3400
3559static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
3560{
3561 struct iwl_priv *priv;
3562
3563 priv = hw->priv;
3564 IWL_DEBUG_MAC80211("enter\n");
3565 IWL_DEBUG_MAC80211("leave\n");
3566
3567 return 0;
3568}
3569
3570static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) 3401static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
3571{ 3402{
3572 struct iwl_priv *priv = hw->priv; 3403 struct iwl_priv *priv = hw->priv;
@@ -3575,7 +3406,6 @@ static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
3575 mutex_lock(&priv->mutex); 3406 mutex_lock(&priv->mutex);
3576 IWL_DEBUG_MAC80211("enter\n"); 3407 IWL_DEBUG_MAC80211("enter\n");
3577 3408
3578 priv->lq_mngr.lq_ready = 0;
3579 spin_lock_irqsave(&priv->lock, flags); 3409 spin_lock_irqsave(&priv->lock, flags);
3580 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); 3410 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
3581 spin_unlock_irqrestore(&priv->lock, flags); 3411 spin_unlock_irqrestore(&priv->lock, flags);
@@ -3638,6 +3468,7 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
3638{ 3468{
3639 struct iwl_priv *priv = hw->priv; 3469 struct iwl_priv *priv = hw->priv;
3640 unsigned long flags; 3470 unsigned long flags;
3471 __le64 timestamp;
3641 3472
3642 mutex_lock(&priv->mutex); 3473 mutex_lock(&priv->mutex);
3643 IWL_DEBUG_MAC80211("enter\n"); 3474 IWL_DEBUG_MAC80211("enter\n");
@@ -3662,6 +3493,8 @@ static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *sk
3662 priv->ibss_beacon = skb; 3493 priv->ibss_beacon = skb;
3663 3494
3664 priv->assoc_id = 0; 3495 priv->assoc_id = 0;
3496 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
3497 priv->timestamp = le64_to_cpu(timestamp) + (priv->beacon_int * 1000);
3665 3498
3666 IWL_DEBUG_MAC80211("leave\n"); 3499 IWL_DEBUG_MAC80211("leave\n");
3667 spin_unlock_irqrestore(&priv->lock, flags); 3500 spin_unlock_irqrestore(&priv->lock, flags);
@@ -3728,16 +3561,28 @@ static ssize_t show_version(struct device *d,
3728{ 3561{
3729 struct iwl_priv *priv = d->driver_data; 3562 struct iwl_priv *priv = d->driver_data;
3730 struct iwl_alive_resp *palive = &priv->card_alive; 3563 struct iwl_alive_resp *palive = &priv->card_alive;
3564 ssize_t pos = 0;
3565 u16 eeprom_ver;
3731 3566
3732 if (palive->is_valid) 3567 if (palive->is_valid)
3733 return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" 3568 pos += sprintf(buf + pos,
3734 "fw type: 0x%01X 0x%01X\n", 3569 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3570 "fw type: 0x%01X 0x%01X\n",
3735 palive->ucode_major, palive->ucode_minor, 3571 palive->ucode_major, palive->ucode_minor,
3736 palive->sw_rev[0], palive->sw_rev[1], 3572 palive->sw_rev[0], palive->sw_rev[1],
3737 palive->ver_type, palive->ver_subtype); 3573 palive->ver_type, palive->ver_subtype);
3738
3739 else 3574 else
3740 return sprintf(buf, "fw not loaded\n"); 3575 pos += sprintf(buf + pos, "fw not loaded\n");
3576
3577 if (priv->eeprom) {
3578 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3579 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3580 eeprom_ver);
3581 } else {
3582 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3583 }
3584
3585 return pos;
3741} 3586}
3742 3587
3743static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); 3588static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
@@ -4106,7 +3951,7 @@ static ssize_t show_statistics(struct device *d,
4106 struct device_attribute *attr, char *buf) 3951 struct device_attribute *attr, char *buf)
4107{ 3952{
4108 struct iwl_priv *priv = dev_get_drvdata(d); 3953 struct iwl_priv *priv = dev_get_drvdata(d);
4109 u32 size = sizeof(struct iwl4965_notif_statistics); 3954 u32 size = sizeof(struct iwl_notif_statistics);
4110 u32 len = 0, ofs = 0; 3955 u32 len = 0, ofs = 0;
4111 u8 *data = (u8 *) & priv->statistics; 3956 u8 *data = (u8 *) & priv->statistics;
4112 int rc = 0; 3957 int rc = 0;
@@ -4243,7 +4088,6 @@ static struct ieee80211_ops iwl4965_hw_ops = {
4243 .get_stats = iwl4965_mac_get_stats, 4088 .get_stats = iwl4965_mac_get_stats,
4244 .get_tx_stats = iwl4965_mac_get_tx_stats, 4089 .get_tx_stats = iwl4965_mac_get_tx_stats,
4245 .conf_tx = iwl4965_mac_conf_tx, 4090 .conf_tx = iwl4965_mac_conf_tx,
4246 .get_tsf = iwl4965_mac_get_tsf,
4247 .reset_tsf = iwl4965_mac_reset_tsf, 4091 .reset_tsf = iwl4965_mac_reset_tsf,
4248 .beacon_update = iwl4965_mac_beacon_update, 4092 .beacon_update = iwl4965_mac_beacon_update,
4249 .bss_info_changed = iwl4965_bss_info_changed, 4093 .bss_info_changed = iwl4965_bss_info_changed,
@@ -4372,8 +4216,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4372 /************************ 4216 /************************
4373 * 5. Setup HW constants 4217 * 5. Setup HW constants
4374 ************************/ 4218 ************************/
4375 /* Device-specific setup */ 4219 if (iwl_set_hw_params(priv)) {
4376 if (priv->cfg->ops->lib->set_hw_params(priv)) {
4377 IWL_ERROR("failed to set hw parameters\n"); 4220 IWL_ERROR("failed to set hw parameters\n");
4378 goto out_free_eeprom; 4221 goto out_free_eeprom;
4379 } 4222 }
@@ -4412,7 +4255,7 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4412 4255
4413 4256
4414 iwl_setup_deferred_work(priv); 4257 iwl_setup_deferred_work(priv);
4415 iwl4965_setup_rx_handlers(priv); 4258 iwl_setup_rx_handlers(priv);
4416 4259
4417 /******************** 4260 /********************
4418 * 9. Conclude 4261 * 9. Conclude
@@ -4461,8 +4304,6 @@ static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4461static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) 4304static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4462{ 4305{
4463 struct iwl_priv *priv = pci_get_drvdata(pdev); 4306 struct iwl_priv *priv = pci_get_drvdata(pdev);
4464 struct list_head *p, *q;
4465 int i;
4466 unsigned long flags; 4307 unsigned long flags;
4467 4308
4468 if (!priv) 4309 if (!priv)
@@ -4491,14 +4332,6 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4491 4332
4492 iwl_synchronize_irq(priv); 4333 iwl_synchronize_irq(priv);
4493 4334
4494 /* Free MAC hash list for ADHOC */
4495 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
4496 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
4497 list_del(p);
4498 kfree(list_entry(p, struct iwl4965_ibss_seq, list));
4499 }
4500 }
4501
4502 iwl_rfkill_unregister(priv); 4335 iwl_rfkill_unregister(priv);
4503 iwl4965_dealloc_ucode_pci(priv); 4336 iwl4965_dealloc_ucode_pci(priv);
4504 4337
@@ -4506,7 +4339,7 @@ static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
4506 iwl_rx_queue_free(priv, &priv->rxq); 4339 iwl_rx_queue_free(priv, &priv->rxq);
4507 iwl_hw_txq_ctx_free(priv); 4340 iwl_hw_txq_ctx_free(priv);
4508 4341
4509 iwlcore_clear_stations_table(priv); 4342 iwl_clear_stations_table(priv);
4510 iwl_eeprom_free(priv); 4343 iwl_eeprom_free(priv);
4511 4344
4512 4345