2 * Atheros CARL9170 driver
4 * 802.11 xmit & status routines
6 * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright 2009, 2010, Christian Lamparter <chunkeey@googlemail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; see the file COPYING. If not, see
21 * http://www.gnu.org/licenses/.
23 * This file incorporates work covered by the following copyright and
25 * Copyright (c) 2007-2008 Atheros Communications, Inc.
27 * Permission to use, copy, modify, and/or distribute this software for any
28 * purpose with or without fee is hereby granted, provided that the above
29 * copyright notice and this permission notice appear in all copies.
31 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
32 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
34 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
35 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
36 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
37 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
40 #include <linux/init.h>
41 #include <linux/slab.h>
42 #include <linux/module.h>
43 #include <linux/etherdevice.h>
44 #include <net/mac80211.h>
49 static inline unsigned int __carl9170_get_queue(struct ar9170
*ar
,
52 if (unlikely(modparam_noht
)) {
56 * This is just another workaround, until
57 * someone figures out how to get QoS and
58 * AMPDU to play nicely together.
65 static inline unsigned int carl9170_get_queue(struct ar9170
*ar
,
68 return __carl9170_get_queue(ar
, skb_get_queue_mapping(skb
));
71 static bool is_mem_full(struct ar9170
*ar
)
73 return (DIV_ROUND_UP(IEEE80211_MAX_FRAME_LEN
, ar
->fw
.mem_block_size
) >
74 atomic_read(&ar
->mem_free_blocks
));
77 static void carl9170_tx_accounting(struct ar9170
*ar
, struct sk_buff
*skb
)
82 atomic_inc(&ar
->tx_total_queued
);
84 queue
= skb_get_queue_mapping(skb
);
85 spin_lock_bh(&ar
->tx_stats_lock
);
88 * The driver has to accept the frame, regardless if the queue is
89 * full to the brim, or not. We have to do the queuing internally,
90 * since mac80211 assumes that a driver which can operate with
91 * aggregated frames does not reject frames for this reason.
93 ar
->tx_stats
[queue
].len
++;
94 ar
->tx_stats
[queue
].count
++;
96 mem_full
= is_mem_full(ar
);
97 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
98 if (mem_full
|| ar
->tx_stats
[i
].len
>= ar
->tx_stats
[i
].limit
) {
99 ieee80211_stop_queue(ar
->hw
, i
);
100 ar
->queue_stop_timeout
[i
] = jiffies
;
104 spin_unlock_bh(&ar
->tx_stats_lock
);
107 /* needs rcu_read_lock */
108 static struct ieee80211_sta
*__carl9170_get_tx_sta(struct ar9170
*ar
,
111 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
112 struct ieee80211_hdr
*hdr
= (void *) super
->frame_data
;
113 struct ieee80211_vif
*vif
;
116 vif_id
= (super
->s
.misc
& CARL9170_TX_SUPER_MISC_VIF_ID
) >>
117 CARL9170_TX_SUPER_MISC_VIF_ID_S
;
119 if (WARN_ON_ONCE(vif_id
>= AR9170_MAX_VIRTUAL_MAC
))
122 vif
= rcu_dereference(ar
->vif_priv
[vif_id
].vif
);
127 * Normally we should use wrappers like ieee80211_get_DA to get
128 * the correct peer ieee80211_sta.
130 * But there is a problem with indirect traffic (broadcasts, or
131 * data which is designated for other stations) in station mode.
132 * The frame will be directed to the AP for distribution and not
133 * to the actual destination.
136 return ieee80211_find_sta(vif
, hdr
->addr1
);
139 static void carl9170_tx_ps_unblock(struct ar9170
*ar
, struct sk_buff
*skb
)
141 struct ieee80211_sta
*sta
;
142 struct carl9170_sta_info
*sta_info
;
145 sta
= __carl9170_get_tx_sta(ar
, skb
);
149 sta_info
= (struct carl9170_sta_info
*) sta
->drv_priv
;
150 if (atomic_dec_return(&sta_info
->pending_frames
) == 0)
151 ieee80211_sta_block_awake(ar
->hw
, sta
, false);
157 static void carl9170_tx_accounting_free(struct ar9170
*ar
, struct sk_buff
*skb
)
161 queue
= skb_get_queue_mapping(skb
);
163 spin_lock_bh(&ar
->tx_stats_lock
);
165 ar
->tx_stats
[queue
].len
--;
167 if (!is_mem_full(ar
)) {
169 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
170 if (ar
->tx_stats
[i
].len
>= CARL9170_NUM_TX_LIMIT_SOFT
)
173 if (ieee80211_queue_stopped(ar
->hw
, i
)) {
176 tmp
= jiffies
- ar
->queue_stop_timeout
[i
];
177 if (tmp
> ar
->max_queue_stop_timeout
[i
])
178 ar
->max_queue_stop_timeout
[i
] = tmp
;
181 ieee80211_wake_queue(ar
->hw
, i
);
185 spin_unlock_bh(&ar
->tx_stats_lock
);
187 if (atomic_dec_and_test(&ar
->tx_total_queued
))
188 complete(&ar
->tx_flush
);
191 static int carl9170_alloc_dev_space(struct ar9170
*ar
, struct sk_buff
*skb
)
193 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
197 atomic_inc(&ar
->mem_allocs
);
199 chunks
= DIV_ROUND_UP(skb
->len
, ar
->fw
.mem_block_size
);
200 if (unlikely(atomic_sub_return(chunks
, &ar
->mem_free_blocks
) < 0)) {
201 atomic_add(chunks
, &ar
->mem_free_blocks
);
205 spin_lock_bh(&ar
->mem_lock
);
206 cookie
= bitmap_find_free_region(ar
->mem_bitmap
, ar
->fw
.mem_blocks
, 0);
207 spin_unlock_bh(&ar
->mem_lock
);
209 if (unlikely(cookie
< 0)) {
210 atomic_add(chunks
, &ar
->mem_free_blocks
);
214 super
= (void *) skb
->data
;
217 * Cookie #0 serves two special purposes:
218 * 1. The firmware might use it generate BlockACK frames
219 * in responds of an incoming BlockAckReqs.
221 * 2. Prevent double-free bugs.
223 super
->s
.cookie
= (u8
) cookie
+ 1;
227 static void carl9170_release_dev_space(struct ar9170
*ar
, struct sk_buff
*skb
)
229 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
232 /* make a local copy of the cookie */
233 cookie
= super
->s
.cookie
;
234 /* invalidate cookie */
238 * Do a out-of-bounds check on the cookie:
240 * * cookie "0" is reserved and won't be assigned to any
241 * out-going frame. Internally however, it is used to
242 * mark no longer/un-accounted frames and serves as a
243 * cheap way of preventing frames from being freed
244 * twice by _accident_. NB: There is a tiny race...
246 * * obviously, cookie number is limited by the amount
247 * of available memory blocks, so the number can
248 * never execeed the mem_blocks count.
250 if (unlikely(WARN_ON_ONCE(cookie
== 0) ||
251 WARN_ON_ONCE(cookie
> ar
->fw
.mem_blocks
)))
254 atomic_add(DIV_ROUND_UP(skb
->len
, ar
->fw
.mem_block_size
),
255 &ar
->mem_free_blocks
);
257 spin_lock_bh(&ar
->mem_lock
);
258 bitmap_release_region(ar
->mem_bitmap
, cookie
- 1, 0);
259 spin_unlock_bh(&ar
->mem_lock
);
262 /* Called from any context */
263 static void carl9170_tx_release(struct kref
*ref
)
266 struct carl9170_tx_info
*arinfo
;
267 struct ieee80211_tx_info
*txinfo
;
270 arinfo
= container_of(ref
, struct carl9170_tx_info
, ref
);
271 txinfo
= container_of((void *) arinfo
, struct ieee80211_tx_info
,
273 skb
= container_of((void *) txinfo
, struct sk_buff
, cb
);
276 if (WARN_ON_ONCE(!ar
))
280 offsetof(struct ieee80211_tx_info
, status
.ack_signal
) != 20);
282 memset(&txinfo
->status
.ack_signal
, 0,
283 sizeof(struct ieee80211_tx_info
) -
284 offsetof(struct ieee80211_tx_info
, status
.ack_signal
));
286 if (atomic_read(&ar
->tx_total_queued
))
287 ar
->tx_schedule
= true;
289 if (txinfo
->flags
& IEEE80211_TX_CTL_AMPDU
) {
290 if (!atomic_read(&ar
->tx_ampdu_upload
))
291 ar
->tx_ampdu_schedule
= true;
293 if (txinfo
->flags
& IEEE80211_TX_STAT_AMPDU
) {
294 struct _carl9170_tx_superframe
*super
;
296 super
= (void *)skb
->data
;
297 txinfo
->status
.ampdu_len
= super
->s
.rix
;
298 txinfo
->status
.ampdu_ack_len
= super
->s
.cnt
;
299 } else if ((txinfo
->flags
& IEEE80211_TX_STAT_ACK
) &&
300 !(txinfo
->flags
& IEEE80211_TX_CTL_REQ_TX_STATUS
)) {
302 * drop redundant tx_status reports:
304 * 1. ampdu_ack_len of the final tx_status does
305 * include the feedback of this particular frame.
307 * 2. tx_status_irqsafe only queues up to 128
308 * tx feedback reports and discards the rest.
310 * 3. minstrel_ht is picky, it only accepts
311 * reports of frames with the TX_STATUS_AMPDU flag.
313 * 4. mac80211 is not particularly interested in
314 * feedback either [CTL_REQ_TX_STATUS not set]
317 ieee80211_free_txskb(ar
->hw
, skb
);
321 * Either the frame transmission has failed or
322 * mac80211 requested tx status.
327 skb_pull(skb
, sizeof(struct _carl9170_tx_superframe
));
328 ieee80211_tx_status_irqsafe(ar
->hw
, skb
);
331 void carl9170_tx_get_skb(struct sk_buff
*skb
)
333 struct carl9170_tx_info
*arinfo
= (void *)
334 (IEEE80211_SKB_CB(skb
))->rate_driver_data
;
335 kref_get(&arinfo
->ref
);
338 int carl9170_tx_put_skb(struct sk_buff
*skb
)
340 struct carl9170_tx_info
*arinfo
= (void *)
341 (IEEE80211_SKB_CB(skb
))->rate_driver_data
;
343 return kref_put(&arinfo
->ref
, carl9170_tx_release
);
346 /* Caller must hold the tid_info->lock & rcu_read_lock */
347 static void carl9170_tx_shift_bm(struct ar9170
*ar
,
348 struct carl9170_sta_tid
*tid_info
, u16 seq
)
352 off
= SEQ_DIFF(seq
, tid_info
->bsn
);
354 if (WARN_ON_ONCE(off
>= CARL9170_BAW_BITS
))
358 * Sanity check. For each MPDU we set the bit in bitmap and
359 * clear it once we received the tx_status.
360 * But if the bit is already cleared then we've been bitten
363 WARN_ON_ONCE(!test_and_clear_bit(off
, tid_info
->bitmap
));
365 off
= SEQ_DIFF(tid_info
->snx
, tid_info
->bsn
);
366 if (WARN_ON_ONCE(off
>= CARL9170_BAW_BITS
))
369 if (!bitmap_empty(tid_info
->bitmap
, off
))
370 off
= find_first_bit(tid_info
->bitmap
, off
);
372 tid_info
->bsn
+= off
;
373 tid_info
->bsn
&= 0x0fff;
375 bitmap_shift_right(tid_info
->bitmap
, tid_info
->bitmap
,
376 off
, CARL9170_BAW_BITS
);
379 static void carl9170_tx_status_process_ampdu(struct ar9170
*ar
,
380 struct sk_buff
*skb
, struct ieee80211_tx_info
*txinfo
)
382 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
383 struct ieee80211_hdr
*hdr
= (void *) super
->frame_data
;
384 struct ieee80211_sta
*sta
;
385 struct carl9170_sta_info
*sta_info
;
386 struct carl9170_sta_tid
*tid_info
;
389 if (!(txinfo
->flags
& IEEE80211_TX_CTL_AMPDU
) ||
390 txinfo
->flags
& IEEE80211_TX_CTL_INJECTED
||
391 (!(super
->f
.mac_control
& cpu_to_le16(AR9170_TX_MAC_AGGR
))))
395 sta
= __carl9170_get_tx_sta(ar
, skb
);
399 tid
= get_tid_h(hdr
);
401 sta_info
= (void *) sta
->drv_priv
;
402 tid_info
= rcu_dereference(sta_info
->agg
[tid
]);
406 spin_lock_bh(&tid_info
->lock
);
407 if (likely(tid_info
->state
>= CARL9170_TID_STATE_IDLE
))
408 carl9170_tx_shift_bm(ar
, tid_info
, get_seq_h(hdr
));
410 if (sta_info
->stats
[tid
].clear
) {
411 sta_info
->stats
[tid
].clear
= false;
412 sta_info
->stats
[tid
].req
= false;
413 sta_info
->stats
[tid
].ampdu_len
= 0;
414 sta_info
->stats
[tid
].ampdu_ack_len
= 0;
417 sta_info
->stats
[tid
].ampdu_len
++;
418 if (txinfo
->status
.rates
[0].count
== 1)
419 sta_info
->stats
[tid
].ampdu_ack_len
++;
421 if (!(txinfo
->flags
& IEEE80211_TX_STAT_ACK
))
422 sta_info
->stats
[tid
].req
= true;
424 if (super
->f
.mac_control
& cpu_to_le16(AR9170_TX_MAC_IMM_BA
)) {
425 super
->s
.rix
= sta_info
->stats
[tid
].ampdu_len
;
426 super
->s
.cnt
= sta_info
->stats
[tid
].ampdu_ack_len
;
427 txinfo
->flags
|= IEEE80211_TX_STAT_AMPDU
;
428 if (sta_info
->stats
[tid
].req
)
429 txinfo
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
431 sta_info
->stats
[tid
].clear
= true;
433 spin_unlock_bh(&tid_info
->lock
);
439 static void carl9170_tx_bar_status(struct ar9170
*ar
, struct sk_buff
*skb
,
440 struct ieee80211_tx_info
*tx_info
)
442 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
443 struct ieee80211_bar
*bar
= (void *) super
->frame_data
;
446 * Unlike all other frames, the status report for BARs does
447 * not directly come from the hardware as it is incapable of
448 * matching a BA to a previously send BAR.
449 * Instead the RX-path will scan for incoming BAs and set the
450 * IEEE80211_TX_STAT_ACK if it sees one that was likely
451 * caused by a BAR from us.
454 if (unlikely(ieee80211_is_back_req(bar
->frame_control
)) &&
455 !(tx_info
->flags
& IEEE80211_TX_STAT_ACK
)) {
456 struct carl9170_bar_list_entry
*entry
;
457 int queue
= skb_get_queue_mapping(skb
);
460 list_for_each_entry_rcu(entry
, &ar
->bar_list
[queue
], list
) {
461 if (entry
->skb
== skb
) {
462 spin_lock_bh(&ar
->bar_list_lock
[queue
]);
463 list_del_rcu(&entry
->list
);
464 spin_unlock_bh(&ar
->bar_list_lock
[queue
]);
465 kfree_rcu(entry
, head
);
470 WARN(1, "bar not found in %d - ra:%pM ta:%pM c:%x ssn:%x\n",
471 queue
, bar
->ra
, bar
->ta
, bar
->control
,
478 void carl9170_tx_status(struct ar9170
*ar
, struct sk_buff
*skb
,
481 struct ieee80211_tx_info
*txinfo
;
483 carl9170_tx_accounting_free(ar
, skb
);
485 txinfo
= IEEE80211_SKB_CB(skb
);
487 carl9170_tx_bar_status(ar
, skb
, txinfo
);
490 txinfo
->flags
|= IEEE80211_TX_STAT_ACK
;
492 ar
->tx_ack_failures
++;
494 if (txinfo
->flags
& IEEE80211_TX_CTL_AMPDU
)
495 carl9170_tx_status_process_ampdu(ar
, skb
, txinfo
);
497 carl9170_tx_ps_unblock(ar
, skb
);
498 carl9170_tx_put_skb(skb
);
501 /* This function may be called form any context */
502 void carl9170_tx_callback(struct ar9170
*ar
, struct sk_buff
*skb
)
504 struct ieee80211_tx_info
*txinfo
= IEEE80211_SKB_CB(skb
);
506 atomic_dec(&ar
->tx_total_pending
);
508 if (txinfo
->flags
& IEEE80211_TX_CTL_AMPDU
)
509 atomic_dec(&ar
->tx_ampdu_upload
);
511 if (carl9170_tx_put_skb(skb
))
512 tasklet_hi_schedule(&ar
->usb_tasklet
);
515 static struct sk_buff
*carl9170_get_queued_skb(struct ar9170
*ar
, u8 cookie
,
516 struct sk_buff_head
*queue
)
520 spin_lock_bh(&queue
->lock
);
521 skb_queue_walk(queue
, skb
) {
522 struct _carl9170_tx_superframe
*txc
= (void *) skb
->data
;
524 if (txc
->s
.cookie
!= cookie
)
527 __skb_unlink(skb
, queue
);
528 spin_unlock_bh(&queue
->lock
);
530 carl9170_release_dev_space(ar
, skb
);
533 spin_unlock_bh(&queue
->lock
);
538 static void carl9170_tx_fill_rateinfo(struct ar9170
*ar
, unsigned int rix
,
539 unsigned int tries
, struct ieee80211_tx_info
*txinfo
)
543 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; i
++) {
544 if (txinfo
->status
.rates
[i
].idx
< 0)
548 txinfo
->status
.rates
[i
].count
= tries
;
554 for (; i
< IEEE80211_TX_MAX_RATES
; i
++) {
555 txinfo
->status
.rates
[i
].idx
= -1;
556 txinfo
->status
.rates
[i
].count
= 0;
560 static void carl9170_check_queue_stop_timeout(struct ar9170
*ar
)
564 struct ieee80211_tx_info
*txinfo
;
565 struct carl9170_tx_info
*arinfo
;
566 bool restart
= false;
568 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
569 spin_lock_bh(&ar
->tx_status
[i
].lock
);
571 skb
= skb_peek(&ar
->tx_status
[i
]);
576 txinfo
= IEEE80211_SKB_CB(skb
);
577 arinfo
= (void *) txinfo
->rate_driver_data
;
579 if (time_is_before_jiffies(arinfo
->timeout
+
580 msecs_to_jiffies(CARL9170_QUEUE_STUCK_TIMEOUT
)) == true)
584 spin_unlock_bh(&ar
->tx_status
[i
].lock
);
589 * At least one queue has been stuck for long enough.
590 * Give the device a kick and hope it gets back to
593 * possible reasons may include:
594 * - frames got lost/corrupted (bad connection to the device)
595 * - stalled rx processing/usb controller hiccups
596 * - firmware errors/bugs
597 * - every bug you can think of.
598 * - all bugs you can't...
601 carl9170_restart(ar
, CARL9170_RR_STUCK_TX
);
605 static void carl9170_tx_ampdu_timeout(struct ar9170
*ar
)
607 struct carl9170_sta_tid
*iter
;
609 struct ieee80211_tx_info
*txinfo
;
610 struct carl9170_tx_info
*arinfo
;
611 struct ieee80211_sta
*sta
;
614 list_for_each_entry_rcu(iter
, &ar
->tx_ampdu_list
, list
) {
615 if (iter
->state
< CARL9170_TID_STATE_IDLE
)
618 spin_lock_bh(&iter
->lock
);
619 skb
= skb_peek(&iter
->queue
);
623 txinfo
= IEEE80211_SKB_CB(skb
);
624 arinfo
= (void *)txinfo
->rate_driver_data
;
625 if (time_is_after_jiffies(arinfo
->timeout
+
626 msecs_to_jiffies(CARL9170_QUEUE_TIMEOUT
)))
629 sta
= __carl9170_get_tx_sta(ar
, skb
);
633 ieee80211_stop_tx_ba_session(sta
, iter
->tid
);
635 spin_unlock_bh(&iter
->lock
);
641 void carl9170_tx_janitor(struct work_struct
*work
)
643 struct ar9170
*ar
= container_of(work
, struct ar9170
,
648 ar
->tx_janitor_last_run
= jiffies
;
650 carl9170_check_queue_stop_timeout(ar
);
651 carl9170_tx_ampdu_timeout(ar
);
653 if (!atomic_read(&ar
->tx_total_queued
))
656 ieee80211_queue_delayed_work(ar
->hw
, &ar
->tx_janitor
,
657 msecs_to_jiffies(CARL9170_TX_TIMEOUT
));
660 static void __carl9170_tx_process_status(struct ar9170
*ar
,
661 const uint8_t cookie
, const uint8_t info
)
664 struct ieee80211_tx_info
*txinfo
;
665 unsigned int r
, t
, q
;
668 q
= ar9170_qmap
[info
& CARL9170_TX_STATUS_QUEUE
];
670 skb
= carl9170_get_queued_skb(ar
, cookie
, &ar
->tx_status
[q
]);
673 * We have lost the race to another thread.
679 txinfo
= IEEE80211_SKB_CB(skb
);
681 if (!(info
& CARL9170_TX_STATUS_SUCCESS
))
684 r
= (info
& CARL9170_TX_STATUS_RIX
) >> CARL9170_TX_STATUS_RIX_S
;
685 t
= (info
& CARL9170_TX_STATUS_TRIES
) >> CARL9170_TX_STATUS_TRIES_S
;
687 carl9170_tx_fill_rateinfo(ar
, r
, t
, txinfo
);
688 carl9170_tx_status(ar
, skb
, success
);
691 void carl9170_tx_process_status(struct ar9170
*ar
,
692 const struct carl9170_rsp
*cmd
)
696 for (i
= 0; i
< cmd
->hdr
.ext
; i
++) {
697 if (WARN_ON(i
> ((cmd
->hdr
.len
/ 2) + 1))) {
698 print_hex_dump_bytes("UU:", DUMP_PREFIX_NONE
,
699 (void *) cmd
, cmd
->hdr
.len
+ 4);
703 __carl9170_tx_process_status(ar
, cmd
->_tx_status
[i
].cookie
,
704 cmd
->_tx_status
[i
].info
);
708 static void carl9170_tx_rate_tpc_chains(struct ar9170
*ar
,
709 struct ieee80211_tx_info
*info
, struct ieee80211_tx_rate
*txrate
,
710 unsigned int *phyrate
, unsigned int *tpc
, unsigned int *chains
)
712 struct ieee80211_rate
*rate
= NULL
;
720 if (txrate
->flags
& IEEE80211_TX_RC_MCS
) {
721 if (txrate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) {
722 /* +1 dBm for HT40 */
725 if (info
->band
== IEEE80211_BAND_2GHZ
)
726 txpower
= ar
->power_2G_ht40
;
728 txpower
= ar
->power_5G_ht40
;
730 if (info
->band
== IEEE80211_BAND_2GHZ
)
731 txpower
= ar
->power_2G_ht20
;
733 txpower
= ar
->power_5G_ht20
;
736 *phyrate
= txrate
->idx
;
737 *tpc
+= txpower
[idx
& 7];
739 if (info
->band
== IEEE80211_BAND_2GHZ
) {
741 txpower
= ar
->power_2G_cck
;
743 txpower
= ar
->power_2G_ofdm
;
745 txpower
= ar
->power_5G_leg
;
749 rate
= &__carl9170_ratetable
[idx
];
750 *tpc
+= txpower
[(rate
->hw_value
& 0x30) >> 4];
751 *phyrate
= rate
->hw_value
& 0xf;
754 if (ar
->eeprom
.tx_mask
== 1) {
755 *chains
= AR9170_TX_PHY_TXCHAIN_1
;
757 if (!(txrate
->flags
& IEEE80211_TX_RC_MCS
) &&
758 rate
&& rate
->bitrate
>= 360)
759 *chains
= AR9170_TX_PHY_TXCHAIN_1
;
761 *chains
= AR9170_TX_PHY_TXCHAIN_2
;
764 *tpc
= min_t(unsigned int, *tpc
, ar
->hw
->conf
.power_level
* 2);
767 static __le32
carl9170_tx_physet(struct ar9170
*ar
,
768 struct ieee80211_tx_info
*info
, struct ieee80211_tx_rate
*txrate
)
770 unsigned int power
= 0, chains
= 0, phyrate
= 0;
773 tmp
= cpu_to_le32(0);
775 if (txrate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
776 tmp
|= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ
<<
778 /* this works because 40 MHz is 2 and dup is 3 */
779 if (txrate
->flags
& IEEE80211_TX_RC_DUP_DATA
)
780 tmp
|= cpu_to_le32(AR9170_TX_PHY_BW_40MHZ_DUP
<<
783 if (txrate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
784 tmp
|= cpu_to_le32(AR9170_TX_PHY_SHORT_GI
);
786 if (txrate
->flags
& IEEE80211_TX_RC_MCS
) {
787 SET_VAL(AR9170_TX_PHY_MCS
, phyrate
, txrate
->idx
);
789 /* heavy clip control */
790 tmp
|= cpu_to_le32((txrate
->idx
& 0x7) <<
791 AR9170_TX_PHY_TX_HEAVY_CLIP_S
);
793 tmp
|= cpu_to_le32(AR9170_TX_PHY_MOD_HT
);
796 * green field preamble does not work.
798 * if (txrate->flags & IEEE80211_TX_RC_GREEN_FIELD)
799 * tmp |= cpu_to_le32(AR9170_TX_PHY_GREENFIELD);
802 if (info
->band
== IEEE80211_BAND_2GHZ
) {
803 if (txrate
->idx
<= AR9170_TX_PHY_RATE_CCK_11M
)
804 tmp
|= cpu_to_le32(AR9170_TX_PHY_MOD_CCK
);
806 tmp
|= cpu_to_le32(AR9170_TX_PHY_MOD_OFDM
);
808 tmp
|= cpu_to_le32(AR9170_TX_PHY_MOD_OFDM
);
812 * short preamble seems to be broken too.
814 * if (txrate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
815 * tmp |= cpu_to_le32(AR9170_TX_PHY_SHORT_PREAMBLE);
818 carl9170_tx_rate_tpc_chains(ar
, info
, txrate
,
819 &phyrate
, &power
, &chains
);
821 tmp
|= cpu_to_le32(SET_CONSTVAL(AR9170_TX_PHY_MCS
, phyrate
));
822 tmp
|= cpu_to_le32(SET_CONSTVAL(AR9170_TX_PHY_TX_PWR
, power
));
823 tmp
|= cpu_to_le32(SET_CONSTVAL(AR9170_TX_PHY_TXCHAIN
, chains
));
827 static bool carl9170_tx_rts_check(struct ar9170
*ar
,
828 struct ieee80211_tx_rate
*rate
,
829 bool ampdu
, bool multi
)
831 switch (ar
->erp_mode
) {
832 case CARL9170_ERP_AUTO
:
836 case CARL9170_ERP_MAC80211
:
837 if (!(rate
->flags
& IEEE80211_TX_RC_USE_RTS_CTS
))
840 case CARL9170_ERP_RTS
:
851 static bool carl9170_tx_cts_check(struct ar9170
*ar
,
852 struct ieee80211_tx_rate
*rate
)
854 switch (ar
->erp_mode
) {
855 case CARL9170_ERP_AUTO
:
856 case CARL9170_ERP_MAC80211
:
857 if (!(rate
->flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
))
860 case CARL9170_ERP_CTS
:
870 static int carl9170_tx_prepare(struct ar9170
*ar
,
871 struct ieee80211_sta
*sta
,
874 struct ieee80211_hdr
*hdr
;
875 struct _carl9170_tx_superframe
*txc
;
876 struct carl9170_vif_info
*cvif
;
877 struct ieee80211_tx_info
*info
;
878 struct ieee80211_tx_rate
*txrate
;
879 struct carl9170_tx_info
*arinfo
;
880 unsigned int hw_queue
;
886 BUILD_BUG_ON(sizeof(*arinfo
) > sizeof(info
->rate_driver_data
));
887 BUILD_BUG_ON(sizeof(struct _carl9170_tx_superdesc
) !=
888 CARL9170_TX_SUPERDESC_LEN
);
890 BUILD_BUG_ON(sizeof(struct _ar9170_tx_hwdesc
) !=
891 AR9170_TX_HWDESC_LEN
);
893 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES
< CARL9170_TX_MAX_RATES
);
895 BUILD_BUG_ON(AR9170_MAX_VIRTUAL_MAC
>
896 ((CARL9170_TX_SUPER_MISC_VIF_ID
>>
897 CARL9170_TX_SUPER_MISC_VIF_ID_S
) + 1));
899 hw_queue
= ar9170_qmap
[carl9170_get_queue(ar
, skb
)];
901 hdr
= (void *)skb
->data
;
902 info
= IEEE80211_SKB_CB(skb
);
906 * Note: If the frame was sent through a monitor interface,
907 * the ieee80211_vif pointer can be NULL.
909 if (likely(info
->control
.vif
))
910 cvif
= (void *) info
->control
.vif
->drv_priv
;
914 txc
= (void *)skb_push(skb
, sizeof(*txc
));
915 memset(txc
, 0, sizeof(*txc
));
917 SET_VAL(CARL9170_TX_SUPER_MISC_QUEUE
, txc
->s
.misc
, hw_queue
);
920 SET_VAL(CARL9170_TX_SUPER_MISC_VIF_ID
, txc
->s
.misc
, cvif
->id
);
922 if (unlikely(info
->flags
& IEEE80211_TX_CTL_SEND_AFTER_DTIM
))
923 txc
->s
.misc
|= CARL9170_TX_SUPER_MISC_CAB
;
925 if (unlikely(info
->flags
& IEEE80211_TX_CTL_ASSIGN_SEQ
))
926 txc
->s
.misc
|= CARL9170_TX_SUPER_MISC_ASSIGN_SEQ
;
928 if (unlikely(ieee80211_is_probe_resp(hdr
->frame_control
)))
929 txc
->s
.misc
|= CARL9170_TX_SUPER_MISC_FILL_IN_TSF
;
931 mac_tmp
= cpu_to_le16(AR9170_TX_MAC_HW_DURATION
|
932 AR9170_TX_MAC_BACKOFF
);
933 mac_tmp
|= cpu_to_le16((hw_queue
<< AR9170_TX_MAC_QOS_S
) &
936 no_ack
= !!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
);
937 if (unlikely(no_ack
))
938 mac_tmp
|= cpu_to_le16(AR9170_TX_MAC_NO_ACK
);
940 if (info
->control
.hw_key
) {
941 len
+= info
->control
.hw_key
->icv_len
;
943 switch (info
->control
.hw_key
->cipher
) {
944 case WLAN_CIPHER_SUITE_WEP40
:
945 case WLAN_CIPHER_SUITE_WEP104
:
946 case WLAN_CIPHER_SUITE_TKIP
:
947 mac_tmp
|= cpu_to_le16(AR9170_TX_MAC_ENCR_RC4
);
949 case WLAN_CIPHER_SUITE_CCMP
:
950 mac_tmp
|= cpu_to_le16(AR9170_TX_MAC_ENCR_AES
);
958 ampdu
= !!(info
->flags
& IEEE80211_TX_CTL_AMPDU
);
960 unsigned int density
, factor
;
962 if (unlikely(!sta
|| !cvif
))
965 factor
= min_t(unsigned int, 1u, sta
->ht_cap
.ampdu_factor
);
966 density
= sta
->ht_cap
.ampdu_density
;
972 * Otus uses slightly different density values than
973 * those from the 802.11n spec.
976 density
= max_t(unsigned int, density
+ 1, 7u);
979 SET_VAL(CARL9170_TX_SUPER_AMPDU_DENSITY
,
980 txc
->s
.ampdu_settings
, density
);
982 SET_VAL(CARL9170_TX_SUPER_AMPDU_FACTOR
,
983 txc
->s
.ampdu_settings
, factor
);
985 for (i
= 0; i
< CARL9170_TX_MAX_RATES
; i
++) {
986 txrate
= &info
->control
.rates
[i
];
987 if (txrate
->idx
>= 0) {
989 CARL9170_TX_SUPER_RI_AMPDU
;
991 if (WARN_ON(!(txrate
->flags
&
992 IEEE80211_TX_RC_MCS
))) {
994 * Not sure if it's even possible
995 * to aggregate non-ht rates with
1004 txrate
->count
= ar
->hw
->max_rate_tries
;
1007 mac_tmp
|= cpu_to_le16(AR9170_TX_MAC_AGGR
);
1011 * NOTE: For the first rate, the ERP & AMPDU flags are directly
1012 * taken from mac_control. For all fallback rate, the firmware
1013 * updates the mac_control flags from the rate info field.
1015 for (i
= 1; i
< CARL9170_TX_MAX_RATES
; i
++) {
1016 txrate
= &info
->control
.rates
[i
];
1017 if (txrate
->idx
< 0)
1020 SET_VAL(CARL9170_TX_SUPER_RI_TRIES
, txc
->s
.ri
[i
],
1023 if (carl9170_tx_rts_check(ar
, txrate
, ampdu
, no_ack
))
1024 txc
->s
.ri
[i
] |= (AR9170_TX_MAC_PROT_RTS
<<
1025 CARL9170_TX_SUPER_RI_ERP_PROT_S
);
1026 else if (carl9170_tx_cts_check(ar
, txrate
))
1027 txc
->s
.ri
[i
] |= (AR9170_TX_MAC_PROT_CTS
<<
1028 CARL9170_TX_SUPER_RI_ERP_PROT_S
);
1030 txc
->s
.rr
[i
- 1] = carl9170_tx_physet(ar
, info
, txrate
);
1033 txrate
= &info
->control
.rates
[0];
1034 SET_VAL(CARL9170_TX_SUPER_RI_TRIES
, txc
->s
.ri
[0], txrate
->count
);
1036 if (carl9170_tx_rts_check(ar
, txrate
, ampdu
, no_ack
))
1037 mac_tmp
|= cpu_to_le16(AR9170_TX_MAC_PROT_RTS
);
1038 else if (carl9170_tx_cts_check(ar
, txrate
))
1039 mac_tmp
|= cpu_to_le16(AR9170_TX_MAC_PROT_CTS
);
1041 txc
->s
.len
= cpu_to_le16(skb
->len
);
1042 txc
->f
.length
= cpu_to_le16(len
+ FCS_LEN
);
1043 txc
->f
.mac_control
= mac_tmp
;
1044 txc
->f
.phy_control
= carl9170_tx_physet(ar
, info
, txrate
);
1046 arinfo
= (void *)info
->rate_driver_data
;
1047 arinfo
->timeout
= jiffies
;
1049 kref_init(&arinfo
->ref
);
1053 skb_pull(skb
, sizeof(*txc
));
1057 static void carl9170_set_immba(struct ar9170
*ar
, struct sk_buff
*skb
)
1059 struct _carl9170_tx_superframe
*super
;
1061 super
= (void *) skb
->data
;
1062 super
->f
.mac_control
|= cpu_to_le16(AR9170_TX_MAC_IMM_BA
);
1065 static void carl9170_set_ampdu_params(struct ar9170
*ar
, struct sk_buff
*skb
)
1067 struct _carl9170_tx_superframe
*super
;
1070 super
= (void *) skb
->data
;
1072 tmp
= (super
->s
.ampdu_settings
& CARL9170_TX_SUPER_AMPDU_DENSITY
) <<
1073 CARL9170_TX_SUPER_AMPDU_DENSITY_S
;
1076 * If you haven't noticed carl9170_tx_prepare has already filled
1077 * in all ampdu spacing & factor parameters.
1078 * Now it's the time to check whenever the settings have to be
1079 * updated by the firmware, or if everything is still the same.
1081 * There's no sane way to handle different density values with
1082 * this hardware, so we may as well just do the compare in the
1086 if (tmp
!= ar
->current_density
) {
1087 ar
->current_density
= tmp
;
1088 super
->s
.ampdu_settings
|=
1089 CARL9170_TX_SUPER_AMPDU_COMMIT_DENSITY
;
1092 tmp
= (super
->s
.ampdu_settings
& CARL9170_TX_SUPER_AMPDU_FACTOR
) <<
1093 CARL9170_TX_SUPER_AMPDU_FACTOR_S
;
1095 if (tmp
!= ar
->current_factor
) {
1096 ar
->current_factor
= tmp
;
1097 super
->s
.ampdu_settings
|=
1098 CARL9170_TX_SUPER_AMPDU_COMMIT_FACTOR
;
1102 static bool carl9170_tx_rate_check(struct ar9170
*ar
, struct sk_buff
*_dest
,
1103 struct sk_buff
*_src
)
1105 struct _carl9170_tx_superframe
*dest
, *src
;
1107 dest
= (void *) _dest
->data
;
1108 src
= (void *) _src
->data
;
1111 * The mac80211 rate control algorithm expects that all MPDUs in
1112 * an AMPDU share the same tx vectors.
1113 * This is not really obvious right now, because the hardware
1114 * does the AMPDU setup according to its own rulebook.
1115 * Our nicely assembled, strictly monotonic increasing mpdu
1116 * chains will be broken up, mashed back together...
1119 return (dest
->f
.phy_control
== src
->f
.phy_control
);
1122 static void carl9170_tx_ampdu(struct ar9170
*ar
)
1124 struct sk_buff_head agg
;
1125 struct carl9170_sta_tid
*tid_info
;
1126 struct sk_buff
*skb
, *first
;
1127 unsigned int i
= 0, done_ampdus
= 0;
1128 u16 seq
, queue
, tmpssn
;
1130 atomic_inc(&ar
->tx_ampdu_scheduler
);
1131 ar
->tx_ampdu_schedule
= false;
1133 if (atomic_read(&ar
->tx_ampdu_upload
))
1136 if (!ar
->tx_ampdu_list_len
)
1139 __skb_queue_head_init(&agg
);
1142 tid_info
= rcu_dereference(ar
->tx_ampdu_iter
);
1143 if (WARN_ON_ONCE(!tid_info
)) {
1149 list_for_each_entry_continue_rcu(tid_info
, &ar
->tx_ampdu_list
, list
) {
1152 if (tid_info
->state
< CARL9170_TID_STATE_PROGRESS
)
1155 queue
= TID_TO_WME_AC(tid_info
->tid
);
1157 spin_lock_bh(&tid_info
->lock
);
1158 if (tid_info
->state
!= CARL9170_TID_STATE_XMIT
)
1161 tid_info
->counter
++;
1162 first
= skb_peek(&tid_info
->queue
);
1163 tmpssn
= carl9170_get_seq(first
);
1164 seq
= tid_info
->snx
;
1166 if (unlikely(tmpssn
!= seq
)) {
1167 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1172 while ((skb
= skb_peek(&tid_info
->queue
))) {
1173 /* strict 0, 1, ..., n - 1, n frame sequence order */
1174 if (unlikely(carl9170_get_seq(skb
) != seq
))
1177 /* don't upload more than AMPDU FACTOR allows. */
1178 if (unlikely(SEQ_DIFF(tid_info
->snx
, tid_info
->bsn
) >=
1179 (tid_info
->max
- 1)))
1182 if (!carl9170_tx_rate_check(ar
, skb
, first
))
1185 atomic_inc(&ar
->tx_ampdu_upload
);
1186 tid_info
->snx
= seq
= SEQ_NEXT(seq
);
1187 __skb_unlink(skb
, &tid_info
->queue
);
1189 __skb_queue_tail(&agg
, skb
);
1191 if (skb_queue_len(&agg
) >= CARL9170_NUM_TX_AGG_MAX
)
1195 if (skb_queue_empty(&tid_info
->queue
) ||
1196 carl9170_get_seq(skb_peek(&tid_info
->queue
)) !=
1199 * stop TID, if A-MPDU frames are still missing,
1200 * or whenever the queue is empty.
1203 tid_info
->state
= CARL9170_TID_STATE_IDLE
;
1208 spin_unlock_bh(&tid_info
->lock
);
1210 if (skb_queue_empty(&agg
))
1213 /* apply ampdu spacing & factor settings */
1214 carl9170_set_ampdu_params(ar
, skb_peek(&agg
));
1216 /* set aggregation push bit */
1217 carl9170_set_immba(ar
, skb_peek_tail(&agg
));
1219 spin_lock_bh(&ar
->tx_pending
[queue
].lock
);
1220 skb_queue_splice_tail_init(&agg
, &ar
->tx_pending
[queue
]);
1221 spin_unlock_bh(&ar
->tx_pending
[queue
].lock
);
1222 ar
->tx_schedule
= true;
1224 if ((done_ampdus
++ == 0) && (i
++ == 0))
1227 rcu_assign_pointer(ar
->tx_ampdu_iter
, tid_info
);
1231 static struct sk_buff
*carl9170_tx_pick_skb(struct ar9170
*ar
,
1232 struct sk_buff_head
*queue
)
1234 struct sk_buff
*skb
;
1235 struct ieee80211_tx_info
*info
;
1236 struct carl9170_tx_info
*arinfo
;
1238 BUILD_BUG_ON(sizeof(*arinfo
) > sizeof(info
->rate_driver_data
));
1240 spin_lock_bh(&queue
->lock
);
1241 skb
= skb_peek(queue
);
1245 if (carl9170_alloc_dev_space(ar
, skb
))
1248 __skb_unlink(skb
, queue
);
1249 spin_unlock_bh(&queue
->lock
);
1251 info
= IEEE80211_SKB_CB(skb
);
1252 arinfo
= (void *) info
->rate_driver_data
;
1254 arinfo
->timeout
= jiffies
;
1258 spin_unlock_bh(&queue
->lock
);
1262 void carl9170_tx_drop(struct ar9170
*ar
, struct sk_buff
*skb
)
1264 struct _carl9170_tx_superframe
*super
;
1269 super
= (void *)skb
->data
;
1270 SET_VAL(CARL9170_TX_SUPER_MISC_QUEUE
, q
,
1271 ar9170_qmap
[carl9170_get_queue(ar
, skb
)]);
1272 __carl9170_tx_process_status(ar
, super
->s
.cookie
, q
);
1275 static bool carl9170_tx_ps_drop(struct ar9170
*ar
, struct sk_buff
*skb
)
1277 struct ieee80211_sta
*sta
;
1278 struct carl9170_sta_info
*sta_info
;
1279 struct ieee80211_tx_info
*tx_info
;
1282 sta
= __carl9170_get_tx_sta(ar
, skb
);
1286 sta_info
= (void *) sta
->drv_priv
;
1287 tx_info
= IEEE80211_SKB_CB(skb
);
1289 if (unlikely(sta_info
->sleeping
) &&
1290 !(tx_info
->flags
& (IEEE80211_TX_CTL_NO_PS_BUFFER
|
1291 IEEE80211_TX_CTL_CLEAR_PS_FILT
))) {
1294 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
1295 atomic_dec(&ar
->tx_ampdu_upload
);
1297 tx_info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
1298 carl9170_release_dev_space(ar
, skb
);
1299 carl9170_tx_status(ar
, skb
, false);
1308 static void carl9170_bar_check(struct ar9170
*ar
, struct sk_buff
*skb
)
1310 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
1311 struct ieee80211_bar
*bar
= (void *) super
->frame_data
;
1313 if (unlikely(ieee80211_is_back_req(bar
->frame_control
)) &&
1314 skb
->len
>= sizeof(struct ieee80211_bar
)) {
1315 struct carl9170_bar_list_entry
*entry
;
1316 unsigned int queue
= skb_get_queue_mapping(skb
);
1318 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1319 if (!WARN_ON_ONCE(!entry
)) {
1321 spin_lock_bh(&ar
->bar_list_lock
[queue
]);
1322 list_add_tail_rcu(&entry
->list
, &ar
->bar_list
[queue
]);
1323 spin_unlock_bh(&ar
->bar_list_lock
[queue
]);
1328 static void carl9170_tx(struct ar9170
*ar
)
1330 struct sk_buff
*skb
;
1332 bool schedule_garbagecollector
= false;
1334 ar
->tx_schedule
= false;
1336 if (unlikely(!IS_STARTED(ar
)))
1339 carl9170_usb_handle_tx_err(ar
);
1341 for (i
= 0; i
< ar
->hw
->queues
; i
++) {
1342 while (!skb_queue_empty(&ar
->tx_pending
[i
])) {
1343 skb
= carl9170_tx_pick_skb(ar
, &ar
->tx_pending
[i
]);
1347 if (unlikely(carl9170_tx_ps_drop(ar
, skb
)))
1350 carl9170_bar_check(ar
, skb
);
1352 atomic_inc(&ar
->tx_total_pending
);
1354 q
= __carl9170_get_queue(ar
, i
);
1356 * NB: tx_status[i] vs. tx_status[q],
1357 * TODO: Move into pick_skb or alloc_dev_space.
1359 skb_queue_tail(&ar
->tx_status
[q
], skb
);
1362 * increase ref count to "2".
1363 * Ref counting is the easiest way to solve the
1364 * race between the urb's completion routine:
1365 * carl9170_tx_callback
1366 * and wlan tx status functions:
1367 * carl9170_tx_status/janitor.
1369 carl9170_tx_get_skb(skb
);
1371 carl9170_usb_tx(ar
, skb
);
1372 schedule_garbagecollector
= true;
1376 if (!schedule_garbagecollector
)
1379 ieee80211_queue_delayed_work(ar
->hw
, &ar
->tx_janitor
,
1380 msecs_to_jiffies(CARL9170_TX_TIMEOUT
));
1383 static bool carl9170_tx_ampdu_queue(struct ar9170
*ar
,
1384 struct ieee80211_sta
*sta
, struct sk_buff
*skb
)
1386 struct _carl9170_tx_superframe
*super
= (void *) skb
->data
;
1387 struct carl9170_sta_info
*sta_info
;
1388 struct carl9170_sta_tid
*agg
;
1389 struct sk_buff
*iter
;
1390 u16 tid
, seq
, qseq
, off
;
1393 tid
= carl9170_get_tid(skb
);
1394 seq
= carl9170_get_seq(skb
);
1395 sta_info
= (void *) sta
->drv_priv
;
1398 agg
= rcu_dereference(sta_info
->agg
[tid
]);
1401 goto err_unlock_rcu
;
1403 spin_lock_bh(&agg
->lock
);
1404 if (unlikely(agg
->state
< CARL9170_TID_STATE_IDLE
))
1407 /* check if sequence is within the BA window */
1408 if (unlikely(!BAW_WITHIN(agg
->bsn
, CARL9170_BAW_BITS
, seq
)))
1411 if (WARN_ON_ONCE(!BAW_WITHIN(agg
->snx
, CARL9170_BAW_BITS
, seq
)))
1414 off
= SEQ_DIFF(seq
, agg
->bsn
);
1415 if (WARN_ON_ONCE(test_and_set_bit(off
, agg
->bitmap
)))
1418 if (likely(BAW_WITHIN(agg
->hsn
, CARL9170_BAW_BITS
, seq
))) {
1419 __skb_queue_tail(&agg
->queue
, skb
);
1424 skb_queue_reverse_walk(&agg
->queue
, iter
) {
1425 qseq
= carl9170_get_seq(iter
);
1427 if (BAW_WITHIN(qseq
, CARL9170_BAW_BITS
, seq
)) {
1428 __skb_queue_after(&agg
->queue
, iter
, skb
);
1433 __skb_queue_head(&agg
->queue
, skb
);
1436 if (unlikely(agg
->state
!= CARL9170_TID_STATE_XMIT
)) {
1437 if (agg
->snx
== carl9170_get_seq(skb_peek(&agg
->queue
))) {
1438 agg
->state
= CARL9170_TID_STATE_XMIT
;
1443 spin_unlock_bh(&agg
->lock
);
1449 spin_unlock_bh(&agg
->lock
);
1453 super
->f
.mac_control
&= ~cpu_to_le16(AR9170_TX_MAC_AGGR
);
1454 carl9170_tx_status(ar
, skb
, false);
1459 void carl9170_op_tx(struct ieee80211_hw
*hw
,
1460 struct ieee80211_tx_control
*control
,
1461 struct sk_buff
*skb
)
1463 struct ar9170
*ar
= hw
->priv
;
1464 struct ieee80211_tx_info
*info
;
1465 struct ieee80211_sta
*sta
= control
->sta
;
1468 if (unlikely(!IS_STARTED(ar
)))
1471 info
= IEEE80211_SKB_CB(skb
);
1473 if (unlikely(carl9170_tx_prepare(ar
, sta
, skb
)))
1476 carl9170_tx_accounting(ar
, skb
);
1478 * from now on, one has to use carl9170_tx_status to free
1479 * all ressouces which are associated with the frame.
1483 struct carl9170_sta_info
*stai
= (void *) sta
->drv_priv
;
1484 atomic_inc(&stai
->pending_frames
);
1487 if (info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
1488 /* to static code analyzers and reviewers:
1489 * mac80211 guarantees that a valid "sta"
1490 * reference is present, if a frame is to
1491 * be part of an ampdu. Hence any extra
1492 * sta == NULL checks are redundant in this
1495 run
= carl9170_tx_ampdu_queue(ar
, sta
, skb
);
1497 carl9170_tx_ampdu(ar
);
1500 unsigned int queue
= skb_get_queue_mapping(skb
);
1502 skb_queue_tail(&ar
->tx_pending
[queue
], skb
);
1510 ieee80211_free_txskb(ar
->hw
, skb
);
1513 void carl9170_tx_scheduler(struct ar9170
*ar
)
1516 if (ar
->tx_ampdu_schedule
)
1517 carl9170_tx_ampdu(ar
);
1519 if (ar
->tx_schedule
)
1523 int carl9170_update_beacon(struct ar9170
*ar
, const bool submit
)
1525 struct sk_buff
*skb
= NULL
;
1526 struct carl9170_vif_info
*cvif
;
1527 struct ieee80211_tx_info
*txinfo
;
1528 struct ieee80211_tx_rate
*rate
;
1529 __le32
*data
, *old
= NULL
;
1530 unsigned int plcp
, power
, chains
;
1531 u32 word
, ht1
, off
, addr
, len
;
1535 cvif
= rcu_dereference(ar
->beacon_iter
);
1537 if (ar
->vifs
== 0 || !cvif
)
1540 list_for_each_entry_continue_rcu(cvif
, &ar
->vif_list
, list
) {
1541 if (cvif
->active
&& cvif
->enable_beacon
)
1545 if (!ar
->beacon_enabled
|| i
++)
1551 rcu_assign_pointer(ar
->beacon_iter
, cvif
);
1553 skb
= ieee80211_beacon_get_tim(ar
->hw
, carl9170_get_vif(cvif
),
1561 txinfo
= IEEE80211_SKB_CB(skb
);
1562 spin_lock_bh(&ar
->beacon_lock
);
1563 data
= (__le32
*)skb
->data
;
1565 old
= (__le32
*)cvif
->beacon
->data
;
1567 off
= cvif
->id
* AR9170_MAC_BCN_LENGTH_MAX
;
1568 addr
= ar
->fw
.beacon_addr
+ off
;
1569 len
= roundup(skb
->len
+ FCS_LEN
, 4);
1571 if ((off
+ len
) > ar
->fw
.beacon_max_len
) {
1572 if (net_ratelimit()) {
1573 wiphy_err(ar
->hw
->wiphy
, "beacon does not "
1574 "fit into device memory!\n");
1580 if (len
> AR9170_MAC_BCN_LENGTH_MAX
) {
1581 if (net_ratelimit()) {
1582 wiphy_err(ar
->hw
->wiphy
, "no support for beacons "
1583 "bigger than %d (yours:%d).\n",
1584 AR9170_MAC_BCN_LENGTH_MAX
, len
);
1591 ht1
= AR9170_MAC_BCN_HT1_TX_ANT0
;
1592 rate
= &txinfo
->control
.rates
[0];
1593 carl9170_tx_rate_tpc_chains(ar
, txinfo
, rate
, &plcp
, &power
, &chains
);
1594 if (!(txinfo
->control
.rates
[0].flags
& IEEE80211_TX_RC_MCS
)) {
1595 if (plcp
<= AR9170_TX_PHY_RATE_CCK_11M
)
1596 plcp
|= ((skb
->len
+ FCS_LEN
) << (3 + 16)) + 0x0400;
1598 plcp
|= ((skb
->len
+ FCS_LEN
) << 16) + 0x0010;
1600 ht1
|= AR9170_MAC_BCN_HT1_HT_EN
;
1601 if (rate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
1602 plcp
|= AR9170_MAC_BCN_HT2_SGI
;
1604 if (rate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
) {
1605 ht1
|= AR9170_MAC_BCN_HT1_BWC_40M_SHARED
;
1606 plcp
|= AR9170_MAC_BCN_HT2_BW40
;
1608 if (rate
->flags
& IEEE80211_TX_RC_DUP_DATA
) {
1609 ht1
|= AR9170_MAC_BCN_HT1_BWC_40M_DUP
;
1610 plcp
|= AR9170_MAC_BCN_HT2_BW40
;
1613 SET_VAL(AR9170_MAC_BCN_HT2_LEN
, plcp
, skb
->len
+ FCS_LEN
);
1616 SET_VAL(AR9170_MAC_BCN_HT1_PWR_CTRL
, ht1
, 7);
1617 SET_VAL(AR9170_MAC_BCN_HT1_TPC
, ht1
, power
);
1618 SET_VAL(AR9170_MAC_BCN_HT1_CHAIN_MASK
, ht1
, chains
);
1619 if (chains
== AR9170_TX_PHY_TXCHAIN_2
)
1620 ht1
|= AR9170_MAC_BCN_HT1_TX_ANT1
;
1622 carl9170_async_regwrite_begin(ar
);
1623 carl9170_async_regwrite(AR9170_MAC_REG_BCN_HT1
, ht1
);
1624 if (!(txinfo
->control
.rates
[0].flags
& IEEE80211_TX_RC_MCS
))
1625 carl9170_async_regwrite(AR9170_MAC_REG_BCN_PLCP
, plcp
);
1627 carl9170_async_regwrite(AR9170_MAC_REG_BCN_HT2
, plcp
);
1629 for (i
= 0; i
< DIV_ROUND_UP(skb
->len
, 4); i
++) {
1631 * XXX: This accesses beyond skb data for up
1632 * to the last 3 bytes!!
1635 if (old
&& (data
[i
] == old
[i
]))
1638 word
= le32_to_cpu(data
[i
]);
1639 carl9170_async_regwrite(addr
+ 4 * i
, word
);
1641 carl9170_async_regwrite_finish();
1643 dev_kfree_skb_any(cvif
->beacon
);
1644 cvif
->beacon
= NULL
;
1646 err
= carl9170_async_regwrite_result();
1649 spin_unlock_bh(&ar
->beacon_lock
);
1654 err
= carl9170_bcn_ctrl(ar
, cvif
->id
,
1655 CARL9170_BCN_CTRL_CAB_TRIGGER
,
1656 addr
, skb
->len
+ FCS_LEN
);
1666 spin_unlock_bh(&ar
->beacon_lock
);
1670 dev_kfree_skb_any(skb
);