]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/wireless/orinoco/orinoco.c
Merge branches 'bugzilla-11884' and 'bugzilla-8544' into release
[linux-2.6-omap-h63xx.git] / drivers / net / wireless / orinoco / orinoco.c
index 09eec7f620bcf64f098c348be56e0da8cd0b7185..c3bb85e0251e87731899fb17d8b186feda2c6883 100644 (file)
@@ -84,6 +84,7 @@
 #include <linux/etherdevice.h>
 #include <linux/ethtool.h>
 #include <linux/firmware.h>
+#include <linux/suspend.h>
 #include <linux/if_arp.h>
 #include <linux/wireless.h>
 #include <linux/ieee80211.h>
@@ -712,6 +713,7 @@ static int orinoco_download(struct orinoco_private *priv)
        return err;
 }
 
+#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
 static void orinoco_cache_fw(struct orinoco_private *priv, int ap)
 {
        const struct firmware *fw_entry = NULL;
@@ -745,6 +747,10 @@ static void orinoco_uncache_fw(struct orinoco_private *priv)
        priv->cached_pri_fw = NULL;
        priv->cached_fw = NULL;
 }
+#else
+#define orinoco_cache_fw(priv, ap)
+#define orinoco_uncache_fw(priv)
+#endif
 
 /********************************************************************/
 /* Device methods                                                   */
@@ -1604,6 +1610,16 @@ static void orinoco_rx_isr_tasklet(unsigned long data)
        struct orinoco_rx_data *rx_data, *temp;
        struct hermes_rx_descriptor *desc;
        struct sk_buff *skb;
+       unsigned long flags;
+
+       /* orinoco_rx requires the driver lock, and we also need to
+        * protect priv->rx_list, so just hold the lock over the
+        * lot.
+        *
+        * If orinoco_lock fails, we've unplugged the card. In this
+        * case just abort. */
+       if (orinoco_lock(priv, &flags) != 0)
+               return;
 
        /* extract desc and skb from queue */
        list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
@@ -1616,6 +1632,8 @@ static void orinoco_rx_isr_tasklet(unsigned long data)
 
                kfree(desc);
        }
+
+       orinoco_unlock(priv, &flags);
 }
 
 /********************************************************************/
@@ -1744,7 +1762,7 @@ static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
        union iwreq_data wrqu;
        int err;
 
-       err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
                              ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
        if (err != 0)
                return;
@@ -1767,7 +1785,7 @@ static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
        if (!priv->has_wpa)
                return;
 
-       err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
                              sizeof(buf), NULL, &buf);
        if (err != 0)
                return;
@@ -1797,7 +1815,7 @@ static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
        if (!priv->has_wpa)
                return;
 
-       err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
                              sizeof(buf), NULL, &buf);
        if (err != 0)
                return;
@@ -3099,6 +3117,50 @@ irqreturn_t orinoco_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+/********************************************************************/
+/* Power management                                                 */
+/********************************************************************/
+#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
+static int orinoco_pm_notifier(struct notifier_block *notifier,
+                              unsigned long pm_event,
+                              void *unused)
+{
+       struct orinoco_private *priv = container_of(notifier,
+                                                   struct orinoco_private,
+                                                   pm_notifier);
+
+       /* All we need to do is cache the firmware before suspend, and
+        * release it when we come out.
+        *
+        * Only need to do this if we're downloading firmware. */
+       if (!priv->do_fw_download)
+               return NOTIFY_DONE;
+
+       switch (pm_event) {
+       case PM_HIBERNATION_PREPARE:
+       case PM_SUSPEND_PREPARE:
+               orinoco_cache_fw(priv, 0);
+               break;
+
+       case PM_POST_RESTORE:
+               /* Restore from hibernation failed. We need to clean
+                * up in exactly the same way, so fall through. */
+       case PM_POST_HIBERNATION:
+       case PM_POST_SUSPEND:
+               orinoco_uncache_fw(priv);
+               break;
+
+       case PM_RESTORE_PREPARE:
+       default:
+               break;
+       }
+
+       return NOTIFY_DONE;
+}
+#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
+#define orinoco_pm_notifier NULL
+#endif
+
 /********************************************************************/
 /* Initialization                                                   */
 /********************************************************************/
@@ -3342,7 +3404,9 @@ static int orinoco_init(struct net_device *dev)
        }
 
        if (priv->do_fw_download) {
+#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
                orinoco_cache_fw(priv, 0);
+#endif
 
                err = orinoco_download(priv);
                if (err)
@@ -3583,18 +3647,33 @@ struct net_device
        priv->cached_pri_fw = NULL;
        priv->cached_fw = NULL;
 
+       /* Register PM notifiers */
+       priv->pm_notifier.notifier_call = orinoco_pm_notifier;
+       register_pm_notifier(&priv->pm_notifier);
+
        return dev;
 }
 
 void free_orinocodev(struct net_device *dev)
 {
        struct orinoco_private *priv = netdev_priv(dev);
+       struct orinoco_rx_data *rx_data, *temp;
 
-       /* No need to empty priv->rx_list: if the tasklet is scheduled
-        * when we call tasklet_kill it will run one final time,
-        * emptying the list */
+       /* If the tasklet is scheduled when we call tasklet_kill it
+        * will run one final time. However the tasklet will only
+        * drain priv->rx_list if the hw is still available. */
        tasklet_kill(&priv->rx_tasklet);
 
+       /* Explicitly drain priv->rx_list */
+       list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
+               list_del(&rx_data->list);
+
+               dev_kfree_skb(rx_data->skb);
+               kfree(rx_data->desc);
+               kfree(rx_data);
+       }
+
+       unregister_pm_notifier(&priv->pm_notifier);
        orinoco_uncache_fw(priv);
 
        priv->wpa_ie_len = 0;