Commit 0f3d5bae authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

USB: serial: clean up read processing in generic driver

Always process and flush read urb, but only resubmit when not throttled.
The new tty-layer supply plenty of slack so there is really no need to
cache and delay processing of a single urb while throttled.

Note that unthrottle now submits using GFP_KERNEL as we are not in
atomic context (so there is no need to save irq state either).

Note also that the process_read_urb function could be added to
usb_serial_driver should any driver need to do any device specific
processing.
Signed-off-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 2db6c769
...@@ -408,16 +408,16 @@ int usb_serial_generic_submit_read_urb(struct usb_serial_port *port, ...@@ -408,16 +408,16 @@ int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
} }
EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urb); EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urb);
/* Push data to tty layer and resubmit the bulk read URB */ static void usb_serial_generic_process_read_urb(struct urb *urb)
static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
{ {
struct urb *urb = port->read_urb; struct usb_serial_port *port = urb->context;
struct tty_struct *tty = tty_port_tty_get(&port->port); struct tty_struct *tty;
char *ch = (char *)urb->transfer_buffer; char *ch = (char *)urb->transfer_buffer;
int i; int i;
tty = tty_port_tty_get(&port->port);
if (!tty) if (!tty)
goto done; return;
/* The per character mucking around with sysrq path it too slow for /* The per character mucking around with sysrq path it too slow for
stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases
...@@ -425,7 +425,6 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port) ...@@ -425,7 +425,6 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
if (!port->port.console || !port->sysrq) if (!port->port.console || !port->sysrq)
tty_insert_flip_string(tty, ch, urb->actual_length); tty_insert_flip_string(tty, ch, urb->actual_length);
else { else {
/* Push data to tty */
for (i = 0; i < urb->actual_length; i++, ch++) { for (i = 0; i < urb->actual_length; i++, ch++) {
if (!usb_serial_handle_sysrq_char(tty, port, *ch)) if (!usb_serial_handle_sysrq_char(tty, port, *ch))
tty_insert_flip_char(tty, *ch, TTY_NORMAL); tty_insert_flip_char(tty, *ch, TTY_NORMAL);
...@@ -433,8 +432,6 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port) ...@@ -433,8 +432,6 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
} }
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
tty_kref_put(tty); tty_kref_put(tty);
done:
usb_serial_generic_submit_read_urb(port, GFP_ATOMIC);
} }
void usb_serial_generic_read_bulk_callback(struct urb *urb) void usb_serial_generic_read_bulk_callback(struct urb *urb)
...@@ -454,13 +451,14 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb) ...@@ -454,13 +451,14 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb)
usb_serial_debug_data(debug, &port->dev, __func__, usb_serial_debug_data(debug, &port->dev, __func__,
urb->actual_length, data); urb->actual_length, data);
usb_serial_generic_process_read_urb(urb);
/* Throttle the device if requested by tty */ /* Throttle the device if requested by tty */
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
port->throttled = port->throttle_req; port->throttled = port->throttle_req;
if (!port->throttled) { if (!port->throttled) {
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
flush_and_resubmit_read_urb(port); usb_serial_generic_submit_read_urb(port, GFP_ATOMIC);
} else } else
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);
} }
...@@ -523,20 +521,17 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty) ...@@ -523,20 +521,17 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
int was_throttled; int was_throttled;
unsigned long flags;
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
/* Clear the throttle flags */ /* Clear the throttle flags */
spin_lock_irqsave(&port->lock, flags); spin_lock_irq(&port->lock);
was_throttled = port->throttled; was_throttled = port->throttled;
port->throttled = port->throttle_req = 0; port->throttled = port->throttle_req = 0;
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irq(&port->lock);
if (was_throttled) { if (was_throttled)
/* Resume reading from device */ usb_serial_generic_submit_read_urb(port, GFP_KERNEL);
flush_and_resubmit_read_urb(port);
}
} }
#ifdef CONFIG_MAGIC_SYSRQ #ifdef CONFIG_MAGIC_SYSRQ
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment