fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / net / rtl8150.c
index 8ca52be..670262a 100644 (file)
@@ -6,7 +6,6 @@
  * version 2 as published by the Free Software Foundation.
  */
 
-#include <linux/config.h>
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/signal.h>
 #define        RX_URB_FAIL             3
 
 /* Define these values to match your device */
-#define VENDOR_ID_REALTEK              0x0bda
+#define        VENDOR_ID_REALTEK               0x0bda
 #define        VENDOR_ID_MELCO                 0x0411
-#define VENDOR_ID_MICRONET             0x3980
+#define        VENDOR_ID_MICRONET              0x3980
 #define        VENDOR_ID_LONGSHINE             0x07b8
+#define        VENDOR_ID_OQO                   0x1557
+#define        VENDOR_ID_ZYXEL                 0x0586
 
 #define PRODUCT_ID_RTL8150             0x8150
 #define        PRODUCT_ID_LUAKTX               0x0012
 #define        PRODUCT_ID_LCS8138TX            0x401a
 #define PRODUCT_ID_SP128AR             0x0003
+#define        PRODUCT_ID_PRESTIGE             0x401a
 
 #undef EEPROM_WRITE
 
@@ -143,6 +145,8 @@ static struct usb_device_id rtl8150_table[] = {
        {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
        {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
        {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
+       {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
+       {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
        {}
 };
 
@@ -173,6 +177,8 @@ static inline struct sk_buff *pull_skb(rtl8150_t *);
 static void rtl8150_disconnect(struct usb_interface *intf);
 static int rtl8150_probe(struct usb_interface *intf,
                           const struct usb_device_id *id);
+static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message);
+static int rtl8150_resume(struct usb_interface *intf);
 
 static const char driver_name [] = "rtl8150";
 
@@ -181,6 +187,8 @@ static struct usb_driver rtl8150_driver = {
        .probe =        rtl8150_probe,
        .disconnect =   rtl8150_disconnect,
        .id_table =     rtl8150_table,
+       .suspend =      rtl8150_suspend,
+       .resume =       rtl8150_resume
 };
 
 /*
@@ -202,7 +210,7 @@ static int set_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
                               indx, 0, data, size, 500);
 }
 
-static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
+static void ctrl_callback(struct urb *urb)
 {
        rtl8150_t *dev;
 
@@ -236,9 +244,11 @@ static int async_set_registers(rtl8150_t * dev, u16 indx, u16 size)
        usb_fill_control_urb(dev->ctrl_urb, dev->udev,
                         usb_sndctrlpipe(dev->udev, 0), (char *) &dev->dr,
                         &dev->rx_creg, size, ctrl_callback, dev);
-       if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC)))
+       if ((ret = usb_submit_urb(dev->ctrl_urb, GFP_ATOMIC))) {
+               if (ret == -ENODEV)
+                       netif_device_detach(dev->netdev);
                err("control request submission failed: %d", ret);
-       else
+       else
                set_bit(RX_REG_SET, &dev->flags);
 
        return ret;
@@ -274,7 +284,8 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
        u8 data[3], tmp;
 
        data[0] = phy;
-       *(data + 1) = cpu_to_le16p(&reg);
+       data[1] = reg & 0xff;
+       data[2] = (reg >> 8) & 0xff;
        tmp = indx | PHY_WRITE | PHY_GO;
        i = 0;
 
@@ -407,13 +418,14 @@ static inline struct sk_buff *pull_skb(rtl8150_t *dev)
        return NULL;
 }
 
-static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
+static void read_bulk_callback(struct urb *urb)
 {
        rtl8150_t *dev;
        unsigned pkt_len, res;
        struct sk_buff *skb;
        struct net_device *netdev;
        u16 rx_stat;
+       int status;
 
        dev = urb->context;
        if (!dev)
@@ -429,7 +441,7 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
                break;
        case -ENOENT:
                return; /* the urb is in unlink state */
-       case -ETIMEDOUT:
+       case -ETIME:
                warn("may be reset is needed?..");
                goto goon;
        default:
@@ -463,7 +475,10 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
 goon:
        usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
                      dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
-       if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
+       status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
+       if (status == -ENODEV)
+               netif_device_detach(dev->netdev);
+       else if (status) {
                set_bit(RX_URB_FAIL, &dev->flags);
                goto resched;
        } else {
@@ -479,6 +494,7 @@ static void rx_fixup(unsigned long data)
 {
        rtl8150_t *dev;
        struct sk_buff *skb;
+       int status;
 
        dev = (rtl8150_t *)data;
 
@@ -497,10 +513,13 @@ static void rx_fixup(unsigned long data)
        usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
                      dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
 try_again:
-       if (usb_submit_urb(dev->rx_urb, GFP_ATOMIC)) {
+       status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
+       if (status == -ENODEV) {
+               netif_device_detach(dev->netdev);
+       } else if (status) {
                set_bit(RX_URB_FAIL, &dev->flags);
                goto tlsched;
-        } else {
+       } else {
                clear_bit(RX_URB_FAIL, &dev->flags);
        }
 
@@ -509,7 +528,7 @@ tlsched:
        tasklet_schedule(&dev->tl);
 }
 
-static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
+static void write_bulk_callback(struct urb *urb)
 {
        rtl8150_t *dev;
 
@@ -525,7 +544,7 @@ static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
        netif_wake_queue(dev->netdev);
 }
 
-static void intr_callback(struct urb *urb, struct pt_regs *regs)
+static void intr_callback(struct urb *urb)
 {
        rtl8150_t *dev;
        __u8 *d;
@@ -571,13 +590,44 @@ static void intr_callback(struct urb *urb, struct pt_regs *regs)
        }
 
 resubmit:
-       status = usb_submit_urb (urb, SLAB_ATOMIC);
-       if (status)
+       status = usb_submit_urb (urb, GFP_ATOMIC);
+       if (status == -ENODEV)
+               netif_device_detach(dev->netdev);
+       else if (status)
                err ("can't resubmit intr, %s-%s/input0, status %d",
                                dev->udev->bus->bus_name,
                                dev->udev->devpath, status);
 }
 
+static int rtl8150_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       rtl8150_t *dev = usb_get_intfdata(intf);
+
+       netif_device_detach(dev->netdev);
+
+       if (netif_running(dev->netdev)) {
+               usb_kill_urb(dev->rx_urb);
+               usb_kill_urb(dev->intr_urb);
+       }
+       return 0;
+}
+
+static int rtl8150_resume(struct usb_interface *intf)
+{
+       rtl8150_t *dev = usb_get_intfdata(intf);
+
+       netif_device_attach(dev->netdev);
+       if (netif_running(dev->netdev)) {
+               dev->rx_urb->status = 0;
+               dev->rx_urb->actual_length = 0;
+               read_bulk_callback(dev->rx_urb);
+
+               dev->intr_urb->status = 0;
+               dev->intr_urb->actual_length = 0;
+               intr_callback(dev->intr_urb);
+       }
+       return 0;
+}
 
 /*
 **
@@ -688,9 +738,14 @@ static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
        usb_fill_bulk_urb(dev->tx_urb, dev->udev, usb_sndbulkpipe(dev->udev, 2),
                      skb->data, count, write_bulk_callback, dev);
        if ((res = usb_submit_urb(dev->tx_urb, GFP_ATOMIC))) {
-               warn("failed tx_urb %d\n", res);
-               dev->stats.tx_errors++;
-               netif_start_queue(netdev);
+               /* Can we get/handle EPIPE here? */
+               if (res == -ENODEV)
+                       netif_device_detach(dev->netdev);
+               else {
+                       warn("failed tx_urb %d\n", res);
+                       dev->stats.tx_errors++;
+                       netif_start_queue(netdev);
+               }
        } else {
                dev->stats.tx_packets++;
                dev->stats.tx_bytes += skb->len;
@@ -727,16 +782,25 @@ static int rtl8150_open(struct net_device *netdev)
        
        usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
                      dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
-       if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL)))
+       if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
+               if (res == -ENODEV)
+                       netif_device_detach(dev->netdev);
                warn("%s: rx_urb submit failed: %d", __FUNCTION__, res);
+               return res;
+       }
        usb_fill_int_urb(dev->intr_urb, dev->udev, usb_rcvintpipe(dev->udev, 3),
                     dev->intr_buff, INTBUFSIZE, intr_callback,
                     dev, dev->intr_interval);
-       if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL)))
+       if ((res = usb_submit_urb(dev->intr_urb, GFP_KERNEL))) {
+               if (res == -ENODEV)
+                       netif_device_detach(dev->netdev);
                warn("%s: intr_urb submit failed: %d", __FUNCTION__, res);
-       netif_start_queue(netdev);
+               usb_kill_urb(dev->rx_urb);
+               return res;
+       }
        enable_net_traffic(dev);
        set_carrier(netdev);
+       netif_start_queue(netdev);
 
        return res;
 }
@@ -880,7 +944,6 @@ static int rtl8150_probe(struct usb_interface *intf,
        }
        fill_skb_pool(dev);
        set_ethernet_addr(dev);
-       info("%s: rtl8150 is detected", netdev->name);
        
        usb_set_intfdata(intf, dev);
        SET_NETDEV_DEV(netdev, &intf->dev);
@@ -888,6 +951,9 @@ static int rtl8150_probe(struct usb_interface *intf,
                err("couldn't register the device");
                goto out2;
        }
+
+       info("%s: rtl8150 is detected", netdev->name);
+
        return 0;
 
 out2:
@@ -909,6 +975,7 @@ static void rtl8150_disconnect(struct usb_interface *intf)
        if (dev) {
                set_bit(RTL8150_UNPLUG, &dev->flags);
                tasklet_disable(&dev->tl);
+               tasklet_kill(&dev->tl);
                unregister_netdev(dev->netdev);
                unlink_all_urbs(dev);
                free_all_urbs(dev);