1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2024 Realtek Corporation.*/
#include "../wifi.h"
#include "../base.h"
#include "../usb.h"
#include "../rtl8192d/reg.h"
#include "../rtl8192d/def.h"
#include "../rtl8192d/trx_common.h"
#include "trx.h"
void rtl92du_tx_cleanup(struct ieee80211_hw *hw, struct sk_buff *skb)
{
}
int rtl92du_tx_post_hdl(struct ieee80211_hw *hw, struct urb *urb,
struct sk_buff *skb)
{
return 0;
}
struct sk_buff *rtl92du_tx_aggregate_hdl(struct ieee80211_hw *hw,
struct sk_buff_head *list)
{
return skb_dequeue(list);
}
static enum rtl_desc_qsel _rtl92du_hwq_to_descq(u16 queue_index)
{
switch (queue_index) {
case RTL_TXQ_BCN:
return QSLT_BEACON;
case RTL_TXQ_MGT:
return QSLT_MGNT;
case RTL_TXQ_VO:
return QSLT_VO;
case RTL_TXQ_VI:
return QSLT_VI;
case RTL_TXQ_BK:
return QSLT_BK;
default:
case RTL_TXQ_BE:
return QSLT_BE;
}
}
/* For HW recovery information */
static void _rtl92du_tx_desc_checksum(__le32 *txdesc)
{
__le16 *ptr = (__le16 *)txdesc;
u16 checksum = 0;
u32 index;
/* Clear first */
set_tx_desc_tx_desc_checksum(txdesc, 0);
for (index = 0; index < 16; index++)
checksum = checksum ^ le16_to_cpu(*(ptr + index));
set_tx_desc_tx_desc_checksum(txdesc, checksum);
}
void rtl92du_tx_fill_desc(struct ieee80211_hw *hw,
struct ieee80211_hdr *hdr, u8 *pdesc_tx,
u8 *pbd_desc_tx, struct ieee80211_tx_info *info,
struct ieee80211_sta *sta,
struct sk_buff *skb,
u8 queue_index,
struct rtl_tcb_desc *tcb_desc)
{
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
struct rtl_mac *mac = rtl_mac(rtlpriv);
struct rtl_sta_info *sta_entry;
__le16 fc = hdr->frame_control;
u8 agg_state = RTL_AGG_STOP;
u16 pktlen = skb->len;
u32 rts_en, hw_rts_en;
u8 ampdu_density = 0;
u16 seq_number;
__le32 *txdesc;
u8 rate_flag;
u8 tid;
rtl_get_tcb_desc(hw, info, sta, skb, tcb_desc);
txdesc = (__le32 *)skb_push(skb, RTL_TX_HEADER_SIZE);
memset(txdesc, 0, RTL_TX_HEADER_SIZE);
set_tx_desc_pkt_size(txdesc, pktlen);
set_tx_desc_linip(txdesc, 0);
set_tx_desc_pkt_offset(txdesc, RTL_DUMMY_OFFSET);
set_tx_desc_offset(txdesc, RTL_TX_HEADER_SIZE);
/* 5G have no CCK rate */
if (rtlhal->current_bandtype == BAND_ON_5G)
if (tcb_desc->hw_rate < DESC_RATE6M)
tcb_desc->hw_rate = DESC_RATE6M;
set_tx_desc_tx_rate(txdesc, tcb_desc->hw_rate);
if (tcb_desc->use_shortgi || tcb_desc->use_shortpreamble)
set_tx_desc_data_shortgi(txdesc, 1);
if (rtlhal->macphymode == DUALMAC_DUALPHY &&
tcb_desc->hw_rate == DESC_RATEMCS7)
set_tx_desc_data_shortgi(txdesc, 1);
if (sta) {
sta_entry = (struct rtl_sta_info *)sta->drv_priv;
tid = ieee80211_get_tid(hdr);
agg_state = sta_entry->tids[tid].agg.agg_state;
ampdu_density = sta->deflink.ht_cap.ampdu_density;
}
if (agg_state == RTL_AGG_OPERATIONAL &&
info->flags & IEEE80211_TX_CTL_AMPDU) {
set_tx_desc_agg_enable(txdesc, 1);
set_tx_desc_max_agg_num(txdesc, 0x14);
set_tx_desc_ampdu_density(txdesc, ampdu_density);
tcb_desc->rts_enable = 1;
tcb_desc->rts_rate = DESC_RATE24M;
} else {
set_tx_desc_agg_break(txdesc, 1);
}
seq_number = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
set_tx_desc_seq(txdesc, seq_number);
rts_en = tcb_desc->rts_enable && !tcb_desc->cts_enable;
hw_rts_en = tcb_desc->rts_enable || tcb_desc->cts_enable;
set_tx_desc_rts_enable(txdesc, rts_en);
set_tx_desc_hw_rts_enable(txdesc, hw_rts_en);
set_tx_desc_cts2self(txdesc, tcb_desc->cts_enable);
set_tx_desc_rts_stbc(txdesc, tcb_desc->rts_stbc);
/* 5G have no CCK rate */
if (rtlhal->current_bandtype == BAND_ON_5G)
if (tcb_desc->rts_rate < DESC_RATE6M)
tcb_desc->rts_rate = DESC_RATE6M;
set_tx_desc_rts_rate(txdesc, tcb_desc->rts_rate);
set_tx_desc_rts_bw(txdesc, 0);
set_tx_desc_rts_sc(txdesc, tcb_desc->rts_sc);
set_tx_desc_rts_short(txdesc, tcb_desc->rts_use_shortpreamble);
rate_flag = info->control.rates[0].flags;
if (mac->bw_40) {
if (rate_flag & IEEE80211_TX_RC_DUP_DATA) {
set_tx_desc_data_bw(txdesc, 1);
set_tx_desc_tx_sub_carrier(txdesc, 3);
} else if (rate_flag & IEEE80211_TX_RC_40_MHZ_WIDTH) {
set_tx_desc_data_bw(txdesc, 1);
set_tx_desc_tx_sub_carrier(txdesc, mac->cur_40_prime_sc);
} else {
set_tx_desc_data_bw(txdesc, 0);
set_tx_desc_tx_sub_carrier(txdesc, 0);
}
} else {
set_tx_desc_data_bw(txdesc, 0);
set_tx_desc_tx_sub_carrier(txdesc, 0);
}
if (info->control.hw_key) {
struct ieee80211_key_conf *keyconf = info->control.hw_key;
switch (keyconf->cipher) {
case WLAN_CIPHER_SUITE_WEP40:
case WLAN_CIPHER_SUITE_WEP104:
case WLAN_CIPHER_SUITE_TKIP:
set_tx_desc_sec_type(txdesc, 0x1);
break;
case WLAN_CIPHER_SUITE_CCMP:
set_tx_desc_sec_type(txdesc, 0x3);
break;
default:
set_tx_desc_sec_type(txdesc, 0x0);
break;
}
}
set_tx_desc_pkt_id(txdesc, 0);
set_tx_desc_queue_sel(txdesc, _rtl92du_hwq_to_descq(queue_index));
set_tx_desc_data_rate_fb_limit(txdesc, 0x1F);
set_tx_desc_rts_rate_fb_limit(txdesc, 0xF);
set_tx_desc_disable_fb(txdesc, 0);
set_tx_desc_use_rate(txdesc, tcb_desc->use_driver_rate);
if (ieee80211_is_data_qos(fc)) {
if (mac->rdg_en) {
rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
"Enable RDG function\n");
set_tx_desc_rdg_enable(txdesc, 1);
set_tx_desc_htc(txdesc, 1);
}
set_tx_desc_qos(txdesc, 1);
}
if (rtlpriv->dm.useramask) {
set_tx_desc_rate_id(txdesc, tcb_desc->ratr_index);
set_tx_desc_macid(txdesc, tcb_desc->mac_id);
} else {
set_tx_desc_rate_id(txdesc, 0xC + tcb_desc->ratr_index);
set_tx_desc_macid(txdesc, tcb_desc->ratr_index);
}
if (!ieee80211_is_data_qos(fc) && ppsc->leisure_ps &&
ppsc->fwctrl_lps) {
set_tx_desc_hwseq_en(txdesc, 1);
set_tx_desc_pkt_id(txdesc, 8);
}
if (ieee80211_has_morefrags(fc))
set_tx_desc_more_frag(txdesc, 1);
if (is_multicast_ether_addr(ieee80211_get_DA(hdr)) ||
is_broadcast_ether_addr(ieee80211_get_DA(hdr)))
set_tx_desc_bmc(txdesc, 1);
set_tx_desc_own(txdesc, 1);
set_tx_desc_last_seg(txdesc, 1);
set_tx_desc_first_seg(txdesc, 1);
_rtl92du_tx_desc_checksum(txdesc);
rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, "==>\n");
}
static void _rtl92du_config_out_ep(struct ieee80211_hw *hw, u8 num_out_pipe)
{
struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
u16 ep_cfg;
rtlusb->out_queue_sel = 0;
rtlusb->out_ep_nums = 0;
if (rtlhal->interfaceindex == 0)
ep_cfg = rtl_read_word(rtlpriv, REG_USB_Queue_Select_MAC0);
else
ep_cfg = rtl_read_word(rtlpriv, REG_USB_Queue_Select_MAC1);
if (ep_cfg & 0x00f) {
rtlusb->out_queue_sel |= TX_SELE_HQ;
rtlusb->out_ep_nums++;
}
if (ep_cfg & 0x0f0) {
rtlusb->out_queue_sel |= TX_SELE_NQ;
rtlusb->out_ep_nums++;
}
if (ep_cfg & 0xf00) {
rtlusb->out_queue_sel |= TX_SELE_LQ;
rtlusb->out_ep_nums++;
}
switch (num_out_pipe) {
case 3:
rtlusb->out_queue_sel = TX_SELE_HQ | TX_SELE_NQ | TX_SELE_LQ;
rtlusb->out_ep_nums = 3;
break;
case 2:
rtlusb->out_queue_sel = TX_SELE_HQ | TX_SELE_NQ;
rtlusb->out_ep_nums = 2;
break;
case 1:
rtlusb->out_queue_sel = TX_SELE_HQ;
rtlusb->out_ep_nums = 1;
break;
default:
break;
}
}
static void _rtl92du_one_out_ep_mapping(struct rtl_usb *rtlusb,
struct rtl_ep_map *ep_map)
{
ep_map->ep_mapping[RTL_TXQ_BE] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_BK] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_VI] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_VO] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_HI] = rtlusb->out_eps[0];
}
static void _rtl92du_two_out_ep_mapping(struct rtl_usb *rtlusb,
struct rtl_ep_map *ep_map)
{
ep_map->ep_mapping[RTL_TXQ_BE] = rtlusb->out_eps[1];
ep_map->ep_mapping[RTL_TXQ_BK] = rtlusb->out_eps[1];
ep_map->ep_mapping[RTL_TXQ_VI] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_VO] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_HI] = rtlusb->out_eps[0];
}
static void _rtl92du_three_out_ep_mapping(struct rtl_usb *rtlusb,
struct rtl_ep_map *ep_map)
{
ep_map->ep_mapping[RTL_TXQ_BE] = rtlusb->out_eps[2];
ep_map->ep_mapping[RTL_TXQ_BK] = rtlusb->out_eps[2];
ep_map->ep_mapping[RTL_TXQ_VI] = rtlusb->out_eps[1];
ep_map->ep_mapping[RTL_TXQ_VO] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
ep_map->ep_mapping[RTL_TXQ_HI] = rtlusb->out_eps[0];
}
static int _rtl92du_out_ep_mapping(struct ieee80211_hw *hw)
{
struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
struct rtl_ep_map *ep_map = &rtlusb->ep_map;
switch (rtlusb->out_ep_nums) {
case 1:
_rtl92du_one_out_ep_mapping(rtlusb, ep_map);
break;
case 2:
_rtl92du_two_out_ep_mapping(rtlusb, ep_map);
break;
case 3:
_rtl92du_three_out_ep_mapping(rtlusb, ep_map);
break;
default:
return -EINVAL;
}
return 0;
}
int rtl92du_endpoint_mapping(struct ieee80211_hw *hw)
{
struct rtl_usb *rtlusb = rtl_usbdev(rtl_usbpriv(hw));
_rtl92du_config_out_ep(hw, rtlusb->out_ep_nums);
/* Normal chip with one IN and one OUT doesn't have interrupt IN EP. */
if (rtlusb->out_ep_nums == 1 && rtlusb->in_ep_nums != 1)
return -EINVAL;
return _rtl92du_out_ep_mapping(hw);
}
u16 rtl92du_mq_to_hwq(__le16 fc, u16 mac80211_queue_index)
{
u16 hw_queue_index;
if (unlikely(ieee80211_is_beacon(fc))) {
hw_queue_index = RTL_TXQ_BCN;
goto out;
}
if (ieee80211_is_mgmt(fc)) {
hw_queue_index = RTL_TXQ_MGT;
goto out;
}
switch (mac80211_queue_index) {
case 0:
hw_queue_index = RTL_TXQ_VO;
break;
case 1:
hw_queue_index = RTL_TXQ_VI;
break;
case 2:
hw_queue_index = RTL_TXQ_BE;
break;
case 3:
hw_queue_index = RTL_TXQ_BK;
break;
default:
hw_queue_index = RTL_TXQ_BE;
WARN_ONCE(true, "rtl8192du: QSLT_BE queue, skb_queue:%d\n",
mac80211_queue_index);
break;
}
out:
return hw_queue_index;
}
|