Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/hal/rtl8814a/usb/rtl8814au_xmit.c
1308 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2007 - 2017 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
*****************************************************************************/
15
#define _RTL8814AU_XMIT_C_
16
17
/* #include <drv_types.h> */
18
#include <rtl8814a_hal.h>
19
20
21
s32 rtl8814au_init_xmit_priv(_adapter *padapter)
22
{
23
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
24
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
25
26
#ifdef PLATFORM_LINUX
27
tasklet_init(&pxmitpriv->xmit_tasklet,
28
(void(*))rtl8814au_xmit_tasklet,
29
(unsigned long)padapter);
30
#endif
31
#ifdef CONFIG_TX_EARLY_MODE
32
pHalData->bEarlyModeEnable = padapter->registrypriv.early_mode;
33
#endif
34
35
return _SUCCESS;
36
}
37
38
void rtl8814au_free_xmit_priv(_adapter *padapter)
39
{
40
}
41
42
static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz , u8 bagg_pkt)
43
{
44
int pull = 0;
45
uint qsel;
46
u8 data_rate, pwr_status, offset;
47
_adapter *padapter = pxmitframe->padapter;
48
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
49
struct pkt_attrib *pattrib = &pxmitframe->attrib;
50
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
51
u8 *ptxdesc = pmem;
52
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
53
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
54
sint bmcst = IS_MCAST(pattrib->ra);
55
u16 SWDefineContent = 0x0;
56
u8 DriverFixedRate = 0x0;
57
58
#ifndef CONFIG_USE_USB_BUFFER_ALLOC_TX
59
if (padapter->registrypriv.mp_mode == 0) {
60
if ((PACKET_OFFSET_SZ != 0) && (!bagg_pkt) && (rtw_usb_bulk_size_boundary(padapter, TXDESC_SIZE + sz) == _FALSE)) {
61
ptxdesc = (pmem + PACKET_OFFSET_SZ);
62
/* RTW_INFO("==> non-agg-pkt,shift pointer...\n"); */
63
pull = 1;
64
}
65
}
66
#endif /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
67
68
_rtw_memset(ptxdesc, 0, TXDESC_SIZE);
69
70
/* 4 offset 0 */
71
/* SET_TX_DESC_FIRST_SEG_8812(ptxdesc, 1); */
72
SET_TX_DESC_LAST_SEG_8814A(ptxdesc, 1);
73
/* SET_TX_DESC_OWN_8812(ptxdesc, 1); */
74
75
/* RTW_INFO("%s==> pkt_len=%d,bagg_pkt=%02x\n",__FUNCTION__,sz,bagg_pkt); */
76
SET_TX_DESC_PKT_SIZE_8814A(ptxdesc, sz);
77
78
offset = TXDESC_SIZE + OFFSET_SZ;
79
80
#ifdef CONFIG_TX_EARLY_MODE
81
if (bagg_pkt) {
82
offset += EARLY_MODE_INFO_SIZE ;/* 0x28 */
83
}
84
#endif
85
/* RTW_INFO("%s==>offset(0x%02x)\n",__FUNCTION__,offset); */
86
SET_TX_DESC_OFFSET_8814A(ptxdesc, offset);
87
88
if (bmcst)
89
SET_TX_DESC_BMC_8814A(ptxdesc, 1);
90
91
#ifndef CONFIG_USE_USB_BUFFER_ALLOC_TX
92
if (padapter->registrypriv.mp_mode == 0) {
93
if ((PACKET_OFFSET_SZ != 0) && (!bagg_pkt)) {
94
if ((pull) && (pxmitframe->pkt_offset > 0))
95
pxmitframe->pkt_offset = pxmitframe->pkt_offset - 1;
96
}
97
}
98
#endif
99
100
/* RTW_INFO("%s, pkt_offset=0x%02x\n",__FUNCTION__,pxmitframe->pkt_offset); */
101
/* pkt_offset, unit:8 bytes padding */
102
if (pxmitframe->pkt_offset > 0)
103
SET_TX_DESC_PKT_OFFSET_8814A(ptxdesc, pxmitframe->pkt_offset);
104
105
SET_TX_DESC_MACID_8814A(ptxdesc, pattrib->mac_id);
106
SET_TX_DESC_RATE_ID_8814A(ptxdesc, pattrib->raid);
107
108
SET_TX_DESC_QUEUE_SEL_8814A(ptxdesc, pattrib->qsel);
109
110
/* offset 12 */
111
112
if (!pattrib->qos_en) {
113
/* HW sequence, to fix to use 0 queue. todo: 4AC packets to use auto queue select */
114
SET_TX_DESC_HWSEQ_EN_8814A(ptxdesc, 1); /* Hw set sequence number */
115
SET_TX_DESC_EN_HWEXSEQ_8814A(ptxdesc, 0);
116
SET_TX_DESC_DISQSELSEQ_8814A(ptxdesc, 1);
117
SET_TX_DESC_HW_SSN_SEL_8814A(ptxdesc, 0);
118
} else {
119
SET_TX_DESC_SEQ_8814A(ptxdesc, pattrib->seqnum);
120
}
121
if ((pxmitframe->frame_tag & 0x0f) == DATA_FRAMETAG) {
122
/* RTW_INFO("pxmitframe->frame_tag == DATA_FRAMETAG\n"); */
123
124
rtl8814a_fill_txdesc_sectype(pattrib, ptxdesc);
125
#if defined(CONFIG_CONCURRENT_MODE)
126
if (bmcst)
127
fill_txdesc_force_bmc_camid(pattrib, ptxdesc);
128
#endif
129
130
/* offset 20 */
131
#ifdef CONFIG_USB_TX_AGGREGATION
132
if (pxmitframe->agg_num > 1) {
133
/* RTW_INFO("%s agg_num:%d\n",__FUNCTION__,pxmitframe->agg_num ); */
134
SET_TX_DESC_USB_TXAGG_NUM_8814A(ptxdesc, pxmitframe->agg_num);
135
}
136
#endif /* CONFIG_USB_TX_AGGREGATION */
137
138
rtl8814a_fill_txdesc_vcs(padapter, pattrib, ptxdesc);
139
140
if ((pattrib->ether_type != 0x888e) &&
141
(pattrib->ether_type != 0x0806) &&
142
(pattrib->ether_type != 0x88b4) &&
143
(pattrib->dhcp_pkt != 1)
144
#ifdef CONFIG_AUTO_AP_MODE
145
&& (pattrib->pctrl != _TRUE)
146
#endif
147
) {
148
/* Non EAP & ARP & DHCP type data packet */
149
150
if (pattrib->ampdu_en == _TRUE) {
151
SET_TX_DESC_AGG_ENABLE_8814A(ptxdesc, 1);
152
SET_TX_DESC_MAX_AGG_NUM_8814A(ptxdesc, 0x1f);
153
/* Set A-MPDU aggregation. */
154
SET_TX_DESC_AMPDU_DENSITY_8814A(ptxdesc, pattrib->ampdu_spacing);
155
} else
156
SET_TX_DESC_BK_8814A(ptxdesc, 1);
157
158
rtl8814a_fill_txdesc_phy(padapter, pattrib, ptxdesc);
159
160
/* compatibility for MCC consideration, use pmlmeext->cur_channel */
161
if (pmlmeext->cur_channel > 14)
162
/* for 5G. OFMD 6M */
163
SET_TX_DESC_DATA_RATE_FB_LIMIT_8814A(ptxdesc, 4);
164
else
165
/* for 2.4G CCK 1M */
166
SET_TX_DESC_DATA_RATE_FB_LIMIT_8814A(ptxdesc, 0);
167
168
if (pHalData->fw_ractrl == _FALSE) {
169
SET_TX_DESC_USE_RATE_8814A(ptxdesc, 1);
170
DriverFixedRate = 0x01;
171
172
if (pHalData->INIDATA_RATE[pattrib->mac_id] & BIT(7))
173
SET_TX_DESC_DATA_SHORT_8814A(ptxdesc, 1);
174
175
SET_TX_DESC_TX_RATE_8814A(ptxdesc, (pHalData->INIDATA_RATE[pattrib->mac_id] & 0x7F));
176
}
177
if (bmcst) {
178
DriverFixedRate = 0x01;
179
fill_txdesc_bmc_tx_rate(pattrib, ptxdesc);
180
}
181
182
if (padapter->fix_rate != 0xFF) { /* modify data rate by iwpriv */
183
SET_TX_DESC_USE_RATE_8814A(ptxdesc, 1);
184
DriverFixedRate = 0x01;
185
if (padapter->fix_rate & BIT(7))
186
SET_TX_DESC_DATA_SHORT_8814A(ptxdesc, 1);
187
188
SET_TX_DESC_TX_RATE_8814A(ptxdesc, (padapter->fix_rate & 0x7F));
189
if (!padapter->data_fb)
190
SET_TX_DESC_DISABLE_FB_8814A(ptxdesc, 1);
191
}
192
193
if (pattrib->ldpc)
194
SET_TX_DESC_DATA_LDPC_8814A(ptxdesc, 1);
195
if (pattrib->stbc)
196
SET_TX_DESC_DATA_STBC_8814A(ptxdesc, 1);
197
198
/* work arond before fixing RA */
199
/* SET_TX_DESC_USE_RATE_8814A(ptxdesc, 1); */
200
/* SET_TX_DESC_TX_RATE_8814A(ptxdesc, 0x10); */
201
} else {
202
/* EAP data packet and ARP packet and DHCP. */
203
/* Use the 1M data rate to send the EAP/ARP packet. */
204
/* This will maybe make the handshake smooth. */
205
206
SET_TX_DESC_USE_RATE_8814A(ptxdesc, 1);
207
DriverFixedRate = 0x01;
208
SET_TX_DESC_BK_8814A(ptxdesc, 1);
209
210
/* HW will ignore this setting if the transmission rate is legacy OFDM. */
211
if (pmlmeinfo->preamble_mode == PREAMBLE_SHORT)
212
SET_TX_DESC_DATA_SHORT_8814A(ptxdesc, 1);
213
#ifdef CONFIG_IP_R_MONITOR
214
if((pattrib->ether_type == ETH_P_ARP) &&
215
(IsSupportedTxOFDM(padapter->registrypriv.wireless_mode))) {
216
SET_TX_DESC_TX_RATE_8814A(ptxdesc, MRateToHwRate(IEEE80211_OFDM_RATE_6MB));
217
#ifdef DBG_IP_R_MONITOR
218
RTW_INFO(FUNC_ADPT_FMT ": SP Packet(0x%04X) rate=0x%x SeqNum = %d\n",
219
FUNC_ADPT_ARG(padapter), pattrib->ether_type, MRateToHwRate(pmlmeext->tx_rate), pattrib->seqnum);
220
#endif/*DBG_IP_R_MONITOR*/
221
} else
222
#endif/*CONFIG_IP_R_MONITOR*/
223
SET_TX_DESC_TX_RATE_8814A(ptxdesc, MRateToHwRate(pmlmeext->tx_rate));
224
}
225
226
} else if ((pxmitframe->frame_tag & 0x0f) == MGNT_FRAMETAG) {
227
/* RTW_INFO("pxmitframe->frame_tag == MGNT_FRAMETAG\n"); */
228
229
SET_TX_DESC_USE_RATE_8814A(ptxdesc, 1);
230
DriverFixedRate = 0x01;
231
232
SET_TX_DESC_TX_RATE_8814A(ptxdesc, MRateToHwRate(pattrib->rate));
233
234
/* VHT NDPA or HT NDPA Packet for Beamformer. */
235
236
#ifdef CONFIG_BEAMFORMING
237
if ((pattrib->subtype == WIFI_NDPA) ||
238
((pattrib->subtype == WIFI_ACTION_NOACK) && (pattrib->order == 1))) {
239
SET_TX_DESC_NAV_USE_HDR_8814A(ptxdesc, 1);
240
241
SET_TX_DESC_DATA_BW_8814A(ptxdesc, BWMapping_8814(padapter, pattrib));
242
SET_TX_DESC_RTS_SC_8814A(ptxdesc, SCMapping_8814(padapter, pattrib));
243
244
SET_TX_DESC_RETRY_LIMIT_ENABLE_8814A(ptxdesc, 1);
245
SET_TX_DESC_DATA_RETRY_LIMIT_8814A(ptxdesc, 5);
246
SET_TX_DESC_DISABLE_FB_8814A(ptxdesc, 1);
247
248
/* if(pattrib->rts_cca) */
249
/* { */
250
/* SET_TX_DESC_NDPA_8812(ptxdesc, 2); */
251
/* } */
252
/* else */
253
{
254
SET_TX_DESC_NDPA_8814A(ptxdesc, 1);
255
}
256
} else
257
#endif
258
{
259
SET_TX_DESC_RETRY_LIMIT_ENABLE_8814A(ptxdesc, 1);
260
if (pattrib->retry_ctrl == _TRUE)
261
SET_TX_DESC_DATA_RETRY_LIMIT_8814A(ptxdesc, 6);
262
else
263
SET_TX_DESC_DATA_RETRY_LIMIT_8814A(ptxdesc, 12);
264
}
265
266
#ifdef CONFIG_XMIT_ACK
267
/* CCX-TXRPT ack for xmit mgmt frames. */
268
if (pxmitframe->ack_report) {
269
SET_TX_DESC_SPE_RPT_8814A(ptxdesc, 1);
270
#ifdef DBG_CCX
271
RTW_INFO("%s set tx report\n", __func__);
272
#endif
273
}
274
#endif /* CONFIG_XMIT_ACK */
275
} else if ((pxmitframe->frame_tag & 0x0f) == TXAGG_FRAMETAG)
276
RTW_INFO("pxmitframe->frame_tag == TXAGG_FRAMETAG\n");
277
#ifdef CONFIG_MP_INCLUDED
278
else if (((pxmitframe->frame_tag & 0x0f) == MP_FRAMETAG) &&
279
(padapter->registrypriv.mp_mode == 1))
280
fill_txdesc_for_mp(padapter, ptxdesc);
281
#endif
282
else {
283
RTW_INFO("pxmitframe->frame_tag = %d\n", pxmitframe->frame_tag);
284
285
SET_TX_DESC_USE_RATE_8814A(ptxdesc, 1);
286
DriverFixedRate = 0x01;
287
SET_TX_DESC_TX_RATE_8814A(ptxdesc, MRateToHwRate(pmlmeext->tx_rate));
288
}
289
if (DriverFixedRate)
290
SWDefineContent |= 0x01;
291
SET_TX_DESC_SW_DEFINE_8814A(ptxdesc, SWDefineContent);
292
293
#ifdef CONFIG_ANTENNA_DIVERSITY
294
if (!bmcst && pattrib->psta)
295
odm_set_tx_ant_by_tx_info(adapter_to_phydm(padapter), ptxdesc, pattrib->psta->cmn.mac_id);
296
#endif
297
298
#ifdef CONFIG_BEAMFORMING
299
SET_TX_DESC_GID_8814A(ptxdesc, pattrib->txbf_g_id);
300
SET_TX_DESC_PAID_8814A(ptxdesc, pattrib->txbf_p_aid);
301
#endif
302
rtl8814a_cal_txdesc_chksum(ptxdesc);
303
_dbg_dump_tx_info(padapter, pxmitframe->frame_tag, ptxdesc);
304
return pull;
305
}
306
307
308
#ifdef CONFIG_XMIT_THREAD_MODE
309
/*
310
* Description
311
* Transmit xmitbuf to hardware tx fifo
312
*
313
* Return
314
* _SUCCESS ok
315
* _FAIL something error
316
*/
317
s32 rtl8814au_xmit_buf_handler(PADAPTER padapter)
318
{
319
PHAL_DATA_TYPE phal;
320
struct xmit_priv *pxmitpriv;
321
struct xmit_buf *pxmitbuf;
322
struct xmit_frame *pxmitframe;
323
s32 ret;
324
325
326
phal = GET_HAL_DATA(padapter);
327
pxmitpriv = &padapter->xmitpriv;
328
329
ret = _rtw_down_sema(&pxmitpriv->xmit_sema);
330
if (_FAIL == ret) {
331
return _FAIL;
332
}
333
334
if (RTW_CANNOT_RUN(padapter)) {
335
return _FAIL;
336
}
337
338
if (rtw_mi_check_pending_xmitbuf(padapter) == 0)
339
return _SUCCESS;
340
341
#ifdef CONFIG_LPS_LCLK
342
ret = rtw_register_tx_alive(padapter);
343
if (ret != _SUCCESS) {
344
return _SUCCESS;
345
}
346
#endif /* CONFIG_LPS_LCLK */
347
348
do {
349
pxmitbuf = dequeue_pending_xmitbuf(pxmitpriv);
350
if (pxmitbuf == NULL)
351
break;
352
353
pxmitframe = (struct xmit_frame *) pxmitbuf->priv_data;
354
rtw_write_port(padapter, pxmitbuf->ff_hwaddr, pxmitbuf->len, (unsigned char *)pxmitbuf);
355
rtw_free_xmitframe(pxmitpriv, pxmitframe);
356
357
} while (1);
358
359
#ifdef CONFIG_LPS_LCLK
360
rtw_unregister_tx_alive(padapter);
361
#endif /* CONFIG_LPS_LCLK */
362
363
return _SUCCESS;
364
}
365
#endif /* CONFIG_XMIT_THREAD_MODE */
366
367
368
/* for non-agg data frame or management frame */
369
static s32 rtw_dump_xframe(_adapter *padapter, struct xmit_frame *pxmitframe)
370
{
371
s32 ret = _SUCCESS;
372
s32 inner_ret = _SUCCESS;
373
int t, sz, w_sz, pull = 0;
374
u8 *mem_addr;
375
u32 ff_hwaddr;
376
struct xmit_buf *pxmitbuf = pxmitframe->pxmitbuf;
377
struct pkt_attrib *pattrib = &pxmitframe->attrib;
378
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
379
struct security_priv *psecuritypriv = &padapter->securitypriv;
380
#ifdef CONFIG_80211N_HT
381
if ((pxmitframe->frame_tag == DATA_FRAMETAG) &&
382
(pxmitframe->attrib.ether_type != 0x0806) &&
383
(pxmitframe->attrib.ether_type != 0x888e) &&
384
(pxmitframe->attrib.ether_type != 0x88b4) &&
385
(pxmitframe->attrib.dhcp_pkt != 1))
386
rtw_issue_addbareq_cmd(padapter, pxmitframe);
387
#endif /* CONFIG_80211N_HT */
388
mem_addr = pxmitframe->buf_addr;
389
390
/* RTW_INFO("rtw_dump_xframe()\n"); */
391
392
for (t = 0; t < pattrib->nr_frags; t++) {
393
if (inner_ret != _SUCCESS && ret == _SUCCESS)
394
ret = _FAIL;
395
396
if (t != (pattrib->nr_frags - 1)) {
397
398
sz = pxmitpriv->frag_len;
399
sz = sz - 4 - (psecuritypriv->sw_encrypt ? 0 : pattrib->icv_len);
400
} else /* no frag */
401
sz = pattrib->last_txcmdsz;
402
403
pull = update_txdesc(pxmitframe, mem_addr, sz, _FALSE);
404
405
if (pull) {
406
mem_addr += PACKET_OFFSET_SZ; /* pull txdesc head */
407
408
/* pxmitbuf->pbuf = mem_addr; */
409
pxmitframe->buf_addr = mem_addr;
410
411
w_sz = sz + TXDESC_SIZE;
412
} else
413
w_sz = sz + TXDESC_SIZE + PACKET_OFFSET_SZ;
414
415
ff_hwaddr = rtw_get_ff_hwaddr(pxmitframe);
416
417
#ifdef CONFIG_XMIT_THREAD_MODE
418
pxmitbuf->len = w_sz;
419
pxmitbuf->ff_hwaddr = ff_hwaddr;
420
421
if (pxmitframe->attrib.qsel == QSLT_BEACON)
422
/* download rsvd page*/
423
rtw_write_port(padapter, ff_hwaddr, w_sz, (u8 *)pxmitbuf);
424
else
425
enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf);
426
#else
427
inner_ret = rtw_write_port(padapter, ff_hwaddr, w_sz, (unsigned char *)pxmitbuf);
428
#endif
429
rtw_count_tx_stats(padapter, pxmitframe, sz);
430
431
/* RTW_INFO("rtw_write_port, w_sz=%d\n", w_sz); */
432
/* RTW_INFO("rtw_write_port, w_sz=%d, sz=%d, txdesc_sz=%d, tid=%d\n", w_sz, sz, w_sz-sz, pattrib->priority); */
433
434
mem_addr += w_sz;
435
436
mem_addr = (u8 *)RND4(((SIZE_PTR)(mem_addr)));
437
438
}
439
440
#ifdef CONFIG_XMIT_THREAD_MODE
441
if (pxmitframe->attrib.qsel == QSLT_BEACON)
442
#endif
443
rtw_free_xmitframe(pxmitpriv, pxmitframe);
444
445
if (ret != _SUCCESS)
446
rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_UNKNOWN);
447
448
return ret;
449
}
450
451
#ifdef CONFIG_USB_TX_AGGREGATION
452
#define IDEA_CONDITION 1 /* check all packets before enqueue */
453
s32 rtl8814au_xmitframe_complete(_adapter *padapter, struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
454
{
455
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
456
struct xmit_frame *pxmitframe = NULL;
457
struct xmit_frame *pfirstframe = NULL;
458
459
/* aggregate variable */
460
struct hw_xmit *phwxmit;
461
struct sta_info *psta = NULL;
462
struct tx_servq *ptxservq = NULL;
463
464
_irqL irqL;
465
_list *xmitframe_plist = NULL, *xmitframe_phead = NULL;
466
467
u32 pbuf; /* next pkt address */
468
u32 pbuf_tail; /* last pkt tail */
469
u32 len; /* packet length, except TXDESC_SIZE and PKT_OFFSET */
470
471
u32 bulkSize = pHalData->UsbBulkOutSize;
472
u8 descCount;
473
u32 bulkPtr;
474
475
/* dump frame variable */
476
u32 ff_hwaddr;
477
478
_list *sta_plist, *sta_phead;
479
u8 single_sta_in_queue = _FALSE;
480
481
#ifndef IDEA_CONDITION
482
int res = _SUCCESS;
483
#endif
484
485
486
487
/* check xmitbuffer is ok */
488
if (pxmitbuf == NULL) {
489
pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
490
if (pxmitbuf == NULL) {
491
/* RTW_INFO("%s #1, connot alloc xmitbuf!!!!\n",__FUNCTION__); */
492
return _FALSE;
493
}
494
}
495
496
/* RTW_INFO("%s =====================================\n",__FUNCTION__); */
497
/* 3 1. pick up first frame */
498
do {
499
rtw_free_xmitframe(pxmitpriv, pxmitframe);
500
501
pxmitframe = rtw_dequeue_xframe(pxmitpriv, pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
502
if (pxmitframe == NULL) {
503
/* no more xmit frame, release xmit buffer */
504
/* RTW_INFO("no more xmit frame ,return\n"); */
505
rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
506
return _FALSE;
507
}
508
509
#ifndef IDEA_CONDITION
510
if (pxmitframe->frame_tag != DATA_FRAMETAG) {
511
/* rtw_free_xmitframe(pxmitpriv, pxmitframe); */
512
continue;
513
}
514
515
/* TID 0~15 */
516
if ((pxmitframe->attrib.priority < 0) ||
517
(pxmitframe->attrib.priority > 15)) {
518
/* rtw_free_xmitframe(pxmitpriv, pxmitframe); */
519
continue;
520
}
521
#endif
522
/* RTW_INFO("==> pxmitframe->attrib.priority:%d\n",pxmitframe->attrib.priority); */
523
pxmitframe->pxmitbuf = pxmitbuf;
524
pxmitframe->buf_addr = pxmitbuf->pbuf;
525
pxmitbuf->priv_data = pxmitframe;
526
527
pxmitframe->agg_num = 1; /* alloc xmitframe should assign to 1. */
528
#ifdef CONFIG_TX_EARLY_MODE
529
pxmitframe->pkt_offset = (PACKET_OFFSET_SZ / 8) + 1; /* 2; */ /* first frame of aggregation, reserve one offset for EM info ,another for usb bulk-out block check */
530
#else
531
pxmitframe->pkt_offset = (PACKET_OFFSET_SZ / 8); /* 1; */ /* first frame of aggregation, reserve offset */
532
#endif
533
534
if (rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe) == _FALSE) {
535
RTW_INFO("%s coalesce 1st xmitframe failed\n", __FUNCTION__);
536
continue;
537
}
538
539
540
/* always return ndis_packet after rtw_xmitframe_coalesce */
541
rtw_os_xmit_complete(padapter, pxmitframe);
542
543
break;
544
} while (1);
545
546
/* 3 2. aggregate same priority and same DA(AP or STA) frames */
547
pfirstframe = pxmitframe;
548
len = rtw_wlan_pkt_size(pfirstframe) + TXDESC_SIZE + (pfirstframe->pkt_offset * PACKET_OFFSET_SZ);
549
pbuf_tail = len;
550
pbuf = _RND8(pbuf_tail);
551
552
/* check pkt amount in one bulk */
553
descCount = 0;
554
bulkPtr = bulkSize;
555
if (pbuf < bulkPtr)
556
descCount++;
557
if (descCount == pHalData->UsbTxAggDescNum)
558
goto agg_end;
559
else {
560
descCount = 0;
561
bulkPtr = ((pbuf / bulkSize) + 1) * bulkSize; /* round to next bulkSize */
562
}
563
564
/* dequeue same priority packet from station tx queue */
565
psta = pfirstframe->attrib.psta;
566
switch (pfirstframe->attrib.priority) {
567
case 1:
568
case 2:
569
ptxservq = &(psta->sta_xmitpriv.bk_q);
570
phwxmit = pxmitpriv->hwxmits + 3;
571
break;
572
573
case 4:
574
case 5:
575
ptxservq = &(psta->sta_xmitpriv.vi_q);
576
phwxmit = pxmitpriv->hwxmits + 1;
577
break;
578
579
case 6:
580
case 7:
581
ptxservq = &(psta->sta_xmitpriv.vo_q);
582
phwxmit = pxmitpriv->hwxmits;
583
break;
584
585
case 0:
586
case 3:
587
default:
588
ptxservq = &(psta->sta_xmitpriv.be_q);
589
phwxmit = pxmitpriv->hwxmits + 2;
590
break;
591
}
592
/* RTW_INFO("==> pkt_no=%d,pkt_len=%d,len=%d,RND8_LEN=%d,pkt_offset=0x%02x\n", */
593
/* pxmitframe->agg_num,pxmitframe->attrib.last_txcmdsz,len,pbuf,pxmitframe->pkt_offset ); */
594
595
596
_enter_critical_bh(&pxmitpriv->lock, &irqL);
597
598
sta_phead = get_list_head(phwxmit->sta_queue);
599
sta_plist = get_next(sta_phead);
600
single_sta_in_queue = rtw_end_of_queue_search(sta_phead, get_next(sta_plist));
601
602
xmitframe_phead = get_list_head(&ptxservq->sta_pending);
603
xmitframe_plist = get_next(xmitframe_phead);
604
605
while (rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist) == _FALSE) {
606
pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
607
xmitframe_plist = get_next(xmitframe_plist);
608
609
if (_FAIL == rtw_hal_busagg_qsel_check(padapter, pfirstframe->attrib.qsel, pxmitframe->attrib.qsel))
610
break;
611
612
pxmitframe->agg_num = 0; /* not first frame of aggregation */
613
#ifdef CONFIG_TX_EARLY_MODE
614
pxmitframe->pkt_offset = 1;/* not first frame of aggregation,reserve offset for EM Info */
615
#else
616
pxmitframe->pkt_offset = 0; /* not first frame of aggregation, no need to reserve offset */
617
#endif
618
619
len = rtw_wlan_pkt_size(pxmitframe) + TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
620
621
if (_RND8(pbuf + len) > MAX_XMITBUF_SZ) {
622
/* RTW_INFO("%s....len> MAX_XMITBUF_SZ\n",__FUNCTION__); */
623
pxmitframe->agg_num = 1;
624
pxmitframe->pkt_offset = 1;
625
break;
626
}
627
rtw_list_delete(&pxmitframe->list);
628
ptxservq->qcnt--;
629
phwxmit->accnt--;
630
631
#ifndef IDEA_CONDITION
632
/* suppose only data frames would be in queue */
633
if (pxmitframe->frame_tag != DATA_FRAMETAG) {
634
rtw_free_xmitframe(pxmitpriv, pxmitframe);
635
continue;
636
}
637
638
/* TID 0~15 */
639
if ((pxmitframe->attrib.priority < 0) ||
640
(pxmitframe->attrib.priority > 15)) {
641
rtw_free_xmitframe(pxmitpriv, pxmitframe);
642
continue;
643
}
644
#endif
645
646
/* pxmitframe->pxmitbuf = pxmitbuf; */
647
pxmitframe->buf_addr = pxmitbuf->pbuf + pbuf;
648
649
if (rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe) == _FALSE) {
650
RTW_INFO("%s coalesce failed\n", __FUNCTION__);
651
rtw_free_xmitframe(pxmitpriv, pxmitframe);
652
continue;
653
}
654
655
/* RTW_INFO("==> pxmitframe->attrib.priority:%d\n",pxmitframe->attrib.priority); */
656
/* always return ndis_packet after rtw_xmitframe_coalesce */
657
rtw_os_xmit_complete(padapter, pxmitframe);
658
659
/* (len - TXDESC_SIZE) == pxmitframe->attrib.last_txcmdsz */
660
update_txdesc(pxmitframe, pxmitframe->buf_addr, pxmitframe->attrib.last_txcmdsz, _TRUE);
661
662
/* don't need xmitframe any more */
663
rtw_free_xmitframe(pxmitpriv, pxmitframe);
664
665
/* handle pointer and stop condition */
666
pbuf_tail = pbuf + len;
667
pbuf = _RND8(pbuf_tail);
668
669
670
pfirstframe->agg_num++;
671
#ifdef CONFIG_TX_EARLY_MODE
672
pxmitpriv->agg_pkt[pfirstframe->agg_num - 1].offset = _RND8(len);
673
pxmitpriv->agg_pkt[pfirstframe->agg_num - 1].pkt_len = pxmitframe->attrib.last_txcmdsz;
674
#endif
675
if (MAX_TX_AGG_PACKET_NUMBER == pfirstframe->agg_num)
676
break;
677
678
if (pbuf < bulkPtr) {
679
descCount++;
680
if (descCount == pHalData->UsbTxAggDescNum)
681
break;
682
} else {
683
descCount = 0;
684
bulkPtr = ((pbuf / bulkSize) + 1) * bulkSize;
685
}
686
} /* end while( aggregate same priority and same DA(AP or STA) frames) */
687
if (_rtw_queue_empty(&ptxservq->sta_pending) == _TRUE)
688
rtw_list_delete(&ptxservq->tx_pending);
689
else if (single_sta_in_queue == _FALSE) {
690
/* Re-arrange the order of stations in this ac queue to balance the service for these stations */
691
rtw_list_delete(&ptxservq->tx_pending);
692
rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(phwxmit->sta_queue));
693
}
694
695
_exit_critical_bh(&pxmitpriv->lock, &irqL);
696
agg_end:
697
#ifdef CONFIG_80211N_HT
698
if ((pfirstframe->attrib.ether_type != 0x0806) &&
699
(pfirstframe->attrib.ether_type != 0x888e) &&
700
(pfirstframe->attrib.ether_type != 0x88b4) &&
701
(pfirstframe->attrib.dhcp_pkt != 1))
702
rtw_issue_addbareq_cmd(padapter, pfirstframe);
703
#endif /* CONFIG_80211N_HT */
704
#ifndef CONFIG_USE_USB_BUFFER_ALLOC_TX
705
/* 3 3. update first frame txdesc */
706
if ((PACKET_OFFSET_SZ != 0) && ((pbuf_tail % bulkSize) == 0)) {
707
/* remove pkt_offset */
708
pbuf_tail -= PACKET_OFFSET_SZ;
709
pfirstframe->buf_addr += PACKET_OFFSET_SZ;
710
pfirstframe->pkt_offset--;
711
/* RTW_INFO("$$$$$ buf size equal to USB block size $$$$$$\n"); */
712
}
713
#endif /* CONFIG_USE_USB_BUFFER_ALLOC_TX */
714
715
update_txdesc(pfirstframe, pfirstframe->buf_addr, pfirstframe->attrib.last_txcmdsz, _TRUE);
716
717
#ifdef CONFIG_TX_EARLY_MODE
718
/* prepare EM info for first frame, agg_num value start from 1 */
719
pxmitpriv->agg_pkt[0].offset = _RND8(pfirstframe->attrib.last_txcmdsz + TXDESC_SIZE + (pfirstframe->pkt_offset * PACKET_OFFSET_SZ));
720
pxmitpriv->agg_pkt[0].pkt_len = pfirstframe->attrib.last_txcmdsz;/* get from rtw_xmitframe_coalesce */
721
722
UpdateEarlyModeInfo8812(pxmitpriv, pxmitbuf);
723
#endif
724
725
/* 3 4. write xmit buffer to USB FIFO */
726
ff_hwaddr = rtw_get_ff_hwaddr(pfirstframe);
727
/* RTW_INFO("%s ===================================== write port,buf_size(%d)\n",__FUNCTION__,pbuf_tail); */
728
/* xmit address == ((xmit_frame*)pxmitbuf->priv_data)->buf_addr */
729
730
#ifdef CONFIG_XMIT_THREAD_MODE
731
pxmitbuf->len = pbuf_tail;
732
pxmitbuf->ff_hwaddr = ff_hwaddr;
733
734
if (pfirstframe->attrib.qsel == QSLT_BEACON)
735
/* download rsvd page*/
736
rtw_write_port(padapter, ff_hwaddr, pbuf_tail, (u8 *)pxmitbuf);
737
else
738
enqueue_pending_xmitbuf(pxmitpriv, pxmitbuf);
739
#else
740
rtw_write_port(padapter, ff_hwaddr, pbuf_tail, (u8 *)pxmitbuf);
741
#endif
742
743
744
/* 3 5. update statisitc */
745
pbuf_tail -= (pfirstframe->agg_num * TXDESC_SIZE);
746
pbuf_tail -= (pfirstframe->pkt_offset * PACKET_OFFSET_SZ);
747
748
749
rtw_count_tx_stats(padapter, pfirstframe, pbuf_tail);
750
751
#ifdef CONFIG_XMIT_THREAD_MODE
752
if (pfirstframe->attrib.qsel == QSLT_BEACON)
753
#endif
754
rtw_free_xmitframe(pxmitpriv, pfirstframe);
755
756
return _TRUE;
757
}
758
759
#else /* CONFIG_USB_TX_AGGREGATION */
760
761
s32 rtl8814au_xmitframe_complete(_adapter *padapter, struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
762
{
763
764
struct hw_xmit *phwxmits;
765
sint hwentry;
766
struct xmit_frame *pxmitframe = NULL;
767
int res = _SUCCESS, xcnt = 0;
768
769
phwxmits = pxmitpriv->hwxmits;
770
hwentry = pxmitpriv->hwxmit_entry;
771
772
773
if (pxmitbuf == NULL) {
774
pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
775
if (!pxmitbuf)
776
return _FALSE;
777
}
778
779
780
do {
781
pxmitframe = rtw_dequeue_xframe(pxmitpriv, phwxmits, hwentry);
782
783
if (pxmitframe) {
784
pxmitframe->pxmitbuf = pxmitbuf;
785
786
pxmitframe->buf_addr = pxmitbuf->pbuf;
787
788
pxmitbuf->priv_data = pxmitframe;
789
790
if ((pxmitframe->frame_tag & 0x0f) == DATA_FRAMETAG) {
791
if (pxmitframe->attrib.priority <= 15) /* TID0~15 */
792
res = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
793
/* RTW_INFO("==> pxmitframe->attrib.priority:%d\n",pxmitframe->attrib.priority); */
794
rtw_os_xmit_complete(padapter, pxmitframe);/* always return ndis_packet after rtw_xmitframe_coalesce */
795
}
796
797
798
799
800
if (res == _SUCCESS)
801
rtw_dump_xframe(padapter, pxmitframe);
802
else {
803
rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
804
rtw_free_xmitframe(pxmitpriv, pxmitframe);
805
}
806
807
xcnt++;
808
809
} else {
810
rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
811
return _FALSE;
812
}
813
814
break;
815
816
} while (0/*xcnt < (NR_XMITFRAME >> 3)*/);
817
818
return _TRUE;
819
820
}
821
#endif
822
823
824
825
static s32 xmitframe_direct(_adapter *padapter, struct xmit_frame *pxmitframe)
826
{
827
s32 res = _SUCCESS;
828
/* RTW_INFO("==> %s\n",__FUNCTION__); */
829
830
res = rtw_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
831
if (res == _SUCCESS)
832
rtw_dump_xframe(padapter, pxmitframe);
833
else
834
RTW_INFO("==> %s xmitframe_coalsece failed\n", __FUNCTION__);
835
836
return res;
837
}
838
839
/*
840
* Return
841
* _TRUE dump packet directly
842
* _FALSE enqueue packet
843
*/
844
static s32 pre_xmitframe(_adapter *padapter, struct xmit_frame *pxmitframe)
845
{
846
_irqL irqL;
847
s32 res;
848
struct xmit_buf *pxmitbuf = NULL;
849
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
850
struct pkt_attrib *pattrib = &pxmitframe->attrib;
851
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
852
853
_enter_critical_bh(&pxmitpriv->lock, &irqL);
854
855
if (rtw_txframes_sta_ac_pending(padapter, pattrib) > 0) {
856
/* RTW_INFO("enqueue AC(%d)\n",pattrib->priority); */
857
goto enqueue;
858
}
859
860
if (rtw_xmit_ac_blocked(padapter) == _TRUE)
861
goto enqueue;
862
863
if (DEV_STA_LG_NUM(padapter->dvobj))
864
goto enqueue;
865
866
pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
867
if (pxmitbuf == NULL)
868
goto enqueue;
869
870
_exit_critical_bh(&pxmitpriv->lock, &irqL);
871
872
pxmitframe->pxmitbuf = pxmitbuf;
873
pxmitframe->buf_addr = pxmitbuf->pbuf;
874
pxmitbuf->priv_data = pxmitframe;
875
876
if (xmitframe_direct(padapter, pxmitframe) != _SUCCESS) {
877
rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
878
rtw_free_xmitframe(pxmitpriv, pxmitframe);
879
}
880
881
return _TRUE;
882
883
enqueue:
884
res = rtw_xmitframe_enqueue(padapter, pxmitframe);
885
_exit_critical_bh(&pxmitpriv->lock, &irqL);
886
887
if (res != _SUCCESS) {
888
rtw_free_xmitframe(pxmitpriv, pxmitframe);
889
890
pxmitpriv->tx_drop++;
891
return _TRUE;
892
}
893
894
return _FALSE;
895
}
896
897
s32 rtl8814au_mgnt_xmit(_adapter *padapter, struct xmit_frame *pmgntframe)
898
{
899
return rtw_dump_xframe(padapter, pmgntframe);
900
}
901
902
/*
903
* Return
904
* _TRUE dump packet directly ok
905
* _FALSE temporary can't transmit packets to hardware
906
*/
907
s32 rtl8814au_hal_xmit(_adapter *padapter, struct xmit_frame *pxmitframe)
908
{
909
return pre_xmitframe(padapter, pxmitframe);
910
}
911
912
s32 rtl8814au_hal_xmitframe_enqueue(_adapter *padapter, struct xmit_frame *pxmitframe)
913
{
914
struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
915
s32 err;
916
917
err = rtw_xmitframe_enqueue(padapter, pxmitframe);
918
if (err != _SUCCESS) {
919
rtw_free_xmitframe(pxmitpriv, pxmitframe);
920
921
pxmitpriv->tx_drop++;
922
} else {
923
#ifdef PLATFORM_LINUX
924
tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
925
#endif
926
}
927
928
return err;
929
930
}
931
932
933
#ifdef CONFIG_HOSTAPD_MLME
934
935
static void rtl8814au_hostap_mgnt_xmit_cb(struct urb *urb)
936
{
937
#ifdef PLATFORM_LINUX
938
struct sk_buff *skb = (struct sk_buff *)urb->context;
939
940
/* RTW_INFO("%s\n", __FUNCTION__); */
941
942
rtw_skb_free(skb);
943
#endif
944
}
945
946
s32 rtl8814au_hostap_mgnt_xmit_entry(_adapter *padapter, _pkt *pkt)
947
{
948
#ifdef PLATFORM_LINUX
949
u16 fc;
950
int rc, len, pipe;
951
unsigned int bmcst, tid, qsel;
952
struct sk_buff *skb, *pxmit_skb;
953
struct urb *urb;
954
unsigned char *pxmitbuf;
955
struct tx_desc *ptxdesc;
956
struct rtw_ieee80211_hdr *tx_hdr;
957
struct hostapd_priv *phostapdpriv = padapter->phostapdpriv;
958
struct net_device *pnetdev = padapter->pnetdev;
959
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
960
struct dvobj_priv *pdvobj = adapter_to_dvobj(padapter);
961
962
963
/* RTW_INFO("%s\n", __FUNCTION__); */
964
965
skb = pkt;
966
967
len = skb->len;
968
tx_hdr = (struct rtw_ieee80211_hdr *)(skb->data);
969
fc = le16_to_cpu(tx_hdr->frame_ctl);
970
bmcst = IS_MCAST(tx_hdr->addr1);
971
972
if ((fc & RTW_IEEE80211_FCTL_FTYPE) != RTW_IEEE80211_FTYPE_MGMT)
973
goto _exit;
974
975
pxmit_skb = rtw_skb_alloc(len + TXDESC_SIZE);
976
977
if (!pxmit_skb)
978
goto _exit;
979
980
pxmitbuf = pxmit_skb->data;
981
982
urb = usb_alloc_urb(0, GFP_ATOMIC);
983
if (!urb)
984
goto _exit;
985
986
/* ----- fill tx desc ----- */
987
ptxdesc = (struct tx_desc *)pxmitbuf;
988
_rtw_memset(ptxdesc, 0, sizeof(*ptxdesc));
989
990
/* offset 0 */
991
ptxdesc->txdw0 |= cpu_to_le32(len & 0x0000ffff);
992
ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) & 0x00ff0000); /* default = 32 bytes for TX Desc */
993
ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
994
995
if (bmcst)
996
ptxdesc->txdw0 |= cpu_to_le32(BIT(24));
997
998
/* offset 4 */
999
ptxdesc->txdw1 |= cpu_to_le32(0x00);/* MAC_ID */
1000
1001
ptxdesc->txdw1 |= cpu_to_le32((0x12 << QSEL_SHT) & 0x00001f00);
1002
1003
ptxdesc->txdw1 |= cpu_to_le32((0x06 << 16) & 0x000f0000); /* b mode */
1004
1005
/* offset 8 */
1006
1007
/* offset 12 */
1008
ptxdesc->txdw3 |= cpu_to_le32((le16_to_cpu(tx_hdr->seq_ctl) << 16) & 0xffff0000);
1009
1010
/* offset 16 */
1011
ptxdesc->txdw4 |= cpu_to_le32(BIT(8));/* driver uses rate */
1012
1013
/* offset 20 */
1014
1015
1016
/* HW append seq */
1017
ptxdesc->txdw4 |= cpu_to_le32(BIT(7)); /* Hw set sequence number */
1018
ptxdesc->txdw3 |= cpu_to_le32((8 << 28)); /* set bit3 to 1. Suugested by TimChen. 2009.12.29. */
1019
1020
1021
rtl8188eu_cal_txdesc_chksum(ptxdesc);
1022
/* ----- end of fill tx desc ----- */
1023
1024
/* */
1025
skb_put(pxmit_skb, len + TXDESC_SIZE);
1026
pxmitbuf = pxmitbuf + TXDESC_SIZE;
1027
_rtw_memcpy(pxmitbuf, skb->data, len);
1028
1029
/* RTW_INFO("mgnt_xmit, len=%x\n", pxmit_skb->len); */
1030
1031
1032
/* ----- prepare urb for submit ----- */
1033
1034
/* translate DMA FIFO addr to pipehandle */
1035
/* pipe = ffaddr2pipehdl(pdvobj, MGT_QUEUE_INX); */
1036
pipe = usb_sndbulkpipe(pdvobj->pusbdev, pHalData->Queue2EPNum[(u8)MGT_QUEUE_INX] & 0x0f);
1037
1038
usb_fill_bulk_urb(urb, pdvobj->pusbdev, pipe,
1039
pxmit_skb->data, pxmit_skb->len, rtl8192cu_hostap_mgnt_xmit_cb, pxmit_skb);
1040
1041
urb->transfer_flags |= URB_ZERO_PACKET;
1042
usb_anchor_urb(urb, &phostapdpriv->anchored);
1043
rc = usb_submit_urb(urb, GFP_ATOMIC);
1044
if (rc < 0) {
1045
usb_unanchor_urb(urb);
1046
kfree_skb(skb);
1047
}
1048
usb_free_urb(urb);
1049
1050
1051
_exit:
1052
1053
rtw_skb_free(skb);
1054
1055
#endif
1056
1057
return 0;
1058
1059
}
1060
#endif
1061
1062