blob: 2ab4a00246cca14fa77af6ba98a176f29917884f [file] [log] [blame]
Larry Finger0c817332010-12-08 11:12:31 -06001/******************************************************************************
2 *
Larry Finger9003a4a2012-01-07 20:46:44 -06003 * Copyright(c) 2009-2012 Realtek Corporation.
Larry Finger0c817332010-12-08 11:12:31 -06004 *
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 *
Larry Finger0c817332010-12-08 11:12:31 -060014 * 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"
Larry Finger3a16b412013-03-24 22:06:40 -050029#include "../stats.h"
John W. Linville5c405b52010-12-16 15:43:36 -050030#include "reg.h"
31#include "def.h"
32#include "phy.h"
33#include "trx.h"
34#include "led.h"
Larry Finger0c817332010-12-08 11:12:31 -060035
Larry Fingerd3bb1422011-04-25 13:23:20 -050036static u8 _rtl92ce_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
Larry Finger0c817332010-12-08 11:12:31 -060037{
Larry Fingerd3bb1422011-04-25 13:23:20 -050038 __le16 fc = rtl_get_fc(skb);
Larry Finger0c817332010-12-08 11:12:31 -060039
Chaoming_Li76c34f92011-04-25 12:54:05 -050040 if (unlikely(ieee80211_is_beacon(fc)))
41 return QSLT_BEACON;
Larry Finger3a16b412013-03-24 22:06:40 -050042 if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
Chaoming_Li76c34f92011-04-25 12:54:05 -050043 return QSLT_MGNT;
Larry Finger0c817332010-12-08 11:12:31 -060044
Chaoming_Li76c34f92011-04-25 12:54:05 -050045 return skb->priority;
Larry Finger0c817332010-12-08 11:12:31 -060046}
47
Arnd Bergmann08aba422016-06-15 23:30:43 +020048static u8 _rtl92c_query_rxpwrpercentage(s8 antpower)
Larry Finger0c817332010-12-08 11:12:31 -060049{
50 if ((antpower <= -100) || (antpower >= 20))
51 return 0;
52 else if (antpower >= 0)
53 return 100;
54 else
55 return 100 + antpower;
56}
57
Arnd Bergmann08aba422016-06-15 23:30:43 +020058static u8 _rtl92c_evm_db_to_percentage(s8 value)
Larry Finger0c817332010-12-08 11:12:31 -060059{
Arnd Bergmann08aba422016-06-15 23:30:43 +020060 s8 ret_val;
Larry Finger0c817332010-12-08 11:12:31 -060061 ret_val = value;
62
63 if (ret_val >= 0)
64 ret_val = 0;
65
66 if (ret_val <= -33)
67 ret_val = -33;
68
69 ret_val = 0 - ret_val;
70 ret_val *= 3;
71
72 if (ret_val == 99)
73 ret_val = 100;
74
75 return ret_val;
76}
77
Larry Finger0c817332010-12-08 11:12:31 -060078static long _rtl92ce_signal_scale_mapping(struct ieee80211_hw *hw,
79 long currsig)
80{
81 long retsig;
82
83 if (currsig >= 61 && currsig <= 100)
84 retsig = 90 + ((currsig - 60) / 4);
85 else if (currsig >= 41 && currsig <= 60)
86 retsig = 78 + ((currsig - 40) / 2);
87 else if (currsig >= 31 && currsig <= 40)
88 retsig = 66 + (currsig - 30);
89 else if (currsig >= 21 && currsig <= 30)
90 retsig = 54 + (currsig - 20);
91 else if (currsig >= 5 && currsig <= 20)
92 retsig = 42 + (((currsig - 5) * 2) / 3);
93 else if (currsig == 4)
94 retsig = 36;
95 else if (currsig == 3)
96 retsig = 27;
97 else if (currsig == 2)
98 retsig = 18;
99 else if (currsig == 1)
100 retsig = 9;
101 else
102 retsig = currsig;
103
104 return retsig;
105}
106
107static void _rtl92ce_query_rxphystatus(struct ieee80211_hw *hw,
108 struct rtl_stats *pstats,
109 struct rx_desc_92c *pdesc,
110 struct rx_fwinfo_92c *p_drvinfo,
Larry Finger7ea47242011-02-19 16:28:57 -0600111 bool packet_match_bssid,
112 bool packet_toself,
113 bool packet_beacon)
Larry Finger0c817332010-12-08 11:12:31 -0600114{
115 struct rtl_priv *rtlpriv = rtl_priv(hw);
116 struct phy_sts_cck_8192s_t *cck_buf;
Larry Finger0bd899e2012-10-25 13:46:30 -0500117 struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
Larry Finger7101f402011-06-10 11:05:23 -0500118 s8 rx_pwr_all = 0, rx_pwr[4];
Alessio Igor Boganic2a7dca02011-02-28 09:11:55 +0100119 u8 evm, pwdb_all, rf_rx_num = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600120 u8 i, max_spatial_stream;
Alessio Igor Boganic2a7dca02011-02-28 09:11:55 +0100121 u32 rssi, total_rssi = 0;
Larry Finger0c817332010-12-08 11:12:31 -0600122 bool is_cck_rate;
123
Larry Finger5c99f042014-09-26 16:40:25 -0500124 is_cck_rate = RX_HAL_IS_CCK_RATE(pdesc->rxmcs);
Larry Finger7ea47242011-02-19 16:28:57 -0600125 pstats->packet_matchbssid = packet_match_bssid;
126 pstats->packet_toself = packet_toself;
127 pstats->is_cck = is_cck_rate;
128 pstats->packet_beacon = packet_beacon;
Larry Fingerda17fcf2012-10-25 13:46:31 -0500129 pstats->rx_mimo_sig_qual[0] = -1;
130 pstats->rx_mimo_sig_qual[1] = -1;
Larry Finger0c817332010-12-08 11:12:31 -0600131
132 if (is_cck_rate) {
133 u8 report, cck_highpwr;
134 cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
135
Larry Finger0bd899e2012-10-25 13:46:30 -0500136 if (ppsc->rfpwr_state == ERFON)
Chaoming_Li76c34f92011-04-25 12:54:05 -0500137 cck_highpwr = (u8) rtl_get_bbreg(hw,
138 RFPGA0_XA_HSSIPARAMETER2,
139 BIT(9));
140 else
141 cck_highpwr = false;
142
Larry Finger0c817332010-12-08 11:12:31 -0600143 if (!cck_highpwr) {
144 u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
145 report = cck_buf->cck_agc_rpt & 0xc0;
146 report = report >> 6;
147 switch (report) {
148 case 0x3:
149 rx_pwr_all = -46 - (cck_agc_rpt & 0x3e);
150 break;
151 case 0x2:
152 rx_pwr_all = -26 - (cck_agc_rpt & 0x3e);
153 break;
154 case 0x1:
155 rx_pwr_all = -12 - (cck_agc_rpt & 0x3e);
156 break;
157 case 0x0:
158 rx_pwr_all = 16 - (cck_agc_rpt & 0x3e);
159 break;
160 }
161 } else {
162 u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
163 report = p_drvinfo->cfosho[0] & 0x60;
164 report = report >> 5;
165 switch (report) {
166 case 0x3:
167 rx_pwr_all = -46 - ((cck_agc_rpt & 0x1f) << 1);
168 break;
169 case 0x2:
170 rx_pwr_all = -26 - ((cck_agc_rpt & 0x1f) << 1);
171 break;
172 case 0x1:
173 rx_pwr_all = -12 - ((cck_agc_rpt & 0x1f) << 1);
174 break;
175 case 0x0:
176 rx_pwr_all = 16 - ((cck_agc_rpt & 0x1f) << 1);
177 break;
178 }
179 }
180
Larry Finger3a16b412013-03-24 22:06:40 -0500181 pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
182 /* CCK gain is smaller than OFDM/MCS gain,
183 * so we add gain diff by experiences,
184 * the val is 6
185 */
186 pwdb_all += 6;
187 if (pwdb_all > 100)
188 pwdb_all = 100;
189 /* modify the offset to make the same
190 * gain index with OFDM.
191 */
192 if (pwdb_all > 34 && pwdb_all <= 42)
193 pwdb_all -= 2;
194 else if (pwdb_all > 26 && pwdb_all <= 34)
195 pwdb_all -= 6;
196 else if (pwdb_all > 14 && pwdb_all <= 26)
197 pwdb_all -= 8;
198 else if (pwdb_all > 4 && pwdb_all <= 14)
199 pwdb_all -= 4;
200
Larry Finger0c817332010-12-08 11:12:31 -0600201 pstats->rx_pwdb_all = pwdb_all;
202 pstats->recvsignalpower = rx_pwr_all;
203
Larry Finger3a16b412013-03-24 22:06:40 -0500204 /* (3) Get Signal Quality (EVM) */
Larry Finger7ea47242011-02-19 16:28:57 -0600205 if (packet_match_bssid) {
Larry Finger0c817332010-12-08 11:12:31 -0600206 u8 sq;
207 if (pstats->rx_pwdb_all > 40)
208 sq = 100;
209 else {
210 sq = cck_buf->sq_rpt;
211 if (sq > 64)
212 sq = 0;
213 else if (sq < 20)
214 sq = 100;
215 else
216 sq = ((64 - sq) * 100) / 44;
217 }
218
219 pstats->signalquality = sq;
Larry Fingerda17fcf2012-10-25 13:46:31 -0500220 pstats->rx_mimo_sig_qual[0] = sq;
221 pstats->rx_mimo_sig_qual[1] = -1;
Larry Finger0c817332010-12-08 11:12:31 -0600222 }
223 } else {
Larry Finger7ea47242011-02-19 16:28:57 -0600224 rtlpriv->dm.rfpath_rxenable[0] =
225 rtlpriv->dm.rfpath_rxenable[1] = true;
Larry Finger3a16b412013-03-24 22:06:40 -0500226 /* (1)Get RSSI for HT rate */
Larry Finger0c817332010-12-08 11:12:31 -0600227 for (i = RF90_PATH_A; i < RF90_PATH_MAX; i++) {
Larry Finger3a16b412013-03-24 22:06:40 -0500228 /* we will judge RF RX path now. */
Larry Finger7ea47242011-02-19 16:28:57 -0600229 if (rtlpriv->dm.rfpath_rxenable[i])
Larry Finger0c817332010-12-08 11:12:31 -0600230 rf_rx_num++;
231
232 rx_pwr[i] =
233 ((p_drvinfo->gain_trsw[i] & 0x3f) * 2) - 110;
Larry Finger3a16b412013-03-24 22:06:40 -0500234 /* Translate DBM to percentage. */
Larry Finger0c817332010-12-08 11:12:31 -0600235 rssi = _rtl92c_query_rxpwrpercentage(rx_pwr[i]);
236 total_rssi += rssi;
Larry Finger3a16b412013-03-24 22:06:40 -0500237 /* Get Rx snr value in DB */
Larry Finger0c817332010-12-08 11:12:31 -0600238 rtlpriv->stats.rx_snr_db[i] =
239 (long)(p_drvinfo->rxsnr[i] / 2);
240
Larry Finger3a16b412013-03-24 22:06:40 -0500241 /* Record Signal Strength for next packet */
Larry Finger7ea47242011-02-19 16:28:57 -0600242 if (packet_match_bssid)
Larry Finger0c817332010-12-08 11:12:31 -0600243 pstats->rx_mimo_signalstrength[i] = (u8) rssi;
244 }
245
Larry Finger3a16b412013-03-24 22:06:40 -0500246 /* (2)PWDB, Average PWDB cacluated by
247 * hardware (for rate adaptive)
248 */
Larry Finger0c817332010-12-08 11:12:31 -0600249 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
250 pwdb_all = _rtl92c_query_rxpwrpercentage(rx_pwr_all);
251 pstats->rx_pwdb_all = pwdb_all;
252 pstats->rxpower = rx_pwr_all;
253 pstats->recvsignalpower = rx_pwr_all;
254
Larry Finger3a16b412013-03-24 22:06:40 -0500255 /* (3)EVM of HT rate */
Larry Fingere0e776a2014-12-18 03:05:36 -0600256 if (pstats->is_ht && pstats->rate >= DESC_RATEMCS8 &&
257 pstats->rate <= DESC_RATEMCS15)
Larry Finger0c817332010-12-08 11:12:31 -0600258 max_spatial_stream = 2;
259 else
260 max_spatial_stream = 1;
261
262 for (i = 0; i < max_spatial_stream; i++) {
263 evm = _rtl92c_evm_db_to_percentage(p_drvinfo->rxevm[i]);
264
Larry Finger7ea47242011-02-19 16:28:57 -0600265 if (packet_match_bssid) {
Larry Finger3a16b412013-03-24 22:06:40 -0500266 /* Fill value in RFD, Get the first
267 * spatial stream only
268 */
Larry Finger0c817332010-12-08 11:12:31 -0600269 if (i == 0)
270 pstats->signalquality =
271 (u8) (evm & 0xff);
Larry Fingerda17fcf2012-10-25 13:46:31 -0500272 pstats->rx_mimo_sig_qual[i] = (u8) (evm & 0xff);
Larry Finger0c817332010-12-08 11:12:31 -0600273 }
274 }
275 }
276
Larry Finger3a16b412013-03-24 22:06:40 -0500277 /* UI BSS List signal strength(in percentage),
278 * make it good looking, from 0~100.
279 */
Larry Finger0c817332010-12-08 11:12:31 -0600280 if (is_cck_rate)
281 pstats->signalstrength =
282 (u8) (_rtl92ce_signal_scale_mapping(hw, pwdb_all));
283 else if (rf_rx_num != 0)
284 pstats->signalstrength =
285 (u8) (_rtl92ce_signal_scale_mapping
286 (hw, total_rssi /= rf_rx_num));
287}
288
Larry Finger0c817332010-12-08 11:12:31 -0600289static void _rtl92ce_translate_rx_signal_stuff(struct ieee80211_hw *hw,
290 struct sk_buff *skb,
291 struct rtl_stats *pstats,
292 struct rx_desc_92c *pdesc,
293 struct rx_fwinfo_92c *p_drvinfo)
294{
295 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
296 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
297
298 struct ieee80211_hdr *hdr;
299 u8 *tmp_buf;
300 u8 *praddr;
Larry Finger17c9ac62011-02-19 16:29:57 -0600301 __le16 fc;
302 u16 type, c_fc;
Cong Dinge48caab2013-02-04 22:43:22 +0100303 bool packet_matchbssid, packet_toself, packet_beacon = false;
Larry Finger0c817332010-12-08 11:12:31 -0600304
305 tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
306
307 hdr = (struct ieee80211_hdr *)tmp_buf;
Larry Finger17c9ac62011-02-19 16:29:57 -0600308 fc = hdr->frame_control;
309 c_fc = le16_to_cpu(fc);
Larry Finger0c817332010-12-08 11:12:31 -0600310 type = WLAN_FC_GET_TYPE(fc);
311 praddr = hdr->addr1;
Larry Finger0c817332010-12-08 11:12:31 -0600312
Larry Finger7ea47242011-02-19 16:28:57 -0600313 packet_matchbssid =
Larry Finger0c817332010-12-08 11:12:31 -0600314 ((IEEE80211_FTYPE_CTL != type) &&
Joe Perches2e42e472012-05-09 17:17:46 +0000315 ether_addr_equal(mac->bssid,
316 (c_fc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
317 (c_fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
318 hdr->addr3) &&
Larry Finger7ea47242011-02-19 16:28:57 -0600319 (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
Larry Finger0c817332010-12-08 11:12:31 -0600320
Larry Finger7ea47242011-02-19 16:28:57 -0600321 packet_toself = packet_matchbssid &&
Joe Perches2e42e472012-05-09 17:17:46 +0000322 ether_addr_equal(praddr, rtlefuse->dev_addr);
Larry Finger0c817332010-12-08 11:12:31 -0600323
324 if (ieee80211_is_beacon(fc))
Larry Finger7ea47242011-02-19 16:28:57 -0600325 packet_beacon = true;
Larry Finger0c817332010-12-08 11:12:31 -0600326
327 _rtl92ce_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
Larry Finger7ea47242011-02-19 16:28:57 -0600328 packet_matchbssid, packet_toself,
329 packet_beacon);
Larry Finger0c817332010-12-08 11:12:31 -0600330
Larry Finger3a16b412013-03-24 22:06:40 -0500331 rtl_process_phyinfo(hw, tmp_buf, pstats);
Larry Finger0c817332010-12-08 11:12:31 -0600332}
333
334bool rtl92ce_rx_query_desc(struct ieee80211_hw *hw,
335 struct rtl_stats *stats,
336 struct ieee80211_rx_status *rx_status,
337 u8 *p_desc, struct sk_buff *skb)
338{
339 struct rx_fwinfo_92c *p_drvinfo;
340 struct rx_desc_92c *pdesc = (struct rx_desc_92c *)p_desc;
Larry Finger3a16b412013-03-24 22:06:40 -0500341 struct ieee80211_hdr *hdr;
Larry Finger0c817332010-12-08 11:12:31 -0600342 u32 phystatus = GET_RX_DESC_PHYST(pdesc);
343 stats->length = (u16) GET_RX_DESC_PKT_LEN(pdesc);
344 stats->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) *
345 RX_DRV_INFO_SIZE_UNIT;
346 stats->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03);
Larry Finger7ea47242011-02-19 16:28:57 -0600347 stats->icv = (u16) GET_RX_DESC_ICV(pdesc);
348 stats->crc = (u16) GET_RX_DESC_CRC32(pdesc);
349 stats->hwerror = (stats->crc | stats->icv);
Larry Finger0c817332010-12-08 11:12:31 -0600350 stats->decrypted = !GET_RX_DESC_SWDEC(pdesc);
351 stats->rate = (u8) GET_RX_DESC_RXMCS(pdesc);
Larry Finger7ea47242011-02-19 16:28:57 -0600352 stats->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc);
353 stats->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1);
Larry Finger3a16b412013-03-24 22:06:40 -0500354 stats->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1)
Larry Finger0c817332010-12-08 11:12:31 -0600355 && (GET_RX_DESC_FAGGR(pdesc) == 1));
356 stats->timestamp_low = GET_RX_DESC_TSFL(pdesc);
357 stats->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc);
Larry Finger3a16b412013-03-24 22:06:40 -0500358 stats->is_ht = (bool)GET_RX_DESC_RXHT(pdesc);
359
Larry Finger5c99f042014-09-26 16:40:25 -0500360 stats->is_cck = RX_HAL_IS_CCK_RATE(pdesc->rxmcs);
Larry Finger0c817332010-12-08 11:12:31 -0600361
Karl Beldan675a0b02013-03-25 16:26:57 +0100362 rx_status->freq = hw->conf.chandef.chan->center_freq;
363 rx_status->band = hw->conf.chandef.chan->band;
Larry Finger0c817332010-12-08 11:12:31 -0600364
Larry Finger3a16b412013-03-24 22:06:40 -0500365 hdr = (struct ieee80211_hdr *)(skb->data + stats->rx_drvinfo_size
366 + stats->rx_bufshift);
367
368 if (stats->crc)
Larry Finger0c817332010-12-08 11:12:31 -0600369 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
370
Larry Finger3a16b412013-03-24 22:06:40 -0500371 if (stats->rx_is40Mhzpacket)
Larry Finger0c817332010-12-08 11:12:31 -0600372 rx_status->flag |= RX_FLAG_40MHZ;
373
Larry Finger3a16b412013-03-24 22:06:40 -0500374 if (stats->is_ht)
Larry Finger0c817332010-12-08 11:12:31 -0600375 rx_status->flag |= RX_FLAG_HT;
376
Thomas Pedersenf4bda332012-11-13 10:46:27 -0800377 rx_status->flag |= RX_FLAG_MACTIME_START;
Larry Finger0c817332010-12-08 11:12:31 -0600378
Larry Finger3a16b412013-03-24 22:06:40 -0500379 /* hw will set stats->decrypted true, if it finds the
380 * frame is open data frame or mgmt frame.
381 * So hw will not decryption robust managment frame
382 * for IEEE80211w but still set status->decrypted
383 * true, so here we should set it back to undecrypted
384 * for IEEE80211w frame, and mac80211 sw will help
385 * to decrypt it
386 */
387 if (stats->decrypted) {
Johannes Bergd8ca16d2014-01-23 16:20:29 +0100388 if ((_ieee80211_is_robust_mgmt_frame(hdr)) &&
Larry Finger3a16b412013-03-24 22:06:40 -0500389 (ieee80211_has_protected(hdr->frame_control)))
390 rx_status->flag &= ~RX_FLAG_DECRYPTED;
391 else
392 rx_status->flag |= RX_FLAG_DECRYPTED;
393 }
394 /* rate_idx: index of data rate into band's
395 * supported rates or MCS index if HT rates
396 * are use (RX_FLAG_HT)
397 * Notice: this is diff with windows define
398 */
Larry Fingerf1f21772014-12-18 03:05:31 -0600399 rx_status->rate_idx = rtlwifi_rate_mapping(hw, stats->is_ht,
Larry Fingerfd3cb222014-12-18 03:05:40 -0600400 false, stats->rate);
Larry Finger0c817332010-12-08 11:12:31 -0600401
Larry Finger3a16b412013-03-24 22:06:40 -0500402 rx_status->mactime = stats->timestamp_low;
Mike McCormacke10542c2011-06-20 10:47:51 +0900403 if (phystatus) {
Larry Finger0c817332010-12-08 11:12:31 -0600404 p_drvinfo = (struct rx_fwinfo_92c *)(skb->data +
405 stats->rx_bufshift);
406
407 _rtl92ce_translate_rx_signal_stuff(hw,
408 skb, stats, pdesc,
409 p_drvinfo);
410 }
411
412 /*rx_status->qual = stats->signal; */
Larry Finger3a16b412013-03-24 22:06:40 -0500413 rx_status->signal = stats->recvsignalpower + 10;
Larry Finger0c817332010-12-08 11:12:31 -0600414
415 return true;
416}
417
418void rtl92ce_tx_fill_desc(struct ieee80211_hw *hw,
419 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
Larry Fingerf3355dd2014-03-04 16:53:47 -0600420 u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
Thomas Huehn36323f82012-07-23 21:33:42 +0200421 struct ieee80211_sta *sta,
422 struct sk_buff *skb,
Chaoming_Li76c34f92011-04-25 12:54:05 -0500423 u8 hw_queue, struct rtl_tcb_desc *tcb_desc)
Larry Finger0c817332010-12-08 11:12:31 -0600424{
425 struct rtl_priv *rtlpriv = rtl_priv(hw);
426 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
427 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
428 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
Larry Finger7ea47242011-02-19 16:28:57 -0600429 bool defaultadapter = true;
Joe Perches2c208892012-06-04 12:44:17 +0000430 u8 *pdesc = pdesc_tx;
Larry Finger0c817332010-12-08 11:12:31 -0600431 u16 seq_number;
Larry Finger17c9ac62011-02-19 16:29:57 -0600432 __le16 fc = hdr->frame_control;
Chaoming_Li76c34f92011-04-25 12:54:05 -0500433 u8 fw_qsel = _rtl92ce_map_hwqueue_to_fwqueue(skb, hw_queue);
Larry Finger7ea47242011-02-19 16:28:57 -0600434 bool firstseg = ((hdr->seq_ctrl &
435 cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
Larry Finger0c817332010-12-08 11:12:31 -0600436
Larry Finger7ea47242011-02-19 16:28:57 -0600437 bool lastseg = ((hdr->frame_control &
438 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
Larry Finger0c817332010-12-08 11:12:31 -0600439
440 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
441 skb->data, skb->len,
442 PCI_DMA_TODEVICE);
Larry Finger91459102012-12-27 10:37:29 -0600443
Chaoming_Li76c34f92011-04-25 12:54:05 -0500444 u8 bw_40 = 0;
445
Larry Finger91459102012-12-27 10:37:29 -0600446 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
447 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
Joe Perches4713bd12016-06-26 12:34:30 -0700448 "DMA mapping error\n");
Larry Finger91459102012-12-27 10:37:29 -0600449 return;
450 }
Chaoming_Li76c34f92011-04-25 12:54:05 -0500451 rcu_read_lock();
452 sta = get_sta(hw, mac->vif, mac->bssid);
453 if (mac->opmode == NL80211_IFTYPE_STATION) {
454 bw_40 = mac->bw_40;
455 } else if (mac->opmode == NL80211_IFTYPE_AP ||
Larry Finger3a16b412013-03-24 22:06:40 -0500456 mac->opmode == NL80211_IFTYPE_ADHOC ||
457 mac->opmode == NL80211_IFTYPE_MESH_POINT) {
Chaoming_Li76c34f92011-04-25 12:54:05 -0500458 if (sta)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100459 bw_40 = sta->bandwidth >= IEEE80211_STA_RX_BW_40;
Chaoming_Li76c34f92011-04-25 12:54:05 -0500460 }
Larry Finger0c817332010-12-08 11:12:31 -0600461
462 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
463
Chaoming_Li76c34f92011-04-25 12:54:05 -0500464 rtl_get_tcb_desc(hw, info, sta, skb, tcb_desc);
Larry Finger0c817332010-12-08 11:12:31 -0600465
466 CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_92c));
467
Chaoming_Li76c34f92011-04-25 12:54:05 -0500468 if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
469 firstseg = true;
470 lastseg = true;
471 }
Larry Finger7ea47242011-02-19 16:28:57 -0600472 if (firstseg) {
Larry Finger0c817332010-12-08 11:12:31 -0600473 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
474
Chaoming_Li76c34f92011-04-25 12:54:05 -0500475 SET_TX_DESC_TX_RATE(pdesc, tcb_desc->hw_rate);
Larry Finger0c817332010-12-08 11:12:31 -0600476
Chaoming_Li76c34f92011-04-25 12:54:05 -0500477 if (tcb_desc->use_shortgi || tcb_desc->use_shortpreamble)
Larry Finger0c817332010-12-08 11:12:31 -0600478 SET_TX_DESC_DATA_SHORTGI(pdesc, 1);
479
Chaoming_Li76c34f92011-04-25 12:54:05 -0500480 if (info->flags & IEEE80211_TX_CTL_AMPDU) {
Larry Finger0c817332010-12-08 11:12:31 -0600481 SET_TX_DESC_AGG_BREAK(pdesc, 1);
482 SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14);
483 }
484 SET_TX_DESC_SEQ(pdesc, seq_number);
485
Chaoming_Li76c34f92011-04-25 12:54:05 -0500486 SET_TX_DESC_RTS_ENABLE(pdesc, ((tcb_desc->rts_enable &&
487 !tcb_desc->
Larry Finger7ea47242011-02-19 16:28:57 -0600488 cts_enable) ? 1 : 0));
Larry Finger0c817332010-12-08 11:12:31 -0600489 SET_TX_DESC_HW_RTS_ENABLE(pdesc,
Chaoming_Li76c34f92011-04-25 12:54:05 -0500490 ((tcb_desc->rts_enable
491 || tcb_desc->cts_enable) ? 1 : 0));
492 SET_TX_DESC_CTS2SELF(pdesc, ((tcb_desc->cts_enable) ? 1 : 0));
493 SET_TX_DESC_RTS_STBC(pdesc, ((tcb_desc->rts_stbc) ? 1 : 0));
Larry Finger0c817332010-12-08 11:12:31 -0600494
Chaoming_Li76c34f92011-04-25 12:54:05 -0500495 SET_TX_DESC_RTS_RATE(pdesc, tcb_desc->rts_rate);
Larry Finger0c817332010-12-08 11:12:31 -0600496 SET_TX_DESC_RTS_BW(pdesc, 0);
Chaoming_Li76c34f92011-04-25 12:54:05 -0500497 SET_TX_DESC_RTS_SC(pdesc, tcb_desc->rts_sc);
Larry Finger0c817332010-12-08 11:12:31 -0600498 SET_TX_DESC_RTS_SHORT(pdesc,
Larry Fingere0e776a2014-12-18 03:05:36 -0600499 ((tcb_desc->rts_rate <= DESC_RATE54M) ?
Chaoming_Li76c34f92011-04-25 12:54:05 -0500500 (tcb_desc->rts_use_shortpreamble ? 1 : 0)
501 : (tcb_desc->rts_use_shortgi ? 1 : 0)));
Larry Finger0c817332010-12-08 11:12:31 -0600502
Chaoming_Li76c34f92011-04-25 12:54:05 -0500503 if (bw_40) {
504 if (tcb_desc->packet_bw) {
Larry Finger0c817332010-12-08 11:12:31 -0600505 SET_TX_DESC_DATA_BW(pdesc, 1);
506 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3);
507 } else {
508 SET_TX_DESC_DATA_BW(pdesc, 0);
Chaoming_Li76c34f92011-04-25 12:54:05 -0500509 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
510 mac->cur_40_prime_sc);
Larry Finger0c817332010-12-08 11:12:31 -0600511 }
512 } else {
513 SET_TX_DESC_DATA_BW(pdesc, 0);
514 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
515 }
516
517 SET_TX_DESC_LINIP(pdesc, 0);
518 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
519
520 if (sta) {
521 u8 ampdu_density = sta->ht_cap.ampdu_density;
522 SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density);
523 }
524
525 if (info->control.hw_key) {
526 struct ieee80211_key_conf *keyconf =
527 info->control.hw_key;
528
529 switch (keyconf->cipher) {
530 case WLAN_CIPHER_SUITE_WEP40:
531 case WLAN_CIPHER_SUITE_WEP104:
532 case WLAN_CIPHER_SUITE_TKIP:
533 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
534 break;
535 case WLAN_CIPHER_SUITE_CCMP:
536 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
537 break;
538 default:
539 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
540 break;
541
542 }
543 }
544
545 SET_TX_DESC_PKT_ID(pdesc, 0);
546 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
547
548 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
549 SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF);
550 SET_TX_DESC_DISABLE_FB(pdesc, 0);
Chaoming_Li76c34f92011-04-25 12:54:05 -0500551 SET_TX_DESC_USE_RATE(pdesc, tcb_desc->use_driver_rate ? 1 : 0);
Larry Finger0c817332010-12-08 11:12:31 -0600552
553 if (ieee80211_is_data_qos(fc)) {
554 if (mac->rdg_en) {
555 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
Joe Perchesf30d7502012-01-04 19:40:41 -0800556 "Enable RDG function\n");
Larry Finger0c817332010-12-08 11:12:31 -0600557 SET_TX_DESC_RDG_ENABLE(pdesc, 1);
558 SET_TX_DESC_HTC(pdesc, 1);
559 }
560 }
561 }
Larry Fingerd3bb1422011-04-25 13:23:20 -0500562 rcu_read_unlock();
Larry Finger0c817332010-12-08 11:12:31 -0600563
Larry Finger7ea47242011-02-19 16:28:57 -0600564 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
565 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
Larry Finger0c817332010-12-08 11:12:31 -0600566
567 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
568
Larry Fingerd3bb1422011-04-25 13:23:20 -0500569 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
Larry Finger0c817332010-12-08 11:12:31 -0600570
Larry Finger7ea47242011-02-19 16:28:57 -0600571 if (rtlpriv->dm.useramask) {
Chaoming_Li76c34f92011-04-25 12:54:05 -0500572 SET_TX_DESC_RATE_ID(pdesc, tcb_desc->ratr_index);
573 SET_TX_DESC_MACID(pdesc, tcb_desc->mac_id);
Larry Finger0c817332010-12-08 11:12:31 -0600574 } else {
Chaoming_Li76c34f92011-04-25 12:54:05 -0500575 SET_TX_DESC_RATE_ID(pdesc, 0xC + tcb_desc->ratr_index);
576 SET_TX_DESC_MACID(pdesc, tcb_desc->ratr_index);
Larry Finger0c817332010-12-08 11:12:31 -0600577 }
578
Chaoming_Li76c34f92011-04-25 12:54:05 -0500579 if ((!ieee80211_is_data_qos(fc)) && ppsc->fwctrl_lps) {
Larry Finger0c817332010-12-08 11:12:31 -0600580 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
581 SET_TX_DESC_PKT_ID(pdesc, 8);
582
Larry Finger7ea47242011-02-19 16:28:57 -0600583 if (!defaultadapter)
Larry Finger0c817332010-12-08 11:12:31 -0600584 SET_TX_DESC_QOS(pdesc, 1);
585 }
586
Larry Finger7ea47242011-02-19 16:28:57 -0600587 SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1));
Larry Finger0c817332010-12-08 11:12:31 -0600588
589 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
590 is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
591 SET_TX_DESC_BMC(pdesc, 1);
592 }
593
Joe Perchesf30d7502012-01-04 19:40:41 -0800594 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
Larry Finger0c817332010-12-08 11:12:31 -0600595}
596
597void rtl92ce_tx_fill_cmddesc(struct ieee80211_hw *hw,
Larry Finger7ea47242011-02-19 16:28:57 -0600598 u8 *pdesc, bool firstseg,
599 bool lastseg, struct sk_buff *skb)
Larry Finger0c817332010-12-08 11:12:31 -0600600{
601 struct rtl_priv *rtlpriv = rtl_priv(hw);
602 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
603 u8 fw_queue = QSLT_BEACON;
604
605 dma_addr_t mapping = pci_map_single(rtlpci->pdev,
606 skb->data, skb->len,
607 PCI_DMA_TODEVICE);
608
609 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
Larry Finger17c9ac62011-02-19 16:29:57 -0600610 __le16 fc = hdr->frame_control;
Larry Finger0c817332010-12-08 11:12:31 -0600611
Larry Finger91459102012-12-27 10:37:29 -0600612 if (pci_dma_mapping_error(rtlpci->pdev, mapping)) {
613 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE,
Joe Perches4713bd12016-06-26 12:34:30 -0700614 "DMA mapping error\n");
Larry Finger91459102012-12-27 10:37:29 -0600615 return;
616 }
Larry Finger0c817332010-12-08 11:12:31 -0600617 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE);
618
Larry Finger7ea47242011-02-19 16:28:57 -0600619 if (firstseg)
Larry Finger0c817332010-12-08 11:12:31 -0600620 SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN);
621
Larry Fingere0e776a2014-12-18 03:05:36 -0600622 SET_TX_DESC_TX_RATE(pdesc, DESC_RATE1M);
Larry Finger0c817332010-12-08 11:12:31 -0600623
624 SET_TX_DESC_SEQ(pdesc, 0);
625
626 SET_TX_DESC_LINIP(pdesc, 0);
627
628 SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue);
629
630 SET_TX_DESC_FIRST_SEG(pdesc, 1);
631 SET_TX_DESC_LAST_SEG(pdesc, 1);
632
633 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len));
634
Larry Fingerd3bb1422011-04-25 13:23:20 -0500635 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
Larry Finger0c817332010-12-08 11:12:31 -0600636
637 SET_TX_DESC_RATE_ID(pdesc, 7);
638 SET_TX_DESC_MACID(pdesc, 0);
639
640 SET_TX_DESC_OWN(pdesc, 1);
641
Joe Perches2c208892012-06-04 12:44:17 +0000642 SET_TX_DESC_PKT_SIZE(pdesc, (u16) (skb->len));
Larry Finger0c817332010-12-08 11:12:31 -0600643
644 SET_TX_DESC_FIRST_SEG(pdesc, 1);
645 SET_TX_DESC_LAST_SEG(pdesc, 1);
646
647 SET_TX_DESC_OFFSET(pdesc, 0x20);
648
649 SET_TX_DESC_USE_RATE(pdesc, 1);
650
651 if (!ieee80211_is_data_qos(fc)) {
652 SET_TX_DESC_HWSEQ_EN(pdesc, 1);
653 SET_TX_DESC_PKT_ID(pdesc, 8);
654 }
655
656 RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
Joe Perchesaf086872012-01-04 19:40:40 -0800657 "H2C Tx Cmd Content", pdesc, TX_DESC_SIZE);
Larry Finger0c817332010-12-08 11:12:31 -0600658}
659
Larry Fingerf3355dd2014-03-04 16:53:47 -0600660void rtl92ce_set_desc(struct ieee80211_hw *hw, u8 *pdesc, bool istx,
661 u8 desc_name, u8 *val)
Larry Finger0c817332010-12-08 11:12:31 -0600662{
Mike McCormacke10542c2011-06-20 10:47:51 +0900663 if (istx) {
Larry Finger0c817332010-12-08 11:12:31 -0600664 switch (desc_name) {
665 case HW_DESC_OWN:
Mike McCormack71352b22011-05-31 08:50:07 +0900666 wmb();
Larry Finger0c817332010-12-08 11:12:31 -0600667 SET_TX_DESC_OWN(pdesc, 1);
668 break;
669 case HW_DESC_TX_NEXTDESC_ADDR:
670 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
671 break;
672 default:
Joe Perches9d833ed2012-01-04 19:40:43 -0800673 RT_ASSERT(false, "ERR txdesc :%d not process\n",
674 desc_name);
Larry Finger0c817332010-12-08 11:12:31 -0600675 break;
676 }
677 } else {
678 switch (desc_name) {
679 case HW_DESC_RXOWN:
Mike McCormack71352b22011-05-31 08:50:07 +0900680 wmb();
Larry Finger0c817332010-12-08 11:12:31 -0600681 SET_RX_DESC_OWN(pdesc, 1);
682 break;
683 case HW_DESC_RXBUFF_ADDR:
684 SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val);
685 break;
686 case HW_DESC_RXPKT_LEN:
687 SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val);
688 break;
689 case HW_DESC_RXERO:
690 SET_RX_DESC_EOR(pdesc, 1);
691 break;
692 default:
Joe Perches9d833ed2012-01-04 19:40:43 -0800693 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
694 desc_name);
Larry Finger0c817332010-12-08 11:12:31 -0600695 break;
696 }
697 }
698}
699
700u32 rtl92ce_get_desc(u8 *p_desc, bool istx, u8 desc_name)
701{
702 u32 ret = 0;
703
Mike McCormacke10542c2011-06-20 10:47:51 +0900704 if (istx) {
Larry Finger0c817332010-12-08 11:12:31 -0600705 switch (desc_name) {
706 case HW_DESC_OWN:
707 ret = GET_TX_DESC_OWN(p_desc);
708 break;
709 case HW_DESC_TXBUFF_ADDR:
710 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(p_desc);
711 break;
712 default:
Joe Perches9d833ed2012-01-04 19:40:43 -0800713 RT_ASSERT(false, "ERR txdesc :%d not process\n",
714 desc_name);
Larry Finger0c817332010-12-08 11:12:31 -0600715 break;
716 }
717 } else {
Larry Finger0c817332010-12-08 11:12:31 -0600718 switch (desc_name) {
719 case HW_DESC_OWN:
Larry Finger99a82f72014-11-28 10:41:14 -0600720 ret = GET_RX_DESC_OWN(p_desc);
Larry Finger0c817332010-12-08 11:12:31 -0600721 break;
722 case HW_DESC_RXPKT_LEN:
Larry Finger99a82f72014-11-28 10:41:14 -0600723 ret = GET_RX_DESC_PKT_LEN(p_desc);
Larry Finger0c817332010-12-08 11:12:31 -0600724 break;
Larry Finger8ae3c162014-10-29 23:17:11 -0500725 case HW_DESC_RXBUFF_ADDR:
Larry Finger99a82f72014-11-28 10:41:14 -0600726 ret = GET_RX_DESC_BUFF_ADDR(p_desc);
Larry Finger8ae3c162014-10-29 23:17:11 -0500727 break;
Larry Finger0c817332010-12-08 11:12:31 -0600728 default:
Joe Perches9d833ed2012-01-04 19:40:43 -0800729 RT_ASSERT(false, "ERR rxdesc :%d not process\n",
730 desc_name);
Larry Finger0c817332010-12-08 11:12:31 -0600731 break;
732 }
733 }
734 return ret;
735}
736
Larry Fingerf8929142014-11-28 10:41:15 -0600737bool rtl92ce_is_tx_desc_closed(struct ieee80211_hw *hw,
738 u8 hw_queue, u16 index)
739{
740 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
741 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
742 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
743 u8 own = (u8)rtl92ce_get_desc(entry, true, HW_DESC_OWN);
744
745 /*beacon packet will only use the first
746 *descriptor defautly,and the own may not
747 *be cleared by the hardware
748 */
749 if (own)
750 return false;
751 return true;
752}
753
Chaoming_Li76c34f92011-04-25 12:54:05 -0500754void rtl92ce_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
Larry Finger0c817332010-12-08 11:12:31 -0600755{
756 struct rtl_priv *rtlpriv = rtl_priv(hw);
757 if (hw_queue == BEACON_QUEUE) {
758 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4));
759 } else {
760 rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG,
761 BIT(0) << (hw_queue));
762 }
763}
Larry Finger25b2bc32011-02-11 14:34:03 -0600764