0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/kernel.h>
0013 #include <linux/skbuff.h>
0014 #include <linux/slab.h>
0015 #include <net/mac80211.h>
0016
0017 #include <linux/netdevice.h>
0018 #include <linux/etherdevice.h>
0019 #include <linux/delay.h>
0020
0021 #include <linux/workqueue.h>
0022
0023 #include "commands.h"
0024 #include "3945.h"
0025
0026 #define RS_NAME "iwl-3945-rs"
0027
0028 static s32 il3945_expected_tpt_g[RATE_COUNT_3945] = {
0029 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202
0030 };
0031
0032 static s32 il3945_expected_tpt_g_prot[RATE_COUNT_3945] = {
0033 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125
0034 };
0035
0036 static s32 il3945_expected_tpt_a[RATE_COUNT_3945] = {
0037 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186
0038 };
0039
0040 static s32 il3945_expected_tpt_b[RATE_COUNT_3945] = {
0041 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0
0042 };
0043
0044 struct il3945_tpt_entry {
0045 s8 min_rssi;
0046 u8 idx;
0047 };
0048
0049 static struct il3945_tpt_entry il3945_tpt_table_a[] = {
0050 {-60, RATE_54M_IDX},
0051 {-64, RATE_48M_IDX},
0052 {-72, RATE_36M_IDX},
0053 {-80, RATE_24M_IDX},
0054 {-84, RATE_18M_IDX},
0055 {-85, RATE_12M_IDX},
0056 {-87, RATE_9M_IDX},
0057 {-89, RATE_6M_IDX}
0058 };
0059
0060 static struct il3945_tpt_entry il3945_tpt_table_g[] = {
0061 {-60, RATE_54M_IDX},
0062 {-64, RATE_48M_IDX},
0063 {-68, RATE_36M_IDX},
0064 {-80, RATE_24M_IDX},
0065 {-84, RATE_18M_IDX},
0066 {-85, RATE_12M_IDX},
0067 {-86, RATE_11M_IDX},
0068 {-88, RATE_5M_IDX},
0069 {-90, RATE_2M_IDX},
0070 {-92, RATE_1M_IDX}
0071 };
0072
0073 #define RATE_MAX_WINDOW 62
0074 #define RATE_FLUSH (3*HZ)
0075 #define RATE_WIN_FLUSH (HZ/2)
0076 #define IL39_RATE_HIGH_TH 11520
0077 #define IL_SUCCESS_UP_TH 8960
0078 #define IL_SUCCESS_DOWN_TH 10880
0079 #define RATE_MIN_FAILURE_TH 6
0080 #define RATE_MIN_SUCCESS_TH 8
0081 #define RATE_DECREASE_TH 1920
0082 #define RATE_RETRY_TH 15
0083
0084 static u8
0085 il3945_get_rate_idx_by_rssi(s32 rssi, enum nl80211_band band)
0086 {
0087 u32 idx = 0;
0088 u32 table_size = 0;
0089 struct il3945_tpt_entry *tpt_table = NULL;
0090
0091 if (rssi < IL_MIN_RSSI_VAL || rssi > IL_MAX_RSSI_VAL)
0092 rssi = IL_MIN_RSSI_VAL;
0093
0094 switch (band) {
0095 case NL80211_BAND_2GHZ:
0096 tpt_table = il3945_tpt_table_g;
0097 table_size = ARRAY_SIZE(il3945_tpt_table_g);
0098 break;
0099 case NL80211_BAND_5GHZ:
0100 tpt_table = il3945_tpt_table_a;
0101 table_size = ARRAY_SIZE(il3945_tpt_table_a);
0102 break;
0103 default:
0104 BUG();
0105 break;
0106 }
0107
0108 while (idx < table_size && rssi < tpt_table[idx].min_rssi)
0109 idx++;
0110
0111 idx = min(idx, table_size - 1);
0112
0113 return tpt_table[idx].idx;
0114 }
0115
0116 static void
0117 il3945_clear_win(struct il3945_rate_scale_data *win)
0118 {
0119 win->data = 0;
0120 win->success_counter = 0;
0121 win->success_ratio = -1;
0122 win->counter = 0;
0123 win->average_tpt = IL_INVALID_VALUE;
0124 win->stamp = 0;
0125 }
0126
0127
0128
0129
0130
0131
0132
0133
0134 static int
0135 il3945_rate_scale_flush_wins(struct il3945_rs_sta *rs_sta)
0136 {
0137 int unflushed = 0;
0138 int i;
0139 unsigned long flags;
0140 struct il_priv *il __maybe_unused = rs_sta->il;
0141
0142
0143
0144
0145
0146
0147 for (i = 0; i < RATE_COUNT_3945; i++) {
0148 if (!rs_sta->win[i].counter)
0149 continue;
0150
0151 spin_lock_irqsave(&rs_sta->lock, flags);
0152 if (time_after(jiffies, rs_sta->win[i].stamp + RATE_WIN_FLUSH)) {
0153 D_RATE("flushing %d samples of rate " "idx %d\n",
0154 rs_sta->win[i].counter, i);
0155 il3945_clear_win(&rs_sta->win[i]);
0156 } else
0157 unflushed++;
0158 spin_unlock_irqrestore(&rs_sta->lock, flags);
0159 }
0160
0161 return unflushed;
0162 }
0163
0164 #define RATE_FLUSH_MAX 5000
0165 #define RATE_FLUSH_MIN 50
0166 #define IL_AVERAGE_PACKETS 1500
0167
0168 static void
0169 il3945_bg_rate_scale_flush(struct timer_list *t)
0170 {
0171 struct il3945_rs_sta *rs_sta = from_timer(rs_sta, t, rate_scale_flush);
0172 struct il_priv *il __maybe_unused = rs_sta->il;
0173 int unflushed = 0;
0174 unsigned long flags;
0175 u32 packet_count, duration, pps;
0176
0177 D_RATE("enter\n");
0178
0179 unflushed = il3945_rate_scale_flush_wins(rs_sta);
0180
0181 spin_lock_irqsave(&rs_sta->lock, flags);
0182
0183
0184 packet_count = (rs_sta->tx_packets - rs_sta->last_tx_packets) + 1;
0185
0186 rs_sta->last_tx_packets = rs_sta->tx_packets + 1;
0187
0188 if (unflushed) {
0189 duration =
0190 jiffies_to_msecs(jiffies - rs_sta->last_partial_flush);
0191
0192 D_RATE("Tx'd %d packets in %dms\n", packet_count, duration);
0193
0194
0195 if (duration)
0196 pps = (packet_count * 1000) / duration;
0197 else
0198 pps = 0;
0199
0200 if (pps) {
0201 duration = (IL_AVERAGE_PACKETS * 1000) / pps;
0202 if (duration < RATE_FLUSH_MIN)
0203 duration = RATE_FLUSH_MIN;
0204 else if (duration > RATE_FLUSH_MAX)
0205 duration = RATE_FLUSH_MAX;
0206 } else
0207 duration = RATE_FLUSH_MAX;
0208
0209 rs_sta->flush_time = msecs_to_jiffies(duration);
0210
0211 D_RATE("new flush period: %d msec ave %d\n", duration,
0212 packet_count);
0213
0214 mod_timer(&rs_sta->rate_scale_flush,
0215 jiffies + rs_sta->flush_time);
0216
0217 rs_sta->last_partial_flush = jiffies;
0218 } else {
0219 rs_sta->flush_time = RATE_FLUSH;
0220 rs_sta->flush_pending = 0;
0221 }
0222
0223
0224
0225 rs_sta->last_flush = jiffies;
0226
0227 spin_unlock_irqrestore(&rs_sta->lock, flags);
0228
0229 D_RATE("leave\n");
0230 }
0231
0232
0233
0234
0235
0236
0237
0238
0239 static void
0240 il3945_collect_tx_data(struct il3945_rs_sta *rs_sta,
0241 struct il3945_rate_scale_data *win, int success,
0242 int retries, int idx)
0243 {
0244 unsigned long flags;
0245 s32 fail_count;
0246 struct il_priv *il __maybe_unused = rs_sta->il;
0247
0248 if (!retries) {
0249 D_RATE("leave: retries == 0 -- should be at least 1\n");
0250 return;
0251 }
0252
0253 spin_lock_irqsave(&rs_sta->lock, flags);
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 while (retries > 0) {
0264 if (win->counter >= RATE_MAX_WINDOW) {
0265
0266
0267 win->counter = RATE_MAX_WINDOW - 1;
0268
0269 if (win->data & (1ULL << (RATE_MAX_WINDOW - 1))) {
0270 win->data &= ~(1ULL << (RATE_MAX_WINDOW - 1));
0271 win->success_counter--;
0272 }
0273 }
0274
0275
0276 win->counter++;
0277
0278
0279
0280
0281 win->data <<= 1;
0282 if (success > 0) {
0283 win->success_counter++;
0284 win->data |= 0x1;
0285 success--;
0286 }
0287
0288 retries--;
0289 }
0290
0291
0292 if (win->counter > 0)
0293 win->success_ratio =
0294 128 * (100 * win->success_counter) / win->counter;
0295 else
0296 win->success_ratio = IL_INVALID_VALUE;
0297
0298 fail_count = win->counter - win->success_counter;
0299
0300
0301 if (fail_count >= RATE_MIN_FAILURE_TH ||
0302 win->success_counter >= RATE_MIN_SUCCESS_TH)
0303 win->average_tpt =
0304 ((win->success_ratio * rs_sta->expected_tpt[idx] +
0305 64) / 128);
0306 else
0307 win->average_tpt = IL_INVALID_VALUE;
0308
0309
0310 win->stamp = jiffies;
0311
0312 spin_unlock_irqrestore(&rs_sta->lock, flags);
0313 }
0314
0315
0316
0317
0318 void
0319 il3945_rs_rate_init(struct il_priv *il, struct ieee80211_sta *sta, u8 sta_id)
0320 {
0321 struct ieee80211_hw *hw = il->hw;
0322 struct ieee80211_conf *conf = &il->hw->conf;
0323 struct il3945_sta_priv *psta;
0324 struct il3945_rs_sta *rs_sta;
0325 struct ieee80211_supported_band *sband;
0326 int i;
0327
0328 D_INFO("enter\n");
0329 if (sta_id == il->hw_params.bcast_id)
0330 goto out;
0331
0332 psta = (struct il3945_sta_priv *)sta->drv_priv;
0333 rs_sta = &psta->rs_sta;
0334 sband = hw->wiphy->bands[conf->chandef.chan->band];
0335
0336 rs_sta->il = il;
0337
0338 rs_sta->start_rate = RATE_INVALID;
0339
0340
0341 rs_sta->expected_tpt = il3945_expected_tpt_b;
0342
0343 rs_sta->last_partial_flush = jiffies;
0344 rs_sta->last_flush = jiffies;
0345 rs_sta->flush_time = RATE_FLUSH;
0346 rs_sta->last_tx_packets = 0;
0347
0348 for (i = 0; i < RATE_COUNT_3945; i++)
0349 il3945_clear_win(&rs_sta->win[i]);
0350
0351
0352
0353
0354
0355
0356 for (i = sband->n_bitrates - 1; i >= 0; i--) {
0357 if (sta->deflink.supp_rates[sband->band] & (1 << i)) {
0358 rs_sta->last_txrate_idx = i;
0359 break;
0360 }
0361 }
0362
0363 il->_3945.sta_supp_rates = sta->deflink.supp_rates[sband->band];
0364
0365 if (sband->band == NL80211_BAND_5GHZ) {
0366 rs_sta->last_txrate_idx += IL_FIRST_OFDM_RATE;
0367 il->_3945.sta_supp_rates <<= IL_FIRST_OFDM_RATE;
0368 }
0369
0370 out:
0371 il->stations[sta_id].used &= ~IL_STA_UCODE_INPROGRESS;
0372
0373 D_INFO("leave\n");
0374 }
0375
0376 static void *
0377 il3945_rs_alloc(struct ieee80211_hw *hw)
0378 {
0379 return hw->priv;
0380 }
0381
0382
0383 static void
0384 il3945_rs_free(void *il)
0385 {
0386 }
0387
0388 static void *
0389 il3945_rs_alloc_sta(void *il_priv, struct ieee80211_sta *sta, gfp_t gfp)
0390 {
0391 struct il3945_rs_sta *rs_sta;
0392 struct il3945_sta_priv *psta = (void *)sta->drv_priv;
0393 struct il_priv *il __maybe_unused = il_priv;
0394
0395 D_RATE("enter\n");
0396
0397 rs_sta = &psta->rs_sta;
0398
0399 spin_lock_init(&rs_sta->lock);
0400 timer_setup(&rs_sta->rate_scale_flush, il3945_bg_rate_scale_flush, 0);
0401 D_RATE("leave\n");
0402
0403 return rs_sta;
0404 }
0405
0406 static void
0407 il3945_rs_free_sta(void *il_priv, struct ieee80211_sta *sta, void *il_sta)
0408 {
0409 struct il3945_rs_sta *rs_sta = il_sta;
0410
0411
0412
0413
0414
0415
0416 del_timer_sync(&rs_sta->rate_scale_flush);
0417 }
0418
0419
0420
0421
0422
0423
0424
0425 static void
0426 il3945_rs_tx_status(void *il_rate, struct ieee80211_supported_band *sband,
0427 struct ieee80211_sta *sta, void *il_sta,
0428 struct sk_buff *skb)
0429 {
0430 s8 retries = 0, current_count;
0431 int scale_rate_idx, first_idx, last_idx;
0432 unsigned long flags;
0433 struct il_priv *il = (struct il_priv *)il_rate;
0434 struct il3945_rs_sta *rs_sta = il_sta;
0435 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
0436
0437 D_RATE("enter\n");
0438
0439 retries = info->status.rates[0].count;
0440
0441 if (retries > RATE_RETRY_TH)
0442 retries = RATE_RETRY_TH;
0443
0444 first_idx = sband->bitrates[info->status.rates[0].idx].hw_value;
0445 if (first_idx < 0 || first_idx >= RATE_COUNT_3945) {
0446 D_RATE("leave: Rate out of bounds: %d\n", first_idx);
0447 return;
0448 }
0449
0450 if (!il_sta) {
0451 D_RATE("leave: No STA il data to update!\n");
0452 return;
0453 }
0454
0455
0456 if (!rs_sta->il) {
0457 D_RATE("leave: STA il data uninitialized!\n");
0458 return;
0459 }
0460
0461 rs_sta->tx_packets++;
0462
0463 scale_rate_idx = first_idx;
0464 last_idx = first_idx;
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476 while (retries > 1) {
0477 if ((retries - 1) < il->retry_rate) {
0478 current_count = (retries - 1);
0479 last_idx = scale_rate_idx;
0480 } else {
0481 current_count = il->retry_rate;
0482 last_idx = il3945_rs_next_rate(il, scale_rate_idx);
0483 }
0484
0485
0486
0487 il3945_collect_tx_data(rs_sta, &rs_sta->win[scale_rate_idx], 0,
0488 current_count, scale_rate_idx);
0489 D_RATE("Update rate %d for %d retries.\n", scale_rate_idx,
0490 current_count);
0491
0492 retries -= current_count;
0493
0494 scale_rate_idx = last_idx;
0495 }
0496
0497
0498 D_RATE("Update rate %d with %s.\n", last_idx,
0499 (info->flags & IEEE80211_TX_STAT_ACK) ? "success" : "failure");
0500 il3945_collect_tx_data(rs_sta, &rs_sta->win[last_idx],
0501 info->flags & IEEE80211_TX_STAT_ACK, 1,
0502 last_idx);
0503
0504
0505
0506
0507 spin_lock_irqsave(&rs_sta->lock, flags);
0508
0509 if (!rs_sta->flush_pending &&
0510 time_after(jiffies, rs_sta->last_flush + rs_sta->flush_time)) {
0511
0512 rs_sta->last_partial_flush = jiffies;
0513 rs_sta->flush_pending = 1;
0514 mod_timer(&rs_sta->rate_scale_flush,
0515 jiffies + rs_sta->flush_time);
0516 }
0517
0518 spin_unlock_irqrestore(&rs_sta->lock, flags);
0519
0520 D_RATE("leave\n");
0521 }
0522
0523 static u16
0524 il3945_get_adjacent_rate(struct il3945_rs_sta *rs_sta, u8 idx, u16 rate_mask,
0525 enum nl80211_band band)
0526 {
0527 u8 high = RATE_INVALID;
0528 u8 low = RATE_INVALID;
0529 struct il_priv *il __maybe_unused = rs_sta->il;
0530
0531
0532
0533 if (unlikely(band == NL80211_BAND_5GHZ)) {
0534 int i;
0535 u32 mask;
0536
0537
0538 i = idx - 1;
0539 for (mask = (1 << i); i >= 0; i--, mask >>= 1) {
0540 if (rate_mask & mask) {
0541 low = i;
0542 break;
0543 }
0544 }
0545
0546
0547 i = idx + 1;
0548 for (mask = (1 << i); i < RATE_COUNT_3945; i++, mask <<= 1) {
0549 if (rate_mask & mask) {
0550 high = i;
0551 break;
0552 }
0553 }
0554
0555 return (high << 8) | low;
0556 }
0557
0558 low = idx;
0559 while (low != RATE_INVALID) {
0560 if (rs_sta->tgg)
0561 low = il3945_rates[low].prev_rs_tgg;
0562 else
0563 low = il3945_rates[low].prev_rs;
0564 if (low == RATE_INVALID)
0565 break;
0566 if (rate_mask & (1 << low))
0567 break;
0568 D_RATE("Skipping masked lower rate: %d\n", low);
0569 }
0570
0571 high = idx;
0572 while (high != RATE_INVALID) {
0573 if (rs_sta->tgg)
0574 high = il3945_rates[high].next_rs_tgg;
0575 else
0576 high = il3945_rates[high].next_rs;
0577 if (high == RATE_INVALID)
0578 break;
0579 if (rate_mask & (1 << high))
0580 break;
0581 D_RATE("Skipping masked higher rate: %d\n", high);
0582 }
0583
0584 return (high << 8) | low;
0585 }
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603 static void
0604 il3945_rs_get_rate(void *il_r, struct ieee80211_sta *sta, void *il_sta,
0605 struct ieee80211_tx_rate_control *txrc)
0606 {
0607 struct ieee80211_supported_band *sband = txrc->sband;
0608 struct sk_buff *skb = txrc->skb;
0609 u8 low = RATE_INVALID;
0610 u8 high = RATE_INVALID;
0611 u16 high_low;
0612 int idx;
0613 struct il3945_rs_sta *rs_sta = il_sta;
0614 struct il3945_rate_scale_data *win = NULL;
0615 int current_tpt = IL_INVALID_VALUE;
0616 int low_tpt = IL_INVALID_VALUE;
0617 int high_tpt = IL_INVALID_VALUE;
0618 u32 fail_count;
0619 s8 scale_action = 0;
0620 unsigned long flags;
0621 u16 rate_mask;
0622 s8 max_rate_idx = -1;
0623 struct il_priv *il __maybe_unused = (struct il_priv *)il_r;
0624 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
0625
0626 D_RATE("enter\n");
0627
0628
0629 if (rs_sta && !rs_sta->il) {
0630 D_RATE("Rate scaling information not initialized yet.\n");
0631 il_sta = NULL;
0632 }
0633
0634 rate_mask = sta->deflink.supp_rates[sband->band];
0635
0636
0637 max_rate_idx = fls(txrc->rate_idx_mask) - 1;
0638 if (sband->band == NL80211_BAND_5GHZ && max_rate_idx != -1)
0639 max_rate_idx += IL_FIRST_OFDM_RATE;
0640 if (max_rate_idx < 0 || max_rate_idx >= RATE_COUNT)
0641 max_rate_idx = -1;
0642
0643 idx = min(rs_sta->last_txrate_idx & 0xffff, RATE_COUNT_3945 - 1);
0644
0645 if (sband->band == NL80211_BAND_5GHZ)
0646 rate_mask = rate_mask << IL_FIRST_OFDM_RATE;
0647
0648 spin_lock_irqsave(&rs_sta->lock, flags);
0649
0650
0651
0652
0653 if (rs_sta->start_rate != RATE_INVALID) {
0654 if (rs_sta->start_rate < idx &&
0655 (rate_mask & (1 << rs_sta->start_rate)))
0656 idx = rs_sta->start_rate;
0657 rs_sta->start_rate = RATE_INVALID;
0658 }
0659
0660
0661 if (max_rate_idx != -1 && max_rate_idx < idx) {
0662 if (rate_mask & (1 << max_rate_idx))
0663 idx = max_rate_idx;
0664 }
0665
0666 win = &(rs_sta->win[idx]);
0667
0668 fail_count = win->counter - win->success_counter;
0669
0670 if (fail_count < RATE_MIN_FAILURE_TH &&
0671 win->success_counter < RATE_MIN_SUCCESS_TH) {
0672 spin_unlock_irqrestore(&rs_sta->lock, flags);
0673
0674 D_RATE("Invalid average_tpt on rate %d: "
0675 "counter: %d, success_counter: %d, "
0676 "expected_tpt is %sNULL\n", idx, win->counter,
0677 win->success_counter,
0678 rs_sta->expected_tpt ? "not " : "");
0679
0680
0681 win->average_tpt = IL_INVALID_VALUE;
0682 goto out;
0683
0684 }
0685
0686 current_tpt = win->average_tpt;
0687
0688 high_low =
0689 il3945_get_adjacent_rate(rs_sta, idx, rate_mask, sband->band);
0690 low = high_low & 0xff;
0691 high = (high_low >> 8) & 0xff;
0692
0693
0694 if (max_rate_idx != -1 && max_rate_idx < high)
0695 high = RATE_INVALID;
0696
0697
0698 if (low != RATE_INVALID)
0699 low_tpt = rs_sta->win[low].average_tpt;
0700
0701 if (high != RATE_INVALID)
0702 high_tpt = rs_sta->win[high].average_tpt;
0703
0704 spin_unlock_irqrestore(&rs_sta->lock, flags);
0705
0706 scale_action = 0;
0707
0708
0709 if (win->success_ratio < RATE_DECREASE_TH || !current_tpt) {
0710 D_RATE("decrease rate because of low success_ratio\n");
0711 scale_action = -1;
0712
0713
0714 } else if (low_tpt == IL_INVALID_VALUE && high_tpt == IL_INVALID_VALUE) {
0715
0716 if (high != RATE_INVALID &&
0717 win->success_ratio >= RATE_INCREASE_TH)
0718 scale_action = 1;
0719 else if (low != RATE_INVALID)
0720 scale_action = 0;
0721
0722
0723
0724
0725 } else if (low_tpt != IL_INVALID_VALUE && high_tpt != IL_INVALID_VALUE
0726 && low_tpt < current_tpt && high_tpt < current_tpt) {
0727
0728 D_RATE("No action -- low [%d] & high [%d] < "
0729 "current_tpt [%d]\n", low_tpt, high_tpt, current_tpt);
0730 scale_action = 0;
0731
0732
0733 } else {
0734 if (high_tpt != IL_INVALID_VALUE) {
0735
0736
0737
0738 if (high_tpt > current_tpt &&
0739 win->success_ratio >= RATE_INCREASE_TH)
0740 scale_action = 1;
0741 else {
0742 D_RATE("decrease rate because of high tpt\n");
0743 scale_action = 0;
0744 }
0745 } else if (low_tpt != IL_INVALID_VALUE) {
0746 if (low_tpt > current_tpt) {
0747 D_RATE("decrease rate because of low tpt\n");
0748 scale_action = -1;
0749 } else if (win->success_ratio >= RATE_INCREASE_TH) {
0750
0751
0752 scale_action = 1;
0753 }
0754 }
0755 }
0756
0757
0758
0759 if (scale_action == -1 && low != RATE_INVALID &&
0760 (win->success_ratio > RATE_HIGH_TH ||
0761 current_tpt > 100 * rs_sta->expected_tpt[low]))
0762 scale_action = 0;
0763
0764 switch (scale_action) {
0765 case -1:
0766
0767 if (low != RATE_INVALID)
0768 idx = low;
0769 break;
0770 case 1:
0771
0772 if (high != RATE_INVALID)
0773 idx = high;
0774
0775 break;
0776 case 0:
0777 default:
0778
0779 break;
0780 }
0781
0782 D_RATE("Selected %d (action %d) - low %d high %d\n", idx, scale_action,
0783 low, high);
0784
0785 out:
0786
0787 if (sband->band == NL80211_BAND_5GHZ) {
0788 if (WARN_ON_ONCE(idx < IL_FIRST_OFDM_RATE))
0789 idx = IL_FIRST_OFDM_RATE;
0790 rs_sta->last_txrate_idx = idx;
0791 info->control.rates[0].idx = idx - IL_FIRST_OFDM_RATE;
0792 } else {
0793 rs_sta->last_txrate_idx = idx;
0794 info->control.rates[0].idx = rs_sta->last_txrate_idx;
0795 }
0796 info->control.rates[0].count = 1;
0797
0798 D_RATE("leave: %d\n", idx);
0799 }
0800
0801 #ifdef CONFIG_MAC80211_DEBUGFS
0802
0803 static ssize_t
0804 il3945_sta_dbgfs_stats_table_read(struct file *file, char __user *user_buf,
0805 size_t count, loff_t *ppos)
0806 {
0807 char *buff;
0808 int desc = 0;
0809 int j;
0810 ssize_t ret;
0811 struct il3945_rs_sta *lq_sta = file->private_data;
0812
0813 buff = kmalloc(1024, GFP_KERNEL);
0814 if (!buff)
0815 return -ENOMEM;
0816
0817 desc +=
0818 sprintf(buff + desc,
0819 "tx packets=%d last rate idx=%d\n"
0820 "rate=0x%X flush time %d\n", lq_sta->tx_packets,
0821 lq_sta->last_txrate_idx, lq_sta->start_rate,
0822 jiffies_to_msecs(lq_sta->flush_time));
0823 for (j = 0; j < RATE_COUNT_3945; j++) {
0824 desc +=
0825 sprintf(buff + desc, "counter=%d success=%d %%=%d\n",
0826 lq_sta->win[j].counter,
0827 lq_sta->win[j].success_counter,
0828 lq_sta->win[j].success_ratio);
0829 }
0830 ret = simple_read_from_buffer(user_buf, count, ppos, buff, desc);
0831 kfree(buff);
0832 return ret;
0833 }
0834
0835 static const struct file_operations rs_sta_dbgfs_stats_table_ops = {
0836 .read = il3945_sta_dbgfs_stats_table_read,
0837 .open = simple_open,
0838 .llseek = default_llseek,
0839 };
0840
0841 static void
0842 il3945_add_debugfs(void *il, void *il_sta, struct dentry *dir)
0843 {
0844 struct il3945_rs_sta *lq_sta = il_sta;
0845
0846 debugfs_create_file("rate_stats_table", 0600, dir, lq_sta,
0847 &rs_sta_dbgfs_stats_table_ops);
0848 }
0849 #endif
0850
0851
0852
0853
0854
0855
0856 static void
0857 il3945_rs_rate_init_stub(void *il_r, struct ieee80211_supported_band *sband,
0858 struct cfg80211_chan_def *chandef,
0859 struct ieee80211_sta *sta, void *il_sta)
0860 {
0861 }
0862
0863 static const struct rate_control_ops rs_ops = {
0864 .name = RS_NAME,
0865 .tx_status = il3945_rs_tx_status,
0866 .get_rate = il3945_rs_get_rate,
0867 .rate_init = il3945_rs_rate_init_stub,
0868 .alloc = il3945_rs_alloc,
0869 .free = il3945_rs_free,
0870 .alloc_sta = il3945_rs_alloc_sta,
0871 .free_sta = il3945_rs_free_sta,
0872 #ifdef CONFIG_MAC80211_DEBUGFS
0873 .add_sta_debugfs = il3945_add_debugfs,
0874 #endif
0875
0876 };
0877
0878 void
0879 il3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
0880 {
0881 struct il_priv *il = hw->priv;
0882 s32 rssi = 0;
0883 unsigned long flags;
0884 struct il3945_rs_sta *rs_sta;
0885 struct ieee80211_sta *sta;
0886 struct il3945_sta_priv *psta;
0887
0888 D_RATE("enter\n");
0889
0890 rcu_read_lock();
0891
0892 sta = ieee80211_find_sta(il->vif, il->stations[sta_id].sta.sta.addr);
0893 if (!sta) {
0894 D_RATE("Unable to find station to initialize rate scaling.\n");
0895 rcu_read_unlock();
0896 return;
0897 }
0898
0899 psta = (void *)sta->drv_priv;
0900 rs_sta = &psta->rs_sta;
0901
0902 spin_lock_irqsave(&rs_sta->lock, flags);
0903
0904 rs_sta->tgg = 0;
0905 switch (il->band) {
0906 case NL80211_BAND_2GHZ:
0907
0908 if (il->active.flags & RXON_FLG_TGG_PROTECT_MSK) {
0909 rs_sta->tgg = 1;
0910 rs_sta->expected_tpt = il3945_expected_tpt_g_prot;
0911 } else
0912 rs_sta->expected_tpt = il3945_expected_tpt_g;
0913 break;
0914 case NL80211_BAND_5GHZ:
0915 rs_sta->expected_tpt = il3945_expected_tpt_a;
0916 break;
0917 default:
0918 BUG();
0919 break;
0920 }
0921
0922 spin_unlock_irqrestore(&rs_sta->lock, flags);
0923
0924 rssi = il->_3945.last_rx_rssi;
0925 if (rssi == 0)
0926 rssi = IL_MIN_RSSI_VAL;
0927
0928 D_RATE("Network RSSI: %d\n", rssi);
0929
0930 rs_sta->start_rate = il3945_get_rate_idx_by_rssi(rssi, il->band);
0931
0932 D_RATE("leave: rssi %d assign rate idx: " "%d (plcp 0x%x)\n", rssi,
0933 rs_sta->start_rate, il3945_rates[rs_sta->start_rate].plcp);
0934 rcu_read_unlock();
0935 }
0936
0937 int
0938 il3945_rate_control_register(void)
0939 {
0940 return ieee80211_rate_control_register(&rs_ops);
0941 }
0942
0943 void
0944 il3945_rate_control_unregister(void)
0945 {
0946 ieee80211_rate_control_unregister(&rs_ops);
0947 }