]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/net/kaweth.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[linux-2.6-omap-h63xx.git] / drivers / usb / net / kaweth.c
index 7c906a43e4973b081b9cdd20d068913e43a930bd..a0cc05d21a6ad66e347861809d2a7b83870a882a 100644 (file)
@@ -46,7 +46,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/init.h>
@@ -179,6 +178,7 @@ static struct usb_driver kaweth_driver = {
        .suspend =      kaweth_suspend,
        .resume =       kaweth_resume,
        .id_table =     usb_klsi_table,
+       .supports_autosuspend = 1,
 };
 
 typedef __u8 eth_addr_t[6];
@@ -222,9 +222,10 @@ struct kaweth_device
        int suspend_lowmem_ctrl;
        int linkstate;
        int opened;
-       struct work_struct lowmem_work;
+       struct delayed_work lowmem_work;
 
        struct usb_device *dev;
+       struct usb_interface *intf;
        struct net_device *net;
        wait_queue_head_t term_wait;
 
@@ -530,9 +531,10 @@ resubmit:
        kaweth_resubmit_int_urb(kaweth, GFP_ATOMIC);
 }
 
-static void kaweth_resubmit_tl(void *d)
+static void kaweth_resubmit_tl(struct work_struct *work)
 {
-       struct kaweth_device *kaweth = (struct kaweth_device *)d;
+       struct kaweth_device *kaweth =
+               container_of(work, struct kaweth_device, lowmem_work.work);
 
        if (IS_BLOCKED(kaweth->status))
                return;
@@ -634,8 +636,6 @@ static void kaweth_usb_receive(struct urb *urb)
 
                skb_reserve(skb, 2);    /* Align IP on 16 byte boundaries */
 
-               skb->dev = net;
-
                eth_copy_and_sum(skb, kaweth->rx_buf + 2, pkt_len, 0);
 
                skb_put(skb, pkt_len);
@@ -661,9 +661,14 @@ static int kaweth_open(struct net_device *net)
 
        dbg("Opening network device.");
 
+       res = usb_autopm_get_interface(kaweth->intf);
+       if (res) {
+               err("Interface cannot be resumed.");
+               return -EIO;
+       }
        res = kaweth_resubmit_rx_urb(kaweth, GFP_KERNEL);
        if (res)
-               return -EIO;
+               goto err_out;
 
        usb_fill_int_urb(
                kaweth->irq_urb,
@@ -680,7 +685,7 @@ static int kaweth_open(struct net_device *net)
        res = usb_submit_urb(kaweth->irq_urb, GFP_KERNEL);
        if (res) {
                usb_kill_urb(kaweth->rx_urb);
-               return -EIO;
+               goto err_out;
        }
        kaweth->opened = 1;
 
@@ -688,10 +693,14 @@ static int kaweth_open(struct net_device *net)
 
        kaweth_async_set_rx_mode(kaweth);
        return 0;
+
+err_out:
+       usb_autopm_enable(kaweth->intf);
+       return -EIO;
 }
 
 /****************************************************************
- *     kaweth_close
+ *     kaweth_kill_urbs
  ****************************************************************/
 static void kaweth_kill_urbs(struct kaweth_device *kaweth)
 {
@@ -723,17 +732,29 @@ static int kaweth_close(struct net_device *net)
 
        kaweth->status &= ~KAWETH_STATUS_CLOSING;
 
+       usb_autopm_enable(kaweth->intf);
+
        return 0;
 }
 
 static void kaweth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
+       struct kaweth_device *kaweth = netdev_priv(dev);
 
        strlcpy(info->driver, driver_name, sizeof(info->driver));
+       usb_make_path(kaweth->dev, info->bus_info, sizeof (info->bus_info));
+}
+
+static u32 kaweth_get_link(struct net_device *dev)
+{
+       struct kaweth_device *kaweth = netdev_priv(dev);
+
+       return kaweth->linkstate;
 }
 
 static struct ethtool_ops ops = {
-       .get_drvinfo = kaweth_get_drvinfo
+       .get_drvinfo    = kaweth_get_drvinfo,
+       .get_link       = kaweth_get_link
 };
 
 /****************************************************************
@@ -907,6 +928,7 @@ static int kaweth_suspend(struct usb_interface *intf, pm_message_t message)
        struct kaweth_device *kaweth = usb_get_intfdata(intf);
        unsigned long flags;
 
+       dbg("Suspending device");
        spin_lock_irqsave(&kaweth->device_lock, flags);
        kaweth->status |= KAWETH_STATUS_SUSPENDING;
        spin_unlock_irqrestore(&kaweth->device_lock, flags);
@@ -923,6 +945,7 @@ static int kaweth_resume(struct usb_interface *intf)
        struct kaweth_device *kaweth = usb_get_intfdata(intf);
        unsigned long flags;
 
+       dbg("Resuming device");
        spin_lock_irqsave(&kaweth->device_lock, flags);
        kaweth->status &= ~KAWETH_STATUS_SUSPENDING;
        spin_unlock_irqrestore(&kaweth->device_lock, flags);
@@ -1085,6 +1108,8 @@ err_fw:
 
        dbg("Initializing net device.");
 
+       kaweth->intf = intf;
+
        kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
        if (!kaweth->tx_urb)
                goto err_free_netdev;
@@ -1126,7 +1151,7 @@ err_fw:
 
        /* kaweth is zeroed as part of alloc_netdev */
 
-       INIT_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl, (void *)kaweth);
+       INIT_DELAYED_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl);
 
        SET_MODULE_OWNER(netdev);
 
@@ -1264,7 +1289,7 @@ static int kaweth_internal_control_msg(struct usb_device *usb_dev,
 {
         struct urb *urb;
         int retv;
-        int length;
+        int length = 0; /* shut up GCC */
 
         urb = usb_alloc_urb(0, GFP_NOIO);
         if (!urb)