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