fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / net / pegasus.c
index 5174c9f..d48c024 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 1999-2003 Petko Manolov (petkan@users.sourceforge.net)
+ *  Copyright (c) 1999-2005 Petko Manolov (petkan@users.sourceforge.net)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -45,7 +45,7 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v0.5.12 (2003/06/06)"
+#define DRIVER_VERSION "v0.6.14 (2006/09/27)"
 #define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
 #define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
 
@@ -57,13 +57,14 @@ static const char driver_name[] = "pegasus";
 
 static int loopback = 0;
 static int mii_mode = 0;
-static int multicast_filter_limit = 32;
+static char *devid=NULL;
 
 static struct usb_eth_dev usb_dev_id[] = {
 #define        PEGASUS_DEV(pn, vid, pid, flags)        \
        {.name = pn, .vendor = vid, .device = pid, .private = flags},
 #include "pegasus.h"
 #undef PEGASUS_DEV
+       {NULL, 0, 0, 0},
        {NULL, 0, 0, 0}
 };
 
@@ -72,22 +73,30 @@ static struct usb_device_id pegasus_ids[] = {
        {.match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = vid, .idProduct = pid},
 #include "pegasus.h"
 #undef PEGASUS_DEV
+       {},
        {}
 };
 
 MODULE_AUTHOR(DRIVER_AUTHOR);
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_LICENSE("GPL");
-MODULE_PARM(loopback, "i");
-MODULE_PARM(mii_mode, "i");
+module_param(loopback, bool, 0);
+module_param(mii_mode, bool, 0);
+module_param(devid, charp, 0);
 MODULE_PARM_DESC(loopback, "Enable MAC loopback mode (bit 0)");
 MODULE_PARM_DESC(mii_mode, "Enable HomePNA mode (bit 0),default=MII mode = 0");
+MODULE_PARM_DESC(devid, "The format is: 'DEV_name:VendorID:DeviceID:Flags'");
+
+/* use ethtool to change the level for any given device */
+static int msg_level = -1;
+module_param (msg_level, int, 0);
+MODULE_PARM_DESC (msg_level, "Override default message level");
 
 MODULE_DEVICE_TABLE(usb, pegasus_ids);
 
 static int update_eth_regs_async(pegasus_t *);
 /* Aargh!!! I _really_ hate such tweaks */
-static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
+static void ctrl_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
 
@@ -108,7 +117,9 @@ static void ctrl_callback(struct urb *urb, struct pt_regs *regs)
        case -ENOENT:
                break;
        default:
-               warn("%s: status %d", __FUNCTION__, urb->status);
+               if (netif_msg_drv(pegasus))
+                       dev_dbg(&pegasus->intf->dev, "%s, status %d\n",
+                               __FUNCTION__, urb->status);
        }
        pegasus->flags &= ~ETH_REGS_CHANGED;
        wake_up(&pegasus->ctrl_wait);
@@ -123,7 +134,9 @@ static int get_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
 
        buffer = kmalloc(size, GFP_KERNEL);
        if (!buffer) {
-               warn("%s: looks like we're out of memory", __FUNCTION__);
+               if (netif_msg_drv(pegasus))
+                       dev_warn(&pegasus->intf->dev, "out of memory in %s\n",
+                                       __FUNCTION__);
                return -ENOMEM;
        }
        add_wait_queue(&pegasus->ctrl_wait, &wait);
@@ -150,7 +163,12 @@ static int get_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
 
        /* using ATOMIC, we'd never wake up if we slept */
        if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
-               err("%s: BAD CTRLs %d", __FUNCTION__, ret);
+               set_current_state(TASK_RUNNING);
+               if (ret == -ENODEV)
+                       netif_device_detach(pegasus->net);
+               if (netif_msg_drv(pegasus))
+                       dev_err(&pegasus->intf->dev, "%s, status %d\n",
+                                       __FUNCTION__, ret);
                goto out;
        }
 
@@ -172,7 +190,9 @@ static int set_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
 
        buffer = kmalloc(size, GFP_KERNEL);
        if (!buffer) {
-               warn("%s: looks like we're out of memory", __FUNCTION__);
+               if (netif_msg_drv(pegasus))
+                       dev_warn(&pegasus->intf->dev, "out of memory in %s\n",
+                                       __FUNCTION__);
                return -ENOMEM;
        }
        memcpy(buffer, data, size);
@@ -200,7 +220,11 @@ static int set_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
        set_current_state(TASK_UNINTERRUPTIBLE);
 
        if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
-               err("%s: BAD CTRL %d", __FUNCTION__, ret);
+               if (ret == -ENODEV)
+                       netif_device_detach(pegasus->net);
+               if (netif_msg_drv(pegasus))
+                       dev_err(&pegasus->intf->dev, "%s, status %d\n",
+                                       __FUNCTION__, ret);
                goto out;
        }
 
@@ -220,7 +244,9 @@ static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
 
        tmp = kmalloc(1, GFP_KERNEL);
        if (!tmp) {
-               warn("%s: looks like we're out of memory", __FUNCTION__);
+               if (netif_msg_drv(pegasus))
+                       dev_warn(&pegasus->intf->dev, "out of memory in %s\n",
+                                       __FUNCTION__);
                return -ENOMEM;
        }
        memcpy(tmp, &data, 1);
@@ -241,13 +267,17 @@ static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
        usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
                             usb_sndctrlpipe(pegasus->usb, 0),
                             (char *) &pegasus->dr,
-                            &tmp, 1, ctrl_callback, pegasus);
+                            tmp, 1, ctrl_callback, pegasus);
 
        add_wait_queue(&pegasus->ctrl_wait, &wait);
        set_current_state(TASK_UNINTERRUPTIBLE);
 
        if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
-               err("%s: BAD CTRL %d", __FUNCTION__, ret);
+               if (ret == -ENODEV)
+                       netif_device_detach(pegasus->net);
+               if (netif_msg_drv(pegasus))
+                       dev_err(&pegasus->intf->dev, "%s, status %d\n",
+                                       __FUNCTION__, ret);
                goto out;
        }
 
@@ -275,9 +305,13 @@ static int update_eth_regs_async(pegasus_t * pegasus)
                             (char *) &pegasus->dr,
                             pegasus->eth_regs, 3, ctrl_callback, pegasus);
 
-       if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC)))
-               err("%s: BAD CTRL %d, flgs %x", __FUNCTION__, ret,
-                   pegasus->flags);
+       if ((ret = usb_submit_urb(pegasus->ctrl_urb, GFP_ATOMIC))) {
+               if (ret == -ENODEV)
+                       netif_device_detach(pegasus->net);
+               if (netif_msg_drv(pegasus))
+                       dev_err(&pegasus->intf->dev, "%s, status %d\n",
+                                       __FUNCTION__, ret);
+       }
 
        return ret;
 }
@@ -286,59 +320,70 @@ static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
 {
        int i;
        __u8 data[4] = { phy, 0, 0, indx };
-       __u16 regdi;
+       __le16 regdi;
+       int ret;
 
        set_register(pegasus, PhyCtrl, 0);
        set_registers(pegasus, PhyAddr, sizeof (data), data);
        set_register(pegasus, PhyCtrl, (indx | PHY_READ));
        for (i = 0; i < REG_TIMEOUT; i++) {
-               get_registers(pegasus, PhyCtrl, 1, data);
+               ret = get_registers(pegasus, PhyCtrl, 1, data);
+               if (ret == -ESHUTDOWN)
+                       goto fail;
                if (data[0] & PHY_DONE)
                        break;
        }
        if (i < REG_TIMEOUT) {
-               get_registers(pegasus, PhyData, 2, &regdi);
+               ret = get_registers(pegasus, PhyData, 2, &regdi);
                *regd = le16_to_cpu(regdi);
-               return 0;
+               return ret;
        }
-       warn("%s: failed", __FUNCTION__);
+fail:
+       if (netif_msg_drv(pegasus))
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
 
-       return 1;
+       return ret;
 }
 
 static int mdio_read(struct net_device *dev, int phy_id, int loc)
 {
-       pegasus_t *pegasus = (pegasus_t *) dev->priv;
-       int res;
+       pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
+       u16 res;
 
-       read_mii_word(pegasus, phy_id, loc, (u16 *) & res);
-       return res & 0xffff;
+       read_mii_word(pegasus, phy_id, loc, &res);
+       return (int)res;
 }
 
 static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
 {
        int i;
        __u8 data[4] = { phy, 0, 0, indx };
+       int ret;
 
-       *(data + 1) = cpu_to_le16p(&regd);
+       data[1] = (u8) regd;
+       data[2] = (u8) (regd >> 8);
        set_register(pegasus, PhyCtrl, 0);
-       set_registers(pegasus, PhyAddr, 4, data);
+       set_registers(pegasus, PhyAddr, sizeof(data), data);
        set_register(pegasus, PhyCtrl, (indx | PHY_WRITE));
        for (i = 0; i < REG_TIMEOUT; i++) {
-               get_registers(pegasus, PhyCtrl, 1, data);
+               ret = get_registers(pegasus, PhyCtrl, 1, data);
+               if (ret == -ESHUTDOWN)
+                       goto fail;
                if (data[0] & PHY_DONE)
                        break;
        }
        if (i < REG_TIMEOUT)
-               return 0;
-       warn("%s: failed", __FUNCTION__);
+               return ret;
 
-       return 1;
+fail:
+       if (netif_msg_drv(pegasus))
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
+       return -ETIMEDOUT;
 }
 
 static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
 {
-       pegasus_t *pegasus = (pegasus_t *) dev->priv;
+       pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
 
        write_mii_word(pegasus, phy_id, loc, val);
 }
@@ -347,31 +392,37 @@ static int read_eprom_word(pegasus_t * pegasus, __u8 index, __u16 * retdata)
 {
        int i;
        __u8 tmp;
-       __u16 retdatai;
+       __le16 retdatai;
+       int ret;
 
        set_register(pegasus, EpromCtrl, 0);
        set_register(pegasus, EpromOffset, index);
        set_register(pegasus, EpromCtrl, EPROM_READ);
 
        for (i = 0; i < REG_TIMEOUT; i++) {
-               get_registers(pegasus, EpromCtrl, 1, &tmp);
+               ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
                if (tmp & EPROM_DONE)
                        break;
+               if (ret == -ESHUTDOWN)
+                       goto fail;
        }
        if (i < REG_TIMEOUT) {
-               get_registers(pegasus, EpromData, 2, &retdatai);
+               ret = get_registers(pegasus, EpromData, 2, &retdatai);
                *retdata = le16_to_cpu(retdatai);
-               return 0;
+               return ret;
        }
-       warn("%s: failed", __FUNCTION__);
 
-       return -1;
+fail:
+       if (netif_msg_drv(pegasus))
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
+       return -ETIMEDOUT;
 }
 
 #ifdef PEGASUS_WRITE_EEPROM
 static inline void enable_eprom_write(pegasus_t * pegasus)
 {
        __u8 tmp;
+       int ret;
 
        get_registers(pegasus, EthCtrl2, 1, &tmp);
        set_register(pegasus, EthCtrl2, tmp | EPROM_WR_ENABLE);
@@ -380,6 +431,7 @@ static inline void enable_eprom_write(pegasus_t * pegasus)
 static inline void disable_eprom_write(pegasus_t * pegasus)
 {
        __u8 tmp;
+       int ret;
 
        get_registers(pegasus, EthCtrl2, 1, &tmp);
        set_register(pegasus, EpromCtrl, 0);
@@ -388,8 +440,9 @@ static inline void disable_eprom_write(pegasus_t * pegasus)
 
 static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
 {
-       int i, tmp;
-       __u8 d[4] = { 0x3f, 0, 0, EPROM_WRITE };
+       int i;
+       __u8 tmp, d[4] = { 0x3f, 0, 0, EPROM_WRITE };
+       int ret;
 
        set_registers(pegasus, EpromOffset, 4, d);
        enable_eprom_write(pegasus);
@@ -398,15 +451,19 @@ static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
        set_register(pegasus, EpromCtrl, EPROM_WRITE);
 
        for (i = 0; i < REG_TIMEOUT; i++) {
-               get_registers(pegasus, EpromCtrl, 1, &tmp);
+               ret = get_registers(pegasus, EpromCtrl, 1, &tmp);
+               if (ret == -ESHUTDOWN)
+                       goto fail;
                if (tmp & EPROM_DONE)
                        break;
        }
        disable_eprom_write(pegasus);
        if (i < REG_TIMEOUT)
-               return 0;
-       warn("%s: failed", __FUNCTION__);
-       return -1;
+               return ret;
+fail:
+       if (netif_msg_drv(pegasus))
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
+       return -ETIMEDOUT;
 }
 #endif                         /* PEGASUS_WRITE_EEPROM */
 
@@ -417,7 +474,7 @@ static inline void get_node_id(pegasus_t * pegasus, __u8 * id)
 
        for (i = 0; i < 3; i++) {
                read_eprom_word(pegasus, i, &w16);
-               ((__u16 *) id)[i] = cpu_to_le16p(&w16);
+               ((__le16 *) id)[i] = cpu_to_le16p(&w16);
        }
 }
 
@@ -425,8 +482,12 @@ static void set_ethernet_addr(pegasus_t * pegasus)
 {
        __u8 node_id[6];
 
-       get_node_id(pegasus, node_id);
-       set_registers(pegasus, EthID, sizeof (node_id), node_id);
+       if (pegasus->features & PEGASUS_II) {
+               get_registers(pegasus, 0x10, sizeof(node_id), node_id);
+       } else {
+               get_node_id(pegasus, node_id);
+               set_registers(pegasus, EthID, sizeof (node_id), node_id);
+       }
        memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id));
 }
 
@@ -451,7 +512,7 @@ static inline int reset_mac(pegasus_t * pegasus)
                }
        }
        if (i == REG_TIMEOUT)
-               return 1;
+               return -ETIMEDOUT;
 
        if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
            usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
@@ -471,7 +532,8 @@ static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
 {
        __u16 linkpart;
        __u8 data[4];
-       pegasus_t *pegasus = dev->priv;
+       pegasus_t *pegasus = netdev_priv(dev);
+       int ret;
 
        read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
        data[0] = 0xc9;
@@ -485,16 +547,17 @@ static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
        data[2] = (loopback & 1) ? 0x09 : 0x01;
 
        memcpy(pegasus->eth_regs, data, sizeof (data));
-       set_registers(pegasus, EthCtrl0, 3, data);
+       ret = set_registers(pegasus, EthCtrl0, 3, data);
 
        if (usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS ||
+           usb_dev_id[pegasus->dev_index].vendor == VENDOR_LINKSYS2 ||
            usb_dev_id[pegasus->dev_index].vendor == VENDOR_DLINK) {
                u16 auxmode;
                read_mii_word(pegasus, 0, 0x1b, &auxmode);
                write_mii_word(pegasus, 0, 0x1b, auxmode | 4);
        }
 
-       return 0;
+       return ret;
 }
 
 static void fill_skb_pool(pegasus_t * pegasus)
@@ -543,64 +606,82 @@ static inline struct sk_buff *pull_skb(pegasus_t * pegasus)
        return NULL;
 }
 
-static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
+static void read_bulk_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
        struct net_device *net;
        int rx_status, count = urb->actual_length;
+       u8 *buf = urb->transfer_buffer;
        __u16 pkt_len;
 
-       if (!pegasus || !(pegasus->flags & PEGASUS_RUNNING))
+       if (!pegasus)
                return;
 
        net = pegasus->net;
-       if (!netif_device_present(net))
+       if (!netif_device_present(net) || !netif_running(net))
                return;
 
        switch (urb->status) {
        case 0:
                break;
-       case -ETIMEDOUT:
-               dbg("%s: reset MAC", net->name);
+       case -ETIME:
+               if (netif_msg_rx_err(pegasus))
+                       pr_debug("%s: reset MAC\n", net->name);
                pegasus->flags &= ~PEGASUS_RX_BUSY;
                break;
        case -EPIPE:            /* stall, or disconnect from TT */
                /* FIXME schedule work to clear the halt */
-               warn("%s: no rx stall recovery", net->name);
+               if (netif_msg_rx_err(pegasus))
+                       printk(KERN_WARNING "%s: no rx stall recovery\n",
+                                       net->name);
                return;
        case -ENOENT:
        case -ECONNRESET:
        case -ESHUTDOWN:
-               dbg("%s: rx unlink, %d", net->name, urb->status);
+               if (netif_msg_ifdown(pegasus))
+                       pr_debug("%s: rx unlink, %d\n", net->name, urb->status);
                return;
        default:
-               dbg("%s: RX status %d", net->name, urb->status);
+               if (netif_msg_rx_err(pegasus))
+                       pr_debug("%s: RX status %d\n", net->name, urb->status);
                goto goon;
        }
 
-       if (!count)
+       if (!count || count < 4)
                goto goon;
 
-       rx_status = le32_to_cpu(*(int *) (urb->transfer_buffer + count - 4));
-       if (rx_status & 0x000e0000) {
-               dbg("%s: RX packet error %x", net->name, rx_status & 0xe0000);
+       rx_status = buf[count - 2];
+       if (rx_status & 0x1e) {
+               if (netif_msg_rx_err(pegasus))
+                       pr_debug("%s: RX packet error %x\n",
+                                       net->name, rx_status);
                pegasus->stats.rx_errors++;
-               if (rx_status & 0x060000)
+               if (rx_status & 0x06)   // long or runt
                        pegasus->stats.rx_length_errors++;
-               if (rx_status & 0x080000)
+               if (rx_status & 0x08)
                        pegasus->stats.rx_crc_errors++;
-               if (rx_status & 0x100000)
+               if (rx_status & 0x10)   // extra bits
                        pegasus->stats.rx_frame_errors++;
                goto goon;
        }
        if (pegasus->chip == 0x8513) {
-               pkt_len = le32_to_cpu(*(int *)urb->transfer_buffer);
+               pkt_len = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
                pkt_len &= 0x0fff;
                pegasus->rx_skb->data += 2;
        } else {
-               pkt_len = (rx_status & 0xfff) - 8;
+               pkt_len = buf[count - 3] << 8;
+               pkt_len += buf[count - 4];
+               pkt_len &= 0xfff;
+               pkt_len -= 8;
        }
 
+       /*
+        * If the packet is unreasonably long, quietly drop it rather than
+        * kernel panicing by calling skb_put.
+        */
+       if (pkt_len > PEGASUS_MTU)
+               goto goon;
+
        /*
         * at this point we are sure pegasus->rx_skb != NULL
         * so we go ahead and pass up the packet.
@@ -625,7 +706,10 @@ goon:
                          usb_rcvbulkpipe(pegasus->usb, 1),
                          pegasus->rx_skb->data, PEGASUS_MTU + 8,
                          read_bulk_callback, pegasus);
-       if (usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC)) {
+       rx_status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
+       if (rx_status == -ENODEV)
+               netif_device_detach(pegasus->net);
+       else if (rx_status) {
                pegasus->flags |= PEGASUS_RX_URB_FAIL;
                goto tl_sched;
        } else {
@@ -634,7 +718,7 @@ goon:
 
        return;
 
-      tl_sched:
+tl_sched:
        tasklet_schedule(&pegasus->rx_tl);
 }
 
@@ -642,6 +726,7 @@ static void rx_fixup(unsigned long data)
 {
        pegasus_t *pegasus;
        unsigned long flags;
+       int status;
 
        pegasus = (pegasus_t *) data;
        if (pegasus->flags & PEGASUS_UNPLUG)
@@ -656,7 +741,9 @@ static void rx_fixup(unsigned long data)
                pegasus->rx_skb = pull_skb(pegasus);
        }
        if (pegasus->rx_skb == NULL) {
-               warn("wow, low on memory");
+               if (netif_msg_rx_err(pegasus))
+                       printk(KERN_WARNING "%s: low on memory\n",
+                                       pegasus->net->name);
                tasklet_schedule(&pegasus->rx_tl);
                goto done;
        }
@@ -665,7 +752,10 @@ static void rx_fixup(unsigned long data)
                          pegasus->rx_skb->data, PEGASUS_MTU + 8,
                          read_bulk_callback, pegasus);
 try_again:
-       if (usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC)) {
+       status = usb_submit_urb(pegasus->rx_urb, GFP_ATOMIC);
+       if (status == -ENODEV)
+               netif_device_detach(pegasus->net);
+       else if (status) {
                pegasus->flags |= PEGASUS_RX_URB_FAIL;
                tasklet_schedule(&pegasus->rx_tl);
        } else {
@@ -675,30 +765,34 @@ done:
        spin_unlock_irqrestore(&pegasus->rx_pool_lock, flags);
 }
 
-static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
+static void write_bulk_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
        struct net_device *net = pegasus->net;
 
-       if (!pegasus || !(pegasus->flags & PEGASUS_RUNNING))
+       if (!pegasus)
                return;
 
-       if (!netif_device_present(net))
+       if (!netif_device_present(net) || !netif_running(net))
                return;
 
        switch (urb->status) {
        case -EPIPE:
                /* FIXME schedule_work() to clear the tx halt */
                netif_stop_queue(net);
-               warn("%s: no tx stall recovery", net->name);
+               if (netif_msg_tx_err(pegasus))
+                       printk(KERN_WARNING "%s: no tx stall recovery\n",
+                                       net->name);
                return;
        case -ENOENT:
        case -ECONNRESET:
        case -ESHUTDOWN:
-               dbg("%s: tx unlink, %d", net->name, urb->status);
+               if (netif_msg_ifdown(pegasus))
+                       pr_debug("%s: tx unlink, %d\n", net->name, urb->status);
                return;
        default:
-               info("%s: TX status %d", net->name, urb->status);
+               if (netif_msg_tx_err(pegasus))
+                       pr_info("%s: TX status %d\n", net->name, urb->status);
                /* FALL THROUGH */
        case 0:
                break;
@@ -708,15 +802,15 @@ static void write_bulk_callback(struct urb *urb, struct pt_regs *regs)
        netif_wake_queue(net);
 }
 
-static void intr_callback(struct urb *urb, struct pt_regs *regs)
+static void intr_callback(struct urb *urb)
 {
        pegasus_t *pegasus = urb->context;
        struct net_device *net;
-       __u8 *d;
        int status;
 
        if (!pegasus)
                return;
+       net = pegasus->net;
 
        switch (urb->status) {
        case 0:
@@ -726,67 +820,84 @@ static void intr_callback(struct urb *urb, struct pt_regs *regs)
        case -ESHUTDOWN:
                return;
        default:
-               info("intr status %d", urb->status);
+               /* some Pegasus-I products report LOTS of data
+                * toggle errors... avoid log spamming
+                */
+               if (netif_msg_timer(pegasus))
+                       pr_debug("%s: intr status %d\n", net->name,
+                                       urb->status);
        }
 
-       d = urb->transfer_buffer;
-       net = pegasus->net;
-       if (d[0] & 0xfc) {
-               pegasus->stats.tx_errors++;
-               if (d[0] & TX_UNDERRUN)
-                       pegasus->stats.tx_fifo_errors++;
-               if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
-                       pegasus->stats.tx_aborted_errors++;
-               if (d[0] & LATE_COL)
-                       pegasus->stats.tx_window_errors++;
-               if (d[5] & LINK_STATUS) {
-                       netif_carrier_on(net);
-               } else {
-                       pegasus->stats.tx_carrier_errors++;
-                       netif_carrier_off(net); 
+       if (urb->actual_length >= 6) {
+               u8      * d = urb->transfer_buffer;
+
+               /* byte 0 == tx_status1, reg 2B */
+               if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
+                                       |LATE_COL|JABBER_TIMEOUT)) {
+                       pegasus->stats.tx_errors++;
+                       if (d[0] & TX_UNDERRUN)
+                               pegasus->stats.tx_fifo_errors++;
+                       if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
+                               pegasus->stats.tx_aborted_errors++;
+                       if (d[0] & LATE_COL)
+                               pegasus->stats.tx_window_errors++;
                }
+
+               /* d[5].LINK_STATUS lies on some adapters.
+                * d[0].NO_CARRIER kicks in only with failed TX.
+                * ... so monitoring with MII may be safest.
+                */
+               if (d[0] & NO_CARRIER)
+                       netif_carrier_off(net); 
+               else
+                       netif_carrier_on(net);
+
+               /* bytes 3-4 == rx_lostpkt, reg 2E/2F */
+               pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
        }
 
-       status = usb_submit_urb(urb, SLAB_ATOMIC);
-       if (status)
-               err("%s: can't resubmit interrupt urb, %d", net->name, status);
+       status = usb_submit_urb(urb, GFP_ATOMIC);
+       if (status == -ENODEV)
+               netif_device_detach(pegasus->net);
+       if (status && netif_msg_timer(pegasus))
+               printk(KERN_ERR "%s: can't resubmit interrupt urb, %d\n",
+                               net->name, status);
 }
 
 static void pegasus_tx_timeout(struct net_device *net)
 {
-       pegasus_t *pegasus = net->priv;
-
-       if (!pegasus)
-               return;
-
-       warn("%s: Tx timed out.", net->name);
-       pegasus->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
+       pegasus_t *pegasus = netdev_priv(net);
+       if (netif_msg_timer(pegasus))
+               printk(KERN_WARNING "%s: tx timeout\n", net->name);
        usb_unlink_urb(pegasus->tx_urb);
        pegasus->stats.tx_errors++;
 }
 
 static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
 {
-       pegasus_t *pegasus = net->priv;
+       pegasus_t *pegasus = netdev_priv(net);
        int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
        int res;
        __u16 l16 = skb->len;
 
        netif_stop_queue(net);
 
-       ((__u16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
+       ((__le16 *) pegasus->tx_buff)[0] = cpu_to_le16(l16);
        memcpy(pegasus->tx_buff + 2, skb->data, skb->len);
        usb_fill_bulk_urb(pegasus->tx_urb, pegasus->usb,
                          usb_sndbulkpipe(pegasus->usb, 2),
                          pegasus->tx_buff, count,
                          write_bulk_callback, pegasus);
        if ((res = usb_submit_urb(pegasus->tx_urb, GFP_ATOMIC))) {
-               warn("failed tx_urb %d", res);
+               if (netif_msg_tx_err(pegasus))
+                       printk(KERN_WARNING "%s: fail tx, %d\n",
+                                       net->name, res);
                switch (res) {
                case -EPIPE:            /* stall, or disconnect from TT */
                        /* cleanup should already have been scheduled */
                        break;
                case -ENODEV:           /* disconnect() upcoming */
+                       netif_device_detach(pegasus->net);
                        break;
                default:
                        pegasus->stats.tx_errors++;
@@ -804,7 +915,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
 
 static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
 {
-       return &((pegasus_t *) dev->priv)->stats;
+       return &((pegasus_t *) netdev_priv(dev))->stats;
 }
 
 static inline void disable_net_traffic(pegasus_t * pegasus)
@@ -819,29 +930,33 @@ static inline void get_interrupt_interval(pegasus_t * pegasus)
        __u8 data[2];
 
        read_eprom_word(pegasus, 4, (__u16 *) data);
-       if (data[1] < 0x80) {
-               info("intr interval will be changed from %ums to %ums",
-                    data[1], 0x80);
-               data[1] = 0x80;
-#ifdef PEGASUS_WRITE_EEPROM
-               write_eprom_word(pegasus, 4, *(__u16 *) data);
+       if (pegasus->usb->speed != USB_SPEED_HIGH) {
+               if (data[1] < 0x80) {
+                       if (netif_msg_timer(pegasus))
+                               dev_info(&pegasus->intf->dev, "intr interval "
+                                       "changed from %ums to %ums\n",
+                                       data[1], 0x80);
+                       data[1] = 0x80;
+#ifdef PEGASUS_WRITE_EEPROM
+                       write_eprom_word(pegasus, 4, *(__u16 *) data);
 #endif
+               }
        }
        pegasus->intr_interval = data[1];
 }
 
 static void set_carrier(struct net_device *net)
 {
-       pegasus_t *pegasus;
-       short tmp;
+       pegasus_t *pegasus = netdev_priv(net);
+       u16 tmp;
+
+       if (!read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp))
+               return;
 
-       pegasus = net->priv;
-       read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp);
        if (tmp & BMSR_LSTATUS)
                netif_carrier_on(net);
        else
                netif_carrier_off(net);
-
 }
 
 static void free_all_urbs(pegasus_t * pegasus)
@@ -854,10 +969,10 @@ static void free_all_urbs(pegasus_t * pegasus)
 
 static void unlink_all_urbs(pegasus_t * pegasus)
 {
-       usb_unlink_urb(pegasus->intr_urb);
-       usb_unlink_urb(pegasus->tx_urb);
-       usb_unlink_urb(pegasus->rx_urb);
-       usb_unlink_urb(pegasus->ctrl_urb);
+       usb_kill_urb(pegasus->intr_urb);
+       usb_kill_urb(pegasus->tx_urb);
+       usb_kill_urb(pegasus->rx_urb);
+       usb_kill_urb(pegasus->ctrl_urb);
 }
 
 static int alloc_urbs(pegasus_t * pegasus)
@@ -890,7 +1005,7 @@ static int alloc_urbs(pegasus_t * pegasus)
 
 static int pegasus_open(struct net_device *net)
 {
-       pegasus_t *pegasus = (pegasus_t *) net->priv;
+       pegasus_t *pegasus = netdev_priv(net);
        int res;
 
        if (pegasus->rx_skb == NULL)
@@ -901,31 +1016,46 @@ static int pegasus_open(struct net_device *net)
        if (!pegasus->rx_skb)
                return -ENOMEM;
 
-       set_registers(pegasus, EthID, 6, net->dev_addr);
+       res = set_registers(pegasus, EthID, 6, net->dev_addr);
        
        usb_fill_bulk_urb(pegasus->rx_urb, pegasus->usb,
                          usb_rcvbulkpipe(pegasus->usb, 1),
                          pegasus->rx_skb->data, PEGASUS_MTU + 8,
                          read_bulk_callback, pegasus);
-       if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL)))
-               warn("%s: failed rx_urb %d", __FUNCTION__, res);
+       if ((res = usb_submit_urb(pegasus->rx_urb, GFP_KERNEL))) {
+               if (res == -ENODEV)
+                       netif_device_detach(pegasus->net);
+               if (netif_msg_ifup(pegasus))
+                       pr_debug("%s: failed rx_urb, %d", net->name, res);
+               goto exit;
+       }
+
        usb_fill_int_urb(pegasus->intr_urb, pegasus->usb,
                         usb_rcvintpipe(pegasus->usb, 3),
                         pegasus->intr_buff, sizeof (pegasus->intr_buff),
                         intr_callback, pegasus, pegasus->intr_interval);
-       if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL)))
-               warn("%s: failed intr_urb %d", __FUNCTION__, res);
-       netif_start_queue(net);
-       pegasus->flags |= PEGASUS_RUNNING;
+       if ((res = usb_submit_urb(pegasus->intr_urb, GFP_KERNEL))) {
+               if (res == -ENODEV)
+                       netif_device_detach(pegasus->net);
+               if (netif_msg_ifup(pegasus))
+                       pr_debug("%s: failed intr_urb, %d\n", net->name, res);
+               usb_kill_urb(pegasus->rx_urb);
+               goto exit;
+       }
        if ((res = enable_net_traffic(net, pegasus->usb))) {
-               err("can't enable_net_traffic() - %d", res);
+               if (netif_msg_ifup(pegasus))
+                       pr_debug("%s: can't enable_net_traffic() - %d\n",
+                                       net->name, res);
                res = -EIO;
-               usb_unlink_urb(pegasus->rx_urb);
-               usb_unlink_urb(pegasus->intr_urb);
+               usb_kill_urb(pegasus->rx_urb);
+               usb_kill_urb(pegasus->intr_urb);
                free_skb_pool(pegasus);
                goto exit;
        }
        set_carrier(net);
+       netif_start_queue(net);
+       if (netif_msg_ifup(pegasus))
+               pr_debug("%s: open\n", net->name);
        res = 0;
 exit:
        return res;
@@ -933,9 +1063,8 @@ exit:
 
 static int pegasus_close(struct net_device *net)
 {
-       pegasus_t *pegasus = net->priv;
+       pegasus_t *pegasus = netdev_priv(net);
 
-       pegasus->flags &= ~PEGASUS_RUNNING;
        netif_stop_queue(net);
        if (!(pegasus->flags & PEGASUS_UNPLUG))
                disable_net_traffic(pegasus);
@@ -944,177 +1073,122 @@ static int pegasus_close(struct net_device *net)
 
        return 0;
 }
-#ifdef CONFIG_MII
-static int pegasus_ethtool_ioctl(struct net_device *dev, void __user *useraddr)
-{
 
-       u32 ethcmd;
-       pegasus_t *pegasus = dev->priv;
-
-       if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
-               return -EFAULT;
-
-       switch (ethcmd) {
-       /* get driver-specific version/etc. info */
-       case ETHTOOL_GDRVINFO:{
-                       struct ethtool_drvinfo info;
-                       memset (&info, 0, sizeof (info));
-                       info.cmd = ETHTOOL_GDRVINFO;
-                       strncpy(info.driver, driver_name,
-                               sizeof (info.driver) - 1);
-                       strncpy(info.version, DRIVER_VERSION,
-                               sizeof (info.version) - 1);
-                       usb_make_path(pegasus->usb, info.bus_info,
-                                     sizeof (info.bus_info));
-                       if (copy_to_user(useraddr, &info, sizeof (info)))
-                               return -EFAULT;
-                       return 0;
-               }
+static void pegasus_get_drvinfo(struct net_device *dev,
+                               struct ethtool_drvinfo *info)
+{
+       pegasus_t *pegasus = netdev_priv(dev);
+       strncpy(info->driver, driver_name, sizeof (info->driver) - 1);
+       strncpy(info->version, DRIVER_VERSION, sizeof (info->version) - 1);
+       usb_make_path(pegasus->usb, info->bus_info, sizeof (info->bus_info));
+}
 
-       /* get settings */
-       case ETHTOOL_GSET:{
-                       struct ethtool_cmd ecmd = { ETHTOOL_GSET };
-                       mii_ethtool_gset(&pegasus->mii, &ecmd);
-                       if (copy_to_user(useraddr, &ecmd, sizeof (ecmd)))
-                               return -EFAULT;
-                       return 0;
-               }
-       /* set settings */
-       case ETHTOOL_SSET:{
-                       int r;
-                       struct ethtool_cmd ecmd;
-                       if (copy_from_user(&ecmd, useraddr, sizeof (ecmd)))
-                               return -EFAULT;
-                       r = mii_ethtool_sset(&pegasus->mii, &ecmd);
-                       return r;
-               }
-       /* restart autonegotiation */
-       case ETHTOOL_NWAY_RST:{
-                       return mii_nway_restart(&pegasus->mii);
-               }
+/* also handles three patterns of some kind in hardware */
+#define        WOL_SUPPORTED   (WAKE_MAGIC|WAKE_PHY)
 
-       /* get link status */
-       case ETHTOOL_GLINK:{
-                       struct ethtool_value edata = { ETHTOOL_GLINK };
-                       edata.data = mii_link_ok(&pegasus->mii);
-                       if (copy_to_user(useraddr, &edata, sizeof (edata)))
-                               return -EFAULT;
-                       return 0;
-               }
-       /* get message-level */
-       case ETHTOOL_GMSGLVL:{
-                       struct ethtool_value edata = { ETHTOOL_GMSGLVL };
-                       /* edata.data = pegasus->msg_enable; FIXME */
-                       if (copy_to_user(useraddr, &edata, sizeof (edata)))
-                               return -EFAULT;
-                       return 0;
-               }
-       /* set message-level */
-       case ETHTOOL_SMSGLVL:{
-                       struct ethtool_value edata;
-                       if (copy_from_user(&edata, useraddr, sizeof (edata)))
-                               return -EFAULT;
-                       /* sp->msg_enable = edata.data; FIXME */
-                       return 0;
-               }
+static void
+pegasus_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       pegasus_t       *pegasus = netdev_priv(dev);
 
-       }
+       wol->supported = WAKE_MAGIC | WAKE_PHY;
+       wol->wolopts = pegasus->wolopts;
+}
 
-       return -EOPNOTSUPP;
+static int
+pegasus_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
+{
+       pegasus_t       *pegasus = netdev_priv(dev);
+       u8              reg78 = 0x04;
+       
+       if (wol->wolopts & ~WOL_SUPPORTED)
+               return -EINVAL;
+
+       if (wol->wolopts & WAKE_MAGIC)
+               reg78 |= 0x80;
+       if (wol->wolopts & WAKE_PHY)
+               reg78 |= 0x40;
+       /* FIXME this 0x10 bit still needs to get set in the chip... */
+       if (wol->wolopts)
+               pegasus->eth_regs[0] |= 0x10;
+       else
+               pegasus->eth_regs[0] &= ~0x10;
+       pegasus->wolopts = wol->wolopts;
+       return set_register(pegasus, WakeupControl, reg78);
+}
 
+static inline void pegasus_reset_wol(struct net_device *dev)
+{
+       struct ethtool_wolinfo wol;
+       
+       memset(&wol, 0, sizeof wol);
+       (void) pegasus_set_wol(dev, &wol);
 }
-#else
-static int pegasus_ethtool_ioctl(struct net_device *net, void __user *uaddr)
+
+static int
+pegasus_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
 {
        pegasus_t *pegasus;
-       int cmd;
 
-       pegasus = net->priv;
-       if (get_user(cmd, (int *) uaddr))
-               return -EFAULT;
-       switch (cmd) {
-       case ETHTOOL_GDRVINFO:{
-                       struct ethtool_drvinfo info;
-                       memset (&info, 0, sizeof (info));
-                       info.cmd = ETHTOOL_GDRVINFO;
-                       strncpy(info.driver, driver_name,
-                               sizeof (info.driver) - 1);
-                       strncpy(info.version, DRIVER_VERSION,
-                               sizeof (info.version) - 1);
-                       usb_make_path(pegasus->usb, info.bus_info,
-                                     sizeof (info.bus_info));
-                       if (copy_to_user(uaddr, &info, sizeof (info)))
-                               return -EFAULT;
-                       return 0;
-               }
-       case ETHTOOL_GSET:{
-                       struct ethtool_cmd ecmd;
-                       short lpa, bmcr;
-                       u8 port;
-
-                       memset(&ecmd, 0, sizeof (ecmd));
-                       ecmd.supported = (SUPPORTED_10baseT_Half |
-                                         SUPPORTED_10baseT_Full |
-                                         SUPPORTED_100baseT_Half |
-                                         SUPPORTED_100baseT_Full |
-                                         SUPPORTED_Autoneg |
-                                         SUPPORTED_TP | SUPPORTED_MII);
-                       get_registers(pegasus, Reg7b, 1, &port);
-                       if (port == 0)
-                               ecmd.port = PORT_MII;
-                       else
-                               ecmd.port = PORT_TP;
-                       ecmd.transceiver = XCVR_INTERNAL;
-                       ecmd.phy_address = pegasus->phy;
-                       read_mii_word(pegasus, pegasus->phy, MII_BMCR, &bmcr);
-                       read_mii_word(pegasus, pegasus->phy, MII_LPA, &lpa);
-                       if (bmcr & BMCR_ANENABLE) {
-                               ecmd.autoneg = AUTONEG_ENABLE;
-                               ecmd.speed = lpa & (LPA_100HALF | LPA_100FULL) ?
-                                   SPEED_100 : SPEED_10;
-                               if (ecmd.speed == SPEED_100)
-                                       ecmd.duplex = lpa & LPA_100FULL ?
-                                           DUPLEX_FULL : DUPLEX_HALF;
-                               else
-                                       ecmd.duplex = lpa & LPA_10FULL ?
-                                           DUPLEX_FULL : DUPLEX_HALF;
-                       } else {
-                               ecmd.autoneg = AUTONEG_DISABLE;
-                               ecmd.speed = bmcr & BMCR_SPEED100 ?
-                                   SPEED_100 : SPEED_10;
-                               ecmd.duplex = bmcr & BMCR_FULLDPLX ?
-                                   DUPLEX_FULL : DUPLEX_HALF;
-                       }
-                       if (copy_to_user(uaddr, &ecmd, sizeof (ecmd)))
-                               return -EFAULT;
-
-                       return 0;
-               }
-       case ETHTOOL_SSET:{
-                       return -EOPNOTSUPP;
-               }
-       case ETHTOOL_GLINK:{
-                       struct ethtool_value edata = { ETHTOOL_GLINK };
-                       edata.data = netif_carrier_ok(net);
-                       if (copy_to_user(uaddr, &edata, sizeof (edata)))
-                               return -EFAULT;
-                       return 0;
-               }
-       default:
-               return -EOPNOTSUPP;
-       }
+       if (in_atomic())
+               return 0;
+
+       pegasus = netdev_priv(dev);
+       mii_ethtool_gset(&pegasus->mii, ecmd);
+
+       return 0;
 }
-#endif
+
+static int
+pegasus_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
+{
+       pegasus_t *pegasus = netdev_priv(dev);
+       return mii_ethtool_sset(&pegasus->mii, ecmd);
+}
+
+static int pegasus_nway_reset(struct net_device *dev)
+{
+       pegasus_t *pegasus = netdev_priv(dev);
+       return mii_nway_restart(&pegasus->mii);
+}
+
+static u32 pegasus_get_link(struct net_device *dev)
+{
+       pegasus_t *pegasus = netdev_priv(dev);
+       return mii_link_ok(&pegasus->mii);
+}
+
+static u32 pegasus_get_msglevel(struct net_device *dev)
+{
+       pegasus_t *pegasus = netdev_priv(dev);
+       return pegasus->msg_enable;
+}
+
+static void pegasus_set_msglevel(struct net_device *dev, u32 v)
+{
+       pegasus_t *pegasus = netdev_priv(dev);
+       pegasus->msg_enable = v;
+}
+
+static struct ethtool_ops ops = {
+       .get_drvinfo = pegasus_get_drvinfo,
+       .get_settings = pegasus_get_settings,
+       .set_settings = pegasus_set_settings,
+       .nway_reset = pegasus_nway_reset,
+       .get_link = pegasus_get_link,
+       .get_msglevel = pegasus_get_msglevel,
+       .set_msglevel = pegasus_set_msglevel,
+       .get_wol = pegasus_get_wol,
+       .set_wol = pegasus_set_wol,
+};
+
 static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
 {
-       __u16 *data = (__u16 *) & rq->ifr_data;
-       pegasus_t *pegasus = net->priv;
+       __u16 *data = (__u16 *) & rq->ifr_ifru;
+       pegasus_t *pegasus = netdev_priv(net);
        int res;
 
        switch (cmd) {
-       case SIOCETHTOOL:
-               res = pegasus_ethtool_ioctl(net, (void __user *)rq->ifr_data);
-               break;
        case SIOCDEVPRIVATE:
                data[0] = pegasus->phy;
        case SIOCDEVPRIVATE + 1:
@@ -1135,27 +1209,25 @@ static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
 
 static void pegasus_set_multicast(struct net_device *net)
 {
-       pegasus_t *pegasus = net->priv;
-
-       netif_stop_queue(net);
+       pegasus_t *pegasus = netdev_priv(net);
 
        if (net->flags & IFF_PROMISC) {
                pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
-               info("%s: Promiscuous mode enabled", net->name);
-       } else if ((net->mc_count > multicast_filter_limit) ||
+               if (netif_msg_link(pegasus))
+                       pr_info("%s: Promiscuous mode enabled.\n", net->name);
+       } else if (net->mc_count ||
                   (net->flags & IFF_ALLMULTI)) {
                pegasus->eth_regs[EthCtrl0] |= RX_MULTICAST;
                pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
-               info("%s set allmulti", net->name);
+               if (netif_msg_link(pegasus))
+                       pr_info("%s: set allmulti\n", net->name);
        } else {
                pegasus->eth_regs[EthCtrl0] &= ~RX_MULTICAST;
                pegasus->eth_regs[EthCtrl2] &= ~RX_PROMISCUOUS;
        }
 
        pegasus->flags |= ETH_REGS_CHANGE;
-       ctrl_callback(pegasus->ctrl_urb, NULL);
-
-       netif_wake_queue(net);
+       ctrl_callback(pegasus->ctrl_urb);
 }
 
 static __u8 mii_phy_probe(pegasus_t * pegasus)
@@ -1176,7 +1248,7 @@ static __u8 mii_phy_probe(pegasus_t * pegasus)
 
 static inline void setup_pegasus_II(pegasus_t * pegasus)
 {
-       u16 data = 0xa5;
+       __u8 data = 0xa5;
        
        set_register(pegasus, Reg1d, 0);
        set_register(pegasus, Reg7b, 1);
@@ -1205,6 +1277,20 @@ static inline void setup_pegasus_II(pegasus_t * pegasus)
                set_register(pegasus, Reg81, 2);
 }
 
+
+static struct workqueue_struct *pegasus_workqueue = NULL;
+#define CARRIER_CHECK_DELAY (2 * HZ)
+
+static void check_carrier(struct work_struct *work)
+{
+       pegasus_t *pegasus = container_of(work, pegasus_t, carrier_check.work);
+       set_carrier(pegasus->net);
+       if (!(pegasus->flags & PEGASUS_UNPLUG)) {
+               queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
+                       CARRIER_CHECK_DELAY);
+       }
+}
+
 static int pegasus_probe(struct usb_interface *intf,
                         const struct usb_device_id *id)
 {
@@ -1215,28 +1301,30 @@ static int pegasus_probe(struct usb_interface *intf,
        int res = -ENOMEM;
 
        usb_get_dev(dev);
-       if (!(pegasus = kmalloc(sizeof (struct pegasus), GFP_KERNEL))) {
-               err("out of memory allocating device structure");
+       net = alloc_etherdev(sizeof(struct pegasus));
+       if (!net) {
+               dev_err(&intf->dev, "can't allocate %s\n", "device");
                goto out;
        }
 
+       pegasus = netdev_priv(net);
        memset(pegasus, 0, sizeof (struct pegasus));
        pegasus->dev_index = dev_index;
        init_waitqueue_head(&pegasus->ctrl_wait);
 
-       if (!alloc_urbs(pegasus))
+       if (!alloc_urbs(pegasus)) {
+               dev_err(&intf->dev, "can't allocate %s\n", "urbs");
                goto out1;
-
-       net = alloc_etherdev(0);
-       if (!net)
-               goto out2;
+       }
 
        tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
 
+       INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
+
+       pegasus->intf = intf;
        pegasus->usb = dev;
        pegasus->net = net;
        SET_MODULE_OWNER(net);
-       net->priv = pegasus;
        net->open = pegasus_open;
        net->stop = pegasus_close;
        net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
@@ -1245,49 +1333,59 @@ static int pegasus_probe(struct usb_interface *intf,
        net->hard_start_xmit = pegasus_start_xmit;
        net->set_multicast_list = pegasus_set_multicast;
        net->get_stats = pegasus_netdev_stats;
-       net->mtu = PEGASUS_MTU;
+       SET_ETHTOOL_OPS(net, &ops);
        pegasus->mii.dev = net;
        pegasus->mii.mdio_read = mdio_read;
        pegasus->mii.mdio_write = mdio_write;
        pegasus->mii.phy_id_mask = 0x1f;
        pegasus->mii.reg_num_mask = 0x1f;
        spin_lock_init(&pegasus->rx_pool_lock);
+       pegasus->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
+                               | NETIF_MSG_PROBE | NETIF_MSG_LINK);
 
        pegasus->features = usb_dev_id[dev_index].private;
        get_interrupt_interval(pegasus);
        if (reset_mac(pegasus)) {
-               err("can't reset MAC");
+               dev_err(&intf->dev, "can't reset MAC\n");
                res = -EIO;
-               goto out3;
+               goto out2;
        }
        set_ethernet_addr(pegasus);
        fill_skb_pool(pegasus);
        if (pegasus->features & PEGASUS_II) {
-               info("setup Pegasus II specific registers");
+               dev_info(&intf->dev, "setup Pegasus II specific registers\n");
                setup_pegasus_II(pegasus);
        }
        pegasus->phy = mii_phy_probe(pegasus);
        if (pegasus->phy == 0xff) {
-               warn("can't locate MII phy, using default");
+               dev_warn(&intf->dev, "can't locate MII phy, using default\n");
                pegasus->phy = 1;
        }
+       pegasus->mii.phy_id = pegasus->phy;
        usb_set_intfdata(intf, pegasus);
        SET_NETDEV_DEV(net, &intf->dev);
+       pegasus_reset_wol(net);
        res = register_netdev(net);
        if (res)
-               goto out4;
-       printk("%s: %s\n", net->name, usb_dev_id[dev_index].name);
+               goto out3;
+       queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
+                               CARRIER_CHECK_DELAY);
+
+       dev_info(&intf->dev, "%s, %s, %02x:%02x:%02x:%02x:%02x:%02x\n",
+               net->name,
+               usb_dev_id[dev_index].name,
+               net->dev_addr [0], net->dev_addr [1],
+               net->dev_addr [2], net->dev_addr [3],
+               net->dev_addr [4], net->dev_addr [5]);
        return 0;
 
-out4:
+out3:
        usb_set_intfdata(intf, NULL);
        free_skb_pool(pegasus);
-out3:
-       free_netdev(net);
 out2:
        free_all_urbs(pegasus);
 out1:
-       kfree(pegasus);
+       free_netdev(net);
 out:
        usb_put_dev(dev);
        return res;
@@ -1299,19 +1397,52 @@ static void pegasus_disconnect(struct usb_interface *intf)
 
        usb_set_intfdata(intf, NULL);
        if (!pegasus) {
-               warn("unregistering non-existant device");
+               dev_dbg(&intf->dev, "unregistering non-bound device?\n");
                return;
        }
 
        pegasus->flags |= PEGASUS_UNPLUG;
+       cancel_delayed_work(&pegasus->carrier_check);
        unregister_netdev(pegasus->net);
        usb_put_dev(interface_to_usbdev(intf));
+       unlink_all_urbs(pegasus);
        free_all_urbs(pegasus);
        free_skb_pool(pegasus);
        if (pegasus->rx_skb)
                dev_kfree_skb(pegasus->rx_skb);
        free_netdev(pegasus->net);
-       kfree(pegasus);
+}
+
+static int pegasus_suspend (struct usb_interface *intf, pm_message_t message)
+{
+       struct pegasus *pegasus = usb_get_intfdata(intf);
+       
+       netif_device_detach (pegasus->net);
+       cancel_delayed_work(&pegasus->carrier_check);
+       if (netif_running(pegasus->net)) {
+               usb_kill_urb(pegasus->rx_urb);
+               usb_kill_urb(pegasus->intr_urb);
+       }
+       return 0;
+}
+
+static int pegasus_resume (struct usb_interface *intf)
+{
+       struct pegasus *pegasus = usb_get_intfdata(intf);
+
+       netif_device_attach (pegasus->net);
+       if (netif_running(pegasus->net)) {
+               pegasus->rx_urb->status = 0;
+               pegasus->rx_urb->actual_length = 0;
+               read_bulk_callback(pegasus->rx_urb);
+
+               pegasus->intr_urb->status = 0;
+               pegasus->intr_urb->actual_length = 0;
+               intr_callback(pegasus->intr_urb);
+       }
+       queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
+                               CARRIER_CHECK_DELAY);
+       return 0;
 }
 
 static struct usb_driver pegasus_driver = {
@@ -1319,16 +1450,55 @@ static struct usb_driver pegasus_driver = {
        .probe = pegasus_probe,
        .disconnect = pegasus_disconnect,
        .id_table = pegasus_ids,
+       .suspend = pegasus_suspend,
+       .resume = pegasus_resume,
 };
 
-int __init pegasus_init(void)
+static void parse_id(char *id)
 {
-       info(DRIVER_VERSION ":" DRIVER_DESC);
+       unsigned int vendor_id=0, device_id=0, flags=0, i=0;
+       char *token, *name=NULL;
+
+       if ((token = strsep(&id, ":")) != NULL)
+               name = token;
+       /* name now points to a null terminated string*/
+       if ((token = strsep(&id, ":")) != NULL)
+               vendor_id = simple_strtoul(token, NULL, 16);
+       if ((token = strsep(&id, ":")) != NULL)
+               device_id = simple_strtoul(token, NULL, 16);
+       flags = simple_strtoul(id, NULL, 16);
+       pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
+               driver_name, name, vendor_id, device_id, flags);
+
+       if (vendor_id > 0x10000 || vendor_id == 0)
+               return;
+       if (device_id > 0x10000 || device_id == 0)
+               return;
+
+       for (i=0; usb_dev_id[i].name; i++);
+       usb_dev_id[i].name = name;
+       usb_dev_id[i].vendor = vendor_id;
+       usb_dev_id[i].device = device_id;
+       usb_dev_id[i].private = flags;
+       pegasus_ids[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
+       pegasus_ids[i].idVendor = vendor_id;
+       pegasus_ids[i].idProduct = device_id;
+}
+
+static int __init pegasus_init(void)
+{
+       pr_info("%s: %s, " DRIVER_DESC "\n", driver_name, DRIVER_VERSION);
+       if (devid)
+               parse_id(devid);
+       pegasus_workqueue = create_singlethread_workqueue("pegasus");
+       if (!pegasus_workqueue)
+               return -ENOMEM;
        return usb_register(&pegasus_driver);
 }
 
-void __exit pegasus_exit(void)
+static void __exit pegasus_exit(void)
 {
+       destroy_workqueue(pegasus_workqueue);
        usb_deregister(&pegasus_driver);
 }