1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2016 Realtek Corporation.
7 * wlanfae <wlanfae@realtek.com>
8 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
11 * Larry Finger <Larry.Finger@lwfinger.net>
13 *****************************************************************************/
15 /* ************************************************************
17 * *************************************************************/
19 #include "mp_precomp.h"
20 #include "phydm_precomp.h"
22 #define READ_AND_CONFIG_MP(ic, txt) (odm_read_and_config_mp_##ic##txt(dm))
23 #define READ_AND_CONFIG_TC(ic, txt) (odm_read_and_config_tc_##ic##txt(dm))
25 #define READ_AND_CONFIG READ_AND_CONFIG_MP
27 #define READ_FIRMWARE_MP(ic, txt) \
28 (odm_read_firmware_mp_##ic##txt(dm, p_firmware, size))
29 #define READ_FIRMWARE_TC(ic, txt) \
30 (odm_read_firmware_tc_##ic##txt(dm, p_firmware, size))
32 #define READ_FIRMWARE READ_FIRMWARE_MP
34 #define GET_VERSION_MP(ic, txt) (odm_get_version_mp_##ic##txt())
35 #define GET_VERSION_TC(ic, txt) (odm_get_version_tc_##ic##txt())
37 #define GET_VERSION(ic, txt) GET_VERSION_MP(ic, txt)
39 static u32 phydm_process_rssi_pwdb(struct phy_dm_struct *dm,
40 struct rtl_sta_info *entry,
41 struct dm_per_pkt_info *pktinfo,
42 u32 undecorated_smoothed_ofdm,
43 u32 undecorated_smoothed_cck)
45 u32 weighting = 0, undecorated_smoothed_pwdb;
46 /* 2011.07.28 LukeLee: modified to prevent unstable CCK RSSI */
48 if (entry->rssi_stat.ofdm_pkt ==
49 64) { /* speed up when all packets are OFDM*/
50 undecorated_smoothed_pwdb = undecorated_smoothed_ofdm;
51 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
52 "PWDB_0[%d] = (( %d ))\n", pktinfo->station_id,
53 undecorated_smoothed_cck);
55 if (entry->rssi_stat.valid_bit < 64)
56 entry->rssi_stat.valid_bit++;
58 if (entry->rssi_stat.valid_bit == 64) {
59 weighting = ((entry->rssi_stat.ofdm_pkt) > 4) ?
61 (entry->rssi_stat.ofdm_pkt << 4);
62 undecorated_smoothed_pwdb =
63 (weighting * undecorated_smoothed_ofdm +
64 (64 - weighting) * undecorated_smoothed_cck) >>
66 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
67 "PWDB_1[%d] = (( %d )), W = (( %d ))\n",
69 undecorated_smoothed_cck, weighting);
71 if (entry->rssi_stat.valid_bit != 0)
72 undecorated_smoothed_pwdb =
73 (entry->rssi_stat.ofdm_pkt *
74 undecorated_smoothed_ofdm +
75 (entry->rssi_stat.valid_bit -
76 entry->rssi_stat.ofdm_pkt) *
77 undecorated_smoothed_cck) /
78 entry->rssi_stat.valid_bit;
80 undecorated_smoothed_pwdb = 0;
83 dm, ODM_COMP_RSSI_MONITOR,
84 "PWDB_2[%d] = (( %d )), ofdm_pkt = (( %d )), Valid_Bit = (( %d ))\n",
85 pktinfo->station_id, undecorated_smoothed_cck,
86 entry->rssi_stat.ofdm_pkt,
87 entry->rssi_stat.valid_bit);
91 return undecorated_smoothed_pwdb;
94 static u32 phydm_process_rssi_cck(struct phy_dm_struct *dm,
95 struct dm_phy_status_info *phy_info,
96 struct rtl_sta_info *entry,
97 u32 undecorated_smoothed_cck)
102 rssi_ave = phy_info->rx_pwdb_all;
103 dm->rssi_a = (u8)phy_info->rx_pwdb_all;
108 if (entry->rssi_stat.cck_pkt <= 63)
109 entry->rssi_stat.cck_pkt++;
111 /* 1 Process CCK RSSI */
112 if (undecorated_smoothed_cck <= 0) { /* initialize */
113 undecorated_smoothed_cck = phy_info->rx_pwdb_all;
114 entry->rssi_stat.cck_sum_power =
115 (u16)phy_info->rx_pwdb_all; /*reset*/
116 entry->rssi_stat.cck_pkt = 1; /*reset*/
117 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR, "CCK_INIT: (( %d ))\n",
118 undecorated_smoothed_cck);
119 } else if (entry->rssi_stat.cck_pkt <= CCK_RSSI_INIT_COUNT) {
120 entry->rssi_stat.cck_sum_power =
121 entry->rssi_stat.cck_sum_power +
122 (u16)phy_info->rx_pwdb_all;
123 undecorated_smoothed_cck = entry->rssi_stat.cck_sum_power /
124 entry->rssi_stat.cck_pkt;
127 dm, ODM_COMP_RSSI_MONITOR,
128 "CCK_0: (( %d )), SumPow = (( %d )), cck_pkt = (( %d ))\n",
129 undecorated_smoothed_cck,
130 entry->rssi_stat.cck_sum_power,
131 entry->rssi_stat.cck_pkt);
133 if (phy_info->rx_pwdb_all > (u32)undecorated_smoothed_cck) {
134 undecorated_smoothed_cck =
135 (((undecorated_smoothed_cck) *
136 (RX_SMOOTH_FACTOR - 1)) +
137 (phy_info->rx_pwdb_all)) /
139 undecorated_smoothed_cck = undecorated_smoothed_cck + 1;
140 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
142 undecorated_smoothed_cck);
144 undecorated_smoothed_cck =
145 (((undecorated_smoothed_cck) *
146 (RX_SMOOTH_FACTOR - 1)) +
147 (phy_info->rx_pwdb_all)) /
149 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
151 undecorated_smoothed_cck);
156 entry->rssi_stat.ofdm_pkt -=
157 (u8)((entry->rssi_stat.packet_map >> i) & BIT(0));
158 entry->rssi_stat.packet_map = entry->rssi_stat.packet_map << 1;
159 return undecorated_smoothed_cck;
162 static u32 phydm_process_rssi_ofdm(struct phy_dm_struct *dm,
163 struct dm_phy_status_info *phy_info,
164 struct rtl_sta_info *entry,
165 u32 undecorated_smoothed_ofdm)
168 u8 rssi_max, rssi_min, i;
170 if (dm->support_ic_type & (ODM_RTL8814A | ODM_RTL8822B)) {
174 if (dm->rx_ant_status & ODM_RF_A) {
175 dm->rssi_a = phy_info->rx_mimo_signal_strength
178 rssi_linear += odm_convert_to_linear(
179 phy_info->rx_mimo_signal_strength
185 if (dm->rx_ant_status & ODM_RF_B) {
186 dm->rssi_b = phy_info->rx_mimo_signal_strength
189 rssi_linear += odm_convert_to_linear(
190 phy_info->rx_mimo_signal_strength
196 if (dm->rx_ant_status & ODM_RF_C) {
197 dm->rssi_c = phy_info->rx_mimo_signal_strength
200 rssi_linear += odm_convert_to_linear(
201 phy_info->rx_mimo_signal_strength
207 if (dm->rx_ant_status & ODM_RF_D) {
208 dm->rssi_d = phy_info->rx_mimo_signal_strength
211 rssi_linear += odm_convert_to_linear(
212 phy_info->rx_mimo_signal_strength
218 /* Calculate average RSSI */
221 rssi_linear = (rssi_linear >> 1);
224 /* rssi_linear/3 ~ rssi_linear*11/32 */
225 rssi_linear = ((rssi_linear) + (rssi_linear << 1) +
226 (rssi_linear << 3)) >>
230 rssi_linear = (rssi_linear >> 2);
234 rssi_ave = odm_convert_to_db(rssi_linear);
236 if (phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B] == 0) {
237 rssi_ave = phy_info->rx_mimo_signal_strength
239 dm->rssi_a = phy_info->rx_mimo_signal_strength
243 dm->rssi_a = phy_info->rx_mimo_signal_strength
245 dm->rssi_b = phy_info->rx_mimo_signal_strength
248 if (phy_info->rx_mimo_signal_strength[ODM_RF_PATH_A] >
249 phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B]) {
250 rssi_max = phy_info->rx_mimo_signal_strength
252 rssi_min = phy_info->rx_mimo_signal_strength
255 rssi_max = phy_info->rx_mimo_signal_strength
257 rssi_min = phy_info->rx_mimo_signal_strength
260 if ((rssi_max - rssi_min) < 3)
262 else if ((rssi_max - rssi_min) < 6)
263 rssi_ave = rssi_max - 1;
264 else if ((rssi_max - rssi_min) < 10)
265 rssi_ave = rssi_max - 2;
267 rssi_ave = rssi_max - 3;
271 /* 1 Process OFDM RSSI */
272 if (undecorated_smoothed_ofdm <= 0) { /* initialize */
273 undecorated_smoothed_ofdm = phy_info->rx_pwdb_all;
274 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR, "OFDM_INIT: (( %d ))\n",
275 undecorated_smoothed_ofdm);
277 if (phy_info->rx_pwdb_all > (u32)undecorated_smoothed_ofdm) {
278 undecorated_smoothed_ofdm =
279 (((undecorated_smoothed_ofdm) *
280 (RX_SMOOTH_FACTOR - 1)) +
283 undecorated_smoothed_ofdm =
284 undecorated_smoothed_ofdm + 1;
285 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
286 "OFDM_1: (( %d ))\n",
287 undecorated_smoothed_ofdm);
289 undecorated_smoothed_ofdm =
290 (((undecorated_smoothed_ofdm) *
291 (RX_SMOOTH_FACTOR - 1)) +
294 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
295 "OFDM_2: (( %d ))\n",
296 undecorated_smoothed_ofdm);
300 if (entry->rssi_stat.ofdm_pkt != 64) {
302 entry->rssi_stat.ofdm_pkt -=
303 (u8)(((entry->rssi_stat.packet_map >> i) & BIT(0)) - 1);
306 entry->rssi_stat.packet_map =
307 (entry->rssi_stat.packet_map << 1) | BIT(0);
308 return undecorated_smoothed_ofdm;
311 static u8 odm_evm_db_to_percentage(s8);
312 static u8 odm_evm_dbm_jaguar_series(s8);
314 static inline u32 phydm_get_rssi_average(struct phy_dm_struct *dm,
315 struct dm_phy_status_info *phy_info)
317 u8 rssi_max = 0, rssi_min = 0;
319 dm->rssi_a = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_A];
320 dm->rssi_b = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B];
322 if (phy_info->rx_mimo_signal_strength[ODM_RF_PATH_A] >
323 phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B]) {
324 rssi_max = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_A];
325 rssi_min = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B];
327 rssi_max = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B];
328 rssi_min = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_A];
330 if ((rssi_max - rssi_min) < 3)
332 else if ((rssi_max - rssi_min) < 6)
334 else if ((rssi_max - rssi_min) < 10)
340 static inline u8 phydm_get_evm_dbm(u8 i, u8 EVM,
341 struct phy_status_rpt_8812 *phy_sta_rpt,
342 struct dm_phy_status_info *phy_info)
344 if (i < ODM_RF_PATH_C)
345 return odm_evm_dbm_jaguar_series(phy_sta_rpt->rxevm[i]);
347 return odm_evm_dbm_jaguar_series(phy_sta_rpt->rxevm_cd[i - 2]);
348 /*RT_DISP(FRX, RX_PHY_SQ, ("RXRATE=%x RXEVM=%x EVM=%s%d\n",*/
349 /*pktinfo->data_rate, phy_sta_rpt->rxevm[i], "%", EVM));*/
352 static inline u8 phydm_get_odm_evm(u8 i, struct dm_per_pkt_info *pktinfo,
353 struct phy_status_rpt_8812 *phy_sta_rpt)
357 if (pktinfo->data_rate >= ODM_RATE6M &&
358 pktinfo->data_rate <= ODM_RATE54M) {
359 if (i == ODM_RF_PATH_A) {
360 evm = odm_evm_db_to_percentage(
361 (phy_sta_rpt->sigevm)); /*dbm*/
367 if (i < ODM_RF_PATH_C) {
368 if (phy_sta_rpt->rxevm[i] == -128)
369 phy_sta_rpt->rxevm[i] = -25;
370 evm = odm_evm_db_to_percentage(
371 (phy_sta_rpt->rxevm[i])); /*dbm*/
373 if (phy_sta_rpt->rxevm_cd[i - 2] == -128)
374 phy_sta_rpt->rxevm_cd[i - 2] = -25;
375 evm = odm_evm_db_to_percentage(
376 (phy_sta_rpt->rxevm_cd[i - 2])); /*dbm*/
383 static inline s8 phydm_get_rx_pwr(u8 LNA_idx, u8 VGA_idx, u8 cck_highpwr)
388 return -100 + 2 * (27 - VGA_idx); /*VGA_idx = 27~2*/
393 return -48 + 2 * (2 - VGA_idx); /*VGA_idx = 2~0*/
395 return -42 + 2 * (7 - VGA_idx); /*VGA_idx = 7~5*/
397 return -36 + 2 * (7 - VGA_idx); /*VGA_idx = 7~4*/
399 return -24 + 2 * (7 - VGA_idx); /*VGA_idx = 7~0*/
402 return -12 + 2 * (5 - VGA_idx); /*VGA_idx = 5~0*/
404 return -6 + 2 * (5 - VGA_idx);
407 return 8 - 2 * VGA_idx;
409 return 14 - 2 * VGA_idx;
416 static inline u8 phydm_adjust_pwdb(u8 cck_highpwr, u8 pwdb_all)
420 return ((pwdb_all - 80) << 1) + ((pwdb_all - 80) >> 1) +
422 else if ((pwdb_all <= 78) && (pwdb_all >= 20))
431 phydm_get_signal_quality_8812(struct dm_phy_status_info *phy_info,
432 struct phy_dm_struct *dm,
433 struct phy_status_rpt_8812 *phy_sta_rpt)
437 if (phy_info->rx_pwdb_all > 40 && !dm->is_in_hct_test)
440 sq_rpt = phy_sta_rpt->pwdb_all;
444 else if (sq_rpt < 20)
447 return ((64 - sq_rpt) * 100) / 44;
451 phydm_get_signal_quality_8192(struct dm_phy_status_info *phy_info,
452 struct phy_dm_struct *dm,
453 struct phy_status_rpt_8192cd *phy_sta_rpt)
457 if (phy_info->rx_pwdb_all > 40 && !dm->is_in_hct_test)
460 sq_rpt = phy_sta_rpt->cck_sig_qual_ofdm_pwdb_all;
464 else if (sq_rpt < 20)
467 return ((64 - sq_rpt) * 100) / 44;
470 static u8 odm_query_rx_pwr_percentage(s8 ant_power)
472 if ((ant_power <= -100) || (ant_power >= 20))
474 else if (ant_power >= 0)
477 return 100 + ant_power;
481 * 2012/01/12 MH MOve some signal strength smooth method to MP HAL layer.
482 * IF other SW team do not support the feature, remove this section.??
485 s32 odm_signal_scale_mapping(struct phy_dm_struct *dm, s32 curr_sig)
492 static u8 odm_sq_process_patch_rt_cid_819x_lenovo(struct phy_dm_struct *dm,
493 u8 is_cck_rate, u8 pwdb_all,
500 static u8 odm_evm_db_to_percentage(s8 value)
502 /* -33dB~0dB to 0%~99% */
514 ret_val = 0 - ret_val;
523 static u8 odm_evm_dbm_jaguar_series(s8 value)
527 /* -33dB~0dB to 33dB ~ 0dB */
530 else if (ret_val < 0)
531 ret_val = 0 - ret_val;
533 ret_val = ret_val >> 1;
537 static s16 odm_cfo(s8 value)
543 ret_val = (ret_val << 1) + (ret_val >> 1); /* *2.5~=312.5/2^7 */
545 ret_val | BIT(12); /* set bit12 as 1 for negative cfo */
548 ret_val = (ret_val << 1) + (ret_val >> 1); /* *2.5~=312.5/2^7 */
553 static u8 phydm_rate_to_num_ss(struct phy_dm_struct *dm, u8 data_rate)
557 if (data_rate <= ODM_RATE54M)
559 else if (data_rate <= ODM_RATEMCS31)
560 num_ss = ((data_rate - ODM_RATEMCS0) >> 3) + 1;
561 else if (data_rate <= ODM_RATEVHTSS1MCS9)
563 else if (data_rate <= ODM_RATEVHTSS2MCS9)
565 else if (data_rate <= ODM_RATEVHTSS3MCS9)
567 else if (data_rate <= ODM_RATEVHTSS4MCS9)
573 static void odm_rx_phy_status92c_series_parsing(
574 struct phy_dm_struct *dm, struct dm_phy_status_info *phy_info,
575 u8 *phy_status, struct dm_per_pkt_info *pktinfo)
577 u8 i, max_spatial_stream;
578 s8 rx_pwr[4], rx_pwr_all = 0;
579 u8 EVM, pwdb_all = 0, pwdb_all_bt;
580 u8 RSSI, total_rssi = 0;
581 bool is_cck_rate = false;
587 struct phy_status_rpt_8192cd *phy_sta_rpt =
588 (struct phy_status_rpt_8192cd *)phy_status;
590 is_cck_rate = (pktinfo->data_rate <= ODM_RATE11M) ? true : false;
592 if (pktinfo->is_to_self)
593 dm->curr_station_id = pktinfo->station_id;
595 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_A] = -1;
596 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_B] = -1;
599 dm->phy_dbg_info.num_qry_phy_status_cck++;
600 cck_agc_rpt = phy_sta_rpt->cck_agc_rpt_ofdm_cfosho_a;
602 if (dm->support_ic_type & (ODM_RTL8703B)) {
603 } else { /*3 bit LNA*/
605 LNA_idx = ((cck_agc_rpt & 0xE0) >> 5);
606 VGA_idx = (cck_agc_rpt & 0x1F);
610 dm, ODM_COMP_RSSI_MONITOR,
611 "ext_lna_gain (( %d )), LNA_idx: (( 0x%x )), VGA_idx: (( 0x%x )), rx_pwr_all: (( %d ))\n",
612 dm->ext_lna_gain, LNA_idx, VGA_idx, rx_pwr_all);
614 if (dm->board_type & ODM_BOARD_EXT_LNA)
615 rx_pwr_all -= dm->ext_lna_gain;
617 pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all);
619 if (pktinfo->is_to_self) {
620 dm->cck_lna_idx = LNA_idx;
621 dm->cck_vga_idx = VGA_idx;
623 phy_info->rx_pwdb_all = pwdb_all;
625 phy_info->bt_rx_rssi_percentage = pwdb_all;
626 phy_info->recv_signal_power = rx_pwr_all;
627 /* (3) Get Signal Quality (EVM) */
631 sq = phydm_get_signal_quality_8192(phy_info, dm,
633 phy_info->signal_quality = sq;
634 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_A] = sq;
635 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_B] = -1;
638 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX; i++) {
640 phy_info->rx_mimo_signal_strength[0] = pwdb_all;
642 phy_info->rx_mimo_signal_strength[1] = 0;
644 } else { /* 2 is OFDM rate */
645 dm->phy_dbg_info.num_qry_phy_status_ofdm++;
648 /* (1)Get RSSI for HT rate */
651 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX; i++) {
652 /* 2008/01/30 MH we will judge RF RX path now. */
653 if (dm->rf_path_rx_enable & BIT(i))
659 ((phy_sta_rpt->path_agc[i].gain & 0x3F) * 2) -
662 if (pktinfo->is_to_self) {
663 dm->ofdm_agc_idx[i] =
664 (phy_sta_rpt->path_agc[i].gain & 0x3F);
668 phy_info->rx_pwr[i] = rx_pwr[i];
670 /* Translate DBM to percentage. */
671 RSSI = odm_query_rx_pwr_percentage(rx_pwr[i]);
674 phy_info->rx_mimo_signal_strength[i] = (u8)RSSI;
676 /* Get Rx snr value in DB */
677 dm->phy_dbg_info.rx_snr_db[i] =
678 (s32)(phy_sta_rpt->path_rxsnr[i] / 2);
679 phy_info->rx_snr[i] = dm->phy_dbg_info.rx_snr_db[i];
681 /* Record Signal Strength for next packet */
682 /* if(pktinfo->is_packet_match_bssid) */
688 /* (2)PWDB, Average PWDB calcuated by hardware (for RA) */
690 rx_pwr_all = (((phy_sta_rpt->cck_sig_qual_ofdm_pwdb_all) >> 1) &
694 pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all);
695 pwdb_all_bt = pwdb_all;
697 phy_info->rx_pwdb_all = pwdb_all;
698 phy_info->bt_rx_rssi_percentage = pwdb_all_bt;
699 phy_info->rx_power = rx_pwr_all;
700 phy_info->recv_signal_power = rx_pwr_all;
702 if ((dm->support_platform == ODM_WIN) && (dm->patch_id == 19)) {
704 } else if ((dm->support_platform == ODM_WIN) &&
705 (dm->patch_id == 25)) {
707 } else { /* mgnt_info->customer_id != RT_CID_819X_LENOVO */
709 /* (3)EVM of HT rate */
711 if (pktinfo->data_rate >= ODM_RATEMCS8 &&
712 pktinfo->data_rate <= ODM_RATEMCS15) {
713 /* both spatial stream make sense */
714 max_spatial_stream = 2;
716 /* only spatial stream 1 makes sense */
717 max_spatial_stream = 1;
720 for (i = 0; i < max_spatial_stream; i++) {
721 /*Don't use shift operation like "rx_evmX >>= 1"
722 *because the compilor of free build environment
723 *fill most significant bit to "zero" when doing
724 *shifting operation which may change a negative
725 *value to positive one, then the dbm value
726 *(which is supposed to be negative) is not
729 EVM = odm_evm_db_to_percentage(
731 ->stream_rxevm[i])); /* dbm */
733 /* Fill value in RFD, Get the first spatial
736 if (i == ODM_RF_PATH_A)
737 phy_info->signal_quality =
739 phy_info->rx_mimo_signal_quality[i] =
744 num_ss = phydm_rate_to_num_ss(dm, pktinfo->data_rate);
745 odm_parsing_cfo(dm, pktinfo, phy_sta_rpt->path_cfotail, num_ss);
747 /* UI BSS List signal strength(in percentage), make it good looking,
750 /* It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp(). */
752 phy_info->signal_strength = (u8)(
753 odm_signal_scale_mapping(dm, pwdb_all)); /*pwdb_all;*/
755 if (rf_rx_num != 0) {
756 phy_info->signal_strength =
757 (u8)(odm_signal_scale_mapping(dm, total_rssi /=
762 /* For 92C/92D HW (Hybrid) Antenna Diversity */
766 odm_rx_phy_bw_jaguar_series_parsing(struct dm_phy_status_info *phy_info,
767 struct dm_per_pkt_info *pktinfo,
768 struct phy_status_rpt_8812 *phy_sta_rpt)
770 if (pktinfo->data_rate <= ODM_RATE54M) {
771 switch (phy_sta_rpt->r_RFMOD) {
773 if (phy_sta_rpt->sub_chnl == 0)
774 phy_info->band_width = 1;
776 phy_info->band_width = 0;
780 if (phy_sta_rpt->sub_chnl == 0)
781 phy_info->band_width = 2;
782 else if (phy_sta_rpt->sub_chnl == 9 ||
783 phy_sta_rpt->sub_chnl == 10)
784 phy_info->band_width = 1;
786 phy_info->band_width = 0;
791 phy_info->band_width = 0;
797 static void odm_rx_phy_status_jaguar_series_parsing(
798 struct phy_dm_struct *dm, struct dm_phy_status_info *phy_info,
799 u8 *phy_status, struct dm_per_pkt_info *pktinfo)
801 u8 i, max_spatial_stream;
802 s8 rx_pwr[4], rx_pwr_all = 0;
803 u8 EVM = 0, evm_dbm, pwdb_all = 0, pwdb_all_bt;
804 u8 RSSI, avg_rssi = 0, best_rssi = 0, second_rssi = 0;
809 struct phy_status_rpt_8812 *phy_sta_rpt =
810 (struct phy_status_rpt_8812 *)phy_status;
811 struct fast_antenna_training *fat_tab = &dm->dm_fat_table;
814 odm_rx_phy_bw_jaguar_series_parsing(phy_info, pktinfo, phy_sta_rpt);
816 if (pktinfo->data_rate <= ODM_RATE11M)
821 if (pktinfo->is_to_self)
822 dm->curr_station_id = pktinfo->station_id;
824 dm->curr_station_id = 0xff;
826 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_A] = -1;
827 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_B] = -1;
828 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_C] = -1;
829 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_D] = -1;
834 dm->phy_dbg_info.num_qry_phy_status_cck++;
836 /*(1)Hardware does not provide RSSI for CCK*/
837 /*(2)PWDB, Average PWDB calculated by hardware (for RA)*/
839 cck_highpwr = dm->is_cck_high_power;
841 cck_agc_rpt = phy_sta_rpt->cfosho[0];
842 LNA_idx = ((cck_agc_rpt & 0xE0) >> 5);
843 VGA_idx = (cck_agc_rpt & 0x1F);
845 if (dm->support_ic_type == ODM_RTL8812) {
847 phydm_get_rx_pwr(LNA_idx, VGA_idx, cck_highpwr);
849 pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all);
850 pwdb_all = phydm_adjust_pwdb(cck_highpwr, pwdb_all);
852 } else if (dm->support_ic_type & (ODM_RTL8821 | ODM_RTL8881A)) {
857 rx_pwr_all = pout - 32 - (2 * VGA_idx);
860 rx_pwr_all = pout - 24 - (2 * VGA_idx);
863 rx_pwr_all = pout - 11 - (2 * VGA_idx);
866 rx_pwr_all = pout + 5 - (2 * VGA_idx);
869 rx_pwr_all = pout + 21 - (2 * VGA_idx);
872 pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all);
873 } else if (dm->support_ic_type == ODM_RTL8814A ||
874 dm->support_ic_type == ODM_RTL8822B) {
878 /*CCK only use LNA: 2, 3, 5, 7*/
880 rx_pwr_all = pout - 32 - (2 * VGA_idx);
883 rx_pwr_all = pout - 22 - (2 * VGA_idx);
886 rx_pwr_all = pout - 2 - (2 * VGA_idx);
889 rx_pwr_all = pout + 5 - (2 * VGA_idx);
894 pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all);
897 dm->cck_lna_idx = LNA_idx;
898 dm->cck_vga_idx = VGA_idx;
899 phy_info->rx_pwdb_all = pwdb_all;
900 phy_info->bt_rx_rssi_percentage = pwdb_all;
901 phy_info->recv_signal_power = rx_pwr_all;
902 /*(3) Get Signal Quality (EVM)*/
906 if ((dm->support_platform == ODM_WIN) &&
907 (dm->patch_id == RT_CID_819X_LENOVO))
908 sq = odm_sq_process_patch_rt_cid_819x_lenovo(
909 dm, is_cck_rate, pwdb_all, 0, 0);
911 sq = phydm_get_signal_quality_8812(phy_info, dm,
914 phy_info->signal_quality = sq;
915 phy_info->rx_mimo_signal_quality[ODM_RF_PATH_A] = sq;
918 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX_JAGUAR; i++) {
920 phy_info->rx_mimo_signal_strength[0] = pwdb_all;
922 phy_info->rx_mimo_signal_strength[i] = 0;
926 fat_tab->hw_antsw_occur = phy_sta_rpt->hw_antsw_occur;
928 dm->phy_dbg_info.num_qry_phy_status_ofdm++;
930 /*(1)Get RSSI for OFDM rate*/
932 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX_JAGUAR; i++) {
933 /*2008/01/30 MH we will judge RF RX path now.*/
934 if (dm->rf_path_rx_enable & BIT(i))
936 /*2012.05.25 LukeLee: Testchip AGC report is wrong,
937 *it should be restored back to old formula in MP chip
939 if (i < ODM_RF_PATH_C)
940 rx_pwr[i] = (phy_sta_rpt->gain_trsw[i] & 0x7F) -
943 rx_pwr[i] = (phy_sta_rpt->gain_trsw_cd[i - 2] &
947 phy_info->rx_pwr[i] = rx_pwr[i];
949 /* Translate DBM to percentage. */
950 RSSI = odm_query_rx_pwr_percentage(rx_pwr[i]);
952 /*total_rssi += RSSI;*/
953 /*Get the best two RSSI*/
954 if (RSSI > best_rssi && RSSI > second_rssi) {
955 second_rssi = best_rssi;
957 } else if (RSSI > second_rssi && RSSI <= best_rssi) {
961 phy_info->rx_mimo_signal_strength[i] = (u8)RSSI;
963 /*Get Rx snr value in DB*/
964 if (i < ODM_RF_PATH_C)
965 phy_info->rx_snr[i] =
966 dm->phy_dbg_info.rx_snr_db[i] =
967 phy_sta_rpt->rxsnr[i] / 2;
968 else if (dm->support_ic_type &
969 (ODM_RTL8814A | ODM_RTL8822B))
970 phy_info->rx_snr[i] = dm->phy_dbg_info
972 phy_sta_rpt->csi_current[i - 2] / 2;
974 /*(2) CFO_short & CFO_tail*/
975 if (i < ODM_RF_PATH_C) {
976 phy_info->cfo_short[i] =
977 odm_cfo((phy_sta_rpt->cfosho[i]));
978 phy_info->cfo_tail[i] =
979 odm_cfo((phy_sta_rpt->cfotail[i]));
983 /*(3)PWDB, Average PWDB calculated by hardware (for RA)*/
985 /*2012.05.25 LukeLee: Testchip AGC report is wrong, it should be
986 *restored back to old formula in MP chip
988 if ((dm->support_ic_type &
989 (ODM_RTL8812 | ODM_RTL8821 | ODM_RTL8881A)) &&
991 rx_pwr_all = (phy_sta_rpt->pwdb_all & 0x7f) - 110;
993 rx_pwr_all = (((phy_sta_rpt->pwdb_all) >> 1) & 0x7f) -
996 pwdb_all = odm_query_rx_pwr_percentage(rx_pwr_all);
997 pwdb_all_bt = pwdb_all;
999 phy_info->rx_pwdb_all = pwdb_all;
1000 phy_info->bt_rx_rssi_percentage = pwdb_all_bt;
1001 phy_info->rx_power = rx_pwr_all;
1002 phy_info->recv_signal_power = rx_pwr_all;
1004 if ((dm->support_platform == ODM_WIN) && (dm->patch_id == 19)) {
1007 /*mgnt_info->customer_id != RT_CID_819X_LENOVO*/
1009 /*(4)EVM of OFDM rate*/
1011 if ((pktinfo->data_rate >= ODM_RATEMCS8) &&
1012 (pktinfo->data_rate <= ODM_RATEMCS15))
1013 max_spatial_stream = 2;
1014 else if ((pktinfo->data_rate >= ODM_RATEVHTSS2MCS0) &&
1015 (pktinfo->data_rate <= ODM_RATEVHTSS2MCS9))
1016 max_spatial_stream = 2;
1017 else if ((pktinfo->data_rate >= ODM_RATEMCS16) &&
1018 (pktinfo->data_rate <= ODM_RATEMCS23))
1019 max_spatial_stream = 3;
1020 else if ((pktinfo->data_rate >= ODM_RATEVHTSS3MCS0) &&
1021 (pktinfo->data_rate <= ODM_RATEVHTSS3MCS9))
1022 max_spatial_stream = 3;
1024 max_spatial_stream = 1;
1026 for (i = 0; i < max_spatial_stream; i++) {
1027 /*Don't use shift operation like "rx_evmX >>= 1"
1028 *because the compilor of free build environment
1029 *fill most significant bit to "zero" when doing
1030 *shifting operation which may change a negative
1031 *value to positive one, then the dbm value
1032 *(which is supposed to be negative) is not
1036 EVM = phydm_get_odm_evm(i, pktinfo,
1038 evm_dbm = phydm_get_evm_dbm(i, EVM, phy_sta_rpt,
1040 phy_info->rx_mimo_signal_quality[i] = EVM;
1041 phy_info->rx_mimo_evm_dbm[i] = evm_dbm;
1045 num_ss = phydm_rate_to_num_ss(dm, pktinfo->data_rate);
1046 odm_parsing_cfo(dm, pktinfo, phy_sta_rpt->cfotail, num_ss);
1049 /*UI BSS List signal strength(in percentage), make it good looking,
1052 /*It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().*/
1054 phy_info->signal_strength = (u8)(
1055 odm_signal_scale_mapping(dm, pwdb_all)); /*pwdb_all;*/
1057 if (rf_rx_num != 0) {
1058 /* 2015/01 Sean, use the best two RSSI only,
1059 * suggested by Ynlin and ChenYu.
1062 avg_rssi = best_rssi;
1064 avg_rssi = (best_rssi + second_rssi) / 2;
1065 phy_info->signal_strength =
1066 (u8)(odm_signal_scale_mapping(dm, avg_rssi));
1069 dm->rx_pwdb_ave = dm->rx_pwdb_ave + phy_info->rx_pwdb_all;
1071 dm->dm_fat_table.antsel_rx_keep_0 = phy_sta_rpt->antidx_anta;
1072 dm->dm_fat_table.antsel_rx_keep_1 = phy_sta_rpt->antidx_antb;
1073 dm->dm_fat_table.antsel_rx_keep_2 = phy_sta_rpt->antidx_antc;
1074 dm->dm_fat_table.antsel_rx_keep_3 = phy_sta_rpt->antidx_antd;
1077 void phydm_reset_rssi_for_dm(struct phy_dm_struct *dm, u8 station_id)
1079 struct rtl_sta_info *entry;
1081 entry = dm->odm_sta_info[station_id];
1083 if (!IS_STA_VALID(entry))
1086 ODM_RT_TRACE(dm, ODM_COMP_RSSI_MONITOR,
1087 "Reset RSSI for macid = (( %d ))\n", station_id);
1089 entry->rssi_stat.undecorated_smoothed_cck = -1;
1090 entry->rssi_stat.undecorated_smoothed_ofdm = -1;
1091 entry->rssi_stat.undecorated_smoothed_pwdb = -1;
1092 entry->rssi_stat.ofdm_pkt = 0;
1093 entry->rssi_stat.cck_pkt = 0;
1094 entry->rssi_stat.cck_sum_power = 0;
1095 entry->rssi_stat.is_send_rssi = RA_RSSI_STATE_INIT;
1096 entry->rssi_stat.packet_map = 0;
1097 entry->rssi_stat.valid_bit = 0;
1100 void odm_init_rssi_for_dm(struct phy_dm_struct *dm) {}
1102 static void odm_process_rssi_for_dm(struct phy_dm_struct *dm,
1103 struct dm_phy_status_info *phy_info,
1104 struct dm_per_pkt_info *pktinfo)
1106 s32 undecorated_smoothed_pwdb, undecorated_smoothed_cck,
1107 undecorated_smoothed_ofdm;
1109 u8 send_rssi_2_fw = 0;
1110 struct rtl_sta_info *entry;
1112 if (pktinfo->station_id >= ODM_ASSOCIATE_ENTRY_NUM)
1115 /* 2012/05/30 MH/Luke.Lee Add some description */
1116 /* In windows driver: AP/IBSS mode STA */
1117 entry = dm->odm_sta_info[pktinfo->station_id];
1119 if (!IS_STA_VALID(entry))
1123 if ((!pktinfo->is_packet_match_bssid)) /*data frame only*/
1127 if (pktinfo->is_packet_beacon)
1128 dm->phy_dbg_info.num_qry_beacon_pkt++;
1130 is_cck_rate = (pktinfo->data_rate <= ODM_RATE11M) ? true : false;
1131 dm->rx_rate = pktinfo->data_rate;
1133 /* --------------Statistic for antenna/path diversity---------------- */
1135 /* -----------------Smart Antenna Debug Message------------------ */
1137 undecorated_smoothed_cck = entry->rssi_stat.undecorated_smoothed_cck;
1138 undecorated_smoothed_ofdm = entry->rssi_stat.undecorated_smoothed_ofdm;
1139 undecorated_smoothed_pwdb = entry->rssi_stat.undecorated_smoothed_pwdb;
1141 if (pktinfo->is_packet_to_self || pktinfo->is_packet_beacon) {
1142 if (!is_cck_rate) /* ofdm rate */
1143 undecorated_smoothed_ofdm = phydm_process_rssi_ofdm(
1144 dm, phy_info, entry, undecorated_smoothed_ofdm);
1146 undecorated_smoothed_cck = phydm_process_rssi_cck(
1147 dm, phy_info, entry, undecorated_smoothed_cck);
1149 undecorated_smoothed_pwdb = phydm_process_rssi_pwdb(
1150 dm, entry, pktinfo, undecorated_smoothed_ofdm,
1151 undecorated_smoothed_cck);
1153 if ((entry->rssi_stat.ofdm_pkt >= 1 ||
1154 entry->rssi_stat.cck_pkt >= 5) &&
1155 (entry->rssi_stat.is_send_rssi == RA_RSSI_STATE_INIT)) {
1157 entry->rssi_stat.is_send_rssi = RA_RSSI_STATE_SEND;
1160 entry->rssi_stat.undecorated_smoothed_cck =
1161 undecorated_smoothed_cck;
1162 entry->rssi_stat.undecorated_smoothed_ofdm =
1163 undecorated_smoothed_ofdm;
1164 entry->rssi_stat.undecorated_smoothed_pwdb =
1165 undecorated_smoothed_pwdb;
1167 if (send_rssi_2_fw) { /* Trigger init rate by RSSI */
1169 if (entry->rssi_stat.ofdm_pkt != 0)
1170 entry->rssi_stat.undecorated_smoothed_pwdb =
1171 undecorated_smoothed_ofdm;
1174 dm, ODM_COMP_RSSI_MONITOR,
1175 "[Send to FW] PWDB = (( %d )), ofdm_pkt = (( %d )), cck_pkt = (( %d ))\n",
1176 undecorated_smoothed_pwdb,
1177 entry->rssi_stat.ofdm_pkt,
1178 entry->rssi_stat.cck_pkt);
1184 * Endianness before calling this API
1186 static void odm_phy_status_query_92c_series(struct phy_dm_struct *dm,
1187 struct dm_phy_status_info *phy_info,
1189 struct dm_per_pkt_info *pktinfo)
1191 odm_rx_phy_status92c_series_parsing(dm, phy_info, phy_status, pktinfo);
1192 odm_process_rssi_for_dm(dm, phy_info, pktinfo);
1196 * Endianness before calling this API
1199 static void odm_phy_status_query_jaguar_series(
1200 struct phy_dm_struct *dm, struct dm_phy_status_info *phy_info,
1201 u8 *phy_status, struct dm_per_pkt_info *pktinfo)
1203 odm_rx_phy_status_jaguar_series_parsing(dm, phy_info, phy_status,
1205 odm_process_rssi_for_dm(dm, phy_info, pktinfo);
1208 void odm_phy_status_query(struct phy_dm_struct *dm,
1209 struct dm_phy_status_info *phy_info, u8 *phy_status,
1210 struct dm_per_pkt_info *pktinfo)
1212 if (dm->support_ic_type & ODM_IC_PHY_STATUE_NEW_TYPE) {
1213 phydm_rx_phy_status_new_type(dm, phy_status, pktinfo, phy_info);
1217 if (dm->support_ic_type & ODM_IC_11AC_SERIES)
1218 odm_phy_status_query_jaguar_series(dm, phy_info, phy_status,
1221 if (dm->support_ic_type & ODM_IC_11N_SERIES)
1222 odm_phy_status_query_92c_series(dm, phy_info, phy_status,
1226 /* For future use. */
1227 void odm_mac_status_query(struct phy_dm_struct *dm, u8 *mac_status, u8 mac_id,
1228 bool is_packet_match_bssid, bool is_packet_to_self,
1229 bool is_packet_beacon)
1231 /* 2011/10/19 Driver team will handle in the future. */
1235 * If you want to add a new IC, Please follow below template and generate
1240 odm_config_rf_with_header_file(struct phy_dm_struct *dm,
1241 enum odm_rf_config_type config_type,
1242 enum odm_rf_radio_path e_rf_path)
1244 ODM_RT_TRACE(dm, ODM_COMP_INIT,
1245 "===>%s (%s)\n", __func__,
1246 (dm->is_mp_chip) ? "MPChip" : "TestChip");
1249 "dm->support_platform: 0x%X, dm->support_interface: 0x%X, dm->board_type: 0x%X\n",
1250 dm->support_platform, dm->support_interface, dm->board_type);
1252 /* 1 AP doesn't use PHYDM power tracking table in these ICs */
1253 /* JJ ADD 20161014 */
1255 /* 1 All platforms support */
1256 if (dm->support_ic_type == ODM_RTL8822B) {
1257 if (config_type == CONFIG_RF_RADIO) {
1258 if (e_rf_path == ODM_RF_PATH_A)
1259 READ_AND_CONFIG_MP(8822b, _radioa);
1260 else if (e_rf_path == ODM_RF_PATH_B)
1261 READ_AND_CONFIG_MP(8822b, _radiob);
1262 } else if (config_type == CONFIG_RF_TXPWR_LMT) {
1263 if (dm->rfe_type == 5)
1264 READ_AND_CONFIG_MP(8822b, _txpwr_lmt_type5);
1266 READ_AND_CONFIG_MP(8822b, _txpwr_lmt);
1270 return HAL_STATUS_SUCCESS;
1274 odm_config_rf_with_tx_pwr_track_header_file(struct phy_dm_struct *dm)
1276 ODM_RT_TRACE(dm, ODM_COMP_INIT,
1277 "===>%s (%s)\n", __func__,
1278 (dm->is_mp_chip) ? "MPChip" : "TestChip");
1281 "dm->support_platform: 0x%X, dm->support_interface: 0x%X, dm->board_type: 0x%X\n",
1282 dm->support_platform, dm->support_interface, dm->board_type);
1284 /* 1 AP doesn't use PHYDM power tracking table in these ICs */
1285 /* JJ ADD 20161014 */
1287 /* 1 All platforms support */
1289 if (dm->support_ic_type == ODM_RTL8822B) {
1290 if (dm->rfe_type == 0)
1291 READ_AND_CONFIG_MP(8822b, _txpowertrack_type0);
1292 else if (dm->rfe_type == 1)
1293 READ_AND_CONFIG_MP(8822b, _txpowertrack_type1);
1294 else if (dm->rfe_type == 2)
1295 READ_AND_CONFIG_MP(8822b, _txpowertrack_type2);
1296 else if ((dm->rfe_type == 3) || (dm->rfe_type == 5))
1297 READ_AND_CONFIG_MP(8822b, _txpowertrack_type3_type5);
1298 else if (dm->rfe_type == 4)
1299 READ_AND_CONFIG_MP(8822b, _txpowertrack_type4);
1300 else if (dm->rfe_type == 6)
1301 READ_AND_CONFIG_MP(8822b, _txpowertrack_type6);
1302 else if (dm->rfe_type == 7)
1303 READ_AND_CONFIG_MP(8822b, _txpowertrack_type7);
1304 else if (dm->rfe_type == 8)
1305 READ_AND_CONFIG_MP(8822b, _txpowertrack_type8);
1306 else if (dm->rfe_type == 9)
1307 READ_AND_CONFIG_MP(8822b, _txpowertrack_type9);
1309 READ_AND_CONFIG_MP(8822b, _txpowertrack);
1312 return HAL_STATUS_SUCCESS;
1316 odm_config_bb_with_header_file(struct phy_dm_struct *dm,
1317 enum odm_bb_config_type config_type)
1319 /* 1 AP doesn't use PHYDM initialization in these ICs */
1320 /* JJ ADD 20161014 */
1322 /* 1 All platforms support */
1323 if (dm->support_ic_type == ODM_RTL8822B) {
1324 if (config_type == CONFIG_BB_PHY_REG)
1325 READ_AND_CONFIG_MP(8822b, _phy_reg);
1326 else if (config_type == CONFIG_BB_AGC_TAB)
1327 READ_AND_CONFIG_MP(8822b, _agc_tab);
1328 else if (config_type == CONFIG_BB_PHY_REG_PG)
1329 READ_AND_CONFIG_MP(8822b, _phy_reg_pg);
1330 /*else if (config_type == CONFIG_BB_PHY_REG_MP)*/
1331 /*READ_AND_CONFIG_MP(8822b, _phy_reg_mp);*/
1334 return HAL_STATUS_SUCCESS;
1337 enum hal_status odm_config_mac_with_header_file(struct phy_dm_struct *dm)
1339 ODM_RT_TRACE(dm, ODM_COMP_INIT,
1340 "===>%s (%s)\n", __func__,
1341 (dm->is_mp_chip) ? "MPChip" : "TestChip");
1344 "dm->support_platform: 0x%X, dm->support_interface: 0x%X, dm->board_type: 0x%X\n",
1345 dm->support_platform, dm->support_interface, dm->board_type);
1347 /* 1 AP doesn't use PHYDM initialization in these ICs */
1348 /* JJ ADD 20161014 */
1350 /* 1 All platforms support */
1351 if (dm->support_ic_type == ODM_RTL8822B)
1352 READ_AND_CONFIG_MP(8822b, _mac_reg);
1354 return HAL_STATUS_SUCCESS;
1358 odm_config_fw_with_header_file(struct phy_dm_struct *dm,
1359 enum odm_fw_config_type config_type,
1360 u8 *p_firmware, u32 *size)
1362 return HAL_STATUS_SUCCESS;
1365 u32 odm_get_hw_img_version(struct phy_dm_struct *dm)
1369 /* 1 AP doesn't use PHYDM initialization in these ICs */
1370 /* JJ ADD 20161014 */
1372 /*1 All platforms support*/
1373 if (dm->support_ic_type == ODM_RTL8822B)
1374 version = GET_VERSION_MP(8822b, _mac_reg);
1379 /* For 8822B only!! need to move to FW finally */
1380 /*==============================================*/
1382 bool phydm_query_is_mu_api(struct phy_dm_struct *phydm, u8 ppdu_idx,
1383 u8 *p_data_rate, u8 *p_gid)
1385 u8 data_rate = 0, gid = 0;
1388 data_rate = phydm->phy_dbg_info.num_of_ppdu[ppdu_idx];
1389 gid = phydm->phy_dbg_info.gid_num[ppdu_idx];
1391 if (data_rate & BIT(7)) {
1393 data_rate = data_rate & ~(BIT(7));
1398 *p_data_rate = data_rate;
1404 static void phydm_rx_statistic_cal(struct phy_dm_struct *phydm, u8 *phy_status,
1405 struct dm_per_pkt_info *pktinfo)
1407 struct phy_status_rpt_jaguar2_type1 *phy_sta_rpt =
1408 (struct phy_status_rpt_jaguar2_type1 *)phy_status;
1409 u8 date_rate = pktinfo->data_rate & ~(BIT(7));
1411 if ((phy_sta_rpt->gid != 0) && (phy_sta_rpt->gid != 63)) {
1412 if (date_rate >= ODM_RATEVHTSS1MCS0) {
1414 .num_qry_mu_vht_pkt[date_rate - 0x2C]++;
1415 phydm->phy_dbg_info.num_of_ppdu[pktinfo->ppdu_cnt] =
1417 phydm->phy_dbg_info.gid_num[pktinfo->ppdu_cnt] =
1422 if (date_rate >= ODM_RATEVHTSS1MCS0) {
1423 phydm->phy_dbg_info.num_qry_vht_pkt[date_rate - 0x2C]++;
1424 phydm->phy_dbg_info.num_of_ppdu[pktinfo->ppdu_cnt] =
1426 phydm->phy_dbg_info.gid_num[pktinfo->ppdu_cnt] =
1432 static void phydm_reset_phy_info(struct phy_dm_struct *phydm,
1433 struct dm_phy_status_info *phy_info)
1435 phy_info->rx_pwdb_all = 0;
1436 phy_info->signal_quality = 0;
1437 phy_info->band_width = 0;
1438 phy_info->rx_count = 0;
1439 odm_memory_set(phydm, phy_info->rx_mimo_signal_quality, 0, 4);
1440 odm_memory_set(phydm, phy_info->rx_mimo_signal_strength, 0, 4);
1441 odm_memory_set(phydm, phy_info->rx_snr, 0, 4);
1443 phy_info->rx_power = -110;
1444 phy_info->recv_signal_power = -110;
1445 phy_info->bt_rx_rssi_percentage = 0;
1446 phy_info->signal_strength = 0;
1447 phy_info->bt_coex_pwr_adjust = 0;
1448 phy_info->channel = 0;
1449 phy_info->is_mu_packet = 0;
1450 phy_info->is_beamformed = 0;
1452 odm_memory_set(phydm, phy_info->rx_pwr, -110, 4);
1453 odm_memory_set(phydm, phy_info->rx_mimo_evm_dbm, 0, 4);
1454 odm_memory_set(phydm, phy_info->cfo_short, 0, 8);
1455 odm_memory_set(phydm, phy_info->cfo_tail, 0, 8);
1458 static void phydm_set_per_path_phy_info(u8 rx_path, s8 rx_pwr, s8 rx_evm,
1459 s8 cfo_tail, s8 rx_snr,
1460 struct dm_phy_status_info *phy_info)
1463 u8 evm_percentage = 0;
1465 /* SNR is S(8,1), EVM is S(8,1), CFO is S(8,7) */
1468 /* Calculate EVM in dBm */
1469 evm_dbm = ((u8)(0 - rx_evm) >> 1);
1471 /* Calculate EVM in percentage */
1473 evm_percentage = 100;
1475 evm_percentage = (evm_dbm << 1) + (evm_dbm);
1478 phy_info->rx_pwr[rx_path] = rx_pwr;
1479 phy_info->rx_mimo_evm_dbm[rx_path] = evm_dbm;
1481 /* CFO = CFO_tail * 312.5 / 2^7 ~= CFO tail * 39/512 (kHz)*/
1482 phy_info->cfo_tail[rx_path] = cfo_tail;
1483 phy_info->cfo_tail[rx_path] = ((phy_info->cfo_tail[rx_path] << 5) +
1484 (phy_info->cfo_tail[rx_path] << 2) +
1485 (phy_info->cfo_tail[rx_path] << 1) +
1486 (phy_info->cfo_tail[rx_path])) >>
1489 phy_info->rx_mimo_signal_strength[rx_path] =
1490 odm_query_rx_pwr_percentage(rx_pwr);
1491 phy_info->rx_mimo_signal_quality[rx_path] = evm_percentage;
1492 phy_info->rx_snr[rx_path] = rx_snr >> 1;
1495 static void phydm_set_common_phy_info(s8 rx_power, u8 channel,
1496 bool is_beamformed, bool is_mu_packet,
1497 u8 bandwidth, u8 signal_quality, u8 rxsc,
1498 struct dm_phy_status_info *phy_info)
1500 phy_info->rx_power = rx_power; /* RSSI in dB */
1501 phy_info->recv_signal_power = rx_power; /* RSSI in dB */
1502 phy_info->channel = channel; /* channel number */
1503 phy_info->is_beamformed = is_beamformed; /* apply BF */
1504 phy_info->is_mu_packet = is_mu_packet; /* MU packet */
1505 phy_info->rxsc = rxsc;
1506 phy_info->rx_pwdb_all =
1507 odm_query_rx_pwr_percentage(rx_power); /* RSSI in percentage */
1508 phy_info->signal_quality = signal_quality; /* signal quality */
1509 phy_info->band_width = bandwidth; /* bandwidth */
1512 static void phydm_get_rx_phy_status_type0(struct phy_dm_struct *dm,
1514 struct dm_per_pkt_info *pktinfo,
1515 struct dm_phy_status_info *phy_info)
1517 /* type 0 is used for cck packet */
1519 struct phy_status_rpt_jaguar2_type0 *phy_sta_rpt =
1520 (struct phy_status_rpt_jaguar2_type0 *)phy_status;
1522 s8 rx_power = phy_sta_rpt->pwdb - 110;
1524 /* JJ ADD 20161014 */
1526 /* Calculate Signal Quality*/
1527 if (pktinfo->is_packet_match_bssid) {
1528 if (phy_sta_rpt->signal_quality >= 64) {
1530 } else if (phy_sta_rpt->signal_quality <= 20) {
1533 /* mapping to 2~99% */
1534 sq = 64 - phy_sta_rpt->signal_quality;
1535 sq = ((sq << 3) + sq) >> 2;
1539 /* Modify CCK PWDB if old AGC */
1540 if (!dm->cck_new_agc) {
1541 u8 lna_idx, vga_idx;
1543 lna_idx = ((phy_sta_rpt->lna_h << 3) | phy_sta_rpt->lna_l);
1544 vga_idx = phy_sta_rpt->vga;
1546 /* JJ ADD 20161014 */
1549 /*if (dm->support_ic_type & ODM_RTL8822B) */
1550 /*rx_power = odm_CCKRSSI_8822B(LNA_idx, VGA_idx);*/
1553 /* Update CCK packet counter */
1554 dm->phy_dbg_info.num_qry_phy_status_cck++;
1556 /*CCK no STBC and LDPC*/
1557 dm->phy_dbg_info.is_ldpc_pkt = false;
1558 dm->phy_dbg_info.is_stbc_pkt = false;
1560 /* Update Common information */
1561 phydm_set_common_phy_info(rx_power, phy_sta_rpt->channel, false, false,
1562 ODM_BW20M, sq, phy_sta_rpt->rxsc, phy_info);
1564 /* Update CCK pwdb */
1565 /* Update per-path information */
1566 phydm_set_per_path_phy_info(ODM_RF_PATH_A, rx_power, 0, 0, 0, phy_info);
1568 dm->dm_fat_table.antsel_rx_keep_0 = phy_sta_rpt->antidx_a;
1569 dm->dm_fat_table.antsel_rx_keep_1 = phy_sta_rpt->antidx_b;
1570 dm->dm_fat_table.antsel_rx_keep_2 = phy_sta_rpt->antidx_c;
1571 dm->dm_fat_table.antsel_rx_keep_3 = phy_sta_rpt->antidx_d;
1574 static void phydm_get_rx_phy_status_type1(struct phy_dm_struct *dm,
1576 struct dm_per_pkt_info *pktinfo,
1577 struct dm_phy_status_info *phy_info)
1579 /* type 1 is used for ofdm packet */
1581 struct phy_status_rpt_jaguar2_type1 *phy_sta_rpt =
1582 (struct phy_status_rpt_jaguar2_type1 *)phy_status;
1583 s8 rx_pwr_db = -120;
1584 u8 i, rxsc, bw = ODM_BW20M, rx_count = 0;
1588 /* Update OFDM packet counter */
1589 dm->phy_dbg_info.num_qry_phy_status_ofdm++;
1591 /* Update per-path information */
1592 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX_JAGUAR; i++) {
1593 if (dm->rx_ant_status & BIT(i)) {
1596 /* RX path counter */
1599 /* Update per-path information
1600 * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
1602 /* EVM report is reported by stream, not path */
1603 rx_path_pwr_db = phy_sta_rpt->pwdb[i] -
1604 110; /* per-path pwdb in dB domain */
1605 phydm_set_per_path_phy_info(
1607 phy_sta_rpt->rxevm[rx_count - 1],
1608 phy_sta_rpt->cfo_tail[i], phy_sta_rpt->rxsnr[i],
1611 /* search maximum pwdb */
1612 if (rx_path_pwr_db > rx_pwr_db)
1613 rx_pwr_db = rx_path_pwr_db;
1617 /* mapping RX counter from 1~4 to 0~3 */
1619 phy_info->rx_count = rx_count - 1;
1621 /* Check if MU packet or not */
1622 if ((phy_sta_rpt->gid != 0) && (phy_sta_rpt->gid != 63)) {
1624 dm->phy_dbg_info.num_qry_mu_pkt++;
1629 /* count BF packet */
1630 dm->phy_dbg_info.num_qry_bf_pkt =
1631 dm->phy_dbg_info.num_qry_bf_pkt + phy_sta_rpt->beamformed;
1633 /*STBC or LDPC pkt*/
1634 dm->phy_dbg_info.is_ldpc_pkt = phy_sta_rpt->ldpc;
1635 dm->phy_dbg_info.is_stbc_pkt = phy_sta_rpt->stbc;
1637 /* Check sub-channel */
1638 if ((pktinfo->data_rate > ODM_RATE11M) &&
1639 (pktinfo->data_rate < ODM_RATEMCS0))
1640 rxsc = phy_sta_rpt->l_rxsc;
1642 rxsc = phy_sta_rpt->ht_rxsc;
1644 /* Check RX bandwidth */
1645 if (dm->support_ic_type & ODM_RTL8822B) {
1646 if ((rxsc >= 1) && (rxsc <= 8))
1648 else if ((rxsc >= 9) && (rxsc <= 12))
1650 else if (rxsc >= 13)
1653 bw = phy_sta_rpt->rf_mode;
1654 } else if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8723D |
1655 ODM_RTL8710B)) { /* JJ ADD 20161014 */
1656 if (phy_sta_rpt->rf_mode == 0)
1658 else if ((rxsc == 1) || (rxsc == 2))
1664 /* Update packet information */
1665 phydm_set_common_phy_info(
1666 rx_pwr_db, phy_sta_rpt->channel, (bool)phy_sta_rpt->beamformed,
1667 is_mu, bw, odm_evm_db_to_percentage(phy_sta_rpt->rxevm[0]),
1670 num_ss = phydm_rate_to_num_ss(dm, pktinfo->data_rate);
1672 odm_parsing_cfo(dm, pktinfo, phy_sta_rpt->cfo_tail, num_ss);
1673 dm->dm_fat_table.antsel_rx_keep_0 = phy_sta_rpt->antidx_a;
1674 dm->dm_fat_table.antsel_rx_keep_1 = phy_sta_rpt->antidx_b;
1675 dm->dm_fat_table.antsel_rx_keep_2 = phy_sta_rpt->antidx_c;
1676 dm->dm_fat_table.antsel_rx_keep_3 = phy_sta_rpt->antidx_d;
1678 if (pktinfo->is_packet_match_bssid) {
1680 phydm_rx_statistic_cal(dm, phy_status, pktinfo);
1684 static void phydm_get_rx_phy_status_type2(struct phy_dm_struct *dm,
1686 struct dm_per_pkt_info *pktinfo,
1687 struct dm_phy_status_info *phy_info)
1689 struct phy_status_rpt_jaguar2_type2 *phy_sta_rpt =
1690 (struct phy_status_rpt_jaguar2_type2 *)phy_status;
1691 s8 rx_pwr_db = -120;
1692 u8 i, rxsc, bw = ODM_BW20M, rx_count = 0;
1694 /* Update OFDM packet counter */
1695 dm->phy_dbg_info.num_qry_phy_status_ofdm++;
1697 /* Update per-path information */
1698 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX_JAGUAR; i++) {
1699 if (dm->rx_ant_status & BIT(i)) {
1702 /* RX path counter */
1705 /* Update per-path information
1706 * (RSSI_dB RSSI_percentage EVM SNR CFO sq)
1708 rx_path_pwr_db = phy_sta_rpt->pwdb[i] -
1709 110; /* per-path pwdb in dB domain */
1711 phydm_set_per_path_phy_info(i, rx_path_pwr_db, 0, 0, 0,
1714 /* search maximum pwdb */
1715 if (rx_path_pwr_db > rx_pwr_db)
1716 rx_pwr_db = rx_path_pwr_db;
1720 /* mapping RX counter from 1~4 to 0~3 */
1722 phy_info->rx_count = rx_count - 1;
1724 /* Check RX sub-channel */
1725 if ((pktinfo->data_rate > ODM_RATE11M) &&
1726 (pktinfo->data_rate < ODM_RATEMCS0))
1727 rxsc = phy_sta_rpt->l_rxsc;
1729 rxsc = phy_sta_rpt->ht_rxsc;
1731 /*STBC or LDPC pkt*/
1732 dm->phy_dbg_info.is_ldpc_pkt = phy_sta_rpt->ldpc;
1733 dm->phy_dbg_info.is_stbc_pkt = phy_sta_rpt->stbc;
1735 /* Check RX bandwidth */
1736 /* the BW information of sc=0 is useless, because there is
1737 * no information of RF mode
1740 if (dm->support_ic_type & ODM_RTL8822B) {
1741 if ((rxsc >= 1) && (rxsc <= 8))
1743 else if ((rxsc >= 9) && (rxsc <= 12))
1745 else if (rxsc >= 13)
1749 } else if (dm->support_ic_type & (ODM_RTL8197F | ODM_RTL8723D |
1750 ODM_RTL8710B)) { /* JJ ADD 20161014 */
1753 else if ((rxsc == 1) || (rxsc == 2))
1759 /* Update packet information */
1760 phydm_set_common_phy_info(rx_pwr_db, phy_sta_rpt->channel,
1761 (bool)phy_sta_rpt->beamformed, false, bw, 0,
1766 phydm_process_rssi_for_dm_new_type(struct phy_dm_struct *dm,
1767 struct dm_phy_status_info *phy_info,
1768 struct dm_per_pkt_info *pktinfo)
1770 s32 undecorated_smoothed_pwdb, accumulate_pwdb;
1773 struct rtl_sta_info *entry;
1774 u8 scaling_factor = 4;
1776 if (pktinfo->station_id >= ODM_ASSOCIATE_ENTRY_NUM)
1779 entry = dm->odm_sta_info[pktinfo->station_id];
1781 if (!IS_STA_VALID(entry))
1784 if ((!pktinfo->is_packet_match_bssid)) /*data frame only*/
1787 if (pktinfo->is_packet_beacon)
1788 dm->phy_dbg_info.num_qry_beacon_pkt++;
1790 if (pktinfo->is_packet_to_self || pktinfo->is_packet_beacon) {
1791 u32 rssi_linear = 0;
1793 dm->rx_rate = pktinfo->data_rate;
1794 undecorated_smoothed_pwdb =
1795 entry->rssi_stat.undecorated_smoothed_pwdb;
1796 accumulate_pwdb = dm->accumulate_pwdb[pktinfo->station_id];
1797 dm->rssi_a = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_A];
1798 dm->rssi_b = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_B];
1799 dm->rssi_c = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_C];
1800 dm->rssi_d = phy_info->rx_mimo_signal_strength[ODM_RF_PATH_D];
1802 for (i = ODM_RF_PATH_A; i < ODM_RF_PATH_MAX_JAGUAR; i++) {
1803 if (phy_info->rx_mimo_signal_strength[i] != 0)
1804 rssi_linear += odm_convert_to_linear(
1805 phy_info->rx_mimo_signal_strength[i]);
1808 switch (phy_info->rx_count + 1) {
1810 rssi_linear = (rssi_linear >> 1);
1813 /* rssi_linear/3 ~ rssi_linear*11/32 */
1814 rssi_linear = ((rssi_linear) + (rssi_linear << 1) +
1815 (rssi_linear << 3)) >>
1819 rssi_linear = (rssi_linear >> 2);
1822 rssi_ave = odm_convert_to_db(rssi_linear);
1824 if (undecorated_smoothed_pwdb <= 0) {
1826 (phy_info->rx_pwdb_all << scaling_factor);
1827 undecorated_smoothed_pwdb = phy_info->rx_pwdb_all;
1829 accumulate_pwdb = accumulate_pwdb -
1830 (accumulate_pwdb >> scaling_factor) +
1832 undecorated_smoothed_pwdb =
1834 (1 << (scaling_factor - 1))) >>
1838 entry->rssi_stat.undecorated_smoothed_pwdb =
1839 undecorated_smoothed_pwdb;
1840 dm->accumulate_pwdb[pktinfo->station_id] = accumulate_pwdb;
1844 void phydm_rx_phy_status_new_type(struct phy_dm_struct *phydm, u8 *phy_status,
1845 struct dm_per_pkt_info *pktinfo,
1846 struct dm_phy_status_info *phy_info)
1848 u8 phy_status_type = (*phy_status & 0xf);
1851 phydm_reset_phy_info(phydm, phy_info);
1853 /* Phy status parsing */
1854 switch (phy_status_type) {
1856 phydm_get_rx_phy_status_type0(phydm, phy_status, pktinfo,
1861 phydm_get_rx_phy_status_type1(phydm, phy_status, pktinfo,
1866 phydm_get_rx_phy_status_type2(phydm, phy_status, pktinfo,
1874 /* Update signal strength to UI, and phy_info->rx_pwdb_all is the
1875 * maximum RSSI of all path
1877 phy_info->signal_strength =
1878 (u8)(odm_signal_scale_mapping(phydm, phy_info->rx_pwdb_all));
1880 /* Calculate average RSSI and smoothed RSSI */
1881 phydm_process_rssi_for_dm_new_type(phydm, phy_info, pktinfo);
1884 u32 query_phydm_trx_capability(struct phy_dm_struct *dm)
1886 u32 value32 = 0xFFFFFFFF;
1891 u32 query_phydm_stbc_capability(struct phy_dm_struct *dm)
1893 u32 value32 = 0xFFFFFFFF;
1898 u32 query_phydm_ldpc_capability(struct phy_dm_struct *dm)
1900 u32 value32 = 0xFFFFFFFF;
1905 u32 query_phydm_txbf_parameters(struct phy_dm_struct *dm)
1907 u32 value32 = 0xFFFFFFFF;
1912 u32 query_phydm_txbf_capability(struct phy_dm_struct *dm)
1914 u32 value32 = 0xFFFFFFFF;