Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * This file contains the handling of TX in wlan driver.
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  * convert_radiotap_rate_to_mv - converts Tx/Rx rates from IEEE80211_RADIOTAP_RATE
0021  * units (500 Kb/s) into Marvell WLAN format (see Table 8 in Section 3.2.1)
0022  *
0023  * @rate:   Input rate
0024  * returns: Output Rate (0 if invalid)
0025  */
0026 static u32 convert_radiotap_rate_to_mv(u8 rate)
0027 {
0028     switch (rate) {
0029     case 2:     /*   1 Mbps */
0030         return 0 | (1 << 4);
0031     case 4:     /*   2 Mbps */
0032         return 1 | (1 << 4);
0033     case 11:        /* 5.5 Mbps */
0034         return 2 | (1 << 4);
0035     case 22:        /*  11 Mbps */
0036         return 3 | (1 << 4);
0037     case 12:        /*   6 Mbps */
0038         return 4 | (1 << 4);
0039     case 18:        /*   9 Mbps */
0040         return 5 | (1 << 4);
0041     case 24:        /*  12 Mbps */
0042         return 6 | (1 << 4);
0043     case 36:        /*  18 Mbps */
0044         return 7 | (1 << 4);
0045     case 48:        /*  24 Mbps */
0046         return 8 | (1 << 4);
0047     case 72:        /*  36 Mbps */
0048         return 9 | (1 << 4);
0049     case 96:        /*  48 Mbps */
0050         return 10 | (1 << 4);
0051     case 108:       /*  54 Mbps */
0052         return 11 | (1 << 4);
0053     }
0054     return 0;
0055 }
0056 
0057 /**
0058  * lbs_hard_start_xmit - checks the conditions and sends packet to IF
0059  * layer if everything is ok
0060  *
0061  * @skb:    A pointer to skb which includes TX packet
0062  * @dev:    A pointer to the &struct net_device
0063  * returns: 0 or -1
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     /* We need to protect against the queues being restarted before
0075        we get round to stopping them */
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         /* We'll never manage to send this one; drop it and return 'OK' */
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         /* This can happen if packets come in on the mesh and eth
0098            device simultaneously -- there's no mutual exclusion on
0099            hard_start_xmit() calls between devices. */
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         /* set txpd fields from the radiotap header */
0121         txpd->tx_control = cpu_to_le32(convert_radiotap_rate_to_mv(rtap_hdr->rate));
0122 
0123         /* skip the radiotap header */
0124         p802x_hdr += sizeof(*rtap_hdr);
0125         pkt_len -= sizeof(*rtap_hdr);
0126 
0127         /* copy destination address from 802.11 header */
0128         memcpy(&txpd->tx_dest_addr, p802x_hdr + 4, ETH_ALEN);
0129     } else {
0130         /* copy destination address from 802.3 header */
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         /* Keep the skb to echo it back once Tx feedback is
0155            received from FW */
0156         skb_orphan(skb);
0157 
0158         /* Keep the skb around for when we get feedback */
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  * lbs_send_tx_feedback - sends to the host the last transmitted packet,
0174  * filling the radiotap headers with transmission information.
0175  *
0176  * @priv:   A pointer to &struct lbs_private structure
0177  * @try_count:  A 32-bit value containing transmission retry status.
0178  *
0179  * returns: void
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);