aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-3945.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-3945.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c361
1 files changed, 217 insertions, 144 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 0728054a22d4..068f7f8435c5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -50,6 +50,7 @@
50#include "iwl-helpers.h" 50#include "iwl-helpers.h"
51#include "iwl-led.h" 51#include "iwl-led.h"
52#include "iwl-3945-led.h" 52#include "iwl-3945-led.h"
53#include "iwl-3945-debugfs.h"
53 54
54#define IWL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \ 55#define IWL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \
55 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ 56 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
@@ -192,12 +193,12 @@ static int iwl3945_hwrate_to_plcp_idx(u8 plcp)
192} 193}
193 194
194#ifdef CONFIG_IWLWIFI_DEBUG 195#ifdef CONFIG_IWLWIFI_DEBUG
195#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x 196#define TX_STATUS_ENTRY(x) case TX_3945_STATUS_FAIL_ ## x: return #x
196 197
197static const char *iwl3945_get_tx_fail_reason(u32 status) 198static const char *iwl3945_get_tx_fail_reason(u32 status)
198{ 199{
199 switch (status & TX_STATUS_MSK) { 200 switch (status & TX_STATUS_MSK) {
200 case TX_STATUS_SUCCESS: 201 case TX_3945_STATUS_SUCCESS:
201 return "SUCCESS"; 202 return "SUCCESS";
202 TX_STATUS_ENTRY(SHORT_LIMIT); 203 TX_STATUS_ENTRY(SHORT_LIMIT);
203 TX_STATUS_ENTRY(LONG_LIMIT); 204 TX_STATUS_ENTRY(LONG_LIMIT);
@@ -243,7 +244,7 @@ int iwl3945_rs_next_rate(struct iwl_priv *priv, int rate)
243 next_rate = IWL_RATE_6M_INDEX; 244 next_rate = IWL_RATE_6M_INDEX;
244 break; 245 break;
245 case IEEE80211_BAND_2GHZ: 246 case IEEE80211_BAND_2GHZ:
246 if (!(priv->sta_supp_rates & IWL_OFDM_RATES_MASK) && 247 if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) &&
247 iwl_is_associated(priv)) { 248 iwl_is_associated(priv)) {
248 if (rate == IWL_RATE_11M_INDEX) 249 if (rate == IWL_RATE_11M_INDEX)
249 next_rate = IWL_RATE_5M_INDEX; 250 next_rate = IWL_RATE_5M_INDEX;
@@ -293,7 +294,7 @@ static void iwl3945_tx_queue_reclaim(struct iwl_priv *priv,
293 * iwl3945_rx_reply_tx - Handle Tx response 294 * iwl3945_rx_reply_tx - Handle Tx response
294 */ 295 */
295static void iwl3945_rx_reply_tx(struct iwl_priv *priv, 296static void iwl3945_rx_reply_tx(struct iwl_priv *priv,
296 struct iwl_rx_mem_buffer *rxb) 297 struct iwl_rx_mem_buffer *rxb)
297{ 298{
298 struct iwl_rx_packet *pkt = rxb_addr(rxb); 299 struct iwl_rx_packet *pkt = rxb_addr(rxb);
299 u16 sequence = le16_to_cpu(pkt->hdr.sequence); 300 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
@@ -351,18 +352,143 @@ static void iwl3945_rx_reply_tx(struct iwl_priv *priv,
351 * RX handler implementations 352 * RX handler implementations
352 * 353 *
353 *****************************************************************************/ 354 *****************************************************************************/
355#ifdef CONFIG_IWLWIFI_DEBUG
356/*
357 * based on the assumption of all statistics counter are in DWORD
358 * FIXME: This function is for debugging, do not deal with
359 * the case of counters roll-over.
360 */
361static void iwl3945_accumulative_statistics(struct iwl_priv *priv,
362 __le32 *stats)
363{
364 int i;
365 __le32 *prev_stats;
366 u32 *accum_stats;
367 u32 *delta, *max_delta;
368
369 prev_stats = (__le32 *)&priv->_3945.statistics;
370 accum_stats = (u32 *)&priv->_3945.accum_statistics;
371 delta = (u32 *)&priv->_3945.delta_statistics;
372 max_delta = (u32 *)&priv->_3945.max_delta;
373
374 for (i = sizeof(__le32); i < sizeof(struct iwl3945_notif_statistics);
375 i += sizeof(__le32), stats++, prev_stats++, delta++,
376 max_delta++, accum_stats++) {
377 if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
378 *delta = (le32_to_cpu(*stats) -
379 le32_to_cpu(*prev_stats));
380 *accum_stats += *delta;
381 if (*delta > *max_delta)
382 *max_delta = *delta;
383 }
384 }
385
386 /* reset accumulative statistics for "no-counter" type statistics */
387 priv->_3945.accum_statistics.general.temperature =
388 priv->_3945.statistics.general.temperature;
389 priv->_3945.accum_statistics.general.ttl_timestamp =
390 priv->_3945.statistics.general.ttl_timestamp;
391}
392#endif
393
394/**
395 * iwl3945_good_plcp_health - checks for plcp error.
396 *
397 * When the plcp error is exceeding the thresholds, reset the radio
398 * to improve the throughput.
399 */
400static bool iwl3945_good_plcp_health(struct iwl_priv *priv,
401 struct iwl_rx_packet *pkt)
402{
403 bool rc = true;
404 struct iwl3945_notif_statistics current_stat;
405 int combined_plcp_delta;
406 unsigned int plcp_msec;
407 unsigned long plcp_received_jiffies;
408
409 memcpy(&current_stat, pkt->u.raw, sizeof(struct
410 iwl3945_notif_statistics));
411 /*
412 * check for plcp_err and trigger radio reset if it exceeds
413 * the plcp error threshold plcp_delta.
414 */
415 plcp_received_jiffies = jiffies;
416 plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
417 (long) priv->plcp_jiffies);
418 priv->plcp_jiffies = plcp_received_jiffies;
419 /*
420 * check to make sure plcp_msec is not 0 to prevent division
421 * by zero.
422 */
423 if (plcp_msec) {
424 combined_plcp_delta =
425 (le32_to_cpu(current_stat.rx.ofdm.plcp_err) -
426 le32_to_cpu(priv->_3945.statistics.rx.ofdm.plcp_err));
427
428 if ((combined_plcp_delta > 0) &&
429 ((combined_plcp_delta * 100) / plcp_msec) >
430 priv->cfg->plcp_delta_threshold) {
431 /*
432 * if plcp_err exceed the threshold, the following
433 * data is printed in csv format:
434 * Text: plcp_err exceeded %d,
435 * Received ofdm.plcp_err,
436 * Current ofdm.plcp_err,
437 * combined_plcp_delta,
438 * plcp_msec
439 */
440 IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
441 "%u, %d, %u mSecs\n",
442 priv->cfg->plcp_delta_threshold,
443 le32_to_cpu(current_stat.rx.ofdm.plcp_err),
444 combined_plcp_delta, plcp_msec);
445 /*
446 * Reset the RF radio due to the high plcp
447 * error rate
448 */
449 rc = false;
450 }
451 }
452 return rc;
453}
354 454
355void iwl3945_hw_rx_statistics(struct iwl_priv *priv, 455void iwl3945_hw_rx_statistics(struct iwl_priv *priv,
356 struct iwl_rx_mem_buffer *rxb) 456 struct iwl_rx_mem_buffer *rxb)
357{ 457{
358 struct iwl_rx_packet *pkt = rxb_addr(rxb); 458 struct iwl_rx_packet *pkt = rxb_addr(rxb);
459
359 IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n", 460 IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
360 (int)sizeof(struct iwl3945_notif_statistics), 461 (int)sizeof(struct iwl3945_notif_statistics),
361 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK); 462 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
463#ifdef CONFIG_IWLWIFI_DEBUG
464 iwl3945_accumulative_statistics(priv, (__le32 *)&pkt->u.raw);
465#endif
466 iwl_recover_from_statistics(priv, pkt);
467
468 memcpy(&priv->_3945.statistics, pkt->u.raw, sizeof(priv->_3945.statistics));
469}
470
471void iwl3945_reply_statistics(struct iwl_priv *priv,
472 struct iwl_rx_mem_buffer *rxb)
473{
474 struct iwl_rx_packet *pkt = rxb_addr(rxb);
475 __le32 *flag = (__le32 *)&pkt->u.raw;
362 476
363 memcpy(&priv->statistics_39, pkt->u.raw, sizeof(priv->statistics_39)); 477 if (le32_to_cpu(*flag) & UCODE_STATISTICS_CLEAR_MSK) {
478#ifdef CONFIG_IWLWIFI_DEBUG
479 memset(&priv->_3945.accum_statistics, 0,
480 sizeof(struct iwl3945_notif_statistics));
481 memset(&priv->_3945.delta_statistics, 0,
482 sizeof(struct iwl3945_notif_statistics));
483 memset(&priv->_3945.max_delta, 0,
484 sizeof(struct iwl3945_notif_statistics));
485#endif
486 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
487 }
488 iwl3945_hw_rx_statistics(priv, rxb);
364} 489}
365 490
491
366/****************************************************************************** 492/******************************************************************************
367 * 493 *
368 * Misc. internal state and helper functions 494 * Misc. internal state and helper functions
@@ -487,7 +613,7 @@ static void _iwl3945_dbg_report_frame(struct iwl_priv *priv,
487 * but you can hack it to show more, if you'd like to. */ 613 * but you can hack it to show more, if you'd like to. */
488 if (dataframe) 614 if (dataframe)
489 IWL_DEBUG_RX(priv, "%s: mhd=0x%04x, dst=0x%02x, " 615 IWL_DEBUG_RX(priv, "%s: mhd=0x%04x, dst=0x%02x, "
490 "len=%u, rssi=%d, chnl=%d, rate=%d, \n", 616 "len=%u, rssi=%d, chnl=%d, rate=%d,\n",
491 title, le16_to_cpu(fc), header->addr1[5], 617 title, le16_to_cpu(fc), header->addr1[5],
492 length, rssi, channel, rate); 618 length, rssi, channel, rate);
493 else { 619 else {
@@ -549,7 +675,6 @@ static void iwl3945_pass_packet_to_mac80211(struct iwl_priv *priv,
549 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); 675 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
550 u16 len = le16_to_cpu(rx_hdr->len); 676 u16 len = le16_to_cpu(rx_hdr->len);
551 struct sk_buff *skb; 677 struct sk_buff *skb;
552 int ret;
553 __le16 fc = hdr->frame_control; 678 __le16 fc = hdr->frame_control;
554 679
555 /* We received data from the HW, so stop the watchdog */ 680 /* We received data from the HW, so stop the watchdog */
@@ -566,9 +691,9 @@ static void iwl3945_pass_packet_to_mac80211(struct iwl_priv *priv,
566 return; 691 return;
567 } 692 }
568 693
569 skb = alloc_skb(IWL_LINK_HDR_MAX * 2, GFP_ATOMIC); 694 skb = dev_alloc_skb(128);
570 if (!skb) { 695 if (!skb) {
571 IWL_ERR(priv, "alloc_skb failed\n"); 696 IWL_ERR(priv, "dev_alloc_skb failed\n");
572 return; 697 return;
573 } 698 }
574 699
@@ -577,37 +702,13 @@ static void iwl3945_pass_packet_to_mac80211(struct iwl_priv *priv,
577 (struct ieee80211_hdr *)rxb_addr(rxb), 702 (struct ieee80211_hdr *)rxb_addr(rxb),
578 le32_to_cpu(rx_end->status), stats); 703 le32_to_cpu(rx_end->status), stats);
579 704
580 skb_reserve(skb, IWL_LINK_HDR_MAX);
581 skb_add_rx_frag(skb, 0, rxb->page, 705 skb_add_rx_frag(skb, 0, rxb->page,
582 (void *)rx_hdr->payload - (void *)pkt, len); 706 (void *)rx_hdr->payload - (void *)pkt, len);
583 707
584 /* mac80211 currently doesn't support paged SKB. Convert it to
585 * linear SKB for management frame and data frame requires
586 * software decryption or software defragementation. */
587 if (ieee80211_is_mgmt(fc) ||
588 ieee80211_has_protected(fc) ||
589 ieee80211_has_morefrags(fc) ||
590 le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG)
591 ret = skb_linearize(skb);
592 else
593 ret = __pskb_pull_tail(skb, min_t(u16, IWL_LINK_HDR_MAX, len)) ?
594 0 : -ENOMEM;
595
596 if (ret) {
597 kfree_skb(skb);
598 goto out;
599 }
600
601 /*
602 * XXX: We cannot touch the page and its virtual memory (pkt) after
603 * here. It might have already been freed by the above skb change.
604 */
605
606 iwl_update_stats(priv, false, fc, len); 708 iwl_update_stats(priv, false, fc, len);
607 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); 709 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
608 710
609 ieee80211_rx(priv->hw, skb); 711 ieee80211_rx(priv->hw, skb);
610 out:
611 priv->alloc_rxb_page--; 712 priv->alloc_rxb_page--;
612 rxb->page = NULL; 713 rxb->page = NULL;
613} 714}
@@ -623,9 +724,8 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv,
623 struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); 724 struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
624 struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); 725 struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
625 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); 726 struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
626 int snr; 727 u16 rx_stats_sig_avg __maybe_unused = le16_to_cpu(rx_stats->sig_avg);
627 u16 rx_stats_sig_avg = le16_to_cpu(rx_stats->sig_avg); 728 u16 rx_stats_noise_diff __maybe_unused = le16_to_cpu(rx_stats->noise_diff);
628 u16 rx_stats_noise_diff = le16_to_cpu(rx_stats->noise_diff);
629 u8 network_packet; 729 u8 network_packet;
630 730
631 rx_status.flag = 0; 731 rx_status.flag = 0;
@@ -663,53 +763,29 @@ static void iwl3945_rx_reply_rx(struct iwl_priv *priv,
663 /* Convert 3945's rssi indicator to dBm */ 763 /* Convert 3945's rssi indicator to dBm */
664 rx_status.signal = rx_stats->rssi - IWL39_RSSI_OFFSET; 764 rx_status.signal = rx_stats->rssi - IWL39_RSSI_OFFSET;
665 765
666 /* Set default noise value to -127 */ 766 IWL_DEBUG_STATS(priv, "Rssi %d sig_avg %d noise_diff %d\n",
667 if (priv->last_rx_noise == 0) 767 rx_status.signal, rx_stats_sig_avg,
668 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; 768 rx_stats_noise_diff);
669
670 /* 3945 provides noise info for OFDM frames only.
671 * sig_avg and noise_diff are measured by the 3945's digital signal
672 * processor (DSP), and indicate linear levels of signal level and
673 * distortion/noise within the packet preamble after
674 * automatic gain control (AGC). sig_avg should stay fairly
675 * constant if the radio's AGC is working well.
676 * Since these values are linear (not dB or dBm), linear
677 * signal-to-noise ratio (SNR) is (sig_avg / noise_diff).
678 * Convert linear SNR to dB SNR, then subtract that from rssi dBm
679 * to obtain noise level in dBm.
680 * Calculate rx_status.signal (quality indicator in %) based on SNR. */
681 if (rx_stats_noise_diff) {
682 snr = rx_stats_sig_avg / rx_stats_noise_diff;
683 rx_status.noise = rx_status.signal -
684 iwl3945_calc_db_from_ratio(snr);
685 } else {
686 rx_status.noise = priv->last_rx_noise;
687 }
688
689
690 IWL_DEBUG_STATS(priv, "Rssi %d noise %d sig_avg %d noise_diff %d\n",
691 rx_status.signal, rx_status.noise,
692 rx_stats_sig_avg, rx_stats_noise_diff);
693 769
694 header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt); 770 header = (struct ieee80211_hdr *)IWL_RX_DATA(pkt);
695 771
696 network_packet = iwl3945_is_network_packet(priv, header); 772 network_packet = iwl3945_is_network_packet(priv, header);
697 773
698 IWL_DEBUG_STATS_LIMIT(priv, "[%c] %d RSSI:%d Signal:%u, Noise:%u, Rate:%u\n", 774 IWL_DEBUG_STATS_LIMIT(priv, "[%c] %d RSSI:%d Signal:%u, Rate:%u\n",
699 network_packet ? '*' : ' ', 775 network_packet ? '*' : ' ',
700 le16_to_cpu(rx_hdr->channel), 776 le16_to_cpu(rx_hdr->channel),
701 rx_status.signal, rx_status.signal, 777 rx_status.signal, rx_status.signal,
702 rx_status.noise, rx_status.rate_idx); 778 rx_status.rate_idx);
703 779
704 /* Set "1" to report good data frames in groups of 100 */ 780 /* Set "1" to report good data frames in groups of 100 */
705 iwl3945_dbg_report_frame(priv, pkt, header, 1); 781 iwl3945_dbg_report_frame(priv, pkt, header, 1);
706 iwl_dbg_log_rx_data_frame(priv, le16_to_cpu(rx_hdr->len), header); 782 iwl_dbg_log_rx_data_frame(priv, le16_to_cpu(rx_hdr->len), header);
707 783
708 if (network_packet) { 784 if (network_packet) {
709 priv->last_beacon_time = le32_to_cpu(rx_end->beacon_timestamp); 785 priv->_3945.last_beacon_time =
710 priv->last_tsf = le64_to_cpu(rx_end->timestamp); 786 le32_to_cpu(rx_end->beacon_timestamp);
711 priv->last_rx_rssi = rx_status.signal; 787 priv->_3945.last_tsf = le64_to_cpu(rx_end->timestamp);
712 priv->last_rx_noise = rx_status.noise; 788 priv->_3945.last_rx_rssi = rx_status.signal;
713 } 789 }
714 790
715 iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status); 791 iwl3945_pass_packet_to_mac80211(priv, rxb, &rx_status);
@@ -871,7 +947,8 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl_priv *priv,
871 tx_cmd->supp_rates[1], tx_cmd->supp_rates[0]); 947 tx_cmd->supp_rates[1], tx_cmd->supp_rates[0]);
872} 948}
873 949
874u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id, u16 tx_rate, u8 flags) 950static u8 iwl3945_sync_sta(struct iwl_priv *priv, int sta_id,
951 u16 tx_rate, u8 flags)
875{ 952{
876 unsigned long flags_spin; 953 unsigned long flags_spin;
877 struct iwl_station_entry *station; 954 struct iwl_station_entry *station;
@@ -957,7 +1034,7 @@ static int iwl3945_tx_reset(struct iwl_priv *priv)
957 iwl_write_prph(priv, ALM_SCD_TXF5MF_REG, 0x000005); 1034 iwl_write_prph(priv, ALM_SCD_TXF5MF_REG, 0x000005);
958 1035
959 iwl_write_direct32(priv, FH39_TSSR_CBB_BASE, 1036 iwl_write_direct32(priv, FH39_TSSR_CBB_BASE,
960 priv->shared_phys); 1037 priv->_3945.shared_phys);
961 1038
962 iwl_write_direct32(priv, FH39_TSSR_MSG_CONFIG, 1039 iwl_write_direct32(priv, FH39_TSSR_MSG_CONFIG,
963 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON | 1040 FH39_TSSR_TX_MSG_CONFIG_REG_VAL_SNOOP_RD_TXPD_ON |
@@ -1049,7 +1126,7 @@ static void iwl3945_nic_config(struct iwl_priv *priv)
1049 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id); 1126 IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", rev_id);
1050 1127
1051 if (rev_id & PCI_CFG_REV_ID_BIT_RTP) 1128 if (rev_id & PCI_CFG_REV_ID_BIT_RTP)
1052 IWL_DEBUG_INFO(priv, "RTP type \n"); 1129 IWL_DEBUG_INFO(priv, "RTP type\n");
1053 else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) { 1130 else if (rev_id & PCI_CFG_REV_ID_BIT_BASIC_SKU) {
1054 IWL_DEBUG_INFO(priv, "3945 RADIO-MB type\n"); 1131 IWL_DEBUG_INFO(priv, "3945 RADIO-MB type\n");
1055 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, 1132 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
@@ -1607,7 +1684,7 @@ static int iwl3945_hw_reg_set_new_power(struct iwl_priv *priv,
1607 int power; 1684 int power;
1608 1685
1609 /* Get this chnlgrp's rate-to-max/clip-powers table */ 1686 /* Get this chnlgrp's rate-to-max/clip-powers table */
1610 clip_pwrs = priv->clip39_groups[ch_info->group_index].clip_powers; 1687 clip_pwrs = priv->_3945.clip_groups[ch_info->group_index].clip_powers;
1611 1688
1612 /* Get this channel's rate-to-current-power settings table */ 1689 /* Get this channel's rate-to-current-power settings table */
1613 power_info = ch_info->power_info; 1690 power_info = ch_info->power_info;
@@ -1701,6 +1778,11 @@ static int iwl3945_hw_reg_comp_txpower_temp(struct iwl_priv *priv)
1701 int ref_temp; 1778 int ref_temp;
1702 int temperature = priv->temperature; 1779 int temperature = priv->temperature;
1703 1780
1781 if (priv->disable_tx_power_cal ||
1782 test_bit(STATUS_SCANNING, &priv->status)) {
1783 /* do not perform tx power calibration */
1784 return 0;
1785 }
1704 /* set up new Tx power info for each and every channel, 2.4 and 5.x */ 1786 /* set up new Tx power info for each and every channel, 2.4 and 5.x */
1705 for (i = 0; i < priv->channel_count; i++) { 1787 for (i = 0; i < priv->channel_count; i++) {
1706 ch_info = &priv->channel_info[i]; 1788 ch_info = &priv->channel_info[i];
@@ -1733,7 +1815,7 @@ static int iwl3945_hw_reg_comp_txpower_temp(struct iwl_priv *priv)
1733 } 1815 }
1734 1816
1735 /* Get this chnlgrp's rate-to-max/clip-powers table */ 1817 /* Get this chnlgrp's rate-to-max/clip-powers table */
1736 clip_pwrs = priv->clip39_groups[ch_info->group_index].clip_powers; 1818 clip_pwrs = priv->_3945.clip_groups[ch_info->group_index].clip_powers;
1737 1819
1738 /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */ 1820 /* set scan tx power, 1Mbit for CCK, 6Mbit for OFDM */
1739 for (scan_tbl_index = 0; 1821 for (scan_tbl_index = 0;
@@ -1911,6 +1993,8 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1911 "configuration (%d).\n", rc); 1993 "configuration (%d).\n", rc);
1912 return rc; 1994 return rc;
1913 } 1995 }
1996 iwl_clear_ucode_stations(priv);
1997 iwl_restore_stations(priv);
1914 } 1998 }
1915 1999
1916 IWL_DEBUG_INFO(priv, "Sending RXON\n" 2000 IWL_DEBUG_INFO(priv, "Sending RXON\n"
@@ -1941,7 +2025,10 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1941 2025
1942 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon)); 2026 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
1943 2027
1944 iwl_clear_stations_table(priv); 2028 if (!new_assoc) {
2029 iwl_clear_ucode_stations(priv);
2030 iwl_restore_stations(priv);
2031 }
1945 2032
1946 /* If we issue a new RXON command which required a tune then we must 2033 /* If we issue a new RXON command which required a tune then we must
1947 * send a new TXPOWER command or we won't be able to Tx any frames */ 2034 * send a new TXPOWER command or we won't be able to Tx any frames */
@@ -1951,19 +2038,6 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1951 return rc; 2038 return rc;
1952 } 2039 }
1953 2040
1954 /* Add the broadcast address so we can send broadcast frames */
1955 priv->cfg->ops->lib->add_bcast_station(priv);
1956
1957 /* If we have set the ASSOC_MSK and we are in BSS mode then
1958 * add the IWL_AP_ID to the station rate table */
1959 if (iwl_is_associated(priv) &&
1960 (priv->iw_mode == NL80211_IFTYPE_STATION))
1961 if (iwl_add_station(priv, priv->active_rxon.bssid_addr,
1962 true, CMD_SYNC, NULL) == IWL_INVALID_STATION) {
1963 IWL_ERR(priv, "Error adding AP address for transmit\n");
1964 return -EIO;
1965 }
1966
1967 /* Init the hardware's rate fallback order based on the band */ 2041 /* Init the hardware's rate fallback order based on the band */
1968 rc = iwl3945_init_hw_rate_table(priv); 2042 rc = iwl3945_init_hw_rate_table(priv);
1969 if (rc) { 2043 if (rc) {
@@ -1998,13 +2072,13 @@ void iwl3945_reg_txpower_periodic(struct iwl_priv *priv)
1998 2072
1999 reschedule: 2073 reschedule:
2000 queue_delayed_work(priv->workqueue, 2074 queue_delayed_work(priv->workqueue,
2001 &priv->thermal_periodic, REG_RECALIB_PERIOD * HZ); 2075 &priv->_3945.thermal_periodic, REG_RECALIB_PERIOD * HZ);
2002} 2076}
2003 2077
2004static void iwl3945_bg_reg_txpower_periodic(struct work_struct *work) 2078static void iwl3945_bg_reg_txpower_periodic(struct work_struct *work)
2005{ 2079{
2006 struct iwl_priv *priv = container_of(work, struct iwl_priv, 2080 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2007 thermal_periodic.work); 2081 _3945.thermal_periodic.work);
2008 2082
2009 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2083 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2010 return; 2084 return;
@@ -2140,7 +2214,7 @@ static void iwl3945_hw_reg_init_channel_groups(struct iwl_priv *priv)
2140 * power peaks, without too much distortion (clipping). 2214 * power peaks, without too much distortion (clipping).
2141 */ 2215 */
2142 /* we'll fill in this array with h/w max power levels */ 2216 /* we'll fill in this array with h/w max power levels */
2143 clip_pwrs = (s8 *) priv->clip39_groups[i].clip_powers; 2217 clip_pwrs = (s8 *) priv->_3945.clip_groups[i].clip_powers;
2144 2218
2145 /* divide factory saturation power by 2 to find -3dB level */ 2219 /* divide factory saturation power by 2 to find -3dB level */
2146 satur_pwr = (s8) (group->saturation_power >> 1); 2220 satur_pwr = (s8) (group->saturation_power >> 1);
@@ -2224,7 +2298,7 @@ int iwl3945_txpower_set_from_eeprom(struct iwl_priv *priv)
2224 iwl3945_hw_reg_get_ch_grp_index(priv, ch_info); 2298 iwl3945_hw_reg_get_ch_grp_index(priv, ch_info);
2225 2299
2226 /* Get this chnlgrp's rate->max/clip-powers table */ 2300 /* Get this chnlgrp's rate->max/clip-powers table */
2227 clip_pwrs = priv->clip39_groups[ch_info->group_index].clip_powers; 2301 clip_pwrs = priv->_3945.clip_groups[ch_info->group_index].clip_powers;
2228 2302
2229 /* calculate power index *adjustment* value according to 2303 /* calculate power index *adjustment* value according to
2230 * diff between current temperature and factory temperature */ 2304 * diff between current temperature and factory temperature */
@@ -2332,7 +2406,7 @@ int iwl3945_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq)
2332{ 2406{
2333 int txq_id = txq->q.id; 2407 int txq_id = txq->q.id;
2334 2408
2335 struct iwl3945_shared *shared_data = priv->shared_virt; 2409 struct iwl3945_shared *shared_data = priv->_3945.shared_virt;
2336 2410
2337 shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr); 2411 shared_data->tx_base_ptr[txq_id] = cpu_to_le32((u32)txq->q.dma_addr);
2338 2412
@@ -2385,6 +2459,30 @@ static u16 iwl3945_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
2385 return (u16)sizeof(struct iwl3945_addsta_cmd); 2459 return (u16)sizeof(struct iwl3945_addsta_cmd);
2386} 2460}
2387 2461
2462static int iwl3945_manage_ibss_station(struct iwl_priv *priv,
2463 struct ieee80211_vif *vif, bool add)
2464{
2465 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
2466 int ret;
2467
2468 if (add) {
2469 ret = iwl_add_bssid_station(priv, vif->bss_conf.bssid, false,
2470 &vif_priv->ibss_bssid_sta_id);
2471 if (ret)
2472 return ret;
2473
2474 iwl3945_sync_sta(priv, vif_priv->ibss_bssid_sta_id,
2475 (priv->band == IEEE80211_BAND_5GHZ) ?
2476 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
2477 CMD_ASYNC);
2478 iwl3945_rate_scale_init(priv->hw, vif_priv->ibss_bssid_sta_id);
2479
2480 return 0;
2481 }
2482
2483 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
2484 vif->bss_conf.bssid);
2485}
2388 2486
2389/** 2487/**
2390 * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table 2488 * iwl3945_init_hw_rate_table - Initialize the hardware rate fallback table
@@ -2432,7 +2530,7 @@ int iwl3945_init_hw_rate_table(struct iwl_priv *priv)
2432 /* If an OFDM rate is used, have it fall back to the 2530 /* If an OFDM rate is used, have it fall back to the
2433 * 1M CCK rates */ 2531 * 1M CCK rates */
2434 2532
2435 if (!(priv->sta_supp_rates & IWL_OFDM_RATES_MASK) && 2533 if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) &&
2436 iwl_is_associated(priv)) { 2534 iwl_is_associated(priv)) {
2437 2535
2438 index = IWL_FIRST_CCK_RATE; 2536 index = IWL_FIRST_CCK_RATE;
@@ -2471,12 +2569,12 @@ int iwl3945_hw_set_hw_params(struct iwl_priv *priv)
2471 memset((void *)&priv->hw_params, 0, 2569 memset((void *)&priv->hw_params, 0,
2472 sizeof(struct iwl_hw_params)); 2570 sizeof(struct iwl_hw_params));
2473 2571
2474 priv->shared_virt = dma_alloc_coherent(&priv->pci_dev->dev, 2572 priv->_3945.shared_virt =
2475 sizeof(struct iwl3945_shared), 2573 dma_alloc_coherent(&priv->pci_dev->dev,
2476 &priv->shared_phys, GFP_KERNEL); 2574 sizeof(struct iwl3945_shared),
2477 if (!priv->shared_virt) { 2575 &priv->_3945.shared_phys, GFP_KERNEL);
2576 if (!priv->_3945.shared_virt) {
2478 IWL_ERR(priv, "failed to allocate pci memory\n"); 2577 IWL_ERR(priv, "failed to allocate pci memory\n");
2479 mutex_unlock(&priv->mutex);
2480 return -ENOMEM; 2578 return -ENOMEM;
2481 } 2579 }
2482 2580
@@ -2537,13 +2635,13 @@ void iwl3945_hw_rx_handler_setup(struct iwl_priv *priv)
2537 2635
2538void iwl3945_hw_setup_deferred_work(struct iwl_priv *priv) 2636void iwl3945_hw_setup_deferred_work(struct iwl_priv *priv)
2539{ 2637{
2540 INIT_DELAYED_WORK(&priv->thermal_periodic, 2638 INIT_DELAYED_WORK(&priv->_3945.thermal_periodic,
2541 iwl3945_bg_reg_txpower_periodic); 2639 iwl3945_bg_reg_txpower_periodic);
2542} 2640}
2543 2641
2544void iwl3945_hw_cancel_deferred_work(struct iwl_priv *priv) 2642void iwl3945_hw_cancel_deferred_work(struct iwl_priv *priv)
2545{ 2643{
2546 cancel_delayed_work(&priv->thermal_periodic); 2644 cancel_delayed_work(&priv->_3945.thermal_periodic);
2547} 2645}
2548 2646
2549/* check contents of special bootstrap uCode SRAM */ 2647/* check contents of special bootstrap uCode SRAM */
@@ -2714,48 +2812,10 @@ static int iwl3945_load_bsm(struct iwl_priv *priv)
2714 return 0; 2812 return 0;
2715} 2813}
2716 2814
2717#define IWL3945_UCODE_GET(item) \
2718static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode,\
2719 u32 api_ver) \
2720{ \
2721 return le32_to_cpu(ucode->u.v1.item); \
2722}
2723
2724static u32 iwl3945_ucode_get_header_size(u32 api_ver)
2725{
2726 return UCODE_HEADER_SIZE(1);
2727}
2728static u32 iwl3945_ucode_get_build(const struct iwl_ucode_header *ucode,
2729 u32 api_ver)
2730{
2731 return 0;
2732}
2733static u8 *iwl3945_ucode_get_data(const struct iwl_ucode_header *ucode,
2734 u32 api_ver)
2735{
2736 return (u8 *) ucode->u.v1.data;
2737}
2738
2739IWL3945_UCODE_GET(inst_size);
2740IWL3945_UCODE_GET(data_size);
2741IWL3945_UCODE_GET(init_size);
2742IWL3945_UCODE_GET(init_data_size);
2743IWL3945_UCODE_GET(boot_size);
2744
2745static struct iwl_hcmd_ops iwl3945_hcmd = { 2815static struct iwl_hcmd_ops iwl3945_hcmd = {
2746 .rxon_assoc = iwl3945_send_rxon_assoc, 2816 .rxon_assoc = iwl3945_send_rxon_assoc,
2747 .commit_rxon = iwl3945_commit_rxon, 2817 .commit_rxon = iwl3945_commit_rxon,
2748}; 2818 .send_bt_config = iwl_send_bt_config,
2749
2750static struct iwl_ucode_ops iwl3945_ucode = {
2751 .get_header_size = iwl3945_ucode_get_header_size,
2752 .get_build = iwl3945_ucode_get_build,
2753 .get_inst_size = iwl3945_ucode_get_inst_size,
2754 .get_data_size = iwl3945_ucode_get_data_size,
2755 .get_init_size = iwl3945_ucode_get_init_size,
2756 .get_init_data_size = iwl3945_ucode_get_init_data_size,
2757 .get_boot_size = iwl3945_ucode_get_boot_size,
2758 .get_data = iwl3945_ucode_get_data,
2759}; 2819};
2760 2820
2761static struct iwl_lib_ops iwl3945_lib = { 2821static struct iwl_lib_ops iwl3945_lib = {
@@ -2791,17 +2851,24 @@ static struct iwl_lib_ops iwl3945_lib = {
2791 .post_associate = iwl3945_post_associate, 2851 .post_associate = iwl3945_post_associate,
2792 .isr = iwl_isr_legacy, 2852 .isr = iwl_isr_legacy,
2793 .config_ap = iwl3945_config_ap, 2853 .config_ap = iwl3945_config_ap,
2794 .add_bcast_station = iwl3945_add_bcast_station, 2854 .manage_ibss_station = iwl3945_manage_ibss_station,
2855 .check_plcp_health = iwl3945_good_plcp_health,
2856
2857 .debugfs_ops = {
2858 .rx_stats_read = iwl3945_ucode_rx_stats_read,
2859 .tx_stats_read = iwl3945_ucode_tx_stats_read,
2860 .general_stats_read = iwl3945_ucode_general_stats_read,
2861 },
2795}; 2862};
2796 2863
2797static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { 2864static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
2798 .get_hcmd_size = iwl3945_get_hcmd_size, 2865 .get_hcmd_size = iwl3945_get_hcmd_size,
2799 .build_addsta_hcmd = iwl3945_build_addsta_hcmd, 2866 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
2800 .rts_tx_cmd_flag = iwlcore_rts_tx_cmd_flag, 2867 .rts_tx_cmd_flag = iwlcore_rts_tx_cmd_flag,
2868 .request_scan = iwl3945_request_scan,
2801}; 2869};
2802 2870
2803static const struct iwl_ops iwl3945_ops = { 2871static const struct iwl_ops iwl3945_ops = {
2804 .ucode = &iwl3945_ucode,
2805 .lib = &iwl3945_lib, 2872 .lib = &iwl3945_lib,
2806 .hcmd = &iwl3945_hcmd, 2873 .hcmd = &iwl3945_hcmd,
2807 .utils = &iwl3945_hcmd_utils, 2874 .utils = &iwl3945_hcmd_utils,
@@ -2826,7 +2893,10 @@ static struct iwl_cfg iwl3945_bg_cfg = {
2826 .ht_greenfield_support = false, 2893 .ht_greenfield_support = false,
2827 .led_compensation = 64, 2894 .led_compensation = 64,
2828 .broken_powersave = true, 2895 .broken_powersave = true,
2829 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 2896 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
2897 .monitor_recover_period = IWL_MONITORING_PERIOD,
2898 .max_event_log_size = 512,
2899 .tx_power_by_driver = true,
2830}; 2900};
2831 2901
2832static struct iwl_cfg iwl3945_abg_cfg = { 2902static struct iwl_cfg iwl3945_abg_cfg = {
@@ -2844,7 +2914,10 @@ static struct iwl_cfg iwl3945_abg_cfg = {
2844 .ht_greenfield_support = false, 2914 .ht_greenfield_support = false,
2845 .led_compensation = 64, 2915 .led_compensation = 64,
2846 .broken_powersave = true, 2916 .broken_powersave = true,
2847 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, 2917 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
2918 .monitor_recover_period = IWL_MONITORING_PERIOD,
2919 .max_event_log_size = 512,
2920 .tx_power_by_driver = true,
2848}; 2921};
2849 2922
2850DEFINE_PCI_DEVICE_TABLE(iwl3945_hw_card_ids) = { 2923DEFINE_PCI_DEVICE_TABLE(iwl3945_hw_card_ids) = {