Commit | Line | Data |
---|---|---|
c592e631 LF |
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 <wlanfae@realtek.com> | |
23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | |
24 | * Hsinchu 300, Taiwan. | |
25 | * | |
26 | * Larry Finger <Larry.Finger@lwfinger.net> | |
27 | * | |
28 | *****************************************************************************/ | |
29 | ||
30 | #include "../wifi.h" | |
31 | #include "../pci.h" | |
32 | #include "../base.h" | |
33 | #include "../stats.h" | |
34 | #include "reg.h" | |
35 | #include "def.h" | |
36 | #include "phy.h" | |
37 | #include "trx.h" | |
38 | #include "led.h" | |
39 | ||
40 | static u8 _rtl8723ae_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_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) || ieee80211_is_ctl(fc)) | |
47 | return QSLT_MGNT; | |
48 | ||
49 | return skb->priority; | |
50 | } | |
51 | ||
52 | static void _rtl8723ae_query_rxphystatus(struct ieee80211_hw *hw, | |
53 | struct rtl_stats *pstatus, u8 *pdesc, | |
54 | struct rx_fwinfo_8723e *p_drvinfo, | |
55 | bool bpacket_match_bssid, | |
56 | bool bpacket_toself, bool packet_beacon) | |
57 | { | |
58 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
59 | struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); | |
60 | struct phy_sts_cck_8723e_t *cck_buf; | |
61 | s8 rx_pwr_all, rx_pwr[4]; | |
62 | u8 rf_rx_num = 0, evm, pwdb_all; | |
63 | u8 i, max_spatial_stream; | |
64 | u32 rssi, total_rssi = 0; | |
65 | bool is_cck = pstatus->is_cck; | |
66 | ||
67 | /* Record it for next packet processing */ | |
68 | pstatus->packet_matchbssid = bpacket_match_bssid; | |
69 | pstatus->packet_toself = bpacket_toself; | |
70 | pstatus->packet_beacon = packet_beacon; | |
71 | pstatus->rx_mimo_sig_qual[0] = -1; | |
72 | pstatus->rx_mimo_sig_qual[1] = -1; | |
73 | ||
74 | if (is_cck) { | |
75 | u8 report, cck_highpwr; | |
76 | ||
77 | /* CCK Driver info Structure is not the same as OFDM packet. */ | |
78 | cck_buf = (struct phy_sts_cck_8723e_t *)p_drvinfo; | |
79 | ||
80 | /* (1)Hardware does not provide RSSI for CCK | |
81 | * (2)PWDB, Average PWDB cacluated by | |
82 | * hardware (for rate adaptive) | |
83 | */ | |
84 | if (ppsc->rfpwr_state == ERFON) | |
85 | cck_highpwr = (u8) rtl_get_bbreg(hw, | |
86 | RFPGA0_XA_HSSIPARAMETER2, | |
87 | BIT(9)); | |
88 | else | |
89 | cck_highpwr = false; | |
90 | ||
91 | if (!cck_highpwr) { | |
92 | u8 cck_agc_rpt = cck_buf->cck_agc_rpt; | |
93 | report = cck_buf->cck_agc_rpt & 0xc0; | |
94 | report = report >> 6; | |
95 | switch (report) { | |
96 | case 0x3: | |
97 | rx_pwr_all = -46 - (cck_agc_rpt & 0x3e); | |
98 | break; | |
99 | case 0x2: | |
100 | rx_pwr_all = -26 - (cck_agc_rpt & 0x3e); | |
101 | break; | |
102 | case 0x1: | |
103 | rx_pwr_all = -12 - (cck_agc_rpt & 0x3e); | |
104 | break; | |
105 | case 0x0: | |
106 | rx_pwr_all = 16 - (cck_agc_rpt & 0x3e); | |
107 | break; | |
108 | } | |
109 | } else { | |
110 | u8 cck_agc_rpt = cck_buf->cck_agc_rpt; | |
111 | report = p_drvinfo->cfosho[0] & 0x60; | |
112 | report = report >> 5; | |
113 | switch (report) { | |
114 | case 0x3: | |
115 | rx_pwr_all = -46 - ((cck_agc_rpt & 0x1f) << 1); | |
116 | break; | |
117 | case 0x2: | |
118 | rx_pwr_all = -26 - ((cck_agc_rpt & 0x1f) << 1); | |
119 | break; | |
120 | case 0x1: | |
121 | rx_pwr_all = -12 - ((cck_agc_rpt & 0x1f) << 1); | |
122 | break; | |
123 | case 0x0: | |
124 | rx_pwr_all = 16 - ((cck_agc_rpt & 0x1f) << 1); | |
125 | break; | |
126 | } | |
127 | } | |
128 | ||
129 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); | |
130 | /* CCK gain is smaller than OFDM/MCS gain, | |
131 | * so we add gain diff. From experience, the val is 6 | |
132 | */ | |
133 | pwdb_all += 6; | |
134 | if (pwdb_all > 100) | |
135 | pwdb_all = 100; | |
136 | /* modify the offset to make the same | |
137 | * gain index with OFDM. | |
138 | */ | |
139 | if (pwdb_all > 34 && pwdb_all <= 42) | |
140 | pwdb_all -= 2; | |
141 | else if (pwdb_all > 26 && pwdb_all <= 34) | |
142 | pwdb_all -= 6; | |
143 | else if (pwdb_all > 14 && pwdb_all <= 26) | |
144 | pwdb_all -= 8; | |
145 | else if (pwdb_all > 4 && pwdb_all <= 14) | |
146 | pwdb_all -= 4; | |
147 | ||
148 | pstatus->rx_pwdb_all = pwdb_all; | |
149 | pstatus->recvsignalpower = rx_pwr_all; | |
150 | ||
151 | /* (3) Get Signal Quality (EVM) */ | |
152 | if (bpacket_match_bssid) { | |
153 | u8 sq; | |
154 | ||
155 | if (pstatus->rx_pwdb_all > 40) { | |
156 | sq = 100; | |
157 | } else { | |
158 | sq = cck_buf->sq_rpt; | |
159 | if (sq > 64) | |
160 | sq = 0; | |
161 | else if (sq < 20) | |
162 | sq = 100; | |
163 | else | |
164 | sq = ((64 - sq) * 100) / 44; | |
165 | } | |
166 | ||
167 | pstatus->signalquality = sq; | |
168 | pstatus->rx_mimo_sig_qual[0] = sq; | |
169 | pstatus->rx_mimo_sig_qual[1] = -1; | |
170 | } | |
171 | } else { | |
172 | rtlpriv->dm.rfpath_rxenable[0] = | |
173 | rtlpriv->dm.rfpath_rxenable[1] = true; | |
174 | ||
175 | /* (1)Get RSSI for HT rate */ | |
176 | for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) { | |
177 | ||
178 | /* we will judge RF RX path now. */ | |
179 | if (rtlpriv->dm.rfpath_rxenable[i]) | |
180 | rf_rx_num++; | |
181 | ||
182 | rx_pwr[i] = ((p_drvinfo->gain_trsw[i] & 0x3f)*2) - 110; | |
183 | ||
184 | /* Translate DBM to percentage. */ | |
185 | rssi = rtl_query_rxpwrpercentage(rx_pwr[i]); | |
186 | total_rssi += rssi; | |
187 | ||
188 | /* Get Rx snr value in DB */ | |
189 | rtlpriv->stats.rx_snr_db[i] = (p_drvinfo->rxsnr[i] / 2); | |
190 | ||
191 | /* Record Signal Strength for next packet */ | |
192 | if (bpacket_match_bssid) | |
193 | pstatus->rx_mimo_signalstrength[i] = (u8) rssi; | |
194 | } | |
195 | ||
196 | /* (2)PWDB, Average PWDB cacluated by | |
197 | * hardware (for rate adaptive) | |
198 | */ | |
199 | rx_pwr_all = ((p_drvinfo->pwdb_all >> 1) & 0x7f) - 110; | |
200 | ||
201 | pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all); | |
202 | pstatus->rx_pwdb_all = pwdb_all; | |
203 | pstatus->rxpower = rx_pwr_all; | |
204 | pstatus->recvsignalpower = rx_pwr_all; | |
205 | ||
206 | /* (3)EVM of HT rate */ | |
207 | if (pstatus->is_ht && pstatus->rate >= DESC92_RATEMCS8 && | |
208 | pstatus->rate <= DESC92_RATEMCS15) | |
209 | max_spatial_stream = 2; | |
210 | else | |
211 | max_spatial_stream = 1; | |
212 | ||
213 | for (i = 0; i < max_spatial_stream; i++) { | |
214 | evm = rtl_evm_db_to_percentage(p_drvinfo->rxevm[i]); | |
215 | ||
216 | if (bpacket_match_bssid) { | |
217 | /* Fill value in RFD, Get the first | |
218 | * spatial stream only | |
219 | */ | |
220 | if (i == 0) | |
221 | pstatus->signalquality = (evm & 0xff); | |
222 | pstatus->rx_mimo_sig_qual[i] = (evm & 0xff); | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | /* UI BSS List signal strength(in percentage), | |
228 | * make it good looking, from 0~100. | |
229 | */ | |
230 | if (is_cck) | |
231 | pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw, | |
232 | pwdb_all)); | |
233 | else if (rf_rx_num != 0) | |
234 | pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw, | |
235 | total_rssi /= rf_rx_num)); | |
236 | } | |
237 | ||
238 | static void _rtl8723ae_translate_rx_signal_stuff(struct ieee80211_hw *hw, | |
239 | struct sk_buff *skb, struct rtl_stats *pstatus, | |
240 | u8 *pdesc, struct rx_fwinfo_8723e *p_drvinfo) | |
241 | { | |
242 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
243 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); | |
244 | struct ieee80211_hdr *hdr; | |
245 | u8 *tmp_buf; | |
246 | u8 *praddr; | |
c592e631 LF |
247 | __le16 fc; |
248 | u16 type; | |
eee569e4 | 249 | bool packet_matchbssid, packet_toself, packet_beacon = false; |
c592e631 LF |
250 | |
251 | tmp_buf = skb->data + pstatus->rx_drvinfo_size + pstatus->rx_bufshift; | |
252 | ||
253 | hdr = (struct ieee80211_hdr *)tmp_buf; | |
254 | fc = hdr->frame_control; | |
255 | type = WLAN_FC_GET_TYPE(fc); | |
256 | praddr = hdr->addr1; | |
c592e631 LF |
257 | |
258 | packet_matchbssid = ((IEEE80211_FTYPE_CTL != type) && | |
259 | (!compare_ether_addr(mac->bssid, | |
260 | (le16_to_cpu(fc) & IEEE80211_FCTL_TODS) ? | |
261 | hdr->addr1 : (le16_to_cpu(fc) & | |
262 | IEEE80211_FCTL_FROMDS) ? | |
263 | hdr->addr2 : hdr->addr3)) && (!pstatus->hwerror) && | |
264 | (!pstatus->crc) && (!pstatus->icv)); | |
265 | ||
266 | packet_toself = packet_matchbssid && | |
267 | (!compare_ether_addr(praddr, rtlefuse->dev_addr)); | |
268 | ||
269 | if (ieee80211_is_beacon(fc)) | |
270 | packet_beacon = true; | |
271 | ||
272 | _rtl8723ae_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo, | |
273 | packet_matchbssid, packet_toself, | |
274 | packet_beacon); | |
275 | ||
276 | rtl_process_phyinfo(hw, tmp_buf, pstatus); | |
277 | } | |
278 | ||
279 | bool rtl8723ae_rx_query_desc(struct ieee80211_hw *hw, | |
280 | struct rtl_stats *status, | |
281 | struct ieee80211_rx_status *rx_status, | |
282 | u8 *pdesc, struct sk_buff *skb) | |
283 | { | |
284 | struct rx_fwinfo_8723e *p_drvinfo; | |
285 | struct ieee80211_hdr *hdr; | |
286 | u32 phystatus = GET_RX_DESC_PHYST(pdesc); | |
287 | ||
288 | status->length = (u16) GET_RX_DESC_PKT_LEN(pdesc); | |
289 | status->rx_drvinfo_size = (u8) GET_RX_DESC_DRV_INFO_SIZE(pdesc) * | |
290 | RX_DRV_INFO_SIZE_UNIT; | |
291 | status->rx_bufshift = (u8) (GET_RX_DESC_SHIFT(pdesc) & 0x03); | |
292 | status->icv = (u16) GET_RX_DESC_ICV(pdesc); | |
293 | status->crc = (u16) GET_RX_DESC_CRC32(pdesc); | |
294 | status->hwerror = (status->crc | status->icv); | |
295 | status->decrypted = !GET_RX_DESC_SWDEC(pdesc); | |
296 | status->rate = (u8) GET_RX_DESC_RXMCS(pdesc); | |
297 | status->shortpreamble = (u16) GET_RX_DESC_SPLCP(pdesc); | |
298 | status->isampdu = (bool) (GET_RX_DESC_PAGGR(pdesc) == 1); | |
299 | status->isfirst_ampdu = (bool) ((GET_RX_DESC_PAGGR(pdesc) == 1) | |
300 | && (GET_RX_DESC_FAGGR(pdesc) == 1)); | |
301 | status->timestamp_low = GET_RX_DESC_TSFL(pdesc); | |
302 | status->rx_is40Mhzpacket = (bool) GET_RX_DESC_BW(pdesc); | |
303 | status->is_ht = (bool)GET_RX_DESC_RXHT(pdesc); | |
304 | ||
305 | status->is_cck = RTL8723E_RX_HAL_IS_CCK_RATE(status->rate); | |
306 | ||
307 | rx_status->freq = hw->conf.channel->center_freq; | |
308 | rx_status->band = hw->conf.channel->band; | |
309 | ||
310 | hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size | |
311 | + status->rx_bufshift); | |
312 | ||
313 | if (status->crc) | |
314 | rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; | |
315 | ||
316 | if (status->rx_is40Mhzpacket) | |
317 | rx_status->flag |= RX_FLAG_40MHZ; | |
318 | ||
319 | if (status->is_ht) | |
320 | rx_status->flag |= RX_FLAG_HT; | |
321 | ||
e4cb3ff9 | 322 | rx_status->flag |= RX_FLAG_MACTIME_START; |
c592e631 LF |
323 | |
324 | /* hw will set status->decrypted true, if it finds the | |
325 | * frame is open data frame or mgmt frame. | |
326 | * Thus hw will not decrypt a robust managment frame | |
327 | * for IEEE80211w but still set status->decrypted | |
328 | * true, so here we should set it back to undecrypted | |
329 | * for IEEE80211w frame, and mac80211 sw will help | |
330 | * to decrypt it | |
331 | */ | |
332 | if (status->decrypted) { | |
333 | if ((ieee80211_is_robust_mgmt_frame(hdr)) && | |
334 | (ieee80211_has_protected(hdr->frame_control))) | |
335 | rx_status->flag &= ~RX_FLAG_DECRYPTED; | |
336 | else | |
337 | rx_status->flag |= RX_FLAG_DECRYPTED; | |
338 | } | |
339 | ||
340 | /* rate_idx: index of data rate into band's | |
341 | * supported rates or MCS index if HT rates | |
342 | * are use (RX_FLAG_HT) | |
343 | */ | |
344 | rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht, | |
345 | status->rate, false); | |
346 | ||
347 | rx_status->mactime = status->timestamp_low; | |
348 | if (phystatus == true) { | |
349 | p_drvinfo = (struct rx_fwinfo_8723e *)(skb->data + | |
350 | status->rx_bufshift); | |
351 | ||
352 | _rtl8723ae_translate_rx_signal_stuff(hw, | |
353 | skb, status, pdesc, p_drvinfo); | |
354 | } | |
355 | ||
356 | /*rx_status->qual = status->signal; */ | |
357 | rx_status->signal = status->recvsignalpower + 10; | |
358 | /*rx_status->noise = -status->noise; */ | |
359 | ||
360 | return true; | |
361 | } | |
362 | ||
363 | void rtl8723ae_tx_fill_desc(struct ieee80211_hw *hw, | |
364 | struct ieee80211_hdr *hdr, u8 *pdesc_tx, | |
365 | struct ieee80211_tx_info *info, | |
366 | struct ieee80211_sta *sta, | |
367 | struct sk_buff *skb, u8 hw_queue, | |
368 | struct rtl_tcb_desc *ptcdesc) | |
369 | { | |
370 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
371 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | |
372 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); | |
373 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | |
374 | bool defaultadapter = true; | |
375 | u8 *pdesc = (u8 *) pdesc_tx; | |
376 | u16 seq_number; | |
377 | __le16 fc = hdr->frame_control; | |
378 | u8 fw_qsel = _rtl8723ae_map_hwqueue_to_fwqueue(skb, hw_queue); | |
379 | bool firstseg = ((hdr->seq_ctrl & | |
380 | cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0); | |
381 | bool lastseg = ((hdr->frame_control & | |
382 | cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0); | |
383 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, | |
384 | skb->data, skb->len, | |
385 | PCI_DMA_TODEVICE); | |
386 | u8 bw_40 = 0; | |
387 | ||
3f009c78 LF |
388 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
389 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | |
390 | "DMA mapping error"); | |
391 | return; | |
392 | } | |
c592e631 LF |
393 | if (mac->opmode == NL80211_IFTYPE_STATION) { |
394 | bw_40 = mac->bw_40; | |
395 | } else if (mac->opmode == NL80211_IFTYPE_AP || | |
396 | mac->opmode == NL80211_IFTYPE_ADHOC) { | |
397 | if (sta) | |
398 | bw_40 = sta->ht_cap.cap & | |
399 | IEEE80211_HT_CAP_SUP_WIDTH_20_40; | |
400 | } | |
401 | ||
402 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; | |
403 | ||
404 | rtl_get_tcb_desc(hw, info, sta, skb, ptcdesc); | |
405 | ||
406 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, sizeof(struct tx_desc_8723e)); | |
407 | ||
408 | if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) { | |
409 | firstseg = true; | |
410 | lastseg = true; | |
411 | } | |
412 | ||
413 | if (firstseg) { | |
414 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); | |
415 | ||
416 | SET_TX_DESC_TX_RATE(pdesc, ptcdesc->hw_rate); | |
417 | ||
418 | if (ptcdesc->use_shortgi || ptcdesc->use_shortpreamble) | |
419 | SET_TX_DESC_DATA_SHORTGI(pdesc, 1); | |
420 | ||
421 | if (info->flags & IEEE80211_TX_CTL_AMPDU) { | |
422 | SET_TX_DESC_AGG_BREAK(pdesc, 1); | |
423 | SET_TX_DESC_MAX_AGG_NUM(pdesc, 0x14); | |
424 | } | |
425 | SET_TX_DESC_SEQ(pdesc, seq_number); | |
426 | ||
427 | SET_TX_DESC_RTS_ENABLE(pdesc, ((ptcdesc->rts_enable && | |
428 | !ptcdesc-> | |
429 | cts_enable) ? 1 : 0)); | |
430 | SET_TX_DESC_HW_RTS_ENABLE(pdesc, | |
431 | ((ptcdesc->rts_enable | |
432 | || ptcdesc->cts_enable) ? 1 : 0)); | |
433 | SET_TX_DESC_CTS2SELF(pdesc, ((ptcdesc->cts_enable) ? 1 : 0)); | |
434 | SET_TX_DESC_RTS_STBC(pdesc, ((ptcdesc->rts_stbc) ? 1 : 0)); | |
435 | ||
436 | SET_TX_DESC_RTS_RATE(pdesc, ptcdesc->rts_rate); | |
437 | SET_TX_DESC_RTS_BW(pdesc, 0); | |
438 | SET_TX_DESC_RTS_SC(pdesc, ptcdesc->rts_sc); | |
439 | SET_TX_DESC_RTS_SHORT(pdesc, | |
440 | ((ptcdesc->rts_rate <= DESC92_RATE54M) ? | |
441 | (ptcdesc->rts_use_shortpreamble ? 1 : 0) | |
442 | : (ptcdesc->rts_use_shortgi ? 1 : 0))); | |
443 | ||
444 | if (bw_40) { | |
445 | if (ptcdesc->packet_bw) { | |
446 | SET_TX_DESC_DATA_BW(pdesc, 1); | |
447 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 3); | |
448 | } else { | |
449 | SET_TX_DESC_DATA_BW(pdesc, 0); | |
450 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, | |
451 | mac->cur_40_prime_sc); | |
452 | } | |
453 | } else { | |
454 | SET_TX_DESC_DATA_BW(pdesc, 0); | |
455 | SET_TX_DESC_TX_SUB_CARRIER(pdesc, 0); | |
456 | } | |
457 | ||
458 | SET_TX_DESC_LINIP(pdesc, 0); | |
459 | SET_TX_DESC_PKT_SIZE(pdesc, (u16) skb->len); | |
460 | ||
461 | if (sta) { | |
462 | u8 ampdu_density = sta->ht_cap.ampdu_density; | |
463 | SET_TX_DESC_AMPDU_DENSITY(pdesc, ampdu_density); | |
464 | } | |
465 | ||
466 | if (info->control.hw_key) { | |
467 | struct ieee80211_key_conf *keyconf = | |
468 | info->control.hw_key; | |
469 | ||
470 | switch (keyconf->cipher) { | |
471 | case WLAN_CIPHER_SUITE_WEP40: | |
472 | case WLAN_CIPHER_SUITE_WEP104: | |
473 | case WLAN_CIPHER_SUITE_TKIP: | |
474 | SET_TX_DESC_SEC_TYPE(pdesc, 0x1); | |
475 | break; | |
476 | case WLAN_CIPHER_SUITE_CCMP: | |
477 | SET_TX_DESC_SEC_TYPE(pdesc, 0x3); | |
478 | break; | |
479 | default: | |
480 | SET_TX_DESC_SEC_TYPE(pdesc, 0x0); | |
481 | break; | |
482 | } | |
483 | } | |
484 | ||
485 | SET_TX_DESC_PKT_ID(pdesc, 0); | |
486 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_qsel); | |
487 | ||
488 | SET_TX_DESC_DATA_RATE_FB_LIMIT(pdesc, 0x1F); | |
489 | SET_TX_DESC_RTS_RATE_FB_LIMIT(pdesc, 0xF); | |
490 | SET_TX_DESC_DISABLE_FB(pdesc, 0); | |
491 | SET_TX_DESC_USE_RATE(pdesc, ptcdesc->use_driver_rate ? 1 : 0); | |
492 | ||
493 | if (ieee80211_is_data_qos(fc)) { | |
494 | if (mac->rdg_en) { | |
495 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | |
496 | "Enable RDG function.\n"); | |
497 | SET_TX_DESC_RDG_ENABLE(pdesc, 1); | |
498 | SET_TX_DESC_HTC(pdesc, 1); | |
499 | } | |
500 | } | |
501 | } | |
502 | ||
503 | SET_TX_DESC_FIRST_SEG(pdesc, (firstseg ? 1 : 0)); | |
504 | SET_TX_DESC_LAST_SEG(pdesc, (lastseg ? 1 : 0)); | |
505 | ||
506 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) skb->len); | |
507 | ||
508 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); | |
509 | ||
510 | if (rtlpriv->dm.useramask) { | |
511 | SET_TX_DESC_RATE_ID(pdesc, ptcdesc->ratr_index); | |
512 | SET_TX_DESC_MACID(pdesc, ptcdesc->mac_id); | |
513 | } else { | |
514 | SET_TX_DESC_RATE_ID(pdesc, 0xC + ptcdesc->ratr_index); | |
515 | SET_TX_DESC_MACID(pdesc, ptcdesc->ratr_index); | |
516 | } | |
517 | ||
518 | if ((!ieee80211_is_data_qos(fc)) && ppsc->fwctrl_lps) { | |
519 | SET_TX_DESC_HWSEQ_EN_8723(pdesc, 1); | |
520 | ||
521 | if (!defaultadapter) | |
522 | SET_TX_DESC_HWSEQ_SEL_8723(pdesc, 1); | |
523 | } | |
524 | ||
525 | SET_TX_DESC_MORE_FRAG(pdesc, (lastseg ? 0 : 1)); | |
526 | ||
527 | if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) || | |
528 | is_broadcast_ether_addr(ieee80211_get_DA(hdr))) { | |
529 | SET_TX_DESC_BMC(pdesc, 1); | |
530 | } | |
531 | ||
532 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, "\n"); | |
533 | } | |
534 | ||
535 | void rtl8723ae_tx_fill_cmddesc(struct ieee80211_hw *hw, | |
536 | u8 *pdesc, bool firstseg, | |
537 | bool lastseg, struct sk_buff *skb) | |
538 | { | |
539 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
540 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); | |
541 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); | |
542 | u8 fw_queue = QSLT_BEACON; | |
543 | dma_addr_t mapping = pci_map_single(rtlpci->pdev, | |
544 | skb->data, skb->len, | |
545 | PCI_DMA_TODEVICE); | |
546 | __le16 fc = hdr->frame_control; | |
547 | ||
3f009c78 LF |
548 | if (pci_dma_mapping_error(rtlpci->pdev, mapping)) { |
549 | RT_TRACE(rtlpriv, COMP_SEND, DBG_TRACE, | |
550 | "DMA mapping error"); | |
551 | return; | |
552 | } | |
c592e631 LF |
553 | CLEAR_PCI_TX_DESC_CONTENT(pdesc, TX_DESC_SIZE); |
554 | ||
555 | if (firstseg) | |
556 | SET_TX_DESC_OFFSET(pdesc, USB_HWDESC_HEADER_LEN); | |
557 | ||
558 | SET_TX_DESC_TX_RATE(pdesc, DESC92_RATE1M); | |
559 | ||
560 | SET_TX_DESC_SEQ(pdesc, 0); | |
561 | ||
562 | SET_TX_DESC_LINIP(pdesc, 0); | |
563 | ||
564 | SET_TX_DESC_QUEUE_SEL(pdesc, fw_queue); | |
565 | ||
566 | SET_TX_DESC_FIRST_SEG(pdesc, 1); | |
567 | SET_TX_DESC_LAST_SEG(pdesc, 1); | |
568 | ||
569 | SET_TX_DESC_TX_BUFFER_SIZE(pdesc, (u16) (skb->len)); | |
570 | ||
571 | SET_TX_DESC_TX_BUFFER_ADDRESS(pdesc, mapping); | |
572 | ||
573 | SET_TX_DESC_RATE_ID(pdesc, 7); | |
574 | SET_TX_DESC_MACID(pdesc, 0); | |
575 | ||
576 | SET_TX_DESC_OWN(pdesc, 1); | |
577 | ||
578 | SET_TX_DESC_PKT_SIZE((u8 *) pdesc, (u16) (skb->len)); | |
579 | ||
580 | SET_TX_DESC_FIRST_SEG(pdesc, 1); | |
581 | SET_TX_DESC_LAST_SEG(pdesc, 1); | |
582 | ||
583 | SET_TX_DESC_OFFSET(pdesc, 0x20); | |
584 | ||
585 | SET_TX_DESC_USE_RATE(pdesc, 1); | |
586 | ||
587 | if (!ieee80211_is_data_qos(fc)) { | |
588 | SET_TX_DESC_HWSEQ_EN_8723(pdesc, 1); | |
589 | /* SET_TX_DESC_HWSEQ_EN(pdesc, 1); */ | |
590 | /* SET_TX_DESC_PKT_ID(pdesc, 8); */ | |
591 | } | |
592 | ||
593 | RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD, | |
594 | "H2C Tx Cmd Content\n", | |
595 | pdesc, TX_DESC_SIZE); | |
596 | } | |
597 | ||
598 | void rtl8723ae_set_desc(u8 *pdesc, bool istx, u8 desc_name, u8 *val) | |
599 | { | |
600 | if (istx == true) { | |
601 | switch (desc_name) { | |
602 | case HW_DESC_OWN: | |
603 | SET_TX_DESC_OWN(pdesc, 1); | |
604 | break; | |
605 | case HW_DESC_TX_NEXTDESC_ADDR: | |
606 | SET_TX_DESC_NEXT_DESC_ADDRESS(pdesc, *(u32 *) val); | |
607 | break; | |
608 | default: | |
609 | RT_ASSERT(false, "ERR txdesc :%d not process\n", | |
610 | desc_name); | |
611 | break; | |
612 | } | |
613 | } else { | |
614 | switch (desc_name) { | |
615 | case HW_DESC_RXOWN: | |
616 | SET_RX_DESC_OWN(pdesc, 1); | |
617 | break; | |
618 | case HW_DESC_RXBUFF_ADDR: | |
619 | SET_RX_DESC_BUFF_ADDR(pdesc, *(u32 *) val); | |
620 | break; | |
621 | case HW_DESC_RXPKT_LEN: | |
622 | SET_RX_DESC_PKT_LEN(pdesc, *(u32 *) val); | |
623 | break; | |
624 | case HW_DESC_RXERO: | |
625 | SET_RX_DESC_EOR(pdesc, 1); | |
626 | break; | |
627 | default: | |
628 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", | |
629 | desc_name); | |
630 | break; | |
631 | } | |
632 | } | |
633 | } | |
634 | ||
635 | u32 rtl8723ae_get_desc(u8 *pdesc, bool istx, u8 desc_name) | |
636 | { | |
637 | u32 ret = 0; | |
638 | ||
639 | if (istx == true) { | |
640 | switch (desc_name) { | |
641 | case HW_DESC_OWN: | |
642 | ret = GET_TX_DESC_OWN(pdesc); | |
643 | break; | |
644 | case HW_DESC_TXBUFF_ADDR: | |
645 | ret = GET_TX_DESC_TX_BUFFER_ADDRESS(pdesc); | |
646 | break; | |
647 | default: | |
648 | RT_ASSERT(false, "ERR txdesc :%d not process\n", | |
649 | desc_name); | |
650 | break; | |
651 | } | |
652 | } else { | |
653 | switch (desc_name) { | |
654 | case HW_DESC_OWN: | |
655 | ret = GET_RX_DESC_OWN(pdesc); | |
656 | break; | |
657 | case HW_DESC_RXPKT_LEN: | |
658 | ret = GET_RX_DESC_PKT_LEN(pdesc); | |
659 | break; | |
660 | default: | |
661 | RT_ASSERT(false, "ERR rxdesc :%d not process\n", | |
662 | desc_name); | |
663 | break; | |
664 | } | |
665 | } | |
666 | return ret; | |
667 | } | |
668 | ||
669 | void rtl8723ae_tx_polling(struct ieee80211_hw *hw, u8 hw_queue) | |
670 | { | |
671 | struct rtl_priv *rtlpriv = rtl_priv(hw); | |
672 | if (hw_queue == BEACON_QUEUE) { | |
673 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, BIT(4)); | |
674 | } else { | |
675 | rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, | |
676 | BIT(0) << (hw_queue)); | |
677 | } | |
678 | } |