]> Pileus Git - ~andy/linux/blob - drivers/staging/winbond/mto.c
05d12625dfcd29cf830af4bbde5207792f2f1b54
[~andy/linux] / drivers / staging / winbond / mto.c
1 /*
2  * ============================================================================
3  * MTO.C -
4  *
5  * Description:
6  * MAC Throughput Optimization for W89C33 802.11g WLAN STA.
7  *
8  * The following MIB attributes or internal variables will be affected
9  * while the MTO is being executed:
10  *      dot11FragmentationThreshold,
11  *      dot11RTSThreshold,
12  *      transmission rate and PLCP preamble type,
13  *      CCA mode,
14  *      antenna diversity.
15  *
16  * Copyright (c) 2003 Winbond Electronics Corp. All rights reserved.
17  * ============================================================================
18  */
19
20 #include "sysdef.h"
21 #include "sme_api.h"
22 #include "wbhal_s.h"
23 #include "wb35reg_f.h"
24 #include "core.h"
25
26 /* Declare SQ3 to rate and fragmentation threshold table */
27 /* Declare fragmentation thresholds table */
28 #define MTO_MAX_FRAG_TH_LEVELS          5
29 #define MTO_MAX_DATA_RATE_LEVELS        12
30
31 u16 MTO_Frag_Th_Tbl[MTO_MAX_FRAG_TH_LEVELS] = {
32         256, 384, 512, 768, 1536
33 };
34
35 /*
36  * Declare data rate table:
37  * The following table will be changed at anytime if the opration rate
38  * supported by AP don't match the table
39  */
40 static u8 MTO_Data_Rate_Tbl[MTO_MAX_DATA_RATE_LEVELS] = {
41         2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108
42 };
43
44 static int TotalTxPkt;
45 static int TotalTxPktRetry;
46 /* this record the retry rate at different data rate */
47 static int retryrate_rec[MTO_MAX_DATA_RATE_LEVELS];
48
49 static int PeriodTotalTxPkt;
50 static int PeriodTotalTxPktRetry;
51
52 static u8 boSparseTxTraffic;
53
54 void MTO_Init(struct wbsoft_priv *adapter);
55 void TxRateReductionCtrl(struct wbsoft_priv *adapter);
56 void MTO_SetTxCount(struct wbsoft_priv *adapter, u8 t0, u8 index);
57 void MTO_TxFailed(struct wbsoft_priv *adapter);
58 void hal_get_dto_para(struct wbsoft_priv *adapter, char *buffer);
59
60 /*
61  * ===========================================================================
62  * MTO_Init --
63  *
64  *  Description:
65  *    Initialize MTO parameters.
66  *
67  *    This function should be invoked during system initialization.
68  *
69  *  Arguments:
70  *    adapter      - The pointer to the Miniport adapter Context
71  * ===========================================================================
72  */
73 void MTO_Init(struct wbsoft_priv *adapter)
74 {
75         int i;
76
77         MTO_PREAMBLE_TYPE() = MTO_PREAMBLE_SHORT;   /* for test */
78
79         MTO_CNT_ANT(0)                  = 0;
80         MTO_CNT_ANT(1)                  = 0;
81         MTO_SQ_ANT(0)                   = 0;
82         MTO_SQ_ANT(1)                   = 0;
83
84         MTO_AGING_TIMEOUT()             = 0;
85
86         /* The following parameters should be initialized to the values set by user */
87         MTO_RATE_LEVEL()                = 0;
88         MTO_FRAG_TH_LEVEL()             = 4;
89         MTO_RTS_THRESHOLD()             = MTO_FRAG_TH() + 1;
90         MTO_RTS_THRESHOLD_SETUP()       = MTO_FRAG_TH() + 1;
91         MTO_RATE_CHANGE_ENABLE()        = 1;
92         MTO_FRAG_CHANGE_ENABLE()        = 0;
93         MTO_POWER_CHANGE_ENABLE()       = 1;
94         MTO_PREAMBLE_CHANGE_ENABLE()    = 1;
95         MTO_RTS_CHANGE_ENABLE()         = 0;
96
97         for (i = 0; i < MTO_MAX_DATA_RATE_LEVELS; i++)
98                 retryrate_rec[i] = 5;
99
100         MTO_TXFLOWCOUNT() = 0;
101         /* --------- DTO threshold parameters ------------- */
102         MTOPARA_PERIODIC_CHECK_CYCLE()          = 10;
103         MTOPARA_RSSI_TH_FOR_ANTDIV()            = 10;
104         MTOPARA_TXCOUNT_TH_FOR_CALC_RATE()      = 50;
105         MTOPARA_TXRATE_INC_TH()                 = 10;
106         MTOPARA_TXRATE_DEC_TH()                 = 30;
107         MTOPARA_TXRATE_EQ_TH()                  = 40;
108         MTOPARA_TXRATE_BACKOFF()                = 12;
109         MTOPARA_TXRETRYRATE_REDUCE()            = 6;
110         if (MTO_TXPOWER_FROM_EEPROM == 0xff) {
111                 switch (MTO_HAL()->phy_type) {
112                 case RF_AIROHA_2230:
113                 case RF_AIROHA_2230S:
114                         MTOPARA_TXPOWER_INDEX() = 46; /* MAX-8 @@ Only for AL 2230 */
115                         break;
116                 case RF_AIROHA_7230:
117                         MTOPARA_TXPOWER_INDEX() = 49;
118                         break;
119                 case RF_WB_242:
120                         MTOPARA_TXPOWER_INDEX() = 10;
121                         break;
122                 case RF_WB_242_1:
123                         MTOPARA_TXPOWER_INDEX() = 24;
124                         break;
125                 }
126         } else { /* follow the setting from EEPROM */
127                 MTOPARA_TXPOWER_INDEX() = MTO_TXPOWER_FROM_EEPROM;
128         }
129         RFSynthesizer_SetPowerIndex(MTO_HAL(), (u8) MTOPARA_TXPOWER_INDEX());
130         /* ------------------------------------------------ */
131
132         /* For RSSI turning -- Cancel load from EEPROM */
133         MTO_DATA().RSSI_high = -41;
134         MTO_DATA().RSSI_low = -60;
135 }
136
137 /* ===========================================================================
138  * Description:
139  *      If we enable DTO, we will ignore the tx count with different tx rate
140  *      from DTO rate. This is because when we adjust DTO tx rate, there could
141  *      be some packets in the tx queue with previous tx rate
142  */
143
144 void MTO_SetTxCount(struct wbsoft_priv *adapter, u8 tx_rate, u8 index)
145 {
146         MTO_TXFLOWCOUNT()++;
147         if ((MTO_ENABLE == 1) && (MTO_RATE_CHANGE_ENABLE() == 1)) {
148                 if (tx_rate == MTO_DATA_RATE()) {
149                         if (index == 0) {
150                                 if (boSparseTxTraffic)
151                                         MTO_HAL()->dto_tx_frag_count += MTOPARA_PERIODIC_CHECK_CYCLE();
152                                 else
153                                         MTO_HAL()->dto_tx_frag_count += 1;
154                         } else {
155                                 if (index < 8) {
156                                         MTO_HAL()->dto_tx_retry_count += index;
157                                         MTO_HAL()->dto_tx_frag_count += (index + 1);
158                                 } else {
159                                         MTO_HAL()->dto_tx_retry_count += 7;
160                                         MTO_HAL()->dto_tx_frag_count += 7;
161                                 }
162                         }
163                 } else if (MTO_DATA_RATE() > 48 && tx_rate == 48) {
164                         /* for reducing data rate scheme, do not calculate different data rate. 3 is the reducing data rate at retry. */
165                         if (index < 3) {
166                                 MTO_HAL()->dto_tx_retry_count += index;
167                                 MTO_HAL()->dto_tx_frag_count += (index + 1);
168                         } else {
169                                 MTO_HAL()->dto_tx_retry_count += 3;
170                                 MTO_HAL()->dto_tx_frag_count += 3;
171                         }
172
173                 }
174         } else {
175                 MTO_HAL()->dto_tx_retry_count += index;
176                 MTO_HAL()->dto_tx_frag_count += (index + 1);
177         }
178         TotalTxPkt++;
179         TotalTxPktRetry += (index + 1);
180
181         PeriodTotalTxPkt++;
182         PeriodTotalTxPktRetry += (index + 1);
183 }