blob: e61729f0645a8b4bdfb2da67ddc333978c1507fe [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"
8#include "sbi.h"
9#include "decl.h"
10#include "defs.h"
11#include "dev.h"
12#include "wext.h"
13
14/**
15 * @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
16 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
17 *
18 * @param rate Input rate
19 * @return Output Rate (0 if invalid)
20 */
21static u32 convert_radiotap_rate_to_mv(u8 rate)
22{
23 switch (rate) {
24 case 2: /* 1 Mbps */
25 return 0 | (1 << 4);
26 case 4: /* 2 Mbps */
27 return 1 | (1 << 4);
28 case 11: /* 5.5 Mbps */
29 return 2 | (1 << 4);
30 case 22: /* 11 Mbps */
31 return 3 | (1 << 4);
32 case 12: /* 6 Mbps */
33 return 4 | (1 << 4);
34 case 18: /* 9 Mbps */
35 return 5 | (1 << 4);
36 case 24: /* 12 Mbps */
37 return 6 | (1 << 4);
38 case 36: /* 18 Mbps */
39 return 7 | (1 << 4);
40 case 48: /* 24 Mbps */
41 return 8 | (1 << 4);
42 case 72: /* 36 Mbps */
43 return 9 | (1 << 4);
44 case 96: /* 48 Mbps */
45 return 10 | (1 << 4);
46 case 108: /* 54 Mbps */
47 return 11 | (1 << 4);
48 }
49 return 0;
50}
51
52/**
53 * @brief This function processes a single packet and sends
54 * to IF layer
55 *
56 * @param priv A pointer to wlan_private structure
57 * @param skb A pointer to skb which includes TX packet
58 * @return 0 or -1
59 */
60static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb)
61{
62 wlan_adapter *adapter = priv->adapter;
63 int ret = 0;
64 struct txpd localtxpd;
65 struct txpd *plocaltxpd = &localtxpd;
66 u8 *p802x_hdr;
67 struct tx_radiotap_hdr *pradiotap_hdr;
68 u32 new_rate;
69 u8 *ptr = priv->adapter->tmptxbuf;
70
Holger Schurig9012b282007-05-25 11:27:16 -040071 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072
73 if (priv->adapter->surpriseremoved)
74 return -1;
75
76 if ((priv->adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
77 lbs_dbg_hex("TX packet: ", skb->data,
78 min_t(unsigned int, skb->len, 100));
79
80 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
Holger Schurig9012b282007-05-25 11:27:16 -040081 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020082 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
83 ret = -1;
84 goto done;
85 }
86
87 memset(plocaltxpd, 0, sizeof(struct txpd));
88
89 plocaltxpd->tx_packet_length = skb->len;
90
91 /* offset of actual data */
92 plocaltxpd->tx_packet_location = sizeof(struct txpd);
93
94 /* TxCtrl set by user or default */
95 plocaltxpd->tx_control = adapter->pkttxctrl;
96
97 p802x_hdr = skb->data;
98 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) {
99
100 /* locate radiotap header */
101 pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
102
103 /* set txpd fields from the radiotap header */
104 new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
105 if (new_rate != 0) {
106 /* erase tx_control[4:0] */
107 plocaltxpd->tx_control &= ~0x1f;
108 /* write new tx_control[4:0] */
109 plocaltxpd->tx_control |= new_rate;
110 }
111
112 /* skip the radiotap header */
113 p802x_hdr += sizeof(struct tx_radiotap_hdr);
114 plocaltxpd->tx_packet_length -= sizeof(struct tx_radiotap_hdr);
115
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)) {
126 plocaltxpd->tx_control |= TxPD_MESH_FRAME;
127 }
128
129 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
130
131 ptr += sizeof(struct txpd);
132
133 lbs_dbg_hex("Tx Data", (u8 *) p802x_hdr, plocaltxpd->tx_packet_length);
134 memcpy(ptr, p802x_hdr, plocaltxpd->tx_packet_length);
135 ret = libertas_sbi_host_to_card(priv, MVMS_DAT,
136 priv->adapter->tmptxbuf,
137 plocaltxpd->tx_packet_length +
138 sizeof(struct txpd));
139
140 if (ret) {
Holger Schurig9012b282007-05-25 11:27:16 -0400141 lbs_deb_tx("tx err: libertas_sbi_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 */
161 netif_stop_queue(priv->wlan_dev.netdev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400162 netif_stop_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 /* freeze any packets already in our queues */
164 priv->adapter->TxLockFlag = 1;
165 } else {
166 dev_kfree_skb_any(skb);
167 priv->adapter->currenttxskb = NULL;
168 }
169
Holger Schurig9012b282007-05-25 11:27:16 -0400170 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171 return ret;
172}
173
174
175void libertas_tx_runqueue(wlan_private *priv)
176{
177 wlan_adapter *adapter = priv->adapter;
178 int i;
179
180 spin_lock(&adapter->txqueue_lock);
181 for (i = 0; i < adapter->tx_queue_idx; i++) {
182 struct sk_buff *skb = adapter->tx_queue_ps[i];
183 spin_unlock(&adapter->txqueue_lock);
184 SendSinglePacket(priv, skb);
185 spin_lock(&adapter->txqueue_lock);
186 }
187 adapter->tx_queue_idx = 0;
188 spin_unlock(&adapter->txqueue_lock);
189}
190
191static void wlan_tx_queue(wlan_private *priv, struct sk_buff *skb)
192{
193 wlan_adapter *adapter = priv->adapter;
194
195 spin_lock(&adapter->txqueue_lock);
196
197 WARN_ON(priv->adapter->tx_queue_idx >= NR_TX_QUEUE);
198 adapter->tx_queue_ps[adapter->tx_queue_idx++] = skb;
Javier Cardona51d84f52007-05-25 12:06:56 -0400199 if (adapter->tx_queue_idx == NR_TX_QUEUE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200 netif_stop_queue(priv->wlan_dev.netdev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400201 netif_stop_queue(priv->mesh_dev);
202 } else {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203 netif_start_queue(priv->wlan_dev.netdev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400204 netif_start_queue(priv->mesh_dev);
205 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200206
207 spin_unlock(&adapter->txqueue_lock);
208}
209
210/**
211 * @brief This function checks the conditions and sends packet to IF
212 * layer if everything is ok.
213 *
214 * @param priv A pointer to wlan_private structure
215 * @return n/a
216 */
217int libertas_process_tx(wlan_private * priv, struct sk_buff *skb)
218{
219 int ret = -1;
220
Holger Schurig9012b282007-05-25 11:27:16 -0400221 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222 lbs_dbg_hex("TX Data", skb->data, min_t(unsigned int, skb->len, 100));
223
224 if (priv->wlan_dev.dnld_sent) {
225 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
226 priv->wlan_dev.dnld_sent);
227 goto done;
228 }
229
230 if ((priv->adapter->psstate == PS_STATE_SLEEP) ||
231 (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) {
232 wlan_tx_queue(priv, skb);
233 return ret;
234 }
235
236 priv->adapter->currenttxskb = skb;
237
238 ret = SendSinglePacket(priv, skb);
239done:
Holger Schurig9012b282007-05-25 11:27:16 -0400240 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200241 return ret;
242}
243
244/**
245 * @brief This function sends to the host the last transmitted packet,
246 * filling the radiotap headers with transmission information.
247 *
248 * @param priv A pointer to wlan_private structure
249 * @param status A 32 bit value containing transmission status.
250 *
251 * @returns void
252 */
253void libertas_send_tx_feedback(wlan_private * priv)
254{
255 wlan_adapter *adapter = priv->adapter;
256 struct tx_radiotap_hdr *radiotap_hdr;
257 u32 status = adapter->eventcause;
258 int txfail;
259 int try_count;
260
261 if (adapter->radiomode != WLAN_RADIOMODE_RADIOTAP ||
262 adapter->currenttxskb == NULL)
263 return;
264
265 radiotap_hdr = (struct tx_radiotap_hdr *)adapter->currenttxskb->data;
266
267 if ((adapter->debugmode & MRVDRV_DEBUG_TX_PATH) != 0)
268 lbs_dbg_hex("TX feedback: ", (u8 *) radiotap_hdr,
269 min_t(unsigned int, adapter->currenttxskb->len, 100));
270
271 txfail = (status >> 24);
272
273#if 0
274 /* The version of roofnet that we've tested does not use this yet
275 * But it may be used in the future.
276 */
277 if (txfail)
278 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
279#endif
280 try_count = (status >> 16) & 0xff;
281 radiotap_hdr->data_retries = (try_count) ?
282 (1 + adapter->txretrycount - try_count) : 0;
283 libertas_upload_rx_packet(priv, adapter->currenttxskb);
284 adapter->currenttxskb = NULL;
285 priv->adapter->TxLockFlag = 0;
Javier Cardona51d84f52007-05-25 12:06:56 -0400286 if (priv->adapter->connect_status == libertas_connected) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287 netif_wake_queue(priv->wlan_dev.netdev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400288 netif_wake_queue(priv->mesh_dev);
289 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200290}