# This is a BitKeeper generated patch for the following project: # Project Name: Linux kernel tree # This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas: # ChangeSet 1.555 -> 1.556 # drivers/usb/serial/kl5kusb105.c 1.5 -> 1.6 # drivers/usb/serial/belkin_sa.c 1.18 -> 1.19 # drivers/usb/serial/io_edgeport.c 1.25 -> 1.26 # drivers/usb/serial/keyspan.c 1.23 -> 1.24 # drivers/usb/serial/ftdi_sio.c 1.26 -> 1.27 # drivers/usb/serial/ipaq.c 1.6 -> 1.7 # drivers/usb/serial/visor.c 1.27 -> 1.28 # drivers/usb/serial/omninet.c 1.17 -> 1.18 # drivers/usb/serial/whiteheat.c 1.16 -> 1.17 # drivers/usb/serial/empeg.c 1.22 -> 1.23 # drivers/usb/serial/pl2303.c 1.12 -> 1.13 # drivers/usb/serial/ir-usb.c 1.12 -> 1.13 # drivers/usb/serial/digi_acceleport.c 1.17 -> 1.18 # drivers/usb/serial/keyspan_pda.c 1.14 -> 1.15 # drivers/usb/serial/mct_u232.c 1.21 -> 1.22 # drivers/usb/serial/cyberjack.c 1.12 -> 1.13 # # The following is the BitKeeper ChangeSet Log # -------------------------------------------- # 02/03/21 greg@kroah.com 1.556 # USB serial drivers # # changes due to open_count being handled by the usb-serial core code. # -------------------------------------------- # diff -Nru a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c --- a/drivers/usb/serial/belkin_sa.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/belkin_sa.c Wed Apr 3 16:39:49 2002 @@ -191,9 +191,6 @@ /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - belkin_sa_close (&serial->port[i], NULL); - } /* My special items, the standard routines free my urbs */ if (serial->port[i].private) kfree(serial->port[i].private); @@ -207,26 +204,22 @@ dbg(__FUNCTION__" port %d", port->number); - ++port->open_count; - - if (port->open_count == 1) { - /*Start reading from the device*/ - /* TODO: Look at possibility of submitting mulitple URBs to device to - * enhance buffering. Win trace shows 16 initial read URBs. - */ - port->read_urb->dev = port->serial->dev; - retval = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (retval) { - err("usb_submit_urb(read bulk) failed"); - goto exit; - } - - port->interrupt_in_urb->dev = port->serial->dev; - retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); - if (retval) - err(" usb_submit_urb(read int) failed"); + /*Start reading from the device*/ + /* TODO: Look at possibility of submitting mulitple URBs to device to + * enhance buffering. Win trace shows 16 initial read URBs. + */ + port->read_urb->dev = port->serial->dev; + retval = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (retval) { + err("usb_submit_urb(read bulk) failed"); + goto exit; } - + + port->interrupt_in_urb->dev = port->serial->dev; + retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); + if (retval) + err(" usb_submit_urb(read int) failed"); + exit: return retval; } /* belkin_sa_open */ @@ -245,16 +238,11 @@ dbg(__FUNCTION__" port %d", port->number); - --port->open_count; - - if (port->open_count <= 0) { - if (serial->dev) { - /* shutdown our bulk reads and writes */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - usb_unlink_urb (port->interrupt_in_urb); - } - port->open_count = 0; + if (serial->dev) { + /* shutdown our bulk reads and writes */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); + usb_unlink_urb (port->interrupt_in_urb); } } /* belkin_sa_close */ diff -Nru a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c --- a/drivers/usb/serial/cyberjack.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/cyberjack.c Wed Apr 3 16:39:49 2002 @@ -130,11 +130,7 @@ dbg (__FUNCTION__); - /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - cyberjack_close (&serial->port[i], NULL); - } /* My special items, the standard routines free my urbs */ if (serial->port[i].private) kfree(serial->port[i].private); @@ -151,31 +147,27 @@ dbg(__FUNCTION__ " - port %d", port->number); - ++port->open_count; - - if (port->open_count == 1) { - /* force low_latency on so that our tty_push actually forces - * the data through, otherwise it is scheduled, and with high - * data rates (like with OHCI) data can get lost. - */ - port->tty->low_latency = 1; - - priv = (struct cyberjack_private *)port->private; - priv->rdtodo = 0; - priv->wrfilled = 0; - priv->wrsent = 0; - - /* shutdown any bulk reads that might be going on */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - usb_unlink_urb (port->interrupt_in_urb); - - port->interrupt_in_urb->dev = port->serial->dev; - result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); - if (result) - err(" usb_submit_urb(read int) failed"); - dbg(__FUNCTION__ " - usb_submit_urb(int urb)"); - } + /* force low_latency on so that our tty_push actually forces + * the data through, otherwise it is scheduled, and with high + * data rates (like with OHCI) data can get lost. + */ + port->tty->low_latency = 1; + + priv = (struct cyberjack_private *)port->private; + priv->rdtodo = 0; + priv->wrfilled = 0; + priv->wrsent = 0; + + /* shutdown any bulk reads that might be going on */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); + usb_unlink_urb (port->interrupt_in_urb); + + port->interrupt_in_urb->dev = port->serial->dev; + result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); + if (result) + err(" usb_submit_urb(read int) failed"); + dbg(__FUNCTION__ " - usb_submit_urb(int urb)"); return result; } @@ -184,16 +176,11 @@ { dbg(__FUNCTION__ " - port %d", port->number); - --port->open_count; - - if (port->open_count <= 0) { - if (port->serial->dev) { - /* shutdown any bulk reads that might be going on */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - usb_unlink_urb (port->interrupt_in_urb); - } - port->open_count = 0; + if (port->serial->dev) { + /* shutdown any bulk reads that might be going on */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); + usb_unlink_urb (port->interrupt_in_urb); } } diff -Nru a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c --- a/drivers/usb/serial/digi_acceleport.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/digi_acceleport.c Wed Apr 3 16:39:49 2002 @@ -1490,28 +1490,17 @@ return( -EAGAIN ); } - /* inc module use count before sleeping to wait for closes */ - ++port->open_count; - /* wait for a close in progress to finish */ while( priv->dp_in_close ) { cond_wait_interruptible_timeout_irqrestore( &priv->dp_close_wait, DIGI_RETRY_TIMEOUT, &priv->dp_port_lock, flags ); if( signal_pending(current) ) { - --port->open_count; return( -EINTR ); } spin_lock_irqsave( &priv->dp_port_lock, flags ); } - /* if port is already open, just return */ - /* be sure exactly one open proceeds */ - if( port->open_count != 1) { - spin_unlock_irqrestore( &priv->dp_port_lock, flags ); - return( 0 ); - } - spin_unlock_irqrestore( &priv->dp_port_lock, flags ); /* read modem signals automatically whenever they change */ @@ -1557,14 +1546,6 @@ /* do cleanup only after final close on this port */ spin_lock_irqsave( &priv->dp_port_lock, flags ); - if( port->open_count > 1 ) { - --port->open_count; - spin_unlock_irqrestore( &priv->dp_port_lock, flags ); - return; - } else if( port->open_count <= 0 ) { - spin_unlock_irqrestore( &priv->dp_port_lock, flags ); - return; - } priv->dp_in_close = 1; spin_unlock_irqrestore( &priv->dp_port_lock, flags ); @@ -1637,7 +1618,6 @@ spin_lock_irqsave( &priv->dp_port_lock, flags ); priv->dp_write_urb_in_use = 0; priv->dp_in_close = 0; - --port->open_count; wake_up_interruptible( &priv->dp_close_wait ); spin_unlock_irqrestore( &priv->dp_port_lock, flags ); @@ -1765,8 +1745,6 @@ { int i; - struct digi_port *priv; - unsigned long flags; dbg( "digi_shutdown: TOP, in_interrupt()=%d", in_interrupt() ); @@ -1775,16 +1753,6 @@ for( i=0; itype->num_ports+1; i++ ) { usb_unlink_urb( serial->port[i].read_urb ); usb_unlink_urb( serial->port[i].write_urb ); - } - - /* dec module use count */ - for( i=0; itype->num_ports; i++ ) { - priv = serial->port[i].private; - spin_lock_irqsave( &priv->dp_port_lock, flags ); - while( serial->port[i].open_count > 0 ) { - --serial->port[i].open_count; - } - spin_unlock_irqrestore( &priv->dp_port_lock, flags ); } /* free the private data structures for all ports */ diff -Nru a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c --- a/drivers/usb/serial/empeg.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/empeg.c Wed Apr 3 16:39:49 2002 @@ -157,35 +157,29 @@ dbg(__FUNCTION__ " - port %d", port->number); - ++port->open_count; + /* Force default termio settings */ + empeg_set_termios (port, NULL) ; - if (port->open_count == 1) { + bytes_in = 0; + bytes_out = 0; - /* Force default termio settings */ - empeg_set_termios (port, NULL) ; - - bytes_in = 0; - bytes_out = 0; - - /* Start reading from the device */ - FILL_BULK_URB( - port->read_urb, - serial->dev, - usb_rcvbulkpipe(serial->dev, - port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, - port->read_urb->transfer_buffer_length, - empeg_read_bulk_callback, - port); - - port->read_urb->transfer_flags |= USB_QUEUE_BULK; + /* Start reading from the device */ + FILL_BULK_URB( + port->read_urb, + serial->dev, + usb_rcvbulkpipe(serial->dev, + port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, + port->read_urb->transfer_buffer_length, + empeg_read_bulk_callback, + port); - result = usb_submit_urb(port->read_urb, GFP_KERNEL); + port->read_urb->transfer_flags |= USB_QUEUE_BULK; - if (result) - err(__FUNCTION__ " - failed submitting read urb, error %d", result); + result = usb_submit_urb(port->read_urb, GFP_KERNEL); - } + if (result) + err(__FUNCTION__ " - failed submitting read urb, error %d", result); return result; } @@ -204,16 +198,10 @@ if (!serial) return; - --port->open_count; - - if (port->open_count <= 0) { - if (serial->dev) { - /* shutdown our bulk read */ - usb_unlink_urb (port->read_urb); - } - port->open_count = 0; + if (serial->dev) { + /* shutdown our bulk read */ + usb_unlink_urb (port->read_urb); } - /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ } @@ -491,17 +479,7 @@ static void empeg_shutdown (struct usb_serial *serial) { - int i; - dbg (__FUNCTION__); - - /* stop reads and writes on all ports */ - for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - empeg_close (&serial->port[i], NULL); - } - } - } diff -Nru a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c --- a/drivers/usb/serial/ftdi_sio.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/ftdi_sio.c Wed Apr 3 16:39:49 2002 @@ -294,14 +294,8 @@ static void ftdi_sio_shutdown (struct usb_serial *serial) { - dbg (__FUNCTION__); - - /* stop reads and writes on all ports */ - while (serial->port[0].open_count > 0) { - ftdi_sio_close (&serial->port[0], NULL); - } if (serial->port[0].private){ kfree(serial->port[0].private); serial->port[0].private = NULL; @@ -319,45 +313,41 @@ dbg(__FUNCTION__); - ++port->open_count; - - if (port->open_count == 1){ - /* This will push the characters through immediately rather - than queue a task to deliver them */ - port->tty->low_latency = 1; - - /* No error checking for this (will get errors later anyway) */ - /* See ftdi_sio.h for description of what is reset */ - usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, - FTDI_SIO_RESET_SIO, - 0, buf, 0, WDR_TIMEOUT); - - /* Setup termios defaults. According to tty_io.c the - settings are driver specific */ - port->tty->termios->c_cflag = - B9600 | CS8 | CREAD | HUPCL | CLOCAL; - - /* ftdi_sio_set_termios will send usb control messages */ - ftdi_sio_set_termios(port, &tmp_termios); - - /* Turn on RTS and DTR since we are not flow controlling by default */ - if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),HIGH) < 0) { - err(__FUNCTION__ " Error from DTR HIGH urb"); - } - if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),HIGH) < 0){ - err(__FUNCTION__ " Error from RTS HIGH urb"); - } - - /* Start reading from the device */ - FILL_BULK_URB(port->read_urb, serial->dev, - usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, - ftdi_sio_read_bulk_callback, port); - result = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (result) - err(__FUNCTION__ " - failed submitting read urb, error %d", result); + /* This will push the characters through immediately rather + than queue a task to deliver them */ + port->tty->low_latency = 1; + + /* No error checking for this (will get errors later anyway) */ + /* See ftdi_sio.h for description of what is reset */ + usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), + FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, + FTDI_SIO_RESET_SIO, + 0, buf, 0, WDR_TIMEOUT); + + /* Setup termios defaults. According to tty_io.c the + settings are driver specific */ + port->tty->termios->c_cflag = + B9600 | CS8 | CREAD | HUPCL | CLOCAL; + + /* ftdi_sio_set_termios will send usb control messages */ + ftdi_sio_set_termios(port, &tmp_termios); + + /* Turn on RTS and DTR since we are not flow controlling by default */ + if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0),HIGH) < 0) { + err(__FUNCTION__ " Error from DTR HIGH urb"); } + if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),HIGH) < 0){ + err(__FUNCTION__ " Error from RTS HIGH urb"); + } + + /* Start reading from the device */ + FILL_BULK_URB(port->read_urb, serial->dev, + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, + ftdi_sio_read_bulk_callback, port); + result = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (result) + err(__FUNCTION__ " - failed submitting read urb, error %d", result); return result; } /* ftdi_sio_open */ @@ -371,41 +361,31 @@ dbg( __FUNCTION__); - --port->open_count; - - if (port->open_count <= 0) { - if (serial->dev) { - if (c_cflag & HUPCL){ - /* Disable flow control */ - if (usb_control_msg(serial->dev, - usb_sndctrlpipe(serial->dev, 0), - FTDI_SIO_SET_FLOW_CTRL_REQUEST, - FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, - 0, 0, buf, 0, WDR_TIMEOUT) < 0) { - err("error from flowcontrol urb"); - } - - /* drop DTR */ - if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0), LOW) < 0){ - err("Error from DTR LOW urb"); - } - /* drop RTS */ - if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0) { - err("Error from RTS LOW urb"); - } - } /* Note change no line is hupcl is off */ - - /* shutdown our bulk reads and writes */ - /* ***CHECK*** behaviour when there is nothing queued */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - } - port->open_count = 0; - } else { - /* Send a HUP if necessary */ - if (!(port->tty->termios->c_cflag & CLOCAL)){ - tty_hangup(port->tty); - } + if (serial->dev) { + if (c_cflag & HUPCL){ + /* Disable flow control */ + if (usb_control_msg(serial->dev, + usb_sndctrlpipe(serial->dev, 0), + FTDI_SIO_SET_FLOW_CTRL_REQUEST, + FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, + 0, 0, buf, 0, WDR_TIMEOUT) < 0) { + err("error from flowcontrol urb"); + } + + /* drop DTR */ + if (set_dtr(serial->dev, usb_sndctrlpipe(serial->dev, 0), LOW) < 0){ + err("Error from DTR LOW urb"); + } + /* drop RTS */ + if (set_rts(serial->dev, usb_sndctrlpipe(serial->dev, 0),LOW) < 0) { + err("Error from RTS LOW urb"); + } + } /* Note change no line is hupcl is off */ + + /* shutdown our bulk reads and writes */ + /* ***CHECK*** behaviour when there is nothing queued */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); } } /* ftdi_sio_close */ diff -Nru a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c --- a/drivers/usb/serial/io_edgeport.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/io_edgeport.c Wed Apr 3 16:39:49 2002 @@ -987,124 +987,117 @@ if (edge_port == NULL) return -ENODEV; - ++port->open_count; - - if (port->open_count == 1) { - /* force low_latency on so that our tty_push actually forces the data through, - otherwise it is scheduled, and with high data rates (like with OHCI) data - can get lost. */ - port->tty->low_latency = 1; + /* force low_latency on so that our tty_push actually forces the data through, + otherwise it is scheduled, and with high data rates (like with OHCI) data + can get lost. */ + port->tty->low_latency = 1; + + /* see if we've set up our endpoint info yet (can't set it up in edge_startup + as the structures were not set up at that time.) */ + serial = port->serial; + edge_serial = (struct edgeport_serial *)serial->private; + if (edge_serial == NULL) { + return -ENODEV; + } + if (edge_serial->interrupt_in_buffer == NULL) { + struct usb_serial_port *port0 = &serial->port[0]; + + /* not set up yet, so do it now */ + edge_serial->interrupt_in_buffer = port0->interrupt_in_buffer; + edge_serial->interrupt_in_endpoint = port0->interrupt_in_endpointAddress; + edge_serial->interrupt_read_urb = port0->interrupt_in_urb; + edge_serial->bulk_in_buffer = port0->bulk_in_buffer; + edge_serial->bulk_in_endpoint = port0->bulk_in_endpointAddress; + edge_serial->read_urb = port0->read_urb; + edge_serial->bulk_out_endpoint = port0->bulk_out_endpointAddress; - /* see if we've set up our endpoint info yet (can't set it up in edge_startup - as the structures were not set up at that time.) */ - serial = port->serial; - edge_serial = (struct edgeport_serial *)serial->private; - if (edge_serial == NULL) { - port->open_count = 0; - return -ENODEV; - } - if (edge_serial->interrupt_in_buffer == NULL) { - struct usb_serial_port *port0 = &serial->port[0]; - - /* not set up yet, so do it now */ - edge_serial->interrupt_in_buffer = port0->interrupt_in_buffer; - edge_serial->interrupt_in_endpoint = port0->interrupt_in_endpointAddress; - edge_serial->interrupt_read_urb = port0->interrupt_in_urb; - edge_serial->bulk_in_buffer = port0->bulk_in_buffer; - edge_serial->bulk_in_endpoint = port0->bulk_in_endpointAddress; - edge_serial->read_urb = port0->read_urb; - edge_serial->bulk_out_endpoint = port0->bulk_out_endpointAddress; + /* set up our interrupt urb */ + FILL_INT_URB(edge_serial->interrupt_read_urb, + serial->dev, + usb_rcvintpipe(serial->dev, + port0->interrupt_in_endpointAddress), + port0->interrupt_in_buffer, + edge_serial->interrupt_read_urb->transfer_buffer_length, + edge_interrupt_callback, edge_serial, + edge_serial->interrupt_read_urb->interval); - /* set up our interrupt urb */ - FILL_INT_URB(edge_serial->interrupt_read_urb, - serial->dev, - usb_rcvintpipe(serial->dev, - port0->interrupt_in_endpointAddress), - port0->interrupt_in_buffer, - edge_serial->interrupt_read_urb->transfer_buffer_length, - edge_interrupt_callback, edge_serial, - edge_serial->interrupt_read_urb->interval); - - /* set up our bulk in urb */ - FILL_BULK_URB(edge_serial->read_urb, serial->dev, - usb_rcvbulkpipe(serial->dev, port0->bulk_in_endpointAddress), - port0->bulk_in_buffer, - edge_serial->read_urb->transfer_buffer_length, - edge_bulk_in_callback, edge_serial); - - /* start interrupt read for this edgeport - * this interrupt will continue as long as the edgeport is connected */ - response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL); - if (response) { - err(__FUNCTION__" - Error %d submitting control urb", response); - } + /* set up our bulk in urb */ + FILL_BULK_URB(edge_serial->read_urb, serial->dev, + usb_rcvbulkpipe(serial->dev, port0->bulk_in_endpointAddress), + port0->bulk_in_buffer, + edge_serial->read_urb->transfer_buffer_length, + edge_bulk_in_callback, edge_serial); + + /* start interrupt read for this edgeport + * this interrupt will continue as long as the edgeport is connected */ + response = usb_submit_urb (edge_serial->interrupt_read_urb, GFP_KERNEL); + if (response) { + err(__FUNCTION__" - Error %d submitting control urb", response); } - - /* initialize our wait queues */ - init_waitqueue_head(&edge_port->wait_open); - init_waitqueue_head(&edge_port->wait_chase); - init_waitqueue_head(&edge_port->delta_msr_wait); - init_waitqueue_head(&edge_port->wait_command); - - /* initialize our icount structure */ - memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); - - /* initialize our port settings */ - edge_port->txCredits = 0; /* Can't send any data yet */ - edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ - edge_port->chaseResponsePending = FALSE; + } + + /* initialize our wait queues */ + init_waitqueue_head(&edge_port->wait_open); + init_waitqueue_head(&edge_port->wait_chase); + init_waitqueue_head(&edge_port->delta_msr_wait); + init_waitqueue_head(&edge_port->wait_command); + + /* initialize our icount structure */ + memset (&(edge_port->icount), 0x00, sizeof(edge_port->icount)); + + /* initialize our port settings */ + edge_port->txCredits = 0; /* Can't send any data yet */ + edge_port->shadowMCR = MCR_MASTER_IE; /* Must always set this bit to enable ints! */ + edge_port->chaseResponsePending = FALSE; + + /* send a open port command */ + edge_port->openPending = TRUE; + edge_port->open = FALSE; + response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); - /* send a open port command */ - edge_port->openPending = TRUE; - edge_port->open = FALSE; - response = send_iosp_ext_cmd (edge_port, IOSP_CMD_OPEN_PORT, 0); + if (response < 0) { + err(__FUNCTION__" - error sending open port command"); + edge_port->openPending = FALSE; + return -ENODEV; + } - if (response < 0) { - err(__FUNCTION__" - error sending open port command"); - edge_port->openPending = FALSE; - port->open_count = 0; - return -ENODEV; - } - - /* now wait for the port to be completly opened */ - timeout = OPEN_TIMEOUT; - while (timeout && edge_port->openPending == TRUE) { - timeout = interruptible_sleep_on_timeout (&edge_port->wait_open, timeout); - } - - if (edge_port->open == FALSE) { - /* open timed out */ - dbg(__FUNCTION__" - open timedout"); - edge_port->openPending = FALSE; - port->open_count = 0; - return -ENODEV; - } - - /* create the txfifo */ - edge_port->txfifo.head = 0; - edge_port->txfifo.tail = 0; - edge_port->txfifo.count = 0; - edge_port->txfifo.size = edge_port->maxTxCredits; - edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL); - - if (!edge_port->txfifo.fifo) { - dbg(__FUNCTION__" - no memory"); - edge_close (port, filp); - return -ENOMEM; - } + /* now wait for the port to be completly opened */ + timeout = OPEN_TIMEOUT; + while (timeout && edge_port->openPending == TRUE) { + timeout = interruptible_sleep_on_timeout (&edge_port->wait_open, timeout); + } - /* Allocate a URB for the write */ - edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); + if (edge_port->open == FALSE) { + /* open timed out */ + dbg(__FUNCTION__" - open timedout"); + edge_port->openPending = FALSE; + return -ENODEV; + } - if (!edge_port->write_urb) { - dbg(__FUNCTION__" - no memory"); - edge_close (port, filp); - return -ENOMEM; - } + /* create the txfifo */ + edge_port->txfifo.head = 0; + edge_port->txfifo.tail = 0; + edge_port->txfifo.count = 0; + edge_port->txfifo.size = edge_port->maxTxCredits; + edge_port->txfifo.fifo = kmalloc (edge_port->maxTxCredits, GFP_KERNEL); + + if (!edge_port->txfifo.fifo) { + dbg(__FUNCTION__" - no memory"); + edge_close (port, filp); + return -ENOMEM; + } + + /* Allocate a URB for the write */ + edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL); - dbg(__FUNCTION__"(%d) - Initialize TX fifo to %d bytes", port->number, edge_port->maxTxCredits); + if (!edge_port->write_urb) { + dbg(__FUNCTION__" - no memory"); + edge_close (port, filp); + return -ENOMEM; } + dbg(__FUNCTION__"(%d) - Initialize TX fifo to %d bytes", port->number, edge_port->maxTxCredits); + dbg(__FUNCTION__" exited"); return 0; @@ -1234,52 +1227,47 @@ if ((edge_serial == NULL) || (edge_port == NULL)) return; - --port->open_count; + if (serial->dev) { + // block until tx is empty + block_until_tx_empty(edge_port); + + edge_port->closePending = TRUE; + + /* flush and chase */ + edge_port->chaseResponsePending = TRUE; + + dbg(__FUNCTION__" - Sending IOSP_CMD_CHASE_PORT"); + status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); + if (status == 0) { + // block until chase finished + block_until_chase_response(edge_port); + } else { + edge_port->chaseResponsePending = FALSE; + } - if (port->open_count <= 0) { - if (serial->dev) { - // block until tx is empty - block_until_tx_empty(edge_port); - - edge_port->closePending = TRUE; - - /* flush and chase */ - edge_port->chaseResponsePending = TRUE; - - dbg(__FUNCTION__" - Sending IOSP_CMD_CHASE_PORT"); - status = send_iosp_ext_cmd (edge_port, IOSP_CMD_CHASE_PORT, 0); - if (status == 0) { - // block until chase finished - block_until_chase_response(edge_port); - } else { - edge_port->chaseResponsePending = FALSE; - } + /* close the port */ + dbg(__FUNCTION__" - Sending IOSP_CMD_CLOSE_PORT"); + send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); - /* close the port */ - dbg(__FUNCTION__" - Sending IOSP_CMD_CLOSE_PORT"); - send_iosp_ext_cmd (edge_port, IOSP_CMD_CLOSE_PORT, 0); - - //port->close = TRUE; - edge_port->closePending = FALSE; - edge_port->open = FALSE; - edge_port->openPending = FALSE; + //port->close = TRUE; + edge_port->closePending = FALSE; + edge_port->open = FALSE; + edge_port->openPending = FALSE; - if (edge_port->write_urb) { - usb_unlink_urb (edge_port->write_urb); - } - } - if (edge_port->write_urb) { - /* if this urb had a transfer buffer already (old transfer) free it */ - if (edge_port->write_urb->transfer_buffer != NULL) { - kfree(edge_port->write_urb->transfer_buffer); - } - usb_free_urb (edge_port->write_urb); + usb_unlink_urb (edge_port->write_urb); } - if (edge_port->txfifo.fifo) { - kfree(edge_port->txfifo.fifo); + } + + if (edge_port->write_urb) { + /* if this urb had a transfer buffer already (old transfer) free it */ + if (edge_port->write_urb->transfer_buffer != NULL) { + kfree(edge_port->write_urb->transfer_buffer); } - port->open_count = 0; + usb_free_urb (edge_port->write_urb); + } + if (edge_port->txfifo.fifo) { + kfree(edge_port->txfifo.fifo); } dbg(__FUNCTION__" exited"); @@ -3027,9 +3015,6 @@ /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - edge_close (&serial->port[i], NULL); - } kfree (serial->port[i].private); serial->port[i].private = NULL; } diff -Nru a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c --- a/drivers/usb/serial/ipaq.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/ipaq.c Wed Apr 3 16:39:49 2002 @@ -123,93 +123,89 @@ dbg(__FUNCTION__ " - port %d", port->number); - ++port->open_count; - - if (port->open_count == 1) { - bytes_in = 0; - bytes_out = 0; - priv = (struct ipaq_private *)kmalloc(sizeof(struct ipaq_private), GFP_KERNEL); - if (priv == NULL) { - err(__FUNCTION__ " - Out of memory"); - return -ENOMEM; - } - port->private = (void *)priv; - priv->active = 0; - priv->queue_len = 0; - INIT_LIST_HEAD(&priv->queue); - INIT_LIST_HEAD(&priv->freelist); - - for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) { - pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL); - if (pkt == NULL) { - goto enomem; - } - pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL); - if (pkt->data == NULL) { - kfree(pkt); - goto enomem; - } - pkt->len = 0; - pkt->written = 0; - INIT_LIST_HEAD(&pkt->list); - list_add(&pkt->list, &priv->freelist); - priv->free_len += PACKET_SIZE; - } - - /* - * Force low latency on. This will immediately push data to the line - * discipline instead of queueing. - */ - - port->tty->low_latency = 1; - port->tty->raw = 1; - port->tty->real_raw = 1; - - /* - * Lose the small buffers usbserial provides. Make larger ones. - */ - - kfree(port->bulk_in_buffer); - kfree(port->bulk_out_buffer); - port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); - if (port->bulk_in_buffer == NULL) { + bytes_in = 0; + bytes_out = 0; + priv = (struct ipaq_private *)kmalloc(sizeof(struct ipaq_private), GFP_KERNEL); + if (priv == NULL) { + err(__FUNCTION__ " - Out of memory"); + return -ENOMEM; + } + port->private = (void *)priv; + priv->active = 0; + priv->queue_len = 0; + INIT_LIST_HEAD(&priv->queue); + INIT_LIST_HEAD(&priv->freelist); + + for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) { + pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL); + if (pkt == NULL) { goto enomem; } - port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); - if (port->bulk_out_buffer == NULL) { - kfree(port->bulk_in_buffer); + pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL); + if (pkt->data == NULL) { + kfree(pkt); goto enomem; } - port->read_urb->transfer_buffer = port->bulk_in_buffer; - port->write_urb->transfer_buffer = port->bulk_out_buffer; - port->read_urb->transfer_buffer_length = URBDATA_SIZE; - port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; - - /* Start reading from the device */ - FILL_BULK_URB(port->read_urb, serial->dev, - usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, - ipaq_read_bulk_callback, port); - result = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (result) { - err(__FUNCTION__ " - failed submitting read urb, error %d", result); - } - - /* - * Send out two control messages observed in win98 sniffs. Not sure what - * they do. - */ - - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, - 0x1, 0, NULL, 0, 5 * HZ); - if (result < 0) { - err(__FUNCTION__ " - failed doing control urb, error %d", result); - } - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, - 0x1, 0, NULL, 0, 5 * HZ); - if (result < 0) { - err(__FUNCTION__ " - failed doing control urb, error %d", result); - } + pkt->len = 0; + pkt->written = 0; + INIT_LIST_HEAD(&pkt->list); + list_add(&pkt->list, &priv->freelist); + priv->free_len += PACKET_SIZE; + } + + /* + * Force low latency on. This will immediately push data to the line + * discipline instead of queueing. + */ + + port->tty->low_latency = 1; + port->tty->raw = 1; + port->tty->real_raw = 1; + + /* + * Lose the small buffers usbserial provides. Make larger ones. + */ + + kfree(port->bulk_in_buffer); + kfree(port->bulk_out_buffer); + port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); + if (port->bulk_in_buffer == NULL) { + goto enomem; + } + port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); + if (port->bulk_out_buffer == NULL) { + kfree(port->bulk_in_buffer); + goto enomem; + } + port->read_urb->transfer_buffer = port->bulk_in_buffer; + port->write_urb->transfer_buffer = port->bulk_out_buffer; + port->read_urb->transfer_buffer_length = URBDATA_SIZE; + port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; + + /* Start reading from the device */ + FILL_BULK_URB(port->read_urb, serial->dev, + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, + ipaq_read_bulk_callback, port); + result = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (result) { + err(__FUNCTION__ " - failed submitting read urb, error %d", result); + } + + /* + * Send out two control messages observed in win98 sniffs. Not sure what + * they do. + */ + + result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, + 0x1, 0, NULL, 0, 5 * HZ); + if (result < 0) { + err(__FUNCTION__ " - failed doing control urb, error %d", result); + } + result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, + 0x1, 0, NULL, 0, 5 * HZ); + if (result < 0) { + err(__FUNCTION__ " - failed doing control urb, error %d", result); } return result; @@ -237,22 +233,16 @@ if (!serial) return; - --port->open_count; + /* + * shut down bulk read and write + */ - if (port->open_count <= 0) { - - /* - * shut down bulk read and write - */ - - usb_unlink_urb(port->write_urb); - usb_unlink_urb(port->read_urb); - ipaq_destroy_lists(port); - kfree(priv); - port->private = NULL; - port->open_count = 0; + usb_unlink_urb(port->write_urb); + usb_unlink_urb(port->read_urb); + ipaq_destroy_lists(port); + kfree(priv); + port->private = NULL; - } /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ } @@ -507,16 +497,7 @@ static void ipaq_shutdown(struct usb_serial *serial) { - int i; - dbg (__FUNCTION__); - - /* stop reads and writes on all ports */ - for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - ipaq_close(&serial->port[i], NULL); - } - } } static int __init ipaq_init(void) diff -Nru a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c --- a/drivers/usb/serial/ir-usb.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/ir-usb.c Wed Apr 3 16:39:49 2002 @@ -283,45 +283,42 @@ dbg("%s - port %d", __FUNCTION__, port->number); - ++port->open_count; - - if (port->open_count == 1) { - if (buffer_size) { - /* override the default buffer sizes */ - buffer = kmalloc (buffer_size, GFP_KERNEL); - if (!buffer) { - err ("%s - out of memory.", __FUNCTION__); - return -ENOMEM; - } - kfree (port->read_urb->transfer_buffer); - port->read_urb->transfer_buffer = buffer; - port->read_urb->transfer_buffer_length = buffer_size; - - buffer = kmalloc (buffer_size, GFP_KERNEL); - if (!buffer) { - err ("%s - out of memory.", __FUNCTION__); - return -ENOMEM; - } - kfree (port->write_urb->transfer_buffer); - port->write_urb->transfer_buffer = buffer; - port->write_urb->transfer_buffer_length = buffer_size; - port->bulk_out_size = buffer_size; + if (buffer_size) { + /* override the default buffer sizes */ + buffer = kmalloc (buffer_size, GFP_KERNEL); + if (!buffer) { + err ("%s - out of memory.", __FUNCTION__); + return -ENOMEM; } - - /* Start reading from the device */ - usb_fill_bulk_urb ( - port->read_urb, - serial->dev, - usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, - port->read_urb->transfer_buffer_length, - ir_read_bulk_callback, - port); - port->read_urb->transfer_flags = USB_QUEUE_BULK; - result = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (result) - err("%s - failed submitting read urb, error %d", __FUNCTION__, result); + kfree (port->read_urb->transfer_buffer); + port->read_urb->transfer_buffer = buffer; + port->read_urb->transfer_buffer_length = buffer_size; + + buffer = kmalloc (buffer_size, GFP_KERNEL); + if (!buffer) { + err ("%s - out of memory.", __FUNCTION__); + return -ENOMEM; + } + kfree (port->write_urb->transfer_buffer); + port->write_urb->transfer_buffer = buffer; + port->write_urb->transfer_buffer_length = buffer_size; + port->bulk_out_size = buffer_size; } + + /* Start reading from the device */ + usb_fill_bulk_urb ( + port->read_urb, + serial->dev, + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, + port->read_urb->transfer_buffer_length, + ir_read_bulk_callback, + port); + port->read_urb->transfer_flags = USB_QUEUE_BULK; + result = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (result) + err("%s - failed submitting read urb, error %d", __FUNCTION__, result); + return result; } @@ -338,15 +335,9 @@ if (!serial) return; - --port->open_count; - - if (port->open_count <= 0) { - if (serial->dev) { - /* shutdown our bulk read */ - usb_unlink_urb (port->read_urb); - } - port->open_count = 0; - + if (serial->dev) { + /* shutdown our bulk read */ + usb_unlink_urb (port->read_urb); } } diff -Nru a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c --- a/drivers/usb/serial/keyspan.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/keyspan.c Wed Apr 3 16:39:49 2002 @@ -852,7 +852,7 @@ struct keyspan_serial_private *s_priv; struct usb_serial *serial = port->serial; const struct keyspan_device_details *d_details; - int i, already_active, err; + int i, err; struct urb *urb; s_priv = (struct keyspan_serial_private *)(serial->private); @@ -861,12 +861,6 @@ dbg("keyspan_open called for port%d.\n", port->number); - already_active = port->open_count; - ++port->open_count; - - if (already_active) - return 0; - p_priv = (struct keyspan_port_private *)(port->private); /* Set some sane defaults */ @@ -924,19 +918,16 @@ p_priv->out_flip = 0; p_priv->in_flip = 0; - if (--port->open_count <= 0) { - if (serial->dev) { - /* Stop reading/writing urbs */ - stop_urb(p_priv->inack_urb); - stop_urb(p_priv->outcont_urb); - for (i = 0; i < 2; i++) { - stop_urb(p_priv->in_urbs[i]); - stop_urb(p_priv->out_urbs[i]); - } + if (serial->dev) { + /* Stop reading/writing urbs */ + stop_urb(p_priv->inack_urb); + stop_urb(p_priv->outcont_urb); + for (i = 0; i < 2; i++) { + stop_urb(p_priv->in_urbs[i]); + stop_urb(p_priv->out_urbs[i]); } - port->open_count = 0; - port->tty = 0; } + port->tty = 0; } @@ -1762,9 +1753,6 @@ /* Now free per port private data */ for (i = 0; i < serial->num_ports; i++) { port = &serial->port[i]; - while (port->open_count > 0) { - --port->open_count; - } kfree(port->private); } } diff -Nru a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c --- a/drivers/usb/serial/keyspan_pda.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/keyspan_pda.c Wed Apr 3 16:39:49 2002 @@ -662,52 +662,45 @@ int rc = 0; struct keyspan_pda_private *priv; - ++port->open_count; - - if (port->open_count == 1) { - /* find out how much room is in the Tx ring */ - rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - 6, /* write_room */ - USB_TYPE_VENDOR | USB_RECIP_INTERFACE - | USB_DIR_IN, - 0, /* value */ - 0, /* index */ - &room, - 1, - 2*HZ); - if (rc < 0) { - dbg(__FUNCTION__" - roomquery failed"); - goto error; - } - if (rc == 0) { - dbg(__FUNCTION__" - roomquery returned 0 bytes"); - rc = -EIO; - goto error; - } - priv = (struct keyspan_pda_private *)(port->private); - priv->tx_room = room; - priv->tx_throttled = room ? 0 : 1; - - /* the normal serial device seems to always turn on DTR and RTS here, - so do the same */ - if (port->tty->termios->c_cflag & CBAUD) - keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) ); - else - keyspan_pda_set_modem_info(serial, 0); - - /*Start reading from the device*/ - port->interrupt_in_urb->dev = serial->dev; - rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); - if (rc) { - dbg(__FUNCTION__" - usb_submit_urb(read int) failed"); - goto error; - } - + /* find out how much room is in the Tx ring */ + rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), + 6, /* write_room */ + USB_TYPE_VENDOR | USB_RECIP_INTERFACE + | USB_DIR_IN, + 0, /* value */ + 0, /* index */ + &room, + 1, + 2*HZ); + if (rc < 0) { + dbg(__FUNCTION__" - roomquery failed"); + goto error; + } + if (rc == 0) { + dbg(__FUNCTION__" - roomquery returned 0 bytes"); + rc = -EIO; + goto error; + } + priv = (struct keyspan_pda_private *)(port->private); + priv->tx_room = room; + priv->tx_throttled = room ? 0 : 1; + + /* the normal serial device seems to always turn on DTR and RTS here, + so do the same */ + if (port->tty->termios->c_cflag & CBAUD) + keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) ); + else + keyspan_pda_set_modem_info(serial, 0); + + /*Start reading from the device*/ + port->interrupt_in_urb->dev = serial->dev; + rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); + if (rc) { + dbg(__FUNCTION__" - usb_submit_urb(read int) failed"); + goto error; } - return rc; error: - --port->open_count; return rc; } @@ -716,19 +709,14 @@ { struct usb_serial *serial = port->serial; - --port->open_count; + if (serial->dev) { + /* the normal serial device seems to always shut off DTR and RTS now */ + if (port->tty->termios->c_cflag & HUPCL) + keyspan_pda_set_modem_info(serial, 0); - if (port->open_count <= 0) { - if (serial->dev) { - /* the normal serial device seems to always shut off DTR and RTS now */ - if (port->tty->termios->c_cflag & HUPCL) - keyspan_pda_set_modem_info(serial, 0); - - /* shutdown our bulk reads and writes */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->interrupt_in_urb); - } - port->open_count = 0; + /* shutdown our bulk reads and writes */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->interrupt_in_urb); } } @@ -805,9 +793,6 @@ { dbg (__FUNCTION__); - while (serial->port[0].open_count > 0) { - keyspan_pda_close (&serial->port[0], NULL); - } kfree(serial->port[0].private); } diff -Nru a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c --- a/drivers/usb/serial/kl5kusb105.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/kl5kusb105.c Wed Apr 3 16:39:49 2002 @@ -317,9 +317,6 @@ struct klsi_105_private *priv = (struct klsi_105_private*) serial->port[i].private; unsigned long flags; - while (serial->port[i].open_count > 0) { - klsi_105_close (&serial->port[i], NULL); - } if (priv) { /* kill our write urb pool */ @@ -355,85 +352,80 @@ struct usb_serial *serial = port->serial; struct klsi_105_private *priv = (struct klsi_105_private *)port->private; int retval = 0; + int rc; + int i; + unsigned long line_state; dbg(__FUNCTION__" port %d", port->number); - ++port->open_count; - - if (port->open_count == 1) { - int rc; - int i; - unsigned long line_state; - - /* force low_latency on so that our tty_push actually forces - * the data through - * port->tty->low_latency = 1; */ - - /* Do a defined restart: - * Set up sane default baud rate and send the 'READ_ON' - * vendor command. - * FIXME: set modem line control (how?) - * Then read the modem line control and store values in - * priv->line_state. - */ - priv->cfg.pktlen = 5; - priv->cfg.baudrate = kl5kusb105a_sio_b9600; - priv->cfg.databits = kl5kusb105a_dtb_8; - priv->cfg.unknown1 = 0; - priv->cfg.unknown2 = 1; - klsi_105_chg_port_settings(serial, &(priv->cfg)); - - /* set up termios structure */ - priv->termios.c_iflag = port->tty->termios->c_iflag; - priv->termios.c_oflag = port->tty->termios->c_oflag; - priv->termios.c_cflag = port->tty->termios->c_cflag; - priv->termios.c_lflag = port->tty->termios->c_lflag; - for (i=0; itermios.c_cc[i] = port->tty->termios->c_cc[i]; - - - /* READ_ON and urb submission */ - FILL_BULK_URB(port->read_urb, serial->dev, - usb_rcvbulkpipe(serial->dev, - port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, - port->read_urb->transfer_buffer_length, - klsi_105_read_bulk_callback, - port); - port->read_urb->transfer_flags |= USB_QUEUE_BULK; - - rc = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (rc) { - err(__FUNCTION__ - " - failed submitting read urb, error %d", rc); - retval = rc; - goto exit; - } - - rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), - KL5KUSB105A_SIO_CONFIGURE, - USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, - KL5KUSB105A_SIO_CONFIGURE_READ_ON, - 0, /* index */ - NULL, - 0, - KLSI_TIMEOUT); - if (rc < 0) { - err("Enabling read failed (error = %d)", rc); - retval = rc; - } else - dbg(__FUNCTION__ " - enabled reading"); - - rc = klsi_105_get_line_state(serial, &line_state); - if (rc >= 0) { - priv->line_state = line_state; - dbg(__FUNCTION__ - " - read line state 0x%lx", line_state); - retval = 0; - } else - retval = rc; + /* force low_latency on so that our tty_push actually forces + * the data through + * port->tty->low_latency = 1; */ + + /* Do a defined restart: + * Set up sane default baud rate and send the 'READ_ON' + * vendor command. + * FIXME: set modem line control (how?) + * Then read the modem line control and store values in + * priv->line_state. + */ + priv->cfg.pktlen = 5; + priv->cfg.baudrate = kl5kusb105a_sio_b9600; + priv->cfg.databits = kl5kusb105a_dtb_8; + priv->cfg.unknown1 = 0; + priv->cfg.unknown2 = 1; + klsi_105_chg_port_settings(serial, &(priv->cfg)); + + /* set up termios structure */ + priv->termios.c_iflag = port->tty->termios->c_iflag; + priv->termios.c_oflag = port->tty->termios->c_oflag; + priv->termios.c_cflag = port->tty->termios->c_cflag; + priv->termios.c_lflag = port->tty->termios->c_lflag; + for (i=0; itermios.c_cc[i] = port->tty->termios->c_cc[i]; + + + /* READ_ON and urb submission */ + FILL_BULK_URB(port->read_urb, serial->dev, + usb_rcvbulkpipe(serial->dev, + port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, + port->read_urb->transfer_buffer_length, + klsi_105_read_bulk_callback, + port); + port->read_urb->transfer_flags |= USB_QUEUE_BULK; + + rc = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (rc) { + err(__FUNCTION__ + " - failed submitting read urb, error %d", rc); + retval = rc; + goto exit; } + rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), + KL5KUSB105A_SIO_CONFIGURE, + USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, + KL5KUSB105A_SIO_CONFIGURE_READ_ON, + 0, /* index */ + NULL, + 0, + KLSI_TIMEOUT); + if (rc < 0) { + err("Enabling read failed (error = %d)", rc); + retval = rc; + } else + dbg(__FUNCTION__ " - enabled reading"); + + rc = klsi_105_get_line_state(serial, &line_state); + if (rc >= 0) { + priv->line_state = line_state; + dbg(__FUNCTION__ + " - read line state 0x%lx", line_state); + retval = 0; + } else + retval = rc; + exit: return retval; } /* klsi_105_open */ @@ -444,6 +436,7 @@ struct usb_serial *serial; struct klsi_105_private *priv = (struct klsi_105_private *)port->private; + int rc; dbg(__FUNCTION__" port %d", port->number); serial = get_usb_serial (port, __FUNCTION__); @@ -451,31 +444,26 @@ if(!serial) return; - --port->open_count; - - if (port->open_count <= 0) { - /* send READ_OFF */ - int rc = usb_control_msg(serial->dev, - usb_sndctrlpipe(serial->dev, 0), - KL5KUSB105A_SIO_CONFIGURE, - USB_TYPE_VENDOR | USB_DIR_OUT, - KL5KUSB105A_SIO_CONFIGURE_READ_OFF, - 0, /* index */ - NULL, 0, - KLSI_TIMEOUT); - if (rc < 0) - err("Disabling read failed (error = %d)", rc); - - /* shutdown our bulk reads and writes */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - /* unlink our write pool */ - /* FIXME */ - /* wgg - do I need this? I think so. */ - usb_unlink_urb (port->interrupt_in_urb); - port->open_count = 0; - info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out); - } + /* send READ_OFF */ + rc = usb_control_msg (serial->dev, + usb_sndctrlpipe(serial->dev, 0), + KL5KUSB105A_SIO_CONFIGURE, + USB_TYPE_VENDOR | USB_DIR_OUT, + KL5KUSB105A_SIO_CONFIGURE_READ_OFF, + 0, /* index */ + NULL, 0, + KLSI_TIMEOUT); + if (rc < 0) + err("Disabling read failed (error = %d)", rc); + + /* shutdown our bulk reads and writes */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); + /* unlink our write pool */ + /* FIXME */ + /* wgg - do I need this? I think so. */ + usb_unlink_urb (port->interrupt_in_urb); + info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out); } /* klsi_105_close */ diff -Nru a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c --- a/drivers/usb/serial/mct_u232.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/mct_u232.c Wed Apr 3 16:39:49 2002 @@ -324,9 +324,6 @@ /* stop reads and writes on all ports */ for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - mct_u232_close (&serial->port[i], NULL); - } /* My special items, the standard routines free my urbs */ if (serial->port[i].private) kfree(serial->port[i].private); @@ -341,60 +338,55 @@ dbg(__FUNCTION__" port %d", port->number); - ++port->open_count; - - if (port->open_count == 1) { - /* Compensate for a hardware bug: although the Sitecom U232-P25 - * device reports a maximum output packet size of 32 bytes, - * it seems to be able to accept only 16 bytes (and that's what - * SniffUSB says too...) - */ - if (serial->dev->descriptor.idProduct == MCT_U232_SITECOM_PID) - port->bulk_out_size = 16; - - /* Do a defined restart: the normal serial device seems to - * always turn on DTR and RTS here, so do the same. I'm not - * sure if this is really necessary. But it should not harm - * either. - */ - if (port->tty->termios->c_cflag & CBAUD) - priv->control_state = TIOCM_DTR | TIOCM_RTS; - else - priv->control_state = 0; - mct_u232_set_modem_ctrl(serial, priv->control_state); - - priv->last_lcr = (MCT_U232_DATA_BITS_8 | - MCT_U232_PARITY_NONE | - MCT_U232_STOP_BITS_1); - mct_u232_set_line_ctrl(serial, priv->last_lcr); - - /* Read modem status and update control state */ - mct_u232_get_modem_stat(serial, &priv->last_msr); - mct_u232_msr_to_state(&priv->control_state, priv->last_msr); - - { - /* Puh, that's dirty */ - struct usb_serial_port *rport; - rport = &serial->port[1]; - rport->tty = port->tty; - rport->private = port->private; - port->read_urb = rport->interrupt_in_urb; - } - - port->read_urb->dev = port->serial->dev; - retval = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (retval) { - err("usb_submit_urb(read bulk) failed"); - goto exit; - } - - port->interrupt_in_urb->dev = port->serial->dev; - retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); - if (retval) - err(" usb_submit_urb(read int) failed"); + /* Compensate for a hardware bug: although the Sitecom U232-P25 + * device reports a maximum output packet size of 32 bytes, + * it seems to be able to accept only 16 bytes (and that's what + * SniffUSB says too...) + */ + if (serial->dev->descriptor.idProduct == MCT_U232_SITECOM_PID) + port->bulk_out_size = 16; + + /* Do a defined restart: the normal serial device seems to + * always turn on DTR and RTS here, so do the same. I'm not + * sure if this is really necessary. But it should not harm + * either. + */ + if (port->tty->termios->c_cflag & CBAUD) + priv->control_state = TIOCM_DTR | TIOCM_RTS; + else + priv->control_state = 0; + mct_u232_set_modem_ctrl(serial, priv->control_state); + + priv->last_lcr = (MCT_U232_DATA_BITS_8 | + MCT_U232_PARITY_NONE | + MCT_U232_STOP_BITS_1); + mct_u232_set_line_ctrl(serial, priv->last_lcr); + + /* Read modem status and update control state */ + mct_u232_get_modem_stat(serial, &priv->last_msr); + mct_u232_msr_to_state(&priv->control_state, priv->last_msr); + + { + /* Puh, that's dirty */ + struct usb_serial_port *rport; + rport = &serial->port[1]; + rport->tty = port->tty; + rport->private = port->private; + port->read_urb = rport->interrupt_in_urb; + } + port->read_urb->dev = port->serial->dev; + retval = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (retval) { + err("usb_submit_urb(read bulk) failed"); + goto exit; } + port->interrupt_in_urb->dev = port->serial->dev; + retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); + if (retval) + err(" usb_submit_urb(read int) failed"); + exit: return 0; } /* mct_u232_open */ @@ -404,16 +396,11 @@ { dbg(__FUNCTION__" port %d", port->number); - --port->open_count; - - if (port->open_count <= 0) { - if (port->serial->dev) { - /* shutdown our urbs */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - usb_unlink_urb (port->interrupt_in_urb); - } - port->open_count = 0; + if (port->serial->dev) { + /* shutdown our urbs */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); + usb_unlink_urb (port->interrupt_in_urb); } } /* mct_u232_close */ diff -Nru a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c --- a/drivers/usb/serial/omninet.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/omninet.c Wed Apr 3 16:39:49 2002 @@ -157,29 +157,24 @@ if (!serial) return -ENODEV; - ++port->open_count; - - if (port->open_count == 1) { - od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); - if( !od ) { - err(__FUNCTION__"- kmalloc(%Zd) failed.", sizeof(struct omninet_data)); - port->open_count = 0; - return -ENOMEM; - } + od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); + if( !od ) { + err(__FUNCTION__"- kmalloc(%Zd) failed.", sizeof(struct omninet_data)); + return -ENOMEM; + } - port->private = od; - wport = &serial->port[1]; - wport->tty = port->tty; + port->private = od; + wport = &serial->port[1]; + wport->tty = port->tty; - /* Start reading from the device */ - FILL_BULK_URB(port->read_urb, serial->dev, - usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, - omninet_read_bulk_callback, port); - result = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (result) - err(__FUNCTION__ " - failed submitting read urb, error %d", result); - } + /* Start reading from the device */ + FILL_BULK_URB(port->read_urb, serial->dev, + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, + omninet_read_bulk_callback, port); + result = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (result) + err(__FUNCTION__ " - failed submitting read urb, error %d", result); return result; } @@ -199,20 +194,15 @@ if (!serial) return; - --port->open_count; - - if (port->open_count <= 0) { - if (serial->dev) { - wport = &serial->port[1]; - usb_unlink_urb (wport->write_urb); - usb_unlink_urb (port->read_urb); - } - - port->open_count = 0; - od = (struct omninet_data *)port->private; - if (od) - kfree(od); + if (serial->dev) { + wport = &serial->port[1]; + usb_unlink_urb (wport->write_urb); + usb_unlink_urb (port->read_urb); } + + od = (struct omninet_data *)port->private; + if (od) + kfree(od); } @@ -377,10 +367,6 @@ static void omninet_shutdown (struct usb_serial *serial) { dbg (__FUNCTION__); - - while (serial->port[0].open_count > 0) { - omninet_close (&serial->port[0], NULL); - } } diff -Nru a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c --- a/drivers/usb/serial/pl2303.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/pl2303.c Wed Apr 3 16:39:49 2002 @@ -367,56 +367,52 @@ dbg (__FUNCTION__ " - port %d", port->number); - ++port->open_count; - - if (port->open_count == 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 (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); - FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0xc0); - SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 4); - - /* 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 - - dbg (__FUNCTION__ " - submitting read urb"); - port->read_urb->dev = serial->dev; - result = usb_submit_urb (port->read_urb, GFP_KERNEL); - if (result) { - err(__FUNCTION__ " - failed submitting read urb, error %d", result); - pl2303_close (port, NULL); - return -EPROTO; - } +#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 (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); + SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0); + FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); + FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0); + FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); + SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1); + FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0); + FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0); + SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1); + SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0xc0); + SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 4); + + /* 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 + + dbg (__FUNCTION__ " - submitting read urb"); + port->read_urb->dev = serial->dev; + result = usb_submit_urb (port->read_urb, GFP_KERNEL); + if (result) { + err(__FUNCTION__ " - failed submitting read urb, error %d", result); + pl2303_close (port, NULL); + return -EPROTO; + } - dbg (__FUNCTION__ " - submitting interrupt urb"); - port->interrupt_in_urb->dev = serial->dev; - result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL); - if (result) { - err(__FUNCTION__ " - failed submitting interrupt urb, error %d", result); - pl2303_close (port, NULL); - return -EPROTO; - } + dbg (__FUNCTION__ " - submitting interrupt urb"); + port->interrupt_in_urb->dev = serial->dev; + result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL); + if (result) { + err(__FUNCTION__ " - failed submitting interrupt urb, error %d", result); + pl2303_close (port, NULL); + return -EPROTO; } return 0; } @@ -437,39 +433,35 @@ dbg (__FUNCTION__ " - port %d", port->number); - --port->open_count; - if (port->open_count <= 0) { - if (serial->dev) { - c_cflag = port->tty->termios->c_cflag; - if (c_cflag & HUPCL) { - /* drop DTR and RTS */ - priv = port->private; - priv->line_control = 0; - set_control_lines (port->serial->dev, - priv->line_control); - } - - /* shutdown our urbs */ - dbg (__FUNCTION__ " - shutting down urbs"); - result = usb_unlink_urb (port->write_urb); - if (result) - dbg (__FUNCTION__ " - usb_unlink_urb " - "(write_urb) failed with reason: %d", - result); - - result = usb_unlink_urb (port->read_urb); - if (result) - dbg (__FUNCTION__ " - usb_unlink_urb " - "(read_urb) failed with reason: %d", - result); - - result = usb_unlink_urb (port->interrupt_in_urb); - if (result) - dbg (__FUNCTION__ " - usb_unlink_urb " - "(interrupt_in_urb) failed with reason: %d", - result); + if (serial->dev) { + c_cflag = port->tty->termios->c_cflag; + if (c_cflag & HUPCL) { + /* drop DTR and RTS */ + priv = port->private; + priv->line_control = 0; + set_control_lines (port->serial->dev, + priv->line_control); } - port->open_count = 0; + + /* shutdown our urbs */ + dbg (__FUNCTION__ " - shutting down urbs"); + result = usb_unlink_urb (port->write_urb); + if (result) + dbg (__FUNCTION__ " - usb_unlink_urb " + "(write_urb) failed with reason: %d", + result); + + result = usb_unlink_urb (port->read_urb); + if (result) + dbg (__FUNCTION__ " - usb_unlink_urb " + "(read_urb) failed with reason: %d", + result); + + result = usb_unlink_urb (port->interrupt_in_urb); + if (result) + dbg (__FUNCTION__ " - usb_unlink_urb " + "(interrupt_in_urb) failed with reason: %d", + result); } } @@ -577,12 +569,8 @@ dbg (__FUNCTION__); - /* stop everything on all ports */ for (i = 0; i < serial->num_ports; ++i) - while (serial->port[i].open_count > 0) { - pl2303_close (&serial->port[i], NULL); - kfree (serial->port[i].private); - } + kfree (serial->port[i].private); } diff -Nru a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c --- a/drivers/usb/serial/visor.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/visor.c Wed Apr 3 16:39:49 2002 @@ -268,32 +268,31 @@ dbg(__FUNCTION__ " - port %d", port->number); if (!port->read_urb) { + /* this is needed for some brain dead Sony devices */ err ("Device lied about number of ports, please use a lower one."); return -ENODEV; } - ++port->open_count; + bytes_in = 0; + bytes_out = 0; + + /* + * Force low_latency on so that our tty_push actually forces the data + * through, otherwise it is scheduled, and with high data rates (like + * with OHCI) data can get lost. + */ + port->tty->low_latency = 1; - if (port->open_count == 1) { - bytes_in = 0; - bytes_out = 0; - - /* force low_latency on so that our tty_push actually forces the data through, - otherwise it is scheduled, and with high data rates (like with OHCI) data - can get lost. */ - port->tty->low_latency = 1; - - /* Start reading from the device */ - usb_fill_bulk_urb (port->read_urb, serial->dev, - usb_rcvbulkpipe (serial->dev, - port->bulk_in_endpointAddress), - port->read_urb->transfer_buffer, - port->read_urb->transfer_buffer_length, - visor_read_bulk_callback, port); - result = usb_submit_urb(port->read_urb, GFP_KERNEL); - if (result) - err(__FUNCTION__ " - failed submitting read urb, error %d", result); - } + /* Start reading from the device */ + usb_fill_bulk_urb (port->read_urb, serial->dev, + usb_rcvbulkpipe (serial->dev, + port->bulk_in_endpointAddress), + port->read_urb->transfer_buffer, + port->read_urb->transfer_buffer_length, + visor_read_bulk_callback, port); + result = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (result) + err(__FUNCTION__ " - failed submitting read urb, error %d", result); return result; } @@ -313,28 +312,23 @@ if (!serial) return; - --port->open_count; - - if (port->open_count <= 0) { - if (serial->dev) { - /* only send a shutdown message if the - * device is still here */ - transfer_buffer = kmalloc (0x12, GFP_KERNEL); - if (!transfer_buffer) { - err(__FUNCTION__ " - kmalloc(%d) failed.", 0x12); - } else { - /* send a shutdown message to the device */ - usb_control_msg (serial->dev, - usb_rcvctrlpipe(serial->dev, 0), - VISOR_CLOSE_NOTIFICATION, 0xc2, - 0x0000, 0x0000, - transfer_buffer, 0x12, 300); - kfree (transfer_buffer); - } - /* shutdown our bulk read */ - usb_unlink_urb (port->read_urb); + if (serial->dev) { + /* only send a shutdown message if the + * device is still here */ + transfer_buffer = kmalloc (0x12, GFP_KERNEL); + if (!transfer_buffer) { + err(__FUNCTION__ " - kmalloc(%d) failed.", 0x12); + } else { + /* send a shutdown message to the device */ + usb_control_msg (serial->dev, + usb_rcvctrlpipe(serial->dev, 0), + VISOR_CLOSE_NOTIFICATION, 0xc2, + 0x0000, 0x0000, + transfer_buffer, 0x12, 300); + kfree (transfer_buffer); } - port->open_count = 0; + /* shutdown our bulk read */ + usb_unlink_urb (port->read_urb); } /* Uncomment the following line if you want to see some statistics in your syslog */ /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */ @@ -396,7 +390,7 @@ usb_free_urb (urb); return count; -} +} static int visor_write_room (struct usb_serial_port *port) @@ -655,15 +649,8 @@ static void visor_shutdown (struct usb_serial *serial) { - int i; - dbg (__FUNCTION__); - - /* stop reads and writes on all ports */ - for (i=0; i < serial->num_ports; ++i) - serial->port[i].open_count = 0; } - static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) { diff -Nru a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c --- a/drivers/usb/serial/whiteheat.c Wed Apr 3 16:39:49 2002 +++ b/drivers/usb/serial/whiteheat.c Wed Apr 3 16:39:49 2002 @@ -306,58 +306,49 @@ dbg(__FUNCTION__" - port %d", port->number); - ++port->open_count; - - if (port->open_count == 1) { - /* set up some stuff for our command port */ - command_port = &port->serial->port[COMMAND_PORT]; - if (command_port->private == NULL) { - info = (struct whiteheat_private *)kmalloc (sizeof(struct whiteheat_private), GFP_KERNEL); - if (info == NULL) { - err(__FUNCTION__ " - out of memory"); - retval = -ENOMEM; - goto error_exit; - } - - init_waitqueue_head(&info->wait_command); - command_port->private = info; - command_port->write_urb->complete = command_port_write_callback; - command_port->read_urb->complete = command_port_read_callback; - command_port->read_urb->dev = port->serial->dev; - command_port->tty = port->tty; /* need this to "fake" our our sanity check macros */ - retval = usb_submit_urb (command_port->read_urb, GFP_KERNEL); - if (retval) { - err(__FUNCTION__ " - failed submitting read urb, error %d", retval); - goto error_exit; - } + /* set up some stuff for our command port */ + command_port = &port->serial->port[COMMAND_PORT]; + if (command_port->private == NULL) { + info = (struct whiteheat_private *)kmalloc (sizeof(struct whiteheat_private), GFP_KERNEL); + if (info == NULL) { + err(__FUNCTION__ " - out of memory"); + retval = -ENOMEM; + goto exit; } - /* Start reading from the device */ - port->read_urb->dev = port->serial->dev; - retval = usb_submit_urb(port->read_urb, GFP_KERNEL); + init_waitqueue_head(&info->wait_command); + command_port->private = info; + command_port->write_urb->complete = command_port_write_callback; + command_port->read_urb->complete = command_port_read_callback; + command_port->read_urb->dev = port->serial->dev; + command_port->tty = port->tty; /* need this to "fake" our our sanity check macros */ + retval = usb_submit_urb (command_port->read_urb, GFP_KERNEL); if (retval) { err(__FUNCTION__ " - failed submitting read urb, error %d", retval); - goto error_exit; + goto exit; } + } - /* send an open port command */ - /* firmware uses 1 based port numbering */ - open_command.port = port->number - port->serial->minor + 1; - retval = whiteheat_send_cmd (port->serial, WHITEHEAT_OPEN, (__u8 *)&open_command, sizeof(open_command)); - if (retval) - goto error_exit; - - /* Need to do device specific setup here (control lines, baud rate, etc.) */ - /* FIXME!!! */ + /* Start reading from the device */ + port->read_urb->dev = port->serial->dev; + retval = usb_submit_urb(port->read_urb, GFP_KERNEL); + if (retval) { + err(__FUNCTION__ " - failed submitting read urb, error %d", retval); + goto exit; } - dbg(__FUNCTION__ " - exit"); - return retval; + /* send an open port command */ + /* firmware uses 1 based port numbering */ + open_command.port = port->number - port->serial->minor + 1; + retval = whiteheat_send_cmd (port->serial, WHITEHEAT_OPEN, (__u8 *)&open_command, sizeof(open_command)); + if (retval) + goto exit; -error_exit: - --port->open_count; + /* Need to do device specific setup here (control lines, baud rate, etc.) */ + /* FIXME!!! */ - dbg(__FUNCTION__ " - error_exit"); +exit: + dbg(__FUNCTION__ " - exit, retval = %d", retval); return retval; } @@ -368,22 +359,17 @@ dbg(__FUNCTION__ " - port %d", port->number); - --port->open_count; + /* send a close command to the port */ + /* firmware uses 1 based port numbering */ + close_command.port = port->number - port->serial->minor + 1; + whiteheat_send_cmd (port->serial, WHITEHEAT_CLOSE, (__u8 *)&close_command, sizeof(close_command)); - if (port->open_count <= 0) { - /* send a close command to the port */ - /* firmware uses 1 based port numbering */ - close_command.port = port->number - port->serial->minor + 1; - whiteheat_send_cmd (port->serial, WHITEHEAT_CLOSE, (__u8 *)&close_command, sizeof(close_command)); + /* Need to change the control lines here */ + /* FIXME */ - /* Need to change the control lines here */ - /* FIXME */ - - /* shutdown our bulk reads and writes */ - usb_unlink_urb (port->write_urb); - usb_unlink_urb (port->read_urb); - port->open_count = 0; - } + /* shutdown our bulk reads and writes */ + usb_unlink_urb (port->write_urb); + usb_unlink_urb (port->read_urb); } @@ -641,17 +627,9 @@ static void whiteheat_real_shutdown (struct usb_serial *serial) { - struct usb_serial_port *command_port; - int i; + struct usb_serial_port *command_port; dbg(__FUNCTION__); - - /* stop reads and writes on all ports */ - for (i=0; i < serial->num_ports; ++i) { - while (serial->port[i].open_count > 0) { - whiteheat_close (&serial->port[i], NULL); - } - } /* free up our private data for our command port */ command_port = &serial->port[COMMAND_PORT];