Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
trx.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012 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 <[email protected]>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <[email protected]>
27  *
28  *****************************************************************************/
29 
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"
39 
40 static u8 _rtl92se_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 skb_queue)
41 {
42  __le16 fc = rtl_get_fc(skb);
43 
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;
50 
51  return skb->priority;
52 }
53 
54 static u8 _rtl92s_query_rxpwrpercentage(char antpower)
55 {
56  if ((antpower <= -100) || (antpower >= 20))
57  return 0;
58  else if (antpower >= 0)
59  return 100;
60  else
61  return 100 + antpower;
62 }
63 
64 static u8 _rtl92s_evm_db_to_percentage(char value)
65 {
66  char ret_val;
67  ret_val = value;
68 
69  if (ret_val >= 0)
70  ret_val = 0;
71 
72  if (ret_val <= -33)
73  ret_val = -33;
74 
75  ret_val = 0 - ret_val;
76  ret_val *= 3;
77 
78  if (ret_val == 99)
79  ret_val = 100;
80 
81  return ret_val;
82 }
83 
84 static long _rtl92se_translate_todbm(struct ieee80211_hw *hw,
85  u8 signal_strength_index)
86 {
87  long signal_power;
88 
89  signal_power = (long)((signal_strength_index + 1) >> 1);
90  signal_power -= 95;
91  return signal_power;
92 }
93 
94 static long _rtl92se_signal_scale_mapping(struct ieee80211_hw *hw,
95  long currsig)
96 {
97  long retsig = 0;
98 
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;
108 
109  return retsig;
110 }
111 
112 
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)
119 {
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;
128 
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;
134 
135  if (is_cck) {
136  u8 report, cck_highpwr;
137  cck_buf = (struct phy_sts_cck_8192s_t *)p_drvinfo;
138 
139  if (!in_powersavemode)
140  cck_highpwr = (u8) rtl_get_bbreg(hw,
142  0x200);
143  else
144  cck_highpwr = false;
145 
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;
163  }
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;
181  }
182  }
183 
184  pwdb_all = _rtl92s_query_rxpwrpercentage(rx_pwr_all);
185 
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;
200 
201  pstats->rx_pwdb_all = pwdb_all;
202  pstats->recvsignalpower = rx_pwr_all;
203 
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;
216  }
217 
218  pstats->signalquality = sq;
219  pstats->rx_mimo_signalquality[0] = sq;
220  pstats->rx_mimo_signalquality[1] = -1;
221  }
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++;
228 
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);
235 
236  if (packet_match_bssid)
237  pstats->rx_mimo_signalstrength[i] = (u8) rssi;
238  }
239 
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;
245 
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;
251 
252  for (i = 0; i < max_spatial_stream; i++) {
253  evm = _rtl92s_evm_db_to_percentage(p_drvinfo->rxevm[i]);
254 
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);
261  }
262  }
263  }
264 
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));
271 }
272 
273 static void _rtl92se_process_ui_rssi(struct ieee80211_hw *hw,
274  struct rtl_stats *pstats)
275 {
276  struct rtl_priv *rtlpriv = rtl_priv(hw);
277  struct rtl_phy *rtlphy = &(rtlpriv->phy);
278  u8 rfpath;
279  u32 last_rssi, tmpval;
280 
281  if (pstats->packet_toself || pstats->packet_beacon) {
282  rtlpriv->stats.rssi_calculate_cnt++;
283 
284  if (rtlpriv->stats.ui_rssi.total_num++ >=
286  rtlpriv->stats.ui_rssi.total_num =
288  last_rssi = rtlpriv->stats.ui_rssi.elements[
289  rtlpriv->stats.ui_rssi.index];
290  rtlpriv->stats.ui_rssi.total_val -= last_rssi;
291  }
292 
293  rtlpriv->stats.ui_rssi.total_val += pstats->signalstrength;
294  rtlpriv->stats.ui_rssi.elements[rtlpriv->stats.ui_rssi.index++]
295  = pstats->signalstrength;
296 
297  if (rtlpriv->stats.ui_rssi.index >= PHY_RSSI_SLID_WIN_MAX)
298  rtlpriv->stats.ui_rssi.index = 0;
299 
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;
305  }
306 
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];
313 
314  }
315 
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])) /
323 
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])) /
333  }
334 
335  }
336  }
337 }
338 
339 static void _rtl92se_update_rxsignalstatistics(struct ieee80211_hw *hw,
340  struct rtl_stats *pstats)
341 {
342  struct rtl_priv *rtlpriv = rtl_priv(hw);
343  int weighting = 0;
344 
345  if (rtlpriv->stats.recv_signal_power == 0)
346  rtlpriv->stats.recv_signal_power = pstats->recvsignalpower;
347 
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);
352 
353  rtlpriv->stats.recv_signal_power = (rtlpriv->stats.recv_signal_power * 5
354  + pstats->recvsignalpower +
355  weighting) / 6;
356 }
357 
358 static void _rtl92se_process_pwdb(struct ieee80211_hw *hw,
359  struct rtl_stats *pstats)
360 {
361  struct rtl_priv *rtlpriv = rtl_priv(hw);
362  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
363  long undec_sm_pwdb = 0;
364 
365  if (mac->opmode == NL80211_IFTYPE_ADHOC) {
366  return;
367  } else {
368  undec_sm_pwdb =
369  rtlpriv->dm.undecorated_smoothed_pwdb;
370  }
371 
372  if (pstats->packet_toself || pstats->packet_beacon) {
373  if (undec_sm_pwdb < 0)
374  undec_sm_pwdb = pstats->rx_pwdb_all;
375 
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);
381 
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)) /
387  }
388 
389  rtlpriv->dm.undecorated_smoothed_pwdb = undec_sm_pwdb;
390  _rtl92se_update_rxsignalstatistics(hw, pstats);
391  }
392 }
393 
394 static void rtl_92s_process_streams(struct ieee80211_hw *hw,
395  struct rtl_stats *pstats)
396 {
397  struct rtl_priv *rtlpriv = rtl_priv(hw);
398  u32 stream;
399 
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];
405  }
406 
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);
412  }
413  }
414 }
415 
416 static void _rtl92se_process_ui_link_quality(struct ieee80211_hw *hw,
417  struct rtl_stats *pstats)
418 {
419  struct rtl_priv *rtlpriv = rtl_priv(hw);
420  u32 last_evm = 0, tmpval;
421 
422  if (pstats->signalquality != 0) {
423  if (pstats->packet_toself || pstats->packet_beacon) {
424 
425  if (rtlpriv->stats.ui_link_quality.total_num++ >=
427  rtlpriv->stats.ui_link_quality.total_num =
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;
434  }
435 
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;
441 
442  if (rtlpriv->stats.ui_link_quality.index >=
444  rtlpriv->stats.ui_link_quality.index = 0;
445 
446  tmpval = rtlpriv->stats.ui_link_quality.total_val /
447  rtlpriv->stats.ui_link_quality.total_num;
448  rtlpriv->stats.signal_quality = tmpval;
449 
450  rtlpriv->stats.last_sigstrength_inpercent = tmpval;
451 
452  rtl_92s_process_streams(hw, pstats);
453 
454  }
455  }
456 }
457 
458 static void _rtl92se_process_phyinfo(struct ieee80211_hw *hw,
459  u8 *buffer,
460  struct rtl_stats *pcurrent_stats)
461 {
462 
463  if (!pcurrent_stats->packet_matchbssid &&
464  !pcurrent_stats->packet_beacon)
465  return;
466 
467  _rtl92se_process_ui_rssi(hw, pcurrent_stats);
468  _rtl92se_process_pwdb(hw, pcurrent_stats);
469  _rtl92se_process_ui_link_quality(hw, pcurrent_stats);
470 }
471 
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)
475 {
476  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
477  struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
478 
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;
485 
486  tmp_buf = skb->data + pstats->rx_drvinfo_size + pstats->rx_bufshift;
487 
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;
493 
494  packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) &&
495  ether_addr_equal(mac->bssid,
496  (cfc & IEEE80211_FCTL_TODS) ? hdr->addr1 :
497  (cfc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 :
498  hdr->addr3) &&
499  (!pstats->hwerror) && (!pstats->crc) && (!pstats->icv));
500 
501  packet_toself = packet_matchbssid &&
502  ether_addr_equal(praddr, rtlefuse->dev_addr);
503 
504  if (ieee80211_is_beacon(fc))
505  packet_beacon = true;
506 
507  _rtl92se_query_rxphystatus(hw, pstats, pdesc, p_drvinfo,
508  packet_matchbssid, packet_toself, packet_beacon);
509  _rtl92se_process_phyinfo(hw, tmp_buf, pstats);
510 }
511 
513  struct ieee80211_rx_status *rx_status, u8 *pdesc,
514  struct sk_buff *skb)
515 {
516  struct rx_fwinfo *p_drvinfo;
517  u32 phystatus = (u32)GET_RX_STATUS_DESC_PHY_STATUS(pdesc);
518  struct ieee80211_hdr *hdr;
519  bool first_ampdu = false;
520 
521  stats->length = (u16)GET_RX_STATUS_DESC_PKT_LEN(pdesc);
523  stats->rx_bufshift = (u8)(GET_RX_STATUS_DESC_SHIFT(pdesc) & 0x03);
524  stats->icv = (u16)GET_RX_STATUS_DESC_ICV(pdesc);
525  stats->crc = (u16)GET_RX_STATUS_DESC_CRC32(pdesc);
526  stats->hwerror = (u16)(stats->crc | stats->icv);
527  stats->decrypted = !GET_RX_STATUS_DESC_SWDEC(pdesc);
528 
529  stats->rate = (u8)GET_RX_STATUS_DESC_RX_MCS(pdesc);
530  stats->shortpreamble = (u16)GET_RX_STATUS_DESC_SPLCP(pdesc);
531  stats->isampdu = (bool)(GET_RX_STATUS_DESC_PAGGR(pdesc) == 1);
532  stats->isfirst_ampdu = (bool) ((GET_RX_STATUS_DESC_PAGGR(pdesc) == 1)
533  && (GET_RX_STATUS_DESC_FAGGR(pdesc) == 1));
534  stats->timestamp_low = GET_RX_STATUS_DESC_TSFL(pdesc);
536  stats->is_ht = (bool)GET_RX_STATUS_DESC_RX_HT(pdesc);
537  stats->is_cck = SE_RX_HAL_IS_CCK_RATE(pdesc);
538 
539  if (stats->hwerror)
540  return false;
541 
542  rx_status->freq = hw->conf.channel->center_freq;
543  rx_status->band = hw->conf.channel->band;
544 
545  hdr = (struct ieee80211_hdr *)(skb->data + stats->rx_drvinfo_size
546  + stats->rx_bufshift);
547 
548  if (stats->crc)
549  rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
550 
551  if (stats->rx_is40Mhzpacket)
552  rx_status->flag |= RX_FLAG_40MHZ;
553 
554  if (stats->is_ht)
555  rx_status->flag |= RX_FLAG_HT;
556 
557  rx_status->flag |= RX_FLAG_MACTIME_MPDU;
558 
559  /* hw will set stats->decrypted true, if it finds the
560  * frame is open data frame or mgmt frame,
561  * hw will not decrypt robust managment frame
562  * for IEEE80211w but still set stats->decrypted
563  * true, so here we should set it back to undecrypted
564  * for IEEE80211w frame, and mac80211 sw will help
565  * to decrypt it */
566  if (stats->decrypted) {
567  if ((ieee80211_is_robust_mgmt_frame(hdr)) &&
568  (ieee80211_has_protected(hdr->frame_control)))
569  rx_status->flag &= ~RX_FLAG_DECRYPTED;
570  else
571  rx_status->flag |= RX_FLAG_DECRYPTED;
572  }
573 
574  rx_status->rate_idx = rtlwifi_rate_mapping(hw,
575  stats->is_ht, stats->rate, first_ampdu);
576 
577  rx_status->mactime = stats->timestamp_low;
578  if (phystatus) {
579  p_drvinfo = (struct rx_fwinfo *)(skb->data +
580  stats->rx_bufshift);
581  _rtl92se_translate_rx_signal_stuff(hw, skb, stats, pdesc,
582  p_drvinfo);
583  }
584 
585  /*rx_status->qual = stats->signal; */
586  rx_status->signal = stats->rssi + 10;
587  /*rx_status->noise = -stats->noise; */
588 
589  return true;
590 }
591 
593  struct ieee80211_hdr *hdr, u8 *pdesc_tx,
594  struct ieee80211_tx_info *info,
595  struct ieee80211_sta *sta,
596  struct sk_buff *skb,
597  u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
598 {
599  struct rtl_priv *rtlpriv = rtl_priv(hw);
600  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
601  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
602  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
603  u8 *pdesc = pdesc_tx;
604  u16 seq_number;
605  __le16 fc = hdr->frame_control;
606  u8 reserved_macid = 0;
607  u8 fw_qsel = _rtl92se_map_hwqueue_to_fwqueue(skb, hw_queue);
608  bool firstseg = (!(hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG)));
609  bool lastseg = (!(hdr->frame_control &
611  dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
613  u8 bw_40 = 0;
614 
615  if (mac->opmode == NL80211_IFTYPE_STATION) {
616  bw_40 = mac->bw_40;
617  } else if (mac->opmode == NL80211_IFTYPE_AP ||
618  mac->opmode == NL80211_IFTYPE_ADHOC) {
619  if (sta)
620  bw_40 = sta->ht_cap.cap &
622  }
623 
624  seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
625 
626  rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
627 
629 
630  if (firstseg) {
631  if (rtlpriv->dm.useramask) {
632  /* set txdesc macId */
633  if (ptcb_desc->mac_id < 32) {
634  SET_TX_DESC_MACID(pdesc, ptcb_desc->mac_id);
635  reserved_macid |= ptcb_desc->mac_id;
636  }
637  }
638  SET_TX_DESC_RSVD_MACID(pdesc, reserved_macid);
639 
640  SET_TX_DESC_TXHT(pdesc, ((ptcb_desc->hw_rate >=
641  DESC92_RATEMCS0) ? 1 : 0));
642 
643  if (rtlhal->version == VERSION_8192S_ACUT) {
644  if (ptcb_desc->hw_rate == DESC92_RATE1M ||
645  ptcb_desc->hw_rate == DESC92_RATE2M ||
646  ptcb_desc->hw_rate == DESC92_RATE5_5M ||
647  ptcb_desc->hw_rate == DESC92_RATE11M) {
648  ptcb_desc->hw_rate = DESC92_RATE12M;
649  }
650  }
651 
652  SET_TX_DESC_TX_RATE(pdesc, ptcb_desc->hw_rate);
653 
654  if (ptcb_desc->use_shortgi || ptcb_desc->use_shortpreamble)
655  SET_TX_DESC_TX_SHORT(pdesc, 0);
656 
657  /* Aggregation related */
658  if (info->flags & IEEE80211_TX_CTL_AMPDU)
659  SET_TX_DESC_AGG_ENABLE(pdesc, 1);
660 
661  /* For AMPDU, we must insert SSN into TX_DESC */
662  SET_TX_DESC_SEQ(pdesc, seq_number);
663 
664  /* Protection mode related */
665  /* For 92S, if RTS/CTS are set, HW will execute RTS. */
666  /* We choose only one protection mode to execute */
667  SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcb_desc->rts_enable &&
668  !ptcb_desc->cts_enable) ? 1 : 0));
669  SET_TX_DESC_CTS_ENABLE(pdesc, ((ptcb_desc->cts_enable) ?
670  1 : 0));
671  SET_TX_DESC_RTS_STBC(pdesc, ((ptcb_desc->rts_stbc) ? 1 : 0));
672 
673  SET_TX_DESC_RTS_RATE(pdesc, ptcb_desc->rts_rate);
674  SET_TX_DESC_RTS_BANDWIDTH(pdesc, 0);
675  SET_TX_DESC_RTS_SUB_CARRIER(pdesc, ptcb_desc->rts_sc);
676  SET_TX_DESC_RTS_SHORT(pdesc, ((ptcb_desc->rts_rate <=
677  DESC92_RATE54M) ?
678  (ptcb_desc->rts_use_shortpreamble ? 1 : 0)
679  : (ptcb_desc->rts_use_shortgi ? 1 : 0)));
680 
681 
682  /* Set Bandwidth and sub-channel settings. */
683  if (bw_40) {
684  if (ptcb_desc->packet_bw) {
685  SET_TX_DESC_TX_BANDWIDTH(pdesc, 1);
686  /* use duplicated mode */
687  SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
688  } else {
689  SET_TX_DESC_TX_BANDWIDTH(pdesc, 0);
691  mac->cur_40_prime_sc);
692  }
693  } else {
694  SET_TX_DESC_TX_BANDWIDTH(pdesc, 0);
695  SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0);
696  }
697 
698  /* 3 Fill necessary field in First Descriptor */
699  /*DWORD 0*/
700  SET_TX_DESC_LINIP(pdesc, 0);
701  SET_TX_DESC_OFFSET(pdesc, 32);
702  SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len);
703 
704  /*DWORD 1*/
705  SET_TX_DESC_RA_BRSR_ID(pdesc, ptcb_desc->ratr_index);
706 
707  /* Fill security related */
708  if (info->control.hw_key) {
709  struct ieee80211_key_conf *keyconf;
710 
711  keyconf = info->control.hw_key;
712  switch (keyconf->cipher) {
715  SET_TX_DESC_SEC_TYPE(pdesc, 0x1);
716  break;
718  SET_TX_DESC_SEC_TYPE(pdesc, 0x2);
719  break;
721  SET_TX_DESC_SEC_TYPE(pdesc, 0x3);
722  break;
723  default:
724  SET_TX_DESC_SEC_TYPE(pdesc, 0x0);
725  break;
726 
727  }
728  }
729 
730  /* Set Packet ID */
731  SET_TX_DESC_PACKET_ID(pdesc, 0);
732 
733  /* We will assign magement queue to BK. */
734  SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel);
735 
736  /* Alwasy enable all rate fallback range */
737  SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F);
738 
739  /* Fix: I don't kown why hw use 6.5M to tx when set it */
740  SET_TX_DESC_USER_RATE(pdesc,
741  ptcb_desc->use_driver_rate ? 1 : 0);
742 
743  /* Set NON_QOS bit. */
744  if (!ieee80211_is_data_qos(fc))
745  SET_TX_DESC_NON_QOS(pdesc, 1);
746 
747  }
748 
749  /* Fill fields that are required to be initialized
750  * in all of the descriptors */
751  /*DWORD 0 */
752  SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0));
753  SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0));
754 
755  /* DWORD 7 */
756  SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len);
757 
758  /* DOWRD 8 */
759  SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
760 
761  RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
762 }
763 
764 void rtl92se_tx_fill_cmddesc(struct ieee80211_hw *hw, u8 *pdesc,
765  bool firstseg, bool lastseg, struct sk_buff *skb)
766 {
767  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
768  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
769  struct rtl_tcb_desc *tcb_desc = (struct rtl_tcb_desc *)(skb->cb);
770 
771  dma_addr_t mapping = pci_map_single(rtlpci->pdev, skb->data, skb->len,
773 
774  /* Clear all status */
776 
777  /* This bit indicate this packet is used for FW download. */
778  if (tcb_desc->cmd_or_init == DESC_PACKET_TYPE_INIT) {
779  /* For firmware downlaod we only need to set LINIP */
780  SET_TX_DESC_LINIP(pdesc, tcb_desc->last_inipkt);
781 
782  /* 92SE must set as 1 for firmware download HW DMA error */
783  SET_TX_DESC_FIRST_SEG(pdesc, 1);
784  SET_TX_DESC_LAST_SEG(pdesc, 1);
785 
786  /* 92SE need not to set TX packet size when firmware download */
787  SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
788  SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
789  SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
790 
791  wmb();
792  SET_TX_DESC_OWN(pdesc, 1);
793  } else { /* H2C Command Desc format (Host TXCMD) */
794  /* 92SE must set as 1 for firmware download HW DMA error */
795  SET_TX_DESC_FIRST_SEG(pdesc, 1);
796  SET_TX_DESC_LAST_SEG(pdesc, 1);
797 
798  SET_TX_DESC_OFFSET(pdesc, 0x20);
799 
800  /* Buffer size + command header */
801  SET_TX_DESC_PKT_SIZE(pdesc, (u16)(skb->len));
802  /* Fixed queue of H2C command */
803  SET_TX_DESC_QUEUE_SEL(pdesc, 0x13);
804 
805  SET_BITS_TO_LE_4BYTE(skb->data, 24, 7, rtlhal->h2c_txcmd_seq);
806 
807  SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16)(skb->len));
808  SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping);
809 
810  wmb();
811  SET_TX_DESC_OWN(pdesc, 1);
812 
813  }
814 }
815 
816 void rtl92se_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val)
817 {
818  if (istx) {
819  switch (desc_name) {
820  case HW_DESC_OWN:
821  wmb();
822  SET_TX_DESC_OWN(pdesc, 1);
823  break;
825  SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val);
826  break;
827  default:
828  RT_ASSERT(false, "ERR txdesc :%d not process\n",
829  desc_name);
830  break;
831  }
832  } else {
833  switch (desc_name) {
834  case HW_DESC_RXOWN:
835  wmb();
836  SET_RX_STATUS_DESC_OWN(pdesc, 1);
837  break;
838  case HW_DESC_RXBUFF_ADDR:
839  SET_RX_STATUS__DESC_BUFF_ADDR(pdesc, *(u32 *) val);
840  break;
841  case HW_DESC_RXPKT_LEN:
842  SET_RX_STATUS_DESC_PKT_LEN(pdesc, *(u32 *) val);
843  break;
844  case HW_DESC_RXERO:
845  SET_RX_STATUS_DESC_EOR(pdesc, 1);
846  break;
847  default:
848  RT_ASSERT(false, "ERR rxdesc :%d not process\n",
849  desc_name);
850  break;
851  }
852  }
853 }
854 
855 u32 rtl92se_get_desc(u8 *desc, bool istx, u8 desc_name)
856 {
857  u32 ret = 0;
858 
859  if (istx) {
860  switch (desc_name) {
861  case HW_DESC_OWN:
862  ret = GET_TX_DESC_OWN(desc);
863  break;
864  case HW_DESC_TXBUFF_ADDR:
865  ret = GET_TX_DESC_TX_BUFFER_ADDRESS(desc);
866  break;
867  default:
868  RT_ASSERT(false, "ERR txdesc :%d not process\n",
869  desc_name);
870  break;
871  }
872  } else {
873  switch (desc_name) {
874  case HW_DESC_OWN:
875  ret = GET_RX_STATUS_DESC_OWN(desc);
876  break;
877  case HW_DESC_RXPKT_LEN:
878  ret = GET_RX_STATUS_DESC_PKT_LEN(desc);
879  break;
880  default:
881  RT_ASSERT(false, "ERR rxdesc :%d not process\n",
882  desc_name);
883  break;
884  }
885  }
886  return ret;
887 }
888 
890 {
891  struct rtl_priv *rtlpriv = rtl_priv(hw);
892  rtl_write_word(rtlpriv, TP_POLL, BIT(0) << (hw_queue));
893 }