Commit | Line | Data |
---|---|---|
bdcd8170 KV |
1 | /* |
2 | * Copyright (c) 2004-2011 Atheros Communications Inc. | |
1b2df407 | 3 | * Copyright (c) 2011-2012 Qualcomm Atheros, Inc. |
bdcd8170 KV |
4 | * |
5 | * Permission to use, copy, modify, and/or distribute this software for any | |
6 | * purpose with or without fee is hereby granted, provided that the above | |
7 | * copyright notice and this permission notice appear in all copies. | |
8 | * | |
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
16 | */ | |
17 | ||
18 | #include "core.h" | |
19 | #include "debug.h" | |
20 | ||
3fdc0991 VT |
21 | /* |
22 | * tid - tid_mux0..tid_mux3 | |
23 | * aid - tid_mux4..tid_mux7 | |
24 | */ | |
25 | #define ATH6KL_TID_MASK 0xf | |
1d2a4456 | 26 | #define ATH6KL_AID_SHIFT 4 |
3fdc0991 VT |
27 | |
28 | static inline u8 ath6kl_get_tid(u8 tid_mux) | |
29 | { | |
30 | return tid_mux & ATH6KL_TID_MASK; | |
31 | } | |
32 | ||
1d2a4456 VT |
33 | static inline u8 ath6kl_get_aid(u8 tid_mux) |
34 | { | |
35 | return tid_mux >> ATH6KL_AID_SHIFT; | |
36 | } | |
37 | ||
bdcd8170 KV |
38 | static u8 ath6kl_ibss_map_epid(struct sk_buff *skb, struct net_device *dev, |
39 | u32 *map_no) | |
40 | { | |
41 | struct ath6kl *ar = ath6kl_priv(dev); | |
42 | struct ethhdr *eth_hdr; | |
43 | u32 i, ep_map = -1; | |
44 | u8 *datap; | |
45 | ||
46 | *map_no = 0; | |
47 | datap = skb->data; | |
48 | eth_hdr = (struct ethhdr *) (datap + sizeof(struct wmi_data_hdr)); | |
49 | ||
50 | if (is_multicast_ether_addr(eth_hdr->h_dest)) | |
51 | return ENDPOINT_2; | |
52 | ||
53 | for (i = 0; i < ar->node_num; i++) { | |
54 | if (memcmp(eth_hdr->h_dest, ar->node_map[i].mac_addr, | |
55 | ETH_ALEN) == 0) { | |
56 | *map_no = i + 1; | |
57 | ar->node_map[i].tx_pend++; | |
58 | return ar->node_map[i].ep_id; | |
59 | } | |
60 | ||
61 | if ((ep_map == -1) && !ar->node_map[i].tx_pend) | |
62 | ep_map = i; | |
63 | } | |
64 | ||
65 | if (ep_map == -1) { | |
66 | ep_map = ar->node_num; | |
67 | ar->node_num++; | |
68 | if (ar->node_num > MAX_NODE_NUM) | |
69 | return ENDPOINT_UNUSED; | |
70 | } | |
71 | ||
72 | memcpy(ar->node_map[ep_map].mac_addr, eth_hdr->h_dest, ETH_ALEN); | |
73 | ||
74 | for (i = ENDPOINT_2; i <= ENDPOINT_5; i++) { | |
75 | if (!ar->tx_pending[i]) { | |
76 | ar->node_map[ep_map].ep_id = i; | |
77 | break; | |
78 | } | |
79 | ||
80 | /* | |
81 | * No free endpoint is available, start redistribution on | |
82 | * the inuse endpoints. | |
83 | */ | |
84 | if (i == ENDPOINT_5) { | |
85 | ar->node_map[ep_map].ep_id = ar->next_ep_id; | |
86 | ar->next_ep_id++; | |
87 | if (ar->next_ep_id > ENDPOINT_5) | |
88 | ar->next_ep_id = ENDPOINT_2; | |
89 | } | |
90 | } | |
91 | ||
92 | *map_no = ep_map + 1; | |
93 | ar->node_map[ep_map].tx_pend++; | |
94 | ||
95 | return ar->node_map[ep_map].ep_id; | |
96 | } | |
97 | ||
c1762a3f TP |
98 | static bool ath6kl_process_uapsdq(struct ath6kl_sta *conn, |
99 | struct ath6kl_vif *vif, | |
100 | struct sk_buff *skb, | |
101 | u32 *flags) | |
102 | { | |
103 | struct ath6kl *ar = vif->ar; | |
104 | bool is_apsdq_empty = false; | |
105 | struct ethhdr *datap = (struct ethhdr *) skb->data; | |
e5726028 | 106 | u8 up = 0, traffic_class, *ip_hdr; |
c1762a3f TP |
107 | u16 ether_type; |
108 | struct ath6kl_llc_snap_hdr *llc_hdr; | |
109 | ||
110 | if (conn->sta_flags & STA_PS_APSD_TRIGGER) { | |
111 | /* | |
112 | * This tx is because of a uAPSD trigger, determine | |
113 | * more and EOSP bit. Set EOSP if queue is empty | |
114 | * or sufficient frames are delivered for this trigger. | |
115 | */ | |
116 | spin_lock_bh(&conn->psq_lock); | |
117 | if (!skb_queue_empty(&conn->apsdq)) | |
118 | *flags |= WMI_DATA_HDR_FLAGS_MORE; | |
119 | else if (conn->sta_flags & STA_PS_APSD_EOSP) | |
120 | *flags |= WMI_DATA_HDR_FLAGS_EOSP; | |
121 | *flags |= WMI_DATA_HDR_FLAGS_UAPSD; | |
122 | spin_unlock_bh(&conn->psq_lock); | |
123 | return false; | |
124 | } else if (!conn->apsd_info) | |
125 | return false; | |
126 | ||
127 | if (test_bit(WMM_ENABLED, &vif->flags)) { | |
128 | ether_type = be16_to_cpu(datap->h_proto); | |
129 | if (is_ethertype(ether_type)) { | |
130 | /* packet is in DIX format */ | |
131 | ip_hdr = (u8 *)(datap + 1); | |
132 | } else { | |
133 | /* packet is in 802.3 format */ | |
134 | llc_hdr = (struct ath6kl_llc_snap_hdr *) | |
135 | (datap + 1); | |
136 | ether_type = be16_to_cpu(llc_hdr->eth_type); | |
137 | ip_hdr = (u8 *)(llc_hdr + 1); | |
138 | } | |
139 | ||
140 | if (ether_type == IP_ETHERTYPE) | |
141 | up = ath6kl_wmi_determine_user_priority( | |
142 | ip_hdr, 0); | |
c1762a3f TP |
143 | } |
144 | ||
145 | traffic_class = ath6kl_wmi_get_traffic_class(up); | |
146 | ||
147 | if ((conn->apsd_info & (1 << traffic_class)) == 0) | |
148 | return false; | |
149 | ||
150 | /* Queue the frames if the STA is sleeping */ | |
151 | spin_lock_bh(&conn->psq_lock); | |
152 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); | |
153 | skb_queue_tail(&conn->apsdq, skb); | |
154 | spin_unlock_bh(&conn->psq_lock); | |
155 | ||
156 | /* | |
157 | * If this is the first pkt getting queued | |
158 | * for this STA, update the PVB for this STA | |
159 | */ | |
160 | if (is_apsdq_empty) { | |
161 | ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi, | |
162 | vif->fw_vif_idx, | |
163 | conn->aid, 1, 0); | |
164 | } | |
165 | *flags |= WMI_DATA_HDR_FLAGS_UAPSD; | |
166 | ||
167 | return true; | |
168 | } | |
169 | ||
170 | static bool ath6kl_process_psq(struct ath6kl_sta *conn, | |
171 | struct ath6kl_vif *vif, | |
172 | struct sk_buff *skb, | |
173 | u32 *flags) | |
174 | { | |
175 | bool is_psq_empty = false; | |
176 | struct ath6kl *ar = vif->ar; | |
177 | ||
178 | if (conn->sta_flags & STA_PS_POLLED) { | |
179 | spin_lock_bh(&conn->psq_lock); | |
180 | if (!skb_queue_empty(&conn->psq)) | |
181 | *flags |= WMI_DATA_HDR_FLAGS_MORE; | |
182 | spin_unlock_bh(&conn->psq_lock); | |
183 | return false; | |
184 | } | |
185 | ||
186 | /* Queue the frames if the STA is sleeping */ | |
187 | spin_lock_bh(&conn->psq_lock); | |
188 | is_psq_empty = skb_queue_empty(&conn->psq); | |
189 | skb_queue_tail(&conn->psq, skb); | |
190 | spin_unlock_bh(&conn->psq_lock); | |
191 | ||
192 | /* | |
193 | * If this is the first pkt getting queued | |
194 | * for this STA, update the PVB for this | |
195 | * STA. | |
196 | */ | |
197 | if (is_psq_empty) | |
198 | ath6kl_wmi_set_pvb_cmd(ar->wmi, | |
199 | vif->fw_vif_idx, | |
200 | conn->aid, 1); | |
201 | return true; | |
202 | } | |
203 | ||
6765d0aa | 204 | static bool ath6kl_powersave_ap(struct ath6kl_vif *vif, struct sk_buff *skb, |
c1762a3f | 205 | u32 *flags) |
bdcd8170 KV |
206 | { |
207 | struct ethhdr *datap = (struct ethhdr *) skb->data; | |
208 | struct ath6kl_sta *conn = NULL; | |
c1762a3f | 209 | bool ps_queued = false; |
6765d0aa | 210 | struct ath6kl *ar = vif->ar; |
bdcd8170 KV |
211 | |
212 | if (is_multicast_ether_addr(datap->h_dest)) { | |
213 | u8 ctr = 0; | |
214 | bool q_mcast = false; | |
215 | ||
216 | for (ctr = 0; ctr < AP_MAX_NUM_STA; ctr++) { | |
217 | if (ar->sta_list[ctr].sta_flags & STA_PS_SLEEP) { | |
218 | q_mcast = true; | |
219 | break; | |
220 | } | |
221 | } | |
222 | ||
223 | if (q_mcast) { | |
224 | /* | |
225 | * If this transmit is not because of a Dtim Expiry | |
226 | * q it. | |
227 | */ | |
59c98449 | 228 | if (!test_bit(DTIM_EXPIRED, &vif->flags)) { |
bdcd8170 KV |
229 | bool is_mcastq_empty = false; |
230 | ||
231 | spin_lock_bh(&ar->mcastpsq_lock); | |
232 | is_mcastq_empty = | |
233 | skb_queue_empty(&ar->mcastpsq); | |
234 | skb_queue_tail(&ar->mcastpsq, skb); | |
235 | spin_unlock_bh(&ar->mcastpsq_lock); | |
236 | ||
237 | /* | |
238 | * If this is the first Mcast pkt getting | |
239 | * queued indicate to the target to set the | |
240 | * BitmapControl LSB of the TIM IE. | |
241 | */ | |
242 | if (is_mcastq_empty) | |
243 | ath6kl_wmi_set_pvb_cmd(ar->wmi, | |
334234b5 | 244 | vif->fw_vif_idx, |
bdcd8170 KV |
245 | MCAST_AID, 1); |
246 | ||
247 | ps_queued = true; | |
248 | } else { | |
249 | /* | |
250 | * This transmit is because of Dtim expiry. | |
251 | * Determine if MoreData bit has to be set. | |
252 | */ | |
253 | spin_lock_bh(&ar->mcastpsq_lock); | |
254 | if (!skb_queue_empty(&ar->mcastpsq)) | |
c1762a3f | 255 | *flags |= WMI_DATA_HDR_FLAGS_MORE; |
bdcd8170 KV |
256 | spin_unlock_bh(&ar->mcastpsq_lock); |
257 | } | |
258 | } | |
259 | } else { | |
6765d0aa | 260 | conn = ath6kl_find_sta(vif, datap->h_dest); |
bdcd8170 KV |
261 | if (!conn) { |
262 | dev_kfree_skb(skb); | |
263 | ||
264 | /* Inform the caller that the skb is consumed */ | |
265 | return true; | |
266 | } | |
267 | ||
268 | if (conn->sta_flags & STA_PS_SLEEP) { | |
c1762a3f TP |
269 | ps_queued = ath6kl_process_uapsdq(conn, |
270 | vif, skb, flags); | |
271 | if (!(*flags & WMI_DATA_HDR_FLAGS_UAPSD)) | |
272 | ps_queued = ath6kl_process_psq(conn, | |
273 | vif, skb, flags); | |
bdcd8170 KV |
274 | } |
275 | } | |
bdcd8170 KV |
276 | return ps_queued; |
277 | } | |
278 | ||
279 | /* Tx functions */ | |
280 | ||
281 | int ath6kl_control_tx(void *devt, struct sk_buff *skb, | |
282 | enum htc_endpoint_id eid) | |
283 | { | |
284 | struct ath6kl *ar = devt; | |
285 | int status = 0; | |
286 | struct ath6kl_cookie *cookie = NULL; | |
287 | ||
390a8c8f RM |
288 | if (WARN_ON_ONCE(ar->state == ATH6KL_STATE_WOW)) |
289 | return -EACCES; | |
290 | ||
bdcd8170 KV |
291 | spin_lock_bh(&ar->lock); |
292 | ||
293 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, | |
294 | "%s: skb=0x%p, len=0x%x eid =%d\n", __func__, | |
295 | skb, skb->len, eid); | |
296 | ||
297 | if (test_bit(WMI_CTRL_EP_FULL, &ar->flag) && (eid == ar->ctrl_ep)) { | |
298 | /* | |
299 | * Control endpoint is full, don't allocate resources, we | |
300 | * are just going to drop this packet. | |
301 | */ | |
302 | cookie = NULL; | |
303 | ath6kl_err("wmi ctrl ep full, dropping pkt : 0x%p, len:%d\n", | |
304 | skb, skb->len); | |
305 | } else | |
306 | cookie = ath6kl_alloc_cookie(ar); | |
307 | ||
308 | if (cookie == NULL) { | |
309 | spin_unlock_bh(&ar->lock); | |
310 | status = -ENOMEM; | |
311 | goto fail_ctrl_tx; | |
312 | } | |
313 | ||
314 | ar->tx_pending[eid]++; | |
315 | ||
316 | if (eid != ar->ctrl_ep) | |
317 | ar->total_tx_data_pend++; | |
318 | ||
319 | spin_unlock_bh(&ar->lock); | |
320 | ||
321 | cookie->skb = skb; | |
322 | cookie->map_no = 0; | |
323 | set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len, | |
324 | eid, ATH6KL_CONTROL_PKT_TAG); | |
325 | ||
326 | /* | |
327 | * This interface is asynchronous, if there is an error, cleanup | |
328 | * will happen in the TX completion callback. | |
329 | */ | |
ad226ec2 | 330 | ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt); |
bdcd8170 KV |
331 | |
332 | return 0; | |
333 | ||
334 | fail_ctrl_tx: | |
335 | dev_kfree_skb(skb); | |
336 | return status; | |
337 | } | |
338 | ||
339 | int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev) | |
340 | { | |
341 | struct ath6kl *ar = ath6kl_priv(dev); | |
342 | struct ath6kl_cookie *cookie = NULL; | |
343 | enum htc_endpoint_id eid = ENDPOINT_UNUSED; | |
59c98449 | 344 | struct ath6kl_vif *vif = netdev_priv(dev); |
bdcd8170 KV |
345 | u32 map_no = 0; |
346 | u16 htc_tag = ATH6KL_DATA_PKT_TAG; | |
347 | u8 ac = 99 ; /* initialize to unmapped ac */ | |
c1762a3f | 348 | bool chk_adhoc_ps_mapping = false; |
bdcd8170 | 349 | int ret; |
bc48ad31 RP |
350 | struct wmi_tx_meta_v2 meta_v2; |
351 | void *meta; | |
352 | u8 csum_start = 0, csum_dest = 0, csum = skb->ip_summed; | |
353 | u8 meta_ver = 0; | |
c1762a3f | 354 | u32 flags = 0; |
bdcd8170 KV |
355 | |
356 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, | |
357 | "%s: skb=0x%p, data=0x%p, len=0x%x\n", __func__, | |
358 | skb, skb->data, skb->len); | |
359 | ||
360 | /* If target is not associated */ | |
59c98449 | 361 | if (!test_bit(CONNECTED, &vif->flags)) { |
bdcd8170 KV |
362 | dev_kfree_skb(skb); |
363 | return 0; | |
364 | } | |
365 | ||
390a8c8f RM |
366 | if (WARN_ON_ONCE(ar->state != ATH6KL_STATE_ON)) { |
367 | dev_kfree_skb(skb); | |
368 | return 0; | |
369 | } | |
370 | ||
bdcd8170 KV |
371 | if (!test_bit(WMI_READY, &ar->flag)) |
372 | goto fail_tx; | |
373 | ||
374 | /* AP mode Power saving processing */ | |
f5938f24 | 375 | if (vif->nw_type == AP_NETWORK) { |
c1762a3f | 376 | if (ath6kl_powersave_ap(vif, skb, &flags)) |
bdcd8170 KV |
377 | return 0; |
378 | } | |
379 | ||
380 | if (test_bit(WMI_ENABLED, &ar->flag)) { | |
bc48ad31 RP |
381 | if ((dev->features & NETIF_F_IP_CSUM) && |
382 | (csum == CHECKSUM_PARTIAL)) { | |
383 | csum_start = skb->csum_start - | |
384 | (skb_network_header(skb) - skb->head) + | |
385 | sizeof(struct ath6kl_llc_snap_hdr); | |
386 | csum_dest = skb->csum_offset + csum_start; | |
387 | } | |
388 | ||
bdcd8170 | 389 | if (skb_headroom(skb) < dev->needed_headroom) { |
a29517ce VT |
390 | struct sk_buff *tmp_skb = skb; |
391 | ||
392 | skb = skb_realloc_headroom(skb, dev->needed_headroom); | |
393 | kfree_skb(tmp_skb); | |
394 | if (skb == NULL) { | |
395 | vif->net_stats.tx_dropped++; | |
396 | return 0; | |
397 | } | |
bdcd8170 KV |
398 | } |
399 | ||
400 | if (ath6kl_wmi_dix_2_dot3(ar->wmi, skb)) { | |
401 | ath6kl_err("ath6kl_wmi_dix_2_dot3 failed\n"); | |
402 | goto fail_tx; | |
403 | } | |
404 | ||
bc48ad31 RP |
405 | if ((dev->features & NETIF_F_IP_CSUM) && |
406 | (csum == CHECKSUM_PARTIAL)) { | |
407 | meta_v2.csum_start = csum_start; | |
408 | meta_v2.csum_dest = csum_dest; | |
409 | ||
410 | /* instruct target to calculate checksum */ | |
411 | meta_v2.csum_flags = WMI_META_V2_FLAG_CSUM_OFFLOAD; | |
412 | meta_ver = WMI_META_VERSION_2; | |
413 | meta = &meta_v2; | |
414 | } else { | |
415 | meta_ver = 0; | |
416 | meta = NULL; | |
417 | } | |
418 | ||
419 | ret = ath6kl_wmi_data_hdr_add(ar->wmi, skb, | |
c1762a3f | 420 | DATA_MSGTYPE, flags, 0, |
bc48ad31 RP |
421 | meta_ver, |
422 | meta, vif->fw_vif_idx); | |
423 | ||
424 | if (ret) { | |
425 | ath6kl_warn("failed to add wmi data header:%d\n" | |
426 | , ret); | |
bdcd8170 KV |
427 | goto fail_tx; |
428 | } | |
429 | ||
f5938f24 | 430 | if ((vif->nw_type == ADHOC_NETWORK) && |
59c98449 | 431 | ar->ibss_ps_enable && test_bit(CONNECTED, &vif->flags)) |
bdcd8170 KV |
432 | chk_adhoc_ps_mapping = true; |
433 | else { | |
434 | /* get the stream mapping */ | |
240d2799 VT |
435 | ret = ath6kl_wmi_implicit_create_pstream(ar->wmi, |
436 | vif->fw_vif_idx, skb, | |
59c98449 | 437 | 0, test_bit(WMM_ENABLED, &vif->flags), &ac); |
bdcd8170 KV |
438 | if (ret) |
439 | goto fail_tx; | |
440 | } | |
441 | } else | |
442 | goto fail_tx; | |
443 | ||
444 | spin_lock_bh(&ar->lock); | |
445 | ||
446 | if (chk_adhoc_ps_mapping) | |
447 | eid = ath6kl_ibss_map_epid(skb, dev, &map_no); | |
448 | else | |
449 | eid = ar->ac2ep_map[ac]; | |
450 | ||
451 | if (eid == 0 || eid == ENDPOINT_UNUSED) { | |
452 | ath6kl_err("eid %d is not mapped!\n", eid); | |
453 | spin_unlock_bh(&ar->lock); | |
454 | goto fail_tx; | |
455 | } | |
456 | ||
457 | /* allocate resource for this packet */ | |
458 | cookie = ath6kl_alloc_cookie(ar); | |
459 | ||
460 | if (!cookie) { | |
461 | spin_unlock_bh(&ar->lock); | |
462 | goto fail_tx; | |
463 | } | |
464 | ||
465 | /* update counts while the lock is held */ | |
466 | ar->tx_pending[eid]++; | |
467 | ar->total_tx_data_pend++; | |
468 | ||
469 | spin_unlock_bh(&ar->lock); | |
470 | ||
00b1edf1 JM |
471 | if (!IS_ALIGNED((unsigned long) skb->data - HTC_HDR_LENGTH, 4) && |
472 | skb_cloned(skb)) { | |
473 | /* | |
474 | * We will touch (move the buffer data to align it. Since the | |
475 | * skb buffer is cloned and not only the header is changed, we | |
476 | * have to copy it to allow the changes. Since we are copying | |
477 | * the data here, we may as well align it by reserving suitable | |
478 | * headroom to avoid the memmove in ath6kl_htc_tx_buf_align(). | |
479 | */ | |
480 | struct sk_buff *nskb; | |
481 | ||
482 | nskb = skb_copy_expand(skb, HTC_HDR_LENGTH, 0, GFP_ATOMIC); | |
483 | if (nskb == NULL) | |
484 | goto fail_tx; | |
485 | kfree_skb(skb); | |
486 | skb = nskb; | |
487 | } | |
488 | ||
bdcd8170 KV |
489 | cookie->skb = skb; |
490 | cookie->map_no = map_no; | |
491 | set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len, | |
492 | eid, htc_tag); | |
493 | ||
ef094103 KV |
494 | ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ", |
495 | skb->data, skb->len); | |
bdcd8170 KV |
496 | |
497 | /* | |
498 | * HTC interface is asynchronous, if this fails, cleanup will | |
499 | * happen in the ath6kl_tx_complete callback. | |
500 | */ | |
ad226ec2 | 501 | ath6kl_htc_tx(ar->htc_target, &cookie->htc_pkt); |
bdcd8170 KV |
502 | |
503 | return 0; | |
504 | ||
505 | fail_tx: | |
506 | dev_kfree_skb(skb); | |
507 | ||
b95907a7 VT |
508 | vif->net_stats.tx_dropped++; |
509 | vif->net_stats.tx_aborted_errors++; | |
bdcd8170 KV |
510 | |
511 | return 0; | |
512 | } | |
513 | ||
514 | /* indicate tx activity or inactivity on a WMI stream */ | |
515 | void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active) | |
516 | { | |
517 | struct ath6kl *ar = devt; | |
518 | enum htc_endpoint_id eid; | |
519 | int i; | |
520 | ||
521 | eid = ar->ac2ep_map[traffic_class]; | |
522 | ||
523 | if (!test_bit(WMI_ENABLED, &ar->flag)) | |
524 | goto notify_htc; | |
525 | ||
526 | spin_lock_bh(&ar->lock); | |
527 | ||
528 | ar->ac_stream_active[traffic_class] = active; | |
529 | ||
530 | if (active) { | |
531 | /* | |
532 | * Keep track of the active stream with the highest | |
533 | * priority. | |
534 | */ | |
535 | if (ar->ac_stream_pri_map[traffic_class] > | |
536 | ar->hiac_stream_active_pri) | |
537 | /* set the new highest active priority */ | |
538 | ar->hiac_stream_active_pri = | |
539 | ar->ac_stream_pri_map[traffic_class]; | |
540 | ||
541 | } else { | |
542 | /* | |
543 | * We may have to search for the next active stream | |
544 | * that is the highest priority. | |
545 | */ | |
546 | if (ar->hiac_stream_active_pri == | |
547 | ar->ac_stream_pri_map[traffic_class]) { | |
548 | /* | |
549 | * The highest priority stream just went inactive | |
550 | * reset and search for the "next" highest "active" | |
551 | * priority stream. | |
552 | */ | |
553 | ar->hiac_stream_active_pri = 0; | |
554 | ||
555 | for (i = 0; i < WMM_NUM_AC; i++) { | |
556 | if (ar->ac_stream_active[i] && | |
557 | (ar->ac_stream_pri_map[i] > | |
558 | ar->hiac_stream_active_pri)) | |
559 | /* | |
560 | * Set the new highest active | |
561 | * priority. | |
562 | */ | |
563 | ar->hiac_stream_active_pri = | |
564 | ar->ac_stream_pri_map[i]; | |
565 | } | |
566 | } | |
567 | } | |
568 | ||
569 | spin_unlock_bh(&ar->lock); | |
570 | ||
571 | notify_htc: | |
572 | /* notify HTC, this may cause credit distribution changes */ | |
ad226ec2 | 573 | ath6kl_htc_indicate_activity_change(ar->htc_target, eid, active); |
bdcd8170 KV |
574 | } |
575 | ||
576 | enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target, | |
577 | struct htc_packet *packet) | |
578 | { | |
579 | struct ath6kl *ar = target->dev->ar; | |
990bd915 | 580 | struct ath6kl_vif *vif; |
bdcd8170 | 581 | enum htc_endpoint_id endpoint = packet->endpoint; |
990bd915 | 582 | enum htc_send_full_action action = HTC_SEND_FULL_KEEP; |
bdcd8170 KV |
583 | |
584 | if (endpoint == ar->ctrl_ep) { | |
585 | /* | |
586 | * Under normal WMI if this is getting full, then something | |
587 | * is running rampant the host should not be exhausting the | |
588 | * WMI queue with too many commands the only exception to | |
589 | * this is during testing using endpointping. | |
590 | */ | |
bdcd8170 | 591 | set_bit(WMI_CTRL_EP_FULL, &ar->flag); |
bdcd8170 | 592 | ath6kl_err("wmi ctrl ep is full\n"); |
901db39c | 593 | return action; |
bdcd8170 KV |
594 | } |
595 | ||
596 | if (packet->info.tx.tag == ATH6KL_CONTROL_PKT_TAG) | |
901db39c | 597 | return action; |
bdcd8170 KV |
598 | |
599 | /* | |
600 | * The last MAX_HI_COOKIE_NUM "batch" of cookies are reserved for | |
601 | * the highest active stream. | |
602 | */ | |
603 | if (ar->ac_stream_pri_map[ar->ep2ac_map[endpoint]] < | |
604 | ar->hiac_stream_active_pri && | |
0ea10f2b CN |
605 | ar->cookie_count <= |
606 | target->endpoint[endpoint].tx_drop_packet_threshold) | |
bdcd8170 KV |
607 | /* |
608 | * Give preference to the highest priority stream by | |
609 | * dropping the packets which overflowed. | |
610 | */ | |
990bd915 | 611 | action = HTC_SEND_FULL_DROP; |
990bd915 | 612 | |
990bd915 | 613 | /* FIXME: Locking */ |
11f6e40d | 614 | spin_lock_bh(&ar->list_lock); |
990bd915 | 615 | list_for_each_entry(vif, &ar->vif_list, list) { |
901db39c VT |
616 | if (vif->nw_type == ADHOC_NETWORK || |
617 | action != HTC_SEND_FULL_DROP) { | |
11f6e40d | 618 | spin_unlock_bh(&ar->list_lock); |
bdcd8170 | 619 | |
990bd915 | 620 | set_bit(NETQ_STOPPED, &vif->flags); |
990bd915 | 621 | netif_stop_queue(vif->ndev); |
bdcd8170 | 622 | |
990bd915 VT |
623 | return action; |
624 | } | |
625 | } | |
11f6e40d | 626 | spin_unlock_bh(&ar->list_lock); |
990bd915 VT |
627 | |
628 | return action; | |
bdcd8170 KV |
629 | } |
630 | ||
631 | /* TODO this needs to be looked at */ | |
990bd915 | 632 | static void ath6kl_tx_clear_node_map(struct ath6kl_vif *vif, |
bdcd8170 KV |
633 | enum htc_endpoint_id eid, u32 map_no) |
634 | { | |
990bd915 | 635 | struct ath6kl *ar = vif->ar; |
bdcd8170 KV |
636 | u32 i; |
637 | ||
f5938f24 | 638 | if (vif->nw_type != ADHOC_NETWORK) |
bdcd8170 KV |
639 | return; |
640 | ||
641 | if (!ar->ibss_ps_enable) | |
642 | return; | |
643 | ||
644 | if (eid == ar->ctrl_ep) | |
645 | return; | |
646 | ||
647 | if (map_no == 0) | |
648 | return; | |
649 | ||
650 | map_no--; | |
651 | ar->node_map[map_no].tx_pend--; | |
652 | ||
653 | if (ar->node_map[map_no].tx_pend) | |
654 | return; | |
655 | ||
656 | if (map_no != (ar->node_num - 1)) | |
657 | return; | |
658 | ||
659 | for (i = ar->node_num; i > 0; i--) { | |
660 | if (ar->node_map[i - 1].tx_pend) | |
661 | break; | |
662 | ||
663 | memset(&ar->node_map[i - 1], 0, | |
664 | sizeof(struct ath6kl_node_mapping)); | |
665 | ar->node_num--; | |
666 | } | |
667 | } | |
668 | ||
669 | void ath6kl_tx_complete(void *context, struct list_head *packet_queue) | |
670 | { | |
671 | struct ath6kl *ar = context; | |
672 | struct sk_buff_head skb_queue; | |
673 | struct htc_packet *packet; | |
674 | struct sk_buff *skb; | |
675 | struct ath6kl_cookie *ath6kl_cookie; | |
676 | u32 map_no = 0; | |
677 | int status; | |
678 | enum htc_endpoint_id eid; | |
679 | bool wake_event = false; | |
71f96ee6 | 680 | bool flushing[ATH6KL_VIF_MAX] = {false}; |
6765d0aa | 681 | u8 if_idx; |
990bd915 | 682 | struct ath6kl_vif *vif; |
bdcd8170 KV |
683 | |
684 | skb_queue_head_init(&skb_queue); | |
685 | ||
686 | /* lock the driver as we update internal state */ | |
687 | spin_lock_bh(&ar->lock); | |
688 | ||
689 | /* reap completed packets */ | |
690 | while (!list_empty(packet_queue)) { | |
691 | ||
692 | packet = list_first_entry(packet_queue, struct htc_packet, | |
693 | list); | |
694 | list_del(&packet->list); | |
695 | ||
696 | ath6kl_cookie = (struct ath6kl_cookie *)packet->pkt_cntxt; | |
697 | if (!ath6kl_cookie) | |
698 | goto fatal; | |
699 | ||
700 | status = packet->status; | |
701 | skb = ath6kl_cookie->skb; | |
702 | eid = packet->endpoint; | |
703 | map_no = ath6kl_cookie->map_no; | |
704 | ||
705 | if (!skb || !skb->data) | |
706 | goto fatal; | |
707 | ||
bdcd8170 KV |
708 | __skb_queue_tail(&skb_queue, skb); |
709 | ||
710 | if (!status && (packet->act_len != skb->len)) | |
711 | goto fatal; | |
712 | ||
713 | ar->tx_pending[eid]--; | |
714 | ||
715 | if (eid != ar->ctrl_ep) | |
716 | ar->total_tx_data_pend--; | |
717 | ||
718 | if (eid == ar->ctrl_ep) { | |
719 | if (test_bit(WMI_CTRL_EP_FULL, &ar->flag)) | |
720 | clear_bit(WMI_CTRL_EP_FULL, &ar->flag); | |
721 | ||
722 | if (ar->tx_pending[eid] == 0) | |
723 | wake_event = true; | |
724 | } | |
725 | ||
6765d0aa VT |
726 | if (eid == ar->ctrl_ep) { |
727 | if_idx = wmi_cmd_hdr_get_if_idx( | |
f3803eb2 | 728 | (struct wmi_cmd_hdr *) packet->buf); |
6765d0aa VT |
729 | } else { |
730 | if_idx = wmi_data_hdr_get_if_idx( | |
f3803eb2 | 731 | (struct wmi_data_hdr *) packet->buf); |
6765d0aa VT |
732 | } |
733 | ||
734 | vif = ath6kl_get_vif_by_index(ar, if_idx); | |
735 | if (!vif) { | |
736 | ath6kl_free_cookie(ar, ath6kl_cookie); | |
737 | continue; | |
738 | } | |
739 | ||
bdcd8170 KV |
740 | if (status) { |
741 | if (status == -ECANCELED) | |
742 | /* a packet was flushed */ | |
990bd915 | 743 | flushing[if_idx] = true; |
bdcd8170 | 744 | |
b95907a7 | 745 | vif->net_stats.tx_errors++; |
bdcd8170 | 746 | |
778e6502 KV |
747 | if (status != -ENOSPC && status != -ECANCELED) |
748 | ath6kl_warn("tx complete error: %d\n", status); | |
749 | ||
bdcd8170 KV |
750 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, |
751 | "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n", | |
752 | __func__, skb, packet->buf, packet->act_len, | |
753 | eid, "error!"); | |
754 | } else { | |
755 | ath6kl_dbg(ATH6KL_DBG_WLAN_TX, | |
756 | "%s: skb=0x%p data=0x%p len=0x%x eid=%d %s\n", | |
757 | __func__, skb, packet->buf, packet->act_len, | |
758 | eid, "OK"); | |
759 | ||
990bd915 | 760 | flushing[if_idx] = false; |
b95907a7 VT |
761 | vif->net_stats.tx_packets++; |
762 | vif->net_stats.tx_bytes += skb->len; | |
bdcd8170 KV |
763 | } |
764 | ||
990bd915 | 765 | ath6kl_tx_clear_node_map(vif, eid, map_no); |
bdcd8170 KV |
766 | |
767 | ath6kl_free_cookie(ar, ath6kl_cookie); | |
768 | ||
59c98449 VT |
769 | if (test_bit(NETQ_STOPPED, &vif->flags)) |
770 | clear_bit(NETQ_STOPPED, &vif->flags); | |
bdcd8170 KV |
771 | } |
772 | ||
773 | spin_unlock_bh(&ar->lock); | |
774 | ||
775 | __skb_queue_purge(&skb_queue); | |
776 | ||
990bd915 | 777 | /* FIXME: Locking */ |
11f6e40d | 778 | spin_lock_bh(&ar->list_lock); |
990bd915 VT |
779 | list_for_each_entry(vif, &ar->vif_list, list) { |
780 | if (test_bit(CONNECTED, &vif->flags) && | |
781 | !flushing[vif->fw_vif_idx]) { | |
11f6e40d | 782 | spin_unlock_bh(&ar->list_lock); |
28ae58dd | 783 | netif_wake_queue(vif->ndev); |
11f6e40d | 784 | spin_lock_bh(&ar->list_lock); |
990bd915 | 785 | } |
bdcd8170 | 786 | } |
11f6e40d | 787 | spin_unlock_bh(&ar->list_lock); |
bdcd8170 KV |
788 | |
789 | if (wake_event) | |
790 | wake_up(&ar->event_wq); | |
791 | ||
792 | return; | |
793 | ||
794 | fatal: | |
795 | WARN_ON(1); | |
796 | spin_unlock_bh(&ar->lock); | |
797 | return; | |
798 | } | |
799 | ||
800 | void ath6kl_tx_data_cleanup(struct ath6kl *ar) | |
801 | { | |
802 | int i; | |
803 | ||
804 | /* flush all the data (non-control) streams */ | |
805 | for (i = 0; i < WMM_NUM_AC; i++) | |
ad226ec2 KV |
806 | ath6kl_htc_flush_txep(ar->htc_target, ar->ac2ep_map[i], |
807 | ATH6KL_DATA_PKT_TAG); | |
bdcd8170 KV |
808 | } |
809 | ||
810 | /* Rx functions */ | |
811 | ||
812 | static void ath6kl_deliver_frames_to_nw_stack(struct net_device *dev, | |
813 | struct sk_buff *skb) | |
814 | { | |
815 | if (!skb) | |
816 | return; | |
817 | ||
818 | skb->dev = dev; | |
819 | ||
820 | if (!(skb->dev->flags & IFF_UP)) { | |
821 | dev_kfree_skb(skb); | |
822 | return; | |
823 | } | |
824 | ||
825 | skb->protocol = eth_type_trans(skb, skb->dev); | |
826 | ||
827 | netif_rx_ni(skb); | |
828 | } | |
829 | ||
830 | static void ath6kl_alloc_netbufs(struct sk_buff_head *q, u16 num) | |
831 | { | |
832 | struct sk_buff *skb; | |
833 | ||
834 | while (num) { | |
835 | skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE); | |
836 | if (!skb) { | |
837 | ath6kl_err("netbuf allocation failed\n"); | |
838 | return; | |
839 | } | |
840 | skb_queue_tail(q, skb); | |
841 | num--; | |
842 | } | |
843 | } | |
844 | ||
845 | static struct sk_buff *aggr_get_free_skb(struct aggr_info *p_aggr) | |
846 | { | |
847 | struct sk_buff *skb = NULL; | |
848 | ||
7baef812 VT |
849 | if (skb_queue_len(&p_aggr->rx_amsdu_freeq) < |
850 | (AGGR_NUM_OF_FREE_NETBUFS >> 2)) | |
851 | ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq, | |
852 | AGGR_NUM_OF_FREE_NETBUFS); | |
bdcd8170 | 853 | |
7baef812 | 854 | skb = skb_dequeue(&p_aggr->rx_amsdu_freeq); |
bdcd8170 KV |
855 | |
856 | return skb; | |
857 | } | |
858 | ||
859 | void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint) | |
860 | { | |
861 | struct ath6kl *ar = target->dev->ar; | |
862 | struct sk_buff *skb; | |
863 | int rx_buf; | |
864 | int n_buf_refill; | |
865 | struct htc_packet *packet; | |
866 | struct list_head queue; | |
867 | ||
868 | n_buf_refill = ATH6KL_MAX_RX_BUFFERS - | |
ad226ec2 | 869 | ath6kl_htc_get_rxbuf_num(ar->htc_target, endpoint); |
bdcd8170 KV |
870 | |
871 | if (n_buf_refill <= 0) | |
872 | return; | |
873 | ||
874 | INIT_LIST_HEAD(&queue); | |
875 | ||
876 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, | |
877 | "%s: providing htc with %d buffers at eid=%d\n", | |
878 | __func__, n_buf_refill, endpoint); | |
879 | ||
880 | for (rx_buf = 0; rx_buf < n_buf_refill; rx_buf++) { | |
881 | skb = ath6kl_buf_alloc(ATH6KL_BUFFER_SIZE); | |
882 | if (!skb) | |
883 | break; | |
884 | ||
885 | packet = (struct htc_packet *) skb->head; | |
94e532d1 VT |
886 | if (!IS_ALIGNED((unsigned long) skb->data, 4)) |
887 | skb->data = PTR_ALIGN(skb->data - 4, 4); | |
bdcd8170 KV |
888 | set_htc_rxpkt_info(packet, skb, skb->data, |
889 | ATH6KL_BUFFER_SIZE, endpoint); | |
890 | list_add_tail(&packet->list, &queue); | |
891 | } | |
892 | ||
893 | if (!list_empty(&queue)) | |
ad226ec2 | 894 | ath6kl_htc_add_rxbuf_multiple(ar->htc_target, &queue); |
bdcd8170 KV |
895 | } |
896 | ||
897 | void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count) | |
898 | { | |
899 | struct htc_packet *packet; | |
900 | struct sk_buff *skb; | |
901 | ||
902 | while (count) { | |
903 | skb = ath6kl_buf_alloc(ATH6KL_AMSDU_BUFFER_SIZE); | |
904 | if (!skb) | |
905 | return; | |
906 | ||
907 | packet = (struct htc_packet *) skb->head; | |
94e532d1 VT |
908 | if (!IS_ALIGNED((unsigned long) skb->data, 4)) |
909 | skb->data = PTR_ALIGN(skb->data - 4, 4); | |
bdcd8170 KV |
910 | set_htc_rxpkt_info(packet, skb, skb->data, |
911 | ATH6KL_AMSDU_BUFFER_SIZE, 0); | |
912 | spin_lock_bh(&ar->lock); | |
913 | list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue); | |
914 | spin_unlock_bh(&ar->lock); | |
915 | count--; | |
916 | } | |
917 | } | |
918 | ||
919 | /* | |
920 | * Callback to allocate a receive buffer for a pending packet. We use a | |
921 | * pre-allocated list of buffers of maximum AMSDU size (4K). | |
922 | */ | |
923 | struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target, | |
924 | enum htc_endpoint_id endpoint, | |
925 | int len) | |
926 | { | |
927 | struct ath6kl *ar = target->dev->ar; | |
928 | struct htc_packet *packet = NULL; | |
929 | struct list_head *pkt_pos; | |
930 | int refill_cnt = 0, depth = 0; | |
931 | ||
932 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: eid=%d, len:%d\n", | |
933 | __func__, endpoint, len); | |
934 | ||
935 | if ((len <= ATH6KL_BUFFER_SIZE) || | |
936 | (len > ATH6KL_AMSDU_BUFFER_SIZE)) | |
937 | return NULL; | |
938 | ||
939 | spin_lock_bh(&ar->lock); | |
940 | ||
941 | if (list_empty(&ar->amsdu_rx_buffer_queue)) { | |
942 | spin_unlock_bh(&ar->lock); | |
943 | refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS; | |
944 | goto refill_buf; | |
945 | } | |
946 | ||
947 | packet = list_first_entry(&ar->amsdu_rx_buffer_queue, | |
948 | struct htc_packet, list); | |
949 | list_del(&packet->list); | |
950 | list_for_each(pkt_pos, &ar->amsdu_rx_buffer_queue) | |
951 | depth++; | |
952 | ||
953 | refill_cnt = ATH6KL_MAX_AMSDU_RX_BUFFERS - depth; | |
954 | spin_unlock_bh(&ar->lock); | |
955 | ||
956 | /* set actual endpoint ID */ | |
957 | packet->endpoint = endpoint; | |
958 | ||
959 | refill_buf: | |
960 | if (refill_cnt >= ATH6KL_AMSDU_REFILL_THRESHOLD) | |
961 | ath6kl_refill_amsdu_rxbufs(ar, refill_cnt); | |
962 | ||
963 | return packet; | |
964 | } | |
965 | ||
966 | static void aggr_slice_amsdu(struct aggr_info *p_aggr, | |
967 | struct rxtid *rxtid, struct sk_buff *skb) | |
968 | { | |
969 | struct sk_buff *new_skb; | |
970 | struct ethhdr *hdr; | |
971 | u16 frame_8023_len, payload_8023_len, mac_hdr_len, amsdu_len; | |
972 | u8 *framep; | |
973 | ||
974 | mac_hdr_len = sizeof(struct ethhdr); | |
975 | framep = skb->data + mac_hdr_len; | |
976 | amsdu_len = skb->len - mac_hdr_len; | |
977 | ||
978 | while (amsdu_len > mac_hdr_len) { | |
979 | hdr = (struct ethhdr *) framep; | |
980 | payload_8023_len = ntohs(hdr->h_proto); | |
981 | ||
982 | if (payload_8023_len < MIN_MSDU_SUBFRAME_PAYLOAD_LEN || | |
983 | payload_8023_len > MAX_MSDU_SUBFRAME_PAYLOAD_LEN) { | |
984 | ath6kl_err("802.3 AMSDU frame bound check failed. len %d\n", | |
985 | payload_8023_len); | |
986 | break; | |
987 | } | |
988 | ||
989 | frame_8023_len = payload_8023_len + mac_hdr_len; | |
990 | new_skb = aggr_get_free_skb(p_aggr); | |
991 | if (!new_skb) { | |
992 | ath6kl_err("no buffer available\n"); | |
993 | break; | |
994 | } | |
995 | ||
996 | memcpy(new_skb->data, framep, frame_8023_len); | |
997 | skb_put(new_skb, frame_8023_len); | |
998 | if (ath6kl_wmi_dot3_2_dix(new_skb)) { | |
999 | ath6kl_err("dot3_2_dix error\n"); | |
1000 | dev_kfree_skb(new_skb); | |
1001 | break; | |
1002 | } | |
1003 | ||
1004 | skb_queue_tail(&rxtid->q, new_skb); | |
1005 | ||
1006 | /* Is this the last subframe within this aggregate ? */ | |
1007 | if ((amsdu_len - frame_8023_len) == 0) | |
1008 | break; | |
1009 | ||
1010 | /* Add the length of A-MSDU subframe padding bytes - | |
1011 | * Round to nearest word. | |
1012 | */ | |
13e34ea1 | 1013 | frame_8023_len = ALIGN(frame_8023_len, 4); |
bdcd8170 KV |
1014 | |
1015 | framep += frame_8023_len; | |
1016 | amsdu_len -= frame_8023_len; | |
1017 | } | |
1018 | ||
1019 | dev_kfree_skb(skb); | |
1020 | } | |
1021 | ||
1d2a4456 | 1022 | static void aggr_deque_frms(struct aggr_info_conn *agg_conn, u8 tid, |
bdcd8170 KV |
1023 | u16 seq_no, u8 order) |
1024 | { | |
1025 | struct sk_buff *skb; | |
1026 | struct rxtid *rxtid; | |
1027 | struct skb_hold_q *node; | |
1028 | u16 idx, idx_end, seq_end; | |
1029 | struct rxtid_stats *stats; | |
1030 | ||
7baef812 VT |
1031 | rxtid = &agg_conn->rx_tid[tid]; |
1032 | stats = &agg_conn->stat[tid]; | |
bdcd8170 KV |
1033 | |
1034 | idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz); | |
1035 | ||
1036 | /* | |
1037 | * idx_end is typically the last possible frame in the window, | |
1038 | * but changes to 'the' seq_no, when BAR comes. If seq_no | |
1039 | * is non-zero, we will go up to that and stop. | |
1040 | * Note: last seq no in current window will occupy the same | |
1041 | * index position as index that is just previous to start. | |
1042 | * An imp point : if win_sz is 7, for seq_no space of 4095, | |
1043 | * then, there would be holes when sequence wrap around occurs. | |
1044 | * Target should judiciously choose the win_sz, based on | |
1045 | * this condition. For 4095, (TID_WINDOW_SZ = 2 x win_sz | |
1046 | * 2, 4, 8, 16 win_sz works fine). | |
1047 | * We must deque from "idx" to "idx_end", including both. | |
1048 | */ | |
1049 | seq_end = seq_no ? seq_no : rxtid->seq_next; | |
1050 | idx_end = AGGR_WIN_IDX(seq_end, rxtid->hold_q_sz); | |
1051 | ||
1052 | spin_lock_bh(&rxtid->lock); | |
1053 | ||
1054 | do { | |
1055 | node = &rxtid->hold_q[idx]; | |
1056 | if ((order == 1) && (!node->skb)) | |
1057 | break; | |
1058 | ||
1059 | if (node->skb) { | |
1060 | if (node->is_amsdu) | |
1d2a4456 VT |
1061 | aggr_slice_amsdu(agg_conn->aggr_info, rxtid, |
1062 | node->skb); | |
bdcd8170 KV |
1063 | else |
1064 | skb_queue_tail(&rxtid->q, node->skb); | |
1065 | node->skb = NULL; | |
1066 | } else | |
1067 | stats->num_hole++; | |
1068 | ||
1069 | rxtid->seq_next = ATH6KL_NEXT_SEQ_NO(rxtid->seq_next); | |
1070 | idx = AGGR_WIN_IDX(rxtid->seq_next, rxtid->hold_q_sz); | |
1071 | } while (idx != idx_end); | |
1072 | ||
1073 | spin_unlock_bh(&rxtid->lock); | |
1074 | ||
1075 | stats->num_delivered += skb_queue_len(&rxtid->q); | |
1076 | ||
1077 | while ((skb = skb_dequeue(&rxtid->q))) | |
7baef812 | 1078 | ath6kl_deliver_frames_to_nw_stack(agg_conn->dev, skb); |
bdcd8170 KV |
1079 | } |
1080 | ||
1d2a4456 | 1081 | static bool aggr_process_recv_frm(struct aggr_info_conn *agg_conn, u8 tid, |
bdcd8170 KV |
1082 | u16 seq_no, |
1083 | bool is_amsdu, struct sk_buff *frame) | |
1084 | { | |
1085 | struct rxtid *rxtid; | |
1086 | struct rxtid_stats *stats; | |
1087 | struct sk_buff *skb; | |
1088 | struct skb_hold_q *node; | |
1089 | u16 idx, st, cur, end; | |
1090 | bool is_queued = false; | |
1091 | u16 extended_end; | |
1092 | ||
7baef812 VT |
1093 | rxtid = &agg_conn->rx_tid[tid]; |
1094 | stats = &agg_conn->stat[tid]; | |
bdcd8170 KV |
1095 | |
1096 | stats->num_into_aggr++; | |
1097 | ||
1098 | if (!rxtid->aggr) { | |
1099 | if (is_amsdu) { | |
1d2a4456 | 1100 | aggr_slice_amsdu(agg_conn->aggr_info, rxtid, frame); |
bdcd8170 KV |
1101 | is_queued = true; |
1102 | stats->num_amsdu++; | |
1103 | while ((skb = skb_dequeue(&rxtid->q))) | |
7baef812 | 1104 | ath6kl_deliver_frames_to_nw_stack(agg_conn->dev, |
bdcd8170 KV |
1105 | skb); |
1106 | } | |
1107 | return is_queued; | |
1108 | } | |
1109 | ||
1110 | /* Check the incoming sequence no, if it's in the window */ | |
1111 | st = rxtid->seq_next; | |
1112 | cur = seq_no; | |
1113 | end = (st + rxtid->hold_q_sz-1) & ATH6KL_MAX_SEQ_NO; | |
1114 | ||
1115 | if (((st < end) && (cur < st || cur > end)) || | |
1116 | ((st > end) && (cur > end) && (cur < st))) { | |
1117 | extended_end = (end + rxtid->hold_q_sz - 1) & | |
1118 | ATH6KL_MAX_SEQ_NO; | |
1119 | ||
1120 | if (((end < extended_end) && | |
1121 | (cur < end || cur > extended_end)) || | |
1122 | ((end > extended_end) && (cur > extended_end) && | |
1123 | (cur < end))) { | |
1d2a4456 | 1124 | aggr_deque_frms(agg_conn, tid, 0, 0); |
bdcd8170 KV |
1125 | if (cur >= rxtid->hold_q_sz - 1) |
1126 | rxtid->seq_next = cur - (rxtid->hold_q_sz - 1); | |
1127 | else | |
1128 | rxtid->seq_next = ATH6KL_MAX_SEQ_NO - | |
1129 | (rxtid->hold_q_sz - 2 - cur); | |
1130 | } else { | |
1131 | /* | |
1132 | * Dequeue only those frames that are outside the | |
1133 | * new shifted window. | |
1134 | */ | |
1135 | if (cur >= rxtid->hold_q_sz - 1) | |
1136 | st = cur - (rxtid->hold_q_sz - 1); | |
1137 | else | |
1138 | st = ATH6KL_MAX_SEQ_NO - | |
1139 | (rxtid->hold_q_sz - 2 - cur); | |
1140 | ||
1d2a4456 | 1141 | aggr_deque_frms(agg_conn, tid, st, 0); |
bdcd8170 KV |
1142 | } |
1143 | ||
1144 | stats->num_oow++; | |
1145 | } | |
1146 | ||
1147 | idx = AGGR_WIN_IDX(seq_no, rxtid->hold_q_sz); | |
1148 | ||
1149 | node = &rxtid->hold_q[idx]; | |
1150 | ||
1151 | spin_lock_bh(&rxtid->lock); | |
1152 | ||
1153 | /* | |
1154 | * Is the cur frame duplicate or something beyond our window(hold_q | |
1155 | * -> which is 2x, already)? | |
1156 | * | |
1157 | * 1. Duplicate is easy - drop incoming frame. | |
1158 | * 2. Not falling in current sliding window. | |
1159 | * 2a. is the frame_seq_no preceding current tid_seq_no? | |
1160 | * -> drop the frame. perhaps sender did not get our ACK. | |
1161 | * this is taken care of above. | |
1162 | * 2b. is the frame_seq_no beyond window(st, TID_WINDOW_SZ); | |
1163 | * -> Taken care of it above, by moving window forward. | |
1164 | */ | |
1165 | dev_kfree_skb(node->skb); | |
1166 | stats->num_dups++; | |
1167 | ||
1168 | node->skb = frame; | |
1169 | is_queued = true; | |
1170 | node->is_amsdu = is_amsdu; | |
1171 | node->seq_no = seq_no; | |
1172 | ||
1173 | if (node->is_amsdu) | |
1174 | stats->num_amsdu++; | |
1175 | else | |
1176 | stats->num_mpdu++; | |
1177 | ||
1178 | spin_unlock_bh(&rxtid->lock); | |
1179 | ||
1d2a4456 | 1180 | aggr_deque_frms(agg_conn, tid, 0, 1); |
bdcd8170 | 1181 | |
7baef812 | 1182 | if (agg_conn->timer_scheduled) |
bdcd8170 KV |
1183 | rxtid->progress = true; |
1184 | else | |
1185 | for (idx = 0 ; idx < rxtid->hold_q_sz; idx++) { | |
1186 | if (rxtid->hold_q[idx].skb) { | |
1187 | /* | |
1188 | * There is a frame in the queue and no | |
1189 | * timer so start a timer to ensure that | |
1190 | * the frame doesn't remain stuck | |
1191 | * forever. | |
1192 | */ | |
7baef812 VT |
1193 | agg_conn->timer_scheduled = true; |
1194 | mod_timer(&agg_conn->timer, | |
bdcd8170 KV |
1195 | (jiffies + |
1196 | HZ * (AGGR_RX_TIMEOUT) / 1000)); | |
1197 | rxtid->progress = false; | |
1198 | rxtid->timer_mon = true; | |
1199 | break; | |
1200 | } | |
1201 | } | |
1202 | ||
1203 | return is_queued; | |
1204 | } | |
1205 | ||
c1762a3f TP |
1206 | static void ath6kl_uapsd_trigger_frame_rx(struct ath6kl_vif *vif, |
1207 | struct ath6kl_sta *conn) | |
1208 | { | |
1209 | struct ath6kl *ar = vif->ar; | |
1210 | bool is_apsdq_empty, is_apsdq_empty_at_start; | |
1211 | u32 num_frames_to_deliver, flags; | |
1212 | struct sk_buff *skb = NULL; | |
1213 | ||
1214 | /* | |
1215 | * If the APSD q for this STA is not empty, dequeue and | |
1216 | * send a pkt from the head of the q. Also update the | |
1217 | * More data bit in the WMI_DATA_HDR if there are | |
1218 | * more pkts for this STA in the APSD q. | |
1219 | * If there are no more pkts for this STA, | |
1220 | * update the APSD bitmap for this STA. | |
1221 | */ | |
1222 | ||
1223 | num_frames_to_deliver = (conn->apsd_info >> ATH6KL_APSD_NUM_OF_AC) & | |
1224 | ATH6KL_APSD_FRAME_MASK; | |
1225 | /* | |
1226 | * Number of frames to send in a service period is | |
1227 | * indicated by the station | |
1228 | * in the QOS_INFO of the association request | |
1229 | * If it is zero, send all frames | |
1230 | */ | |
1231 | if (!num_frames_to_deliver) | |
1232 | num_frames_to_deliver = ATH6KL_APSD_ALL_FRAME; | |
1233 | ||
1234 | spin_lock_bh(&conn->psq_lock); | |
1235 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); | |
1236 | spin_unlock_bh(&conn->psq_lock); | |
1237 | is_apsdq_empty_at_start = is_apsdq_empty; | |
1238 | ||
1239 | while ((!is_apsdq_empty) && (num_frames_to_deliver)) { | |
1240 | ||
1241 | spin_lock_bh(&conn->psq_lock); | |
1242 | skb = skb_dequeue(&conn->apsdq); | |
1243 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); | |
1244 | spin_unlock_bh(&conn->psq_lock); | |
1245 | ||
1246 | /* | |
1247 | * Set the STA flag to Trigger delivery, | |
1248 | * so that the frame will go out | |
1249 | */ | |
1250 | conn->sta_flags |= STA_PS_APSD_TRIGGER; | |
1251 | num_frames_to_deliver--; | |
1252 | ||
1253 | /* Last frame in the service period, set EOSP or queue empty */ | |
1254 | if ((is_apsdq_empty) || (!num_frames_to_deliver)) | |
1255 | conn->sta_flags |= STA_PS_APSD_EOSP; | |
1256 | ||
1257 | ath6kl_data_tx(skb, vif->ndev); | |
1258 | conn->sta_flags &= ~(STA_PS_APSD_TRIGGER); | |
1259 | conn->sta_flags &= ~(STA_PS_APSD_EOSP); | |
1260 | } | |
1261 | ||
1262 | if (is_apsdq_empty) { | |
1263 | if (is_apsdq_empty_at_start) | |
1264 | flags = WMI_AP_APSD_NO_DELIVERY_FRAMES; | |
1265 | else | |
1266 | flags = 0; | |
1267 | ||
1268 | ath6kl_wmi_set_apsd_bfrd_traf(ar->wmi, | |
1269 | vif->fw_vif_idx, | |
1270 | conn->aid, 0, flags); | |
1271 | } | |
1272 | ||
1273 | return; | |
1274 | } | |
1275 | ||
bdcd8170 KV |
1276 | void ath6kl_rx(struct htc_target *target, struct htc_packet *packet) |
1277 | { | |
1278 | struct ath6kl *ar = target->dev->ar; | |
1279 | struct sk_buff *skb = packet->pkt_cntxt; | |
1280 | struct wmi_rx_meta_v2 *meta; | |
1281 | struct wmi_data_hdr *dhdr; | |
1282 | int min_hdr_len; | |
1283 | u8 meta_type, dot11_hdr = 0; | |
1284 | int status = packet->status; | |
1285 | enum htc_endpoint_id ept = packet->endpoint; | |
1286 | bool is_amsdu, prev_ps, ps_state = false; | |
c1762a3f | 1287 | bool trig_state = false; |
bdcd8170 KV |
1288 | struct ath6kl_sta *conn = NULL; |
1289 | struct sk_buff *skb1 = NULL; | |
1290 | struct ethhdr *datap = NULL; | |
6765d0aa | 1291 | struct ath6kl_vif *vif; |
1d2a4456 | 1292 | struct aggr_info_conn *aggr_conn; |
bdcd8170 | 1293 | u16 seq_no, offset; |
6765d0aa | 1294 | u8 tid, if_idx; |
bdcd8170 KV |
1295 | |
1296 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, | |
1297 | "%s: ar=0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d", | |
1298 | __func__, ar, ept, skb, packet->buf, | |
1299 | packet->act_len, status); | |
1300 | ||
1301 | if (status || !(skb->data + HTC_HDR_LENGTH)) { | |
6765d0aa VT |
1302 | dev_kfree_skb(skb); |
1303 | return; | |
1304 | } | |
1305 | ||
1306 | skb_put(skb, packet->act_len + HTC_HDR_LENGTH); | |
1307 | skb_pull(skb, HTC_HDR_LENGTH); | |
1308 | ||
81db48dc VT |
1309 | ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "rx ", |
1310 | skb->data, skb->len); | |
1311 | ||
6765d0aa | 1312 | if (ept == ar->ctrl_ep) { |
81db48dc VT |
1313 | if (test_bit(WMI_ENABLED, &ar->flag)) { |
1314 | ath6kl_check_wow_status(ar); | |
1315 | ath6kl_wmi_control_rx(ar->wmi, skb); | |
1316 | return; | |
1317 | } | |
6765d0aa VT |
1318 | if_idx = |
1319 | wmi_cmd_hdr_get_if_idx((struct wmi_cmd_hdr *) skb->data); | |
1320 | } else { | |
1321 | if_idx = | |
1322 | wmi_data_hdr_get_if_idx((struct wmi_data_hdr *) skb->data); | |
1323 | } | |
1324 | ||
1325 | vif = ath6kl_get_vif_by_index(ar, if_idx); | |
1326 | if (!vif) { | |
bdcd8170 KV |
1327 | dev_kfree_skb(skb); |
1328 | return; | |
1329 | } | |
1330 | ||
1331 | /* | |
1332 | * Take lock to protect buffer counts and adaptive power throughput | |
1333 | * state. | |
1334 | */ | |
478ac027 | 1335 | spin_lock_bh(&vif->if_lock); |
bdcd8170 | 1336 | |
b95907a7 VT |
1337 | vif->net_stats.rx_packets++; |
1338 | vif->net_stats.rx_bytes += packet->act_len; | |
bdcd8170 | 1339 | |
478ac027 | 1340 | spin_unlock_bh(&vif->if_lock); |
83dc5f2f | 1341 | |
28ae58dd | 1342 | skb->dev = vif->ndev; |
bdcd8170 KV |
1343 | |
1344 | if (!test_bit(WMI_ENABLED, &ar->flag)) { | |
1345 | if (EPPING_ALIGNMENT_PAD > 0) | |
1346 | skb_pull(skb, EPPING_ALIGNMENT_PAD); | |
28ae58dd | 1347 | ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb); |
bdcd8170 KV |
1348 | return; |
1349 | } | |
1350 | ||
a918fb3c RM |
1351 | ath6kl_check_wow_status(ar); |
1352 | ||
67f9178f VT |
1353 | min_hdr_len = sizeof(struct ethhdr) + sizeof(struct wmi_data_hdr) + |
1354 | sizeof(struct ath6kl_llc_snap_hdr); | |
bdcd8170 KV |
1355 | |
1356 | dhdr = (struct wmi_data_hdr *) skb->data; | |
1357 | ||
1358 | /* | |
1359 | * In the case of AP mode we may receive NULL data frames | |
1360 | * that do not have LLC hdr. They are 16 bytes in size. | |
1361 | * Allow these frames in the AP mode. | |
1362 | */ | |
f5938f24 | 1363 | if (vif->nw_type != AP_NETWORK && |
bdcd8170 KV |
1364 | ((packet->act_len < min_hdr_len) || |
1365 | (packet->act_len > WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH))) { | |
1366 | ath6kl_info("frame len is too short or too long\n"); | |
b95907a7 VT |
1367 | vif->net_stats.rx_errors++; |
1368 | vif->net_stats.rx_length_errors++; | |
bdcd8170 KV |
1369 | dev_kfree_skb(skb); |
1370 | return; | |
1371 | } | |
1372 | ||
1373 | /* Get the Power save state of the STA */ | |
f5938f24 | 1374 | if (vif->nw_type == AP_NETWORK) { |
bdcd8170 KV |
1375 | meta_type = wmi_data_hdr_get_meta(dhdr); |
1376 | ||
1377 | ps_state = !!((dhdr->info >> WMI_DATA_HDR_PS_SHIFT) & | |
1378 | WMI_DATA_HDR_PS_MASK); | |
1379 | ||
1380 | offset = sizeof(struct wmi_data_hdr); | |
c1762a3f | 1381 | trig_state = !!(le16_to_cpu(dhdr->info3) & WMI_DATA_HDR_TRIG); |
bdcd8170 KV |
1382 | |
1383 | switch (meta_type) { | |
1384 | case 0: | |
1385 | break; | |
1386 | case WMI_META_VERSION_1: | |
1387 | offset += sizeof(struct wmi_rx_meta_v1); | |
1388 | break; | |
1389 | case WMI_META_VERSION_2: | |
1390 | offset += sizeof(struct wmi_rx_meta_v2); | |
1391 | break; | |
1392 | default: | |
1393 | break; | |
1394 | } | |
1395 | ||
1396 | datap = (struct ethhdr *) (skb->data + offset); | |
6765d0aa | 1397 | conn = ath6kl_find_sta(vif, datap->h_source); |
bdcd8170 KV |
1398 | |
1399 | if (!conn) { | |
1400 | dev_kfree_skb(skb); | |
1401 | return; | |
1402 | } | |
1403 | ||
1404 | /* | |
1405 | * If there is a change in PS state of the STA, | |
1406 | * take appropriate steps: | |
1407 | * | |
1408 | * 1. If Sleep-->Awake, flush the psq for the STA | |
1409 | * Clear the PVB for the STA. | |
1410 | * 2. If Awake-->Sleep, Starting queueing frames | |
1411 | * the STA. | |
1412 | */ | |
1413 | prev_ps = !!(conn->sta_flags & STA_PS_SLEEP); | |
1414 | ||
1415 | if (ps_state) | |
1416 | conn->sta_flags |= STA_PS_SLEEP; | |
1417 | else | |
1418 | conn->sta_flags &= ~STA_PS_SLEEP; | |
1419 | ||
c1762a3f TP |
1420 | /* Accept trigger only when the station is in sleep */ |
1421 | if ((conn->sta_flags & STA_PS_SLEEP) && trig_state) | |
1422 | ath6kl_uapsd_trigger_frame_rx(vif, conn); | |
1423 | ||
bdcd8170 KV |
1424 | if (prev_ps ^ !!(conn->sta_flags & STA_PS_SLEEP)) { |
1425 | if (!(conn->sta_flags & STA_PS_SLEEP)) { | |
1426 | struct sk_buff *skbuff = NULL; | |
c1762a3f | 1427 | bool is_apsdq_empty; |
d0ff7383 NG |
1428 | struct ath6kl_mgmt_buff *mgmt; |
1429 | u8 idx; | |
bdcd8170 KV |
1430 | |
1431 | spin_lock_bh(&conn->psq_lock); | |
d0ff7383 NG |
1432 | while (conn->mgmt_psq_len > 0) { |
1433 | mgmt = list_first_entry( | |
1434 | &conn->mgmt_psq, | |
1435 | struct ath6kl_mgmt_buff, | |
1436 | list); | |
1437 | list_del(&mgmt->list); | |
1438 | conn->mgmt_psq_len--; | |
1439 | spin_unlock_bh(&conn->psq_lock); | |
1440 | idx = vif->fw_vif_idx; | |
1441 | ||
1442 | ath6kl_wmi_send_mgmt_cmd(ar->wmi, | |
1443 | idx, | |
1444 | mgmt->id, | |
1445 | mgmt->freq, | |
1446 | mgmt->wait, | |
1447 | mgmt->buf, | |
1448 | mgmt->len, | |
1449 | mgmt->no_cck); | |
1450 | ||
1451 | kfree(mgmt); | |
1452 | spin_lock_bh(&conn->psq_lock); | |
1453 | } | |
1454 | conn->mgmt_psq_len = 0; | |
c1762a3f TP |
1455 | while ((skbuff = skb_dequeue(&conn->psq))) { |
1456 | spin_unlock_bh(&conn->psq_lock); | |
1457 | ath6kl_data_tx(skbuff, vif->ndev); | |
1458 | spin_lock_bh(&conn->psq_lock); | |
1459 | } | |
1460 | ||
1461 | is_apsdq_empty = skb_queue_empty(&conn->apsdq); | |
1462 | while ((skbuff = skb_dequeue(&conn->apsdq))) { | |
bdcd8170 | 1463 | spin_unlock_bh(&conn->psq_lock); |
28ae58dd | 1464 | ath6kl_data_tx(skbuff, vif->ndev); |
bdcd8170 KV |
1465 | spin_lock_bh(&conn->psq_lock); |
1466 | } | |
1467 | spin_unlock_bh(&conn->psq_lock); | |
c1762a3f TP |
1468 | |
1469 | if (!is_apsdq_empty) | |
1470 | ath6kl_wmi_set_apsd_bfrd_traf( | |
1471 | ar->wmi, | |
1472 | vif->fw_vif_idx, | |
1473 | conn->aid, 0, 0); | |
1474 | ||
bdcd8170 | 1475 | /* Clear the PVB for this STA */ |
334234b5 VT |
1476 | ath6kl_wmi_set_pvb_cmd(ar->wmi, vif->fw_vif_idx, |
1477 | conn->aid, 0); | |
bdcd8170 KV |
1478 | } |
1479 | } | |
1480 | ||
1481 | /* drop NULL data frames here */ | |
1482 | if ((packet->act_len < min_hdr_len) || | |
1483 | (packet->act_len > | |
1484 | WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH)) { | |
1485 | dev_kfree_skb(skb); | |
1486 | return; | |
1487 | } | |
1488 | } | |
1489 | ||
1490 | is_amsdu = wmi_data_hdr_is_amsdu(dhdr) ? true : false; | |
1491 | tid = wmi_data_hdr_get_up(dhdr); | |
1492 | seq_no = wmi_data_hdr_get_seqno(dhdr); | |
1493 | meta_type = wmi_data_hdr_get_meta(dhdr); | |
1494 | dot11_hdr = wmi_data_hdr_get_dot11(dhdr); | |
594a0bc8 | 1495 | skb_pull(skb, sizeof(struct wmi_data_hdr)); |
bdcd8170 KV |
1496 | |
1497 | switch (meta_type) { | |
1498 | case WMI_META_VERSION_1: | |
1499 | skb_pull(skb, sizeof(struct wmi_rx_meta_v1)); | |
1500 | break; | |
1501 | case WMI_META_VERSION_2: | |
1502 | meta = (struct wmi_rx_meta_v2 *) skb->data; | |
1503 | if (meta->csum_flags & 0x1) { | |
1504 | skb->ip_summed = CHECKSUM_COMPLETE; | |
1505 | skb->csum = (__force __wsum) meta->csum; | |
1506 | } | |
1507 | skb_pull(skb, sizeof(struct wmi_rx_meta_v2)); | |
1508 | break; | |
1509 | default: | |
1510 | break; | |
1511 | } | |
1512 | ||
1513 | if (dot11_hdr) | |
1514 | status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb); | |
1515 | else if (!is_amsdu) | |
1516 | status = ath6kl_wmi_dot3_2_dix(skb); | |
1517 | ||
1518 | if (status) { | |
1519 | /* | |
1520 | * Drop frames that could not be processed (lack of | |
1521 | * memory, etc.) | |
1522 | */ | |
1523 | dev_kfree_skb(skb); | |
1524 | return; | |
1525 | } | |
1526 | ||
28ae58dd | 1527 | if (!(vif->ndev->flags & IFF_UP)) { |
bdcd8170 KV |
1528 | dev_kfree_skb(skb); |
1529 | return; | |
1530 | } | |
1531 | ||
f5938f24 | 1532 | if (vif->nw_type == AP_NETWORK) { |
bdcd8170 KV |
1533 | datap = (struct ethhdr *) skb->data; |
1534 | if (is_multicast_ether_addr(datap->h_dest)) | |
1535 | /* | |
1536 | * Bcast/Mcast frames should be sent to the | |
1537 | * OS stack as well as on the air. | |
1538 | */ | |
1539 | skb1 = skb_copy(skb, GFP_ATOMIC); | |
1540 | else { | |
1541 | /* | |
1542 | * Search for a connected STA with dstMac | |
1543 | * as the Mac address. If found send the | |
1544 | * frame to it on the air else send the | |
1545 | * frame up the stack. | |
1546 | */ | |
6765d0aa | 1547 | conn = ath6kl_find_sta(vif, datap->h_dest); |
bdcd8170 KV |
1548 | |
1549 | if (conn && ar->intra_bss) { | |
1550 | skb1 = skb; | |
1551 | skb = NULL; | |
1552 | } else if (conn && !ar->intra_bss) { | |
1553 | dev_kfree_skb(skb); | |
1554 | skb = NULL; | |
1555 | } | |
1556 | } | |
1557 | if (skb1) | |
28ae58dd | 1558 | ath6kl_data_tx(skb1, vif->ndev); |
ad3f78b9 KV |
1559 | |
1560 | if (skb == NULL) { | |
1561 | /* nothing to deliver up the stack */ | |
1562 | return; | |
1563 | } | |
bdcd8170 KV |
1564 | } |
1565 | ||
5694f962 KV |
1566 | datap = (struct ethhdr *) skb->data; |
1567 | ||
1d2a4456 VT |
1568 | if (is_unicast_ether_addr(datap->h_dest)) { |
1569 | if (vif->nw_type == AP_NETWORK) { | |
1570 | conn = ath6kl_find_sta(vif, datap->h_source); | |
1571 | if (!conn) | |
1572 | return; | |
1573 | aggr_conn = conn->aggr_conn; | |
1574 | } else | |
1575 | aggr_conn = vif->aggr_cntxt->aggr_conn; | |
1576 | ||
1577 | if (aggr_process_recv_frm(aggr_conn, tid, seq_no, | |
1578 | is_amsdu, skb)) { | |
1579 | /* aggregation code will handle the skb */ | |
1580 | return; | |
1581 | } | |
1582 | } | |
5694f962 | 1583 | |
28ae58dd | 1584 | ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb); |
bdcd8170 KV |
1585 | } |
1586 | ||
1587 | static void aggr_timeout(unsigned long arg) | |
1588 | { | |
1589 | u8 i, j; | |
7baef812 | 1590 | struct aggr_info_conn *aggr_conn = (struct aggr_info_conn *) arg; |
bdcd8170 KV |
1591 | struct rxtid *rxtid; |
1592 | struct rxtid_stats *stats; | |
1593 | ||
1594 | for (i = 0; i < NUM_OF_TIDS; i++) { | |
7baef812 VT |
1595 | rxtid = &aggr_conn->rx_tid[i]; |
1596 | stats = &aggr_conn->stat[i]; | |
bdcd8170 KV |
1597 | |
1598 | if (!rxtid->aggr || !rxtid->timer_mon || rxtid->progress) | |
1599 | continue; | |
1600 | ||
1601 | stats->num_timeouts++; | |
37ca6335 KV |
1602 | ath6kl_dbg(ATH6KL_DBG_AGGR, |
1603 | "aggr timeout (st %d end %d)\n", | |
bdcd8170 KV |
1604 | rxtid->seq_next, |
1605 | ((rxtid->seq_next + rxtid->hold_q_sz-1) & | |
1606 | ATH6KL_MAX_SEQ_NO)); | |
1d2a4456 | 1607 | aggr_deque_frms(aggr_conn, i, 0, 0); |
bdcd8170 KV |
1608 | } |
1609 | ||
7baef812 | 1610 | aggr_conn->timer_scheduled = false; |
bdcd8170 KV |
1611 | |
1612 | for (i = 0; i < NUM_OF_TIDS; i++) { | |
7baef812 | 1613 | rxtid = &aggr_conn->rx_tid[i]; |
bdcd8170 KV |
1614 | |
1615 | if (rxtid->aggr && rxtid->hold_q) { | |
1616 | for (j = 0; j < rxtid->hold_q_sz; j++) { | |
1617 | if (rxtid->hold_q[j].skb) { | |
7baef812 | 1618 | aggr_conn->timer_scheduled = true; |
bdcd8170 KV |
1619 | rxtid->timer_mon = true; |
1620 | rxtid->progress = false; | |
1621 | break; | |
1622 | } | |
1623 | } | |
1624 | ||
1625 | if (j >= rxtid->hold_q_sz) | |
1626 | rxtid->timer_mon = false; | |
1627 | } | |
1628 | } | |
1629 | ||
7baef812 VT |
1630 | if (aggr_conn->timer_scheduled) |
1631 | mod_timer(&aggr_conn->timer, | |
bdcd8170 KV |
1632 | jiffies + msecs_to_jiffies(AGGR_RX_TIMEOUT)); |
1633 | } | |
1634 | ||
7baef812 | 1635 | static void aggr_delete_tid_state(struct aggr_info_conn *aggr_conn, u8 tid) |
bdcd8170 KV |
1636 | { |
1637 | struct rxtid *rxtid; | |
1638 | struct rxtid_stats *stats; | |
1639 | ||
7baef812 | 1640 | if (!aggr_conn || tid >= NUM_OF_TIDS) |
bdcd8170 KV |
1641 | return; |
1642 | ||
7baef812 VT |
1643 | rxtid = &aggr_conn->rx_tid[tid]; |
1644 | stats = &aggr_conn->stat[tid]; | |
bdcd8170 KV |
1645 | |
1646 | if (rxtid->aggr) | |
1d2a4456 | 1647 | aggr_deque_frms(aggr_conn, tid, 0, 0); |
bdcd8170 KV |
1648 | |
1649 | rxtid->aggr = false; | |
1650 | rxtid->progress = false; | |
1651 | rxtid->timer_mon = false; | |
1652 | rxtid->win_sz = 0; | |
1653 | rxtid->seq_next = 0; | |
1654 | rxtid->hold_q_sz = 0; | |
1655 | ||
1656 | kfree(rxtid->hold_q); | |
1657 | rxtid->hold_q = NULL; | |
1658 | ||
1659 | memset(stats, 0, sizeof(struct rxtid_stats)); | |
1660 | } | |
1661 | ||
3fdc0991 | 1662 | void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid_mux, u16 seq_no, |
240d2799 | 1663 | u8 win_sz) |
bdcd8170 | 1664 | { |
1d2a4456 VT |
1665 | struct ath6kl_sta *sta; |
1666 | struct aggr_info_conn *aggr_conn = NULL; | |
bdcd8170 KV |
1667 | struct rxtid *rxtid; |
1668 | struct rxtid_stats *stats; | |
1669 | u16 hold_q_size; | |
1d2a4456 | 1670 | u8 tid, aid; |
bdcd8170 | 1671 | |
1d2a4456 VT |
1672 | if (vif->nw_type == AP_NETWORK) { |
1673 | aid = ath6kl_get_aid(tid_mux); | |
1674 | sta = ath6kl_find_sta_by_aid(vif->ar, aid); | |
1675 | if (sta) | |
1676 | aggr_conn = sta->aggr_conn; | |
1677 | } else | |
1678 | aggr_conn = vif->aggr_cntxt->aggr_conn; | |
bdcd8170 | 1679 | |
1d2a4456 VT |
1680 | if (!aggr_conn) |
1681 | return; | |
7baef812 | 1682 | |
3fdc0991 VT |
1683 | tid = ath6kl_get_tid(tid_mux); |
1684 | if (tid >= NUM_OF_TIDS) | |
1685 | return; | |
1686 | ||
7baef812 VT |
1687 | rxtid = &aggr_conn->rx_tid[tid]; |
1688 | stats = &aggr_conn->stat[tid]; | |
bdcd8170 KV |
1689 | |
1690 | if (win_sz < AGGR_WIN_SZ_MIN || win_sz > AGGR_WIN_SZ_MAX) | |
1691 | ath6kl_dbg(ATH6KL_DBG_WLAN_RX, "%s: win_sz %d, tid %d\n", | |
1692 | __func__, win_sz, tid); | |
1693 | ||
1694 | if (rxtid->aggr) | |
7baef812 | 1695 | aggr_delete_tid_state(aggr_conn, tid); |
bdcd8170 KV |
1696 | |
1697 | rxtid->seq_next = seq_no; | |
1698 | hold_q_size = TID_WINDOW_SZ(win_sz) * sizeof(struct skb_hold_q); | |
1699 | rxtid->hold_q = kzalloc(hold_q_size, GFP_KERNEL); | |
1700 | if (!rxtid->hold_q) | |
1701 | return; | |
1702 | ||
1703 | rxtid->win_sz = win_sz; | |
1704 | rxtid->hold_q_sz = TID_WINDOW_SZ(win_sz); | |
1705 | if (!skb_queue_empty(&rxtid->q)) | |
1706 | return; | |
1707 | ||
1708 | rxtid->aggr = true; | |
1709 | } | |
1710 | ||
c8651541 VT |
1711 | void aggr_conn_init(struct ath6kl_vif *vif, struct aggr_info *aggr_info, |
1712 | struct aggr_info_conn *aggr_conn) | |
bdcd8170 | 1713 | { |
bdcd8170 KV |
1714 | struct rxtid *rxtid; |
1715 | u8 i; | |
1716 | ||
7baef812 VT |
1717 | aggr_conn->aggr_sz = AGGR_SZ_DEFAULT; |
1718 | aggr_conn->dev = vif->ndev; | |
1719 | init_timer(&aggr_conn->timer); | |
1720 | aggr_conn->timer.function = aggr_timeout; | |
1721 | aggr_conn->timer.data = (unsigned long) aggr_conn; | |
c8651541 | 1722 | aggr_conn->aggr_info = aggr_info; |
bdcd8170 | 1723 | |
7baef812 | 1724 | aggr_conn->timer_scheduled = false; |
bdcd8170 KV |
1725 | |
1726 | for (i = 0; i < NUM_OF_TIDS; i++) { | |
7baef812 | 1727 | rxtid = &aggr_conn->rx_tid[i]; |
bdcd8170 KV |
1728 | rxtid->aggr = false; |
1729 | rxtid->progress = false; | |
1730 | rxtid->timer_mon = false; | |
1731 | skb_queue_head_init(&rxtid->q); | |
1732 | spin_lock_init(&rxtid->lock); | |
1733 | } | |
1734 | ||
7baef812 VT |
1735 | } |
1736 | ||
1737 | struct aggr_info *aggr_init(struct ath6kl_vif *vif) | |
1738 | { | |
1739 | struct aggr_info *p_aggr = NULL; | |
1740 | ||
1741 | p_aggr = kzalloc(sizeof(struct aggr_info), GFP_KERNEL); | |
1742 | if (!p_aggr) { | |
1743 | ath6kl_err("failed to alloc memory for aggr_node\n"); | |
1744 | return NULL; | |
1745 | } | |
1746 | ||
1747 | p_aggr->aggr_conn = kzalloc(sizeof(struct aggr_info_conn), GFP_KERNEL); | |
1748 | if (!p_aggr->aggr_conn) { | |
1749 | ath6kl_err("failed to alloc memory for connection specific aggr info\n"); | |
1750 | kfree(p_aggr); | |
1751 | return NULL; | |
1752 | } | |
1753 | ||
c8651541 | 1754 | aggr_conn_init(vif, p_aggr, p_aggr->aggr_conn); |
7baef812 VT |
1755 | |
1756 | skb_queue_head_init(&p_aggr->rx_amsdu_freeq); | |
1757 | ath6kl_alloc_netbufs(&p_aggr->rx_amsdu_freeq, AGGR_NUM_OF_FREE_NETBUFS); | |
1758 | ||
bdcd8170 KV |
1759 | return p_aggr; |
1760 | } | |
1761 | ||
3fdc0991 | 1762 | void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid_mux) |
bdcd8170 | 1763 | { |
1d2a4456 | 1764 | struct ath6kl_sta *sta; |
bdcd8170 | 1765 | struct rxtid *rxtid; |
1d2a4456 VT |
1766 | struct aggr_info_conn *aggr_conn = NULL; |
1767 | u8 tid, aid; | |
1768 | ||
1769 | if (vif->nw_type == AP_NETWORK) { | |
1770 | aid = ath6kl_get_aid(tid_mux); | |
1771 | sta = ath6kl_find_sta_by_aid(vif->ar, aid); | |
1772 | if (sta) | |
1773 | aggr_conn = sta->aggr_conn; | |
1774 | } else | |
1775 | aggr_conn = vif->aggr_cntxt->aggr_conn; | |
bdcd8170 | 1776 | |
1d2a4456 | 1777 | if (!aggr_conn) |
bdcd8170 KV |
1778 | return; |
1779 | ||
3fdc0991 VT |
1780 | tid = ath6kl_get_tid(tid_mux); |
1781 | if (tid >= NUM_OF_TIDS) | |
1782 | return; | |
1783 | ||
7baef812 | 1784 | rxtid = &aggr_conn->rx_tid[tid]; |
bdcd8170 KV |
1785 | |
1786 | if (rxtid->aggr) | |
7baef812 | 1787 | aggr_delete_tid_state(aggr_conn, tid); |
bdcd8170 KV |
1788 | } |
1789 | ||
1d2a4456 | 1790 | void aggr_reset_state(struct aggr_info_conn *aggr_conn) |
bdcd8170 KV |
1791 | { |
1792 | u8 tid; | |
1793 | ||
1d2a4456 | 1794 | if (!aggr_conn) |
7baef812 VT |
1795 | return; |
1796 | ||
1d2a4456 VT |
1797 | if (aggr_conn->timer_scheduled) { |
1798 | del_timer(&aggr_conn->timer); | |
1799 | aggr_conn->timer_scheduled = false; | |
7a950ea8 VT |
1800 | } |
1801 | ||
bdcd8170 | 1802 | for (tid = 0; tid < NUM_OF_TIDS; tid++) |
1d2a4456 | 1803 | aggr_delete_tid_state(aggr_conn, tid); |
bdcd8170 KV |
1804 | } |
1805 | ||
1806 | /* clean up our amsdu buffer list */ | |
1807 | void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar) | |
1808 | { | |
1809 | struct htc_packet *packet, *tmp_pkt; | |
1810 | ||
1811 | spin_lock_bh(&ar->lock); | |
1812 | if (list_empty(&ar->amsdu_rx_buffer_queue)) { | |
1813 | spin_unlock_bh(&ar->lock); | |
1814 | return; | |
1815 | } | |
1816 | ||
1817 | list_for_each_entry_safe(packet, tmp_pkt, &ar->amsdu_rx_buffer_queue, | |
1818 | list) { | |
1819 | list_del(&packet->list); | |
1820 | spin_unlock_bh(&ar->lock); | |
1821 | dev_kfree_skb(packet->pkt_cntxt); | |
1822 | spin_lock_bh(&ar->lock); | |
1823 | } | |
1824 | ||
1825 | spin_unlock_bh(&ar->lock); | |
1826 | } | |
1827 | ||
1828 | void aggr_module_destroy(struct aggr_info *aggr_info) | |
1829 | { | |
1d2a4456 | 1830 | if (!aggr_info) |
bdcd8170 KV |
1831 | return; |
1832 | ||
1d2a4456 | 1833 | aggr_reset_state(aggr_info->aggr_conn); |
7baef812 VT |
1834 | skb_queue_purge(&aggr_info->rx_amsdu_freeq); |
1835 | kfree(aggr_info->aggr_conn); | |
bdcd8170 KV |
1836 | kfree(aggr_info); |
1837 | } |