1 /******************************************************************************
3 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/skbuff.h>
30 #include <linux/slab.h>
31 #include <net/mac80211.h>
33 #include <linux/netdevice.h>
34 #include <linux/etherdevice.h>
35 #include <linux/delay.h>
37 #include <linux/workqueue.h>
42 #define RS_NAME "iwl-3945-rs"
44 static s32 il3945_expected_tpt_g
[RATE_COUNT_3945
] = {
45 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202
48 static s32 il3945_expected_tpt_g_prot
[RATE_COUNT_3945
] = {
49 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125
52 static s32 il3945_expected_tpt_a
[RATE_COUNT_3945
] = {
53 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186
56 static s32 il3945_expected_tpt_b
[RATE_COUNT_3945
] = {
57 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0
60 struct il3945_tpt_entry
{
65 static struct il3945_tpt_entry il3945_tpt_table_a
[] = {
76 static struct il3945_tpt_entry il3945_tpt_table_g
[] = {
89 #define RATE_MAX_WINDOW 62
90 #define RATE_FLUSH (3*HZ)
91 #define RATE_WIN_FLUSH (HZ/2)
92 #define IL39_RATE_HIGH_TH 11520
93 #define IL_SUCCESS_UP_TH 8960
94 #define IL_SUCCESS_DOWN_TH 10880
95 #define RATE_MIN_FAILURE_TH 6
96 #define RATE_MIN_SUCCESS_TH 8
97 #define RATE_DECREASE_TH 1920
98 #define RATE_RETRY_TH 15
101 il3945_get_rate_idx_by_rssi(s32 rssi
, enum ieee80211_band band
)
105 struct il3945_tpt_entry
*tpt_table
= NULL
;
107 if (rssi
< IL_MIN_RSSI_VAL
|| rssi
> IL_MAX_RSSI_VAL
)
108 rssi
= IL_MIN_RSSI_VAL
;
111 case IEEE80211_BAND_2GHZ
:
112 tpt_table
= il3945_tpt_table_g
;
113 table_size
= ARRAY_SIZE(il3945_tpt_table_g
);
115 case IEEE80211_BAND_5GHZ
:
116 tpt_table
= il3945_tpt_table_a
;
117 table_size
= ARRAY_SIZE(il3945_tpt_table_a
);
124 while (idx
< table_size
&& rssi
< tpt_table
[idx
].min_rssi
)
127 idx
= min(idx
, table_size
- 1);
129 return tpt_table
[idx
].idx
;
133 il3945_clear_win(struct il3945_rate_scale_data
*win
)
136 win
->success_counter
= 0;
137 win
->success_ratio
= -1;
139 win
->average_tpt
= IL_INVALID_VALUE
;
144 * il3945_rate_scale_flush_wins - flush out the rate scale wins
146 * Returns the number of wins that have gathered data but were
147 * not flushed. If there were any that were not flushed, then
148 * reschedule the rate flushing routine.
151 il3945_rate_scale_flush_wins(struct il3945_rs_sta
*rs_sta
)
156 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
159 * For each rate, if we have collected data on that rate
160 * and it has been more than RATE_WIN_FLUSH
161 * since we flushed, clear out the gathered stats
163 for (i
= 0; i
< RATE_COUNT_3945
; i
++) {
164 if (!rs_sta
->win
[i
].counter
)
167 spin_lock_irqsave(&rs_sta
->lock
, flags
);
168 if (time_after(jiffies
, rs_sta
->win
[i
].stamp
+ RATE_WIN_FLUSH
)) {
169 D_RATE("flushing %d samples of rate " "idx %d\n",
170 rs_sta
->win
[i
].counter
, i
);
171 il3945_clear_win(&rs_sta
->win
[i
]);
174 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
180 #define RATE_FLUSH_MAX 5000 /* msec */
181 #define RATE_FLUSH_MIN 50 /* msec */
182 #define IL_AVERAGE_PACKETS 1500
185 il3945_bg_rate_scale_flush(unsigned long data
)
187 struct il3945_rs_sta
*rs_sta
= (void *)data
;
188 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
191 u32 packet_count
, duration
, pps
;
195 unflushed
= il3945_rate_scale_flush_wins(rs_sta
);
197 spin_lock_irqsave(&rs_sta
->lock
, flags
);
199 /* Number of packets Rx'd since last time this timer ran */
200 packet_count
= (rs_sta
->tx_packets
- rs_sta
->last_tx_packets
) + 1;
202 rs_sta
->last_tx_packets
= rs_sta
->tx_packets
+ 1;
206 jiffies_to_msecs(jiffies
- rs_sta
->last_partial_flush
);
208 D_RATE("Tx'd %d packets in %dms\n", packet_count
, duration
);
210 /* Determine packets per second */
212 pps
= (packet_count
* 1000) / duration
;
217 duration
= (IL_AVERAGE_PACKETS
* 1000) / pps
;
218 if (duration
< RATE_FLUSH_MIN
)
219 duration
= RATE_FLUSH_MIN
;
220 else if (duration
> RATE_FLUSH_MAX
)
221 duration
= RATE_FLUSH_MAX
;
223 duration
= RATE_FLUSH_MAX
;
225 rs_sta
->flush_time
= msecs_to_jiffies(duration
);
227 D_RATE("new flush period: %d msec ave %d\n", duration
,
230 mod_timer(&rs_sta
->rate_scale_flush
,
231 jiffies
+ rs_sta
->flush_time
);
233 rs_sta
->last_partial_flush
= jiffies
;
235 rs_sta
->flush_time
= RATE_FLUSH
;
236 rs_sta
->flush_pending
= 0;
238 /* If there weren't any unflushed entries, we don't schedule the timer
241 rs_sta
->last_flush
= jiffies
;
243 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
249 * il3945_collect_tx_data - Update the success/failure sliding win
251 * We keep a sliding win of the last 64 packets transmitted
252 * at this rate. win->data contains the bitmask of successful
256 il3945_collect_tx_data(struct il3945_rs_sta
*rs_sta
,
257 struct il3945_rate_scale_data
*win
, int success
,
258 int retries
, int idx
)
262 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
265 D_RATE("leave: retries == 0 -- should be at least 1\n");
269 spin_lock_irqsave(&rs_sta
->lock
, flags
);
272 * Keep track of only the latest 62 tx frame attempts in this rate's
273 * history win; anything older isn't really relevant any more.
274 * If we have filled up the sliding win, drop the oldest attempt;
275 * if the oldest attempt (highest bit in bitmap) shows "success",
276 * subtract "1" from the success counter (this is the main reason
277 * we keep these bitmaps!).
279 while (retries
> 0) {
280 if (win
->counter
>= RATE_MAX_WINDOW
) {
282 /* remove earliest */
283 win
->counter
= RATE_MAX_WINDOW
- 1;
285 if (win
->data
& (1ULL << (RATE_MAX_WINDOW
- 1))) {
286 win
->data
&= ~(1ULL << (RATE_MAX_WINDOW
- 1));
287 win
->success_counter
--;
291 /* Increment frames-attempted counter */
294 /* Shift bitmap by one frame (throw away oldest history),
295 * OR in "1", and increment "success" if this
296 * frame was successful. */
299 win
->success_counter
++;
307 /* Calculate current success ratio, avoid divide-by-0! */
308 if (win
->counter
> 0)
310 128 * (100 * win
->success_counter
) / win
->counter
;
312 win
->success_ratio
= IL_INVALID_VALUE
;
314 fail_count
= win
->counter
- win
->success_counter
;
316 /* Calculate average throughput, if we have enough history. */
317 if (fail_count
>= RATE_MIN_FAILURE_TH
||
318 win
->success_counter
>= RATE_MIN_SUCCESS_TH
)
320 ((win
->success_ratio
* rs_sta
->expected_tpt
[idx
] +
323 win
->average_tpt
= IL_INVALID_VALUE
;
325 /* Tag this win as having been updated */
326 win
->stamp
= jiffies
;
328 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
332 * Called after adding a new station to initialize rate scaling
335 il3945_rs_rate_init(struct il_priv
*il
, struct ieee80211_sta
*sta
, u8 sta_id
)
337 struct ieee80211_hw
*hw
= il
->hw
;
338 struct ieee80211_conf
*conf
= &il
->hw
->conf
;
339 struct il3945_sta_priv
*psta
;
340 struct il3945_rs_sta
*rs_sta
;
341 struct ieee80211_supported_band
*sband
;
345 if (sta_id
== il
->hw_params
.bcast_id
)
348 psta
= (struct il3945_sta_priv
*)sta
->drv_priv
;
349 rs_sta
= &psta
->rs_sta
;
350 sband
= hw
->wiphy
->bands
[conf
->chandef
.chan
->band
];
354 rs_sta
->start_rate
= RATE_INVALID
;
356 /* default to just 802.11b */
357 rs_sta
->expected_tpt
= il3945_expected_tpt_b
;
359 rs_sta
->last_partial_flush
= jiffies
;
360 rs_sta
->last_flush
= jiffies
;
361 rs_sta
->flush_time
= RATE_FLUSH
;
362 rs_sta
->last_tx_packets
= 0;
364 rs_sta
->rate_scale_flush
.data
= (unsigned long)rs_sta
;
365 rs_sta
->rate_scale_flush
.function
= il3945_bg_rate_scale_flush
;
367 for (i
= 0; i
< RATE_COUNT_3945
; i
++)
368 il3945_clear_win(&rs_sta
->win
[i
]);
370 /* TODO: what is a good starting rate for STA? About middle? Maybe not
371 * the lowest or the highest rate.. Could consider using RSSI from
372 * previous packets? Need to have IEEE 802.1X auth succeed immediately
375 for (i
= sband
->n_bitrates
- 1; i
>= 0; i
--) {
376 if (sta
->supp_rates
[sband
->band
] & (1 << i
)) {
377 rs_sta
->last_txrate_idx
= i
;
382 il
->_3945
.sta_supp_rates
= sta
->supp_rates
[sband
->band
];
383 /* For 5 GHz band it start at IL_FIRST_OFDM_RATE */
384 if (sband
->band
== IEEE80211_BAND_5GHZ
) {
385 rs_sta
->last_txrate_idx
+= IL_FIRST_OFDM_RATE
;
386 il
->_3945
.sta_supp_rates
<<= IL_FIRST_OFDM_RATE
;
390 il
->stations
[sta_id
].used
&= ~IL_STA_UCODE_INPROGRESS
;
396 il3945_rs_alloc(struct ieee80211_hw
*hw
, struct dentry
*debugfsdir
)
401 /* rate scale requires free function to be implemented */
403 il3945_rs_free(void *il
)
408 il3945_rs_alloc_sta(void *il_priv
, struct ieee80211_sta
*sta
, gfp_t gfp
)
410 struct il3945_rs_sta
*rs_sta
;
411 struct il3945_sta_priv
*psta
= (void *)sta
->drv_priv
;
412 struct il_priv
*il __maybe_unused
= il_priv
;
416 rs_sta
= &psta
->rs_sta
;
418 spin_lock_init(&rs_sta
->lock
);
419 init_timer(&rs_sta
->rate_scale_flush
);
427 il3945_rs_free_sta(void *il_priv
, struct ieee80211_sta
*sta
, void *il_sta
)
429 struct il3945_rs_sta
*rs_sta
= il_sta
;
432 * Be careful not to use any members of il3945_rs_sta (like trying
433 * to use il_priv to print out debugging) since it may not be fully
434 * initialized at this point.
436 del_timer_sync(&rs_sta
->rate_scale_flush
);
440 * il3945_rs_tx_status - Update rate control values based on Tx results
442 * NOTE: Uses il_priv->retry_rate for the # of retries attempted by
443 * the hardware for each rate.
446 il3945_rs_tx_status(void *il_rate
, struct ieee80211_supported_band
*sband
,
447 struct ieee80211_sta
*sta
, void *il_sta
,
450 s8 retries
= 0, current_count
;
451 int scale_rate_idx
, first_idx
, last_idx
;
453 struct il_priv
*il
= (struct il_priv
*)il_rate
;
454 struct il3945_rs_sta
*rs_sta
= il_sta
;
455 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
459 retries
= info
->status
.rates
[0].count
;
460 /* Sanity Check for retries */
461 if (retries
> RATE_RETRY_TH
)
462 retries
= RATE_RETRY_TH
;
464 first_idx
= sband
->bitrates
[info
->status
.rates
[0].idx
].hw_value
;
465 if (first_idx
< 0 || first_idx
>= RATE_COUNT_3945
) {
466 D_RATE("leave: Rate out of bounds: %d\n", first_idx
);
471 D_RATE("leave: No STA il data to update!\n");
475 /* Treat uninitialized rate scaling data same as non-existing. */
477 D_RATE("leave: STA il data uninitialized!\n");
481 rs_sta
->tx_packets
++;
483 scale_rate_idx
= first_idx
;
484 last_idx
= first_idx
;
487 * Update the win for each rate. We determine which rates
488 * were Tx'd based on the total number of retries vs. the number
489 * of retries configured for each rate -- currently set to the
490 * il value 'retry_rate' vs. rate specific
492 * On exit from this while loop last_idx indicates the rate
493 * at which the frame was finally transmitted (or failed if no
496 while (retries
> 1) {
497 if ((retries
- 1) < il
->retry_rate
) {
498 current_count
= (retries
- 1);
499 last_idx
= scale_rate_idx
;
501 current_count
= il
->retry_rate
;
502 last_idx
= il3945_rs_next_rate(il
, scale_rate_idx
);
505 /* Update this rate accounting for as many retries
506 * as was used for it (per current_count) */
507 il3945_collect_tx_data(rs_sta
, &rs_sta
->win
[scale_rate_idx
], 0,
508 current_count
, scale_rate_idx
);
509 D_RATE("Update rate %d for %d retries.\n", scale_rate_idx
,
512 retries
-= current_count
;
514 scale_rate_idx
= last_idx
;
517 /* Update the last idx win with success/failure based on ACK */
518 D_RATE("Update rate %d with %s.\n", last_idx
,
519 (info
->flags
& IEEE80211_TX_STAT_ACK
) ? "success" : "failure");
520 il3945_collect_tx_data(rs_sta
, &rs_sta
->win
[last_idx
],
521 info
->flags
& IEEE80211_TX_STAT_ACK
, 1,
524 /* We updated the rate scale win -- if its been more than
525 * flush_time since the last run, schedule the flush
527 spin_lock_irqsave(&rs_sta
->lock
, flags
);
529 if (!rs_sta
->flush_pending
&&
530 time_after(jiffies
, rs_sta
->last_flush
+ rs_sta
->flush_time
)) {
532 rs_sta
->last_partial_flush
= jiffies
;
533 rs_sta
->flush_pending
= 1;
534 mod_timer(&rs_sta
->rate_scale_flush
,
535 jiffies
+ rs_sta
->flush_time
);
538 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
544 il3945_get_adjacent_rate(struct il3945_rs_sta
*rs_sta
, u8 idx
, u16 rate_mask
,
545 enum ieee80211_band band
)
547 u8 high
= RATE_INVALID
;
548 u8 low
= RATE_INVALID
;
549 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
551 /* 802.11A walks to the next literal adjacent rate in
553 if (unlikely(band
== IEEE80211_BAND_5GHZ
)) {
557 /* Find the previous rate that is in the rate mask */
559 for (mask
= (1 << i
); i
>= 0; i
--, mask
>>= 1) {
560 if (rate_mask
& mask
) {
566 /* Find the next rate that is in the rate mask */
568 for (mask
= (1 << i
); i
< RATE_COUNT_3945
; i
++, mask
<<= 1) {
569 if (rate_mask
& mask
) {
575 return (high
<< 8) | low
;
579 while (low
!= RATE_INVALID
) {
581 low
= il3945_rates
[low
].prev_rs_tgg
;
583 low
= il3945_rates
[low
].prev_rs
;
584 if (low
== RATE_INVALID
)
586 if (rate_mask
& (1 << low
))
588 D_RATE("Skipping masked lower rate: %d\n", low
);
592 while (high
!= RATE_INVALID
) {
594 high
= il3945_rates
[high
].next_rs_tgg
;
596 high
= il3945_rates
[high
].next_rs
;
597 if (high
== RATE_INVALID
)
599 if (rate_mask
& (1 << high
))
601 D_RATE("Skipping masked higher rate: %d\n", high
);
604 return (high
<< 8) | low
;
608 * il3945_rs_get_rate - find the rate for the requested packet
610 * Returns the ieee80211_rate structure allocated by the driver.
612 * The rate control algorithm has no internal mapping between hw_mode's
613 * rate ordering and the rate ordering used by the rate control algorithm.
615 * The rate control algorithm uses a single table of rates that goes across
616 * the entire A/B/G spectrum vs. being limited to just one particular
619 * As such, we can't convert the idx obtained below into the hw_mode's
620 * rate table and must reference the driver allocated rate table
624 il3945_rs_get_rate(void *il_r
, struct ieee80211_sta
*sta
, void *il_sta
,
625 struct ieee80211_tx_rate_control
*txrc
)
627 struct ieee80211_supported_band
*sband
= txrc
->sband
;
628 struct sk_buff
*skb
= txrc
->skb
;
629 u8 low
= RATE_INVALID
;
630 u8 high
= RATE_INVALID
;
633 struct il3945_rs_sta
*rs_sta
= il_sta
;
634 struct il3945_rate_scale_data
*win
= NULL
;
635 int current_tpt
= IL_INVALID_VALUE
;
636 int low_tpt
= IL_INVALID_VALUE
;
637 int high_tpt
= IL_INVALID_VALUE
;
642 s8 max_rate_idx
= -1;
643 struct il_priv
*il __maybe_unused
= (struct il_priv
*)il_r
;
644 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
648 /* Treat uninitialized rate scaling data same as non-existing. */
649 if (rs_sta
&& !rs_sta
->il
) {
650 D_RATE("Rate scaling information not initialized yet.\n");
654 if (rate_control_send_low(sta
, il_sta
, txrc
))
657 rate_mask
= sta
->supp_rates
[sband
->band
];
659 /* get user max rate if set */
660 max_rate_idx
= txrc
->max_rate_idx
;
661 if (sband
->band
== IEEE80211_BAND_5GHZ
&& max_rate_idx
!= -1)
662 max_rate_idx
+= IL_FIRST_OFDM_RATE
;
663 if (max_rate_idx
< 0 || max_rate_idx
>= RATE_COUNT
)
666 idx
= min(rs_sta
->last_txrate_idx
& 0xffff, RATE_COUNT_3945
- 1);
668 if (sband
->band
== IEEE80211_BAND_5GHZ
)
669 rate_mask
= rate_mask
<< IL_FIRST_OFDM_RATE
;
671 spin_lock_irqsave(&rs_sta
->lock
, flags
);
673 /* for recent assoc, choose best rate regarding
676 if (rs_sta
->start_rate
!= RATE_INVALID
) {
677 if (rs_sta
->start_rate
< idx
&&
678 (rate_mask
& (1 << rs_sta
->start_rate
)))
679 idx
= rs_sta
->start_rate
;
680 rs_sta
->start_rate
= RATE_INVALID
;
683 /* force user max rate if set by user */
684 if (max_rate_idx
!= -1 && max_rate_idx
< idx
) {
685 if (rate_mask
& (1 << max_rate_idx
))
689 win
= &(rs_sta
->win
[idx
]);
691 fail_count
= win
->counter
- win
->success_counter
;
693 if (fail_count
< RATE_MIN_FAILURE_TH
&&
694 win
->success_counter
< RATE_MIN_SUCCESS_TH
) {
695 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
697 D_RATE("Invalid average_tpt on rate %d: "
698 "counter: %d, success_counter: %d, "
699 "expected_tpt is %sNULL\n", idx
, win
->counter
,
700 win
->success_counter
,
701 rs_sta
->expected_tpt
? "not " : "");
703 /* Can't calculate this yet; not enough history */
704 win
->average_tpt
= IL_INVALID_VALUE
;
709 current_tpt
= win
->average_tpt
;
712 il3945_get_adjacent_rate(rs_sta
, idx
, rate_mask
, sband
->band
);
713 low
= high_low
& 0xff;
714 high
= (high_low
>> 8) & 0xff;
716 /* If user set max rate, dont allow higher than user constrain */
717 if (max_rate_idx
!= -1 && max_rate_idx
< high
)
720 /* Collect Measured throughputs of adjacent rates */
721 if (low
!= RATE_INVALID
)
722 low_tpt
= rs_sta
->win
[low
].average_tpt
;
724 if (high
!= RATE_INVALID
)
725 high_tpt
= rs_sta
->win
[high
].average_tpt
;
727 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
731 /* Low success ratio , need to drop the rate */
732 if (win
->success_ratio
< RATE_DECREASE_TH
|| !current_tpt
) {
733 D_RATE("decrease rate because of low success_ratio\n");
735 /* No throughput measured yet for adjacent rates,
737 } else if (low_tpt
== IL_INVALID_VALUE
&& high_tpt
== IL_INVALID_VALUE
) {
739 if (high
!= RATE_INVALID
&&
740 win
->success_ratio
>= RATE_INCREASE_TH
)
742 else if (low
!= RATE_INVALID
)
745 /* Both adjacent throughputs are measured, but neither one has
746 * better throughput; we're using the best rate, don't change
748 } else if (low_tpt
!= IL_INVALID_VALUE
&& high_tpt
!= IL_INVALID_VALUE
749 && low_tpt
< current_tpt
&& high_tpt
< current_tpt
) {
751 D_RATE("No action -- low [%d] & high [%d] < "
752 "current_tpt [%d]\n", low_tpt
, high_tpt
, current_tpt
);
755 /* At least one of the rates has better throughput */
757 if (high_tpt
!= IL_INVALID_VALUE
) {
759 /* High rate has better throughput, Increase
761 if (high_tpt
> current_tpt
&&
762 win
->success_ratio
>= RATE_INCREASE_TH
)
765 D_RATE("decrease rate because of high tpt\n");
768 } else if (low_tpt
!= IL_INVALID_VALUE
) {
769 if (low_tpt
> current_tpt
) {
770 D_RATE("decrease rate because of low tpt\n");
772 } else if (win
->success_ratio
>= RATE_INCREASE_TH
) {
773 /* Lower rate has better
774 * throughput,decrease rate */
780 /* Sanity check; asked for decrease, but success rate or throughput
781 * has been good at old rate. Don't change it. */
782 if (scale_action
== -1 && low
!= RATE_INVALID
&&
783 (win
->success_ratio
> RATE_HIGH_TH
||
784 current_tpt
> 100 * rs_sta
->expected_tpt
[low
]))
787 switch (scale_action
) {
790 if (low
!= RATE_INVALID
)
795 if (high
!= RATE_INVALID
)
805 D_RATE("Selected %d (action %d) - low %d high %d\n", idx
, scale_action
,
810 if (sband
->band
== IEEE80211_BAND_5GHZ
) {
811 if (WARN_ON_ONCE(idx
< IL_FIRST_OFDM_RATE
))
812 idx
= IL_FIRST_OFDM_RATE
;
813 rs_sta
->last_txrate_idx
= idx
;
814 info
->control
.rates
[0].idx
= idx
- IL_FIRST_OFDM_RATE
;
816 rs_sta
->last_txrate_idx
= idx
;
817 info
->control
.rates
[0].idx
= rs_sta
->last_txrate_idx
;
819 info
->control
.rates
[0].count
= 1;
821 D_RATE("leave: %d\n", idx
);
824 #ifdef CONFIG_MAC80211_DEBUGFS
827 il3945_sta_dbgfs_stats_table_read(struct file
*file
, char __user
*user_buf
,
828 size_t count
, loff_t
*ppos
)
834 struct il3945_rs_sta
*lq_sta
= file
->private_data
;
836 buff
= kmalloc(1024, GFP_KERNEL
);
842 "tx packets=%d last rate idx=%d\n"
843 "rate=0x%X flush time %d\n", lq_sta
->tx_packets
,
844 lq_sta
->last_txrate_idx
, lq_sta
->start_rate
,
845 jiffies_to_msecs(lq_sta
->flush_time
));
846 for (j
= 0; j
< RATE_COUNT_3945
; j
++) {
848 sprintf(buff
+ desc
, "counter=%d success=%d %%=%d\n",
849 lq_sta
->win
[j
].counter
,
850 lq_sta
->win
[j
].success_counter
,
851 lq_sta
->win
[j
].success_ratio
);
853 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
858 static const struct file_operations rs_sta_dbgfs_stats_table_ops
= {
859 .read
= il3945_sta_dbgfs_stats_table_read
,
861 .llseek
= default_llseek
,
865 il3945_add_debugfs(void *il
, void *il_sta
, struct dentry
*dir
)
867 struct il3945_rs_sta
*lq_sta
= il_sta
;
869 lq_sta
->rs_sta_dbgfs_stats_table_file
=
870 debugfs_create_file("rate_stats_table", 0600, dir
, lq_sta
,
871 &rs_sta_dbgfs_stats_table_ops
);
876 il3945_remove_debugfs(void *il
, void *il_sta
)
878 struct il3945_rs_sta
*lq_sta
= il_sta
;
879 debugfs_remove(lq_sta
->rs_sta_dbgfs_stats_table_file
);
884 * Initialization of rate scaling information is done by driver after
885 * the station is added. Since mac80211 calls this function before a
886 * station is added we ignore it.
889 il3945_rs_rate_init_stub(void *il_r
, struct ieee80211_supported_band
*sband
,
890 struct cfg80211_chan_def
*chandef
,
891 struct ieee80211_sta
*sta
, void *il_sta
)
895 static struct rate_control_ops rs_ops
= {
898 .tx_status
= il3945_rs_tx_status
,
899 .get_rate
= il3945_rs_get_rate
,
900 .rate_init
= il3945_rs_rate_init_stub
,
901 .alloc
= il3945_rs_alloc
,
902 .free
= il3945_rs_free
,
903 .alloc_sta
= il3945_rs_alloc_sta
,
904 .free_sta
= il3945_rs_free_sta
,
905 #ifdef CONFIG_MAC80211_DEBUGFS
906 .add_sta_debugfs
= il3945_add_debugfs
,
907 .remove_sta_debugfs
= il3945_remove_debugfs
,
913 il3945_rate_scale_init(struct ieee80211_hw
*hw
, s32 sta_id
)
915 struct il_priv
*il
= hw
->priv
;
918 struct il3945_rs_sta
*rs_sta
;
919 struct ieee80211_sta
*sta
;
920 struct il3945_sta_priv
*psta
;
926 sta
= ieee80211_find_sta(il
->vif
, il
->stations
[sta_id
].sta
.sta
.addr
);
928 D_RATE("Unable to find station to initialize rate scaling.\n");
933 psta
= (void *)sta
->drv_priv
;
934 rs_sta
= &psta
->rs_sta
;
936 spin_lock_irqsave(&rs_sta
->lock
, flags
);
940 case IEEE80211_BAND_2GHZ
:
941 /* TODO: this always does G, not a regression */
942 if (il
->active
.flags
& RXON_FLG_TGG_PROTECT_MSK
) {
944 rs_sta
->expected_tpt
= il3945_expected_tpt_g_prot
;
946 rs_sta
->expected_tpt
= il3945_expected_tpt_g
;
948 case IEEE80211_BAND_5GHZ
:
949 rs_sta
->expected_tpt
= il3945_expected_tpt_a
;
956 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
958 rssi
= il
->_3945
.last_rx_rssi
;
960 rssi
= IL_MIN_RSSI_VAL
;
962 D_RATE("Network RSSI: %d\n", rssi
);
964 rs_sta
->start_rate
= il3945_get_rate_idx_by_rssi(rssi
, il
->band
);
966 D_RATE("leave: rssi %d assign rate idx: " "%d (plcp 0x%x)\n", rssi
,
967 rs_sta
->start_rate
, il3945_rates
[rs_sta
->start_rate
].plcp
);
972 il3945_rate_control_register(void)
974 return ieee80211_rate_control_register(&rs_ops
);
978 il3945_rate_control_unregister(void)
980 ieee80211_rate_control_unregister(&rs_ops
);