tx.c 6.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
  * This file contains the handling of TX in wlan driver.
  */
#include <linux/netdevice.h>

#include "hostcmd.h"
#include "radiotap.h"
#include "decl.h"
#include "defs.h"
#include "dev.h"
#include "wext.h"

/**
 *  @brief This function converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
 *  units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
 *
 *  @param rate    Input rate
 *  @return      Output Rate (0 if invalid)
 */
static u32 convert_radiotap_rate_to_mv(u8 rate)
{
	switch (rate) {
	case 2:		/*   1 Mbps */
		return 0 | (1 << 4);
	case 4:		/*   2 Mbps */
		return 1 | (1 << 4);
	case 11:		/* 5.5 Mbps */
		return 2 | (1 << 4);
	case 22:		/*  11 Mbps */
		return 3 | (1 << 4);
	case 12:		/*   6 Mbps */
		return 4 | (1 << 4);
	case 18:		/*   9 Mbps */
		return 5 | (1 << 4);
	case 24:		/*  12 Mbps */
		return 6 | (1 << 4);
	case 36:		/*  18 Mbps */
		return 7 | (1 << 4);
	case 48:		/*  24 Mbps */
		return 8 | (1 << 4);
	case 72:		/*  36 Mbps */
		return 9 | (1 << 4);
	case 96:		/*  48 Mbps */
		return 10 | (1 << 4);
	case 108:		/*  54 Mbps */
		return 11 | (1 << 4);
	}
	return 0;
}

/**
 *  @brief This function processes a single packet and sends
 *  to IF layer
 *
55
 *  @param priv    A pointer to struct lbs_private structure
56 57 58
 *  @param skb     A pointer to skb which includes TX packet
 *  @return 	   0 or -1
 */
59
static int SendSinglePacket(struct lbs_private *priv, struct sk_buff *skb)
60 61 62 63 64 65 66
{
	int ret = 0;
	struct txpd localtxpd;
	struct txpd *plocaltxpd = &localtxpd;
	u8 *p802x_hdr;
	struct tx_radiotap_hdr *pradiotap_hdr;
	u32 new_rate;
67
	u8 *ptr = priv->tmptxbuf;
68

69
	lbs_deb_enter(LBS_DEB_TX);
70

71
	if (priv->surpriseremoved)
72 73 74
		return -1;

	if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
75
		lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
76 77 78 79 80 81 82
		       skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
		ret = -1;
		goto done;
	}

	memset(plocaltxpd, 0, sizeof(struct txpd));

83
	plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
84 85

	/* offset of actual data */
86
	plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
87 88

	p802x_hdr = skb->data;
89
	if (priv->monitormode != LBS_MONITOR_OFF) {
90 91 92 93 94 95 96

		/* locate radiotap header */
		pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;

		/* set txpd fields from the radiotap header */
		new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
		if (new_rate != 0) {
97 98
			/* use new tx_control[4:0] */
			plocaltxpd->tx_control = cpu_to_le32(new_rate);
99 100 101 102
		}

		/* skip the radiotap header */
		p802x_hdr += sizeof(struct tx_radiotap_hdr);
103
		plocaltxpd->tx_packet_length =
104
			cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
105
				    - sizeof(struct tx_radiotap_hdr));
106 107 108

	}
	/* copy destination address from 802.3 or 802.11 header */
109
	if (priv->monitormode != LBS_MONITOR_OFF)
110 111 112 113
		memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
	else
		memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);

114
	lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
115 116

	if (IS_MESH_FRAME(skb)) {
117
		plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
118 119 120 121 122 123
	}

	memcpy(ptr, plocaltxpd, sizeof(struct txpd));

	ptr += sizeof(struct txpd);

124
	lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
125
	memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
126
	ret = priv->hw_host_to_card(priv, MVMS_DAT,
127
				    priv->tmptxbuf,
128
				    le16_to_cpu(plocaltxpd->tx_packet_length) +
129
				    sizeof(struct txpd));
130 131

	if (ret) {
132
		lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
133 134 135
		goto done;
	}

136
	lbs_deb_tx("SendSinglePacket succeeds\n");
137

138
done:
139 140 141 142 143 144 145 146
	if (!ret) {
		priv->stats.tx_packets++;
		priv->stats.tx_bytes += skb->len;
	} else {
		priv->stats.tx_dropped++;
		priv->stats.tx_errors++;
	}

147
	if (!ret && priv->monitormode != LBS_MONITOR_OFF) {
148 149 150 151
		/* Keep the skb to echo it back once Tx feedback is
		   received from FW */
		skb_orphan(skb);
		/* stop processing outgoing pkts */
152
		netif_stop_queue(priv->dev);
153 154
		if (priv->mesh_dev)
			netif_stop_queue(priv->mesh_dev);
D
David Woodhouse 已提交
155 156

		/* Keep the skb around for when we get feedback */
157
		priv->currenttxskb = skb;
158 159 160 161
	} else {
		dev_kfree_skb_any(skb);
	}

162
	lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
163 164 165 166
	return ret;
}


167
void lbs_tx_runqueue(struct lbs_private *priv)
168 169 170
{
	int i;

171 172 173 174
	spin_lock(&priv->txqueue_lock);
	for (i = 0; i < priv->tx_queue_idx; i++) {
		struct sk_buff *skb = priv->tx_queue_ps[i];
		spin_unlock(&priv->txqueue_lock);
175
		SendSinglePacket(priv, skb);
176
		spin_lock(&priv->txqueue_lock);
177
	}
178 179
	priv->tx_queue_idx = 0;
	spin_unlock(&priv->txqueue_lock);
180 181
}

182
static void lbs_tx_queue(struct lbs_private *priv, struct sk_buff *skb)
183 184
{

185
	spin_lock(&priv->txqueue_lock);
186

187 188 189
	WARN_ON(priv->tx_queue_idx >= NR_TX_QUEUE);
	priv->tx_queue_ps[priv->tx_queue_idx++] = skb;
	if (priv->tx_queue_idx == NR_TX_QUEUE) {
190
		netif_stop_queue(priv->dev);
191 192
		if (priv->mesh_dev)
			netif_stop_queue(priv->mesh_dev);
193
	} else {
194
		netif_start_queue(priv->dev);
195 196
		if (priv->mesh_dev)
			netif_start_queue(priv->mesh_dev);
197
	}
198

199
	spin_unlock(&priv->txqueue_lock);
200 201 202 203 204 205
}

/**
 *  @brief This function checks the conditions and sends packet to IF
 *  layer if everything is ok.
 *
206
 *  @param priv    A pointer to struct lbs_private structure
207 208
 *  @return 	   n/a
 */
209
int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
210 211 212
{
	int ret = -1;

213
	lbs_deb_enter(LBS_DEB_TX);
214
	lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
215

216
	if (priv->dnld_sent) {
217
		lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
218
		       priv->dnld_sent);
219 220 221
		goto done;
	}

222 223
	if ((priv->psstate == PS_STATE_SLEEP) ||
	    (priv->psstate == PS_STATE_PRE_SLEEP)) {
224
		lbs_tx_queue(priv, skb);
225 226 227 228 229
		return ret;
	}

	ret = SendSinglePacket(priv, skb);
done:
230
	lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
231 232 233 234 235 236 237
	return ret;
}

/**
 *  @brief This function sends to the host the last transmitted packet,
 *  filling the radiotap headers with transmission information.
 *
238
 *  @param priv     A pointer to struct lbs_private structure
239 240 241 242
 *  @param status   A 32 bit value containing transmission status.
 *
 *  @returns void
 */
243
void lbs_send_tx_feedback(struct lbs_private *priv)
244 245
{
	struct tx_radiotap_hdr *radiotap_hdr;
246
	u32 status = priv->eventcause;
247 248 249
	int txfail;
	int try_count;

250 251
	if (priv->monitormode == LBS_MONITOR_OFF ||
	    priv->currenttxskb == NULL)
252 253
		return;

254
	radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
255 256 257 258 259 260 261 262 263 264 265 266

	txfail = (status >> 24);

#if 0
	/* The version of roofnet that we've tested does not use this yet
	 * But it may be used in the future.
	 */
	if (txfail)
		radiotap_hdr->flags &= IEEE80211_RADIOTAP_F_TX_FAIL;
#endif
	try_count = (status >> 16) & 0xff;
	radiotap_hdr->data_retries = (try_count) ?
267 268 269
	    (1 + priv->txretrycount - try_count) : 0;
	lbs_upload_rx_packet(priv, priv->currenttxskb);
	priv->currenttxskb = NULL;
270

271
	if (priv->connect_status == LBS_CONNECTED)
272
		netif_wake_queue(priv->dev);
273

274
	if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
275
		netif_wake_queue(priv->mesh_dev);
276
}
277
EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);