1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * This file is part of wl18xx
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2011 Texas Instruments Inc.
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include "../wlcore/wlcore.h"
9*4882a593Smuzhiyun #include "../wlcore/cmd.h"
10*4882a593Smuzhiyun #include "../wlcore/debug.h"
11*4882a593Smuzhiyun #include "../wlcore/acx.h"
12*4882a593Smuzhiyun #include "../wlcore/tx.h"
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include "wl18xx.h"
15*4882a593Smuzhiyun #include "tx.h"
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun static
wl18xx_get_last_tx_rate(struct wl1271 * wl,struct ieee80211_vif * vif,u8 band,struct ieee80211_tx_rate * rate,u8 hlid)18*4882a593Smuzhiyun void wl18xx_get_last_tx_rate(struct wl1271 *wl, struct ieee80211_vif *vif,
19*4882a593Smuzhiyun u8 band, struct ieee80211_tx_rate *rate, u8 hlid)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun u8 fw_rate = wl->links[hlid].fw_rate_idx;
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun if (fw_rate > CONF_HW_RATE_INDEX_MAX) {
24*4882a593Smuzhiyun wl1271_error("last Tx rate invalid: %d", fw_rate);
25*4882a593Smuzhiyun rate->idx = 0;
26*4882a593Smuzhiyun rate->flags = 0;
27*4882a593Smuzhiyun return;
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun if (fw_rate <= CONF_HW_RATE_INDEX_54MBPS) {
31*4882a593Smuzhiyun rate->idx = fw_rate;
32*4882a593Smuzhiyun if (band == NL80211_BAND_5GHZ)
33*4882a593Smuzhiyun rate->idx -= CONF_HW_RATE_INDEX_6MBPS;
34*4882a593Smuzhiyun rate->flags = 0;
35*4882a593Smuzhiyun } else {
36*4882a593Smuzhiyun rate->flags = IEEE80211_TX_RC_MCS;
37*4882a593Smuzhiyun rate->idx = fw_rate - CONF_HW_RATE_INDEX_MCS0;
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun /* SGI modifier is counted as a separate rate */
40*4882a593Smuzhiyun if (fw_rate >= CONF_HW_RATE_INDEX_MCS7_SGI)
41*4882a593Smuzhiyun (rate->idx)--;
42*4882a593Smuzhiyun if (fw_rate == CONF_HW_RATE_INDEX_MCS15_SGI)
43*4882a593Smuzhiyun (rate->idx)--;
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /* this also covers the 40Mhz SGI case (= MCS15) */
46*4882a593Smuzhiyun if (fw_rate == CONF_HW_RATE_INDEX_MCS7_SGI ||
47*4882a593Smuzhiyun fw_rate == CONF_HW_RATE_INDEX_MCS15_SGI)
48*4882a593Smuzhiyun rate->flags |= IEEE80211_TX_RC_SHORT_GI;
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun if (fw_rate > CONF_HW_RATE_INDEX_MCS7_SGI && vif) {
51*4882a593Smuzhiyun struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
52*4882a593Smuzhiyun if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
53*4882a593Smuzhiyun wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
54*4882a593Smuzhiyun /* adjustment needed for range 0-7 */
55*4882a593Smuzhiyun rate->idx -= 8;
56*4882a593Smuzhiyun rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
wl18xx_tx_complete_packet(struct wl1271 * wl,u8 tx_stat_byte)62*4882a593Smuzhiyun static void wl18xx_tx_complete_packet(struct wl1271 *wl, u8 tx_stat_byte)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun struct ieee80211_tx_info *info;
65*4882a593Smuzhiyun struct sk_buff *skb;
66*4882a593Smuzhiyun int id = tx_stat_byte & WL18XX_TX_STATUS_DESC_ID_MASK;
67*4882a593Smuzhiyun bool tx_success;
68*4882a593Smuzhiyun struct wl1271_tx_hw_descr *tx_desc;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun /* check for id legality */
71*4882a593Smuzhiyun if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) {
72*4882a593Smuzhiyun wl1271_warning("illegal id in tx completion: %d", id);
73*4882a593Smuzhiyun return;
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun /* a zero bit indicates Tx success */
77*4882a593Smuzhiyun tx_success = !(tx_stat_byte & BIT(WL18XX_TX_STATUS_STAT_BIT_IDX));
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun skb = wl->tx_frames[id];
80*4882a593Smuzhiyun info = IEEE80211_SKB_CB(skb);
81*4882a593Smuzhiyun tx_desc = (struct wl1271_tx_hw_descr *)skb->data;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun if (wl12xx_is_dummy_packet(wl, skb)) {
84*4882a593Smuzhiyun wl1271_free_tx_id(wl, id);
85*4882a593Smuzhiyun return;
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun /* update the TX status info */
89*4882a593Smuzhiyun if (tx_success && !(info->flags & IEEE80211_TX_CTL_NO_ACK))
90*4882a593Smuzhiyun info->flags |= IEEE80211_TX_STAT_ACK;
91*4882a593Smuzhiyun /*
92*4882a593Smuzhiyun * first pass info->control.vif while it's valid, and then fill out
93*4882a593Smuzhiyun * the info->status structures
94*4882a593Smuzhiyun */
95*4882a593Smuzhiyun wl18xx_get_last_tx_rate(wl, info->control.vif,
96*4882a593Smuzhiyun info->band,
97*4882a593Smuzhiyun &info->status.rates[0],
98*4882a593Smuzhiyun tx_desc->hlid);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun info->status.rates[0].count = 1; /* no data about retries */
101*4882a593Smuzhiyun info->status.ack_signal = -1;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun if (!tx_success)
104*4882a593Smuzhiyun wl->stats.retry_count++;
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun /*
107*4882a593Smuzhiyun * TODO: update sequence number for encryption? seems to be
108*4882a593Smuzhiyun * unsupported for now. needed for recovery with encryption.
109*4882a593Smuzhiyun */
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun /* remove private header from packet */
112*4882a593Smuzhiyun skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /* remove TKIP header space if present */
115*4882a593Smuzhiyun if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) &&
116*4882a593Smuzhiyun info->control.hw_key &&
117*4882a593Smuzhiyun info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
118*4882a593Smuzhiyun int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
119*4882a593Smuzhiyun memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data, hdrlen);
120*4882a593Smuzhiyun skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p success %d",
124*4882a593Smuzhiyun id, skb, tx_success);
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* return the packet to the stack */
127*4882a593Smuzhiyun skb_queue_tail(&wl->deferred_tx_queue, skb);
128*4882a593Smuzhiyun queue_work(wl->freezable_wq, &wl->netstack_work);
129*4882a593Smuzhiyun wl1271_free_tx_id(wl, id);
130*4882a593Smuzhiyun }
131*4882a593Smuzhiyun
wl18xx_tx_immediate_complete(struct wl1271 * wl)132*4882a593Smuzhiyun void wl18xx_tx_immediate_complete(struct wl1271 *wl)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun struct wl18xx_fw_status_priv *status_priv =
135*4882a593Smuzhiyun (struct wl18xx_fw_status_priv *)wl->fw_status->priv;
136*4882a593Smuzhiyun struct wl18xx_priv *priv = wl->priv;
137*4882a593Smuzhiyun u8 i, hlid;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun /* nothing to do here */
140*4882a593Smuzhiyun if (priv->last_fw_rls_idx == status_priv->fw_release_idx)
141*4882a593Smuzhiyun return;
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun /* update rates per link */
144*4882a593Smuzhiyun hlid = wl->fw_status->counters.hlid;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun if (hlid < WLCORE_MAX_LINKS) {
147*4882a593Smuzhiyun wl->links[hlid].fw_rate_idx =
148*4882a593Smuzhiyun wl->fw_status->counters.tx_last_rate;
149*4882a593Smuzhiyun wl->links[hlid].fw_rate_mbps =
150*4882a593Smuzhiyun wl->fw_status->counters.tx_last_rate_mbps;
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun /* freed Tx descriptors */
154*4882a593Smuzhiyun wl1271_debug(DEBUG_TX, "last released desc = %d, current idx = %d",
155*4882a593Smuzhiyun priv->last_fw_rls_idx, status_priv->fw_release_idx);
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun if (status_priv->fw_release_idx >= WL18XX_FW_MAX_TX_STATUS_DESC) {
158*4882a593Smuzhiyun wl1271_error("invalid desc release index %d",
159*4882a593Smuzhiyun status_priv->fw_release_idx);
160*4882a593Smuzhiyun WARN_ON(1);
161*4882a593Smuzhiyun return;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun for (i = priv->last_fw_rls_idx;
165*4882a593Smuzhiyun i != status_priv->fw_release_idx;
166*4882a593Smuzhiyun i = (i + 1) % WL18XX_FW_MAX_TX_STATUS_DESC) {
167*4882a593Smuzhiyun wl18xx_tx_complete_packet(wl,
168*4882a593Smuzhiyun status_priv->released_tx_desc[i]);
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun wl->tx_results_count++;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun priv->last_fw_rls_idx = status_priv->fw_release_idx;
174*4882a593Smuzhiyun }
175