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