Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/ide
[deliverable/linux.git] / drivers / net / wireless / rtlwifi / rtl8723be / trx.c
CommitLineData
a619d1ab
LF
1/******************************************************************************
2 *
3 * Copyright(c) 2009-2014 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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
16 *
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
21 *
22 * Larry Finger <Larry.Finger@lwfinger.net>
23 *
24 *****************************************************************************/
25
26#include "../wifi.h"
27#include "../pci.h"
28#include "../base.h"
29#include "../stats.h"
30#include "reg.h"
31#include "def.h"
32#include "phy.h"
33#include "trx.h"
34#include "led.h"
35#include "dm.h"
a619d1ab
LF
36
37static u8 _rtl8723be_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
38{
39 __le16 fc = rtl_get_fc(skb);
40
41 if (unlikely(ieee80211_is_beacon(fc)))
42 return QSLT_BEACON;
43 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
44 return QSLT_MGNT;
45
46 return skb->priority;
47}
48
49/* mac80211's rate_idx is like this:
50 *
51 * 2.4G band:rx_status->band == IEEE80211_BAND_2GHZ
52 *
53 * B/G rate:
54 * (rx_status->flag & RX_FLAG_HT) = 0,
55 * DESC92C_RATE1M-->DESC92C_RATE54M ==> idx is 0-->11,
56 *
57 * N rate:
58 * (rx_status->flag & RX_FLAG_HT) = 1,
59 * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
60 *
61 * 5G band:rx_status->band == IEEE80211_BAND_5GHZ
62 * A rate:
63 * (rx_status->flag & RX_FLAG_HT) = 0,
64 * DESC92C_RATE6M-->DESC92C_RATE54M ==> idx is 0-->7,
65 *
66 * N rate:
67 * (rx_status->flag & RX_FLAG_HT) = 1,
68 * DESC92C_RATEMCS0-->DESC92C_RATEMCS15 ==> idx is 0-->15
69 */
70static int _rtl8723be_rate_mapping(struct ieee80211_hw *hw,
71 bool isht, u8 desc_rate)
72{
73 int rate_idx;
74
75 if (!isht) {
76 if (IEEE80211_BAND_2GHZ == hw->conf.chandef.chan->band) {
77 switch (desc_rate) {
78 case DESC92C_RATE1M:
79 rate_idx = 0;
80 break;
81 case DESC92C_RATE2M:
82 rate_idx = 1;
83 break;
84 case DESC92C_RATE5_5M:
85 rate_idx = 2;
86 break;
87 case DESC92C_RATE11M:
88 rate_idx = 3;
89 break;
90 case DESC92C_RATE6M:
91 rate_idx = 4;
92 break;
93 case DESC92C_RATE9M:
94 rate_idx = 5;
95 break;
96 case DESC92C_RATE12M:
97 rate_idx = 6;
98 break;
99 case DESC92C_RATE18M:
100 rate_idx = 7;
101 break;
102 case DESC92C_RATE24M:
103 rate_idx = 8;
104 break;
105 case DESC92C_RATE36M:
106 rate_idx = 9;
107 break;
108 case DESC92C_RATE48M:
109 rate_idx = 10;
110 break;
111 case DESC92C_RATE54M:
112 rate_idx = 11;
113 break;
114 default:
115 rate_idx = 0;
116 break;
117 }
118 } else {
119 switch (desc_rate) {
120 case DESC92C_RATE6M:
121 rate_idx = 0;
122 break;
123 case DESC92C_RATE9M:
124 rate_idx = 1;
125 break;
126 case DESC92C_RATE12M:
127 rate_idx = 2;
128 break;
129 case DESC92C_RATE18M:
130 rate_idx = 3;
131 break;
132 case DESC92C_RATE24M:
133 rate_idx = 4;
134 break;
135 case DESC92C_RATE36M:
136 rate_idx = 5;
137 break;
138 case DESC92C_RATE48M:
139 rate_idx = 6;
140 break;
141 case DESC92C_RATE54M:
142 rate_idx = 7;
143 break;
144 default:
145 rate_idx = 0;
146 break;
147 }
148 }
149 } else {
150 switch (desc_rate) {
151 case DESC92C_RATEMCS0:
152 rate_idx = 0;
153 break;
154 case DESC92C_RATEMCS1:
155 rate_idx = 1;
156 break;
157 case DESC92C_RATEMCS2:
158 rate_idx = 2;
159 break;
160 case DESC92C_RATEMCS3:
161 rate_idx = 3;
162 break;
163 case DESC92C_RATEMCS4:
164 rate_idx = 4;
165 break;
166 case DESC92C_RATEMCS5:
167 rate_idx = 5;
168 break;
169 case DESC92C_RATEMCS6:
170 rate_idx = 6;
171 break;
172 case DESC92C_RATEMCS7:
173 rate_idx = 7;
174 break;
175 case DESC92C_RATEMCS8:
176 rate_idx = 8;
177 break;
178 case DESC92C_RATEMCS9:
179 rate_idx = 9;
180 break;
181 case DESC92C_RATEMCS10:
182 rate_idx = 10;
183 break;
184 case DESC92C_RATEMCS11:
185 rate_idx = 11;
186 break;
187 case DESC92C_RATEMCS12:
188 rate_idx = 12;
189 break;
190 case DESC92C_RATEMCS13:
191 rate_idx = 13;
192 break;
193 case DESC92C_RATEMCS14:
194 rate_idx = 14;
195 break;
196 case DESC92C_RATEMCS15:
197 rate_idx = 15;
198 break;
199 default:
200 rate_idx = 0;
201 break;
202 }
203 }
204 return rate_idx;
205}
206
207static void _rtl8723be_query_rxphystatus(struct ieee80211_hw *hw,
208 struct rtl_stats *pstatus, u8 *pdesc,
209 struct rx_fwinfo_8723be *p_drvinfo,
210 bool packet_match_bssid,
211 bool packet_toself,
212 bool packet_beacon)
213{
214 struct rtl_priv *rtlpriv = rtl_priv(hw);
215 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
216 struct phy_sts_cck_8723e_t *cck_buf;
217 struct phy_status_rpt *p_phystrpt = (struct phy_status_rpt *)p_drvinfo;
218 struct rtl_dm *rtldm = rtl_dm(rtl_priv(hw));
219 char rx_pwr_all = 0, rx_pwr[4];
220 u8 rf_rx_num = 0, evm, pwdb_all;
221 u8 i, max_spatial_stream;
222 u32 rssi, total_rssi = 0;
223 bool is_cck = pstatus->is_cck;
224 u8 lan_idx, vga_idx;
225
226 /* Record it for next packet processing */
227 pstatus->packet_matchbssid = packet_match_bssid;
228 pstatus->packet_toself = packet_toself;
229 pstatus->packet_beacon = packet_beacon;
230 pstatus->rx_mimo_sig_qual[0] = -1;
231 pstatus->rx_mimo_sig_qual[1] = -1;
232
233 if (is_cck) {
234 u8 cck_highpwr;
235 u8 cck_agc_rpt;
236 /* CCK Driver info Structure is not the same as OFDM packet. */
237 cck_buf = (struct phy_sts_cck_8723e_t *)p_drvinfo;
238 cck_agc_rpt = cck_buf->cck_agc_rpt;
239
240 /* (1)Hardware does not provide RSSI for CCK
241 * (2)PWDB, Average PWDB cacluated by
242 * hardware (for rate adaptive)
243 */
244 if (ppsc->rfpwr_state == ERFON)
245 cck_highpwr = (u8) rtl_get_bbreg(hw,
246 RFPGA0_XA_HSSIPARAMETER2,
247 BIT(9));
248 else
249 cck_highpwr = false;
250
251 lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
252 vga_idx = (cck_agc_rpt & 0x1f);
253 switch (lan_idx) {
254 case 7:
255 if (vga_idx <= 27)/*VGA_idx = 27~2*/
256 rx_pwr_all = -100 + 2 * (27 - vga_idx);
257 else
258 rx_pwr_all = -100;
259 break;
260 case 6:/*VGA_idx = 2~0*/
261 rx_pwr_all = -48 + 2 * (2 - vga_idx);
262 break;
263 case 5:/*VGA_idx = 7~5*/
264 rx_pwr_all = -42 + 2 * (7 - vga_idx);
265 break;
266 case 4:/*VGA_idx = 7~4*/
267 rx_pwr_all = -36 + 2 * (7 - vga_idx);
268 break;
269 case 3:/*VGA_idx = 7~0*/
270 rx_pwr_all = -24 + 2 * (7 - vga_idx);
271 break;
272 case 2:
273 if (cck_highpwr)/*VGA_idx = 5~0*/
274 rx_pwr_all = -12 + 2 * (5 - vga_idx);
275 else
276 rx_pwr_all = -6 + 2 * (5 - vga_idx);
277 break;
278 case 1:
279 rx_pwr_all = 8 - 2 * vga_idx;
280 break;
281 case 0:
282 rx_pwr_all = 14 - 2 * vga_idx;
283 break;
284 default:
285 break;
286 }
287 rx_pwr_all += 6;
288 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
289 /* CCK gain is smaller than OFDM/MCS gain, */
290 /* so we add gain diff by experiences,
291 * the val is 6
292 */
293 pwdb_all += 6;
294 if (pwdb_all > 100)
295 pwdb_all = 100;
296 /* modify the offset to make the same gain index with OFDM. */
297 if (pwdb_all > 34 && pwdb_all <= 42)
298 pwdb_all -= 2;
299 else if (pwdb_all > 26 && pwdb_all <= 34)
300 pwdb_all -= 6;
301 else if (pwdb_all > 14 && pwdb_all <= 26)
302 pwdb_all -= 8;
303 else if (pwdb_all > 4 && pwdb_all <= 14)
304 pwdb_all -= 4;
305 if (!cck_highpwr) {
306 if (pwdb_all >= 80)
307 pwdb_all = ((pwdb_all - 80) << 1) +
308 ((pwdb_all - 80) >> 1) + 80;
309 else if ((pwdb_all <= 78) && (pwdb_all >= 20))
310 pwdb_all += 3;
311 if (pwdb_all > 100)
312 pwdb_all = 100;
313 }
314
315 pstatus->rx_pwdb_all = pwdb_all;
316 pstatus->recvsignalpower = rx_pwr_all;
317
318 /* (3) Get Signal Quality (EVM) */
319 if (packet_match_bssid) {
320 u8 sq;
321
322 if (pstatus->rx_pwdb_all > 40) {
323 sq = 100;
324 } else {
325 sq = cck_buf->sq_rpt;
326 if (sq > 64)
327 sq = 0;
328 else if (sq < 20)
329 sq = 100;
330 else
331 sq = ((64 - sq) * 100) / 44;
332 }
333
334 pstatus->signalquality = sq;
335 pstatus->rx_mimo_sig_qual[0] = sq;
336 pstatus->rx_mimo_sig_qual[1] = -1;
337 }
338 } else {
339 rtlpriv->dm.rfpath_rxenable[0] = true;
340 rtlpriv->dm.rfpath_rxenable[1] = true;
341
342 /* (1)Get RSSI for HT rate */
343 for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
344 /* we will judge RF RX path now. */
345 if (rtlpriv->dm.rfpath_rxenable[i])
346 rf_rx_num++;
347
348 rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f)*2) - 110;
349
350 /* Translate DBM to percentage. */
351 rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
352 total_rssi += rssi;
353
354 /* Get Rx snr value in DB */
355 rtlpriv->stats.rx_snr_db[i] =
356 (long)(p_drvinfo->rxsnr[i] / 2);
357
358 /* Record Signal Strength for next packet */
359 if (packet_match_bssid)
360 pstatus->rx_mimo_signalstrength[i] = (u8) rssi;
361 }
362
363 /* (2)PWDB, Avg cacluated by hardware (for rate adaptive) */
364 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
365
366 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
367 pstatus->rx_pwdb_all = pwdb_all;
368 pstatus->rxpower = rx_pwr_all;
369 pstatus->recvsignalpower = rx_pwr_all;
370
371 /* (3)EVM of HT rate */
372 if (pstatus->is_ht && pstatus->rate >= DESC92C_RATEMCS8 &&
373 pstatus->rate <= DESC92C_RATEMCS15)
374 max_spatial_stream = 2;
375 else
376 max_spatial_stream = 1;
377
378 for (i = 0; i < max_spatial_stream; i++) {
379 evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]);
380
381 if (packet_match_bssid) {
382 /* Fill value in RFD, Get the first
383 * spatial stream only
384 */
385 if (i == 0)
386 pstatus->signalquality =
387 (u8) (evm & 0xff);
388 pstatus->rx_mimo_sig_qual[i] =
389 (u8) (evm & 0xff);
390 }
391 }
392 if (packet_match_bssid) {
393 for (i = RF90_PATH_A; i <= RF90_PATH_B; i++)
394 rtl_priv(hw)->dm.cfo_tail[i] =
395 (char)p_phystrpt->path_cfotail[i];
396
397 rtl_priv(hw)->dm.packet_count++;
398 if (rtl_priv(hw)->dm.packet_count == 0xffffffff)
399 rtl_priv(hw)->dm.packet_count = 0;
400 }
401 }
402
403 /* UI BSS List signal strength(in percentage),
404 * make it good looking, from 0~100.
405 */
406 if (is_cck)
407 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
408 pwdb_all));
409 else if (rf_rx_num != 0)
410 pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
411 total_rssi /= rf_rx_num));
412 /*HW antenna diversity*/
413 rtldm->fat_table.antsel_rx_keep_0 = p_phystrpt->ant_sel;
414 rtldm->fat_table.antsel_rx_keep_1 = p_phystrpt->ant_sel_b;
415 rtldm->fat_table.antsel_rx_keep_2 = p_phystrpt->antsel_rx_keep_2;
416}
417
418static void _rtl8723be_translate_rx_signal_stuff(struct ieee80211_hw *hw,
419 struct sk_buff *skb,
420 struct rtl_stats *pstatus,
421 u8 *pdesc,
422 struct rx_fwinfo_8723be *p_drvinfo)
423{
424 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
425 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
426 struct ieee80211_hdr *hdr;
427 u8 *tmp_buf;
428 u8 *praddr;
429 u8 *psaddr;
430 u16 fc, type;
431 bool packet_matchbssid, packet_toself, packet_beacon;
432
433 tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift;
434
435 hdr = (struct ieee80211_hdr *)tmp_buf;
436 fc = le16_to_cpu(hdr->frame_control);
437 type = WLAN_FC_GET_TYPE(hdr->frame_control);
438 praddr = hdr->addr1;
439 psaddr = ieee80211_get_SA(hdr);
440 memcpy(pstatus->psaddr, psaddr, ETH_ALEN);
441
442 packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
443 (!ether_addr_equal(mac->bssid, (fc & IEEE80211_FCTL_TODS) ?
444 hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ?
445 hdr->addr2 : hdr->addr3)) &&
446 (!pstatus->hwerror) &&
447 (!pstatus->crc) && (!pstatus->icv));
448
449 packet_toself = packet_matchbssid &&
450 (!ether_addr_equal(praddr, rtlefuse->dev_addr));
451
452 /* YP: packet_beacon is not initialized,
453 * this assignment is neccesary,
454 * otherwise it counld be true in this case
455 * the situation is much worse in Kernel 3.10
456 */
457 if (ieee80211_is_beacon(hdr->frame_control))
458 packet_beacon = true;
459 else
460 packet_beacon = false;
461
462 if (packet_beacon && packet_matchbssid)
463 rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
464
465 _rtl8723be_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
466 packet_matchbssid,
467 packet_toself,
468 packet_beacon);
469
470 rtl_process_phyinfo(hw, tmp_buf, pstatus);
471}
472
473static void _rtl8723be_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
474 u8 *virtualaddress)
475{
476 u32 dwtmp = 0;
477 memset(virtualaddress, 0, 8);
478
479 SET_EARLYMODE_PKTNUM(virtualaddress, ptcb_desc->empkt_num);
480 if (ptcb_desc->empkt_num == 1) {
481 dwtmp = ptcb_desc->empkt_len[0];
482 } else {
483 dwtmp = ptcb_desc->empkt_len[0];
484 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
485 dwtmp += ptcb_desc->empkt_len[1];
486 }
487 SET_EARLYMODE_LEN0(virtualaddress, dwtmp);
488
489 if (ptcb_desc->empkt_num <= 3) {
490 dwtmp = ptcb_desc->empkt_len[2];
491 } else {
492 dwtmp = ptcb_desc->empkt_len[2];
493 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
494 dwtmp += ptcb_desc->empkt_len[3];
495 }
496 SET_EARLYMODE_LEN1(virtualaddress, dwtmp);
497 if (ptcb_desc->empkt_num <= 5) {
498 dwtmp = ptcb_desc->empkt_len[4];
499 } else {
500 dwtmp = ptcb_desc->empkt_len[4];
501 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
502 dwtmp += ptcb_desc->empkt_len[5];
503 }
504 SET_EARLYMODE_LEN2_1(virtualaddress, dwtmp & 0xF);
505 SET_EARLYMODE_LEN2_2(virtualaddress, dwtmp >> 4);
506 if (ptcb_desc->empkt_num <= 7) {
507 dwtmp = ptcb_desc->empkt_len[6];
508 } else {
509 dwtmp = ptcb_desc->empkt_len[6];
510 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
511 dwtmp += ptcb_desc->empkt_len[7];
512 }
513 SET_EARLYMODE_LEN3(virtualaddress, dwtmp);
514 if (ptcb_desc->empkt_num <= 9) {
515 dwtmp = ptcb_desc->empkt_len[8];
516 } else {
517 dwtmp = ptcb_desc->empkt_len[8];
518 dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
519 dwtmp += ptcb_desc->empkt_len[9];
520 }
521 SET_EARLYMODE_LEN4(virtualaddress, dwtmp);
522}
523
524bool rtl8723be_rx_query_desc(struct ieee80211_hw *hw,
525 struct rtl_stats *status,
526 struct ieee80211_rx_status *rx_status,
527 u8 *pdesc, struct sk_buff *skb)
528{
529 struct rtl_priv *rtlpriv = rtl_priv(hw);
530 struct rx_fwinfo_8723be *p_drvinfo;
531 struct ieee80211_hdr *hdr;
532
533 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
534 status->packet_report_type = (u8)GET_RX_STATUS_DESC_RPT_SEL(pdesc);
535 if (status->packet_report_type == TX_REPORT2)
536 status->length = (u16) GET_RX_RPT2_DESC_PKT_LEN(pdesc);
537 else
538 status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
539 status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
540 RX_DRV_INFO_SIZE_UNIT;
541 status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
542 status->icv = (u16) GET_RX_DESC_ICV(pdesc);
543 status->crc = (u16) GET_RX_DESC_CRC32(pdesc);
544 status->hwerror = (status->crc | status->icv);
545 status->decrypted = !GET_RX_DESC_SWDEC(pdesc);
546 status->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
547 status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
548 status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
549 status->isfirst_ampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
550 if (status->packet_report_type == NORMAL_RX)
551 status->timestamp_low = GET_RX_DESC_TSFL(pdesc);
552 status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
553 status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
554
555 status->is_cck = RTL8723E_RX_HAL_IS_CCK_RATE(status->rate);
556
557 status->macid = GET_RX_DESC_MACID(pdesc);
558 if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
559 status->wake_match = BIT(2);
560 else if (GET_RX_STATUS_DESC_MAGIC_MATCH(pdesc))
561 status->wake_match = BIT(1);
562 else if (GET_RX_STATUS_DESC_UNICAST_MATCH(pdesc))
563 status->wake_match = BIT(0);
564 else
565 status->wake_match = 0;
566 if (status->wake_match)
567 RT_TRACE(rtlpriv, COMP_RXDESC, DBG_LOUD,
568 "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
569 status->wake_match);
570 rx_status->freq = hw->conf.chandef.chan->center_freq;
571 rx_status->band = hw->conf.chandef.chan->band;
572
573
574 hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size +
575 status->rx_bufshift);
576
577 if (status->crc)
578 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
579
580 if (status->rx_is40Mhzpacket)
581 rx_status->flag |= RX_FLAG_40MHZ;
582
583 if (status->is_ht)
584 rx_status->flag |= RX_FLAG_HT;
585
586 rx_status->flag |= RX_FLAG_MACTIME_START;
587
588 /* hw will set status->decrypted true, if it finds the
589 * frame is open data frame or mgmt frame.
590 * So hw will not decryption robust managment frame
591 * for IEEE80211w but still set status->decrypted
592 * true, so here we should set it back to undecrypted
593 * for IEEE80211w frame, and mac80211 sw will help
594 * to decrypt it
595 */
596 if (status->decrypted) {
597 if (!hdr) {
598 WARN_ON_ONCE(true);
599 pr_err("decrypted is true but hdr NULL in skb %p\n",
600 rtl_get_hdr(skb));
601 return false;
602 }
603
604 if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
605 (ieee80211_has_protected(hdr->frame_control)))
606 rx_status->flag &= ~RX_FLAG_DECRYPTED;
607 else
608 rx_status->flag |= RX_FLAG_DECRYPTED;
609 }
610
611 /* rate_idx: index of data rate into band's
612 * supported rates or MCS index if HT rates
613 * are use (RX_FLAG_HT)
614 * Notice: this is diff with windows define
615 */
616 rx_status->rate_idx = _rtl8723be_rate_mapping(hw, status->is_ht,
617 status->rate);
618
619 rx_status->mactime = status->timestamp_low;
620 if (phystatus) {
621 p_drvinfo = (struct rx_fwinfo_8723be *)(skb->data +
622 status->rx_bufshift);
623
624 _rtl8723be_translate_rx_signal_stuff(hw, skb, status,
625 pdesc, p_drvinfo);
626 }
627
628 /*rx_status->qual = status->signal; */
629 rx_status->signal = status->recvsignalpower + 10;
630 if (status->packet_report_type == TX_REPORT2) {
631 status->macid_valid_entry[0] =
632 GET_RX_RPT2_DESC_MACID_VALID_1(pdesc);
633 status->macid_valid_entry[1] =
634 GET_RX_RPT2_DESC_MACID_VALID_2(pdesc);
635 }
636 return true;
637}
638
639void rtl8723be_tx_fill_desc(struct ieee80211_hw *hw,
640 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
f3355dd9 641 u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
a619d1ab
LF
642 struct ieee80211_sta *sta, struct sk_buff *skb,
643 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
644{
645 struct rtl_priv *rtlpriv = rtl_priv(hw);
646 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
647 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
648 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1851cb4a 649 u8 *pdesc = pdesc_tx;
a619d1ab
LF
650 u16 seq_number;
651 __le16 fc = hdr->frame_control;
652 unsigned int buf_len = 0;
653 unsigned int skb_len = skb->len;
654 u8 fw_qsel = _rtl8723be_map_hwqueue_to_fwqueue(skb, hw_queue);
655 bool firstseg = ((hdr->seq_ctrl &
656 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
657 bool lastseg = ((hdr->frame_control &
658 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
659 dma_addr_t mapping;
660 u8 bw_40 = 0;
661 u8 short_gi = 0;
662
663 if (mac->opmode == NL80211_IFTYPE_STATION) {
664 bw_40 = mac->bw_40;
665 } else if (mac->opmode == NL80211_IFTYPE_AP ||
666 mac->opmode == NL80211_IFTYPE_ADHOC) {
667 if (sta)
668 bw_40 = sta->ht_cap.cap &
669 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
670 }
671 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
672 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
673 /* reserve 8 byte for AMPDU early mode */
674 if (rtlhal->earlymode_enable) {
675 skb_push(skb, EM_HDR_LEN);
676 memset(skb->data, 0, EM_HDR_LEN);
677 }
678 buf_len = skb->len;
679 mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
680 PCI_DMA_TODEVICE);
681 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
682 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "DMA mapping error");
683 return;
684 }
685 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8723be));
686 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
687 firstseg = true;
688 lastseg = true;
689 }
690 if (firstseg) {
691 if (rtlhal->earlymode_enable) {
692 SET_TX_DESC_PKT_OFFSET(pdesc, 1);
693 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN +
694 EM_HDR_LEN);
695 if (ptcb_desc->empkt_num) {
696 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
697 "Insert 8 byte.pTcb->EMPktNum:%d\n",
698 ptcb_desc->empkt_num);
699 _rtl8723be_insert_emcontent(ptcb_desc,
700 (u8 *)(skb->data));
701 }
702 } else {
703 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
704 }
705
706 /* ptcb_desc->use_driver_rate = true; */
707 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
708 if (ptcb_desc->hw_rate > DESC92C_RATEMCS0)
709 short_gi = (ptcb_desc->use_shortgi) ? 1 : 0;
710 else
711 short_gi = (ptcb_desc->use_shortpreamble) ? 1 : 0;
712
713 SET_TX_DESC_DATA_SHORTGI(pdesc, short_gi);
714
715 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
716 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
717 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
718 }
719 SET_TX_DESC_SEQ(pdesc, seq_number);
720 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
721 !ptcb_desc->cts_enable) ?
722 1 : 0));
723 SET_TX_DESC_HW_RTS_ENABLE(pdesc, 0);
724 SET_TX_DESC_CTS2SELF(pdesc, ((ptcb_desc->cts_enable) ?
725 1 : 0));
726
727 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
728
729 SET_TX_DESC_RTS_SC(pdesc, ptcb_desc->rts_sc);
730 SET_TX_DESC_RTS_SHORT(pdesc,
731 ((ptcb_desc->rts_rate <= DESC92C_RATE54M) ?
732 (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
733 (ptcb_desc->rts_use_shortgi ? 1 : 0)));
734
735 if (ptcb_desc->btx_enable_sw_calc_duration)
736 SET_TX_DESC_NAV_USE_HDR(pdesc, 1);
737
738 if (bw_40) {
739 if (ptcb_desc->packet_bw) {
740 SET_TX_DESC_DATA_BW(pdesc, 1);
741 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
742 } else {
743 SET_TX_DESC_DATA_BW(pdesc, 0);
744 SET_TX_DESC_TX_SUB_CARRIER(pdesc, mac->cur_40_prime_sc);
745 }
746 } else {
747 SET_TX_DESC_DATA_BW(pdesc, 0);
748 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
749 }
750
751 SET_TX_DESC_LINIP(pdesc, 0);
752 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb_len);
753 if (sta) {
754 u8 ampdu_density = sta->ht_cap.ampdu_density;
755 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
756 }
757 if (info->control.hw_key) {
758 struct ieee80211_key_conf *keyconf =
759 info->control.hw_key;
760 switch (keyconf->cipher) {
761 case WLAN_CIPHER_SUITE_WEP40:
762 case WLAN_CIPHER_SUITE_WEP104:
763 case WLAN_CIPHER_SUITE_TKIP:
764 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
765 break;
766 case WLAN_CIPHER_SUITE_CCMP:
767 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
768 break;
769 default:
770 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
771 break;
772 }
773 }
774
775 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
776 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
777 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
778 SET_TX_DESC_DISABLE_FB(pdesc, ptcb_desc->disable_ratefallback ?
779 1 : 0);
780 SET_TX_DESC_USE_RATE(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
781
782 if (ieee80211_is_data_qos(fc)) {
783 if (mac->rdg_en) {
784 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
785 "Enable RDG function.\n");
786 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
787 SET_TX_DESC_HTC(pdesc, 1);
788 }
789 }
790 }
791
792 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
793 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
794 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) buf_len);
795 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
796 SET_TX_DESC_RATE_ID(pdesc, ptcb_desc->ratr_index);
797 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
798
799 if (!ieee80211_is_data_qos(fc)) {
800 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
801 SET_TX_DESC_HWSEQ_SEL(pdesc, 0);
802 }
803 SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
804 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
805 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
806 SET_TX_DESC_BMC(pdesc, 1);
807 }
808 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
809}
810
811void rtl8723be_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
812 bool b_firstseg, bool b_lastseg,
813 struct sk_buff *skb)
814{
815 struct rtl_priv *rtlpriv = rtl_priv(hw);
816 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
817 u8 fw_queue = QSLT_BEACON;
818
819 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
820 skb->data, skb->len,
821 PCI_DMA_TODEVICE);
822
823 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
824 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
825 "DMA mapping error");
826 return;
827 }
828 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
829
830 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
831
832 SET_TX_DESC_TX_RATE(pdesc, DESC92C_RATE1M);
833
834 SET_TX_DESC_SEQ(pdesc, 0);
835
836 SET_TX_DESC_LINIP(pdesc, 0);
837
838 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
839
840 SET_TX_DESC_FIRST_SEG(pdesc, 1);
841 SET_TX_DESC_LAST_SEG(pdesc, 1);
842
843 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
844
845 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
846
847 SET_TX_DESC_RATE_ID(pdesc, 0);
848 SET_TX_DESC_MACID(pdesc, 0);
849
850 SET_TX_DESC_OWN(pdesc, 1);
851
1851cb4a 852 SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
a619d1ab
LF
853
854 SET_TX_DESC_FIRST_SEG(pdesc, 1);
855 SET_TX_DESC_LAST_SEG(pdesc, 1);
856
857 SET_TX_DESC_USE_RATE(pdesc, 1);
858}
859
f3355dd9
LF
860void rtl8723be_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx,
861 u8 desc_name, u8 *val)
a619d1ab
LF
862{
863 if (istx) {
864 switch (desc_name) {
865 case HW_DESC_OWN:
866 SET_TX_DESC_OWN(pdesc, 1);
867 break;
868 case HW_DESC_TX_NEXTDESC_ADDR:
869 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *)val);
870 break;
871 default:
872 RT_ASSERT(false, "ERR txdesc :%d not process\n",
873 desc_name);
874 break;
875 }
876 } else {
877 switch (desc_name) {
878 case HW_DESC_RXOWN:
879 SET_RX_DESC_OWN(pdesc, 1);
880 break;
881 case HW_DESC_RXBUFF_ADDR:
882 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *)val);
883 break;
884 case HW_DESC_RXPKT_LEN:
885 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *)val);
886 break;
887 case HW_DESC_RXERO:
888 SET_RX_DESC_EOR(pdesc, 1);
889 break;
890 default:
891 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
892 desc_name);
893 break;
894 }
895 }
896}
897
898u32 rtl8723be_get_desc(u8 *pdesc, bool istx, u8 desc_name)
899{
900 u32 ret = 0;
901
902 if (istx) {
903 switch (desc_name) {
904 case HW_DESC_OWN:
905 ret = GET_TX_DESC_OWN(pdesc);
906 break;
907 case HW_DESC_TXBUFF_ADDR:
908 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc);
909 break;
910 default:
911 RT_ASSERT(false, "ERR txdesc :%d not process\n",
912 desc_name);
913 break;
914 }
915 } else {
916 switch (desc_name) {
917 case HW_DESC_OWN:
918 ret = GET_RX_DESC_OWN(pdesc);
919 break;
920 case HW_DESC_RXPKT_LEN:
921 ret = GET_RX_DESC_PKT_LEN(pdesc);
922 break;
923 default:
924 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
925 desc_name);
926 break;
927 }
928 }
929 return ret;
930}
931
932bool rtl8723be_is_tx_desc_closed(struct ieee80211_hw *hw,
933 u8 hw_queue, u16 index)
934{
935 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
936 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
937 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
938 u8 own = (u8) rtl8723be_get_desc(entry, true, HW_DESC_OWN);
939
940 /*beacon packet will only use the first
941 *descriptor by default, and the own may not
942 *be cleared by the hardware
943 */
944 if (own)
945 return false;
946 else
947 return true;
948}
949
950void rtl8723be_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
951{
952 struct rtl_priv *rtlpriv = rtl_priv(hw);
953 if (hw_queue == BEACON_QUEUE) {
954 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
955 } else {
956 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
957 BIT(0) << (hw_queue));
958 }
959}
This page took 0.148054 seconds and 5 git commands to generate.