1647f21b1SLarry Finger // SPDX-License-Identifier: GPL-2.0
2647f21b1SLarry Finger /* Copyright(c) 2009-2014 Realtek Corporation.*/
3f1d2b4d3SLarry Finger
4f1d2b4d3SLarry Finger #include "../wifi.h"
5f1d2b4d3SLarry Finger #include "../pci.h"
6f1d2b4d3SLarry Finger #include "../base.h"
7f1d2b4d3SLarry Finger #include "../stats.h"
8f1d2b4d3SLarry Finger #include "reg.h"
9f1d2b4d3SLarry Finger #include "def.h"
10f1d2b4d3SLarry Finger #include "phy.h"
11f1d2b4d3SLarry Finger #include "trx.h"
12f1d2b4d3SLarry Finger #include "led.h"
13f1d2b4d3SLarry Finger #include "dm.h"
14f1d2b4d3SLarry Finger #include "fw.h"
15f1d2b4d3SLarry Finger
_rtl92ee_map_hwqueue_to_fwqueue(struct sk_buff * skb,u8 hw_queue)16f1d2b4d3SLarry Finger static u8 _rtl92ee_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
17f1d2b4d3SLarry Finger {
18f1d2b4d3SLarry Finger __le16 fc = rtl_get_fc(skb);
19f1d2b4d3SLarry Finger
20f1d2b4d3SLarry Finger if (unlikely(ieee80211_is_beacon(fc)))
21f1d2b4d3SLarry Finger return QSLT_BEACON;
22f1d2b4d3SLarry Finger if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
23f1d2b4d3SLarry Finger return QSLT_MGNT;
24f1d2b4d3SLarry Finger
25f1d2b4d3SLarry Finger return skb->priority;
26f1d2b4d3SLarry Finger }
27f1d2b4d3SLarry Finger
_rtl92ee_query_rxphystatus(struct ieee80211_hw * hw,struct rtl_stats * pstatus,u8 * pdesc,struct rx_fwinfo * p_drvinfo,bool bpacket_match_bssid,bool bpacket_toself,bool packet_beacon)28f1d2b4d3SLarry Finger static void _rtl92ee_query_rxphystatus(struct ieee80211_hw *hw,
29f1d2b4d3SLarry Finger struct rtl_stats *pstatus, u8 *pdesc,
30f1d2b4d3SLarry Finger struct rx_fwinfo *p_drvinfo,
31f1d2b4d3SLarry Finger bool bpacket_match_bssid,
32f1d2b4d3SLarry Finger bool bpacket_toself,
33f1d2b4d3SLarry Finger bool packet_beacon)
34f1d2b4d3SLarry Finger {
35f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
36f1d2b4d3SLarry Finger struct phy_status_rpt *p_phystrpt = (struct phy_status_rpt *)p_drvinfo;
379dc35d8aSLarry Finger s8 rx_pwr_all, rx_pwr[4];
38f1d2b4d3SLarry Finger u8 rf_rx_num = 0, evm, pwdb_all;
39f1d2b4d3SLarry Finger u8 i, max_spatial_stream;
40f1d2b4d3SLarry Finger u32 rssi, total_rssi = 0;
41f1d2b4d3SLarry Finger bool is_cck = pstatus->is_cck;
42f1d2b4d3SLarry Finger u8 lan_idx, vga_idx;
43f1d2b4d3SLarry Finger
44f1d2b4d3SLarry Finger /* Record it for next packet processing */
45f1d2b4d3SLarry Finger pstatus->packet_matchbssid = bpacket_match_bssid;
46f1d2b4d3SLarry Finger pstatus->packet_toself = bpacket_toself;
47f1d2b4d3SLarry Finger pstatus->packet_beacon = packet_beacon;
48f1d2b4d3SLarry Finger pstatus->rx_mimo_signalquality[0] = -1;
49f1d2b4d3SLarry Finger pstatus->rx_mimo_signalquality[1] = -1;
50f1d2b4d3SLarry Finger
51f1d2b4d3SLarry Finger if (is_cck) {
52f1d2b4d3SLarry Finger u8 cck_highpwr;
53f1d2b4d3SLarry Finger u8 cck_agc_rpt;
54f1d2b4d3SLarry Finger /* CCK Driver info Structure is not the same as OFDM packet. */
55f1d2b4d3SLarry Finger cck_agc_rpt = p_phystrpt->cck_agc_rpt_ofdm_cfosho_a;
56f1d2b4d3SLarry Finger
57f1d2b4d3SLarry Finger /* (1)Hardware does not provide RSSI for CCK
58*e8c241d4SLv Ruyi * (2)PWDB, Average PWDB calculated by
59f1d2b4d3SLarry Finger * hardware (for rate adaptive)
60f1d2b4d3SLarry Finger */
61f1d2b4d3SLarry Finger cck_highpwr = (u8)rtl_get_bbreg(hw, RFPGA0_XA_HSSIPARAMETER2,
62f1d2b4d3SLarry Finger BIT(9));
63f1d2b4d3SLarry Finger
64f1d2b4d3SLarry Finger lan_idx = ((cck_agc_rpt & 0xE0) >> 5);
65f1d2b4d3SLarry Finger vga_idx = (cck_agc_rpt & 0x1f);
66f1d2b4d3SLarry Finger switch (lan_idx) {
67f1d2b4d3SLarry Finger case 7: /*VGA_idx = 27~2*/
68f1d2b4d3SLarry Finger if (vga_idx <= 27)
69f1d2b4d3SLarry Finger rx_pwr_all = -100 + 2 * (27 - vga_idx);
70f1d2b4d3SLarry Finger else
71f1d2b4d3SLarry Finger rx_pwr_all = -100;
72f1d2b4d3SLarry Finger break;
73f1d2b4d3SLarry Finger case 6: /*VGA_idx = 2~0*/
74f1d2b4d3SLarry Finger rx_pwr_all = -48 + 2 * (2 - vga_idx);
75f1d2b4d3SLarry Finger break;
76f1d2b4d3SLarry Finger case 5: /*VGA_idx = 7~5*/
77f1d2b4d3SLarry Finger rx_pwr_all = -42 + 2 * (7 - vga_idx);
78f1d2b4d3SLarry Finger break;
79f1d2b4d3SLarry Finger case 4: /*VGA_idx = 7~4*/
80f1d2b4d3SLarry Finger rx_pwr_all = -36 + 2 * (7 - vga_idx);
81f1d2b4d3SLarry Finger break;
82f1d2b4d3SLarry Finger case 3: /*VGA_idx = 7~0*/
83f1d2b4d3SLarry Finger rx_pwr_all = -24 + 2 * (7 - vga_idx);
84f1d2b4d3SLarry Finger break;
85f1d2b4d3SLarry Finger case 2: /*VGA_idx = 5~0*/
86f1d2b4d3SLarry Finger if (cck_highpwr)
87f1d2b4d3SLarry Finger rx_pwr_all = -12 + 2 * (5 - vga_idx);
88f1d2b4d3SLarry Finger else
89f1d2b4d3SLarry Finger rx_pwr_all = -6 + 2 * (5 - vga_idx);
90f1d2b4d3SLarry Finger break;
91f1d2b4d3SLarry Finger case 1:
92f1d2b4d3SLarry Finger rx_pwr_all = 8 - 2 * vga_idx;
93f1d2b4d3SLarry Finger break;
94f1d2b4d3SLarry Finger case 0:
95f1d2b4d3SLarry Finger rx_pwr_all = 14 - 2 * vga_idx;
96f1d2b4d3SLarry Finger break;
97f1d2b4d3SLarry Finger default:
989dc35d8aSLarry Finger rx_pwr_all = 0;
99f1d2b4d3SLarry Finger break;
100f1d2b4d3SLarry Finger }
101f1d2b4d3SLarry Finger rx_pwr_all += 16;
102f1d2b4d3SLarry Finger pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
103f1d2b4d3SLarry Finger
104f1d2b4d3SLarry Finger if (!cck_highpwr) {
105f1d2b4d3SLarry Finger if (pwdb_all >= 80)
106f1d2b4d3SLarry Finger pwdb_all = ((pwdb_all - 80) << 1) +
107f1d2b4d3SLarry Finger ((pwdb_all - 80) >> 1) + 80;
108f1d2b4d3SLarry Finger else if ((pwdb_all <= 78) && (pwdb_all >= 20))
109f1d2b4d3SLarry Finger pwdb_all += 3;
110f1d2b4d3SLarry Finger if (pwdb_all > 100)
111f1d2b4d3SLarry Finger pwdb_all = 100;
112f1d2b4d3SLarry Finger }
113f1d2b4d3SLarry Finger
114f1d2b4d3SLarry Finger pstatus->rx_pwdb_all = pwdb_all;
115f1d2b4d3SLarry Finger pstatus->bt_rx_rssi_percentage = pwdb_all;
116f1d2b4d3SLarry Finger pstatus->recvsignalpower = rx_pwr_all;
117f1d2b4d3SLarry Finger
118f1d2b4d3SLarry Finger /* (3) Get Signal Quality (EVM) */
119f1d2b4d3SLarry Finger if (bpacket_match_bssid) {
120f1d2b4d3SLarry Finger u8 sq, sq_rpt;
121f1d2b4d3SLarry Finger
122f1d2b4d3SLarry Finger if (pstatus->rx_pwdb_all > 40) {
123f1d2b4d3SLarry Finger sq = 100;
124f1d2b4d3SLarry Finger } else {
125f1d2b4d3SLarry Finger sq_rpt = p_phystrpt->cck_sig_qual_ofdm_pwdb_all;
126f1d2b4d3SLarry Finger if (sq_rpt > 64)
127f1d2b4d3SLarry Finger sq = 0;
128f1d2b4d3SLarry Finger else if (sq_rpt < 20)
129f1d2b4d3SLarry Finger sq = 100;
130f1d2b4d3SLarry Finger else
131f1d2b4d3SLarry Finger sq = ((64 - sq_rpt) * 100) / 44;
132f1d2b4d3SLarry Finger }
133f1d2b4d3SLarry Finger
134f1d2b4d3SLarry Finger pstatus->signalquality = sq;
135f1d2b4d3SLarry Finger pstatus->rx_mimo_signalquality[0] = sq;
136f1d2b4d3SLarry Finger pstatus->rx_mimo_signalquality[1] = -1;
137f1d2b4d3SLarry Finger }
138f1d2b4d3SLarry Finger } else {
139f1d2b4d3SLarry Finger /* (1)Get RSSI for HT rate */
140f1d2b4d3SLarry Finger for (i = RF90_PATH_A; i < RF6052_MAX_PATH; i++) {
141f1d2b4d3SLarry Finger /* we will judge RF RX path now. */
142f1d2b4d3SLarry Finger if (rtlpriv->dm.rfpath_rxenable[i])
143f1d2b4d3SLarry Finger rf_rx_num++;
144f1d2b4d3SLarry Finger
145f1d2b4d3SLarry Finger rx_pwr[i] = ((p_phystrpt->path_agc[i].gain & 0x3f) * 2)
146f1d2b4d3SLarry Finger - 110;
147f1d2b4d3SLarry Finger
148f1d2b4d3SLarry Finger pstatus->rx_pwr[i] = rx_pwr[i];
149f1d2b4d3SLarry Finger /* Translate DBM to percentage. */
150f1d2b4d3SLarry Finger rssi = rtl_query_rxpwrpercentage(rx_pwr[i]);
151f1d2b4d3SLarry Finger total_rssi += rssi;
152f1d2b4d3SLarry Finger
153f1d2b4d3SLarry Finger pstatus->rx_mimo_signalstrength[i] = (u8)rssi;
154f1d2b4d3SLarry Finger }
155f1d2b4d3SLarry Finger
156*e8c241d4SLv Ruyi /* (2)PWDB, Average PWDB calculated by
157f1d2b4d3SLarry Finger * hardware (for rate adaptive)
158f1d2b4d3SLarry Finger */
159f1d2b4d3SLarry Finger rx_pwr_all = ((p_phystrpt->cck_sig_qual_ofdm_pwdb_all >> 1)
160f1d2b4d3SLarry Finger & 0x7f) - 110;
161f1d2b4d3SLarry Finger
162f1d2b4d3SLarry Finger pwdb_all = rtl_query_rxpwrpercentage(rx_pwr_all);
163f1d2b4d3SLarry Finger pstatus->rx_pwdb_all = pwdb_all;
164f1d2b4d3SLarry Finger pstatus->bt_rx_rssi_percentage = pwdb_all;
165f1d2b4d3SLarry Finger pstatus->rxpower = rx_pwr_all;
166f1d2b4d3SLarry Finger pstatus->recvsignalpower = rx_pwr_all;
167f1d2b4d3SLarry Finger
168f1d2b4d3SLarry Finger /* (3)EVM of HT rate */
169f1d2b4d3SLarry Finger if (pstatus->rate >= DESC_RATEMCS8 &&
170f1d2b4d3SLarry Finger pstatus->rate <= DESC_RATEMCS15)
171f1d2b4d3SLarry Finger max_spatial_stream = 2;
172f1d2b4d3SLarry Finger else
173f1d2b4d3SLarry Finger max_spatial_stream = 1;
174f1d2b4d3SLarry Finger
175f1d2b4d3SLarry Finger for (i = 0; i < max_spatial_stream; i++) {
176f1d2b4d3SLarry Finger evm = rtl_evm_db_to_percentage(
177f1d2b4d3SLarry Finger p_phystrpt->stream_rxevm[i]);
178f1d2b4d3SLarry Finger
179f1d2b4d3SLarry Finger if (bpacket_match_bssid) {
180f1d2b4d3SLarry Finger /* Fill value in RFD, Get the first
181f1d2b4d3SLarry Finger * spatial stream only
182f1d2b4d3SLarry Finger */
183f1d2b4d3SLarry Finger if (i == 0)
184f1d2b4d3SLarry Finger pstatus->signalquality = (u8)(evm &
185f1d2b4d3SLarry Finger 0xff);
186f1d2b4d3SLarry Finger pstatus->rx_mimo_signalquality[i] = (u8)(evm &
187f1d2b4d3SLarry Finger 0xff);
188f1d2b4d3SLarry Finger }
189f1d2b4d3SLarry Finger }
190f1d2b4d3SLarry Finger
191f1d2b4d3SLarry Finger if (bpacket_match_bssid) {
192f1d2b4d3SLarry Finger for (i = RF90_PATH_A; i <= RF90_PATH_B; i++)
193f1d2b4d3SLarry Finger rtl_priv(hw)->dm.cfo_tail[i] =
194f1d2b4d3SLarry Finger (int)p_phystrpt->path_cfotail[i];
195f1d2b4d3SLarry Finger
196f1d2b4d3SLarry Finger if (rtl_priv(hw)->dm.packet_count == 0xffffffff)
197f1d2b4d3SLarry Finger rtl_priv(hw)->dm.packet_count = 0;
198f1d2b4d3SLarry Finger else
199f1d2b4d3SLarry Finger rtl_priv(hw)->dm.packet_count++;
200f1d2b4d3SLarry Finger }
201f1d2b4d3SLarry Finger }
202f1d2b4d3SLarry Finger
203f1d2b4d3SLarry Finger /* UI BSS List signal strength(in percentage),
204f1d2b4d3SLarry Finger * make it good looking, from 0~100.
205f1d2b4d3SLarry Finger */
206f1d2b4d3SLarry Finger if (is_cck)
207f1d2b4d3SLarry Finger pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
208f1d2b4d3SLarry Finger pwdb_all));
209f1d2b4d3SLarry Finger else if (rf_rx_num != 0)
210f1d2b4d3SLarry Finger pstatus->signalstrength = (u8)(rtl_signal_scale_mapping(hw,
211f1d2b4d3SLarry Finger total_rssi /= rf_rx_num));
212f1d2b4d3SLarry Finger }
213f1d2b4d3SLarry Finger
_rtl92ee_translate_rx_signal_stuff(struct ieee80211_hw * hw,struct sk_buff * skb,struct rtl_stats * pstatus,u8 * pdesc,struct rx_fwinfo * p_drvinfo)214f1d2b4d3SLarry Finger static void _rtl92ee_translate_rx_signal_stuff(struct ieee80211_hw *hw,
215f1d2b4d3SLarry Finger struct sk_buff *skb,
216f1d2b4d3SLarry Finger struct rtl_stats *pstatus,
217f1d2b4d3SLarry Finger u8 *pdesc,
218f1d2b4d3SLarry Finger struct rx_fwinfo *p_drvinfo)
219f1d2b4d3SLarry Finger {
220f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
221f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
222f1d2b4d3SLarry Finger struct ieee80211_hdr *hdr;
223f1d2b4d3SLarry Finger u8 *tmp_buf;
224f1d2b4d3SLarry Finger u8 *praddr;
225f1d2b4d3SLarry Finger u8 *psaddr;
226f1d2b4d3SLarry Finger __le16 fc;
227f1d2b4d3SLarry Finger bool packet_matchbssid, packet_toself, packet_beacon;
228f1d2b4d3SLarry Finger
229f1d2b4d3SLarry Finger tmp_buf = skb->data + pstatus->rx_drvinfo_size +
230f1d2b4d3SLarry Finger pstatus->rx_bufshift + 24;
231f1d2b4d3SLarry Finger
232f1d2b4d3SLarry Finger hdr = (struct ieee80211_hdr *)tmp_buf;
233f1d2b4d3SLarry Finger fc = hdr->frame_control;
234f1d2b4d3SLarry Finger praddr = hdr->addr1;
235f1d2b4d3SLarry Finger psaddr = ieee80211_get_SA(hdr);
236f1d2b4d3SLarry Finger ether_addr_copy(pstatus->psaddr, psaddr);
237f1d2b4d3SLarry Finger
238f1d2b4d3SLarry Finger packet_matchbssid = (!ieee80211_is_ctl(fc) &&
239f1d2b4d3SLarry Finger (ether_addr_equal(mac->bssid,
240f1d2b4d3SLarry Finger ieee80211_has_tods(fc) ?
241f1d2b4d3SLarry Finger hdr->addr1 :
242f1d2b4d3SLarry Finger ieee80211_has_fromds(fc) ?
243f1d2b4d3SLarry Finger hdr->addr2 : hdr->addr3)) &&
244f1d2b4d3SLarry Finger (!pstatus->hwerror) && (!pstatus->crc) &&
245f1d2b4d3SLarry Finger (!pstatus->icv));
246f1d2b4d3SLarry Finger
247f1d2b4d3SLarry Finger packet_toself = packet_matchbssid &&
248f1d2b4d3SLarry Finger (ether_addr_equal(praddr, rtlefuse->dev_addr));
249f1d2b4d3SLarry Finger
250f1d2b4d3SLarry Finger if (ieee80211_is_beacon(fc))
251f1d2b4d3SLarry Finger packet_beacon = true;
252f1d2b4d3SLarry Finger else
253f1d2b4d3SLarry Finger packet_beacon = false;
254f1d2b4d3SLarry Finger
255f1d2b4d3SLarry Finger if (packet_beacon && packet_matchbssid)
256f1d2b4d3SLarry Finger rtl_priv(hw)->dm.dbginfo.num_qry_beacon_pkt++;
257f1d2b4d3SLarry Finger
258f1d2b4d3SLarry Finger if (packet_matchbssid && ieee80211_is_data_qos(hdr->frame_control) &&
259f1d2b4d3SLarry Finger !is_multicast_ether_addr(ieee80211_get_DA(hdr))) {
260f1d2b4d3SLarry Finger struct ieee80211_qos_hdr *hdr_qos =
261f1d2b4d3SLarry Finger (struct ieee80211_qos_hdr *)tmp_buf;
262f1d2b4d3SLarry Finger u16 tid = le16_to_cpu(hdr_qos->qos_ctrl) & 0xf;
263f1d2b4d3SLarry Finger
264f1d2b4d3SLarry Finger if (tid != 0 && tid != 3)
265f1d2b4d3SLarry Finger rtl_priv(hw)->dm.dbginfo.num_non_be_pkt++;
266f1d2b4d3SLarry Finger }
267f1d2b4d3SLarry Finger
268f1d2b4d3SLarry Finger _rtl92ee_query_rxphystatus(hw, pstatus, pdesc, p_drvinfo,
269f1d2b4d3SLarry Finger packet_matchbssid, packet_toself,
270f1d2b4d3SLarry Finger packet_beacon);
271f1d2b4d3SLarry Finger rtl_process_phyinfo(hw, tmp_buf, pstatus);
272f1d2b4d3SLarry Finger }
273f1d2b4d3SLarry Finger
_rtl92ee_insert_emcontent(struct rtl_tcb_desc * ptcb_desc,u8 * virtualaddress8)274f1d2b4d3SLarry Finger static void _rtl92ee_insert_emcontent(struct rtl_tcb_desc *ptcb_desc,
275200e8bd4SLarry Finger u8 *virtualaddress8)
276f1d2b4d3SLarry Finger {
2779dc35d8aSLarry Finger u32 dwtmp;
278200e8bd4SLarry Finger __le32 *virtualaddress = (__le32 *)virtualaddress8;
279f1d2b4d3SLarry Finger
280f1d2b4d3SLarry Finger memset(virtualaddress, 0, 8);
281f1d2b4d3SLarry Finger
2827f1c7460SLarry Finger set_earlymode_pktnum(virtualaddress, ptcb_desc->empkt_num);
283f1d2b4d3SLarry Finger if (ptcb_desc->empkt_num == 1) {
284f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[0];
285f1d2b4d3SLarry Finger } else {
286f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[0];
287f1d2b4d3SLarry Finger dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
288f1d2b4d3SLarry Finger dwtmp += ptcb_desc->empkt_len[1];
289f1d2b4d3SLarry Finger }
2907f1c7460SLarry Finger set_earlymode_len0(virtualaddress, dwtmp);
291f1d2b4d3SLarry Finger
292f1d2b4d3SLarry Finger if (ptcb_desc->empkt_num <= 3) {
293f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[2];
294f1d2b4d3SLarry Finger } else {
295f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[2];
296f1d2b4d3SLarry Finger dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
297f1d2b4d3SLarry Finger dwtmp += ptcb_desc->empkt_len[3];
298f1d2b4d3SLarry Finger }
2997f1c7460SLarry Finger set_earlymode_len1(virtualaddress, dwtmp);
300f1d2b4d3SLarry Finger if (ptcb_desc->empkt_num <= 5) {
301f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[4];
302f1d2b4d3SLarry Finger } else {
303f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[4];
304f1d2b4d3SLarry Finger dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
305f1d2b4d3SLarry Finger dwtmp += ptcb_desc->empkt_len[5];
306f1d2b4d3SLarry Finger }
3077f1c7460SLarry Finger set_earlymode_len2_1(virtualaddress, dwtmp & 0xF);
3087f1c7460SLarry Finger set_earlymode_len2_2(virtualaddress, dwtmp >> 4);
309f1d2b4d3SLarry Finger if (ptcb_desc->empkt_num <= 7) {
310f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[6];
311f1d2b4d3SLarry Finger } else {
312f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[6];
313f1d2b4d3SLarry Finger dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
314f1d2b4d3SLarry Finger dwtmp += ptcb_desc->empkt_len[7];
315f1d2b4d3SLarry Finger }
3167f1c7460SLarry Finger set_earlymode_len3(virtualaddress, dwtmp);
317f1d2b4d3SLarry Finger if (ptcb_desc->empkt_num <= 9) {
318f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[8];
319f1d2b4d3SLarry Finger } else {
320f1d2b4d3SLarry Finger dwtmp = ptcb_desc->empkt_len[8];
321f1d2b4d3SLarry Finger dwtmp += ((dwtmp % 4) ? (4 - dwtmp % 4) : 0) + 4;
322f1d2b4d3SLarry Finger dwtmp += ptcb_desc->empkt_len[9];
323f1d2b4d3SLarry Finger }
3247f1c7460SLarry Finger set_earlymode_len4(virtualaddress, dwtmp);
325f1d2b4d3SLarry Finger }
326f1d2b4d3SLarry Finger
rtl92ee_rx_query_desc(struct ieee80211_hw * hw,struct rtl_stats * status,struct ieee80211_rx_status * rx_status,u8 * pdesc8,struct sk_buff * skb)327f1d2b4d3SLarry Finger bool rtl92ee_rx_query_desc(struct ieee80211_hw *hw,
328f1d2b4d3SLarry Finger struct rtl_stats *status,
329f1d2b4d3SLarry Finger struct ieee80211_rx_status *rx_status,
330200e8bd4SLarry Finger u8 *pdesc8, struct sk_buff *skb)
331f1d2b4d3SLarry Finger {
332f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
333f1d2b4d3SLarry Finger struct rx_fwinfo *p_drvinfo;
334f1d2b4d3SLarry Finger struct ieee80211_hdr *hdr;
335200e8bd4SLarry Finger __le32 *pdesc = (__le32 *)pdesc8;
3367f1c7460SLarry Finger u32 phystatus = get_rx_desc_physt(pdesc);
337ddab2eeeSLarry Finger u8 wake_match;
338f1d2b4d3SLarry Finger
3397f1c7460SLarry Finger if (get_rx_status_desc_rpt_sel(pdesc) == 0)
340f1d2b4d3SLarry Finger status->packet_report_type = NORMAL_RX;
341f1d2b4d3SLarry Finger else
342f1d2b4d3SLarry Finger status->packet_report_type = C2H_PACKET;
3437f1c7460SLarry Finger status->length = (u16)get_rx_desc_pkt_len(pdesc);
3447f1c7460SLarry Finger status->rx_drvinfo_size = (u8)get_rx_desc_drv_info_size(pdesc) *
345f1d2b4d3SLarry Finger RX_DRV_INFO_SIZE_UNIT;
3467f1c7460SLarry Finger status->rx_bufshift = (u8)(get_rx_desc_shift(pdesc) & 0x03);
3477f1c7460SLarry Finger status->icv = (u16)get_rx_desc_icv(pdesc);
3487f1c7460SLarry Finger status->crc = (u16)get_rx_desc_crc32(pdesc);
349f1d2b4d3SLarry Finger status->hwerror = (status->crc | status->icv);
3507f1c7460SLarry Finger status->decrypted = !get_rx_desc_swdec(pdesc);
3517f1c7460SLarry Finger status->rate = (u8)get_rx_desc_rxmcs(pdesc);
3527f1c7460SLarry Finger status->isampdu = (bool)(get_rx_desc_paggr(pdesc) == 1);
3537f1c7460SLarry Finger status->timestamp_low = get_rx_desc_tsfl(pdesc);
354f1d2b4d3SLarry Finger status->is_cck = RTL92EE_RX_HAL_IS_CCK_RATE(status->rate);
355f1d2b4d3SLarry Finger
3567f1c7460SLarry Finger status->macid = get_rx_desc_macid(pdesc);
3577f1c7460SLarry Finger if (get_rx_status_desc_pattern_match(pdesc))
358ddab2eeeSLarry Finger wake_match = BIT(2);
3597f1c7460SLarry Finger else if (get_rx_status_desc_magic_match(pdesc))
360ddab2eeeSLarry Finger wake_match = BIT(1);
3617f1c7460SLarry Finger else if (get_rx_status_desc_unicast_match(pdesc))
362ddab2eeeSLarry Finger wake_match = BIT(0);
363f1d2b4d3SLarry Finger else
364ddab2eeeSLarry Finger wake_match = 0;
365ddab2eeeSLarry Finger if (wake_match)
366e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_RXDESC, DBG_LOUD,
367f1d2b4d3SLarry Finger "GGGGGGGGGGGGGet Wakeup Packet!! WakeMatch=%d\n",
368ddab2eeeSLarry Finger wake_match);
369f1d2b4d3SLarry Finger rx_status->freq = hw->conf.chandef.chan->center_freq;
370f1d2b4d3SLarry Finger rx_status->band = hw->conf.chandef.chan->band;
371f1d2b4d3SLarry Finger
372f1d2b4d3SLarry Finger hdr = (struct ieee80211_hdr *)(skb->data + status->rx_drvinfo_size +
373f1d2b4d3SLarry Finger status->rx_bufshift + 24);
374f1d2b4d3SLarry Finger
375f1d2b4d3SLarry Finger if (status->crc)
376f1d2b4d3SLarry Finger rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
377f1d2b4d3SLarry Finger
378e703c5ddSLarry Finger if (status->rx_is40mhzpacket)
379da6a4352SJohannes Berg rx_status->bw = RATE_INFO_BW_40;
380f1d2b4d3SLarry Finger
381f1d2b4d3SLarry Finger if (status->is_ht)
382da6a4352SJohannes Berg rx_status->encoding = RX_ENC_HT;
383f1d2b4d3SLarry Finger
384f1d2b4d3SLarry Finger rx_status->flag |= RX_FLAG_MACTIME_START;
385f1d2b4d3SLarry Finger
386f1d2b4d3SLarry Finger /* hw will set status->decrypted true, if it finds the
387f1d2b4d3SLarry Finger * frame is open data frame or mgmt frame.
388f1d2b4d3SLarry Finger * So hw will not decryption robust managment frame
389f1d2b4d3SLarry Finger * for IEEE80211w but still set status->decrypted
390f1d2b4d3SLarry Finger * true, so here we should set it back to undecrypted
391f1d2b4d3SLarry Finger * for IEEE80211w frame, and mac80211 sw will help
392f1d2b4d3SLarry Finger * to decrypt it
393f1d2b4d3SLarry Finger */
394f1d2b4d3SLarry Finger if (status->decrypted) {
395f1d2b4d3SLarry Finger if ((!_ieee80211_is_robust_mgmt_frame(hdr)) &&
396f1d2b4d3SLarry Finger (ieee80211_has_protected(hdr->frame_control)))
397f1d2b4d3SLarry Finger rx_status->flag |= RX_FLAG_DECRYPTED;
398f1d2b4d3SLarry Finger else
399f1d2b4d3SLarry Finger rx_status->flag &= ~RX_FLAG_DECRYPTED;
400f1d2b4d3SLarry Finger }
401f1d2b4d3SLarry Finger
402f1d2b4d3SLarry Finger /* rate_idx: index of data rate into band's
403f1d2b4d3SLarry Finger * supported rates or MCS index if HT rates
404f1d2b4d3SLarry Finger * are use (RX_FLAG_HT)
405f1d2b4d3SLarry Finger * Notice: this is diff with windows define
406f1d2b4d3SLarry Finger */
407f1d2b4d3SLarry Finger rx_status->rate_idx = rtlwifi_rate_mapping(hw, status->is_ht,
408f1d2b4d3SLarry Finger false, status->rate);
409f1d2b4d3SLarry Finger
410f1d2b4d3SLarry Finger rx_status->mactime = status->timestamp_low;
411f1d2b4d3SLarry Finger if (phystatus) {
412f1d2b4d3SLarry Finger p_drvinfo = (struct rx_fwinfo *)(skb->data +
413f1d2b4d3SLarry Finger status->rx_bufshift + 24);
414f1d2b4d3SLarry Finger
415200e8bd4SLarry Finger _rtl92ee_translate_rx_signal_stuff(hw, skb, status, pdesc8,
416f1d2b4d3SLarry Finger p_drvinfo);
417f1d2b4d3SLarry Finger }
418f1d2b4d3SLarry Finger rx_status->signal = status->recvsignalpower + 10;
419f1d2b4d3SLarry Finger if (status->packet_report_type == TX_REPORT2) {
420f1d2b4d3SLarry Finger status->macid_valid_entry[0] =
4217f1c7460SLarry Finger get_rx_rpt2_desc_macid_valid_1(pdesc);
422f1d2b4d3SLarry Finger status->macid_valid_entry[1] =
4237f1c7460SLarry Finger get_rx_rpt2_desc_macid_valid_2(pdesc);
424f1d2b4d3SLarry Finger }
425f1d2b4d3SLarry Finger return true;
426f1d2b4d3SLarry Finger }
427f1d2b4d3SLarry Finger
428f1d2b4d3SLarry Finger /*in Windows, this == Rx_92EE_Interrupt*/
rtl92ee_rx_check_dma_ok(struct ieee80211_hw * hw,u8 * header_desc8,u8 queue_index)429200e8bd4SLarry Finger void rtl92ee_rx_check_dma_ok(struct ieee80211_hw *hw, u8 *header_desc8,
430f1d2b4d3SLarry Finger u8 queue_index)
431f1d2b4d3SLarry Finger {
432f1d2b4d3SLarry Finger u8 first_seg = 0;
433f1d2b4d3SLarry Finger u8 last_seg = 0;
434f1d2b4d3SLarry Finger u16 total_len = 0;
435f1d2b4d3SLarry Finger u16 read_cnt = 0;
436200e8bd4SLarry Finger __le32 *header_desc = (__le32 *)header_desc8;
437f1d2b4d3SLarry Finger
438f1d2b4d3SLarry Finger if (header_desc == NULL)
439f1d2b4d3SLarry Finger return;
440f1d2b4d3SLarry Finger
4417f1c7460SLarry Finger total_len = (u16)get_rx_buffer_desc_total_length(header_desc);
442f1d2b4d3SLarry Finger
4437f1c7460SLarry Finger first_seg = (u8)get_rx_buffer_desc_fs(header_desc);
444f1d2b4d3SLarry Finger
4457f1c7460SLarry Finger last_seg = (u8)get_rx_buffer_desc_ls(header_desc);
446f1d2b4d3SLarry Finger
447f1d2b4d3SLarry Finger while (total_len == 0 && first_seg == 0 && last_seg == 0) {
448f1d2b4d3SLarry Finger read_cnt++;
4497f1c7460SLarry Finger total_len = (u16)get_rx_buffer_desc_total_length(header_desc);
4507f1c7460SLarry Finger first_seg = (u8)get_rx_buffer_desc_fs(header_desc);
4517f1c7460SLarry Finger last_seg = (u8)get_rx_buffer_desc_ls(header_desc);
452f1d2b4d3SLarry Finger
453f1d2b4d3SLarry Finger if (read_cnt > 20)
454f1d2b4d3SLarry Finger break;
455f1d2b4d3SLarry Finger }
456f1d2b4d3SLarry Finger }
457f1d2b4d3SLarry Finger
rtl92ee_rx_desc_buff_remained_cnt(struct ieee80211_hw * hw,u8 queue_index)458f1d2b4d3SLarry Finger u16 rtl92ee_rx_desc_buff_remained_cnt(struct ieee80211_hw *hw, u8 queue_index)
459f1d2b4d3SLarry Finger {
460f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
461f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
4629dc35d8aSLarry Finger u16 read_point, write_point, remind_cnt;
4639dc35d8aSLarry Finger u32 tmp_4byte;
464f1d2b4d3SLarry Finger static bool start_rx;
465f1d2b4d3SLarry Finger
466f1d2b4d3SLarry Finger tmp_4byte = rtl_read_dword(rtlpriv, REG_RXQ_TXBD_IDX);
467f1d2b4d3SLarry Finger read_point = (u16)((tmp_4byte>>16) & 0x7ff);
468f1d2b4d3SLarry Finger write_point = (u16)(tmp_4byte & 0x7ff);
469f1d2b4d3SLarry Finger
470f1d2b4d3SLarry Finger if (write_point != rtlpci->rx_ring[queue_index].next_rx_rp) {
471e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_RXDESC, DBG_DMESG,
472f1d2b4d3SLarry Finger "!!!write point is 0x%x, reg 0x3B4 value is 0x%x\n",
473f1d2b4d3SLarry Finger write_point, tmp_4byte);
474f1d2b4d3SLarry Finger tmp_4byte = rtl_read_dword(rtlpriv, REG_RXQ_TXBD_IDX);
475f1d2b4d3SLarry Finger read_point = (u16)((tmp_4byte>>16) & 0x7ff);
476f1d2b4d3SLarry Finger write_point = (u16)(tmp_4byte & 0x7ff);
477f1d2b4d3SLarry Finger }
478f1d2b4d3SLarry Finger
479f1d2b4d3SLarry Finger if (read_point > 0)
480f1d2b4d3SLarry Finger start_rx = true;
481f1d2b4d3SLarry Finger if (!start_rx)
482f1d2b4d3SLarry Finger return 0;
483f1d2b4d3SLarry Finger
484dc9682a0SPing-Ke Shih remind_cnt = calc_fifo_space(read_point, write_point,
485dc9682a0SPing-Ke Shih RTL_PCI_MAX_RX_COUNT);
486f1d2b4d3SLarry Finger
487f1d2b4d3SLarry Finger if (remind_cnt == 0)
488f1d2b4d3SLarry Finger return 0;
489f1d2b4d3SLarry Finger
490f1d2b4d3SLarry Finger rtlpci->rx_ring[queue_index].next_rx_rp = write_point;
491f1d2b4d3SLarry Finger
492f1d2b4d3SLarry Finger return remind_cnt;
493f1d2b4d3SLarry Finger }
494f1d2b4d3SLarry Finger
get_desc_addr_fr_q_idx(u16 queue_index)495f1d2b4d3SLarry Finger static u16 get_desc_addr_fr_q_idx(u16 queue_index)
496f1d2b4d3SLarry Finger {
4979dc35d8aSLarry Finger u16 desc_address;
498f1d2b4d3SLarry Finger
499f1d2b4d3SLarry Finger switch (queue_index) {
500f1d2b4d3SLarry Finger case BK_QUEUE:
501f1d2b4d3SLarry Finger desc_address = REG_BKQ_TXBD_IDX;
502f1d2b4d3SLarry Finger break;
503f1d2b4d3SLarry Finger case BE_QUEUE:
504f1d2b4d3SLarry Finger desc_address = REG_BEQ_TXBD_IDX;
505f1d2b4d3SLarry Finger break;
506f1d2b4d3SLarry Finger case VI_QUEUE:
507f1d2b4d3SLarry Finger desc_address = REG_VIQ_TXBD_IDX;
508f1d2b4d3SLarry Finger break;
509f1d2b4d3SLarry Finger case VO_QUEUE:
510f1d2b4d3SLarry Finger desc_address = REG_VOQ_TXBD_IDX;
511f1d2b4d3SLarry Finger break;
512f1d2b4d3SLarry Finger case BEACON_QUEUE:
513f1d2b4d3SLarry Finger desc_address = REG_BEQ_TXBD_IDX;
514f1d2b4d3SLarry Finger break;
515f1d2b4d3SLarry Finger case TXCMD_QUEUE:
516f1d2b4d3SLarry Finger desc_address = REG_BEQ_TXBD_IDX;
517f1d2b4d3SLarry Finger break;
518f1d2b4d3SLarry Finger case MGNT_QUEUE:
519f1d2b4d3SLarry Finger desc_address = REG_MGQ_TXBD_IDX;
520f1d2b4d3SLarry Finger break;
521f1d2b4d3SLarry Finger case HIGH_QUEUE:
522f1d2b4d3SLarry Finger desc_address = REG_HI0Q_TXBD_IDX;
523f1d2b4d3SLarry Finger break;
524f1d2b4d3SLarry Finger case HCCA_QUEUE:
525f1d2b4d3SLarry Finger desc_address = REG_BEQ_TXBD_IDX;
526f1d2b4d3SLarry Finger break;
527f1d2b4d3SLarry Finger default:
5289dc35d8aSLarry Finger desc_address = REG_BEQ_TXBD_IDX;
529f1d2b4d3SLarry Finger break;
530f1d2b4d3SLarry Finger }
531f1d2b4d3SLarry Finger return desc_address;
532f1d2b4d3SLarry Finger }
533f1d2b4d3SLarry Finger
rtl92ee_get_available_desc(struct ieee80211_hw * hw,u8 q_idx)534f1d2b4d3SLarry Finger u16 rtl92ee_get_available_desc(struct ieee80211_hw *hw, u8 q_idx)
535f1d2b4d3SLarry Finger {
536f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
537f1d2b4d3SLarry Finger u16 point_diff = 0;
5389dc35d8aSLarry Finger u16 current_tx_read_point, current_tx_write_point;
539f1d2b4d3SLarry Finger u32 tmp_4byte;
540f1d2b4d3SLarry Finger
541f1d2b4d3SLarry Finger tmp_4byte = rtl_read_dword(rtlpriv,
542f1d2b4d3SLarry Finger get_desc_addr_fr_q_idx(q_idx));
543f1d2b4d3SLarry Finger current_tx_read_point = (u16)((tmp_4byte >> 16) & 0x0fff);
544f1d2b4d3SLarry Finger current_tx_write_point = (u16)((tmp_4byte) & 0x0fff);
545f1d2b4d3SLarry Finger
546f1d2b4d3SLarry Finger point_diff = calc_fifo_space(current_tx_read_point,
547dc9682a0SPing-Ke Shih current_tx_write_point,
548dc9682a0SPing-Ke Shih TX_DESC_NUM_92E);
549f1d2b4d3SLarry Finger
550f1d2b4d3SLarry Finger return point_diff;
551f1d2b4d3SLarry Finger }
552f1d2b4d3SLarry Finger
rtl92ee_pre_fill_tx_bd_desc(struct ieee80211_hw * hw,u8 * tx_bd_desc8,u8 * desc8,u8 queue_index,struct sk_buff * skb,dma_addr_t addr)553f1d2b4d3SLarry Finger void rtl92ee_pre_fill_tx_bd_desc(struct ieee80211_hw *hw,
554200e8bd4SLarry Finger u8 *tx_bd_desc8, u8 *desc8, u8 queue_index,
555f1d2b4d3SLarry Finger struct sk_buff *skb, dma_addr_t addr)
556f1d2b4d3SLarry Finger {
557f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
558f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
559f1d2b4d3SLarry Finger u32 pkt_len = skb->len;
560f1d2b4d3SLarry Finger u16 desc_size = 40; /*tx desc size*/
561f1d2b4d3SLarry Finger u32 psblen = 0;
5629dc35d8aSLarry Finger u16 tx_page_size;
5639dc35d8aSLarry Finger u32 total_packet_size;
564f1d2b4d3SLarry Finger u16 current_bd_desc;
5659dc35d8aSLarry Finger u8 i;
566f1d2b4d3SLarry Finger u16 real_desc_size = 0x28;
567f1d2b4d3SLarry Finger u16 append_early_mode_size = 0;
5680c07bd74SPing-Ke Shih u8 segmentnum = 1 << (RTL8192EE_SEG_NUM + 1);
5690c07bd74SPing-Ke Shih dma_addr_t desc_dma_addr;
5700c07bd74SPing-Ke Shih bool dma64 = rtlpriv->cfg->mod_params->dma64;
571200e8bd4SLarry Finger __le32 *desc = (__le32 *)desc8;
572200e8bd4SLarry Finger __le32 *tx_bd_desc = (__le32 *)tx_bd_desc8;
573f1d2b4d3SLarry Finger
574f1d2b4d3SLarry Finger tx_page_size = 2;
575f1d2b4d3SLarry Finger current_bd_desc = rtlpci->tx_ring[queue_index].cur_tx_wp;
576f1d2b4d3SLarry Finger
577f1d2b4d3SLarry Finger total_packet_size = desc_size+pkt_len;
578f1d2b4d3SLarry Finger
579f1d2b4d3SLarry Finger if (rtlpriv->rtlhal.earlymode_enable) {
580f1d2b4d3SLarry Finger if (queue_index < BEACON_QUEUE) {
581f1d2b4d3SLarry Finger append_early_mode_size = 8;
582f1d2b4d3SLarry Finger total_packet_size += append_early_mode_size;
583f1d2b4d3SLarry Finger }
584f1d2b4d3SLarry Finger }
585f1d2b4d3SLarry Finger
586f1d2b4d3SLarry Finger if (tx_page_size > 0) {
587f1d2b4d3SLarry Finger psblen = (pkt_len + real_desc_size + append_early_mode_size) /
588f1d2b4d3SLarry Finger (tx_page_size * 128);
589f1d2b4d3SLarry Finger
590f1d2b4d3SLarry Finger if (psblen * (tx_page_size * 128) < total_packet_size)
591f1d2b4d3SLarry Finger psblen += 1;
592f1d2b4d3SLarry Finger }
593f1d2b4d3SLarry Finger
5940c07bd74SPing-Ke Shih /* tx desc addr */
5950c07bd74SPing-Ke Shih desc_dma_addr = rtlpci->tx_ring[queue_index].dma +
5960c07bd74SPing-Ke Shih (current_bd_desc * TX_DESC_SIZE);
5970c07bd74SPing-Ke Shih
598f1d2b4d3SLarry Finger /* Reset */
5997f1c7460SLarry Finger set_tx_buff_desc_len_0(tx_bd_desc, 0);
6007f1c7460SLarry Finger set_tx_buff_desc_psb(tx_bd_desc, 0);
6017f1c7460SLarry Finger set_tx_buff_desc_own(tx_bd_desc, 0);
602f1d2b4d3SLarry Finger
603f1d2b4d3SLarry Finger for (i = 1; i < segmentnum; i++) {
6047f1c7460SLarry Finger set_txbuffer_desc_len_with_offset(tx_bd_desc, i, 0);
6057f1c7460SLarry Finger set_txbuffer_desc_amsdu_with_offset(tx_bd_desc, i, 0);
6067f1c7460SLarry Finger set_txbuffer_desc_add_low_with_offset(tx_bd_desc, i, 0);
6077f1c7460SLarry Finger set_txbuffer_desc_add_high_with_offset(tx_bd_desc, i, 0, dma64);
608f1d2b4d3SLarry Finger }
609f1d2b4d3SLarry Finger
610f1d2b4d3SLarry Finger /* Clear all status */
611200e8bd4SLarry Finger clear_pci_tx_desc_content(desc, TX_DESC_SIZE);
612f1d2b4d3SLarry Finger
613f1d2b4d3SLarry Finger if (rtlpriv->rtlhal.earlymode_enable) {
614f1d2b4d3SLarry Finger if (queue_index < BEACON_QUEUE) {
615f1d2b4d3SLarry Finger /* This if needs braces */
6167f1c7460SLarry Finger set_tx_buff_desc_len_0(tx_bd_desc, desc_size + 8);
617f1d2b4d3SLarry Finger } else {
6187f1c7460SLarry Finger set_tx_buff_desc_len_0(tx_bd_desc, desc_size);
619f1d2b4d3SLarry Finger }
620f1d2b4d3SLarry Finger } else {
6217f1c7460SLarry Finger set_tx_buff_desc_len_0(tx_bd_desc, desc_size);
622f1d2b4d3SLarry Finger }
6237f1c7460SLarry Finger set_tx_buff_desc_psb(tx_bd_desc, psblen);
6247f1c7460SLarry Finger set_tx_buff_desc_addr_low_0(tx_bd_desc, desc_dma_addr);
6257f1c7460SLarry Finger set_tx_buff_desc_addr_high_0(tx_bd_desc, ((u64)desc_dma_addr >> 32),
6260c07bd74SPing-Ke Shih dma64);
627f1d2b4d3SLarry Finger
6287f1c7460SLarry Finger set_txbuffer_desc_len_with_offset(tx_bd_desc, 1, pkt_len);
629f1d2b4d3SLarry Finger /* don't using extendsion mode. */
6307f1c7460SLarry Finger set_txbuffer_desc_amsdu_with_offset(tx_bd_desc, 1, 0);
6317f1c7460SLarry Finger set_txbuffer_desc_add_low_with_offset(tx_bd_desc, 1, addr);
6327f1c7460SLarry Finger set_txbuffer_desc_add_high_with_offset(tx_bd_desc, 1,
6330c07bd74SPing-Ke Shih ((u64)addr >> 32), dma64);
634f1d2b4d3SLarry Finger
6357f1c7460SLarry Finger set_tx_desc_pkt_size(desc, (u16)(pkt_len));
6367f1c7460SLarry Finger set_tx_desc_tx_buffer_size(desc, (u16)(pkt_len));
637f1d2b4d3SLarry Finger }
638f1d2b4d3SLarry Finger
rtl92ee_tx_fill_desc(struct ieee80211_hw * hw,struct ieee80211_hdr * hdr,u8 * pdesc8,u8 * pbd_desc_tx,struct ieee80211_tx_info * info,struct ieee80211_sta * sta,struct sk_buff * skb,u8 hw_queue,struct rtl_tcb_desc * ptcb_desc)639f1d2b4d3SLarry Finger void rtl92ee_tx_fill_desc(struct ieee80211_hw *hw,
640200e8bd4SLarry Finger struct ieee80211_hdr *hdr, u8 *pdesc8,
641f1d2b4d3SLarry Finger u8 *pbd_desc_tx,
642f1d2b4d3SLarry Finger struct ieee80211_tx_info *info,
643f1d2b4d3SLarry Finger struct ieee80211_sta *sta,
644f1d2b4d3SLarry Finger struct sk_buff *skb,
645f1d2b4d3SLarry Finger u8 hw_queue, struct rtl_tcb_desc *ptcb_desc)
646f1d2b4d3SLarry Finger {
647f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
648f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
649f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
650f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
6516acfbb81STzu-En Huang struct rtlwifi_tx_info *tx_info = rtl_tx_skb_cb_info(skb);
652f1d2b4d3SLarry Finger u16 seq_number;
653f1d2b4d3SLarry Finger __le16 fc = hdr->frame_control;
654f1d2b4d3SLarry Finger u8 fw_qsel = _rtl92ee_map_hwqueue_to_fwqueue(skb, hw_queue);
655f1d2b4d3SLarry Finger bool firstseg = ((hdr->seq_ctrl &
656f1d2b4d3SLarry Finger cpu_to_le16(IEEE80211_SCTL_FRAG)) == 0);
657f1d2b4d3SLarry Finger bool lastseg = ((hdr->frame_control &
658f1d2b4d3SLarry Finger cpu_to_le16(IEEE80211_FCTL_MOREFRAGS)) == 0);
659f1d2b4d3SLarry Finger dma_addr_t mapping;
660f1d2b4d3SLarry Finger u8 bw_40 = 0;
661200e8bd4SLarry Finger __le32 *pdesc = (__le32 *)pdesc8;
662f1d2b4d3SLarry Finger
663f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_STATION) {
664f1d2b4d3SLarry Finger bw_40 = mac->bw_40;
665f1d2b4d3SLarry Finger } else if (mac->opmode == NL80211_IFTYPE_AP ||
666f1d2b4d3SLarry Finger mac->opmode == NL80211_IFTYPE_ADHOC) {
667f1d2b4d3SLarry Finger if (sta)
668046d2e7cSSriram R bw_40 = sta->deflink.ht_cap.cap &
669f1d2b4d3SLarry Finger IEEE80211_HT_CAP_SUP_WIDTH_20_40;
670f1d2b4d3SLarry Finger }
671f1d2b4d3SLarry Finger seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
672f1d2b4d3SLarry Finger rtl_get_tcb_desc(hw, info, sta, skb, ptcb_desc);
673f1d2b4d3SLarry Finger /* reserve 8 byte for AMPDU early mode */
674f1d2b4d3SLarry Finger if (rtlhal->earlymode_enable) {
675f1d2b4d3SLarry Finger skb_push(skb, EM_HDR_LEN);
676f1d2b4d3SLarry Finger memset(skb->data, 0, EM_HDR_LEN);
677f1d2b4d3SLarry Finger }
6780dc0b5c2SChristophe JAILLET mapping = dma_map_single(&rtlpci->pdev->dev, skb->data, skb->len,
6790dc0b5c2SChristophe JAILLET DMA_TO_DEVICE);
6800dc0b5c2SChristophe JAILLET if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) {
681e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
6824713bd1cSJoe Perches "DMA mapping error\n");
683f1d2b4d3SLarry Finger return;
684f1d2b4d3SLarry Finger }
685f1d2b4d3SLarry Finger
686f1d2b4d3SLarry Finger if (pbd_desc_tx != NULL)
687200e8bd4SLarry Finger rtl92ee_pre_fill_tx_bd_desc(hw, pbd_desc_tx, pdesc8, hw_queue,
688f1d2b4d3SLarry Finger skb, mapping);
689f1d2b4d3SLarry Finger
690f1d2b4d3SLarry Finger if (ieee80211_is_nullfunc(fc) || ieee80211_is_ctl(fc)) {
691f1d2b4d3SLarry Finger firstseg = true;
692f1d2b4d3SLarry Finger lastseg = true;
693f1d2b4d3SLarry Finger }
694f1d2b4d3SLarry Finger if (firstseg) {
695f1d2b4d3SLarry Finger if (rtlhal->earlymode_enable) {
6967f1c7460SLarry Finger set_tx_desc_pkt_offset(pdesc, 1);
6977f1c7460SLarry Finger set_tx_desc_offset(pdesc,
698f1d2b4d3SLarry Finger USB_HWDESC_HEADER_LEN + EM_HDR_LEN);
699f1d2b4d3SLarry Finger if (ptcb_desc->empkt_num) {
700e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
701f1d2b4d3SLarry Finger "Insert 8 byte.pTcb->EMPktNum:%d\n",
702f1d2b4d3SLarry Finger ptcb_desc->empkt_num);
703f1d2b4d3SLarry Finger _rtl92ee_insert_emcontent(ptcb_desc,
704f1d2b4d3SLarry Finger (u8 *)(skb->data));
705f1d2b4d3SLarry Finger }
706f1d2b4d3SLarry Finger } else {
7077f1c7460SLarry Finger set_tx_desc_offset(pdesc, USB_HWDESC_HEADER_LEN);
708f1d2b4d3SLarry Finger }
709f1d2b4d3SLarry Finger
7108479580bSPing-Ke Shih
7117f1c7460SLarry Finger set_tx_desc_tx_rate(pdesc, ptcb_desc->hw_rate);
712f1d2b4d3SLarry Finger
713f1d2b4d3SLarry Finger if (ieee80211_is_mgmt(fc)) {
714f1d2b4d3SLarry Finger ptcb_desc->use_driver_rate = true;
715f1d2b4d3SLarry Finger } else {
716f1d2b4d3SLarry Finger if (rtlpriv->ra.is_special_data) {
717f1d2b4d3SLarry Finger ptcb_desc->use_driver_rate = true;
7187f1c7460SLarry Finger set_tx_desc_tx_rate(pdesc, DESC_RATE11M);
719f1d2b4d3SLarry Finger } else {
720f1d2b4d3SLarry Finger ptcb_desc->use_driver_rate = false;
721f1d2b4d3SLarry Finger }
722f1d2b4d3SLarry Finger }
723f1d2b4d3SLarry Finger
724f1d2b4d3SLarry Finger if (info->flags & IEEE80211_TX_CTL_AMPDU) {
7257f1c7460SLarry Finger set_tx_desc_agg_enable(pdesc, 1);
7267f1c7460SLarry Finger set_tx_desc_max_agg_num(pdesc, 0x14);
727f1d2b4d3SLarry Finger }
7287f1c7460SLarry Finger set_tx_desc_seq(pdesc, seq_number);
7297f1c7460SLarry Finger set_tx_desc_rts_enable(pdesc,
730f1d2b4d3SLarry Finger ((ptcb_desc->rts_enable &&
731f1d2b4d3SLarry Finger !ptcb_desc->cts_enable) ? 1 : 0));
7327f1c7460SLarry Finger set_tx_desc_hw_rts_enable(pdesc, 0);
7337f1c7460SLarry Finger set_tx_desc_cts2self(pdesc,
734f1d2b4d3SLarry Finger ((ptcb_desc->cts_enable) ? 1 : 0));
735f1d2b4d3SLarry Finger
7367f1c7460SLarry Finger set_tx_desc_rts_rate(pdesc, ptcb_desc->rts_rate);
7377f1c7460SLarry Finger set_tx_desc_rts_sc(pdesc, ptcb_desc->rts_sc);
7387f1c7460SLarry Finger set_tx_desc_rts_short(pdesc,
739f1d2b4d3SLarry Finger ((ptcb_desc->rts_rate <= DESC_RATE54M) ?
740f1d2b4d3SLarry Finger (ptcb_desc->rts_use_shortpreamble ? 1 : 0) :
741f1d2b4d3SLarry Finger (ptcb_desc->rts_use_shortgi ? 1 : 0)));
742f1d2b4d3SLarry Finger
743f1d2b4d3SLarry Finger if (ptcb_desc->tx_enable_sw_calc_duration)
7447f1c7460SLarry Finger set_tx_desc_nav_use_hdr(pdesc, 1);
745f1d2b4d3SLarry Finger
746f1d2b4d3SLarry Finger if (bw_40) {
747f1d2b4d3SLarry Finger if (ptcb_desc->packet_bw == HT_CHANNEL_WIDTH_20_40) {
7487f1c7460SLarry Finger set_tx_desc_data_bw(pdesc, 1);
7497f1c7460SLarry Finger set_tx_desc_tx_sub_carrier(pdesc, 3);
750f1d2b4d3SLarry Finger } else {
7517f1c7460SLarry Finger set_tx_desc_data_bw(pdesc, 0);
7527f1c7460SLarry Finger set_tx_desc_tx_sub_carrier(pdesc,
753f1d2b4d3SLarry Finger mac->cur_40_prime_sc);
754f1d2b4d3SLarry Finger }
755f1d2b4d3SLarry Finger } else {
7567f1c7460SLarry Finger set_tx_desc_data_bw(pdesc, 0);
7577f1c7460SLarry Finger set_tx_desc_tx_sub_carrier(pdesc, 0);
758f1d2b4d3SLarry Finger }
759f1d2b4d3SLarry Finger
7607f1c7460SLarry Finger set_tx_desc_linip(pdesc, 0);
761f1d2b4d3SLarry Finger if (sta) {
762046d2e7cSSriram R u8 ampdu_density = sta->deflink.ht_cap.ampdu_density;
763f1d2b4d3SLarry Finger
7647f1c7460SLarry Finger set_tx_desc_ampdu_density(pdesc, ampdu_density);
765f1d2b4d3SLarry Finger }
766f1d2b4d3SLarry Finger if (info->control.hw_key) {
767f1d2b4d3SLarry Finger struct ieee80211_key_conf *key = info->control.hw_key;
768f1d2b4d3SLarry Finger
769f1d2b4d3SLarry Finger switch (key->cipher) {
770f1d2b4d3SLarry Finger case WLAN_CIPHER_SUITE_WEP40:
771f1d2b4d3SLarry Finger case WLAN_CIPHER_SUITE_WEP104:
772f1d2b4d3SLarry Finger case WLAN_CIPHER_SUITE_TKIP:
7737f1c7460SLarry Finger set_tx_desc_sec_type(pdesc, 0x1);
774f1d2b4d3SLarry Finger break;
775f1d2b4d3SLarry Finger case WLAN_CIPHER_SUITE_CCMP:
7767f1c7460SLarry Finger set_tx_desc_sec_type(pdesc, 0x3);
777f1d2b4d3SLarry Finger break;
778f1d2b4d3SLarry Finger default:
7797f1c7460SLarry Finger set_tx_desc_sec_type(pdesc, 0x0);
780f1d2b4d3SLarry Finger break;
781f1d2b4d3SLarry Finger }
782f1d2b4d3SLarry Finger }
783f1d2b4d3SLarry Finger
7847f1c7460SLarry Finger set_tx_desc_queue_sel(pdesc, fw_qsel);
7857f1c7460SLarry Finger set_tx_desc_data_rate_fb_limit(pdesc, 0x1F);
7867f1c7460SLarry Finger set_tx_desc_rts_rate_fb_limit(pdesc, 0xF);
7877f1c7460SLarry Finger set_tx_desc_disable_fb(pdesc,
788f1d2b4d3SLarry Finger ptcb_desc->disable_ratefallback ? 1 : 0);
7897f1c7460SLarry Finger set_tx_desc_use_rate(pdesc, ptcb_desc->use_driver_rate ? 1 : 0);
790f1d2b4d3SLarry Finger
7917f1c7460SLarry Finger /*set_tx_desc_pwr_status(pdesc, pwr_status);*/
792f1d2b4d3SLarry Finger /* Set TxRate and RTSRate in TxDesc */
793f1d2b4d3SLarry Finger /* This prevent Tx initial rate of new-coming packets */
794f1d2b4d3SLarry Finger /* from being overwritten by retried packet rate.*/
795f1d2b4d3SLarry Finger if (!ptcb_desc->use_driver_rate) {
7967f1c7460SLarry Finger /*set_tx_desc_rts_rate(pdesc, 0x08); */
7977f1c7460SLarry Finger /* set_tx_desc_tx_rate(pdesc, 0x0b); */
798f1d2b4d3SLarry Finger }
799f1d2b4d3SLarry Finger if (ieee80211_is_data_qos(fc)) {
800f1d2b4d3SLarry Finger if (mac->rdg_en) {
801e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
802f1d2b4d3SLarry Finger "Enable RDG function.\n");
8037f1c7460SLarry Finger set_tx_desc_rdg_enable(pdesc, 1);
8047f1c7460SLarry Finger set_tx_desc_htc(pdesc, 1);
805f1d2b4d3SLarry Finger }
806f1d2b4d3SLarry Finger }
8076acfbb81STzu-En Huang /* tx report */
808200e8bd4SLarry Finger rtl_set_tx_report(ptcb_desc, pdesc8, hw, tx_info);
809f1d2b4d3SLarry Finger }
810f1d2b4d3SLarry Finger
8117f1c7460SLarry Finger set_tx_desc_first_seg(pdesc, (firstseg ? 1 : 0));
8127f1c7460SLarry Finger set_tx_desc_last_seg(pdesc, (lastseg ? 1 : 0));
8137f1c7460SLarry Finger set_tx_desc_tx_buffer_address(pdesc, mapping);
814f1d2b4d3SLarry Finger if (rtlpriv->dm.useramask) {
8157f1c7460SLarry Finger set_tx_desc_rate_id(pdesc, ptcb_desc->ratr_index);
8167f1c7460SLarry Finger set_tx_desc_macid(pdesc, ptcb_desc->mac_id);
817f1d2b4d3SLarry Finger } else {
8187f1c7460SLarry Finger set_tx_desc_rate_id(pdesc, 0xC + ptcb_desc->ratr_index);
8197f1c7460SLarry Finger set_tx_desc_macid(pdesc, ptcb_desc->ratr_index);
820f1d2b4d3SLarry Finger }
821f1d2b4d3SLarry Finger
8227f1c7460SLarry Finger set_tx_desc_more_frag(pdesc, (lastseg ? 0 : 1));
823f1d2b4d3SLarry Finger if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
824f1d2b4d3SLarry Finger is_broadcast_ether_addr(ieee80211_get_DA(hdr))) {
8257f1c7460SLarry Finger set_tx_desc_bmc(pdesc, 1);
826f1d2b4d3SLarry Finger }
827e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, "\n");
828f1d2b4d3SLarry Finger }
829f1d2b4d3SLarry Finger
rtl92ee_tx_fill_cmddesc(struct ieee80211_hw * hw,u8 * pdesc8,bool firstseg,bool lastseg,struct sk_buff * skb)830f1d2b4d3SLarry Finger void rtl92ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
831200e8bd4SLarry Finger u8 *pdesc8, bool firstseg,
832f1d2b4d3SLarry Finger bool lastseg, struct sk_buff *skb)
833f1d2b4d3SLarry Finger {
834f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
835f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
836f1d2b4d3SLarry Finger u8 fw_queue = QSLT_BEACON;
8370dc0b5c2SChristophe JAILLET dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
8380dc0b5c2SChristophe JAILLET skb->len, DMA_TO_DEVICE);
839f1d2b4d3SLarry Finger u8 txdesc_len = 40;
840200e8bd4SLarry Finger __le32 *pdesc = (__le32 *)pdesc8;
841f1d2b4d3SLarry Finger
8420dc0b5c2SChristophe JAILLET if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) {
843e24a2a87SLarry Finger rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
8444713bd1cSJoe Perches "DMA mapping error\n");
845f1d2b4d3SLarry Finger return;
846f1d2b4d3SLarry Finger }
847200e8bd4SLarry Finger clear_pci_tx_desc_content(pdesc, txdesc_len);
848f1d2b4d3SLarry Finger
849f1d2b4d3SLarry Finger if (firstseg)
8507f1c7460SLarry Finger set_tx_desc_offset(pdesc, txdesc_len);
851f1d2b4d3SLarry Finger
8527f1c7460SLarry Finger set_tx_desc_tx_rate(pdesc, DESC_RATE1M);
853f1d2b4d3SLarry Finger
8547f1c7460SLarry Finger set_tx_desc_seq(pdesc, 0);
855f1d2b4d3SLarry Finger
8567f1c7460SLarry Finger set_tx_desc_linip(pdesc, 0);
857f1d2b4d3SLarry Finger
8587f1c7460SLarry Finger set_tx_desc_queue_sel(pdesc, fw_queue);
859f1d2b4d3SLarry Finger
8607f1c7460SLarry Finger set_tx_desc_first_seg(pdesc, 1);
8617f1c7460SLarry Finger set_tx_desc_last_seg(pdesc, 1);
862f1d2b4d3SLarry Finger
8637f1c7460SLarry Finger set_tx_desc_tx_buffer_size(pdesc, (u16)(skb->len));
864f1d2b4d3SLarry Finger
8657f1c7460SLarry Finger set_tx_desc_tx_buffer_address(pdesc, mapping);
866f1d2b4d3SLarry Finger
8677f1c7460SLarry Finger set_tx_desc_rate_id(pdesc, 7);
8687f1c7460SLarry Finger set_tx_desc_macid(pdesc, 0);
869f1d2b4d3SLarry Finger
8707f1c7460SLarry Finger set_tx_desc_own(pdesc, 1);
871f1d2b4d3SLarry Finger
872200e8bd4SLarry Finger set_tx_desc_pkt_size(pdesc, (u16)(skb->len));
873f1d2b4d3SLarry Finger
8747f1c7460SLarry Finger set_tx_desc_first_seg(pdesc, 1);
8757f1c7460SLarry Finger set_tx_desc_last_seg(pdesc, 1);
876f1d2b4d3SLarry Finger
8777f1c7460SLarry Finger set_tx_desc_offset(pdesc, 40);
878f1d2b4d3SLarry Finger
8797f1c7460SLarry Finger set_tx_desc_use_rate(pdesc, 1);
880f1d2b4d3SLarry Finger
881f1d2b4d3SLarry Finger RT_PRINT_DATA(rtlpriv, COMP_CMD, DBG_LOUD,
882f1d2b4d3SLarry Finger "H2C Tx Cmd Content\n", pdesc, txdesc_len);
883f1d2b4d3SLarry Finger }
884f1d2b4d3SLarry Finger
rtl92ee_set_desc(struct ieee80211_hw * hw,u8 * pdesc8,bool istx,u8 desc_name,u8 * val)885200e8bd4SLarry Finger void rtl92ee_set_desc(struct ieee80211_hw *hw, u8 *pdesc8, bool istx,
886f1d2b4d3SLarry Finger u8 desc_name, u8 *val)
887f1d2b4d3SLarry Finger {
888f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
889f1d2b4d3SLarry Finger u8 q_idx = *val;
8900c07bd74SPing-Ke Shih bool dma64 = rtlpriv->cfg->mod_params->dma64;
891200e8bd4SLarry Finger __le32 *pdesc = (__le32 *)pdesc8;
892f1d2b4d3SLarry Finger
893f1d2b4d3SLarry Finger if (istx) {
894f1d2b4d3SLarry Finger switch (desc_name) {
895f1d2b4d3SLarry Finger case HW_DESC_TX_NEXTDESC_ADDR:
8967f1c7460SLarry Finger set_tx_desc_next_desc_address(pdesc, *(u32 *)val);
897f1d2b4d3SLarry Finger break;
898f1d2b4d3SLarry Finger case HW_DESC_OWN:{
899f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
900f1d2b4d3SLarry Finger struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[q_idx];
901f1d2b4d3SLarry Finger u16 max_tx_desc = ring->entries;
902f1d2b4d3SLarry Finger
903f1d2b4d3SLarry Finger if (q_idx == BEACON_QUEUE) {
904f1d2b4d3SLarry Finger ring->cur_tx_wp = 0;
905f1d2b4d3SLarry Finger ring->cur_tx_rp = 0;
9067f1c7460SLarry Finger set_tx_buff_desc_own(pdesc, 1);
907f1d2b4d3SLarry Finger return;
908f1d2b4d3SLarry Finger }
909f1d2b4d3SLarry Finger
910cf54622cSPing-Ke Shih /* make sure tx desc is available by caller */
911f1d2b4d3SLarry Finger ring->cur_tx_wp = ((ring->cur_tx_wp + 1) % max_tx_desc);
912f1d2b4d3SLarry Finger
913f1d2b4d3SLarry Finger rtl_write_word(rtlpriv,
914f1d2b4d3SLarry Finger get_desc_addr_fr_q_idx(q_idx),
915f1d2b4d3SLarry Finger ring->cur_tx_wp);
916f1d2b4d3SLarry Finger }
917f1d2b4d3SLarry Finger break;
918f1d2b4d3SLarry Finger }
919f1d2b4d3SLarry Finger } else {
920f1d2b4d3SLarry Finger switch (desc_name) {
921f1d2b4d3SLarry Finger case HW_DESC_RX_PREPARE:
9227f1c7460SLarry Finger set_rx_buffer_desc_ls(pdesc, 0);
9237f1c7460SLarry Finger set_rx_buffer_desc_fs(pdesc, 0);
9247f1c7460SLarry Finger set_rx_buffer_desc_total_length(pdesc, 0);
925f1d2b4d3SLarry Finger
9267f1c7460SLarry Finger set_rx_buffer_desc_data_length(pdesc,
927f1d2b4d3SLarry Finger MAX_RECEIVE_BUFFER_SIZE +
928f1d2b4d3SLarry Finger RX_DESC_SIZE);
929f1d2b4d3SLarry Finger
9307f1c7460SLarry Finger set_rx_buffer_physical_low(pdesc, (*(dma_addr_t *)val) &
9310c07bd74SPing-Ke Shih DMA_BIT_MASK(32));
9327f1c7460SLarry Finger set_rx_buffer_physical_high(pdesc,
9330c07bd74SPing-Ke Shih ((u64)(*(dma_addr_t *)val)
9340c07bd74SPing-Ke Shih >> 32),
9350c07bd74SPing-Ke Shih dma64);
936f1d2b4d3SLarry Finger break;
937f1d2b4d3SLarry Finger case HW_DESC_RXERO:
9387f1c7460SLarry Finger set_rx_desc_eor(pdesc, 1);
939f1d2b4d3SLarry Finger break;
940f1d2b4d3SLarry Finger default:
941531940f9SLarry Finger WARN_ONCE(true,
942531940f9SLarry Finger "rtl8192ee: ERR rxdesc :%d not processed\n",
943531940f9SLarry Finger desc_name);
944f1d2b4d3SLarry Finger break;
945f1d2b4d3SLarry Finger }
946f1d2b4d3SLarry Finger }
947f1d2b4d3SLarry Finger }
948f1d2b4d3SLarry Finger
rtl92ee_get_desc(struct ieee80211_hw * hw,u8 * pdesc8,bool istx,u8 desc_name)9490c07bd74SPing-Ke Shih u64 rtl92ee_get_desc(struct ieee80211_hw *hw,
950200e8bd4SLarry Finger u8 *pdesc8, bool istx, u8 desc_name)
951f1d2b4d3SLarry Finger {
9520c07bd74SPing-Ke Shih struct rtl_priv *rtlpriv = rtl_priv(hw);
9530c07bd74SPing-Ke Shih u64 ret = 0;
9540c07bd74SPing-Ke Shih bool dma64 = rtlpriv->cfg->mod_params->dma64;
955200e8bd4SLarry Finger __le32 *pdesc = (__le32 *)pdesc8;
956f1d2b4d3SLarry Finger
957f1d2b4d3SLarry Finger if (istx) {
958f1d2b4d3SLarry Finger switch (desc_name) {
959f1d2b4d3SLarry Finger case HW_DESC_OWN:
9607f1c7460SLarry Finger ret = get_tx_desc_own(pdesc);
961f1d2b4d3SLarry Finger break;
962f1d2b4d3SLarry Finger case HW_DESC_TXBUFF_ADDR:
9637f1c7460SLarry Finger ret = get_txbuffer_desc_addr_low(pdesc, 1);
9647f1c7460SLarry Finger ret |= (u64)get_txbuffer_desc_addr_high(pdesc, 1,
9650c07bd74SPing-Ke Shih dma64) << 32;
966f1d2b4d3SLarry Finger break;
967f1d2b4d3SLarry Finger default:
968531940f9SLarry Finger WARN_ONCE(true,
969531940f9SLarry Finger "rtl8192ee: ERR txdesc :%d not processed\n",
970531940f9SLarry Finger desc_name);
971f1d2b4d3SLarry Finger break;
972f1d2b4d3SLarry Finger }
973f1d2b4d3SLarry Finger } else {
974f1d2b4d3SLarry Finger switch (desc_name) {
975f1d2b4d3SLarry Finger case HW_DESC_OWN:
9767f1c7460SLarry Finger ret = get_rx_desc_own(pdesc);
977f1d2b4d3SLarry Finger break;
978f1d2b4d3SLarry Finger case HW_DESC_RXPKT_LEN:
9797f1c7460SLarry Finger ret = get_rx_desc_pkt_len(pdesc);
980f1d2b4d3SLarry Finger break;
981f1d2b4d3SLarry Finger case HW_DESC_RXBUFF_ADDR:
9827f1c7460SLarry Finger ret = get_rx_desc_buff_addr(pdesc);
983f1d2b4d3SLarry Finger break;
984f1d2b4d3SLarry Finger default:
985531940f9SLarry Finger WARN_ONCE(true,
986531940f9SLarry Finger "rtl8192ee: ERR rxdesc :%d not processed\n",
987531940f9SLarry Finger desc_name);
988f1d2b4d3SLarry Finger break;
989f1d2b4d3SLarry Finger }
990f1d2b4d3SLarry Finger }
991f1d2b4d3SLarry Finger return ret;
992f1d2b4d3SLarry Finger }
993f1d2b4d3SLarry Finger
rtl92ee_is_tx_desc_closed(struct ieee80211_hw * hw,u8 hw_queue,u16 index)994f1d2b4d3SLarry Finger bool rtl92ee_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue, u16 index)
995f1d2b4d3SLarry Finger {
996f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
997f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw);
998cf54622cSPing-Ke Shih u16 read_point, write_point;
999f1d2b4d3SLarry Finger bool ret = false;
1000f1d2b4d3SLarry Finger struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
1001f1d2b4d3SLarry Finger
1002f1d2b4d3SLarry Finger {
1003ac8efe4fSzhengbin u16 cur_tx_rp;
10049dc35d8aSLarry Finger u32 tmpu32;
1005f1d2b4d3SLarry Finger
1006f1d2b4d3SLarry Finger tmpu32 =
1007f1d2b4d3SLarry Finger rtl_read_dword(rtlpriv,
1008f1d2b4d3SLarry Finger get_desc_addr_fr_q_idx(hw_queue));
1009f1d2b4d3SLarry Finger cur_tx_rp = (u16)((tmpu32 >> 16) & 0x0fff);
1010f1d2b4d3SLarry Finger
1011cf54622cSPing-Ke Shih /* don't need to update ring->cur_tx_wp */
1012f1d2b4d3SLarry Finger ring->cur_tx_rp = cur_tx_rp;
1013f1d2b4d3SLarry Finger }
1014f1d2b4d3SLarry Finger
1015f1d2b4d3SLarry Finger read_point = ring->cur_tx_rp;
1016f1d2b4d3SLarry Finger write_point = ring->cur_tx_wp;
1017f1d2b4d3SLarry Finger
1018f1d2b4d3SLarry Finger if (write_point > read_point) {
1019f1d2b4d3SLarry Finger if (index < write_point && index >= read_point)
1020f1d2b4d3SLarry Finger ret = false;
1021f1d2b4d3SLarry Finger else
1022f1d2b4d3SLarry Finger ret = true;
1023f1d2b4d3SLarry Finger } else if (write_point < read_point) {
1024f1d2b4d3SLarry Finger if (index > write_point && index < read_point)
1025f1d2b4d3SLarry Finger ret = true;
1026f1d2b4d3SLarry Finger else
1027f1d2b4d3SLarry Finger ret = false;
1028f1d2b4d3SLarry Finger } else {
1029f1d2b4d3SLarry Finger if (index != read_point)
1030f1d2b4d3SLarry Finger ret = true;
1031f1d2b4d3SLarry Finger }
1032f1d2b4d3SLarry Finger
1033f1d2b4d3SLarry Finger if (hw_queue == BEACON_QUEUE)
1034f1d2b4d3SLarry Finger ret = true;
1035f1d2b4d3SLarry Finger
1036f1d2b4d3SLarry Finger if (rtlpriv->rtlhal.driver_is_goingto_unload ||
1037f1d2b4d3SLarry Finger rtlpriv->psc.rfoff_reason > RF_CHANGE_BY_PS)
1038f1d2b4d3SLarry Finger ret = true;
1039f1d2b4d3SLarry Finger
1040f1d2b4d3SLarry Finger return ret;
1041f1d2b4d3SLarry Finger }
1042f1d2b4d3SLarry Finger
rtl92ee_tx_polling(struct ieee80211_hw * hw,u8 hw_queue)1043f1d2b4d3SLarry Finger void rtl92ee_tx_polling(struct ieee80211_hw *hw, u8 hw_queue)
1044f1d2b4d3SLarry Finger {
1045f1d2b4d3SLarry Finger }
1046