blob: f19495b178f6ab84dca50e1c29f5b67bcc3b2722 [file] [log] [blame]
Randy Dunlap8973a6e2011-04-26 15:25:29 -07001/*
2 * This file contains the handling of TX in wlan driver.
3 */
Alexey Dobriyana6b7a402011-06-06 10:43:46 +00004#include <linux/hardirq.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02005#include <linux/netdevice.h>
David Woodhouse6f93a8e2007-12-10 00:49:26 -05006#include <linux/etherdevice.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +04007#include <linux/sched.h>
Kiran Divekare86dc1c2010-06-14 22:01:26 +05308#include <net/cfg80211.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009
Holger Schurig9e66e702009-10-16 17:32:16 +020010#include "host.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011#include "radiotap.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012#include "decl.h"
13#include "defs.h"
14#include "dev.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015
16/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -070017 * convert_radiotap_rate_to_mv - converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
18 * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020019 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -070020 * @rate: Input rate
21 * returns: Output Rate (0 if invalid)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022 */
23static u32 convert_radiotap_rate_to_mv(u8 rate)
24{
25 switch (rate) {
26 case 2: /* 1 Mbps */
27 return 0 | (1 << 4);
28 case 4: /* 2 Mbps */
29 return 1 | (1 << 4);
30 case 11: /* 5.5 Mbps */
31 return 2 | (1 << 4);
32 case 22: /* 11 Mbps */
33 return 3 | (1 << 4);
34 case 12: /* 6 Mbps */
35 return 4 | (1 << 4);
36 case 18: /* 9 Mbps */
37 return 5 | (1 << 4);
38 case 24: /* 12 Mbps */
39 return 6 | (1 << 4);
40 case 36: /* 18 Mbps */
41 return 7 | (1 << 4);
42 case 48: /* 24 Mbps */
43 return 8 | (1 << 4);
44 case 72: /* 36 Mbps */
45 return 9 | (1 << 4);
46 case 96: /* 48 Mbps */
47 return 10 | (1 << 4);
48 case 108: /* 54 Mbps */
49 return 11 | (1 << 4);
50 }
51 return 0;
52}
53
54/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -070055 * lbs_hard_start_xmit - checks the conditions and sends packet to IF
56 * layer if everything is ok
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020057 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -070058 * @skb: A pointer to skb which includes TX packet
59 * @dev: A pointer to the &struct net_device
60 * returns: 0 or -1
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020061 */
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000062netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063{
David Woodhousea2b62dc2007-12-09 14:37:59 -050064 unsigned long flags;
Kiran Divekarab65f642009-02-19 19:32:39 -050065 struct lbs_private *priv = dev->ml_priv;
David Woodhousea2b62dc2007-12-09 14:37:59 -050066 struct txpd *txpd;
67 char *p802x_hdr;
68 uint16_t pkt_len;
Stephen Hemmingerd0cf9c02009-08-31 19:50:57 +000069 netdev_tx_t ret = NETDEV_TX_OK;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020070
Holger Schurig9012b282007-05-25 11:27:16 -040071 lbs_deb_enter(LBS_DEB_TX);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020072
David Woodhouse2eb188a2007-12-09 23:54:27 -050073 /* We need to protect against the queues being restarted before
74 we get round to stopping them */
75 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse6b4a7e02007-12-09 12:48:10 -050076
David Woodhouseaa21c002007-12-08 20:04:36 +000077 if (priv->surpriseremoved)
David Woodhouse2eb188a2007-12-09 23:54:27 -050078 goto free;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020079
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020080 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);
David Woodhousea2b62dc2007-12-09 14:37:59 -050083 /* We'll never manage to send this one; drop it and return 'OK' */
David Woodhouse2eb188a2007-12-09 23:54:27 -050084
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +000085 dev->stats.tx_dropped++;
86 dev->stats.tx_errors++;
David Woodhouse2eb188a2007-12-09 23:54:27 -050087 goto free;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020088 }
89
David Woodhouse2eb188a2007-12-09 23:54:27 -050090
91 netif_stop_queue(priv->dev);
92 if (priv->mesh_dev)
93 netif_stop_queue(priv->mesh_dev);
94
95 if (priv->tx_pending_len) {
David Woodhouse7e226272007-12-14 22:53:41 -050096 /* This can happen if packets come in on the mesh and eth
97 device simultaneously -- there's no mutual exclusion on
David Woodhouse2eb188a2007-12-09 23:54:27 -050098 hard_start_xmit() calls between devices. */
99 lbs_deb_tx("Packet on %s while busy\n", dev->name);
100 ret = NETDEV_TX_BUSY;
101 goto unlock;
102 }
103
104 priv->tx_pending_len = -1;
105 spin_unlock_irqrestore(&priv->driver_lock, flags);
106
David Woodhousea2b62dc2007-12-09 14:37:59 -0500107 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200108
David Woodhouse2eb188a2007-12-09 23:54:27 -0500109 txpd = (void *)priv->tx_pending_buf;
David Woodhousea2b62dc2007-12-09 14:37:59 -0500110 memset(txpd, 0, sizeof(struct txpd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200111
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200112 p802x_hdr = skb->data;
David Woodhousea2b62dc2007-12-09 14:37:59 -0500113 pkt_len = skb->len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200114
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530115 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
David Woodhousea2b62dc2007-12-09 14:37:59 -0500116 struct tx_radiotap_hdr *rtap_hdr = (void *)skb->data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117
118 /* set txpd fields from the radiotap header */
David Woodhousea2b62dc2007-12-09 14:37:59 -0500119 txpd->tx_control = cpu_to_le32(convert_radiotap_rate_to_mv(rtap_hdr->rate));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200120
121 /* skip the radiotap header */
David Woodhousea2b62dc2007-12-09 14:37:59 -0500122 p802x_hdr += sizeof(*rtap_hdr);
123 pkt_len -= sizeof(*rtap_hdr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124
David Woodhousea2b62dc2007-12-09 14:37:59 -0500125 /* copy destination address from 802.11 header */
126 memcpy(txpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200127 } else {
David Woodhousea2b62dc2007-12-09 14:37:59 -0500128 /* copy destination address from 802.3 header */
129 memcpy(txpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200130 }
131
David Woodhousea2b62dc2007-12-09 14:37:59 -0500132 txpd->tx_packet_length = cpu_to_le16(pkt_len);
133 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
134
Holger Schurige0e42da2009-11-25 13:10:15 +0100135 lbs_mesh_set_txpd(priv, dev, txpd);
David Woodhousea2b62dc2007-12-09 14:37:59 -0500136
137 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd));
138
139 lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(txpd->tx_packet_length));
140
141 memcpy(&txpd[1], p802x_hdr, le16_to_cpu(txpd->tx_packet_length));
142
David Woodhousea2b62dc2007-12-09 14:37:59 -0500143 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouse2eb188a2007-12-09 23:54:27 -0500144 priv->tx_pending_len = pkt_len + sizeof(struct txpd);
David Woodhousea2b62dc2007-12-09 14:37:59 -0500145
David Woodhouse2eb188a2007-12-09 23:54:27 -0500146 lbs_deb_tx("%s lined up packet\n", __func__);
David Woodhousea2b62dc2007-12-09 14:37:59 -0500147
Stephen Hemmingerbbfc6b72009-03-20 19:36:36 +0000148 dev->stats.tx_packets++;
149 dev->stats.tx_bytes += skb->len;
David Woodhousea2b62dc2007-12-09 14:37:59 -0500150
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530151 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
David Woodhouse2eb188a2007-12-09 23:54:27 -0500152 /* Keep the skb to echo it back once Tx feedback is
153 received from FW */
154 skb_orphan(skb);
David Woodhousea2b62dc2007-12-09 14:37:59 -0500155
David Woodhouse2eb188a2007-12-09 23:54:27 -0500156 /* Keep the skb around for when we get feedback */
157 priv->currenttxskb = skb;
158 } else {
159 free:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160 dev_kfree_skb_any(skb);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200161 }
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530162
David Woodhouse2eb188a2007-12-09 23:54:27 -0500163 unlock:
164 spin_unlock_irqrestore(&priv->driver_lock, flags);
165 wake_up(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200166
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/**
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700172 * lbs_send_tx_feedback - sends to the host the last transmitted packet,
173 * filling the radiotap headers with transmission information.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200174 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700175 * @priv: A pointer to &struct lbs_private structure
176 * @try_count: A 32-bit value containing transmission retry status.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200177 *
Randy Dunlap8973a6e2011-04-26 15:25:29 -0700178 * returns: void
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200179 */
Holger Schurig7919b892008-04-01 14:50:43 +0200180void lbs_send_tx_feedback(struct lbs_private *priv, u32 try_count)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200181{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200182 struct tx_radiotap_hdr *radiotap_hdr;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200183
Dan Carpenterbd75eb82010-07-22 14:21:02 +0200184 if (priv->wdev->iftype != NL80211_IFTYPE_MONITOR ||
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530185 priv->currenttxskb == NULL)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200186 return;
187
David Woodhouseaa21c002007-12-08 20:04:36 +0000188 radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200189
Holger Schurig7919b892008-04-01 14:50:43 +0200190 radiotap_hdr->data_retries = try_count ?
191 (1 + priv->txretrycount - try_count) : 0;
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500192
193 priv->currenttxskb->protocol = eth_type_trans(priv->currenttxskb,
Kiran Divekare86dc1c2010-06-14 22:01:26 +0530194 priv->dev);
David Woodhouse6f93a8e2007-12-10 00:49:26 -0500195 netif_rx(priv->currenttxskb);
196
David Woodhouseaa21c002007-12-08 20:04:36 +0000197 priv->currenttxskb = NULL;
Brajesh Dave01d77d82007-11-20 17:44:14 -0500198
David Woodhouseaa21c002007-12-08 20:04:36 +0000199 if (priv->connect_status == LBS_CONNECTED)
Holger Schurig634b8f42007-05-25 13:05:16 -0400200 netif_wake_queue(priv->dev);
Brajesh Dave01d77d82007-11-20 17:44:14 -0500201
Holger Schurig602114a2009-12-02 15:26:01 +0100202 if (priv->mesh_dev && lbs_mesh_connected(priv))
Brajesh Dave01d77d82007-11-20 17:44:14 -0500203 netif_wake_queue(priv->mesh_dev);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204}
Holger Schurig10078322007-11-15 18:05:47 -0500205EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);