1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3
4 #define _RTL8188E_REDESC_C_
5
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/rtl8188e_hal.h"
9
process_rssi(struct adapter * padapter,struct recv_frame * prframe)10 static void process_rssi(struct adapter *padapter, struct recv_frame *prframe)
11 {
12 struct rx_pkt_attrib *pattrib = &prframe->attrib;
13 struct signal_stat *signal_stat = &padapter->recvpriv.signal_strength_data;
14
15 if (signal_stat->update_req) {
16 signal_stat->total_num = 0;
17 signal_stat->total_val = 0;
18 signal_stat->update_req = 0;
19 }
20
21 signal_stat->total_num++;
22 signal_stat->total_val += pattrib->phy_info.SignalStrength;
23 signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
24 } /* Process_UI_RSSI_8192C */
25
process_link_qual(struct adapter * padapter,struct recv_frame * prframe)26 static void process_link_qual(struct adapter *padapter, struct recv_frame *prframe)
27 {
28 struct rx_pkt_attrib *pattrib;
29 struct signal_stat *signal_stat;
30
31 if (!prframe || !padapter)
32 return;
33
34 pattrib = &prframe->attrib;
35 signal_stat = &padapter->recvpriv.signal_qual_data;
36
37 if (signal_stat->update_req) {
38 signal_stat->total_num = 0;
39 signal_stat->total_val = 0;
40 signal_stat->update_req = 0;
41 }
42
43 signal_stat->total_num++;
44 signal_stat->total_val += pattrib->phy_info.SignalQuality;
45 signal_stat->avg_val = signal_stat->total_val / signal_stat->total_num;
46 }
47
rtl8188e_process_phy_info(struct adapter * padapter,void * prframe)48 void rtl8188e_process_phy_info(struct adapter *padapter, void *prframe)
49 {
50 struct recv_frame *precvframe = (struct recv_frame *)prframe;
51
52 /* Check RSSI */
53 process_rssi(padapter, precvframe);
54 /* Check EVM */
55 process_link_qual(padapter, precvframe);
56 }
57
update_recvframe_attrib_88e(struct recv_frame * precvframe,struct recv_stat * prxstat)58 void update_recvframe_attrib_88e(struct recv_frame *precvframe, struct recv_stat *prxstat)
59 {
60 struct rx_pkt_attrib *pattrib;
61 struct recv_stat report;
62
63 report.rxdw0 = prxstat->rxdw0;
64 report.rxdw1 = prxstat->rxdw1;
65 report.rxdw2 = prxstat->rxdw2;
66 report.rxdw3 = prxstat->rxdw3;
67 report.rxdw4 = prxstat->rxdw4;
68 report.rxdw5 = prxstat->rxdw5;
69
70 pattrib = &precvframe->attrib;
71 memset(pattrib, 0, sizeof(struct rx_pkt_attrib));
72
73 pattrib->crc_err = (u8)((le32_to_cpu(report.rxdw0) >> 14) & 0x1);/* u8)prxreport->crc32; */
74
75 /* update rx report to recv_frame attribute */
76 pattrib->pkt_rpt_type = (u8)((le32_to_cpu(report.rxdw3) >> 14) & 0x3);/* prxreport->rpt_sel; */
77
78 if (pattrib->pkt_rpt_type == NORMAL_RX) { /* Normal rx packet */
79 pattrib->pkt_len = (u16)(le32_to_cpu(report.rxdw0) & 0x00003fff);/* u16)prxreport->pktlen; */
80 pattrib->drvinfo_sz = (u8)((le32_to_cpu(report.rxdw0) >> 16) & 0xf) * 8;/* u8)(prxreport->drvinfosize << 3); */
81
82 pattrib->physt = (u8)((le32_to_cpu(report.rxdw0) >> 26) & 0x1);/* u8)prxreport->physt; */
83
84 pattrib->bdecrypted = (le32_to_cpu(report.rxdw0) & BIT(27)) ? 0 : 1;/* u8)(prxreport->swdec ? 0 : 1); */
85 pattrib->encrypt = (u8)((le32_to_cpu(report.rxdw0) >> 20) & 0x7);/* u8)prxreport->security; */
86
87 pattrib->qos = (u8)((le32_to_cpu(report.rxdw0) >> 23) & 0x1);/* u8)prxreport->qos; */
88 pattrib->priority = (u8)((le32_to_cpu(report.rxdw1) >> 8) & 0xf);/* u8)prxreport->tid; */
89
90 pattrib->amsdu = (u8)((le32_to_cpu(report.rxdw1) >> 13) & 0x1);/* u8)prxreport->amsdu; */
91
92 pattrib->seq_num = (u16)(le32_to_cpu(report.rxdw2) & 0x00000fff);/* u16)prxreport->seq; */
93 pattrib->frag_num = (u8)((le32_to_cpu(report.rxdw2) >> 12) & 0xf);/* u8)prxreport->frag; */
94 pattrib->mfrag = (u8)((le32_to_cpu(report.rxdw1) >> 27) & 0x1);/* u8)prxreport->mf; */
95 pattrib->mdata = (u8)((le32_to_cpu(report.rxdw1) >> 26) & 0x1);/* u8)prxreport->md; */
96
97 pattrib->mcs_rate = (u8)(le32_to_cpu(report.rxdw3) & 0x3f);/* u8)prxreport->rxmcs; */
98 pattrib->rxht = (u8)((le32_to_cpu(report.rxdw3) >> 6) & 0x1);/* u8)prxreport->rxht; */
99
100 pattrib->icv_err = (u8)((le32_to_cpu(report.rxdw0) >> 15) & 0x1);/* u8)prxreport->icverr; */
101 pattrib->shift_sz = (u8)((le32_to_cpu(report.rxdw0) >> 24) & 0x3);
102 } else if (pattrib->pkt_rpt_type == TX_REPORT1) { /* CCX */
103 pattrib->pkt_len = TX_RPT1_PKT_LEN;
104 pattrib->drvinfo_sz = 0;
105 } else if (pattrib->pkt_rpt_type == TX_REPORT2) { /* TX RPT */
106 pattrib->pkt_len = (u16)(le32_to_cpu(report.rxdw0) & 0x3FF);/* Rx length[9:0] */
107 pattrib->drvinfo_sz = 0;
108
109 /* */
110 /* Get TX report MAC ID valid. */
111 /* */
112 pattrib->MacIDValidEntry[0] = le32_to_cpu(report.rxdw4);
113 pattrib->MacIDValidEntry[1] = le32_to_cpu(report.rxdw5);
114
115 } else if (pattrib->pkt_rpt_type == HIS_REPORT) { /* USB HISR RPT */
116 pattrib->pkt_len = (u16)(le32_to_cpu(report.rxdw0) & 0x00003fff);/* u16)prxreport->pktlen; */
117 }
118 }
119
120 /*
121 * Notice:
122 * Before calling this function,
123 * precvframe->rx_data should be ready!
124 */
update_recvframe_phyinfo_88e(struct recv_frame * precvframe,struct phy_stat * pphy_status)125 void update_recvframe_phyinfo_88e(struct recv_frame *precvframe, struct phy_stat *pphy_status)
126 {
127 struct adapter *padapter = precvframe->adapter;
128 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
129 struct hal_data_8188e *pHalData = GET_HAL_DATA(padapter);
130 struct odm_phy_status_info *pPHYInfo = (struct odm_phy_status_info *)(&pattrib->phy_info);
131 u8 *wlanhdr;
132 struct odm_per_pkt_info pkt_info;
133 u8 *sa = NULL;
134 struct sta_priv *pstapriv;
135 struct sta_info *psta;
136
137 pkt_info.bPacketMatchBSSID = false;
138 pkt_info.bPacketToSelf = false;
139 pkt_info.bPacketBeacon = false;
140
141 wlanhdr = get_recvframe_data(precvframe);
142
143 pkt_info.bPacketMatchBSSID = ((!IsFrameTypeCtrl(wlanhdr)) &&
144 !pattrib->icv_err && !pattrib->crc_err &&
145 !memcmp(get_hdr_bssid(wlanhdr),
146 get_bssid(&padapter->mlmepriv), ETH_ALEN));
147
148 pkt_info.bPacketToSelf = pkt_info.bPacketMatchBSSID &&
149 (!memcmp(get_da(wlanhdr),
150 myid(&padapter->eeprompriv), ETH_ALEN));
151
152 pkt_info.bPacketBeacon = pkt_info.bPacketMatchBSSID &&
153 (GetFrameSubType(wlanhdr) == WIFI_BEACON);
154
155 if (pkt_info.bPacketBeacon) {
156 if (check_fwstate(&padapter->mlmepriv, WIFI_STATION_STATE))
157 sa = padapter->mlmepriv.cur_network.network.MacAddress;
158 /* to do Ad-hoc */
159 } else {
160 sa = get_sa(wlanhdr);
161 }
162
163 pstapriv = &padapter->stapriv;
164 pkt_info.StationID = 0xFF;
165 psta = rtw_get_stainfo(pstapriv, sa);
166 if (psta)
167 pkt_info.StationID = psta->mac_id;
168 pkt_info.Rate = pattrib->mcs_rate;
169
170 ODM_PhyStatusQuery(&pHalData->odmpriv, pPHYInfo, (u8 *)pphy_status, &(pkt_info), padapter);
171
172 precvframe->psta = NULL;
173 if (pkt_info.bPacketMatchBSSID &&
174 (check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE))) {
175 if (psta) {
176 precvframe->psta = psta;
177 rtl8188e_process_phy_info(padapter, precvframe);
178 }
179 } else if (pkt_info.bPacketToSelf || pkt_info.bPacketBeacon) {
180 if (check_fwstate(&padapter->mlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE)) {
181 if (psta)
182 precvframe->psta = psta;
183 }
184 rtl8188e_process_phy_info(padapter, precvframe);
185 }
186 }
187