blob: 7c383014a274e5a290a46494a6a7d022cc33b495 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the handling of TX in wlan driver.
3 */
4#include <linux/netdevice.h>
5
6#include "hostcmd.h"
7#include "radiotap.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02008#include "decl.h"
9#include "defs.h"
10#include "dev.h"
11#include "wext.h"
12
13/**
14 * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
15 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
16 *
17 * @param rate Input rate
18 * @return Output Rate (0 if invalid)
19 */
20static u32 convert_radiotap_rate_to_mv(u8 rate)
21{
22 switch (rate) {
23 case 2: /* 1 Mbps */
24 return 0 | (1 << 4);
25 case 4: /* 2 Mbps */
26 return 1 | (1 << 4);
27 case 11: /* 5.5 Mbps */
28 return 2 | (1 << 4);
29 case 22: /* 11 Mbps */
30 return 3 | (1 << 4);
31 case 12: /* 6 Mbps */
32 return 4 | (1 << 4);
33 case 18: /* 9 Mbps */
34 return 5 | (1 << 4);
35 case 24: /* 12 Mbps */
36 return 6 | (1 << 4);
37 case 36: /* 18 Mbps */
38 return 7 | (1 << 4);
39 case 48: /* 24 Mbps */
40 return 8 | (1 << 4);
41 case 72: /* 36 Mbps */
42 return 9 | (1 << 4);
43 case 96: /* 48 Mbps */
44 return 10 | (1 << 4);
45 case 108: /* 54 Mbps */
46 return 11 | (1 << 4);
47 }
48 return 0;
49}
50
51/**
52 * @brief This function processes a single packet and sends
53 * to IF layer
54 *
55 * @param priv A pointer to wlan_private structure
56 * @param skb A pointer to skb which includes TX packet
57 * @return 0 or -1
58 */
59static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb)
60{
61 wlan_adapter *adapter = priv->adapter;
62 int ret = 0;
63 struct txpd localtxpd;
64 struct txpd *plocaltxpd = &localtxpd;
65 u8 *p802x_hdr;
66 struct tx_radiotap_hdr *pradiotap_hdr;
67 u32 new_rate;
68 u8 *ptr = priv->adapter->tmptxbuf;
69
Holger Schurig9012b282007-05-25 11:27:16 -040070 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020071
72 if (priv->adapter->surpriseremoved)
73 return -1;
74
75 if ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
76 lbs_dbg_hex("TX packet: ", skb->data,
77 min_t(unsigned int, skb->len, 100));
78
79 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
Holger Schurig9012b282007-05-25 11:27:16 -040080 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020081 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
82 ret = -1;
83 goto done;
84 }
85
86 memset(plocaltxpd, 0, sizeof(struct txpd));
87
David Woodhouse981f1872007-05-25 23:36:54 -040088 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089
90 /* offset of actual data */
David Woodhouse981f1872007-05-25 23:36:54 -040091 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092
93 /* TxCtrl set by user or default */
David Woodhouse981f1872007-05-25 23:36:54 -040094 plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095
96 p802x_hdr = skb->data;
97 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
98
99 /* locate radiotap header */
100 pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
101
102 /* set txpd fields from the radiotap header */
103 new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
104 if (new_rate != 0) {
David Woodhouse981f1872007-05-25 23:36:54 -0400105 /* use new tx_control[4:0] */
106 new_rate |= (adapter->pkttxctrl & ~0x1f);
107 plocaltxpd->tx_control = cpu_to_le32(new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108 }
109
110 /* skip the radiotap header */
111 p802x_hdr += sizeof(struct tx_radiotap_hdr);
David Woodhouse981f1872007-05-25 23:36:54 -0400112 plocaltxpd->tx_packet_length =
David Woodhouse86760082007-05-25 23:39:34 -0400113 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
David Woodhouse981f1872007-05-25 23:36:54 -0400114 - sizeof(struct tx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
116 }
117 /* copy destination address from 802.3 or 802.11 header */
118 if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
119 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
120 else
121 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
122
123 lbs_dbg_hex("txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
124
125 if (IS_MESH_FRAME(skb)) {
David Woodhouse981f1872007-05-25 23:36:54 -0400126 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 }
128
129 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
130
131 ptr += sizeof(struct txpd);
132
David Woodhouse86760082007-05-25 23:39:34 -0400133 lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
134 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
Holger Schurig208fdd22007-05-25 12:17:06 -0400135 ret = priv->hw_host_to_card(priv, MVMS_DAT,
David Woodhouse981f1872007-05-25 23:36:54 -0400136 priv->adapter->tmptxbuf,
David Woodhouse86760082007-05-25 23:39:34 -0400137 le16_to_cpu(plocaltxpd->tx_packet_length) +
David Woodhouse981f1872007-05-25 23:36:54 -0400138 sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139
140 if (ret) {
Holger Schurig208fdd22007-05-25 12:17:06 -0400141 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142 goto done;
143 }
144
Holger Schurig9012b282007-05-25 11:27:16 -0400145 lbs_deb_tx("SendSinglePacket succeeds\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146
Holger Schurig9012b282007-05-25 11:27:16 -0400147done:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148 if (!ret) {
149 priv->stats.tx_packets++;
150 priv->stats.tx_bytes += skb->len;
151 } else {
152 priv->stats.tx_dropped++;
153 priv->stats.tx_errors++;
154 }
155
156 if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
157 /* Keep the skb to echo it back once Tx feedback is
158 received from FW */
159 skb_orphan(skb);
160 /* stop processing outgoing pkts */
Holger Schurig634b8f42007-05-25 13:05:16 -0400161 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400162 if (priv->mesh_dev)
163 netif_stop_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200164 /* freeze any packets already in our queues */
165 priv->adapter->TxLockFlag = 1;
166 } else {
167 dev_kfree_skb_any(skb);
168 priv->adapter->currenttxskb = NULL;
169 }
170
Holger Schurig9012b282007-05-25 11:27:16 -0400171 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200172 return ret;
173}
174
175
176void libertas_tx_runqueue(wlan_private *priv)
177{
178 wlan_adapter *adapter = priv->adapter;
179 int i;
180
181 spin_lock(&adapter->txqueue_lock);
182 for (i = 0; i < adapter->tx_queue_idx; i++) {
183 struct sk_buff *skb = adapter->tx_queue_ps[i];
184 spin_unlock(&adapter->txqueue_lock);
185 SendSinglePacket(priv, skb);
186 spin_lock(&adapter->txqueue_lock);
187 }
188 adapter->tx_queue_idx = 0;
189 spin_unlock(&adapter->txqueue_lock);
190}
191
192static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
193{
194 wlan_adapter *adapter = priv->adapter;
195
196 spin_lock(&adapter->txqueue_lock);
197
198 WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
199 adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
Javier Cardona51d84f52007-05-25 12:06:56 -0400200 if (adapter->tx_queue_idx == NR_TX_QUEUE) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400201 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400202 if (priv->mesh_dev)
203 netif_stop_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400204 } else {
Holger Schurig634b8f42007-05-25 13:05:16 -0400205 netif_start_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400206 if (priv->mesh_dev)
207 netif_start_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400208 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209
210 spin_unlock(&adapter->txqueue_lock);
211}
212
213/**
214 * @brief This function checks the conditions and sends packet to IF
215 * layer if everything is ok.
216 *
217 * @param priv A pointer to wlan_private structure
218 * @return n/a
219 */
220int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
221{
222 int ret = -1;
223
Holger Schurig9012b282007-05-25 11:27:16 -0400224 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225 lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100));
226
Holger Schurig634b8f42007-05-25 13:05:16 -0400227 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
Holger Schurig634b8f42007-05-25 13:05:16 -0400229 priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200230 goto done;
231 }
232
233 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
234 (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
235 wlan_tx_queue(priv, skb);
236 return ret;
237 }
238
239 priv->adapter->currenttxskb = skb;
240
241 ret = SendSinglePacket(priv, skb);
242done:
Holger Schurig9012b282007-05-25 11:27:16 -0400243 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 return ret;
245}
246
247/**
248 * @brief This function sends to the host the last transmitted packet,
249 * filling the radiotap headers with transmission information.
250 *
251 * @param priv A pointer to wlan_private structure
252 * @param status A 32 bit value containing transmission status.
253 *
254 * @returns void
255 */
256void libertas_send_tx_feedback(wlan_private * priv)
257{
258 wlan_adapter *adapter = priv->adapter;
259 struct tx_radiotap_hdr *radiotap_hdr;
260 u32 status = adapter->eventcause;
261 int txfail;
262 int try_count;
263
264 if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP ||
265 adapter->currenttxskb == NULL)
266 return;
267
268 radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
269
270 if ((adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
271 lbs_dbg_hex("TX feedback: ", (u8 *) radiotap_hdr,
272 min_t(unsigned int, adapter->currenttxskb->len, 100));
273
274 txfail = (status >> 24);
275
276#if 0
277 /* The version of roofnet that we've tested does not use this yet
278 * But it may be used in the future.
279 */
280 if (txfail)
281 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
282#endif
283 try_count = (status >> 16) & 0xff;
284 radiotap_hdr->data_retries = (try_count) ?
285 (1 + adapter->txretrycount - try_count) : 0;
286 libertas_upload_rx_packet(priv, adapter->currenttxskb);
287 adapter->currenttxskb = NULL;
288 priv->adapter->TxLockFlag = 0;
Dan Williams0aef64d2007-08-02 11:31:18 -0400289 if (priv->adapter->connect_status == LIBERTAS_CONNECTED) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400290 netif_wake_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400291 if (priv->mesh_dev)
292 netif_wake_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400293 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200294}
Holger Schurig084708b2007-05-25 12:37:58 -0400295EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);