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