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