Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/core/rtw_rm_util.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2007 - 2019 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
*****************************************************************************/
15
16
#include <drv_types.h>
17
#include <hal_data.h>
18
#ifdef CONFIG_RTW_80211K
19
#include "rtw_rm_fsm.h"
20
#include "rtw_rm_util.h"
21
22
/* 802.11-2012 Table E-1 Operationg classes in United States */
23
static RT_OPERATING_CLASS RTW_OP_CLASS_US[] = {
24
/* 0, OP_CLASS_NULL */ { 0, 0, {}},
25
/* 1, OP_CLASS_1 */ {115, 4, {36, 40, 44, 48}},
26
/* 2, OP_CLASS_2 */ {118, 4, {52, 56, 60, 64}},
27
/* 3, OP_CLASS_3 */ {124, 4, {149, 153, 157, 161}},
28
/* 4, OP_CLASS_4 */ {121, 11, {100, 104, 108, 112, 116, 120, 124,
29
128, 132, 136, 140}},
30
/* 5, OP_CLASS_5 */ {125, 5, {149, 153, 157, 161, 165}},
31
/* 6, OP_CLASS_12 */ { 81, 11, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}
32
};
33
34
u8 rm_get_ch_set(
35
struct rtw_ieee80211_channel *pch_set, u8 op_class, u8 ch_num)
36
{
37
int i,j,sz;
38
u8 ch_amount = 0;
39
40
41
sz = sizeof(RTW_OP_CLASS_US)/sizeof(struct _RT_OPERATING_CLASS);
42
43
if (ch_num != 0) {
44
pch_set[0].hw_value = ch_num;
45
ch_amount = 1;
46
RTW_INFO("RM: meas_ch->hw_value = %u\n", pch_set->hw_value);
47
goto done;
48
}
49
50
for (i = 0; i < sz; i++) {
51
52
if (RTW_OP_CLASS_US[i].global_op_class == op_class) {
53
54
for (j = 0; j < RTW_OP_CLASS_US[i].Len; j++) {
55
pch_set[j].hw_value =
56
RTW_OP_CLASS_US[i].Channel[j];
57
RTW_INFO("RM: meas_ch[%d].hw_value = %u\n",
58
j, pch_set[j].hw_value);
59
}
60
ch_amount = RTW_OP_CLASS_US[i].Len;
61
break;
62
}
63
}
64
done:
65
return ch_amount;
66
}
67
68
u8 rm_get_oper_class_via_ch(u8 ch)
69
{
70
int i,j,sz;
71
72
73
sz = sizeof(RTW_OP_CLASS_US)/sizeof(struct _RT_OPERATING_CLASS);
74
75
for (i = 0; i < sz; i++) {
76
for (j = 0; j < RTW_OP_CLASS_US[i].Len; j++) {
77
if ( ch == RTW_OP_CLASS_US[i].Channel[j]) {
78
RTW_INFO("RM: ch %u in oper_calss %u\n",
79
ch, RTW_OP_CLASS_US[i].global_op_class);
80
return RTW_OP_CLASS_US[i].global_op_class;
81
break;
82
}
83
}
84
}
85
return 0;
86
}
87
88
int is_wildcard_bssid(u8 *bssid)
89
{
90
int i;
91
u8 val8 = 0xff;
92
93
94
for (i=0;i<6;i++)
95
val8 &= bssid[i];
96
97
if (val8 == 0xff)
98
return _SUCCESS;
99
return _FALSE;
100
}
101
102
u8 translate_dbm_to_rcpi(s8 SignalPower)
103
{
104
/* RCPI = Int{(Power in dBm + 110)*2} for 0dBm > Power > -110dBm
105
* 0 : power <= -110.0 dBm
106
* 1 : power = -109.5 dBm
107
* 2 : power = -109.0 dBm
108
*/
109
return (SignalPower + 110)*2;
110
}
111
112
u8 translate_percentage_to_rcpi(u32 SignalStrengthIndex)
113
{
114
/* Translate to dBm (x=y-100) */
115
return translate_dbm_to_rcpi(SignalStrengthIndex - 100);
116
}
117
118
u8 rm_get_bcn_rcpi(struct rm_obj *prm, struct wlan_network *pnetwork)
119
{
120
return translate_percentage_to_rcpi(
121
pnetwork->network.PhyInfo.SignalStrength);
122
}
123
124
u8 rm_get_frame_rsni(struct rm_obj *prm, union recv_frame *pframe)
125
{
126
int i;
127
u8 val8, snr;
128
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(prm->psta->padapter);
129
130
if (IS_CCK_RATE((hw_rate_to_m_rate(pframe->u.hdr.attrib.data_rate))))
131
val8 = 255;
132
else {
133
snr = 0;
134
for (i = 0; i < pHalData->NumTotalRFPath; i++)
135
snr += pframe->u.hdr.attrib.phy_info.rx_snr[i];
136
snr = snr / pHalData->NumTotalRFPath;
137
val8 = (u8)(snr + 10)*2;
138
}
139
return val8;
140
}
141
142
u8 rm_get_bcn_rsni(struct rm_obj *prm, struct wlan_network *pnetwork)
143
{
144
int i;
145
u8 val8, snr;
146
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(prm->psta->padapter);
147
148
149
if (pnetwork->network.PhyInfo.is_cck_rate) {
150
/* current HW doesn't have CCK RSNI */
151
/* 255 indicates RSNI is unavailable */
152
val8 = 255;
153
} else {
154
snr = 0;
155
for (i = 0; i < pHalData->NumTotalRFPath; i++) {
156
snr += pnetwork->network.PhyInfo.rx_snr[i];
157
}
158
snr = snr / pHalData->NumTotalRFPath;
159
val8 = (u8)(snr + 10)*2;
160
}
161
return val8;
162
}
163
164
char *get_rate_name(enum MGN_RATE rate)
165
{
166
switch(rate) {
167
case MGN_1M:
168
return "CCK_1M";
169
break;
170
case MGN_2M:
171
return "CCK_2M";
172
break;
173
case MGN_5_5M:
174
return "CCK_5.5M";
175
break;
176
case MGN_11M:
177
return "CCK_11M";
178
break;
179
case MGN_6M:
180
return "OFDM_6M";
181
break;
182
case MGN_9M:
183
return "OFDM_9M";
184
break;
185
case MGN_12M:
186
return "OFDM_12M";
187
break;
188
case MGN_18M:
189
return "OFDM_18M";
190
break;
191
case MGN_24M:
192
return "OFDM_24M";
193
break;
194
case MGN_36M:
195
return "OFDM_36M";
196
break;
197
case MGN_48M:
198
return "OFDM_48M";
199
break;
200
case MGN_54M:
201
return "OFDM_54M";
202
break;
203
case MGN_MCS0:
204
return "HT_MCS0";
205
break;
206
case MGN_MCS8:
207
return "HT_MCS8";
208
break;
209
case MGN_MCS16:
210
return "HT_MCS16";
211
break;
212
case MGN_MCS24:
213
return "HT_MCS24";
214
break;
215
case MGN_MCS32:
216
return "HT_MCS32";
217
break;
218
case MGN_MCS1:
219
return "HT_MCS1";
220
break;
221
case MGN_MCS9:
222
return "HT_MCS9";
223
break;
224
case MGN_MCS17:
225
return "HT_MCS17";
226
break;
227
case MGN_MCS25:
228
return "HT_MCS25";
229
break;
230
case MGN_MCS2:
231
return "HT_MCS2";
232
break;
233
case MGN_MCS10:
234
return "HT_MCS10";
235
break;
236
case MGN_MCS18:
237
return "HT_MCS18";
238
break;
239
case MGN_MCS26:
240
return "HT_MCS26";
241
break;
242
case MGN_MCS3:
243
return "HT_MCS3";
244
break;
245
case MGN_MCS11:
246
return "HT_MCS11";
247
break;
248
case MGN_MCS19:
249
return "HT_MCS19";
250
break;
251
case MGN_MCS27:
252
return "HT_MCS27";
253
break;
254
case MGN_MCS4:
255
return "HT_MCS4";
256
break;
257
case MGN_MCS12:
258
return "HT_MCS12";
259
break;
260
case MGN_MCS20:
261
return "HT_MCS20";
262
break;
263
case MGN_MCS28:
264
return "HT_MCS28";
265
break;
266
case MGN_MCS5:
267
return "HT_MCS5";
268
break;
269
case MGN_MCS13:
270
return "HT_MCS13";
271
break;
272
case MGN_MCS21:
273
return "HT_MCS21";
274
break;
275
case MGN_MCS29:
276
return "HT_MCS29";
277
break;
278
case MGN_MCS6:
279
return "HT_MCS6";
280
break;
281
case MGN_MCS14:
282
return "HT_MCS14";
283
break;
284
case MGN_MCS22:
285
return "HT_MCS22";
286
break;
287
case MGN_MCS30:
288
return "HT_MCS30";
289
break;
290
case MGN_MCS7:
291
return "HT_MCS7";
292
break;
293
case MGN_MCS15:
294
return "HT_MCS15";
295
break;
296
case MGN_MCS23:
297
return "HT_MCS23";
298
break;
299
case MGN_MCS31:
300
return "HT_MCS31";
301
break;
302
case MGN_VHT1SS_MCS0:
303
return "VHT1SS_MCS0";
304
break;
305
case MGN_VHT2SS_MCS0:
306
return "VHT2SS_MCS0";
307
break;
308
case MGN_VHT3SS_MCS0:
309
return "VHT3SS_MCS0";
310
break;
311
case MGN_VHT4SS_MCS0:
312
return "VHT4SS_MCS0";
313
break;
314
case MGN_VHT1SS_MCS1:
315
return "VHT1SS_MCS1";
316
break;
317
case MGN_VHT2SS_MCS1:
318
return "VHT2SS_MCS1";
319
break;
320
case MGN_VHT3SS_MCS1:
321
return "VHT3SS_MCS1";
322
break;
323
case MGN_VHT4SS_MCS1:
324
return "VHT4SS_MCS1";
325
break;
326
case MGN_VHT1SS_MCS2:
327
return "VHT1SS_MCS2";
328
break;
329
case MGN_VHT2SS_MCS2:
330
return "VHT2SS_MCS2";
331
break;
332
case MGN_VHT3SS_MCS2:
333
return "VHT3SS_MCS2";
334
break;
335
case MGN_VHT4SS_MCS2:
336
return "VHT4SS_MCS2";
337
break;
338
case MGN_VHT1SS_MCS3:
339
return "VHT1SS_MCS3";
340
break;
341
case MGN_VHT2SS_MCS3:
342
return "VHT2SS_MCS3";
343
break;
344
case MGN_VHT3SS_MCS3:
345
return "VHT3SS_MCS3";
346
break;
347
case MGN_VHT4SS_MCS3:
348
return "VHT4SS_MCS3";
349
break;
350
case MGN_VHT1SS_MCS4:
351
return "VHT1SS_MCS4";
352
break;
353
case MGN_VHT2SS_MCS4:
354
return "VHT2SS_MCS4";
355
break;
356
case MGN_VHT3SS_MCS4:
357
return "VHT3SS_MCS4";
358
break;
359
case MGN_VHT4SS_MCS4:
360
return "VHT4SS_MCS4";
361
break;
362
case MGN_VHT1SS_MCS5:
363
return "VHT1SS_MCS5";
364
break;
365
case MGN_VHT2SS_MCS5:
366
return "VHT2SS_MCS5";
367
break;
368
case MGN_VHT3SS_MCS5:
369
return "VHT3SS_MCS5";
370
break;
371
case MGN_VHT4SS_MCS5:
372
return "VHT4SS_MCS5";
373
break;
374
case MGN_VHT1SS_MCS6:
375
return "VHT1SS_MCS6";
376
break;
377
case MGN_VHT2SS_MCS6:
378
return "VHT2SS_MCS6";
379
break;
380
case MGN_VHT3SS_MCS6:
381
return "VHT3SS_MCS6";
382
break;
383
case MGN_VHT4SS_MCS6:
384
return "VHT4SS_MCS6";
385
break;
386
case MGN_VHT1SS_MCS7:
387
return "VHT1SS_MCS7";
388
break;
389
case MGN_VHT2SS_MCS7:
390
return "VHT2SS_MCS7";
391
break;
392
case MGN_VHT3SS_MCS7:
393
return "VHT3SS_MCS7";
394
break;
395
case MGN_VHT4SS_MCS7:
396
return "VHT4SS_MCS7";
397
break;
398
case MGN_VHT1SS_MCS8:
399
return "VHT1SS_MCS8";
400
break;
401
case MGN_VHT2SS_MCS8:
402
return "VHT2SS_MCS8";
403
break;
404
case MGN_VHT3SS_MCS8:
405
return "VHT3SS_MCS8";
406
break;
407
case MGN_VHT4SS_MCS8:
408
return "VHT4SS_MCS8";
409
break;
410
case MGN_VHT1SS_MCS9:
411
return "VHT1SS_MCS9";
412
break;
413
case MGN_VHT2SS_MCS9:
414
return "VHT2SS_MCS9";
415
break;
416
case MGN_VHT3SS_MCS9:
417
return "VHT3SS_MCS9";
418
break;
419
case MGN_VHT4SS_MCS9:
420
return "VHT4SS_MCS9";
421
break;
422
default:
423
break;
424
425
}
426
return "UNKNOWN";
427
}
428
429
static int get_rate_index(enum MGN_RATE rate)
430
{
431
int rate_num = -1;
432
433
switch(rate) {
434
case MGN_1M:
435
rate_num = 0;
436
break;
437
case MGN_2M:
438
rate_num = 1;
439
break;
440
case MGN_5_5M:
441
rate_num = 2;
442
break;
443
case MGN_11M:
444
rate_num = 3;
445
break;
446
case MGN_6M:
447
rate_num = 0;
448
break;
449
case MGN_9M:
450
rate_num = 1;
451
break;
452
case MGN_12M:
453
rate_num = 2;
454
break;
455
case MGN_18M:
456
rate_num = 3;
457
break;
458
case MGN_24M:
459
rate_num = 4;
460
break;
461
case MGN_36M:
462
rate_num = 5;
463
break;
464
case MGN_48M:
465
rate_num = 6;
466
break;
467
case MGN_54M:
468
rate_num = 7;
469
break;
470
case MGN_MCS0:
471
case MGN_MCS8:
472
case MGN_MCS16:
473
case MGN_MCS24:
474
case MGN_MCS32:
475
rate_num = 0;
476
break;
477
case MGN_MCS1:
478
case MGN_MCS9:
479
case MGN_MCS17:
480
case MGN_MCS25:
481
rate_num = 1;
482
break;
483
case MGN_MCS2:
484
case MGN_MCS10:
485
case MGN_MCS18:
486
case MGN_MCS26:
487
rate_num = 2;
488
break;
489
case MGN_MCS3:
490
case MGN_MCS11:
491
case MGN_MCS19:
492
case MGN_MCS27:
493
rate_num = 3;
494
break;
495
case MGN_MCS4:
496
case MGN_MCS12:
497
case MGN_MCS20:
498
case MGN_MCS28:
499
rate_num = 4;
500
break;
501
case MGN_MCS5:
502
case MGN_MCS13:
503
case MGN_MCS21:
504
case MGN_MCS29:
505
rate_num = 5;
506
break;
507
case MGN_MCS6:
508
case MGN_MCS14:
509
case MGN_MCS22:
510
case MGN_MCS30:
511
rate_num = 6;
512
break;
513
case MGN_MCS7:
514
case MGN_MCS15:
515
case MGN_MCS23:
516
case MGN_MCS31:
517
rate_num = 7;
518
break;
519
case MGN_VHT1SS_MCS0:
520
case MGN_VHT2SS_MCS0:
521
case MGN_VHT3SS_MCS0:
522
case MGN_VHT4SS_MCS0:
523
rate_num = 0;
524
break;
525
case MGN_VHT1SS_MCS1:
526
case MGN_VHT2SS_MCS1:
527
case MGN_VHT3SS_MCS1:
528
case MGN_VHT4SS_MCS1:
529
rate_num = 1;
530
break;
531
case MGN_VHT1SS_MCS2:
532
case MGN_VHT2SS_MCS2:
533
case MGN_VHT3SS_MCS2:
534
case MGN_VHT4SS_MCS2:
535
rate_num = 2;
536
break;
537
case MGN_VHT1SS_MCS3:
538
case MGN_VHT2SS_MCS3:
539
case MGN_VHT3SS_MCS3:
540
case MGN_VHT4SS_MCS3:
541
rate_num = 3;
542
break;
543
case MGN_VHT1SS_MCS4:
544
case MGN_VHT2SS_MCS4:
545
case MGN_VHT3SS_MCS4:
546
case MGN_VHT4SS_MCS4:
547
rate_num = 4;
548
break;
549
case MGN_VHT1SS_MCS5:
550
case MGN_VHT2SS_MCS5:
551
case MGN_VHT3SS_MCS5:
552
case MGN_VHT4SS_MCS5:
553
rate_num = 5;
554
break;
555
case MGN_VHT1SS_MCS6:
556
case MGN_VHT2SS_MCS6:
557
case MGN_VHT3SS_MCS6:
558
case MGN_VHT4SS_MCS6:
559
rate_num = 6;
560
break;
561
case MGN_VHT1SS_MCS7:
562
case MGN_VHT2SS_MCS7:
563
case MGN_VHT3SS_MCS7:
564
case MGN_VHT4SS_MCS7:
565
rate_num = 7;
566
break;
567
case MGN_VHT1SS_MCS8:
568
case MGN_VHT2SS_MCS8:
569
case MGN_VHT3SS_MCS8:
570
case MGN_VHT4SS_MCS8:
571
rate_num = 8;
572
break;
573
case MGN_VHT1SS_MCS9:
574
case MGN_VHT2SS_MCS9:
575
case MGN_VHT3SS_MCS9:
576
case MGN_VHT4SS_MCS9:
577
rate_num = 9;
578
break;
579
default:
580
break;
581
582
}
583
return rate_num;
584
}
585
586
/* output: pwr (unit dBm) */
587
int rm_get_tx_power(PADAPTER adapter, enum rf_path path, enum MGN_RATE rate, s8 *pwr)
588
{
589
struct hal_spec_t *hal_spec = GET_HAL_SPEC(adapter);
590
HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
591
int tx_num, band, bw, ch, n, rs;
592
u8 base;
593
s8 limt_offset = 127; /* max value of s8 */
594
s8 rate_offset;
595
s8 powr_offset;
596
int rate_pos;
597
598
599
band = hal_data->current_band_type;
600
bw = hal_data->current_channel_bw;
601
ch = hal_data->current_channel;
602
603
if (!HAL_SPEC_CHK_RF_PATH(hal_spec, band, path))
604
return -1;
605
606
if (HAL_IsLegalChannel(adapter, ch) == _FALSE) {
607
RTW_INFO("Illegal channel!!\n");
608
return -2;
609
}
610
611
/* find rs by rate */
612
if (IS_CCK_RATE(rate))
613
rs = CCK;
614
else if (IS_OFDM_RATE(rate))
615
rs = OFDM;
616
else if (IS_HT1SS_RATE(rate))
617
rs = HT_1SS;
618
else if (IS_HT2SS_RATE(rate))
619
rs = HT_2SS;
620
else if (IS_HT3SS_RATE(rate))
621
rs = HT_3SS;
622
else if (IS_HT4SS_RATE(rate))
623
rs = HT_4SS;
624
else if (IS_VHT1SS_RATE(rate))
625
rs = VHT_1SS;
626
else if (IS_VHT2SS_RATE(rate))
627
rs = VHT_2SS;
628
else if (IS_VHT3SS_RATE(rate))
629
rs = VHT_3SS;
630
else if (IS_VHT4SS_RATE(rate))
631
rs = VHT_4SS;
632
else
633
return -3;
634
635
tx_num = rate_section_to_tx_num(rs);
636
637
if (tx_num >= hal_spec->tx_nss_num)
638
return -4;
639
640
if (band == BAND_ON_5G && IS_CCK_RATE_SECTION(rs))
641
return -5;
642
643
if (IS_VHT_RATE_SECTION(rs) && !IS_HARDWARE_TYPE_JAGUAR_ALL(adapter))
644
return -6;
645
646
base = PHY_GetTxPowerByRateBase(adapter, band, path, rs);
647
648
/* get power by rate in db */
649
rate_pos = get_rate_index(rate);
650
if (rate_pos < 0)
651
return -7;
652
653
rate_offset = PHY_GetTxPowerByRate(adapter, band, path,
654
rates_by_sections[rs].rates[rate_pos]);
655
#ifdef CONFIG_TXPWR_LIMIT
656
limt_offset = PHY_GetTxPowerLimit(adapter, NULL, band, bw,
657
path, rates_by_sections[rs].rates[rate_pos], RF_1TX, ch);
658
#endif
659
powr_offset = MIN(rate_offset, limt_offset);
660
661
*pwr = (base + powr_offset) / hal_spec->txgi_pdbm;
662
#if (RM_MORE_DBG_MSG)
663
RTW_INFO("RM: [%s][path_%c] %s base=%d offset=min(%d|%d)=%d (%d,%d)\n",
664
band_str(band), rf_path_char(path),
665
MGN_RATE_STR(rate),base, rate_offset, limt_offset,
666
powr_offset, ((base + rate_offset) / hal_spec->txgi_pdbm), *pwr);
667
#endif
668
return 0;
669
}
670
671
int rm_get_rx_sensitivity(PADAPTER adapter, enum channel_width bw, enum MGN_RATE rate, s8 *pwr)
672
{
673
s8 rx_sensitivity = -110;
674
675
switch(rate) {
676
case MGN_1M:
677
rx_sensitivity= -101;
678
break;
679
case MGN_2M:
680
rx_sensitivity= -98;
681
break;
682
case MGN_5_5M:
683
rx_sensitivity= -92;
684
break;
685
case MGN_11M:
686
rx_sensitivity= -89;
687
break;
688
case MGN_6M:
689
case MGN_9M:
690
case MGN_12M:
691
rx_sensitivity = -92;
692
break;
693
case MGN_18M:
694
rx_sensitivity = -90;
695
break;
696
case MGN_24M:
697
rx_sensitivity = -88;
698
break;
699
case MGN_36M:
700
rx_sensitivity = -84;
701
break;
702
case MGN_48M:
703
rx_sensitivity = -79;
704
break;
705
case MGN_54M:
706
rx_sensitivity = -78;
707
break;
708
709
case MGN_MCS0:
710
case MGN_MCS8:
711
case MGN_MCS16:
712
case MGN_MCS24:
713
case MGN_VHT1SS_MCS0:
714
case MGN_VHT2SS_MCS0:
715
case MGN_VHT3SS_MCS0:
716
case MGN_VHT4SS_MCS0:
717
/* BW20 BPSK 1/2 */
718
rx_sensitivity = -82;
719
break;
720
721
case MGN_MCS1:
722
case MGN_MCS9:
723
case MGN_MCS17:
724
case MGN_MCS25:
725
case MGN_VHT1SS_MCS1:
726
case MGN_VHT2SS_MCS1:
727
case MGN_VHT3SS_MCS1:
728
case MGN_VHT4SS_MCS1:
729
/* BW20 QPSK 1/2 */
730
rx_sensitivity = -79;
731
break;
732
733
case MGN_MCS2:
734
case MGN_MCS10:
735
case MGN_MCS18:
736
case MGN_MCS26:
737
case MGN_VHT1SS_MCS2:
738
case MGN_VHT2SS_MCS2:
739
case MGN_VHT3SS_MCS2:
740
case MGN_VHT4SS_MCS2:
741
/* BW20 QPSK 3/4 */
742
rx_sensitivity = -77;
743
break;
744
745
case MGN_MCS3:
746
case MGN_MCS11:
747
case MGN_MCS19:
748
case MGN_MCS27:
749
case MGN_VHT1SS_MCS3:
750
case MGN_VHT2SS_MCS3:
751
case MGN_VHT3SS_MCS3:
752
case MGN_VHT4SS_MCS3:
753
/* BW20 16-QAM 1/2 */
754
rx_sensitivity = -74;
755
break;
756
757
case MGN_MCS4:
758
case MGN_MCS12:
759
case MGN_MCS20:
760
case MGN_MCS28:
761
case MGN_VHT1SS_MCS4:
762
case MGN_VHT2SS_MCS4:
763
case MGN_VHT3SS_MCS4:
764
case MGN_VHT4SS_MCS4:
765
/* BW20 16-QAM 3/4 */
766
rx_sensitivity = -70;
767
break;
768
769
case MGN_MCS5:
770
case MGN_MCS13:
771
case MGN_MCS21:
772
case MGN_MCS29:
773
case MGN_VHT1SS_MCS5:
774
case MGN_VHT2SS_MCS5:
775
case MGN_VHT3SS_MCS5:
776
case MGN_VHT4SS_MCS5:
777
/* BW20 64-QAM 2/3 */
778
rx_sensitivity = -66;
779
break;
780
781
case MGN_MCS6:
782
case MGN_MCS14:
783
case MGN_MCS22:
784
case MGN_MCS30:
785
case MGN_VHT1SS_MCS6:
786
case MGN_VHT2SS_MCS6:
787
case MGN_VHT3SS_MCS6:
788
case MGN_VHT4SS_MCS6:
789
/* BW20 64-QAM 3/4 */
790
rx_sensitivity = -65;
791
break;
792
793
case MGN_MCS7:
794
case MGN_MCS15:
795
case MGN_MCS23:
796
case MGN_MCS31:
797
case MGN_VHT1SS_MCS7:
798
case MGN_VHT2SS_MCS7:
799
case MGN_VHT3SS_MCS7:
800
case MGN_VHT4SS_MCS7:
801
/* BW20 64-QAM 5/6 */
802
rx_sensitivity = -64;
803
break;
804
805
case MGN_VHT1SS_MCS8:
806
case MGN_VHT2SS_MCS8:
807
case MGN_VHT3SS_MCS8:
808
case MGN_VHT4SS_MCS8:
809
/* BW20 256-QAM 3/4 */
810
rx_sensitivity = -59;
811
break;
812
813
case MGN_VHT1SS_MCS9:
814
case MGN_VHT2SS_MCS9:
815
case MGN_VHT3SS_MCS9:
816
case MGN_VHT4SS_MCS9:
817
/* BW20 256-QAM 5/6 */
818
rx_sensitivity = -57;
819
break;
820
821
default:
822
return -1;
823
break;
824
825
}
826
827
switch(bw) {
828
case CHANNEL_WIDTH_20:
829
break;
830
case CHANNEL_WIDTH_40:
831
rx_sensitivity -= 3;
832
break;
833
case CHANNEL_WIDTH_80:
834
rx_sensitivity -= 6;
835
break;
836
case CHANNEL_WIDTH_160:
837
rx_sensitivity -= 9;
838
break;
839
case CHANNEL_WIDTH_5:
840
case CHANNEL_WIDTH_10:
841
case CHANNEL_WIDTH_80_80:
842
default:
843
return -1;
844
break;
845
}
846
*pwr = rx_sensitivity;
847
848
return 0;
849
}
850
851
/* output: path_a max tx power in dBm */
852
int rm_get_path_a_max_tx_power(_adapter *adapter, s8 *path_a)
853
{
854
struct hal_spec_t *hal_spec = GET_HAL_SPEC(adapter);
855
HAL_DATA_TYPE *hal_data = GET_HAL_DATA(adapter);
856
int path, tx_num, band, bw, ch, n, rs;
857
u8 rate_num, base;
858
s8 limt_offset = 127; /* max value of s8 */
859
s8 rate_offset;
860
s8 powr_offset;
861
s8 max_pwr[RF_PATH_MAX], pwr;
862
863
864
band = hal_data->current_band_type;
865
bw = hal_data->current_channel_bw;
866
ch = hal_data->current_channel;
867
868
for (path = 0; path < RF_PATH_MAX; path++) {
869
if (!HAL_SPEC_CHK_RF_PATH(hal_spec, band, path))
870
break;
871
872
max_pwr[path] = -127; /* min value of s8 */
873
#if (RM_MORE_DBG_MSG)
874
RTW_INFO("RM: [%s][%c]\n", band_str(band), rf_path_char(path));
875
#endif
876
for (rs = 0; rs < RATE_SECTION_NUM; rs++) {
877
tx_num = rate_section_to_tx_num(rs);
878
879
if (tx_num >= hal_spec->tx_nss_num)
880
continue;
881
882
if (band == BAND_ON_5G && IS_CCK_RATE_SECTION(rs))
883
continue;
884
885
if (IS_VHT_RATE_SECTION(rs) && !IS_HARDWARE_TYPE_JAGUAR_ALL(adapter))
886
continue;
887
888
rate_num = rate_section_rate_num(rs);
889
base = PHY_GetTxPowerByRateBase(adapter, band, path, rs);
890
891
/* get power by rate in db */
892
for (n = rate_num - 1; n >= 0; n--) {
893
rate_offset = PHY_GetTxPowerByRate(adapter, band,
894
path, rates_by_sections[rs].rates[n]);
895
#ifdef CONFIG_TXPWR_LIMIT
896
limt_offset = PHY_GetTxPowerLimit(adapter, NULL, band, bw,
897
path, rates_by_sections[rs].rates[n], RF_1TX, ch);
898
#endif
899
powr_offset = MIN(rate_offset, limt_offset);
900
pwr = (base + powr_offset) / hal_spec->txgi_pdbm;
901
max_pwr[path] = MAX(max_pwr[path], pwr);
902
#if (RM_MORE_DBG_MSG)
903
RTW_INFO("RM: %2d base=%7s(%2d), min(%2d|%2d)=%2d; (%2d,%2d)\n",
904
n, rate_section_str(rs), base,
905
rate_offset, limt_offset, powr_offset,
906
((base + rate_offset) / hal_spec->txgi_pdbm), pwr);
907
#endif
908
}
909
}
910
}
911
#if (RM_MORE_DBG_MSG)
912
RTW_INFO("RM: path_a max_pwr=%ddBm\n", max_pwr[0]);
913
#endif
914
*path_a = max_pwr[0];
915
return 0;
916
}
917
918
#endif /* CONFIG_RTW_80211K */
919
920