blob: 10596f3bb59a4cc76cc74cad5930ef2bf24eba7c [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/**
David Woodhouse6b4a7e02007-12-09 12:48:10 -050052 * @brief This function checks the conditions and sends packet to IF
53 * layer if everything is ok.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054 *
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 */
David Woodhouse6b4a7e02007-12-09 12:48:10 -050059int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020060{
David Woodhouse6b4a7e02007-12-09 12:48:10 -050061 int ret = -1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020062 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 Woodhouse6b4a7e02007-12-09 12:48:10 -050071 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
72
73 if (priv->dnld_sent) {
74 lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
75 priv->dnld_sent);
76 goto done;
77 }
78
79 if ((priv->psstate == PS_STATE_SLEEP) ||
80 (priv->psstate == PS_STATE_PRE_SLEEP)) {
81 lbs_pr_alert("TX error: packet xmit in %ssleep mode\n",
82 priv->psstate == PS_STATE_SLEEP?"":"pre-");
83 goto done;
84 }
85
David Woodhouseaa21c002007-12-08 20:04:36 +000086 if (priv->surpriseremoved)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020087 return -1;
88
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020089 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
Holger Schurig9012b282007-05-25 11:27:16 -040090 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
David Woodhouse6b4a7e02007-12-09 12:48:10 -050092 goto done_tx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093 }
94
David Woodhouse6b4a7e02007-12-09 12:48:10 -050095 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020096 memset(plocaltxpd, 0, sizeof(struct txpd));
97
David Woodhouse981f1872007-05-25 23:36:54 -040098 plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099
100 /* offset of actual data */
David Woodhouse981f1872007-05-25 23:36:54 -0400101 plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200102
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200103 p802x_hdr = skb->data;
David Woodhouseaa21c002007-12-08 20:04:36 +0000104 if (priv->monitormode != LBS_MONITOR_OFF) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200105
106 /* locate radiotap header */
107 pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
108
109 /* set txpd fields from the radiotap header */
110 new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
111 if (new_rate != 0) {
David Woodhouse981f1872007-05-25 23:36:54 -0400112 /* use new tx_control[4:0] */
David Woodhouse981f1872007-05-25 23:36:54 -0400113 plocaltxpd->tx_control = cpu_to_le32(new_rate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114 }
115
116 /* skip the radiotap header */
117 p802x_hdr += sizeof(struct tx_radiotap_hdr);
David Woodhouse981f1872007-05-25 23:36:54 -0400118 plocaltxpd->tx_packet_length =
David Woodhouse86760082007-05-25 23:39:34 -0400119 cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
David Woodhouse981f1872007-05-25 23:36:54 -0400120 - sizeof(struct tx_radiotap_hdr));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200121
122 }
123 /* copy destination address from 802.3 or 802.11 header */
David Woodhouseaa21c002007-12-08 20:04:36 +0000124 if (priv->monitormode != LBS_MONITOR_OFF)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200125 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
126 else
127 memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
128
Holger Schurigece56192007-08-02 11:53:06 -0400129 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130
131 if (IS_MESH_FRAME(skb)) {
David Woodhouse981f1872007-05-25 23:36:54 -0400132 plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200133 }
134
135 memcpy(ptr, plocaltxpd, sizeof(struct txpd));
136
137 ptr += sizeof(struct txpd);
138
Holger Schurigece56192007-08-02 11:53:06 -0400139 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 -0400140 memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
Holger Schurig208fdd22007-05-25 12:17:06 -0400141 ret = priv->hw_host_to_card(priv, MVMS_DAT,
David Woodhouseaa21c002007-12-08 20:04:36 +0000142 priv->tmptxbuf,
David Woodhouse86760082007-05-25 23:39:34 -0400143 le16_to_cpu(plocaltxpd->tx_packet_length) +
David Woodhouse981f1872007-05-25 23:36:54 -0400144 sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200145
146 if (ret) {
Holger Schurig208fdd22007-05-25 12:17:06 -0400147 lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
David Woodhouse6b4a7e02007-12-09 12:48:10 -0500148 goto done_tx;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200149 }
150
David Woodhouse6b4a7e02007-12-09 12:48:10 -0500151 lbs_deb_tx("%s succeeds\n", __func__);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200152
David Woodhouse6b4a7e02007-12-09 12:48:10 -0500153done_tx:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200154 if (!ret) {
155 priv->stats.tx_packets++;
156 priv->stats.tx_bytes += skb->len;
157 } else {
158 priv->stats.tx_dropped++;
159 priv->stats.tx_errors++;
160 }
161
David Woodhouseaa21c002007-12-08 20:04:36 +0000162 if (!ret && priv->monitormode != LBS_MONITOR_OFF) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200163 /* Keep the skb to echo it back once Tx feedback is
164 received from FW */
165 skb_orphan(skb);
166 /* stop processing outgoing pkts */
Holger Schurig634b8f42007-05-25 13:05:16 -0400167 netif_stop_queue(priv->dev);
Holger Schurig3cf84092007-08-02 11:50:12 -0400168 if (priv->mesh_dev)
169 netif_stop_queue(priv->mesh_dev);
David Woodhousef86a93e2007-12-08 19:46:19 +0000170
171 /* Keep the skb around for when we get feedback */
David Woodhouseaa21c002007-12-08 20:04:36 +0000172 priv->currenttxskb = skb;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200173 } else {
174 dev_kfree_skb_any(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200175 }
176
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200177done:
Holger Schurig9012b282007-05-25 11:27:16 -0400178 lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179 return ret;
180}
181
182/**
183 * @brief This function sends to the host the last transmitted packet,
184 * filling the radiotap headers with transmission information.
185 *
Holger Schurig69f90322007-11-23 15:43:44 +0100186 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200187 * @param status A 32 bit value containing transmission status.
188 *
189 * @returns void
190 */
Holger Schurig69f90322007-11-23 15:43:44 +0100191void lbs_send_tx_feedback(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200192{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200193 struct tx_radiotap_hdr *radiotap_hdr;
David Woodhouseaa21c002007-12-08 20:04:36 +0000194 u32 status = priv->eventcause;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200195 int txfail;
196 int try_count;
197
David Woodhouseaa21c002007-12-08 20:04:36 +0000198 if (priv->monitormode == LBS_MONITOR_OFF ||
199 priv->currenttxskb == NULL)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200 return;
201
David Woodhouseaa21c002007-12-08 20:04:36 +0000202 radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200203
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 txfail = (status >> 24);
205
206#if 0
207 /* The version of roofnet that we've tested does not use this yet
208 * But it may be used in the future.
209 */
210 if (txfail)
211 radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
212#endif
213 try_count = (status >> 16) & 0xff;
214 radiotap_hdr->data_retries = (try_count) ?
David Woodhouseaa21c002007-12-08 20:04:36 +0000215 (1 + priv->txretrycount - try_count) : 0;
216 lbs_upload_rx_packet(priv, priv->currenttxskb);
217 priv->currenttxskb = NULL;
Brajesh Dave01d77d82007-11-20 17:44:14 -0500218
David Woodhouseaa21c002007-12-08 20:04:36 +0000219 if (priv->connect_status == LBS_CONNECTED)
Holger Schurig634b8f42007-05-25 13:05:16 -0400220 netif_wake_queue(priv->dev);
Brajesh Dave01d77d82007-11-20 17:44:14 -0500221
David Woodhouseaa21c002007-12-08 20:04:36 +0000222 if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
Brajesh Dave01d77d82007-11-20 17:44:14 -0500223 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224}
Holger Schurig10078322007-11-15 18:05:47 -0500225EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);