Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/hal/phydm/phydm_adaptivity.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
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
33
#if WPP_SOFTWARE_TRACE
34
#include "PhyDM_Adaptivity.tmh"
35
#endif
36
#endif
37
#ifdef PHYDM_SUPPORT_ADAPTIVITY
38
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
39
boolean
40
phydm_check_channel_plan(void *dm_void)
41
{
42
struct dm_struct *dm = (struct dm_struct *)dm_void;
43
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
44
void *adapter = dm->adapter;
45
PMGNT_INFO mgnt_info = &((PADAPTER)adapter)->MgntInfo;
46
47
if (mgnt_info->RegEnableAdaptivity != 2)
48
return false;
49
50
if (!dm->carrier_sense_enable) { /*@check domain Code for adaptivity or CarrierSense*/
51
if ((*dm->band_type == ODM_BAND_5G) &&
52
!(adapt->regulation_5g == REGULATION_ETSI || adapt->regulation_5g == REGULATION_WW)) {
53
PHYDM_DBG(dm, DBG_ADPTVTY,
54
"adaptivity skip 5G domain code : %d\n",
55
adapt->regulation_5g);
56
return true;
57
} else if ((*dm->band_type == ODM_BAND_2_4G) &&
58
!(adapt->regulation_2g == REGULATION_ETSI || adapt->regulation_2g == REGULATION_WW)) {
59
PHYDM_DBG(dm, DBG_ADPTVTY,
60
"adaptivity skip 2.4G domain code : %d\n",
61
adapt->regulation_2g);
62
return true;
63
} else if ((*dm->band_type != ODM_BAND_2_4G) && (*dm->band_type != ODM_BAND_5G)) {
64
PHYDM_DBG(dm, DBG_ADPTVTY,
65
"adaptivity neither 2G nor 5G band, return\n");
66
return true;
67
}
68
} else {
69
if ((*dm->band_type == ODM_BAND_5G) &&
70
!(adapt->regulation_5g == REGULATION_MKK || adapt->regulation_5g == REGULATION_WW)) {
71
PHYDM_DBG(dm, DBG_ADPTVTY,
72
"CarrierSense skip 5G domain code : %d\n",
73
adapt->regulation_5g);
74
return true;
75
} else if ((*dm->band_type == ODM_BAND_2_4G) &&
76
!(adapt->regulation_2g == REGULATION_MKK || adapt->regulation_2g == REGULATION_WW)) {
77
PHYDM_DBG(dm, DBG_ADPTVTY,
78
"CarrierSense skip 2.4G domain code : %d\n",
79
adapt->regulation_2g);
80
return true;
81
} else if ((*dm->band_type != ODM_BAND_2_4G) && (*dm->band_type != ODM_BAND_5G)) {
82
PHYDM_DBG(dm, DBG_ADPTVTY,
83
"CarrierSense neither 2G nor 5G band, return\n");
84
return true;
85
}
86
}
87
88
return false;
89
}
90
91
boolean
92
phydm_soft_ap_special_set(void *dm_void)
93
{
94
struct dm_struct *dm = (struct dm_struct *)dm_void;
95
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
96
boolean disable_ap_adapt_setting = false;
97
98
if (dm->soft_ap_mode != NULL) {
99
if (*dm->soft_ap_mode != 0 &&
100
(dm->soft_ap_special_setting & BIT(0)))
101
disable_ap_adapt_setting = true;
102
else
103
disable_ap_adapt_setting = false;
104
PHYDM_DBG(dm, DBG_ADPTVTY,
105
"soft_ap_setting = %x, soft_ap = %d, dis_ap_adapt = %d\n",
106
dm->soft_ap_special_setting, *dm->soft_ap_mode,
107
disable_ap_adapt_setting);
108
}
109
110
return disable_ap_adapt_setting;
111
}
112
113
boolean
114
phydm_ap_num_check(void *dm_void)
115
{
116
struct dm_struct *dm = (struct dm_struct *)dm_void;
117
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
118
boolean dis_adapt = false;
119
120
if (dm->ap_total_num > adapt->ap_num_th)
121
dis_adapt = true;
122
else
123
dis_adapt = false;
124
125
PHYDM_DBG(dm, DBG_ADPTVTY, "AP total num = %d, AP num threshold = %d\n",
126
dm->ap_total_num, adapt->ap_num_th);
127
return dis_adapt;
128
}
129
130
void phydm_check_adaptivity(void *dm_void)
131
{
132
struct dm_struct *dm = (struct dm_struct *)dm_void;
133
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
134
boolean disable_adapt = false;
135
136
if (!adapt->mode_cvrt_en)
137
return;
138
139
if (phydm_check_channel_plan(dm) || phydm_ap_num_check(dm) ||
140
phydm_soft_ap_special_set(dm))
141
disable_adapt = true;
142
143
if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE && disable_adapt)
144
*dm->edcca_mode = PHYDM_EDCCA_NORMAL_MODE;
145
else if (*dm->edcca_mode == PHYDM_EDCCA_NORMAL_MODE && !disable_adapt)
146
*dm->edcca_mode = PHYDM_EDCCA_ADAPT_MODE;
147
}
148
149
#endif
150
151
void phydm_dig_up_bound_lmt_en(void *dm_void)
152
{
153
struct dm_struct *dm = (struct dm_struct *)dm_void;
154
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
155
156
if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE ||
157
!dm->is_linked) {
158
adapt->igi_up_bound_lmt_cnt = 0;
159
adapt->igi_lmt_en = false;
160
return;
161
}
162
163
if (dm->total_tp > 1) {
164
adapt->igi_lmt_en = true;
165
adapt->igi_up_bound_lmt_cnt = adapt->igi_up_bound_lmt_val;
166
PHYDM_DBG(dm, DBG_ADPTVTY,
167
"TP >1, Start limit IGI upper bound\n");
168
} else {
169
if (adapt->igi_up_bound_lmt_cnt == 0)
170
adapt->igi_lmt_en = false;
171
else
172
adapt->igi_up_bound_lmt_cnt--;
173
}
174
175
PHYDM_DBG(dm, DBG_ADPTVTY, "IGI_lmt_cnt = %d\n",
176
adapt->igi_up_bound_lmt_cnt);
177
}
178
179
void phydm_set_edcca_threshold(void *dm_void, s8 H2L, s8 L2H)
180
{
181
struct dm_struct *dm = (struct dm_struct *)dm_void;
182
183
if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
184
odm_set_bb_reg(dm, R_0x84c, MASKBYTE2, (u8)L2H + 0x80);
185
odm_set_bb_reg(dm, R_0x84c, MASKBYTE3, (u8)H2L + 0x80);
186
} else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
187
odm_set_bb_reg(dm, R_0xc4c, MASKBYTE0, (u8)L2H);
188
odm_set_bb_reg(dm, R_0xc4c, MASKBYTE2, (u8)H2L);
189
} else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
190
odm_set_bb_reg(dm, R_0x8a4, MASKBYTE0, (u8)L2H);
191
odm_set_bb_reg(dm, R_0x8a4, MASKBYTE1, (u8)H2L);
192
}
193
}
194
195
void phydm_mac_edcca_state(void *dm_void, enum phydm_mac_edcca_type state)
196
{
197
struct dm_struct *dm = (struct dm_struct *)dm_void;
198
199
if (state == PHYDM_IGNORE_EDCCA) {
200
/*@ignore EDCCA*/
201
odm_set_mac_reg(dm, R_0x520, BIT(15), 1);
202
/*@enable EDCCA count down*/
203
odm_set_mac_reg(dm, R_0x524, BIT(11), 0);
204
} else { /*@don't set MAC ignore EDCCA signal*/
205
/*@don't ignore EDCCA*/
206
odm_set_mac_reg(dm, R_0x520, BIT(15), 0);
207
/*@disable EDCCA count down*/
208
odm_set_mac_reg(dm, R_0x524, BIT(11), 1);
209
}
210
PHYDM_DBG(dm, DBG_ADPTVTY, "EDCCA enable state = %d\n", state);
211
}
212
213
void phydm_search_pwdb_lower_bound(void *dm_void)
214
{
215
struct dm_struct *dm = (struct dm_struct *)dm_void;
216
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
217
u32 value32 = 0, reg_value32 = 0;
218
u8 cnt = 0, try_count = 0;
219
u8 tx_edcca1 = 0;
220
boolean is_adjust = true;
221
s8 th_l2h, th_h2l, igi_target_dc = 0x32;
222
s8 diff = 0;
223
s8 IGI = adapt->igi_base + 30 + dm->th_l2h_ini - dm->th_edcca_hl_diff;
224
225
halrf_rf_lna_setting(dm, HALRF_LNA_DISABLE);
226
diff = igi_target_dc - IGI;
227
th_l2h = dm->th_l2h_ini + diff;
228
if (th_l2h > 10)
229
th_l2h = 10;
230
231
th_h2l = th_l2h - dm->th_edcca_hl_diff;
232
phydm_set_edcca_threshold(dm, th_h2l, th_l2h);
233
ODM_delay_ms(30);
234
235
while (is_adjust) {
236
/*@check CCA status*/
237
/*set debug port to 0x0*/
238
if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_1, 0x0)) {
239
reg_value32 = phydm_get_bb_dbg_port_val(dm);
240
241
while (reg_value32 & BIT(3) && try_count < 3) {
242
ODM_delay_ms(3);
243
try_count = try_count + 1;
244
reg_value32 = phydm_get_bb_dbg_port_val(dm);
245
}
246
phydm_release_bb_dbg_port(dm);
247
try_count = 0;
248
}
249
250
/*@count EDCCA signal = 1 times*/
251
for (cnt = 0; cnt < 20; cnt++) {
252
if (phydm_set_bb_dbg_port(dm, DBGPORT_PRI_1,
253
adapt->adaptivity_dbg_port)) {
254
value32 = phydm_get_bb_dbg_port_val(dm);
255
phydm_release_bb_dbg_port(dm);
256
}
257
258
if (value32 & BIT(30) && dm->support_ic_type &
259
(ODM_RTL8723B | ODM_RTL8188E))
260
tx_edcca1 = tx_edcca1 + 1;
261
else if (value32 & BIT(29))
262
tx_edcca1 = tx_edcca1 + 1;
263
}
264
265
if (tx_edcca1 > 1) {
266
IGI = IGI - 1;
267
th_l2h = th_l2h + 1;
268
if (th_l2h > 10)
269
th_l2h = 10;
270
271
th_h2l = th_l2h - dm->th_edcca_hl_diff;
272
phydm_set_edcca_threshold(dm, th_h2l, th_l2h);
273
tx_edcca1 = 0;
274
if (th_l2h == 10)
275
is_adjust = false;
276
277
} else {
278
is_adjust = false;
279
}
280
}
281
282
adapt->adapt_igi_up = IGI - ADAPT_DC_BACKOFF;
283
adapt->h2l_lb = th_h2l + ADAPT_DC_BACKOFF;
284
adapt->l2h_lb = th_l2h + ADAPT_DC_BACKOFF;
285
286
halrf_rf_lna_setting(dm, HALRF_LNA_ENABLE);
287
phydm_set_edcca_threshold(dm, 0x7f, 0x7f); /*resume to no link state*/
288
}
289
290
boolean phydm_re_search_condition(void *dm_void)
291
{
292
struct dm_struct *dm = (struct dm_struct *)dm_void;
293
struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;
294
u8 adaptivity_igi_upper = adaptivity->adapt_igi_up + ADAPT_DC_BACKOFF;
295
296
if (adaptivity_igi_upper <= 0x26)
297
return true;
298
else
299
return false;
300
}
301
302
void phydm_set_l2h_th_ini(void *dm_void)
303
{
304
struct dm_struct *dm = (struct dm_struct *)dm_void;
305
306
/*@ [New Format: JGR3]IGI-idx:45 = RSSI:35 = -65dBm*/
307
if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
308
if (dm->support_ic_type & ODM_RTL8822C)
309
dm->th_l2h_ini = 45;
310
else if (dm->support_ic_type & ODM_RTL8814B)
311
dm->th_l2h_ini = 49;
312
} else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
313
/*@ [Old Format] -11+base(50) = IGI_idx:39 = RSSI:29 = -71dBm*/
314
if (dm->support_ic_type & (ODM_RTL8821 | ODM_RTL8812))
315
dm->th_l2h_ini = -17;
316
else
317
dm->th_l2h_ini = -14;
318
} else { /*ODM_IC_11N_SERIES*/
319
if (dm->support_ic_type & ODM_RTL8721D)
320
dm->th_l2h_ini = -14;
321
else
322
dm->th_l2h_ini = -11;
323
}
324
}
325
326
void phydm_set_l2h_th_ini_carrier_sense(void *dm_void)
327
{
328
struct dm_struct *dm = (struct dm_struct *)dm_void;
329
330
if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
331
dm->th_l2h_ini = 60; /*@ -50dBm*/
332
else
333
dm->th_l2h_ini = 10; /*@ -50dBm*/
334
}
335
336
void phydm_set_forgetting_factor(void *dm_void)
337
{
338
struct dm_struct *dm = (struct dm_struct *)dm_void;
339
340
if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE)
341
return;
342
343
if (dm->support_ic_type & (ODM_RTL8821C | ODM_RTL8822B | ODM_RTL8814A |
344
ODM_RTL8195B))
345
odm_set_bb_reg(dm, R_0x8a0, BIT(1) | BIT(0), 0);
346
}
347
348
void phydm_edcca_decision_opt(void *dm_void)
349
{
350
struct dm_struct *dm = (struct dm_struct *)dm_void;
351
352
if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE)
353
return;
354
355
if (dm->support_ic_type & ODM_RTL8822B)
356
odm_set_bb_reg(dm, R_0x8dc, BIT(5), 0x1);
357
else if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8192F))
358
odm_set_bb_reg(dm, R_0xce8, BIT(13), 0x1);
359
else if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
360
odm_set_bb_reg(dm, R_0x844, BIT(30) | BIT(29), 0x0);
361
}
362
363
void phydm_adaptivity_debug(void *dm_void, char input[][16], u32 *_used,
364
char *output, u32 *_out_len)
365
{
366
struct dm_struct *dm = (struct dm_struct *)dm_void;
367
struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;
368
u32 used = *_used;
369
u32 out_len = *_out_len;
370
char help[] = "-h";
371
u32 dm_value[10] = {0};
372
u8 i = 0, input_idx = 0;
373
u32 reg_value32 = 0;
374
s8 h2l_diff = 0;
375
376
for (i = 0; i < 5; i++) {
377
if (input[i + 1]) {
378
PHYDM_SSCANF(input[i + 1], DCMD_HEX, &dm_value[i]);
379
input_idx++;
380
}
381
}
382
if (strcmp(input[1], help) == 0) {
383
PDM_SNPF(out_len, used, output + used, out_len - used,
384
"Show adaptivity message: {0}\n");
385
PDM_SNPF(out_len, used, output + used, out_len - used,
386
"Enter debug mode: {1} {th_l2h_ini} {th_edcca_hl_diff}\n");
387
PDM_SNPF(out_len, used, output + used, out_len - used,
388
"Leave debug mode: {2}\n");
389
goto out;
390
}
391
392
if (input_idx == 0)
393
return;
394
395
if (dm_value[0] == PHYDM_ADAPT_DEBUG) {
396
adaptivity->debug_mode = true;
397
if (dm_value[1] != 0)
398
dm->th_l2h_ini = (s8)dm_value[1];
399
if (dm_value[2] != 0)
400
dm->th_edcca_hl_diff = (s8)dm_value[2];
401
PDM_SNPF(out_len, used, output + used, out_len - used,
402
"th_l2h_ini = %d, th_edcca_hl_diff = %d\n",
403
dm->th_l2h_ini, dm->th_edcca_hl_diff);
404
} else if (dm_value[0] == PHYDM_ADAPT_RESUME) {
405
adaptivity->debug_mode = false;
406
dm->th_l2h_ini = adaptivity->th_l2h_ini_backup;
407
dm->th_edcca_hl_diff = adaptivity->th_edcca_hl_diff_backup;
408
} else if (dm_value[0] == PHYDM_ADAPT_MSG) {
409
PDM_SNPF(out_len, used, output + used, out_len - used,
410
"debug_mode = %s, th_l2h_ini = %d\n",
411
(adaptivity->debug_mode ? "TRUE" : "FALSE"),
412
dm->th_l2h_ini);
413
if (dm->support_ic_type & ODM_IC_JGR3_SERIES) {
414
reg_value32 = odm_get_bb_reg(dm, R_0x84c, MASKDWORD);
415
h2l_diff = (s8)((0x00ff0000 & reg_value32) >> 16) -
416
(s8)((0xff000000 & reg_value32) >> 24);
417
} else if (dm->support_ic_type & ODM_IC_11N_SERIES) {
418
reg_value32 = odm_get_bb_reg(dm, R_0xc4c, MASKDWORD);
419
h2l_diff = (s8)(0x000000ff & reg_value32) -
420
(s8)((0x00ff0000 & reg_value32) >> 16);
421
} else if (dm->support_ic_type & ODM_IC_11AC_SERIES) {
422
reg_value32 = odm_get_bb_reg(dm, R_0x8a4, MASKDWORD);
423
h2l_diff = (s8)(0x000000ff & reg_value32) -
424
(s8)((0x0000ff00 & reg_value32) >> 8);
425
}
426
427
if (h2l_diff == 7)
428
PDM_SNPF(out_len, used, output + used, out_len - used,
429
"adaptivity enable\n");
430
else
431
PDM_SNPF(out_len, used, output + used, out_len - used,
432
"adaptivity disable\n");
433
}
434
435
out:
436
*_used = used;
437
*_out_len = out_len;
438
}
439
440
void phydm_set_edcca_val(void *dm_void, u32 *val_buf, u8 val_len)
441
{
442
struct dm_struct *dm = (struct dm_struct *)dm_void;
443
444
if (val_len != 2) {
445
PHYDM_DBG(dm, ODM_COMP_API,
446
"[Error][adaptivity]Need val_len = 2\n");
447
return;
448
}
449
phydm_set_edcca_threshold(dm, (s8)val_buf[1], (s8)val_buf[0]);
450
}
451
452
boolean phydm_edcca_abort(void *dm_void)
453
{
454
struct dm_struct *dm = (struct dm_struct *)dm_void;
455
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
456
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
457
void *adapter = dm->adapter;
458
u32 is_fw_in_psmode = false;
459
#endif
460
461
if (!(dm->support_ability & ODM_BB_ADAPTIVITY)) {
462
PHYDM_DBG(dm, DBG_ADPTVTY, "adaptivity disable\n");
463
return true;
464
}
465
466
if (dm->pause_ability & ODM_BB_ADAPTIVITY) {
467
PHYDM_DBG(dm, DBG_ADPTVTY, "Return: Pause ADPTVTY in LV=%d\n",
468
dm->pause_lv_table.lv_adapt);
469
return true;
470
}
471
472
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
473
((PADAPTER)adapter)->HalFunc.GetHwRegHandler(adapter,
474
HW_VAR_FW_PSMODE_STATUS,
475
(u8 *)(&is_fw_in_psmode));
476
477
/*@Disable EDCCA while under LPS mode, added by Roger, 2012.09.14.*/
478
if (is_fw_in_psmode)
479
return true;
480
#endif
481
482
return false;
483
}
484
485
void phydm_edcca_thre_calc_jgr3(void *dm_void)
486
{
487
struct dm_struct *dm = (struct dm_struct *)dm_void;
488
struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
489
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
490
u8 igi = dig_t->cur_ig_value;
491
s8 th_l2h = 0, th_h2l = 0;
492
493
if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE) {
494
/*prevent pwdB clipping and result in Miss Detection*/
495
adapt->l2h_dyn_min = (u8)(dm->th_l2h_ini - ADC_BACKOFF);
496
497
if (igi < adapt->l2h_dyn_min)
498
th_l2h = igi + ADC_BACKOFF;
499
else
500
th_l2h = dm->th_l2h_ini;
501
502
th_h2l = th_l2h - dm->th_edcca_hl_diff;
503
} else {
504
th_l2h = MAX_2(igi + TH_L2H_DIFF_IGI, EDCCA_TH_L2H_LB);
505
th_h2l = th_l2h - EDCCA_HL_DIFF_NORMAL;
506
}
507
adapt->th_l2h = th_l2h;
508
adapt->th_h2l = th_h2l;
509
510
phydm_set_edcca_threshold(dm, adapt->th_h2l, adapt->th_l2h);
511
}
512
513
void phydm_edcca_thre_calc(void *dm_void)
514
{
515
struct dm_struct *dm = (struct dm_struct *)dm_void;
516
struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
517
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
518
u8 igi = dig_t->cur_ig_value;
519
s8 th_l2h = 0, th_h2l = 0;
520
s8 diff = 0, igi_target = adapt->igi_base;
521
522
if (dm->support_ic_type & ODM_IC_PWDB_EDCCA) {
523
/*@fix EDCCA hang issue*/
524
if (dm->support_ic_type & ODM_RTL8812) {
525
/*@ADC_mask disable*/
526
odm_set_bb_reg(dm, R_0x800, BIT(10), 1);
527
/*@ADC_mask enable*/
528
odm_set_bb_reg(dm, R_0x800, BIT(10), 0);
529
}
530
531
if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE) {
532
/*@Limit IGI upper bound for adaptivity*/
533
phydm_dig_up_bound_lmt_en(dm);
534
diff = igi_target - (s8)igi;
535
th_l2h = dm->th_l2h_ini + diff;
536
if (th_l2h > 10)
537
th_l2h = 10;
538
539
th_h2l = th_l2h - dm->th_edcca_hl_diff;
540
} else {
541
th_l2h = 70 - igi;
542
th_h2l = th_l2h - EDCCA_HL_DIFF_NORMAL;
543
}
544
/*replace lower bound to prevent EDCCA always equal 1*/
545
if (th_h2l < adapt->h2l_lb)
546
th_h2l = adapt->h2l_lb;
547
if (th_l2h < adapt->l2h_lb)
548
th_l2h = adapt->l2h_lb;
549
PHYDM_DBG(dm, DBG_ADPTVTY,
550
"adapt_igi_up=0x%x, l2h_lb = %d dBm, h2l_lb = %d dBm\n",
551
adapt->adapt_igi_up,
552
IGI_2_DBM(adapt->l2h_lb + adapt->adapt_igi_up),
553
IGI_2_DBM(adapt->h2l_lb + adapt->adapt_igi_up));
554
} else { /* < JGR2 & N*/
555
if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE) {
556
/*need to consider PwdB upper bound for 8814 later IC*/
557
adapt->l2h_dyn_min = (u8)(dm->th_l2h_ini + igi_target);
558
559
if (igi < adapt->l2h_dyn_min)
560
th_l2h = igi;
561
else
562
th_l2h = adapt->l2h_dyn_min;
563
564
th_h2l = th_l2h - dm->th_edcca_hl_diff;
565
} else {
566
th_l2h = MAX_2(igi + TH_L2H_DIFF_IGI, EDCCA_TH_L2H_LB);
567
th_h2l = th_l2h - EDCCA_HL_DIFF_NORMAL;
568
}
569
}
570
571
adapt->th_l2h = th_l2h;
572
adapt->th_h2l = th_h2l;
573
574
phydm_set_edcca_threshold(dm, adapt->th_h2l, adapt->th_l2h);
575
}
576
#endif
577
578
void phydm_set_edcca_threshold_api(void *dm_void)
579
{
580
#ifdef PHYDM_SUPPORT_ADAPTIVITY
581
struct dm_struct *dm = (struct dm_struct *)dm_void;
582
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
583
584
if (*dm->edcca_mode != PHYDM_EDCCA_ADAPT_MODE)
585
return;
586
587
if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
588
phydm_edcca_thre_calc_jgr3(dm);
589
else
590
phydm_edcca_thre_calc(dm);
591
592
PHYDM_DBG(dm, DBG_ADPTVTY,
593
"API :IGI = 0x%x, th_l2h = %d, th_h2l = %d\n",
594
dm->dm_dig_table.cur_ig_value, adapt->th_l2h, adapt->th_h2l);
595
#endif
596
}
597
598
void phydm_adaptivity_info_init(void *dm_void, enum phydm_adapinfo cmn_info,
599
u32 value)
600
{
601
struct dm_struct *dm = (struct dm_struct *)dm_void;
602
struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;
603
604
switch (cmn_info) {
605
case PHYDM_ADAPINFO_CARRIER_SENSE_ENABLE:
606
dm->carrier_sense_enable = (boolean)value;
607
break;
608
case PHYDM_ADAPINFO_TH_L2H_INI:
609
dm->th_l2h_ini = (s8)value;
610
break;
611
case PHYDM_ADAPINFO_TH_EDCCA_HL_DIFF:
612
dm->th_edcca_hl_diff = (s8)value;
613
break;
614
case PHYDM_ADAPINFO_AP_NUM_TH:
615
adaptivity->ap_num_th = (u8)value;
616
break;
617
default:
618
break;
619
}
620
}
621
622
void phydm_adaptivity_info_update(void *dm_void, enum phydm_adapinfo cmn_info,
623
u32 value)
624
{
625
struct dm_struct *dm = (struct dm_struct *)dm_void;
626
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
627
628
/*This init variable may be changed in run time.*/
629
switch (cmn_info) {
630
case PHYDM_ADAPINFO_DOMAIN_CODE_2G:
631
adapt->regulation_2g = (u8)value;
632
break;
633
case PHYDM_ADAPINFO_DOMAIN_CODE_5G:
634
adapt->regulation_5g = (u8)value;
635
break;
636
default:
637
break;
638
}
639
}
640
641
void phydm_adaptivity_init(void *dm_void)
642
{
643
#ifdef PHYDM_SUPPORT_ADAPTIVITY
644
struct dm_struct *dm = (struct dm_struct *)dm_void;
645
struct phydm_adaptivity_struct *adaptivity = &dm->adaptivity;
646
647
/* @[Config Adaptivity]*/
648
if (!dm->edcca_mode) {
649
pr_debug("[%s] warning!\n", __func__);
650
dm->edcca_mode = &dm->u8_dummy;
651
dm->support_ability &= ~ODM_BB_ADAPTIVITY;
652
return;
653
}
654
655
#if (DM_ODM_SUPPORT_TYPE & ODM_WIN)
656
if (!dm->carrier_sense_enable) {
657
if (dm->th_l2h_ini == 0)
658
phydm_set_l2h_th_ini(dm);
659
} else {
660
phydm_set_l2h_th_ini_carrier_sense(dm);
661
}
662
663
if (dm->th_edcca_hl_diff == 0)
664
dm->th_edcca_hl_diff = 7;
665
666
if (dm->wifi_test & RT_WIFI_LOGO)
667
dm->support_ability &= ~ODM_BB_ADAPTIVITY;
668
669
if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE)
670
adaptivity->mode_cvrt_en = true;
671
else
672
adaptivity->mode_cvrt_en = false;
673
#elif (DM_ODM_SUPPORT_TYPE & ODM_CE)
674
if (!dm->carrier_sense_enable) {
675
if (dm->th_l2h_ini == 0)
676
phydm_set_l2h_th_ini(dm);
677
} else {
678
phydm_set_l2h_th_ini_carrier_sense(dm);
679
}
680
681
if (dm->th_edcca_hl_diff == 0)
682
dm->th_edcca_hl_diff = 7;
683
684
if (dm->wifi_test || *dm->mp_mode)
685
dm->support_ability &= ~ODM_BB_ADAPTIVITY;
686
#elif (DM_ODM_SUPPORT_TYPE & ODM_AP)
687
if (dm->carrier_sense_enable) {
688
phydm_set_l2h_th_ini_carrier_sense(dm);
689
dm->th_edcca_hl_diff = 7;
690
} else {
691
dm->th_l2h_ini = dm->TH_L2H_default; /*set by mib*/
692
dm->th_edcca_hl_diff = dm->th_edcca_hl_diff_default;
693
}
694
#elif (DM_ODM_SUPPORT_TYPE & ODM_IOT)
695
if (!dm->carrier_sense_enable) {
696
if (dm->th_l2h_ini == 0)
697
phydm_set_l2h_th_ini(dm);
698
} else {
699
phydm_set_l2h_th_ini_carrier_sense(dm);
700
}
701
702
if (dm->th_edcca_hl_diff == 0)
703
dm->th_edcca_hl_diff = 7;
704
#endif
705
706
adaptivity->debug_mode = false;
707
adaptivity->th_l2h_ini_backup = dm->th_l2h_ini;
708
adaptivity->th_edcca_hl_diff_backup = dm->th_edcca_hl_diff;
709
adaptivity->igi_base = 0x32;
710
adaptivity->adapt_igi_up = 0;
711
adaptivity->h2l_lb = 0;
712
adaptivity->l2h_lb = 0;
713
adaptivity->l2h_dyn_min = 0;
714
adaptivity->th_l2h = 0x7f;
715
adaptivity->th_h2l = 0x7f;
716
717
if (dm->support_ic_type & ODM_IC_11N_SERIES)
718
adaptivity->adaptivity_dbg_port = 0x208;
719
else if (dm->support_ic_type & ODM_IC_11AC_SERIES)
720
adaptivity->adaptivity_dbg_port = 0x209;
721
722
if (dm->support_ic_type & ODM_IC_11N_SERIES &&
723
!(dm->support_ic_type & ODM_IC_PWDB_EDCCA)) {
724
if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8192F)) {
725
/*set to page B1*/
726
odm_set_bb_reg(dm, R_0xe28, BIT(30), 0x1);
727
/*@0:rx_dfir, 1: dcnf_out, 2 :rx_iq, 3: rx_nbi_nf_out*/
728
odm_set_bb_reg(dm, R_0xbc0, BIT(27) | BIT(26), 0x1);
729
odm_set_bb_reg(dm, R_0xe28, BIT(30), 0x0);
730
} else {
731
/*@0:rx_dfir, 1: dcnf_out, 2 :rx_iq, 3: rx_nbi_nf_out*/
732
odm_set_bb_reg(dm, R_0xe24, BIT(21) | BIT(20), 0x1);
733
}
734
} else if (dm->support_ic_type & ODM_IC_11AC_SERIES &&
735
!(dm->support_ic_type & ODM_IC_PWDB_EDCCA)) {
736
/*@0:rx_dfir, 1: dcnf_out, 2 :rx_iq, 3: rx_nbi_nf_out*/
737
odm_set_bb_reg(dm, R_0x944, BIT(29) | BIT(28), 0x1);
738
}
739
740
if (dm->support_ic_type & ODM_IC_PWDB_EDCCA) {
741
phydm_search_pwdb_lower_bound(dm);
742
if (phydm_re_search_condition(dm))
743
phydm_search_pwdb_lower_bound(dm);
744
} else {
745
/*resume to no link state*/
746
phydm_set_edcca_threshold(dm, 0x7f, 0x7f);
747
}
748
749
/*@whether to ignore EDCCA*/
750
phydm_mac_edcca_state(dm, PHYDM_DONT_IGNORE_EDCCA);
751
752
/*@forgetting factor setting*/
753
phydm_set_forgetting_factor(dm);
754
755
/*@EDCCA behavior based on maximum or mean power*/
756
phydm_edcca_decision_opt(dm);
757
758
#if (DM_ODM_SUPPORT_TYPE == ODM_AP)
759
adaptivity->igi_up_bound_lmt_val = 180;
760
#else
761
adaptivity->igi_up_bound_lmt_val = 90;
762
#endif
763
adaptivity->igi_up_bound_lmt_cnt = 0;
764
adaptivity->igi_lmt_en = false;
765
#endif
766
}
767
768
void phydm_adaptivity(void *dm_void)
769
{
770
#ifdef PHYDM_SUPPORT_ADAPTIVITY
771
struct dm_struct *dm = (struct dm_struct *)dm_void;
772
struct phydm_adaptivity_struct *adapt = &dm->adaptivity;
773
struct phydm_dig_struct *dig_t = &dm->dm_dig_table;
774
775
if (phydm_edcca_abort(dm))
776
return;
777
778
#if (DM_ODM_SUPPORT_TYPE == ODM_WIN)
779
phydm_check_adaptivity(dm); /*@Check adaptivity enable*/
780
#endif
781
782
PHYDM_DBG(dm, DBG_ADPTVTY, "%s ====>\n", __func__);
783
PHYDM_DBG(dm, DBG_ADPTVTY, "mode = %s, debug_mode = %d\n",
784
(*dm->edcca_mode ?
785
(dm->carrier_sense_enable ?
786
"CARRIER SENSE" :
787
"ADAPTIVITY") :
788
"NORMAL"),
789
adapt->debug_mode);
790
791
if (dm->support_ic_type & ODM_IC_JGR3_SERIES)
792
phydm_edcca_thre_calc_jgr3(dm);
793
else
794
phydm_edcca_thre_calc(dm);
795
796
if (*dm->edcca_mode == PHYDM_EDCCA_ADAPT_MODE)
797
PHYDM_DBG(dm, DBG_ADPTVTY,
798
"th_l2h_ini = %d, th_edcca_hl_diff = %d\n",
799
dm->th_l2h_ini, dm->th_edcca_hl_diff);
800
if (dm->support_ic_type & ODM_IC_PWDB_EDCCA)
801
PHYDM_DBG(dm, DBG_ADPTVTY,
802
"IGI = 0x%x, th_l2h = %d dBm, th_h2l = %d dBm\n",
803
dig_t->cur_ig_value,
804
IGI_2_DBM(adapt->th_l2h + dig_t->cur_ig_value),
805
IGI_2_DBM(adapt->th_h2l + dig_t->cur_ig_value));
806
else
807
PHYDM_DBG(dm, DBG_ADPTVTY,
808
"IGI = 0x%x, th_l2h = %d dBm, th_h2l = %d dBm\n",
809
dig_t->cur_ig_value,
810
IGI_2_DBM(adapt->th_l2h),
811
IGI_2_DBM(adapt->th_h2l));
812
#endif
813
}
814
815
816