1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
7 * Intel Linux Wireless <ilw@linux.intel.com>
8 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
10 *****************************************************************************/
12 #include <linux/kernel.h>
13 #include <linux/skbuff.h>
14 #include <linux/slab.h>
15 #include <net/mac80211.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/delay.h>
21 #include <linux/workqueue.h>
26 #define RS_NAME "iwl-3945-rs"
28 static s32 il3945_expected_tpt_g
[RATE_COUNT_3945
] = {
29 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202
32 static s32 il3945_expected_tpt_g_prot
[RATE_COUNT_3945
] = {
33 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125
36 static s32 il3945_expected_tpt_a
[RATE_COUNT_3945
] = {
37 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186
40 static s32 il3945_expected_tpt_b
[RATE_COUNT_3945
] = {
41 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0
44 struct il3945_tpt_entry
{
49 static struct il3945_tpt_entry il3945_tpt_table_a
[] = {
60 static struct il3945_tpt_entry il3945_tpt_table_g
[] = {
73 #define RATE_MAX_WINDOW 62
74 #define RATE_FLUSH (3*HZ)
75 #define RATE_WIN_FLUSH (HZ/2)
76 #define IL39_RATE_HIGH_TH 11520
77 #define IL_SUCCESS_UP_TH 8960
78 #define IL_SUCCESS_DOWN_TH 10880
79 #define RATE_MIN_FAILURE_TH 6
80 #define RATE_MIN_SUCCESS_TH 8
81 #define RATE_DECREASE_TH 1920
82 #define RATE_RETRY_TH 15
85 il3945_get_rate_idx_by_rssi(s32 rssi
, enum nl80211_band band
)
89 struct il3945_tpt_entry
*tpt_table
= NULL
;
91 if (rssi
< IL_MIN_RSSI_VAL
|| rssi
> IL_MAX_RSSI_VAL
)
92 rssi
= IL_MIN_RSSI_VAL
;
95 case NL80211_BAND_2GHZ
:
96 tpt_table
= il3945_tpt_table_g
;
97 table_size
= ARRAY_SIZE(il3945_tpt_table_g
);
99 case NL80211_BAND_5GHZ
:
100 tpt_table
= il3945_tpt_table_a
;
101 table_size
= ARRAY_SIZE(il3945_tpt_table_a
);
108 while (idx
< table_size
&& rssi
< tpt_table
[idx
].min_rssi
)
111 idx
= min(idx
, table_size
- 1);
113 return tpt_table
[idx
].idx
;
117 il3945_clear_win(struct il3945_rate_scale_data
*win
)
120 win
->success_counter
= 0;
121 win
->success_ratio
= -1;
123 win
->average_tpt
= IL_INVALID_VALUE
;
128 * il3945_rate_scale_flush_wins - flush out the rate scale wins
130 * Returns the number of wins that have gathered data but were
131 * not flushed. If there were any that were not flushed, then
132 * reschedule the rate flushing routine.
135 il3945_rate_scale_flush_wins(struct il3945_rs_sta
*rs_sta
)
140 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
143 * For each rate, if we have collected data on that rate
144 * and it has been more than RATE_WIN_FLUSH
145 * since we flushed, clear out the gathered stats
147 for (i
= 0; i
< RATE_COUNT_3945
; i
++) {
148 if (!rs_sta
->win
[i
].counter
)
151 spin_lock_irqsave(&rs_sta
->lock
, flags
);
152 if (time_after(jiffies
, rs_sta
->win
[i
].stamp
+ RATE_WIN_FLUSH
)) {
153 D_RATE("flushing %d samples of rate " "idx %d\n",
154 rs_sta
->win
[i
].counter
, i
);
155 il3945_clear_win(&rs_sta
->win
[i
]);
158 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
164 #define RATE_FLUSH_MAX 5000 /* msec */
165 #define RATE_FLUSH_MIN 50 /* msec */
166 #define IL_AVERAGE_PACKETS 1500
169 il3945_bg_rate_scale_flush(struct timer_list
*t
)
171 struct il3945_rs_sta
*rs_sta
= from_timer(rs_sta
, t
, rate_scale_flush
);
172 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
175 u32 packet_count
, duration
, pps
;
179 unflushed
= il3945_rate_scale_flush_wins(rs_sta
);
181 spin_lock_irqsave(&rs_sta
->lock
, flags
);
183 /* Number of packets Rx'd since last time this timer ran */
184 packet_count
= (rs_sta
->tx_packets
- rs_sta
->last_tx_packets
) + 1;
186 rs_sta
->last_tx_packets
= rs_sta
->tx_packets
+ 1;
190 jiffies_to_msecs(jiffies
- rs_sta
->last_partial_flush
);
192 D_RATE("Tx'd %d packets in %dms\n", packet_count
, duration
);
194 /* Determine packets per second */
196 pps
= (packet_count
* 1000) / duration
;
201 duration
= (IL_AVERAGE_PACKETS
* 1000) / pps
;
202 if (duration
< RATE_FLUSH_MIN
)
203 duration
= RATE_FLUSH_MIN
;
204 else if (duration
> RATE_FLUSH_MAX
)
205 duration
= RATE_FLUSH_MAX
;
207 duration
= RATE_FLUSH_MAX
;
209 rs_sta
->flush_time
= msecs_to_jiffies(duration
);
211 D_RATE("new flush period: %d msec ave %d\n", duration
,
214 mod_timer(&rs_sta
->rate_scale_flush
,
215 jiffies
+ rs_sta
->flush_time
);
217 rs_sta
->last_partial_flush
= jiffies
;
219 rs_sta
->flush_time
= RATE_FLUSH
;
220 rs_sta
->flush_pending
= 0;
222 /* If there weren't any unflushed entries, we don't schedule the timer
225 rs_sta
->last_flush
= jiffies
;
227 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
233 * il3945_collect_tx_data - Update the success/failure sliding win
235 * We keep a sliding win of the last 64 packets transmitted
236 * at this rate. win->data contains the bitmask of successful
240 il3945_collect_tx_data(struct il3945_rs_sta
*rs_sta
,
241 struct il3945_rate_scale_data
*win
, int success
,
242 int retries
, int idx
)
246 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
249 D_RATE("leave: retries == 0 -- should be at least 1\n");
253 spin_lock_irqsave(&rs_sta
->lock
, flags
);
256 * Keep track of only the latest 62 tx frame attempts in this rate's
257 * history win; anything older isn't really relevant any more.
258 * If we have filled up the sliding win, drop the oldest attempt;
259 * if the oldest attempt (highest bit in bitmap) shows "success",
260 * subtract "1" from the success counter (this is the main reason
261 * we keep these bitmaps!).
263 while (retries
> 0) {
264 if (win
->counter
>= RATE_MAX_WINDOW
) {
266 /* remove earliest */
267 win
->counter
= RATE_MAX_WINDOW
- 1;
269 if (win
->data
& (1ULL << (RATE_MAX_WINDOW
- 1))) {
270 win
->data
&= ~(1ULL << (RATE_MAX_WINDOW
- 1));
271 win
->success_counter
--;
275 /* Increment frames-attempted counter */
278 /* Shift bitmap by one frame (throw away oldest history),
279 * OR in "1", and increment "success" if this
280 * frame was successful. */
283 win
->success_counter
++;
291 /* Calculate current success ratio, avoid divide-by-0! */
292 if (win
->counter
> 0)
294 128 * (100 * win
->success_counter
) / win
->counter
;
296 win
->success_ratio
= IL_INVALID_VALUE
;
298 fail_count
= win
->counter
- win
->success_counter
;
300 /* Calculate average throughput, if we have enough history. */
301 if (fail_count
>= RATE_MIN_FAILURE_TH
||
302 win
->success_counter
>= RATE_MIN_SUCCESS_TH
)
304 ((win
->success_ratio
* rs_sta
->expected_tpt
[idx
] +
307 win
->average_tpt
= IL_INVALID_VALUE
;
309 /* Tag this win as having been updated */
310 win
->stamp
= jiffies
;
312 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
316 * Called after adding a new station to initialize rate scaling
319 il3945_rs_rate_init(struct il_priv
*il
, struct ieee80211_sta
*sta
, u8 sta_id
)
321 struct ieee80211_hw
*hw
= il
->hw
;
322 struct ieee80211_conf
*conf
= &il
->hw
->conf
;
323 struct il3945_sta_priv
*psta
;
324 struct il3945_rs_sta
*rs_sta
;
325 struct ieee80211_supported_band
*sband
;
329 if (sta_id
== il
->hw_params
.bcast_id
)
332 psta
= (struct il3945_sta_priv
*)sta
->drv_priv
;
333 rs_sta
= &psta
->rs_sta
;
334 sband
= hw
->wiphy
->bands
[conf
->chandef
.chan
->band
];
338 rs_sta
->start_rate
= RATE_INVALID
;
340 /* default to just 802.11b */
341 rs_sta
->expected_tpt
= il3945_expected_tpt_b
;
343 rs_sta
->last_partial_flush
= jiffies
;
344 rs_sta
->last_flush
= jiffies
;
345 rs_sta
->flush_time
= RATE_FLUSH
;
346 rs_sta
->last_tx_packets
= 0;
348 for (i
= 0; i
< RATE_COUNT_3945
; i
++)
349 il3945_clear_win(&rs_sta
->win
[i
]);
351 /* TODO: what is a good starting rate for STA? About middle? Maybe not
352 * the lowest or the highest rate.. Could consider using RSSI from
353 * previous packets? Need to have IEEE 802.1X auth succeed immediately
356 for (i
= sband
->n_bitrates
- 1; i
>= 0; i
--) {
357 if (sta
->deflink
.supp_rates
[sband
->band
] & (1 << i
)) {
358 rs_sta
->last_txrate_idx
= i
;
363 il
->_3945
.sta_supp_rates
= sta
->deflink
.supp_rates
[sband
->band
];
364 /* For 5 GHz band it start at IL_FIRST_OFDM_RATE */
365 if (sband
->band
== NL80211_BAND_5GHZ
) {
366 rs_sta
->last_txrate_idx
+= IL_FIRST_OFDM_RATE
;
367 il
->_3945
.sta_supp_rates
<<= IL_FIRST_OFDM_RATE
;
371 il
->stations
[sta_id
].used
&= ~IL_STA_UCODE_INPROGRESS
;
377 il3945_rs_alloc(struct ieee80211_hw
*hw
)
382 /* rate scale requires free function to be implemented */
384 il3945_rs_free(void *il
)
389 il3945_rs_alloc_sta(void *il_priv
, struct ieee80211_sta
*sta
, gfp_t gfp
)
391 struct il3945_rs_sta
*rs_sta
;
392 struct il3945_sta_priv
*psta
= (void *)sta
->drv_priv
;
393 struct il_priv
*il __maybe_unused
= il_priv
;
397 rs_sta
= &psta
->rs_sta
;
399 spin_lock_init(&rs_sta
->lock
);
400 timer_setup(&rs_sta
->rate_scale_flush
, il3945_bg_rate_scale_flush
, 0);
407 il3945_rs_free_sta(void *il_priv
, struct ieee80211_sta
*sta
, void *il_sta
)
409 struct il3945_rs_sta
*rs_sta
= il_sta
;
412 * Be careful not to use any members of il3945_rs_sta (like trying
413 * to use il_priv to print out debugging) since it may not be fully
414 * initialized at this point.
416 del_timer_sync(&rs_sta
->rate_scale_flush
);
420 * il3945_rs_tx_status - Update rate control values based on Tx results
422 * NOTE: Uses il_priv->retry_rate for the # of retries attempted by
423 * the hardware for each rate.
426 il3945_rs_tx_status(void *il_rate
, struct ieee80211_supported_band
*sband
,
427 struct ieee80211_sta
*sta
, void *il_sta
,
430 s8 retries
= 0, current_count
;
431 int scale_rate_idx
, first_idx
, last_idx
;
433 struct il_priv
*il
= (struct il_priv
*)il_rate
;
434 struct il3945_rs_sta
*rs_sta
= il_sta
;
435 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
439 retries
= info
->status
.rates
[0].count
;
440 /* Sanity Check for retries */
441 if (retries
> RATE_RETRY_TH
)
442 retries
= RATE_RETRY_TH
;
444 first_idx
= sband
->bitrates
[info
->status
.rates
[0].idx
].hw_value
;
445 if (first_idx
< 0 || first_idx
>= RATE_COUNT_3945
) {
446 D_RATE("leave: Rate out of bounds: %d\n", first_idx
);
451 D_RATE("leave: No STA il data to update!\n");
455 /* Treat uninitialized rate scaling data same as non-existing. */
457 D_RATE("leave: STA il data uninitialized!\n");
461 rs_sta
->tx_packets
++;
463 scale_rate_idx
= first_idx
;
464 last_idx
= first_idx
;
467 * Update the win for each rate. We determine which rates
468 * were Tx'd based on the total number of retries vs. the number
469 * of retries configured for each rate -- currently set to the
470 * il value 'retry_rate' vs. rate specific
472 * On exit from this while loop last_idx indicates the rate
473 * at which the frame was finally transmitted (or failed if no
476 while (retries
> 1) {
477 if ((retries
- 1) < il
->retry_rate
) {
478 current_count
= (retries
- 1);
479 last_idx
= scale_rate_idx
;
481 current_count
= il
->retry_rate
;
482 last_idx
= il3945_rs_next_rate(il
, scale_rate_idx
);
485 /* Update this rate accounting for as many retries
486 * as was used for it (per current_count) */
487 il3945_collect_tx_data(rs_sta
, &rs_sta
->win
[scale_rate_idx
], 0,
488 current_count
, scale_rate_idx
);
489 D_RATE("Update rate %d for %d retries.\n", scale_rate_idx
,
492 retries
-= current_count
;
494 scale_rate_idx
= last_idx
;
497 /* Update the last idx win with success/failure based on ACK */
498 D_RATE("Update rate %d with %s.\n", last_idx
,
499 (info
->flags
& IEEE80211_TX_STAT_ACK
) ? "success" : "failure");
500 il3945_collect_tx_data(rs_sta
, &rs_sta
->win
[last_idx
],
501 info
->flags
& IEEE80211_TX_STAT_ACK
, 1,
504 /* We updated the rate scale win -- if its been more than
505 * flush_time since the last run, schedule the flush
507 spin_lock_irqsave(&rs_sta
->lock
, flags
);
509 if (!rs_sta
->flush_pending
&&
510 time_after(jiffies
, rs_sta
->last_flush
+ rs_sta
->flush_time
)) {
512 rs_sta
->last_partial_flush
= jiffies
;
513 rs_sta
->flush_pending
= 1;
514 mod_timer(&rs_sta
->rate_scale_flush
,
515 jiffies
+ rs_sta
->flush_time
);
518 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
524 il3945_get_adjacent_rate(struct il3945_rs_sta
*rs_sta
, u8 idx
, u16 rate_mask
,
525 enum nl80211_band band
)
527 u8 high
= RATE_INVALID
;
528 u8 low
= RATE_INVALID
;
529 struct il_priv
*il __maybe_unused
= rs_sta
->il
;
531 /* 802.11A walks to the next literal adjacent rate in
533 if (unlikely(band
== NL80211_BAND_5GHZ
)) {
537 /* Find the previous rate that is in the rate mask */
539 for (mask
= (1 << i
); i
>= 0; i
--, mask
>>= 1) {
540 if (rate_mask
& mask
) {
546 /* Find the next rate that is in the rate mask */
548 for (mask
= (1 << i
); i
< RATE_COUNT_3945
; i
++, mask
<<= 1) {
549 if (rate_mask
& mask
) {
555 return (high
<< 8) | low
;
559 while (low
!= RATE_INVALID
) {
561 low
= il3945_rates
[low
].prev_rs_tgg
;
563 low
= il3945_rates
[low
].prev_rs
;
564 if (low
== RATE_INVALID
)
566 if (rate_mask
& (1 << low
))
568 D_RATE("Skipping masked lower rate: %d\n", low
);
572 while (high
!= RATE_INVALID
) {
574 high
= il3945_rates
[high
].next_rs_tgg
;
576 high
= il3945_rates
[high
].next_rs
;
577 if (high
== RATE_INVALID
)
579 if (rate_mask
& (1 << high
))
581 D_RATE("Skipping masked higher rate: %d\n", high
);
584 return (high
<< 8) | low
;
588 * il3945_rs_get_rate - find the rate for the requested packet
590 * Returns the ieee80211_rate structure allocated by the driver.
592 * The rate control algorithm has no internal mapping between hw_mode's
593 * rate ordering and the rate ordering used by the rate control algorithm.
595 * The rate control algorithm uses a single table of rates that goes across
596 * the entire A/B/G spectrum vs. being limited to just one particular
599 * As such, we can't convert the idx obtained below into the hw_mode's
600 * rate table and must reference the driver allocated rate table
604 il3945_rs_get_rate(void *il_r
, struct ieee80211_sta
*sta
, void *il_sta
,
605 struct ieee80211_tx_rate_control
*txrc
)
607 struct ieee80211_supported_band
*sband
= txrc
->sband
;
608 struct sk_buff
*skb
= txrc
->skb
;
609 u8 low
= RATE_INVALID
;
610 u8 high
= RATE_INVALID
;
613 struct il3945_rs_sta
*rs_sta
= il_sta
;
614 struct il3945_rate_scale_data
*win
= NULL
;
615 int current_tpt
= IL_INVALID_VALUE
;
616 int low_tpt
= IL_INVALID_VALUE
;
617 int high_tpt
= IL_INVALID_VALUE
;
622 s8 max_rate_idx
= -1;
623 struct il_priv
*il __maybe_unused
= (struct il_priv
*)il_r
;
624 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
628 /* Treat uninitialized rate scaling data same as non-existing. */
629 if (rs_sta
&& !rs_sta
->il
) {
630 D_RATE("Rate scaling information not initialized yet.\n");
634 rate_mask
= sta
->deflink
.supp_rates
[sband
->band
];
636 /* get user max rate if set */
637 max_rate_idx
= fls(txrc
->rate_idx_mask
) - 1;
638 if (sband
->band
== NL80211_BAND_5GHZ
&& max_rate_idx
!= -1)
639 max_rate_idx
+= IL_FIRST_OFDM_RATE
;
640 if (max_rate_idx
< 0 || max_rate_idx
>= RATE_COUNT
)
643 idx
= min(rs_sta
->last_txrate_idx
& 0xffff, RATE_COUNT_3945
- 1);
645 if (sband
->band
== NL80211_BAND_5GHZ
)
646 rate_mask
= rate_mask
<< IL_FIRST_OFDM_RATE
;
648 spin_lock_irqsave(&rs_sta
->lock
, flags
);
650 /* for recent assoc, choose best rate regarding
653 if (rs_sta
->start_rate
!= RATE_INVALID
) {
654 if (rs_sta
->start_rate
< idx
&&
655 (rate_mask
& (1 << rs_sta
->start_rate
)))
656 idx
= rs_sta
->start_rate
;
657 rs_sta
->start_rate
= RATE_INVALID
;
660 /* force user max rate if set by user */
661 if (max_rate_idx
!= -1 && max_rate_idx
< idx
) {
662 if (rate_mask
& (1 << max_rate_idx
))
666 win
= &(rs_sta
->win
[idx
]);
668 fail_count
= win
->counter
- win
->success_counter
;
670 if (fail_count
< RATE_MIN_FAILURE_TH
&&
671 win
->success_counter
< RATE_MIN_SUCCESS_TH
) {
672 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
674 D_RATE("Invalid average_tpt on rate %d: "
675 "counter: %d, success_counter: %d, "
676 "expected_tpt is %sNULL\n", idx
, win
->counter
,
677 win
->success_counter
,
678 rs_sta
->expected_tpt
? "not " : "");
680 /* Can't calculate this yet; not enough history */
681 win
->average_tpt
= IL_INVALID_VALUE
;
686 current_tpt
= win
->average_tpt
;
689 il3945_get_adjacent_rate(rs_sta
, idx
, rate_mask
, sband
->band
);
690 low
= high_low
& 0xff;
691 high
= (high_low
>> 8) & 0xff;
693 /* If user set max rate, dont allow higher than user constrain */
694 if (max_rate_idx
!= -1 && max_rate_idx
< high
)
697 /* Collect Measured throughputs of adjacent rates */
698 if (low
!= RATE_INVALID
)
699 low_tpt
= rs_sta
->win
[low
].average_tpt
;
701 if (high
!= RATE_INVALID
)
702 high_tpt
= rs_sta
->win
[high
].average_tpt
;
704 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
708 /* Low success ratio , need to drop the rate */
709 if (win
->success_ratio
< RATE_DECREASE_TH
|| !current_tpt
) {
710 D_RATE("decrease rate because of low success_ratio\n");
712 /* No throughput measured yet for adjacent rates,
714 } else if (low_tpt
== IL_INVALID_VALUE
&& high_tpt
== IL_INVALID_VALUE
) {
716 if (high
!= RATE_INVALID
&&
717 win
->success_ratio
>= RATE_INCREASE_TH
)
719 else if (low
!= RATE_INVALID
)
722 /* Both adjacent throughputs are measured, but neither one has
723 * better throughput; we're using the best rate, don't change
725 } else if (low_tpt
!= IL_INVALID_VALUE
&& high_tpt
!= IL_INVALID_VALUE
726 && low_tpt
< current_tpt
&& high_tpt
< current_tpt
) {
728 D_RATE("No action -- low [%d] & high [%d] < "
729 "current_tpt [%d]\n", low_tpt
, high_tpt
, current_tpt
);
732 /* At least one of the rates has better throughput */
734 if (high_tpt
!= IL_INVALID_VALUE
) {
736 /* High rate has better throughput, Increase
738 if (high_tpt
> current_tpt
&&
739 win
->success_ratio
>= RATE_INCREASE_TH
)
742 D_RATE("decrease rate because of high tpt\n");
745 } else if (low_tpt
!= IL_INVALID_VALUE
) {
746 if (low_tpt
> current_tpt
) {
747 D_RATE("decrease rate because of low tpt\n");
749 } else if (win
->success_ratio
>= RATE_INCREASE_TH
) {
750 /* Lower rate has better
751 * throughput,decrease rate */
757 /* Sanity check; asked for decrease, but success rate or throughput
758 * has been good at old rate. Don't change it. */
759 if (scale_action
== -1 && low
!= RATE_INVALID
&&
760 (win
->success_ratio
> RATE_HIGH_TH
||
761 current_tpt
> 100 * rs_sta
->expected_tpt
[low
]))
764 switch (scale_action
) {
767 if (low
!= RATE_INVALID
)
772 if (high
!= RATE_INVALID
)
782 D_RATE("Selected %d (action %d) - low %d high %d\n", idx
, scale_action
,
787 if (sband
->band
== NL80211_BAND_5GHZ
) {
788 if (WARN_ON_ONCE(idx
< IL_FIRST_OFDM_RATE
))
789 idx
= IL_FIRST_OFDM_RATE
;
790 rs_sta
->last_txrate_idx
= idx
;
791 info
->control
.rates
[0].idx
= idx
- IL_FIRST_OFDM_RATE
;
793 rs_sta
->last_txrate_idx
= idx
;
794 info
->control
.rates
[0].idx
= rs_sta
->last_txrate_idx
;
796 info
->control
.rates
[0].count
= 1;
798 D_RATE("leave: %d\n", idx
);
801 #ifdef CONFIG_MAC80211_DEBUGFS
804 il3945_sta_dbgfs_stats_table_read(struct file
*file
, char __user
*user_buf
,
805 size_t count
, loff_t
*ppos
)
811 struct il3945_rs_sta
*lq_sta
= file
->private_data
;
813 buff
= kmalloc(1024, GFP_KERNEL
);
819 "tx packets=%d last rate idx=%d\n"
820 "rate=0x%X flush time %d\n", lq_sta
->tx_packets
,
821 lq_sta
->last_txrate_idx
, lq_sta
->start_rate
,
822 jiffies_to_msecs(lq_sta
->flush_time
));
823 for (j
= 0; j
< RATE_COUNT_3945
; j
++) {
825 sprintf(buff
+ desc
, "counter=%d success=%d %%=%d\n",
826 lq_sta
->win
[j
].counter
,
827 lq_sta
->win
[j
].success_counter
,
828 lq_sta
->win
[j
].success_ratio
);
830 ret
= simple_read_from_buffer(user_buf
, count
, ppos
, buff
, desc
);
835 static const struct file_operations rs_sta_dbgfs_stats_table_ops
= {
836 .read
= il3945_sta_dbgfs_stats_table_read
,
838 .llseek
= default_llseek
,
842 il3945_add_debugfs(void *il
, void *il_sta
, struct dentry
*dir
)
844 struct il3945_rs_sta
*lq_sta
= il_sta
;
846 debugfs_create_file("rate_stats_table", 0600, dir
, lq_sta
,
847 &rs_sta_dbgfs_stats_table_ops
);
852 * Initialization of rate scaling information is done by driver after
853 * the station is added. Since mac80211 calls this function before a
854 * station is added we ignore it.
857 il3945_rs_rate_init_stub(void *il_r
, struct ieee80211_supported_band
*sband
,
858 struct cfg80211_chan_def
*chandef
,
859 struct ieee80211_sta
*sta
, void *il_sta
)
863 static const struct rate_control_ops rs_ops
= {
865 .tx_status
= il3945_rs_tx_status
,
866 .get_rate
= il3945_rs_get_rate
,
867 .rate_init
= il3945_rs_rate_init_stub
,
868 .alloc
= il3945_rs_alloc
,
869 .free
= il3945_rs_free
,
870 .alloc_sta
= il3945_rs_alloc_sta
,
871 .free_sta
= il3945_rs_free_sta
,
872 #ifdef CONFIG_MAC80211_DEBUGFS
873 .add_sta_debugfs
= il3945_add_debugfs
,
879 il3945_rate_scale_init(struct ieee80211_hw
*hw
, s32 sta_id
)
881 struct il_priv
*il
= hw
->priv
;
884 struct il3945_rs_sta
*rs_sta
;
885 struct ieee80211_sta
*sta
;
886 struct il3945_sta_priv
*psta
;
892 sta
= ieee80211_find_sta(il
->vif
, il
->stations
[sta_id
].sta
.sta
.addr
);
894 D_RATE("Unable to find station to initialize rate scaling.\n");
899 psta
= (void *)sta
->drv_priv
;
900 rs_sta
= &psta
->rs_sta
;
902 spin_lock_irqsave(&rs_sta
->lock
, flags
);
906 case NL80211_BAND_2GHZ
:
907 /* TODO: this always does G, not a regression */
908 if (il
->active
.flags
& RXON_FLG_TGG_PROTECT_MSK
) {
910 rs_sta
->expected_tpt
= il3945_expected_tpt_g_prot
;
912 rs_sta
->expected_tpt
= il3945_expected_tpt_g
;
914 case NL80211_BAND_5GHZ
:
915 rs_sta
->expected_tpt
= il3945_expected_tpt_a
;
922 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
924 rssi
= il
->_3945
.last_rx_rssi
;
926 rssi
= IL_MIN_RSSI_VAL
;
928 D_RATE("Network RSSI: %d\n", rssi
);
930 rs_sta
->start_rate
= il3945_get_rate_idx_by_rssi(rssi
, il
->band
);
932 D_RATE("leave: rssi %d assign rate idx: " "%d (plcp 0x%x)\n", rssi
,
933 rs_sta
->start_rate
, il3945_rates
[rs_sta
->start_rate
].plcp
);
938 il3945_rate_control_register(void)
940 return ieee80211_rate_control_register(&rs_ops
);
944 il3945_rate_control_unregister(void)
946 ieee80211_rate_control_unregister(&rs_ops
);