Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[safe/jmp/linux-2.6] / drivers / net / irda / irda-usb.c
index c6355c0..2c9b3af 100644 (file)
@@ -111,7 +111,8 @@ static void irda_usb_init_qos(struct irda_usb_cb *self) ;
 static struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf);
 static void irda_usb_disconnect(struct usb_interface *intf);
 static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self);
-static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *dev);
+static netdev_tx_t irda_usb_hard_xmit(struct sk_buff *skb,
+                                           struct net_device *dev);
 static int irda_usb_open(struct irda_usb_cb *self);
 static void irda_usb_close(struct irda_usb_cb *self);
 static void speed_bulk_callback(struct urb *urb);
@@ -122,7 +123,6 @@ static int irda_usb_net_open(struct net_device *dev);
 static int irda_usb_net_close(struct net_device *dev);
 static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static void irda_usb_net_timeout(struct net_device *dev);
-static struct net_device_stats *irda_usb_net_get_stats(struct net_device *dev);
 
 /************************ TRANSMIT ROUTINES ************************/
 /*
@@ -177,12 +177,12 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
                    (!force) && (self->speed != -1)) {
                        /* No speed and xbofs change here
                         * (we'll do it later in the write callback) */
-                       IRDA_DEBUG(2, "%s(), not changing speed yet\n", __FUNCTION__);
+                       IRDA_DEBUG(2, "%s(), not changing speed yet\n", __func__);
                        *header = 0;
                        return;
                }
 
-               IRDA_DEBUG(2, "%s(), changing speed to %d\n", __FUNCTION__, self->new_speed);
+               IRDA_DEBUG(2, "%s(), changing speed to %d\n", __func__, self->new_speed);
                self->speed = self->new_speed;
                /* We will do ` self->new_speed = -1; ' in the completion
                 * handler just in case the current URB fail - Jean II */
@@ -228,7 +228,7 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
        
        /* Set the negotiated additional XBOFS */
        if (self->new_xbofs != -1) {
-               IRDA_DEBUG(2, "%s(), changing xbofs to %d\n", __FUNCTION__, self->new_xbofs);
+               IRDA_DEBUG(2, "%s(), changing xbofs to %d\n", __func__, self->new_xbofs);
                self->xbofs = self->new_xbofs;
                /* We will do ` self->new_xbofs = -1; ' in the completion
                 * handler just in case the current URB fail - Jean II */
@@ -302,13 +302,13 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
        struct urb *urb;
        int ret;
 
-       IRDA_DEBUG(2, "%s(), speed=%d, xbofs=%d\n", __FUNCTION__,
+       IRDA_DEBUG(2, "%s(), speed=%d, xbofs=%d\n", __func__,
                   self->new_speed, self->new_xbofs);
 
        /* Grab the speed URB */
        urb = self->speed_urb;
        if (urb->status != 0) {
-               IRDA_WARNING("%s(), URB still in use!\n", __FUNCTION__);
+               IRDA_WARNING("%s(), URB still in use!\n", __func__);
                return;
        }
 
@@ -334,7 +334,7 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
 
        /* Irq disabled -> GFP_ATOMIC */
        if ((ret = usb_submit_urb(urb, GFP_ATOMIC))) {
-               IRDA_WARNING("%s(), failed Speed URB\n", __FUNCTION__);
+               IRDA_WARNING("%s(), failed Speed URB\n", __func__);
        }
 }
 
@@ -347,7 +347,7 @@ static void speed_bulk_callback(struct urb *urb)
 {
        struct irda_usb_cb *self = urb->context;
        
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        /* We should always have a context */
        IRDA_ASSERT(self != NULL, return;);
@@ -357,7 +357,7 @@ static void speed_bulk_callback(struct urb *urb)
        /* Check for timeout and other USB nasties */
        if (urb->status != 0) {
                /* I get a lot of -ECONNABORTED = -103 here - Jean II */
-               IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __FUNCTION__, urb->status, urb->transfer_flags);
+               IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __func__, urb->status, urb->transfer_flags);
 
                /* Don't do anything here, that might confuse the USB layer.
                 * Instead, we will wait for irda_usb_net_timeout(), the
@@ -382,17 +382,17 @@ static void speed_bulk_callback(struct urb *urb)
 /*
  * Send an IrDA frame to the USB dongle (for transmission)
  */
-static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
+static netdev_tx_t irda_usb_hard_xmit(struct sk_buff *skb,
+                                           struct net_device *netdev)
 {
-       struct irda_usb_cb *self = netdev->priv;
+       struct irda_usb_cb *self = netdev_priv(netdev);
        struct urb *urb = self->tx_urb;
        unsigned long flags;
        s32 speed;
        s16 xbofs;
        int res, mtt;
-       int     err = 1;        /* Failed */
 
-       IRDA_DEBUG(4, "%s() on %s\n", __FUNCTION__, netdev->name);
+       IRDA_DEBUG(4, "%s() on %s\n", __func__, netdev->name);
 
        netif_stop_queue(netdev);
 
@@ -403,7 +403,7 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
         * We need to check self->present under the spinlock because
         * of irda_usb_disconnect() is synchronous - Jean II */
        if (!self->present) {
-               IRDA_DEBUG(0, "%s(), Device is gone...\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), Device is gone...\n", __func__);
                goto drop;
        }
 
@@ -431,13 +431,12 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
                        irda_usb_change_speed_xbofs(self);
                        netdev->trans_start = jiffies;
                        /* Will netif_wake_queue() in callback */
-                       err = 0;        /* No error */
                        goto drop;
                }
        }
 
        if (urb->status != 0) {
-               IRDA_WARNING("%s(), URB still in use!\n", __FUNCTION__);
+               IRDA_WARNING("%s(), URB still in use!\n", __func__);
                goto drop;
        }
 
@@ -524,26 +523,26 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
        
        /* Ask USB to send the packet - Irq disabled -> GFP_ATOMIC */
        if ((res = usb_submit_urb(urb, GFP_ATOMIC))) {
-               IRDA_WARNING("%s(), failed Tx URB\n", __FUNCTION__);
-               self->stats.tx_errors++;
+               IRDA_WARNING("%s(), failed Tx URB\n", __func__);
+               netdev->stats.tx_errors++;
                /* Let USB recover : We will catch that in the watchdog */
                /*netif_start_queue(netdev);*/
        } else {
                /* Increment packet stats */
-               self->stats.tx_packets++;
-                self->stats.tx_bytes += skb->len;
+               netdev->stats.tx_packets++;
+                netdev->stats.tx_bytes += skb->len;
                
                netdev->trans_start = jiffies;
        }
        spin_unlock_irqrestore(&self->lock, flags);
        
-       return 0;
+       return NETDEV_TX_OK;
 
 drop:
        /* Drop silently the skb and exit */
        dev_kfree_skb(skb);
        spin_unlock_irqrestore(&self->lock, flags);
-       return err;             /* Usually 1 */
+       return NETDEV_TX_OK;
 }
 
 /*------------------------------------------------------------------*/
@@ -556,7 +555,7 @@ static void write_bulk_callback(struct urb *urb)
        struct sk_buff *skb = urb->context;
        struct irda_usb_cb *self = ((struct irda_skb_cb *) skb->cb)->context;
        
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        /* We should always have a context */
        IRDA_ASSERT(self != NULL, return;);
@@ -570,7 +569,7 @@ static void write_bulk_callback(struct urb *urb)
        /* Check for timeout and other USB nasties */
        if (urb->status != 0) {
                /* I get a lot of -ECONNABORTED = -103 here - Jean II */
-               IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __FUNCTION__, urb->status, urb->transfer_flags);
+               IRDA_DEBUG(0, "%s(), URB complete status %d, transfer_flags 0x%04X\n", __func__, urb->status, urb->transfer_flags);
 
                /* Don't do anything here, that might confuse the USB layer,
                 * and we could go in recursion and blow the kernel stack...
@@ -589,7 +588,7 @@ static void write_bulk_callback(struct urb *urb)
 
        /* If the network is closed, stop everything */
        if ((!self->netopen) || (!self->present)) {
-               IRDA_DEBUG(0, "%s(), Network is gone...\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), Network is gone...\n", __func__);
                spin_unlock_irqrestore(&self->lock, flags);
                return;
        }
@@ -600,7 +599,7 @@ static void write_bulk_callback(struct urb *urb)
                    (self->new_xbofs != self->xbofs)) {
                        /* We haven't changed speed yet (because of
                         * IUC_SPEED_BUG), so do it now - Jean II */
-                       IRDA_DEBUG(1, "%s(), Changing speed now...\n", __FUNCTION__);
+                       IRDA_DEBUG(1, "%s(), Changing speed now...\n", __func__);
                        irda_usb_change_speed_xbofs(self);
                } else {
                        /* New speed and xbof is now commited in hardware */
@@ -628,11 +627,11 @@ static void write_bulk_callback(struct urb *urb)
 static void irda_usb_net_timeout(struct net_device *netdev)
 {
        unsigned long flags;
-       struct irda_usb_cb *self = netdev->priv;
+       struct irda_usb_cb *self = netdev_priv(netdev);
        struct urb *urb;
        int     done = 0;       /* If we have made any progress */
 
-       IRDA_DEBUG(0, "%s(), Network layer thinks we timed out!\n", __FUNCTION__);
+       IRDA_DEBUG(0, "%s(), Network layer thinks we timed out!\n", __func__);
        IRDA_ASSERT(self != NULL, return;);
 
        /* Protect us from USB callbacks, net Tx and else. */
@@ -640,7 +639,7 @@ static void irda_usb_net_timeout(struct net_device *netdev)
 
        /* self->present *MUST* be read under spinlock */
        if (!self->present) {
-               IRDA_WARNING("%s(), device not present!\n", __FUNCTION__);
+               IRDA_WARNING("%s(), device not present!\n", __func__);
                netif_stop_queue(netdev);
                spin_unlock_irqrestore(&self->lock, flags);
                return;
@@ -677,7 +676,7 @@ static void irda_usb_net_timeout(struct net_device *netdev)
                IRDA_DEBUG(0, "%s: Tx timed out, urb->status=%d, urb->transfer_flags=0x%04X\n", netdev->name, urb->status, urb->transfer_flags);
 
                /* Increase error count */
-               self->stats.tx_errors++;
+               netdev->stats.tx_errors++;
 
 #ifdef IU_BUG_KICK_TIMEOUT
                /* Can't be a bad idea to reset the speed ;-) - Jean II */
@@ -763,7 +762,7 @@ static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struc
        struct irda_skb_cb *cb;
        int ret;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        /* This should never happen */
        IRDA_ASSERT(skb != NULL, return;);
@@ -786,7 +785,7 @@ static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struc
                /* If this ever happen, we are in deep s***.
                 * Basically, the Rx path will stop... */
                IRDA_WARNING("%s(), Failed to submit Rx URB %d\n",
-                            __FUNCTION__, ret);
+                            __func__, ret);
        }
 }
 
@@ -807,7 +806,7 @@ static void irda_usb_receive(struct urb *urb)
        struct urb *next_urb;
        unsigned int len, docopy;
 
-       IRDA_DEBUG(2, "%s(), len=%d\n", __FUNCTION__, urb->actual_length);
+       IRDA_DEBUG(2, "%s(), len=%d\n", __func__, urb->actual_length);
        
        /* Find ourselves */
        cb = (struct irda_skb_cb *) skb->cb;
@@ -817,7 +816,7 @@ static void irda_usb_receive(struct urb *urb)
 
        /* If the network is closed or the device gone, stop everything */
        if ((!self->netopen) || (!self->present)) {
-               IRDA_DEBUG(0, "%s(), Network is gone!\n", __FUNCTION__);
+               IRDA_DEBUG(0, "%s(), Network is gone!\n", __func__);
                /* Don't re-submit the URB : will stall the Rx path */
                return;
        }
@@ -826,7 +825,7 @@ static void irda_usb_receive(struct urb *urb)
        if (urb->status != 0) {
                switch (urb->status) {
                case -EILSEQ:
-                       self->stats.rx_crc_errors++;    
+                       self->netdev->stats.rx_crc_errors++;
                        /* Also precursor to a hot-unplug on UHCI. */
                        /* Fallthrough... */
                case -ECONNRESET:
@@ -839,8 +838,8 @@ static void irda_usb_receive(struct urb *urb)
                case -ETIME:
                        /* Usually precursor to a hot-unplug on OHCI. */
                default:
-                       self->stats.rx_errors++;
-                       IRDA_DEBUG(0, "%s(), RX status %d, transfer_flags 0x%04X \n", __FUNCTION__, urb->status, urb->transfer_flags);
+                       self->netdev->stats.rx_errors++;
+                       IRDA_DEBUG(0, "%s(), RX status %d, transfer_flags 0x%04X \n", __func__, urb->status, urb->transfer_flags);
                        break;
                }
                /* If we received an error, we don't want to resubmit the
@@ -853,7 +852,7 @@ static void irda_usb_receive(struct urb *urb)
                 * hot unplug of the dongle...
                 * Lowest effective timer is 10ms...
                 * Jean II */
-               self->rx_defer_timer.function = &irda_usb_rx_defer_expired;
+               self->rx_defer_timer.function = irda_usb_rx_defer_expired;
                self->rx_defer_timer.data = (unsigned long) urb;
                mod_timer(&self->rx_defer_timer, jiffies + (10 * HZ / 1000));
                return;
@@ -861,7 +860,7 @@ static void irda_usb_receive(struct urb *urb)
        
        /* Check for empty frames */
        if (urb->actual_length <= self->header_length) {
-               IRDA_WARNING("%s(), empty frame!\n", __FUNCTION__);
+               IRDA_WARNING("%s(), empty frame!\n", __func__);
                goto done;
        }
 
@@ -890,7 +889,7 @@ static void irda_usb_receive(struct urb *urb)
                                       IRDA_SKB_MAX_MTU);
 
        if (!newskb)  {
-               self->stats.rx_dropped++;
+               self->netdev->stats.rx_dropped++;
                /* We could deliver the current skb, but this would stall
                 * the Rx path. Better drop the packet... Jean II */
                goto done;  
@@ -927,9 +926,8 @@ static void irda_usb_receive(struct urb *urb)
        netif_rx(dataskb);
 
        /* Keep stats up to date */
-       self->stats.rx_bytes += len;
-       self->stats.rx_packets++;
-       self->netdev->last_rx = jiffies;
+       self->netdev->stats.rx_bytes += len;
+       self->netdev->stats.rx_packets++;
 
 done:
        /* Note : at this point, the URB we've just received (urb)
@@ -967,7 +965,7 @@ static void irda_usb_rx_defer_expired(unsigned long data)
        struct irda_skb_cb *cb;
        struct urb *next_urb;
 
-       IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(2, "%s()\n", __func__);
 
        /* Find ourselves */
        cb = (struct irda_skb_cb *) skb->cb;
@@ -1024,7 +1022,7 @@ static int irda_usb_is_receiving(struct irda_usb_cb *self)
  *   Upload firmware code to SigmaTel 421X IRDA-USB dongle
  */
 static int stir421x_fw_upload(struct irda_usb_cb *self,
-                            unsigned char *patch,
+                            const unsigned char *patch,
                             const unsigned int patch_len)
 {
         int ret = -ENOMEM;
@@ -1053,7 +1051,7 @@ static int stir421x_fw_upload(struct irda_usb_cb *self,
                                   patch_block, block_size,
                                   &actual_len, msecs_to_jiffies(500));
                IRDA_DEBUG(3,"%s(): Bulk send %u bytes, ret=%d\n",
-                          __FUNCTION__, actual_len, ret);
+                          __func__, actual_len, ret);
 
                if (ret < 0)
                        break;
@@ -1073,11 +1071,11 @@ static int stir421x_fw_upload(struct irda_usb_cb *self,
   */
 static int stir421x_patch_device(struct irda_usb_cb *self)
 {
-        unsigned int i;
-        int ret;
-        char stir421x_fw_name[11];
-        const struct firmware *fw;
-        unsigned char *fw_version_ptr; /* pointer to version string */
+       unsigned int i;
+       int ret;
+       char stir421x_fw_name[12];
+       const struct firmware *fw;
+       const unsigned char *fw_version_ptr; /* pointer to version string */
        unsigned long fw_version = 0;
 
         /*
@@ -1092,7 +1090,7 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
 
         /* We get a patch from userspace */
         IRDA_MESSAGE("%s(): Received firmware %s (%zu bytes)\n",
-                     __FUNCTION__, stir421x_fw_name, fw->size);
+                     __func__, stir421x_fw_name, fw->size);
 
         ret = -EINVAL;
 
@@ -1116,21 +1114,21 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
                                + (build % 10);
 
                        IRDA_DEBUG(3, "%s(): Firmware Product version %ld\n",
-                                   __FUNCTION__, fw_version);
+                                   __func__, fw_version);
                 }
         }
 
-        if (self->usbdev->descriptor.bcdDevice == fw_version) {
+        if (self->usbdev->descriptor.bcdDevice == cpu_to_le16(fw_version)) {
                 /*
                 * If we're here, we've found a correct patch
                  * The actual image starts after the "STMP" keyword
                  * so forward to the firmware header tag
                  */
-                for (i = 0; (fw->data[i] != STIR421X_PATCH_END_OF_HDR_TAG)
-                            && (i < fw->size); i++) ;
+                for (i = 0; (fw->data[i] != STIR421X_PATCH_END_OF_HDR_TAG) &&
+                            (i < fw->size); i++) ;
                 /* here we check for the out of buffer case */
-                if ((STIR421X_PATCH_END_OF_HDR_TAG == fw->data[i])
-                    && (i < STIR421X_PATCH_CODE_OFFSET)) {
+                if ((STIR421X_PATCH_END_OF_HDR_TAG == fw->data[i]) &&
+                    (i < STIR421X_PATCH_CODE_OFFSET)) {
                         if (!memcmp(fw->data + i + 1, STIR421X_PATCH_STMP_TAG,
                                     sizeof(STIR421X_PATCH_STMP_TAG) - 1)) {
 
@@ -1168,23 +1166,27 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
 static int irda_usb_net_open(struct net_device *netdev)
 {
        struct irda_usb_cb *self;
+       unsigned long flags;
        char    hwname[16];
        int i;
        
-       IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(1, "%s()\n", __func__);
 
        IRDA_ASSERT(netdev != NULL, return -1;);
-       self = (struct irda_usb_cb *) netdev->priv;
+       self = netdev_priv(netdev);
        IRDA_ASSERT(self != NULL, return -1;);
 
+       spin_lock_irqsave(&self->lock, flags);
        /* Can only open the device if it's there */
        if(!self->present) {
-               IRDA_WARNING("%s(), device not present!\n", __FUNCTION__);
+               spin_unlock_irqrestore(&self->lock, flags);
+               IRDA_WARNING("%s(), device not present!\n", __func__);
                return -1;
        }
 
        if(self->needspatch) {
-               IRDA_WARNING("%s(), device needs patch\n", __FUNCTION__) ;
+               spin_unlock_irqrestore(&self->lock, flags);
+               IRDA_WARNING("%s(), device needs patch\n", __func__) ;
                return -EIO ;
        }
 
@@ -1198,6 +1200,7 @@ static int irda_usb_net_open(struct net_device *netdev)
        /* To do *before* submitting Rx urbs and starting net Tx queue
         * Jean II */
        self->netopen = 1;
+       spin_unlock_irqrestore(&self->lock, flags);
 
        /* 
         * Now that everything should be initialized properly,
@@ -1226,7 +1229,7 @@ static int irda_usb_net_open(struct net_device *netdev)
                        /* If this ever happen, we are in deep s***.
                         * Basically, we can't start the Rx path... */
                        IRDA_WARNING("%s(), Failed to allocate Rx skb\n",
-                                    __FUNCTION__);
+                                    __func__);
                        return -1;
                }
                //skb_reserve(newskb, USB_IRDA_HEADER - 1);
@@ -1249,10 +1252,10 @@ static int irda_usb_net_close(struct net_device *netdev)
        struct irda_usb_cb *self;
        int     i;
 
-       IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(1, "%s()\n", __func__);
 
        IRDA_ASSERT(netdev != NULL, return -1;);
-       self = (struct irda_usb_cb *) netdev->priv;
+       self = netdev_priv(netdev);
        IRDA_ASSERT(self != NULL, return -1;);
 
        /* Clear this flag *before* unlinking the urbs and *before*
@@ -1301,10 +1304,10 @@ static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        int ret = 0;
 
        IRDA_ASSERT(dev != NULL, return -1;);
-       self = dev->priv;
+       self = netdev_priv(dev);
        IRDA_ASSERT(self != NULL, return -1;);
 
-       IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
+       IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__, dev->name, cmd);
 
        switch (cmd) {
        case SIOCSBANDWIDTH: /* Set bandwidth */
@@ -1338,14 +1341,6 @@ static int irda_usb_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 }
 
 /*------------------------------------------------------------------*/
-/*
- * Get device stats (for /proc/net/dev and ifconfig)
- */
-static struct net_device_stats *irda_usb_net_get_stats(struct net_device *dev)
-{
-       struct irda_usb_cb *self = dev->priv;
-       return &self->stats;
-}
 
 /********************* IRDA CONFIG SUBROUTINES *********************/
 /*
@@ -1362,7 +1357,7 @@ static inline void irda_usb_init_qos(struct irda_usb_cb *self)
 {
        struct irda_class_desc *desc;
 
-       IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(3, "%s()\n", __func__);
        
        desc = self->irda_desc;
        
@@ -1379,7 +1374,7 @@ static inline void irda_usb_init_qos(struct irda_usb_cb *self)
        self->qos.data_size.bits       = desc->bmDataSize;
 
        IRDA_DEBUG(0, "%s(), dongle says speed=0x%X, size=0x%X, window=0x%X, bofs=0x%X, turn=0x%X\n", 
-               __FUNCTION__, self->qos.baud_rate.bits, self->qos.data_size.bits, self->qos.window_size.bits, self->qos.additional_bofs.bits, self->qos.min_turn_time.bits);
+               __func__, self->qos.baud_rate.bits, self->qos.data_size.bits, self->qos.window_size.bits, self->qos.additional_bofs.bits, self->qos.min_turn_time.bits);
 
        /* Don't always trust what the dongle tell us */
        if(self->capability & IUC_SIR_ONLY)
@@ -1406,6 +1401,14 @@ static inline void irda_usb_init_qos(struct irda_usb_cb *self)
 }
 
 /*------------------------------------------------------------------*/
+static const struct net_device_ops irda_usb_netdev_ops = {
+       .ndo_open       = irda_usb_net_open,
+       .ndo_stop       = irda_usb_net_close,
+       .ndo_do_ioctl   = irda_usb_net_ioctl,
+       .ndo_start_xmit = irda_usb_hard_xmit,
+       .ndo_tx_timeout = irda_usb_net_timeout,
+};
+
 /*
  * Initialise the network side of the irda-usb instance
  * Called when a new USB instance is registered in irda_usb_probe()
@@ -1414,18 +1417,11 @@ static inline int irda_usb_open(struct irda_usb_cb *self)
 {
        struct net_device *netdev = self->netdev;
 
-       IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(1, "%s()\n", __func__);
 
-       irda_usb_init_qos(self);
+       netdev->netdev_ops = &irda_usb_netdev_ops;
 
-       /* Override the network functions we need to use */
-       netdev->hard_start_xmit = irda_usb_hard_xmit;
-       netdev->tx_timeout      = irda_usb_net_timeout;
-       netdev->watchdog_timeo  = 250*HZ/1000;  /* 250 ms > USB timeout */
-       netdev->open            = irda_usb_net_open;
-       netdev->stop            = irda_usb_net_close;
-       netdev->get_stats       = irda_usb_net_get_stats;
-       netdev->do_ioctl        = irda_usb_net_ioctl;
+       irda_usb_init_qos(self);
 
        return register_netdev(netdev);
 }
@@ -1437,7 +1433,7 @@ static inline int irda_usb_open(struct irda_usb_cb *self)
  */
 static inline void irda_usb_close(struct irda_usb_cb *self)
 {
-       IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(1, "%s()\n", __func__);
 
        /* Remove netdevice */
        unregister_netdev(self->netdev);
@@ -1510,13 +1506,13 @@ static inline int irda_usb_parse_endpoints(struct irda_usb_cb *self, struct usb_
                                /* This is our interrupt endpoint */
                                self->bulk_int_ep = ep;
                        } else {
-                               IRDA_ERROR("%s(), Unrecognised endpoint %02X.\n", __FUNCTION__, ep);
+                               IRDA_ERROR("%s(), Unrecognised endpoint %02X.\n", __func__, ep);
                        }
                }
        }
 
        IRDA_DEBUG(0, "%s(), And our endpoints are : in=%02X, out=%02X (%d), int=%02X\n",
-               __FUNCTION__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep);
+               __func__, self->bulk_in_ep, self->bulk_out_ep, self->bulk_out_mtu, self->bulk_int_ep);
 
        return((self->bulk_in_ep != 0) && (self->bulk_out_ep != 0));
 }
@@ -1578,7 +1574,7 @@ static inline struct irda_class_desc *irda_usb_find_class_desc(struct usb_interf
                0, intf->altsetting->desc.bInterfaceNumber, desc,
                sizeof(*desc), 500);
        
-       IRDA_DEBUG(1, "%s(), ret=%d\n", __FUNCTION__, ret);
+       IRDA_DEBUG(1, "%s(), ret=%d\n", __func__, ret);
        if (ret < sizeof(*desc)) {
                IRDA_WARNING("usb-irda: class_descriptor read %s (%d)\n",
                             (ret<0) ? "failed" : "too short", ret);
@@ -1636,7 +1632,7 @@ static int irda_usb_probe(struct usb_interface *intf,
                goto err_out;
 
        SET_NETDEV_DEV(net, &intf->dev);
-       self = net->priv;
+       self = netdev_priv(net);
        self->netdev = net;
        spin_lock_init(&self->lock);
        init_timer(&self->rx_defer_timer);
@@ -1655,6 +1651,8 @@ static int irda_usb_probe(struct usb_interface *intf,
 
        self->rx_urb = kcalloc(self->max_rx_urb, sizeof(struct urb *),
                                GFP_KERNEL);
+       if (!self->rx_urb)
+               goto err_free_net;
 
        for (i = 0; i < self->max_rx_urb; i++) {
                self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
@@ -1691,10 +1689,10 @@ static int irda_usb_probe(struct usb_interface *intf,
                        /* Martin Diehl says if we get a -EPIPE we should
                         * be fine and we don't need to do a usb_clear_halt().
                         * - Jean II */
-                       IRDA_DEBUG(0, "%s(), Received -EPIPE, ignoring...\n", __FUNCTION__);
+                       IRDA_DEBUG(0, "%s(), Received -EPIPE, ignoring...\n", __func__);
                        break;
                default:
-                       IRDA_DEBUG(0, "%s(), Unknown error %d\n", __FUNCTION__, ret);
+                       IRDA_DEBUG(0, "%s(), Unknown error %d\n", __func__, ret);
                        ret = -EIO;
                        goto err_out_3;
        }
@@ -1703,7 +1701,7 @@ static int irda_usb_probe(struct usb_interface *intf,
        interface = intf->cur_altsetting;
        if(!irda_usb_parse_endpoints(self, interface->endpoint,
                                     interface->desc.bNumEndpoints)) {
-               IRDA_ERROR("%s(), Bogus endpoints...\n", __FUNCTION__);
+               IRDA_ERROR("%s(), Bogus endpoints...\n", __func__);
                ret = -EIO;
                goto err_out_3;
        }
@@ -1787,6 +1785,8 @@ err_out_2:
 err_out_1:
        for (i = 0; i < self->max_rx_urb; i++)
                usb_free_urb(self->rx_urb[i]);
+       kfree(self->rx_urb);
+err_free_net:
        free_netdev(net);
 err_out:
        return ret;
@@ -1810,7 +1810,7 @@ static void irda_usb_disconnect(struct usb_interface *intf)
        struct irda_usb_cb *self = usb_get_intfdata(intf);
        int i;
 
-       IRDA_DEBUG(1, "%s()\n", __FUNCTION__);
+       IRDA_DEBUG(1, "%s()\n", __func__);
 
        usb_set_intfdata(intf, NULL);
        if (!self)
@@ -1860,8 +1860,44 @@ static void irda_usb_disconnect(struct usb_interface *intf)
 
        /* Free self and network device */
        free_netdev(self->netdev);
-       IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __FUNCTION__);
+       IRDA_DEBUG(0, "%s(), USB IrDA Disconnected\n", __func__);
+}
+
+#ifdef CONFIG_PM
+/* USB suspend, so power off the transmitter/receiver */
+static int irda_usb_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct irda_usb_cb *self = usb_get_intfdata(intf);
+       int i;
+
+       netif_device_detach(self->netdev);
+
+       if (self->tx_urb != NULL)
+               usb_kill_urb(self->tx_urb);
+       if (self->speed_urb != NULL)
+               usb_kill_urb(self->speed_urb);
+       for (i = 0; i < self->max_rx_urb; i++) {
+               if (self->rx_urb[i] != NULL)
+                       usb_kill_urb(self->rx_urb[i]);
+       }
+       return 0;
+}
+
+/* Coming out of suspend, so reset hardware */
+static int irda_usb_resume(struct usb_interface *intf)
+{
+       struct irda_usb_cb *self = usb_get_intfdata(intf);
+       int i;
+
+       for (i = 0; i < self->max_rx_urb; i++) {
+               if (self->rx_urb[i] != NULL)
+                       usb_submit_urb(self->rx_urb[i], GFP_KERNEL);
+       }
+
+       netif_device_attach(self->netdev);
+       return 0;
 }
+#endif
 
 /*------------------------------------------------------------------*/
 /*
@@ -1872,6 +1908,10 @@ static struct usb_driver irda_driver = {
        .probe          = irda_usb_probe,
        .disconnect     = irda_usb_disconnect,
        .id_table       = dongles,
+#ifdef CONFIG_PM
+       .suspend        = irda_usb_suspend,
+       .resume         = irda_usb_resume,
+#endif
 };
 
 /************************* MODULE CALLBACKS *************************/