blob: 56d84027ec2b82622ec0461a88f4045508b23aed [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
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
Holger Schurig9012b282007-05-25 11:27:16 -040076 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020077 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
78 ret = -1;
79 goto done;
80 }
81
82 memset(plocaltxpd, 0, sizeof(struct txpd));
83
David Woodhouse981f1872007-05-25 23:36:54 -040084 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020085
86 /* offset of actual data */
David Woodhouse981f1872007-05-25 23:36:54 -040087 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088
89 /* TxCtrl set by user or default */
David Woodhouse981f1872007-05-25 23:36:54 -040090 plocaltxpd->tx_control = cpu_to_le32(adapter->pkttxctrl);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091
92 p802x_hdr = skb->data;
93 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
94
95 /* locate radiotap header */
96 pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
97
98 /* set txpd fields from the radiotap header */
99 new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
100 if (new_rate != 0) {
David Woodhouse981f1872007-05-25 23:36:54 -0400101 /* use new tx_control[4:0] */
102 new_rate |= (adapter->pkttxctrl & ~0x1f);
103 plocaltxpd->tx_control = cpu_to_le32(new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200104 }
105
106 /* skip the radiotap header */
107 p802x_hdr += sizeof(struct tx_radiotap_hdr);
David Woodhouse981f1872007-05-25 23:36:54 -0400108 plocaltxpd->tx_packet_length =
David Woodhouse86760082007-05-25 23:39:34 -0400109 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
David Woodhouse981f1872007-05-25 23:36:54 -0400110 - sizeof(struct tx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111
112 }
113 /* copy destination address from 802.3 or 802.11 header */
114 if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
115 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
116 else
117 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
118
Holger Schurigece56192007-08-02 11:53:06 -0400119 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120
121 if (IS_MESH_FRAME(skb)) {
David Woodhouse981f1872007-05-25 23:36:54 -0400122 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200123 }
124
125 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
126
127 ptr += sizeof(struct txpd);
128
Holger Schurigece56192007-08-02 11:53:06 -0400129 lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
David Woodhouse86760082007-05-25 23:39:34 -0400130 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
Holger Schurig208fdd22007-05-25 12:17:06 -0400131 ret = priv->hw_host_to_card(priv, MVMS_DAT,
David Woodhouse981f1872007-05-25 23:36:54 -0400132 priv->adapter->tmptxbuf,
David Woodhouse86760082007-05-25 23:39:34 -0400133 le16_to_cpu(plocaltxpd->tx_packet_length) +
David Woodhouse981f1872007-05-25 23:36:54 -0400134 sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200135
136 if (ret) {
Holger Schurig208fdd22007-05-25 12:17:06 -0400137 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138 goto done;
139 }
140
Holger Schurig9012b282007-05-25 11:27:16 -0400141 lbs_deb_tx("SendSinglePacket succeeds\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200142
Holger Schurig9012b282007-05-25 11:27:16 -0400143done:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144 if (!ret) {
145 priv->stats.tx_packets++;
146 priv->stats.tx_bytes += skb->len;
147 } else {
148 priv->stats.tx_dropped++;
149 priv->stats.tx_errors++;
150 }
151
152 if (!ret && priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
153 /* Keep the skb to echo it back once Tx feedback is
154 received from FW */
155 skb_orphan(skb);
156 /* stop processing outgoing pkts */
Holger Schurig634b8f42007-05-25 13:05:16 -0400157 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400158 if (priv->mesh_dev)
159 netif_stop_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 /* freeze any packets already in our queues */
161 priv->adapter->TxLockFlag = 1;
162 } else {
163 dev_kfree_skb_any(skb);
164 priv->adapter->currenttxskb = NULL;
165 }
166
Holger Schurig9012b282007-05-25 11:27:16 -0400167 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168 return ret;
169}
170
171
172void libertas_tx_runqueue(wlan_private *priv)
173{
174 wlan_adapter *adapter = priv->adapter;
175 int i;
176
177 spin_lock(&adapter->txqueue_lock);
178 for (i = 0; i < adapter->tx_queue_idx; i++) {
179 struct sk_buff *skb = adapter->tx_queue_ps[i];
180 spin_unlock(&adapter->txqueue_lock);
181 SendSinglePacket(priv, skb);
182 spin_lock(&adapter->txqueue_lock);
183 }
184 adapter->tx_queue_idx = 0;
185 spin_unlock(&adapter->txqueue_lock);
186}
187
188static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
189{
190 wlan_adapter *adapter = priv->adapter;
191
192 spin_lock(&adapter->txqueue_lock);
193
194 WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
195 adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
Javier Cardona51d84f52007-05-25 12:06:56 -0400196 if (adapter->tx_queue_idx == NR_TX_QUEUE) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400197 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400198 if (priv->mesh_dev)
199 netif_stop_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400200 } else {
Holger Schurig634b8f42007-05-25 13:05:16 -0400201 netif_start_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400202 if (priv->mesh_dev)
203 netif_start_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400204 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200205
206 spin_unlock(&adapter->txqueue_lock);
207}
208
209/**
210 * @brief This function checks the conditions and sends packet to IF
211 * layer if everything is ok.
212 *
213 * @param priv A pointer to wlan_private structure
214 * @return n/a
215 */
216int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
217{
218 int ret = -1;
219
Holger Schurig9012b282007-05-25 11:27:16 -0400220 lbs_deb_enter(LBS_DEB_TX);
Holger Schurigece56192007-08-02 11:53:06 -0400221 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222
Holger Schurig634b8f42007-05-25 13:05:16 -0400223 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
Holger Schurig634b8f42007-05-25 13:05:16 -0400225 priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226 goto done;
227 }
228
229 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
230 (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
231 wlan_tx_queue(priv, skb);
232 return ret;
233 }
234
235 priv->adapter->currenttxskb = skb;
236
237 ret = SendSinglePacket(priv, skb);
238done:
Holger Schurig9012b282007-05-25 11:27:16 -0400239 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240 return ret;
241}
242
243/**
244 * @brief This function sends to the host the last transmitted packet,
245 * filling the radiotap headers with transmission information.
246 *
247 * @param priv A pointer to wlan_private structure
248 * @param status A 32 bit value containing transmission status.
249 *
250 * @returns void
251 */
252void libertas_send_tx_feedback(wlan_private * priv)
253{
254 wlan_adapter *adapter = priv->adapter;
255 struct tx_radiotap_hdr *radiotap_hdr;
256 u32 status = adapter->eventcause;
257 int txfail;
258 int try_count;
259
260 if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP ||
261 adapter->currenttxskb == NULL)
262 return;
263
264 radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
265
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266 txfail = (status >> 24);
267
268#if 0
269 /* The version of roofnet that we've tested does not use this yet
270 * But it may be used in the future.
271 */
272 if (txfail)
273 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
274#endif
275 try_count = (status >> 16) & 0xff;
276 radiotap_hdr->data_retries = (try_count) ?
277 (1 + adapter->txretrycount - try_count) : 0;
278 libertas_upload_rx_packet(priv, adapter->currenttxskb);
279 adapter->currenttxskb = NULL;
280 priv->adapter->TxLockFlag = 0;
Dan Williams0aef64d2007-08-02 11:31:18 -0400281 if (priv->adapter->connect_status == LIBERTAS_CONNECTED) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400282 netif_wake_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400283 if (priv->mesh_dev)
284 netif_wake_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400285 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286}
Holger Schurig084708b2007-05-25 12:37:58 -0400287EXPORT_SYMBOL_GPL(libertas_send_tx_feedback);