Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/hal/phydm/phydm_dynamictxpower.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2007 - 2017 Realtek Corporation.
4
*
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.
8
*
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
12
* more details.
13
*
14
* The full GNU General Public License is included in this distribution in the
15
* file called LICENSE.
16
*
17
* Contact Information:
18
* wlanfae <[email protected]>
19
* Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20
* Hsinchu 300, Taiwan.
21
*
22
* Larry Finger <[email protected]>
23
*
24
*****************************************************************************/
25
26
/*************************************************************
27
* include files
28
************************************************************/
29
#include "mp_precomp.h"
30
#include "phydm_precomp.h"
31
32
#ifdef CONFIG_DYNAMIC_TX_TWR
33
#ifdef BB_RAM_SUPPORT
34
void phydm_rd_reg_pwr(void *dm_void, u32 *_used, char *output, u32 *_out_len)
35
{
36
struct dm_struct *dm = (struct dm_struct *)dm_void;
37
u32 used = *_used;
38
u32 out_len = *_out_len;
39
boolean pwr_ofst0_en = false;
40
boolean pwr_ofst1_en = false;
41
s8 pwr_ofst0 = 0;
42
s8 pwr_ofst1 = 0;
43
44
pwr_ofst0_en = (boolean)odm_get_bb_reg(dm, R_0x1e70, BIT(23));
45
pwr_ofst1_en = (boolean)odm_get_bb_reg(dm, R_0x1e70, BIT(31));
46
pwr_ofst0 = (s8)odm_get_bb_reg(dm, R_0x1e70, 0x7f0000);
47
pwr_ofst1 = (s8)odm_get_bb_reg(dm, R_0x1e70, 0x7f000000);
48
49
PDM_SNPF(out_len, used, output + used, out_len - used,
50
"reg0: en:%d, pwr_ofst:0x%x, reg1: en:%d, pwr_ofst:0x%x\n",
51
pwr_ofst0_en, pwr_ofst0, pwr_ofst1_en, pwr_ofst1);
52
53
*_used = used;
54
*_out_len = out_len;
55
};
56
57
void phydm_wt_reg_pwr(void *dm_void, boolean is_ofst1, boolean pwr_ofst_en,
58
s8 pwr_ofst)
59
{
60
struct dm_struct *dm = (struct dm_struct *)dm_void;
61
struct phydm_bb_ram_ctrl *bb_ctrl = &dm->p_bb_ram_ctrl;
62
u8 reg_0x1e70 = 0;
63
64
if (!is_ofst1) {
65
bb_ctrl->tx_pwr_ofst_reg0_en = pwr_ofst_en;
66
bb_ctrl->tx_pwr_ofst_reg0 = pwr_ofst;
67
68
reg_0x1e70 |= (pwr_ofst_en << 7) + (pwr_ofst & 0x7f);
69
odm_set_bb_reg(dm, R_0x1e70, 0x00ff0000, reg_0x1e70);
70
} else {
71
bb_ctrl->tx_pwr_ofst_reg1_en = pwr_ofst_en;
72
bb_ctrl->tx_pwr_ofst_reg1 = pwr_ofst;
73
74
reg_0x1e70 |= (pwr_ofst_en << 7) + (pwr_ofst & 0x7f);
75
odm_set_bb_reg(dm, R_0x1e70, 0xff000000, reg_0x1e70);
76
}
77
};
78
79
void phydm_rd_ram_pwr(void *dm_void, u8 macid, u32 *_used, char *output,
80
u32 *_out_len)
81
{
82
struct dm_struct *dm = (struct dm_struct *)dm_void;
83
u32 used = *_used;
84
u32 out_len = *_out_len;
85
boolean pwr_ofst0_en = false;
86
boolean pwr_ofst1_en = false;
87
s8 pwr_ofst0 = 0;
88
s8 pwr_ofst1 = 0;
89
u32 reg_0x1e84 = 0;
90
91
reg_0x1e84 |= (macid & 0x3f) << 24; /* macid*/
92
reg_0x1e84 |= BIT(31); /* read_en*/
93
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, reg_0x1e84);
94
95
pwr_ofst0_en = (boolean)odm_get_bb_reg(dm, R_0x2de8, BIT(23));
96
pwr_ofst1_en = (boolean)odm_get_bb_reg(dm, R_0x2de8, BIT(31));
97
pwr_ofst0 = (s8)odm_get_bb_reg(dm, R_0x2de8, 0x7f0000);
98
pwr_ofst1 = (s8)odm_get_bb_reg(dm, R_0x2de8, 0x7f000000);
99
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, 0x0); /* disable rd/wt*/
100
101
PDM_SNPF(out_len, used, output + used, out_len - used,
102
"(macid:%d) ram0: en:%d, pwr_ofst:0x%x, ram1: en:%d, pwr_ofst:0x%x\n",
103
macid, pwr_ofst0_en, pwr_ofst0, pwr_ofst1_en, pwr_ofst1);
104
105
*_used = used;
106
*_out_len = out_len;
107
};
108
109
void phydm_wt_ram_pwr(void *dm_void, u8 macid, boolean is_ofst1,
110
boolean pwr_ofst_en, s8 pwr_ofst)
111
{
112
struct dm_struct *dm = (struct dm_struct *)dm_void;
113
struct phydm_bb_ram_per_sta *dm_ram_per_sta = NULL;
114
u32 reg_0x1e84 = 0;
115
boolean pwr_ofst_ano_en = false;
116
s8 pwr_ofst_ano = 0;
117
118
if (macid > 63)
119
macid = 63;
120
121
dm_ram_per_sta = &dm->p_bb_ram_ctrl.pram_sta_ctrl[macid];
122
reg_0x1e84 = (dm_ram_per_sta->hw_igi_en << 7) + dm_ram_per_sta->hw_igi;
123
if (!is_ofst1) {
124
dm_ram_per_sta->tx_pwr_offset0_en = pwr_ofst_en;
125
dm_ram_per_sta->tx_pwr_offset0 = pwr_ofst;
126
127
pwr_ofst_ano_en = dm_ram_per_sta->tx_pwr_offset1_en;
128
pwr_ofst_ano = dm_ram_per_sta->tx_pwr_offset1;
129
130
reg_0x1e84 |= (pwr_ofst_en << 15) + ((pwr_ofst & 0x7f) << 8) +
131
(pwr_ofst_ano_en << 23) +
132
((pwr_ofst_ano & 0x7f) << 16);
133
} else {
134
dm_ram_per_sta->tx_pwr_offset1_en = pwr_ofst_en;
135
dm_ram_per_sta->tx_pwr_offset1 = pwr_ofst;
136
137
pwr_ofst_ano_en = dm_ram_per_sta->tx_pwr_offset0_en;
138
pwr_ofst_ano = dm_ram_per_sta->tx_pwr_offset1;
139
140
reg_0x1e84 |= (pwr_ofst_ano_en << 15) +
141
((pwr_ofst_ano & 0x7f) << 8) +
142
(pwr_ofst_en << 23) + ((pwr_ofst & 0x7f) << 16);
143
}
144
reg_0x1e84 |= (macid & 0x3f) << 24;/* macid*/
145
reg_0x1e84 |= BIT(30); /* write_en*/
146
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, reg_0x1e84);
147
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, 0x80000000); /* read_en*/
148
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, 0x0); /* disable rd/wt*/
149
};
150
151
void phydm_rst_ram_pwr(void *dm_void)
152
{
153
struct dm_struct *dm = (struct dm_struct *)dm_void;
154
struct phydm_bb_ram_per_sta *dm_ram_per_sta = NULL;
155
u32 reg_0x1e84 = 0;
156
u8 i = 0;
157
158
for (i = 0; i < 64; i++) {
159
dm_ram_per_sta = &dm->p_bb_ram_ctrl.pram_sta_ctrl[i];
160
dm_ram_per_sta->tx_pwr_offset0_en = false;
161
dm_ram_per_sta->tx_pwr_offset1_en = false;
162
dm_ram_per_sta->tx_pwr_offset0 = 0x0;
163
dm_ram_per_sta->tx_pwr_offset1 = 0x0;
164
reg_0x1e84 = (dm_ram_per_sta->hw_igi_en << 7) +
165
dm_ram_per_sta->hw_igi;
166
reg_0x1e84 |= (i & 0x3f) << 24;
167
reg_0x1e84 |= BIT(30);
168
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, reg_0x1e84);
169
}
170
171
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, 0x80000000);
172
odm_set_bb_reg(dm, R_0x1e84, MASKDWORD, 0x0);
173
};
174
175
u8 phydm_pwr_lv_mapping_2nd(u8 tx_pwr_lv)
176
{
177
if (tx_pwr_lv == tx_high_pwr_level_level3)
178
return PHYDM_2ND_OFFSET_MINUS_11DB;
179
else if (tx_pwr_lv == tx_high_pwr_level_level2)
180
return PHYDM_2ND_OFFSET_MINUS_7DB;
181
else if (tx_pwr_lv == tx_high_pwr_level_level1)
182
return PHYDM_2ND_OFFSET_MINUS_3DB;
183
else
184
return PHYDM_2ND_OFFSET_ZERO;
185
}
186
187
void phydm_pwr_lv_ctrl(void *dm_void, u8 macid, u8 tx_pwr_lv)
188
{
189
struct dm_struct *dm = (struct dm_struct *)dm_void;
190
s8 pwr_offset = 0;
191
192
if (tx_pwr_lv == tx_high_pwr_level_level3)
193
pwr_offset = PHYDM_BBRAM_OFFSET_MINUS_11DB;
194
else if (tx_pwr_lv == tx_high_pwr_level_level2)
195
pwr_offset = PHYDM_BBRAM_OFFSET_MINUS_7DB;
196
else if (tx_pwr_lv == tx_high_pwr_level_level1)
197
pwr_offset = PHYDM_BBRAM_OFFSET_MINUS_3DB;
198
else
199
pwr_offset = PHYDM_BBRAM_OFFSET_ZERO;
200
201
phydm_wt_ram_pwr(dm, macid, RAM_PWR_OFST0, true, pwr_offset);
202
/* still need to check with SD7*/
203
#if (RTL8822C_SUPPORT)
204
if (dm->support_ic_type & ODM_RTL8822C)
205
phydm_wt_ram_pwr(dm, 127, RAM_PWR_OFST0, true, pwr_offset);
206
#endif
207
}
208
209
void phydm_dtp_fill_cmninfo_2nd(void *dm_void, u8 macid, u8 dtp_lvl)
210
{
211
struct dm_struct *dm = (struct dm_struct *)dm_void;
212
struct cmn_sta_info *sta = dm->phydm_sta_info[macid];
213
struct dtp_info *dtp = NULL;
214
215
if (!is_sta_active(sta))
216
return;
217
218
dtp = &dm->phydm_sta_info[macid]->dtp_stat;
219
dtp->dyn_tx_power = phydm_pwr_lv_mapping_2nd(dtp_lvl);
220
phydm_pwr_lv_ctrl(dm, macid, dtp_lvl);
221
222
PHYDM_DBG(dm, DBG_DYN_TXPWR,
223
"Fill cmninfo TxPwr: macid=(%d), PwrLv (%d)\n", macid,
224
dtp->dyn_tx_power);
225
}
226
227
void phydm_dtp_init_2nd(void *dm_void)
228
{
229
struct dm_struct *dm = (struct dm_struct *)dm_void;
230
231
if (!(dm->support_ability & ODM_BB_DYNAMIC_TXPWR))
232
return;
233
234
#if (RTL8822C_SUPPORT)
235
if (dm->support_ic_type & ODM_RTL8822C) {
236
phydm_rst_ram_pwr(dm);
237
/* rsp tx use type 0*/
238
odm_set_mac_reg(dm, R_0x6d8, BIT(19) | BIT(18), RAM_PWR_OFST0);
239
}
240
#endif
241
};
242
#endif
243
244
boolean
245
phydm_check_rates(void *dm_void, u8 rate_idx)
246
{
247
struct dm_struct *dm = (struct dm_struct *)dm_void;
248
u32 check_rate_bitmap0 = 0x08080808; /* @check CCK11M, OFDM54M, MCS7, MCS15*/
249
u32 check_rate_bitmap1 = 0x80200808; /* @check MCS23, MCS31, VHT1SS M9, VHT2SS M9*/
250
u32 check_rate_bitmap2 = 0x00080200; /* @check VHT3SS M9, VHT4SS M9*/
251
u32 bitmap_result;
252
253
#if (RTL8822B_SUPPORT)
254
if (dm->support_ic_type & ODM_RTL8822B) {
255
check_rate_bitmap2 &= 0;
256
check_rate_bitmap1 &= 0xfffff000;
257
check_rate_bitmap0 &= 0x0fffffff;
258
}
259
#endif
260
#if (RTL8197F_SUPPORT)
261
if (dm->support_ic_type & ODM_RTL8197F) {
262
check_rate_bitmap2 &= 0;
263
check_rate_bitmap1 &= 0;
264
check_rate_bitmap0 &= 0x0fffffff;
265
}
266
#endif
267
#if (RTL8192E_SUPPORT)
268
if (dm->support_ic_type & ODM_RTL8192E) {
269
check_rate_bitmap2 &= 0;
270
check_rate_bitmap1 &= 0;
271
check_rate_bitmap0 &= 0x0fffffff;
272
}
273
#endif
274
#if (RTL8192F_SUPPORT)
275
if (dm->support_ic_type & ODM_RTL8192F) {
276
check_rate_bitmap2 &= 0;
277
check_rate_bitmap1 &= 0;
278
check_rate_bitmap0 &= 0x0fffffff;
279
}
280
#endif
281
#if (RTL8721D_SUPPORT)
282
if (dm->support_ic_type & ODM_RTL8721D) {
283
check_rate_bitmap2 &= 0;
284
check_rate_bitmap1 &= 0;
285
check_rate_bitmap0 &= 0x000fffff;
286
}
287
#endif
288
#if (RTL8821C_SUPPORT)
289
if (dm->support_ic_type & ODM_RTL8821C) {
290
check_rate_bitmap2 &= 0;
291
check_rate_bitmap1 &= 0x003ff000;
292
check_rate_bitmap0 &= 0x000fffff;
293
}
294
#endif
295
if (rate_idx >= 64)
296
bitmap_result = BIT(rate_idx - 64) & check_rate_bitmap2;
297
else if (rate_idx >= 32)
298
bitmap_result = BIT(rate_idx - 32) & check_rate_bitmap1;
299
else if (rate_idx <= 31)
300
bitmap_result = BIT(rate_idx) & check_rate_bitmap0;
301
302
if (bitmap_result != 0)
303
return true;
304
else
305
return false;
306
}
307
308
enum rf_path
309
phydm_check_paths(void *dm_void)
310
{
311
struct dm_struct *dm = (struct dm_struct *)dm_void;
312
enum rf_path max_path = RF_PATH_A;
313
314
if (dm->num_rf_path == 1)
315
max_path = RF_PATH_A;
316
if (dm->num_rf_path == 2)
317
max_path = RF_PATH_B;
318
if (dm->num_rf_path == 3)
319
max_path = RF_PATH_C;
320
if (dm->num_rf_path == 4)
321
max_path = RF_PATH_D;
322
323
return max_path;
324
}
325
326
#ifndef PHYDM_COMMON_API_SUPPORT
327
u8 phydm_dtp_get_txagc(void *dm_void, enum rf_path path, u8 hw_rate)
328
{
329
struct dm_struct *dm = (struct dm_struct *)dm_void;
330
u8 ret = 0xff;
331
332
#if (RTL8192E_SUPPORT)
333
ret = config_phydm_read_txagc_n(dm, path, hw_rate);
334
#endif
335
return ret;
336
}
337
#endif
338
339
u8 phydm_search_min_power_index(void *dm_void)
340
{
341
struct dm_struct *dm = (struct dm_struct *)dm_void;
342
enum rf_path path;
343
enum rf_path max_path;
344
u8 min_gain_index = 0x3f;
345
u8 gain_index;
346
u8 rate_idx;
347
348
PHYDM_DBG(dm, DBG_DYN_TXPWR, "%s\n", __func__);
349
max_path = phydm_check_paths(dm);
350
for (path = 0; path <= max_path; path++)
351
for (rate_idx = 0; rate_idx < 84; rate_idx++)
352
if (phydm_check_rates(dm, rate_idx)) {
353
#ifdef PHYDM_COMMON_API_SUPPORT
354
/*This is for API support IC : 97F,8822B,92F,8821C*/
355
gain_index = phydm_api_get_txagc(dm, path, rate_idx);
356
#else
357
/*This is for API non-support IC : 92E */
358
gain_index = phydm_dtp_get_txagc(dm, path, rate_idx);
359
#endif
360
if (gain_index == 0xff) {
361
min_gain_index = 0x20;
362
PHYDM_DBG(dm, DBG_DYN_TXPWR,
363
"Error Gain idx!! Rewite to: ((%d))\n",
364
min_gain_index);
365
break;
366
}
367
PHYDM_DBG(dm, DBG_DYN_TXPWR,
368
"Support Rate: ((%d)) -> Gain idx: ((%d))\n",
369
rate_idx, gain_index);
370
if (gain_index < min_gain_index)
371
min_gain_index = gain_index;
372
}
373
return min_gain_index;
374
}
375
376
void phydm_dynamic_tx_power_init(void *dm_void)
377
{
378
struct dm_struct *dm = (struct dm_struct *)dm_void;
379
u8 i = 0;
380
381
dm->last_dtp_lvl = tx_high_pwr_level_normal;
382
dm->dynamic_tx_high_power_lvl = tx_high_pwr_level_normal;
383
384
switch (dm->ic_ip_series) {
385
#ifdef BB_RAM_SUPPORT
386
case PHYDM_IC_JGR3:
387
dm->set_pwr_th[0] = TX_PWR_NEAR_FIELD_TH_JGR3_LVL1;
388
dm->set_pwr_th[1] = TX_PWR_NEAR_FIELD_TH_JGR3_LVL2;
389
dm->set_pwr_th[2] = TX_PWR_NEAR_FIELD_TH_JGR3_LVL3;
390
phydm_dtp_init_2nd(dm);
391
break;
392
#endif
393
default:
394
for (i = 0; i < 3; i++)
395
dm->enhance_pwr_th[i] = 0xff;
396
397
dm->set_pwr_th[0] = TX_POWER_NEAR_FIELD_THRESH_LVL1;
398
dm->set_pwr_th[1] = TX_POWER_NEAR_FIELD_THRESH_LVL2;
399
dm->set_pwr_th[2] = 0xff;
400
dm->min_power_index = phydm_search_min_power_index(dm);
401
PHYDM_DBG(dm, DBG_DYN_TXPWR, "DTP init: Min Gain idx: ((%d))\n",
402
dm->min_power_index);
403
break;
404
}
405
}
406
407
void phydm_noisy_enhance_hp_th(void *dm_void, u8 noisy_state)
408
{
409
struct dm_struct *dm = (struct dm_struct *)dm_void;
410
411
if (noisy_state == 0) {
412
dm->enhance_pwr_th[0] = dm->set_pwr_th[0];
413
dm->enhance_pwr_th[1] = dm->set_pwr_th[1];
414
dm->enhance_pwr_th[2] = dm->set_pwr_th[2];
415
} else {
416
dm->enhance_pwr_th[0] = dm->set_pwr_th[0] + 8;
417
dm->enhance_pwr_th[1] = dm->set_pwr_th[1] + 5;
418
dm->enhance_pwr_th[2] = dm->set_pwr_th[2];
419
}
420
PHYDM_DBG(dm, DBG_DYN_TXPWR,
421
"DTP hp_enhance_th: Lv1_th =%d ,Lv2_th = %d ,Lv3_th = %d\n",
422
dm->enhance_pwr_th[0], dm->enhance_pwr_th[1],
423
dm->enhance_pwr_th[2]);
424
}
425
426
u8 phydm_pwr_lvl_check(void *dm_void, u8 input_rssi)
427
{
428
struct dm_struct *dm = (struct dm_struct *)dm_void;
429
u8 th0, th1, th2;
430
431
if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
432
th2 = dm->set_pwr_th[2];
433
th1 = dm->set_pwr_th[1];
434
th0 = dm->set_pwr_th[0];
435
PHYDM_DBG(dm, DBG_DYN_TXPWR,
436
"DTP th: Lv1_th = %d, Lv2_th = %d, Lv3_th = %d\n",
437
th0, th1, th2);
438
} else {
439
th2 = dm->enhance_pwr_th[2];
440
th1 = dm->enhance_pwr_th[1];
441
th0 = dm->enhance_pwr_th[0];
442
}
443
444
if (input_rssi >= th2)
445
return tx_high_pwr_level_level3;
446
else if (input_rssi < (th2 - 3) && input_rssi >= th1)
447
return tx_high_pwr_level_level2;
448
else if (input_rssi < (th1 - 3) && input_rssi >= th0)
449
return tx_high_pwr_level_level1;
450
else if (input_rssi < (th0 - 3))
451
return tx_high_pwr_level_normal;
452
else
453
return tx_high_pwr_level_unchange;
454
}
455
456
u8 phydm_pwr_lv_mapping(u8 tx_pwr_lv)
457
{
458
if (tx_pwr_lv == tx_high_pwr_level_level3)
459
return PHYDM_OFFSET_MINUS_11DB;
460
else if (tx_pwr_lv == tx_high_pwr_level_level2)
461
return PHYDM_OFFSET_MINUS_7DB;
462
else if (tx_pwr_lv == tx_high_pwr_level_level1)
463
return PHYDM_OFFSET_MINUS_3DB;
464
else
465
return PHYDM_OFFSET_ZERO;
466
}
467
468
void phydm_dynamic_response_power(void *dm_void)
469
{
470
struct dm_struct *dm = (struct dm_struct *)dm_void;
471
u8 rpwr = 0;
472
473
if (!(dm->support_ability & ODM_BB_DYNAMIC_TXPWR))
474
return;
475
476
if (dm->dynamic_tx_high_power_lvl == tx_high_pwr_level_unchange) {
477
dm->dynamic_tx_high_power_lvl = dm->last_dtp_lvl;
478
PHYDM_DBG(dm, DBG_DYN_TXPWR, "RespPwr not change\n");
479
return;
480
}
481
PHYDM_DBG(dm, DBG_DYN_TXPWR,
482
"RespPwr update_DTP_lv: ((%d)) -> ((%d))\n", dm->last_dtp_lvl,
483
dm->dynamic_tx_high_power_lvl);
484
dm->last_dtp_lvl = dm->dynamic_tx_high_power_lvl;
485
rpwr = phydm_pwr_lv_mapping(dm->dynamic_tx_high_power_lvl);
486
odm_set_mac_reg(dm, ODM_REG_RESP_TX_11AC, BIT(20) | BIT(19) | BIT(18),
487
rpwr);
488
PHYDM_DBG(dm, DBG_DYN_TXPWR, "RespPwr Set TxPwr: Lv (%d)\n",
489
dm->dynamic_tx_high_power_lvl);
490
}
491
492
void phydm_dtp_fill_cmninfo(void *dm_void, u8 macid, u8 dtp_lvl)
493
{
494
struct dm_struct *dm = (struct dm_struct *)dm_void;
495
struct cmn_sta_info *sta = dm->phydm_sta_info[macid];
496
struct dtp_info *dtp = NULL;
497
498
if (!is_sta_active(sta))
499
return;
500
501
dtp = &sta->dtp_stat;
502
dtp->dyn_tx_power = phydm_pwr_lv_mapping(dtp_lvl);
503
PHYDM_DBG(dm, DBG_DYN_TXPWR,
504
"Fill cmninfo TxPwr: macid=(%d), PwrLv (%d)\n", macid,
505
dtp->dyn_tx_power);
506
}
507
508
void phydm_dtp_per_sta(void *dm_void, u8 macid)
509
{
510
struct dm_struct *dm = (struct dm_struct *)dm_void;
511
struct cmn_sta_info *sta = dm->phydm_sta_info[macid];
512
struct dtp_info *dtp = NULL;
513
struct rssi_info *rssi = NULL;
514
515
if (is_sta_active(sta)) {
516
dtp = &sta->dtp_stat;
517
rssi = &sta->rssi_stat;
518
dtp->sta_tx_high_power_lvl = phydm_pwr_lvl_check(dm,
519
rssi->rssi);
520
PHYDM_DBG(dm, DBG_DYN_TXPWR,
521
"STA=%d , RSSI: %d , GetPwrLv: %d\n", macid,
522
rssi->rssi, dtp->sta_tx_high_power_lvl);
523
524
if (dtp->sta_tx_high_power_lvl == tx_high_pwr_level_unchange
525
|| dtp->sta_tx_high_power_lvl == dtp->sta_last_dtp_lvl) {
526
dtp->sta_tx_high_power_lvl = dtp->sta_last_dtp_lvl;
527
PHYDM_DBG(dm, DBG_DYN_TXPWR,
528
"DTP_lv not change: ((%d))\n",
529
dtp->sta_tx_high_power_lvl);
530
return;
531
}
532
533
PHYDM_DBG(dm, DBG_DYN_TXPWR,
534
"DTP_lv update: ((%d)) -> ((%d))\n",
535
dtp->sta_last_dtp_lvl, dtp->sta_tx_high_power_lvl);
536
537
dtp->sta_last_dtp_lvl = dtp->sta_tx_high_power_lvl;
538
539
switch (dm->ic_ip_series) {
540
#ifdef BB_RAM_SUPPORT
541
case PHYDM_IC_JGR3:
542
phydm_dtp_fill_cmninfo_2nd(dm, macid,
543
dtp->sta_tx_high_power_lvl);
544
break;
545
#endif
546
default:
547
phydm_dtp_fill_cmninfo(dm, macid,
548
dtp->sta_tx_high_power_lvl);
549
break;
550
}
551
552
}
553
}
554
555
void odm_set_dyntxpwr(void *dm_void, u8 *desc, u8 macid)
556
{
557
struct dm_struct *dm = (struct dm_struct *)dm_void;
558
struct cmn_sta_info *sta = dm->phydm_sta_info[macid];
559
struct dtp_info *dtp = NULL;
560
561
if (!is_sta_active(sta))
562
return;
563
dtp = &sta->dtp_stat;
564
565
if (!(dm->support_ability & ODM_BB_DYNAMIC_TXPWR))
566
return;
567
568
if (dm->fill_desc_dyntxpwr)
569
dm->fill_desc_dyntxpwr(dm, desc, dtp->dyn_tx_power);
570
else
571
PHYDM_DBG(dm, DBG_DYN_TXPWR,
572
"%s: fill_desc_dyntxpwr is null!\n", __func__);
573
574
if (dtp->last_tx_power != dtp->dyn_tx_power) {
575
PHYDM_DBG(dm, DBG_DYN_TXPWR,
576
"%s: last_offset=%d, txpwr_offset=%d\n", __func__,
577
dtp->last_tx_power, dtp->dyn_tx_power);
578
dtp->last_tx_power = dtp->dyn_tx_power;
579
}
580
}
581
582
void phydm_dtp_debug(void *dm_void, char input[][16], u32 *_used, char *output,
583
u32 *_out_len)
584
{
585
u32 used = *_used;
586
u32 out_len = *_out_len;
587
588
struct dm_struct *dm = (struct dm_struct *)dm_void;
589
char help[] = "-h";
590
u32 var1[7] = {0};
591
u8 set_pwr_th1, set_pwr_th2, set_pwr_th3;
592
u8 i = 0;
593
#ifdef BB_RAM_SUPPORT
594
s8 pwr_ofst_tmp = 0x0;
595
#endif
596
597
if ((strcmp(input[1], help) == 0)) {
598
PDM_SNPF(out_len, used, output + used, out_len - used,
599
"Set DTP threhosld: {1} {Lv1_th} {Lv2_th} {Lv3_th}\n");
600
#ifdef BB_RAM_SUPPORT
601
PDM_SNPF(out_len, used, output + used, out_len - used,
602
"Set pwr_tx_offset: {2} {0:reg 1:macid} {en} {offset 0/1} {0:-, 1:+} {Pwr Offset} {macid}\n");
603
PDM_SNPF(out_len, used, output + used, out_len - used,
604
"Read pwr_tx_offset : {3} {0:reg 1:macid} {macid(0~63), 255:all}\n");
605
PDM_SNPF(out_len, used, output + used, out_len - used,
606
"Reset all ram pwr_tx_offset : {4}\n");
607
#endif
608
} else {
609
for (i = 0; i < 7; i++) {
610
if (input[i + 1])
611
PHYDM_SSCANF(input[i + 1], DCMD_DECIMAL,
612
&var1[i]);
613
}
614
switch (var1[0]) {
615
case 1:
616
for (i = 0; i < 3; i++) {
617
if (var1[i] == 0 || var1[i] > 100)
618
dm->set_pwr_th[i] = 0xff;
619
else
620
dm->set_pwr_th[i] = (u8)var1[1 + i];
621
}
622
623
PDM_SNPF(out_len, used, output + used, out_len - used,
624
"DTP_TH[0:2] = {%d, %d, %d}\n",
625
dm->set_pwr_th[0], dm->set_pwr_th[1],
626
dm->set_pwr_th[2]);
627
break;
628
#ifdef BB_RAM_SUPPORT
629
case 2:
630
if ((boolean)var1[4])
631
pwr_ofst_tmp = (s8)var1[5];
632
else
633
pwr_ofst_tmp = 0x0 - (s8)var1[5];
634
635
if ((boolean)var1[1])
636
phydm_wt_ram_pwr(dm, (u8)var1[6],
637
(boolean)var1[3],
638
(boolean)var1[2],
639
pwr_ofst_tmp);
640
else
641
phydm_wt_reg_pwr(dm, (boolean)var1[3],
642
(boolean)var1[2],
643
pwr_ofst_tmp);
644
break;
645
case 3:
646
if ((boolean)var1[1]) {
647
if ((u8)var1[2] == 0xff)
648
for (i = 0; i < 64; i++)
649
phydm_rd_ram_pwr(dm, i, &used,
650
output,
651
&out_len);
652
else
653
phydm_rd_ram_pwr(dm, (u8)var1[2], &used,
654
output, &out_len);
655
} else {
656
phydm_rd_reg_pwr(dm, &used, output, &out_len);
657
}
658
break;
659
case 4:
660
phydm_rst_ram_pwr(dm);
661
break;
662
#endif
663
}
664
}
665
*_used = used;
666
*_out_len = out_len;
667
}
668
669
void phydm_dynamic_tx_power(void *dm_void)
670
{
671
struct dm_struct *dm = (struct dm_struct *)dm_void;
672
struct cmn_sta_info *sta = NULL;
673
u8 i = 0;
674
u8 cnt = 0;
675
u8 rssi_min = dm->rssi_min;
676
u8 rssi_tmp = 0;
677
678
if (!(dm->support_ability & ODM_BB_DYNAMIC_TXPWR))
679
return;
680
681
if (!(dm->support_ic_type & ODM_IC_JGR3_SERIES)) {
682
PHYDM_DBG(dm, DBG_DYN_TXPWR,
683
"[%s] RSSI_min = %d, Noisy_dec = %d\n", __func__,
684
rssi_min, dm->noisy_decision);
685
phydm_noisy_enhance_hp_th(dm, dm->noisy_decision);
686
/* Response Power */
687
dm->dynamic_tx_high_power_lvl = phydm_pwr_lvl_check(dm,
688
rssi_min);
689
phydm_dynamic_response_power(dm);
690
}
691
/* Per STA Tx power */
692
for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
693
phydm_dtp_per_sta(dm, i);
694
cnt++;
695
if (cnt >= dm->number_linked_client)
696
break;
697
}
698
}
699
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
700
701
void phydm_dynamic_tx_power_init_win(void *dm_void)
702
{
703
struct dm_struct *dm = (struct dm_struct *)dm_void;
704
void *adapter = dm->adapter;
705
PMGNT_INFO mgnt_info = &((PADAPTER)adapter)->MgntInfo;
706
HAL_DATA_TYPE *hal_data = GET_HAL_DATA((PADAPTER)adapter);
707
708
mgnt_info->bDynamicTxPowerEnable = false;
709
#if DEV_BUS_TYPE == RT_USB_INTERFACE
710
if (RT_GetInterfaceSelection((PADAPTER)adapter) ==
711
INTF_SEL1_USB_High_Power) {
712
mgnt_info->bDynamicTxPowerEnable = true;
713
}
714
#endif
715
716
hal_data->LastDTPLvl = tx_high_pwr_level_normal;
717
hal_data->DynamicTxHighPowerLvl = tx_high_pwr_level_normal;
718
719
PHYDM_DBG(dm, DBG_DYN_TXPWR, "[%s] DTP=%d\n", __func__,
720
mgnt_info->bDynamicTxPowerEnable);
721
}
722
723
void phydm_dynamic_tx_power_win(void *dm_void)
724
{
725
struct dm_struct *dm = (struct dm_struct *)dm_void;
726
727
if (!(dm->support_ability & ODM_BB_DYNAMIC_TXPWR))
728
return;
729
730
#if (RTL8814A_SUPPORT)
731
if (dm->support_ic_type == ODM_RTL8814A)
732
odm_dynamic_tx_power_8814a(dm);
733
#endif
734
735
#if (RTL8821A_SUPPORT)
736
if (dm->support_ic_type & ODM_RTL8821) {
737
void *adapter = dm->adapter;
738
PMGNT_INFO mgnt_info = GetDefaultMgntInfo((PADAPTER)adapter);
739
740
if (mgnt_info->RegRspPwr == 1) {
741
if (dm->rssi_min > 60) {
742
/*Resp TXAGC offset = -3dB*/
743
odm_set_mac_reg(dm, R_0x6d8, 0x1C0000, 1);
744
} else if (dm->rssi_min < 55) {
745
/*Resp TXAGC offset = 0dB*/
746
odm_set_mac_reg(dm, R_0x6d8, 0x1C0000, 0);
747
}
748
}
749
}
750
#endif
751
}
752
#endif /*@#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)*/
753
#endif /* @#ifdef CONFIG_DYNAMIC_TX_TWR */
754
755