linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / net / irda / irda-usb.c
index 2a0d538..6e2ec56 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  *
  * Filename:      irda-usb.c
- * Version:       0.10
+ * Version:       0.9b
  * Description:   IrDA-USB Driver
  * Status:        Experimental 
  * Author:        Dag Brattli <dag@brattli.net>
@@ -9,9 +9,6 @@
  *     Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at>
  *      Copyright (C) 2001, Dag Brattli <dag@brattli.net>
  *      Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
- *      Copyright (C) 2004, SigmaTel, Inc. <irquality@sigmatel.com>
- *      Copyright (C) 2005, Milan Beno <beno@pobox.sk>
- *      Copyright (C) 2006, Nick Fedchik <nick@fedchik.org.ua>
  *          
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -64,7 +61,6 @@
 #include <linux/slab.h>
 #include <linux/rtnetlink.h>
 #include <linux/usb.h>
-#include <linux/firmware.h>
 
 #include "irda-usb.h"
 
@@ -82,12 +78,8 @@ static struct usb_device_id dongles[] = {
        { USB_DEVICE(0x50f, 0x180), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
        /* Extended Systems, Inc.,  XTNDAccess IrDA USB (ESI-9685) */
        { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
-       /* SigmaTel STIR4210/4220/4116 USB IrDA (VFIR) Bridge */
-       { USB_DEVICE(0x66f, 0x4210), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
-       { USB_DEVICE(0x66f, 0x4220), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
-       { USB_DEVICE(0x66f, 0x4116), .driver_info = IUC_STIR421X | IUC_SPEED_BUG },
        { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
-         USB_DEVICE_ID_MATCH_INT_SUBCLASS,
+                      USB_DEVICE_ID_MATCH_INT_SUBCLASS,
          .bInterfaceClass = USB_CLASS_APP_SPEC,
          .bInterfaceSubClass = USB_CLASS_IRDA,
          .driver_info = IUC_DEFAULT, },
@@ -107,7 +99,6 @@ MODULE_DEVICE_TABLE(usb, dongles);
 
 /*------------------------------------------------------------------*/
 
-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);
@@ -150,24 +141,7 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
                                  __u8 *header,
                                  int   force)
 {
-       /* Here we check if we have an STIR421x chip,
-        * and if either speed or xbofs (or both) needs
-        * to be changed.
-        */
-       if (self->capability & IUC_STIR421X &&
-           ((self->new_speed != -1) || (self->new_xbofs != -1))) {
-
-               /* With STIR421x, speed and xBOFs must be set at the same
-                * time, even if only one of them changes.
-                */
-               if (self->new_speed == -1)
-                       self->new_speed = self->speed ;
-
-               if (self->new_xbofs == -1)
-                       self->new_xbofs = self->xbofs ;
-       }
-
-       /* Set the link speed */
+       /* Set the negotiated link speed */
        if (self->new_speed != -1) {
                /* Hum... Ugly hack :-(
                 * Some device are not compliant with the spec and change
@@ -217,11 +191,7 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
                        *header = SPEED_4000000;
                        self->new_xbofs = 0;
                        break;
-               case 16000000:
-                       *header = SPEED_16000000;
-                       self->new_xbofs = 0;
-                       break;
-               }
+               }
        } else
                /* No change */
                *header = 0;
@@ -265,32 +235,6 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
        }
 }
 
-/*
-*   calculate turnaround time for SigmaTel header
-*/
-static __u8 get_turnaround_time(struct sk_buff *skb)
-{
-       int turnaround_time = irda_get_mtt(skb);
-
-       if ( turnaround_time == 0 )
-               return 0;
-       else if ( turnaround_time <= 10 )
-               return 1;
-       else if ( turnaround_time <= 50 )
-               return 2;
-       else if ( turnaround_time <= 100 )
-               return 3;
-       else if ( turnaround_time <= 500 )
-               return 4;
-       else if ( turnaround_time <= 1000 )
-               return 5;
-       else if ( turnaround_time <= 5000 )
-               return 6;
-       else
-               return 7;
-}
-
-
 /*------------------------------------------------------------------*/
 /*
  * Send a command to change the speed of the dongle
@@ -318,18 +262,12 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
        /* Set the new speed and xbofs in this fake frame */
        irda_usb_build_header(self, frame, 1);
 
-       if (self->capability & IUC_STIR421X) {
-               if (frame[0] == 0) return ; // do nothing if no change
-               frame[1] = 0; // other parameters don't change here
-               frame[2] = 0;
-       }
-
        /* Submit the 0 length IrDA frame to trigger new speed settings */
         usb_fill_bulk_urb(urb, self->usbdev,
                      usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
                       frame, IRDA_USB_SPEED_MTU,
                       speed_bulk_callback, self);
-       urb->transfer_buffer_length = self->header_length;
+       urb->transfer_buffer_length = USB_IRDA_HEADER;
        urb->transfer_flags = 0;
 
        /* Irq disabled -> GFP_ATOMIC */
@@ -445,35 +383,16 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
         * allocation will be done lower in skb_push().
         * Also, we don't use directly skb_cow(), because it require
         * headroom >= 16, which force unnecessary copies - Jean II */
-       if (skb_headroom(skb) < self->header_length) {
+       if (skb_headroom(skb) < USB_IRDA_HEADER) {
                IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__);
-               if (skb_cow(skb, self->header_length)) {
+               if (skb_cow(skb, USB_IRDA_HEADER)) {
                        IRDA_WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
                        goto drop;
                }
        }
 
        /* Change setting for next frame */
-
-       if (self->capability & IUC_STIR421X) {
-               __u8 turnaround_time;
-               __u8* frame;
-               turnaround_time = get_turnaround_time( skb );
-               frame= skb_push(skb, self->header_length);
-               irda_usb_build_header(self, frame, 0);
-               frame[2] = turnaround_time;
-               if ((skb->len != 0) &&
-                   ((skb->len % 128) == 0) &&
-                   ((skb->len % 512) != 0)) {
-                       /* add extra byte for special SigmaTel feature */
-                       frame[1] = 1;
-                       skb_put(skb, 1);
-               } else {
-                       frame[1] = 0;
-               }
-       } else {
-               irda_usb_build_header(self, skb_push(skb, self->header_length), 0);
-       }
+       irda_usb_build_header(self, skb_push(skb, USB_IRDA_HEADER), 0);
 
        /* FIXME: Make macro out of this one */
        ((struct irda_skb_cb *)skb->cb)->context = self;
@@ -876,7 +795,7 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
        }
        
        /* Check for empty frames */
-       if (urb->actual_length <= self->header_length) {
+       if (urb->actual_length <= USB_IRDA_HEADER) {
                IRDA_WARNING("%s(), empty frame!\n", __FUNCTION__);
                goto done;
        }
@@ -897,14 +816,7 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
        docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD);
 
        /* Allocate a new skb */
-       if (self->capability & IUC_STIR421X)
-               newskb = dev_alloc_skb(docopy ? urb->actual_length :
-                                      IRDA_SKB_MAX_MTU +
-                                      USB_IRDA_STIR421X_HEADER);
-       else
-               newskb = dev_alloc_skb(docopy ? urb->actual_length :
-                                      IRDA_SKB_MAX_MTU);
-
+       newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU);
        if (!newskb)  {
                self->stats.rx_dropped++;
                /* We could deliver the current skb, but this would stall
@@ -933,7 +845,7 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
 
        /* Set proper length on skb & remove USB-IrDA header */
        skb_put(dataskb, urb->actual_length);
-       skb_pull(dataskb, self->header_length);
+       skb_pull(dataskb, USB_IRDA_HEADER);
 
        /* Ask the networking layer to queue the packet for the IrDA stack */
        dataskb->dev = self->netdev;
@@ -1025,143 +937,6 @@ static int irda_usb_is_receiving(struct irda_usb_cb *self)
        return 0; /* For now */
 }
 
-#define STIR421X_PATCH_PRODUCT_VER     "Product Version: "
-#define STIR421X_PATCH_STMP_TAG        "STMP"
-#define STIR421X_PATCH_CODE_OFFSET     512 /* patch image starts before here */
-/* marks end of patch file header (PC DOS text file EOF character) */
-#define STIR421X_PATCH_END_OF_HDR_TAG  0x1A
-#define STIR421X_PATCH_BLOCK_SIZE      1023
-
-/*
- * Function stir421x_fwupload (struct irda_usb_cb *self,
- *                             unsigned char *patch,
- *                             const unsigned int patch_len)
- *
- *   Upload firmware code to SigmaTel 421X IRDA-USB dongle
- */
-static int stir421x_fw_upload(struct irda_usb_cb *self,
-                            unsigned char *patch,
-                            const unsigned int patch_len)
-{
-        int ret = -ENOMEM;
-        int actual_len = 0;
-        unsigned int i;
-        unsigned int block_size = 0;
-        unsigned char *patch_block;
-
-        patch_block = kzalloc(STIR421X_PATCH_BLOCK_SIZE, GFP_KERNEL);
-       if (patch_block == NULL)
-               return -ENOMEM;
-
-       /* break up patch into 1023-byte sections */
-       for (i = 0; i < patch_len; i += block_size) {
-               block_size = patch_len - i;
-
-               if (block_size > STIR421X_PATCH_BLOCK_SIZE)
-                       block_size = STIR421X_PATCH_BLOCK_SIZE;
-
-               /* upload the patch section */
-               memcpy(patch_block, patch + i, block_size);
-
-               ret = usb_bulk_msg(self->usbdev,
-                                  usb_sndbulkpipe(self->usbdev,
-                                                  self->bulk_out_ep),
-                                  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);
-
-               if (ret < 0)
-                       break;
-       }
-
-       kfree(patch_block);
-
-        return ret;
- }
-
-/*
- * Function stir421x_patch_device(struct irda_usb_cb *self)
- *
- * Get a firmware code from userspase using hotplug request_firmware() call
-  */
-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 long fw_version = 0;
-
-        /*
-         * Known firmware patch file names for STIR421x dongles
-         * are "42101001.sb" or "42101002.sb"
-         */
-        sprintf(stir421x_fw_name, "4210%4X.sb",
-                self->usbdev->descriptor.bcdDevice);
-        ret = request_firmware(&fw, stir421x_fw_name, &self->usbdev->dev);
-        if (ret < 0)
-                return ret;
-
-        /* We get a patch from userspace */
-        IRDA_MESSAGE("%s(): Received firmware %s (%zu bytes)\n",
-                     __FUNCTION__, stir421x_fw_name, fw->size);
-
-        ret = -EINVAL;
-
-       /* Get the bcd product version */
-        if (!memcmp(fw->data, STIR421X_PATCH_PRODUCT_VER,
-                    sizeof(STIR421X_PATCH_PRODUCT_VER) - 1)) {
-                fw_version_ptr = fw->data +
-                       sizeof(STIR421X_PATCH_PRODUCT_VER) - 1;
-
-                /* Let's check if the product version is dotted */
-                if (fw_version_ptr[3] == '.' &&
-                   fw_version_ptr[7] == '.') {
-                       unsigned long major, minor, build;
-                       major = simple_strtoul(fw_version_ptr, NULL, 10);
-                       minor = simple_strtoul(fw_version_ptr + 4, NULL, 10);
-                       build = simple_strtoul(fw_version_ptr + 8, NULL, 10);
-
-                       fw_version = (major << 12)
-                               + (minor << 8)
-                               + ((build / 10) << 4)
-                               + (build % 10);
-
-                       IRDA_DEBUG(3, "%s(): Firmware Product version %ld\n",
-                                   __FUNCTION__, fw_version);
-                }
-        }
-
-        if (self->usbdev->descriptor.bcdDevice == 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++) ;
-                /* 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 (!memcmp(fw->data + i + 1, STIR421X_PATCH_STMP_TAG,
-                                    sizeof(STIR421X_PATCH_STMP_TAG) - 1)) {
-
-                               /* We can upload the patch to the target */
-                               i += sizeof(STIR421X_PATCH_STMP_TAG);
-                                ret = stir421x_fw_upload(self, &fw->data[i],
-                                                        fw->size - i);
-                        }
-                }
-        }
-
-        release_firmware(fw);
-
-        return ret;
-}
-
-
 /********************** IRDA DEVICE CALLBACKS **********************/
 /*
  * Main calls from the IrDA/Network subsystem.
@@ -1197,11 +972,6 @@ static int irda_usb_net_open(struct net_device *netdev)
                return -1;
        }
 
-       if(self->needspatch) {
-               IRDA_WARNING("%s(), device needs patch\n", __FUNCTION__) ;
-               return -EIO ;
-       }
-
        /* Initialise default speed and xbofs value
         * (IrLAP will change that soon) */
        self->speed = -1;
@@ -1280,7 +1050,7 @@ static int irda_usb_net_close(struct net_device *netdev)
        del_timer(&self->rx_defer_timer);
 
        /* Deallocate all the Rx path buffers (URBs and skb) */
-       for (i = 0; i < self->max_rx_urb; i++) {
+       for (i = 0; i < IU_MAX_RX_URBS; i++) {
                struct urb *urb = self->rx_urb[i];
                struct sk_buff *skb = (struct sk_buff *) urb->context;
                /* Cancel the receive command */
@@ -1656,22 +1426,8 @@ static int irda_usb_probe(struct usb_interface *intf,
        spin_lock_init(&self->lock);
        init_timer(&self->rx_defer_timer);
 
-       self->capability = id->driver_info;
-       self->needspatch = ((self->capability & IUC_STIR421X) != 0);
-
        /* Create all of the needed urbs */
-       if (self->capability & IUC_STIR421X) {
-               self->max_rx_urb = IU_SIGMATEL_MAX_RX_URBS;
-               self->header_length = USB_IRDA_STIR421X_HEADER;
-       } else {
-               self->max_rx_urb = IU_MAX_RX_URBS;
-               self->header_length = USB_IRDA_HEADER;
-       }
-
-       self->rx_urb = kzalloc(self->max_rx_urb * sizeof(struct urb *),
-                               GFP_KERNEL);
-
-       for (i = 0; i < self->max_rx_urb; i++) {
+       for (i = 0; i < IU_MAX_RX_URBS; i++) {
                self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
                if (!self->rx_urb[i]) {
                        goto err_out_1;
@@ -1723,28 +1479,17 @@ static int irda_usb_probe(struct usb_interface *intf,
                goto err_out_3;
        }
 
-       self->usbdev = dev;
-
        /* Find IrDA class descriptor */
        irda_desc = irda_usb_find_class_desc(intf);
        ret = -ENODEV;
        if (irda_desc == NULL)
                goto err_out_3;
 
-       if (self->needspatch) {
-               ret = usb_control_msg (self->usbdev, usb_sndctrlpipe (self->usbdev, 0),
-                                      0x02, 0x40, 0, 0, NULL, 0, 500);
-               if (ret < 0) {
-                       IRDA_DEBUG (0, "usb_control_msg failed %d\n", ret);
-                       goto err_out_3;
-               } else {
-                       mdelay(10);
-               }
-       }
-
        self->irda_desc =  irda_desc;
        self->present = 1;
        self->netopen = 0;
+       self->capability = id->driver_info;
+       self->usbdev = dev;
        self->usbintf = intf;
 
        /* Allocate the buffer for speed changes */
@@ -1763,32 +1508,8 @@ static int irda_usb_probe(struct usb_interface *intf,
 
        IRDA_MESSAGE("IrDA: Registered device %s\n", net->name);
        usb_set_intfdata(intf, self);
-
-       if (self->needspatch) {
-               /* Now we fetch and upload the firmware patch */
-               ret = stir421x_patch_device(self);
-               self->needspatch = (ret < 0);
-               if (self->needspatch) {
-                       IRDA_ERROR("STIR421X: Couldn't upload patch\n");
-                       goto err_out_5;
-               }
-
-               /* replace IrDA class descriptor with what patched device is now reporting */
-               irda_desc = irda_usb_find_class_desc (self->usbintf);
-               if (irda_desc == NULL) {
-                       ret = -ENODEV;
-                       goto err_out_5;
-               }
-               if (self->irda_desc)
-                       kfree (self->irda_desc);
-               self->irda_desc = irda_desc;
-               irda_usb_init_qos(self);
-       }
-
        return 0;
 
-err_out_5:
-       unregister_netdev(self->netdev);
 err_out_4:
        kfree(self->speed_buff);
 err_out_3:
@@ -1797,7 +1518,7 @@ err_out_3:
 err_out_2:
        usb_free_urb(self->tx_urb);
 err_out_1:
-       for (i = 0; i < self->max_rx_urb; i++) {
+       for (i = 0; i < IU_MAX_RX_URBS; i++) {
                if (self->rx_urb[i])
                        usb_free_urb(self->rx_urb[i]);
        }
@@ -1850,7 +1571,7 @@ static void irda_usb_disconnect(struct usb_interface *intf)
                /*netif_device_detach(self->netdev);*/
                netif_stop_queue(self->netdev);
                /* Stop all the receive URBs. Must be synchronous. */
-               for (i = 0; i < self->max_rx_urb; i++)
+               for (i = 0; i < IU_MAX_RX_URBS; i++)
                        usb_kill_urb(self->rx_urb[i]);
                /* Cancel Tx and speed URB.
                 * Make sure it's synchronous to avoid races. */
@@ -1865,9 +1586,8 @@ static void irda_usb_disconnect(struct usb_interface *intf)
        self->usbintf = NULL;
 
        /* Clean up our urbs */
-       for (i = 0; i < self->max_rx_urb; i++)
+       for (i = 0; i < IU_MAX_RX_URBS; i++)
                usb_free_urb(self->rx_urb[i]);
-       kfree(self->rx_urb);
        /* Clean up Tx and speed URB */
        usb_free_urb(self->tx_urb);
        usb_free_urb(self->speed_urb);
@@ -1928,6 +1648,6 @@ module_exit(usb_irda_cleanup);
  */
 module_param(qos_mtt_bits, int, 0);
 MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");
-MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net>, Jean Tourrilhes <jt@hpl.hp.com> and Nick Fedchik <nick@fedchik.org.ua>");
-MODULE_DESCRIPTION("IrDA-USB Dongle Driver");
+MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net> and Jean Tourrilhes <jt@hpl.hp.com>");
+MODULE_DESCRIPTION("IrDA-USB Dongle Driver"); 
 MODULE_LICENSE("GPL");