1 /******************************************************************************
3 * Copyright(c) 2005 - 2008 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 * James P. Ketrenos <ipw2100-admin@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/wireless.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>
41 #define RS_NAME "iwl-3945-rs"
43 struct iwl3945_rate_scale_data
{
52 struct iwl3945_rs_sta
{
55 unsigned long last_partial_flush
;
56 unsigned long last_flush
;
64 struct timer_list rate_scale_flush
;
65 struct iwl3945_rate_scale_data win
[IWL_RATE_COUNT
];
67 /* used to be in sta_info */
71 static s32 iwl3945_expected_tpt_g
[IWL_RATE_COUNT
] = {
72 7, 13, 35, 58, 0, 0, 76, 104, 130, 168, 191, 202
75 static s32 iwl3945_expected_tpt_g_prot
[IWL_RATE_COUNT
] = {
76 7, 13, 35, 58, 0, 0, 0, 80, 93, 113, 123, 125
79 static s32 iwl3945_expected_tpt_a
[IWL_RATE_COUNT
] = {
80 0, 0, 0, 0, 40, 57, 72, 98, 121, 154, 177, 186
83 static s32 iwl3945_expected_tpt_b
[IWL_RATE_COUNT
] = {
84 7, 13, 35, 58, 0, 0, 0, 0, 0, 0, 0, 0
87 struct iwl3945_tpt_entry
{
92 static struct iwl3945_tpt_entry iwl3945_tpt_table_a
[] = {
93 {-60, IWL_RATE_54M_INDEX
},
94 {-64, IWL_RATE_48M_INDEX
},
95 {-72, IWL_RATE_36M_INDEX
},
96 {-80, IWL_RATE_24M_INDEX
},
97 {-84, IWL_RATE_18M_INDEX
},
98 {-85, IWL_RATE_12M_INDEX
},
99 {-87, IWL_RATE_9M_INDEX
},
100 {-89, IWL_RATE_6M_INDEX
}
103 static struct iwl3945_tpt_entry iwl3945_tpt_table_g
[] = {
104 {-60, IWL_RATE_54M_INDEX
},
105 {-64, IWL_RATE_48M_INDEX
},
106 {-68, IWL_RATE_36M_INDEX
},
107 {-80, IWL_RATE_24M_INDEX
},
108 {-84, IWL_RATE_18M_INDEX
},
109 {-85, IWL_RATE_12M_INDEX
},
110 {-86, IWL_RATE_11M_INDEX
},
111 {-88, IWL_RATE_5M_INDEX
},
112 {-90, IWL_RATE_2M_INDEX
},
113 {-92, IWL_RATE_1M_INDEX
}
116 #define IWL_RATE_MAX_WINDOW 62
117 #define IWL_RATE_FLUSH (3*HZ/10)
118 #define IWL_RATE_WIN_FLUSH (HZ/2)
119 #define IWL_RATE_HIGH_TH 11520
120 #define IWL_RATE_MIN_FAILURE_TH 8
121 #define IWL_RATE_MIN_SUCCESS_TH 8
122 #define IWL_RATE_DECREASE_TH 1920
124 static u8
iwl3945_get_rate_index_by_rssi(s32 rssi
, enum ieee80211_band band
)
128 struct iwl3945_tpt_entry
*tpt_table
= NULL
;
130 if ((rssi
< IWL_MIN_RSSI_VAL
) || (rssi
> IWL_MAX_RSSI_VAL
))
131 rssi
= IWL_MIN_RSSI_VAL
;
134 case IEEE80211_BAND_2GHZ
:
135 tpt_table
= iwl3945_tpt_table_g
;
136 table_size
= ARRAY_SIZE(iwl3945_tpt_table_g
);
139 case IEEE80211_BAND_5GHZ
:
140 tpt_table
= iwl3945_tpt_table_a
;
141 table_size
= ARRAY_SIZE(iwl3945_tpt_table_a
);
149 while ((index
< table_size
) && (rssi
< tpt_table
[index
].min_rssi
))
152 index
= min(index
, (table_size
- 1));
154 return tpt_table
[index
].index
;
157 static void iwl3945_clear_window(struct iwl3945_rate_scale_data
*window
)
160 window
->success_counter
= 0;
161 window
->success_ratio
= -1;
163 window
->average_tpt
= IWL_INV_TPT
;
168 * iwl3945_rate_scale_flush_windows - flush out the rate scale windows
170 * Returns the number of windows that have gathered data but were
171 * not flushed. If there were any that were not flushed, then
172 * reschedule the rate flushing routine.
174 static int iwl3945_rate_scale_flush_windows(struct iwl3945_rs_sta
*rs_sta
)
181 * For each rate, if we have collected data on that rate
182 * and it has been more than IWL_RATE_WIN_FLUSH
183 * since we flushed, clear out the gathered statistics
185 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
186 if (!rs_sta
->win
[i
].counter
)
189 spin_lock_irqsave(&rs_sta
->lock
, flags
);
190 if (time_after(jiffies
, rs_sta
->win
[i
].stamp
+
191 IWL_RATE_WIN_FLUSH
)) {
192 IWL_DEBUG_RATE("flushing %d samples of rate "
194 rs_sta
->win
[i
].counter
, i
);
195 iwl3945_clear_window(&rs_sta
->win
[i
]);
198 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
204 #define IWL_RATE_FLUSH_MAX 5000 /* msec */
205 #define IWL_RATE_FLUSH_MIN 50 /* msec */
207 static void iwl3945_bg_rate_scale_flush(unsigned long data
)
209 struct iwl3945_rs_sta
*rs_sta
= (void *)data
;
212 u32 packet_count
, duration
, pps
;
214 IWL_DEBUG_RATE("enter\n");
216 unflushed
= iwl3945_rate_scale_flush_windows(rs_sta
);
218 spin_lock_irqsave(&rs_sta
->lock
, flags
);
220 rs_sta
->flush_pending
= 0;
222 /* Number of packets Rx'd since last time this timer ran */
223 packet_count
= (rs_sta
->tx_packets
- rs_sta
->last_tx_packets
) + 1;
225 rs_sta
->last_tx_packets
= rs_sta
->tx_packets
+ 1;
229 jiffies_to_msecs(jiffies
- rs_sta
->last_partial_flush
);
230 /* duration = jiffies_to_msecs(rs_sta->flush_time); */
232 IWL_DEBUG_RATE("Tx'd %d packets in %dms\n",
233 packet_count
, duration
);
235 /* Determine packets per second */
237 pps
= (packet_count
* 1000) / duration
;
242 duration
= IWL_RATE_FLUSH_MAX
/ pps
;
243 if (duration
< IWL_RATE_FLUSH_MIN
)
244 duration
= IWL_RATE_FLUSH_MIN
;
246 duration
= IWL_RATE_FLUSH_MAX
;
248 rs_sta
->flush_time
= msecs_to_jiffies(duration
);
250 IWL_DEBUG_RATE("new flush period: %d msec ave %d\n",
251 duration
, packet_count
);
253 mod_timer(&rs_sta
->rate_scale_flush
, jiffies
+
256 rs_sta
->last_partial_flush
= jiffies
;
259 /* If there weren't any unflushed entries, we don't schedule the timer
262 rs_sta
->last_flush
= jiffies
;
264 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
266 IWL_DEBUG_RATE("leave\n");
270 * iwl3945_collect_tx_data - Update the success/failure sliding window
272 * We keep a sliding window of the last 64 packets transmitted
273 * at this rate. window->data contains the bitmask of successful
276 static void iwl3945_collect_tx_data(struct iwl3945_rs_sta
*rs_sta
,
277 struct iwl3945_rate_scale_data
*window
,
278 int success
, int retries
)
283 IWL_DEBUG_RATE("leave: retries == 0 -- should be at least 1\n");
288 spin_lock_irqsave(&rs_sta
->lock
, flags
);
290 /* If we have filled up the window then subtract one from the
291 * success counter if the high-bit is counting toward
293 if (window
->counter
== IWL_RATE_MAX_WINDOW
) {
294 if (window
->data
& (1ULL << (IWL_RATE_MAX_WINDOW
- 1)))
295 window
->success_counter
--;
299 /* Slide the window to the left one bit */
300 window
->data
= (window
->data
<< 1);
302 /* If this packet was a success then set the low bit high */
304 window
->success_counter
++;
308 /* window->counter can't be 0 -- it is either >0 or
309 * IWL_RATE_MAX_WINDOW */
310 window
->success_ratio
= 12800 * window
->success_counter
/
313 /* Tag this window as having been updated */
314 window
->stamp
= jiffies
;
316 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
320 static void rs_rate_init(void *priv
, struct ieee80211_supported_band
*sband
,
321 struct ieee80211_sta
*sta
, void *priv_sta
)
323 struct iwl3945_rs_sta
*rs_sta
= priv_sta
;
326 IWL_DEBUG_RATE("enter\n");
328 /* TODO: what is a good starting rate for STA? About middle? Maybe not
329 * the lowest or the highest rate.. Could consider using RSSI from
330 * previous packets? Need to have IEEE 802.1X auth succeed immediately
333 for (i
= IWL_RATE_COUNT
- 1; i
>= 0; i
--) {
334 if (sta
->supp_rates
[sband
->band
] & (1 << i
)) {
335 rs_sta
->last_txrate_idx
= i
;
340 /* For 5 GHz band it start at IWL_FIRST_OFDM_RATE */
341 if (sband
->band
== IEEE80211_BAND_5GHZ
)
342 rs_sta
->last_txrate_idx
+= IWL_FIRST_OFDM_RATE
;
344 IWL_DEBUG_RATE("leave\n");
347 static void *rs_alloc(struct ieee80211_hw
*hw
, struct dentry
*debugfsdir
)
352 /* rate scale requires free function to be implemented */
353 static void rs_free(void *priv
)
358 static void *rs_alloc_sta(void *priv
, struct ieee80211_sta
*sta
, gfp_t gfp
)
360 struct iwl3945_rs_sta
*rs_sta
;
361 struct iwl3945_sta_priv
*psta
= (void *) sta
->drv_priv
;
365 * XXX: If it's using sta->drv_priv anyway, it might
366 * as well just put all the information there.
369 IWL_DEBUG_RATE("enter\n");
371 rs_sta
= kzalloc(sizeof(struct iwl3945_rs_sta
), gfp
);
373 IWL_DEBUG_RATE("leave: ENOMEM\n");
377 psta
->rs_sta
= rs_sta
;
379 spin_lock_init(&rs_sta
->lock
);
381 rs_sta
->start_rate
= IWL_RATE_INVALID
;
383 /* default to just 802.11b */
384 rs_sta
->expected_tpt
= iwl3945_expected_tpt_b
;
386 rs_sta
->last_partial_flush
= jiffies
;
387 rs_sta
->last_flush
= jiffies
;
388 rs_sta
->flush_time
= IWL_RATE_FLUSH
;
389 rs_sta
->last_tx_packets
= 0;
390 rs_sta
->ibss_sta_added
= 0;
392 init_timer(&rs_sta
->rate_scale_flush
);
393 rs_sta
->rate_scale_flush
.data
= (unsigned long)rs_sta
;
394 rs_sta
->rate_scale_flush
.function
= &iwl3945_bg_rate_scale_flush
;
396 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
397 iwl3945_clear_window(&rs_sta
->win
[i
]);
399 IWL_DEBUG_RATE("leave\n");
404 static void rs_free_sta(void *priv
, struct ieee80211_sta
*sta
,
407 struct iwl3945_sta_priv
*psta
= (void *) sta
->drv_priv
;
408 struct iwl3945_rs_sta
*rs_sta
= priv_sta
;
412 IWL_DEBUG_RATE("enter\n");
413 del_timer_sync(&rs_sta
->rate_scale_flush
);
415 IWL_DEBUG_RATE("leave\n");
420 * rs_tx_status - Update rate control values based on Tx results
422 * NOTE: Uses iwl3945_priv->retry_rate for the # of retries attempted by
423 * the hardware for each rate.
425 static void rs_tx_status(void *priv_rate
, struct ieee80211_supported_band
*sband
,
426 struct ieee80211_sta
*sta
, void *priv_sta
,
429 u8 retries
= 0, current_count
;
430 int scale_rate_index
, first_index
, last_index
;
432 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)priv_rate
;
433 struct iwl3945_rs_sta
*rs_sta
= priv_sta
;
434 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
437 IWL_DEBUG_RATE("enter\n");
439 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; i
++)
440 retries
+= info
->status
.rates
[i
].count
;
443 first_index
= sband
->bitrates
[info
->status
.rates
[0].idx
].hw_value
;
444 if ((first_index
< 0) || (first_index
>= IWL_RATE_COUNT
)) {
445 IWL_DEBUG_RATE("leave: Rate out of bounds: %d\n", first_index
);
450 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
454 rs_sta
->tx_packets
++;
456 scale_rate_index
= first_index
;
457 last_index
= first_index
;
460 * Update the window for each rate. We determine which rates
461 * were Tx'd based on the total number of retries vs. the number
462 * of retries configured for each rate -- currently set to the
463 * priv value 'retry_rate' vs. rate specific
465 * On exit from this while loop last_index indicates the rate
466 * at which the frame was finally transmitted (or failed if no
469 while (retries
> 0) {
470 if (retries
< priv
->retry_rate
) {
471 current_count
= retries
;
472 last_index
= scale_rate_index
;
474 current_count
= priv
->retry_rate
;
475 last_index
= iwl3945_rs_next_rate(priv
,
479 /* Update this rate accounting for as many retries
480 * as was used for it (per current_count) */
481 iwl3945_collect_tx_data(rs_sta
,
482 &rs_sta
->win
[scale_rate_index
],
484 IWL_DEBUG_RATE("Update rate %d for %d retries.\n",
485 scale_rate_index
, current_count
);
487 retries
-= current_count
;
491 iwl3945_rs_next_rate(priv
, scale_rate_index
);
495 /* Update the last index window with success/failure based on ACK */
496 IWL_DEBUG_RATE("Update rate %d with %s.\n",
498 (info
->flags
& IEEE80211_TX_STAT_ACK
) ?
499 "success" : "failure");
500 iwl3945_collect_tx_data(rs_sta
,
501 &rs_sta
->win
[last_index
],
502 info
->flags
& IEEE80211_TX_STAT_ACK
, 1);
504 /* We updated the rate scale window -- 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_partial_flush
+
511 rs_sta
->flush_time
)) {
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
);
520 IWL_DEBUG_RATE("leave\n");
525 static u16
iwl3945_get_adjacent_rate(struct iwl3945_rs_sta
*rs_sta
,
526 u8 index
, u16 rate_mask
, enum ieee80211_band band
)
528 u8 high
= IWL_RATE_INVALID
;
529 u8 low
= IWL_RATE_INVALID
;
531 /* 802.11A walks to the next literal adjacent rate in
533 if (unlikely(band
== IEEE80211_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
< IWL_RATE_COUNT
; i
++, mask
<<= 1) {
549 if (rate_mask
& mask
) {
555 return (high
<< 8) | low
;
559 while (low
!= IWL_RATE_INVALID
) {
561 low
= iwl3945_rates
[low
].prev_rs_tgg
;
563 low
= iwl3945_rates
[low
].prev_rs
;
564 if (low
== IWL_RATE_INVALID
)
566 if (rate_mask
& (1 << low
))
568 IWL_DEBUG_RATE("Skipping masked lower rate: %d\n", low
);
572 while (high
!= IWL_RATE_INVALID
) {
574 high
= iwl3945_rates
[high
].next_rs_tgg
;
576 high
= iwl3945_rates
[high
].next_rs
;
577 if (high
== IWL_RATE_INVALID
)
579 if (rate_mask
& (1 << high
))
581 IWL_DEBUG_RATE("Skipping masked higher rate: %d\n", high
);
584 return (high
<< 8) | low
;
588 * 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 index obtained below into the hw_mode's
600 * rate table and must reference the driver allocated rate table
603 static void rs_get_rate(void *priv_r
, struct ieee80211_sta
*sta
,
604 void *priv_sta
, struct ieee80211_tx_rate_control
*txrc
)
606 struct ieee80211_supported_band
*sband
= txrc
->sband
;
607 struct sk_buff
*skb
= txrc
->skb
;
608 u8 low
= IWL_RATE_INVALID
;
609 u8 high
= IWL_RATE_INVALID
;
612 struct iwl3945_rs_sta
*rs_sta
= priv_sta
;
613 struct iwl3945_rate_scale_data
*window
= NULL
;
614 int current_tpt
= IWL_INV_TPT
;
615 int low_tpt
= IWL_INV_TPT
;
616 int high_tpt
= IWL_INV_TPT
;
620 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
622 struct iwl3945_priv
*priv
= (struct iwl3945_priv
*)priv_r
;
623 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
625 IWL_DEBUG_RATE("enter\n");
627 /* Send management frames and broadcast/multicast data using lowest
629 fc
= le16_to_cpu(hdr
->frame_control
);
630 if ((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
||
631 is_multicast_ether_addr(hdr
->addr1
) ||
633 IWL_DEBUG_RATE("leave: No STA priv data to update!\n");
634 info
->control
.rates
[0].idx
= rate_lowest_index(sband
, sta
);
638 rate_mask
= sta
->supp_rates
[sband
->band
];
639 index
= min(rs_sta
->last_txrate_idx
& 0xffff, IWL_RATE_COUNT
- 1);
641 if (sband
->band
== IEEE80211_BAND_5GHZ
)
642 rate_mask
= rate_mask
<< IWL_FIRST_OFDM_RATE
;
644 if ((priv
->iw_mode
== NL80211_IFTYPE_ADHOC
) &&
645 !rs_sta
->ibss_sta_added
) {
646 u8 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
648 if (sta_id
== IWL_INVALID_STATION
) {
649 IWL_DEBUG_RATE("LQ: ADD station %pm\n",
651 sta_id
= iwl3945_add_station(priv
,
652 hdr
->addr1
, 0, CMD_ASYNC
);
654 if (sta_id
!= IWL_INVALID_STATION
)
655 rs_sta
->ibss_sta_added
= 1;
658 spin_lock_irqsave(&rs_sta
->lock
, flags
);
660 if (rs_sta
->start_rate
!= IWL_RATE_INVALID
) {
661 index
= rs_sta
->start_rate
;
662 rs_sta
->start_rate
= IWL_RATE_INVALID
;
665 window
= &(rs_sta
->win
[index
]);
667 fail_count
= window
->counter
- window
->success_counter
;
669 if (((fail_count
<= IWL_RATE_MIN_FAILURE_TH
) &&
670 (window
->success_counter
< IWL_RATE_MIN_SUCCESS_TH
))) {
671 window
->average_tpt
= IWL_INV_TPT
;
672 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
674 IWL_DEBUG_RATE("Invalid average_tpt on rate %d: "
675 "counter: %d, success_counter: %d, "
676 "expected_tpt is %sNULL\n",
679 window
->success_counter
,
680 rs_sta
->expected_tpt
? "not " : "");
685 window
->average_tpt
= ((window
->success_ratio
*
686 rs_sta
->expected_tpt
[index
] + 64) / 128);
687 current_tpt
= window
->average_tpt
;
689 high_low
= iwl3945_get_adjacent_rate(rs_sta
, index
, rate_mask
,
691 low
= high_low
& 0xff;
692 high
= (high_low
>> 8) & 0xff;
694 if (low
!= IWL_RATE_INVALID
)
695 low_tpt
= rs_sta
->win
[low
].average_tpt
;
697 if (high
!= IWL_RATE_INVALID
)
698 high_tpt
= rs_sta
->win
[high
].average_tpt
;
700 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
704 if ((window
->success_ratio
< IWL_RATE_DECREASE_TH
) || !current_tpt
) {
705 IWL_DEBUG_RATE("decrease rate because of low success_ratio\n");
707 } else if ((low_tpt
== IWL_INV_TPT
) && (high_tpt
== IWL_INV_TPT
))
709 else if ((low_tpt
!= IWL_INV_TPT
) && (high_tpt
!= IWL_INV_TPT
) &&
710 (low_tpt
< current_tpt
) && (high_tpt
< current_tpt
)) {
711 IWL_DEBUG_RATE("No action -- low [%d] & high [%d] < "
712 "current_tpt [%d]\n",
713 low_tpt
, high_tpt
, current_tpt
);
716 if (high_tpt
!= IWL_INV_TPT
) {
717 if (high_tpt
> current_tpt
)
721 ("decrease rate because of high tpt\n");
724 } else if (low_tpt
!= IWL_INV_TPT
) {
725 if (low_tpt
> current_tpt
) {
727 ("decrease rate because of low tpt\n");
734 if ((window
->success_ratio
> IWL_RATE_HIGH_TH
) ||
735 (current_tpt
> window
->average_tpt
)) {
736 IWL_DEBUG_RATE("No action -- success_ratio [%d] > HIGH_TH or "
737 "current_tpt [%d] > average_tpt [%d]\n",
738 window
->success_ratio
,
739 current_tpt
, window
->average_tpt
);
743 switch (scale_action
) {
745 if (low
!= IWL_RATE_INVALID
)
750 if (high
!= IWL_RATE_INVALID
)
760 IWL_DEBUG_RATE("Selected %d (action %d) - low %d high %d\n",
761 index
, scale_action
, low
, high
);
765 rs_sta
->last_txrate_idx
= index
;
766 if (sband
->band
== IEEE80211_BAND_5GHZ
)
767 info
->control
.rates
[0].idx
= rs_sta
->last_txrate_idx
-
770 info
->control
.rates
[0].idx
= rs_sta
->last_txrate_idx
;
772 IWL_DEBUG_RATE("leave: %d\n", index
);
775 static struct rate_control_ops rs_ops
= {
778 .tx_status
= rs_tx_status
,
779 .get_rate
= rs_get_rate
,
780 .rate_init
= rs_rate_init
,
783 .alloc_sta
= rs_alloc_sta
,
784 .free_sta
= rs_free_sta
,
787 void iwl3945_rate_scale_init(struct ieee80211_hw
*hw
, s32 sta_id
)
789 struct iwl3945_priv
*priv
= hw
->priv
;
792 struct iwl3945_rs_sta
*rs_sta
;
793 struct ieee80211_sta
*sta
;
794 struct iwl3945_sta_priv
*psta
;
796 IWL_DEBUG_RATE("enter\n");
800 sta
= ieee80211_find_sta(hw
, priv
->stations
[sta_id
].sta
.sta
.addr
);
806 psta
= (void *) sta
->drv_priv
;
807 rs_sta
= psta
->rs_sta
;
809 spin_lock_irqsave(&rs_sta
->lock
, flags
);
812 switch (priv
->band
) {
813 case IEEE80211_BAND_2GHZ
:
814 /* TODO: this always does G, not a regression */
815 if (priv
->active_rxon
.flags
& RXON_FLG_TGG_PROTECT_MSK
) {
817 rs_sta
->expected_tpt
= iwl3945_expected_tpt_g_prot
;
819 rs_sta
->expected_tpt
= iwl3945_expected_tpt_g
;
822 case IEEE80211_BAND_5GHZ
:
823 rs_sta
->expected_tpt
= iwl3945_expected_tpt_a
;
825 case IEEE80211_NUM_BANDS
:
830 spin_unlock_irqrestore(&rs_sta
->lock
, flags
);
832 rssi
= priv
->last_rx_rssi
;
834 rssi
= IWL_MIN_RSSI_VAL
;
836 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RATE
, "Network RSSI: %d\n", rssi
);
838 rs_sta
->start_rate
= iwl3945_get_rate_index_by_rssi(rssi
, priv
->band
);
840 IWL_DEBUG_RATE("leave: rssi %d assign rate index: "
841 "%d (plcp 0x%x)\n", rssi
, rs_sta
->start_rate
,
842 iwl3945_rates
[rs_sta
->start_rate
].plcp
);
846 int iwl3945_rate_control_register(void)
848 return ieee80211_rate_control_register(&rs_ops
);
851 void iwl3945_rate_control_unregister(void)
853 ieee80211_rate_control_unregister(&rs_ops
);