2 * Copyright (c) 2010-2011 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 static const int subtype_txq_to_hwq
[] = {
24 [IEEE80211_AC_BE
] = ATH_TXQ_AC_BE
,
25 [IEEE80211_AC_BK
] = ATH_TXQ_AC_BK
,
26 [IEEE80211_AC_VI
] = ATH_TXQ_AC_VI
,
27 [IEEE80211_AC_VO
] = ATH_TXQ_AC_VO
,
30 #define ATH9K_HTC_INIT_TXQ(subtype) do { \
31 qi.tqi_subtype = subtype_txq_to_hwq[subtype]; \
32 qi.tqi_aifs = ATH9K_TXQ_USEDEFAULT; \
33 qi.tqi_cwmin = ATH9K_TXQ_USEDEFAULT; \
34 qi.tqi_cwmax = ATH9K_TXQ_USEDEFAULT; \
35 qi.tqi_physCompBuf = 0; \
36 qi.tqi_qflags = TXQ_FLAG_TXEOLINT_ENABLE | \
37 TXQ_FLAG_TXDESCINT_ENABLE; \
40 int get_hw_qnum(u16 queue
, int *hwq_map
)
44 return hwq_map
[IEEE80211_AC_VO
];
46 return hwq_map
[IEEE80211_AC_VI
];
48 return hwq_map
[IEEE80211_AC_BE
];
50 return hwq_map
[IEEE80211_AC_BK
];
52 return hwq_map
[IEEE80211_AC_BE
];
56 void ath9k_htc_check_stop_queues(struct ath9k_htc_priv
*priv
)
58 spin_lock_bh(&priv
->tx
.tx_lock
);
59 priv
->tx
.queued_cnt
++;
60 if ((priv
->tx
.queued_cnt
>= ATH9K_HTC_TX_THRESHOLD
) &&
61 !(priv
->tx
.flags
& ATH9K_HTC_OP_TX_QUEUES_STOP
)) {
62 priv
->tx
.flags
|= ATH9K_HTC_OP_TX_QUEUES_STOP
;
63 ieee80211_stop_queues(priv
->hw
);
65 spin_unlock_bh(&priv
->tx
.tx_lock
);
68 void ath9k_htc_check_wake_queues(struct ath9k_htc_priv
*priv
)
70 spin_lock_bh(&priv
->tx
.tx_lock
);
71 if ((priv
->tx
.queued_cnt
< ATH9K_HTC_TX_THRESHOLD
) &&
72 (priv
->tx
.flags
& ATH9K_HTC_OP_TX_QUEUES_STOP
)) {
73 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_QUEUES_STOP
;
74 ieee80211_wake_queues(priv
->hw
);
76 spin_unlock_bh(&priv
->tx
.tx_lock
);
79 int ath9k_htc_tx_get_slot(struct ath9k_htc_priv
*priv
)
83 spin_lock_bh(&priv
->tx
.tx_lock
);
84 slot
= find_first_zero_bit(priv
->tx
.tx_slot
, MAX_TX_BUF_NUM
);
85 if (slot
>= MAX_TX_BUF_NUM
) {
86 spin_unlock_bh(&priv
->tx
.tx_lock
);
89 __set_bit(slot
, priv
->tx
.tx_slot
);
90 spin_unlock_bh(&priv
->tx
.tx_lock
);
95 void ath9k_htc_tx_clear_slot(struct ath9k_htc_priv
*priv
, int slot
)
97 spin_lock_bh(&priv
->tx
.tx_lock
);
98 __clear_bit(slot
, priv
->tx
.tx_slot
);
99 spin_unlock_bh(&priv
->tx
.tx_lock
);
102 static inline enum htc_endpoint_id
get_htc_epid(struct ath9k_htc_priv
*priv
,
105 enum htc_endpoint_id epid
;
109 TX_QSTAT_INC(priv
, IEEE80211_AC_VO
);
110 epid
= priv
->data_vo_ep
;
113 TX_QSTAT_INC(priv
, IEEE80211_AC_VI
);
114 epid
= priv
->data_vi_ep
;
117 TX_QSTAT_INC(priv
, IEEE80211_AC_BE
);
118 epid
= priv
->data_be_ep
;
122 TX_QSTAT_INC(priv
, IEEE80211_AC_BK
);
123 epid
= priv
->data_bk_ep
;
130 static inline struct sk_buff_head
*
131 get_htc_epid_queue(struct ath9k_htc_priv
*priv
, u8 epid
)
133 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
134 struct sk_buff_head
*epid_queue
= NULL
;
136 if (epid
== priv
->mgmt_ep
)
137 epid_queue
= &priv
->tx
.mgmt_ep_queue
;
138 else if (epid
== priv
->cab_ep
)
139 epid_queue
= &priv
->tx
.cab_ep_queue
;
140 else if (epid
== priv
->data_be_ep
)
141 epid_queue
= &priv
->tx
.data_be_queue
;
142 else if (epid
== priv
->data_bk_ep
)
143 epid_queue
= &priv
->tx
.data_bk_queue
;
144 else if (epid
== priv
->data_vi_ep
)
145 epid_queue
= &priv
->tx
.data_vi_queue
;
146 else if (epid
== priv
->data_vo_ep
)
147 epid_queue
= &priv
->tx
.data_vo_queue
;
149 ath_err(common
, "Invalid EPID: %d\n", epid
);
155 * Removes the driver header and returns the TX slot number
157 static inline int strip_drv_header(struct ath9k_htc_priv
*priv
,
160 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
161 struct ath9k_htc_tx_ctl
*tx_ctl
;
164 tx_ctl
= HTC_SKB_CB(skb
);
166 if (tx_ctl
->epid
== priv
->mgmt_ep
) {
167 struct tx_mgmt_hdr
*tx_mhdr
=
168 (struct tx_mgmt_hdr
*)skb
->data
;
169 slot
= tx_mhdr
->cookie
;
170 skb_pull(skb
, sizeof(struct tx_mgmt_hdr
));
171 } else if ((tx_ctl
->epid
== priv
->data_bk_ep
) ||
172 (tx_ctl
->epid
== priv
->data_be_ep
) ||
173 (tx_ctl
->epid
== priv
->data_vi_ep
) ||
174 (tx_ctl
->epid
== priv
->data_vo_ep
) ||
175 (tx_ctl
->epid
== priv
->cab_ep
)) {
176 struct tx_frame_hdr
*tx_fhdr
=
177 (struct tx_frame_hdr
*)skb
->data
;
178 slot
= tx_fhdr
->cookie
;
179 skb_pull(skb
, sizeof(struct tx_frame_hdr
));
181 ath_err(common
, "Unsupported EPID: %d\n", tx_ctl
->epid
);
188 int ath_htc_txq_update(struct ath9k_htc_priv
*priv
, int qnum
,
189 struct ath9k_tx_queue_info
*qinfo
)
191 struct ath_hw
*ah
= priv
->ah
;
193 struct ath9k_tx_queue_info qi
;
195 ath9k_hw_get_txq_props(ah
, qnum
, &qi
);
197 qi
.tqi_aifs
= qinfo
->tqi_aifs
;
198 qi
.tqi_cwmin
= qinfo
->tqi_cwmin
/ 2; /* XXX */
199 qi
.tqi_cwmax
= qinfo
->tqi_cwmax
;
200 qi
.tqi_burstTime
= qinfo
->tqi_burstTime
;
201 qi
.tqi_readyTime
= qinfo
->tqi_readyTime
;
203 if (!ath9k_hw_set_txq_props(ah
, qnum
, &qi
)) {
204 ath_err(ath9k_hw_common(ah
),
205 "Unable to update hardware queue %u!\n", qnum
);
208 ath9k_hw_resettxqueue(ah
, qnum
);
214 static void ath9k_htc_tx_mgmt(struct ath9k_htc_priv
*priv
,
215 struct ath9k_htc_vif
*avp
,
217 u8 sta_idx
, u8 vif_idx
, u8 slot
)
219 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
220 struct ieee80211_mgmt
*mgmt
;
221 struct ieee80211_hdr
*hdr
;
222 struct tx_mgmt_hdr mgmt_hdr
;
223 struct ath9k_htc_tx_ctl
*tx_ctl
;
226 tx_ctl
= HTC_SKB_CB(skb
);
227 hdr
= (struct ieee80211_hdr
*) skb
->data
;
229 memset(tx_ctl
, 0, sizeof(*tx_ctl
));
230 memset(&mgmt_hdr
, 0, sizeof(struct tx_mgmt_hdr
));
233 * Set the TSF adjust value for probe response
236 if (avp
&& unlikely(ieee80211_is_probe_resp(hdr
->frame_control
))) {
237 mgmt
= (struct ieee80211_mgmt
*)skb
->data
;
238 mgmt
->u
.probe_resp
.timestamp
= avp
->tsfadjust
;
241 tx_ctl
->type
= ATH9K_HTC_MGMT
;
243 mgmt_hdr
.node_idx
= sta_idx
;
244 mgmt_hdr
.vif_idx
= vif_idx
;
247 mgmt_hdr
.cookie
= slot
;
249 mgmt_hdr
.key_type
= ath9k_cmn_get_hw_crypto_keytype(skb
);
250 if (mgmt_hdr
.key_type
== ATH9K_KEY_TYPE_CLEAR
)
251 mgmt_hdr
.keyix
= (u8
) ATH9K_TXKEYIX_INVALID
;
253 mgmt_hdr
.keyix
= tx_info
->control
.hw_key
->hw_key_idx
;
255 tx_fhdr
= skb_push(skb
, sizeof(mgmt_hdr
));
256 memcpy(tx_fhdr
, (u8
*) &mgmt_hdr
, sizeof(mgmt_hdr
));
257 tx_ctl
->epid
= priv
->mgmt_ep
;
260 static void ath9k_htc_tx_data(struct ath9k_htc_priv
*priv
,
261 struct ieee80211_vif
*vif
,
263 u8 sta_idx
, u8 vif_idx
, u8 slot
,
266 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
267 struct ieee80211_hdr
*hdr
;
268 struct ath9k_htc_tx_ctl
*tx_ctl
;
269 struct tx_frame_hdr tx_hdr
;
274 tx_ctl
= HTC_SKB_CB(skb
);
275 hdr
= (struct ieee80211_hdr
*) skb
->data
;
277 memset(tx_ctl
, 0, sizeof(*tx_ctl
));
278 memset(&tx_hdr
, 0, sizeof(struct tx_frame_hdr
));
280 tx_hdr
.node_idx
= sta_idx
;
281 tx_hdr
.vif_idx
= vif_idx
;
282 tx_hdr
.cookie
= slot
;
285 * This is a bit redundant but it helps to get
286 * the per-packet index quickly when draining the
287 * TX queue in the HIF layer. Otherwise we would
288 * have to parse the packet contents ...
290 tx_ctl
->sta_idx
= sta_idx
;
292 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
) {
293 tx_ctl
->type
= ATH9K_HTC_AMPDU
;
294 tx_hdr
.data_type
= ATH9K_HTC_AMPDU
;
296 tx_ctl
->type
= ATH9K_HTC_NORMAL
;
297 tx_hdr
.data_type
= ATH9K_HTC_NORMAL
;
300 /* Transmit all frames that should not be reordered relative
301 * to each other using the same priority. For other QoS data
302 * frames extract the priority from the header.
304 if (!(tx_info
->control
.flags
& IEEE80211_TX_CTRL_DONT_REORDER
) &&
305 ieee80211_is_data_qos(hdr
->frame_control
)) {
306 qc
= ieee80211_get_qos_ctl(hdr
);
307 tx_hdr
.tidno
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
310 /* Check for RTS protection */
311 if (priv
->hw
->wiphy
->rts_threshold
!= (u32
) -1)
312 if (skb
->len
> priv
->hw
->wiphy
->rts_threshold
)
313 flags
|= ATH9K_HTC_TX_RTSCTS
;
316 if (!(flags
& ATH9K_HTC_TX_RTSCTS
) &&
317 (vif
&& vif
->bss_conf
.use_cts_prot
))
318 flags
|= ATH9K_HTC_TX_CTSONLY
;
320 tx_hdr
.flags
= cpu_to_be32(flags
);
321 tx_hdr
.key_type
= ath9k_cmn_get_hw_crypto_keytype(skb
);
322 if (tx_hdr
.key_type
== ATH9K_KEY_TYPE_CLEAR
)
323 tx_hdr
.keyix
= (u8
) ATH9K_TXKEYIX_INVALID
;
325 tx_hdr
.keyix
= tx_info
->control
.hw_key
->hw_key_idx
;
327 tx_fhdr
= skb_push(skb
, sizeof(tx_hdr
));
328 memcpy(tx_fhdr
, (u8
*) &tx_hdr
, sizeof(tx_hdr
));
332 tx_ctl
->epid
= priv
->cab_ep
;
336 qnum
= skb_get_queue_mapping(skb
);
337 tx_ctl
->epid
= get_htc_epid(priv
, qnum
);
340 int ath9k_htc_tx_start(struct ath9k_htc_priv
*priv
,
341 struct ieee80211_sta
*sta
,
343 u8 slot
, bool is_cab
)
345 struct ieee80211_hdr
*hdr
;
346 struct ieee80211_tx_info
*tx_info
= IEEE80211_SKB_CB(skb
);
347 struct ieee80211_vif
*vif
= tx_info
->control
.vif
;
348 struct ath9k_htc_sta
*ista
;
349 struct ath9k_htc_vif
*avp
= NULL
;
352 hdr
= (struct ieee80211_hdr
*) skb
->data
;
355 * Find out on which interface this packet has to be
359 avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
360 vif_idx
= avp
->index
;
362 if (!priv
->ah
->is_monitoring
) {
363 ath_dbg(ath9k_hw_common(priv
->ah
), XMIT
,
364 "VIF is null, but no monitor interface !\n");
368 vif_idx
= priv
->mon_vif_idx
;
372 * Find out which station this packet is destined for.
375 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
376 sta_idx
= ista
->index
;
378 sta_idx
= priv
->vif_sta_pos
[vif_idx
];
381 if (ieee80211_is_data(hdr
->frame_control
))
382 ath9k_htc_tx_data(priv
, vif
, skb
,
383 sta_idx
, vif_idx
, slot
, is_cab
);
385 ath9k_htc_tx_mgmt(priv
, avp
, skb
,
386 sta_idx
, vif_idx
, slot
);
389 return htc_send(priv
->htc
, skb
);
392 static inline bool __ath9k_htc_check_tx_aggr(struct ath9k_htc_priv
*priv
,
393 struct ath9k_htc_sta
*ista
, u8 tid
)
397 spin_lock_bh(&priv
->tx
.tx_lock
);
398 if ((tid
< ATH9K_HTC_MAX_TID
) && (ista
->tid_state
[tid
] == AGGR_STOP
))
400 spin_unlock_bh(&priv
->tx
.tx_lock
);
405 static void ath9k_htc_check_tx_aggr(struct ath9k_htc_priv
*priv
,
406 struct ieee80211_vif
*vif
,
409 struct ieee80211_sta
*sta
;
410 struct ieee80211_hdr
*hdr
;
413 hdr
= (struct ieee80211_hdr
*) skb
->data
;
414 fc
= hdr
->frame_control
;
418 sta
= ieee80211_find_sta(vif
, hdr
->addr1
);
424 if (sta
&& conf_is_ht(&priv
->hw
->conf
) &&
425 !(skb
->protocol
== cpu_to_be16(ETH_P_PAE
))) {
426 if (ieee80211_is_data_qos(fc
)) {
428 struct ath9k_htc_sta
*ista
;
430 qc
= ieee80211_get_qos_ctl(hdr
);
432 ista
= (struct ath9k_htc_sta
*)sta
->drv_priv
;
433 if (__ath9k_htc_check_tx_aggr(priv
, ista
, tid
)) {
434 ieee80211_start_tx_ba_session(sta
, tid
, 0);
435 spin_lock_bh(&priv
->tx
.tx_lock
);
436 ista
->tid_state
[tid
] = AGGR_PROGRESS
;
437 spin_unlock_bh(&priv
->tx
.tx_lock
);
445 static void ath9k_htc_tx_process(struct ath9k_htc_priv
*priv
,
447 struct __wmi_event_txstatus
*txs
)
449 struct ieee80211_vif
*vif
;
450 struct ath9k_htc_tx_ctl
*tx_ctl
;
451 struct ieee80211_tx_info
*tx_info
;
452 struct ieee80211_tx_rate
*rate
;
453 struct ieee80211_conf
*cur_conf
= &priv
->hw
->conf
;
458 slot
= strip_drv_header(priv
, skb
);
460 dev_kfree_skb_any(skb
);
464 tx_ctl
= HTC_SKB_CB(skb
);
466 tx_info
= IEEE80211_SKB_CB(skb
);
467 vif
= tx_info
->control
.vif
;
468 rate
= &tx_info
->status
.rates
[0];
470 memset(&tx_info
->status
, 0, sizeof(tx_info
->status
));
473 * URB submission failed for this frame, it never reached
476 if (!txok
|| !vif
|| !txs
)
479 if (txs
->ts_flags
& ATH9K_HTC_TXSTAT_ACK
) {
480 tx_info
->flags
|= IEEE80211_TX_STAT_ACK
;
481 if (tx_info
->flags
& IEEE80211_TX_CTL_AMPDU
)
482 tx_info
->flags
|= IEEE80211_TX_STAT_AMPDU
;
485 if (txs
->ts_flags
& ATH9K_HTC_TXSTAT_FILT
)
486 tx_info
->flags
|= IEEE80211_TX_STAT_TX_FILTERED
;
488 if (txs
->ts_flags
& ATH9K_HTC_TXSTAT_RTC_CTS
)
489 rate
->flags
|= IEEE80211_TX_RC_USE_RTS_CTS
;
492 rate
->idx
= MS(txs
->ts_rate
, ATH9K_HTC_TXSTAT_RATE
);
494 if (txs
->ts_flags
& ATH9K_HTC_TXSTAT_MCS
) {
495 rate
->flags
|= IEEE80211_TX_RC_MCS
;
497 if (txs
->ts_flags
& ATH9K_HTC_TXSTAT_CW40
)
498 rate
->flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
499 if (txs
->ts_flags
& ATH9K_HTC_TXSTAT_SGI
)
500 rate
->flags
|= IEEE80211_TX_RC_SHORT_GI
;
502 if (cur_conf
->chandef
.chan
->band
== NL80211_BAND_5GHZ
)
503 rate
->idx
+= 4; /* No CCK rates */
506 ath9k_htc_check_tx_aggr(priv
, vif
, skb
);
509 spin_lock_bh(&priv
->tx
.tx_lock
);
510 if (WARN_ON(--priv
->tx
.queued_cnt
< 0))
511 priv
->tx
.queued_cnt
= 0;
512 spin_unlock_bh(&priv
->tx
.tx_lock
);
514 ath9k_htc_tx_clear_slot(priv
, slot
);
516 /* Remove padding before handing frame back to mac80211 */
517 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
519 padsize
= hdrlen
& 3;
520 if (padsize
&& skb
->len
> hdrlen
+ padsize
) {
521 memmove(skb
->data
+ padsize
, skb
->data
, hdrlen
);
522 skb_pull(skb
, padsize
);
525 /* Send status to mac80211 */
526 ieee80211_tx_status_skb(priv
->hw
, skb
);
529 static inline void ath9k_htc_tx_drainq(struct ath9k_htc_priv
*priv
,
530 struct sk_buff_head
*queue
)
534 while ((skb
= skb_dequeue(queue
)) != NULL
) {
535 ath9k_htc_tx_process(priv
, skb
, NULL
);
539 void ath9k_htc_tx_drain(struct ath9k_htc_priv
*priv
)
541 struct ath9k_htc_tx_event
*event
, *tmp
;
543 spin_lock_bh(&priv
->tx
.tx_lock
);
544 priv
->tx
.flags
|= ATH9K_HTC_OP_TX_DRAIN
;
545 spin_unlock_bh(&priv
->tx
.tx_lock
);
548 * Ensure that all pending TX frames are flushed,
549 * and that the TX completion/failed tasklets is killed.
552 tasklet_kill(&priv
->wmi
->wmi_event_tasklet
);
553 tasklet_kill(&priv
->tx_failed_tasklet
);
555 ath9k_htc_tx_drainq(priv
, &priv
->tx
.mgmt_ep_queue
);
556 ath9k_htc_tx_drainq(priv
, &priv
->tx
.cab_ep_queue
);
557 ath9k_htc_tx_drainq(priv
, &priv
->tx
.data_be_queue
);
558 ath9k_htc_tx_drainq(priv
, &priv
->tx
.data_bk_queue
);
559 ath9k_htc_tx_drainq(priv
, &priv
->tx
.data_vi_queue
);
560 ath9k_htc_tx_drainq(priv
, &priv
->tx
.data_vo_queue
);
561 ath9k_htc_tx_drainq(priv
, &priv
->tx
.tx_failed
);
564 * The TX cleanup timer has already been killed.
566 spin_lock_bh(&priv
->wmi
->event_lock
);
567 list_for_each_entry_safe(event
, tmp
, &priv
->wmi
->pending_tx_events
, list
) {
568 list_del(&event
->list
);
571 spin_unlock_bh(&priv
->wmi
->event_lock
);
573 spin_lock_bh(&priv
->tx
.tx_lock
);
574 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_DRAIN
;
575 spin_unlock_bh(&priv
->tx
.tx_lock
);
578 void ath9k_tx_failed_tasklet(struct tasklet_struct
*t
)
580 struct ath9k_htc_priv
*priv
= from_tasklet(priv
, t
, tx_failed_tasklet
);
582 spin_lock(&priv
->tx
.tx_lock
);
583 if (priv
->tx
.flags
& ATH9K_HTC_OP_TX_DRAIN
) {
584 spin_unlock(&priv
->tx
.tx_lock
);
587 spin_unlock(&priv
->tx
.tx_lock
);
589 ath9k_htc_tx_drainq(priv
, &priv
->tx
.tx_failed
);
592 static inline bool check_cookie(struct ath9k_htc_priv
*priv
,
598 if (epid
== priv
->mgmt_ep
) {
599 struct tx_mgmt_hdr
*hdr
;
600 hdr
= (struct tx_mgmt_hdr
*) skb
->data
;
601 fcookie
= hdr
->cookie
;
602 } else if ((epid
== priv
->data_bk_ep
) ||
603 (epid
== priv
->data_be_ep
) ||
604 (epid
== priv
->data_vi_ep
) ||
605 (epid
== priv
->data_vo_ep
) ||
606 (epid
== priv
->cab_ep
)) {
607 struct tx_frame_hdr
*hdr
;
608 hdr
= (struct tx_frame_hdr
*) skb
->data
;
609 fcookie
= hdr
->cookie
;
612 if (fcookie
== cookie
)
618 static struct sk_buff
* ath9k_htc_tx_get_packet(struct ath9k_htc_priv
*priv
,
619 struct __wmi_event_txstatus
*txs
)
621 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
622 struct sk_buff_head
*epid_queue
;
623 struct sk_buff
*skb
, *tmp
;
625 u8 epid
= MS(txs
->ts_rate
, ATH9K_HTC_TXSTAT_EPID
);
627 epid_queue
= get_htc_epid_queue(priv
, epid
);
631 spin_lock_irqsave(&epid_queue
->lock
, flags
);
632 skb_queue_walk_safe(epid_queue
, skb
, tmp
) {
633 if (check_cookie(priv
, skb
, txs
->cookie
, epid
)) {
634 __skb_unlink(skb
, epid_queue
);
635 spin_unlock_irqrestore(&epid_queue
->lock
, flags
);
639 spin_unlock_irqrestore(&epid_queue
->lock
, flags
);
641 ath_dbg(common
, XMIT
, "No matching packet for cookie: %d, epid: %d\n",
647 void ath9k_htc_txstatus(struct ath9k_htc_priv
*priv
, void *wmi_event
)
649 struct wmi_event_txstatus
*txs
= wmi_event
;
650 struct __wmi_event_txstatus
*__txs
;
652 struct ath9k_htc_tx_event
*tx_pend
;
655 if (WARN_ON_ONCE(txs
->cnt
> HTC_MAX_TX_STATUS
))
658 for (i
= 0; i
< txs
->cnt
; i
++) {
659 __txs
= &txs
->txstatus
[i
];
661 skb
= ath9k_htc_tx_get_packet(priv
, __txs
);
664 * Store this event, so that the TX cleanup
665 * routine can check later for the needed packet.
667 tx_pend
= kzalloc(sizeof(struct ath9k_htc_tx_event
),
672 memcpy(&tx_pend
->txs
, __txs
,
673 sizeof(struct __wmi_event_txstatus
));
675 spin_lock(&priv
->wmi
->event_lock
);
676 list_add_tail(&tx_pend
->list
,
677 &priv
->wmi
->pending_tx_events
);
678 spin_unlock(&priv
->wmi
->event_lock
);
683 ath9k_htc_tx_process(priv
, skb
, __txs
);
686 /* Wake TX queues if needed */
687 ath9k_htc_check_wake_queues(priv
);
690 void ath9k_htc_txep(void *drv_priv
, struct sk_buff
*skb
,
691 enum htc_endpoint_id ep_id
, bool txok
)
693 struct ath9k_htc_priv
*priv
= drv_priv
;
694 struct ath9k_htc_tx_ctl
*tx_ctl
;
695 struct sk_buff_head
*epid_queue
;
697 tx_ctl
= HTC_SKB_CB(skb
);
699 tx_ctl
->timestamp
= jiffies
;
702 skb_queue_tail(&priv
->tx
.tx_failed
, skb
);
703 tasklet_schedule(&priv
->tx_failed_tasklet
);
707 epid_queue
= get_htc_epid_queue(priv
, ep_id
);
709 dev_kfree_skb_any(skb
);
713 skb_queue_tail(epid_queue
, skb
);
716 static inline bool check_packet(struct ath9k_htc_priv
*priv
, struct sk_buff
*skb
)
718 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
719 struct ath9k_htc_tx_ctl
*tx_ctl
;
721 tx_ctl
= HTC_SKB_CB(skb
);
723 if (time_after(jiffies
,
725 msecs_to_jiffies(ATH9K_HTC_TX_TIMEOUT_INTERVAL
))) {
726 ath_dbg(common
, XMIT
, "Dropping a packet due to TX timeout\n");
733 static void ath9k_htc_tx_cleanup_queue(struct ath9k_htc_priv
*priv
,
734 struct sk_buff_head
*epid_queue
)
736 bool process
= false;
738 struct sk_buff
*skb
, *tmp
;
739 struct sk_buff_head queue
;
741 skb_queue_head_init(&queue
);
743 spin_lock_irqsave(&epid_queue
->lock
, flags
);
744 skb_queue_walk_safe(epid_queue
, skb
, tmp
) {
745 if (check_packet(priv
, skb
)) {
746 __skb_unlink(skb
, epid_queue
);
747 __skb_queue_tail(&queue
, skb
);
751 spin_unlock_irqrestore(&epid_queue
->lock
, flags
);
754 skb_queue_walk_safe(&queue
, skb
, tmp
) {
755 __skb_unlink(skb
, &queue
);
756 ath9k_htc_tx_process(priv
, skb
, NULL
);
761 void ath9k_htc_tx_cleanup_timer(struct timer_list
*t
)
763 struct ath9k_htc_priv
*priv
= from_timer(priv
, t
, tx
.cleanup_timer
);
764 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
765 struct ath9k_htc_tx_event
*event
, *tmp
;
768 spin_lock(&priv
->wmi
->event_lock
);
769 list_for_each_entry_safe(event
, tmp
, &priv
->wmi
->pending_tx_events
, list
) {
771 skb
= ath9k_htc_tx_get_packet(priv
, &event
->txs
);
773 ath_dbg(common
, XMIT
,
774 "Found packet for cookie: %d, epid: %d\n",
776 MS(event
->txs
.ts_rate
, ATH9K_HTC_TXSTAT_EPID
));
778 ath9k_htc_tx_process(priv
, skb
, &event
->txs
);
779 list_del(&event
->list
);
784 if (++event
->count
>= ATH9K_HTC_TX_TIMEOUT_COUNT
) {
785 list_del(&event
->list
);
789 spin_unlock(&priv
->wmi
->event_lock
);
792 * Check if status-pending packets have to be cleaned up.
794 ath9k_htc_tx_cleanup_queue(priv
, &priv
->tx
.mgmt_ep_queue
);
795 ath9k_htc_tx_cleanup_queue(priv
, &priv
->tx
.cab_ep_queue
);
796 ath9k_htc_tx_cleanup_queue(priv
, &priv
->tx
.data_be_queue
);
797 ath9k_htc_tx_cleanup_queue(priv
, &priv
->tx
.data_bk_queue
);
798 ath9k_htc_tx_cleanup_queue(priv
, &priv
->tx
.data_vi_queue
);
799 ath9k_htc_tx_cleanup_queue(priv
, &priv
->tx
.data_vo_queue
);
801 /* Wake TX queues if needed */
802 ath9k_htc_check_wake_queues(priv
);
804 mod_timer(&priv
->tx
.cleanup_timer
,
805 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
808 int ath9k_tx_init(struct ath9k_htc_priv
*priv
)
810 skb_queue_head_init(&priv
->tx
.mgmt_ep_queue
);
811 skb_queue_head_init(&priv
->tx
.cab_ep_queue
);
812 skb_queue_head_init(&priv
->tx
.data_be_queue
);
813 skb_queue_head_init(&priv
->tx
.data_bk_queue
);
814 skb_queue_head_init(&priv
->tx
.data_vi_queue
);
815 skb_queue_head_init(&priv
->tx
.data_vo_queue
);
816 skb_queue_head_init(&priv
->tx
.tx_failed
);
821 void ath9k_tx_cleanup(struct ath9k_htc_priv
*priv
)
826 bool ath9k_htc_txq_setup(struct ath9k_htc_priv
*priv
, int subtype
)
828 struct ath_hw
*ah
= priv
->ah
;
829 struct ath_common
*common
= ath9k_hw_common(ah
);
830 struct ath9k_tx_queue_info qi
;
833 memset(&qi
, 0, sizeof(qi
));
834 ATH9K_HTC_INIT_TXQ(subtype
);
836 qnum
= ath9k_hw_setuptxqueue(priv
->ah
, ATH9K_TX_QUEUE_DATA
, &qi
);
840 if (qnum
>= ARRAY_SIZE(priv
->hwq_map
)) {
841 ath_err(common
, "qnum %u out of range, max %zu!\n",
842 qnum
, ARRAY_SIZE(priv
->hwq_map
));
843 ath9k_hw_releasetxqueue(ah
, qnum
);
847 priv
->hwq_map
[subtype
] = qnum
;
851 int ath9k_htc_cabq_setup(struct ath9k_htc_priv
*priv
)
853 struct ath9k_tx_queue_info qi
;
855 memset(&qi
, 0, sizeof(qi
));
856 ATH9K_HTC_INIT_TXQ(0);
858 return ath9k_hw_setuptxqueue(priv
->ah
, ATH9K_TX_QUEUE_CAB
, &qi
);
866 * Calculate the RX filter to be set in the HW.
868 u32
ath9k_htc_calcrxfilter(struct ath9k_htc_priv
*priv
)
870 #define RX_FILTER_PRESERVE (ATH9K_RX_FILTER_PHYERR | ATH9K_RX_FILTER_PHYRADAR)
872 struct ath_hw
*ah
= priv
->ah
;
875 rfilt
= (ath9k_hw_getrxfilter(ah
) & RX_FILTER_PRESERVE
)
876 | ATH9K_RX_FILTER_UCAST
| ATH9K_RX_FILTER_BCAST
877 | ATH9K_RX_FILTER_MCAST
;
879 if (priv
->rxfilter
& FIF_PROBE_REQ
)
880 rfilt
|= ATH9K_RX_FILTER_PROBEREQ
;
882 if (ah
->is_monitoring
)
883 rfilt
|= ATH9K_RX_FILTER_PROM
;
885 if (priv
->rxfilter
& FIF_CONTROL
)
886 rfilt
|= ATH9K_RX_FILTER_CONTROL
;
888 if ((ah
->opmode
== NL80211_IFTYPE_STATION
) &&
889 (priv
->nvifs
<= 1) &&
890 !(priv
->rxfilter
& FIF_BCN_PRBRESP_PROMISC
))
891 rfilt
|= ATH9K_RX_FILTER_MYBEACON
;
893 rfilt
|= ATH9K_RX_FILTER_BEACON
;
895 if (conf_is_ht(&priv
->hw
->conf
)) {
896 rfilt
|= ATH9K_RX_FILTER_COMP_BAR
;
897 rfilt
|= ATH9K_RX_FILTER_UNCOMP_BA_BAR
;
900 if (priv
->rxfilter
& FIF_PSPOLL
)
901 rfilt
|= ATH9K_RX_FILTER_PSPOLL
;
903 if (priv
->nvifs
> 1 ||
904 priv
->rxfilter
& (FIF_OTHER_BSS
| FIF_MCAST_ACTION
))
905 rfilt
|= ATH9K_RX_FILTER_MCAST_BCAST_ALL
;
909 #undef RX_FILTER_PRESERVE
913 * Recv initialization for opmode change.
915 static void ath9k_htc_opmode_init(struct ath9k_htc_priv
*priv
)
917 struct ath_hw
*ah
= priv
->ah
;
920 /* configure rx filter */
921 rfilt
= ath9k_htc_calcrxfilter(priv
);
922 ath9k_hw_setrxfilter(ah
, rfilt
);
924 /* calculate and install multicast filter */
925 mfilt
[0] = mfilt
[1] = ~0;
926 ath9k_hw_setmcastfilter(ah
, mfilt
[0], mfilt
[1]);
929 void ath9k_host_rx_init(struct ath9k_htc_priv
*priv
)
931 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
932 ath9k_hw_rxena(priv
->ah
);
933 ath9k_htc_opmode_init(priv
);
934 ath9k_hw_startpcureceive(priv
->ah
, test_bit(ATH_OP_SCANNING
, &common
->op_flags
));
937 static inline void convert_htc_flag(struct ath_rx_status
*rx_stats
,
938 struct ath_htc_rx_status
*rxstatus
)
940 rx_stats
->enc_flags
= 0;
941 rx_stats
->bw
= RATE_INFO_BW_20
;
942 if (rxstatus
->rs_flags
& ATH9K_RX_2040
)
943 rx_stats
->bw
= RATE_INFO_BW_40
;
944 if (rxstatus
->rs_flags
& ATH9K_RX_GI
)
945 rx_stats
->enc_flags
|= RX_ENC_FLAG_SHORT_GI
;
948 static void rx_status_htc_to_ath(struct ath_rx_status
*rx_stats
,
949 struct ath_htc_rx_status
*rxstatus
)
951 rx_stats
->rs_datalen
= be16_to_cpu(rxstatus
->rs_datalen
);
952 rx_stats
->rs_status
= rxstatus
->rs_status
;
953 rx_stats
->rs_phyerr
= rxstatus
->rs_phyerr
;
954 rx_stats
->rs_rssi
= rxstatus
->rs_rssi
;
955 rx_stats
->rs_keyix
= rxstatus
->rs_keyix
;
956 rx_stats
->rs_rate
= rxstatus
->rs_rate
;
957 rx_stats
->rs_antenna
= rxstatus
->rs_antenna
;
958 rx_stats
->rs_more
= rxstatus
->rs_more
;
960 memcpy(rx_stats
->rs_rssi_ctl
, rxstatus
->rs_rssi_ctl
,
961 sizeof(rx_stats
->rs_rssi_ctl
));
962 memcpy(rx_stats
->rs_rssi_ext
, rxstatus
->rs_rssi_ext
,
963 sizeof(rx_stats
->rs_rssi_ext
));
965 rx_stats
->rs_isaggr
= rxstatus
->rs_isaggr
;
966 rx_stats
->rs_moreaggr
= rxstatus
->rs_moreaggr
;
967 rx_stats
->rs_num_delims
= rxstatus
->rs_num_delims
;
968 convert_htc_flag(rx_stats
, rxstatus
);
971 static bool ath9k_rx_prepare(struct ath9k_htc_priv
*priv
,
972 struct ath9k_htc_rxbuf
*rxbuf
,
973 struct ieee80211_rx_status
*rx_status
)
976 struct ieee80211_hdr
*hdr
;
977 struct ieee80211_hw
*hw
= priv
->hw
;
978 struct sk_buff
*skb
= rxbuf
->skb
;
979 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
980 struct ath_hw
*ah
= common
->ah
;
981 struct ath_htc_rx_status
*rxstatus
;
982 struct ath_rx_status rx_stats
;
983 bool decrypt_error
= false;
987 if (skb
->len
< HTC_RX_FRAME_HEADER_SIZE
) {
988 ath_err(common
, "Corrupted RX frame, dropping (len: %d)\n",
993 rxstatus
= (struct ath_htc_rx_status
*)skb
->data
;
995 rs_datalen
= be16_to_cpu(rxstatus
->rs_datalen
);
996 if (unlikely(rs_datalen
-
997 (skb
->len
- HTC_RX_FRAME_HEADER_SIZE
) != 0)) {
999 "Corrupted RX data len, dropping (dlen: %d, skblen: %d)\n",
1000 rs_datalen
, skb
->len
);
1004 is_phyerr
= rxstatus
->rs_status
& ATH9K_RXERR_PHY
;
1006 * Discard zero-length packets and packets smaller than an ACK
1007 * which are not PHY_ERROR (short radar pulses have a length of 3)
1009 if (unlikely(!rs_datalen
|| (rs_datalen
< 10 && !is_phyerr
))) {
1010 ath_dbg(common
, ANY
,
1011 "Short RX data len, dropping (dlen: %d)\n",
1016 if (rxstatus
->rs_keyix
>= ATH_KEYMAX
&&
1017 rxstatus
->rs_keyix
!= ATH9K_RXKEYIX_INVALID
) {
1018 ath_dbg(common
, ANY
,
1019 "Invalid keyix, dropping (keyix: %d)\n",
1020 rxstatus
->rs_keyix
);
1024 /* Get the RX status information */
1026 memset(rx_status
, 0, sizeof(struct ieee80211_rx_status
));
1028 /* Copy everything from ath_htc_rx_status (HTC_RX_FRAME_HEADER).
1029 * After this, we can drop this part of skb. */
1030 rx_status_htc_to_ath(&rx_stats
, rxstatus
);
1031 ath9k_htc_err_stat_rx(priv
, &rx_stats
);
1032 rx_status
->mactime
= be64_to_cpu(rxstatus
->rs_tstamp
);
1033 skb_pull(skb
, HTC_RX_FRAME_HEADER_SIZE
);
1036 * everything but the rate is checked here, the rate check is done
1037 * separately to avoid doing two lookups for a rate for each frame.
1039 hdr
= (struct ieee80211_hdr
*)skb
->data
;
1042 * Process PHY errors and return so that the packet
1045 if (unlikely(is_phyerr
)) {
1046 /* TODO: Not using DFS processing now. */
1047 if (ath_cmn_process_fft(&priv
->spec_priv
, hdr
,
1048 &rx_stats
, rx_status
->mactime
)) {
1049 /* TODO: Code to collect spectral scan statistics */
1054 if (!ath9k_cmn_rx_accept(common
, hdr
, rx_status
, &rx_stats
,
1055 &decrypt_error
, priv
->rxfilter
))
1058 ath9k_cmn_rx_skb_postprocess(common
, skb
, &rx_stats
,
1059 rx_status
, decrypt_error
);
1061 if (ath9k_cmn_process_rate(common
, hw
, &rx_stats
, rx_status
))
1064 rx_stats
.is_mybeacon
= ath_is_mybeacon(common
, hdr
);
1065 ath9k_cmn_process_rssi(common
, hw
, &rx_stats
, rx_status
);
1067 rx_status
->band
= ah
->curchan
->chan
->band
;
1068 rx_status
->freq
= ah
->curchan
->chan
->center_freq
;
1069 rx_status
->antenna
= rx_stats
.rs_antenna
;
1070 rx_status
->flag
|= RX_FLAG_MACTIME_END
;
1078 * FIXME: Handle FLUSH later on.
1080 void ath9k_rx_tasklet(struct tasklet_struct
*t
)
1082 struct ath9k_htc_priv
*priv
= from_tasklet(priv
, t
, rx_tasklet
);
1083 struct ath9k_htc_rxbuf
*rxbuf
= NULL
, *tmp_buf
= NULL
;
1084 struct ieee80211_rx_status rx_status
;
1085 struct sk_buff
*skb
;
1086 unsigned long flags
;
1087 struct ieee80211_hdr
*hdr
;
1090 spin_lock_irqsave(&priv
->rx
.rxbuflock
, flags
);
1091 list_for_each_entry(tmp_buf
, &priv
->rx
.rxbuf
, list
) {
1092 if (tmp_buf
->in_process
) {
1098 if (rxbuf
== NULL
) {
1099 spin_unlock_irqrestore(&priv
->rx
.rxbuflock
, flags
);
1106 if (!ath9k_rx_prepare(priv
, rxbuf
, &rx_status
)) {
1107 dev_kfree_skb_any(rxbuf
->skb
);
1111 memcpy(IEEE80211_SKB_RXCB(rxbuf
->skb
), &rx_status
,
1112 sizeof(struct ieee80211_rx_status
));
1114 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1116 if (ieee80211_is_beacon(hdr
->frame_control
) && priv
->ps_enabled
)
1117 ieee80211_queue_work(priv
->hw
, &priv
->ps_work
);
1119 spin_unlock_irqrestore(&priv
->rx
.rxbuflock
, flags
);
1121 ieee80211_rx(priv
->hw
, skb
);
1123 spin_lock_irqsave(&priv
->rx
.rxbuflock
, flags
);
1125 rxbuf
->in_process
= false;
1127 list_move_tail(&rxbuf
->list
, &priv
->rx
.rxbuf
);
1129 spin_unlock_irqrestore(&priv
->rx
.rxbuflock
, flags
);
1134 void ath9k_htc_rxep(void *drv_priv
, struct sk_buff
*skb
,
1135 enum htc_endpoint_id ep_id
)
1137 struct ath9k_htc_priv
*priv
= drv_priv
;
1138 struct ath_hw
*ah
= priv
->ah
;
1139 struct ath_common
*common
= ath9k_hw_common(ah
);
1140 struct ath9k_htc_rxbuf
*rxbuf
= NULL
, *tmp_buf
= NULL
;
1141 unsigned long flags
;
1143 /* Check if ath9k_rx_init() completed. */
1144 if (!data_race(priv
->rx
.initialized
))
1147 spin_lock_irqsave(&priv
->rx
.rxbuflock
, flags
);
1148 list_for_each_entry(tmp_buf
, &priv
->rx
.rxbuf
, list
) {
1149 if (!tmp_buf
->in_process
) {
1154 spin_unlock_irqrestore(&priv
->rx
.rxbuflock
, flags
);
1156 if (rxbuf
== NULL
) {
1157 ath_dbg(common
, ANY
, "No free RX buffer\n");
1161 spin_lock_irqsave(&priv
->rx
.rxbuflock
, flags
);
1163 rxbuf
->in_process
= true;
1164 spin_unlock_irqrestore(&priv
->rx
.rxbuflock
, flags
);
1166 tasklet_schedule(&priv
->rx_tasklet
);
1169 dev_kfree_skb_any(skb
);
1172 /* FIXME: Locking for cleanup/init */
1174 void ath9k_rx_cleanup(struct ath9k_htc_priv
*priv
)
1176 struct ath9k_htc_rxbuf
*rxbuf
, *tbuf
;
1178 list_for_each_entry_safe(rxbuf
, tbuf
, &priv
->rx
.rxbuf
, list
) {
1179 list_del(&rxbuf
->list
);
1181 dev_kfree_skb_any(rxbuf
->skb
);
1186 int ath9k_rx_init(struct ath9k_htc_priv
*priv
)
1190 INIT_LIST_HEAD(&priv
->rx
.rxbuf
);
1191 spin_lock_init(&priv
->rx
.rxbuflock
);
1193 for (i
= 0; i
< ATH9K_HTC_RXBUF
; i
++) {
1194 struct ath9k_htc_rxbuf
*rxbuf
=
1195 kzalloc(sizeof(struct ath9k_htc_rxbuf
), GFP_KERNEL
);
1199 list_add_tail(&rxbuf
->list
, &priv
->rx
.rxbuf
);
1202 /* Allow ath9k_htc_rxep() to operate. */
1204 priv
->rx
.initialized
= true;
1209 ath9k_rx_cleanup(priv
);