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