2 * This file is part of wl18xx
4 * Copyright (C) 2011 Texas Instruments Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 #include "../wlcore/wlcore.h"
23 #include "../wlcore/cmd.h"
24 #include "../wlcore/debug.h"
25 #include "../wlcore/acx.h"
26 #include "../wlcore/tx.h"
32 void wl18xx_get_last_tx_rate(struct wl1271
*wl
, struct ieee80211_vif
*vif
,
33 u8 band
, struct ieee80211_tx_rate
*rate
)
35 u8 fw_rate
= wl
->fw_status
->counters
.tx_last_rate
;
37 if (fw_rate
> CONF_HW_RATE_INDEX_MAX
) {
38 wl1271_error("last Tx rate invalid: %d", fw_rate
);
44 if (fw_rate
<= CONF_HW_RATE_INDEX_54MBPS
) {
46 if (band
== IEEE80211_BAND_5GHZ
)
47 rate
->idx
-= CONF_HW_RATE_INDEX_6MBPS
;
50 rate
->flags
= IEEE80211_TX_RC_MCS
;
51 rate
->idx
= fw_rate
- CONF_HW_RATE_INDEX_MCS0
;
53 /* SGI modifier is counted as a separate rate */
54 if (fw_rate
>= CONF_HW_RATE_INDEX_MCS7_SGI
)
56 if (fw_rate
== CONF_HW_RATE_INDEX_MCS15_SGI
)
59 /* this also covers the 40Mhz SGI case (= MCS15) */
60 if (fw_rate
== CONF_HW_RATE_INDEX_MCS7_SGI
||
61 fw_rate
== CONF_HW_RATE_INDEX_MCS15_SGI
)
62 rate
->flags
|= IEEE80211_TX_RC_SHORT_GI
;
64 if (fw_rate
> CONF_HW_RATE_INDEX_MCS7_SGI
&& vif
) {
65 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
66 if (wlvif
->channel_type
== NL80211_CHAN_HT40MINUS
||
67 wlvif
->channel_type
== NL80211_CHAN_HT40PLUS
) {
68 /* adjustment needed for range 0-7 */
70 rate
->flags
|= IEEE80211_TX_RC_40_MHZ_WIDTH
;
76 static void wl18xx_tx_complete_packet(struct wl1271
*wl
, u8 tx_stat_byte
)
78 struct ieee80211_tx_info
*info
;
80 int id
= tx_stat_byte
& WL18XX_TX_STATUS_DESC_ID_MASK
;
83 /* check for id legality */
84 if (unlikely(id
>= wl
->num_tx_desc
|| wl
->tx_frames
[id
] == NULL
)) {
85 wl1271_warning("illegal id in tx completion: %d", id
);
89 /* a zero bit indicates Tx success */
90 tx_success
= !(tx_stat_byte
& BIT(WL18XX_TX_STATUS_STAT_BIT_IDX
));
92 skb
= wl
->tx_frames
[id
];
93 info
= IEEE80211_SKB_CB(skb
);
95 if (wl12xx_is_dummy_packet(wl
, skb
)) {
96 wl1271_free_tx_id(wl
, id
);
100 /* update the TX status info */
101 if (tx_success
&& !(info
->flags
& IEEE80211_TX_CTL_NO_ACK
))
102 info
->flags
|= IEEE80211_TX_STAT_ACK
;
104 * first pass info->control.vif while it's valid, and then fill out
105 * the info->status structures
107 wl18xx_get_last_tx_rate(wl
, info
->control
.vif
,
108 info
->band
, &info
->status
.rates
[0]);
110 info
->status
.rates
[0].count
= 1; /* no data about retries */
111 info
->status
.ack_signal
= -1;
114 wl
->stats
.retry_count
++;
117 * TODO: update sequence number for encryption? seems to be
118 * unsupported for now. needed for recovery with encryption.
121 /* remove private header from packet */
122 skb_pull(skb
, sizeof(struct wl1271_tx_hw_descr
));
124 /* remove TKIP header space if present */
125 if ((wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
) &&
126 info
->control
.hw_key
&&
127 info
->control
.hw_key
->cipher
== WLAN_CIPHER_SUITE_TKIP
) {
128 int hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
129 memmove(skb
->data
+ WL1271_EXTRA_SPACE_TKIP
, skb
->data
, hdrlen
);
130 skb_pull(skb
, WL1271_EXTRA_SPACE_TKIP
);
133 wl1271_debug(DEBUG_TX
, "tx status id %u skb 0x%p success %d",
134 id
, skb
, tx_success
);
136 /* return the packet to the stack */
137 skb_queue_tail(&wl
->deferred_tx_queue
, skb
);
138 queue_work(wl
->freezable_wq
, &wl
->netstack_work
);
139 wl1271_free_tx_id(wl
, id
);
142 void wl18xx_tx_immediate_complete(struct wl1271
*wl
)
144 struct wl18xx_fw_status_priv
*status_priv
=
145 (struct wl18xx_fw_status_priv
*)wl
->fw_status
->priv
;
146 struct wl18xx_priv
*priv
= wl
->priv
;
149 /* nothing to do here */
150 if (priv
->last_fw_rls_idx
== status_priv
->fw_release_idx
)
153 /* freed Tx descriptors */
154 wl1271_debug(DEBUG_TX
, "last released desc = %d, current idx = %d",
155 priv
->last_fw_rls_idx
, status_priv
->fw_release_idx
);
157 if (status_priv
->fw_release_idx
>= WL18XX_FW_MAX_TX_STATUS_DESC
) {
158 wl1271_error("invalid desc release index %d",
159 status_priv
->fw_release_idx
);
164 for (i
= priv
->last_fw_rls_idx
;
165 i
!= status_priv
->fw_release_idx
;
166 i
= (i
+ 1) % WL18XX_FW_MAX_TX_STATUS_DESC
) {
167 wl18xx_tx_complete_packet(wl
,
168 status_priv
->released_tx_desc
[i
]);
170 wl
->tx_results_count
++;
173 priv
->last_fw_rls_idx
= status_priv
->fw_release_idx
;