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