Lines 76-88
struct ftdi_private {
Link Here
|
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 |
|
Lines 737-746
static const char *ftdi_chip_name[] = {
Link Here
|
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) |
Lines 764-770
static int ftdi_write_room(struct tty_struct *tty);
Link Here
|
764 |
static int ftdi_chars_in_buffer(struct tty_struct *tty); |
754 |
static int ftdi_chars_in_buffer(struct tty_struct *tty); |
765 |
static void ftdi_write_bulk_callback(struct urb *urb); |
755 |
static void ftdi_write_bulk_callback(struct urb *urb); |
766 |
static void ftdi_read_bulk_callback(struct urb *urb); |
756 |
static void ftdi_read_bulk_callback(struct urb *urb); |
767 |
static void ftdi_process_read(struct work_struct *work); |
757 |
static void ftdi_process_read(struct usb_serial_port *port); |
768 |
static void ftdi_set_termios(struct tty_struct *tty, |
758 |
static void ftdi_set_termios(struct tty_struct *tty, |
769 |
struct usb_serial_port *port, struct ktermios *old); |
759 |
struct usb_serial_port *port, struct ktermios *old); |
770 |
static int ftdi_tiocmget(struct tty_struct *tty, struct file *file); |
760 |
static int ftdi_tiocmget(struct tty_struct *tty, struct file *file); |
Lines 1235-1241
static int set_serial_info(struct tty_struct *tty,
Link Here
|
1235 |
(new_serial.flags & ASYNC_FLAGS)); |
1225 |
(new_serial.flags & ASYNC_FLAGS)); |
1236 |
priv->custom_divisor = new_serial.custom_divisor; |
1226 |
priv->custom_divisor = new_serial.custom_divisor; |
1237 |
|
1227 |
|
1238 |
tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
|
|
1239 |
write_latency_timer(port); |
1228 |
write_latency_timer(port); |
1240 |
|
1229 |
|
1241 |
check_and_exit: |
1230 |
check_and_exit: |
Lines 1528-1534
static int ftdi_sio_port_probe(struct usb_serial_port *port)
Link Here
|
1528 |
} |
1517 |
} |
1529 |
|
1518 |
|
1530 |
kref_init(&priv->kref); |
1519 |
kref_init(&priv->kref); |
1531 |
spin_lock_init(&priv->rx_lock); |
|
|
1532 |
spin_lock_init(&priv->tx_lock); |
1520 |
spin_lock_init(&priv->tx_lock); |
1533 |
init_waitqueue_head(&priv->delta_msr_wait); |
1521 |
init_waitqueue_head(&priv->delta_msr_wait); |
1534 |
/* This will push the characters through immediately rather |
1522 |
/* This will push the characters through immediately rather |
Lines 1550-1556
static int ftdi_sio_port_probe(struct usb_serial_port *port)
Link Here
|
1550 |
port->read_urb->transfer_buffer_length = BUFSZ; |
1538 |
port->read_urb->transfer_buffer_length = BUFSZ; |
1551 |
} |
1539 |
} |
1552 |
|
1540 |
|
1553 |
INIT_DELAYED_WORK(&priv->rx_work, ftdi_process_read); |
|
|
1554 |
priv->port = port; |
1541 |
priv->port = port; |
1555 |
|
1542 |
|
1556 |
/* Free port's existing write urb and transfer buffer. */ |
1543 |
/* Free port's existing write urb and transfer buffer. */ |
Lines 1687-1692
static int ftdi_sio_port_remove(struct usb_serial_port *port)
Link Here
|
1687 |
return 0; |
1674 |
return 0; |
1688 |
} |
1675 |
} |
1689 |
|
1676 |
|
|
|
1677 |
static int ftdi_submit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) |
1678 |
{ |
1679 |
struct urb *urb = port->read_urb; |
1680 |
struct usb_serial *serial = port->serial; |
1681 |
int result; |
1682 |
|
1683 |
usb_fill_bulk_urb(urb, serial->dev, |
1684 |
usb_rcvbulkpipe(serial->dev, |
1685 |
port->bulk_in_endpointAddress), |
1686 |
urb->transfer_buffer, |
1687 |
urb->transfer_buffer_length, |
1688 |
ftdi_read_bulk_callback, port); |
1689 |
result = usb_submit_urb(urb, mem_flags); |
1690 |
if (result) |
1691 |
dev_err(&port->dev, |
1692 |
"%s - failed submitting read urb, error %d\n", |
1693 |
__func__, result); |
1694 |
return result; |
1695 |
} |
1696 |
|
1690 |
static int ftdi_open(struct tty_struct *tty, |
1697 |
static int ftdi_open(struct tty_struct *tty, |
1691 |
struct usb_serial_port *port, struct file *filp) |
1698 |
struct usb_serial_port *port, struct file *filp) |
1692 |
{ /* ftdi_open */ |
1699 |
{ /* ftdi_open */ |
Lines 1702-1713
static int ftdi_open(struct tty_struct *tty,
Link Here
|
1702 |
spin_lock_irqsave(&priv->tx_lock, flags); |
1709 |
spin_lock_irqsave(&priv->tx_lock, flags); |
1703 |
priv->tx_bytes = 0; |
1710 |
priv->tx_bytes = 0; |
1704 |
spin_unlock_irqrestore(&priv->tx_lock, flags); |
1711 |
spin_unlock_irqrestore(&priv->tx_lock, flags); |
1705 |
spin_lock_irqsave(&priv->rx_lock, flags); |
|
|
1706 |
priv->rx_bytes = 0; |
1707 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
1708 |
|
1709 |
if (tty) |
1710 |
tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
1711 |
|
1712 |
|
1712 |
write_latency_timer(port); |
1713 |
write_latency_timer(port); |
1713 |
|
1714 |
|
Lines 1727-1749
static int ftdi_open(struct tty_struct *tty,
Link Here
|
1727 |
ftdi_set_termios(tty, port, tty->termios); |
1728 |
ftdi_set_termios(tty, port, tty->termios); |
1728 |
|
1729 |
|
1729 |
/* Not throttled */ |
1730 |
/* Not throttled */ |
1730 |
spin_lock_irqsave(&priv->rx_lock, flags); |
1731 |
spin_lock_irqsave(&port->lock, flags); |
1731 |
priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); |
1732 |
port->throttled = 0; |
1732 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
1733 |
port->throttle_req = 0; |
|
|
1734 |
spin_unlock_irqrestore(&port->lock, flags); |
1733 |
|
1735 |
|
1734 |
/* Start reading from the device */ |
1736 |
/* Start reading from the device */ |
1735 |
priv->rx_processed = 0; |
1737 |
result = ftdi_submit_read_urb(port, GFP_KERNEL); |
1736 |
usb_fill_bulk_urb(port->read_urb, dev, |
1738 |
if (!result) |
1737 |
usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress), |
|
|
1738 |
port->read_urb->transfer_buffer, |
1739 |
port->read_urb->transfer_buffer_length, |
1740 |
ftdi_read_bulk_callback, port); |
1741 |
result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
1742 |
if (result) |
1743 |
dev_err(&port->dev, |
1744 |
"%s - failed submitting read urb, error %d\n", |
1745 |
__func__, result); |
1746 |
else |
1747 |
kref_get(&priv->kref); |
1739 |
kref_get(&priv->kref); |
1748 |
|
1740 |
|
1749 |
return result; |
1741 |
return result; |
Lines 1789-1798
static void ftdi_close(struct usb_serial_port *port)
Link Here
|
1789 |
|
1781 |
|
1790 |
dbg("%s", __func__); |
1782 |
dbg("%s", __func__); |
1791 |
|
1783 |
|
1792 |
|
|
|
1793 |
/* cancel any scheduled reading */ |
1794 |
cancel_delayed_work_sync(&priv->rx_work); |
1795 |
|
1796 |
/* shutdown our bulk read */ |
1784 |
/* shutdown our bulk read */ |
1797 |
usb_kill_urb(port->read_urb); |
1785 |
usb_kill_urb(port->read_urb); |
1798 |
kref_put(&priv->kref, ftdi_sio_priv_release); |
1786 |
kref_put(&priv->kref, ftdi_sio_priv_release); |
Lines 2015-2285
static int ftdi_chars_in_buffer(struct tty_struct *tty)
Link Here
|
2015 |
return buffered; |
2003 |
return buffered; |
2016 |
} |
2004 |
} |
2017 |
|
2005 |
|
2018 |
static void ftdi_read_bulk_callback(struct urb *urb) |
2006 |
static int ftdi_process_packet(struct tty_struct *tty, |
|
|
2007 |
struct usb_serial_port *port, struct ftdi_private *priv, |
2008 |
char *packet, int len) |
2019 |
{ |
2009 |
{ |
2020 |
struct usb_serial_port *port = urb->context; |
2010 |
int i; |
2021 |
struct tty_struct *tty; |
2011 |
char status; |
2022 |
struct ftdi_private *priv; |
2012 |
char flag; |
2023 |
unsigned long countread; |
2013 |
char *ch; |
2024 |
unsigned long flags; |
|
|
2025 |
int status = urb->status; |
2026 |
|
2027 |
if (urb->number_of_packets > 0) { |
2028 |
dev_err(&port->dev, "%s transfer_buffer_length %d " |
2029 |
"actual_length %d number of packets %d\n", __func__, |
2030 |
urb->transfer_buffer_length, |
2031 |
urb->actual_length, urb->number_of_packets); |
2032 |
dev_err(&port->dev, "%s transfer_flags %x\n", __func__, |
2033 |
urb->transfer_flags); |
2034 |
} |
2035 |
|
2014 |
|
2036 |
dbg("%s - port %d", __func__, port->number); |
2015 |
dbg("%s - port %d", __func__, port->number); |
2037 |
|
2016 |
|
2038 |
if (port->port.count <= 0) |
2017 |
if (len < 2) { |
2039 |
return; |
2018 |
dbg("malformed packet"); |
2040 |
|
2019 |
return 0; |
2041 |
tty = tty_port_tty_get(&port->port); |
|
|
2042 |
if (!tty) { |
2043 |
dbg("%s - bad tty pointer - exiting", __func__); |
2044 |
return; |
2045 |
} |
2020 |
} |
2046 |
|
2021 |
|
2047 |
priv = usb_get_serial_port_data(port); |
2022 |
/* Compare new line status to the old one, signal if different/ |
2048 |
if (!priv) { |
2023 |
N.B. packet may be processed more than once, but differences |
2049 |
dbg("%s - bad port private data pointer - exiting", __func__); |
2024 |
are only processed once. */ |
2050 |
goto out; |
2025 |
status = packet[0] & FTDI_STATUS_B0_MASK; |
|
|
2026 |
if (status != priv->prev_status) { |
2027 |
priv->diff_status |= status ^ priv->prev_status; |
2028 |
wake_up_interruptible(&priv->delta_msr_wait); |
2029 |
priv->prev_status = status; |
2051 |
} |
2030 |
} |
2052 |
|
2031 |
|
2053 |
if (urb != port->read_urb) |
2032 |
/* |
2054 |
dev_err(&port->dev, "%s - Not my urb!\n", __func__); |
2033 |
* Although the device uses a bitmask and hence can have multiple |
2055 |
|
2034 |
* errors on a packet - the order here sets the priority the error is |
2056 |
if (status) { |
2035 |
* returned to the tty layer. |
2057 |
/* This will happen at close every time so it is a dbg not an |
2036 |
*/ |
2058 |
err */ |
2037 |
flag = TTY_NORMAL; |
2059 |
dbg("(this is ok on close) nonzero read bulk status received: %d", status); |
2038 |
if (packet[1] & FTDI_RS_OE) { |
2060 |
goto out; |
2039 |
flag = TTY_OVERRUN; |
|
|
2040 |
dbg("OVERRRUN error"); |
2041 |
} |
2042 |
if (packet[1] & FTDI_RS_BI) { |
2043 |
flag = TTY_BREAK; |
2044 |
dbg("BREAK received"); |
2045 |
usb_serial_handle_break(port); |
2046 |
} |
2047 |
if (packet[1] & FTDI_RS_PE) { |
2048 |
flag = TTY_PARITY; |
2049 |
dbg("PARITY error"); |
2050 |
} |
2051 |
if (packet[1] & FTDI_RS_FE) { |
2052 |
flag = TTY_FRAME; |
2053 |
dbg("FRAMING error"); |
2061 |
} |
2054 |
} |
2062 |
|
2055 |
|
2063 |
/* count data bytes, but not status bytes */ |
2056 |
len -= 2; |
2064 |
countread = urb->actual_length; |
2057 |
if (!len) |
2065 |
countread -= 2 * DIV_ROUND_UP(countread, priv->max_packet_size); |
2058 |
return 0; /* status only */ |
2066 |
spin_lock_irqsave(&priv->rx_lock, flags); |
2059 |
ch = packet + 2; |
2067 |
priv->rx_bytes += countread; |
2060 |
|
2068 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
2061 |
if (!(port->console && port->sysrq) && flag == TTY_NORMAL) |
2069 |
|
2062 |
tty_insert_flip_string(tty, ch, len); |
2070 |
ftdi_process_read(&priv->rx_work.work); |
2063 |
else { |
2071 |
out: |
2064 |
for (i = 0; i < len; i++, ch++) { |
2072 |
tty_kref_put(tty); |
2065 |
if (!usb_serial_handle_sysrq_char(tty, port, *ch)) |
2073 |
} /* ftdi_read_bulk_callback */ |
2066 |
tty_insert_flip_char(tty, *ch, flag); |
2074 |
|
2067 |
} |
|
|
2068 |
} |
2069 |
return len; |
2070 |
} |
2075 |
|
2071 |
|
2076 |
static void ftdi_process_read(struct work_struct *work) |
2072 |
static void ftdi_process_read(struct usb_serial_port *port) |
2077 |
{ /* ftdi_process_read */ |
2073 |
{ |
2078 |
struct ftdi_private *priv = |
2074 |
struct urb *urb = port->read_urb; |
2079 |
container_of(work, struct ftdi_private, rx_work.work); |
|
|
2080 |
struct usb_serial_port *port = priv->port; |
2081 |
struct urb *urb; |
2082 |
struct tty_struct *tty; |
2075 |
struct tty_struct *tty; |
2083 |
char error_flag; |
2076 |
struct ftdi_private *priv = usb_get_serial_port_data(port); |
2084 |
unsigned char *data; |
2077 |
char *data = (char *)urb->transfer_buffer; |
2085 |
|
|
|
2086 |
int i; |
2078 |
int i; |
2087 |
int result; |
2079 |
int len; |
2088 |
int need_flip; |
2080 |
int count = 0; |
2089 |
int packet_offset; |
|
|
2090 |
unsigned long flags; |
2091 |
|
2092 |
dbg("%s - port %d", __func__, port->number); |
2093 |
|
2094 |
if (port->port.count <= 0) |
2095 |
return; |
2096 |
|
2081 |
|
2097 |
tty = tty_port_tty_get(&port->port); |
2082 |
tty = tty_port_tty_get(&port->port); |
2098 |
if (!tty) { |
2083 |
if (!tty) |
2099 |
dbg("%s - bad tty pointer - exiting", __func__); |
|
|
2100 |
return; |
2084 |
return; |
2101 |
} |
|
|
2102 |
|
2103 |
priv = usb_get_serial_port_data(port); |
2104 |
if (!priv) { |
2105 |
dbg("%s - bad port private data pointer - exiting", __func__); |
2106 |
goto out; |
2107 |
} |
2108 |
|
2109 |
urb = port->read_urb; |
2110 |
if (!urb) { |
2111 |
dbg("%s - bad read_urb pointer - exiting", __func__); |
2112 |
goto out; |
2113 |
} |
2114 |
|
2115 |
data = urb->transfer_buffer; |
2116 |
|
2085 |
|
2117 |
if (priv->rx_processed) { |
2086 |
for (i = 0; i < urb->actual_length; i += priv->max_packet_size) { |
2118 |
dbg("%s - already processed: %d bytes, %d remain", __func__, |
2087 |
len = min_t(int, urb->actual_length - i, priv->max_packet_size); |
2119 |
priv->rx_processed, |
2088 |
count += ftdi_process_packet(tty, port, priv, &data[i], len); |
2120 |
urb->actual_length - priv->rx_processed); |
|
|
2121 |
} else { |
2122 |
/* The first two bytes of every read packet are status */ |
2123 |
if (urb->actual_length > 2) |
2124 |
usb_serial_debug_data(debug, &port->dev, __func__, |
2125 |
urb->actual_length, data); |
2126 |
else |
2127 |
dbg("Status only: %03oo %03oo", data[0], data[1]); |
2128 |
} |
2089 |
} |
2129 |
|
2090 |
|
2130 |
|
2091 |
if (count) |
2131 |
/* TO DO -- check for hung up line and handle appropriately: */ |
|
|
2132 |
/* send hangup */ |
2133 |
/* See acm.c - you do a tty_hangup - eg tty_hangup(tty) */ |
2134 |
/* if CD is dropped and the line is not CLOCAL then we should hangup */ |
2135 |
|
2136 |
need_flip = 0; |
2137 |
for (packet_offset = priv->rx_processed; |
2138 |
packet_offset < urb->actual_length; packet_offset += priv->max_packet_size) { |
2139 |
int length; |
2140 |
|
2141 |
/* Compare new line status to the old one, signal if different/ |
2142 |
N.B. packet may be processed more than once, but differences |
2143 |
are only processed once. */ |
2144 |
char new_status = data[packet_offset + 0] & |
2145 |
FTDI_STATUS_B0_MASK; |
2146 |
if (new_status != priv->prev_status) { |
2147 |
priv->diff_status |= |
2148 |
new_status ^ priv->prev_status; |
2149 |
wake_up_interruptible(&priv->delta_msr_wait); |
2150 |
priv->prev_status = new_status; |
2151 |
} |
2152 |
|
2153 |
length = min_t(u32, priv->max_packet_size, urb->actual_length-packet_offset)-2; |
2154 |
if (length < 0) { |
2155 |
dev_err(&port->dev, "%s - bad packet length: %d\n", |
2156 |
__func__, length+2); |
2157 |
length = 0; |
2158 |
} |
2159 |
|
2160 |
if (priv->rx_flags & THROTTLED) { |
2161 |
dbg("%s - throttled", __func__); |
2162 |
break; |
2163 |
} |
2164 |
if (tty_buffer_request_room(tty, length) < length) { |
2165 |
/* break out & wait for throttling/unthrottling to |
2166 |
happen */ |
2167 |
dbg("%s - receive room low", __func__); |
2168 |
break; |
2169 |
} |
2170 |
|
2171 |
/* Handle errors and break */ |
2172 |
error_flag = TTY_NORMAL; |
2173 |
/* Although the device uses a bitmask and hence can have |
2174 |
multiple errors on a packet - the order here sets the |
2175 |
priority the error is returned to the tty layer */ |
2176 |
|
2177 |
if (data[packet_offset+1] & FTDI_RS_OE) { |
2178 |
error_flag = TTY_OVERRUN; |
2179 |
dbg("OVERRRUN error"); |
2180 |
} |
2181 |
if (data[packet_offset+1] & FTDI_RS_BI) { |
2182 |
error_flag = TTY_BREAK; |
2183 |
dbg("BREAK received"); |
2184 |
usb_serial_handle_break(port); |
2185 |
} |
2186 |
if (data[packet_offset+1] & FTDI_RS_PE) { |
2187 |
error_flag = TTY_PARITY; |
2188 |
dbg("PARITY error"); |
2189 |
} |
2190 |
if (data[packet_offset+1] & FTDI_RS_FE) { |
2191 |
error_flag = TTY_FRAME; |
2192 |
dbg("FRAMING error"); |
2193 |
} |
2194 |
if (length > 0) { |
2195 |
for (i = 2; i < length+2; i++) { |
2196 |
/* Note that the error flag is duplicated for |
2197 |
every character received since we don't know |
2198 |
which character it applied to */ |
2199 |
if (!usb_serial_handle_sysrq_char(tty, port, |
2200 |
data[packet_offset + i])) |
2201 |
tty_insert_flip_char(tty, |
2202 |
data[packet_offset + i], |
2203 |
error_flag); |
2204 |
} |
2205 |
need_flip = 1; |
2206 |
} |
2207 |
|
2208 |
#ifdef NOT_CORRECT_BUT_KEEPING_IT_FOR_NOW |
2209 |
/* if a parity error is detected you get status packets forever |
2210 |
until a character is sent without a parity error. |
2211 |
This doesn't work well since the application receives a |
2212 |
never ending stream of bad data - even though new data |
2213 |
hasn't been sent. Therefore I (bill) have taken this out. |
2214 |
However - this might make sense for framing errors and so on |
2215 |
so I am leaving the code in for now. |
2216 |
*/ |
2217 |
else { |
2218 |
if (error_flag != TTY_NORMAL) { |
2219 |
dbg("error_flag is not normal"); |
2220 |
/* In this case it is just status - if that is |
2221 |
an error send a bad character */ |
2222 |
if (tty->flip.count >= TTY_FLIPBUF_SIZE) |
2223 |
tty_flip_buffer_push(tty); |
2224 |
tty_insert_flip_char(tty, 0xff, error_flag); |
2225 |
need_flip = 1; |
2226 |
} |
2227 |
} |
2228 |
#endif |
2229 |
} /* "for(packet_offset=0..." */ |
2230 |
|
2231 |
/* Low latency */ |
2232 |
if (need_flip) |
2233 |
tty_flip_buffer_push(tty); |
2092 |
tty_flip_buffer_push(tty); |
|
|
2093 |
tty_kref_put(tty); |
2094 |
} |
2234 |
|
2095 |
|
2235 |
if (packet_offset < urb->actual_length) { |
2096 |
static void ftdi_read_bulk_callback(struct urb *urb) |
2236 |
/* not completely processed - record progress */ |
2097 |
{ |
2237 |
priv->rx_processed = packet_offset; |
2098 |
struct usb_serial_port *port = urb->context; |
2238 |
dbg("%s - incomplete, %d bytes processed, %d remain", |
2099 |
unsigned long flags; |
2239 |
__func__, packet_offset, |
|
|
2240 |
urb->actual_length - packet_offset); |
2241 |
/* check if we were throttled while processing */ |
2242 |
spin_lock_irqsave(&priv->rx_lock, flags); |
2243 |
if (priv->rx_flags & THROTTLED) { |
2244 |
priv->rx_flags |= ACTUALLY_THROTTLED; |
2245 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
2246 |
dbg("%s - deferring remainder until unthrottled", |
2247 |
__func__); |
2248 |
goto out; |
2249 |
} |
2250 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
2251 |
/* if the port is closed stop trying to read */ |
2252 |
if (port->port.count > 0) |
2253 |
/* delay processing of remainder */ |
2254 |
schedule_delayed_work(&priv->rx_work, 1); |
2255 |
else |
2256 |
dbg("%s - port is closed", __func__); |
2257 |
goto out; |
2258 |
} |
2259 |
|
2260 |
/* urb is completely processed */ |
2261 |
priv->rx_processed = 0; |
2262 |
|
2100 |
|
2263 |
/* if the port is closed stop trying to read */ |
2101 |
dbg("%s - port %d", __func__, port->number); |
2264 |
if (port->port.count > 0) { |
|
|
2265 |
/* Continue trying to always read */ |
2266 |
usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
2267 |
usb_rcvbulkpipe(port->serial->dev, |
2268 |
port->bulk_in_endpointAddress), |
2269 |
port->read_urb->transfer_buffer, |
2270 |
port->read_urb->transfer_buffer_length, |
2271 |
ftdi_read_bulk_callback, port); |
2272 |
|
2102 |
|
2273 |
result = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
2103 |
if (urb->status) { |
2274 |
if (result) |
2104 |
dbg("%s - nonzero read bulk status received: %d", |
2275 |
dev_err(&port->dev, |
2105 |
__func__, urb->status); |
2276 |
"%s - failed resubmitting read urb, error %d\n", |
2106 |
return; |
2277 |
__func__, result); |
|
|
2278 |
} |
2107 |
} |
2279 |
out: |
|
|
2280 |
tty_kref_put(tty); |
2281 |
} /* ftdi_process_read */ |
2282 |
|
2108 |
|
|
|
2109 |
usb_serial_debug_data(debug, &port->dev, __func__, |
2110 |
urb->actual_length, urb->transfer_buffer); |
2111 |
ftdi_process_read(port); |
2112 |
|
2113 |
spin_lock_irqsave(&port->lock, flags); |
2114 |
port->throttled = port->throttle_req; |
2115 |
if (!port->throttled) { |
2116 |
spin_unlock_irqrestore(&port->lock, flags); |
2117 |
ftdi_submit_read_urb(port, GFP_ATOMIC); |
2118 |
} else |
2119 |
spin_unlock_irqrestore(&port->lock, flags); |
2120 |
} |
2283 |
|
2121 |
|
2284 |
static void ftdi_break_ctl(struct tty_struct *tty, int break_state) |
2122 |
static void ftdi_break_ctl(struct tty_struct *tty, int break_state) |
2285 |
{ |
2123 |
{ |
Lines 2611-2643
static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
Link Here
|
2611 |
static void ftdi_throttle(struct tty_struct *tty) |
2449 |
static void ftdi_throttle(struct tty_struct *tty) |
2612 |
{ |
2450 |
{ |
2613 |
struct usb_serial_port *port = tty->driver_data; |
2451 |
struct usb_serial_port *port = tty->driver_data; |
2614 |
struct ftdi_private *priv = usb_get_serial_port_data(port); |
|
|
2615 |
unsigned long flags; |
2452 |
unsigned long flags; |
2616 |
|
2453 |
|
2617 |
dbg("%s - port %d", __func__, port->number); |
2454 |
dbg("%s - port %d", __func__, port->number); |
2618 |
|
2455 |
|
2619 |
spin_lock_irqsave(&priv->rx_lock, flags); |
2456 |
spin_lock_irqsave(&port->lock, flags); |
2620 |
priv->rx_flags |= THROTTLED; |
2457 |
port->throttle_req = 1; |
2621 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
2458 |
spin_unlock_irqrestore(&port->lock, flags); |
2622 |
} |
2459 |
} |
2623 |
|
2460 |
|
2624 |
|
2461 |
void ftdi_unthrottle(struct tty_struct *tty) |
2625 |
static void ftdi_unthrottle(struct tty_struct *tty) |
|
|
2626 |
{ |
2462 |
{ |
2627 |
struct usb_serial_port *port = tty->driver_data; |
2463 |
struct usb_serial_port *port = tty->driver_data; |
2628 |
struct ftdi_private *priv = usb_get_serial_port_data(port); |
2464 |
int was_throttled; |
2629 |
int actually_throttled; |
|
|
2630 |
unsigned long flags; |
2465 |
unsigned long flags; |
2631 |
|
2466 |
|
2632 |
dbg("%s - port %d", __func__, port->number); |
2467 |
dbg("%s - port %d", __func__, port->number); |
2633 |
|
2468 |
|
2634 |
spin_lock_irqsave(&priv->rx_lock, flags); |
2469 |
spin_lock_irqsave(&port->lock, flags); |
2635 |
actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED; |
2470 |
was_throttled = port->throttled; |
2636 |
priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); |
2471 |
port->throttled = port->throttle_req = 0; |
2637 |
spin_unlock_irqrestore(&priv->rx_lock, flags); |
2472 |
spin_unlock_irqrestore(&port->lock, flags); |
2638 |
|
2473 |
|
2639 |
if (actually_throttled) |
2474 |
/* Resubmit urb if throttled and open. */ |
2640 |
schedule_delayed_work(&priv->rx_work, 0); |
2475 |
if (was_throttled && test_bit(ASYNCB_INITIALIZED, &port->port.flags)) |
|
|
2476 |
ftdi_submit_read_urb(port, GFP_KERNEL); |
2641 |
} |
2477 |
} |
2642 |
|
2478 |
|
2643 |
static int __init ftdi_init(void) |
2479 |
static int __init ftdi_init(void) |