diff options
author | Alan Cox <alan@lxorguk.ukuu.org.uk> | 2006-01-10 07:54:13 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-10 19:01:59 +0300 |
commit | 33f0f88f1c51ae5c2d593d26960c760ea154c2e2 (patch) | |
tree | f53a38cf49406863f079d74d0e8f91b276f7c1a9 /drivers/usb/serial | |
parent | 6ed80991a2dce4afc113be35089c564d62fa1f11 (diff) | |
download | linux-33f0f88f1c51ae5c2d593d26960c760ea154c2e2.tar.xz |
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r-- | drivers/usb/serial/Kconfig | 2 | ||||
-rw-r--r-- | drivers/usb/serial/cyberjack.c | 11 | ||||
-rw-r--r-- | drivers/usb/serial/cypress_m8.c | 4 | ||||
-rw-r--r-- | drivers/usb/serial/digi_acceleport.c | 28 | ||||
-rw-r--r-- | drivers/usb/serial/empeg.c | 16 | ||||
-rw-r--r-- | drivers/usb/serial/ftdi_sio.c | 15 | ||||
-rw-r--r-- | drivers/usb/serial/garmin_gps.c | 13 | ||||
-rw-r--r-- | drivers/usb/serial/generic.c | 11 | ||||
-rw-r--r-- | drivers/usb/serial/io_edgeport.c | 20 | ||||
-rw-r--r-- | drivers/usb/serial/io_ti.c | 20 | ||||
-rw-r--r-- | drivers/usb/serial/ipaq.c | 12 | ||||
-rw-r--r-- | drivers/usb/serial/ipw.c | 11 | ||||
-rw-r--r-- | drivers/usb/serial/kl5kusb105.c | 13 | ||||
-rw-r--r-- | drivers/usb/serial/kobil_sct.c | 11 | ||||
-rw-r--r-- | drivers/usb/serial/option.c | 9 | ||||
-rw-r--r-- | drivers/usb/serial/pl2303.c | 8 | ||||
-rw-r--r-- | drivers/usb/serial/ti_usb_3410_5052.c | 20 | ||||
-rw-r--r-- | drivers/usb/serial/visor.c | 11 | ||||
-rw-r--r-- | drivers/usb/serial/whiteheat.c | 11 |
19 files changed, 65 insertions, 181 deletions
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig index 14f55fd26a64..be5dc80836c3 100644 --- a/drivers/usb/serial/Kconfig +++ b/drivers/usb/serial/Kconfig @@ -84,7 +84,7 @@ config USB_SERIAL_BELKIN config USB_SERIAL_WHITEHEAT tristate "USB ConnectTech WhiteHEAT Serial Driver" - depends on USB_SERIAL && BROKEN_ON_SMP + depends on USB_SERIAL help Say Y here if you want to use a ConnectTech WhiteHEAT 4 port USB to serial converter device. diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c index 6d18d4eaba35..2357b1d102d7 100644 --- a/drivers/usb/serial/cyberjack.c +++ b/drivers/usb/serial/cyberjack.c @@ -364,7 +364,6 @@ static void cyberjack_read_bulk_callback (struct urb *urb, struct pt_regs *regs) struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; short todo; - int i; int result; dbg("%s - port %d", __FUNCTION__, port->number); @@ -381,14 +380,8 @@ static void cyberjack_read_bulk_callback (struct urb *urb, struct pt_regs *regs) return; } if (urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless tty->low_latency is set */ - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); } diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c index 4e9637eb6137..68067fe117a4 100644 --- a/drivers/usb/serial/cypress_m8.c +++ b/drivers/usb/serial/cypress_m8.c @@ -1263,12 +1263,10 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs) /* process read if there is data other than line status */ if (tty && (bytes > i)) { + bytes = tty_buffer_request_room(tty, bytes); for (; i < bytes ; ++i) { dbg("pushing byte number %d - %d - %c", i, data[i], data[i]); - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } tty_insert_flip_char(tty, data[i], tty_flag); } tty_flip_buffer_push(port->tty); diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c index 8fc414bd5b24..b3f776a90c93 100644 --- a/drivers/usb/serial/digi_acceleport.c +++ b/drivers/usb/serial/digi_acceleport.c @@ -946,13 +946,10 @@ dbg( "digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num ); spin_lock_irqsave( &priv->dp_port_lock, flags ); /* send any buffered chars from throttle time on to tty subsystem */ - len = min(priv->dp_in_buf_len, TTY_FLIPBUF_SIZE - tty->flip.count ); + + len = tty_buffer_request_room(tty, priv->dp_in_buf_len); if( len > 0 ) { - memcpy( tty->flip.char_buf_ptr, priv->dp_in_buf, len ); - memcpy( tty->flip.flag_buf_ptr, priv->dp_in_flag_buf, len ); - tty->flip.char_buf_ptr += len; - tty->flip.flag_buf_ptr += len; - tty->flip.count += len; + tty_insert_flip_string_flags(tty, priv->dp_in_buf, priv->dp_in_flag_buf, len); tty_flip_buffer_push( tty ); } @@ -1827,6 +1824,7 @@ static int digi_read_inb_callback( struct urb *urb ) int status = ((unsigned char *)urb->transfer_buffer)[2]; unsigned char *data = ((unsigned char *)urb->transfer_buffer)+3; int flag,throttled; + int i; /* do not process callbacks on closed ports */ /* but do continue the read chain */ @@ -1885,20 +1883,18 @@ static int digi_read_inb_callback( struct urb *urb ) } } else { - - len = min( len, TTY_FLIPBUF_SIZE - tty->flip.count ); - + len = tty_buffer_request_room(tty, len); if( len > 0 ) { - memcpy( tty->flip.char_buf_ptr, data, len ); - memset( tty->flip.flag_buf_ptr, flag, len ); - tty->flip.char_buf_ptr += len; - tty->flip.flag_buf_ptr += len; - tty->flip.count += len; + /* Hot path */ + if(flag == TTY_NORMAL) + tty_insert_flip_string(tty, data, len); + else { + for(i = 0; i < len; i++) + tty_insert_flip_char(tty, data[i], flag); + } tty_flip_buffer_push( tty ); } - } - } spin_unlock( &priv->dp_port_lock ); diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c index 79a766e9ca23..63f7c78a1152 100644 --- a/drivers/usb/serial/empeg.c +++ b/drivers/usb/serial/empeg.c @@ -344,7 +344,6 @@ static void empeg_read_bulk_callback (struct urb *urb, struct pt_regs *regs) struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; - int i; int result; dbg("%s - port %d", __FUNCTION__, port->number); @@ -359,19 +358,8 @@ static void empeg_read_bulk_callback (struct urb *urb, struct pt_regs *regs) tty = port->tty; if (urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - /* gb - 2000/11/13 - * If we insert too many characters we'll overflow the buffer. - * This means we'll lose bytes - Decidedly bad. - */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - tty_insert_flip_char(tty, data[i], 0); - } - /* gb - 2000/11/13 - * Goes straight through instead of scheduling - if tty->low_latency is set. - */ + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); bytes_in += urb->actual_length; } diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index eb863b3f2d79..10bc1bf23b35 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1610,24 +1610,11 @@ static void ftdi_process_read (void *param) length = 0; } - /* have to make sure we don't overflow the buffer - with tty_insert_flip_char's */ - if (tty->flip.count+length > TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - need_flip = 0; - - if (tty->flip.count != 0) { - /* flip didn't work, this happens when ftdi_process_read() is - * called from ftdi_unthrottle, because TTY_DONT_FLIP is set */ - dbg("%s - flip buffer push failed", __FUNCTION__); - break; - } - } if (priv->rx_flags & THROTTLED) { dbg("%s - throttled", __FUNCTION__); break; } - if (tty->ldisc.receive_room(tty)-tty->flip.count < length) { + if (tty_buffer_request_room(tty, length) < length) { /* break out & wait for throttling/unthrottling to happen */ dbg("%s - receive room low", __FUNCTION__); break; diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 452efce72714..d6f55e9dccae 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -275,23 +275,14 @@ static void send_to_tty(struct usb_serial_port *port, char *data, unsigned int actual_length) { struct tty_struct *tty = port->tty; - int i; if (tty && actual_length) { usb_serial_debug_data(debug, &port->dev, __FUNCTION__, actual_length, data); - for (i = 0; i < actual_length ; ++i) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, - we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless - tty->low_latency is set */ - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, actual_length); + tty_insert_flip_string(tty, data, actual_length); tty_flip_buffer_push(tty); } } diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 4ddac620fc0c..476cda107f4f 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c @@ -254,7 +254,6 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *reg struct usb_serial *serial = port->serial; struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; - int i; int result; dbg("%s - port %d", __FUNCTION__, port->number); @@ -268,14 +267,8 @@ void usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *reg tty = port->tty; if (tty && urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless tty->low_latency is set */ - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); } diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index faedbeb6ba49..3f29e6b0fd19 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -1965,20 +1965,14 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c int cnt; do { - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - dev_err(dev, "%s - dropping data, %d bytes lost\n", - __FUNCTION__, length); - return; - } + cnt = tty_buffer_request_room(tty, length); + if (cnt < length) { + dev_err(dev, "%s - dropping data, %d bytes lost\n", + __FUNCTION__, length - cnt); + if(cnt == 0) + break; } - cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count); - memcpy(tty->flip.char_buf_ptr, data, cnt); - memset(tty->flip.flag_buf_ptr, 0, cnt); - tty->flip.char_buf_ptr += cnt; - tty->flip.flag_buf_ptr += cnt; - tty->flip.count += cnt; + tty_insert_flip_string(tty, data, cnt); data += cnt; length -= cnt; } while (length > 0); diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index 2edf9cabad20..afc0f34b3a46 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -1865,20 +1865,14 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c int cnt; do { - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - dev_err(dev, "%s - dropping data, %d bytes lost\n", - __FUNCTION__, length); - return; - } + cnt = tty_buffer_request_room(tty, length); + if (cnt < length) { + dev_err(dev, "%s - dropping data, %d bytes lost\n", + __FUNCTION__, length - cnt); + if(cnt == 0) + break; } - cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count); - memcpy(tty->flip.char_buf_ptr, data, cnt); - memset(tty->flip.flag_buf_ptr, 0, cnt); - tty->flip.char_buf_ptr += cnt; - tty->flip.flag_buf_ptr += cnt; - tty->flip.count += cnt; + tty_insert_flip_string(tty, data, cnt); data += cnt; length -= cnt; } while (length > 0); diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c index 06d07cea0b70..9a5c97989562 100644 --- a/drivers/usb/serial/ipaq.c +++ b/drivers/usb/serial/ipaq.c @@ -711,7 +711,7 @@ static void ipaq_read_bulk_callback(struct urb *urb, struct pt_regs *regs) struct usb_serial_port *port = (struct usb_serial_port *)urb->context; struct tty_struct *tty; unsigned char *data = urb->transfer_buffer; - int i, result; + int result; dbg("%s - port %d", __FUNCTION__, port->number); @@ -724,14 +724,8 @@ static void ipaq_read_bulk_callback(struct urb *urb, struct pt_regs *regs) tty = port->tty; if (tty && urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless tty->low_latency is set */ - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); bytes_in += urb->actual_length; } diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c index 2dd191f5fe76..e760a70242c1 100644 --- a/drivers/usb/serial/ipw.c +++ b/drivers/usb/serial/ipw.c @@ -166,7 +166,6 @@ static void ipw_read_bulk_callback(struct urb *urb, struct pt_regs *regs) struct usb_serial_port *port = urb->context; unsigned char *data = urb->transfer_buffer; struct tty_struct *tty; - int i; int result; dbg("%s - port %d", __FUNCTION__, port->number); @@ -180,14 +179,8 @@ static void ipw_read_bulk_callback(struct urb *urb, struct pt_regs *regs) tty = port->tty; if (tty && urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless tty->low_latency is set */ - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); } diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c index 4e2f7dfb58b2..78335a5f7743 100644 --- a/drivers/usb/serial/kl5kusb105.c +++ b/drivers/usb/serial/kl5kusb105.c @@ -648,7 +648,6 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs) usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); } else { - int i; int bytes_sent = ((__u8 *) data)[0] + ((unsigned int) ((__u8 *) data)[1] << 8); tty = port->tty; @@ -669,16 +668,8 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs) bytes_sent = urb->actual_length - 2; } - for (i = 2; i < 2+bytes_sent; i++) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, - * we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless - * tty->low_latency is set */ - tty_insert_flip_char(tty, ((__u8*) data)[i], 0); - } + tty_buffer_request_room(tty, bytes_sent); + tty_insert_flip_string(tty, data + 2, bytes_sent); tty_flip_buffer_push(tty); /* again lockless, but debug info only */ diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index d9c21e275130..b8b213185d0f 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c @@ -365,7 +365,6 @@ static void kobil_close (struct usb_serial_port *port, struct file *filp) static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs) { - int i; int result; struct usb_serial_port *port = (struct usb_serial_port *) purb->context; struct tty_struct *tty; @@ -397,14 +396,8 @@ static void kobil_read_int_callback( struct urb *purb, struct pt_regs *regs) */ // END DEBUG - for (i = 0; i < purb->actual_length; ++i) { - // if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - // this doesn't actually push the data through unless tty->low_latency is set - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, purb->actual_length); + tty_insert_flip_string(tty, data, purb->actual_length); tty_flip_buffer_push(tty); } diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c index 3fd2405304fd..52bdf6fe46f2 100644 --- a/drivers/usb/serial/option.c +++ b/drivers/usb/serial/option.c @@ -321,7 +321,7 @@ static int option_write(struct usb_serial_port *port, static void option_indat_callback(struct urb *urb, struct pt_regs *regs) { - int i, err; + int err; int endpoint; struct usb_serial_port *port; struct tty_struct *tty; @@ -338,11 +338,8 @@ static void option_indat_callback(struct urb *urb, struct pt_regs *regs) } else { tty = port->tty; if (urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - if (tty->flip.count >= TTY_FLIPBUF_SIZE) - tty_flip_buffer_push(tty); - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); } else { dbg("%s: empty read urb received", __FUNCTION__); diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index f03721056190..9ffff1938239 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -924,16 +924,12 @@ static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs) tty = port->tty; if (tty && urb->actual_length) { + tty_buffer_request_room(tty, urb->actual_length + 1); /* overrun is special, not associated with a char */ if (status & UART_OVERRUN_ERROR) tty_insert_flip_char(tty, 0, TTY_OVERRUN); - - for (i = 0; i < urb->actual_length; ++i) { - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } + for (i = 0; i < urb->actual_length; ++i) tty_insert_flip_char (tty, data[i], tty_flag); - } tty_flip_buffer_push (tty); } diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c index abb830cb77bd..c18db3257073 100644 --- a/drivers/usb/serial/ti_usb_3410_5052.c +++ b/drivers/usb/serial/ti_usb_3410_5052.c @@ -1280,24 +1280,18 @@ static void ti_recv(struct device *dev, struct tty_struct *tty, int cnt; do { - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - dev_err(dev, "%s - dropping data, %d bytes lost\n", __FUNCTION__, length); - return; - } + cnt = tty_buffer_request_room(tty, length); + if (cnt < length) { + dev_err(dev, "%s - dropping data, %d bytes lost\n", __FUNCTION__, length - cnt); + if(cnt == 0) + break; } - cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count); - memcpy(tty->flip.char_buf_ptr, data, cnt); - memset(tty->flip.flag_buf_ptr, 0, cnt); - tty->flip.char_buf_ptr += cnt; - tty->flip.flag_buf_ptr += cnt; - tty->flip.count += cnt; + tty_insert_flip_string(tty, data, cnt); + tty_flip_buffer_push(tty); data += cnt; length -= cnt; } while (length > 0); - tty_flip_buffer_push(tty); } diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c index 49b1fbe61f25..bce3d55affd8 100644 --- a/drivers/usb/serial/visor.c +++ b/drivers/usb/serial/visor.c @@ -488,7 +488,6 @@ static void visor_read_bulk_callback (struct urb *urb, struct pt_regs *regs) unsigned char *data = urb->transfer_buffer; struct tty_struct *tty; unsigned long flags; - int i; int throttled; int result; @@ -503,14 +502,8 @@ static void visor_read_bulk_callback (struct urb *urb, struct pt_regs *regs) tty = port->tty; if (tty && urb->actual_length) { - for (i = 0; i < urb->actual_length ; ++i) { - /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */ - if(tty->flip.count >= TTY_FLIPBUF_SIZE) { - tty_flip_buffer_push(tty); - } - /* this doesn't actually push the data through unless tty->low_latency is set */ - tty_insert_flip_char(tty, data[i], 0); - } + tty_buffer_request_room(tty, urb->actual_length); + tty_insert_flip_string(tty, data, urb->actual_length); tty_flip_buffer_push(tty); } spin_lock_irqsave(&priv->lock, flags); diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c index a7c3c4734d83..557411c6e7c7 100644 --- a/drivers/usb/serial/whiteheat.c +++ b/drivers/usb/serial/whiteheat.c @@ -1434,7 +1434,9 @@ static void rx_data_softint(void *private) urb = wrap->urb; if (tty && urb->actual_length) { - if (urb->actual_length > TTY_FLIPBUF_SIZE - tty->flip.count) { + int len = tty_buffer_request_room(tty, urb->actual_length); + /* This stuff can go away now I suspect */ + if (unlikely(len < urb->actual_length)) { spin_lock_irqsave(&info->lock, flags); list_add(tmp, &info->rx_urb_q); spin_unlock_irqrestore(&info->lock, flags); @@ -1442,11 +1444,8 @@ static void rx_data_softint(void *private) schedule_work(&info->rx_work); return; } - - memcpy(tty->flip.char_buf_ptr, urb->transfer_buffer, urb->actual_length); - tty->flip.char_buf_ptr += urb->actual_length; - tty->flip.count += urb->actual_length; - sent += urb->actual_length; + tty_insert_flip_string(tty, urb->transfer_buffer, len); + sent += len; } urb->dev = port->serial->dev; |