patch-2.4.10 linux/drivers/usb/serial/pl2303.c

Next file: linux/drivers/usb/serial/usb-serial.h
Previous file: linux/drivers/usb/serial/omninet.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.9/linux/drivers/usb/serial/pl2303.c linux/drivers/usb/serial/pl2303.c
@@ -12,6 +12,13 @@
  *
  * See Documentation/usb/usb-serial.txt for more information on using this driver
  *
+ * 2001_Aug_30 gkh
+ *	fixed oops in write_bulk_callback.
+ *
+ * 2001_Aug_28 gkh
+ *	reworked buffer logic to be like other usb-serial drivers.  Hopefully
+ *	removing some reported problems.
+ *
  * 2001_Jun_06 gkh
  *	finished porting to 2.4 format.
  * 
@@ -46,26 +53,10 @@
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v0.5"
+#define DRIVER_VERSION "v0.7"
 #define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver"
 
 
-#ifndef MIN
-#define MIN(a,b)        ((a) < (b) ? (a) : (b))
-#endif
-
-
-#define	PL2303_LOCK(port,flags)					\
-		do {						\
-		spin_lock_irqsave(&((struct pl2303_private *)(port->private))->lock, flags);	\
-		} while (0)
-
-#define	PL2303_UNLOCK(port,flags)				\
-		do {						\
-		spin_unlock_irqrestore(&((struct pl2303_private *)(port->private))->lock, flags);	\
-		} while (0)
-
-
 
 static __devinitdata struct usb_device_id id_table [] = {
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
@@ -75,33 +66,20 @@
 
 MODULE_DEVICE_TABLE (usb, id_table);
 
-struct pl2303_private {
-	spinlock_t	lock;
-	unsigned char	*xmit_buf;
-	int		xmit_head;
-	int		xmit_tail;
-	int		xmit_cnt;
-};
 
 /* function prototypes for a PL2303 serial converter */
-static int pl2303_startup (struct usb_serial *serial);
 static int pl2303_open (struct usb_serial_port *port, struct file *filp);
 static void pl2303_close (struct usb_serial_port *port, struct file *filp);
 static void pl2303_set_termios (struct usb_serial_port *port,
 				struct termios *old);
 static int pl2303_ioctl (struct usb_serial_port *port, struct file *file,
 			 unsigned int cmd, unsigned long arg);
-static void pl2303_throttle (struct usb_serial_port *port);
-static void pl2303_unthrottle (struct usb_serial_port *port);
 static void pl2303_read_int_callback (struct urb *urb);
 static void pl2303_read_bulk_callback (struct urb *urb);
 static void pl2303_write_bulk_callback (struct urb *urb);
 static int pl2303_write (struct usb_serial_port *port, int from_user,
 			 const unsigned char *buf, int count);
-static int pl2303_write_room(struct usb_serial_port *port);
-static int pl2303_chars_in_buffer(struct usb_serial_port *port);
 static void pl2303_break_ctl(struct usb_serial_port *port,int break_state);
-static void start_xmit (struct usb_serial_port *port);
 
 
 /* All of the device info needed for the PL2303 SIO serial converter */
@@ -117,172 +95,54 @@
 	num_ports:		1,
 	open:			pl2303_open,
 	close:			pl2303_close,
-	throttle:		pl2303_throttle,
-	unthrottle:		pl2303_unthrottle,
 	write:			pl2303_write,
 	ioctl:			pl2303_ioctl,
-	write_room:		pl2303_write_room,
-	chars_in_buffer:	pl2303_chars_in_buffer,
 	break_ctl:		pl2303_break_ctl,
 	set_termios:		pl2303_set_termios,
 	read_bulk_callback:	pl2303_read_bulk_callback,
 	read_int_callback:	pl2303_read_int_callback,
 	write_bulk_callback:	pl2303_write_bulk_callback,
-	startup:		pl2303_startup,
 };
 
 
-#define WDR_TIMEOUT (HZ * 5 )   /* default urb timeout */
 
-static unsigned char *tmp_buf;
-static DECLARE_MUTEX (tmp_buf_sem);
-
-
-
-static int
-pl2303_write (struct usb_serial_port *port, int from_user,
-	      const unsigned char *buf, int count)
-{				/* pl2303_write */
-	struct pl2303_private *info = (struct pl2303_private *)port->private;
-	unsigned long flags;
-	int c,ret=0;
-	struct tty_struct *tty=port->tty;
+static int pl2303_write (struct usb_serial_port *port, int from_user,  const unsigned char *buf, int count)
+{
+	int result;
 
-	dbg ("pl2303_write port %d, %d bytes", port->number, count);
+	dbg (__FUNCTION__ " - port %d, %d bytes", port->number, count);
 
-	if (!info) {
-		return -ENODEV;
+	if (!port->tty) {
+		err (__FUNCTION__ " - no tty???");
+		return 0;
 	}
 
-	if (!tty || !info->xmit_buf || !tmp_buf) {
+	if (port->write_urb->status == -EINPROGRESS) {
+		dbg (__FUNCTION__ " - already writing");
 		return 0;
 	}
 
-
-	PL2303_LOCK(port,flags);
-
-
+	count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
 	if (from_user) {
-		down(&tmp_buf_sem);
-		while (1) {
-			c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
-					   SERIAL_XMIT_SIZE - info->xmit_head));
-			if (c <= 0)
-				break;
-
-			c -= copy_from_user(tmp_buf, buf, c);
-			if (!c) {
-				if (!ret) {
-					ret = -EFAULT;
-				}
-				break;
-			}
-			c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
-				       SERIAL_XMIT_SIZE - info->xmit_head));
-			memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
-			info->xmit_head = ((info->xmit_head + c) & (SERIAL_XMIT_SIZE-1));
-			info->xmit_cnt += c;
-			buf += c;
-			count -= c;
-			ret += c;
-		}
-		up(&tmp_buf_sem);
+		if (copy_from_user (port->write_urb->transfer_buffer, buf, count))
+			return -EFAULT;
 	} else {
-		while (1) {
-			c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, 
-					   SERIAL_XMIT_SIZE - info->xmit_head));
-			if (c <= 0) {
-				break;
-			}
-			memcpy(info->xmit_buf + info->xmit_head, buf, c);
-			info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
-			info->xmit_cnt += c;
-			buf += c;
-			count -= c;
-			ret += c;
-		}
-	}
-	PL2303_UNLOCK(port, flags);
-
-	if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
-		start_xmit(port);
+		memcpy (port->write_urb->transfer_buffer, buf, count);
 	}
-	return ret;
-}
-
-static int pl2303_write_room(struct usb_serial_port *port)
-{
-	struct pl2303_private *info = (struct pl2303_private *)port->private;
-	int     ret;
-
-	if (!info)
-		return 0;
+	
+	usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
 
-	ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
-	if (ret < 0)
-		ret = 0;
-	return ret;
-}
-
-static int pl2303_chars_in_buffer(struct usb_serial_port *port)
-{
-	struct pl2303_private *info = (struct pl2303_private *)port->private;
-
-	if (!info)
-		return 0;
+	port->write_urb->transfer_buffer_length = count;
+	port->write_urb->dev = port->serial->dev;
+	result = usb_submit_urb (port->write_urb);
+	if (result)
+		err(__FUNCTION__ " - failed submitting write urb, error %d", result);
+	else
+		result = count;
 
-	return info->xmit_cnt;
+	return result;
 }
 
-static void pl2303_throttle(struct usb_serial_port *port)
-{
-#if 0
-	//struct usb_serial *serial = port->serial;
-	struct tty_struct *tty=port->tty;
-	unsigned long flags;
-
-
-	char    buf[64];
-
-	dbg("throttle %s: %d....", tty_name(tty, buf),
-	    tty->ldisc.chars_in_buffer(tty));
-
-//FIXME FIXME FIXME	
-	if (I_IXOFF(tty))
-		rs_send_xchar(tty, STOP_CHAR(tty));
-
-	PL2303_LOCK(port,flags);
-	//Should remove read request if one is present
-	PL2303_UNLOCK(port,flags);
-#endif
-}
-
-static void pl2303_unthrottle(struct usb_serial_port *port)
-{
-#if 0
-	//struct usb_serial *serial = port->serial;
-	struct tty_struct *tty=port->tty;
-	unsigned long flags;
-
-
-	char    buf[64];
-
-	dbg("unthrottle %s: %d....", tty_name(tty, buf),
-	    tty->ldisc.chars_in_buffer(tty));
-
-	//FIXME FIXME FIXME FIXME FIXME
-	if (I_IXOFF(tty)) {
-		if (info->x_char)
-			info->x_char = 0;
-		else
-			rs_send_xchar(tty, START_CHAR(tty));
-	}
-
-	PL2303_LOCK(port,flags);
-	//Should add read request if one is not present
-	PL2303_UNLOCK(fport,flags);
-#endif
-}
 
 
 static void
@@ -314,6 +174,10 @@
 
 	if (cflag & CSIZE) {
 		switch (cflag & CSIZE) {
+			case CS5:
+				buf[6] = 5;
+				dbg ("Setting CS5");
+				break;
 			case CS6:
 				buf[6] = 6;
 				dbg ("Setting CS6");
@@ -327,47 +191,29 @@
 				dbg ("Setting CS8");
 				break;
 			default:
-				err ("CSIZE was set but not CS6-CS8");
+				err ("CSIZE was set but not CS5-CS8");
 		}
 	}
 
 	baud = 0;
 	switch (cflag & CBAUD) {
-		case B0:
-			err ("Can't do B0 yet");  //FIXME
-			break;
-		case B300:
-			baud = 300;
-			break;
-		case B600:
-			baud = 600;
-			break;
-		case B1200:
-			baud = 1200;
-			break;
-		case B2400:
-			baud = 2400;
-			break;
-		case B4800:
-			baud = 4800;
-			break;
-		case B9600:
-			baud = 9600;
-			break;
-		case B19200:
-			baud = 19200;
-			break;
-		case B38400:
-			baud = 38400;
-			break;
-		case B57600:
-			baud = 57600;
-			break;
-		case B115200:
-			baud = 115200;
-			break;
+		case B75:	baud = 75;	break;
+		case B150:	baud = 150;	break;
+		case B300:	baud = 300;	break;
+		case B600:	baud = 600;	break;
+		case B1200:	baud = 1200;	break;
+		case B1800:	baud = 1800;	break;
+		case B2400:	baud = 2400;	break;
+		case B4800:	baud = 4800;	break;
+		case B9600:	baud = 9600;	break;
+		case B19200:	baud = 19200;	break;
+		case B38400:	baud = 38400;	break;
+		case B57600:	baud = 57600;	break;
+		case B115200:	baud = 115200;	break;
+		case B230400:	baud = 230400;	break;
+		case B460800:	baud = 460800;	break;
 		default:
-			dbg ("pl2303 driver does not support the baudrate requested (fix it)");
+			err ("pl2303 driver does not support the baudrate requested (fix it)");
 			break;
 	}
 
@@ -379,7 +225,9 @@
 	}
 
 
+	/* For reference buf[4]=0 is 1 stop bits */
 	/* For reference buf[4]=1 is 1.5 stop bits */
+	/* For reference buf[4]=2 is 2 stop bits */
 
 	if (cflag & CSTOPB) {
 		buf[4] = 2;
@@ -387,6 +235,9 @@
 
 
 	if (cflag & PARENB) {
+		/* For reference buf[5]=0 is none parity */
+		/* For reference buf[5]=1 is odd parity */
+		/* For reference buf[5]=2 is even parity */
 		/* For reference buf[5]=3 is mark parity */
 		/* For reference buf[5]=4 is space parity */
 		if (cflag & PARODD) {
@@ -433,169 +284,108 @@
 }       
 
 
-static int
-pl2303_open (struct usb_serial_port *port, struct file *filp)
-{				/* pl2303_open */
+static int pl2303_open (struct usb_serial_port *port, struct file *filp)
+{
 	struct termios tmp_termios;
 	struct usb_serial *serial = port->serial;
 	unsigned char buf[10];
-	int i;
+	int result;
 
-	dbg ("pl2303_open port %d", port->number);
+	if (port_paranoia_check (port, __FUNCTION__))
+		return -ENODEV;
+		
+	dbg (__FUNCTION__ "-  port %d", port->number);
 
-	port->active++;
+	down (&port->sem);
 
-#define FISH(a,b,c,d) \
-	i=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
-		    b, a,c  , d, buf, 1, 100); \
-	dbg("0x%x:0x%x:0x%x:0x%x  %d - %x",a,b,c,d,i,buf[0]);
-
-#define SOUP(a,b,c,d) \
-	i=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
-		    b, a,c  , d, NULL, 0, 100); \
-	dbg("0x%x:0x%x:0x%x:0x%x  %d",a,b,c,d,i);
-
-
-	FISH (0xc0, 1, 0x8484, 0);
-	SOUP (0x40, 1, 0x0404, 0);
-	FISH (0xc0, 1, 0x8484, 0);
-	FISH (0xc0, 1, 0x8383, 0);
-	FISH (0xc0, 1, 0x8484, 0);
-	SOUP (0x40, 1, 0x0404, 1);
-	FISH (0xc0, 1, 0x8484, 0);
-	FISH (0xc0, 1, 0x8383, 0);
-	SOUP (0x40, 1, 0, 1);
-	SOUP (0x40, 1, 1, 0xc0);
-	SOUP (0x40, 1, 2, 4);
+	++port->open_count;
+	MOD_INC_USE_COUNT;
 
-	/* Setup termios */
+	if (!port->active) {
+		port->active = 1;
+
+#define FISH(a,b,c,d)									\
+		result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0),	\
+				       b, a, c, d, buf, 1, 100);			\
+		dbg("0x%x:0x%x:0x%x:0x%x  %d - %x",a,b,c,d,result,buf[0]);
+
+#define SOUP(a,b,c,d)									\
+		result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0),	\
+				       b, a, c , d, NULL, 0, 100);			\
+		dbg("0x%x:0x%x:0x%x:0x%x  %d",a,b,c,d,result);
+
+		FISH (0xc0, 1, 0x8484, 0);
+		SOUP (0x40, 1, 0x0404, 0);
+		FISH (0xc0, 1, 0x8484, 0);
+		FISH (0xc0, 1, 0x8383, 0);
+		FISH (0xc0, 1, 0x8484, 0);
+		SOUP (0x40, 1, 0x0404, 1);
+		FISH (0xc0, 1, 0x8484, 0);
+		FISH (0xc0, 1, 0x8383, 0);
+		SOUP (0x40, 1, 0, 1);
+		SOUP (0x40, 1, 1, 0xc0);
+		SOUP (0x40, 1, 2, 4);
 
-	if (port->active == 1) {
+		/* Setup termios */
 		*(port->tty->termios) = tty_std_termios;
 		port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
-	}
-
-
-	pl2303_set_termios (port, &tmp_termios);
-
-	//FIXME: need to assert RTS and DTR if CRTSCTS off
-
-
-	if (port->active == 1) {
-		struct pl2303_private *info;
-		unsigned long flags,page;
-		int i;
-
-		info = (struct pl2303_private *)kmalloc (sizeof(struct pl2303_private), GFP_KERNEL);
-		if (info == NULL) {
-			err(__FUNCTION__ " - out of memory");
-			pl2303_close (port, NULL);
-			return -ENOMEM;
-		}
-		spin_lock_init(&info->lock);
-		port->private = info;
-
-
-		page = get_free_page(GFP_KERNEL);
-		if (!page) {
-			pl2303_close (port, NULL);
-			return -ENOMEM;
-		}
-
-		PL2303_LOCK(port,flags);
 
-		info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
+		pl2303_set_termios (port, &tmp_termios);
 
-		if (tmp_buf)
-			free_page(page);
-		else
-			tmp_buf	= (unsigned char *) page;
+		//FIXME: need to assert RTS and DTR if CRTSCTS off
 
-		PL2303_UNLOCK(port,flags);
-
-		page = get_free_page(GFP_KERNEL);
-		if (!page) {
-			pl2303_close (port, NULL);
-			return -ENOMEM;
-		}
-
-		PL2303_LOCK(port,flags);
-
-		if (info->xmit_buf)
-			free_page(page);
-		else
-			info->xmit_buf=(unsigned char *) page;
-
-		PL2303_UNLOCK(port,flags);
-
-
-		if ((i = usb_submit_urb (port->read_urb))) {
-			err ("usb_submit_urb(read bulk 1) failed");
-			dbg ("i=%d", i);
+		port->read_urb->dev = serial->dev;
+		result = usb_submit_urb (port->read_urb);
+		if (result) {
+			err(__FUNCTION__ " - failed submitting read urb, error %d", result);
+			up (&port->sem);
 			pl2303_close (port, NULL);
 			return -EPROTO;
-
 		}
 
-		if ((i = usb_submit_urb (port->interrupt_in_urb))) {
-			err ("usb_submit_urb(interrupt ink) failed");
-			dbg ("i=%d", i);
+		port->interrupt_in_urb->dev = serial->dev;
+		result = usb_submit_urb (port->interrupt_in_urb);
+		if (result) {
+			err(__FUNCTION__ " - failed submitting interrupt urb, error %d", result);
+			up (&port->sem);
 			pl2303_close (port, NULL);
-
 			return -EPROTO;
 		}
 	}
+	up (&port->sem);
+	return 0;
+}
 
-	return(0);
-}				/* pl2303_open */
 
+static void pl2303_close (struct usb_serial_port *port, struct file *filp)
+{
+	unsigned int c_cflag;
 
-static void
-pl2303_close (struct usb_serial_port *port, struct file *filp)
-{				/* pl2303_close */
-	struct pl2303_private *info;
-	unsigned int c_cflag = port->tty->termios->c_cflag;
-	unsigned long flags;
+	if (port_paranoia_check (port, __FUNCTION__))
+		return;
 
-	dbg ("pl2303_close port %d", port->number);
+	dbg (__FUNCTION__ " - port %d", port->number);
 
-	/* shutdown our bulk reads and writes */
-	if (port->active == 1) {
+	down (&port->sem);
 
+	--port->open_count;
+	if (port->open_count <= 0) {
+		c_cflag = port->tty->termios->c_cflag;
 		if (c_cflag & HUPCL) {
 			//FIXME: Do drop DTR
 			//FIXME: Do drop RTS
 		}
 
+		/* shutdown our urbs */
 		usb_unlink_urb (port->write_urb);
 		usb_unlink_urb (port->read_urb);
 		usb_unlink_urb (port->interrupt_in_urb);
 
-		info = (struct pl2303_private *)port->private;
-		if (info) {
-			PL2303_LOCK(port,flags);
-			if (info->xmit_buf) {
-				unsigned char * temp;
-				temp = info->xmit_buf;
-				info->xmit_buf = 0;
-				free_page((unsigned long) temp);
-			}
-			PL2303_UNLOCK(port,flags);
-		}
-
-		//FIXME: tmp_buf memory leak
-
-
+		port->active = 0;
+		port->open_count = 0;
 	}
-	port->active--;
-}				/* pl2303_close */
 
-
-/* do some startup allocations not currently performed by usb_serial_probe() */
-static int
-pl2303_startup (struct usb_serial *serial)
-{
-	return(0);
+	up (&port->sem);
 }
 
 
@@ -664,166 +454,105 @@
 		return;
 	}
 
-
+	usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
 #if 0
 //FIXME need to update state of terminal lines variable
-	if (urb->actual_length) {
-		printk (KERN_DEBUG __FILE__ ": INT data read - length = %d, data = ",
-			urb->actual_length);
-		for (i = 0; i < urb->actual_length; ++i) {
-			printk ("%.2x ", data[i]);
-		}
-		printk ("\n");
-	}
 #endif
 
 	return;
 }
 
-static void
-pl2303_read_bulk_callback (struct urb *urb)
+
+static void pl2303_read_bulk_callback (struct urb *urb)
 {
 	struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
-	struct usb_serial *serial = get_usb_serial (port, "pl2303_read_bulk_callback");
+	struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
 	struct tty_struct *tty;
 	unsigned char *data = urb->transfer_buffer;
 	int i;
+	int result;
+
+	if (port_paranoia_check (port, __FUNCTION__))
+		return;
+
+	dbg(__FUNCTION__ " - port %d", port->number);
 
 	if (!serial) {
+		dbg(__FUNCTION__ " - bad serial pointer, exiting");
 		return;
 	}
 
-// PL2303 mysteriously fails with -EPROTO reschedule the read
+	/* PL2303 mysteriously fails with -EPROTO reschedule the read */
 	if (urb->status) {
 		urb->status = 0;
-		if (usb_submit_urb (urb))
-			dbg ("failed resubmitting read bulk urb");
+		urb->dev = serial->dev;
+		result = usb_submit_urb(urb);
+		if (result)
+			err(__FUNCTION__ " - failed resubmitting read urb, error %d", result);
 		return;
 	}
 
-	if (debug) {
-		if (urb->actual_length) {
-			printk (KERN_DEBUG __FILE__ ": BULK data read - length = %d, data = ",
-				urb->actual_length);
-			for (i = 0; i < urb->actual_length; ++i) {
-				printk ("%.2x ", data[i]);
-			}
-			printk ("\n");
-		}
-	}
+	usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
 
 	tty = port->tty;
 	if (urb->actual_length) {
 		for (i = 0; i < urb->actual_length; ++i) {
 			if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-				dbg ("ARGH ------------ Flip buffer overrun...");
-
-				break;
+				tty_flip_buffer_push(tty);
 			}
 			tty_insert_flip_char (tty, data[i], 0);
 		}
 		tty_flip_buffer_push (tty);
 	}
 
-
 	/* Schedule the next read*/
-	if (usb_submit_urb (urb))
-		dbg ("failed submitting read bulk urb");
+	urb->dev = serial->dev;
+	result = usb_submit_urb(urb);
+	if (result)
+		err(__FUNCTION__ " - failed resubmitting read urb, error %d", result);
 
 	return;
 }
 
 
 
-static void
-pl2303_write_bulk_callback (struct urb *urb)
+static void pl2303_write_bulk_callback (struct urb *urb)
 {
 	struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
-	struct usb_serial *serial;
-	struct tty_struct *tty = port->tty;
-
-	dbg ("pl2303_write_bulk_callback");
-
-
-	if (port_paranoia_check (port, "pl2303_write_bulk_callback")) {
-		return;
-	}
+	int result;
 
-	serial = port->serial;
-	if (serial_paranoia_check (serial, "pl2303_write_bulk_callback")) {
+	if (port_paranoia_check (port, __FUNCTION__))
 		return;
-	}
-
-
+	
+	dbg(__FUNCTION__ " - port %d", port->number);
+	
 	if (urb->status) {
-		dbg ("Overflow in write");
-		dbg ("nonzero write bulk status received: %d", urb->status);
-		//need to resubmit frame;
-
+		/* error in the urb, so we have to resubmit it */
+		if (serial_paranoia_check (port->serial, __FUNCTION__)) {
+			return;
+		}
+		dbg (__FUNCTION__ " - Overflow in write");
+		dbg (__FUNCTION__ " - nonzero write bulk status received: %d", urb->status);
 		port->write_urb->transfer_buffer_length = 1;
-
-		//Resubmit ourselves
-
-		if (usb_submit_urb (port->write_urb))
-			err ("usb_submit_urb(write bulk) failed");
+		port->write_urb->dev = port->serial->dev;
+		result = usb_submit_urb (port->write_urb);
+		if (result)
+			err(__FUNCTION__ " - failed resubmitting write urb, error %d", result);
 
 		return;
 	}
 
-	wake_up_interruptible (&port->write_wait);
-
-	if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
-		(tty->ldisc.write_wakeup) (tty);
-
-	wake_up_interruptible (&tty->write_wait);
-
-	start_xmit(port);
+	queue_task(&port->tqueue, &tq_immediate);
+	mark_bh(IMMEDIATE_BH);
 
 	return;
 }
 
 
-
-static void
-start_xmit (struct usb_serial_port *port)
-{
-	struct usb_serial *serial;
-	struct pl2303_private *info;
-	unsigned long flags;
-
-	serial = port->serial;
-	info = (struct pl2303_private *)port->private;
-
-	if (info) {
-		PL2303_LOCK(port,flags);
-
-		if (port->write_urb->status != -EINPROGRESS) {
-			if (info->xmit_tail != info->xmit_head) {
-
-				memcpy (port->write_urb->transfer_buffer, &info->xmit_buf[info->xmit_tail],1);
-				info->xmit_cnt--;
-				info->xmit_tail = (info->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
-
-
-				port->write_urb->transfer_buffer_length = 1;
-
-
-				if (usb_submit_urb (port->write_urb))
-					err ("usb_submit_urb(write bulk) failed");
-
-
-			}
-		}
-
-		PL2303_UNLOCK(port,flags);
-	}
-}
-
-
 static int __init pl2303_init (void)
 {
 	usb_serial_register (&pl2303_device);
-	info(DRIVER_VERSION " : " DRIVER_DESC);
+	info(DRIVER_DESC " " DRIVER_VERSION);
 	return 0;
 }
 
@@ -838,6 +567,7 @@
 module_exit(pl2303_exit);
 
 MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
 
 MODULE_PARM(debug, "i");
 MODULE_PARM_DESC(debug, "Debug enabled or not");

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)