netdev: bfin_mac: add support for wake-on-lan magic packets
authorMichael Hennerich <michael.hennerich@analog.com>
Mon, 10 May 2010 05:39:11 +0000 (05:39 +0000)
committerDavid S. Miller <davem@davemloft.net>
Tue, 18 May 2010 00:20:59 +0000 (17:20 -0700)
Note that WOL works only in PM Suspend Standby Mode (Sleep Mode).

Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bfin_mac.c
drivers/net/bfin_mac.h

index 5d962b86ee2266e190014de8e080a1261f0b8cf1..28f350711267064d39e7a0ca3d5415e78f551e7e 100644 (file)
@@ -464,6 +464,14 @@ static int mii_probe(struct net_device *dev)
  * Ethtool support
  */
 
+/*
+ * interrupt routine for magic packet wakeup
+ */
+static irqreturn_t bfin_mac_wake_interrupt(int irq, void *dev_id)
+{
+       return IRQ_HANDLED;
+}
+
 static int
 bfin_mac_ethtool_getsettings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
@@ -498,11 +506,57 @@ static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev,
        strcpy(info->bus_info, dev_name(&dev->dev));
 }
 
+static void bfin_mac_ethtool_getwol(struct net_device *dev,
+       struct ethtool_wolinfo *wolinfo)
+{
+       struct bfin_mac_local *lp = netdev_priv(dev);
+
+       wolinfo->supported = WAKE_MAGIC;
+       wolinfo->wolopts = lp->wol;
+}
+
+static int bfin_mac_ethtool_setwol(struct net_device *dev,
+       struct ethtool_wolinfo *wolinfo)
+{
+       struct bfin_mac_local *lp = netdev_priv(dev);
+       int rc;
+
+       if (wolinfo->wolopts & (WAKE_MAGICSECURE |
+                               WAKE_UCAST |
+                               WAKE_MCAST |
+                               WAKE_BCAST |
+                               WAKE_ARP))
+               return -EOPNOTSUPP;
+
+       lp->wol = wolinfo->wolopts;
+
+       if (lp->wol && !lp->irq_wake_requested) {
+               /* register wake irq handler */
+               rc = request_irq(IRQ_MAC_WAKEDET, bfin_mac_wake_interrupt,
+                                IRQF_DISABLED, "EMAC_WAKE", dev);
+               if (rc)
+                       return rc;
+               lp->irq_wake_requested = true;
+       }
+
+       if (!lp->wol && lp->irq_wake_requested) {
+               free_irq(IRQ_MAC_WAKEDET, dev);
+               lp->irq_wake_requested = false;
+       }
+
+       /* Make sure the PHY driver doesn't suspend */
+       device_init_wakeup(&dev->dev, lp->wol);
+
+       return 0;
+}
+
 static const struct ethtool_ops bfin_mac_ethtool_ops = {
        .get_settings = bfin_mac_ethtool_getsettings,
        .set_settings = bfin_mac_ethtool_setsettings,
        .get_link = ethtool_op_get_link,
        .get_drvinfo = bfin_mac_ethtool_getdrvinfo,
+       .get_wol = bfin_mac_ethtool_getwol,
+       .set_wol = bfin_mac_ethtool_setwol,
 };
 
 /**************************************************************************/
@@ -1474,9 +1528,16 @@ static int __devexit bfin_mac_remove(struct platform_device *pdev)
 static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t mesg)
 {
        struct net_device *net_dev = platform_get_drvdata(pdev);
+       struct bfin_mac_local *lp = netdev_priv(net_dev);
 
-       if (netif_running(net_dev))
-               bfin_mac_close(net_dev);
+       if (lp->wol) {
+               bfin_write_EMAC_OPMODE((bfin_read_EMAC_OPMODE() & ~TE) | RE);
+               bfin_write_EMAC_WKUP_CTL(MPKE);
+               enable_irq_wake(IRQ_MAC_WAKEDET);
+       } else {
+               if (netif_running(net_dev))
+                       bfin_mac_close(net_dev);
+       }
 
        return 0;
 }
@@ -1484,9 +1545,16 @@ static int bfin_mac_suspend(struct platform_device *pdev, pm_message_t mesg)
 static int bfin_mac_resume(struct platform_device *pdev)
 {
        struct net_device *net_dev = platform_get_drvdata(pdev);
+       struct bfin_mac_local *lp = netdev_priv(net_dev);
 
-       if (netif_running(net_dev))
-               bfin_mac_open(net_dev);
+       if (lp->wol) {
+               bfin_write_EMAC_OPMODE(bfin_read_EMAC_OPMODE() | TE);
+               bfin_write_EMAC_WKUP_CTL(0);
+               disable_irq_wake(IRQ_MAC_WAKEDET);
+       } else {
+               if (netif_running(net_dev))
+                       bfin_mac_open(net_dev);
+       }
 
        return 0;
 }
index 87c454fc0319076aae8fa1bd6c2e013ffdb33b71..1ae7b82ceeee716b98c18f7f42d4cd6a6f8ccc74 100644 (file)
@@ -66,6 +66,9 @@ struct bfin_mac_local {
        unsigned char Mac[6];   /* MAC address of the board */
        spinlock_t lock;
 
+       int wol;                /* Wake On Lan */
+       int irq_wake_requested;
+
        /* MII and PHY stuffs */
        int old_link;          /* used by bf537_adjust_link */
        int old_speed;