diff options
author | Larry Finger <Larry.Finger@lwfinger.net> | 2013-03-24 23:06:42 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2013-04-01 16:20:13 -0400 |
commit | f0eb856e0b6cbd21244afc0f252cec718ecf88fb (patch) | |
tree | 77d5cb7faf46f7ffd6b79a6d97be72b4eef422b1 /drivers/net/wireless/rtlwifi/rtl8188ee/trx.c | |
parent | a269913c52ad37952a4d9953bb6d748f7299c304 (diff) |
rtlwifi: rtl8188ee: Add new driver
Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Cc: jcheung@suse.com
Cc: machen@suse.com
Cc: mmarek@suse.cz
Cc: page_he@realsil.com.cn
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rtlwifi/rtl8188ee/trx.c')
-rw-r--r-- | drivers/net/wireless/rtlwifi/rtl8188ee/trx.c | 817 |
1 files changed, 817 insertions, 0 deletions
diff --git a/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c new file mode 100644 index 000000000000..251853178de2 --- /dev/null +++ b/drivers/net/wireless/rtlwifi/rtl8188ee/trx.c | |||
@@ -0,0 +1,817 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2009-2013 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 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in the | ||
19 | * file called LICENSE. | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * wlanfae <wlanfae@realtek.com> | ||
23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | ||
24 | * Hsinchu 300, Taiwan. | ||
25 | * | ||
26 | * Larry Finger <Larry.Finger@lwfinger.net> | ||
27 | * | ||
28 | *****************************************************************************/ | ||
29 | |||
30 | #include "wifi.h" | ||
31 | #include "pci.h" | ||
32 | #include "base.h" | ||
33 | #include "stats.h" | ||
34 | #include "reg.h" | ||
35 | #include "def.h" | ||
36 | #include "phy.h" | ||
37 | #include "trx.h" | ||
38 | #include "led.h" | ||
39 | #include "dm.h" | ||
40 | |||
41 | static u8 _rtl88ee_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue) | ||
42 | { | ||
43 | __le16 fc = rtl_get_fc(skb); | ||
44 | |||
45 | if (unlikely(ieee80211_is_beacon(fc))) | ||
46 | return QSLT_BEACON; | ||
47 | if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) | ||
48 | return QSLT_MGNT; | ||
49 | |||
50 | return skb->priority; | ||
51 | } | ||
52 | |||
53 | static void _rtl88ee_query_rxphystatus(struct ieee80211_hw *hw, | ||
54 | struct rtl_stats *pstatus, u8 *pdesc, | ||
55 | struct rx_fwinfo_88e *p_drvinfo, | ||
56 | bool bpacket_match_bssid, | ||
57 | bool bpacket_toself, bool packet_beacon) | ||
58 | { | ||
59 | struct rtl_priv *rtlpriv = rtl_priv(hw); | ||
60 | struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); | ||
61 | struct phy_sts_cck_8192s_t *cck_buf; | ||
62 | struct phy_status_rpt *phystrpt = (struct phy_status_rpt *)p_drvinfo; | ||
63 | struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw)); | ||
64 | char rx_pwr_all = 0, rx_pwr[4]; | ||
65 | u8 rf_rx_num = 0, evm, pwdb_all; | ||
66 | u8 i, max_spatial_stream; | ||
67 | u32 rssi, total_rssi = 0; | ||
68 | bool is_cck = pstatus->is_cck; | ||
69 | u8 lan_idx, vga_idx; | ||
70 | |||
71 | /* Record it for next packet processing */ | ||
72 | pstatus->packet_matchbssid = bpacket_match_bssid; | ||
73 | pstatus->packet_toself = bpacket_toself; | ||
74 | pstatus->packet_beacon = packet_beacon; | ||
75 | pstatus->rx_mimo_sig_qual[0] = -1; | ||
76 | pstatus->rx_mimo_sig_qual[1] = -1; | ||
77 | |||
78 | if (is_cck) { | ||
79 | u8 cck_hipwr; | ||
80 | u8 cck_agc_rpt; | ||
81 | /* CCK Driver info Structure is not the same as OFDM packet. */ | ||
82 | cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo; | ||
83 | cck_agc_rpt = cck_buf->cck_agc_rpt; | ||
84 | |||
85 | /* (1)Hardware does not provide RSSI for CCK | ||
86 | * (2)PWDB, Average PWDB cacluated by | ||
87 | * hardware (for rate adaptive) | ||
88 | */ | ||
89 | if (ppsc->rfpwr_state == ERFON) | ||
90 | cck_hipwr = rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2, | ||
91 | BIT(9)); | ||
92 | else | ||
93 | cck_hipwr = false; | ||
94 | |||
95 | lan_idx = ((cck_agc_rpt & 0xE0) >> 5); | ||
96 | vga_idx = (cck_agc_rpt & 0x1f); | ||
97 | switch (lan_idx) { | ||
98 | case 7: | ||
99 | if (vga_idx <= 27) | ||
100 | rx_pwr_all = -100 + 2 * (27 - vga_idx); | ||
101 | else | ||
102 | rx_pwr_all = -100; | ||
103 | break; | ||
104 | case 6: | ||
105 | rx_pwr_all = -48 + 2 * (2 - vga_idx); /*VGA_idx = 2~0*/ | ||
106 | break; | ||
107 | case 5: | ||
108 | rx_pwr_all = -42 + 2 * (7 - vga_idx); /*VGA_idx = 7~5*/ | ||
109 | break; | ||
110 | case 4: | ||
111 | rx_pwr_all = -36 + 2 * (7 - vga_idx); /*VGA_idx = 7~4*/ | ||
112 | break; | ||
113 | case 3: | ||
114 | rx_pwr_all = -24 + 2 * (7 - vga_idx); /*VGA_idx = 7~0*/ | ||
115 | break; | ||
116 | case 2: | ||
117 | if (cck_hipwr) | ||
118 | rx_pwr_all = -12 + 2 * (5 - vga_idx); | ||
119 | else | ||
120 | rx_pwr_all = -6 + 2 * (5 - vga_idx); | ||
121 | break; | ||
122 | case 1: | ||
123 | rx_pwr_all = 8 - 2 * vga_idx; | ||
124 | break; | ||
125 | case 0: | ||
126 | rx_pwr_all = 14 - 2 * vga_idx; | ||
127 | break; | ||
128 | default: | ||
129 | break; | ||
130 | } | ||
131 | rx_pwr_all += 6; | ||
132 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); | ||
133 | /* CCK gain is smaller than OFDM/MCS gain, | ||
134 | * so we add gain diff by experiences, | ||
135 | * the val is 6 | ||
136 | */ | ||
137 | pwdb_all += 6; | ||
138 | if (pwdb_all > 100) | ||
139 | pwdb_all = 100; | ||
140 | /* modify the offset to make the same | ||
141 | * gain index with OFDM. | ||
142 | */ | ||
143 | if (pwdb_all > 34 && pwdb_all <= 42) | ||
144 | pwdb_all -= 2; | ||
145 | else if (pwdb_all > 26 && pwdb_all <= 34) | ||
146 | pwdb_all -= 6; | ||
147 | else if (pwdb_all > 14 && pwdb_all <= 26) | ||
148 | pwdb_all -= 8; | ||
149 | else if (pwdb_all > 4 && pwdb_all <= 14) | ||
150 | pwdb_all -= 4; | ||
151 | if (cck_hipwr == false) { | ||
152 | if (pwdb_all >= 80) | ||
153 | pwdb_all = ((pwdb_all - 80)<<1) + | ||
154 | ((pwdb_all - 80)>>1) + 80; | ||
155 | else if ((pwdb_all <= 78) && (pwdb_all >= 20)) | ||
156 | pwdb_all += 3; | ||
157 | if (pwdb_all > 100) | ||
158 | pwdb_all = 100; | ||
159 | } | ||
160 | |||
161 | pstatus->rx_pwdb_all = pwdb_all; | ||
162 | pstatus->recvsignalpower = rx_pwr_all; | ||
163 | |||
164 | /* (3) Get Signal Quality (EVM) */ | ||
165 | if (bpacket_match_bssid) { | ||
166 | u8 sq; | ||
167 | |||
168 | if (pstatus->rx_pwdb_all > 40) { | ||
169 | sq = 100; | ||
170 | } else { | ||
171 | sq = cck_buf->sq_rpt; | ||
172 | if (sq > 64) | ||
173 | sq = 0; | ||
174 | else if (sq < 20) | ||
175 | sq = 100; | ||
176 | else | ||
177 | sq = ((64 - sq) * 100) / 44; | ||
178 | } | ||
179 | |||
180 | pstatus->signalquality = sq; | ||
181 | pstatus->rx_mimo_sig_qual[0] = sq; | ||
182 | pstatus->rx_mimo_sig_qual[1] = -1; | ||
183 | } | ||
184 | } else { | ||
185 | rtlpriv->dm.rfpath_rxenable[0] = | ||
186 | rtlpriv->dm.rfpath_rxenable[1] = true; | ||
187 | |||
188 | /* (1)Get RSSI for HT rate */ | ||
189 | for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) { | ||
190 | /* we will judge RF RX path now. */ | ||
191 | if (rtlpriv->dm.rfpath_rxenable[i]) | ||
192 | rf_rx_num++; | ||
193 | |||
194 | rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f) * 2)-110; | ||
195 | |||
196 | /* Translate DBM to percentage. */ | ||
197 | rssi = rtl_query_rxpwrpercentage(rx_pwr[i]); | ||
198 | total_rssi += rssi; | ||
199 | |||
200 | /* Get Rx snr value in DB */ | ||
201 | rtlpriv->stats.rx_snr_db[i] = p_drvinfo->rxsnr[i] / 2; | ||
202 | |||
203 | /* Record Signal Strength for next packet */ | ||
204 | if (bpacket_match_bssid) | ||
205 | pstatus->rx_mimo_signalstrength[i] = (u8) rssi; | ||
206 | } | ||
207 | |||
208 | /* (2)PWDB, Average PWDB cacluated by | ||
209 | * hardware (for rate adaptive) | ||
210 | */ | ||
211 | rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110; | ||
212 | |||
213 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); | ||
214 | pstatus->rx_pwdb_all = pwdb_all; | ||
215 | pstatus->rxpower = rx_pwr_all; | ||
216 | pstatus->recvsignalpower = rx_pwr_all; | ||
217 | |||
218 | /* (3)EVM of HT rate */ | ||
219 | if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 && | ||
220 | pstatus->rate <= DESC92C_RATEMCS15) | ||
221 | max_spatial_stream = 2; | ||
222 | else | ||
223 | max_spatial_stream = 1; | ||
224 | |||
225 | for (i = 0; i < max_spatial_stream; i++) { | ||
226 | evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]); | ||
227 | |||
228 | if (bpacket_match_bssid) { | ||
229 | /* Fill value in RFD, Get the first | ||
230 | * spatial stream only | ||
231 | */ | ||
232 | if (i == 0) | ||
233 | pstatus->signalquality = evm & 0xff; | ||
234 | pstatus->rx_mimo_sig_qual[i] = evm & 0xff; | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | |||
239 | /* UI BSS List signal strength(in percentage), | ||
240 | * make it good looking, from 0~100. | ||
241 | */ | ||
242 | if (is_cck) | ||
243 | pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw, | ||
244 | pwdb_all)); | ||
245 | else if (rf_rx_num != 0) | ||
246 | pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw, | ||
247 | total_rssi /= rf_rx_num)); | ||
248 | /*HW antenna diversity*/ | ||
249 | rtldm->fat_table.antsel_rx_keep_0 = phystrpt->ant_sel; | ||
250 | rtldm->fat_table.antsel_rx_keep_1 = phystrpt->ant_sel_b; | ||
251 | rtldm->fat_table.antsel_rx_keep_2 = phystrpt->antsel_rx_keep_2; | ||
252 | } | ||
253 | |||
254 | static void _rtl88ee_smart_antenna(struct ieee80211_hw *hw, | ||
255 | struct rtl_stats *pstatus) | ||
256 | { | ||
257 | struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw)); | ||
258 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | ||
259 | u8 ant_mux; | ||
260 | struct fast_ant_training *pfat = &(rtldm->fat_table); | ||
261 | |||
262 | if (rtlefuse->antenna_div_type == CG_TRX_SMART_ANTDIV) { | ||
263 | if (pfat->fat_state == FAT_TRAINING_STATE) { | ||
264 | if (pstatus->packet_toself) { | ||
265 | ant_mux = (pfat->antsel_rx_keep_2 << 2) | | ||
266 | (pfat->antsel_rx_keep_1 << 1) | | ||
267 | pfat->antsel_rx_keep_0; | ||
268 | pfat->ant_sum[ant_mux] += pstatus->rx_pwdb_all; | ||
269 | pfat->ant_cnt[ant_mux]++; | ||
270 | } | ||
271 | } | ||
272 | } else if ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) || | ||
273 | (rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)) { | ||
274 | if (pstatus->packet_toself || pstatus->packet_matchbssid) { | ||
275 | ant_mux = (pfat->antsel_rx_keep_2 << 2) | | ||
276 | (pfat->antsel_rx_keep_1 << 1) | | ||
277 | pfat->antsel_rx_keep_0; | ||
278 | rtl88e_dm_ant_sel_statistics(hw, ant_mux, 0, | ||
279 | pstatus->rx_pwdb_all); | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | |||
284 | static void _rtl88ee_translate_rx_signal_stuff(struct ieee80211_hw *hw, | ||
285 | struct sk_buff *skb, struct rtl_stats *pstatus, | ||
286 | u8 *pdesc, struct rx_fwinfo_88e *p_drvinfo) | ||
287 | { | ||
288 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | ||
289 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | ||
290 | struct ieee80211_hdr *hdr; | ||
291 | u8 *tmp_buf; | ||
292 | u8 *praddr; | ||
293 | u8 *psaddr; | ||
294 | __le16 fc; | ||
295 | u16 type, ufc; | ||
296 | bool match_bssid, packet_toself, packet_beacon, addr; | ||
297 | |||
298 | tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift; | ||
299 | |||
300 | hdr = (struct ieee80211_hdr *)tmp_buf; | ||
301 | fc = hdr->frame_control; | ||
302 | ufc = le16_to_cpu(fc); | ||
303 | type = WLAN_FC_GET_TYPE(fc); | ||
304 | praddr = hdr->addr1; | ||
305 | psaddr = ieee80211_get_SA(hdr); | ||
306 | memcpy(pstatus->psaddr, psaddr, ETH_ALEN); | ||
307 | |||
308 | addr = (!compare_ether_addr(mac->bssid, (ufc & IEEE80211_FCTL_TODS) ? | ||
309 | hdr->addr1 : (ufc & IEEE80211_FCTL_FROMDS) ? | ||
310 | hdr->addr2 : hdr->addr3)); | ||
311 | match_bssid = ((IEEE80211_FTYPE_CTL != type) && (!pstatus->hwerror) && | ||
312 | (!pstatus->crc) && (!pstatus->icv)) && addr; | ||
313 | |||
314 | addr = (!compare_ether_addr(praddr, rtlefuse->dev_addr)); | ||
315 | packet_toself = match_bssid && addr; | ||
316 | |||
317 | if (ieee80211_is_beacon(fc)) | ||
318 | packet_beacon = true; | ||
319 | |||
320 | _rtl88ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo, | ||
321 | match_bssid, packet_toself, packet_beacon); | ||
322 | _rtl88ee_smart_antenna(hw, pstatus); | ||
323 | rtl_process_phyinfo(hw, tmp_buf, pstatus); | ||
324 | } | ||
325 | |||
326 | static void insert_em(struct rtl_tcb_desc *ptcb_desc, u8 *virtualaddress) | ||
327 | { | ||
328 | u32 dwtmp = 0; | ||
329 | |||
330 | memset(virtualaddress, 0, 8); | ||
331 | |||
332 | SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num); | ||
333 | if (ptcb_desc->empkt_num == 1) { | ||
334 | dwtmp = ptcb_desc->empkt_len[0]; | ||
335 | } else { | ||
336 | dwtmp = ptcb_desc->empkt_len[0]; | ||
337 | dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4; | ||
338 | dwtmp += ptcb_desc->empkt_len[1]; | ||
339 | } | ||
340 | SET_EARLYMODE_LEN0(virtualaddress, dwtmp); | ||
341 | |||
342 | if (ptcb_desc->empkt_num <= 3) { | ||
343 | dwtmp = ptcb_desc->empkt_len[2]; | ||
344 | } else { | ||
345 | dwtmp = ptcb_desc->empkt_len[2]; | ||
346 | dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4; | ||
347 | dwtmp += ptcb_desc->empkt_len[3]; | ||
348 | } | ||
349 | SET_EARLYMODE_LEN1(virtualaddress, dwtmp); | ||
350 | if (ptcb_desc->empkt_num <= 5) { | ||
351 | dwtmp = ptcb_desc->empkt_len[4]; | ||
352 | } else { | ||
353 | dwtmp = ptcb_desc->empkt_len[4]; | ||
354 | dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4; | ||
355 | dwtmp += ptcb_desc->empkt_len[5]; | ||
356 | } | ||
357 | SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF); | ||
358 | SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4); | ||
359 | if (ptcb_desc->empkt_num <= 7) { | ||
360 | dwtmp = ptcb_desc->empkt_len[6]; | ||
361 | } else { | ||
362 | dwtmp = ptcb_desc->empkt_len[6]; | ||
363 | dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4; | ||
364 | dwtmp += ptcb_desc->empkt_len[7]; | ||
365 | } | ||
366 | SET_EARLYMODE_LEN3(virtualaddress, dwtmp); | ||
367 | if (ptcb_desc->empkt_num <= 9) { | ||
368 | dwtmp = ptcb_desc->empkt_len[8]; | ||
369 | } else { | ||
370 | dwtmp = ptcb_desc->empkt_len[8]; | ||
371 | dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4; | ||
372 | dwtmp += ptcb_desc->empkt_len[9]; | ||
373 | } | ||
374 | SET_EARLYMODE_LEN4(virtualaddress, dwtmp); | ||
375 | } | ||
376 | |||
377 | bool rtl88ee_rx_query_desc(struct ieee80211_hw *hw, | ||
378 | struct rtl_stats *status, | ||
379 | struct ieee80211_rx_status *rx_status, | ||
380 | u8 *pdesc, struct sk_buff *skb) | ||
381 | { | ||
382 | struct rtl_priv *rtlpriv = rtl_priv(hw); | ||
383 | struct rx_fwinfo_88e *p_drvinfo; | ||
384 | struct ieee80211_hdr *hdr; | ||
385 | |||
386 | u32 phystatus = GET_RX_DESC_PHYST(pdesc); | ||
387 | status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc); | ||
388 | if (status->packet_report_type == TX_REPORT2) | ||
389 | status->length = (u16) GET_RX_RPT2_DESC_PKT_LEN(pdesc); | ||
390 | else | ||
391 | status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc); | ||
392 | status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) * | ||
393 | RX_DRV_INFO_SIZE_UNIT; | ||
394 | status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03); | ||
395 | status->icv = (u16) GET_RX_DESC_ICV(pdesc); | ||
396 | status->crc = (u16) GET_RX_DESC_CRC32(pdesc); | ||
397 | status->hwerror = (status->crc | status->icv); | ||
398 | status->decrypted = !GET_RX_DESC_SWDEC(pdesc); | ||
399 | status->rate = (u8) GET_RX_DESC_RXMCS(pdesc); | ||
400 | status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc); | ||
401 | status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1); | ||
402 | status->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1) && | ||
403 | (GET_RX_DESC_FAGGR(pdesc) == 1)); | ||
404 | if (status->packet_report_type == NORMAL_RX) | ||
405 | status->timestamp_low = GET_RX_DESC_TSFL(pdesc); | ||
406 | status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc); | ||
407 | status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc); | ||
408 | |||
409 | status->is_cck = RTL8188_RX_HAL_IS_CCK_RATE(status->rate); | ||
410 | |||
411 | status->macid = GET_RX_DESC_MACID(pdesc); | ||
412 | if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc)) | ||
413 | status->wake_match = BIT(2); | ||
414 | else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc)) | ||
415 | status->wake_match = BIT(1); | ||
416 | else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc)) | ||
417 | status->wake_match = BIT(0); | ||
418 | else | ||
419 | status->wake_match = 0; | ||
420 | if (status->wake_match) | ||
421 | RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD, | ||
422 | "Get Wakeup Packet!! WakeMatch =%d\n", | ||
423 | status->wake_match); | ||
424 | rx_status->freq = hw->conf.channel->center_freq; | ||
425 | rx_status->band = hw->conf.channel->band; | ||
426 | |||
427 | if (status->crc) | ||
428 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; | ||
429 | |||
430 | if (status->rx_is40Mhzpacket) | ||
431 | rx_status->flag |= RX_FLAG_40MHZ; | ||
432 | |||
433 | if (status->is_ht) | ||
434 | rx_status->flag |= RX_FLAG_HT; | ||
435 | |||
436 | rx_status->flag |= RX_FLAG_MACTIME_START; | ||
437 | |||
438 | /* hw will set status->decrypted true, if it finds the | ||
439 | * frame is open data frame or mgmt frame. | ||
440 | * So hw will not decryption robust managment frame | ||
441 | * for IEEE80211w but still set status->decrypted | ||
442 | * true, so here we should set it back to undecrypted | ||
443 | * for IEEE80211w frame, and mac80211 sw will help | ||
444 | * to decrypt it | ||
445 | */ | ||
446 | if (status->decrypted) { | ||
447 | hdr = (struct ieee80211_hdr *)(skb->data + | ||
448 | status->rx_drvinfo_size + status->rx_bufshift); | ||
449 | |||
450 | if (!hdr) { | ||
451 | /* During testing, hdr was NULL */ | ||
452 | return false; | ||
453 | } | ||
454 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && | ||
455 | (ieee80211_has_protected(hdr->frame_control))) | ||
456 | rx_status->flag &= ~RX_FLAG_DECRYPTED; | ||
457 | else | ||
458 | rx_status->flag |= RX_FLAG_DECRYPTED; | ||
459 | } | ||
460 | |||
461 | /* rate_idx: index of data rate into band's | ||
462 | * supported rates or MCS index if HT rates | ||
463 | * are use (RX_FLAG_HT) | ||
464 | * Notice: this is diff with windows define | ||
465 | */ | ||
466 | rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht, | ||
467 | status->rate, false); | ||
468 | |||
469 | rx_status->mactime = status->timestamp_low; | ||
470 | if (phystatus == true) { | ||
471 | p_drvinfo = (struct rx_fwinfo_88e *)(skb->data + | ||
472 | status->rx_bufshift); | ||
473 | |||
474 | _rtl88ee_translate_rx_signal_stuff(hw, skb, status, pdesc, | ||
475 | p_drvinfo); | ||
476 | } | ||
477 | |||
478 | /*rx_status->qual = status->signal; */ | ||
479 | rx_status->signal = status->recvsignalpower + 10; | ||
480 | /*rx_status->noise = -status->noise; */ | ||
481 | if (status->packet_report_type == TX_REPORT2) { | ||
482 | status->macid_valid_entry[0] = | ||
483 | GET_RX_RPT2_DESC_MACID_VALID_1(pdesc); | ||
484 | status->macid_valid_entry[1] = | ||
485 | GET_RX_RPT2_DESC_MACID_VALID_2(pdesc); | ||
486 | } | ||
487 | return true; | ||
488 | } | ||
489 | |||
490 | void rtl88ee_tx_fill_desc(struct ieee80211_hw *hw, | ||
491 | struct ieee80211_hdr *hdr, u8 *pdesc_tx, | ||
492 | struct ieee80211_tx_info *info, | ||
493 | struct ieee80211_sta *sta, | ||
494 | struct sk_buff *skb, | ||
495 | u8 hw_queue, struct rtl_tcb_desc *ptcb_desc) | ||
496 | { | ||
497 | struct rtl_priv *rtlpriv = rtl_priv(hw); | ||
498 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | ||
499 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); | ||
500 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); | ||
501 | u8 *pdesc = (u8 *)pdesc_tx; | ||
502 | u16 seq_number; | ||
503 | __le16 fc = hdr->frame_control; | ||
504 | unsigned int buf_len = 0; | ||
505 | unsigned int skb_len = skb->len; | ||
506 | u8 fw_qsel = _rtl88ee_map_hwqueue_to_fwqueue(skb, hw_queue); | ||
507 | bool firstseg = ((hdr->seq_ctrl & | ||
508 | cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0); | ||
509 | bool lastseg = ((hdr->frame_control & | ||
510 | cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0); | ||
511 | dma_addr_t mapping; | ||
512 | u8 bw_40 = 0; | ||
513 | u8 short_gi = 0; | ||
514 | |||
515 | if (mac->opmode == NL80211_IFTYPE_STATION) { | ||
516 | bw_40 = mac->bw_40; | ||
517 | } else if (mac->opmode == NL80211_IFTYPE_AP || | ||
518 | mac->opmode == NL80211_IFTYPE_ADHOC) { | ||
519 | if (sta) | ||
520 | bw_40 = sta->ht_cap.cap & | ||
521 | IEEE80211_HT_CAP_SUP_WIDTH_20_40; | ||
522 | } | ||
523 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; | ||
524 | rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc); | ||
525 | /* reserve 8 byte for AMPDU early mode */ | ||
526 | if (rtlhal->earlymode_enable) { | ||
527 | skb_push(skb, EM_HDR_LEN); | ||
528 | memset(skb->data, 0, EM_HDR_LEN); | ||
529 | } | ||
530 | buf_len = skb->len; | ||
531 | mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len, | ||
532 | PCI_DMA_TODEVICE); | ||
533 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { | ||
534 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | ||
535 | "DMA mapping error"); | ||
536 | return; | ||
537 | } | ||
538 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_88e)); | ||
539 | if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) { | ||
540 | firstseg = true; | ||
541 | lastseg = true; | ||
542 | } | ||
543 | if (firstseg) { | ||
544 | if (rtlhal->earlymode_enable) { | ||
545 | SET_TX_DESC_PKT_OFFSET(pdesc, 1); | ||
546 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN + | ||
547 | EM_HDR_LEN); | ||
548 | if (ptcb_desc->empkt_num) { | ||
549 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | ||
550 | "Insert 8 byte.pTcb->EMPktNum:%d\n", | ||
551 | ptcb_desc->empkt_num); | ||
552 | insert_em(ptcb_desc, (u8 *)(skb->data)); | ||
553 | } | ||
554 | } else { | ||
555 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); | ||
556 | } | ||
557 | |||
558 | ptcb_desc->use_driver_rate = true; | ||
559 | SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate); | ||
560 | if (ptcb_desc->hw_rate > DESC92C_RATEMCS0) | ||
561 | short_gi = (ptcb_desc->use_shortgi) ? 1 : 0; | ||
562 | else | ||
563 | short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0; | ||
564 | SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi); | ||
565 | |||
566 | if (info->flags & IEEE80211_TX_CTL_AMPDU) { | ||
567 | SET_TX_DESC_AGG_ENABLE(pdesc, 1); | ||
568 | SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14); | ||
569 | } | ||
570 | SET_TX_DESC_SEQ(pdesc, seq_number); | ||
571 | SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable && | ||
572 | !ptcb_desc->cts_enable) ? 1 : 0)); | ||
573 | SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0); | ||
574 | SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ? 1 : 0)); | ||
575 | SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0)); | ||
576 | |||
577 | SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate); | ||
578 | SET_TX_DESC_RTS_BW(pdesc, 0); | ||
579 | SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc); | ||
580 | SET_TX_DESC_RTS_SHORT(pdesc, | ||
581 | ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ? | ||
582 | (ptcb_desc->rts_use_shortpreamble ? 1 : 0) : | ||
583 | (ptcb_desc->rts_use_shortgi ? 1 : 0))); | ||
584 | |||
585 | if (ptcb_desc->btx_enable_sw_calc_duration) | ||
586 | SET_TX_DESC_NAV_USE_HDR(pdesc, 1); | ||
587 | |||
588 | if (bw_40) { | ||
589 | if (ptcb_desc->packet_bw) { | ||
590 | SET_TX_DESC_DATA_BW(pdesc, 1); | ||
591 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3); | ||
592 | } else { | ||
593 | SET_TX_DESC_DATA_BW(pdesc, 0); | ||
594 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, | ||
595 | mac->cur_40_prime_sc); | ||
596 | } | ||
597 | } else { | ||
598 | SET_TX_DESC_DATA_BW(pdesc, 0); | ||
599 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0); | ||
600 | } | ||
601 | |||
602 | SET_TX_DESC_LINIP(pdesc, 0); | ||
603 | SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len); | ||
604 | if (sta) { | ||
605 | u8 ampdu_density = sta->ht_cap.ampdu_density; | ||
606 | SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density); | ||
607 | } | ||
608 | if (info->control.hw_key) { | ||
609 | struct ieee80211_key_conf *keyconf; | ||
610 | keyconf = info->control.hw_key; | ||
611 | switch (keyconf->cipher) { | ||
612 | case WLAN_CIPHER_SUITE_WEP40: | ||
613 | case WLAN_CIPHER_SUITE_WEP104: | ||
614 | case WLAN_CIPHER_SUITE_TKIP: | ||
615 | SET_TX_DESC_SEC_TYPE(pdesc, 0x1); | ||
616 | break; | ||
617 | case WLAN_CIPHER_SUITE_CCMP: | ||
618 | SET_TX_DESC_SEC_TYPE(pdesc, 0x3); | ||
619 | break; | ||
620 | default: | ||
621 | SET_TX_DESC_SEC_TYPE(pdesc, 0x0); | ||
622 | break; | ||
623 | } | ||
624 | } | ||
625 | |||
626 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel); | ||
627 | SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F); | ||
628 | SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF); | ||
629 | SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ? | ||
630 | 1 : 0); | ||
631 | SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0); | ||
632 | |||
633 | /* Set TxRate and RTSRate in TxDesc */ | ||
634 | /* This prevent Tx initial rate of new-coming packets */ | ||
635 | /* from being overwritten by retried packet rate.*/ | ||
636 | if (!ptcb_desc->use_driver_rate) { | ||
637 | /*SET_TX_DESC_RTS_RATE(pdesc, 0x08); */ | ||
638 | /* SET_TX_DESC_TX_RATE(pdesc, 0x0b); */ | ||
639 | } | ||
640 | if (ieee80211_is_data_qos(fc)) { | ||
641 | if (mac->rdg_en) { | ||
642 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | ||
643 | "Enable RDG function.\n"); | ||
644 | SET_TX_DESC_RDG_ENABLE(pdesc, 1); | ||
645 | SET_TX_DESC_HTC(pdesc, 1); | ||
646 | } | ||
647 | } | ||
648 | } | ||
649 | |||
650 | SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0)); | ||
651 | SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0)); | ||
652 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len); | ||
653 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); | ||
654 | if (rtlpriv->dm.useramask) { | ||
655 | SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index); | ||
656 | SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id); | ||
657 | } else { | ||
658 | SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcb_desc->ratr_index); | ||
659 | SET_TX_DESC_MACID(pdesc, ptcb_desc->ratr_index); | ||
660 | } | ||
661 | if (ieee80211_is_data_qos(fc)) | ||
662 | SET_TX_DESC_QOS(pdesc, 1); | ||
663 | |||
664 | if (!ieee80211_is_data_qos(fc)) | ||
665 | SET_TX_DESC_HWSEQ_EN(pdesc, 1); | ||
666 | SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1)); | ||
667 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) || | ||
668 | is_broadcast_ether_addr(ieee80211_get_DA(hdr))) | ||
669 | SET_TX_DESC_BMC(pdesc, 1); | ||
670 | |||
671 | rtl88e_dm_set_tx_ant_by_tx_info(hw, pdesc, ptcb_desc->mac_id); | ||
672 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n"); | ||
673 | } | ||
674 | |||
675 | void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw, | ||
676 | u8 *pdesc, bool firstseg, | ||
677 | bool lastseg, struct sk_buff *skb) | ||
678 | { | ||
679 | struct rtl_priv *rtlpriv = rtl_priv(hw); | ||
680 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); | ||
681 | u8 fw_queue = QSLT_BEACON; | ||
682 | |||
683 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, | ||
684 | skb->data, skb->len, | ||
685 | PCI_DMA_TODEVICE); | ||
686 | |||
687 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); | ||
688 | __le16 fc = hdr->frame_control; | ||
689 | |||
690 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { | ||
691 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | ||
692 | "DMA mapping error"); | ||
693 | return; | ||
694 | } | ||
695 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE); | ||
696 | |||
697 | if (firstseg) | ||
698 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); | ||
699 | |||
700 | SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M); | ||
701 | |||
702 | SET_TX_DESC_SEQ(pdesc, 0); | ||
703 | |||
704 | SET_TX_DESC_LINIP(pdesc, 0); | ||
705 | |||
706 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue); | ||
707 | |||
708 | SET_TX_DESC_FIRST_SEG(pdesc, 1); | ||
709 | SET_TX_DESC_LAST_SEG(pdesc, 1); | ||
710 | |||
711 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len)); | ||
712 | |||
713 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); | ||
714 | |||
715 | SET_TX_DESC_RATE_ID(pdesc, 7); | ||
716 | SET_TX_DESC_MACID(pdesc, 0); | ||
717 | |||
718 | SET_TX_DESC_OWN(pdesc, 1); | ||
719 | |||
720 | SET_TX_DESC_PKT_SIZE((u8 *)pdesc, (u16)(skb->len)); | ||
721 | |||
722 | SET_TX_DESC_FIRST_SEG(pdesc, 1); | ||
723 | SET_TX_DESC_LAST_SEG(pdesc, 1); | ||
724 | |||
725 | SET_TX_DESC_OFFSET(pdesc, 0x20); | ||
726 | |||
727 | SET_TX_DESC_USE_RATE(pdesc, 1); | ||
728 | |||
729 | if (!ieee80211_is_data_qos(fc)) | ||
730 | SET_TX_DESC_HWSEQ_EN(pdesc, 1); | ||
731 | |||
732 | RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD, | ||
733 | "H2C Tx Cmd Content\n", | ||
734 | pdesc, TX_DESC_SIZE); | ||
735 | } | ||
736 | |||
737 | void rtl88ee_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val) | ||
738 | { | ||
739 | if (istx == true) { | ||
740 | switch (desc_name) { | ||
741 | case HW_DESC_OWN: | ||
742 | SET_TX_DESC_OWN(pdesc, 1); | ||
743 | break; | ||
744 | case HW_DESC_TX_NEXTDESC_ADDR: | ||
745 | SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val); | ||
746 | break; | ||
747 | default: | ||
748 | RT_ASSERT(false, "ERR txdesc :%d not processed\n", | ||
749 | desc_name); | ||
750 | break; | ||
751 | } | ||
752 | } else { | ||
753 | switch (desc_name) { | ||
754 | case HW_DESC_RXOWN: | ||
755 | SET_RX_DESC_OWN(pdesc, 1); | ||
756 | break; | ||
757 | case HW_DESC_RXBUFF_ADDR: | ||
758 | SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val); | ||
759 | break; | ||
760 | case HW_DESC_RXPKT_LEN: | ||
761 | SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val); | ||
762 | break; | ||
763 | case HW_DESC_RXERO: | ||
764 | SET_RX_DESC_EOR(pdesc, 1); | ||
765 | break; | ||
766 | default: | ||
767 | RT_ASSERT(false, "ERR rxdesc :%d not processed\n", | ||
768 | desc_name); | ||
769 | break; | ||
770 | } | ||
771 | } | ||
772 | } | ||
773 | |||
774 | u32 rtl88ee_get_desc(u8 *pdesc, bool istx, u8 desc_name) | ||
775 | { | ||
776 | u32 ret = 0; | ||
777 | |||
778 | if (istx == true) { | ||
779 | switch (desc_name) { | ||
780 | case HW_DESC_OWN: | ||
781 | ret = GET_TX_DESC_OWN(pdesc); | ||
782 | break; | ||
783 | case HW_DESC_TXBUFF_ADDR: | ||
784 | ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc); | ||
785 | break; | ||
786 | default: | ||
787 | RT_ASSERT(false, "ERR txdesc :%d not processed\n", | ||
788 | desc_name); | ||
789 | break; | ||
790 | } | ||
791 | } else { | ||
792 | switch (desc_name) { | ||
793 | case HW_DESC_OWN: | ||
794 | ret = GET_RX_DESC_OWN(pdesc); | ||
795 | break; | ||
796 | case HW_DESC_RXPKT_LEN: | ||
797 | ret = GET_RX_DESC_PKT_LEN(pdesc); | ||
798 | break; | ||
799 | default: | ||
800 | RT_ASSERT(false, "ERR rxdesc :%d not processed\n", | ||
801 | desc_name); | ||
802 | break; | ||
803 | } | ||
804 | } | ||
805 | return ret; | ||
806 | } | ||
807 | |||
808 | void rtl88ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue) | ||
809 | { | ||
810 | struct rtl_priv *rtlpriv = rtl_priv(hw); | ||
811 | if (hw_queue == BEACON_QUEUE) { | ||
812 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4)); | ||
813 | } else { | ||
814 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, | ||
815 | BIT(0) << (hw_queue)); | ||
816 | } | ||
817 | } | ||