aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-3945-rs.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c200
1 files changed, 49 insertions, 151 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index 10c64bdb314..6fc5e7361f2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -36,8 +36,6 @@
36 36
37#include <linux/workqueue.h> 37#include <linux/workqueue.h>
38 38
39#include "../net/mac80211/rate.h"
40
41#include "iwl-3945.h" 39#include "iwl-3945.h"
42 40
43#define RS_NAME "iwl-3945-rs" 41#define RS_NAME "iwl-3945-rs"
@@ -65,6 +63,9 @@ struct iwl3945_rs_sta {
65 u8 ibss_sta_added; 63 u8 ibss_sta_added;
66 struct timer_list rate_scale_flush; 64 struct timer_list rate_scale_flush;
67 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT]; 65 struct iwl3945_rate_scale_data win[IWL_RATE_COUNT];
66
67 /* used to be in sta_info */
68 int last_txrate_idx;
68}; 69};
69 70
70static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = { 71static s32 iwl3945_expected_tpt_g[IWL_RATE_COUNT] = {
@@ -316,9 +317,10 @@ static void iwl3945_collect_tx_data(struct iwl3945_rs_sta *rs_sta,
316 } 317 }
317} 318}
318 319
319static void rs_rate_init(void *priv_rate, void *priv_sta, 320static void rs_rate_init(void *priv, struct ieee80211_supported_band *sband,
320 struct ieee80211_local *local, struct sta_info *sta) 321 struct ieee80211_sta *sta, void *priv_sta)
321{ 322{
323 struct iwl3945_rs_sta *rs_sta = priv_sta;
322 int i; 324 int i;
323 325
324 IWL_DEBUG_RATE("enter\n"); 326 IWL_DEBUG_RATE("enter\n");
@@ -329,24 +331,22 @@ static void rs_rate_init(void *priv_rate, void *priv_sta,
329 * after assoc.. */ 331 * after assoc.. */
330 332
331 for (i = IWL_RATE_COUNT - 1; i >= 0; i--) { 333 for (i = IWL_RATE_COUNT - 1; i >= 0; i--) {
332 if (sta->supp_rates[local->hw.conf.channel->band] & (1 << i)) { 334 if (sta->supp_rates[sband->band] & (1 << i)) {
333 sta->txrate_idx = i; 335 rs_sta->last_txrate_idx = i;
334 break; 336 break;
335 } 337 }
336 } 338 }
337 339
338 sta->last_txrate_idx = sta->txrate_idx;
339
340 /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */ 340 /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */
341 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) 341 if (sband->band == IEEE80211_BAND_5GHZ)
342 sta->last_txrate_idx += IWL_FIRST_OFDM_RATE; 342 rs_sta->last_txrate_idx += IWL_FIRST_OFDM_RATE;
343 343
344 IWL_DEBUG_RATE("leave\n"); 344 IWL_DEBUG_RATE("leave\n");
345} 345}
346 346
347static void *rs_alloc(struct ieee80211_local *local) 347static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
348{ 348{
349 return local->hw.priv; 349 return hw->priv;
350} 350}
351 351
352/* rate scale requires free function to be implemented */ 352/* rate scale requires free function to be implemented */
@@ -354,17 +354,24 @@ static void rs_free(void *priv)
354{ 354{
355 return; 355 return;
356} 356}
357
357static void rs_clear(void *priv) 358static void rs_clear(void *priv)
358{ 359{
359 return; 360 return;
360} 361}
361 362
362 363
363static void *rs_alloc_sta(void *priv, gfp_t gfp) 364static void *rs_alloc_sta(void *priv, struct ieee80211_sta *sta, gfp_t gfp)
364{ 365{
365 struct iwl3945_rs_sta *rs_sta; 366 struct iwl3945_rs_sta *rs_sta;
367 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
366 int i; 368 int i;
367 369
370 /*
371 * XXX: If it's using sta->drv_priv anyway, it might
372 * as well just put all the information there.
373 */
374
368 IWL_DEBUG_RATE("enter\n"); 375 IWL_DEBUG_RATE("enter\n");
369 376
370 rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp); 377 rs_sta = kzalloc(sizeof(struct iwl3945_rs_sta), gfp);
@@ -373,6 +380,8 @@ static void *rs_alloc_sta(void *priv, gfp_t gfp)
373 return NULL; 380 return NULL;
374 } 381 }
375 382
383 psta->rs_sta = rs_sta;
384
376 spin_lock_init(&rs_sta->lock); 385 spin_lock_init(&rs_sta->lock);
377 386
378 rs_sta->start_rate = IWL_RATE_INVALID; 387 rs_sta->start_rate = IWL_RATE_INVALID;
@@ -398,10 +407,14 @@ static void *rs_alloc_sta(void *priv, gfp_t gfp)
398 return rs_sta; 407 return rs_sta;
399} 408}
400 409
401static void rs_free_sta(void *priv, void *priv_sta) 410static void rs_free_sta(void *priv, struct ieee80211_sta *sta,
411 void *priv_sta)
402{ 412{
413 struct iwl3945_sta_priv *psta = (void *) sta->drv_priv;
403 struct iwl3945_rs_sta *rs_sta = priv_sta; 414 struct iwl3945_rs_sta *rs_sta = priv_sta;
404 415
416 psta->rs_sta = NULL;
417
405 IWL_DEBUG_RATE("enter\n"); 418 IWL_DEBUG_RATE("enter\n");
406 del_timer_sync(&rs_sta->rate_scale_flush); 419 del_timer_sync(&rs_sta->rate_scale_flush);
407 kfree(rs_sta); 420 kfree(rs_sta);
@@ -443,26 +456,19 @@ static int rs_adjust_next_rate(struct iwl3945_priv *priv, int rate)
443 * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by 456 * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by
444 * the hardware for each rate. 457 * the hardware for each rate.
445 */ 458 */
446static void rs_tx_status(void *priv_rate, 459static void rs_tx_status(void *priv_rate, struct ieee80211_supported_band *sband,
447 struct net_device *dev, 460 struct ieee80211_sta *sta, void *priv_sta,
448 struct sk_buff *skb) 461 struct sk_buff *skb)
449{ 462{
450 u8 retries, current_count; 463 u8 retries, current_count;
451 int scale_rate_index, first_index, last_index; 464 int scale_rate_index, first_index, last_index;
452 unsigned long flags; 465 unsigned long flags;
453 struct sta_info *sta;
454 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
455 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; 466 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate;
456 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 467 struct iwl3945_rs_sta *rs_sta = priv_sta;
457 struct iwl3945_rs_sta *rs_sta;
458 struct ieee80211_supported_band *sband;
459 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 468 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
460 469
461 IWL_DEBUG_RATE("enter\n"); 470 IWL_DEBUG_RATE("enter\n");
462 471
463 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
464
465
466 retries = info->status.retry_count; 472 retries = info->status.retry_count;
467 first_index = sband->bitrates[info->tx_rate_idx].hw_value; 473 first_index = sband->bitrates[info->tx_rate_idx].hw_value;
468 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) { 474 if ((first_index < 0) || (first_index >= IWL_RATE_COUNT)) {
@@ -470,17 +476,11 @@ static void rs_tx_status(void *priv_rate,
470 return; 476 return;
471 } 477 }
472 478
473 rcu_read_lock(); 479 if (!priv_sta) {
474
475 sta = sta_info_get(local, hdr->addr1);
476 if (!sta || !sta->rate_ctrl_priv) {
477 rcu_read_unlock();
478 IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); 480 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
479 return; 481 return;
480 } 482 }
481 483
482 rs_sta = (void *)sta->rate_ctrl_priv;
483
484 rs_sta->tx_packets++; 484 rs_sta->tx_packets++;
485 485
486 scale_rate_index = first_index; 486 scale_rate_index = first_index;
@@ -547,8 +547,6 @@ static void rs_tx_status(void *priv_rate,
547 547
548 spin_unlock_irqrestore(&rs_sta->lock, flags); 548 spin_unlock_irqrestore(&rs_sta->lock, flags);
549 549
550 rcu_read_unlock();
551
552 IWL_DEBUG_RATE("leave\n"); 550 IWL_DEBUG_RATE("leave\n");
553 551
554 return; 552 return;
@@ -632,16 +630,15 @@ static u16 iwl3945_get_adjacent_rate(struct iwl3945_rs_sta *rs_sta,
632 * rate table and must reference the driver allocated rate table 630 * rate table and must reference the driver allocated rate table
633 * 631 *
634 */ 632 */
635static void rs_get_rate(void *priv_rate, struct net_device *dev, 633static void rs_get_rate(void *priv_r, struct ieee80211_supported_band *sband,
636 struct ieee80211_supported_band *sband, 634 struct ieee80211_sta *sta, void *priv_sta,
637 struct sk_buff *skb, 635 struct sk_buff *skb, struct rate_selection *sel)
638 struct rate_selection *sel)
639{ 636{
640 u8 low = IWL_RATE_INVALID; 637 u8 low = IWL_RATE_INVALID;
641 u8 high = IWL_RATE_INVALID; 638 u8 high = IWL_RATE_INVALID;
642 u16 high_low; 639 u16 high_low;
643 int index; 640 int index;
644 struct iwl3945_rs_sta *rs_sta; 641 struct iwl3945_rs_sta *rs_sta = priv_sta;
645 struct iwl3945_rate_scale_data *window = NULL; 642 struct iwl3945_rate_scale_data *window = NULL;
646 int current_tpt = IWL_INV_TPT; 643 int current_tpt = IWL_INV_TPT;
647 int low_tpt = IWL_INV_TPT; 644 int low_tpt = IWL_INV_TPT;
@@ -649,40 +646,31 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
649 u32 fail_count; 646 u32 fail_count;
650 s8 scale_action = 0; 647 s8 scale_action = 0;
651 unsigned long flags; 648 unsigned long flags;
652 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
653 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 649 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
654 struct sta_info *sta;
655 u16 fc, rate_mask; 650 u16 fc, rate_mask;
656 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_rate; 651 struct iwl3945_priv *priv = (struct iwl3945_priv *)priv_r;
657 DECLARE_MAC_BUF(mac); 652 DECLARE_MAC_BUF(mac);
658 653
659 IWL_DEBUG_RATE("enter\n"); 654 IWL_DEBUG_RATE("enter\n");
660 655
661 rcu_read_lock();
662
663 sta = sta_info_get(local, hdr->addr1);
664
665 /* Send management frames and broadcast/multicast data using lowest 656 /* Send management frames and broadcast/multicast data using lowest
666 * rate. */ 657 * rate. */
667 fc = le16_to_cpu(hdr->frame_control); 658 fc = le16_to_cpu(hdr->frame_control);
668 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 659 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
669 is_multicast_ether_addr(hdr->addr1) || 660 is_multicast_ether_addr(hdr->addr1) ||
670 !sta || !sta->rate_ctrl_priv) { 661 !sta || !priv_sta) {
671 IWL_DEBUG_RATE("leave: No STA priv data to update!\n"); 662 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
672 sel->rate_idx = rate_lowest_index(local, sband, sta); 663 sel->rate_idx = rate_lowest_index(sband, sta);
673 rcu_read_unlock();
674 return; 664 return;
675 } 665 }
676 666
677 rate_mask = sta->supp_rates[sband->band]; 667 rate_mask = sta->supp_rates[sband->band];
678 index = min(sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1); 668 index = min(rs_sta->last_txrate_idx & 0xffff, IWL_RATE_COUNT - 1);
679 669
680 if (sband->band == IEEE80211_BAND_5GHZ) 670 if (sband->band == IEEE80211_BAND_5GHZ)
681 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE; 671 rate_mask = rate_mask << IWL_FIRST_OFDM_RATE;
682 672
683 rs_sta = (void *)sta->rate_ctrl_priv; 673 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
684
685 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
686 !rs_sta->ibss_sta_added) { 674 !rs_sta->ibss_sta_added) {
687 u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1); 675 u8 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
688 676
@@ -803,17 +791,13 @@ static void rs_get_rate(void *priv_rate, struct net_device *dev,
803 791
804 out: 792 out:
805 793
806 sta->last_txrate_idx = index; 794 rs_sta->last_txrate_idx = index;
807 if (sband->band == IEEE80211_BAND_5GHZ) 795 if (sband->band == IEEE80211_BAND_5GHZ)
808 sta->txrate_idx = sta->last_txrate_idx - IWL_FIRST_OFDM_RATE; 796 sel->rate_idx = rs_sta->last_txrate_idx - IWL_FIRST_OFDM_RATE;
809 else 797 else
810 sta->txrate_idx = sta->last_txrate_idx; 798 sel->rate_idx = rs_sta->last_txrate_idx;
811
812 rcu_read_unlock();
813 799
814 IWL_DEBUG_RATE("leave: %d\n", index); 800 IWL_DEBUG_RATE("leave: %d\n", index);
815
816 sel->rate_idx = sta->txrate_idx;
817} 801}
818 802
819static struct rate_control_ops rs_ops = { 803static struct rate_control_ops rs_ops = {
@@ -829,114 +813,28 @@ static struct rate_control_ops rs_ops = {
829 .free_sta = rs_free_sta, 813 .free_sta = rs_free_sta,
830}; 814};
831 815
832int iwl3945_fill_rs_info(struct ieee80211_hw *hw, char *buf, u8 sta_id)
833{
834 struct ieee80211_local *local = hw_to_local(hw);
835 struct iwl3945_priv *priv = hw->priv;
836 struct iwl3945_rs_sta *rs_sta;
837 struct sta_info *sta;
838 unsigned long flags;
839 int count = 0, i;
840 u32 samples = 0, success = 0, good = 0;
841 unsigned long now = jiffies;
842 u32 max_time = 0;
843
844 rcu_read_lock();
845
846 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr);
847 if (!sta || !sta->rate_ctrl_priv) {
848 if (sta)
849 IWL_DEBUG_RATE("leave - no private rate data!\n");
850 else
851 IWL_DEBUG_RATE("leave - no station!\n");
852 rcu_read_unlock();
853 return sprintf(buf, "station %d not found\n", sta_id);
854 }
855
856 rs_sta = (void *)sta->rate_ctrl_priv;
857 spin_lock_irqsave(&rs_sta->lock, flags);
858 i = IWL_RATE_54M_INDEX;
859 while (1) {
860 u64 mask;
861 int j;
862
863 count +=
864 sprintf(&buf[count], " %2dMbs: ", iwl3945_rates[i].ieee / 2);
865
866 mask = (1ULL << (IWL_RATE_MAX_WINDOW - 1));
867 for (j = 0; j < IWL_RATE_MAX_WINDOW; j++, mask >>= 1)
868 buf[count++] =
869 (rs_sta->win[i].data & mask) ? '1' : '0';
870
871 samples += rs_sta->win[i].counter;
872 good += rs_sta->win[i].success_counter;
873 success += rs_sta->win[i].success_counter *
874 iwl3945_rates[i].ieee;
875
876 if (rs_sta->win[i].stamp) {
877 int delta =
878 jiffies_to_msecs(now - rs_sta->win[i].stamp);
879
880 if (delta > max_time)
881 max_time = delta;
882
883 count += sprintf(&buf[count], "%5dms\n", delta);
884 } else
885 buf[count++] = '\n';
886
887 j = iwl3945_get_prev_ieee_rate(i);
888 if (j == i)
889 break;
890 i = j;
891 }
892 spin_unlock_irqrestore(&rs_sta->lock, flags);
893 rcu_read_unlock();
894
895 /* Display the average rate of all samples taken.
896 *
897 * NOTE: We multiple # of samples by 2 since the IEEE measurement
898 * added from iwl3945_rates is actually 2X the rate */
899 if (samples)
900 count += sprintf(
901 &buf[count],
902 "\nAverage rate is %3d.%02dMbs over last %4dms\n"
903 "%3d%% success (%d good packets over %d tries)\n",
904 success / (2 * samples), (success * 5 / samples) % 10,
905 max_time, good * 100 / samples, good, samples);
906 else
907 count += sprintf(&buf[count], "\nAverage rate: 0Mbs\n");
908
909 return count;
910}
911
912void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id) 816void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
913{ 817{
914 struct iwl3945_priv *priv = hw->priv; 818 struct iwl3945_priv *priv = hw->priv;
915 s32 rssi = 0; 819 s32 rssi = 0;
916 unsigned long flags; 820 unsigned long flags;
917 struct ieee80211_local *local = hw_to_local(hw);
918 struct iwl3945_rs_sta *rs_sta; 821 struct iwl3945_rs_sta *rs_sta;
919 struct sta_info *sta; 822 struct ieee80211_sta *sta;
823 struct iwl3945_sta_priv *psta;
920 824
921 IWL_DEBUG_RATE("enter\n"); 825 IWL_DEBUG_RATE("enter\n");
922 826
923 if (!local->rate_ctrl->ops->name ||
924 strcmp(local->rate_ctrl->ops->name, RS_NAME)) {
925 IWL_WARNING("iwl-3945-rs not selected as rate control algo!\n");
926 IWL_DEBUG_RATE("leave - mac80211 picked the wrong RC algo.\n");
927 return;
928 }
929
930 rcu_read_lock(); 827 rcu_read_lock();
931 828
932 sta = sta_info_get(local, priv->stations[sta_id].sta.sta.addr); 829 sta = ieee80211_find_sta(hw, priv->stations[sta_id].sta.sta.addr);
933 if (!sta || !sta->rate_ctrl_priv) { 830 psta = (void *) sta->drv_priv;
831 if (!sta || !psta) {
934 IWL_DEBUG_RATE("leave - no private rate data!\n"); 832 IWL_DEBUG_RATE("leave - no private rate data!\n");
935 rcu_read_unlock(); 833 rcu_read_unlock();
936 return; 834 return;
937 } 835 }
938 836
939 rs_sta = (void *)sta->rate_ctrl_priv; 837 rs_sta = psta->rs_sta;
940 838
941 spin_lock_irqsave(&rs_sta->lock, flags); 839 spin_lock_irqsave(&rs_sta->lock, flags);
942 840