aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/ftdi_sio.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-10-11 14:24:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-10-11 14:24:25 -0400
commitc6c599272374a358b4171d50ffd605e6cf7b481c (patch)
tree8ce918c724c39e88e96d7abf243955718e71da9a /drivers/usb/serial/ftdi_sio.c
parentff945afb10bc9d81f395da474fa2aa88ee620e48 (diff)
parent40d28582316d8dcb535c359a14b71cb910ad6e73 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (32 commits) USB: serial: no unnecessary GFP_ATOMIC in oti6858 USB: serial: fix race between unthrottle and completion handler in visor USB: serial: fix assumption that throttle/unthrottle cannot sleep USB: serial: fix race between unthrottle and completion handler in symbolserial USB: serial: fix race between unthrottle and completion handler in opticon USB: ehci: Fix isoc scheduling boundary checking. USB: storage: When a device returns no sense data, call it a Hardware Error USB: small fix in error case of suspend in generic usbserial code USB: visor: fix trivial accounting bug in visor driver USB: Fix throttling in generic usbserial driver USB: cp210x: Add support for the DW700 UART USB: ipaq: fix oops when device is plugged in USB: isp1362: fix build warnings on 64-bit systems USB: gadget: imx_udc: Use resource size USB: storage: iRiver P7 UNUSUAL_DEV patch USB: musb: make HAVE_CLK support optional USB: xhci: Fix dropping endpoints from the xHC schedule. USB: xhci: Don't wait for a disable slot cmd when HC dies. USB: xhci: Handle canceled URBs when HC dies. USB: xhci: Stop debugging polling loop when HC dies. ...
Diffstat (limited to 'drivers/usb/serial/ftdi_sio.c')
-rw-r--r--drivers/usb/serial/ftdi_sio.c422
1 files changed, 129 insertions, 293 deletions
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 4f883b1773d0..9c60d6d4908a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -76,13 +76,7 @@ struct ftdi_private {
76 unsigned long last_dtr_rts; /* saved modem control outputs */ 76 unsigned long last_dtr_rts; /* saved modem control outputs */
77 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 77 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
78 char prev_status, diff_status; /* Used for TIOCMIWAIT */ 78 char prev_status, diff_status; /* Used for TIOCMIWAIT */
79 __u8 rx_flags; /* receive state flags (throttling) */
80 spinlock_t rx_lock; /* spinlock for receive state */
81 struct delayed_work rx_work;
82 struct usb_serial_port *port; 79 struct usb_serial_port *port;
83 int rx_processed;
84 unsigned long rx_bytes;
85
86 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface 80 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface
87 (0 for FT232/245) */ 81 (0 for FT232/245) */
88 82
@@ -737,10 +731,6 @@ static const char *ftdi_chip_name[] = {
737/* Constants for read urb and write urb */ 731/* Constants for read urb and write urb */
738#define BUFSZ 512 732#define BUFSZ 512
739 733
740/* rx_flags */
741#define THROTTLED 0x01
742#define ACTUALLY_THROTTLED 0x02
743
744/* Used for TIOCMIWAIT */ 734/* Used for TIOCMIWAIT */
745#define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD) 735#define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
746#define FTDI_STATUS_B1_MASK (FTDI_RS_BI) 736#define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
@@ -763,7 +753,7 @@ static int ftdi_write_room(struct tty_struct *tty);
763static int ftdi_chars_in_buffer(struct tty_struct *tty); 753static int ftdi_chars_in_buffer(struct tty_struct *tty);
764static void ftdi_write_bulk_callback(struct urb *urb); 754static void ftdi_write_bulk_callback(struct urb *urb);
765static void ftdi_read_bulk_callback(struct urb *urb); 755static void ftdi_read_bulk_callback(struct urb *urb);
766static void ftdi_process_read(struct work_struct *work); 756static void ftdi_process_read(struct usb_serial_port *port);
767static void ftdi_set_termios(struct tty_struct *tty, 757static void ftdi_set_termios(struct tty_struct *tty,
768 struct usb_serial_port *port, struct ktermios *old); 758 struct usb_serial_port *port, struct ktermios *old);
769static int ftdi_tiocmget(struct tty_struct *tty, struct file *file); 759static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
@@ -1234,7 +1224,6 @@ static int set_serial_info(struct tty_struct *tty,
1234 (new_serial.flags & ASYNC_FLAGS)); 1224 (new_serial.flags & ASYNC_FLAGS));
1235 priv->custom_divisor = new_serial.custom_divisor; 1225 priv->custom_divisor = new_serial.custom_divisor;
1236 1226
1237 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1238 write_latency_timer(port); 1227 write_latency_timer(port);
1239 1228
1240check_and_exit: 1229check_and_exit:
@@ -1527,7 +1516,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1527 } 1516 }
1528 1517
1529 kref_init(&priv->kref); 1518 kref_init(&priv->kref);
1530 spin_lock_init(&priv->rx_lock);
1531 spin_lock_init(&priv->tx_lock); 1519 spin_lock_init(&priv->tx_lock);
1532 init_waitqueue_head(&priv->delta_msr_wait); 1520 init_waitqueue_head(&priv->delta_msr_wait);
1533 /* This will push the characters through immediately rather 1521 /* This will push the characters through immediately rather
@@ -1549,7 +1537,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1549 port->read_urb->transfer_buffer_length = BUFSZ; 1537 port->read_urb->transfer_buffer_length = BUFSZ;
1550 } 1538 }
1551 1539
1552 INIT_DELAYED_WORK(&priv->rx_work, ftdi_process_read);
1553 priv->port = port; 1540 priv->port = port;
1554 1541
1555 /* Free port's existing write urb and transfer buffer. */ 1542 /* Free port's existing write urb and transfer buffer. */
@@ -1686,6 +1673,26 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1686 return 0; 1673 return 0;
1687} 1674}
1688 1675
1676static int ftdi_submit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
1677{
1678 struct urb *urb = port->read_urb;
1679 struct usb_serial *serial = port->serial;
1680 int result;
1681
1682 usb_fill_bulk_urb(urb, serial->dev,
1683 usb_rcvbulkpipe(serial->dev,
1684 port->bulk_in_endpointAddress),
1685 urb->transfer_buffer,
1686 urb->transfer_buffer_length,
1687 ftdi_read_bulk_callback, port);
1688 result = usb_submit_urb(urb, mem_flags);
1689 if (result)
1690 dev_err(&port->dev,
1691 "%s - failed submitting read urb, error %d\n",
1692 __func__, result);
1693 return result;
1694}
1695
1689static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port) 1696static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1690{ /* ftdi_open */ 1697{ /* ftdi_open */
1691 struct usb_device *dev = port->serial->dev; 1698 struct usb_device *dev = port->serial->dev;
@@ -1700,12 +1707,6 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1700 spin_lock_irqsave(&priv->tx_lock, flags); 1707 spin_lock_irqsave(&priv->tx_lock, flags);
1701 priv->tx_bytes = 0; 1708 priv->tx_bytes = 0;
1702 spin_unlock_irqrestore(&priv->tx_lock, flags); 1709 spin_unlock_irqrestore(&priv->tx_lock, flags);
1703 spin_lock_irqsave(&priv->rx_lock, flags);
1704 priv->rx_bytes = 0;
1705 spin_unlock_irqrestore(&priv->rx_lock, flags);
1706
1707 if (tty)
1708 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1709 1710
1710 write_latency_timer(port); 1711 write_latency_timer(port);
1711 1712
@@ -1725,23 +1726,14 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1725 ftdi_set_termios(tty, port, tty->termios); 1726 ftdi_set_termios(tty, port, tty->termios);
1726 1727
1727 /* Not throttled */ 1728 /* Not throttled */
1728 spin_lock_irqsave(&priv->rx_lock, flags); 1729 spin_lock_irqsave(&port->lock, flags);
1729 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 1730 port->throttled = 0;
1730 spin_unlock_irqrestore(&priv->rx_lock, flags); 1731 port->throttle_req = 0;
1732 spin_unlock_irqrestore(&port->lock, flags);
1731 1733
1732 /* Start reading from the device */ 1734 /* Start reading from the device */
1733 priv->rx_processed = 0; 1735 result = ftdi_submit_read_urb(port, GFP_KERNEL);
1734 usb_fill_bulk_urb(port->read_urb, dev, 1736 if (!result)
1735 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1736 port->read_urb->transfer_buffer,
1737 port->read_urb->transfer_buffer_length,
1738 ftdi_read_bulk_callback, port);
1739 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
1740 if (result)
1741 dev_err(&port->dev,
1742 "%s - failed submitting read urb, error %d\n",
1743 __func__, result);
1744 else
1745 kref_get(&priv->kref); 1737 kref_get(&priv->kref);
1746 1738
1747 return result; 1739 return result;
@@ -1787,10 +1779,6 @@ static void ftdi_close(struct usb_serial_port *port)
1787 1779
1788 dbg("%s", __func__); 1780 dbg("%s", __func__);
1789 1781
1790
1791 /* cancel any scheduled reading */
1792 cancel_delayed_work_sync(&priv->rx_work);
1793
1794 /* shutdown our bulk read */ 1782 /* shutdown our bulk read */
1795 usb_kill_urb(port->read_urb); 1783 usb_kill_urb(port->read_urb);
1796 kref_put(&priv->kref, ftdi_sio_priv_release); 1784 kref_put(&priv->kref, ftdi_sio_priv_release);
@@ -2013,271 +2001,121 @@ static int ftdi_chars_in_buffer(struct tty_struct *tty)
2013 return buffered; 2001 return buffered;
2014} 2002}
2015 2003
2016static void ftdi_read_bulk_callback(struct urb *urb) 2004static int ftdi_process_packet(struct tty_struct *tty,
2005 struct usb_serial_port *port, struct ftdi_private *priv,
2006 char *packet, int len)
2017{ 2007{
2018 struct usb_serial_port *port = urb->context; 2008 int i;
2019 struct tty_struct *tty; 2009 char status;
2020 struct ftdi_private *priv; 2010 char flag;
2021 unsigned long countread; 2011 char *ch;
2022 unsigned long flags;
2023 int status = urb->status;
2024
2025 if (urb->number_of_packets > 0) {
2026 dev_err(&port->dev, "%s transfer_buffer_length %d "
2027 "actual_length %d number of packets %d\n", __func__,
2028 urb->transfer_buffer_length,
2029 urb->actual_length, urb->number_of_packets);
2030 dev_err(&port->dev, "%s transfer_flags %x\n", __func__,
2031 urb->transfer_flags);
2032 }
2033 2012
2034 dbg("%s - port %d", __func__, port->number); 2013 dbg("%s - port %d", __func__, port->number);
2035 2014
2036 if (port->port.count <= 0) 2015 if (len < 2) {
2037 return; 2016 dbg("malformed packet");
2038 2017 return 0;
2039 tty = tty_port_tty_get(&port->port);
2040 if (!tty) {
2041 dbg("%s - bad tty pointer - exiting", __func__);
2042 return;
2043 } 2018 }
2044 2019
2045 priv = usb_get_serial_port_data(port); 2020 /* Compare new line status to the old one, signal if different/
2046 if (!priv) { 2021 N.B. packet may be processed more than once, but differences
2047 dbg("%s - bad port private data pointer - exiting", __func__); 2022 are only processed once. */
2048 goto out; 2023 status = packet[0] & FTDI_STATUS_B0_MASK;
2024 if (status != priv->prev_status) {
2025 priv->diff_status |= status ^ priv->prev_status;
2026 wake_up_interruptible(&priv->delta_msr_wait);
2027 priv->prev_status = status;
2049 } 2028 }
2050 2029
2051 if (urb != port->read_urb) 2030 /*
2052 dev_err(&port->dev, "%s - Not my urb!\n", __func__); 2031 * Although the device uses a bitmask and hence can have multiple
2053 2032 * errors on a packet - the order here sets the priority the error is
2054 if (status) { 2033 * returned to the tty layer.
2055 /* This will happen at close every time so it is a dbg not an 2034 */
2056 err */ 2035 flag = TTY_NORMAL;
2057 dbg("(this is ok on close) nonzero read bulk status received: %d", status); 2036 if (packet[1] & FTDI_RS_OE) {
2058 goto out; 2037 flag = TTY_OVERRUN;
2038 dbg("OVERRRUN error");
2039 }
2040 if (packet[1] & FTDI_RS_BI) {
2041 flag = TTY_BREAK;
2042 dbg("BREAK received");
2043 usb_serial_handle_break(port);
2044 }
2045 if (packet[1] & FTDI_RS_PE) {
2046 flag = TTY_PARITY;
2047 dbg("PARITY error");
2048 }
2049 if (packet[1] & FTDI_RS_FE) {
2050 flag = TTY_FRAME;
2051 dbg("FRAMING error");
2059 } 2052 }
2060 2053
2061 /* count data bytes, but not status bytes */ 2054 len -= 2;
2062 countread = urb->actual_length; 2055 if (!len)
2063 countread -= 2 * DIV_ROUND_UP(countread, priv->max_packet_size); 2056 return 0; /* status only */
2064 spin_lock_irqsave(&priv->rx_lock, flags); 2057 ch = packet + 2;
2065 priv->rx_bytes += countread; 2058
2066 spin_unlock_irqrestore(&priv->rx_lock, flags); 2059 if (!(port->console && port->sysrq) && flag == TTY_NORMAL)
2067 2060 tty_insert_flip_string(tty, ch, len);
2068 ftdi_process_read(&priv->rx_work.work); 2061 else {
2069out: 2062 for (i = 0; i < len; i++, ch++) {
2070 tty_kref_put(tty); 2063 if (!usb_serial_handle_sysrq_char(tty, port, *ch))
2071} /* ftdi_read_bulk_callback */ 2064 tty_insert_flip_char(tty, *ch, flag);
2072 2065 }
2066 }
2067 return len;
2068}
2073 2069
2074static void ftdi_process_read(struct work_struct *work) 2070static void ftdi_process_read(struct usb_serial_port *port)
2075{ /* ftdi_process_read */ 2071{
2076 struct ftdi_private *priv = 2072 struct urb *urb = port->read_urb;
2077 container_of(work, struct ftdi_private, rx_work.work);
2078 struct usb_serial_port *port = priv->port;
2079 struct urb *urb;
2080 struct tty_struct *tty; 2073 struct tty_struct *tty;
2081 char error_flag; 2074 struct ftdi_private *priv = usb_get_serial_port_data(port);
2082 unsigned char *data; 2075 char *data = (char *)urb->transfer_buffer;
2083
2084 int i; 2076 int i;
2085 int result; 2077 int len;
2086 int need_flip; 2078 int count = 0;
2087 int packet_offset;
2088 unsigned long flags;
2089
2090 dbg("%s - port %d", __func__, port->number);
2091
2092 if (port->port.count <= 0)
2093 return;
2094 2079
2095 tty = tty_port_tty_get(&port->port); 2080 tty = tty_port_tty_get(&port->port);
2096 if (!tty) { 2081 if (!tty)
2097 dbg("%s - bad tty pointer - exiting", __func__);
2098 return; 2082 return;
2099 }
2100
2101 priv = usb_get_serial_port_data(port);
2102 if (!priv) {
2103 dbg("%s - bad port private data pointer - exiting", __func__);
2104 goto out;
2105 }
2106
2107 urb = port->read_urb;
2108 if (!urb) {
2109 dbg("%s - bad read_urb pointer - exiting", __func__);
2110 goto out;
2111 }
2112
2113 data = urb->transfer_buffer;
2114 2083
2115 if (priv->rx_processed) { 2084 for (i = 0; i < urb->actual_length; i += priv->max_packet_size) {
2116 dbg("%s - already processed: %d bytes, %d remain", __func__, 2085 len = min_t(int, urb->actual_length - i, priv->max_packet_size);
2117 priv->rx_processed, 2086 count += ftdi_process_packet(tty, port, priv, &data[i], len);
2118 urb->actual_length - priv->rx_processed);
2119 } else {
2120 /* The first two bytes of every read packet are status */
2121 if (urb->actual_length > 2)
2122 usb_serial_debug_data(debug, &port->dev, __func__,
2123 urb->actual_length, data);
2124 else
2125 dbg("Status only: %03oo %03oo", data[0], data[1]);
2126 } 2087 }
2127 2088
2128 2089 if (count)
2129 /* TO DO -- check for hung up line and handle appropriately: */
2130 /* send hangup */
2131 /* See acm.c - you do a tty_hangup - eg tty_hangup(tty) */
2132 /* if CD is dropped and the line is not CLOCAL then we should hangup */
2133
2134 need_flip = 0;
2135 for (packet_offset = priv->rx_processed;
2136 packet_offset < urb->actual_length; packet_offset += priv->max_packet_size) {
2137 int length;
2138
2139 /* Compare new line status to the old one, signal if different/
2140 N.B. packet may be processed more than once, but differences
2141 are only processed once. */
2142 char new_status = data[packet_offset + 0] &
2143 FTDI_STATUS_B0_MASK;
2144 if (new_status != priv->prev_status) {
2145 priv->diff_status |=
2146 new_status ^ priv->prev_status;
2147 wake_up_interruptible(&priv->delta_msr_wait);
2148 priv->prev_status = new_status;
2149 }
2150
2151 length = min_t(u32, priv->max_packet_size, urb->actual_length-packet_offset)-2;
2152 if (length < 0) {
2153 dev_err(&port->dev, "%s - bad packet length: %d\n",
2154 __func__, length+2);
2155 length = 0;
2156 }
2157
2158 if (priv->rx_flags & THROTTLED) {
2159 dbg("%s - throttled", __func__);
2160 break;
2161 }
2162 if (tty_buffer_request_room(tty, length) < length) {
2163 /* break out & wait for throttling/unthrottling to
2164 happen */
2165 dbg("%s - receive room low", __func__);
2166 break;
2167 }
2168
2169 /* Handle errors and break */
2170 error_flag = TTY_NORMAL;
2171 /* Although the device uses a bitmask and hence can have
2172 multiple errors on a packet - the order here sets the
2173 priority the error is returned to the tty layer */
2174
2175 if (data[packet_offset+1] & FTDI_RS_OE) {
2176 error_flag = TTY_OVERRUN;
2177 dbg("OVERRRUN error");
2178 }
2179 if (data[packet_offset+1] & FTDI_RS_BI) {
2180 error_flag = TTY_BREAK;
2181 dbg("BREAK received");
2182 usb_serial_handle_break(port);
2183 }
2184 if (data[packet_offset+1] & FTDI_RS_PE) {
2185 error_flag = TTY_PARITY;
2186 dbg("PARITY error");
2187 }
2188 if (data[packet_offset+1] & FTDI_RS_FE) {
2189 error_flag = TTY_FRAME;
2190 dbg("FRAMING error");
2191 }
2192 if (length > 0) {
2193 for (i = 2; i < length+2; i++) {
2194 /* Note that the error flag is duplicated for
2195 every character received since we don't know
2196 which character it applied to */
2197 if (!usb_serial_handle_sysrq_char(tty, port,
2198 data[packet_offset + i]))
2199 tty_insert_flip_char(tty,
2200 data[packet_offset + i],
2201 error_flag);
2202 }
2203 need_flip = 1;
2204 }
2205
2206#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
2207 /* if a parity error is detected you get status packets forever
2208 until a character is sent without a parity error.
2209 This doesn't work well since the application receives a
2210 never ending stream of bad data - even though new data
2211 hasn't been sent. Therefore I (bill) have taken this out.
2212 However - this might make sense for framing errors and so on
2213 so I am leaving the code in for now.
2214 */
2215 else {
2216 if (error_flag != TTY_NORMAL) {
2217 dbg("error_flag is not normal");
2218 /* In this case it is just status - if that is
2219 an error send a bad character */
2220 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
2221 tty_flip_buffer_push(tty);
2222 tty_insert_flip_char(tty, 0xff, error_flag);
2223 need_flip = 1;
2224 }
2225 }
2226#endif
2227 } /* "for(packet_offset=0..." */
2228
2229 /* Low latency */
2230 if (need_flip)
2231 tty_flip_buffer_push(tty); 2090 tty_flip_buffer_push(tty);
2091 tty_kref_put(tty);
2092}
2232 2093
2233 if (packet_offset < urb->actual_length) { 2094static void ftdi_read_bulk_callback(struct urb *urb)
2234 /* not completely processed - record progress */ 2095{
2235 priv->rx_processed = packet_offset; 2096 struct usb_serial_port *port = urb->context;
2236 dbg("%s - incomplete, %d bytes processed, %d remain", 2097 unsigned long flags;
2237 __func__, packet_offset,
2238 urb->actual_length - packet_offset);
2239 /* check if we were throttled while processing */
2240 spin_lock_irqsave(&priv->rx_lock, flags);
2241 if (priv->rx_flags & THROTTLED) {
2242 priv->rx_flags |= ACTUALLY_THROTTLED;
2243 spin_unlock_irqrestore(&priv->rx_lock, flags);
2244 dbg("%s - deferring remainder until unthrottled",
2245 __func__);
2246 goto out;
2247 }
2248 spin_unlock_irqrestore(&priv->rx_lock, flags);
2249 /* if the port is closed stop trying to read */
2250 if (port->port.count > 0)
2251 /* delay processing of remainder */
2252 schedule_delayed_work(&priv->rx_work, 1);
2253 else
2254 dbg("%s - port is closed", __func__);
2255 goto out;
2256 }
2257
2258 /* urb is completely processed */
2259 priv->rx_processed = 0;
2260 2098
2261 /* if the port is closed stop trying to read */ 2099 dbg("%s - port %d", __func__, port->number);
2262 if (port->port.count > 0) {
2263 /* Continue trying to always read */
2264 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
2265 usb_rcvbulkpipe(port->serial->dev,
2266 port->bulk_in_endpointAddress),
2267 port->read_urb->transfer_buffer,
2268 port->read_urb->transfer_buffer_length,
2269 ftdi_read_bulk_callback, port);
2270 2100
2271 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 2101 if (urb->status) {
2272 if (result) 2102 dbg("%s - nonzero read bulk status received: %d",
2273 dev_err(&port->dev, 2103 __func__, urb->status);
2274 "%s - failed resubmitting read urb, error %d\n", 2104 return;
2275 __func__, result);
2276 } 2105 }
2277out:
2278 tty_kref_put(tty);
2279} /* ftdi_process_read */
2280 2106
2107 usb_serial_debug_data(debug, &port->dev, __func__,
2108 urb->actual_length, urb->transfer_buffer);
2109 ftdi_process_read(port);
2110
2111 spin_lock_irqsave(&port->lock, flags);
2112 port->throttled = port->throttle_req;
2113 if (!port->throttled) {
2114 spin_unlock_irqrestore(&port->lock, flags);
2115 ftdi_submit_read_urb(port, GFP_ATOMIC);
2116 } else
2117 spin_unlock_irqrestore(&port->lock, flags);
2118}
2281 2119
2282static void ftdi_break_ctl(struct tty_struct *tty, int break_state) 2120static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
2283{ 2121{
@@ -2609,33 +2447,31 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2609static void ftdi_throttle(struct tty_struct *tty) 2447static void ftdi_throttle(struct tty_struct *tty)
2610{ 2448{
2611 struct usb_serial_port *port = tty->driver_data; 2449 struct usb_serial_port *port = tty->driver_data;
2612 struct ftdi_private *priv = usb_get_serial_port_data(port);
2613 unsigned long flags; 2450 unsigned long flags;
2614 2451
2615 dbg("%s - port %d", __func__, port->number); 2452 dbg("%s - port %d", __func__, port->number);
2616 2453
2617 spin_lock_irqsave(&priv->rx_lock, flags); 2454 spin_lock_irqsave(&port->lock, flags);
2618 priv->rx_flags |= THROTTLED; 2455 port->throttle_req = 1;
2619 spin_unlock_irqrestore(&priv->rx_lock, flags); 2456 spin_unlock_irqrestore(&port->lock, flags);
2620} 2457}
2621 2458
2622 2459void ftdi_unthrottle(struct tty_struct *tty)
2623static void ftdi_unthrottle(struct tty_struct *tty)
2624{ 2460{
2625 struct usb_serial_port *port = tty->driver_data; 2461 struct usb_serial_port *port = tty->driver_data;
2626 struct ftdi_private *priv = usb_get_serial_port_data(port); 2462 int was_throttled;
2627 int actually_throttled;
2628 unsigned long flags; 2463 unsigned long flags;
2629 2464
2630 dbg("%s - port %d", __func__, port->number); 2465 dbg("%s - port %d", __func__, port->number);
2631 2466
2632 spin_lock_irqsave(&priv->rx_lock, flags); 2467 spin_lock_irqsave(&port->lock, flags);
2633 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; 2468 was_throttled = port->throttled;
2634 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 2469 port->throttled = port->throttle_req = 0;
2635 spin_unlock_irqrestore(&priv->rx_lock, flags); 2470 spin_unlock_irqrestore(&port->lock, flags);
2636 2471
2637 if (actually_throttled) 2472 /* Resubmit urb if throttled and open. */
2638 schedule_delayed_work(&priv->rx_work, 0); 2473 if (was_throttled && test_bit(ASYNCB_INITIALIZED, &port->port.flags))
2474 ftdi_submit_read_urb(port, GFP_KERNEL);
2639} 2475}
2640 2476
2641static int __init ftdi_init(void) 2477static int __init ftdi_init(void)