]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/rtl8188eu/core/rtw_xmit.c
Merge branch 'for-linus' of git://git.linaro.org/people/rmk/linux-arm
[mirror_ubuntu-artful-kernel.git] / drivers / staging / rtl8188eu / core / rtw_xmit.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #define _RTW_XMIT_C_
21
22 #include <osdep_service.h>
23 #include <drv_types.h>
24 #include <wifi.h>
25 #include <osdep_intf.h>
26 #include <ip.h>
27 #include <usb_ops.h>
28 #include <usb_osintf.h>
29
30 static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
31 static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
32
33 static void _init_txservq(struct tx_servq *ptxservq)
34 {
35 _func_enter_;
36 _rtw_init_listhead(&ptxservq->tx_pending);
37 _rtw_init_queue(&ptxservq->sta_pending);
38 ptxservq->qcnt = 0;
39 _func_exit_;
40 }
41
42 void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
43 {
44 _func_enter_;
45 _rtw_memset((unsigned char *)psta_xmitpriv, 0, sizeof (struct sta_xmit_priv));
46 _rtw_spinlock_init(&psta_xmitpriv->lock);
47 _init_txservq(&psta_xmitpriv->be_q);
48 _init_txservq(&psta_xmitpriv->bk_q);
49 _init_txservq(&psta_xmitpriv->vi_q);
50 _init_txservq(&psta_xmitpriv->vo_q);
51 _rtw_init_listhead(&psta_xmitpriv->legacy_dz);
52 _rtw_init_listhead(&psta_xmitpriv->apsd);
53
54 _func_exit_;
55 }
56
57 s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct adapter *padapter)
58 {
59 int i;
60 struct xmit_buf *pxmitbuf;
61 struct xmit_frame *pxframe;
62 int res = _SUCCESS;
63 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
64 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
65
66 _func_enter_;
67
68 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by rtw_zvmalloc(). */
69
70 _rtw_spinlock_init(&pxmitpriv->lock);
71 _rtw_init_sema(&pxmitpriv->xmit_sema, 0);
72 _rtw_init_sema(&pxmitpriv->terminate_xmitthread_sema, 0);
73
74 /*
75 Please insert all the queue initializaiton using _rtw_init_queue below
76 */
77
78 pxmitpriv->adapter = padapter;
79
80 _rtw_init_queue(&pxmitpriv->be_pending);
81 _rtw_init_queue(&pxmitpriv->bk_pending);
82 _rtw_init_queue(&pxmitpriv->vi_pending);
83 _rtw_init_queue(&pxmitpriv->vo_pending);
84 _rtw_init_queue(&pxmitpriv->bm_pending);
85
86 _rtw_init_queue(&pxmitpriv->free_xmit_queue);
87
88 /*
89 Please allocate memory with the sz = (struct xmit_frame) * NR_XMITFRAME,
90 and initialize free_xmit_frame below.
91 Please also apply free_txobj to link_up all the xmit_frames...
92 */
93
94 pxmitpriv->pallocated_frame_buf = rtw_zvmalloc(NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
95
96 if (pxmitpriv->pallocated_frame_buf == NULL) {
97 pxmitpriv->pxmit_frame_buf = NULL;
98 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_frame fail!\n"));
99 res = _FAIL;
100 goto exit;
101 }
102 pxmitpriv->pxmit_frame_buf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_frame_buf), 4);
103 /* pxmitpriv->pxmit_frame_buf = pxmitpriv->pallocated_frame_buf + 4 - */
104 /* ((size_t) (pxmitpriv->pallocated_frame_buf) &3); */
105
106 pxframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
107
108 for (i = 0; i < NR_XMITFRAME; i++) {
109 _rtw_init_listhead(&(pxframe->list));
110
111 pxframe->padapter = padapter;
112 pxframe->frame_tag = NULL_FRAMETAG;
113
114 pxframe->pkt = NULL;
115
116 pxframe->buf_addr = NULL;
117 pxframe->pxmitbuf = NULL;
118
119 rtw_list_insert_tail(&(pxframe->list), &(pxmitpriv->free_xmit_queue.queue));
120
121 pxframe++;
122 }
123
124 pxmitpriv->free_xmitframe_cnt = NR_XMITFRAME;
125
126 pxmitpriv->frag_len = MAX_FRAG_THRESHOLD;
127
128 /* init xmit_buf */
129 _rtw_init_queue(&pxmitpriv->free_xmitbuf_queue);
130 _rtw_init_queue(&pxmitpriv->pending_xmitbuf_queue);
131
132 pxmitpriv->pallocated_xmitbuf = rtw_zvmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
133
134 if (pxmitpriv->pallocated_xmitbuf == NULL) {
135 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_buf fail!\n"));
136 res = _FAIL;
137 goto exit;
138 }
139
140 pxmitpriv->pxmitbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmitbuf), 4);
141 /* pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 - */
142 /* ((size_t) (pxmitpriv->pallocated_xmitbuf) &3); */
143
144 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
145
146 for (i = 0; i < NR_XMITBUFF; i++) {
147 _rtw_init_listhead(&pxmitbuf->list);
148
149 pxmitbuf->priv_data = NULL;
150 pxmitbuf->padapter = padapter;
151 pxmitbuf->ext_tag = false;
152
153 /* Tx buf allocation may fail sometimes, so sleep and retry. */
154 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
155 if (res == _FAIL) {
156 rtw_msleep_os(10);
157 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
158 if (res == _FAIL) {
159 goto exit;
160 }
161 }
162
163 pxmitbuf->flags = XMIT_VO_QUEUE;
164
165 rtw_list_insert_tail(&pxmitbuf->list, &(pxmitpriv->free_xmitbuf_queue.queue));
166 pxmitbuf++;
167 }
168
169 pxmitpriv->free_xmitbuf_cnt = NR_XMITBUFF;
170
171 /* Init xmit extension buff */
172 _rtw_init_queue(&pxmitpriv->free_xmit_extbuf_queue);
173
174 pxmitpriv->pallocated_xmit_extbuf = rtw_zvmalloc(num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
175
176 if (pxmitpriv->pallocated_xmit_extbuf == NULL) {
177 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("alloc xmit_extbuf fail!\n"));
178 res = _FAIL;
179 goto exit;
180 }
181
182 pxmitpriv->pxmit_extbuf = (u8 *)N_BYTE_ALIGMENT((size_t)(pxmitpriv->pallocated_xmit_extbuf), 4);
183
184 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
185
186 for (i = 0; i < num_xmit_extbuf; i++) {
187 _rtw_init_listhead(&pxmitbuf->list);
188
189 pxmitbuf->priv_data = NULL;
190 pxmitbuf->padapter = padapter;
191 pxmitbuf->ext_tag = true;
192
193 res = rtw_os_xmit_resource_alloc(padapter, pxmitbuf, max_xmit_extbuf_size + XMITBUF_ALIGN_SZ);
194 if (res == _FAIL) {
195 res = _FAIL;
196 goto exit;
197 }
198
199 rtw_list_insert_tail(&pxmitbuf->list, &(pxmitpriv->free_xmit_extbuf_queue.queue));
200 pxmitbuf++;
201 }
202
203 pxmitpriv->free_xmit_extbuf_cnt = num_xmit_extbuf;
204
205 rtw_alloc_hwxmits(padapter);
206 rtw_init_hwxmits(pxmitpriv->hwxmits, pxmitpriv->hwxmit_entry);
207
208 for (i = 0; i < 4; i++)
209 pxmitpriv->wmm_para_seq[i] = i;
210
211 pxmitpriv->txirp_cnt = 1;
212
213 _rtw_init_sema(&(pxmitpriv->tx_retevt), 0);
214
215 /* per AC pending irp */
216 pxmitpriv->beq_cnt = 0;
217 pxmitpriv->bkq_cnt = 0;
218 pxmitpriv->viq_cnt = 0;
219 pxmitpriv->voq_cnt = 0;
220
221 pxmitpriv->ack_tx = false;
222 _rtw_mutex_init(&pxmitpriv->ack_tx_mutex);
223 rtw_sctx_init(&pxmitpriv->ack_tx_ops, 0);
224
225 rtw_hal_init_xmit_priv(padapter);
226
227 exit:
228
229 _func_exit_;
230
231 return res;
232 }
233
234 static void rtw_mfree_xmit_priv_lock (struct xmit_priv *pxmitpriv)
235 {
236 _rtw_spinlock_free(&pxmitpriv->lock);
237 _rtw_free_sema(&pxmitpriv->xmit_sema);
238 _rtw_free_sema(&pxmitpriv->terminate_xmitthread_sema);
239
240 _rtw_spinlock_free(&pxmitpriv->be_pending.lock);
241 _rtw_spinlock_free(&pxmitpriv->bk_pending.lock);
242 _rtw_spinlock_free(&pxmitpriv->vi_pending.lock);
243 _rtw_spinlock_free(&pxmitpriv->vo_pending.lock);
244 _rtw_spinlock_free(&pxmitpriv->bm_pending.lock);
245
246 _rtw_spinlock_free(&pxmitpriv->free_xmit_queue.lock);
247 _rtw_spinlock_free(&pxmitpriv->free_xmitbuf_queue.lock);
248 _rtw_spinlock_free(&pxmitpriv->pending_xmitbuf_queue.lock);
249 }
250
251 void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv)
252 {
253 int i;
254 struct adapter *padapter = pxmitpriv->adapter;
255 struct xmit_frame *pxmitframe = (struct xmit_frame *)pxmitpriv->pxmit_frame_buf;
256 struct xmit_buf *pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
257 u32 max_xmit_extbuf_size = MAX_XMIT_EXTBUF_SZ;
258 u32 num_xmit_extbuf = NR_XMIT_EXTBUFF;
259
260 _func_enter_;
261
262 rtw_hal_free_xmit_priv(padapter);
263
264 rtw_mfree_xmit_priv_lock(pxmitpriv);
265
266 if (pxmitpriv->pxmit_frame_buf == NULL)
267 goto out;
268
269 for (i = 0; i < NR_XMITFRAME; i++) {
270 rtw_os_xmit_complete(padapter, pxmitframe);
271
272 pxmitframe++;
273 }
274
275 for (i = 0; i < NR_XMITBUFF; i++) {
276 rtw_os_xmit_resource_free(padapter, pxmitbuf, (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ));
277 pxmitbuf++;
278 }
279
280 if (pxmitpriv->pallocated_frame_buf)
281 rtw_vmfree(pxmitpriv->pallocated_frame_buf, NR_XMITFRAME * sizeof(struct xmit_frame) + 4);
282
283 if (pxmitpriv->pallocated_xmitbuf)
284 rtw_vmfree(pxmitpriv->pallocated_xmitbuf, NR_XMITBUFF * sizeof(struct xmit_buf) + 4);
285
286 /* free xmit extension buff */
287 _rtw_spinlock_free(&pxmitpriv->free_xmit_extbuf_queue.lock);
288
289 pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
290 for (i = 0; i < num_xmit_extbuf; i++) {
291 rtw_os_xmit_resource_free(padapter, pxmitbuf, (max_xmit_extbuf_size + XMITBUF_ALIGN_SZ));
292 pxmitbuf++;
293 }
294
295 if (pxmitpriv->pallocated_xmit_extbuf) {
296 rtw_vmfree(pxmitpriv->pallocated_xmit_extbuf, num_xmit_extbuf * sizeof(struct xmit_buf) + 4);
297 }
298
299 rtw_free_hwxmits(padapter);
300
301 _rtw_mutex_free(&pxmitpriv->ack_tx_mutex);
302
303 out:
304
305 _func_exit_;
306 }
307
308 static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *pxmitframe)
309 {
310 u32 sz;
311 struct pkt_attrib *pattrib = &pxmitframe->attrib;
312 struct sta_info *psta = pattrib->psta;
313 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
314 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
315
316 if (pattrib->nr_frags != 1)
317 sz = padapter->xmitpriv.frag_len;
318 else /* no frag */
319 sz = pattrib->last_txcmdsz;
320
321 /* (1) RTS_Threshold is compared to the MPDU, not MSDU. */
322 /* (2) If there are more than one frag in this MSDU, only the first frag uses protection frame. */
323 /* Other fragments are protected by previous fragment. */
324 /* So we only need to check the length of first fragment. */
325 if (pmlmeext->cur_wireless_mode < WIRELESS_11_24N || padapter->registrypriv.wifi_spec) {
326 if (sz > padapter->registrypriv.rts_thresh) {
327 pattrib->vcs_mode = RTS_CTS;
328 } else {
329 if (psta->rtsen)
330 pattrib->vcs_mode = RTS_CTS;
331 else if (psta->cts2self)
332 pattrib->vcs_mode = CTS_TO_SELF;
333 else
334 pattrib->vcs_mode = NONE_VCS;
335 }
336 } else {
337 while (true) {
338 /* IOT action */
339 if ((pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_ATHEROS) && pattrib->ampdu_en &&
340 (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_)) {
341 pattrib->vcs_mode = CTS_TO_SELF;
342 break;
343 }
344
345 /* check ERP protection */
346 if (psta->rtsen || psta->cts2self) {
347 if (psta->rtsen)
348 pattrib->vcs_mode = RTS_CTS;
349 else if (psta->cts2self)
350 pattrib->vcs_mode = CTS_TO_SELF;
351
352 break;
353 }
354
355 /* check HT op mode */
356 if (pattrib->ht_en) {
357 u8 htopmode = pmlmeinfo->HT_protection;
358 if ((pmlmeext->cur_bwmode && (htopmode == 2 || htopmode == 3)) ||
359 (!pmlmeext->cur_bwmode && htopmode == 3)) {
360 pattrib->vcs_mode = RTS_CTS;
361 break;
362 }
363 }
364
365 /* check rts */
366 if (sz > padapter->registrypriv.rts_thresh) {
367 pattrib->vcs_mode = RTS_CTS;
368 break;
369 }
370
371 /* to do list: check MIMO power save condition. */
372
373 /* check AMPDU aggregation for TXOP */
374 if (pattrib->ampdu_en) {
375 pattrib->vcs_mode = RTS_CTS;
376 break;
377 }
378
379 pattrib->vcs_mode = NONE_VCS;
380 break;
381 }
382 }
383 }
384
385 static void update_attrib_phy_info(struct pkt_attrib *pattrib, struct sta_info *psta)
386 {
387 /*if (psta->rtsen)
388 pattrib->vcs_mode = RTS_CTS;
389 else if (psta->cts2self)
390 pattrib->vcs_mode = CTS_TO_SELF;
391 else
392 pattrib->vcs_mode = NONE_VCS;*/
393
394 pattrib->mdata = 0;
395 pattrib->eosp = 0;
396 pattrib->triggered = 0;
397
398 /* qos_en, ht_en, init rate, , bw, ch_offset, sgi */
399 pattrib->qos_en = psta->qos_option;
400
401 pattrib->raid = psta->raid;
402 pattrib->ht_en = psta->htpriv.ht_option;
403 pattrib->bwmode = psta->htpriv.bwmode;
404 pattrib->ch_offset = psta->htpriv.ch_offset;
405 pattrib->sgi = psta->htpriv.sgi;
406 pattrib->ampdu_en = false;
407 pattrib->retry_ctrl = false;
408 }
409
410 u8 qos_acm(u8 acm_mask, u8 priority)
411 {
412 u8 change_priority = priority;
413
414 switch (priority) {
415 case 0:
416 case 3:
417 if (acm_mask & BIT(1))
418 change_priority = 1;
419 break;
420 case 1:
421 case 2:
422 break;
423 case 4:
424 case 5:
425 if (acm_mask & BIT(2))
426 change_priority = 0;
427 break;
428 case 6:
429 case 7:
430 if (acm_mask & BIT(3))
431 change_priority = 5;
432 break;
433 default:
434 DBG_88E("qos_acm(): invalid pattrib->priority: %d!!!\n", priority);
435 break;
436 }
437
438 return change_priority;
439 }
440
441 static void set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
442 {
443 struct ethhdr etherhdr;
444 struct iphdr ip_hdr;
445 s32 user_prio = 0;
446
447 _rtw_open_pktfile(ppktfile->pkt, ppktfile);
448 _rtw_pktfile_read(ppktfile, (unsigned char *)&etherhdr, ETH_HLEN);
449
450 /* get user_prio from IP hdr */
451 if (pattrib->ether_type == 0x0800) {
452 _rtw_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
453 /* user_prio = (ntohs(ip_hdr.tos) >> 5) & 0x3; */
454 user_prio = ip_hdr.tos >> 5;
455 } else if (pattrib->ether_type == 0x888e) {
456 /* "When priority processing of data frames is supported, */
457 /* a STA's SME should send EAPOL-Key frames at the highest priority." */
458 user_prio = 7;
459 }
460
461 pattrib->priority = user_prio;
462 pattrib->hdrlen = WLAN_HDR_A3_QOS_LEN;
463 pattrib->subtype = WIFI_QOS_DATA_TYPE;
464 }
465
466 static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct pkt_attrib *pattrib)
467 {
468 struct pkt_file pktfile;
469 struct sta_info *psta = NULL;
470 struct ethhdr etherhdr;
471
472 int bmcast;
473 struct sta_priv *pstapriv = &padapter->stapriv;
474 struct security_priv *psecuritypriv = &padapter->securitypriv;
475 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
476 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
477 int res = _SUCCESS;
478
479 _func_enter_;
480
481 _rtw_open_pktfile(pkt, &pktfile);
482 _rtw_pktfile_read(&pktfile, (u8 *)&etherhdr, ETH_HLEN);
483
484 pattrib->ether_type = ntohs(etherhdr.h_proto);
485
486 memcpy(pattrib->dst, &etherhdr.h_dest, ETH_ALEN);
487 memcpy(pattrib->src, &etherhdr.h_source, ETH_ALEN);
488
489 pattrib->pctrl = 0;
490
491 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
492 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
493 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
494 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
495 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
496 memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
497 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
498 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
499 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
500 memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
501 }
502
503 pattrib->pktlen = pktfile.pkt_len;
504
505 if (ETH_P_IP == pattrib->ether_type) {
506 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */
507 /* to prevent DHCP protocol fail */
508 u8 tmp[24];
509 _rtw_pktfile_read(&pktfile, &tmp[0], 24);
510 pattrib->dhcp_pkt = 0;
511 if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
512 if (ETH_P_IP == pattrib->ether_type) {/* IP header */
513 if (((tmp[21] == 68) && (tmp[23] == 67)) ||
514 ((tmp[21] == 67) && (tmp[23] == 68))) {
515 /* 68 : UDP BOOTP client */
516 /* 67 : UDP BOOTP server */
517 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====================== update_attrib: get DHCP Packet\n"));
518 /* Use low rate to send DHCP packet. */
519 pattrib->dhcp_pkt = 1;
520 }
521 }
522 }
523 } else if (0x888e == pattrib->ether_type) {
524 DBG_88E_LEVEL(_drv_info_, "send eapol packet\n");
525 }
526
527 if ((pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
528 rtw_set_scan_deny(padapter, 3000);
529
530 /* If EAPOL , ARP , OR DHCP packet, driver must be in active mode. */
531 if ((pattrib->ether_type == 0x0806) || (pattrib->ether_type == 0x888e) || (pattrib->dhcp_pkt == 1))
532 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SPECIAL_PACKET, 1);
533
534 bmcast = IS_MCAST(pattrib->ra);
535
536 /* get sta_info */
537 if (bmcast) {
538 psta = rtw_get_bcmc_stainfo(padapter);
539 } else {
540 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
541 if (psta == NULL) { /* if we cannot get psta => drrp the pkt */
542 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra: %pM\n", (pattrib->ra)));
543 res = _FAIL;
544 goto exit;
545 } else if ((check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) && (!(psta->state & _FW_LINKED))) {
546 res = _FAIL;
547 goto exit;
548 }
549 }
550
551 if (psta) {
552 pattrib->mac_id = psta->mac_id;
553 /* DBG_88E("%s ==> mac_id(%d)\n", __func__, pattrib->mac_id); */
554 pattrib->psta = psta;
555 } else {
556 /* if we cannot get psta => drop the pkt */
557 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("\nupdate_attrib => get sta_info fail, ra:%pM\n", (pattrib->ra)));
558 res = _FAIL;
559 goto exit;
560 }
561
562 pattrib->ack_policy = 0;
563 /* get ether_hdr_len */
564 pattrib->pkt_hdrlen = ETH_HLEN;/* pattrib->ether_type == 0x8100) ? (14 + 4): 14; vlan tag */
565
566 pattrib->hdrlen = WLAN_HDR_A3_LEN;
567 pattrib->subtype = WIFI_DATA_TYPE;
568 pattrib->priority = 0;
569
570 if (check_fwstate(pmlmepriv, WIFI_AP_STATE|WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE)) {
571 if (psta->qos_option)
572 set_qos(&pktfile, pattrib);
573 } else {
574 if (pqospriv->qos_option) {
575 set_qos(&pktfile, pattrib);
576
577 if (pmlmepriv->acm_mask != 0)
578 pattrib->priority = qos_acm(pmlmepriv->acm_mask, pattrib->priority);
579 }
580 }
581
582 if (psta->ieee8021x_blocked) {
583 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\n psta->ieee8021x_blocked == true\n"));
584
585 pattrib->encrypt = 0;
586
587 if ((pattrib->ether_type != 0x888e) && !check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
588 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != 0x888e\n", pattrib->ether_type));
589 res = _FAIL;
590 goto exit;
591 }
592 } else {
593 GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
594
595 switch (psecuritypriv->dot11AuthAlgrthm) {
596 case dot11AuthAlgrthm_Open:
597 case dot11AuthAlgrthm_Shared:
598 case dot11AuthAlgrthm_Auto:
599 pattrib->key_idx = (u8)psecuritypriv->dot11PrivacyKeyIndex;
600 break;
601 case dot11AuthAlgrthm_8021X:
602 if (bmcast)
603 pattrib->key_idx = (u8)psecuritypriv->dot118021XGrpKeyid;
604 else
605 pattrib->key_idx = 0;
606 break;
607 default:
608 pattrib->key_idx = 0;
609 break;
610 }
611 }
612
613 switch (pattrib->encrypt) {
614 case _WEP40_:
615 case _WEP104_:
616 pattrib->iv_len = 4;
617 pattrib->icv_len = 4;
618 break;
619 case _TKIP_:
620 pattrib->iv_len = 8;
621 pattrib->icv_len = 4;
622
623 if (padapter->securitypriv.busetkipkey == _FAIL) {
624 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
625 ("\npadapter->securitypriv.busetkipkey(%d) == _FAIL drop packet\n",
626 padapter->securitypriv.busetkipkey));
627 res = _FAIL;
628 goto exit;
629 }
630 break;
631 case _AES_:
632 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("pattrib->encrypt=%d (_AES_)\n", pattrib->encrypt));
633 pattrib->iv_len = 8;
634 pattrib->icv_len = 8;
635 break;
636 default:
637 pattrib->iv_len = 0;
638 pattrib->icv_len = 0;
639 break;
640 }
641
642 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
643 ("update_attrib: encrypt=%d securitypriv.sw_encrypt=%d\n",
644 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
645
646 if (pattrib->encrypt &&
647 (padapter->securitypriv.sw_encrypt || !psecuritypriv->hw_decrypted)) {
648 pattrib->bswenc = true;
649 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
650 ("update_attrib: encrypt=%d securitypriv.hw_decrypted=%d bswenc = true\n",
651 pattrib->encrypt, padapter->securitypriv.sw_encrypt));
652 } else {
653 pattrib->bswenc = false;
654 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("update_attrib: bswenc = false\n"));
655 }
656
657 rtw_set_tx_chksum_offload(pkt, pattrib);
658
659 update_attrib_phy_info(pattrib, psta);
660
661 exit:
662
663 _func_exit_;
664
665 return res;
666 }
667
668 static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitframe)
669 {
670 int curfragnum, length;
671 u8 *pframe, *payload, mic[8];
672 struct mic_data micdata;
673 struct sta_info *stainfo;
674 struct pkt_attrib *pattrib = &pxmitframe->attrib;
675 struct security_priv *psecuritypriv = &padapter->securitypriv;
676 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
677 u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
678 u8 hw_hdr_offset = 0;
679 int bmcst = IS_MCAST(pattrib->ra);
680
681 if (pattrib->psta)
682 stainfo = pattrib->psta;
683 else
684 stainfo = rtw_get_stainfo(&padapter->stapriv , &pattrib->ra[0]);
685
686 _func_enter_;
687
688 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);;
689
690 if (pattrib->encrypt == _TKIP_) {/* if (psecuritypriv->dot11PrivacyAlgrthm == _TKIP_PRIVACY_) */
691 /* encode mic code */
692 if (stainfo != NULL) {
693 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
694 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
695 0x0, 0x0};
696
697 pframe = pxmitframe->buf_addr + hw_hdr_offset;
698
699 if (bmcst) {
700 if (_rtw_memcmp(psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey, null_key, 16))
701 return _FAIL;
702 /* start to calculate the mic code */
703 rtw_secmicsetkey(&micdata, psecuritypriv->dot118021XGrptxmickey[psecuritypriv->dot118021XGrpKeyid].skey);
704 } else {
705 if (_rtw_memcmp(&stainfo->dot11tkiptxmickey.skey[0], null_key, 16) == true) {
706 /* DbgPrint("\nxmitframe_addmic:stainfo->dot11tkiptxmickey == 0\n"); */
707 /* rtw_msleep_os(10); */
708 return _FAIL;
709 }
710 /* start to calculate the mic code */
711 rtw_secmicsetkey(&micdata, &stainfo->dot11tkiptxmickey.skey[0]);
712 }
713
714 if (pframe[1]&1) { /* ToDS == 1 */
715 rtw_secmicappend(&micdata, &pframe[16], 6); /* DA */
716 if (pframe[1]&2) /* From Ds == 1 */
717 rtw_secmicappend(&micdata, &pframe[24], 6);
718 else
719 rtw_secmicappend(&micdata, &pframe[10], 6);
720 } else { /* ToDS == 0 */
721 rtw_secmicappend(&micdata, &pframe[4], 6); /* DA */
722 if (pframe[1]&2) /* From Ds == 1 */
723 rtw_secmicappend(&micdata, &pframe[16], 6);
724 else
725 rtw_secmicappend(&micdata, &pframe[10], 6);
726 }
727
728 if (pattrib->qos_en)
729 priority[0] = (u8)pxmitframe->attrib.priority;
730
731 rtw_secmicappend(&micdata, &priority[0], 4);
732
733 payload = pframe;
734
735 for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
736 payload = (u8 *)RND4((size_t)(payload));
737 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
738 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
739 curfragnum, *payload, *(payload+1),
740 *(payload+2), *(payload+3),
741 *(payload+4), *(payload+5),
742 *(payload+6), *(payload+7)));
743
744 payload = payload+pattrib->hdrlen+pattrib->iv_len;
745 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
746 ("curfragnum=%d pattrib->hdrlen=%d pattrib->iv_len=%d",
747 curfragnum, pattrib->hdrlen, pattrib->iv_len));
748 if ((curfragnum+1) == pattrib->nr_frags) {
749 length = pattrib->last_txcmdsz-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
750 rtw_secmicappend(&micdata, payload, length);
751 payload = payload+length;
752 } else {
753 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-((pattrib->bswenc) ? pattrib->icv_len : 0);
754 rtw_secmicappend(&micdata, payload, length);
755 payload = payload+length+pattrib->icv_len;
756 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("curfragnum=%d length=%d pattrib->icv_len=%d", curfragnum, length, pattrib->icv_len));
757 }
758 }
759 rtw_secgetmic(&micdata, &(mic[0]));
760 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: before add mic code!!!\n"));
761 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: pattrib->last_txcmdsz=%d!!!\n", pattrib->last_txcmdsz));
762 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: mic[0]=0x%.2x , mic[1]=0x%.2x , mic[2]= 0x%.2x, mic[3]=0x%.2x\n\
763 mic[4]= 0x%.2x , mic[5]= 0x%.2x , mic[6]= 0x%.2x , mic[7]= 0x%.2x !!!!\n",
764 mic[0], mic[1], mic[2], mic[3], mic[4], mic[5], mic[6], mic[7]));
765 /* add mic code and add the mic code length in last_txcmdsz */
766
767 memcpy(payload, &(mic[0]), 8);
768 pattrib->last_txcmdsz += 8;
769
770 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("\n ======== last pkt ========\n"));
771 payload = payload-pattrib->last_txcmdsz+8;
772 for (curfragnum = 0; curfragnum < pattrib->last_txcmdsz; curfragnum = curfragnum+8)
773 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
774 (" %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x, %.2x ",
775 *(payload+curfragnum), *(payload+curfragnum+1),
776 *(payload+curfragnum+2), *(payload+curfragnum+3),
777 *(payload+curfragnum+4), *(payload+curfragnum+5),
778 *(payload+curfragnum+6), *(payload+curfragnum+7)));
779 } else {
780 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic: rtw_get_stainfo==NULL!!!\n"));
781 }
782 }
783
784 _func_exit_;
785
786 return _SUCCESS;
787 }
788
789 static s32 xmitframe_swencrypt(struct adapter *padapter, struct xmit_frame *pxmitframe)
790 {
791 struct pkt_attrib *pattrib = &pxmitframe->attrib;
792
793 _func_enter_;
794
795 if (pattrib->bswenc) {
796 RT_TRACE(_module_rtl871x_xmit_c_, _drv_alert_, ("### xmitframe_swencrypt\n"));
797 switch (pattrib->encrypt) {
798 case _WEP40_:
799 case _WEP104_:
800 rtw_wep_encrypt(padapter, (u8 *)pxmitframe);
801 break;
802 case _TKIP_:
803 rtw_tkip_encrypt(padapter, (u8 *)pxmitframe);
804 break;
805 case _AES_:
806 rtw_aes_encrypt(padapter, (u8 *)pxmitframe);
807 break;
808 default:
809 break;
810 }
811 } else {
812 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_, ("### xmitframe_hwencrypt\n"));
813 }
814
815 _func_exit_;
816
817 return _SUCCESS;
818 }
819
820 s32 rtw_make_wlanhdr (struct adapter *padapter , u8 *hdr, struct pkt_attrib *pattrib)
821 {
822 u16 *qc;
823
824 struct rtw_ieee80211_hdr *pwlanhdr = (struct rtw_ieee80211_hdr *)hdr;
825 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
826 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
827 u8 qos_option = false;
828
829 int res = _SUCCESS;
830 u16 *fctrl = &pwlanhdr->frame_ctl;
831
832 struct sta_info *psta;
833
834 int bmcst = IS_MCAST(pattrib->ra);
835
836 _func_enter_;
837
838 if (pattrib->psta) {
839 psta = pattrib->psta;
840 } else {
841 if (bmcst) {
842 psta = rtw_get_bcmc_stainfo(padapter);
843 } else {
844 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
845 }
846 }
847
848 _rtw_memset(hdr, 0, WLANHDR_OFFSET);
849
850 SetFrameSubType(fctrl, pattrib->subtype);
851
852 if (pattrib->subtype & WIFI_DATA_TYPE) {
853 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)) {
854 /* to_ds = 1, fr_ds = 0; */
855 /* Data transfer to AP */
856 SetToDs(fctrl);
857 memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), ETH_ALEN);
858 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
859 memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
860
861 if (pqospriv->qos_option)
862 qos_option = true;
863 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
864 /* to_ds = 0, fr_ds = 1; */
865 SetFrDs(fctrl);
866 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
867 memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv), ETH_ALEN);
868 memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
869
870 if (psta->qos_option)
871 qos_option = true;
872 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
873 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
874 memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
875 memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
876 memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv), ETH_ALEN);
877
878 if (psta->qos_option)
879 qos_option = true;
880 } else {
881 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("fw_state:%x is not allowed to xmit frame\n", get_fwstate(pmlmepriv)));
882 res = _FAIL;
883 goto exit;
884 }
885
886 if (pattrib->mdata)
887 SetMData(fctrl);
888
889 if (pattrib->encrypt)
890 SetPrivacy(fctrl);
891
892 if (qos_option) {
893 qc = (unsigned short *)(hdr + pattrib->hdrlen - 2);
894
895 if (pattrib->priority)
896 SetPriority(qc, pattrib->priority);
897
898 SetEOSP(qc, pattrib->eosp);
899
900 SetAckpolicy(qc, pattrib->ack_policy);
901 }
902
903 /* TODO: fill HT Control Field */
904
905 /* Update Seq Num will be handled by f/w */
906 if (psta) {
907 psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
908 psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
909
910 pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
911
912 SetSeqNum(hdr, pattrib->seqnum);
913
914 /* check if enable ampdu */
915 if (pattrib->ht_en && psta->htpriv.ampdu_enable) {
916 if (psta->htpriv.agg_enable_bitmap & BIT(pattrib->priority))
917 pattrib->ampdu_en = true;
918 }
919
920 /* re-check if enable ampdu by BA_starting_seqctrl */
921 if (pattrib->ampdu_en) {
922 u16 tx_seq;
923
924 tx_seq = psta->BA_starting_seqctrl[pattrib->priority & 0x0f];
925
926 /* check BA_starting_seqctrl */
927 if (SN_LESS(pattrib->seqnum, tx_seq)) {
928 pattrib->ampdu_en = false;/* AGG BK */
929 } else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
930 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
931
932 pattrib->ampdu_en = true;/* AGG EN */
933 } else {
934 psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
935 pattrib->ampdu_en = true;/* AGG EN */
936 }
937 }
938 }
939 }
940 exit:
941
942 _func_exit_;
943 return res;
944 }
945
946 s32 rtw_txframes_pending(struct adapter *padapter)
947 {
948 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
949
950 return ((_rtw_queue_empty(&pxmitpriv->be_pending) == false) ||
951 (_rtw_queue_empty(&pxmitpriv->bk_pending) == false) ||
952 (_rtw_queue_empty(&pxmitpriv->vi_pending) == false) ||
953 (_rtw_queue_empty(&pxmitpriv->vo_pending) == false));
954 }
955
956 s32 rtw_txframes_sta_ac_pending(struct adapter *padapter, struct pkt_attrib *pattrib)
957 {
958 struct sta_info *psta;
959 struct tx_servq *ptxservq;
960 int priority = pattrib->priority;
961
962 psta = pattrib->psta;
963
964 switch (priority) {
965 case 1:
966 case 2:
967 ptxservq = &(psta->sta_xmitpriv.bk_q);
968 break;
969 case 4:
970 case 5:
971 ptxservq = &(psta->sta_xmitpriv.vi_q);
972 break;
973 case 6:
974 case 7:
975 ptxservq = &(psta->sta_xmitpriv.vo_q);
976 break;
977 case 0:
978 case 3:
979 default:
980 ptxservq = &(psta->sta_xmitpriv.be_q);
981 break;
982 }
983
984 return ptxservq->qcnt;
985 }
986
987 /*
988 * Calculate wlan 802.11 packet MAX size from pkt_attrib
989 * This function doesn't consider fragment case
990 */
991 u32 rtw_calculate_wlan_pkt_size_by_attribue(struct pkt_attrib *pattrib)
992 {
993 u32 len = 0;
994
995 len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */
996 len += SNAP_SIZE + sizeof(u16); /* LLC */
997 len += pattrib->pktlen;
998 if (pattrib->encrypt == _TKIP_)
999 len += 8; /* MIC */
1000 len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */
1001
1002 return len;
1003 }
1004
1005 /*
1006
1007 This sub-routine will perform all the following:
1008
1009 1. remove 802.3 header.
1010 2. create wlan_header, based on the info in pxmitframe
1011 3. append sta's iv/ext-iv
1012 4. append LLC
1013 5. move frag chunk from pframe to pxmitframe->mem
1014 6. apply sw-encrypt, if necessary.
1015
1016 */
1017 s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct xmit_frame *pxmitframe)
1018 {
1019 struct pkt_file pktfile;
1020 s32 frg_inx, frg_len, mpdu_len, llc_sz, mem_sz;
1021 size_t addr;
1022 u8 *pframe, *mem_start;
1023 u8 hw_hdr_offset;
1024 struct sta_info *psta;
1025 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1026 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1027 u8 *pbuf_start;
1028 s32 bmcst = IS_MCAST(pattrib->ra);
1029 s32 res = _SUCCESS;
1030
1031 _func_enter_;
1032
1033 psta = rtw_get_stainfo(&padapter->stapriv, pattrib->ra);
1034
1035 if (psta == NULL)
1036 return _FAIL;
1037
1038 if (pxmitframe->buf_addr == NULL) {
1039 DBG_88E("==> %s buf_addr == NULL\n", __func__);
1040 return _FAIL;
1041 }
1042
1043 pbuf_start = pxmitframe->buf_addr;
1044
1045 hw_hdr_offset = TXDESC_SIZE + (pxmitframe->pkt_offset * PACKET_OFFSET_SZ);
1046
1047 mem_start = pbuf_start + hw_hdr_offset;
1048
1049 if (rtw_make_wlanhdr(padapter, mem_start, pattrib) == _FAIL) {
1050 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n"));
1051 DBG_88E("rtw_xmitframe_coalesce: rtw_make_wlanhdr fail; drop pkt\n");
1052 res = _FAIL;
1053 goto exit;
1054 }
1055
1056 _rtw_open_pktfile(pkt, &pktfile);
1057 _rtw_pktfile_read(&pktfile, NULL, pattrib->pkt_hdrlen);
1058
1059 frg_inx = 0;
1060 frg_len = pxmitpriv->frag_len - 4;/* 2346-4 = 2342 */
1061
1062 while (1) {
1063 llc_sz = 0;
1064
1065 mpdu_len = frg_len;
1066
1067 pframe = mem_start;
1068
1069 SetMFrag(mem_start);
1070
1071 pframe += pattrib->hdrlen;
1072 mpdu_len -= pattrib->hdrlen;
1073
1074 /* adding icv, if necessary... */
1075 if (pattrib->iv_len) {
1076 if (psta != NULL) {
1077 switch (pattrib->encrypt) {
1078 case _WEP40_:
1079 case _WEP104_:
1080 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1081 break;
1082 case _TKIP_:
1083 if (bmcst)
1084 TKIP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1085 else
1086 TKIP_IV(pattrib->iv, psta->dot11txpn, 0);
1087 break;
1088 case _AES_:
1089 if (bmcst)
1090 AES_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
1091 else
1092 AES_IV(pattrib->iv, psta->dot11txpn, 0);
1093 break;
1094 }
1095 }
1096
1097 memcpy(pframe, pattrib->iv, pattrib->iv_len);
1098
1099 RT_TRACE(_module_rtl871x_xmit_c_, _drv_notice_,
1100 ("rtw_xmitframe_coalesce: keyid=%d pattrib->iv[3]=%.2x pframe=%.2x %.2x %.2x %.2x\n",
1101 padapter->securitypriv.dot11PrivacyKeyIndex, pattrib->iv[3], *pframe, *(pframe+1), *(pframe+2), *(pframe+3)));
1102
1103 pframe += pattrib->iv_len;
1104
1105 mpdu_len -= pattrib->iv_len;
1106 }
1107
1108 if (frg_inx == 0) {
1109 llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
1110 pframe += llc_sz;
1111 mpdu_len -= llc_sz;
1112 }
1113
1114 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1115 mpdu_len -= pattrib->icv_len;
1116 }
1117
1118 if (bmcst) {
1119 /* don't do fragment to broadcat/multicast packets */
1120 mem_sz = _rtw_pktfile_read(&pktfile, pframe, pattrib->pktlen);
1121 } else {
1122 mem_sz = _rtw_pktfile_read(&pktfile, pframe, mpdu_len);
1123 }
1124
1125 pframe += mem_sz;
1126
1127 if ((pattrib->icv_len > 0) && (pattrib->bswenc)) {
1128 memcpy(pframe, pattrib->icv, pattrib->icv_len);
1129 pframe += pattrib->icv_len;
1130 }
1131
1132 frg_inx++;
1133
1134 if (bmcst || rtw_endofpktfile(&pktfile)) {
1135 pattrib->nr_frags = frg_inx;
1136
1137 pattrib->last_txcmdsz = pattrib->hdrlen + pattrib->iv_len + ((pattrib->nr_frags == 1) ? llc_sz : 0) +
1138 ((pattrib->bswenc) ? pattrib->icv_len : 0) + mem_sz;
1139
1140 ClearMFrag(mem_start);
1141
1142 break;
1143 } else {
1144 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("%s: There're still something in packet!\n", __func__));
1145 }
1146
1147 addr = (size_t)(pframe);
1148
1149 mem_start = (unsigned char *)RND4(addr) + hw_hdr_offset;
1150 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
1151 }
1152
1153 if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
1154 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
1155 DBG_88E("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
1156 res = _FAIL;
1157 goto exit;
1158 }
1159
1160 xmitframe_swencrypt(padapter, pxmitframe);
1161
1162 if (!bmcst)
1163 update_attrib_vcs_info(padapter, pxmitframe);
1164 else
1165 pattrib->vcs_mode = NONE_VCS;
1166
1167 exit:
1168
1169 _func_exit_;
1170
1171 return res;
1172 }
1173
1174 /* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1175 * IEEE LLC/SNAP header contains 8 octets
1176 * First 3 octets comprise the LLC portion
1177 * SNAP portion, 5 octets, is divided into two fields:
1178 * Organizationally Unique Identifier(OUI), 3 octets,
1179 * type, defined by that organization, 2 octets.
1180 */
1181 s32 rtw_put_snap(u8 *data, u16 h_proto)
1182 {
1183 struct ieee80211_snap_hdr *snap;
1184 u8 *oui;
1185
1186 _func_enter_;
1187
1188 snap = (struct ieee80211_snap_hdr *)data;
1189 snap->dsap = 0xaa;
1190 snap->ssap = 0xaa;
1191 snap->ctrl = 0x03;
1192
1193 if (h_proto == 0x8137 || h_proto == 0x80f3)
1194 oui = P802_1H_OUI;
1195 else
1196 oui = RFC1042_OUI;
1197
1198 snap->oui[0] = oui[0];
1199 snap->oui[1] = oui[1];
1200 snap->oui[2] = oui[2];
1201
1202 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
1203
1204 _func_exit_;
1205
1206 return SNAP_SIZE + sizeof(u16);
1207 }
1208
1209 void rtw_update_protection(struct adapter *padapter, u8 *ie, uint ie_len)
1210 {
1211 uint protection;
1212 u8 *perp;
1213 int erp_len;
1214 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1215 struct registry_priv *pregistrypriv = &padapter->registrypriv;
1216
1217 _func_enter_;
1218
1219 switch (pxmitpriv->vcs_setting) {
1220 case DISABLE_VCS:
1221 pxmitpriv->vcs = NONE_VCS;
1222 break;
1223 case ENABLE_VCS:
1224 break;
1225 case AUTO_VCS:
1226 default:
1227 perp = rtw_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
1228 if (perp == NULL) {
1229 pxmitpriv->vcs = NONE_VCS;
1230 } else {
1231 protection = (*(perp + 2)) & BIT(1);
1232 if (protection) {
1233 if (pregistrypriv->vcs_type == RTS_CTS)
1234 pxmitpriv->vcs = RTS_CTS;
1235 else
1236 pxmitpriv->vcs = CTS_TO_SELF;
1237 } else {
1238 pxmitpriv->vcs = NONE_VCS;
1239 }
1240 }
1241 break;
1242 }
1243
1244 _func_exit_;
1245 }
1246
1247 void rtw_count_tx_stats(struct adapter *padapter, struct xmit_frame *pxmitframe, int sz)
1248 {
1249 struct sta_info *psta = NULL;
1250 struct stainfo_stats *pstats = NULL;
1251 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1252 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1253
1254 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) {
1255 pxmitpriv->tx_bytes += sz;
1256 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod += pxmitframe->agg_num;
1257
1258 psta = pxmitframe->attrib.psta;
1259 if (psta) {
1260 pstats = &psta->sta_stats;
1261 pstats->tx_pkts += pxmitframe->agg_num;
1262 pstats->tx_bytes += sz;
1263 }
1264 }
1265 }
1266
1267 struct xmit_buf *rtw_alloc_xmitbuf_ext(struct xmit_priv *pxmitpriv)
1268 {
1269 unsigned long irql;
1270 struct xmit_buf *pxmitbuf = NULL;
1271 struct list_head *plist, *phead;
1272 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1273
1274 _func_enter_;
1275
1276 _enter_critical(&pfree_queue->lock, &irql);
1277
1278 if (_rtw_queue_empty(pfree_queue) == true) {
1279 pxmitbuf = NULL;
1280 } else {
1281 phead = get_list_head(pfree_queue);
1282
1283 plist = get_next(phead);
1284
1285 pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
1286
1287 rtw_list_delete(&(pxmitbuf->list));
1288 }
1289
1290 if (pxmitbuf != NULL) {
1291 pxmitpriv->free_xmit_extbuf_cnt--;
1292
1293 pxmitbuf->priv_data = NULL;
1294 /* pxmitbuf->ext_tag = true; */
1295
1296 if (pxmitbuf->sctx) {
1297 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1298 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1299 }
1300 }
1301
1302 _exit_critical(&pfree_queue->lock, &irql);
1303
1304 _func_exit_;
1305
1306 return pxmitbuf;
1307 }
1308
1309 s32 rtw_free_xmitbuf_ext(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1310 {
1311 unsigned long irql;
1312 struct __queue *pfree_queue = &pxmitpriv->free_xmit_extbuf_queue;
1313
1314 _func_enter_;
1315
1316 if (pxmitbuf == NULL)
1317 return _FAIL;
1318
1319 _enter_critical(&pfree_queue->lock, &irql);
1320
1321 rtw_list_delete(&pxmitbuf->list);
1322
1323 rtw_list_insert_tail(&(pxmitbuf->list), get_list_head(pfree_queue));
1324 pxmitpriv->free_xmit_extbuf_cnt++;
1325
1326 _exit_critical(&pfree_queue->lock, &irql);
1327
1328 _func_exit_;
1329
1330 return _SUCCESS;
1331 }
1332
1333 struct xmit_buf *rtw_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
1334 {
1335 unsigned long irql;
1336 struct xmit_buf *pxmitbuf = NULL;
1337 struct list_head *plist, *phead;
1338 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1339
1340 _func_enter_;
1341
1342 /* DBG_88E("+rtw_alloc_xmitbuf\n"); */
1343
1344 _enter_critical(&pfree_xmitbuf_queue->lock, &irql);
1345
1346 if (_rtw_queue_empty(pfree_xmitbuf_queue) == true) {
1347 pxmitbuf = NULL;
1348 } else {
1349 phead = get_list_head(pfree_xmitbuf_queue);
1350
1351 plist = get_next(phead);
1352
1353 pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
1354
1355 rtw_list_delete(&(pxmitbuf->list));
1356 }
1357
1358 if (pxmitbuf != NULL) {
1359 pxmitpriv->free_xmitbuf_cnt--;
1360 pxmitbuf->priv_data = NULL;
1361 if (pxmitbuf->sctx) {
1362 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1363 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_ALLOC);
1364 }
1365 }
1366 _exit_critical(&pfree_xmitbuf_queue->lock, &irql);
1367
1368 _func_exit_;
1369
1370 return pxmitbuf;
1371 }
1372
1373 s32 rtw_free_xmitbuf(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf)
1374 {
1375 unsigned long irql;
1376 struct __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
1377
1378 _func_enter_;
1379 if (pxmitbuf == NULL)
1380 return _FAIL;
1381
1382 if (pxmitbuf->sctx) {
1383 DBG_88E("%s pxmitbuf->sctx is not NULL\n", __func__);
1384 rtw_sctx_done_err(&pxmitbuf->sctx, RTW_SCTX_DONE_BUF_FREE);
1385 }
1386
1387 if (pxmitbuf->ext_tag) {
1388 rtw_free_xmitbuf_ext(pxmitpriv, pxmitbuf);
1389 } else {
1390 _enter_critical(&pfree_xmitbuf_queue->lock, &irql);
1391
1392 rtw_list_delete(&pxmitbuf->list);
1393
1394 rtw_list_insert_tail(&(pxmitbuf->list), get_list_head(pfree_xmitbuf_queue));
1395
1396 pxmitpriv->free_xmitbuf_cnt++;
1397 _exit_critical(&pfree_xmitbuf_queue->lock, &irql);
1398 }
1399
1400 _func_exit_;
1401
1402 return _SUCCESS;
1403 }
1404
1405 /*
1406 Calling context:
1407 1. OS_TXENTRY
1408 2. RXENTRY (rx_thread or RX_ISR/RX_CallBack)
1409
1410 If we turn on USE_RXTHREAD, then, no need for critical section.
1411 Otherwise, we must use _enter/_exit critical to protect free_xmit_queue...
1412
1413 Must be very very cautious...
1414
1415 */
1416
1417 struct xmit_frame *rtw_alloc_xmitframe(struct xmit_priv *pxmitpriv)/* _queue *pfree_xmit_queue) */
1418 {
1419 /*
1420 Please remember to use all the osdep_service api,
1421 and lock/unlock or _enter/_exit critical to protect
1422 pfree_xmit_queue
1423 */
1424
1425 unsigned long irql;
1426 struct xmit_frame *pxframe = NULL;
1427 struct list_head *plist, *phead;
1428 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1429
1430 _func_enter_;
1431
1432 _enter_critical_bh(&pfree_xmit_queue->lock, &irql);
1433
1434 if (_rtw_queue_empty(pfree_xmit_queue) == true) {
1435 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe:%d\n", pxmitpriv->free_xmitframe_cnt));
1436 pxframe = NULL;
1437 } else {
1438 phead = get_list_head(pfree_xmit_queue);
1439
1440 plist = get_next(phead);
1441
1442 pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
1443
1444 rtw_list_delete(&(pxframe->list));
1445 }
1446
1447 if (pxframe != NULL) { /* default value setting */
1448 pxmitpriv->free_xmitframe_cnt--;
1449
1450 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_alloc_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
1451
1452 pxframe->buf_addr = NULL;
1453 pxframe->pxmitbuf = NULL;
1454
1455 _rtw_memset(&pxframe->attrib, 0, sizeof(struct pkt_attrib));
1456 /* pxframe->attrib.psta = NULL; */
1457
1458 pxframe->frame_tag = DATA_FRAMETAG;
1459
1460 pxframe->pkt = NULL;
1461 pxframe->pkt_offset = 1;/* default use pkt_offset to fill tx desc */
1462
1463 pxframe->agg_num = 1;
1464 pxframe->ack_report = 0;
1465 }
1466
1467 _exit_critical_bh(&pfree_xmit_queue->lock, &irql);
1468
1469 _func_exit_;
1470
1471 return pxframe;
1472 }
1473
1474 s32 rtw_free_xmitframe(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe)
1475 {
1476 unsigned long irql;
1477 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
1478 struct adapter *padapter = pxmitpriv->adapter;
1479 struct sk_buff *pndis_pkt = NULL;
1480
1481 _func_enter_;
1482
1483 if (pxmitframe == NULL) {
1484 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("====== rtw_free_xmitframe():pxmitframe == NULL!!!!!!!!!!\n"));
1485 goto exit;
1486 }
1487
1488 _enter_critical_bh(&pfree_xmit_queue->lock, &irql);
1489
1490 rtw_list_delete(&pxmitframe->list);
1491
1492 if (pxmitframe->pkt) {
1493 pndis_pkt = pxmitframe->pkt;
1494 pxmitframe->pkt = NULL;
1495 }
1496
1497 rtw_list_insert_tail(&pxmitframe->list, get_list_head(pfree_xmit_queue));
1498
1499 pxmitpriv->free_xmitframe_cnt++;
1500 RT_TRACE(_module_rtl871x_xmit_c_, _drv_debug_, ("rtw_free_xmitframe():free_xmitframe_cnt=%d\n", pxmitpriv->free_xmitframe_cnt));
1501
1502 _exit_critical_bh(&pfree_xmit_queue->lock, &irql);
1503
1504 if (pndis_pkt)
1505 rtw_os_pkt_complete(padapter, pndis_pkt);
1506
1507 exit:
1508
1509 _func_exit_;
1510
1511 return _SUCCESS;
1512 }
1513
1514 void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pframequeue)
1515 {
1516 unsigned long irql;
1517 struct list_head *plist, *phead;
1518 struct xmit_frame *pxmitframe;
1519
1520 _func_enter_;
1521
1522 _enter_critical_bh(&(pframequeue->lock), &irql);
1523
1524 phead = get_list_head(pframequeue);
1525 plist = get_next(phead);
1526
1527 while (!rtw_end_of_queue_search(phead, plist)) {
1528 pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
1529
1530 plist = get_next(plist);
1531
1532 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1533 }
1534 _exit_critical_bh(&(pframequeue->lock), &irql);
1535
1536 _func_exit_;
1537 }
1538
1539 s32 rtw_xmitframe_enqueue(struct adapter *padapter, struct xmit_frame *pxmitframe)
1540 {
1541 if (rtw_xmit_classifier(padapter, pxmitframe) == _FAIL) {
1542 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
1543 ("rtw_xmitframe_enqueue: drop xmit pkt for classifier fail\n"));
1544 /* pxmitframe->pkt = NULL; */
1545 return _FAIL;
1546 }
1547
1548 return _SUCCESS;
1549 }
1550
1551 static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit, struct tx_servq *ptxservq, struct __queue *pframe_queue)
1552 {
1553 struct list_head *xmitframe_plist, *xmitframe_phead;
1554 struct xmit_frame *pxmitframe = NULL;
1555
1556 xmitframe_phead = get_list_head(pframe_queue);
1557 xmitframe_plist = get_next(xmitframe_phead);
1558
1559 if (!rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) {
1560 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
1561
1562 xmitframe_plist = get_next(xmitframe_plist);
1563
1564 rtw_list_delete(&pxmitframe->list);
1565
1566 ptxservq->qcnt--;
1567 }
1568 return pxmitframe;
1569 }
1570
1571 struct xmit_frame *rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmit *phwxmit_i, int entry)
1572 {
1573 unsigned long irql0;
1574 struct list_head *sta_plist, *sta_phead;
1575 struct hw_xmit *phwxmit;
1576 struct tx_servq *ptxservq = NULL;
1577 struct __queue *pframe_queue = NULL;
1578 struct xmit_frame *pxmitframe = NULL;
1579 struct adapter *padapter = pxmitpriv->adapter;
1580 struct registry_priv *pregpriv = &padapter->registrypriv;
1581 int i, inx[4];
1582
1583 _func_enter_;
1584
1585 inx[0] = 0; inx[1] = 1; inx[2] = 2; inx[3] = 3;
1586
1587 if (pregpriv->wifi_spec == 1) {
1588 int j;
1589
1590 for (j = 0; j < 4; j++)
1591 inx[j] = pxmitpriv->wmm_para_seq[j];
1592 }
1593
1594 _enter_critical_bh(&pxmitpriv->lock, &irql0);
1595
1596 for (i = 0; i < entry; i++) {
1597 phwxmit = phwxmit_i + inx[i];
1598
1599 sta_phead = get_list_head(phwxmit->sta_queue);
1600 sta_plist = get_next(sta_phead);
1601
1602 while (!rtw_end_of_queue_search(sta_phead, sta_plist)) {
1603 ptxservq = LIST_CONTAINOR(sta_plist, struct tx_servq, tx_pending);
1604
1605 pframe_queue = &ptxservq->sta_pending;
1606
1607 pxmitframe = dequeue_one_xmitframe(pxmitpriv, phwxmit, ptxservq, pframe_queue);
1608
1609 if (pxmitframe) {
1610 phwxmit->accnt--;
1611
1612 /* Remove sta node when there are no pending packets. */
1613 if (_rtw_queue_empty(pframe_queue)) /* must be done after get_next and before break */
1614 rtw_list_delete(&ptxservq->tx_pending);
1615 goto exit;
1616 }
1617
1618 sta_plist = get_next(sta_plist);
1619 }
1620 }
1621 exit:
1622 _exit_critical_bh(&pxmitpriv->lock, &irql0);
1623 _func_exit_;
1624 return pxmitframe;
1625 }
1626
1627 struct tx_servq *rtw_get_sta_pending(struct adapter *padapter, struct sta_info *psta, int up, u8 *ac)
1628 {
1629 struct tx_servq *ptxservq;
1630
1631 _func_enter_;
1632 switch (up) {
1633 case 1:
1634 case 2:
1635 ptxservq = &(psta->sta_xmitpriv.bk_q);
1636 *(ac) = 3;
1637 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BK\n"));
1638 break;
1639 case 4:
1640 case 5:
1641 ptxservq = &(psta->sta_xmitpriv.vi_q);
1642 *(ac) = 1;
1643 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VI\n"));
1644 break;
1645 case 6:
1646 case 7:
1647 ptxservq = &(psta->sta_xmitpriv.vo_q);
1648 *(ac) = 0;
1649 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : VO\n"));
1650 break;
1651 case 0:
1652 case 3:
1653 default:
1654 ptxservq = &(psta->sta_xmitpriv.be_q);
1655 *(ac) = 2;
1656 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("rtw_get_sta_pending : BE\n"));
1657 break;
1658 }
1659
1660 _func_exit_;
1661
1662 return ptxservq;
1663 }
1664
1665 /*
1666 * Will enqueue pxmitframe to the proper queue,
1667 * and indicate it to xx_pending list.....
1668 */
1669 s32 rtw_xmit_classifier(struct adapter *padapter, struct xmit_frame *pxmitframe)
1670 {
1671 /* unsigned long irql0; */
1672 u8 ac_index;
1673 struct sta_info *psta;
1674 struct tx_servq *ptxservq;
1675 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1676 struct sta_priv *pstapriv = &padapter->stapriv;
1677 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
1678 int res = _SUCCESS;
1679
1680 _func_enter_;
1681
1682 if (pattrib->psta) {
1683 psta = pattrib->psta;
1684 } else {
1685 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
1686 }
1687
1688 if (psta == NULL) {
1689 res = _FAIL;
1690 DBG_88E("rtw_xmit_classifier: psta == NULL\n");
1691 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("rtw_xmit_classifier: psta == NULL\n"));
1692 goto exit;
1693 }
1694
1695 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
1696
1697 if (rtw_is_list_empty(&ptxservq->tx_pending))
1698 rtw_list_insert_tail(&ptxservq->tx_pending, get_list_head(phwxmits[ac_index].sta_queue));
1699
1700 rtw_list_insert_tail(&pxmitframe->list, get_list_head(&ptxservq->sta_pending));
1701 ptxservq->qcnt++;
1702 phwxmits[ac_index].accnt++;
1703 exit:
1704
1705 _func_exit_;
1706
1707 return res;
1708 }
1709
1710 void rtw_alloc_hwxmits(struct adapter *padapter)
1711 {
1712 struct hw_xmit *hwxmits;
1713 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1714
1715 pxmitpriv->hwxmit_entry = HWXMIT_ENTRY;
1716
1717 pxmitpriv->hwxmits = (struct hw_xmit *)rtw_zmalloc(sizeof(struct hw_xmit) * pxmitpriv->hwxmit_entry);
1718
1719 hwxmits = pxmitpriv->hwxmits;
1720
1721 if (pxmitpriv->hwxmit_entry == 5) {
1722 hwxmits[0] .sta_queue = &pxmitpriv->bm_pending;
1723 hwxmits[1] .sta_queue = &pxmitpriv->vo_pending;
1724 hwxmits[2] .sta_queue = &pxmitpriv->vi_pending;
1725 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1726 hwxmits[4] .sta_queue = &pxmitpriv->be_pending;
1727 } else if (pxmitpriv->hwxmit_entry == 4) {
1728 hwxmits[0] .sta_queue = &pxmitpriv->vo_pending;
1729 hwxmits[1] .sta_queue = &pxmitpriv->vi_pending;
1730 hwxmits[2] .sta_queue = &pxmitpriv->be_pending;
1731 hwxmits[3] .sta_queue = &pxmitpriv->bk_pending;
1732 } else {
1733 }
1734 }
1735
1736 void rtw_free_hwxmits(struct adapter *padapter)
1737 {
1738 struct hw_xmit *hwxmits;
1739 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1740
1741 hwxmits = pxmitpriv->hwxmits;
1742 kfree(hwxmits);
1743 }
1744
1745 void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry)
1746 {
1747 int i;
1748 _func_enter_;
1749 for (i = 0; i < entry; i++, phwxmit++)
1750 phwxmit->accnt = 0;
1751 _func_exit_;
1752 }
1753
1754 static int rtw_br_client_tx(struct adapter *padapter, struct sk_buff **pskb)
1755 {
1756 struct sk_buff *skb = *pskb;
1757 unsigned long irql;
1758 int res, is_vlan_tag = 0, i, do_nat25 = 1;
1759 unsigned short vlan_hdr = 0;
1760 void *br_port = NULL;
1761
1762 rcu_read_lock();
1763 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
1764 rcu_read_unlock();
1765 _enter_critical_bh(&padapter->br_ext_lock, &irql);
1766 if (!(skb->data[0] & 1) && br_port &&
1767 memcmp(skb->data+MACADDRLEN, padapter->br_mac, MACADDRLEN) &&
1768 *((__be16 *)(skb->data+MACADDRLEN*2)) != __constant_htons(ETH_P_8021Q) &&
1769 *((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP) &&
1770 !memcmp(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN) && padapter->scdb_entry) {
1771 memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
1772 padapter->scdb_entry->ageing_timer = jiffies;
1773 _exit_critical_bh(&padapter->br_ext_lock, &irql);
1774 } else {
1775 if (*((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_8021Q)) {
1776 is_vlan_tag = 1;
1777 vlan_hdr = *((unsigned short *)(skb->data+MACADDRLEN*2+2));
1778 for (i = 0; i < 6; i++)
1779 *((unsigned short *)(skb->data+MACADDRLEN*2+2-i*2)) = *((unsigned short *)(skb->data+MACADDRLEN*2-2-i*2));
1780 skb_pull(skb, 4);
1781 }
1782 if (!memcmp(skb->data+MACADDRLEN, padapter->br_mac, MACADDRLEN) &&
1783 (*((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP)))
1784 memcpy(padapter->br_ip, skb->data+WLAN_ETHHDR_LEN+12, 4);
1785
1786 if (*((__be16 *)(skb->data+MACADDRLEN*2)) == __constant_htons(ETH_P_IP)) {
1787 if (memcmp(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN)) {
1788 padapter->scdb_entry = (struct nat25_network_db_entry *)scdb_findEntry(padapter,
1789 skb->data+MACADDRLEN, skb->data+WLAN_ETHHDR_LEN+12);
1790 if (padapter->scdb_entry) {
1791 memcpy(padapter->scdb_mac, skb->data+MACADDRLEN, MACADDRLEN);
1792 memcpy(padapter->scdb_ip, skb->data+WLAN_ETHHDR_LEN+12, 4);
1793 padapter->scdb_entry->ageing_timer = jiffies;
1794 do_nat25 = 0;
1795 }
1796 } else {
1797 if (padapter->scdb_entry) {
1798 padapter->scdb_entry->ageing_timer = jiffies;
1799 do_nat25 = 0;
1800 } else {
1801 memset(padapter->scdb_mac, 0, MACADDRLEN);
1802 memset(padapter->scdb_ip, 0, 4);
1803 }
1804 }
1805 }
1806 _exit_critical_bh(&padapter->br_ext_lock, &irql);
1807 if (do_nat25) {
1808 if (nat25_db_handle(padapter, skb, NAT25_CHECK) == 0) {
1809 struct sk_buff *newskb;
1810
1811 if (is_vlan_tag) {
1812 skb_push(skb, 4);
1813 for (i = 0; i < 6; i++)
1814 *((unsigned short *)(skb->data+i*2)) = *((unsigned short *)(skb->data+4+i*2));
1815 *((__be16 *)(skb->data+MACADDRLEN*2)) = __constant_htons(ETH_P_8021Q);
1816 *((unsigned short *)(skb->data+MACADDRLEN*2+2)) = vlan_hdr;
1817 }
1818
1819 newskb = skb_copy(skb, GFP_ATOMIC);
1820 if (newskb == NULL) {
1821 DEBUG_ERR("TX DROP: skb_copy fail!\n");
1822 return -1;
1823 }
1824 dev_kfree_skb_any(skb);
1825
1826 *pskb = skb = newskb;
1827 if (is_vlan_tag) {
1828 vlan_hdr = *((unsigned short *)(skb->data+MACADDRLEN*2+2));
1829 for (i = 0; i < 6; i++)
1830 *((unsigned short *)(skb->data+MACADDRLEN*2+2-i*2)) = *((unsigned short *)(skb->data+MACADDRLEN*2-2-i*2));
1831 skb_pull(skb, 4);
1832 }
1833 }
1834
1835 if (skb_is_nonlinear(skb))
1836 DEBUG_ERR("%s(): skb_is_nonlinear!!\n", __func__);
1837
1838 res = skb_linearize(skb);
1839 if (res < 0) {
1840 DEBUG_ERR("TX DROP: skb_linearize fail!\n");
1841 return -1;
1842 }
1843
1844 res = nat25_db_handle(padapter, skb, NAT25_INSERT);
1845 if (res < 0) {
1846 if (res == -2) {
1847 DEBUG_ERR("TX DROP: nat25_db_handle fail!\n");
1848 return -1;
1849 }
1850 return 0;
1851 }
1852 }
1853
1854 memcpy(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN);
1855
1856 dhcp_flag_bcast(padapter, skb);
1857
1858 if (is_vlan_tag) {
1859 skb_push(skb, 4);
1860 for (i = 0; i < 6; i++)
1861 *((unsigned short *)(skb->data+i*2)) = *((unsigned short *)(skb->data+4+i*2));
1862 *((__be16 *)(skb->data+MACADDRLEN*2)) = __constant_htons(ETH_P_8021Q);
1863 *((unsigned short *)(skb->data+MACADDRLEN*2+2)) = vlan_hdr;
1864 }
1865 }
1866
1867 /* check if SA is equal to our MAC */
1868 if (memcmp(skb->data+MACADDRLEN, GET_MY_HWADDR(padapter), MACADDRLEN)) {
1869 DEBUG_ERR("TX DROP: untransformed frame SA:%02X%02X%02X%02X%02X%02X!\n",
1870 skb->data[6], skb->data[7], skb->data[8], skb->data[9], skb->data[10], skb->data[11]);
1871 return -1;
1872 }
1873 return 0;
1874 }
1875
1876 u32 rtw_get_ff_hwaddr(struct xmit_frame *pxmitframe)
1877 {
1878 u32 addr;
1879 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1880
1881 switch (pattrib->qsel) {
1882 case 0:
1883 case 3:
1884 addr = BE_QUEUE_INX;
1885 break;
1886 case 1:
1887 case 2:
1888 addr = BK_QUEUE_INX;
1889 break;
1890 case 4:
1891 case 5:
1892 addr = VI_QUEUE_INX;
1893 break;
1894 case 6:
1895 case 7:
1896 addr = VO_QUEUE_INX;
1897 break;
1898 case 0x10:
1899 addr = BCN_QUEUE_INX;
1900 break;
1901 case 0x11:/* BC/MC in PS (HIQ) */
1902 addr = HIGH_QUEUE_INX;
1903 break;
1904 case 0x12:
1905 default:
1906 addr = MGT_QUEUE_INX;
1907 break;
1908 }
1909
1910 return addr;
1911 }
1912
1913 static void do_queue_select(struct adapter *padapter, struct pkt_attrib *pattrib)
1914 {
1915 u8 qsel;
1916
1917 qsel = pattrib->priority;
1918 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_, ("### do_queue_select priority=%d , qsel = %d\n", pattrib->priority , qsel));
1919
1920 pattrib->qsel = qsel;
1921 }
1922
1923 /*
1924 * The main transmit(tx) entry
1925 *
1926 * Return
1927 * 1 enqueue
1928 * 0 success, hardware will handle this xmit frame(packet)
1929 * <0 fail
1930 */
1931 s32 rtw_xmit(struct adapter *padapter, struct sk_buff **ppkt)
1932 {
1933 #ifdef CONFIG_88EU_AP_MODE
1934 unsigned long irql0;
1935 #endif
1936 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1937 struct xmit_frame *pxmitframe = NULL;
1938 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1939 void *br_port = NULL;
1940 s32 res;
1941
1942 pxmitframe = rtw_alloc_xmitframe(pxmitpriv);
1943 if (pxmitframe == NULL) {
1944 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: no more pxmitframe\n"));
1945 DBG_88E("DBG_TX_DROP_FRAME %s no more pxmitframe\n", __func__);
1946 return -1;
1947 }
1948
1949 rcu_read_lock();
1950 br_port = rcu_dereference(padapter->pnetdev->rx_handler_data);
1951 rcu_read_unlock();
1952
1953 if (br_port && check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE)) {
1954 res = rtw_br_client_tx(padapter, ppkt);
1955 if (res == -1) {
1956 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1957 return -1;
1958 }
1959 }
1960
1961 res = update_attrib(padapter, *ppkt, &pxmitframe->attrib);
1962
1963 if (res == _FAIL) {
1964 RT_TRACE(_module_xmit_osdep_c_, _drv_err_, ("rtw_xmit: update attrib fail\n"));
1965 rtw_free_xmitframe(pxmitpriv, pxmitframe);
1966 return -1;
1967 }
1968 pxmitframe->pkt = *ppkt;
1969
1970 rtw_led_control(padapter, LED_CTL_TX);
1971
1972 do_queue_select(padapter, &pxmitframe->attrib);
1973
1974 #ifdef CONFIG_88EU_AP_MODE
1975 _enter_critical_bh(&pxmitpriv->lock, &irql0);
1976 if (xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe)) {
1977 _exit_critical_bh(&pxmitpriv->lock, &irql0);
1978 return 1;
1979 }
1980 _exit_critical_bh(&pxmitpriv->lock, &irql0);
1981 #endif
1982
1983 if (rtw_hal_xmit(padapter, pxmitframe) == false)
1984 return 1;
1985
1986 return 0;
1987 }
1988
1989 #if defined(CONFIG_88EU_AP_MODE)
1990
1991 int xmitframe_enqueue_for_sleeping_sta(struct adapter *padapter, struct xmit_frame *pxmitframe)
1992 {
1993 unsigned long irql;
1994 int ret = false;
1995 struct sta_info *psta = NULL;
1996 struct sta_priv *pstapriv = &padapter->stapriv;
1997 struct pkt_attrib *pattrib = &pxmitframe->attrib;
1998 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1999 int bmcst = IS_MCAST(pattrib->ra);
2000
2001 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == false)
2002 return ret;
2003
2004 if (pattrib->psta)
2005 psta = pattrib->psta;
2006 else
2007 psta = rtw_get_stainfo(pstapriv, pattrib->ra);
2008
2009 if (psta == NULL)
2010 return ret;
2011
2012 if (pattrib->triggered == 1) {
2013 if (bmcst)
2014 pattrib->qsel = 0x11;/* HIQ */
2015 return ret;
2016 }
2017
2018 if (bmcst) {
2019 _enter_critical_bh(&psta->sleep_q.lock, &irql);
2020
2021 if (pstapriv->sta_dz_bitmap) {/* if any one sta is in ps mode */
2022 rtw_list_delete(&pxmitframe->list);
2023
2024 rtw_list_insert_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
2025
2026 psta->sleepq_len++;
2027
2028 pstapriv->tim_bitmap |= BIT(0);/* */
2029 pstapriv->sta_dz_bitmap |= BIT(0);
2030
2031 update_beacon(padapter, _TIM_IE_, NULL, false);/* tx bc/mc packets after upate bcn */
2032
2033 ret = true;
2034 }
2035
2036 _exit_critical_bh(&psta->sleep_q.lock, &irql);
2037
2038 return ret;
2039 }
2040
2041 _enter_critical_bh(&psta->sleep_q.lock, &irql);
2042
2043 if (psta->state&WIFI_SLEEP_STATE) {
2044 u8 wmmps_ac = 0;
2045
2046 if (pstapriv->sta_dz_bitmap&BIT(psta->aid)) {
2047 rtw_list_delete(&pxmitframe->list);
2048
2049 rtw_list_insert_tail(&pxmitframe->list, get_list_head(&psta->sleep_q));
2050
2051 psta->sleepq_len++;
2052
2053 switch (pattrib->priority) {
2054 case 1:
2055 case 2:
2056 wmmps_ac = psta->uapsd_bk&BIT(0);
2057 break;
2058 case 4:
2059 case 5:
2060 wmmps_ac = psta->uapsd_vi&BIT(0);
2061 break;
2062 case 6:
2063 case 7:
2064 wmmps_ac = psta->uapsd_vo&BIT(0);
2065 break;
2066 case 0:
2067 case 3:
2068 default:
2069 wmmps_ac = psta->uapsd_be&BIT(0);
2070 break;
2071 }
2072
2073 if (wmmps_ac)
2074 psta->sleepq_ac_len++;
2075
2076 if (((psta->has_legacy_ac) && (!wmmps_ac)) ||
2077 ((!psta->has_legacy_ac) && (wmmps_ac))) {
2078 pstapriv->tim_bitmap |= BIT(psta->aid);
2079
2080 if (psta->sleepq_len == 1) {
2081 /* upate BCN for TIM IE */
2082 update_beacon(padapter, _TIM_IE_, NULL, false);
2083 }
2084 }
2085 ret = true;
2086 }
2087 }
2088
2089 _exit_critical_bh(&psta->sleep_q.lock, &irql);
2090
2091 return ret;
2092 }
2093
2094 static void dequeue_xmitframes_to_sleeping_queue(struct adapter *padapter, struct sta_info *psta, struct __queue *pframequeue)
2095 {
2096 struct list_head *plist, *phead;
2097 u8 ac_index;
2098 struct tx_servq *ptxservq;
2099 struct pkt_attrib *pattrib;
2100 struct xmit_frame *pxmitframe;
2101 struct hw_xmit *phwxmits = padapter->xmitpriv.hwxmits;
2102
2103 phead = get_list_head(pframequeue);
2104 plist = get_next(phead);
2105
2106 while (!rtw_end_of_queue_search(phead, plist)) {
2107 pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
2108
2109 plist = get_next(plist);
2110
2111 xmitframe_enqueue_for_sleeping_sta(padapter, pxmitframe);
2112
2113 pattrib = &pxmitframe->attrib;
2114
2115 ptxservq = rtw_get_sta_pending(padapter, psta, pattrib->priority, (u8 *)(&ac_index));
2116
2117 ptxservq->qcnt--;
2118 phwxmits[ac_index].accnt--;
2119 }
2120 }
2121
2122 void stop_sta_xmit(struct adapter *padapter, struct sta_info *psta)
2123 {
2124 unsigned long irql0;
2125 struct sta_info *psta_bmc;
2126 struct sta_xmit_priv *pstaxmitpriv;
2127 struct sta_priv *pstapriv = &padapter->stapriv;
2128 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
2129
2130 pstaxmitpriv = &psta->sta_xmitpriv;
2131
2132 /* for BC/MC Frames */
2133 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2134
2135 _enter_critical_bh(&pxmitpriv->lock, &irql0);
2136
2137 psta->state |= WIFI_SLEEP_STATE;
2138
2139 pstapriv->sta_dz_bitmap |= BIT(psta->aid);
2140
2141 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vo_q.sta_pending);
2142 rtw_list_delete(&(pstaxmitpriv->vo_q.tx_pending));
2143
2144 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->vi_q.sta_pending);
2145 rtw_list_delete(&(pstaxmitpriv->vi_q.tx_pending));
2146
2147 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->be_q.sta_pending);
2148 rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
2149
2150 dequeue_xmitframes_to_sleeping_queue(padapter, psta, &pstaxmitpriv->bk_q.sta_pending);
2151 rtw_list_delete(&(pstaxmitpriv->bk_q.tx_pending));
2152
2153 /* for BC/MC Frames */
2154 pstaxmitpriv = &psta_bmc->sta_xmitpriv;
2155 dequeue_xmitframes_to_sleeping_queue(padapter, psta_bmc, &pstaxmitpriv->be_q.sta_pending);
2156 rtw_list_delete(&(pstaxmitpriv->be_q.tx_pending));
2157
2158 _exit_critical_bh(&pxmitpriv->lock, &irql0);
2159 }
2160
2161 void wakeup_sta_to_xmit(struct adapter *padapter, struct sta_info *psta)
2162 {
2163 unsigned long irql;
2164 u8 update_mask = 0, wmmps_ac = 0;
2165 struct sta_info *psta_bmc;
2166 struct list_head *xmitframe_plist, *xmitframe_phead;
2167 struct xmit_frame *pxmitframe = NULL;
2168 struct sta_priv *pstapriv = &padapter->stapriv;
2169
2170 _enter_critical_bh(&psta->sleep_q.lock, &irql);
2171
2172 xmitframe_phead = get_list_head(&psta->sleep_q);
2173 xmitframe_plist = get_next(xmitframe_phead);
2174
2175 while (!rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) {
2176 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2177
2178 xmitframe_plist = get_next(xmitframe_plist);
2179
2180 rtw_list_delete(&pxmitframe->list);
2181
2182 switch (pxmitframe->attrib.priority) {
2183 case 1:
2184 case 2:
2185 wmmps_ac = psta->uapsd_bk&BIT(1);
2186 break;
2187 case 4:
2188 case 5:
2189 wmmps_ac = psta->uapsd_vi&BIT(1);
2190 break;
2191 case 6:
2192 case 7:
2193 wmmps_ac = psta->uapsd_vo&BIT(1);
2194 break;
2195 case 0:
2196 case 3:
2197 default:
2198 wmmps_ac = psta->uapsd_be&BIT(1);
2199 break;
2200 }
2201
2202 psta->sleepq_len--;
2203 if (psta->sleepq_len > 0)
2204 pxmitframe->attrib.mdata = 1;
2205 else
2206 pxmitframe->attrib.mdata = 0;
2207
2208 if (wmmps_ac) {
2209 psta->sleepq_ac_len--;
2210 if (psta->sleepq_ac_len > 0) {
2211 pxmitframe->attrib.mdata = 1;
2212 pxmitframe->attrib.eosp = 0;
2213 } else {
2214 pxmitframe->attrib.mdata = 0;
2215 pxmitframe->attrib.eosp = 1;
2216 }
2217 }
2218
2219 pxmitframe->attrib.triggered = 1;
2220
2221 _exit_critical_bh(&psta->sleep_q.lock, &irql);
2222 if (rtw_hal_xmit(padapter, pxmitframe))
2223 rtw_os_xmit_complete(padapter, pxmitframe);
2224 _enter_critical_bh(&psta->sleep_q.lock, &irql);
2225 }
2226
2227 if (psta->sleepq_len == 0) {
2228 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2229
2230 update_mask = BIT(0);
2231
2232 if (psta->state&WIFI_SLEEP_STATE)
2233 psta->state ^= WIFI_SLEEP_STATE;
2234
2235 if (psta->state & WIFI_STA_ALIVE_CHK_STATE) {
2236 psta->expire_to = pstapriv->expire_to;
2237 psta->state ^= WIFI_STA_ALIVE_CHK_STATE;
2238 }
2239
2240 pstapriv->sta_dz_bitmap &= ~BIT(psta->aid);
2241 }
2242
2243 _exit_critical_bh(&psta->sleep_q.lock, &irql);
2244
2245 /* for BC/MC Frames */
2246 psta_bmc = rtw_get_bcmc_stainfo(padapter);
2247 if (!psta_bmc)
2248 return;
2249
2250 if ((pstapriv->sta_dz_bitmap&0xfffe) == 0x0) { /* no any sta in ps mode */
2251 _enter_critical_bh(&psta_bmc->sleep_q.lock, &irql);
2252
2253 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
2254 xmitframe_plist = get_next(xmitframe_phead);
2255
2256 while (!rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) {
2257 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2258
2259 xmitframe_plist = get_next(xmitframe_plist);
2260
2261 rtw_list_delete(&pxmitframe->list);
2262
2263 psta_bmc->sleepq_len--;
2264 if (psta_bmc->sleepq_len > 0)
2265 pxmitframe->attrib.mdata = 1;
2266 else
2267 pxmitframe->attrib.mdata = 0;
2268
2269 pxmitframe->attrib.triggered = 1;
2270
2271 _exit_critical_bh(&psta_bmc->sleep_q.lock, &irql);
2272 if (rtw_hal_xmit(padapter, pxmitframe))
2273 rtw_os_xmit_complete(padapter, pxmitframe);
2274 _enter_critical_bh(&psta_bmc->sleep_q.lock, &irql);
2275 }
2276
2277 if (psta_bmc->sleepq_len == 0) {
2278 pstapriv->tim_bitmap &= ~BIT(0);
2279 pstapriv->sta_dz_bitmap &= ~BIT(0);
2280
2281 update_mask |= BIT(1);
2282 }
2283
2284 _exit_critical_bh(&psta_bmc->sleep_q.lock, &irql);
2285 }
2286
2287 if (update_mask)
2288 update_beacon(padapter, _TIM_IE_, NULL, false);
2289 }
2290
2291 void xmit_delivery_enabled_frames(struct adapter *padapter, struct sta_info *psta)
2292 {
2293 unsigned long irql;
2294 u8 wmmps_ac = 0;
2295 struct list_head *xmitframe_plist, *xmitframe_phead;
2296 struct xmit_frame *pxmitframe = NULL;
2297 struct sta_priv *pstapriv = &padapter->stapriv;
2298
2299 _enter_critical_bh(&psta->sleep_q.lock, &irql);
2300
2301 xmitframe_phead = get_list_head(&psta->sleep_q);
2302 xmitframe_plist = get_next(xmitframe_phead);
2303
2304 while (!rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) {
2305 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2306
2307 xmitframe_plist = get_next(xmitframe_plist);
2308
2309 switch (pxmitframe->attrib.priority) {
2310 case 1:
2311 case 2:
2312 wmmps_ac = psta->uapsd_bk&BIT(1);
2313 break;
2314 case 4:
2315 case 5:
2316 wmmps_ac = psta->uapsd_vi&BIT(1);
2317 break;
2318 case 6:
2319 case 7:
2320 wmmps_ac = psta->uapsd_vo&BIT(1);
2321 break;
2322 case 0:
2323 case 3:
2324 default:
2325 wmmps_ac = psta->uapsd_be&BIT(1);
2326 break;
2327 }
2328
2329 if (!wmmps_ac)
2330 continue;
2331
2332 rtw_list_delete(&pxmitframe->list);
2333
2334 psta->sleepq_len--;
2335 psta->sleepq_ac_len--;
2336
2337 if (psta->sleepq_ac_len > 0) {
2338 pxmitframe->attrib.mdata = 1;
2339 pxmitframe->attrib.eosp = 0;
2340 } else {
2341 pxmitframe->attrib.mdata = 0;
2342 pxmitframe->attrib.eosp = 1;
2343 }
2344
2345 pxmitframe->attrib.triggered = 1;
2346
2347 if (rtw_hal_xmit(padapter, pxmitframe) == true)
2348 rtw_os_xmit_complete(padapter, pxmitframe);
2349
2350 if ((psta->sleepq_ac_len == 0) && (!psta->has_legacy_ac) && (wmmps_ac)) {
2351 pstapriv->tim_bitmap &= ~BIT(psta->aid);
2352
2353 /* upate BCN for TIM IE */
2354 update_beacon(padapter, _TIM_IE_, NULL, false);
2355 }
2356 }
2357
2358 _exit_critical_bh(&psta->sleep_q.lock, &irql);
2359 }
2360
2361 #endif
2362
2363 void rtw_sctx_init(struct submit_ctx *sctx, int timeout_ms)
2364 {
2365 sctx->timeout_ms = timeout_ms;
2366 sctx->submit_time = rtw_get_current_time();
2367 init_completion(&sctx->done);
2368 sctx->status = RTW_SCTX_SUBMITTED;
2369 }
2370
2371 int rtw_sctx_wait(struct submit_ctx *sctx)
2372 {
2373 int ret = _FAIL;
2374 unsigned long expire;
2375 int status = 0;
2376
2377 expire = sctx->timeout_ms ? msecs_to_jiffies(sctx->timeout_ms) : MAX_SCHEDULE_TIMEOUT;
2378 if (!wait_for_completion_timeout(&sctx->done, expire)) {
2379 /* timeout, do something?? */
2380 status = RTW_SCTX_DONE_TIMEOUT;
2381 DBG_88E("%s timeout\n", __func__);
2382 } else {
2383 status = sctx->status;
2384 }
2385
2386 if (status == RTW_SCTX_DONE_SUCCESS)
2387 ret = _SUCCESS;
2388
2389 return ret;
2390 }
2391
2392 static bool rtw_sctx_chk_waring_status(int status)
2393 {
2394 switch (status) {
2395 case RTW_SCTX_DONE_UNKNOWN:
2396 case RTW_SCTX_DONE_BUF_ALLOC:
2397 case RTW_SCTX_DONE_BUF_FREE:
2398
2399 case RTW_SCTX_DONE_DRV_STOP:
2400 case RTW_SCTX_DONE_DEV_REMOVE:
2401 return true;
2402 default:
2403 return false;
2404 }
2405 }
2406
2407 void rtw_sctx_done_err(struct submit_ctx **sctx, int status)
2408 {
2409 if (*sctx) {
2410 if (rtw_sctx_chk_waring_status(status))
2411 DBG_88E("%s status:%d\n", __func__, status);
2412 (*sctx)->status = status;
2413 complete(&((*sctx)->done));
2414 *sctx = NULL;
2415 }
2416 }
2417
2418 void rtw_sctx_done(struct submit_ctx **sctx)
2419 {
2420 rtw_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS);
2421 }
2422
2423 int rtw_ack_tx_wait(struct xmit_priv *pxmitpriv, u32 timeout_ms)
2424 {
2425 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2426
2427 pack_tx_ops->submit_time = rtw_get_current_time();
2428 pack_tx_ops->timeout_ms = timeout_ms;
2429 pack_tx_ops->status = RTW_SCTX_SUBMITTED;
2430
2431 return rtw_sctx_wait(pack_tx_ops);
2432 }
2433
2434 void rtw_ack_tx_done(struct xmit_priv *pxmitpriv, int status)
2435 {
2436 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
2437
2438 if (pxmitpriv->ack_tx)
2439 rtw_sctx_done_err(&pack_tx_ops, status);
2440 else
2441 DBG_88E("%s ack_tx not set\n", __func__);
2442 }