spi-topcliff-pch: add recovery processing in case wait-event timeout
[zen-stable.git] / drivers / net / wireless / rtlwifi / rtl8192se / trx.c
blobfbebe3ea0a22b95cedd432b0ca663d871915112c
1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
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.
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.
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
30 #include "../wifi.h"
31 #include "../pci.h"
32 #include "../base.h"
33 #include "reg.h"
34 #include "def.h"
35 #include "phy.h"
36 #include "fw.h"
37 #include "trx.h"
38 #include "led.h"
40 static u8 _rtl92se_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 skb_queue)
42 __le16 fc = rtl_get_fc(skb);
44 if (unlikely(ieee80211_is_beacon(fc)))
45 return QSLT_BEACON;
46 if (ieee80211_is_mgmt(fc))
47 return QSLT_MGNT;
48 if (ieee80211_is_nullfunc(fc))
49 return QSLT_HIGH;
51 return skb->priority;
54 static u8 _rtl92s_query_rxpwrpercentage(char antpower)
56 if ((antpower <= -100) || (antpower >= 20))
57 return 0;
58 else if (antpower >= 0)
59 return 100;
60 else
61 return 100 + antpower;
64 static u8 _rtl92s_evm_db_to_percentage(char value)
66 char ret_val;
67 ret_val = value;
69 if (ret_val >= 0)
70 ret_val = 0;
72 if (ret_val <= -33)
73 ret_val = -33;
75 ret_val = 0 - ret_val;
76 ret_val *= 3;
78 if (ret_val == 99)
79 ret_val = 100;
81 return ret_val;
84 static long _rtl92se_translate_todbm(struct ieee80211_hw *hw,
85 u8 signal_strength_index)
87 long signal_power;
89 signal_power = (long)((signal_strength_index + 1) >> 1);
90 signal_power -= 95;
91 return signal_power;
94 static long _rtl92se_signal_scale_mapping(struct ieee80211_hw *hw,
95 long currsig)
97 long retsig = 0;
99 /* Step 1. Scale mapping. */
100 if (currsig > 47)
101 retsig = 100;
102 else if (currsig > 14 && currsig <= 47)
103 retsig = 100 - ((47 - currsig) * 3) / 2;
104 else if (currsig > 2 && currsig <= 14)
105 retsig = 48 - ((14 - currsig) * 15) / 7;
106 else if (currsig >= 0)
107 retsig = currsig * 9 + 1;
109 return retsig;
113 static void _rtl92se_query_rxphystatus(struct ieee80211_hw *hw,
114 struct rtl_stats *pstats, u8 *pdesc,
115 struct rx_fwinfo *p_drvinfo,
116 bool packet_match_bssid,
117 bool packet_toself,
118 bool packet_beacon)
120 struct rtl_priv *rtlpriv = rtl_priv(hw);
121 struct phy_sts_cck_8192s_t *cck_buf;
122 s8 rx_pwr_all = 0, rx_pwr[4];
123 u8 rf_rx_num = 0, evm, pwdb_all;
124 u8 i, max_spatial_stream;
125 u32 rssi, total_rssi = 0;
126 bool in_powersavemode = false;
127 bool is_cck = pstats->is_cck;
129 pstats->packet_matchbssid = packet_match_bssid;
130 pstats->packet_toself = packet_toself;
131 pstats->packet_beacon = packet_beacon;
132 pstats->rx_mimo_signalquality[0] = -1;
133 pstats->rx_mimo_signalquality[1] = -1;
135 if (is_cck) {
136 u8 report, cck_highpwr;
137 cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
139 if (!in_powersavemode)
140 cck_highpwr = (u8) rtl_get_bbreg(hw,
141 RFPGA0_XA_HSSIPARAMETER2,
142 0x200);
143 else
144 cck_highpwr = false;
146 if (!cck_highpwr) {
147 u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
148 report = cck_buf->cck_agc_rpt & 0xc0;
149 report = report >> 6;
150 switch (report) {
151 case 0x3:
152 rx_pwr_all = -40 - (cck_agc_rpt & 0x3e);
153 break;
154 case 0x2:
155 rx_pwr_all = -20 - (cck_agc_rpt & 0x3e);
156 break;
157 case 0x1:
158 rx_pwr_all = -2 - (cck_agc_rpt & 0x3e);
159 break;
160 case 0x0:
161 rx_pwr_all = 14 - (cck_agc_rpt & 0x3e);
162 break;
164 } else {
165 u8 cck_agc_rpt = cck_buf->cck_agc_rpt;
166 report = p_drvinfo->cfosho[0] & 0x60;
167 report = report >> 5;
168 switch (report) {
169 case 0x3:
170 rx_pwr_all = -40 - ((cck_agc_rpt & 0x1f) << 1);
171 break;
172 case 0x2:
173 rx_pwr_all = -20 - ((cck_agc_rpt & 0x1f) << 1);
174 break;
175 case 0x1:
176 rx_pwr_all = -2 - ((cck_agc_rpt & 0x1f) << 1);
177 break;
178 case 0x0:
179 rx_pwr_all = 14 - ((cck_agc_rpt & 0x1f) << 1);
180 break;
184 pwdb_all = _rtl92s_query_rxpwrpercentage(rx_pwr_all);
186 /* CCK gain is smaller than OFDM/MCS gain, */
187 /* so we add gain diff by experiences, the val is 6 */
188 pwdb_all += 6;
189 if (pwdb_all > 100)
190 pwdb_all = 100;
191 /* modify the offset to make the same gain index with OFDM. */
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;
201 pstats->rx_pwdb_all = pwdb_all;
202 pstats->recvsignalpower = rx_pwr_all;
204 if (packet_match_bssid) {
205 u8 sq;
206 if (pstats->rx_pwdb_all > 40) {
207 sq = 100;
208 } else {
209 sq = cck_buf->sq_rpt;
210 if (sq > 64)
211 sq = 0;
212 else if (sq < 20)
213 sq = 100;
214 else
215 sq = ((64 - sq) * 100) / 44;
218 pstats->signalquality = sq;
219 pstats->rx_mimo_signalquality[0] = sq;
220 pstats->rx_mimo_signalquality[1] = -1;
222 } else {
223 rtlpriv->dm.rfpath_rxenable[0] =
224 rtlpriv->dm.rfpath_rxenable[1] = true;
225 for (i = RF90_PATH_A; i < RF90_PATH_MAX; i++) {
226 if (rtlpriv->dm.rfpath_rxenable[i])
227 rf_rx_num++;
229 rx_pwr[i] = ((p_drvinfo->gain_trsw[i] &
230 0x3f) * 2) - 110;
231 rssi = _rtl92s_query_rxpwrpercentage(rx_pwr[i]);
232 total_rssi += rssi;
233 rtlpriv->stats.rx_snr_db[i] =
234 (long)(p_drvinfo->rxsnr[i] / 2);
236 if (packet_match_bssid)
237 pstats->rx_mimo_signalstrength[i] = (u8) rssi;
240 rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110;
241 pwdb_all = _rtl92s_query_rxpwrpercentage(rx_pwr_all);
242 pstats->rx_pwdb_all = pwdb_all;
243 pstats->rxpower = rx_pwr_all;
244 pstats->recvsignalpower = rx_pwr_all;
246 if (pstats->is_ht && pstats->rate >= DESC92_RATEMCS8 &&
247 pstats->rate <= DESC92_RATEMCS15)
248 max_spatial_stream = 2;
249 else
250 max_spatial_stream = 1;
252 for (i = 0; i < max_spatial_stream; i++) {
253 evm = _rtl92s_evm_db_to_percentage(p_drvinfo->rxevm[i]);
255 if (packet_match_bssid) {
256 if (i == 0)
257 pstats->signalquality = (u8)(evm &
258 0xff);
259 pstats->rx_mimo_signalquality[i] =
260 (u8) (evm & 0xff);
265 if (is_cck)
266 pstats->signalstrength = (u8)(_rtl92se_signal_scale_mapping(hw,
267 pwdb_all));
268 else if (rf_rx_num != 0)
269 pstats->signalstrength = (u8) (_rtl92se_signal_scale_mapping(hw,
270 total_rssi /= rf_rx_num));
273 static void _rtl92se_process_ui_rssi(struct ieee80211_hw *hw,
274 struct rtl_stats *pstats)
276 struct rtl_priv *rtlpriv = rtl_priv(hw);
277 struct rtl_phy *rtlphy = &(rtlpriv->phy);
278 u8 rfpath;
279 u32 last_rssi, tmpval;
281 if (pstats->packet_toself || pstats->packet_beacon) {
282 rtlpriv->stats.rssi_calculate_cnt++;
284 if (rtlpriv->stats.ui_rssi.total_num++ >=
285 PHY_RSSI_SLID_WIN_MAX) {
286 rtlpriv->stats.ui_rssi.total_num =
287 PHY_RSSI_SLID_WIN_MAX;
288 last_rssi = rtlpriv->stats.ui_rssi.elements[
289 rtlpriv->stats.ui_rssi.index];
290 rtlpriv->stats.ui_rssi.total_val -= last_rssi;
293 rtlpriv->stats.ui_rssi.total_val += pstats->signalstrength;
294 rtlpriv->stats.ui_rssi.elements[rtlpriv->stats.ui_rssi.index++]
295 = pstats->signalstrength;
297 if (rtlpriv->stats.ui_rssi.index >= PHY_RSSI_SLID_WIN_MAX)
298 rtlpriv->stats.ui_rssi.index = 0;
300 tmpval = rtlpriv->stats.ui_rssi.total_val /
301 rtlpriv->stats.ui_rssi.total_num;
302 rtlpriv->stats.signal_strength = _rtl92se_translate_todbm(hw,
303 (u8) tmpval);
304 pstats->rssi = rtlpriv->stats.signal_strength;
307 if (!pstats->is_cck && pstats->packet_toself) {
308 for (rfpath = RF90_PATH_A; rfpath < rtlphy->num_total_rfpath;
309 rfpath++) {
310 if (rtlpriv->stats.rx_rssi_percentage[rfpath] == 0) {
311 rtlpriv->stats.rx_rssi_percentage[rfpath] =
312 pstats->rx_mimo_signalstrength[rfpath];
316 if (pstats->rx_mimo_signalstrength[rfpath] >
317 rtlpriv->stats.rx_rssi_percentage[rfpath]) {
318 rtlpriv->stats.rx_rssi_percentage[rfpath] =
319 ((rtlpriv->stats.rx_rssi_percentage[rfpath]
320 * (RX_SMOOTH_FACTOR - 1)) +
321 (pstats->rx_mimo_signalstrength[rfpath])) /
322 (RX_SMOOTH_FACTOR);
324 rtlpriv->stats.rx_rssi_percentage[rfpath] =
325 rtlpriv->stats.rx_rssi_percentage[rfpath]
326 + 1;
327 } else {
328 rtlpriv->stats.rx_rssi_percentage[rfpath] =
329 ((rtlpriv->stats.rx_rssi_percentage[rfpath]
330 * (RX_SMOOTH_FACTOR - 1)) +
331 (pstats->rx_mimo_signalstrength[rfpath])) /
332 (RX_SMOOTH_FACTOR);
339 static void _rtl92se_update_rxsignalstatistics(struct ieee80211_hw *hw,
340 struct rtl_stats *pstats)
342 struct rtl_priv *rtlpriv = rtl_priv(hw);
343 int weighting = 0;
345 if (rtlpriv->stats.recv_signal_power == 0)
346 rtlpriv->stats.recv_signal_power = pstats->recvsignalpower;
348 if (pstats->recvsignalpower > rtlpriv->stats.recv_signal_power)
349 weighting = 5;
350 else if (pstats->recvsignalpower < rtlpriv->stats.recv_signal_power)
351 weighting = (-5);
353 rtlpriv->stats.recv_signal_power = (rtlpriv->stats.recv_signal_power * 5
354 + pstats->recvsignalpower +
355 weighting) / 6;
358 static void _rtl92se_process_pwdb(struct ieee80211_hw *hw,
359 struct rtl_stats *pstats)
361 struct rtl_priv *rtlpriv = rtl_priv(hw);
362 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
363 long undec_sm_pwdb = 0;
365 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
366 return;
367 } else {
368 undec_sm_pwdb =
369 rtlpriv->dm.undecorated_smoothed_pwdb;
372 if (pstats->packet_toself || pstats->packet_beacon) {
373 if (undec_sm_pwdb < 0)
374 undec_sm_pwdb = pstats->rx_pwdb_all;
376 if (pstats->rx_pwdb_all > (u32) undec_sm_pwdb) {
377 undec_sm_pwdb =
378 (((undec_sm_pwdb) *
379 (RX_SMOOTH_FACTOR - 1)) +
380 (pstats->rx_pwdb_all)) / (RX_SMOOTH_FACTOR);
382 undec_sm_pwdb = undec_sm_pwdb + 1;
383 } else {
384 undec_sm_pwdb = (((undec_sm_pwdb) *
385 (RX_SMOOTH_FACTOR - 1)) + (pstats->rx_pwdb_all)) /
386 (RX_SMOOTH_FACTOR);
389 rtlpriv->dm.undecorated_smoothed_pwdb = undec_sm_pwdb;
390 _rtl92se_update_rxsignalstatistics(hw, pstats);
394 static void rtl_92s_process_streams(struct ieee80211_hw *hw,
395 struct rtl_stats *pstats)
397 struct rtl_priv *rtlpriv = rtl_priv(hw);
398 u32 stream;
400 for (stream = 0; stream < 2; stream++) {
401 if (pstats->rx_mimo_signalquality[stream] != -1) {
402 if (rtlpriv->stats.rx_evm_percentage[stream] == 0) {
403 rtlpriv->stats.rx_evm_percentage[stream] =
404 pstats->rx_mimo_signalquality[stream];
407 rtlpriv->stats.rx_evm_percentage[stream] =
408 ((rtlpriv->stats.rx_evm_percentage[stream] *
409 (RX_SMOOTH_FACTOR - 1)) +
410 (pstats->rx_mimo_signalquality[stream] *
411 1)) / (RX_SMOOTH_FACTOR);
416 static void _rtl92se_process_ui_link_quality(struct ieee80211_hw *hw,
417 struct rtl_stats *pstats)
419 struct rtl_priv *rtlpriv = rtl_priv(hw);
420 u32 last_evm = 0, tmpval;
422 if (pstats->signalquality != 0) {
423 if (pstats->packet_toself || pstats->packet_beacon) {
425 if (rtlpriv->stats.ui_link_quality.total_num++ >=
426 PHY_LINKQUALITY_SLID_WIN_MAX) {
427 rtlpriv->stats.ui_link_quality.total_num =
428 PHY_LINKQUALITY_SLID_WIN_MAX;
429 last_evm =
430 rtlpriv->stats.ui_link_quality.elements[
431 rtlpriv->stats.ui_link_quality.index];
432 rtlpriv->stats.ui_link_quality.total_val -=
433 last_evm;
436 rtlpriv->stats.ui_link_quality.total_val +=
437 pstats->signalquality;
438 rtlpriv->stats.ui_link_quality.elements[
439 rtlpriv->stats.ui_link_quality.index++] =
440 pstats->signalquality;
442 if (rtlpriv->stats.ui_link_quality.index >=
443 PHY_LINKQUALITY_SLID_WIN_MAX)
444 rtlpriv->stats.ui_link_quality.index = 0;
446 tmpval = rtlpriv->stats.ui_link_quality.total_val /
447 rtlpriv->stats.ui_link_quality.total_num;
448 rtlpriv->stats.signal_quality = tmpval;
450 rtlpriv->stats.last_sigstrength_inpercent = tmpval;
452 rtl_92s_process_streams(hw, pstats);
458 static void _rtl92se_process_phyinfo(struct ieee80211_hw *hw,
459 u8 *buffer,
460 struct rtl_stats *pcurrent_stats)
463 if (!pcurrent_stats->packet_matchbssid &&
464 !pcurrent_stats->packet_beacon)
465 return;
467 _rtl92se_process_ui_rssi(hw, pcurrent_stats);
468 _rtl92se_process_pwdb(hw, pcurrent_stats);
469 _rtl92se_process_ui_link_quality(hw, pcurrent_stats);
472 static void _rtl92se_translate_rx_signal_stuff(struct ieee80211_hw *hw,
473 struct sk_buff *skb, struct rtl_stats *pstats,
474 u8 *pdesc, struct rx_fwinfo *p_drvinfo)
476 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
477 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
479 struct ieee80211_hdr *hdr;
480 u8 *tmp_buf;
481 u8 *praddr;
482 __le16 fc;
483 u16 type, cfc;
484 bool packet_matchbssid, packet_toself, packet_beacon;
486 tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
488 hdr = (struct ieee80211_hdr *)tmp_buf;
489 fc = hdr->frame_control;
490 cfc = le16_to_cpu(fc);
491 type = WLAN_FC_GET_TYPE(fc);
492 praddr = hdr->addr1;
494 packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
495 (!compare_ether_addr(mac->bssid, (cfc & IEEE80211_FCTL_TODS) ?
496 hdr->addr1 : (cfc & IEEE80211_FCTL_FROMDS) ?
497 hdr->addr2 : hdr->addr3)) && (!pstats->hwerror) &&
498 (!pstats->crc) && (!pstats->icv));
500 packet_toself = packet_matchbssid &&
501 (!compare_ether_addr(praddr, rtlefuse->dev_addr));
503 if (ieee80211_is_beacon(fc))
504 packet_beacon = true;
506 _rtl92se_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
507 packet_matchbssid, packet_toself, packet_beacon);
508 _rtl92se_process_phyinfo(hw, tmp_buf, pstats);
511 bool rtl92se_rx_query_desc(struct ieee80211_hw *hw, struct rtl_stats *stats,
512 struct ieee80211_rx_status *rx_status, u8 *pdesc,
513 struct sk_buff *skb)
515 struct rx_fwinfo *p_drvinfo;
516 u32 phystatus = (u32)GET_RX_STATUS_DESC_PHY_STATUS(pdesc);
517 struct ieee80211_hdr *hdr;
518 bool first_ampdu = false;
520 stats->length = (u16)GET_RX_STATUS_DESC_PKT_LEN(pdesc);
521 stats->rx_drvinfo_size = (u8)GET_RX_STATUS_DESC_DRVINFO_SIZE(pdesc) * 8;
522 stats->rx_bufshift = (u8)(GET_RX_STATUS_DESC_SHIFT(pdesc) & 0x03);
523 stats->icv = (u16)GET_RX_STATUS_DESC_ICV(pdesc);
524 stats->crc = (u16)GET_RX_STATUS_DESC_CRC32(pdesc);
525 stats->hwerror = (u16)(stats->crc | stats->icv);
526 stats->decrypted = !GET_RX_STATUS_DESC_SWDEC(pdesc);
528 stats->rate = (u8)GET_RX_STATUS_DESC_RX_MCS(pdesc);
529 stats->shortpreamble = (u16)GET_RX_STATUS_DESC_SPLCP(pdesc);
530 stats->isampdu = (bool)(GET_RX_STATUS_DESC_PAGGR(pdesc) == 1);
531 stats->isfirst_ampdu = (bool) ((GET_RX_STATUS_DESC_PAGGR(pdesc) == 1)
532 && (GET_RX_STATUS_DESC_FAGGR(pdesc) == 1));
533 stats->timestamp_low = GET_RX_STATUS_DESC_TSFL(pdesc);
534 stats->rx_is40Mhzpacket = (bool)GET_RX_STATUS_DESC_BW(pdesc);
535 stats->is_ht = (bool)GET_RX_STATUS_DESC_RX_HT(pdesc);
536 stats->is_cck = SE_RX_HAL_IS_CCK_RATE(pdesc);
538 if (stats->hwerror)
539 return false;
541 rx_status->freq = hw->conf.channel->center_freq;
542 rx_status->band = hw->conf.channel->band;
544 hdr = (struct ieee80211_hdr *)(skb->data + stats->rx_drvinfo_size
545 + stats->rx_bufshift);
547 if (stats->crc)
548 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
550 if (stats->rx_is40Mhzpacket)
551 rx_status->flag |= RX_FLAG_40MHZ;
553 if (stats->is_ht)
554 rx_status->flag |= RX_FLAG_HT;
556 rx_status->flag |= RX_FLAG_MACTIME_MPDU;
558 /* hw will set stats->decrypted true, if it finds the
559 * frame is open data frame or mgmt frame,
560 * hw will not decrypt robust managment frame
561 * for IEEE80211w but still set stats->decrypted
562 * true, so here we should set it back to undecrypted
563 * for IEEE80211w frame, and mac80211 sw will help
564 * to decrypt it */
565 if (stats->decrypted) {
566 if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
567 (ieee80211_has_protected(hdr->frame_control)))
568 rx_status->flag &= ~RX_FLAG_DECRYPTED;
569 else
570 rx_status->flag |= RX_FLAG_DECRYPTED;
573 rx_status->rate_idx = rtlwifi_rate_mapping(hw,
574 stats->is_ht, stats->rate, first_ampdu);
576 rx_status->mactime = stats->timestamp_low;
577 if (phystatus) {
578 p_drvinfo = (struct rx_fwinfo *)(skb->data +
579 stats->rx_bufshift);
580 _rtl92se_translate_rx_signal_stuff(hw, skb, stats, pdesc,
581 p_drvinfo);
584 /*rx_status->qual = stats->signal; */
585 rx_status->signal = stats->rssi + 10;
586 /*rx_status->noise = -stats->noise; */
588 return true;
591 void rtl92se_tx_fill_desc(struct ieee80211_hw *hw,
592 struct ieee80211_hdr *hdr, u8 *pdesc_tx,
593 struct ieee80211_tx_info *info, struct sk_buff *skb,
594 u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
596 struct rtl_priv *rtlpriv = rtl_priv(hw);
597 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
598 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
599 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
600 struct ieee80211_sta *sta = info->control.sta;
601 u8 *pdesc = (u8 *) pdesc_tx;
602 u16 seq_number;
603 __le16 fc = hdr->frame_control;
604 u8 reserved_macid = 0;
605 u8 fw_qsel = _rtl92se_map_hwqueue_to_fwqueue(skb, hw_queue);
606 bool firstseg = (!(hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG)));
607 bool lastseg = (!(hdr->frame_control &
608 cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)));
609 dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
610 PCI_DMA_TODEVICE);
611 u8 bw_40 = 0;
613 if (mac->opmode == NL80211_IFTYPE_STATION) {
614 bw_40 = mac->bw_40;
615 } else if (mac->opmode == NL80211_IFTYPE_AP ||
616 mac->opmode == NL80211_IFTYPE_ADHOC) {
617 if (sta)
618 bw_40 = sta->ht_cap.cap &
619 IEEE80211_HT_CAP_SUP_WIDTH_20_40;
622 seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
624 rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
626 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE_RTL8192S);
628 if (firstseg) {
629 if (rtlpriv->dm.useramask) {
630 /* set txdesc macId */
631 if (ptcb_desc->mac_id < 32) {
632 SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
633 reserved_macid |= ptcb_desc->mac_id;
636 SET_TX_DESC_RSVD_MACID(pdesc, reserved_macid);
638 SET_TX_DESC_TXHT(pdesc, ((ptcb_desc->hw_rate >=
639 DESC92_RATEMCS0) ? 1 : 0));
641 if (rtlhal->version == VERSION_8192S_ACUT) {
642 if (ptcb_desc->hw_rate == DESC92_RATE1M ||
643 ptcb_desc->hw_rate == DESC92_RATE2M ||
644 ptcb_desc->hw_rate == DESC92_RATE5_5M ||
645 ptcb_desc->hw_rate == DESC92_RATE11M) {
646 ptcb_desc->hw_rate = DESC92_RATE12M;
650 SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
652 if (ptcb_desc->use_shortgi || ptcb_desc->use_shortpreamble)
653 SET_TX_DESC_TX_SHORT(pdesc, 0);
655 /* Aggregation related */
656 if (info->flags & IEEE80211_TX_CTL_AMPDU)
657 SET_TX_DESC_AGG_ENABLE(pdesc, 1);
659 /* For AMPDU, we must insert SSN into TX_DESC */
660 SET_TX_DESC_SEQ(pdesc, seq_number);
662 /* Protection mode related */
663 /* For 92S, if RTS/CTS are set, HW will execute RTS. */
664 /* We choose only one protection mode to execute */
665 SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
666 !ptcb_desc->cts_enable) ? 1 : 0));
667 SET_TX_DESC_CTS_ENABLE(pdesc, ((ptcb_desc->cts_enable) ?
668 1 : 0));
669 SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
671 SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
672 SET_TX_DESC_RTS_BANDWIDTH(pdesc, 0);
673 SET_TX_DESC_RTS_SUB_CARRIER(pdesc, ptcb_desc->rts_sc);
674 SET_TX_DESC_RTS_SHORT(pdesc, ((ptcb_desc->rts_rate <=
675 DESC92_RATE54M) ?
676 (ptcb_desc->rts_use_shortpreamble ? 1 : 0)
677 : (ptcb_desc->rts_use_shortgi ? 1 : 0)));
680 /* Set Bandwidth and sub-channel settings. */
681 if (bw_40) {
682 if (ptcb_desc->packet_bw) {
683 SET_TX_DESC_TX_BANDWIDTH(pdesc, 1);
684 /* use duplicated mode */
685 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
686 } else {
687 SET_TX_DESC_TX_BANDWIDTH(pdesc, 0);
688 SET_TX_DESC_TX_SUB_CARRIER(pdesc,
689 mac->cur_40_prime_sc);
691 } else {
692 SET_TX_DESC_TX_BANDWIDTH(pdesc, 0);
693 SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
696 /* 3 Fill necessary field in First Descriptor */
697 /*DWORD 0*/
698 SET_TX_DESC_LINIP(pdesc, 0);
699 SET_TX_DESC_OFFSET(pdesc, 32);
700 SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
702 /*DWORD 1*/
703 SET_TX_DESC_RA_BRSR_ID(pdesc, ptcb_desc->ratr_index);
705 /* Fill security related */
706 if (info->control.hw_key) {
707 struct ieee80211_key_conf *keyconf;
709 keyconf = info->control.hw_key;
710 switch (keyconf->cipher) {
711 case WLAN_CIPHER_SUITE_WEP40:
712 case WLAN_CIPHER_SUITE_WEP104:
713 SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
714 break;
715 case WLAN_CIPHER_SUITE_TKIP:
716 SET_TX_DESC_SEC_TYPE(pdesc, 0x2);
717 break;
718 case WLAN_CIPHER_SUITE_CCMP:
719 SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
720 break;
721 default:
722 SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
723 break;
728 /* Set Packet ID */
729 SET_TX_DESC_PACKET_ID(pdesc, 0);
731 /* We will assign magement queue to BK. */
732 SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
734 /* Alwasy enable all rate fallback range */
735 SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
737 /* Fix: I don't kown why hw use 6.5M to tx when set it */
738 SET_TX_DESC_USER_RATE(pdesc,
739 ptcb_desc->use_driver_rate ? 1 : 0);
741 /* Set NON_QOS bit. */
742 if (!ieee80211_is_data_qos(fc))
743 SET_TX_DESC_NON_QOS(pdesc, 1);
747 /* Fill fields that are required to be initialized
748 * in all of the descriptors */
749 /*DWORD 0 */
750 SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
751 SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
753 /* DWORD 7 */
754 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
756 /* DOWRD 8 */
757 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
759 RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, ("\n"));
762 void rtl92se_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
763 bool firstseg, bool lastseg, struct sk_buff *skb)
765 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
766 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
767 struct rtl_tcb_desc *tcb_desc = (struct rtl_tcb_desc *)(skb->cb);
769 dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
770 PCI_DMA_TODEVICE);
772 /* Clear all status */
773 CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_CMDDESC_SIZE_RTL8192S);
775 /* This bit indicate this packet is used for FW download. */
776 if (tcb_desc->cmd_or_init == DESC_PACKET_TYPE_INIT) {
777 /* For firmware downlaod we only need to set LINIP */
778 SET_TX_DESC_LINIP(pdesc, tcb_desc->last_inipkt);
780 /* 92SE must set as 1 for firmware download HW DMA error */
781 SET_TX_DESC_FIRST_SEG(pdesc, 1);
782 SET_TX_DESC_LAST_SEG(pdesc, 1);
784 /* 92SE need not to set TX packet size when firmware download */
785 SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
786 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
787 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
789 wmb();
790 SET_TX_DESC_OWN(pdesc, 1);
791 } else { /* H2C Command Desc format (Host TXCMD) */
792 /* 92SE must set as 1 for firmware download HW DMA error */
793 SET_TX_DESC_FIRST_SEG(pdesc, 1);
794 SET_TX_DESC_LAST_SEG(pdesc, 1);
796 SET_TX_DESC_OFFSET(pdesc, 0x20);
798 /* Buffer size + command header */
799 SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
800 /* Fixed queue of H2C command */
801 SET_TX_DESC_QUEUE_SEL(pdesc, 0x13);
803 SET_BITS_TO_LE_4BYTE(skb->data, 24, 7, rtlhal->h2c_txcmd_seq);
805 SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
806 SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, cpu_to_le32(mapping));
808 wmb();
809 SET_TX_DESC_OWN(pdesc, 1);
814 void rtl92se_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val)
816 if (istx) {
817 switch (desc_name) {
818 case HW_DESC_OWN:
819 wmb();
820 SET_TX_DESC_OWN(pdesc, 1);
821 break;
822 case HW_DESC_TX_NEXTDESC_ADDR:
823 SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
824 break;
825 default:
826 RT_ASSERT(false, ("ERR txdesc :%d not process\n",
827 desc_name));
828 break;
830 } else {
831 switch (desc_name) {
832 case HW_DESC_RXOWN:
833 wmb();
834 SET_RX_STATUS_DESC_OWN(pdesc, 1);
835 break;
836 case HW_DESC_RXBUFF_ADDR:
837 SET_RX_STATUS__DESC_BUFF_ADDR(pdesc, *(u32 *) val);
838 break;
839 case HW_DESC_RXPKT_LEN:
840 SET_RX_STATUS_DESC_PKT_LEN(pdesc, *(u32 *) val);
841 break;
842 case HW_DESC_RXERO:
843 SET_RX_STATUS_DESC_EOR(pdesc, 1);
844 break;
845 default:
846 RT_ASSERT(false, ("ERR rxdesc :%d not process\n",
847 desc_name));
848 break;
853 u32 rtl92se_get_desc(u8 *desc, bool istx, u8 desc_name)
855 u32 ret = 0;
857 if (istx) {
858 switch (desc_name) {
859 case HW_DESC_OWN:
860 ret = GET_TX_DESC_OWN(desc);
861 break;
862 case HW_DESC_TXBUFF_ADDR:
863 ret = GET_TX_DESC_TX_BUFFER_ADDRESS(desc);
864 break;
865 default:
866 RT_ASSERT(false, ("ERR txdesc :%d not process\n",
867 desc_name));
868 break;
870 } else {
871 switch (desc_name) {
872 case HW_DESC_OWN:
873 ret = GET_RX_STATUS_DESC_OWN(desc);
874 break;
875 case HW_DESC_RXPKT_LEN:
876 ret = GET_RX_STATUS_DESC_PKT_LEN(desc);
877 break;
878 default:
879 RT_ASSERT(false, ("ERR rxdesc :%d not process\n",
880 desc_name));
881 break;
884 return ret;
887 void rtl92se_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
889 struct rtl_priv *rtlpriv = rtl_priv(hw);
890 rtl_write_word(rtlpriv, TP_POLL, BIT(0) << (hw_queue));