1 // SPDX-License-Identifier: GPL-2.0-only
3 * Datapath implementation for ST-Ericsson CW1200 mac80211 drivers
5 * Copyright (c) 2010, ST-Ericsson
6 * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
9 #include <net/mac80211.h>
10 #include <linux/etherdevice.h>
11 #include <linux/skbuff.h>
19 #define CW1200_INVALID_RATE_ID (0xFF)
21 static int cw1200_handle_action_rx(struct cw1200_common
*priv
,
23 static const struct ieee80211_rate
*
24 cw1200_get_tx_rate(const struct cw1200_common
*priv
,
25 const struct ieee80211_tx_rate
*rate
);
27 /* ******************************************************************** */
28 /* TX queue lock / unlock */
30 static inline void cw1200_tx_queues_lock(struct cw1200_common
*priv
)
33 for (i
= 0; i
< 4; ++i
)
34 cw1200_queue_lock(&priv
->tx_queue
[i
]);
37 static inline void cw1200_tx_queues_unlock(struct cw1200_common
*priv
)
40 for (i
= 0; i
< 4; ++i
)
41 cw1200_queue_unlock(&priv
->tx_queue
[i
]);
44 /* ******************************************************************** */
45 /* TX policy cache implementation */
47 static void tx_policy_dump(struct tx_policy
*policy
)
49 pr_debug("[TX policy] %.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X %.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X %.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X: %d\n",
50 policy
->raw
[0] & 0x0F, policy
->raw
[0] >> 4,
51 policy
->raw
[1] & 0x0F, policy
->raw
[1] >> 4,
52 policy
->raw
[2] & 0x0F, policy
->raw
[2] >> 4,
53 policy
->raw
[3] & 0x0F, policy
->raw
[3] >> 4,
54 policy
->raw
[4] & 0x0F, policy
->raw
[4] >> 4,
55 policy
->raw
[5] & 0x0F, policy
->raw
[5] >> 4,
56 policy
->raw
[6] & 0x0F, policy
->raw
[6] >> 4,
57 policy
->raw
[7] & 0x0F, policy
->raw
[7] >> 4,
58 policy
->raw
[8] & 0x0F, policy
->raw
[8] >> 4,
59 policy
->raw
[9] & 0x0F, policy
->raw
[9] >> 4,
60 policy
->raw
[10] & 0x0F, policy
->raw
[10] >> 4,
61 policy
->raw
[11] & 0x0F, policy
->raw
[11] >> 4,
65 static void tx_policy_build(const struct cw1200_common
*priv
,
66 /* [out] */ struct tx_policy
*policy
,
67 struct ieee80211_tx_rate
*rates
, size_t count
)
70 unsigned limit
= priv
->short_frame_max_tx_count
;
72 BUG_ON(rates
[0].idx
< 0);
73 memset(policy
, 0, sizeof(*policy
));
75 /* Sort rates in descending order. */
76 for (i
= 1; i
< count
; ++i
) {
77 if (rates
[i
].idx
< 0) {
81 if (rates
[i
].idx
> rates
[i
- 1].idx
) {
82 struct ieee80211_tx_rate tmp
= rates
[i
- 1];
83 rates
[i
- 1] = rates
[i
];
88 /* Eliminate duplicates. */
89 total
= rates
[0].count
;
90 for (i
= 0, j
= 1; j
< count
; ++j
) {
91 if (rates
[j
].idx
== rates
[i
].idx
) {
92 rates
[i
].count
+= rates
[j
].count
;
93 } else if (rates
[j
].idx
> rates
[i
].idx
) {
100 total
+= rates
[j
].count
;
104 /* Re-fill policy trying to keep every requested rate and with
105 * respect to the global max tx retransmission count.
110 for (i
= 0; i
< count
; ++i
) {
111 int left
= count
- i
- 1;
112 if (rates
[i
].count
> limit
- left
)
113 rates
[i
].count
= limit
- left
;
114 limit
-= rates
[i
].count
;
118 /* HACK!!! Device has problems (at least) switching from
119 * 54Mbps CTS to 1Mbps. This switch takes enormous amount
120 * of time (100-200 ms), leading to valuable throughput drop.
121 * As a workaround, additional g-rates are injected to the
124 if (count
== 2 && !(rates
[0].flags
& IEEE80211_TX_RC_MCS
) &&
125 rates
[0].idx
> 4 && rates
[0].count
> 2 &&
127 int mid_rate
= (rates
[0].idx
+ 4) >> 1;
129 /* Decrease number of retries for the initial rate */
133 /* Keep fallback rate at 1Mbps. */
136 /* Inject 1 transmission on lowest g-rate */
139 rates
[2].flags
= rates
[1].flags
;
141 /* Inject 1 transmission on mid-rate */
142 rates
[1].idx
= mid_rate
;
145 /* Fallback to 1 Mbps is a really bad thing,
146 * so let's try to increase probability of
147 * successful transmission on the lowest g rate
150 if (rates
[0].count
>= 3) {
155 /* Adjust amount of rates defined */
158 /* Keep fallback rate at 1Mbps. */
161 /* Inject 2 transmissions on lowest g-rate */
165 /* Adjust amount of rates defined */
170 policy
->defined
= cw1200_get_tx_rate(priv
, &rates
[0])->hw_value
+ 1;
172 for (i
= 0; i
< count
; ++i
) {
173 register unsigned rateid
, off
, shift
, retries
;
175 rateid
= cw1200_get_tx_rate(priv
, &rates
[i
])->hw_value
;
176 off
= rateid
>> 3; /* eq. rateid / 8 */
177 shift
= (rateid
& 0x07) << 2; /* eq. (rateid % 8) * 4 */
179 retries
= rates
[i
].count
;
180 if (retries
> 0x0F) {
181 rates
[i
].count
= 0x0f;
184 policy
->tbl
[off
] |= __cpu_to_le32(retries
<< shift
);
185 policy
->retry_count
+= retries
;
188 pr_debug("[TX policy] Policy (%zu): %d:%d, %d:%d, %d:%d, %d:%d\n",
190 rates
[0].idx
, rates
[0].count
,
191 rates
[1].idx
, rates
[1].count
,
192 rates
[2].idx
, rates
[2].count
,
193 rates
[3].idx
, rates
[3].count
);
196 static inline bool tx_policy_is_equal(const struct tx_policy
*wanted
,
197 const struct tx_policy
*cached
)
199 size_t count
= wanted
->defined
>> 1;
200 if (wanted
->defined
> cached
->defined
)
203 if (memcmp(wanted
->raw
, cached
->raw
, count
))
206 if (wanted
->defined
& 1) {
207 if ((wanted
->raw
[count
] & 0x0F) != (cached
->raw
[count
] & 0x0F))
213 static int tx_policy_find(struct tx_policy_cache
*cache
,
214 const struct tx_policy
*wanted
)
216 /* O(n) complexity. Not so good, but there's only 8 entries in
218 * Also lru helps to reduce search time.
220 struct tx_policy_cache_entry
*it
;
221 /* First search for policy in "used" list */
222 list_for_each_entry(it
, &cache
->used
, link
) {
223 if (tx_policy_is_equal(wanted
, &it
->policy
))
224 return it
- cache
->cache
;
226 /* Then - in "free list" */
227 list_for_each_entry(it
, &cache
->free
, link
) {
228 if (tx_policy_is_equal(wanted
, &it
->policy
))
229 return it
- cache
->cache
;
234 static inline void tx_policy_use(struct tx_policy_cache
*cache
,
235 struct tx_policy_cache_entry
*entry
)
237 ++entry
->policy
.usage_count
;
238 list_move(&entry
->link
, &cache
->used
);
241 static inline int tx_policy_release(struct tx_policy_cache
*cache
,
242 struct tx_policy_cache_entry
*entry
)
244 int ret
= --entry
->policy
.usage_count
;
246 list_move(&entry
->link
, &cache
->free
);
250 void tx_policy_clean(struct cw1200_common
*priv
)
253 struct tx_policy_cache
*cache
= &priv
->tx_policy_cache
;
254 struct tx_policy_cache_entry
*entry
;
256 cw1200_tx_queues_lock(priv
);
257 spin_lock_bh(&cache
->lock
);
258 locked
= list_empty(&cache
->free
);
260 for (idx
= 0; idx
< TX_POLICY_CACHE_SIZE
; idx
++) {
261 entry
= &cache
->cache
[idx
];
262 /* Policy usage count should be 0 at this time as all queues
265 if (WARN_ON(entry
->policy
.usage_count
)) {
266 entry
->policy
.usage_count
= 0;
267 list_move(&entry
->link
, &cache
->free
);
269 memset(&entry
->policy
, 0, sizeof(entry
->policy
));
272 cw1200_tx_queues_unlock(priv
);
274 cw1200_tx_queues_unlock(priv
);
275 spin_unlock_bh(&cache
->lock
);
278 /* ******************************************************************** */
279 /* External TX policy cache API */
281 void tx_policy_init(struct cw1200_common
*priv
)
283 struct tx_policy_cache
*cache
= &priv
->tx_policy_cache
;
286 memset(cache
, 0, sizeof(*cache
));
288 spin_lock_init(&cache
->lock
);
289 INIT_LIST_HEAD(&cache
->used
);
290 INIT_LIST_HEAD(&cache
->free
);
292 for (i
= 0; i
< TX_POLICY_CACHE_SIZE
; ++i
)
293 list_add(&cache
->cache
[i
].link
, &cache
->free
);
296 static int tx_policy_get(struct cw1200_common
*priv
,
297 struct ieee80211_tx_rate
*rates
,
298 size_t count
, bool *renew
)
301 struct tx_policy_cache
*cache
= &priv
->tx_policy_cache
;
302 struct tx_policy wanted
;
304 tx_policy_build(priv
, &wanted
, rates
, count
);
306 spin_lock_bh(&cache
->lock
);
307 if (WARN_ON_ONCE(list_empty(&cache
->free
))) {
308 spin_unlock_bh(&cache
->lock
);
309 return CW1200_INVALID_RATE_ID
;
311 idx
= tx_policy_find(cache
, &wanted
);
313 pr_debug("[TX policy] Used TX policy: %d\n", idx
);
316 struct tx_policy_cache_entry
*entry
;
318 /* If policy is not found create a new one
319 * using the oldest entry in "free" list
321 entry
= list_entry(cache
->free
.prev
,
322 struct tx_policy_cache_entry
, link
);
323 entry
->policy
= wanted
;
324 idx
= entry
- cache
->cache
;
325 pr_debug("[TX policy] New TX policy: %d\n", idx
);
326 tx_policy_dump(&entry
->policy
);
328 tx_policy_use(cache
, &cache
->cache
[idx
]);
329 if (list_empty(&cache
->free
)) {
330 /* Lock TX queues. */
331 cw1200_tx_queues_lock(priv
);
333 spin_unlock_bh(&cache
->lock
);
337 static void tx_policy_put(struct cw1200_common
*priv
, int idx
)
340 struct tx_policy_cache
*cache
= &priv
->tx_policy_cache
;
342 spin_lock_bh(&cache
->lock
);
343 locked
= list_empty(&cache
->free
);
344 usage
= tx_policy_release(cache
, &cache
->cache
[idx
]);
345 if (locked
&& !usage
) {
346 /* Unlock TX queues. */
347 cw1200_tx_queues_unlock(priv
);
349 spin_unlock_bh(&cache
->lock
);
352 static int tx_policy_upload(struct cw1200_common
*priv
)
354 struct tx_policy_cache
*cache
= &priv
->tx_policy_cache
;
356 struct wsm_set_tx_rate_retry_policy arg
= {
359 spin_lock_bh(&cache
->lock
);
361 /* Upload only modified entries. */
362 for (i
= 0; i
< TX_POLICY_CACHE_SIZE
; ++i
) {
363 struct tx_policy
*src
= &cache
->cache
[i
].policy
;
364 if (src
->retry_count
&& !src
->uploaded
) {
365 struct wsm_tx_rate_retry_policy
*dst
=
368 dst
->short_retries
= priv
->short_frame_max_tx_count
;
369 dst
->long_retries
= priv
->long_frame_max_tx_count
;
371 dst
->flags
= WSM_TX_RATE_POLICY_FLAG_TERMINATE_WHEN_FINISHED
|
372 WSM_TX_RATE_POLICY_FLAG_COUNT_INITIAL_TRANSMIT
;
373 memcpy(dst
->rate_count_indices
, src
->tbl
,
374 sizeof(dst
->rate_count_indices
));
379 spin_unlock_bh(&cache
->lock
);
380 cw1200_debug_tx_cache_miss(priv
);
381 pr_debug("[TX policy] Upload %d policies\n", arg
.num
);
382 return wsm_set_tx_rate_retry_policy(priv
, &arg
);
385 void tx_policy_upload_work(struct work_struct
*work
)
387 struct cw1200_common
*priv
=
388 container_of(work
, struct cw1200_common
, tx_policy_upload_work
);
390 pr_debug("[TX] TX policy upload.\n");
391 tx_policy_upload(priv
);
394 cw1200_tx_queues_unlock(priv
);
397 /* ******************************************************************** */
398 /* cw1200 TX implementation */
400 struct cw1200_txinfo
{
403 struct ieee80211_tx_info
*tx_info
;
404 const struct ieee80211_rate
*rate
;
405 struct ieee80211_hdr
*hdr
;
408 struct cw1200_sta_priv
*sta_priv
;
409 struct ieee80211_sta
*sta
;
410 struct cw1200_txpriv txpriv
;
413 u32
cw1200_rate_mask_to_wsm(struct cw1200_common
*priv
, u32 rates
)
417 for (i
= 0; i
< 32; ++i
) {
419 ret
|= BIT(priv
->rates
[i
].hw_value
);
424 static const struct ieee80211_rate
*
425 cw1200_get_tx_rate(const struct cw1200_common
*priv
,
426 const struct ieee80211_tx_rate
*rate
)
430 if (rate
->flags
& IEEE80211_TX_RC_MCS
)
431 return &priv
->mcs_rates
[rate
->idx
];
432 return &priv
->hw
->wiphy
->bands
[priv
->channel
->band
]->
437 cw1200_tx_h_calc_link_ids(struct cw1200_common
*priv
,
438 struct cw1200_txinfo
*t
)
440 if (t
->sta
&& t
->sta_priv
->link_id
)
441 t
->txpriv
.raw_link_id
=
443 t
->sta_priv
->link_id
;
444 else if (priv
->mode
!= NL80211_IFTYPE_AP
)
445 t
->txpriv
.raw_link_id
=
446 t
->txpriv
.link_id
= 0;
447 else if (is_multicast_ether_addr(t
->da
)) {
448 if (priv
->enable_beacon
) {
449 t
->txpriv
.raw_link_id
= 0;
450 t
->txpriv
.link_id
= CW1200_LINK_ID_AFTER_DTIM
;
452 t
->txpriv
.raw_link_id
= 0;
453 t
->txpriv
.link_id
= 0;
456 t
->txpriv
.link_id
= cw1200_find_link_id(priv
, t
->da
);
457 if (!t
->txpriv
.link_id
)
458 t
->txpriv
.link_id
= cw1200_alloc_link_id(priv
, t
->da
);
459 if (!t
->txpriv
.link_id
) {
460 wiphy_err(priv
->hw
->wiphy
,
461 "No more link IDs available.\n");
464 t
->txpriv
.raw_link_id
= t
->txpriv
.link_id
;
466 if (t
->txpriv
.raw_link_id
)
467 priv
->link_id_db
[t
->txpriv
.raw_link_id
- 1].timestamp
=
469 if (t
->sta
&& (t
->sta
->uapsd_queues
& BIT(t
->queue
)))
470 t
->txpriv
.link_id
= CW1200_LINK_ID_UAPSD
;
475 cw1200_tx_h_pm(struct cw1200_common
*priv
,
476 struct cw1200_txinfo
*t
)
478 if (ieee80211_is_auth(t
->hdr
->frame_control
)) {
479 u32 mask
= ~BIT(t
->txpriv
.raw_link_id
);
480 spin_lock_bh(&priv
->ps_state_lock
);
481 priv
->sta_asleep_mask
&= mask
;
482 priv
->pspoll_mask
&= mask
;
483 spin_unlock_bh(&priv
->ps_state_lock
);
488 cw1200_tx_h_calc_tid(struct cw1200_common
*priv
,
489 struct cw1200_txinfo
*t
)
491 if (ieee80211_is_data_qos(t
->hdr
->frame_control
)) {
492 u8
*qos
= ieee80211_get_qos_ctl(t
->hdr
);
493 t
->txpriv
.tid
= qos
[0] & IEEE80211_QOS_CTL_TID_MASK
;
494 } else if (ieee80211_is_data(t
->hdr
->frame_control
)) {
500 cw1200_tx_h_crypt(struct cw1200_common
*priv
,
501 struct cw1200_txinfo
*t
)
503 if (!t
->tx_info
->control
.hw_key
||
504 !ieee80211_has_protected(t
->hdr
->frame_control
))
507 t
->hdrlen
+= t
->tx_info
->control
.hw_key
->iv_len
;
508 skb_put(t
->skb
, t
->tx_info
->control
.hw_key
->icv_len
);
510 if (t
->tx_info
->control
.hw_key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
511 skb_put(t
->skb
, 8); /* MIC space */
517 cw1200_tx_h_align(struct cw1200_common
*priv
,
518 struct cw1200_txinfo
*t
,
521 size_t offset
= (size_t)t
->skb
->data
& 3;
527 wiphy_err(priv
->hw
->wiphy
,
528 "Bug: attempt to transmit a frame with wrong alignment: %zu\n",
533 if (skb_headroom(t
->skb
) < offset
) {
534 wiphy_err(priv
->hw
->wiphy
,
535 "Bug: no space allocated for DMA alignment. headroom: %d\n",
536 skb_headroom(t
->skb
));
539 skb_push(t
->skb
, offset
);
541 t
->txpriv
.offset
+= offset
;
542 *flags
|= WSM_TX_2BYTES_SHIFT
;
543 cw1200_debug_tx_align(priv
);
548 cw1200_tx_h_action(struct cw1200_common
*priv
,
549 struct cw1200_txinfo
*t
)
551 struct ieee80211_mgmt
*mgmt
=
552 (struct ieee80211_mgmt
*)t
->hdr
;
553 if (ieee80211_is_action(t
->hdr
->frame_control
) &&
554 mgmt
->u
.action
.category
== WLAN_CATEGORY_BACK
)
561 static struct wsm_tx
*
562 cw1200_tx_h_wsm(struct cw1200_common
*priv
,
563 struct cw1200_txinfo
*t
)
567 if (skb_headroom(t
->skb
) < sizeof(struct wsm_tx
)) {
568 wiphy_err(priv
->hw
->wiphy
,
569 "Bug: no space allocated for WSM header. headroom: %d\n",
570 skb_headroom(t
->skb
));
574 wsm
= skb_push(t
->skb
, sizeof(struct wsm_tx
));
575 t
->txpriv
.offset
+= sizeof(struct wsm_tx
);
576 memset(wsm
, 0, sizeof(*wsm
));
577 wsm
->hdr
.len
= __cpu_to_le16(t
->skb
->len
);
578 wsm
->hdr
.id
= __cpu_to_le16(0x0004);
579 wsm
->queue_id
= wsm_queue_id_to_wsm(t
->queue
);
583 /* BT Coex specific handling */
585 cw1200_tx_h_bt(struct cw1200_common
*priv
,
586 struct cw1200_txinfo
*t
,
591 if (!priv
->bt_present
)
594 if (ieee80211_is_nullfunc(t
->hdr
->frame_control
)) {
595 priority
= WSM_EPTA_PRIORITY_MGT
;
596 } else if (ieee80211_is_data(t
->hdr
->frame_control
)) {
597 /* Skip LLC SNAP header (+6) */
598 u8
*payload
= &t
->skb
->data
[t
->hdrlen
];
599 __be16
*ethertype
= (__be16
*)&payload
[6];
600 if (be16_to_cpu(*ethertype
) == ETH_P_PAE
)
601 priority
= WSM_EPTA_PRIORITY_EAPOL
;
602 } else if (ieee80211_is_assoc_req(t
->hdr
->frame_control
) ||
603 ieee80211_is_reassoc_req(t
->hdr
->frame_control
)) {
604 struct ieee80211_mgmt
*mgt_frame
=
605 (struct ieee80211_mgmt
*)t
->hdr
;
607 if (le16_to_cpu(mgt_frame
->u
.assoc_req
.listen_interval
) <
608 priv
->listen_interval
) {
609 pr_debug("Modified Listen Interval to %d from %d\n",
610 priv
->listen_interval
,
611 mgt_frame
->u
.assoc_req
.listen_interval
);
612 /* Replace listen interval derieved from
613 * the one read from SDD
615 mgt_frame
->u
.assoc_req
.listen_interval
= cpu_to_le16(priv
->listen_interval
);
620 if (ieee80211_is_action(t
->hdr
->frame_control
))
621 priority
= WSM_EPTA_PRIORITY_ACTION
;
622 else if (ieee80211_is_mgmt(t
->hdr
->frame_control
))
623 priority
= WSM_EPTA_PRIORITY_MGT
;
624 else if (wsm
->queue_id
== WSM_QUEUE_VOICE
)
625 priority
= WSM_EPTA_PRIORITY_VOICE
;
626 else if (wsm
->queue_id
== WSM_QUEUE_VIDEO
)
627 priority
= WSM_EPTA_PRIORITY_VIDEO
;
629 priority
= WSM_EPTA_PRIORITY_DATA
;
632 pr_debug("[TX] EPTA priority %d.\n", priority
);
634 wsm
->flags
|= priority
<< 1;
638 cw1200_tx_h_rate_policy(struct cw1200_common
*priv
,
639 struct cw1200_txinfo
*t
,
642 bool tx_policy_renew
= false;
644 t
->txpriv
.rate_id
= tx_policy_get(priv
,
645 t
->tx_info
->control
.rates
, IEEE80211_TX_MAX_RATES
,
647 if (t
->txpriv
.rate_id
== CW1200_INVALID_RATE_ID
)
650 wsm
->flags
|= t
->txpriv
.rate_id
<< 4;
652 t
->rate
= cw1200_get_tx_rate(priv
,
653 &t
->tx_info
->control
.rates
[0]),
654 wsm
->max_tx_rate
= t
->rate
->hw_value
;
655 if (t
->rate
->flags
& IEEE80211_TX_RC_MCS
) {
656 if (cw1200_ht_greenfield(&priv
->ht_info
))
657 wsm
->ht_tx_parameters
|=
658 __cpu_to_le32(WSM_HT_TX_GREENFIELD
);
660 wsm
->ht_tx_parameters
|=
661 __cpu_to_le32(WSM_HT_TX_MIXED
);
664 if (tx_policy_renew
) {
665 pr_debug("[TX] TX policy renew.\n");
666 /* It's not so optimal to stop TX queues every now and then.
667 * Better to reimplement task scheduling with
670 wsm_lock_tx_async(priv
);
671 cw1200_tx_queues_lock(priv
);
672 if (queue_work(priv
->workqueue
,
673 &priv
->tx_policy_upload_work
) <= 0) {
674 cw1200_tx_queues_unlock(priv
);
682 cw1200_tx_h_pm_state(struct cw1200_common
*priv
,
683 struct cw1200_txinfo
*t
)
685 int was_buffered
= 1;
687 if (t
->txpriv
.link_id
== CW1200_LINK_ID_AFTER_DTIM
&&
688 !priv
->buffered_multicasts
) {
689 priv
->buffered_multicasts
= true;
690 if (priv
->sta_asleep_mask
)
691 queue_work(priv
->workqueue
,
692 &priv
->multicast_start_work
);
695 if (t
->txpriv
.raw_link_id
&& t
->txpriv
.tid
< CW1200_MAX_TID
)
696 was_buffered
= priv
->link_id_db
[t
->txpriv
.raw_link_id
- 1].buffered
[t
->txpriv
.tid
]++;
698 return !was_buffered
;
701 /* ******************************************************************** */
703 void cw1200_tx(struct ieee80211_hw
*dev
,
704 struct ieee80211_tx_control
*control
,
707 struct cw1200_common
*priv
= dev
->priv
;
708 struct cw1200_txinfo t
= {
710 .queue
= skb_get_queue_mapping(skb
),
711 .tx_info
= IEEE80211_SKB_CB(skb
),
712 .hdr
= (struct ieee80211_hdr
*)skb
->data
,
713 .txpriv
.tid
= CW1200_MAX_TID
,
714 .txpriv
.rate_id
= CW1200_INVALID_RATE_ID
,
716 struct ieee80211_sta
*sta
;
718 bool tid_update
= false;
725 t
.hdrlen
= ieee80211_hdrlen(t
.hdr
->frame_control
);
726 t
.da
= ieee80211_get_DA(t
.hdr
);
728 t
.sta
= control
->sta
;
729 t
.sta_priv
= (struct cw1200_sta_priv
*)&t
.sta
->drv_priv
;
732 if (WARN_ON(t
.queue
>= 4))
735 ret
= cw1200_tx_h_calc_link_ids(priv
, &t
);
739 pr_debug("[TX] TX %d bytes (queue: %d, link_id: %d (%d)).\n",
740 skb
->len
, t
.queue
, t
.txpriv
.link_id
,
741 t
.txpriv
.raw_link_id
);
743 cw1200_tx_h_pm(priv
, &t
);
744 cw1200_tx_h_calc_tid(priv
, &t
);
745 ret
= cw1200_tx_h_crypt(priv
, &t
);
748 ret
= cw1200_tx_h_align(priv
, &t
, &flags
);
751 ret
= cw1200_tx_h_action(priv
, &t
);
754 wsm
= cw1200_tx_h_wsm(priv
, &t
);
760 cw1200_tx_h_bt(priv
, &t
, wsm
);
761 ret
= cw1200_tx_h_rate_policy(priv
, &t
, wsm
);
766 sta
= rcu_dereference(t
.sta
);
768 spin_lock_bh(&priv
->ps_state_lock
);
770 tid_update
= cw1200_tx_h_pm_state(priv
, &t
);
771 BUG_ON(cw1200_queue_put(&priv
->tx_queue
[t
.queue
],
774 spin_unlock_bh(&priv
->ps_state_lock
);
776 if (tid_update
&& sta
)
777 ieee80211_sta_set_buffered(sta
, t
.txpriv
.tid
, true);
781 cw1200_bh_wakeup(priv
);
786 cw1200_skb_dtor(priv
, skb
, &t
.txpriv
);
790 /* ******************************************************************** */
792 static int cw1200_handle_action_rx(struct cw1200_common
*priv
,
795 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
797 /* Filter block ACK negotiation: fully controlled by firmware */
798 if (mgmt
->u
.action
.category
== WLAN_CATEGORY_BACK
)
804 static int cw1200_handle_pspoll(struct cw1200_common
*priv
,
807 struct ieee80211_sta
*sta
;
808 struct ieee80211_pspoll
*pspoll
= (struct ieee80211_pspoll
*)skb
->data
;
814 if (priv
->join_status
!= CW1200_JOIN_STATUS_AP
)
816 if (memcmp(priv
->vif
->addr
, pspoll
->bssid
, ETH_ALEN
))
820 sta
= ieee80211_find_sta(priv
->vif
, pspoll
->ta
);
822 struct cw1200_sta_priv
*sta_priv
;
823 sta_priv
= (struct cw1200_sta_priv
*)&sta
->drv_priv
;
824 link_id
= sta_priv
->link_id
;
825 pspoll_mask
= BIT(sta_priv
->link_id
);
831 priv
->pspoll_mask
|= pspoll_mask
;
834 /* Do not report pspols if data for given link id is queued already. */
835 for (i
= 0; i
< 4; ++i
) {
836 if (cw1200_queue_get_num_queued(&priv
->tx_queue
[i
],
838 cw1200_bh_wakeup(priv
);
843 pr_debug("[RX] PSPOLL: %s\n", drop
? "local" : "fwd");
848 /* ******************************************************************** */
850 void cw1200_tx_confirm_cb(struct cw1200_common
*priv
,
852 struct wsm_tx_confirm
*arg
)
854 u8 queue_id
= cw1200_queue_get_queue_id(arg
->packet_id
);
855 struct cw1200_queue
*queue
= &priv
->tx_queue
[queue_id
];
857 const struct cw1200_txpriv
*txpriv
;
859 pr_debug("[TX] TX confirm: %d, %d.\n",
860 arg
->status
, arg
->ack_failures
);
862 if (priv
->mode
== NL80211_IFTYPE_UNSPECIFIED
) {
863 /* STA is stopped. */
867 if (WARN_ON(queue_id
>= 4))
871 pr_debug("TX failed: %d.\n", arg
->status
);
873 if ((arg
->status
== WSM_REQUEUE
) &&
874 (arg
->flags
& WSM_TX_STATUS_REQUEUE
)) {
875 /* "Requeue" means "implicit suspend" */
876 struct wsm_suspend_resume suspend
= {
879 .multicast
= !link_id
,
881 cw1200_suspend_resume(priv
, &suspend
);
882 wiphy_warn(priv
->hw
->wiphy
, "Requeue for link_id %d (try %d). STAs asleep: 0x%.8X\n",
884 cw1200_queue_get_generation(arg
->packet_id
) + 1,
885 priv
->sta_asleep_mask
);
886 cw1200_queue_requeue(queue
, arg
->packet_id
);
887 spin_lock_bh(&priv
->ps_state_lock
);
889 priv
->buffered_multicasts
= true;
890 if (priv
->sta_asleep_mask
) {
891 queue_work(priv
->workqueue
,
892 &priv
->multicast_start_work
);
895 spin_unlock_bh(&priv
->ps_state_lock
);
896 } else if (!cw1200_queue_get_skb(queue
, arg
->packet_id
,
898 struct ieee80211_tx_info
*tx
= IEEE80211_SKB_CB(skb
);
899 int tx_count
= arg
->ack_failures
;
903 if (cw1200_ht_greenfield(&priv
->ht_info
))
904 ht_flags
|= IEEE80211_TX_RC_GREEN_FIELD
;
906 spin_lock(&priv
->bss_loss_lock
);
907 if (priv
->bss_loss_state
&&
908 arg
->packet_id
== priv
->bss_loss_confirm_id
) {
910 /* Recovery failed */
911 __cw1200_cqm_bssloss_sm(priv
, 0, 0, 1);
913 /* Recovery succeeded */
914 __cw1200_cqm_bssloss_sm(priv
, 0, 1, 0);
917 spin_unlock(&priv
->bss_loss_lock
);
920 tx
->flags
|= IEEE80211_TX_STAT_ACK
;
922 cw1200_debug_txed(priv
);
923 if (arg
->flags
& WSM_TX_STATUS_AGGREGATION
) {
924 /* Do not report aggregation to mac80211:
925 * it confuses minstrel a lot.
927 /* tx->flags |= IEEE80211_TX_STAT_AMPDU; */
928 cw1200_debug_txed_agg(priv
);
935 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; ++i
) {
936 if (tx
->status
.rates
[i
].count
>= tx_count
) {
937 tx
->status
.rates
[i
].count
= tx_count
;
940 tx_count
-= tx
->status
.rates
[i
].count
;
941 if (tx
->status
.rates
[i
].flags
& IEEE80211_TX_RC_MCS
)
942 tx
->status
.rates
[i
].flags
|= ht_flags
;
945 for (++i
; i
< IEEE80211_TX_MAX_RATES
; ++i
) {
946 tx
->status
.rates
[i
].count
= 0;
947 tx
->status
.rates
[i
].idx
= -1;
950 /* Pull off any crypto trailers that we added on */
951 if (tx
->control
.hw_key
) {
952 skb_trim(skb
, skb
->len
- tx
->control
.hw_key
->icv_len
);
953 if (tx
->control
.hw_key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
954 skb_trim(skb
, skb
->len
- 8); /* MIC space */
956 cw1200_queue_remove(queue
, arg
->packet_id
);
958 /* XXX TODO: Only wake if there are pending transmits.. */
959 cw1200_bh_wakeup(priv
);
962 static void cw1200_notify_buffered_tx(struct cw1200_common
*priv
,
963 struct sk_buff
*skb
, int link_id
, int tid
)
965 struct ieee80211_sta
*sta
;
966 struct ieee80211_hdr
*hdr
;
968 u8 still_buffered
= 0;
970 if (link_id
&& tid
< CW1200_MAX_TID
) {
971 buffered
= priv
->link_id_db
972 [link_id
- 1].buffered
;
974 spin_lock_bh(&priv
->ps_state_lock
);
975 if (!WARN_ON(!buffered
[tid
]))
976 still_buffered
= --buffered
[tid
];
977 spin_unlock_bh(&priv
->ps_state_lock
);
979 if (!still_buffered
&& tid
< CW1200_MAX_TID
) {
980 hdr
= (struct ieee80211_hdr
*)skb
->data
;
982 sta
= ieee80211_find_sta(priv
->vif
, hdr
->addr1
);
984 ieee80211_sta_set_buffered(sta
, tid
, false);
990 void cw1200_skb_dtor(struct cw1200_common
*priv
,
992 const struct cw1200_txpriv
*txpriv
)
994 skb_pull(skb
, txpriv
->offset
);
995 if (txpriv
->rate_id
!= CW1200_INVALID_RATE_ID
) {
996 cw1200_notify_buffered_tx(priv
, skb
,
997 txpriv
->raw_link_id
, txpriv
->tid
);
998 tx_policy_put(priv
, txpriv
->rate_id
);
1000 ieee80211_tx_status(priv
->hw
, skb
);
1003 void cw1200_rx_cb(struct cw1200_common
*priv
,
1006 struct sk_buff
**skb_p
)
1008 struct sk_buff
*skb
= *skb_p
;
1009 struct ieee80211_rx_status
*hdr
= IEEE80211_SKB_RXCB(skb
);
1010 struct ieee80211_hdr
*frame
= (struct ieee80211_hdr
*)skb
->data
;
1011 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)skb
->data
;
1012 struct cw1200_link_entry
*entry
= NULL
;
1013 unsigned long grace_period
;
1015 bool early_data
= false;
1016 bool p2p
= priv
->vif
&& priv
->vif
->p2p
;
1020 if (priv
->mode
== NL80211_IFTYPE_UNSPECIFIED
) {
1021 /* STA is stopped. */
1025 if (link_id
&& link_id
<= CW1200_MAX_STA_IN_AP_MODE
) {
1026 entry
= &priv
->link_id_db
[link_id
- 1];
1027 if (entry
->status
== CW1200_LINK_SOFT
&&
1028 ieee80211_is_data(frame
->frame_control
))
1030 entry
->timestamp
= jiffies
;
1032 ieee80211_is_action(frame
->frame_control
) &&
1033 (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
)) {
1034 pr_debug("[RX] Going to MAP&RESET link ID\n");
1035 WARN_ON(work_pending(&priv
->linkid_reset_work
));
1036 memcpy(&priv
->action_frame_sa
[0],
1037 ieee80211_get_SA(frame
), ETH_ALEN
);
1038 priv
->action_linkid
= 0;
1039 schedule_work(&priv
->linkid_reset_work
);
1042 if (link_id
&& p2p
&&
1043 ieee80211_is_action(frame
->frame_control
) &&
1044 (mgmt
->u
.action
.category
== WLAN_CATEGORY_PUBLIC
)) {
1045 /* Link ID already exists for the ACTION frame.
1048 WARN_ON(work_pending(&priv
->linkid_reset_work
));
1049 memcpy(&priv
->action_frame_sa
[0],
1050 ieee80211_get_SA(frame
), ETH_ALEN
);
1051 priv
->action_linkid
= link_id
;
1052 schedule_work(&priv
->linkid_reset_work
);
1055 if (arg
->status
== WSM_STATUS_MICFAILURE
) {
1056 pr_debug("[RX] MIC failure.\n");
1057 hdr
->flag
|= RX_FLAG_MMIC_ERROR
;
1058 } else if (arg
->status
== WSM_STATUS_NO_KEY_FOUND
) {
1059 pr_debug("[RX] No key found.\n");
1062 pr_debug("[RX] Receive failure: %d.\n",
1068 if (skb
->len
< sizeof(struct ieee80211_pspoll
)) {
1069 wiphy_warn(priv
->hw
->wiphy
, "Malformed SDU rx'ed. Size is lesser than IEEE header.\n");
1073 if (ieee80211_is_pspoll(frame
->frame_control
))
1074 if (cw1200_handle_pspoll(priv
, skb
))
1077 hdr
->band
= ((arg
->channel_number
& 0xff00) ||
1078 (arg
->channel_number
> 14)) ?
1079 NL80211_BAND_5GHZ
: NL80211_BAND_2GHZ
;
1080 hdr
->freq
= ieee80211_channel_to_frequency(
1081 arg
->channel_number
,
1084 if (arg
->rx_rate
>= 14) {
1085 hdr
->encoding
= RX_ENC_HT
;
1086 hdr
->rate_idx
= arg
->rx_rate
- 14;
1087 } else if (arg
->rx_rate
>= 4) {
1088 hdr
->rate_idx
= arg
->rx_rate
- 2;
1090 hdr
->rate_idx
= arg
->rx_rate
;
1093 hdr
->signal
= (s8
)arg
->rcpi_rssi
;
1096 hdrlen
= ieee80211_hdrlen(frame
->frame_control
);
1098 if (WSM_RX_STATUS_ENCRYPTION(arg
->flags
)) {
1099 size_t iv_len
= 0, icv_len
= 0;
1101 hdr
->flag
|= RX_FLAG_DECRYPTED
| RX_FLAG_IV_STRIPPED
;
1103 /* Oops... There is no fast way to ask mac80211 about
1104 * IV/ICV lengths. Even defineas are not exposed.
1106 switch (WSM_RX_STATUS_ENCRYPTION(arg
->flags
)) {
1107 case WSM_RX_STATUS_WEP
:
1108 iv_len
= 4 /* WEP_IV_LEN */;
1109 icv_len
= 4 /* WEP_ICV_LEN */;
1111 case WSM_RX_STATUS_TKIP
:
1112 iv_len
= 8 /* TKIP_IV_LEN */;
1113 icv_len
= 4 /* TKIP_ICV_LEN */
1114 + 8 /*MICHAEL_MIC_LEN*/;
1115 hdr
->flag
|= RX_FLAG_MMIC_STRIPPED
;
1117 case WSM_RX_STATUS_AES
:
1118 iv_len
= 8 /* CCMP_HDR_LEN */;
1119 icv_len
= 8 /* CCMP_MIC_LEN */;
1121 case WSM_RX_STATUS_WAPI
:
1122 iv_len
= 18 /* WAPI_HDR_LEN */;
1123 icv_len
= 16 /* WAPI_MIC_LEN */;
1126 pr_warn("Unknown encryption type %d\n",
1127 WSM_RX_STATUS_ENCRYPTION(arg
->flags
));
1131 /* Firmware strips ICV in case of MIC failure. */
1132 if (arg
->status
== WSM_STATUS_MICFAILURE
)
1135 if (skb
->len
< hdrlen
+ iv_len
+ icv_len
) {
1136 wiphy_warn(priv
->hw
->wiphy
, "Malformed SDU rx'ed. Size is lesser than crypto headers.\n");
1140 /* Remove IV, ICV and MIC */
1141 skb_trim(skb
, skb
->len
- icv_len
);
1142 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
1143 skb_pull(skb
, iv_len
);
1146 /* Remove TSF from the end of frame */
1147 if (arg
->flags
& WSM_RX_STATUS_TSF_INCLUDED
) {
1148 memcpy(&hdr
->mactime
, skb
->data
+ skb
->len
- 8, 8);
1149 hdr
->mactime
= le64_to_cpu(hdr
->mactime
);
1151 skb_trim(skb
, skb
->len
- 8);
1156 cw1200_debug_rxed(priv
);
1157 if (arg
->flags
& WSM_RX_STATUS_AGGREGATE
)
1158 cw1200_debug_rxed_agg(priv
);
1160 if (ieee80211_is_action(frame
->frame_control
) &&
1161 (arg
->flags
& WSM_RX_STATUS_ADDRESS1
)) {
1162 if (cw1200_handle_action_rx(priv
, skb
))
1164 } else if (ieee80211_is_beacon(frame
->frame_control
) &&
1165 !arg
->status
&& priv
->vif
&&
1166 ether_addr_equal(ieee80211_get_SA(frame
), priv
->vif
->bss_conf
.bssid
)) {
1168 u8
*ies
= ((struct ieee80211_mgmt
*)
1169 (skb
->data
))->u
.beacon
.variable
;
1170 size_t ies_len
= skb
->len
- (ies
- (u8
*)(skb
->data
));
1172 tim_ie
= cfg80211_find_ie(WLAN_EID_TIM
, ies
, ies_len
);
1174 struct ieee80211_tim_ie
*tim
=
1175 (struct ieee80211_tim_ie
*)&tim_ie
[2];
1177 if (priv
->join_dtim_period
!= tim
->dtim_period
) {
1178 priv
->join_dtim_period
= tim
->dtim_period
;
1179 queue_work(priv
->workqueue
,
1180 &priv
->set_beacon_wakeup_period_work
);
1184 /* Disable beacon filter once we're associated... */
1185 if (priv
->disable_beacon_filter
&&
1186 (priv
->vif
->bss_conf
.assoc
||
1187 priv
->vif
->bss_conf
.ibss_joined
)) {
1188 priv
->disable_beacon_filter
= false;
1189 queue_work(priv
->workqueue
,
1190 &priv
->update_filtering_work
);
1194 /* Stay awake after frame is received to give
1195 * userspace chance to react and acquire appropriate
1198 if (ieee80211_is_auth(frame
->frame_control
))
1199 grace_period
= 5 * HZ
;
1200 else if (ieee80211_is_deauth(frame
->frame_control
))
1201 grace_period
= 5 * HZ
;
1203 grace_period
= 1 * HZ
;
1204 cw1200_pm_stay_awake(&priv
->pm_state
, grace_period
);
1207 spin_lock_bh(&priv
->ps_state_lock
);
1208 /* Double-check status with lock held */
1209 if (entry
->status
== CW1200_LINK_SOFT
)
1210 skb_queue_tail(&entry
->rx_queue
, skb
);
1212 ieee80211_rx_irqsafe(priv
->hw
, skb
);
1213 spin_unlock_bh(&priv
->ps_state_lock
);
1215 ieee80211_rx_irqsafe(priv
->hw
, skb
);
1222 /* TODO: update failure counters */
1226 /* ******************************************************************** */
1229 int cw1200_alloc_key(struct cw1200_common
*priv
)
1233 idx
= ffs(~priv
->key_map
) - 1;
1234 if (idx
< 0 || idx
> WSM_KEY_MAX_INDEX
)
1237 priv
->key_map
|= BIT(idx
);
1238 priv
->keys
[idx
].index
= idx
;
1242 void cw1200_free_key(struct cw1200_common
*priv
, int idx
)
1244 BUG_ON(!(priv
->key_map
& BIT(idx
)));
1245 memset(&priv
->keys
[idx
], 0, sizeof(priv
->keys
[idx
]));
1246 priv
->key_map
&= ~BIT(idx
);
1249 void cw1200_free_keys(struct cw1200_common
*priv
)
1251 memset(&priv
->keys
, 0, sizeof(priv
->keys
));
1255 int cw1200_upload_keys(struct cw1200_common
*priv
)
1258 for (idx
= 0; idx
<= WSM_KEY_MAX_INDEX
; ++idx
)
1259 if (priv
->key_map
& BIT(idx
)) {
1260 ret
= wsm_add_key(priv
, &priv
->keys
[idx
]);
1267 /* Workaround for WFD test case 6.1.10 */
1268 void cw1200_link_id_reset(struct work_struct
*work
)
1270 struct cw1200_common
*priv
=
1271 container_of(work
, struct cw1200_common
, linkid_reset_work
);
1274 if (!priv
->action_linkid
) {
1275 /* In GO mode we can receive ACTION frames without a linkID */
1276 temp_linkid
= cw1200_alloc_link_id(priv
,
1277 &priv
->action_frame_sa
[0]);
1278 WARN_ON(!temp_linkid
);
1280 /* Make sure we execute the WQ */
1281 flush_workqueue(priv
->workqueue
);
1282 /* Release the link ID */
1283 spin_lock_bh(&priv
->ps_state_lock
);
1284 priv
->link_id_db
[temp_linkid
- 1].prev_status
=
1285 priv
->link_id_db
[temp_linkid
- 1].status
;
1286 priv
->link_id_db
[temp_linkid
- 1].status
=
1288 spin_unlock_bh(&priv
->ps_state_lock
);
1289 wsm_lock_tx_async(priv
);
1290 if (queue_work(priv
->workqueue
,
1291 &priv
->link_id_work
) <= 0)
1292 wsm_unlock_tx(priv
);
1295 spin_lock_bh(&priv
->ps_state_lock
);
1296 priv
->link_id_db
[priv
->action_linkid
- 1].prev_status
=
1297 priv
->link_id_db
[priv
->action_linkid
- 1].status
;
1298 priv
->link_id_db
[priv
->action_linkid
- 1].status
=
1299 CW1200_LINK_RESET_REMAP
;
1300 spin_unlock_bh(&priv
->ps_state_lock
);
1301 wsm_lock_tx_async(priv
);
1302 if (queue_work(priv
->workqueue
, &priv
->link_id_work
) <= 0)
1303 wsm_unlock_tx(priv
);
1304 flush_workqueue(priv
->workqueue
);
1308 int cw1200_find_link_id(struct cw1200_common
*priv
, const u8
*mac
)
1311 spin_lock_bh(&priv
->ps_state_lock
);
1312 for (i
= 0; i
< CW1200_MAX_STA_IN_AP_MODE
; ++i
) {
1313 if (!memcmp(mac
, priv
->link_id_db
[i
].mac
, ETH_ALEN
) &&
1314 priv
->link_id_db
[i
].status
) {
1315 priv
->link_id_db
[i
].timestamp
= jiffies
;
1320 spin_unlock_bh(&priv
->ps_state_lock
);
1324 int cw1200_alloc_link_id(struct cw1200_common
*priv
, const u8
*mac
)
1327 unsigned long max_inactivity
= 0;
1328 unsigned long now
= jiffies
;
1330 spin_lock_bh(&priv
->ps_state_lock
);
1331 for (i
= 0; i
< CW1200_MAX_STA_IN_AP_MODE
; ++i
) {
1332 if (!priv
->link_id_db
[i
].status
) {
1335 } else if (priv
->link_id_db
[i
].status
!= CW1200_LINK_HARD
&&
1336 !priv
->tx_queue_stats
.link_map_cache
[i
+ 1]) {
1337 unsigned long inactivity
=
1338 now
- priv
->link_id_db
[i
].timestamp
;
1339 if (inactivity
< max_inactivity
)
1341 max_inactivity
= inactivity
;
1346 struct cw1200_link_entry
*entry
= &priv
->link_id_db
[ret
- 1];
1347 pr_debug("[AP] STA added, link_id: %d\n", ret
);
1348 entry
->status
= CW1200_LINK_RESERVE
;
1349 memcpy(&entry
->mac
, mac
, ETH_ALEN
);
1350 memset(&entry
->buffered
, 0, CW1200_MAX_TID
);
1351 skb_queue_head_init(&entry
->rx_queue
);
1352 wsm_lock_tx_async(priv
);
1353 if (queue_work(priv
->workqueue
, &priv
->link_id_work
) <= 0)
1354 wsm_unlock_tx(priv
);
1356 wiphy_info(priv
->hw
->wiphy
,
1357 "[AP] Early: no more link IDs available.\n");
1360 spin_unlock_bh(&priv
->ps_state_lock
);
1364 void cw1200_link_id_work(struct work_struct
*work
)
1366 struct cw1200_common
*priv
=
1367 container_of(work
, struct cw1200_common
, link_id_work
);
1369 cw1200_link_id_gc_work(&priv
->link_id_gc_work
.work
);
1370 wsm_unlock_tx(priv
);
1373 void cw1200_link_id_gc_work(struct work_struct
*work
)
1375 struct cw1200_common
*priv
=
1376 container_of(work
, struct cw1200_common
, link_id_gc_work
.work
);
1377 struct wsm_reset reset
= {
1378 .reset_statistics
= false,
1380 struct wsm_map_link map_link
= {
1383 unsigned long now
= jiffies
;
1384 unsigned long next_gc
= -1;
1390 if (priv
->join_status
!= CW1200_JOIN_STATUS_AP
)
1394 spin_lock_bh(&priv
->ps_state_lock
);
1395 for (i
= 0; i
< CW1200_MAX_STA_IN_AP_MODE
; ++i
) {
1398 if (priv
->link_id_db
[i
].status
== CW1200_LINK_RESERVE
||
1399 (priv
->link_id_db
[i
].status
== CW1200_LINK_HARD
&&
1400 !(priv
->link_id_map
& mask
))) {
1401 if (priv
->link_id_map
& mask
) {
1402 priv
->sta_asleep_mask
&= ~mask
;
1403 priv
->pspoll_mask
&= ~mask
;
1406 priv
->link_id_map
|= mask
;
1407 if (priv
->link_id_db
[i
].status
!= CW1200_LINK_HARD
)
1408 priv
->link_id_db
[i
].status
= CW1200_LINK_SOFT
;
1409 memcpy(map_link
.mac_addr
, priv
->link_id_db
[i
].mac
,
1411 spin_unlock_bh(&priv
->ps_state_lock
);
1413 reset
.link_id
= i
+ 1;
1414 wsm_reset(priv
, &reset
);
1416 map_link
.link_id
= i
+ 1;
1417 wsm_map_link(priv
, &map_link
);
1418 next_gc
= min(next_gc
, CW1200_LINK_ID_GC_TIMEOUT
);
1419 spin_lock_bh(&priv
->ps_state_lock
);
1420 } else if (priv
->link_id_db
[i
].status
== CW1200_LINK_SOFT
) {
1421 ttl
= priv
->link_id_db
[i
].timestamp
- now
+
1422 CW1200_LINK_ID_GC_TIMEOUT
;
1425 priv
->link_id_db
[i
].status
= CW1200_LINK_OFF
;
1426 priv
->link_id_map
&= ~mask
;
1427 priv
->sta_asleep_mask
&= ~mask
;
1428 priv
->pspoll_mask
&= ~mask
;
1429 eth_zero_addr(map_link
.mac_addr
);
1430 spin_unlock_bh(&priv
->ps_state_lock
);
1431 reset
.link_id
= i
+ 1;
1432 wsm_reset(priv
, &reset
);
1433 spin_lock_bh(&priv
->ps_state_lock
);
1435 next_gc
= min_t(unsigned long, next_gc
, ttl
);
1437 } else if (priv
->link_id_db
[i
].status
== CW1200_LINK_RESET
||
1438 priv
->link_id_db
[i
].status
==
1439 CW1200_LINK_RESET_REMAP
) {
1440 int status
= priv
->link_id_db
[i
].status
;
1441 priv
->link_id_db
[i
].status
=
1442 priv
->link_id_db
[i
].prev_status
;
1443 priv
->link_id_db
[i
].timestamp
= now
;
1444 reset
.link_id
= i
+ 1;
1445 spin_unlock_bh(&priv
->ps_state_lock
);
1446 wsm_reset(priv
, &reset
);
1447 if (status
== CW1200_LINK_RESET_REMAP
) {
1448 memcpy(map_link
.mac_addr
,
1449 priv
->link_id_db
[i
].mac
,
1451 map_link
.link_id
= i
+ 1;
1452 wsm_map_link(priv
, &map_link
);
1453 next_gc
= min(next_gc
,
1454 CW1200_LINK_ID_GC_TIMEOUT
);
1456 spin_lock_bh(&priv
->ps_state_lock
);
1459 skb_queue_purge(&priv
->link_id_db
[i
].rx_queue
);
1460 pr_debug("[AP] STA removed, link_id: %d\n",
1464 spin_unlock_bh(&priv
->ps_state_lock
);
1466 queue_delayed_work(priv
->workqueue
,
1467 &priv
->link_id_gc_work
, next_gc
);
1468 wsm_unlock_tx(priv
);