fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / usb / net / pegasus.c
index 7683926..d48c024 100644 (file)
@@ -45,7 +45,7 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v0.6.13 (2005/11/13)"
+#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"
 
@@ -96,7 +96,7 @@ 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;
 
@@ -163,6 +163,9 @@ 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))) {
+               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);
@@ -217,6 +220,8 @@ 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))) {
+               if (ret == -ENODEV)
+                       netif_device_detach(pegasus->net);
                if (netif_msg_drv(pegasus))
                        dev_err(&pegasus->intf->dev, "%s, status %d\n",
                                        __FUNCTION__, ret);
@@ -268,6 +273,8 @@ static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
        set_current_state(TASK_UNINTERRUPTIBLE);
 
        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);
@@ -298,10 +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)))
+       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;
 }
@@ -330,7 +340,7 @@ static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
        }
 fail:
        if (netif_msg_drv(pegasus))
-               dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
 
        return ret;
 }
@@ -367,7 +377,7 @@ static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
 
 fail:
        if (netif_msg_drv(pegasus))
-               dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
        return -ETIMEDOUT;
 }
 
@@ -404,7 +414,7 @@ static int read_eprom_word(pegasus_t * pegasus, __u8 index, __u16 * retdata)
 
 fail:
        if (netif_msg_drv(pegasus))
-               dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
        return -ETIMEDOUT;
 }
 
@@ -452,7 +462,7 @@ static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
                return ret;
 fail:
        if (netif_msg_drv(pegasus))
-               dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__);
+               dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
        return -ETIMEDOUT;
 }
 #endif                         /* PEGASUS_WRITE_EEPROM */
@@ -472,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));
 }
 
@@ -592,7 +606,7 @@ 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;
@@ -610,7 +624,7 @@ static void read_bulk_callback(struct urb *urb, struct pt_regs *regs)
        switch (urb->status) {
        case 0:
                break;
-       case -ETIMEDOUT:
+       case -ETIME:
                if (netif_msg_rx_err(pegasus))
                        pr_debug("%s: reset MAC\n", net->name);
                pegasus->flags &= ~PEGASUS_RX_BUSY;
@@ -692,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 {
@@ -709,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)
@@ -734,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 {
@@ -744,7 +765,7 @@ 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;
@@ -781,7 +802,7 @@ 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;
@@ -835,7 +856,9 @@ static void intr_callback(struct urb *urb, struct pt_regs *regs)
                pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
        }
 
-       status = usb_submit_urb(urb, SLAB_ATOMIC);
+       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);
@@ -874,6 +897,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
                        /* cleanup should already have been scheduled */
                        break;
                case -ENODEV:           /* disconnect() upcoming */
+                       netif_device_detach(pegasus->net);
                        break;
                default:
                        pegasus->stats.tx_errors++;
@@ -999,6 +1023,8 @@ static int pegasus_open(struct net_device *net)
                          pegasus->rx_skb->data, PEGASUS_MTU + 8,
                          read_bulk_callback, pegasus);
        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;
@@ -1009,6 +1035,8 @@ static int pegasus_open(struct net_device *net)
                         pegasus->intr_buff, sizeof (pegasus->intr_buff),
                         intr_callback, pegasus, pegasus->intr_interval);
        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);
@@ -1199,7 +1227,7 @@ static void pegasus_set_multicast(struct net_device *net)
        }
 
        pegasus->flags |= ETH_REGS_CHANGE;
-       ctrl_callback(pegasus->ctrl_urb, NULL);
+       ctrl_callback(pegasus->ctrl_urb);
 }
 
 static __u8 mii_phy_probe(pegasus_t * pegasus)
@@ -1253,9 +1281,9 @@ static inline void setup_pegasus_II(pegasus_t * pegasus)
 static struct workqueue_struct *pegasus_workqueue = NULL;
 #define CARRIER_CHECK_DELAY (2 * HZ)
 
-static void check_carrier(void *data)
+static void check_carrier(struct work_struct *work)
 {
-       pegasus_t *pegasus = data;
+       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,
@@ -1291,7 +1319,7 @@ static int pegasus_probe(struct usb_interface *intf,
 
        tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
 
-       INIT_WORK(&pegasus->carrier_check, check_carrier, pegasus);
+       INIT_DELAYED_WORK(&pegasus->carrier_check, check_carrier);
 
        pegasus->intf = intf;
        pegasus->usb = dev;
@@ -1406,11 +1434,11 @@ static int pegasus_resume (struct usb_interface *intf)
        if (netif_running(pegasus->net)) {
                pegasus->rx_urb->status = 0;
                pegasus->rx_urb->actual_length = 0;
-               read_bulk_callback(pegasus->rx_urb, NULL);
+               read_bulk_callback(pegasus->rx_urb);
 
                pegasus->intr_urb->status = 0;
                pegasus->intr_urb->actual_length = 0;
-               intr_callback(pegasus->intr_urb, NULL);
+               intr_callback(pegasus->intr_urb);
        }
        queue_delayed_work(pegasus_workqueue, &pegasus->carrier_check,
                                CARRIER_CHECK_DELAY);