* [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature
@ 2010-03-17 22:00 Johan Hovold
2010-03-17 22:00 ` [PATCH 1/9] USB: serial: allow drivers to define bulk buffer sizes Johan Hovold
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Hi,
Here are a few of fixes to the generic driver as well as a new feature that
lets drivers determine the size of the bulk buffers more easily. It turns out
that increasing the out-buffer sizes for cp210x and pl2303 have a significant
effect on throughput.
Thanks,
Johan
Johan Hovold (9):
USB: serial: allow drivers to define bulk buffer sizes
USB: cp210x: increase the bulk-out buffer size to 256 byte
USB: cp210x: increase bulk-in buffer size to 256 byte
USB: pl2303: increase the bulk-out buffer size to 256 byte
USB: pl2303: increase bulk-in buffer size to 256 byte
USB: serial: fix generic chars_in_buffer
USB: serial: fix missing locking on fifo in write callback
USB: serial: clear fifo on close
USB: serial: refactor generic close
drivers/usb/serial/ark3116.c | 7 ++-----
drivers/usb/serial/belkin_sa.c | 4 +---
drivers/usb/serial/ch341.c | 5 +----
drivers/usb/serial/cp210x.c | 7 +++----
drivers/usb/serial/ftdi_sio.c | 16 +---------------
drivers/usb/serial/generic.c | 31 ++++++++++++++++++++++++-------
drivers/usb/serial/ipaq.c | 28 ++--------------------------
drivers/usb/serial/iuu_phoenix.c | 30 ++----------------------------
drivers/usb/serial/mct_u232.c | 7 ++-----
drivers/usb/serial/pl2303.c | 2 ++
drivers/usb/serial/usb-serial.c | 8 ++++++--
include/linux/usb/serial.h | 5 +++++
12 files changed, 51 insertions(+), 99 deletions(-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/9] USB: serial: allow drivers to define bulk buffer sizes
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 2/9] USB: cp210x: increase the bulk-out buffer size to 256 byte Johan Hovold
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Allow drivers to define custom bulk in/out buffer sizes in struct
usb_serial_driver. If not set, fall back to the default buffer size
which matches the endpoint size.
Three drivers are currently freeing the pre-allocated buffers and
allocating larger ones to achieve this at port probe (ftdi_sio) or even
at port open (ipaq and iuu_phoenix), which needless to say is suboptimal.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/ftdi_sio.c | 16 +---------------
drivers/usb/serial/ipaq.c | 28 ++--------------------------
drivers/usb/serial/iuu_phoenix.c | 30 ++----------------------------
drivers/usb/serial/usb-serial.c | 8 ++++++--
include/linux/usb/serial.h | 5 +++++
5 files changed, 16 insertions(+), 71 deletions(-)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 46a88ae..ab4ad18 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -768,9 +768,6 @@ static const char *ftdi_chip_name[] = {
};
-/* Constants for read urb and write urb */
-#define BUFSZ 512
-
/* Used for TIOCMIWAIT */
#define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
#define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
@@ -821,6 +818,7 @@ static struct usb_serial_driver ftdi_sio_device = {
.usb_driver = &ftdi_driver,
.id_table = id_table_combined,
.num_ports = 1,
+ .bulk_in_size = 512,
.probe = ftdi_sio_probe,
.port_probe = ftdi_sio_port_probe,
.port_remove = ftdi_sio_port_remove,
@@ -1552,18 +1550,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
if (quirk && quirk->port_probe)
quirk->port_probe(priv);
- /* Increase the size of read buffers */
- kfree(port->bulk_in_buffer);
- port->bulk_in_buffer = kmalloc(BUFSZ, GFP_KERNEL);
- if (!port->bulk_in_buffer) {
- kfree(priv);
- return -ENOMEM;
- }
- if (port->read_urb) {
- port->read_urb->transfer_buffer = port->bulk_in_buffer;
- port->read_urb->transfer_buffer_length = BUFSZ;
- }
-
priv->port = port;
/* Free port's existing write urb and transfer buffer. */
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 3fea929..87b1146 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -571,6 +571,8 @@ static struct usb_serial_driver ipaq_device = {
.description = "PocketPC PDA",
.usb_driver = &ipaq_driver,
.id_table = ipaq_id_table,
+ .bulk_in_size = URBDATA_SIZE,
+ .bulk_out_size = URBDATA_SIZE,
.open = ipaq_open,
.close = ipaq_close,
.attach = ipaq_startup,
@@ -628,32 +630,6 @@ static int ipaq_open(struct tty_struct *tty,
priv->free_len += PACKET_SIZE;
}
- /*
- * Lose the small buffers usbserial provides. Make larger ones.
- */
-
- kfree(port->bulk_in_buffer);
- kfree(port->bulk_out_buffer);
- /* make sure the generic serial code knows */
- port->bulk_out_buffer = NULL;
-
- 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) {
- /* the buffer is useless, free it */
- kfree(port->bulk_in_buffer);
- port->bulk_in_buffer = NULL;
- 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;
-
msleep(1000*initial_wait);
/*
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 43f13cf..74551cb 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -1044,34 +1044,6 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
if (buf == NULL)
return -ENOMEM;
- /* fixup the endpoint buffer size */
- kfree(port->bulk_out_buffer);
- port->bulk_out_buffer = kmalloc(512, GFP_KERNEL);
- port->bulk_out_size = 512;
- kfree(port->bulk_in_buffer);
- port->bulk_in_buffer = kmalloc(512, GFP_KERNEL);
- port->bulk_in_size = 512;
-
- if (!port->bulk_out_buffer || !port->bulk_in_buffer) {
- kfree(port->bulk_out_buffer);
- kfree(port->bulk_in_buffer);
- kfree(buf);
- return -ENOMEM;
- }
-
- usb_fill_bulk_urb(port->write_urb, port->serial->dev,
- usb_sndbulkpipe(port->serial->dev,
- port->bulk_out_endpointAddress),
- port->bulk_out_buffer, 512,
- NULL, NULL);
-
-
- usb_fill_bulk_urb(port->read_urb, port->serial->dev,
- usb_rcvbulkpipe(port->serial->dev,
- port->bulk_in_endpointAddress),
- port->bulk_in_buffer, 512,
- NULL, NULL);
-
priv->poll = 0;
/* initialize writebuf */
@@ -1277,6 +1249,8 @@ static struct usb_serial_driver iuu_device = {
},
.id_table = id_table,
.num_ports = 1,
+ .bulk_in_size = 512,
+ .bulk_out_size = 512,
.port_probe = iuu_create_sysfs_attrs,
.port_remove = iuu_remove_sysfs_attrs,
.open = iuu_open,
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index f3f6517..5389246 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -901,7 +901,9 @@ int usb_serial_probe(struct usb_interface *interface,
dev_err(&interface->dev, "No free urbs available\n");
goto probe_error;
}
- buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
+ buffer_size = serial->type->bulk_in_size;
+ if (!buffer_size)
+ buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
port->bulk_in_size = buffer_size;
port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
@@ -927,7 +929,9 @@ int usb_serial_probe(struct usb_interface *interface,
}
if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL))
goto probe_error;
- buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
+ buffer_size = serial->type->bulk_out_size;
+ if (!buffer_size)
+ buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
port->bulk_out_size = buffer_size;
port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index b7682fe..ab311da 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -179,6 +179,8 @@ static inline void usb_set_serial_data(struct usb_serial *serial, void *data)
* @id_table: pointer to a list of usb_device_id structures that define all
* of the devices this structure can support.
* @num_ports: the number of different ports this device will have.
+ * @bulk_in_size: bytes to allocate for bulk-in buffer (0 = end-point size)
+ * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size)
* @calc_num_ports: pointer to a function to determine how many ports this
* device has dynamically. It will be called after the probe()
* callback is called, but before attach()
@@ -223,6 +225,9 @@ struct usb_serial_driver {
struct usb_dynids dynids;
int max_in_flight_urbs;
+ size_t bulk_in_size;
+ size_t bulk_out_size;
+
int (*probe)(struct usb_serial *serial, const struct usb_device_id *id);
int (*attach)(struct usb_serial *serial);
int (*calc_num_ports) (struct usb_serial *serial);
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/9] USB: cp210x: increase the bulk-out buffer size to 256 byte
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
2010-03-17 22:00 ` [PATCH 1/9] USB: serial: allow drivers to define bulk buffer sizes Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 3/9] USB: cp210x: increase bulk-in " Johan Hovold
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Increase the bulk-out buffer size from 64 to 256 byte.
This gives a significant increase in throughput already at 1Mbaud
(e.g. 710 instead of 640 KB/s) as well as lowered CPU usage.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/cp210x.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index ec9b044..e344000 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -138,6 +138,7 @@ static struct usb_serial_driver cp210x_device = {
.usb_driver = &cp210x_driver,
.id_table = id_table,
.num_ports = 1,
+ .bulk_out_size = 256,
.open = cp210x_open,
.close = cp210x_close,
.break_ctl = cp210x_break_ctl,
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/9] USB: cp210x: increase bulk-in buffer size to 256 byte
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
2010-03-17 22:00 ` [PATCH 1/9] USB: serial: allow drivers to define bulk buffer sizes Johan Hovold
2010-03-17 22:00 ` [PATCH 2/9] USB: cp210x: increase the bulk-out buffer size to 256 byte Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 4/9] USB: pl2303: increase the bulk-out " Johan Hovold
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
The cp210x requires a bulk-in buffer larger than endpoint size to keep
up at high baudrates without loosing data.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/cp210x.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index e344000..705a7e7 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -138,6 +138,7 @@ static struct usb_serial_driver cp210x_device = {
.usb_driver = &cp210x_driver,
.id_table = id_table,
.num_ports = 1,
+ .bulk_in_size = 256,
.bulk_out_size = 256,
.open = cp210x_open,
.close = cp210x_close,
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/9] USB: pl2303: increase the bulk-out buffer size to 256 byte
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
` (2 preceding siblings ...)
2010-03-17 22:00 ` [PATCH 3/9] USB: cp210x: increase bulk-in " Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 5/9] USB: pl2303: increase bulk-in " Johan Hovold
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Increase the bulk-out buffer size from 64 to 256 byte.
This gives a significant increase in throughput already at 1Mbaud as well
as lowered CPU usage. The buffer is big enough to keep up also at 3Mbaud
(128b would not suffice).
64b 256b
921k: 640 KB/s 870 KB/s
3M: 640 KB/s 2520 KB/s
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/pl2303.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 1891cfb..afa3744 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -1168,6 +1168,7 @@ static struct usb_serial_driver pl2303_device = {
.id_table = id_table,
.usb_driver = &pl2303_driver,
.num_ports = 1,
+ .bulk_out_size = 256,
.open = pl2303_open,
.close = pl2303_close,
.dtr_rts = pl2303_dtr_rts,
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/9] USB: pl2303: increase bulk-in buffer size to 256 byte
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
` (3 preceding siblings ...)
2010-03-17 22:00 ` [PATCH 4/9] USB: pl2303: increase the bulk-out " Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 6/9] USB: serial: fix generic chars_in_buffer Johan Hovold
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
The pl2303 requires a bulk-in buffer larger than endpoint size to keep
up at high baudrates without loosing data.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/pl2303.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index afa3744..84a7c1f 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -1168,6 +1168,7 @@ static struct usb_serial_driver pl2303_device = {
.id_table = id_table,
.usb_driver = &pl2303_driver,
.num_ports = 1,
+ .bulk_in_size = 256,
.bulk_out_size = 256,
.open = pl2303_open,
.close = pl2303_close,
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6/9] USB: serial: fix generic chars_in_buffer
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
` (4 preceding siblings ...)
2010-03-17 22:00 ` [PATCH 5/9] USB: pl2303: increase bulk-in " Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 7/9] USB: serial: fix missing locking on fifo in write callback Johan Hovold
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Make sure chars_in_buffer accounts also for data in host stack queues.
This fixes the problem with tty_wait_until_sent returning too soon at
close which could cause the final write urb to be cancelled.
Reported-by: Pete Zaitcev <zaitcev@redhat.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/generic.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index ba61c74..8d6d790 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -308,10 +308,14 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port)
/* don't have to grab the lock here, as we will
retry if != 0 */
port->write_urb_busy = 0;
- } else
- result = count;
+ return result;
+ }
- return result;
+ spin_lock_irqsave(&port->lock, flags);
+ port->tx_bytes_flight += count;
+ spin_unlock_irqrestore(&port->lock, flags);
+
+ return count;
}
/**
@@ -399,7 +403,7 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
if (serial->type->max_in_flight_urbs)
chars = port->tx_bytes_flight;
else
- chars = kfifo_len(&port->write_fifo);
+ chars = kfifo_len(&port->write_fifo) + port->tx_bytes_flight;
spin_unlock_irqrestore(&port->lock, flags);
dbg("%s - returns %d", __func__, chars);
@@ -509,7 +513,10 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
port->urbs_in_flight = 0;
spin_unlock_irqrestore(&port->lock, flags);
} else {
+ spin_lock_irqsave(&port->lock, flags);
+ port->tx_bytes_flight -= urb->transfer_buffer_length;
port->write_urb_busy = 0;
+ spin_unlock_irqrestore(&port->lock, flags);
if (status)
kfifo_reset_out(&port->write_fifo);
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/9] USB: serial: fix missing locking on fifo in write callback
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
` (5 preceding siblings ...)
2010-03-17 22:00 ` [PATCH 6/9] USB: serial: fix generic chars_in_buffer Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 8/9] USB: serial: clear fifo on close Johan Hovold
2010-03-17 22:00 ` [PATCH 9/9] USB: serial: refactor generic close Johan Hovold
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
On errors the fifo was reset without any locking. This could race with
write which do kfifo_put and perhaps also chars_in_buffer and write_room.
Every other access to the fifo is protected using the port lock so
better add it to the error path as well.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/generic.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 8d6d790..d3ef69f 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -518,10 +518,13 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
port->write_urb_busy = 0;
spin_unlock_irqrestore(&port->lock, flags);
- if (status)
+ if (status) {
+ spin_lock_irqsave(&port->lock, flags);
kfifo_reset_out(&port->write_fifo);
- else
+ spin_unlock_irqrestore(&port->lock, flags);
+ } else {
usb_serial_generic_write_start(port);
+ }
}
if (status)
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 8/9] USB: serial: clear fifo on close
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
` (6 preceding siblings ...)
2010-03-17 22:00 ` [PATCH 7/9] USB: serial: fix missing locking on fifo in write callback Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
2010-03-17 22:00 ` [PATCH 9/9] USB: serial: refactor generic close Johan Hovold
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Make sure fifo is emptied on close.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/generic.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index d3ef69f..e0c7d53 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -155,13 +155,19 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_open);
static void generic_cleanup(struct usb_serial_port *port)
{
struct usb_serial *serial = port->serial;
+ unsigned long flags;
dbg("%s - port %d", __func__, port->number);
if (serial->dev) {
/* shutdown any bulk transfers that might be going on */
- if (port->bulk_out_size)
+ if (port->bulk_out_size) {
usb_kill_urb(port->write_urb);
+
+ spin_lock_irqsave(&port->lock, flags);
+ kfifo_reset_out(&port->write_fifo);
+ spin_unlock_irqrestore(&port->lock, flags);
+ }
if (port->bulk_in_size)
usb_kill_urb(port->read_urb);
}
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 9/9] USB: serial: refactor generic close
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
` (7 preceding siblings ...)
2010-03-17 22:00 ` [PATCH 8/9] USB: serial: clear fifo on close Johan Hovold
@ 2010-03-17 22:00 ` Johan Hovold
8 siblings, 0 replies; 10+ messages in thread
From: Johan Hovold @ 2010-03-17 22:00 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Johan Hovold
Export usb_serial_generic_close so that drivers can easily kill the read
and write urb and make sure that the write fifo is reset.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
---
drivers/usb/serial/ark3116.c | 7 ++-----
drivers/usb/serial/belkin_sa.c | 4 +---
drivers/usb/serial/ch341.c | 5 +----
drivers/usb/serial/cp210x.c | 5 +----
drivers/usb/serial/generic.c | 1 +
drivers/usb/serial/mct_u232.c | 7 ++-----
6 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 547c944..d655a3d 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -354,14 +354,11 @@ static void ark3116_close(struct usb_serial_port *port)
/* deactivate interrupts */
ark3116_write_reg(serial, UART_IER, 0);
- /* shutdown any bulk reads that might be going on */
- if (serial->num_bulk_out)
- usb_kill_urb(port->write_urb);
- if (serial->num_bulk_in)
- usb_kill_urb(port->read_urb);
+ usb_serial_generic_close(port);
if (serial->num_interrupt_in)
usb_kill_urb(port->interrupt_in_urb);
}
+
}
static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 1295e44..bdab31a 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -246,9 +246,7 @@ static void belkin_sa_close(struct usb_serial_port *port)
{
dbg("%s port %d", __func__, port->number);
- /* shutdown our bulk reads and writes */
- usb_kill_urb(port->write_urb);
- usb_kill_urb(port->read_urb);
+ usb_serial_generic_close(port);
usb_kill_urb(port->interrupt_in_urb);
} /* belkin_sa_close */
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 9f4fed1..1a85e35 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -304,10 +304,7 @@ static void ch341_close(struct usb_serial_port *port)
{
dbg("%s - port %d", __func__, port->number);
- /* shutdown our urbs */
- dbg("%s - shutting down urbs", __func__);
- usb_kill_urb(port->write_urb);
- usb_kill_urb(port->read_urb);
+ usb_serial_generic_close(port);
usb_kill_urb(port->interrupt_in_urb);
}
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 705a7e7..fa4fb5e 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -422,10 +422,7 @@ static void cp210x_close(struct usb_serial_port *port)
{
dbg("%s - port %d", __func__, port->number);
- /* shutdown our urbs */
- dbg("%s - shutting down urbs", __func__);
- usb_kill_urb(port->write_urb);
- usb_kill_urb(port->read_urb);
+ usb_serial_generic_close(port);
mutex_lock(&port->serial->disc_mutex);
if (!port->serial->disconnected)
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index e0c7d53..0b4c7a6 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -178,6 +178,7 @@ void usb_serial_generic_close(struct usb_serial_port *port)
dbg("%s - port %d", __func__, port->number);
generic_cleanup(port);
}
+EXPORT_SYMBOL_GPL(usb_serial_generic_close);
static int usb_serial_multi_urb_write(struct tty_struct *tty,
struct usb_serial_port *port, const unsigned char *buf, int count)
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 2849f8c..7aa01b9 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -549,12 +549,9 @@ static void mct_u232_close(struct usb_serial_port *port)
{
dbg("%s port %d", __func__, port->number);
- if (port->serial->dev) {
- /* shutdown our urbs */
- usb_kill_urb(port->write_urb);
- usb_kill_urb(port->read_urb);
+ usb_serial_generic_close(port);
+ if (port->serial->dev)
usb_kill_urb(port->interrupt_in_urb);
- }
} /* mct_u232_close */
--
1.7.0.2
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2010-03-17 22:08 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-17 22:00 [PATCH 0/9] USB: serial: generic driver fixes and bulk buffer feature Johan Hovold
2010-03-17 22:00 ` [PATCH 1/9] USB: serial: allow drivers to define bulk buffer sizes Johan Hovold
2010-03-17 22:00 ` [PATCH 2/9] USB: cp210x: increase the bulk-out buffer size to 256 byte Johan Hovold
2010-03-17 22:00 ` [PATCH 3/9] USB: cp210x: increase bulk-in " Johan Hovold
2010-03-17 22:00 ` [PATCH 4/9] USB: pl2303: increase the bulk-out " Johan Hovold
2010-03-17 22:00 ` [PATCH 5/9] USB: pl2303: increase bulk-in " Johan Hovold
2010-03-17 22:00 ` [PATCH 6/9] USB: serial: fix generic chars_in_buffer Johan Hovold
2010-03-17 22:00 ` [PATCH 7/9] USB: serial: fix missing locking on fifo in write callback Johan Hovold
2010-03-17 22:00 ` [PATCH 8/9] USB: serial: clear fifo on close Johan Hovold
2010-03-17 22:00 ` [PATCH 9/9] USB: serial: refactor generic close Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®