blob: 4cb39d33003c8018f1e20e53385a4b8d4f111eb5 [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 *
Holger Schurig69f90322007-11-23 15:43:44 +010055 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020056 * @param skb A pointer to skb which includes TX packet
57 * @return 0 or -1
58 */
Holger Schurig69f90322007-11-23 15:43:44 +010059static int SendSinglePacket(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061 int ret = 0;
62 struct txpd localtxpd;
63 struct txpd *plocaltxpd = &localtxpd;
64 u8 *p802x_hdr;
65 struct tx_radiotap_hdr *pradiotap_hdr;
66 u32 new_rate;
David Woodhouseaa21c002007-12-08 20:04:36 +000067 u8 *ptr = priv->tmptxbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068
Holger Schurig9012b282007-05-25 11:27:16 -040069 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070
David Woodhouseaa21c002007-12-08 20:04:36 +000071 if (priv->surpriseremoved)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072 return -1;
73
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
Holger Schurig9012b282007-05-25 11:27:16 -040075 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
77 ret = -1;
78 goto done;
79 }
80
81 memset(plocaltxpd, 0, sizeof(struct txpd));
82
David Woodhouse981f1872007-05-25 23:36:54 -040083 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020084
85 /* offset of actual data */
David Woodhouse981f1872007-05-25 23:36:54 -040086 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020087
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088 p802x_hdr = skb->data;
David Woodhouseaa21c002007-12-08 20:04:36 +000089 if (priv->monitormode != LBS_MONITOR_OFF) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090
91 /* locate radiotap header */
92 pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
93
94 /* set txpd fields from the radiotap header */
95 new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
96 if (new_rate != 0) {
David Woodhouse981f1872007-05-25 23:36:54 -040097 /* use new tx_control[4:0] */
David Woodhouse981f1872007-05-25 23:36:54 -040098 plocaltxpd->tx_control = cpu_to_le32(new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099 }
100
101 /* skip the radiotap header */
102 p802x_hdr += sizeof(struct tx_radiotap_hdr);
David Woodhouse981f1872007-05-25 23:36:54 -0400103 plocaltxpd->tx_packet_length =
David Woodhouse86760082007-05-25 23:39:34 -0400104 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
David Woodhouse981f1872007-05-25 23:36:54 -0400105 - sizeof(struct tx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200106
107 }
108 /* copy destination address from 802.3 or 802.11 header */
David Woodhouseaa21c002007-12-08 20:04:36 +0000109 if (priv->monitormode != LBS_MONITOR_OFF)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200110 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
111 else
112 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
113
Holger Schurigece56192007-08-02 11:53:06 -0400114 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200115
116 if (IS_MESH_FRAME(skb)) {
David Woodhouse981f1872007-05-25 23:36:54 -0400117 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200118 }
119
120 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
121
122 ptr += sizeof(struct txpd);
123
Holger Schurigece56192007-08-02 11:53:06 -0400124 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 -0400125 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
Holger Schurig208fdd22007-05-25 12:17:06 -0400126 ret = priv->hw_host_to_card(priv, MVMS_DAT,
David Woodhouseaa21c002007-12-08 20:04:36 +0000127 priv->tmptxbuf,
David Woodhouse86760082007-05-25 23:39:34 -0400128 le16_to_cpu(plocaltxpd->tx_packet_length) +
David Woodhouse981f1872007-05-25 23:36:54 -0400129 sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
131 if (ret) {
Holger Schurig208fdd22007-05-25 12:17:06 -0400132 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133 goto done;
134 }
135
Holger Schurig9012b282007-05-25 11:27:16 -0400136 lbs_deb_tx("SendSinglePacket succeeds\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200137
Holger Schurig9012b282007-05-25 11:27:16 -0400138done:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200139 if (!ret) {
140 priv->stats.tx_packets++;
141 priv->stats.tx_bytes += skb->len;
142 } else {
143 priv->stats.tx_dropped++;
144 priv->stats.tx_errors++;
145 }
146
David Woodhouseaa21c002007-12-08 20:04:36 +0000147 if (!ret && priv->monitormode != LBS_MONITOR_OFF) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200148 /* Keep the skb to echo it back once Tx feedback is
149 received from FW */
150 skb_orphan(skb);
151 /* stop processing outgoing pkts */
Holger Schurig634b8f42007-05-25 13:05:16 -0400152 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400153 if (priv->mesh_dev)
154 netif_stop_queue(priv->mesh_dev);
David Woodhousef86a93e2007-12-08 19:46:19 +0000155
156 /* Keep the skb around for when we get feedback */
David Woodhouseaa21c002007-12-08 20:04:36 +0000157 priv->currenttxskb = skb;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200158 } else {
159 dev_kfree_skb_any(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 }
161
Holger Schurig9012b282007-05-25 11:27:16 -0400162 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 return ret;
164}
165
166
Holger Schurig69f90322007-11-23 15:43:44 +0100167void lbs_tx_runqueue(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200168{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200169 int i;
170
David Woodhouseaa21c002007-12-08 20:04:36 +0000171 spin_lock(&priv->txqueue_lock);
172 for (i = 0; i < priv->tx_queue_idx; i++) {
173 struct sk_buff *skb = priv->tx_queue_ps[i];
174 spin_unlock(&priv->txqueue_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 SendSinglePacket(priv, skb);
David Woodhouseaa21c002007-12-08 20:04:36 +0000176 spin_lock(&priv->txqueue_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200177 }
David Woodhouseaa21c002007-12-08 20:04:36 +0000178 priv->tx_queue_idx = 0;
179 spin_unlock(&priv->txqueue_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180}
181
Holger Schurig69f90322007-11-23 15:43:44 +0100182static void lbs_tx_queue(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200184
David Woodhouseaa21c002007-12-08 20:04:36 +0000185 spin_lock(&priv->txqueue_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200186
David Woodhouseaa21c002007-12-08 20:04:36 +0000187 WARN_ON(priv->tx_queue_idx >= NR_TX_QUEUE);
188 priv->tx_queue_ps[priv->tx_queue_idx++] = skb;
189 if (priv->tx_queue_idx == NR_TX_QUEUE) {
Holger Schurig634b8f42007-05-25 13:05:16 -0400190 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400191 if (priv->mesh_dev)
192 netif_stop_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400193 } else {
Holger Schurig634b8f42007-05-25 13:05:16 -0400194 netif_start_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400195 if (priv->mesh_dev)
196 netif_start_queue(priv->mesh_dev);
Javier Cardona51d84f52007-05-25 12:06:56 -0400197 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200198
David Woodhouseaa21c002007-12-08 20:04:36 +0000199 spin_unlock(&priv->txqueue_lock);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200}
201
202/**
203 * @brief This function checks the conditions and sends packet to IF
204 * layer if everything is ok.
205 *
Holger Schurig69f90322007-11-23 15:43:44 +0100206 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200207 * @return n/a
208 */
Holger Schurig69f90322007-11-23 15:43:44 +0100209int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200210{
211 int ret = -1;
212
Holger Schurig9012b282007-05-25 11:27:16 -0400213 lbs_deb_enter(LBS_DEB_TX);
Holger Schurigece56192007-08-02 11:53:06 -0400214 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200215
Holger Schurig634b8f42007-05-25 13:05:16 -0400216 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
Holger Schurig634b8f42007-05-25 13:05:16 -0400218 priv->dnld_sent);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219 goto done;
220 }
221
David Woodhouseaa21c002007-12-08 20:04:36 +0000222 if ((priv->psstate == PS_STATE_SLEEP) ||
223 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig10078322007-11-15 18:05:47 -0500224 lbs_tx_queue(priv, skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200225 return ret;
226 }
227
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200228 ret = SendSinglePacket(priv, skb);
229done:
Holger Schurig9012b282007-05-25 11:27:16 -0400230 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 return ret;
232}
233
234/**
235 * @brief This function sends to the host the last transmitted packet,
236 * filling the radiotap headers with transmission information.
237 *
Holger Schurig69f90322007-11-23 15:43:44 +0100238 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239 * @param status A 32 bit value containing transmission status.
240 *
241 * @returns void
242 */
Holger Schurig69f90322007-11-23 15:43:44 +0100243void lbs_send_tx_feedback(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200245 struct tx_radiotap_hdr *radiotap_hdr;
David Woodhouseaa21c002007-12-08 20:04:36 +0000246 u32 status = priv->eventcause;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200247 int txfail;
248 int try_count;
249
David Woodhouseaa21c002007-12-08 20:04:36 +0000250 if (priv->monitormode == LBS_MONITOR_OFF ||
251 priv->currenttxskb == NULL)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200252 return;
253
David Woodhouseaa21c002007-12-08 20:04:36 +0000254 radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200255
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256 txfail = (status >> 24);
257
258#if 0
259 /* The version of roofnet that we've tested does not use this yet
260 * But it may be used in the future.
261 */
262 if (txfail)
263 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
264#endif
265 try_count = (status >> 16) & 0xff;
266 radiotap_hdr->data_retries = (try_count) ?
David Woodhouseaa21c002007-12-08 20:04:36 +0000267 (1 + priv->txretrycount - try_count) : 0;
268 lbs_upload_rx_packet(priv, priv->currenttxskb);
269 priv->currenttxskb = NULL;
Brajesh Dave01d77d82007-11-20 17:44:14 -0500270
David Woodhouseaa21c002007-12-08 20:04:36 +0000271 if (priv->connect_status == LBS_CONNECTED)
Holger Schurig634b8f42007-05-25 13:05:16 -0400272 netif_wake_queue(priv->dev);
Brajesh Dave01d77d82007-11-20 17:44:14 -0500273
David Woodhouseaa21c002007-12-08 20:04:36 +0000274 if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
Brajesh Dave01d77d82007-11-20 17:44:14 -0500275 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200276}
Holger Schurig10078322007-11-15 18:05:47 -0500277EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);