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