Remove the speedtouch CRC library.  With this change, the speedtch
module is no longer a multi-part object, so fix that up too.

 b/drivers/usb/Makefile     |    4 
 b/drivers/usb/Makefile.lib |    1 
 b/drivers/usb/speedtch.c   | 1344 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/speedcrc.c     |  124 ----
 drivers/usb/speedcrc.h     |   28 
 drivers/usb/speedtouch.c   | 1344 ---------------------------------------------
 6 files changed, 1345 insertions(+), 1500 deletions(-)


diff -Nru a/drivers/usb/Makefile b/drivers/usb/Makefile
--- a/drivers/usb/Makefile      Fri Jun 27 10:15:20 2003
+++ b/drivers/usb/Makefile      Fri Jun 27 10:15:20 2003
@@ -19,7 +19,6 @@
 hid-objs               := hid-core.o
 pwc-objs               := pwc-if.o pwc-misc.o pwc-ctrl.o pwc-uncompress.o
 auerswald-objs         := auerbuf.o auerchain.o auerchar.o auermain.o
-speedtch-objs          := speedcrc.o speedtouch.o
 
 # Optional parts of multipart objects.
 
@@ -150,6 +149,3 @@
 
 auerswald.o: $(auerswald-objs)
        $(LD) -r -o $@ $(auerswald-objs)
-
-speedtch.o: $(speedtch-objs)
-       $(LD) -r -o $@ $(speedtch-objs)
diff -Nru a/drivers/usb/Makefile.lib b/drivers/usb/Makefile.lib
--- a/drivers/usb/Makefile.lib  Fri Jun 27 10:15:20 2003
+++ b/drivers/usb/Makefile.lib  Fri Jun 27 10:15:20 2003
@@ -1,3 +1,4 @@
 obj-$(CONFIG_USB_USBNET)               += crc32.o
 obj-$(CONFIG_USB_CATC)                 += crc32.o
+obj-$(CONFIG_USB_SPEEDTOUCH)           += crc32.o
 
diff -Nru a/drivers/usb/speedcrc.c b/drivers/usb/speedcrc.c
--- a/drivers/usb/speedcrc.c    Fri Jun 27 10:15:20 2003
+++ /dev/null   Wed Dec 31 16:00:00 1969
@@ -1,124 +0,0 @@
-/******************************************************************************
- *  speedcrc.c  --  CRC library for use with speedtouch.
- *
- *  Copyright (C) 2000, Johan Verrept
- *
- *  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 the Free
- *  Software Foundation; either version 2 of the License, or (at your option)
- *  any later version.
- *
- *  This program is distributed in the hope that it will be useful, but WITHOUT
- *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- *  more details.
- *
- *  You should have received a copy of the GNU General Public License along with
- *  this program; if not, write to the Free Software Foundation, Inc., 59
- *  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- ******************************************************************************/
-
-#include <stddef.h>
-
-/*
- * CRC Routines from  net/wan/sbni.c)
- * table generated by Rocksoft^tm Model CRC Algorithm Table Generation Program V1.0
- */
-#define CRC32_REMAINDER CBF43926
-#define CRC32_INITIAL 0xffffffff
-unsigned long crc32tab[256] = {
-       0x00000000L, 0x04C11DB7L, 0x09823B6EL, 0x0D4326D9L,
-       0x130476DCL, 0x17C56B6BL, 0x1A864DB2L, 0x1E475005L,
-       0x2608EDB8L, 0x22C9F00FL, 0x2F8AD6D6L, 0x2B4BCB61L,
-       0x350C9B64L, 0x31CD86D3L, 0x3C8EA00AL, 0x384FBDBDL,
-       0x4C11DB70L, 0x48D0C6C7L, 0x4593E01EL, 0x4152FDA9L,
-       0x5F15ADACL, 0x5BD4B01BL, 0x569796C2L, 0x52568B75L,
-       0x6A1936C8L, 0x6ED82B7FL, 0x639B0DA6L, 0x675A1011L,
-       0x791D4014L, 0x7DDC5DA3L, 0x709F7B7AL, 0x745E66CDL,
-       0x9823B6E0L, 0x9CE2AB57L, 0x91A18D8EL, 0x95609039L,
-       0x8B27C03CL, 0x8FE6DD8BL, 0x82A5FB52L, 0x8664E6E5L,
-       0xBE2B5B58L, 0xBAEA46EFL, 0xB7A96036L, 0xB3687D81L,
-       0xAD2F2D84L, 0xA9EE3033L, 0xA4AD16EAL, 0xA06C0B5DL,
-       0xD4326D90L, 0xD0F37027L, 0xDDB056FEL, 0xD9714B49L,
-       0xC7361B4CL, 0xC3F706FBL, 0xCEB42022L, 0xCA753D95L,
-       0xF23A8028L, 0xF6FB9D9FL, 0xFBB8BB46L, 0xFF79A6F1L,
-       0xE13EF6F4L, 0xE5FFEB43L, 0xE8BCCD9AL, 0xEC7DD02DL,
-       0x34867077L, 0x30476DC0L, 0x3D044B19L, 0x39C556AEL,
-       0x278206ABL, 0x23431B1CL, 0x2E003DC5L, 0x2AC12072L,
-       0x128E9DCFL, 0x164F8078L, 0x1B0CA6A1L, 0x1FCDBB16L,
-       0x018AEB13L, 0x054BF6A4L, 0x0808D07DL, 0x0CC9CDCAL,
-       0x7897AB07L, 0x7C56B6B0L, 0x71159069L, 0x75D48DDEL,
-       0x6B93DDDBL, 0x6F52C06CL, 0x6211E6B5L, 0x66D0FB02L,
-       0x5E9F46BFL, 0x5A5E5B08L, 0x571D7DD1L, 0x53DC6066L,
-       0x4D9B3063L, 0x495A2DD4L, 0x44190B0DL, 0x40D816BAL,
-       0xACA5C697L, 0xA864DB20L, 0xA527FDF9L, 0xA1E6E04EL,
-       0xBFA1B04BL, 0xBB60ADFCL, 0xB6238B25L, 0xB2E29692L,
-       0x8AAD2B2FL, 0x8E6C3698L, 0x832F1041L, 0x87EE0DF6L,
-       0x99A95DF3L, 0x9D684044L, 0x902B669DL, 0x94EA7B2AL,
-       0xE0B41DE7L, 0xE4750050L, 0xE9362689L, 0xEDF73B3EL,
-       0xF3B06B3BL, 0xF771768CL, 0xFA325055L, 0xFEF34DE2L,
-       0xC6BCF05FL, 0xC27DEDE8L, 0xCF3ECB31L, 0xCBFFD686L,
-       0xD5B88683L, 0xD1799B34L, 0xDC3ABDEDL, 0xD8FBA05AL,
-       0x690CE0EEL, 0x6DCDFD59L, 0x608EDB80L, 0x644FC637L,
-       0x7A089632L, 0x7EC98B85L, 0x738AAD5CL, 0x774BB0EBL,
-       0x4F040D56L, 0x4BC510E1L, 0x46863638L, 0x42472B8FL,
-       0x5C007B8AL, 0x58C1663DL, 0x558240E4L, 0x51435D53L,
-       0x251D3B9EL, 0x21DC2629L, 0x2C9F00F0L, 0x285E1D47L,
-       0x36194D42L, 0x32D850F5L, 0x3F9B762CL, 0x3B5A6B9BL,
-       0x0315D626L, 0x07D4CB91L, 0x0A97ED48L, 0x0E56F0FFL,
-       0x1011A0FAL, 0x14D0BD4DL, 0x19939B94L, 0x1D528623L,
-       0xF12F560EL, 0xF5EE4BB9L, 0xF8AD6D60L, 0xFC6C70D7L,
-       0xE22B20D2L, 0xE6EA3D65L, 0xEBA91BBCL, 0xEF68060BL,
-       0xD727BBB6L, 0xD3E6A601L, 0xDEA580D8L, 0xDA649D6FL,
-       0xC423CD6AL, 0xC0E2D0DDL, 0xCDA1F604L, 0xC960EBB3L,
-       0xBD3E8D7EL, 0xB9FF90C9L, 0xB4BCB610L, 0xB07DABA7L,
-       0xAE3AFBA2L, 0xAAFBE615L, 0xA7B8C0CCL, 0xA379DD7BL,
-       0x9B3660C6L, 0x9FF77D71L, 0x92B45BA8L, 0x9675461FL,
-       0x8832161AL, 0x8CF30BADL, 0x81B02D74L, 0x857130C3L,
-       0x5D8A9099L, 0x594B8D2EL, 0x5408ABF7L, 0x50C9B640L,
-       0x4E8EE645L, 0x4A4FFBF2L, 0x470CDD2BL, 0x43CDC09CL,
-       0x7B827D21L, 0x7F436096L, 0x7200464FL, 0x76C15BF8L,
-       0x68860BFDL, 0x6C47164AL, 0x61043093L, 0x65C52D24L,
-       0x119B4BE9L, 0x155A565EL, 0x18197087L, 0x1CD86D30L,
-       0x029F3D35L, 0x065E2082L, 0x0B1D065BL, 0x0FDC1BECL,
-       0x3793A651L, 0x3352BBE6L, 0x3E119D3FL, 0x3AD08088L,
-       0x2497D08DL, 0x2056CD3AL, 0x2D15EBE3L, 0x29D4F654L,
-       0xC5A92679L, 0xC1683BCEL, 0xCC2B1D17L, 0xC8EA00A0L,
-       0xD6AD50A5L, 0xD26C4D12L, 0xDF2F6BCBL, 0xDBEE767CL,
-       0xE3A1CBC1L, 0xE760D676L, 0xEA23F0AFL, 0xEEE2ED18L,
-       0xF0A5BD1DL, 0xF464A0AAL, 0xF9278673L, 0xFDE69BC4L,
-       0x89B8FD09L, 0x8D79E0BEL, 0x803AC667L, 0x84FBDBD0L,
-       0x9ABC8BD5L, 0x9E7D9662L, 0x933EB0BBL, 0x97FFAD0CL,
-       0xAFB010B1L, 0xAB710D06L, 0xA6322BDFL, 0xA2F33668L,
-       0xBCB4666DL, 0xB8757BDAL, 0xB5365D03L, 0xB1F740B4L
-};
-
-#ifdef CRCASM
-
-unsigned long spdcrc32 (char *mem, int len, unsigned initial)
-{
-       unsigned crc, dummy_len;
-      __asm__ ("xorl %%eax,%%eax\n\t" "1:\n\t" "movl %%edx,%%eax\n\t" "shrl 
$16,%%eax\n\t" "lodsb\n\t" "xorb %%ah,%%al\n\t" "andl $255,%%eax\n\t" "shll 
$8,%%edx\n\t" "xorl (%%edi,%%eax,4),%%edx\n\t" "loop 1b":"=d" (crc),
-                "=c"
-                (dummy_len)
-      :         "S" (mem), "D" (&crc32tab[0]), "1" (len), "0" (initial)
-      :         "eax");
-       return crc;
-}
-
-#else
-
-#define CRC32(c,crc) (crc32tab[((size_t)(crc>>24) ^ (c)) & 0xff] ^ (((crc) << 8)))
-
-unsigned long spdcrc32 (char *mem, int len, unsigned initial)
-{
-       unsigned crc;
-       crc = initial;
-
-       for (; len; mem++, len--) {
-               crc = CRC32 (*mem, crc);
-       }
-       return (crc);
-}
-#endif
diff -Nru a/drivers/usb/speedcrc.h b/drivers/usb/speedcrc.h
--- a/drivers/usb/speedcrc.h    Fri Jun 27 10:15:20 2003
+++ /dev/null   Wed Dec 31 16:00:00 1969
@@ -1,28 +0,0 @@
-#ifndef _SPEEDCRC_H_
-#define _SPEEDCRC_H_
-
-/******************************************************************************
- *  speedcrc.h  --  CRC library for use with speedtouch.
- *
- *  Copyright (C) 2000, Johan Verrept
- *
- *  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 the Free
- *  Software Foundation; either version 2 of the License, or (at your option)
- *  any later version.
- *
- *  This program is distributed in the hope that it will be useful, but WITHOUT
- *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- *  more details.
- *
- *  You should have received a copy of the GNU General Public License along with
- *  this program; if not, write to the Free Software Foundation, Inc., 59
- *  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- ******************************************************************************/
-
-unsigned long spdcrc32 (char *mem, int len, unsigned initial);
-#define crc32_be(crc, mem, len) spdcrc32(mem, len, crc)
-
-#endif                         /* _SPEEDCRC_H_ */
diff -Nru a/drivers/usb/speedtch.c b/drivers/usb/speedtch.c
--- /dev/null   Wed Dec 31 16:00:00 1969
+++ b/drivers/usb/speedtch.c    Fri Jun 27 10:15:20 2003
@@ -0,0 +1,1344 @@
+/******************************************************************************
+ *  speedtouch.c  -  Alcatel SpeedTouch USB xDSL modem driver
+ *
+ *  Copyright (C) 2001, Alcatel
+ *  Copyright (C) 2003, Duncan Sands
+ *
+ *  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 the Free
+ *  Software Foundation; either version 2 of the License, or (at your option)
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but WITHOUT
+ *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ *  more details.
+ *
+ *  You should have received a copy of the GNU General Public License along with
+ *  this program; if not, write to the Free Software Foundation, Inc., 59
+ *  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ ******************************************************************************/
+
+/*
+ *  Written by Johan Verrept, maintained by Duncan Sands ([EMAIL PROTECTED])
+ *
+ *  1.6:       - No longer opens a connection if the firmware is not loaded
+ *             - Added support for the speedtouch 330
+ *             - Removed the limit on the number of devices
+ *             - Module now autoloads on device plugin
+ *             - Merged relevant parts of sarlib
+ *             - Replaced the kernel thread with a tasklet
+ *             - New packet transmission code
+ *             - Changed proc file contents
+ *             - Fixed all known SMP races
+ *             - Many fixes and cleanups
+ *             - Various fixes by Oliver Neukum ([EMAIL PROTECTED])
+ *
+ *  1.5A:      - Backport of version for inclusion in 2.5 series kernel
+ *             - Modifications by Richard Purdie ([EMAIL PROTECTED])
+ *             - made compatible with kernel 2.5.6 onwards by changing
+ *             udsl_usb_send_data_context->urb to a pointer and adding code
+ *             to alloc and free it
+ *             - remove_wait_queue() added to udsl_atm_processqueue_thread()
+ *
+ *  1.5:       - fixed memory leak when atmsar_decode_aal5 returned NULL.
+ *             (reported by [EMAIL PROTECTED])
+ *
+ *  1.4:       - changed the spin_lock() under interrupt to spin_lock_irqsave()
+ *             - unlink all active send urbs of a vcc that is being closed.
+ *
+ *  1.3.1:     - added the version number
+ *
+ *  1.3:       - Added multiple send urb support
+ *             - fixed memory leak and vcc->tx_inuse starvation bug
+ *               when not enough memory left in vcc.
+ *
+ *  1.2:       - Fixed race condition in udsl_usb_send_data()
+ *  1.1:       - Turned off packet debugging
+ *
+ */
+
+#include <asm/semaphore.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/timer.h>
+#include <linux/errno.h>
+#include <linux/proc_fs.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+#include <asm/uaccess.h>
+#include <linux/smp_lock.h>
+#include <linux/interrupt.h>
+#include <linux/atm.h>
+#include <linux/atmdev.h>
+#include <linux/crc32.h>
+#include <linux/init.h>
+
+/*
+#define DEBUG
+#define VERBOSE_DEBUG
+*/
+
+#include <linux/usb.h>
+
+
+#ifdef VERBOSE_DEBUG
+static int udsl_print_packet (const unsigned char *data, int len);
+#define PACKETDEBUG(arg...)    udsl_print_packet (arg)
+#define vdbg(arg...)           dbg (arg)
+#else
+#define PACKETDEBUG(arg...)
+#define vdbg(arg...)
+#endif
+
+#define DRIVER_AUTHOR  "Johan Verrept, Duncan Sands <[EMAIL PROTECTED]>"
+#define DRIVER_DESC    "Alcatel SpeedTouch USB driver"
+#define DRIVER_VERSION "1.6"
+
+static const char udsl_driver_name [] = "speedtch";
+
+#define SPEEDTOUCH_VENDORID            0x06b9
+#define SPEEDTOUCH_PRODUCTID           0x4061
+
+#define UDSL_MAX_RCV_URBS              4
+#define UDSL_MAX_SND_URBS              4
+#define UDSL_MAX_RCV_BUFS              8
+#define UDSL_MAX_SND_BUFS              8
+#define UDSL_MAX_RCV_BUF_SIZE          1024 /* ATM cells */
+#define UDSL_MAX_SND_BUF_SIZE          1024 /* ATM cells */
+#define UDSL_DEFAULT_RCV_URBS          1
+#define UDSL_DEFAULT_SND_URBS          1
+#define UDSL_DEFAULT_RCV_BUFS          2
+#define UDSL_DEFAULT_SND_BUFS          2
+#define UDSL_DEFAULT_RCV_BUF_SIZE      64 /* ATM cells */
+#define UDSL_DEFAULT_SND_BUF_SIZE      64 /* ATM cells */
+
+static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
+static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
+static unsigned int num_rcv_bufs = UDSL_DEFAULT_RCV_BUFS;
+static unsigned int num_snd_bufs = UDSL_DEFAULT_SND_BUFS;
+static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
+static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
+
+MODULE_PARM (num_rcv_urbs, "i");
+MODULE_PARM_DESC (num_rcv_urbs, "Number of urbs used for reception (range: 0-" 
__MODULE_STRING (UDSL_MAX_RCV_URBS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_RCV_URBS) ")");
+
+MODULE_PARM (num_snd_urbs, "i");
+MODULE_PARM_DESC (num_snd_urbs, "Number of urbs used for transmission (range: 0-" 
__MODULE_STRING (UDSL_MAX_SND_URBS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_SND_URBS) ")");
+
+MODULE_PARM (num_rcv_bufs, "i");
+MODULE_PARM_DESC (num_rcv_bufs, "Number of buffers used for reception (range: 0-" 
__MODULE_STRING (UDSL_MAX_RCV_BUFS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_RCV_BUFS) ")");
+
+MODULE_PARM (num_snd_bufs, "i");
+MODULE_PARM_DESC (num_snd_bufs, "Number of buffers used for transmission (range: 0-" 
__MODULE_STRING (UDSL_MAX_SND_BUFS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_SND_BUFS) ")");
+
+MODULE_PARM (rcv_buf_size, "i");
+MODULE_PARM_DESC (rcv_buf_size, "Size of the buffers used for reception (range: 0-" 
__MODULE_STRING (UDSL_MAX_RCV_BUF_SIZE) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
+
+MODULE_PARM (snd_buf_size, "i");
+MODULE_PARM_DESC (snd_buf_size, "Size of the buffers used for transmission (range: 
0-" __MODULE_STRING (UDSL_MAX_SND_BUF_SIZE) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_SND_BUF_SIZE) ")");
+
+#define UDSL_IOCTL_LINE_UP             1
+#define UDSL_IOCTL_LINE_DOWN           2
+
+#define UDSL_ENDPOINT_DATA_OUT         0x07
+#define UDSL_ENDPOINT_DATA_IN          0x87
+
+#define ATM_CELL_HEADER                        (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
+#define UDSL_NUM_CELLS(x)              (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 
1) / ATM_CELL_PAYLOAD)
+
+#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
+
+static struct usb_device_id udsl_usb_ids [] = {
+       { USB_DEVICE (SPEEDTOUCH_VENDORID, SPEEDTOUCH_PRODUCTID) },
+       { }
+};
+
+MODULE_DEVICE_TABLE (usb, udsl_usb_ids);
+
+/* receive */
+
+struct udsl_receive_buffer {
+       struct list_head list;
+       unsigned char *base;
+       unsigned int filled_cells;
+};
+
+struct udsl_receiver {
+       struct list_head list;
+       struct udsl_receive_buffer *buffer;
+       struct urb *urb;
+       struct udsl_instance_data *instance;
+};
+
+struct udsl_vcc_data {
+       /* vpi/vci lookup */
+       struct list_head list;
+       short vpi;
+       int vci;
+       struct atm_vcc *vcc;
+
+       /* raw cell reassembly */
+       struct sk_buff *skb;
+       unsigned int max_pdu;
+};
+
+/* send */
+
+struct udsl_send_buffer {
+       struct list_head list;
+       unsigned char *base;
+       unsigned char *free_start;
+       unsigned int free_cells;
+};
+
+struct udsl_sender {
+       struct list_head list;
+       struct udsl_send_buffer *buffer;
+       struct urb *urb;
+       struct udsl_instance_data *instance;
+};
+
+struct udsl_control {
+       struct atm_skb_data atm_data;
+       unsigned int num_cells;
+       unsigned int num_entire;
+       unsigned int pdu_padding;
+       unsigned char cell_header [ATM_CELL_HEADER];
+       unsigned char aal5_trailer [ATM_AAL5_TRAILER];
+};
+
+#define UDSL_SKB(x)            ((struct udsl_control *)(x)->cb)
+
+/* main driver data */
+
+struct udsl_instance_data {
+       struct semaphore serialize;
+
+       /* USB device part */
+       struct usb_device *usb_dev;
+       char description [64];
+       int firmware_loaded;
+
+       /* ATM device part */
+       struct atm_dev *atm_dev;
+       struct list_head vcc_list;
+
+       /* receive */
+       struct udsl_receiver receivers [UDSL_MAX_RCV_URBS];
+       struct udsl_receive_buffer receive_buffers [UDSL_MAX_RCV_BUFS];
+
+       spinlock_t receive_lock;
+       struct list_head spare_receivers;
+       struct list_head filled_receive_buffers;
+
+       struct tasklet_struct receive_tasklet;
+       struct list_head spare_receive_buffers;
+
+       /* send */
+       struct udsl_sender senders [UDSL_MAX_SND_URBS];
+       struct udsl_send_buffer send_buffers [UDSL_MAX_SND_BUFS];
+
+       struct sk_buff_head sndqueue;
+
+       spinlock_t send_lock;
+       struct list_head spare_senders;
+       struct list_head spare_send_buffers;
+
+       struct tasklet_struct send_tasklet;
+       struct sk_buff *current_skb;                    /* being emptied */
+       struct udsl_send_buffer *current_buffer;        /* being filled */
+       struct list_head filled_send_buffers;
+};
+
+/* ATM */
+
+static void udsl_atm_dev_close (struct atm_dev *dev);
+static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci);
+static void udsl_atm_close (struct atm_vcc *vcc);
+static int udsl_atm_ioctl (struct atm_dev *dev, unsigned int cmd, void *arg);
+static int udsl_atm_send (struct atm_vcc *vcc, struct sk_buff *skb);
+static int udsl_atm_proc_read (struct atm_dev *atm_dev, loff_t *pos, char *page);
+
+static struct atmdev_ops udsl_atm_devops = {
+       dev_close:      udsl_atm_dev_close,
+       open:           udsl_atm_open,
+       close:          udsl_atm_close,
+       ioctl:          udsl_atm_ioctl,
+       send:           udsl_atm_send,
+       proc_read:      udsl_atm_proc_read,
+       owner:          THIS_MODULE,
+};
+
+/* USB */
+
+static void *udsl_usb_probe (struct usb_device *dev, unsigned int ifnum, const struct 
usb_device_id *id);
+static void udsl_usb_disconnect (struct usb_device *dev, void *ptr);
+static int udsl_usb_ioctl (struct usb_device *hub, unsigned int code, void 
*user_data);
+
+static struct usb_driver udsl_usb_driver = {
+       owner:          THIS_MODULE,
+       name:           udsl_driver_name,
+       probe:          udsl_usb_probe,
+       disconnect:     udsl_usb_disconnect,
+       ioctl:          udsl_usb_ioctl,
+       id_table:       udsl_usb_ids,
+};
+
+
+/*************
+**  decode  **
+*************/
+
+static inline struct udsl_vcc_data *udsl_find_vcc (struct udsl_instance_data 
*instance, short vpi, int vci)
+{
+       struct udsl_vcc_data *vcc;
+
+       list_for_each_entry (vcc, &instance->vcc_list, list)
+               if ((vcc->vci == vci) && (vcc->vpi == vpi))
+                       return vcc;
+       return NULL;
+}
+
+static void udsl_extract_cells (struct udsl_instance_data *instance, unsigned char 
*source, unsigned int howmany)
+{
+       struct udsl_vcc_data *cached_vcc = NULL;
+       struct atm_vcc *vcc;
+       struct sk_buff *skb;
+       struct udsl_vcc_data *vcc_data;
+       int cached_vci = 0;
+       unsigned int i;
+       unsigned int length;
+       unsigned int pdu_length;
+       int pti;
+       int vci;
+       short cached_vpi = 0;
+       short vpi;
+
+       for (i = 0; i < howmany; i++, source += ATM_CELL_SIZE) {
+               vpi = ((source [0] & 0x0f) << 4) | (source [1] >> 4);
+               vci = ((source [1] & 0x0f) << 12) | (source [2] << 4) | (source [3] >> 
4);
+               pti = (source [3] & 0x2) != 0;
+
+               vdbg ("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti);
+
+               if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi))
+                       vcc_data = cached_vcc;
+               else if ((vcc_data = udsl_find_vcc (instance, vpi, vci))) {
+                       cached_vcc = vcc_data;
+                       cached_vpi = vpi;
+                       cached_vci = vci;
+               } else {
+                       dbg ("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, 
vci);
+                       continue;
+               }
+
+               vcc = vcc_data->vcc;
+
+               if (!vcc_data->skb && !(vcc_data->skb = dev_alloc_skb 
(vcc_data->max_pdu))) {
+                       dbg ("udsl_extract_cells: no memory for skb (vcc: 0x%p)!", 
vcc);
+                       if (pti)
+                               atomic_inc (&vcc->stats->rx_err);
+                       continue;
+               }
+
+               skb = vcc_data->skb;
+
+               if (skb->len + ATM_CELL_PAYLOAD > vcc_data->max_pdu) {
+                       dbg ("udsl_extract_cells: buffer overrun (max_pdu: %u, 
skb->len %u, vcc: 0x%p)", vcc_data->max_pdu, skb->len, vcc);
+                       /* discard cells already received */
+                       skb_trim (skb, 0);
+                       BUG_ON (vcc_data->max_pdu < ATM_CELL_PAYLOAD);
+               }
+
+               memcpy (skb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
+               __skb_put (skb, ATM_CELL_PAYLOAD);
+
+               if (pti) {
+                       length = (source [ATM_CELL_SIZE - 6] << 8) + source 
[ATM_CELL_SIZE - 5];
+
+                       /* guard against overflow */
+                       if (length > ATM_MAX_AAL5_PDU) {
+                               dbg ("udsl_extract_cells: bogus length %u (vcc: 
0x%p)", length, vcc);
+                               goto drop;
+                       }
+
+                       pdu_length = UDSL_NUM_CELLS (length) * ATM_CELL_PAYLOAD;
+
+                       if (skb->len < pdu_length) {
+                               dbg ("udsl_extract_cells: bogus pdu_length %u 
(skb->len: %u, vcc: 0x%p)", pdu_length, skb->len, vcc);
+                               goto drop;
+                       }
+
+                       if (crc32_be (~0, skb->tail - pdu_length, pdu_length) != 
0xc704dd7b) {
+                               dbg ("udsl_extract_cells: packet failed crc check 
(vcc: 0x%p)", vcc);
+                               goto drop;
+                       }
+
+                       if (!atm_charge (vcc, skb->truesize)) {
+                               dbg ("udsl_extract_cells: failed atm_charge 
(skb->truesize: %u)", skb->truesize);
+                               goto drop_no_stats; /* atm_charge increments rx_drop */
+                       }
+
+                       /* now that we are sure to send the skb, it is ok to change 
skb->data */
+                       if (skb->len > pdu_length)
+                               skb_pull (skb, skb->len - pdu_length); /* discard 
initial junk */
+
+                       skb_trim (skb, length); /* drop zero padding and trailer */
+
+                       atomic_inc (&vcc->stats->rx);
+
+                       PACKETDEBUG (skb->data, skb->len);
+
+                       vdbg ("udsl_extract_cells: sending skb 0x%p, skb->len %u, 
skb->truesize %u", skb, skb->len, skb->truesize);
+
+                       vcc->push (vcc, skb);
+
+                       vcc_data->skb = NULL;
+
+                       continue;
+
+drop:
+                       atomic_inc (&vcc->stats->rx_err);
+drop_no_stats:
+                       skb_trim (skb, 0);
+               }
+       }
+}
+
+
+/*************
+**  encode  **
+*************/
+
+static const unsigned char zeros [ATM_CELL_PAYLOAD];
+
+static void udsl_groom_skb (struct atm_vcc *vcc, struct sk_buff *skb)
+{
+       struct udsl_control *ctrl = UDSL_SKB (skb);
+       unsigned int zero_padding;
+       u32 crc;
+
+       ctrl->atm_data.vcc = vcc;
+       ctrl->cell_header [0] = vcc->vpi >> 4;
+       ctrl->cell_header [1] = (vcc->vpi << 4) | (vcc->vci >> 12);
+       ctrl->cell_header [2] = vcc->vci >> 4;
+       ctrl->cell_header [3] = vcc->vci << 4;
+       ctrl->cell_header [4] = 0xec;
+
+       ctrl->num_cells = UDSL_NUM_CELLS (skb->len);
+       ctrl->num_entire = skb->len / ATM_CELL_PAYLOAD;
+
+       zero_padding = ctrl->num_cells * ATM_CELL_PAYLOAD - skb->len - 
ATM_AAL5_TRAILER;
+
+       if (ctrl->num_entire + 1 < ctrl->num_cells)
+               ctrl->pdu_padding = zero_padding - (ATM_CELL_PAYLOAD - 
ATM_AAL5_TRAILER);
+       else
+               ctrl->pdu_padding = zero_padding;
+
+       ctrl->aal5_trailer [0] = 0; /* UU = 0 */
+       ctrl->aal5_trailer [1] = 0; /* CPI = 0 */
+       ctrl->aal5_trailer [2] = skb->len >> 8;
+       ctrl->aal5_trailer [3] = skb->len;
+
+       crc = crc32_be (~0, skb->data, skb->len);
+       crc = crc32_be (crc, zeros, zero_padding);
+       crc = crc32_be (crc, ctrl->aal5_trailer, 4);
+       crc = ~crc;
+
+       ctrl->aal5_trailer [4] = crc >> 24;
+       ctrl->aal5_trailer [5] = crc >> 16;
+       ctrl->aal5_trailer [6] = crc >> 8;
+       ctrl->aal5_trailer [7] = crc;
+}
+
+static unsigned int udsl_write_cells (unsigned int howmany, struct sk_buff *skb, 
unsigned char **target_p)
+{
+       struct udsl_control *ctrl = UDSL_SKB (skb);
+       unsigned char *target = *target_p;
+       unsigned int nc, ne, i;
+
+       vdbg ("udsl_write_cells: howmany=%u, skb->len=%d, num_cells=%u, num_entire=%u, 
pdu_padding=%u", howmany, skb->len, ctrl->num_cells, ctrl->num_entire, 
ctrl->pdu_padding);
+
+       nc = ctrl->num_cells;
+       ne = min (howmany, ctrl->num_entire);
+
+       for (i = 0; i < ne; i++) {
+               memcpy (target, ctrl->cell_header, ATM_CELL_HEADER);
+               target += ATM_CELL_HEADER;
+               memcpy (target, skb->data, ATM_CELL_PAYLOAD);
+               target += ATM_CELL_PAYLOAD;
+               __skb_pull (skb, ATM_CELL_PAYLOAD);
+       }
+
+       ctrl->num_entire -= ne;
+
+       if (!(ctrl->num_cells -= ne) || !(howmany -= ne))
+               goto out;
+
+       memcpy (target, ctrl->cell_header, ATM_CELL_HEADER);
+       target += ATM_CELL_HEADER;
+       memcpy (target, skb->data, skb->len);
+       target += skb->len;
+       __skb_pull (skb, skb->len);
+       memset (target, 0, ctrl->pdu_padding);
+       target += ctrl->pdu_padding;
+
+       if (--ctrl->num_cells) {
+               if (!--howmany) {
+                       ctrl->pdu_padding = ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
+                       goto out;
+               }
+
+               memcpy (target, ctrl->cell_header, ATM_CELL_HEADER);
+               target += ATM_CELL_HEADER;
+               memset (target, 0, ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
+               target += ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
+
+               BUG_ON (--ctrl->num_cells);
+       }
+
+       memcpy (target, ctrl->aal5_trailer, ATM_AAL5_TRAILER);
+       target += ATM_AAL5_TRAILER;
+       /* set pti bit in last cell */
+       *(target + 3 - ATM_CELL_SIZE) |= 0x2;
+
+out:
+       *target_p = target;
+       return nc - ctrl->num_cells;
+}
+
+
+/**************
+**  receive  **
+**************/
+
+static void udsl_complete_receive (struct urb *urb)
+{
+       struct udsl_receive_buffer *buf;
+       struct udsl_instance_data *instance;
+       struct udsl_receiver *rcv;
+       unsigned long flags;
+
+       if (!urb || !(rcv = urb->context)) {
+               dbg ("udsl_complete_receive: bad urb!");
+               return;
+       }
+
+       instance = rcv->instance;
+       buf = rcv->buffer;
+
+       buf->filled_cells = urb->actual_length / ATM_CELL_SIZE;
+
+       vdbg ("udsl_complete_receive: urb 0x%p, status %d, actual_length %d, 
filled_cells %u, rcv 0x%p, buf 0x%p", urb, urb->status, urb->actual_length, 
buf->filled_cells, rcv, buf);
+
+       BUG_ON (buf->filled_cells > rcv_buf_size);
+
+       /* may not be in_interrupt() */
+       spin_lock_irqsave (&instance->receive_lock, flags);
+       list_add (&rcv->list, &instance->spare_receivers);
+       list_add_tail (&buf->list, &instance->filled_receive_buffers);
+       if (likely (!urb->status))
+               tasklet_schedule (&instance->receive_tasklet);
+       spin_unlock_irqrestore (&instance->receive_lock, flags);
+}
+
+static void udsl_process_receive (unsigned long data)
+{
+       struct udsl_receive_buffer *buf;
+       struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
+       struct udsl_receiver *rcv;
+       int err;
+
+made_progress:
+       while (!list_empty (&instance->spare_receive_buffers)) {
+               spin_lock_irq (&instance->receive_lock);
+               if (list_empty (&instance->spare_receivers)) {
+                       spin_unlock_irq (&instance->receive_lock);
+                       break;
+               }
+               rcv = list_entry (instance->spare_receivers.next, struct 
udsl_receiver, list);
+               list_del (&rcv->list);
+               spin_unlock_irq (&instance->receive_lock);
+
+               buf = list_entry (instance->spare_receive_buffers.next, struct 
udsl_receive_buffer, list);
+               list_del (&buf->list);
+
+               rcv->buffer = buf;
+
+               FILL_BULK_URB (rcv->urb,
+                              instance->usb_dev,
+                              usb_rcvbulkpipe (instance->usb_dev, 
UDSL_ENDPOINT_DATA_IN),
+                              buf->base,
+                              rcv_buf_size * ATM_CELL_SIZE,
+                              udsl_complete_receive,
+                              rcv);
+               rcv->urb->transfer_flags |= USB_QUEUE_BULK;
+
+               vdbg ("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p", 
rcv->urb, rcv, buf);
+
+               if ((err = usb_submit_urb(rcv->urb)) < 0) {
+                       dbg ("udsl_process_receive: urb submission failed (%d)!", err);
+                       list_add (&buf->list, &instance->spare_receive_buffers);
+                       spin_lock_irq (&instance->receive_lock);
+                       list_add (&rcv->list, &instance->spare_receivers);
+                       spin_unlock_irq (&instance->receive_lock);
+                       break;
+               }
+       }
+
+       spin_lock_irq (&instance->receive_lock);
+       if (list_empty (&instance->filled_receive_buffers)) {
+               spin_unlock_irq (&instance->receive_lock);
+               return; /* done - no more buffers */
+       }
+       buf = list_entry (instance->filled_receive_buffers.next, struct 
udsl_receive_buffer, list);
+       list_del (&buf->list);
+       spin_unlock_irq (&instance->receive_lock);
+       vdbg ("udsl_process_receive: processing buf 0x%p", buf);
+       udsl_extract_cells (instance, buf->base, buf->filled_cells);
+       list_add (&buf->list, &instance->spare_receive_buffers);
+       goto made_progress;
+}
+
+
+/***********
+**  send  **
+***********/
+
+static void udsl_complete_send (struct urb *urb)
+{
+       struct udsl_instance_data *instance;
+       struct udsl_sender *snd;
+       unsigned long flags;
+
+       if (!urb || !(snd = urb->context) || !(instance = snd->instance)) {
+               dbg ("udsl_complete_send: bad urb!");
+               return;
+       }
+
+       vdbg ("udsl_complete_send: urb 0x%p, status %d, snd 0x%p, buf 0x%p", urb, 
urb->status, snd, snd->buffer);
+
+       /* may not be in_interrupt() */
+       spin_lock_irqsave (&instance->send_lock, flags);
+       list_add (&snd->list, &instance->spare_senders);
+       list_add (&snd->buffer->list, &instance->spare_send_buffers);
+       tasklet_schedule (&instance->send_tasklet);
+       spin_unlock_irqrestore (&instance->send_lock, flags);
+}
+
+static void udsl_process_send (unsigned long data)
+{
+       struct udsl_send_buffer *buf;
+       struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
+       struct sk_buff *skb;
+       struct udsl_sender *snd;
+       int err;
+       unsigned int num_written;
+
+made_progress:
+       spin_lock_irq (&instance->send_lock);
+       while (!list_empty (&instance->spare_senders)) {
+               if (!list_empty (&instance->filled_send_buffers)) {
+                       buf = list_entry (instance->filled_send_buffers.next, struct 
udsl_send_buffer, list);
+                       list_del (&buf->list);
+               } else if ((buf = instance->current_buffer)) {
+                       instance->current_buffer = NULL;
+               } else /* all buffers empty */
+                       break;
+
+               snd = list_entry (instance->spare_senders.next, struct udsl_sender, 
list);
+               list_del (&snd->list);
+               spin_unlock_irq (&instance->send_lock);
+
+               snd->buffer = buf;
+               FILL_BULK_URB (snd->urb,
+                              instance->usb_dev,
+                              usb_sndbulkpipe (instance->usb_dev, 
UDSL_ENDPOINT_DATA_OUT),
+                              buf->base,
+                              (snd_buf_size - buf->free_cells) * ATM_CELL_SIZE,
+                              udsl_complete_send,
+                              snd);
+               snd->urb->transfer_flags |= USB_QUEUE_BULK;
+
+               vdbg ("udsl_process_send: submitting urb 0x%p (%d cells), snd 0x%p, 
buf 0x%p", snd->urb, snd_buf_size - buf->free_cells, snd, buf);
+
+               if ((err = usb_submit_urb(snd->urb)) < 0) {
+                       dbg ("udsl_process_send: urb submission failed (%d)!", err);
+                       spin_lock_irq (&instance->send_lock);
+                       list_add (&snd->list, &instance->spare_senders);
+                       spin_unlock_irq (&instance->send_lock);
+                       list_add (&buf->list, &instance->filled_send_buffers);
+                       return; /* bail out */
+               }
+
+               spin_lock_irq (&instance->send_lock);
+       } /* while */
+       spin_unlock_irq (&instance->send_lock);
+
+       if (!instance->current_skb && !(instance->current_skb = skb_dequeue 
(&instance->sndqueue)))
+               return; /* done - no more skbs */
+
+       skb = instance->current_skb;
+
+       if (!(buf = instance->current_buffer)) {
+               spin_lock_irq (&instance->send_lock);
+               if (list_empty (&instance->spare_send_buffers)) {
+                       instance->current_buffer = NULL;
+                       spin_unlock_irq (&instance->send_lock);
+                       return; /* done - no more buffers */
+               }
+               buf = list_entry (instance->spare_send_buffers.next, struct 
udsl_send_buffer, list);
+               list_del (&buf->list);
+               spin_unlock_irq (&instance->send_lock);
+
+               buf->free_start = buf->base;
+               buf->free_cells = snd_buf_size;
+
+               instance->current_buffer = buf;
+       }
+
+       num_written = udsl_write_cells (buf->free_cells, skb, &buf->free_start);
+
+       vdbg ("udsl_process_send: wrote %u cells from skb 0x%p to buffer 0x%p", 
num_written, skb, buf);
+
+       if (!(buf->free_cells -= num_written)) {
+               list_add_tail (&buf->list, &instance->filled_send_buffers);
+               instance->current_buffer = NULL;
+       }
+
+       vdbg ("udsl_process_send: buffer contains %d cells, %d left", snd_buf_size - 
buf->free_cells, buf->free_cells);
+
+       if (!UDSL_SKB (skb)->num_cells) {
+               struct atm_vcc *vcc = UDSL_SKB (skb)->atm_data.vcc;
+
+               if (vcc->pop)
+                       vcc->pop (vcc, skb);
+               else
+                       dev_kfree_skb (skb);
+               instance->current_skb = NULL;
+
+               atomic_inc (&vcc->stats->tx);
+       }
+
+       goto made_progress;
+}
+
+static void udsl_cancel_send (struct udsl_instance_data *instance, struct atm_vcc 
*vcc)
+{
+       struct sk_buff *skb, *n;
+
+       dbg ("udsl_cancel_send entered");
+       spin_lock_irq (&instance->sndqueue.lock);
+       for (skb = instance->sndqueue.next, n = skb->next; skb != (struct sk_buff 
*)&instance->sndqueue; skb = n, n = skb->next)
+               if (UDSL_SKB (skb)->atm_data.vcc == vcc) {
+                       dbg ("udsl_cancel_send: popping skb 0x%p", skb);
+                       __skb_unlink (skb, &instance->sndqueue);
+                       if (vcc->pop)
+                               vcc->pop (vcc, skb);
+                       else
+                               dev_kfree_skb (skb);
+               }
+       spin_unlock_irq (&instance->sndqueue.lock);
+
+       tasklet_disable (&instance->send_tasklet);
+       if ((skb = instance->current_skb) && (UDSL_SKB (skb)->atm_data.vcc == vcc)) {
+               dbg ("udsl_cancel_send: popping current skb (0x%p)", skb);
+               instance->current_skb = NULL;
+               if (vcc->pop)
+                       vcc->pop (vcc, skb);
+               else
+                       dev_kfree_skb (skb);
+       }
+       tasklet_enable (&instance->send_tasklet);
+       dbg ("udsl_cancel_send done");
+}
+
+static int udsl_atm_send (struct atm_vcc *vcc, struct sk_buff *skb)
+{
+       struct udsl_instance_data *instance = vcc->dev->dev_data;
+
+       vdbg ("udsl_atm_send called (skb 0x%p, len %u)", skb, skb->len);
+
+       if (!instance || !instance->usb_dev) {
+               dbg ("udsl_atm_send: NULL data!");
+               return -ENODEV;
+       }
+
+       if (vcc->qos.aal != ATM_AAL5) {
+               dbg ("udsl_atm_send: unsupported ATM type %d!", vcc->qos.aal);
+               return -EINVAL;
+       }
+
+       if (skb->len > ATM_MAX_AAL5_PDU) {
+               dbg ("udsl_atm_send: packet too long (%d vs %d)!", skb->len, 
ATM_MAX_AAL5_PDU);
+               return -EINVAL;
+       }
+
+       PACKETDEBUG (skb->data, skb->len);
+
+       udsl_groom_skb (vcc, skb);
+       skb_queue_tail (&instance->sndqueue, skb);
+       tasklet_schedule (&instance->send_tasklet);
+
+       return 0;
+}
+
+
+/**********
+**  ATM  **
+**********/
+
+static void udsl_atm_dev_close (struct atm_dev *dev)
+{
+       struct udsl_instance_data *instance = dev->dev_data;
+
+       if (!instance) {
+               dbg ("udsl_atm_dev_close: NULL instance!");
+               return;
+       }
+
+       dbg ("udsl_atm_dev_close: queue has %u elements", instance->sndqueue.qlen);
+
+       tasklet_kill (&instance->receive_tasklet);
+       tasklet_kill (&instance->send_tasklet);
+       kfree (instance);
+       dev->dev_data = NULL;
+}
+
+static int udsl_atm_proc_read (struct atm_dev *atm_dev, loff_t *pos, char *page)
+{
+       struct udsl_instance_data *instance = atm_dev->dev_data;
+       int left = *pos;
+
+       if (!instance) {
+               dbg ("udsl_atm_proc_read: NULL instance!");
+               return -ENODEV;
+       }
+
+       if (!left--)
+               return sprintf (page, "%s\n", instance->description);
+
+       if (!left--)
+               return sprintf (page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
+                               atm_dev->esi [0], atm_dev->esi [1], atm_dev->esi [2],
+                               atm_dev->esi [3], atm_dev->esi [4], atm_dev->esi [5]);
+
+       if (!left--)
+               return sprintf (page, "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop 
)\n",
+                               atomic_read (&atm_dev->stats.aal5.tx),
+                               atomic_read (&atm_dev->stats.aal5.tx_err),
+                               atomic_read (&atm_dev->stats.aal5.rx),
+                               atomic_read (&atm_dev->stats.aal5.rx_err),
+                               atomic_read (&atm_dev->stats.aal5.rx_drop));
+
+       if (!left--) {
+               switch (atm_dev->signal) {
+               case ATM_PHY_SIG_FOUND:
+                       sprintf (page, "Line up");
+                       break;
+               case ATM_PHY_SIG_LOST:
+                       sprintf (page, "Line down");
+                       break;
+               default:
+                       sprintf (page, "Line state unknown");
+                       break;
+               }
+
+               if (instance->usb_dev) {
+                       if (!instance->firmware_loaded)
+                               strcat (page, ", no firmware\n");
+                       else
+                               strcat (page, ", firmware loaded\n");
+               } else
+                       strcat (page, ", disconnected\n");
+
+               return strlen (page);
+       }
+
+       return 0;
+}
+
+static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
+{
+       struct udsl_instance_data *instance = vcc->dev->dev_data;
+       struct udsl_vcc_data *new;
+
+       dbg ("udsl_atm_open: vpi %hd, vci %d", vpi, vci);
+
+       if (!instance || !instance->usb_dev) {
+               dbg ("udsl_atm_open: NULL data!");
+               return -ENODEV;
+       }
+
+       if ((vpi == ATM_VPI_ANY) || (vci == ATM_VCI_ANY))
+               return -EINVAL;
+
+       /* only support AAL5 */
+       if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) || 
(vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU))
+               return -EINVAL;
+
+       if (!instance->firmware_loaded) {
+               dbg ("udsl_atm_open: firmware not loaded!");
+               return -EAGAIN;
+       }
+
+       down (&instance->serialize); /* vs self, udsl_atm_close */
+
+       if (udsl_find_vcc (instance, vpi, vci)) {
+               up (&instance->serialize);
+               return -EADDRINUSE;
+       }
+
+       if (!(new = kmalloc (sizeof (struct udsl_vcc_data), GFP_KERNEL))) {
+               up (&instance->serialize);
+               return -ENOMEM;
+       }
+
+       memset (new, 0, sizeof (struct udsl_vcc_data));
+       new->vcc = vcc;
+       new->vpi = vpi;
+       new->vci = vci;
+       new->max_pdu = max (1, UDSL_NUM_CELLS (vcc->qos.rxtp.max_sdu)) * 
ATM_CELL_PAYLOAD;
+
+       vcc->dev_data = new;
+       vcc->vpi = vpi;
+       vcc->vci = vci;
+
+       tasklet_disable (&instance->receive_tasklet);
+       list_add (&new->list, &instance->vcc_list);
+       tasklet_enable (&instance->receive_tasklet);
+
+       set_bit (ATM_VF_ADDR, &vcc->flags);
+       set_bit (ATM_VF_PARTIAL, &vcc->flags);
+       set_bit (ATM_VF_READY, &vcc->flags);
+
+       up (&instance->serialize);
+
+       tasklet_schedule (&instance->receive_tasklet);
+
+       dbg ("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, 
new->max_pdu);
+
+       return 0;
+}
+
+static void udsl_atm_close (struct atm_vcc *vcc)
+{
+       struct udsl_instance_data *instance = vcc->dev->dev_data;
+       struct udsl_vcc_data *vcc_data = vcc->dev_data;
+
+       dbg ("udsl_atm_close called");
+
+       if (!instance || !vcc_data) {
+               dbg ("udsl_atm_close: NULL data!");
+               return;
+       }
+
+       dbg ("udsl_atm_close: deallocating vcc 0x%p with vpi %d vci %d", vcc_data, 
vcc_data->vpi, vcc_data->vci);
+
+       udsl_cancel_send (instance, vcc);
+
+       down (&instance->serialize); /* vs self, udsl_atm_open */
+
+       tasklet_disable (&instance->receive_tasklet);
+       list_del (&vcc_data->list);
+       tasklet_enable (&instance->receive_tasklet);
+
+       if (vcc_data->skb)
+               dev_kfree_skb (vcc_data->skb);
+       vcc_data->skb = NULL;
+
+       kfree (vcc_data);
+       vcc->dev_data = NULL;
+
+       vcc->vpi = ATM_VPI_UNSPEC;
+       vcc->vci = ATM_VCI_UNSPEC;
+       clear_bit (ATM_VF_READY, &vcc->flags);
+       clear_bit (ATM_VF_PARTIAL, &vcc->flags);
+       clear_bit (ATM_VF_ADDR, &vcc->flags);
+
+       up (&instance->serialize);
+
+       dbg ("udsl_atm_close successful");
+}
+
+static int udsl_atm_ioctl (struct atm_dev *dev, unsigned int cmd, void *arg)
+{
+       switch (cmd) {
+       case ATM_QUERYLOOP:
+               return put_user (ATM_LM_NONE, (int *) arg) ? -EFAULT : 0;
+       default:
+               return -ENOIOCTLCMD;
+       }
+}
+
+
+/**********
+**  USB  **
+**********/
+
+static int udsl_set_alternate (struct udsl_instance_data *instance)
+{
+       down (&instance->serialize); /* vs self */
+       if (!instance->firmware_loaded) {
+               int ret;
+
+               if ((ret = usb_set_interface (instance->usb_dev, 1, 1)) < 0) {
+                       dbg ("udsl_set_alternate: usb_set_interface returned %d!", 
ret);
+                       up (&instance->serialize);
+                       return ret;
+               }
+               instance->firmware_loaded = 1;
+       }
+       up (&instance->serialize);
+
+       tasklet_schedule (&instance->receive_tasklet);
+
+       return 0;
+}
+
+static int udsl_usb_ioctl (struct usb_device *dev, unsigned int code, void *user_data)
+{
+       struct usb_interface *intf = usb_ifnum_to_if (dev, 1);
+       struct udsl_instance_data *instance = intf->private_data;
+
+       dbg ("udsl_usb_ioctl entered");
+
+       if (!instance) {
+               dbg ("udsl_usb_ioctl: NULL instance!");
+               return -ENODEV;
+       }
+
+       switch (code) {
+       case UDSL_IOCTL_LINE_UP:
+               instance->atm_dev->signal = ATM_PHY_SIG_FOUND;
+               return udsl_set_alternate (instance);
+       case UDSL_IOCTL_LINE_DOWN:
+               instance->atm_dev->signal = ATM_PHY_SIG_LOST;
+               return 0;
+       default:
+               return -ENOTTY;
+       }
+}
+
+static void *udsl_usb_probe (struct usb_device *dev, unsigned int ifnum, const struct 
usb_device_id *id)
+{
+       struct udsl_instance_data *instance;
+       unsigned char mac_str [13];
+       int i, length;
+       char *buf;
+
+       dbg ("udsl_usb_probe: trying device with vendor=0x%x, product=0x%x, ifnum %d",
+            dev->descriptor.idVendor, dev->descriptor.idProduct, ifnum);
+
+       if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) ||
+           (dev->descriptor.idVendor != SPEEDTOUCH_VENDORID) ||
+           (dev->descriptor.idProduct != SPEEDTOUCH_PRODUCTID) || (ifnum != 1))
+               return NULL;
+
+       dbg ("udsl_usb_probe: device accepted");
+
+       /* instance init */
+       if (!(instance = kmalloc (sizeof (struct udsl_instance_data), GFP_KERNEL))) {
+               dbg ("udsl_usb_probe: no memory for instance data!");
+               return NULL;
+       }
+
+       memset (instance, 0, sizeof (struct udsl_instance_data));
+
+       init_MUTEX (&instance->serialize);
+
+       instance->usb_dev = dev;
+
+       INIT_LIST_HEAD (&instance->vcc_list);
+
+       spin_lock_init (&instance->receive_lock);
+       INIT_LIST_HEAD (&instance->spare_receivers);
+       INIT_LIST_HEAD (&instance->filled_receive_buffers);
+
+       tasklet_init (&instance->receive_tasklet, udsl_process_receive, (unsigned 
long) instance);
+       INIT_LIST_HEAD (&instance->spare_receive_buffers);
+
+       skb_queue_head_init (&instance->sndqueue);
+
+       spin_lock_init (&instance->send_lock);
+       INIT_LIST_HEAD (&instance->spare_senders);
+       INIT_LIST_HEAD (&instance->spare_send_buffers);
+
+       tasklet_init (&instance->send_tasklet, udsl_process_send, (unsigned long) 
instance);
+       INIT_LIST_HEAD (&instance->filled_send_buffers);
+
+       /* receive init */
+       for (i = 0; i < num_rcv_urbs; i++) {
+               struct udsl_receiver *rcv = &(instance->receivers [i]);
+
+               if (!(rcv->urb = usb_alloc_urb (0))) {
+                       dbg ("udsl_usb_probe: no memory for receive urb %d!", i);
+                       goto fail;
+               }
+
+               rcv->instance = instance;
+
+               list_add (&rcv->list, &instance->spare_receivers);
+       }
+
+       for (i = 0; i < num_rcv_bufs; i++) {
+               struct udsl_receive_buffer *buf = &(instance->receive_buffers [i]);
+
+               if (!(buf->base = kmalloc (rcv_buf_size * ATM_CELL_SIZE, GFP_KERNEL))) 
{
+                       dbg ("udsl_usb_probe: no memory for receive buffer %d!", i);
+                       goto fail;
+               }
+
+               list_add (&buf->list, &instance->spare_receive_buffers);
+       }
+
+       /* send init */
+       for (i = 0; i < num_snd_urbs; i++) {
+               struct udsl_sender *snd = &(instance->senders [i]);
+
+               if (!(snd->urb = usb_alloc_urb (0))) {
+                       dbg ("udsl_usb_probe: no memory for send urb %d!", i);
+                       goto fail;
+               }
+
+               snd->instance = instance;
+
+               list_add (&snd->list, &instance->spare_senders);
+       }
+
+       for (i = 0; i < num_snd_bufs; i++) {
+               struct udsl_send_buffer *buf = &(instance->send_buffers [i]);
+
+               if (!(buf->base = kmalloc (snd_buf_size * ATM_CELL_SIZE, GFP_KERNEL))) 
{
+                       dbg ("udsl_usb_probe: no memory for send buffer %d!", i);
+                       goto fail;
+               }
+
+               list_add (&buf->list, &instance->spare_send_buffers);
+       }
+
+       /* ATM init */
+       if (!(instance->atm_dev = atm_dev_register (udsl_driver_name, 
&udsl_atm_devops, -1, 0))) {
+               dbg ("udsl_usb_probe: failed to register ATM device!");
+               goto fail;
+       }
+
+       instance->atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
+       instance->atm_dev->ci_range.vci_bits = ATM_CI_MAX;
+       instance->atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
+
+       /* temp init ATM device, set to 128kbit */
+       instance->atm_dev->link_rate = 128 * 1000 / 424;
+
+       /* set MAC address, it is stored in the serial number */
+       memset (instance->atm_dev->esi, 0, sizeof (instance->atm_dev->esi));
+       if (usb_string (dev, dev->descriptor.iSerialNumber, mac_str, sizeof (mac_str)) 
== 12)
+               for (i = 0; i < 6; i++)
+                       instance->atm_dev->esi [i] = (hex2int (mac_str [i * 2]) * 16) 
+ (hex2int (mac_str [i * 2 + 1]));
+
+       /* device description */
+       buf = instance->description;
+       length = sizeof (instance->description);
+
+       if ((i = usb_string (dev, dev->descriptor.iProduct, buf, length)) < 0)
+               goto finish;
+
+       buf += i;
+       length -= i;
+
+       i = snprintf (buf, length, " (");
+       buf += i;
+       length -= i;
+
+       if (length <= 0 || (i = usb_make_path (dev, buf, length)) < 0)
+               goto finish;
+
+       buf += i;
+       length -= i;
+
+       snprintf (buf, length, ")");
+
+finish:
+       /* ready for ATM callbacks */
+       wmb ();
+       instance->atm_dev->dev_data = instance;
+
+       return instance;
+
+fail:
+       for (i = 0; i < num_snd_bufs; i++)
+               kfree (instance->send_buffers [i].base);
+
+       for (i = 0; i < num_snd_urbs; i++)
+               usb_free_urb (instance->senders [i].urb);
+
+       for (i = 0; i < num_rcv_bufs; i++)
+               kfree (instance->receive_buffers [i].base);
+
+       for (i = 0; i < num_rcv_urbs; i++)
+               usb_free_urb (instance->receivers [i].urb);
+
+       kfree (instance);
+
+       return NULL;
+}
+
+static void udsl_usb_disconnect (struct usb_device *dev, void *ptr)
+{
+       struct udsl_instance_data *instance = ptr;
+       struct list_head *pos;
+       unsigned int count;
+       int result, i;
+
+       dbg ("udsl_usb_disconnect entered");
+
+       if (!instance) {
+               dbg ("udsl_usb_disconnect: NULL instance!");
+               return;
+       }
+
+       /* receive finalize */
+       tasklet_disable (&instance->receive_tasklet);
+
+       for (i = 0; i < num_rcv_urbs; i++)
+               if ((result = usb_unlink_urb (instance->receivers [i].urb)) < 0)
+                       dbg ("udsl_usb_disconnect: usb_unlink_urb on receive urb %d 
returned %d", i, result);
+
+       /* wait for completion handlers to finish */
+       do {
+               count = 0;
+               spin_lock_irq (&instance->receive_lock);
+               list_for_each (pos, &instance->spare_receivers)
+                       if (++count > num_rcv_urbs)
+                               panic (__FILE__ ": memory corruption detected at line 
%d!\n", __LINE__);
+               spin_unlock_irq (&instance->receive_lock);
+
+               dbg ("udsl_usb_disconnect: found %u spare receivers", count);
+
+               if (count == num_rcv_urbs)
+                       break;
+
+               set_current_state (TASK_RUNNING);
+               schedule ();
+       } while (1);
+
+       /* no need to take the spinlock */
+       INIT_LIST_HEAD (&instance->filled_receive_buffers);
+       INIT_LIST_HEAD (&instance->spare_receive_buffers);
+
+       tasklet_enable (&instance->receive_tasklet);
+
+       for (i = 0; i < num_rcv_urbs; i++)
+               usb_free_urb (instance->receivers [i].urb);
+
+       for (i = 0; i < num_rcv_bufs; i++)
+               kfree (instance->receive_buffers [i].base);
+
+       /* send finalize */
+       tasklet_disable (&instance->send_tasklet);
+
+       for (i = 0; i < num_snd_urbs; i++)
+               if ((result = usb_unlink_urb (instance->senders [i].urb)) < 0)
+                       dbg ("udsl_usb_disconnect: usb_unlink_urb on send urb %d 
returned %d", i, result);
+
+       /* wait for completion handlers to finish */
+       do {
+               count = 0;
+               spin_lock_irq (&instance->send_lock);
+               list_for_each (pos, &instance->spare_senders)
+                       if (++count > num_snd_urbs)
+                               panic (__FILE__ ": memory corruption detected at line 
%d!\n", __LINE__);
+               spin_unlock_irq (&instance->send_lock);
+
+               dbg ("udsl_usb_disconnect: found %u spare senders", count);
+
+               if (count == num_snd_urbs)
+                       break;
+
+               set_current_state (TASK_RUNNING);
+               schedule ();
+       } while (1);
+
+       /* no need to take the spinlock */
+       INIT_LIST_HEAD (&instance->spare_senders);
+       INIT_LIST_HEAD (&instance->spare_send_buffers);
+       instance->current_buffer = NULL;
+
+       tasklet_enable (&instance->send_tasklet);
+
+       for (i = 0; i < num_snd_urbs; i++)
+               usb_free_urb (instance->senders [i].urb);
+
+       for (i = 0; i < num_snd_bufs; i++)
+               kfree (instance->send_buffers [i].base);
+
+       wmb ();
+       instance->usb_dev = NULL;
+
+       /* ATM finalize */
+       shutdown_atm_dev (instance->atm_dev); /* frees instance, kills tasklets */
+}
+
+
+/***********
+**  init  **
+***********/
+
+static int __init udsl_usb_init (void)
+{
+       struct sk_buff *skb; /* dummy for sizeof */
+
+       dbg ("udsl_usb_init: driver version " DRIVER_VERSION);
+
+       if (sizeof (struct udsl_control) > sizeof (skb->cb)) {
+               printk (KERN_ERR __FILE__ ": unusable with this kernel!\n");
+               return -EIO;
+       }
+
+       if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) || (num_snd_urbs > UDSL_MAX_SND_URBS) ||
+           (num_rcv_bufs > UDSL_MAX_RCV_BUFS) || (num_snd_bufs > UDSL_MAX_SND_BUFS) ||
+           (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE) || (snd_buf_size > 
UDSL_MAX_SND_BUF_SIZE))
+               return -EINVAL;
+
+       return usb_register (&udsl_usb_driver);
+}
+
+static void __exit udsl_usb_cleanup (void)
+{
+       dbg ("udsl_usb_cleanup entered");
+
+       usb_deregister (&udsl_usb_driver);
+}
+
+module_init (udsl_usb_init);
+module_exit (udsl_usb_cleanup);
+
+MODULE_AUTHOR (DRIVER_AUTHOR);
+MODULE_DESCRIPTION (DRIVER_DESC);
+MODULE_LICENSE ("GPL");
+
+
+/************
+**  debug  **
+************/
+
+#ifdef VERBOSE_DEBUG
+static int udsl_print_packet (const unsigned char *data, int len)
+{
+       unsigned char buffer [256];
+       int i = 0, j = 0;
+
+       for (i = 0; i < len;) {
+               buffer [0] = '\0';
+               sprintf (buffer, "%.3d :", i);
+               for (j = 0; (j < 16) && (i < len); j++, i++) {
+                       sprintf (buffer, "%s %2.2x", buffer, data [i]);
+               }
+               dbg ("%s", buffer);
+       }
+       return i;
+}
+#endif
diff -Nru a/drivers/usb/speedtouch.c b/drivers/usb/speedtouch.c
--- a/drivers/usb/speedtouch.c  Fri Jun 27 10:15:20 2003
+++ /dev/null   Wed Dec 31 16:00:00 1969
@@ -1,1344 +0,0 @@
-/******************************************************************************
- *  speedtouch.c  -  Alcatel SpeedTouch USB xDSL modem driver
- *
- *  Copyright (C) 2001, Alcatel
- *  Copyright (C) 2003, Duncan Sands
- *
- *  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 the Free
- *  Software Foundation; either version 2 of the License, or (at your option)
- *  any later version.
- *
- *  This program is distributed in the hope that it will be useful, but WITHOUT
- *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- *  more details.
- *
- *  You should have received a copy of the GNU General Public License along with
- *  this program; if not, write to the Free Software Foundation, Inc., 59
- *  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- ******************************************************************************/
-
-/*
- *  Written by Johan Verrept, maintained by Duncan Sands ([EMAIL PROTECTED])
- *
- *  1.6:       - No longer opens a connection if the firmware is not loaded
- *             - Added support for the speedtouch 330
- *             - Removed the limit on the number of devices
- *             - Module now autoloads on device plugin
- *             - Merged relevant parts of sarlib
- *             - Replaced the kernel thread with a tasklet
- *             - New packet transmission code
- *             - Changed proc file contents
- *             - Fixed all known SMP races
- *             - Many fixes and cleanups
- *             - Various fixes by Oliver Neukum ([EMAIL PROTECTED])
- *
- *  1.5A:      - Backport of version for inclusion in 2.5 series kernel
- *             - Modifications by Richard Purdie ([EMAIL PROTECTED])
- *             - made compatible with kernel 2.5.6 onwards by changing
- *             udsl_usb_send_data_context->urb to a pointer and adding code
- *             to alloc and free it
- *             - remove_wait_queue() added to udsl_atm_processqueue_thread()
- *
- *  1.5:       - fixed memory leak when atmsar_decode_aal5 returned NULL.
- *             (reported by [EMAIL PROTECTED])
- *
- *  1.4:       - changed the spin_lock() under interrupt to spin_lock_irqsave()
- *             - unlink all active send urbs of a vcc that is being closed.
- *
- *  1.3.1:     - added the version number
- *
- *  1.3:       - Added multiple send urb support
- *             - fixed memory leak and vcc->tx_inuse starvation bug
- *               when not enough memory left in vcc.
- *
- *  1.2:       - Fixed race condition in udsl_usb_send_data()
- *  1.1:       - Turned off packet debugging
- *
- */
-
-#include <asm/semaphore.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/timer.h>
-#include <linux/errno.h>
-#include <linux/proc_fs.h>
-#include <linux/slab.h>
-#include <linux/list.h>
-#include <asm/uaccess.h>
-#include <linux/smp_lock.h>
-#include <linux/interrupt.h>
-#include <linux/atm.h>
-#include <linux/atmdev.h>
-#include <linux/init.h>
-#include "speedcrc.h"
-
-/*
-#define DEBUG
-#define VERBOSE_DEBUG
-*/
-
-#include <linux/usb.h>
-
-
-#ifdef VERBOSE_DEBUG
-static int udsl_print_packet (const unsigned char *data, int len);
-#define PACKETDEBUG(arg...)    udsl_print_packet (arg)
-#define vdbg(arg...)           dbg (arg)
-#else
-#define PACKETDEBUG(arg...)
-#define vdbg(arg...)
-#endif
-
-#define DRIVER_AUTHOR  "Johan Verrept, Duncan Sands <[EMAIL PROTECTED]>"
-#define DRIVER_DESC    "Alcatel SpeedTouch USB driver"
-#define DRIVER_VERSION "1.6"
-
-static const char udsl_driver_name [] = "speedtch";
-
-#define SPEEDTOUCH_VENDORID            0x06b9
-#define SPEEDTOUCH_PRODUCTID           0x4061
-
-#define UDSL_MAX_RCV_URBS              4
-#define UDSL_MAX_SND_URBS              4
-#define UDSL_MAX_RCV_BUFS              8
-#define UDSL_MAX_SND_BUFS              8
-#define UDSL_MAX_RCV_BUF_SIZE          1024 /* ATM cells */
-#define UDSL_MAX_SND_BUF_SIZE          1024 /* ATM cells */
-#define UDSL_DEFAULT_RCV_URBS          1
-#define UDSL_DEFAULT_SND_URBS          1
-#define UDSL_DEFAULT_RCV_BUFS          2
-#define UDSL_DEFAULT_SND_BUFS          2
-#define UDSL_DEFAULT_RCV_BUF_SIZE      64 /* ATM cells */
-#define UDSL_DEFAULT_SND_BUF_SIZE      64 /* ATM cells */
-
-static unsigned int num_rcv_urbs = UDSL_DEFAULT_RCV_URBS;
-static unsigned int num_snd_urbs = UDSL_DEFAULT_SND_URBS;
-static unsigned int num_rcv_bufs = UDSL_DEFAULT_RCV_BUFS;
-static unsigned int num_snd_bufs = UDSL_DEFAULT_SND_BUFS;
-static unsigned int rcv_buf_size = UDSL_DEFAULT_RCV_BUF_SIZE;
-static unsigned int snd_buf_size = UDSL_DEFAULT_SND_BUF_SIZE;
-
-MODULE_PARM (num_rcv_urbs, "i");
-MODULE_PARM_DESC (num_rcv_urbs, "Number of urbs used for reception (range: 0-" 
__MODULE_STRING (UDSL_MAX_RCV_URBS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_RCV_URBS) ")");
-
-MODULE_PARM (num_snd_urbs, "i");
-MODULE_PARM_DESC (num_snd_urbs, "Number of urbs used for transmission (range: 0-" 
__MODULE_STRING (UDSL_MAX_SND_URBS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_SND_URBS) ")");
-
-MODULE_PARM (num_rcv_bufs, "i");
-MODULE_PARM_DESC (num_rcv_bufs, "Number of buffers used for reception (range: 0-" 
__MODULE_STRING (UDSL_MAX_RCV_BUFS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_RCV_BUFS) ")");
-
-MODULE_PARM (num_snd_bufs, "i");
-MODULE_PARM_DESC (num_snd_bufs, "Number of buffers used for transmission (range: 0-" 
__MODULE_STRING (UDSL_MAX_SND_BUFS) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_SND_BUFS) ")");
-
-MODULE_PARM (rcv_buf_size, "i");
-MODULE_PARM_DESC (rcv_buf_size, "Size of the buffers used for reception (range: 0-" 
__MODULE_STRING (UDSL_MAX_RCV_BUF_SIZE) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_RCV_BUF_SIZE) ")");
-
-MODULE_PARM (snd_buf_size, "i");
-MODULE_PARM_DESC (snd_buf_size, "Size of the buffers used for transmission (range: 
0-" __MODULE_STRING (UDSL_MAX_SND_BUF_SIZE) ", default: " __MODULE_STRING 
(UDSL_DEFAULT_SND_BUF_SIZE) ")");
-
-#define UDSL_IOCTL_LINE_UP             1
-#define UDSL_IOCTL_LINE_DOWN           2
-
-#define UDSL_ENDPOINT_DATA_OUT         0x07
-#define UDSL_ENDPOINT_DATA_IN          0x87
-
-#define ATM_CELL_HEADER                        (ATM_CELL_SIZE - ATM_CELL_PAYLOAD)
-#define UDSL_NUM_CELLS(x)              (((x) + ATM_AAL5_TRAILER + ATM_CELL_PAYLOAD - 
1) / ATM_CELL_PAYLOAD)
-
-#define hex2int(c) ( (c >= '0') && (c <= '9') ? (c - '0') : ((c & 0xf) + 9) )
-
-static struct usb_device_id udsl_usb_ids [] = {
-       { USB_DEVICE (SPEEDTOUCH_VENDORID, SPEEDTOUCH_PRODUCTID) },
-       { }
-};
-
-MODULE_DEVICE_TABLE (usb, udsl_usb_ids);
-
-/* receive */
-
-struct udsl_receive_buffer {
-       struct list_head list;
-       unsigned char *base;
-       unsigned int filled_cells;
-};
-
-struct udsl_receiver {
-       struct list_head list;
-       struct udsl_receive_buffer *buffer;
-       struct urb *urb;
-       struct udsl_instance_data *instance;
-};
-
-struct udsl_vcc_data {
-       /* vpi/vci lookup */
-       struct list_head list;
-       short vpi;
-       int vci;
-       struct atm_vcc *vcc;
-
-       /* raw cell reassembly */
-       struct sk_buff *skb;
-       unsigned int max_pdu;
-};
-
-/* send */
-
-struct udsl_send_buffer {
-       struct list_head list;
-       unsigned char *base;
-       unsigned char *free_start;
-       unsigned int free_cells;
-};
-
-struct udsl_sender {
-       struct list_head list;
-       struct udsl_send_buffer *buffer;
-       struct urb *urb;
-       struct udsl_instance_data *instance;
-};
-
-struct udsl_control {
-       struct atm_skb_data atm_data;
-       unsigned int num_cells;
-       unsigned int num_entire;
-       unsigned int pdu_padding;
-       unsigned char cell_header [ATM_CELL_HEADER];
-       unsigned char aal5_trailer [ATM_AAL5_TRAILER];
-};
-
-#define UDSL_SKB(x)            ((struct udsl_control *)(x)->cb)
-
-/* main driver data */
-
-struct udsl_instance_data {
-       struct semaphore serialize;
-
-       /* USB device part */
-       struct usb_device *usb_dev;
-       char description [64];
-       int firmware_loaded;
-
-       /* ATM device part */
-       struct atm_dev *atm_dev;
-       struct list_head vcc_list;
-
-       /* receive */
-       struct udsl_receiver receivers [UDSL_MAX_RCV_URBS];
-       struct udsl_receive_buffer receive_buffers [UDSL_MAX_RCV_BUFS];
-
-       spinlock_t receive_lock;
-       struct list_head spare_receivers;
-       struct list_head filled_receive_buffers;
-
-       struct tasklet_struct receive_tasklet;
-       struct list_head spare_receive_buffers;
-
-       /* send */
-       struct udsl_sender senders [UDSL_MAX_SND_URBS];
-       struct udsl_send_buffer send_buffers [UDSL_MAX_SND_BUFS];
-
-       struct sk_buff_head sndqueue;
-
-       spinlock_t send_lock;
-       struct list_head spare_senders;
-       struct list_head spare_send_buffers;
-
-       struct tasklet_struct send_tasklet;
-       struct sk_buff *current_skb;                    /* being emptied */
-       struct udsl_send_buffer *current_buffer;        /* being filled */
-       struct list_head filled_send_buffers;
-};
-
-/* ATM */
-
-static void udsl_atm_dev_close (struct atm_dev *dev);
-static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci);
-static void udsl_atm_close (struct atm_vcc *vcc);
-static int udsl_atm_ioctl (struct atm_dev *dev, unsigned int cmd, void *arg);
-static int udsl_atm_send (struct atm_vcc *vcc, struct sk_buff *skb);
-static int udsl_atm_proc_read (struct atm_dev *atm_dev, loff_t *pos, char *page);
-
-static struct atmdev_ops udsl_atm_devops = {
-       dev_close:      udsl_atm_dev_close,
-       open:           udsl_atm_open,
-       close:          udsl_atm_close,
-       ioctl:          udsl_atm_ioctl,
-       send:           udsl_atm_send,
-       proc_read:      udsl_atm_proc_read,
-       owner:          THIS_MODULE,
-};
-
-/* USB */
-
-static void *udsl_usb_probe (struct usb_device *dev, unsigned int ifnum, const struct 
usb_device_id *id);
-static void udsl_usb_disconnect (struct usb_device *dev, void *ptr);
-static int udsl_usb_ioctl (struct usb_device *hub, unsigned int code, void 
*user_data);
-
-static struct usb_driver udsl_usb_driver = {
-       owner:          THIS_MODULE,
-       name:           udsl_driver_name,
-       probe:          udsl_usb_probe,
-       disconnect:     udsl_usb_disconnect,
-       ioctl:          udsl_usb_ioctl,
-       id_table:       udsl_usb_ids,
-};
-
-
-/*************
-**  decode  **
-*************/
-
-static inline struct udsl_vcc_data *udsl_find_vcc (struct udsl_instance_data 
*instance, short vpi, int vci)
-{
-       struct udsl_vcc_data *vcc;
-
-       list_for_each_entry (vcc, &instance->vcc_list, list)
-               if ((vcc->vci == vci) && (vcc->vpi == vpi))
-                       return vcc;
-       return NULL;
-}
-
-static void udsl_extract_cells (struct udsl_instance_data *instance, unsigned char 
*source, unsigned int howmany)
-{
-       struct udsl_vcc_data *cached_vcc = NULL;
-       struct atm_vcc *vcc;
-       struct sk_buff *skb;
-       struct udsl_vcc_data *vcc_data;
-       int cached_vci = 0;
-       unsigned int i;
-       unsigned int length;
-       unsigned int pdu_length;
-       int pti;
-       int vci;
-       short cached_vpi = 0;
-       short vpi;
-
-       for (i = 0; i < howmany; i++, source += ATM_CELL_SIZE) {
-               vpi = ((source [0] & 0x0f) << 4) | (source [1] >> 4);
-               vci = ((source [1] & 0x0f) << 12) | (source [2] << 4) | (source [3] >> 
4);
-               pti = (source [3] & 0x2) != 0;
-
-               vdbg ("udsl_extract_cells: vpi %hd, vci %d, pti %d", vpi, vci, pti);
-
-               if (cached_vcc && (vci == cached_vci) && (vpi == cached_vpi))
-                       vcc_data = cached_vcc;
-               else if ((vcc_data = udsl_find_vcc (instance, vpi, vci))) {
-                       cached_vcc = vcc_data;
-                       cached_vpi = vpi;
-                       cached_vci = vci;
-               } else {
-                       dbg ("udsl_extract_cells: unknown vpi/vci (%hd/%d)!", vpi, 
vci);
-                       continue;
-               }
-
-               vcc = vcc_data->vcc;
-
-               if (!vcc_data->skb && !(vcc_data->skb = dev_alloc_skb 
(vcc_data->max_pdu))) {
-                       dbg ("udsl_extract_cells: no memory for skb (vcc: 0x%p)!", 
vcc);
-                       if (pti)
-                               atomic_inc (&vcc->stats->rx_err);
-                       continue;
-               }
-
-               skb = vcc_data->skb;
-
-               if (skb->len + ATM_CELL_PAYLOAD > vcc_data->max_pdu) {
-                       dbg ("udsl_extract_cells: buffer overrun (max_pdu: %u, 
skb->len %u, vcc: 0x%p)", vcc_data->max_pdu, skb->len, vcc);
-                       /* discard cells already received */
-                       skb_trim (skb, 0);
-                       BUG_ON (vcc_data->max_pdu < ATM_CELL_PAYLOAD);
-               }
-
-               memcpy (skb->tail, source + ATM_CELL_HEADER, ATM_CELL_PAYLOAD);
-               __skb_put (skb, ATM_CELL_PAYLOAD);
-
-               if (pti) {
-                       length = (source [ATM_CELL_SIZE - 6] << 8) + source 
[ATM_CELL_SIZE - 5];
-
-                       /* guard against overflow */
-                       if (length > ATM_MAX_AAL5_PDU) {
-                               dbg ("udsl_extract_cells: bogus length %u (vcc: 
0x%p)", length, vcc);
-                               goto drop;
-                       }
-
-                       pdu_length = UDSL_NUM_CELLS (length) * ATM_CELL_PAYLOAD;
-
-                       if (skb->len < pdu_length) {
-                               dbg ("udsl_extract_cells: bogus pdu_length %u 
(skb->len: %u, vcc: 0x%p)", pdu_length, skb->len, vcc);
-                               goto drop;
-                       }
-
-                       if (crc32_be (~0, skb->tail - pdu_length, pdu_length) != 
0xc704dd7b) {
-                               dbg ("udsl_extract_cells: packet failed crc check 
(vcc: 0x%p)", vcc);
-                               goto drop;
-                       }
-
-                       if (!atm_charge (vcc, skb->truesize)) {
-                               dbg ("udsl_extract_cells: failed atm_charge 
(skb->truesize: %u)", skb->truesize);
-                               goto drop_no_stats; /* atm_charge increments rx_drop */
-                       }
-
-                       /* now that we are sure to send the skb, it is ok to change 
skb->data */
-                       if (skb->len > pdu_length)
-                               skb_pull (skb, skb->len - pdu_length); /* discard 
initial junk */
-
-                       skb_trim (skb, length); /* drop zero padding and trailer */
-
-                       atomic_inc (&vcc->stats->rx);
-
-                       PACKETDEBUG (skb->data, skb->len);
-
-                       vdbg ("udsl_extract_cells: sending skb 0x%p, skb->len %u, 
skb->truesize %u", skb, skb->len, skb->truesize);
-
-                       vcc->push (vcc, skb);
-
-                       vcc_data->skb = NULL;
-
-                       continue;
-
-drop:
-                       atomic_inc (&vcc->stats->rx_err);
-drop_no_stats:
-                       skb_trim (skb, 0);
-               }
-       }
-}
-
-
-/*************
-**  encode  **
-*************/
-
-static const unsigned char zeros [ATM_CELL_PAYLOAD];
-
-static void udsl_groom_skb (struct atm_vcc *vcc, struct sk_buff *skb)
-{
-       struct udsl_control *ctrl = UDSL_SKB (skb);
-       unsigned int zero_padding;
-       u32 crc;
-
-       ctrl->atm_data.vcc = vcc;
-       ctrl->cell_header [0] = vcc->vpi >> 4;
-       ctrl->cell_header [1] = (vcc->vpi << 4) | (vcc->vci >> 12);
-       ctrl->cell_header [2] = vcc->vci >> 4;
-       ctrl->cell_header [3] = vcc->vci << 4;
-       ctrl->cell_header [4] = 0xec;
-
-       ctrl->num_cells = UDSL_NUM_CELLS (skb->len);
-       ctrl->num_entire = skb->len / ATM_CELL_PAYLOAD;
-
-       zero_padding = ctrl->num_cells * ATM_CELL_PAYLOAD - skb->len - 
ATM_AAL5_TRAILER;
-
-       if (ctrl->num_entire + 1 < ctrl->num_cells)
-               ctrl->pdu_padding = zero_padding - (ATM_CELL_PAYLOAD - 
ATM_AAL5_TRAILER);
-       else
-               ctrl->pdu_padding = zero_padding;
-
-       ctrl->aal5_trailer [0] = 0; /* UU = 0 */
-       ctrl->aal5_trailer [1] = 0; /* CPI = 0 */
-       ctrl->aal5_trailer [2] = skb->len >> 8;
-       ctrl->aal5_trailer [3] = skb->len;
-
-       crc = crc32_be (~0, skb->data, skb->len);
-       crc = crc32_be (crc, zeros, zero_padding);
-       crc = crc32_be (crc, ctrl->aal5_trailer, 4);
-       crc = ~crc;
-
-       ctrl->aal5_trailer [4] = crc >> 24;
-       ctrl->aal5_trailer [5] = crc >> 16;
-       ctrl->aal5_trailer [6] = crc >> 8;
-       ctrl->aal5_trailer [7] = crc;
-}
-
-static unsigned int udsl_write_cells (unsigned int howmany, struct sk_buff *skb, 
unsigned char **target_p)
-{
-       struct udsl_control *ctrl = UDSL_SKB (skb);
-       unsigned char *target = *target_p;
-       unsigned int nc, ne, i;
-
-       vdbg ("udsl_write_cells: howmany=%u, skb->len=%d, num_cells=%u, num_entire=%u, 
pdu_padding=%u", howmany, skb->len, ctrl->num_cells, ctrl->num_entire, 
ctrl->pdu_padding);
-
-       nc = ctrl->num_cells;
-       ne = min (howmany, ctrl->num_entire);
-
-       for (i = 0; i < ne; i++) {
-               memcpy (target, ctrl->cell_header, ATM_CELL_HEADER);
-               target += ATM_CELL_HEADER;
-               memcpy (target, skb->data, ATM_CELL_PAYLOAD);
-               target += ATM_CELL_PAYLOAD;
-               __skb_pull (skb, ATM_CELL_PAYLOAD);
-       }
-
-       ctrl->num_entire -= ne;
-
-       if (!(ctrl->num_cells -= ne) || !(howmany -= ne))
-               goto out;
-
-       memcpy (target, ctrl->cell_header, ATM_CELL_HEADER);
-       target += ATM_CELL_HEADER;
-       memcpy (target, skb->data, skb->len);
-       target += skb->len;
-       __skb_pull (skb, skb->len);
-       memset (target, 0, ctrl->pdu_padding);
-       target += ctrl->pdu_padding;
-
-       if (--ctrl->num_cells) {
-               if (!--howmany) {
-                       ctrl->pdu_padding = ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
-                       goto out;
-               }
-
-               memcpy (target, ctrl->cell_header, ATM_CELL_HEADER);
-               target += ATM_CELL_HEADER;
-               memset (target, 0, ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER);
-               target += ATM_CELL_PAYLOAD - ATM_AAL5_TRAILER;
-
-               BUG_ON (--ctrl->num_cells);
-       }
-
-       memcpy (target, ctrl->aal5_trailer, ATM_AAL5_TRAILER);
-       target += ATM_AAL5_TRAILER;
-       /* set pti bit in last cell */
-       *(target + 3 - ATM_CELL_SIZE) |= 0x2;
-
-out:
-       *target_p = target;
-       return nc - ctrl->num_cells;
-}
-
-
-/**************
-**  receive  **
-**************/
-
-static void udsl_complete_receive (struct urb *urb)
-{
-       struct udsl_receive_buffer *buf;
-       struct udsl_instance_data *instance;
-       struct udsl_receiver *rcv;
-       unsigned long flags;
-
-       if (!urb || !(rcv = urb->context)) {
-               dbg ("udsl_complete_receive: bad urb!");
-               return;
-       }
-
-       instance = rcv->instance;
-       buf = rcv->buffer;
-
-       buf->filled_cells = urb->actual_length / ATM_CELL_SIZE;
-
-       vdbg ("udsl_complete_receive: urb 0x%p, status %d, actual_length %d, 
filled_cells %u, rcv 0x%p, buf 0x%p", urb, urb->status, urb->actual_length, 
buf->filled_cells, rcv, buf);
-
-       BUG_ON (buf->filled_cells > rcv_buf_size);
-
-       /* may not be in_interrupt() */
-       spin_lock_irqsave (&instance->receive_lock, flags);
-       list_add (&rcv->list, &instance->spare_receivers);
-       list_add_tail (&buf->list, &instance->filled_receive_buffers);
-       if (likely (!urb->status))
-               tasklet_schedule (&instance->receive_tasklet);
-       spin_unlock_irqrestore (&instance->receive_lock, flags);
-}
-
-static void udsl_process_receive (unsigned long data)
-{
-       struct udsl_receive_buffer *buf;
-       struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
-       struct udsl_receiver *rcv;
-       int err;
-
-made_progress:
-       while (!list_empty (&instance->spare_receive_buffers)) {
-               spin_lock_irq (&instance->receive_lock);
-               if (list_empty (&instance->spare_receivers)) {
-                       spin_unlock_irq (&instance->receive_lock);
-                       break;
-               }
-               rcv = list_entry (instance->spare_receivers.next, struct 
udsl_receiver, list);
-               list_del (&rcv->list);
-               spin_unlock_irq (&instance->receive_lock);
-
-               buf = list_entry (instance->spare_receive_buffers.next, struct 
udsl_receive_buffer, list);
-               list_del (&buf->list);
-
-               rcv->buffer = buf;
-
-               FILL_BULK_URB (rcv->urb,
-                              instance->usb_dev,
-                              usb_rcvbulkpipe (instance->usb_dev, 
UDSL_ENDPOINT_DATA_IN),
-                              buf->base,
-                              rcv_buf_size * ATM_CELL_SIZE,
-                              udsl_complete_receive,
-                              rcv);
-               rcv->urb->transfer_flags |= USB_QUEUE_BULK;
-
-               vdbg ("udsl_process_receive: sending urb 0x%p, rcv 0x%p, buf 0x%p", 
rcv->urb, rcv, buf);
-
-               if ((err = usb_submit_urb(rcv->urb)) < 0) {
-                       dbg ("udsl_process_receive: urb submission failed (%d)!", err);
-                       list_add (&buf->list, &instance->spare_receive_buffers);
-                       spin_lock_irq (&instance->receive_lock);
-                       list_add (&rcv->list, &instance->spare_receivers);
-                       spin_unlock_irq (&instance->receive_lock);
-                       break;
-               }
-       }
-
-       spin_lock_irq (&instance->receive_lock);
-       if (list_empty (&instance->filled_receive_buffers)) {
-               spin_unlock_irq (&instance->receive_lock);
-               return; /* done - no more buffers */
-       }
-       buf = list_entry (instance->filled_receive_buffers.next, struct 
udsl_receive_buffer, list);
-       list_del (&buf->list);
-       spin_unlock_irq (&instance->receive_lock);
-       vdbg ("udsl_process_receive: processing buf 0x%p", buf);
-       udsl_extract_cells (instance, buf->base, buf->filled_cells);
-       list_add (&buf->list, &instance->spare_receive_buffers);
-       goto made_progress;
-}
-
-
-/***********
-**  send  **
-***********/
-
-static void udsl_complete_send (struct urb *urb)
-{
-       struct udsl_instance_data *instance;
-       struct udsl_sender *snd;
-       unsigned long flags;
-
-       if (!urb || !(snd = urb->context) || !(instance = snd->instance)) {
-               dbg ("udsl_complete_send: bad urb!");
-               return;
-       }
-
-       vdbg ("udsl_complete_send: urb 0x%p, status %d, snd 0x%p, buf 0x%p", urb, 
urb->status, snd, snd->buffer);
-
-       /* may not be in_interrupt() */
-       spin_lock_irqsave (&instance->send_lock, flags);
-       list_add (&snd->list, &instance->spare_senders);
-       list_add (&snd->buffer->list, &instance->spare_send_buffers);
-       tasklet_schedule (&instance->send_tasklet);
-       spin_unlock_irqrestore (&instance->send_lock, flags);
-}
-
-static void udsl_process_send (unsigned long data)
-{
-       struct udsl_send_buffer *buf;
-       struct udsl_instance_data *instance = (struct udsl_instance_data *) data;
-       struct sk_buff *skb;
-       struct udsl_sender *snd;
-       int err;
-       unsigned int num_written;
-
-made_progress:
-       spin_lock_irq (&instance->send_lock);
-       while (!list_empty (&instance->spare_senders)) {
-               if (!list_empty (&instance->filled_send_buffers)) {
-                       buf = list_entry (instance->filled_send_buffers.next, struct 
udsl_send_buffer, list);
-                       list_del (&buf->list);
-               } else if ((buf = instance->current_buffer)) {
-                       instance->current_buffer = NULL;
-               } else /* all buffers empty */
-                       break;
-
-               snd = list_entry (instance->spare_senders.next, struct udsl_sender, 
list);
-               list_del (&snd->list);
-               spin_unlock_irq (&instance->send_lock);
-
-               snd->buffer = buf;
-               FILL_BULK_URB (snd->urb,
-                              instance->usb_dev,
-                              usb_sndbulkpipe (instance->usb_dev, 
UDSL_ENDPOINT_DATA_OUT),
-                              buf->base,
-                              (snd_buf_size - buf->free_cells) * ATM_CELL_SIZE,
-                              udsl_complete_send,
-                              snd);
-               snd->urb->transfer_flags |= USB_QUEUE_BULK;
-
-               vdbg ("udsl_process_send: submitting urb 0x%p (%d cells), snd 0x%p, 
buf 0x%p", snd->urb, snd_buf_size - buf->free_cells, snd, buf);
-
-               if ((err = usb_submit_urb(snd->urb)) < 0) {
-                       dbg ("udsl_process_send: urb submission failed (%d)!", err);
-                       spin_lock_irq (&instance->send_lock);
-                       list_add (&snd->list, &instance->spare_senders);
-                       spin_unlock_irq (&instance->send_lock);
-                       list_add (&buf->list, &instance->filled_send_buffers);
-                       return; /* bail out */
-               }
-
-               spin_lock_irq (&instance->send_lock);
-       } /* while */
-       spin_unlock_irq (&instance->send_lock);
-
-       if (!instance->current_skb && !(instance->current_skb = skb_dequeue 
(&instance->sndqueue)))
-               return; /* done - no more skbs */
-
-       skb = instance->current_skb;
-
-       if (!(buf = instance->current_buffer)) {
-               spin_lock_irq (&instance->send_lock);
-               if (list_empty (&instance->spare_send_buffers)) {
-                       instance->current_buffer = NULL;
-                       spin_unlock_irq (&instance->send_lock);
-                       return; /* done - no more buffers */
-               }
-               buf = list_entry (instance->spare_send_buffers.next, struct 
udsl_send_buffer, list);
-               list_del (&buf->list);
-               spin_unlock_irq (&instance->send_lock);
-
-               buf->free_start = buf->base;
-               buf->free_cells = snd_buf_size;
-
-               instance->current_buffer = buf;
-       }
-
-       num_written = udsl_write_cells (buf->free_cells, skb, &buf->free_start);
-
-       vdbg ("udsl_process_send: wrote %u cells from skb 0x%p to buffer 0x%p", 
num_written, skb, buf);
-
-       if (!(buf->free_cells -= num_written)) {
-               list_add_tail (&buf->list, &instance->filled_send_buffers);
-               instance->current_buffer = NULL;
-       }
-
-       vdbg ("udsl_process_send: buffer contains %d cells, %d left", snd_buf_size - 
buf->free_cells, buf->free_cells);
-
-       if (!UDSL_SKB (skb)->num_cells) {
-               struct atm_vcc *vcc = UDSL_SKB (skb)->atm_data.vcc;
-
-               if (vcc->pop)
-                       vcc->pop (vcc, skb);
-               else
-                       dev_kfree_skb (skb);
-               instance->current_skb = NULL;
-
-               atomic_inc (&vcc->stats->tx);
-       }
-
-       goto made_progress;
-}
-
-static void udsl_cancel_send (struct udsl_instance_data *instance, struct atm_vcc 
*vcc)
-{
-       struct sk_buff *skb, *n;
-
-       dbg ("udsl_cancel_send entered");
-       spin_lock_irq (&instance->sndqueue.lock);
-       for (skb = instance->sndqueue.next, n = skb->next; skb != (struct sk_buff 
*)&instance->sndqueue; skb = n, n = skb->next)
-               if (UDSL_SKB (skb)->atm_data.vcc == vcc) {
-                       dbg ("udsl_cancel_send: popping skb 0x%p", skb);
-                       __skb_unlink (skb, &instance->sndqueue);
-                       if (vcc->pop)
-                               vcc->pop (vcc, skb);
-                       else
-                               dev_kfree_skb (skb);
-               }
-       spin_unlock_irq (&instance->sndqueue.lock);
-
-       tasklet_disable (&instance->send_tasklet);
-       if ((skb = instance->current_skb) && (UDSL_SKB (skb)->atm_data.vcc == vcc)) {
-               dbg ("udsl_cancel_send: popping current skb (0x%p)", skb);
-               instance->current_skb = NULL;
-               if (vcc->pop)
-                       vcc->pop (vcc, skb);
-               else
-                       dev_kfree_skb (skb);
-       }
-       tasklet_enable (&instance->send_tasklet);
-       dbg ("udsl_cancel_send done");
-}
-
-static int udsl_atm_send (struct atm_vcc *vcc, struct sk_buff *skb)
-{
-       struct udsl_instance_data *instance = vcc->dev->dev_data;
-
-       vdbg ("udsl_atm_send called (skb 0x%p, len %u)", skb, skb->len);
-
-       if (!instance || !instance->usb_dev) {
-               dbg ("udsl_atm_send: NULL data!");
-               return -ENODEV;
-       }
-
-       if (vcc->qos.aal != ATM_AAL5) {
-               dbg ("udsl_atm_send: unsupported ATM type %d!", vcc->qos.aal);
-               return -EINVAL;
-       }
-
-       if (skb->len > ATM_MAX_AAL5_PDU) {
-               dbg ("udsl_atm_send: packet too long (%d vs %d)!", skb->len, 
ATM_MAX_AAL5_PDU);
-               return -EINVAL;
-       }
-
-       PACKETDEBUG (skb->data, skb->len);
-
-       udsl_groom_skb (vcc, skb);
-       skb_queue_tail (&instance->sndqueue, skb);
-       tasklet_schedule (&instance->send_tasklet);
-
-       return 0;
-}
-
-
-/**********
-**  ATM  **
-**********/
-
-static void udsl_atm_dev_close (struct atm_dev *dev)
-{
-       struct udsl_instance_data *instance = dev->dev_data;
-
-       if (!instance) {
-               dbg ("udsl_atm_dev_close: NULL instance!");
-               return;
-       }
-
-       dbg ("udsl_atm_dev_close: queue has %u elements", instance->sndqueue.qlen);
-
-       tasklet_kill (&instance->receive_tasklet);
-       tasklet_kill (&instance->send_tasklet);
-       kfree (instance);
-       dev->dev_data = NULL;
-}
-
-static int udsl_atm_proc_read (struct atm_dev *atm_dev, loff_t *pos, char *page)
-{
-       struct udsl_instance_data *instance = atm_dev->dev_data;
-       int left = *pos;
-
-       if (!instance) {
-               dbg ("udsl_atm_proc_read: NULL instance!");
-               return -ENODEV;
-       }
-
-       if (!left--)
-               return sprintf (page, "%s\n", instance->description);
-
-       if (!left--)
-               return sprintf (page, "MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
-                               atm_dev->esi [0], atm_dev->esi [1], atm_dev->esi [2],
-                               atm_dev->esi [3], atm_dev->esi [4], atm_dev->esi [5]);
-
-       if (!left--)
-               return sprintf (page, "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop 
)\n",
-                               atomic_read (&atm_dev->stats.aal5.tx),
-                               atomic_read (&atm_dev->stats.aal5.tx_err),
-                               atomic_read (&atm_dev->stats.aal5.rx),
-                               atomic_read (&atm_dev->stats.aal5.rx_err),
-                               atomic_read (&atm_dev->stats.aal5.rx_drop));
-
-       if (!left--) {
-               switch (atm_dev->signal) {
-               case ATM_PHY_SIG_FOUND:
-                       sprintf (page, "Line up");
-                       break;
-               case ATM_PHY_SIG_LOST:
-                       sprintf (page, "Line down");
-                       break;
-               default:
-                       sprintf (page, "Line state unknown");
-                       break;
-               }
-
-               if (instance->usb_dev) {
-                       if (!instance->firmware_loaded)
-                               strcat (page, ", no firmware\n");
-                       else
-                               strcat (page, ", firmware loaded\n");
-               } else
-                       strcat (page, ", disconnected\n");
-
-               return strlen (page);
-       }
-
-       return 0;
-}
-
-static int udsl_atm_open (struct atm_vcc *vcc, short vpi, int vci)
-{
-       struct udsl_instance_data *instance = vcc->dev->dev_data;
-       struct udsl_vcc_data *new;
-
-       dbg ("udsl_atm_open: vpi %hd, vci %d", vpi, vci);
-
-       if (!instance || !instance->usb_dev) {
-               dbg ("udsl_atm_open: NULL data!");
-               return -ENODEV;
-       }
-
-       if ((vpi == ATM_VPI_ANY) || (vci == ATM_VCI_ANY))
-               return -EINVAL;
-
-       /* only support AAL5 */
-       if ((vcc->qos.aal != ATM_AAL5) || (vcc->qos.rxtp.max_sdu < 0) || 
(vcc->qos.rxtp.max_sdu > ATM_MAX_AAL5_PDU))
-               return -EINVAL;
-
-       if (!instance->firmware_loaded) {
-               dbg ("udsl_atm_open: firmware not loaded!");
-               return -EAGAIN;
-       }
-
-       down (&instance->serialize); /* vs self, udsl_atm_close */
-
-       if (udsl_find_vcc (instance, vpi, vci)) {
-               up (&instance->serialize);
-               return -EADDRINUSE;
-       }
-
-       if (!(new = kmalloc (sizeof (struct udsl_vcc_data), GFP_KERNEL))) {
-               up (&instance->serialize);
-               return -ENOMEM;
-       }
-
-       memset (new, 0, sizeof (struct udsl_vcc_data));
-       new->vcc = vcc;
-       new->vpi = vpi;
-       new->vci = vci;
-       new->max_pdu = max (1, UDSL_NUM_CELLS (vcc->qos.rxtp.max_sdu)) * 
ATM_CELL_PAYLOAD;
-
-       vcc->dev_data = new;
-       vcc->vpi = vpi;
-       vcc->vci = vci;
-
-       tasklet_disable (&instance->receive_tasklet);
-       list_add (&new->list, &instance->vcc_list);
-       tasklet_enable (&instance->receive_tasklet);
-
-       set_bit (ATM_VF_ADDR, &vcc->flags);
-       set_bit (ATM_VF_PARTIAL, &vcc->flags);
-       set_bit (ATM_VF_READY, &vcc->flags);
-
-       up (&instance->serialize);
-
-       tasklet_schedule (&instance->receive_tasklet);
-
-       dbg ("udsl_atm_open: allocated vcc data 0x%p (max_pdu: %u)", new, 
new->max_pdu);
-
-       return 0;
-}
-
-static void udsl_atm_close (struct atm_vcc *vcc)
-{
-       struct udsl_instance_data *instance = vcc->dev->dev_data;
-       struct udsl_vcc_data *vcc_data = vcc->dev_data;
-
-       dbg ("udsl_atm_close called");
-
-       if (!instance || !vcc_data) {
-               dbg ("udsl_atm_close: NULL data!");
-               return;
-       }
-
-       dbg ("udsl_atm_close: deallocating vcc 0x%p with vpi %d vci %d", vcc_data, 
vcc_data->vpi, vcc_data->vci);
-
-       udsl_cancel_send (instance, vcc);
-
-       down (&instance->serialize); /* vs self, udsl_atm_open */
-
-       tasklet_disable (&instance->receive_tasklet);
-       list_del (&vcc_data->list);
-       tasklet_enable (&instance->receive_tasklet);
-
-       if (vcc_data->skb)
-               dev_kfree_skb (vcc_data->skb);
-       vcc_data->skb = NULL;
-
-       kfree (vcc_data);
-       vcc->dev_data = NULL;
-
-       vcc->vpi = ATM_VPI_UNSPEC;
-       vcc->vci = ATM_VCI_UNSPEC;
-       clear_bit (ATM_VF_READY, &vcc->flags);
-       clear_bit (ATM_VF_PARTIAL, &vcc->flags);
-       clear_bit (ATM_VF_ADDR, &vcc->flags);
-
-       up (&instance->serialize);
-
-       dbg ("udsl_atm_close successful");
-}
-
-static int udsl_atm_ioctl (struct atm_dev *dev, unsigned int cmd, void *arg)
-{
-       switch (cmd) {
-       case ATM_QUERYLOOP:
-               return put_user (ATM_LM_NONE, (int *) arg) ? -EFAULT : 0;
-       default:
-               return -ENOIOCTLCMD;
-       }
-}
-
-
-/**********
-**  USB  **
-**********/
-
-static int udsl_set_alternate (struct udsl_instance_data *instance)
-{
-       down (&instance->serialize); /* vs self */
-       if (!instance->firmware_loaded) {
-               int ret;
-
-               if ((ret = usb_set_interface (instance->usb_dev, 1, 1)) < 0) {
-                       dbg ("udsl_set_alternate: usb_set_interface returned %d!", 
ret);
-                       up (&instance->serialize);
-                       return ret;
-               }
-               instance->firmware_loaded = 1;
-       }
-       up (&instance->serialize);
-
-       tasklet_schedule (&instance->receive_tasklet);
-
-       return 0;
-}
-
-static int udsl_usb_ioctl (struct usb_device *dev, unsigned int code, void *user_data)
-{
-       struct usb_interface *intf = usb_ifnum_to_if (dev, 1);
-       struct udsl_instance_data *instance = intf->private_data;
-
-       dbg ("udsl_usb_ioctl entered");
-
-       if (!instance) {
-               dbg ("udsl_usb_ioctl: NULL instance!");
-               return -ENODEV;
-       }
-
-       switch (code) {
-       case UDSL_IOCTL_LINE_UP:
-               instance->atm_dev->signal = ATM_PHY_SIG_FOUND;
-               return udsl_set_alternate (instance);
-       case UDSL_IOCTL_LINE_DOWN:
-               instance->atm_dev->signal = ATM_PHY_SIG_LOST;
-               return 0;
-       default:
-               return -ENOTTY;
-       }
-}
-
-static void *udsl_usb_probe (struct usb_device *dev, unsigned int ifnum, const struct 
usb_device_id *id)
-{
-       struct udsl_instance_data *instance;
-       unsigned char mac_str [13];
-       int i, length;
-       char *buf;
-
-       dbg ("udsl_usb_probe: trying device with vendor=0x%x, product=0x%x, ifnum %d",
-            dev->descriptor.idVendor, dev->descriptor.idProduct, ifnum);
-
-       if ((dev->descriptor.bDeviceClass != USB_CLASS_VENDOR_SPEC) ||
-           (dev->descriptor.idVendor != SPEEDTOUCH_VENDORID) ||
-           (dev->descriptor.idProduct != SPEEDTOUCH_PRODUCTID) || (ifnum != 1))
-               return NULL;
-
-       dbg ("udsl_usb_probe: device accepted");
-
-       /* instance init */
-       if (!(instance = kmalloc (sizeof (struct udsl_instance_data), GFP_KERNEL))) {
-               dbg ("udsl_usb_probe: no memory for instance data!");
-               return NULL;
-       }
-
-       memset (instance, 0, sizeof (struct udsl_instance_data));
-
-       init_MUTEX (&instance->serialize);
-
-       instance->usb_dev = dev;
-
-       INIT_LIST_HEAD (&instance->vcc_list);
-
-       spin_lock_init (&instance->receive_lock);
-       INIT_LIST_HEAD (&instance->spare_receivers);
-       INIT_LIST_HEAD (&instance->filled_receive_buffers);
-
-       tasklet_init (&instance->receive_tasklet, udsl_process_receive, (unsigned 
long) instance);
-       INIT_LIST_HEAD (&instance->spare_receive_buffers);
-
-       skb_queue_head_init (&instance->sndqueue);
-
-       spin_lock_init (&instance->send_lock);
-       INIT_LIST_HEAD (&instance->spare_senders);
-       INIT_LIST_HEAD (&instance->spare_send_buffers);
-
-       tasklet_init (&instance->send_tasklet, udsl_process_send, (unsigned long) 
instance);
-       INIT_LIST_HEAD (&instance->filled_send_buffers);
-
-       /* receive init */
-       for (i = 0; i < num_rcv_urbs; i++) {
-               struct udsl_receiver *rcv = &(instance->receivers [i]);
-
-               if (!(rcv->urb = usb_alloc_urb (0))) {
-                       dbg ("udsl_usb_probe: no memory for receive urb %d!", i);
-                       goto fail;
-               }
-
-               rcv->instance = instance;
-
-               list_add (&rcv->list, &instance->spare_receivers);
-       }
-
-       for (i = 0; i < num_rcv_bufs; i++) {
-               struct udsl_receive_buffer *buf = &(instance->receive_buffers [i]);
-
-               if (!(buf->base = kmalloc (rcv_buf_size * ATM_CELL_SIZE, GFP_KERNEL))) 
{
-                       dbg ("udsl_usb_probe: no memory for receive buffer %d!", i);
-                       goto fail;
-               }
-
-               list_add (&buf->list, &instance->spare_receive_buffers);
-       }
-
-       /* send init */
-       for (i = 0; i < num_snd_urbs; i++) {
-               struct udsl_sender *snd = &(instance->senders [i]);
-
-               if (!(snd->urb = usb_alloc_urb (0))) {
-                       dbg ("udsl_usb_probe: no memory for send urb %d!", i);
-                       goto fail;
-               }
-
-               snd->instance = instance;
-
-               list_add (&snd->list, &instance->spare_senders);
-       }
-
-       for (i = 0; i < num_snd_bufs; i++) {
-               struct udsl_send_buffer *buf = &(instance->send_buffers [i]);
-
-               if (!(buf->base = kmalloc (snd_buf_size * ATM_CELL_SIZE, GFP_KERNEL))) 
{
-                       dbg ("udsl_usb_probe: no memory for send buffer %d!", i);
-                       goto fail;
-               }
-
-               list_add (&buf->list, &instance->spare_send_buffers);
-       }
-
-       /* ATM init */
-       if (!(instance->atm_dev = atm_dev_register (udsl_driver_name, 
&udsl_atm_devops, -1, 0))) {
-               dbg ("udsl_usb_probe: failed to register ATM device!");
-               goto fail;
-       }
-
-       instance->atm_dev->ci_range.vpi_bits = ATM_CI_MAX;
-       instance->atm_dev->ci_range.vci_bits = ATM_CI_MAX;
-       instance->atm_dev->signal = ATM_PHY_SIG_UNKNOWN;
-
-       /* temp init ATM device, set to 128kbit */
-       instance->atm_dev->link_rate = 128 * 1000 / 424;
-
-       /* set MAC address, it is stored in the serial number */
-       memset (instance->atm_dev->esi, 0, sizeof (instance->atm_dev->esi));
-       if (usb_string (dev, dev->descriptor.iSerialNumber, mac_str, sizeof (mac_str)) 
== 12)
-               for (i = 0; i < 6; i++)
-                       instance->atm_dev->esi [i] = (hex2int (mac_str [i * 2]) * 16) 
+ (hex2int (mac_str [i * 2 + 1]));
-
-       /* device description */
-       buf = instance->description;
-       length = sizeof (instance->description);
-
-       if ((i = usb_string (dev, dev->descriptor.iProduct, buf, length)) < 0)
-               goto finish;
-
-       buf += i;
-       length -= i;
-
-       i = snprintf (buf, length, " (");
-       buf += i;
-       length -= i;
-
-       if (length <= 0 || (i = usb_make_path (dev, buf, length)) < 0)
-               goto finish;
-
-       buf += i;
-       length -= i;
-
-       snprintf (buf, length, ")");
-
-finish:
-       /* ready for ATM callbacks */
-       wmb ();
-       instance->atm_dev->dev_data = instance;
-
-       return instance;
-
-fail:
-       for (i = 0; i < num_snd_bufs; i++)
-               kfree (instance->send_buffers [i].base);
-
-       for (i = 0; i < num_snd_urbs; i++)
-               usb_free_urb (instance->senders [i].urb);
-
-       for (i = 0; i < num_rcv_bufs; i++)
-               kfree (instance->receive_buffers [i].base);
-
-       for (i = 0; i < num_rcv_urbs; i++)
-               usb_free_urb (instance->receivers [i].urb);
-
-       kfree (instance);
-
-       return NULL;
-}
-
-static void udsl_usb_disconnect (struct usb_device *dev, void *ptr)
-{
-       struct udsl_instance_data *instance = ptr;
-       struct list_head *pos;
-       unsigned int count;
-       int result, i;
-
-       dbg ("udsl_usb_disconnect entered");
-
-       if (!instance) {
-               dbg ("udsl_usb_disconnect: NULL instance!");
-               return;
-       }
-
-       /* receive finalize */
-       tasklet_disable (&instance->receive_tasklet);
-
-       for (i = 0; i < num_rcv_urbs; i++)
-               if ((result = usb_unlink_urb (instance->receivers [i].urb)) < 0)
-                       dbg ("udsl_usb_disconnect: usb_unlink_urb on receive urb %d 
returned %d", i, result);
-
-       /* wait for completion handlers to finish */
-       do {
-               count = 0;
-               spin_lock_irq (&instance->receive_lock);
-               list_for_each (pos, &instance->spare_receivers)
-                       if (++count > num_rcv_urbs)
-                               panic (__FILE__ ": memory corruption detected at line 
%d!\n", __LINE__);
-               spin_unlock_irq (&instance->receive_lock);
-
-               dbg ("udsl_usb_disconnect: found %u spare receivers", count);
-
-               if (count == num_rcv_urbs)
-                       break;
-
-               set_current_state (TASK_RUNNING);
-               schedule ();
-       } while (1);
-
-       /* no need to take the spinlock */
-       INIT_LIST_HEAD (&instance->filled_receive_buffers);
-       INIT_LIST_HEAD (&instance->spare_receive_buffers);
-
-       tasklet_enable (&instance->receive_tasklet);
-
-       for (i = 0; i < num_rcv_urbs; i++)
-               usb_free_urb (instance->receivers [i].urb);
-
-       for (i = 0; i < num_rcv_bufs; i++)
-               kfree (instance->receive_buffers [i].base);
-
-       /* send finalize */
-       tasklet_disable (&instance->send_tasklet);
-
-       for (i = 0; i < num_snd_urbs; i++)
-               if ((result = usb_unlink_urb (instance->senders [i].urb)) < 0)
-                       dbg ("udsl_usb_disconnect: usb_unlink_urb on send urb %d 
returned %d", i, result);
-
-       /* wait for completion handlers to finish */
-       do {
-               count = 0;
-               spin_lock_irq (&instance->send_lock);
-               list_for_each (pos, &instance->spare_senders)
-                       if (++count > num_snd_urbs)
-                               panic (__FILE__ ": memory corruption detected at line 
%d!\n", __LINE__);
-               spin_unlock_irq (&instance->send_lock);
-
-               dbg ("udsl_usb_disconnect: found %u spare senders", count);
-
-               if (count == num_snd_urbs)
-                       break;
-
-               set_current_state (TASK_RUNNING);
-               schedule ();
-       } while (1);
-
-       /* no need to take the spinlock */
-       INIT_LIST_HEAD (&instance->spare_senders);
-       INIT_LIST_HEAD (&instance->spare_send_buffers);
-       instance->current_buffer = NULL;
-
-       tasklet_enable (&instance->send_tasklet);
-
-       for (i = 0; i < num_snd_urbs; i++)
-               usb_free_urb (instance->senders [i].urb);
-
-       for (i = 0; i < num_snd_bufs; i++)
-               kfree (instance->send_buffers [i].base);
-
-       wmb ();
-       instance->usb_dev = NULL;
-
-       /* ATM finalize */
-       shutdown_atm_dev (instance->atm_dev); /* frees instance, kills tasklets */
-}
-
-
-/***********
-**  init  **
-***********/
-
-static int __init udsl_usb_init (void)
-{
-       struct sk_buff *skb; /* dummy for sizeof */
-
-       dbg ("udsl_usb_init: driver version " DRIVER_VERSION);
-
-       if (sizeof (struct udsl_control) > sizeof (skb->cb)) {
-               printk (KERN_ERR __FILE__ ": unusable with this kernel!\n");
-               return -EIO;
-       }
-
-       if ((num_rcv_urbs > UDSL_MAX_RCV_URBS) || (num_snd_urbs > UDSL_MAX_SND_URBS) ||
-           (num_rcv_bufs > UDSL_MAX_RCV_BUFS) || (num_snd_bufs > UDSL_MAX_SND_BUFS) ||
-           (rcv_buf_size > UDSL_MAX_RCV_BUF_SIZE) || (snd_buf_size > 
UDSL_MAX_SND_BUF_SIZE))
-               return -EINVAL;
-
-       return usb_register (&udsl_usb_driver);
-}
-
-static void __exit udsl_usb_cleanup (void)
-{
-       dbg ("udsl_usb_cleanup entered");
-
-       usb_deregister (&udsl_usb_driver);
-}
-
-module_init (udsl_usb_init);
-module_exit (udsl_usb_cleanup);
-
-MODULE_AUTHOR (DRIVER_AUTHOR);
-MODULE_DESCRIPTION (DRIVER_DESC);
-MODULE_LICENSE ("GPL");
-
-
-/************
-**  debug  **
-************/
-
-#ifdef VERBOSE_DEBUG
-static int udsl_print_packet (const unsigned char *data, int len)
-{
-       unsigned char buffer [256];
-       int i = 0, j = 0;
-
-       for (i = 0; i < len;) {
-               buffer [0] = '\0';
-               sprintf (buffer, "%.3d :", i);
-               for (j = 0; (j < 16) && (i < len); j++, i++) {
-                       sprintf (buffer, "%s %2.2x", buffer, data [i]);
-               }
-               dbg ("%s", buffer);
-       }
-       return i;
-}
-#endif



-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to