0001
0002
0003
0004
0005 #include <linux/hardirq.h>
0006 #include <linux/netdevice.h>
0007 #include <linux/etherdevice.h>
0008 #include <linux/sched.h>
0009 #include <linux/export.h>
0010 #include <net/cfg80211.h>
0011
0012 #include "host.h"
0013 #include "radiotap.h"
0014 #include "decl.h"
0015 #include "defs.h"
0016 #include "dev.h"
0017 #include "mesh.h"
0018
0019
0020
0021
0022
0023
0024
0025
0026 static u32 convert_radiotap_rate_to_mv(u8 rate)
0027 {
0028 switch (rate) {
0029 case 2:
0030 return 0 | (1 << 4);
0031 case 4:
0032 return 1 | (1 << 4);
0033 case 11:
0034 return 2 | (1 << 4);
0035 case 22:
0036 return 3 | (1 << 4);
0037 case 12:
0038 return 4 | (1 << 4);
0039 case 18:
0040 return 5 | (1 << 4);
0041 case 24:
0042 return 6 | (1 << 4);
0043 case 36:
0044 return 7 | (1 << 4);
0045 case 48:
0046 return 8 | (1 << 4);
0047 case 72:
0048 return 9 | (1 << 4);
0049 case 96:
0050 return 10 | (1 << 4);
0051 case 108:
0052 return 11 | (1 << 4);
0053 }
0054 return 0;
0055 }
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
0066 {
0067 unsigned long flags;
0068 struct lbs_private *priv = dev->ml_priv;
0069 struct txpd *txpd;
0070 char *p802x_hdr;
0071 uint16_t pkt_len;
0072 netdev_tx_t ret = NETDEV_TX_OK;
0073
0074
0075
0076 spin_lock_irqsave(&priv->driver_lock, flags);
0077
0078 if (priv->surpriseremoved)
0079 goto free;
0080
0081 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
0082 lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
0083 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
0084
0085
0086 dev->stats.tx_dropped++;
0087 dev->stats.tx_errors++;
0088 goto free;
0089 }
0090
0091
0092 netif_stop_queue(priv->dev);
0093 if (priv->mesh_dev)
0094 netif_stop_queue(priv->mesh_dev);
0095
0096 if (priv->tx_pending_len) {
0097
0098
0099
0100 lbs_deb_tx("Packet on %s while busy\n", dev->name);
0101 ret = NETDEV_TX_BUSY;
0102 goto unlock;
0103 }
0104
0105 priv->tx_pending_len = -1;
0106 spin_unlock_irqrestore(&priv->driver_lock, flags);
0107
0108 lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
0109
0110 txpd = (void *)priv->tx_pending_buf;
0111 memset(txpd, 0, sizeof(struct txpd));
0112
0113 p802x_hdr = skb->data;
0114 pkt_len = skb->len;
0115
0116 BUILD_BUG_ON(sizeof(txpd->tx_dest_addr) != ETH_ALEN);
0117 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
0118 struct tx_radiotap_hdr *rtap_hdr = (void *)skb->data;
0119
0120
0121 txpd->tx_control = cpu_to_le32(convert_radiotap_rate_to_mv(rtap_hdr->rate));
0122
0123
0124 p802x_hdr += sizeof(*rtap_hdr);
0125 pkt_len -= sizeof(*rtap_hdr);
0126
0127
0128 memcpy(&txpd->tx_dest_addr, p802x_hdr + 4, ETH_ALEN);
0129 } else {
0130
0131 memcpy(&txpd->tx_dest_addr, p802x_hdr, ETH_ALEN);
0132 }
0133
0134 txpd->tx_packet_length = cpu_to_le16(pkt_len);
0135 txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
0136
0137 lbs_mesh_set_txpd(priv, dev, txpd);
0138
0139 lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd));
0140
0141 lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(txpd->tx_packet_length));
0142
0143 memcpy(&txpd[1], p802x_hdr, le16_to_cpu(txpd->tx_packet_length));
0144
0145 spin_lock_irqsave(&priv->driver_lock, flags);
0146 priv->tx_pending_len = pkt_len + sizeof(struct txpd);
0147
0148 lbs_deb_tx("%s lined up packet\n", __func__);
0149
0150 dev->stats.tx_packets++;
0151 dev->stats.tx_bytes += skb->len;
0152
0153 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
0154
0155
0156 skb_orphan(skb);
0157
0158
0159 priv->currenttxskb = skb;
0160 } else {
0161 free:
0162 dev_kfree_skb_any(skb);
0163 }
0164
0165 unlock:
0166 spin_unlock_irqrestore(&priv->driver_lock, flags);
0167 wake_up(&priv->waitq);
0168
0169 return ret;
0170 }
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 void lbs_send_tx_feedback(struct lbs_private *priv, u32 try_count)
0182 {
0183 struct tx_radiotap_hdr *radiotap_hdr;
0184
0185 if (priv->wdev->iftype != NL80211_IFTYPE_MONITOR ||
0186 priv->currenttxskb == NULL)
0187 return;
0188
0189 radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
0190
0191 radiotap_hdr->data_retries = try_count ?
0192 (1 + priv->txretrycount - try_count) : 0;
0193
0194 priv->currenttxskb->protocol = eth_type_trans(priv->currenttxskb,
0195 priv->dev);
0196 netif_rx(priv->currenttxskb);
0197
0198 priv->currenttxskb = NULL;
0199
0200 if (priv->connect_status == LBS_CONNECTED)
0201 netif_wake_queue(priv->dev);
0202
0203 if (priv->mesh_dev && netif_running(priv->mesh_dev))
0204 netif_wake_queue(priv->mesh_dev);
0205 }
0206 EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);