aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/ftdi_sio.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/ftdi_sio.c')
-rw-r--r--drivers/usb/serial/ftdi_sio.c435
1 files changed, 138 insertions, 297 deletions
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 8fec5d4455c9..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
@@ -176,6 +170,9 @@ static struct usb_device_id id_table_combined [] = {
176 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, 170 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
177 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, 171 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
178 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) }, 172 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
173 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_SNIFFER_PID) },
174 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) },
175 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) },
179 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 176 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
180 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 177 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
181 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) }, 178 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) },
@@ -694,6 +691,8 @@ static struct usb_device_id id_table_combined [] = {
694 { USB_DEVICE(DE_VID, WHT_PID) }, 691 { USB_DEVICE(DE_VID, WHT_PID) },
695 { USB_DEVICE(ADI_VID, ADI_GNICE_PID), 692 { USB_DEVICE(ADI_VID, ADI_GNICE_PID),
696 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 693 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
694 { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID),
695 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
697 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, 696 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) },
698 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), 697 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID),
699 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 698 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
@@ -702,6 +701,8 @@ static struct usb_device_id id_table_combined [] = {
702 { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) }, 701 { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) },
703 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), 702 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID),
704 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 703 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
704 { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) },
705 { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) },
705 { }, /* Optional parameter entry */ 706 { }, /* Optional parameter entry */
706 { } /* Terminating entry */ 707 { } /* Terminating entry */
707}; 708};
@@ -730,10 +731,6 @@ static const char *ftdi_chip_name[] = {
730/* Constants for read urb and write urb */ 731/* Constants for read urb and write urb */
731#define BUFSZ 512 732#define BUFSZ 512
732 733
733/* rx_flags */
734#define THROTTLED 0x01
735#define ACTUALLY_THROTTLED 0x02
736
737/* Used for TIOCMIWAIT */ 734/* Used for TIOCMIWAIT */
738#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)
739#define FTDI_STATUS_B1_MASK (FTDI_RS_BI) 736#define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
@@ -747,8 +744,7 @@ static int ftdi_sio_probe(struct usb_serial *serial,
747 const struct usb_device_id *id); 744 const struct usb_device_id *id);
748static int ftdi_sio_port_probe(struct usb_serial_port *port); 745static int ftdi_sio_port_probe(struct usb_serial_port *port);
749static int ftdi_sio_port_remove(struct usb_serial_port *port); 746static int ftdi_sio_port_remove(struct usb_serial_port *port);
750static int ftdi_open(struct tty_struct *tty, 747static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port);
751 struct usb_serial_port *port, struct file *filp);
752static void ftdi_close(struct usb_serial_port *port); 748static void ftdi_close(struct usb_serial_port *port);
753static void ftdi_dtr_rts(struct usb_serial_port *port, int on); 749static void ftdi_dtr_rts(struct usb_serial_port *port, int on);
754static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, 750static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -757,7 +753,7 @@ static int ftdi_write_room(struct tty_struct *tty);
757static int ftdi_chars_in_buffer(struct tty_struct *tty); 753static int ftdi_chars_in_buffer(struct tty_struct *tty);
758static void ftdi_write_bulk_callback(struct urb *urb); 754static void ftdi_write_bulk_callback(struct urb *urb);
759static void ftdi_read_bulk_callback(struct urb *urb); 755static void ftdi_read_bulk_callback(struct urb *urb);
760static void ftdi_process_read(struct work_struct *work); 756static void ftdi_process_read(struct usb_serial_port *port);
761static void ftdi_set_termios(struct tty_struct *tty, 757static void ftdi_set_termios(struct tty_struct *tty,
762 struct usb_serial_port *port, struct ktermios *old); 758 struct usb_serial_port *port, struct ktermios *old);
763static int ftdi_tiocmget(struct tty_struct *tty, struct file *file); 759static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
@@ -1228,7 +1224,6 @@ static int set_serial_info(struct tty_struct *tty,
1228 (new_serial.flags & ASYNC_FLAGS)); 1224 (new_serial.flags & ASYNC_FLAGS));
1229 priv->custom_divisor = new_serial.custom_divisor; 1225 priv->custom_divisor = new_serial.custom_divisor;
1230 1226
1231 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1232 write_latency_timer(port); 1227 write_latency_timer(port);
1233 1228
1234check_and_exit: 1229check_and_exit:
@@ -1521,7 +1516,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1521 } 1516 }
1522 1517
1523 kref_init(&priv->kref); 1518 kref_init(&priv->kref);
1524 spin_lock_init(&priv->rx_lock);
1525 spin_lock_init(&priv->tx_lock); 1519 spin_lock_init(&priv->tx_lock);
1526 init_waitqueue_head(&priv->delta_msr_wait); 1520 init_waitqueue_head(&priv->delta_msr_wait);
1527 /* This will push the characters through immediately rather 1521 /* This will push the characters through immediately rather
@@ -1543,7 +1537,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1543 port->read_urb->transfer_buffer_length = BUFSZ; 1537 port->read_urb->transfer_buffer_length = BUFSZ;
1544 } 1538 }
1545 1539
1546 INIT_DELAYED_WORK(&priv->rx_work, ftdi_process_read);
1547 priv->port = port; 1540 priv->port = port;
1548 1541
1549 /* Free port's existing write urb and transfer buffer. */ 1542 /* Free port's existing write urb and transfer buffer. */
@@ -1680,8 +1673,27 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1680 return 0; 1673 return 0;
1681} 1674}
1682 1675
1683static int ftdi_open(struct tty_struct *tty, 1676static int ftdi_submit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
1684 struct usb_serial_port *port, struct file *filp) 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
1696static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1685{ /* ftdi_open */ 1697{ /* ftdi_open */
1686 struct usb_device *dev = port->serial->dev; 1698 struct usb_device *dev = port->serial->dev;
1687 struct ftdi_private *priv = usb_get_serial_port_data(port); 1699 struct ftdi_private *priv = usb_get_serial_port_data(port);
@@ -1695,12 +1707,6 @@ static int ftdi_open(struct tty_struct *tty,
1695 spin_lock_irqsave(&priv->tx_lock, flags); 1707 spin_lock_irqsave(&priv->tx_lock, flags);
1696 priv->tx_bytes = 0; 1708 priv->tx_bytes = 0;
1697 spin_unlock_irqrestore(&priv->tx_lock, flags); 1709 spin_unlock_irqrestore(&priv->tx_lock, flags);
1698 spin_lock_irqsave(&priv->rx_lock, flags);
1699 priv->rx_bytes = 0;
1700 spin_unlock_irqrestore(&priv->rx_lock, flags);
1701
1702 if (tty)
1703 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1704 1710
1705 write_latency_timer(port); 1711 write_latency_timer(port);
1706 1712
@@ -1720,23 +1726,14 @@ static int ftdi_open(struct tty_struct *tty,
1720 ftdi_set_termios(tty, port, tty->termios); 1726 ftdi_set_termios(tty, port, tty->termios);
1721 1727
1722 /* Not throttled */ 1728 /* Not throttled */
1723 spin_lock_irqsave(&priv->rx_lock, flags); 1729 spin_lock_irqsave(&port->lock, flags);
1724 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 1730 port->throttled = 0;
1725 spin_unlock_irqrestore(&priv->rx_lock, flags); 1731 port->throttle_req = 0;
1732 spin_unlock_irqrestore(&port->lock, flags);
1726 1733
1727 /* Start reading from the device */ 1734 /* Start reading from the device */
1728 priv->rx_processed = 0; 1735 result = ftdi_submit_read_urb(port, GFP_KERNEL);
1729 usb_fill_bulk_urb(port->read_urb, dev, 1736 if (!result)
1730 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
1731 port->read_urb->transfer_buffer,
1732 port->read_urb->transfer_buffer_length,
1733 ftdi_read_bulk_callback, port);
1734 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
1735 if (result)
1736 dev_err(&port->dev,
1737 "%s - failed submitting read urb, error %d\n",
1738 __func__, result);
1739 else
1740 kref_get(&priv->kref); 1737 kref_get(&priv->kref);
1741 1738
1742 return result; 1739 return result;
@@ -1782,10 +1779,6 @@ static void ftdi_close(struct usb_serial_port *port)
1782 1779
1783 dbg("%s", __func__); 1780 dbg("%s", __func__);
1784 1781
1785
1786 /* cancel any scheduled reading */
1787 cancel_delayed_work_sync(&priv->rx_work);
1788
1789 /* shutdown our bulk read */ 1782 /* shutdown our bulk read */
1790 usb_kill_urb(port->read_urb); 1783 usb_kill_urb(port->read_urb);
1791 kref_put(&priv->kref, ftdi_sio_priv_release); 1784 kref_put(&priv->kref, ftdi_sio_priv_release);
@@ -2008,271 +2001,121 @@ static int ftdi_chars_in_buffer(struct tty_struct *tty)
2008 return buffered; 2001 return buffered;
2009} 2002}
2010 2003
2011static 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)
2012{ 2007{
2013 struct usb_serial_port *port = urb->context; 2008 int i;
2014 struct tty_struct *tty; 2009 char status;
2015 struct ftdi_private *priv; 2010 char flag;
2016 unsigned long countread; 2011 char *ch;
2017 unsigned long flags;
2018 int status = urb->status;
2019
2020 if (urb->number_of_packets > 0) {
2021 dev_err(&port->dev, "%s transfer_buffer_length %d "
2022 "actual_length %d number of packets %d\n", __func__,
2023 urb->transfer_buffer_length,
2024 urb->actual_length, urb->number_of_packets);
2025 dev_err(&port->dev, "%s transfer_flags %x\n", __func__,
2026 urb->transfer_flags);
2027 }
2028 2012
2029 dbg("%s - port %d", __func__, port->number); 2013 dbg("%s - port %d", __func__, port->number);
2030 2014
2031 if (port->port.count <= 0) 2015 if (len < 2) {
2032 return; 2016 dbg("malformed packet");
2033 2017 return 0;
2034 tty = tty_port_tty_get(&port->port);
2035 if (!tty) {
2036 dbg("%s - bad tty pointer - exiting", __func__);
2037 return;
2038 } 2018 }
2039 2019
2040 priv = usb_get_serial_port_data(port); 2020 /* Compare new line status to the old one, signal if different/
2041 if (!priv) { 2021 N.B. packet may be processed more than once, but differences
2042 dbg("%s - bad port private data pointer - exiting", __func__); 2022 are only processed once. */
2043 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;
2044 } 2028 }
2045 2029
2046 if (urb != port->read_urb) 2030 /*
2047 dev_err(&port->dev, "%s - Not my urb!\n", __func__); 2031 * Although the device uses a bitmask and hence can have multiple
2048 2032 * errors on a packet - the order here sets the priority the error is
2049 if (status) { 2033 * returned to the tty layer.
2050 /* This will happen at close every time so it is a dbg not an 2034 */
2051 err */ 2035 flag = TTY_NORMAL;
2052 dbg("(this is ok on close) nonzero read bulk status received: %d", status); 2036 if (packet[1] & FTDI_RS_OE) {
2053 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");
2054 } 2052 }
2055 2053
2056 /* count data bytes, but not status bytes */ 2054 len -= 2;
2057 countread = urb->actual_length; 2055 if (!len)
2058 countread -= 2 * DIV_ROUND_UP(countread, priv->max_packet_size); 2056 return 0; /* status only */
2059 spin_lock_irqsave(&priv->rx_lock, flags); 2057 ch = packet + 2;
2060 priv->rx_bytes += countread; 2058
2061 spin_unlock_irqrestore(&priv->rx_lock, flags); 2059 if (!(port->console && port->sysrq) && flag == TTY_NORMAL)
2062 2060 tty_insert_flip_string(tty, ch, len);
2063 ftdi_process_read(&priv->rx_work.work); 2061 else {
2064out: 2062 for (i = 0; i < len; i++, ch++) {
2065 tty_kref_put(tty); 2063 if (!usb_serial_handle_sysrq_char(tty, port, *ch))
2066} /* ftdi_read_bulk_callback */ 2064 tty_insert_flip_char(tty, *ch, flag);
2067 2065 }
2066 }
2067 return len;
2068}
2068 2069
2069static void ftdi_process_read(struct work_struct *work) 2070static void ftdi_process_read(struct usb_serial_port *port)
2070{ /* ftdi_process_read */ 2071{
2071 struct ftdi_private *priv = 2072 struct urb *urb = port->read_urb;
2072 container_of(work, struct ftdi_private, rx_work.work);
2073 struct usb_serial_port *port = priv->port;
2074 struct urb *urb;
2075 struct tty_struct *tty; 2073 struct tty_struct *tty;
2076 char error_flag; 2074 struct ftdi_private *priv = usb_get_serial_port_data(port);
2077 unsigned char *data; 2075 char *data = (char *)urb->transfer_buffer;
2078
2079 int i; 2076 int i;
2080 int result; 2077 int len;
2081 int need_flip; 2078 int count = 0;
2082 int packet_offset;
2083 unsigned long flags;
2084
2085 dbg("%s - port %d", __func__, port->number);
2086
2087 if (port->port.count <= 0)
2088 return;
2089 2079
2090 tty = tty_port_tty_get(&port->port); 2080 tty = tty_port_tty_get(&port->port);
2091 if (!tty) { 2081 if (!tty)
2092 dbg("%s - bad tty pointer - exiting", __func__);
2093 return; 2082 return;
2094 }
2095 2083
2096 priv = usb_get_serial_port_data(port); 2084 for (i = 0; i < urb->actual_length; i += priv->max_packet_size) {
2097 if (!priv) { 2085 len = min_t(int, urb->actual_length - i, priv->max_packet_size);
2098 dbg("%s - bad port private data pointer - exiting", __func__); 2086 count += ftdi_process_packet(tty, port, priv, &data[i], len);
2099 goto out;
2100 }
2101
2102 urb = port->read_urb;
2103 if (!urb) {
2104 dbg("%s - bad read_urb pointer - exiting", __func__);
2105 goto out;
2106 } 2087 }
2107 2088
2108 data = urb->transfer_buffer; 2089 if (count)
2109
2110 if (priv->rx_processed) {
2111 dbg("%s - already processed: %d bytes, %d remain", __func__,
2112 priv->rx_processed,
2113 urb->actual_length - priv->rx_processed);
2114 } else {
2115 /* The first two bytes of every read packet are status */
2116 if (urb->actual_length > 2)
2117 usb_serial_debug_data(debug, &port->dev, __func__,
2118 urb->actual_length, data);
2119 else
2120 dbg("Status only: %03oo %03oo", data[0], data[1]);
2121 }
2122
2123
2124 /* TO DO -- check for hung up line and handle appropriately: */
2125 /* send hangup */
2126 /* See acm.c - you do a tty_hangup - eg tty_hangup(tty) */
2127 /* if CD is dropped and the line is not CLOCAL then we should hangup */
2128
2129 need_flip = 0;
2130 for (packet_offset = priv->rx_processed;
2131 packet_offset < urb->actual_length; packet_offset += priv->max_packet_size) {
2132 int length;
2133
2134 /* Compare new line status to the old one, signal if different/
2135 N.B. packet may be processed more than once, but differences
2136 are only processed once. */
2137 char new_status = data[packet_offset + 0] &
2138 FTDI_STATUS_B0_MASK;
2139 if (new_status != priv->prev_status) {
2140 priv->diff_status |=
2141 new_status ^ priv->prev_status;
2142 wake_up_interruptible(&priv->delta_msr_wait);
2143 priv->prev_status = new_status;
2144 }
2145
2146 length = min_t(u32, priv->max_packet_size, urb->actual_length-packet_offset)-2;
2147 if (length < 0) {
2148 dev_err(&port->dev, "%s - bad packet length: %d\n",
2149 __func__, length+2);
2150 length = 0;
2151 }
2152
2153 if (priv->rx_flags & THROTTLED) {
2154 dbg("%s - throttled", __func__);
2155 break;
2156 }
2157 if (tty_buffer_request_room(tty, length) < length) {
2158 /* break out & wait for throttling/unthrottling to
2159 happen */
2160 dbg("%s - receive room low", __func__);
2161 break;
2162 }
2163
2164 /* Handle errors and break */
2165 error_flag = TTY_NORMAL;
2166 /* Although the device uses a bitmask and hence can have
2167 multiple errors on a packet - the order here sets the
2168 priority the error is returned to the tty layer */
2169
2170 if (data[packet_offset+1] & FTDI_RS_OE) {
2171 error_flag = TTY_OVERRUN;
2172 dbg("OVERRRUN error");
2173 }
2174 if (data[packet_offset+1] & FTDI_RS_BI) {
2175 error_flag = TTY_BREAK;
2176 dbg("BREAK received");
2177 usb_serial_handle_break(port);
2178 }
2179 if (data[packet_offset+1] & FTDI_RS_PE) {
2180 error_flag = TTY_PARITY;
2181 dbg("PARITY error");
2182 }
2183 if (data[packet_offset+1] & FTDI_RS_FE) {
2184 error_flag = TTY_FRAME;
2185 dbg("FRAMING error");
2186 }
2187 if (length > 0) {
2188 for (i = 2; i < length+2; i++) {
2189 /* Note that the error flag is duplicated for
2190 every character received since we don't know
2191 which character it applied to */
2192 if (!usb_serial_handle_sysrq_char(tty, port,
2193 data[packet_offset + i]))
2194 tty_insert_flip_char(tty,
2195 data[packet_offset + i],
2196 error_flag);
2197 }
2198 need_flip = 1;
2199 }
2200
2201#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW
2202 /* if a parity error is detected you get status packets forever
2203 until a character is sent without a parity error.
2204 This doesn't work well since the application receives a
2205 never ending stream of bad data - even though new data
2206 hasn't been sent. Therefore I (bill) have taken this out.
2207 However - this might make sense for framing errors and so on
2208 so I am leaving the code in for now.
2209 */
2210 else {
2211 if (error_flag != TTY_NORMAL) {
2212 dbg("error_flag is not normal");
2213 /* In this case it is just status - if that is
2214 an error send a bad character */
2215 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
2216 tty_flip_buffer_push(tty);
2217 tty_insert_flip_char(tty, 0xff, error_flag);
2218 need_flip = 1;
2219 }
2220 }
2221#endif
2222 } /* "for(packet_offset=0..." */
2223
2224 /* Low latency */
2225 if (need_flip)
2226 tty_flip_buffer_push(tty); 2090 tty_flip_buffer_push(tty);
2091 tty_kref_put(tty);
2092}
2227 2093
2228 if (packet_offset < urb->actual_length) { 2094static void ftdi_read_bulk_callback(struct urb *urb)
2229 /* not completely processed - record progress */ 2095{
2230 priv->rx_processed = packet_offset; 2096 struct usb_serial_port *port = urb->context;
2231 dbg("%s - incomplete, %d bytes processed, %d remain", 2097 unsigned long flags;
2232 __func__, packet_offset,
2233 urb->actual_length - packet_offset);
2234 /* check if we were throttled while processing */
2235 spin_lock_irqsave(&priv->rx_lock, flags);
2236 if (priv->rx_flags & THROTTLED) {
2237 priv->rx_flags |= ACTUALLY_THROTTLED;
2238 spin_unlock_irqrestore(&priv->rx_lock, flags);
2239 dbg("%s - deferring remainder until unthrottled",
2240 __func__);
2241 goto out;
2242 }
2243 spin_unlock_irqrestore(&priv->rx_lock, flags);
2244 /* if the port is closed stop trying to read */
2245 if (port->port.count > 0)
2246 /* delay processing of remainder */
2247 schedule_delayed_work(&priv->rx_work, 1);
2248 else
2249 dbg("%s - port is closed", __func__);
2250 goto out;
2251 }
2252
2253 /* urb is completely processed */
2254 priv->rx_processed = 0;
2255 2098
2256 /* if the port is closed stop trying to read */ 2099 dbg("%s - port %d", __func__, port->number);
2257 if (port->port.count > 0) {
2258 /* Continue trying to always read */
2259 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
2260 usb_rcvbulkpipe(port->serial->dev,
2261 port->bulk_in_endpointAddress),
2262 port->read_urb->transfer_buffer,
2263 port->read_urb->transfer_buffer_length,
2264 ftdi_read_bulk_callback, port);
2265 2100
2266 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 2101 if (urb->status) {
2267 if (result) 2102 dbg("%s - nonzero read bulk status received: %d",
2268 dev_err(&port->dev, 2103 __func__, urb->status);
2269 "%s - failed resubmitting read urb, error %d\n", 2104 return;
2270 __func__, result);
2271 } 2105 }
2272out:
2273 tty_kref_put(tty);
2274} /* ftdi_process_read */
2275 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}
2276 2119
2277static void ftdi_break_ctl(struct tty_struct *tty, int break_state) 2120static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
2278{ 2121{
@@ -2604,33 +2447,31 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2604static void ftdi_throttle(struct tty_struct *tty) 2447static void ftdi_throttle(struct tty_struct *tty)
2605{ 2448{
2606 struct usb_serial_port *port = tty->driver_data; 2449 struct usb_serial_port *port = tty->driver_data;
2607 struct ftdi_private *priv = usb_get_serial_port_data(port);
2608 unsigned long flags; 2450 unsigned long flags;
2609 2451
2610 dbg("%s - port %d", __func__, port->number); 2452 dbg("%s - port %d", __func__, port->number);
2611 2453
2612 spin_lock_irqsave(&priv->rx_lock, flags); 2454 spin_lock_irqsave(&port->lock, flags);
2613 priv->rx_flags |= THROTTLED; 2455 port->throttle_req = 1;
2614 spin_unlock_irqrestore(&priv->rx_lock, flags); 2456 spin_unlock_irqrestore(&port->lock, flags);
2615} 2457}
2616 2458
2617 2459void ftdi_unthrottle(struct tty_struct *tty)
2618static void ftdi_unthrottle(struct tty_struct *tty)
2619{ 2460{
2620 struct usb_serial_port *port = tty->driver_data; 2461 struct usb_serial_port *port = tty->driver_data;
2621 struct ftdi_private *priv = usb_get_serial_port_data(port); 2462 int was_throttled;
2622 int actually_throttled;
2623 unsigned long flags; 2463 unsigned long flags;
2624 2464
2625 dbg("%s - port %d", __func__, port->number); 2465 dbg("%s - port %d", __func__, port->number);
2626 2466
2627 spin_lock_irqsave(&priv->rx_lock, flags); 2467 spin_lock_irqsave(&port->lock, flags);
2628 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; 2468 was_throttled = port->throttled;
2629 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 2469 port->throttled = port->throttle_req = 0;
2630 spin_unlock_irqrestore(&priv->rx_lock, flags); 2470 spin_unlock_irqrestore(&port->lock, flags);
2631 2471
2632 if (actually_throttled) 2472 /* Resubmit urb if throttled and open. */
2633 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);
2634} 2475}
2635 2476
2636static int __init ftdi_init(void) 2477static int __init ftdi_init(void)