libertas: add access functions for mesh open/connect status
[safe/jmp/linux-2.6] / drivers / net / wireless / libertas / tx.c
index 336544c..52d244e 100644 (file)
@@ -2,8 +2,10 @@
   * This file contains the handling of TX in wlan driver.
   */
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/sched.h>
 
-#include "hostcmd.h"
+#include "host.h"
 #include "radiotap.h"
 #include "decl.h"
 #include "defs.h"
@@ -56,156 +58,112 @@ static u32 convert_radiotap_rate_to_mv(u8 rate)
  *  @param skb     A pointer to skb which includes TX packet
  *  @return       0 or -1
  */
-static int lbs_process_tx(struct lbs_private *priv, struct sk_buff *skb)
+netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       int ret = -1;
-       struct txpd localtxpd;
-       struct txpd *plocaltxpd = &localtxpd;
-       u8 *p802x_hdr;
-       struct tx_radiotap_hdr *pradiotap_hdr;
-       u32 new_rate;
-       u8 *ptr = priv->tmptxbuf;
+       unsigned long flags;
+       struct lbs_private *priv = dev->ml_priv;
+       struct txpd *txpd;
+       char *p802x_hdr;
+       uint16_t pkt_len;
+       netdev_tx_t ret = NETDEV_TX_OK;
 
        lbs_deb_enter(LBS_DEB_TX);
 
-       lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
-
-       if (priv->dnld_sent) {
-               lbs_pr_alert( "TX error: dnld_sent = %d, not sending\n",
-                      priv->dnld_sent);
-               goto done;
-       }
-
-       if ((priv->psstate == PS_STATE_SLEEP) ||
-           (priv->psstate == PS_STATE_PRE_SLEEP)) {
-               lbs_pr_alert("TX error: packet xmit in %ssleep mode\n",
-                            priv->psstate == PS_STATE_SLEEP?"":"pre-");
-               goto done;
-       }
+       /* We need to protect against the queues being restarted before
+          we get round to stopping them */
+       spin_lock_irqsave(&priv->driver_lock, flags);
 
        if (priv->surpriseremoved)
-               return -1;
+               goto free;
 
        if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
                lbs_deb_tx("tx err: skb length %d 0 or > %zd\n",
                       skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
-               goto done_tx;
+               /* We'll never manage to send this one; drop it and return 'OK' */
+
+               dev->stats.tx_dropped++;
+               dev->stats.tx_errors++;
+               goto free;
        }
 
-       ret = 0;
-       memset(plocaltxpd, 0, sizeof(struct txpd));
 
-       plocaltxpd->tx_packet_length = cpu_to_le16(skb->len);
+       netif_stop_queue(priv->dev);
+       if (priv->mesh_dev)
+               netif_stop_queue(priv->mesh_dev);
 
-       /* offset of actual data */
-       plocaltxpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
+       if (priv->tx_pending_len) {
+               /* This can happen if packets come in on the mesh and eth
+                  device simultaneously -- there's no mutual exclusion on
+                  hard_start_xmit() calls between devices. */
+               lbs_deb_tx("Packet on %s while busy\n", dev->name);
+               ret = NETDEV_TX_BUSY;
+               goto unlock;
+       }
+
+       priv->tx_pending_len = -1;
+       spin_unlock_irqrestore(&priv->driver_lock, flags);
+
+       lbs_deb_hex(LBS_DEB_TX, "TX Data", skb->data, min_t(unsigned int, skb->len, 100));
+
+       txpd = (void *)priv->tx_pending_buf;
+       memset(txpd, 0, sizeof(struct txpd));
 
        p802x_hdr = skb->data;
-       if (priv->monitormode != LBS_MONITOR_OFF) {
+       pkt_len = skb->len;
 
-               /* locate radiotap header */
-               pradiotap_hdr = (struct tx_radiotap_hdr *)skb->data;
+       if (dev == priv->rtap_net_dev) {
+               struct tx_radiotap_hdr *rtap_hdr = (void *)skb->data;
 
                /* set txpd fields from the radiotap header */
-               new_rate = convert_radiotap_rate_to_mv(pradiotap_hdr->rate);
-               if (new_rate != 0) {
-                       /* use new tx_control[4:0] */
-                       plocaltxpd->tx_control = cpu_to_le32(new_rate);
-               }
+               txpd->tx_control = cpu_to_le32(convert_radiotap_rate_to_mv(rtap_hdr->rate));
 
                /* skip the radiotap header */
-               p802x_hdr += sizeof(struct tx_radiotap_hdr);
-               plocaltxpd->tx_packet_length =
-                       cpu_to_le16(le16_to_cpu(plocaltxpd->tx_packet_length)
-                                   - sizeof(struct tx_radiotap_hdr));
+               p802x_hdr += sizeof(*rtap_hdr);
+               pkt_len -= sizeof(*rtap_hdr);
 
+               /* copy destination address from 802.11 header */
+               memcpy(txpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
+       } else {
+               /* copy destination address from 802.3 header */
+               memcpy(txpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
        }
-       /* copy destination address from 802.3 or 802.11 header */
-       if (priv->monitormode != LBS_MONITOR_OFF)
-               memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr + 4, ETH_ALEN);
-       else
-               memcpy(plocaltxpd->tx_dest_addr_high, p802x_hdr, ETH_ALEN);
 
-       lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) plocaltxpd, sizeof(struct txpd));
+       txpd->tx_packet_length = cpu_to_le16(pkt_len);
+       txpd->tx_packet_location = cpu_to_le32(sizeof(struct txpd));
 
-       if (IS_MESH_FRAME(skb)) {
-               plocaltxpd->tx_control |= cpu_to_le32(TxPD_MESH_FRAME);
-       }
+       lbs_mesh_set_txpd(priv, dev, txpd);
 
-       memcpy(ptr, plocaltxpd, sizeof(struct txpd));
+       lbs_deb_hex(LBS_DEB_TX, "txpd", (u8 *) &txpd, sizeof(struct txpd));
 
-       ptr += sizeof(struct txpd);
+       lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(txpd->tx_packet_length));
 
-       lbs_deb_hex(LBS_DEB_TX, "Tx Data", (u8 *) p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
-       memcpy(ptr, p802x_hdr, le16_to_cpu(plocaltxpd->tx_packet_length));
-       ret = priv->hw_host_to_card(priv, MVMS_DAT,
-                                   priv->tmptxbuf,
-                                   le16_to_cpu(plocaltxpd->tx_packet_length) +
-                                   sizeof(struct txpd));
+       memcpy(&txpd[1], p802x_hdr, le16_to_cpu(txpd->tx_packet_length));
 
-       if (ret) {
-               lbs_deb_tx("tx err: hw_host_to_card returned 0x%X\n", ret);
-               goto done_tx;
-       }
+       spin_lock_irqsave(&priv->driver_lock, flags);
+       priv->tx_pending_len = pkt_len + sizeof(struct txpd);
 
-       lbs_deb_tx("%s succeeds\n", __func__);
+       lbs_deb_tx("%s lined up packet\n", __func__);
 
-done_tx:
-       if (!ret) {
-               priv->stats.tx_packets++;
-               priv->stats.tx_bytes += skb->len;
-       } else {
-               priv->stats.tx_dropped++;
-               priv->stats.tx_errors++;
-       }
+       dev->stats.tx_packets++;
+       dev->stats.tx_bytes += skb->len;
 
-       if (!ret && priv->monitormode != LBS_MONITOR_OFF) {
+       dev->trans_start = jiffies;
+
+       if (priv->monitormode) {
                /* Keep the skb to echo it back once Tx feedback is
                   received from FW */
                skb_orphan(skb);
-               /* stop processing outgoing pkts */
-               netif_stop_queue(priv->dev);
-               if (priv->mesh_dev)
-                       netif_stop_queue(priv->mesh_dev);
 
                /* Keep the skb around for when we get feedback */
                priv->currenttxskb = skb;
        } else {
+ free:
                dev_kfree_skb_any(skb);
        }
+ unlock:
+       spin_unlock_irqrestore(&priv->driver_lock, flags);
+       wake_up(&priv->waitq);
 
-done:
-       lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
-       return ret;
-}
-
-int lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
-{
-       int ret = 0;
-       struct lbs_private *priv = dev->priv;
-
-       lbs_deb_enter(LBS_DEB_TX);
-
-       /* We could return NETDEV_TX_BUSY here, but I'd actually 
-          like to get the point where we can BUG() */
-       if (priv->dnld_sent) {
-               lbs_pr_err("%s while dnld_sent\n", __func__);
-               priv->stats.tx_dropped++;
-               goto done;
-       }
-       if (priv->currenttxskb) {
-               lbs_pr_err("%s while TX skb pending\n", __func__);
-               priv->stats.tx_dropped++;
-               goto done;
-       }
-
-       netif_stop_queue(priv->dev);
-       if (priv->mesh_dev)
-               netif_stop_queue(priv->mesh_dev);
-
-       if (lbs_process_tx(priv, skb) == 0)
-               dev->trans_start = jiffies;
-done:
        lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
        return ret;
 }
@@ -219,38 +177,28 @@ done:
  *
  *  @returns void
  */
-void lbs_send_tx_feedback(struct lbs_private *priv)
+void lbs_send_tx_feedback(struct lbs_private *priv, u32 try_count)
 {
        struct tx_radiotap_hdr *radiotap_hdr;
-       u32 status = priv->eventcause;
-       int txfail;
-       int try_count;
 
-       if (priv->monitormode == LBS_MONITOR_OFF ||
-           priv->currenttxskb == NULL)
+       if (!priv->monitormode || priv->currenttxskb == NULL)
                return;
 
        radiotap_hdr = (struct tx_radiotap_hdr *)priv->currenttxskb->data;
 
-       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) ?
-           (1 + priv->txretrycount - try_count) : 0;
-       lbs_upload_rx_packet(priv, priv->currenttxskb);
+       radiotap_hdr->data_retries = try_count ?
+               (1 + priv->txretrycount - try_count) : 0;
+
+       priv->currenttxskb->protocol = eth_type_trans(priv->currenttxskb,
+                                                     priv->rtap_net_dev);
+       netif_rx(priv->currenttxskb);
+
        priv->currenttxskb = NULL;
 
        if (priv->connect_status == LBS_CONNECTED)
                netif_wake_queue(priv->dev);
 
-       if (priv->mesh_dev && (priv->mesh_connect_status == LBS_CONNECTED))
+       if (priv->mesh_dev && lbs_mesh_connected(priv))
                netif_wake_queue(priv->mesh_dev);
 }
 EXPORT_SYMBOL_GPL(lbs_send_tx_feedback);