]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/libertas/main.c
libertas: convert GET_HW_SPEC to a direct command
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / libertas / main.c
index d311d5773f04baded21b7baff036dea8a2ef0eb7..9f6c119c2d1bc7614aacf118014d6398d2ee1d4c 100644 (file)
@@ -22,6 +22,7 @@
 #include "debugfs.h"
 #include "assoc.h"
 #include "join.h"
+#include "cmd.h"
 
 #define DRIVER_RELEASE_VERSION "323.p0"
 const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
@@ -274,6 +275,8 @@ static ssize_t lbs_rtap_set(struct device *dev,
                if(priv->monitormode == monitor_mode)
                        return strlen(buf);
                if (priv->monitormode == LBS_MONITOR_OFF) {
+                       if (priv->infra_open || priv->mesh_open)
+                               return -EBUSY;
                        if (priv->mode == IW_MODE_INFRA)
                                lbs_send_deauthentication(priv);
                        else if (priv->mode == IW_MODE_ADHOC)
@@ -367,116 +370,42 @@ static struct attribute_group lbs_mesh_attr_group = {
 };
 
 /**
- *  @brief Check if the device can be open and wait if necessary.
+ *  @brief This function opens the ethX or mshX interface
  *
  *  @param dev     A pointer to net_device structure
- *  @return       0
- *
- * For USB adapter, on some systems the device open handler will be
- * called before FW ready. Use the following flag check and wait
- * function to work around the issue.
- *
- */
-static int pre_open_check(struct net_device *dev)
-{
-       struct lbs_private *priv = (struct lbs_private *) dev->priv;
-       int i = 0;
-
-       while (!priv->fw_ready && i < 20) {
-               i++;
-               msleep_interruptible(100);
-       }
-       if (!priv->fw_ready) {
-               lbs_pr_err("firmware not ready\n");
-               return -1;
-       }
-
-       return 0;
-}
-
-/**
- *  @brief This function opens the device
- *
- *  @param dev     A pointer to net_device structure
- *  @return       0
+ *  @return       0 or -EBUSY if monitor mode active
  */
 static int lbs_dev_open(struct net_device *dev)
 {
-       struct lbs_private *priv = (struct lbs_private *) dev->priv;
-
-       lbs_deb_enter(LBS_DEB_NET);
+       struct lbs_private *priv = (struct lbs_private *) dev->priv ;
+       int ret = 0;
 
-       priv->open = 1;
+       spin_lock_irq(&priv->driver_lock);
 
-       if (priv->connect_status == LBS_CONNECTED)
-               netif_carrier_on(priv->dev);
-       else
-               netif_carrier_off(priv->dev);
+       if (priv->monitormode != LBS_MONITOR_OFF) {
+               ret = -EBUSY;
+               goto out;
+       }
 
-       if (priv->mesh_dev) {
-               if (priv->mesh_connect_status == LBS_CONNECTED)
-                       netif_carrier_on(priv->mesh_dev);
+       if (dev == priv->mesh_dev) {
+               priv->mesh_open = 1;
+               priv->mesh_connect_status = LBS_CONNECTED;
+               netif_carrier_on(dev);
+       } else {
+               priv->infra_open = 1;
+               
+               if (priv->connect_status == LBS_CONNECTED)
+                       netif_carrier_on(dev);
                else
-                       netif_carrier_off(priv->mesh_dev);
+                       netif_carrier_off(dev);
        }
 
-       lbs_deb_leave(LBS_DEB_NET);
-       return 0;
-}
-/**
- *  @brief This function opens the mshX interface
- *
- *  @param dev     A pointer to net_device structure
- *  @return       0
- */
-static int lbs_mesh_open(struct net_device *dev)
-{
-       struct lbs_private *priv = (struct lbs_private *) dev->priv ;
-
-       if (pre_open_check(dev) == -1)
-               return -1;
-       priv->mesh_open = 1 ;
-       netif_wake_queue(priv->mesh_dev);
-
-       priv->mesh_connect_status = LBS_CONNECTED;
-
-       netif_carrier_on(priv->mesh_dev);
-       netif_wake_queue(priv->mesh_dev);
-       if (priv->infra_open == 0)
-               return lbs_dev_open(priv->dev) ;
-       return 0;
-}
-
-/**
- *  @brief This function opens the ethX interface
- *
- *  @param dev     A pointer to net_device structure
- *  @return       0
- */
-static int lbs_open(struct net_device *dev)
-{
-       struct lbs_private *priv = (struct lbs_private *) dev->priv ;
-
-       if(pre_open_check(dev) == -1)
-               return -1;
-       priv->infra_open = 1 ;
-       netif_wake_queue(priv->dev);
-       if (priv->open == 0)
-               return lbs_dev_open(priv->dev) ;
-       return 0;
-}
-
-static int lbs_dev_close(struct net_device *dev)
-{
-       struct lbs_private *priv = dev->priv;
-
-       lbs_deb_enter(LBS_DEB_NET);
-
-       netif_carrier_off(priv->dev);
-       priv->open = 0;
+       if (!priv->tx_pending_len)
+               netif_wake_queue(dev);
+ out:
 
-       lbs_deb_leave(LBS_DEB_NET);
-       return 0;
+       spin_unlock_irq(&priv->driver_lock);
+       return ret;
 }
 
 /**
@@ -485,16 +414,20 @@ static int lbs_dev_close(struct net_device *dev)
  *  @param dev     A pointer to net_device structure
  *  @return       0
  */
-static int lbs_mesh_close(struct net_device *dev)
+static int lbs_mesh_stop(struct net_device *dev)
 {
        struct lbs_private *priv = (struct lbs_private *) (dev->priv);
 
+       spin_lock_irq(&priv->driver_lock);
+
        priv->mesh_open = 0;
-       netif_stop_queue(priv->mesh_dev);
-       if (priv->infra_open == 0)
-               return lbs_dev_close(dev);
-       else
-               return 0;
+       priv->mesh_connect_status = LBS_DISCONNECTED;
+
+       netif_stop_queue(dev);
+       netif_carrier_off(dev);
+       
+       spin_unlock_irq(&priv->driver_lock);
+       return 0;
 }
 
 /**
@@ -503,62 +436,18 @@ static int lbs_mesh_close(struct net_device *dev)
  *  @param dev     A pointer to net_device structure
  *  @return       0
  */
-static int lbs_close(struct net_device *dev)
+static int lbs_eth_stop(struct net_device *dev)
 {
        struct lbs_private *priv = (struct lbs_private *) dev->priv;
 
-       netif_stop_queue(dev);
-       priv->infra_open = 0;
-       if (priv->mesh_open == 0)
-               return lbs_dev_close(dev);
-       else
-               return 0;
-}
-
-/**
- * @brief Mark mesh packets and handover them to lbs_hard_start_xmit
- *
- */
-static int lbs_mesh_pre_start_xmit(struct sk_buff *skb,
-               struct net_device *dev)
-{
-       struct lbs_private *priv = dev->priv;
-       int ret;
-
-       lbs_deb_enter(LBS_DEB_MESH);
-       if (priv->monitormode != LBS_MONITOR_OFF) {
-               netif_stop_queue(dev);
-               return -EOPNOTSUPP;
-       }
-
-       SET_MESH_FRAME(skb);
-
-       ret = lbs_hard_start_xmit(skb, priv->mesh_dev);
-       lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret);
-       return ret;
-}
-
-/**
- * @brief Mark non-mesh packets and handover them to lbs_hard_start_xmit
- *
- */
-static int lbs_pre_start_xmit(struct sk_buff *skb, struct net_device *dev)
-{
-       struct lbs_private *priv = dev->priv;
-       int ret;
-
-       lbs_deb_enter(LBS_DEB_TX);
+       spin_lock_irq(&priv->driver_lock);
 
-       if (priv->monitormode != LBS_MONITOR_OFF) {
-               netif_stop_queue(dev);
-               return -EOPNOTSUPP;
-       }
-
-       UNSET_MESH_FRAME(skb);
+       priv->infra_open = 0;
 
-       ret = lbs_hard_start_xmit(skb, dev);
-       lbs_deb_leave_args(LBS_DEB_TX, "ret %d", ret);
-       return ret;
+       netif_stop_queue(dev);
+       
+       spin_unlock_irq(&priv->driver_lock);
+       return 0;
 }
 
 static void lbs_tx_timeout(struct net_device *dev)
@@ -768,6 +657,8 @@ static int lbs_thread(void *data)
        set_freezable();
 
        for (;;) {
+               int shouldsleep;
+
                lbs_deb_thread( "main-thread 111: intcounter=%d currenttxskb=%p dnld_sent=%d\n",
                                priv->intcounter, priv->currenttxskb, priv->dnld_sent);
 
@@ -775,8 +666,26 @@ static int lbs_thread(void *data)
                set_current_state(TASK_INTERRUPTIBLE);
                spin_lock_irq(&priv->driver_lock);
 
-               if ((priv->psstate == PS_STATE_SLEEP) ||
-                   (!priv->intcounter && (priv->dnld_sent || priv->cur_cmd || list_empty(&priv->cmdpendingq)))) {
+               if (priv->surpriseremoved)
+                       shouldsleep = 0;        /* Bye */
+               else if (priv->psstate == PS_STATE_SLEEP)
+                       shouldsleep = 1;        /* Sleep mode. Nothing we can do till it wakes */
+               else if (priv->intcounter)
+                       shouldsleep = 0;        /* Interrupt pending. Deal with it now */
+               else if (!priv->fw_ready)
+                       shouldsleep = 1;        /* Firmware not ready. We're waiting for it */
+               else if (priv->dnld_sent)
+                       shouldsleep = 1;        /* Something is en route to the device already */
+               else if (priv->tx_pending_len > 0)
+                       shouldsleep = 0;        /* We've a packet to send */
+               else if (priv->cur_cmd)
+                       shouldsleep = 1;        /* Can't send a command; one already running */
+               else if (!list_empty(&priv->cmdpendingq))
+                       shouldsleep = 0;        /* We have a command to send */
+               else
+                       shouldsleep = 1;        /* No command */
+
+               if (shouldsleep) {
                        lbs_deb_thread("main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n",
                                       priv->connect_status, priv->intcounter,
                                       priv->psmode, priv->psstate);
@@ -847,6 +756,9 @@ static int lbs_thread(void *data)
                } else
                        spin_unlock_irq(&priv->driver_lock);
 
+               if (!priv->fw_ready)
+                       continue;
+
                /* Check if we need to confirm Sleep Request received previously */
                if (priv->psstate == PS_STATE_PRE_SLEEP &&
                    !priv->dnld_sent && !priv->cur_cmd) {
@@ -882,6 +794,28 @@ static int lbs_thread(void *data)
                 */
                if (!list_empty(&priv->cmdpendingq))
                        wake_up_all(&priv->cmd_pending);
+
+               spin_lock_irq(&priv->driver_lock);
+               if (!priv->dnld_sent && priv->tx_pending_len > 0) {
+                       int ret = priv->hw_host_to_card(priv, MVMS_DAT,
+                                                       priv->tx_pending_buf,
+                                                       priv->tx_pending_len);
+                       if (ret) {
+                               lbs_deb_tx("host_to_card failed %d\n", ret);
+                               priv->dnld_sent = DNLD_RES_RECEIVED;
+                       }
+                       priv->tx_pending_len = 0;
+                       if (!priv->currenttxskb) {
+                               /* We can wake the queues immediately if we aren't
+                                  waiting for TX feedback */
+                               if (priv->connect_status == LBS_CONNECTED)
+                                       netif_wake_queue(priv->dev);
+                               if (priv->mesh_dev &&
+                                   priv->mesh_connect_status == LBS_CONNECTED)
+                                       netif_wake_queue(priv->mesh_dev);
+                       }
+               }
+               spin_unlock_irq(&priv->driver_lock);
        }
 
        del_timer(&priv->command_timer);
@@ -910,10 +844,7 @@ static int lbs_setup_firmware(struct lbs_private *priv)
         * Read MAC address from HW
         */
        memset(priv->current_addr, 0xff, ETH_ALEN);
-
-       ret = lbs_prepare_and_send_command(priv, CMD_GET_HW_SPEC,
-                                   0, CMD_OPTION_WAITFORRSP, 0, NULL);
-
+       ret = lbs_update_hw_spec(priv);
        if (ret) {
                ret = -1;
                goto done;
@@ -1103,9 +1034,9 @@ struct lbs_private *lbs_add_card(void *card, struct device *dmdev)
        priv->infra_open = 0;
 
        /* Setup the OS Interface to our functions */
-       dev->open = lbs_open;
-       dev->hard_start_xmit = lbs_pre_start_xmit;
-       dev->stop = lbs_close;
+       dev->open = lbs_dev_open;
+       dev->hard_start_xmit = lbs_hard_start_xmit;
+       dev->stop = lbs_eth_stop;
        dev->set_mac_address = lbs_set_mac_address;
        dev->tx_timeout = lbs_tx_timeout;
        dev->get_stats = lbs_get_stats;
@@ -1275,9 +1206,9 @@ int lbs_add_mesh(struct lbs_private *priv, struct device *dev)
        mesh_dev->priv = priv;
        priv->mesh_dev = mesh_dev;
 
-       mesh_dev->open = lbs_mesh_open;
-       mesh_dev->hard_start_xmit = lbs_mesh_pre_start_xmit;
-       mesh_dev->stop = lbs_mesh_close;
+       mesh_dev->open = lbs_dev_open;
+       mesh_dev->hard_start_xmit = lbs_hard_start_xmit;
+       mesh_dev->stop = lbs_mesh_stop;
        mesh_dev->get_stats = lbs_get_stats;
        mesh_dev->set_mac_address = lbs_set_mac_address;
        mesh_dev->ethtool_ops = &lbs_ethtool_ops;
@@ -1414,23 +1345,22 @@ out:
  *  @param dev     A pointer to net_device structure
  *  @return       n/a
  */
-void lbs_interrupt(struct net_device *dev)
+void lbs_interrupt(struct lbs_private *priv)
 {
-       struct lbs_private *priv = dev->priv;
-
        lbs_deb_enter(LBS_DEB_THREAD);
 
-       lbs_deb_thread("lbs_interrupt: intcounter=%d\n",
-              priv->intcounter);
+       lbs_deb_thread("lbs_interrupt: intcounter=%d\n", priv->intcounter);
+
+       if (spin_trylock(&priv->driver_lock)) {
+               spin_unlock(&priv->driver_lock);
+               printk(KERN_CRIT "%s called without driver_lock held\n", __func__);
+               WARN_ON(1);
+       }
 
        priv->intcounter++;
 
-       if (priv->psstate == PS_STATE_SLEEP) {
+       if (priv->psstate == PS_STATE_SLEEP)
                priv->psstate = PS_STATE_AWAKE;
-               netif_wake_queue(dev);
-               if (priv->mesh_dev)
-                       netif_wake_queue(priv->mesh_dev);
-       }
 
        wake_up_interruptible(&priv->waitq);
 
@@ -1475,6 +1405,7 @@ static void __exit lbs_exit_module(void)
 
 static int lbs_rtap_open(struct net_device *dev)
 {
+       /* Yes, _stop_ the queue. Because we don't support injection */
         netif_carrier_off(dev);
         netif_stop_queue(dev);
         return 0;
@@ -1488,13 +1419,13 @@ static int lbs_rtap_stop(struct net_device *dev)
 static int lbs_rtap_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
         netif_stop_queue(dev);
-        return -EOPNOTSUPP;
+        return NETDEV_TX_BUSY;
 }
 
 static struct net_device_stats *lbs_rtap_get_stats(struct net_device *dev)
 {
        struct lbs_private *priv = dev->priv;
-       return &priv->ieee->stats;
+       return &priv->stats;
 }
 
 
@@ -1503,42 +1434,37 @@ void lbs_remove_rtap(struct lbs_private *priv)
        if (priv->rtap_net_dev == NULL)
                return;
        unregister_netdev(priv->rtap_net_dev);
-       free_ieee80211(priv->rtap_net_dev);
+       free_netdev(priv->rtap_net_dev);
        priv->rtap_net_dev = NULL;
 }
 
 int lbs_add_rtap(struct lbs_private *priv)
 {
        int rc = 0;
+       struct net_device *rtap_dev;
 
        if (priv->rtap_net_dev)
                return -EPERM;
 
-       priv->rtap_net_dev = alloc_ieee80211(0);
-       if (priv->rtap_net_dev == NULL)
+       rtap_dev = alloc_netdev(0, "rtap%d", ether_setup);
+       if (rtap_dev == NULL)
                return -ENOMEM;
 
+       memcpy(rtap_dev->dev_addr, priv->current_addr, ETH_ALEN);
+       rtap_dev->type = ARPHRD_IEEE80211_RADIOTAP;
+       rtap_dev->open = lbs_rtap_open;
+       rtap_dev->stop = lbs_rtap_stop;
+       rtap_dev->get_stats = lbs_rtap_get_stats;
+       rtap_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
+       rtap_dev->set_multicast_list = lbs_set_multicast_list;
+       rtap_dev->priv = priv;
 
-       priv->ieee = netdev_priv(priv->rtap_net_dev);
-
-       strcpy(priv->rtap_net_dev->name, "rtap%d");
-
-       priv->rtap_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
-       priv->rtap_net_dev->open = lbs_rtap_open;
-       priv->rtap_net_dev->stop = lbs_rtap_stop;
-       priv->rtap_net_dev->get_stats = lbs_rtap_get_stats;
-       priv->rtap_net_dev->hard_start_xmit = lbs_rtap_hard_start_xmit;
-       priv->rtap_net_dev->set_multicast_list = lbs_set_multicast_list;
-       priv->rtap_net_dev->priv = priv;
-
-       priv->ieee->iw_mode = IW_MODE_MONITOR;
-
-       rc = register_netdev(priv->rtap_net_dev);
+       rc = register_netdev(rtap_dev);
        if (rc) {
-               free_ieee80211(priv->rtap_net_dev);
-               priv->rtap_net_dev = NULL;
+               free_netdev(rtap_dev);
                return rc;
        }
+       priv->rtap_net_dev = rtap_dev;
 
        return 0;
 }