aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:25:51 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:26:01 -0500
commitd2fde28ce793c09c1ea36d981cb6765174fd1eea (patch)
treed1922f6572702374900dace5dcbb9d794fecc522
parent609e5b71d0eca163df017ecfcf917b149875e744 (diff)
parente65f0f8271b1b0452334e5da37fd35413a000de4 (diff)
Merge branch 'tty-updates' from Alan
* tty-updates: (75 commits) serial_8250: support for Sealevel Systems Model 7803 COMM+8 hso maintainers update patch hso modem detect fix patch against Alan Cox'es tty tree tty: Fix an ircomm warning and note another bug drivers/char/cyclades.c: cy_pci_probe: fix error path Serial: UART driver changes for Cavium OCTEON. Serial: Allow port type to be specified when calling serial8250_register_port. 8250: Serial driver changes to support future Cavium OCTEON serial patches. 8250: Don't clobber spinlocks. fix for tty-serial-move-port tty: We want the port object to be persistent __FUNCTION__ is gcc-specific, use __func__ serial: RS485 ioctl structure uses __u32 include linux/types.h tty: Drop the lock_kernel in the private ioctl hook synclink_cs: Convert to tty_port tty: use port methods for the rocket driver tty: kref the rocket driver tty: make rocketport use standard port->flags tty: Redo the rocket driver locking tty: Make epca use the port helpers ...
-rw-r--r--Documentation/filesystems/devpts.txt132
-rw-r--r--MAINTAINERS6
-rw-r--r--drivers/char/Kconfig13
-rw-r--r--drivers/char/amiserial.c34
-rw-r--r--drivers/char/cyclades.c2
-rw-r--r--drivers/char/epca.c265
-rw-r--r--drivers/char/esp.c61
-rw-r--r--drivers/char/generic_serial.c76
-rw-r--r--drivers/char/hvc_console.c2
-rw-r--r--drivers/char/hvsi.c12
-rw-r--r--drivers/char/isicom.c166
-rw-r--r--drivers/char/istallion.c221
-rw-r--r--drivers/char/moxa.c26
-rw-r--r--drivers/char/mxser.c150
-rw-r--r--drivers/char/n_r3964.c12
-rw-r--r--drivers/char/n_tty.c792
-rw-r--r--drivers/char/nozomi.c85
-rw-r--r--drivers/char/pcmcia/synclink_cs.c479
-rw-r--r--drivers/char/pty.c57
-rw-r--r--drivers/char/rio/rio_linux.c35
-rw-r--r--drivers/char/riscom8.c194
-rw-r--r--drivers/char/rocket.c320
-rw-r--r--drivers/char/rocket.h2
-rw-r--r--drivers/char/rocket_int.h5
-rw-r--r--drivers/char/selection.c2
-rw-r--r--drivers/char/ser_a2232.c23
-rw-r--r--drivers/char/serial167.c32
-rw-r--r--drivers/char/specialix.c34
-rw-r--r--drivers/char/stallion.c169
-rw-r--r--drivers/char/sx.c31
-rw-r--r--drivers/char/synclink.c177
-rw-r--r--drivers/char/synclink_gt.c120
-rw-r--r--drivers/char/synclinkmp.c171
-rw-r--r--drivers/char/tty_io.c39
-rw-r--r--drivers/char/tty_ldisc.c30
-rw-r--r--drivers/char/tty_port.c225
-rw-r--r--drivers/char/vme_scc.c27
-rw-r--r--drivers/char/vt.c16
-rw-r--r--drivers/char/vt_ioctl.c2
-rw-r--r--drivers/net/usb/hso.c434
-rw-r--r--drivers/serial/8250.c225
-rw-r--r--drivers/serial/8250_pci.c134
-rw-r--r--drivers/serial/bfin_5xx.c239
-rw-r--r--drivers/serial/bfin_sport_uart.c60
-rw-r--r--drivers/serial/jsm/jsm_tty.c2
-rw-r--r--drivers/serial/serial_core.c155
-rw-r--r--drivers/usb/serial/console.c13
-rw-r--r--drivers/usb/serial/ftdi_sio.c9
-rw-r--r--drivers/usb/serial/kl5kusb105.c1
-rw-r--r--drivers/usb/serial/mct_u232.c2
-rw-r--r--drivers/usb/serial/mos7840.c3
-rw-r--r--drivers/usb/serial/sierra.c2
-rw-r--r--drivers/usb/serial/usb-serial.c26
-rw-r--r--fs/devpts/inode.c472
-rw-r--r--include/linux/8250_pci.h2
-rw-r--r--include/linux/generic_serial.h1
-rw-r--r--include/linux/istallion.h2
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/serial.h3
-rw-r--r--include/linux/serial_8250.h3
-rw-r--r--include/linux/serial_core.h69
-rw-r--r--include/linux/tty.h27
-rw-r--r--include/linux/tty_driver.h6
-rw-r--r--net/irda/ircomm/ircomm_tty.c5
64 files changed, 3538 insertions, 2604 deletions
diff --git a/Documentation/filesystems/devpts.txt b/Documentation/filesystems/devpts.txt
new file mode 100644
index 000000000000..68dffd87f9b7
--- /dev/null
+++ b/Documentation/filesystems/devpts.txt
@@ -0,0 +1,132 @@
1
2To support containers, we now allow multiple instances of devpts filesystem,
3such that indices of ptys allocated in one instance are independent of indices
4allocated in other instances of devpts.
5
6To preserve backward compatibility, this support for multiple instances is
7enabled only if:
8
9 - CONFIG_DEVPTS_MULTIPLE_INSTANCES=y, and
10 - '-o newinstance' mount option is specified while mounting devpts
11
12IOW, devpts now supports both single-instance and multi-instance semantics.
13
14If CONFIG_DEVPTS_MULTIPLE_INSTANCES=n, there is no change in behavior and
15this referred to as the "legacy" mode. In this mode, the new mount options
16(-o newinstance and -o ptmxmode) will be ignored with a 'bogus option' message
17on console.
18
19If CONFIG_DEVPTS_MULTIPLE_INSTANCES=y and devpts is mounted without the
20'newinstance' option (as in current start-up scripts) the new mount binds
21to the initial kernel mount of devpts. This mode is referred to as the
22'single-instance' mode and the current, single-instance semantics are
23preserved, i.e PTYs are common across the system.
24
25The only difference between this single-instance mode and the legacy mode
26is the presence of new, '/dev/pts/ptmx' node with permissions 0000, which
27can safely be ignored.
28
29If CONFIG_DEVPTS_MULTIPLE_INSTANCES=y and 'newinstance' option is specified,
30the mount is considered to be in the multi-instance mode and a new instance
31of the devpts fs is created. Any ptys created in this instance are independent
32of ptys in other instances of devpts. Like in the single-instance mode, the
33/dev/pts/ptmx node is present. To effectively use the multi-instance mode,
34open of /dev/ptmx must be a redirected to '/dev/pts/ptmx' using a symlink or
35bind-mount.
36
37Eg: A container startup script could do the following:
38
39 $ chmod 0666 /dev/pts/ptmx
40 $ rm /dev/ptmx
41 $ ln -s pts/ptmx /dev/ptmx
42 $ ns_exec -cm /bin/bash
43
44 # We are now in new container
45
46 $ umount /dev/pts
47 $ mount -t devpts -o newinstance lxcpts /dev/pts
48 $ sshd -p 1234
49
50where 'ns_exec -cm /bin/bash' calls clone() with CLONE_NEWNS flag and execs
51/bin/bash in the child process. A pty created by the sshd is not visible in
52the original mount of /dev/pts.
53
54User-space changes
55------------------
56
57In multi-instance mode (i.e '-o newinstance' mount option is specified at least
58once), following user-space issues should be noted.
59
601. If -o newinstance mount option is never used, /dev/pts/ptmx can be ignored
61 and no change is needed to system-startup scripts.
62
632. To effectively use multi-instance mode (i.e -o newinstance is specified)
64 administrators or startup scripts should "redirect" open of /dev/ptmx to
65 /dev/pts/ptmx using either a bind mount or symlink.
66
67 $ mount -t devpts -o newinstance devpts /dev/pts
68
69 followed by either
70
71 $ rm /dev/ptmx
72 $ ln -s pts/ptmx /dev/ptmx
73 $ chmod 666 /dev/pts/ptmx
74 or
75 $ mount -o bind /dev/pts/ptmx /dev/ptmx
76
773. The '/dev/ptmx -> pts/ptmx' symlink is the preferred method since it
78 enables better error-reporting and treats both single-instance and
79 multi-instance mounts similarly.
80
81 But this method requires that system-startup scripts set the mode of
82 /dev/pts/ptmx correctly (default mode is 0000). The scripts can set the
83 mode by, either
84
85 - adding ptmxmode mount option to devpts entry in /etc/fstab, or
86 - using 'chmod 0666 /dev/pts/ptmx'
87
884. If multi-instance mode mount is needed for containers, but the system
89 startup scripts have not yet been updated, container-startup scripts
90 should bind mount /dev/ptmx to /dev/pts/ptmx to avoid breaking single-
91 instance mounts.
92
93 Or, in general, container-startup scripts should use:
94
95 mount -t devpts -o newinstance -o ptmxmode=0666 devpts /dev/pts
96 if [ ! -L /dev/ptmx ]; then
97 mount -o bind /dev/pts/ptmx /dev/ptmx
98 fi
99
100 When all devpts mounts are multi-instance, /dev/ptmx can permanently be
101 a symlink to pts/ptmx and the bind mount can be ignored.
102
1035. A multi-instance mount that is not accompanied by the /dev/ptmx to
104 /dev/pts/ptmx redirection would result in an unusable/unreachable pty.
105
106 mount -t devpts -o newinstance lxcpts /dev/pts
107
108 immediately followed by:
109
110 open("/dev/ptmx")
111
112 would create a pty, say /dev/pts/7, in the initial kernel mount.
113 But /dev/pts/7 would be invisible in the new mount.
114
1156. The permissions for /dev/pts/ptmx node should be specified when mounting
116 /dev/pts, using the '-o ptmxmode=%o' mount option (default is 0000).
117
118 mount -t devpts -o newinstance -o ptmxmode=0644 devpts /dev/pts
119
120 The permissions can be later be changed as usual with 'chmod'.
121
122 chmod 666 /dev/pts/ptmx
123
1247. A mount of devpts without the 'newinstance' option results in binding to
125 initial kernel mount. This behavior while preserving legacy semantics,
126 does not provide strict isolation in a container environment. i.e by
127 mounting devpts without the 'newinstance' option, a container could
128 get visibility into the 'host' or root container's devpts.
129
130 To workaround this and have strict isolation, all mounts of devpts,
131 including the mount in the root container, should use the newinstance
132 option.
diff --git a/MAINTAINERS b/MAINTAINERS
index ceb32ee51f9d..d5fc534a1085 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2049,6 +2049,12 @@ M: mikulas@artax.karlin.mff.cuni.cz
2049W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi 2049W: http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi
2050S: Maintained 2050S: Maintained
2051 2051
2052HSO 3G Modem Driver (hso.c)
2053P: Denis Joseph Barrow
2054M: d.barow@option.com
2055W: http://www.pharscape.org
2056S: Maintained
2057
2052HTCPEN TOUCHSCREEN DRIVER 2058HTCPEN TOUCHSCREEN DRIVER
2053P: Pau Oliva Fora 2059P: Pau Oliva Fora
2054M: pof@eslack.org 2060M: pof@eslack.org
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index c602b547cc6e..1697043119bd 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -190,7 +190,7 @@ config DIGIEPCA
190 190
191config ESPSERIAL 191config ESPSERIAL
192 tristate "Hayes ESP serial port support" 192 tristate "Hayes ESP serial port support"
193 depends on SERIAL_NONSTANDARD && ISA && ISA_DMA_API 193 depends on SERIAL_NONSTANDARD && ISA && ISA_DMA_API && BROKEN
194 help 194 help
195 This is a driver which supports Hayes ESP serial ports. Both single 195 This is a driver which supports Hayes ESP serial ports. Both single
196 port cards and multiport cards are supported. Make sure to read 196 port cards and multiport cards are supported. Make sure to read
@@ -443,6 +443,17 @@ config UNIX98_PTYS
443 All modern Linux systems use the Unix98 ptys. Say Y unless 443 All modern Linux systems use the Unix98 ptys. Say Y unless
444 you're on an embedded system and want to conserve memory. 444 you're on an embedded system and want to conserve memory.
445 445
446config DEVPTS_MULTIPLE_INSTANCES
447 bool "Support multiple instances of devpts"
448 depends on UNIX98_PTYS
449 default n
450 ---help---
451 Enable support for multiple instances of devpts filesystem.
452 If you want to have isolated PTY namespaces (eg: in containers),
453 say Y here. Otherwise, say N. If enabled, each mount of devpts
454 filesystem with the '-o newinstance' option will create an
455 independent PTY namespace.
456
446config LEGACY_PTYS 457config LEGACY_PTYS
447 bool "Legacy (BSD) PTY support" 458 bool "Legacy (BSD) PTY support"
448 default y 459 default y
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index b97aebd7aeb8..4e0cfdeab146 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -170,7 +170,7 @@ static __inline__ void rtsdtr_ctrl(int bits)
170 */ 170 */
171static void rs_stop(struct tty_struct *tty) 171static void rs_stop(struct tty_struct *tty)
172{ 172{
173 struct async_struct *info = (struct async_struct *)tty->driver_data; 173 struct async_struct *info = tty->driver_data;
174 unsigned long flags; 174 unsigned long flags;
175 175
176 if (serial_paranoia_check(info, tty->name, "rs_stop")) 176 if (serial_paranoia_check(info, tty->name, "rs_stop"))
@@ -190,7 +190,7 @@ static void rs_stop(struct tty_struct *tty)
190 190
191static void rs_start(struct tty_struct *tty) 191static void rs_start(struct tty_struct *tty)
192{ 192{
193 struct async_struct *info = (struct async_struct *)tty->driver_data; 193 struct async_struct *info = tty->driver_data;
194 unsigned long flags; 194 unsigned long flags;
195 195
196 if (serial_paranoia_check(info, tty->name, "rs_start")) 196 if (serial_paranoia_check(info, tty->name, "rs_start"))
@@ -861,7 +861,7 @@ static int rs_put_char(struct tty_struct *tty, unsigned char ch)
861 861
862static void rs_flush_chars(struct tty_struct *tty) 862static void rs_flush_chars(struct tty_struct *tty)
863{ 863{
864 struct async_struct *info = (struct async_struct *)tty->driver_data; 864 struct async_struct *info = tty->driver_data;
865 unsigned long flags; 865 unsigned long flags;
866 866
867 if (serial_paranoia_check(info, tty->name, "rs_flush_chars")) 867 if (serial_paranoia_check(info, tty->name, "rs_flush_chars"))
@@ -934,7 +934,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
934 934
935static int rs_write_room(struct tty_struct *tty) 935static int rs_write_room(struct tty_struct *tty)
936{ 936{
937 struct async_struct *info = (struct async_struct *)tty->driver_data; 937 struct async_struct *info = tty->driver_data;
938 938
939 if (serial_paranoia_check(info, tty->name, "rs_write_room")) 939 if (serial_paranoia_check(info, tty->name, "rs_write_room"))
940 return 0; 940 return 0;
@@ -943,7 +943,7 @@ static int rs_write_room(struct tty_struct *tty)
943 943
944static int rs_chars_in_buffer(struct tty_struct *tty) 944static int rs_chars_in_buffer(struct tty_struct *tty)
945{ 945{
946 struct async_struct *info = (struct async_struct *)tty->driver_data; 946 struct async_struct *info = tty->driver_data;
947 947
948 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer")) 948 if (serial_paranoia_check(info, tty->name, "rs_chars_in_buffer"))
949 return 0; 949 return 0;
@@ -952,7 +952,7 @@ static int rs_chars_in_buffer(struct tty_struct *tty)
952 952
953static void rs_flush_buffer(struct tty_struct *tty) 953static void rs_flush_buffer(struct tty_struct *tty)
954{ 954{
955 struct async_struct *info = (struct async_struct *)tty->driver_data; 955 struct async_struct *info = tty->driver_data;
956 unsigned long flags; 956 unsigned long flags;
957 957
958 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer")) 958 if (serial_paranoia_check(info, tty->name, "rs_flush_buffer"))
@@ -969,7 +969,7 @@ static void rs_flush_buffer(struct tty_struct *tty)
969 */ 969 */
970static void rs_send_xchar(struct tty_struct *tty, char ch) 970static void rs_send_xchar(struct tty_struct *tty, char ch)
971{ 971{
972 struct async_struct *info = (struct async_struct *)tty->driver_data; 972 struct async_struct *info = tty->driver_data;
973 unsigned long flags; 973 unsigned long flags;
974 974
975 if (serial_paranoia_check(info, tty->name, "rs_send_char")) 975 if (serial_paranoia_check(info, tty->name, "rs_send_char"))
@@ -1004,7 +1004,7 @@ static void rs_send_xchar(struct tty_struct *tty, char ch)
1004 */ 1004 */
1005static void rs_throttle(struct tty_struct * tty) 1005static void rs_throttle(struct tty_struct * tty)
1006{ 1006{
1007 struct async_struct *info = (struct async_struct *)tty->driver_data; 1007 struct async_struct *info = tty->driver_data;
1008 unsigned long flags; 1008 unsigned long flags;
1009#ifdef SERIAL_DEBUG_THROTTLE 1009#ifdef SERIAL_DEBUG_THROTTLE
1010 char buf[64]; 1010 char buf[64];
@@ -1029,7 +1029,7 @@ static void rs_throttle(struct tty_struct * tty)
1029 1029
1030static void rs_unthrottle(struct tty_struct * tty) 1030static void rs_unthrottle(struct tty_struct * tty)
1031{ 1031{
1032 struct async_struct *info = (struct async_struct *)tty->driver_data; 1032 struct async_struct *info = tty->driver_data;
1033 unsigned long flags; 1033 unsigned long flags;
1034#ifdef SERIAL_DEBUG_THROTTLE 1034#ifdef SERIAL_DEBUG_THROTTLE
1035 char buf[64]; 1035 char buf[64];
@@ -1194,7 +1194,7 @@ static int get_lsr_info(struct async_struct * info, unsigned int __user *value)
1194 1194
1195static int rs_tiocmget(struct tty_struct *tty, struct file *file) 1195static int rs_tiocmget(struct tty_struct *tty, struct file *file)
1196{ 1196{
1197 struct async_struct * info = (struct async_struct *)tty->driver_data; 1197 struct async_struct * info = tty->driver_data;
1198 unsigned char control, status; 1198 unsigned char control, status;
1199 unsigned long flags; 1199 unsigned long flags;
1200 1200
@@ -1217,7 +1217,7 @@ static int rs_tiocmget(struct tty_struct *tty, struct file *file)
1217static int rs_tiocmset(struct tty_struct *tty, struct file *file, 1217static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1218 unsigned int set, unsigned int clear) 1218 unsigned int set, unsigned int clear)
1219{ 1219{
1220 struct async_struct * info = (struct async_struct *)tty->driver_data; 1220 struct async_struct * info = tty->driver_data;
1221 unsigned long flags; 1221 unsigned long flags;
1222 1222
1223 if (serial_paranoia_check(info, tty->name, "rs_ioctl")) 1223 if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
@@ -1244,7 +1244,7 @@ static int rs_tiocmset(struct tty_struct *tty, struct file *file,
1244 */ 1244 */
1245static int rs_break(struct tty_struct *tty, int break_state) 1245static int rs_break(struct tty_struct *tty, int break_state)
1246{ 1246{
1247 struct async_struct * info = (struct async_struct *)tty->driver_data; 1247 struct async_struct * info = tty->driver_data;
1248 unsigned long flags; 1248 unsigned long flags;
1249 1249
1250 if (serial_paranoia_check(info, tty->name, "rs_break")) 1250 if (serial_paranoia_check(info, tty->name, "rs_break"))
@@ -1264,7 +1264,7 @@ static int rs_break(struct tty_struct *tty, int break_state)
1264static int rs_ioctl(struct tty_struct *tty, struct file * file, 1264static int rs_ioctl(struct tty_struct *tty, struct file * file,
1265 unsigned int cmd, unsigned long arg) 1265 unsigned int cmd, unsigned long arg)
1266{ 1266{
1267 struct async_struct * info = (struct async_struct *)tty->driver_data; 1267 struct async_struct * info = tty->driver_data;
1268 struct async_icount cprev, cnow; /* kernel counter temps */ 1268 struct async_icount cprev, cnow; /* kernel counter temps */
1269 struct serial_icounter_struct icount; 1269 struct serial_icounter_struct icount;
1270 void __user *argp = (void __user *)arg; 1270 void __user *argp = (void __user *)arg;
@@ -1368,7 +1368,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1368 1368
1369static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1369static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1370{ 1370{
1371 struct async_struct *info = (struct async_struct *)tty->driver_data; 1371 struct async_struct *info = tty->driver_data;
1372 unsigned long flags; 1372 unsigned long flags;
1373 unsigned int cflag = tty->termios->c_cflag; 1373 unsigned int cflag = tty->termios->c_cflag;
1374 1374
@@ -1428,7 +1428,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1428 */ 1428 */
1429static void rs_close(struct tty_struct *tty, struct file * filp) 1429static void rs_close(struct tty_struct *tty, struct file * filp)
1430{ 1430{
1431 struct async_struct * info = (struct async_struct *)tty->driver_data; 1431 struct async_struct * info = tty->driver_data;
1432 struct serial_state *state; 1432 struct serial_state *state;
1433 unsigned long flags; 1433 unsigned long flags;
1434 1434
@@ -1523,7 +1523,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1523 */ 1523 */
1524static void rs_wait_until_sent(struct tty_struct *tty, int timeout) 1524static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1525{ 1525{
1526 struct async_struct * info = (struct async_struct *)tty->driver_data; 1526 struct async_struct * info = tty->driver_data;
1527 unsigned long orig_jiffies, char_time; 1527 unsigned long orig_jiffies, char_time;
1528 int lsr; 1528 int lsr;
1529 1529
@@ -1587,7 +1587,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1587 */ 1587 */
1588static void rs_hangup(struct tty_struct *tty) 1588static void rs_hangup(struct tty_struct *tty)
1589{ 1589{
1590 struct async_struct * info = (struct async_struct *)tty->driver_data; 1590 struct async_struct * info = tty->driver_data;
1591 struct serial_state *state = info->state; 1591 struct serial_state *state = info->state;
1592 1592
1593 if (serial_paranoia_check(info, tty->name, "rs_hangup")) 1593 if (serial_paranoia_check(info, tty->name, "rs_hangup"))
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 5e5b1dc1a0a7..6a59f72a9c21 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -5010,7 +5010,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5010 if (nchan == 0) { 5010 if (nchan == 0) {
5011 dev_err(&pdev->dev, "Cyclom-Y PCI host card with no " 5011 dev_err(&pdev->dev, "Cyclom-Y PCI host card with no "
5012 "Serial-Modules\n"); 5012 "Serial-Modules\n");
5013 return -EIO; 5013 goto err_unmap;
5014 } 5014 }
5015 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) { 5015 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
5016 struct RUNTIME_9060 __iomem *ctl_addr; 5016 struct RUNTIME_9060 __iomem *ctl_addr;
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index cf2461d34e5f..39ad820b2350 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -69,7 +69,9 @@ static int invalid_lilo_config;
69 69
70/* 70/*
71 * The ISA boards do window flipping into the same spaces so its only sane with 71 * The ISA boards do window flipping into the same spaces so its only sane with
72 * a single lock. It's still pretty efficient. 72 * a single lock. It's still pretty efficient. This lock guards the hardware
73 * and the tty_port lock guards the kernel side stuff like use counts. Take
74 * this lock inside the port lock if you must take both.
73 */ 75 */
74static DEFINE_SPINLOCK(epca_lock); 76static DEFINE_SPINLOCK(epca_lock);
75 77
@@ -156,14 +158,12 @@ static struct channel *verifyChannel(struct tty_struct *);
156static void pc_sched_event(struct channel *, int); 158static void pc_sched_event(struct channel *, int);
157static void epca_error(int, char *); 159static void epca_error(int, char *);
158static void pc_close(struct tty_struct *, struct file *); 160static void pc_close(struct tty_struct *, struct file *);
159static void shutdown(struct channel *); 161static void shutdown(struct channel *, struct tty_struct *tty);
160static void pc_hangup(struct tty_struct *); 162static void pc_hangup(struct tty_struct *);
161static int pc_write_room(struct tty_struct *); 163static int pc_write_room(struct tty_struct *);
162static int pc_chars_in_buffer(struct tty_struct *); 164static int pc_chars_in_buffer(struct tty_struct *);
163static void pc_flush_buffer(struct tty_struct *); 165static void pc_flush_buffer(struct tty_struct *);
164static void pc_flush_chars(struct tty_struct *); 166static void pc_flush_chars(struct tty_struct *);
165static int block_til_ready(struct tty_struct *, struct file *,
166 struct channel *);
167static int pc_open(struct tty_struct *, struct file *); 167static int pc_open(struct tty_struct *, struct file *);
168static void post_fep_init(unsigned int crd); 168static void post_fep_init(unsigned int crd);
169static void epcapoll(unsigned long); 169static void epcapoll(unsigned long);
@@ -173,7 +173,7 @@ static unsigned termios2digi_h(struct channel *ch, unsigned);
173static unsigned termios2digi_i(struct channel *ch, unsigned); 173static unsigned termios2digi_i(struct channel *ch, unsigned);
174static unsigned termios2digi_c(struct channel *ch, unsigned); 174static unsigned termios2digi_c(struct channel *ch, unsigned);
175static void epcaparam(struct tty_struct *, struct channel *); 175static void epcaparam(struct tty_struct *, struct channel *);
176static void receive_data(struct channel *); 176static void receive_data(struct channel *, struct tty_struct *tty);
177static int pc_ioctl(struct tty_struct *, struct file *, 177static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long); 178 unsigned int, unsigned long);
179static int info_ioctl(struct tty_struct *, struct file *, 179static int info_ioctl(struct tty_struct *, struct file *,
@@ -392,7 +392,7 @@ static struct channel *verifyChannel(struct tty_struct *tty)
392 * through tty->driver_data this should catch it. 392 * through tty->driver_data this should catch it.
393 */ 393 */
394 if (tty) { 394 if (tty) {
395 struct channel *ch = (struct channel *)tty->driver_data; 395 struct channel *ch = tty->driver_data;
396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) { 396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
397 if (ch->magic == EPCA_MAGIC) 397 if (ch->magic == EPCA_MAGIC)
398 return ch; 398 return ch;
@@ -419,76 +419,34 @@ static void epca_error(int line, char *msg)
419static void pc_close(struct tty_struct *tty, struct file *filp) 419static void pc_close(struct tty_struct *tty, struct file *filp)
420{ 420{
421 struct channel *ch; 421 struct channel *ch;
422 unsigned long flags; 422 struct tty_port *port;
423 /* 423 /*
424 * verifyChannel returns the channel from the tty struct if it is 424 * verifyChannel returns the channel from the tty struct if it is
425 * valid. This serves as a sanity check. 425 * valid. This serves as a sanity check.
426 */ 426 */
427 ch = verifyChannel(tty); 427 ch = verifyChannel(tty);
428 if (ch != NULL) { 428 if (ch == NULL)
429 spin_lock_irqsave(&epca_lock, flags); 429 return;
430 if (tty_hung_up_p(filp)) { 430 port = &ch->port;
431 spin_unlock_irqrestore(&epca_lock, flags);
432 return;
433 }
434 if (ch->port.count-- > 1) {
435 /* Begin channel is open more than once */
436 /*
437 * Return without doing anything. Someone might still
438 * be using the channel.
439 */
440 spin_unlock_irqrestore(&epca_lock, flags);
441 return;
442 }
443 /* Port open only once go ahead with shutdown & reset */
444 BUG_ON(ch->port.count < 0);
445
446 /*
447 * Let the rest of the driver know the channel is being closed.
448 * This becomes important if an open is attempted before close
449 * is finished.
450 */
451 ch->port.flags |= ASYNC_CLOSING;
452 tty->closing = 1;
453
454 spin_unlock_irqrestore(&epca_lock, flags);
455
456 if (ch->port.flags & ASYNC_INITIALIZED) {
457 /* Setup an event to indicate when the
458 transmit buffer empties */
459 setup_empty_event(tty, ch);
460 /* 30 seconds timeout */
461 tty_wait_until_sent(tty, 3000);
462 }
463 pc_flush_buffer(tty);
464 431
465 tty_ldisc_flush(tty); 432 if (tty_port_close_start(port, tty, filp) == 0)
466 shutdown(ch); 433 return;
467 434
468 spin_lock_irqsave(&epca_lock, flags); 435 pc_flush_buffer(tty);
469 tty->closing = 0; 436 shutdown(ch, tty);
470 ch->event = 0;
471 ch->port.tty = NULL;
472 spin_unlock_irqrestore(&epca_lock, flags);
473 437
474 if (ch->port.blocked_open) { 438 tty_port_close_end(port, tty);
475 if (ch->close_delay) 439 ch->event = 0; /* FIXME: review ch->event locking */
476 msleep_interruptible(jiffies_to_msecs(ch->close_delay)); 440 tty_port_tty_set(port, NULL);
477 wake_up_interruptible(&ch->port.open_wait);
478 }
479 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
480 ASYNC_CLOSING);
481 wake_up_interruptible(&ch->port.close_wait);
482 }
483} 441}
484 442
485static void shutdown(struct channel *ch) 443static void shutdown(struct channel *ch, struct tty_struct *tty)
486{ 444{
487 unsigned long flags; 445 unsigned long flags;
488 struct tty_struct *tty;
489 struct board_chan __iomem *bc; 446 struct board_chan __iomem *bc;
447 struct tty_port *port = &ch->port;
490 448
491 if (!(ch->port.flags & ASYNC_INITIALIZED)) 449 if (!(port->flags & ASYNC_INITIALIZED))
492 return; 450 return;
493 451
494 spin_lock_irqsave(&epca_lock, flags); 452 spin_lock_irqsave(&epca_lock, flags);
@@ -503,7 +461,6 @@ static void shutdown(struct channel *ch)
503 */ 461 */
504 if (bc) 462 if (bc)
505 writeb(0, &bc->idata); 463 writeb(0, &bc->idata);
506 tty = ch->port.tty;
507 464
508 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */ 465 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
509 if (tty->termios->c_cflag & HUPCL) { 466 if (tty->termios->c_cflag & HUPCL) {
@@ -517,32 +474,26 @@ static void shutdown(struct channel *ch)
517 * will have to reinitialized. Set a flag to indicate this. 474 * will have to reinitialized. Set a flag to indicate this.
518 */ 475 */
519 /* Prevent future Digi programmed interrupts from coming active */ 476 /* Prevent future Digi programmed interrupts from coming active */
520 ch->port.flags &= ~ASYNC_INITIALIZED; 477 port->flags &= ~ASYNC_INITIALIZED;
521 spin_unlock_irqrestore(&epca_lock, flags); 478 spin_unlock_irqrestore(&epca_lock, flags);
522} 479}
523 480
524static void pc_hangup(struct tty_struct *tty) 481static void pc_hangup(struct tty_struct *tty)
525{ 482{
526 struct channel *ch; 483 struct channel *ch;
484
527 /* 485 /*
528 * verifyChannel returns the channel from the tty struct if it is 486 * verifyChannel returns the channel from the tty struct if it is
529 * valid. This serves as a sanity check. 487 * valid. This serves as a sanity check.
530 */ 488 */
531 ch = verifyChannel(tty); 489 ch = verifyChannel(tty);
532 if (ch != NULL) { 490 if (ch != NULL) {
533 unsigned long flags;
534
535 pc_flush_buffer(tty); 491 pc_flush_buffer(tty);
536 tty_ldisc_flush(tty); 492 tty_ldisc_flush(tty);
537 shutdown(ch); 493 shutdown(ch, tty);
538 494
539 spin_lock_irqsave(&epca_lock, flags); 495 ch->event = 0; /* FIXME: review locking of ch->event */
540 ch->port.tty = NULL; 496 tty_port_hangup(&ch->port);
541 ch->event = 0;
542 ch->port.count = 0;
543 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
544 spin_unlock_irqrestore(&epca_lock, flags);
545 wake_up_interruptible(&ch->port.open_wait);
546 } 497 }
547} 498}
548 499
@@ -786,100 +737,22 @@ static void pc_flush_chars(struct tty_struct *tty)
786 } 737 }
787} 738}
788 739
789static int block_til_ready(struct tty_struct *tty, 740static int epca_carrier_raised(struct tty_port *port)
790 struct file *filp, struct channel *ch)
791{ 741{
792 DECLARE_WAITQUEUE(wait, current); 742 struct channel *ch = container_of(port, struct channel, port);
793 int retval, do_clocal = 0; 743 if (ch->imodem & ch->dcd)
794 unsigned long flags; 744 return 1;
795
796 if (tty_hung_up_p(filp)) {
797 if (ch->port.flags & ASYNC_HUP_NOTIFY)
798 retval = -EAGAIN;
799 else
800 retval = -ERESTARTSYS;
801 return retval;
802 }
803
804 /*
805 * If the device is in the middle of being closed, then block until
806 * it's done, and then try again.
807 */
808 if (ch->port.flags & ASYNC_CLOSING) {
809 interruptible_sleep_on(&ch->port.close_wait);
810
811 if (ch->port.flags & ASYNC_HUP_NOTIFY)
812 return -EAGAIN;
813 else
814 return -ERESTARTSYS;
815 }
816
817 if (filp->f_flags & O_NONBLOCK) {
818 /*
819 * If non-blocking mode is set, then make the check up front
820 * and then exit.
821 */
822 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
823 return 0;
824 }
825 if (tty->termios->c_cflag & CLOCAL)
826 do_clocal = 1;
827 /* Block waiting for the carrier detect and the line to become free */
828
829 retval = 0;
830 add_wait_queue(&ch->port.open_wait, &wait);
831
832 spin_lock_irqsave(&epca_lock, flags);
833 /* We dec count so that pc_close will know when to free things */
834 if (!tty_hung_up_p(filp))
835 ch->port.count--;
836 ch->port.blocked_open++;
837 while (1) {
838 set_current_state(TASK_INTERRUPTIBLE);
839 if (tty_hung_up_p(filp) ||
840 !(ch->port.flags & ASYNC_INITIALIZED)) {
841 if (ch->port.flags & ASYNC_HUP_NOTIFY)
842 retval = -EAGAIN;
843 else
844 retval = -ERESTARTSYS;
845 break;
846 }
847 if (!(ch->port.flags & ASYNC_CLOSING) &&
848 (do_clocal || (ch->imodem & ch->dcd)))
849 break;
850 if (signal_pending(current)) {
851 retval = -ERESTARTSYS;
852 break;
853 }
854 spin_unlock_irqrestore(&epca_lock, flags);
855 /*
856 * Allow someone else to be scheduled. We will occasionally go
857 * through this loop until one of the above conditions change.
858 * The below schedule call will allow other processes to enter
859 * and prevent this loop from hogging the cpu.
860 */
861 schedule();
862 spin_lock_irqsave(&epca_lock, flags);
863 }
864
865 __set_current_state(TASK_RUNNING);
866 remove_wait_queue(&ch->port.open_wait, &wait);
867 if (!tty_hung_up_p(filp))
868 ch->port.count++;
869 ch->port.blocked_open--;
870
871 spin_unlock_irqrestore(&epca_lock, flags);
872
873 if (retval)
874 return retval;
875
876 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
877 return 0; 745 return 0;
878} 746}
879 747
748static void epca_raise_dtr_rts(struct tty_port *port)
749{
750}
751
880static int pc_open(struct tty_struct *tty, struct file *filp) 752static int pc_open(struct tty_struct *tty, struct file *filp)
881{ 753{
882 struct channel *ch; 754 struct channel *ch;
755 struct tty_port *port;
883 unsigned long flags; 756 unsigned long flags;
884 int line, retval, boardnum; 757 int line, retval, boardnum;
885 struct board_chan __iomem *bc; 758 struct board_chan __iomem *bc;
@@ -890,6 +763,7 @@ static int pc_open(struct tty_struct *tty, struct file *filp)
890 return -ENODEV; 763 return -ENODEV;
891 764
892 ch = &digi_channels[line]; 765 ch = &digi_channels[line];
766 port = &ch->port;
893 boardnum = ch->boardnum; 767 boardnum = ch->boardnum;
894 768
895 /* Check status of board configured in system. */ 769 /* Check status of board configured in system. */
@@ -926,22 +800,24 @@ static int pc_open(struct tty_struct *tty, struct file *filp)
926 return -ENODEV; 800 return -ENODEV;
927 } 801 }
928 802
929 spin_lock_irqsave(&epca_lock, flags); 803 spin_lock_irqsave(&port->lock, flags);
930 /* 804 /*
931 * Every time a channel is opened, increment a counter. This is 805 * Every time a channel is opened, increment a counter. This is
932 * necessary because we do not wish to flush and shutdown the channel 806 * necessary because we do not wish to flush and shutdown the channel
933 * until the last app holding the channel open, closes it. 807 * until the last app holding the channel open, closes it.
934 */ 808 */
935 ch->port.count++; 809 port->count++;
936 /* 810 /*
937 * Set a kernel structures pointer to our local channel structure. This 811 * Set a kernel structures pointer to our local channel structure. This
938 * way we can get to it when passed only a tty struct. 812 * way we can get to it when passed only a tty struct.
939 */ 813 */
940 tty->driver_data = ch; 814 tty->driver_data = ch;
815 port->tty = tty;
941 /* 816 /*
942 * If this is the first time the channel has been opened, initialize 817 * If this is the first time the channel has been opened, initialize
943 * the tty->termios struct otherwise let pc_close handle it. 818 * the tty->termios struct otherwise let pc_close handle it.
944 */ 819 */
820 spin_lock(&epca_lock);
945 globalwinon(ch); 821 globalwinon(ch);
946 ch->statusflags = 0; 822 ch->statusflags = 0;
947 823
@@ -956,31 +832,33 @@ static int pc_open(struct tty_struct *tty, struct file *filp)
956 writew(head, &bc->rout); 832 writew(head, &bc->rout);
957 833
958 /* Set the channels associated tty structure */ 834 /* Set the channels associated tty structure */
959 ch->port.tty = tty;
960 835
961 /* 836 /*
962 * The below routine generally sets up parity, baud, flow control 837 * The below routine generally sets up parity, baud, flow control
963 * issues, etc.... It effect both control flags and input flags. 838 * issues, etc.... It effect both control flags and input flags.
964 */ 839 */
965 epcaparam(tty, ch); 840 epcaparam(tty, ch);
966 ch->port.flags |= ASYNC_INITIALIZED;
967 memoff(ch); 841 memoff(ch);
968 spin_unlock_irqrestore(&epca_lock, flags); 842 spin_unlock(&epca_lock);
843 port->flags |= ASYNC_INITIALIZED;
844 spin_unlock_irqrestore(&port->lock, flags);
969 845
970 retval = block_til_ready(tty, filp, ch); 846 retval = tty_port_block_til_ready(port, tty, filp);
971 if (retval) 847 if (retval)
972 return retval; 848 return retval;
973 /* 849 /*
974 * Set this again in case a hangup set it to zero while this open() was 850 * Set this again in case a hangup set it to zero while this open() was
975 * waiting for the line... 851 * waiting for the line...
976 */ 852 */
977 spin_lock_irqsave(&epca_lock, flags); 853 spin_lock_irqsave(&port->lock, flags);
978 ch->port.tty = tty; 854 port->tty = tty;
855 spin_lock(&epca_lock);
979 globalwinon(ch); 856 globalwinon(ch);
980 /* Enable Digi Data events */ 857 /* Enable Digi Data events */
981 writeb(1, &bc->idata); 858 writeb(1, &bc->idata);
982 memoff(ch); 859 memoff(ch);
983 spin_unlock_irqrestore(&epca_lock, flags); 860 spin_unlock(&epca_lock);
861 spin_unlock_irqrestore(&port->lock, flags);
984 return 0; 862 return 0;
985} 863}
986 864
@@ -1016,8 +894,11 @@ static void __exit epca_module_exit(void)
1016 } 894 }
1017 ch = card_ptr[crd]; 895 ch = card_ptr[crd];
1018 for (count = 0; count < bd->numports; count++, ch++) { 896 for (count = 0; count < bd->numports; count++, ch++) {
1019 if (ch && ch->port.tty) 897 struct tty_struct *tty = tty_port_tty_get(&ch->port);
1020 tty_hangup(ch->port.tty); 898 if (tty) {
899 tty_hangup(tty);
900 tty_kref_put(tty);
901 }
1021 } 902 }
1022 } 903 }
1023 pci_unregister_driver(&epca_driver); 904 pci_unregister_driver(&epca_driver);
@@ -1042,6 +923,11 @@ static const struct tty_operations pc_ops = {
1042 .break_ctl = pc_send_break 923 .break_ctl = pc_send_break
1043}; 924};
1044 925
926static const struct tty_port_operations epca_port_ops = {
927 .carrier_raised = epca_carrier_raised,
928 .raise_dtr_rts = epca_raise_dtr_rts,
929};
930
1045static int info_open(struct tty_struct *tty, struct file *filp) 931static int info_open(struct tty_struct *tty, struct file *filp)
1046{ 932{
1047 return 0; 933 return 0;
@@ -1377,6 +1263,7 @@ static void post_fep_init(unsigned int crd)
1377 u16 tseg, rseg; 1263 u16 tseg, rseg;
1378 1264
1379 tty_port_init(&ch->port); 1265 tty_port_init(&ch->port);
1266 ch->port.ops = &epca_port_ops;
1380 ch->brdchan = bc; 1267 ch->brdchan = bc;
1381 ch->mailbox = gd; 1268 ch->mailbox = gd;
1382 INIT_WORK(&ch->tqueue, do_softint); 1269 INIT_WORK(&ch->tqueue, do_softint);
@@ -1428,7 +1315,7 @@ static void post_fep_init(unsigned int crd)
1428 ch->boardnum = crd; 1315 ch->boardnum = crd;
1429 ch->channelnum = i; 1316 ch->channelnum = i;
1430 ch->magic = EPCA_MAGIC; 1317 ch->magic = EPCA_MAGIC;
1431 ch->port.tty = NULL; 1318 tty_port_tty_set(&ch->port, NULL);
1432 1319
1433 if (shrinkmem) { 1320 if (shrinkmem) {
1434 fepcmd(ch, SETBUFFER, 32, 0, 0, 0); 1321 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
@@ -1510,7 +1397,7 @@ static void post_fep_init(unsigned int crd)
1510 ch->fepstartca = 0; 1397 ch->fepstartca = 0;
1511 ch->fepstopca = 0; 1398 ch->fepstopca = 0;
1512 1399
1513 ch->close_delay = 50; 1400 ch->port.close_delay = 50;
1514 1401
1515 spin_unlock_irqrestore(&epca_lock, flags); 1402 spin_unlock_irqrestore(&epca_lock, flags);
1516 } 1403 }
@@ -1622,15 +1509,16 @@ static void doevent(int crd)
1622 if (bc == NULL) 1509 if (bc == NULL)
1623 goto next; 1510 goto next;
1624 1511
1512 tty = tty_port_tty_get(&ch->port);
1625 if (event & DATA_IND) { /* Begin DATA_IND */ 1513 if (event & DATA_IND) { /* Begin DATA_IND */
1626 receive_data(ch); 1514 receive_data(ch, tty);
1627 assertgwinon(ch); 1515 assertgwinon(ch);
1628 } /* End DATA_IND */ 1516 } /* End DATA_IND */
1629 /* else *//* Fix for DCD transition missed bug */ 1517 /* else *//* Fix for DCD transition missed bug */
1630 if (event & MODEMCHG_IND) { 1518 if (event & MODEMCHG_IND) {
1631 /* A modem signal change has been indicated */ 1519 /* A modem signal change has been indicated */
1632 ch->imodem = mstat; 1520 ch->imodem = mstat;
1633 if (ch->port.flags & ASYNC_CHECK_CD) { 1521 if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) {
1634 /* We are now receiving dcd */ 1522 /* We are now receiving dcd */
1635 if (mstat & ch->dcd) 1523 if (mstat & ch->dcd)
1636 wake_up_interruptible(&ch->port.open_wait); 1524 wake_up_interruptible(&ch->port.open_wait);
@@ -1638,7 +1526,6 @@ static void doevent(int crd)
1638 pc_sched_event(ch, EPCA_EVENT_HANGUP); 1526 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1639 } 1527 }
1640 } 1528 }
1641 tty = ch->port.tty;
1642 if (tty) { 1529 if (tty) {
1643 if (event & BREAK_IND) { 1530 if (event & BREAK_IND) {
1644 /* A break has been indicated */ 1531 /* A break has been indicated */
@@ -1658,6 +1545,7 @@ static void doevent(int crd)
1658 tty_wakeup(tty); 1545 tty_wakeup(tty);
1659 } 1546 }
1660 } 1547 }
1548 tty_kref_put(tty);
1661 } 1549 }
1662next: 1550next:
1663 globalwinon(ch); 1551 globalwinon(ch);
@@ -1877,9 +1765,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1877 * that the driver will wait on carrier detect. 1765 * that the driver will wait on carrier detect.
1878 */ 1766 */
1879 if (ts->c_cflag & CLOCAL) 1767 if (ts->c_cflag & CLOCAL)
1880 ch->port.flags &= ~ASYNC_CHECK_CD; 1768 clear_bit(ASYNC_CHECK_CD, &ch->port.flags);
1881 else 1769 else
1882 ch->port.flags |= ASYNC_CHECK_CD; 1770 set_bit(ASYNC_CHECK_CD, &ch->port.flags);
1883 mval = ch->m_dtr | ch->m_rts; 1771 mval = ch->m_dtr | ch->m_rts;
1884 } /* End CBAUD not detected */ 1772 } /* End CBAUD not detected */
1885 iflag = termios2digi_i(ch, ts->c_iflag); 1773 iflag = termios2digi_i(ch, ts->c_iflag);
@@ -1952,11 +1840,10 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1952} 1840}
1953 1841
1954/* Caller holds lock */ 1842/* Caller holds lock */
1955static void receive_data(struct channel *ch) 1843static void receive_data(struct channel *ch, struct tty_struct *tty)
1956{ 1844{
1957 unchar *rptr; 1845 unchar *rptr;
1958 struct ktermios *ts = NULL; 1846 struct ktermios *ts = NULL;
1959 struct tty_struct *tty;
1960 struct board_chan __iomem *bc; 1847 struct board_chan __iomem *bc;
1961 int dataToRead, wrapgap, bytesAvailable; 1848 int dataToRead, wrapgap, bytesAvailable;
1962 unsigned int tail, head; 1849 unsigned int tail, head;
@@ -1969,7 +1856,6 @@ static void receive_data(struct channel *ch)
1969 globalwinon(ch); 1856 globalwinon(ch);
1970 if (ch->statusflags & RXSTOPPED) 1857 if (ch->statusflags & RXSTOPPED)
1971 return; 1858 return;
1972 tty = ch->port.tty;
1973 if (tty) 1859 if (tty)
1974 ts = tty->termios; 1860 ts = tty->termios;
1975 bc = ch->brdchan; 1861 bc = ch->brdchan;
@@ -2029,7 +1915,7 @@ static void receive_data(struct channel *ch)
2029 globalwinon(ch); 1915 globalwinon(ch);
2030 writew(tail, &bc->rout); 1916 writew(tail, &bc->rout);
2031 /* Must be called with global data */ 1917 /* Must be called with global data */
2032 tty_schedule_flip(ch->port.tty); 1918 tty_schedule_flip(tty);
2033} 1919}
2034 1920
2035static int info_ioctl(struct tty_struct *tty, struct file *file, 1921static int info_ioctl(struct tty_struct *tty, struct file *file,
@@ -2097,7 +1983,7 @@ static int info_ioctl(struct tty_struct *tty, struct file *file,
2097 1983
2098static int pc_tiocmget(struct tty_struct *tty, struct file *file) 1984static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2099{ 1985{
2100 struct channel *ch = (struct channel *) tty->driver_data; 1986 struct channel *ch = tty->driver_data;
2101 struct board_chan __iomem *bc; 1987 struct board_chan __iomem *bc;
2102 unsigned int mstat, mflag = 0; 1988 unsigned int mstat, mflag = 0;
2103 unsigned long flags; 1989 unsigned long flags;
@@ -2131,7 +2017,7 @@ static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2131static int pc_tiocmset(struct tty_struct *tty, struct file *file, 2017static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2132 unsigned int set, unsigned int clear) 2018 unsigned int set, unsigned int clear)
2133{ 2019{
2134 struct channel *ch = (struct channel *) tty->driver_data; 2020 struct channel *ch = tty->driver_data;
2135 unsigned long flags; 2021 unsigned long flags;
2136 2022
2137 if (!ch) 2023 if (!ch)
@@ -2178,7 +2064,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2178 unsigned int mflag, mstat; 2064 unsigned int mflag, mstat;
2179 unsigned char startc, stopc; 2065 unsigned char startc, stopc;
2180 struct board_chan __iomem *bc; 2066 struct board_chan __iomem *bc;
2181 struct channel *ch = (struct channel *) tty->driver_data; 2067 struct channel *ch = tty->driver_data;
2182 void __user *argp = (void __user *)arg; 2068 void __user *argp = (void __user *)arg;
2183 2069
2184 if (ch) 2070 if (ch)
@@ -2352,15 +2238,16 @@ static void do_softint(struct work_struct *work)
2352 struct channel *ch = container_of(work, struct channel, tqueue); 2238 struct channel *ch = container_of(work, struct channel, tqueue);
2353 /* Called in response to a modem change event */ 2239 /* Called in response to a modem change event */
2354 if (ch && ch->magic == EPCA_MAGIC) { 2240 if (ch && ch->magic == EPCA_MAGIC) {
2355 struct tty_struct *tty = ch->port.tty; 2241 struct tty_struct *tty = tty_port_tty_get(&ch->port);;
2356 2242
2357 if (tty && tty->driver_data) { 2243 if (tty && tty->driver_data) {
2358 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { 2244 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2359 tty_hangup(tty); 2245 tty_hangup(tty);
2360 wake_up_interruptible(&ch->port.open_wait); 2246 wake_up_interruptible(&ch->port.open_wait);
2361 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; 2247 clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags);
2362 } 2248 }
2363 } 2249 }
2250 tty_kref_put(tty);
2364 } 2251 }
2365} 2252}
2366 2253
@@ -2473,7 +2360,7 @@ static void pc_unthrottle(struct tty_struct *tty)
2473 2360
2474static int pc_send_break(struct tty_struct *tty, int msec) 2361static int pc_send_break(struct tty_struct *tty, int msec)
2475{ 2362{
2476 struct channel *ch = (struct channel *) tty->driver_data; 2363 struct channel *ch = tty->driver_data;
2477 unsigned long flags; 2364 unsigned long flags;
2478 2365
2479 if (msec == -1) 2366 if (msec == -1)
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index 7f077c0097f6..45ec263ec012 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -2054,6 +2054,15 @@ static void esp_hangup(struct tty_struct *tty)
2054 wake_up_interruptible(&info->port.open_wait); 2054 wake_up_interruptible(&info->port.open_wait);
2055} 2055}
2056 2056
2057static int esp_carrier_raised(struct tty_port *port)
2058{
2059 struct esp_struct *info = container_of(port, struct esp_struct, port);
2060 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT);
2061 if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD)
2062 return 1;
2063 return 0;
2064}
2065
2057/* 2066/*
2058 * ------------------------------------------------------------ 2067 * ------------------------------------------------------------
2059 * esp_open() and friends 2068 * esp_open() and friends
@@ -2066,17 +2075,19 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
2066 int retval; 2075 int retval;
2067 int do_clocal = 0; 2076 int do_clocal = 0;
2068 unsigned long flags; 2077 unsigned long flags;
2078 int cd;
2079 struct tty_port *port = &info->port;
2069 2080
2070 /* 2081 /*
2071 * If the device is in the middle of being closed, then block 2082 * If the device is in the middle of being closed, then block
2072 * until it's done, and then try again. 2083 * until it's done, and then try again.
2073 */ 2084 */
2074 if (tty_hung_up_p(filp) || 2085 if (tty_hung_up_p(filp) ||
2075 (info->port.flags & ASYNC_CLOSING)) { 2086 (port->flags & ASYNC_CLOSING)) {
2076 if (info->port.flags & ASYNC_CLOSING) 2087 if (port->flags & ASYNC_CLOSING)
2077 interruptible_sleep_on(&info->port.close_wait); 2088 interruptible_sleep_on(&port->close_wait);
2078#ifdef SERIAL_DO_RESTART 2089#ifdef SERIAL_DO_RESTART
2079 if (info->port.flags & ASYNC_HUP_NOTIFY) 2090 if (port->flags & ASYNC_HUP_NOTIFY)
2080 return -EAGAIN; 2091 return -EAGAIN;
2081 else 2092 else
2082 return -ERESTARTSYS; 2093 return -ERESTARTSYS;
@@ -2091,7 +2102,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
2091 */ 2102 */
2092 if ((filp->f_flags & O_NONBLOCK) || 2103 if ((filp->f_flags & O_NONBLOCK) ||
2093 (tty->flags & (1 << TTY_IO_ERROR))) { 2104 (tty->flags & (1 << TTY_IO_ERROR))) {
2094 info->port.flags |= ASYNC_NORMAL_ACTIVE; 2105 port->flags |= ASYNC_NORMAL_ACTIVE;
2095 return 0; 2106 return 0;
2096 } 2107 }
2097 2108
@@ -2101,20 +2112,20 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
2101 /* 2112 /*
2102 * Block waiting for the carrier detect and the line to become 2113 * Block waiting for the carrier detect and the line to become
2103 * free (i.e., not in use by the callout). While we are in 2114 * free (i.e., not in use by the callout). While we are in
2104 * this loop, info->port.count is dropped by one, so that 2115 * this loop, port->count is dropped by one, so that
2105 * rs_close() knows when to free things. We restore it upon 2116 * rs_close() knows when to free things. We restore it upon
2106 * exit, either normal or abnormal. 2117 * exit, either normal or abnormal.
2107 */ 2118 */
2108 retval = 0; 2119 retval = 0;
2109 add_wait_queue(&info->port.open_wait, &wait); 2120 add_wait_queue(&port->open_wait, &wait);
2110#ifdef SERIAL_DEBUG_OPEN 2121#ifdef SERIAL_DEBUG_OPEN
2111 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n", 2122 printk(KERN_DEBUG "block_til_ready before block: ttys%d, count = %d\n",
2112 info->line, info->port.count); 2123 info->line, port->count);
2113#endif 2124#endif
2114 spin_lock_irqsave(&info->lock, flags); 2125 spin_lock_irqsave(&info->lock, flags);
2115 if (!tty_hung_up_p(filp)) 2126 if (!tty_hung_up_p(filp))
2116 info->port.count--; 2127 port->count--;
2117 info->port.blocked_open++; 2128 port->blocked_open++;
2118 while (1) { 2129 while (1) {
2119 if ((tty->termios->c_cflag & CBAUD)) { 2130 if ((tty->termios->c_cflag & CBAUD)) {
2120 unsigned int scratch; 2131 unsigned int scratch;
@@ -2129,9 +2140,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
2129 } 2140 }
2130 set_current_state(TASK_INTERRUPTIBLE); 2141 set_current_state(TASK_INTERRUPTIBLE);
2131 if (tty_hung_up_p(filp) || 2142 if (tty_hung_up_p(filp) ||
2132 !(info->port.flags & ASYNC_INITIALIZED)) { 2143 !(port->flags & ASYNC_INITIALIZED)) {
2133#ifdef SERIAL_DO_RESTART 2144#ifdef SERIAL_DO_RESTART
2134 if (info->port.flags & ASYNC_HUP_NOTIFY) 2145 if (port->flags & ASYNC_HUP_NOTIFY)
2135 retval = -EAGAIN; 2146 retval = -EAGAIN;
2136 else 2147 else
2137 retval = -ERESTARTSYS; 2148 retval = -ERESTARTSYS;
@@ -2141,11 +2152,9 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
2141 break; 2152 break;
2142 } 2153 }
2143 2154
2144 serial_out(info, UART_ESI_CMD1, ESI_GET_UART_STAT); 2155 cd = tty_port_carrier_raised(port);
2145 if (serial_in(info, UART_ESI_STAT2) & UART_MSR_DCD)
2146 do_clocal = 1;
2147 2156
2148 if (!(info->port.flags & ASYNC_CLOSING) && 2157 if (!(port->flags & ASYNC_CLOSING) &&
2149 (do_clocal)) 2158 (do_clocal))
2150 break; 2159 break;
2151 if (signal_pending(current)) { 2160 if (signal_pending(current)) {
@@ -2154,25 +2163,25 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
2154 } 2163 }
2155#ifdef SERIAL_DEBUG_OPEN 2164#ifdef SERIAL_DEBUG_OPEN
2156 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n", 2165 printk(KERN_DEBUG "block_til_ready blocking: ttys%d, count = %d\n",
2157 info->line, info->port.count); 2166 info->line, port->count);
2158#endif 2167#endif
2159 spin_unlock_irqrestore(&info->lock, flags); 2168 spin_unlock_irqrestore(&info->lock, flags);
2160 schedule(); 2169 schedule();
2161 spin_lock_irqsave(&info->lock, flags); 2170 spin_lock_irqsave(&info->lock, flags);
2162 } 2171 }
2163 set_current_state(TASK_RUNNING); 2172 set_current_state(TASK_RUNNING);
2164 remove_wait_queue(&info->port.open_wait, &wait); 2173 remove_wait_queue(&port->open_wait, &wait);
2165 if (!tty_hung_up_p(filp)) 2174 if (!tty_hung_up_p(filp))
2166 info->port.count++; 2175 port->count++;
2167 info->port.blocked_open--; 2176 port->blocked_open--;
2168 spin_unlock_irqrestore(&info->lock, flags); 2177 spin_unlock_irqrestore(&info->lock, flags);
2169#ifdef SERIAL_DEBUG_OPEN 2178#ifdef SERIAL_DEBUG_OPEN
2170 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n", 2179 printk(KERN_DEBUG "block_til_ready after blocking: ttys%d, count = %d\n",
2171 info->line, info->port.count); 2180 info->line, port->count);
2172#endif 2181#endif
2173 if (retval) 2182 if (retval)
2174 return retval; 2183 return retval;
2175 info->port.flags |= ASYNC_NORMAL_ACTIVE; 2184 port->flags |= ASYNC_NORMAL_ACTIVE;
2176 return 0; 2185 return 0;
2177} 2186}
2178 2187
@@ -2329,6 +2338,10 @@ static const struct tty_operations esp_ops = {
2329 .tiocmset = esp_tiocmset, 2338 .tiocmset = esp_tiocmset,
2330}; 2339};
2331 2340
2341static const struct tty_port_operations esp_port_ops = {
2342 .esp_carrier_raised,
2343};
2344
2332/* 2345/*
2333 * The serial driver boot-time initialization code! 2346 * The serial driver boot-time initialization code!
2334 */ 2347 */
@@ -2415,6 +2428,8 @@ static int __init espserial_init(void)
2415 offset = 0; 2428 offset = 0;
2416 2429
2417 do { 2430 do {
2431 tty_port_init(&info->port);
2432 info->port.ops = &esp_port_ops;
2418 info->io_port = esp[i] + offset; 2433 info->io_port = esp[i] + offset;
2419 info->irq = irq[i]; 2434 info->irq = irq[i];
2420 info->line = (i * 8) + (offset / 8); 2435 info->line = (i * 8) + (offset / 8);
@@ -2437,8 +2452,6 @@ static int __init espserial_init(void)
2437 info->config.flow_off = flow_off; 2452 info->config.flow_off = flow_off;
2438 info->config.pio_threshold = pio_threshold; 2453 info->config.pio_threshold = pio_threshold;
2439 info->next_port = ports; 2454 info->next_port = ports;
2440 init_waitqueue_head(&info->port.open_wait);
2441 init_waitqueue_head(&info->port.close_wait);
2442 init_waitqueue_head(&info->delta_msr_wait); 2455 init_waitqueue_head(&info->delta_msr_wait);
2443 init_waitqueue_head(&info->break_wait); 2456 init_waitqueue_head(&info->break_wait);
2444 ports = info; 2457 ports = info;
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index c6090f84a2e4..9e4e569dc00d 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -376,7 +376,8 @@ static void gs_shutdown_port (struct gs_port *port)
376 376
377void gs_hangup(struct tty_struct *tty) 377void gs_hangup(struct tty_struct *tty)
378{ 378{
379 struct gs_port *port; 379 struct gs_port *port;
380 unsigned long flags;
380 381
381 func_enter (); 382 func_enter ();
382 383
@@ -386,9 +387,11 @@ void gs_hangup(struct tty_struct *tty)
386 return; 387 return;
387 388
388 gs_shutdown_port (port); 389 gs_shutdown_port (port);
390 spin_lock_irqsave(&port->port.lock, flags);
389 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|GS_ACTIVE); 391 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|GS_ACTIVE);
390 port->port.tty = NULL; 392 port->port.tty = NULL;
391 port->port.count = 0; 393 port->port.count = 0;
394 spin_unlock_irqrestore(&port->port.lock, flags);
392 395
393 wake_up_interruptible(&port->port.open_wait); 396 wake_up_interruptible(&port->port.open_wait);
394 func_exit (); 397 func_exit ();
@@ -397,7 +400,8 @@ void gs_hangup(struct tty_struct *tty)
397 400
398int gs_block_til_ready(void *port_, struct file * filp) 401int gs_block_til_ready(void *port_, struct file * filp)
399{ 402{
400 struct gs_port *port = port_; 403 struct gs_port *gp = port_;
404 struct tty_port *port = &gp->port;
401 DECLARE_WAITQUEUE(wait, current); 405 DECLARE_WAITQUEUE(wait, current);
402 int retval; 406 int retval;
403 int do_clocal = 0; 407 int do_clocal = 0;
@@ -409,16 +413,16 @@ int gs_block_til_ready(void *port_, struct file * filp)
409 413
410 if (!port) return 0; 414 if (!port) return 0;
411 415
412 tty = port->port.tty; 416 tty = port->tty;
413 417
414 gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n"); 418 gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n");
415 /* 419 /*
416 * If the device is in the middle of being closed, then block 420 * If the device is in the middle of being closed, then block
417 * until it's done, and then try again. 421 * until it's done, and then try again.
418 */ 422 */
419 if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) { 423 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
420 interruptible_sleep_on(&port->port.close_wait); 424 interruptible_sleep_on(&port->close_wait);
421 if (port->port.flags & ASYNC_HUP_NOTIFY) 425 if (port->flags & ASYNC_HUP_NOTIFY)
422 return -EAGAIN; 426 return -EAGAIN;
423 else 427 else
424 return -ERESTARTSYS; 428 return -ERESTARTSYS;
@@ -432,7 +436,7 @@ int gs_block_til_ready(void *port_, struct file * filp)
432 */ 436 */
433 if ((filp->f_flags & O_NONBLOCK) || 437 if ((filp->f_flags & O_NONBLOCK) ||
434 (tty->flags & (1 << TTY_IO_ERROR))) { 438 (tty->flags & (1 << TTY_IO_ERROR))) {
435 port->port.flags |= ASYNC_NORMAL_ACTIVE; 439 port->flags |= ASYNC_NORMAL_ACTIVE;
436 return 0; 440 return 0;
437 } 441 }
438 442
@@ -444,34 +448,34 @@ int gs_block_til_ready(void *port_, struct file * filp)
444 /* 448 /*
445 * Block waiting for the carrier detect and the line to become 449 * Block waiting for the carrier detect and the line to become
446 * free (i.e., not in use by the callout). While we are in 450 * free (i.e., not in use by the callout). While we are in
447 * this loop, port->port.count is dropped by one, so that 451 * this loop, port->count is dropped by one, so that
448 * rs_close() knows when to free things. We restore it upon 452 * rs_close() knows when to free things. We restore it upon
449 * exit, either normal or abnormal. 453 * exit, either normal or abnormal.
450 */ 454 */
451 retval = 0; 455 retval = 0;
452 456
453 add_wait_queue(&port->port.open_wait, &wait); 457 add_wait_queue(&port->open_wait, &wait);
454 458
455 gs_dprintk (GS_DEBUG_BTR, "after add waitq.\n"); 459 gs_dprintk (GS_DEBUG_BTR, "after add waitq.\n");
456 spin_lock_irqsave(&port->driver_lock, flags); 460 spin_lock_irqsave(&port->lock, flags);
457 if (!tty_hung_up_p(filp)) { 461 if (!tty_hung_up_p(filp)) {
458 port->port.count--; 462 port->count--;
459 } 463 }
460 spin_unlock_irqrestore(&port->driver_lock, flags); 464 port->blocked_open++;
461 port->port.blocked_open++; 465 spin_unlock_irqrestore(&port->lock, flags);
462 while (1) { 466 while (1) {
463 CD = port->rd->get_CD (port); 467 CD = tty_port_carrier_raised(port);
464 gs_dprintk (GS_DEBUG_BTR, "CD is now %d.\n", CD); 468 gs_dprintk (GS_DEBUG_BTR, "CD is now %d.\n", CD);
465 set_current_state (TASK_INTERRUPTIBLE); 469 set_current_state (TASK_INTERRUPTIBLE);
466 if (tty_hung_up_p(filp) || 470 if (tty_hung_up_p(filp) ||
467 !(port->port.flags & ASYNC_INITIALIZED)) { 471 !(port->flags & ASYNC_INITIALIZED)) {
468 if (port->port.flags & ASYNC_HUP_NOTIFY) 472 if (port->flags & ASYNC_HUP_NOTIFY)
469 retval = -EAGAIN; 473 retval = -EAGAIN;
470 else 474 else
471 retval = -ERESTARTSYS; 475 retval = -ERESTARTSYS;
472 break; 476 break;
473 } 477 }
474 if (!(port->port.flags & ASYNC_CLOSING) && 478 if (!(port->flags & ASYNC_CLOSING) &&
475 (do_clocal || CD)) 479 (do_clocal || CD))
476 break; 480 break;
477 gs_dprintk (GS_DEBUG_BTR, "signal_pending is now: %d (%lx)\n", 481 gs_dprintk (GS_DEBUG_BTR, "signal_pending is now: %d (%lx)\n",
@@ -483,19 +487,20 @@ int gs_block_til_ready(void *port_, struct file * filp)
483 schedule(); 487 schedule();
484 } 488 }
485 gs_dprintk (GS_DEBUG_BTR, "Got out of the loop. (%d)\n", 489 gs_dprintk (GS_DEBUG_BTR, "Got out of the loop. (%d)\n",
486 port->port.blocked_open); 490 port->blocked_open);
487 set_current_state (TASK_RUNNING); 491 set_current_state (TASK_RUNNING);
488 remove_wait_queue(&port->port.open_wait, &wait); 492 remove_wait_queue(&port->open_wait, &wait);
493
494 spin_lock_irqsave(&port->lock, flags);
489 if (!tty_hung_up_p(filp)) { 495 if (!tty_hung_up_p(filp)) {
490 port->port.count++; 496 port->count++;
491 } 497 }
492 port->port.blocked_open--; 498 port->blocked_open--;
493 if (retval) 499 if (retval == 0)
494 return retval; 500 port->flags |= ASYNC_NORMAL_ACTIVE;
495 501 spin_unlock_irqrestore(&port->lock, flags);
496 port->port.flags |= ASYNC_NORMAL_ACTIVE;
497 func_exit (); 502 func_exit ();
498 return 0; 503 return retval;
499} 504}
500 505
501 506
@@ -506,7 +511,7 @@ void gs_close(struct tty_struct * tty, struct file * filp)
506 511
507 func_enter (); 512 func_enter ();
508 513
509 port = (struct gs_port *) tty->driver_data; 514 port = tty->driver_data;
510 515
511 if (!port) return; 516 if (!port) return;
512 517
@@ -516,10 +521,10 @@ void gs_close(struct tty_struct * tty, struct file * filp)
516 port->port.tty = tty; 521 port->port.tty = tty;
517 } 522 }
518 523
519 spin_lock_irqsave(&port->driver_lock, flags); 524 spin_lock_irqsave(&port->port.lock, flags);
520 525
521 if (tty_hung_up_p(filp)) { 526 if (tty_hung_up_p(filp)) {
522 spin_unlock_irqrestore(&port->driver_lock, flags); 527 spin_unlock_irqrestore(&port->port.lock, flags);
523 if (port->rd->hungup) 528 if (port->rd->hungup)
524 port->rd->hungup (port); 529 port->rd->hungup (port);
525 func_exit (); 530 func_exit ();
@@ -538,7 +543,7 @@ void gs_close(struct tty_struct * tty, struct file * filp)
538 543
539 if (port->port.count) { 544 if (port->port.count) {
540 gs_dprintk(GS_DEBUG_CLOSE, "gs_close port %p: count: %d\n", port, port->port.count); 545 gs_dprintk(GS_DEBUG_CLOSE, "gs_close port %p: count: %d\n", port, port->port.count);
541 spin_unlock_irqrestore(&port->driver_lock, flags); 546 spin_unlock_irqrestore(&port->port.lock, flags);
542 func_exit (); 547 func_exit ();
543 return; 548 return;
544 } 549 }
@@ -559,8 +564,10 @@ void gs_close(struct tty_struct * tty, struct file * filp)
559 * line status register. 564 * line status register.
560 */ 565 */
561 566
567 spin_lock_irqsave(&port->driver_lock, flags);
562 port->rd->disable_rx_interrupts (port); 568 port->rd->disable_rx_interrupts (port);
563 spin_unlock_irqrestore(&port->driver_lock, flags); 569 spin_unlock_irqrestore(&port->driver_lock, flags);
570 spin_unlock_irqrestore(&port->port.lock, flags);
564 571
565 /* close has no way of returning "EINTR", so discard return value */ 572 /* close has no way of returning "EINTR", so discard return value */
566 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 573 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
@@ -573,20 +580,25 @@ void gs_close(struct tty_struct * tty, struct file * filp)
573 tty_ldisc_flush(tty); 580 tty_ldisc_flush(tty);
574 tty->closing = 0; 581 tty->closing = 0;
575 582
583 spin_lock_irqsave(&port->driver_lock, flags);
576 port->event = 0; 584 port->event = 0;
577 port->rd->close (port); 585 port->rd->close (port);
578 port->rd->shutdown_port (port); 586 port->rd->shutdown_port (port);
587 spin_unlock_irqrestore(&port->driver_lock, flags);
588
589 spin_lock_irqsave(&port->port.lock, flags);
579 port->port.tty = NULL; 590 port->port.tty = NULL;
580 591
581 if (port->port.blocked_open) { 592 if (port->port.blocked_open) {
582 if (port->close_delay) { 593 if (port->close_delay) {
583 spin_unlock_irqrestore(&port->driver_lock, flags); 594 spin_unlock_irqrestore(&port->port.lock, flags);
584 msleep_interruptible(jiffies_to_msecs(port->close_delay)); 595 msleep_interruptible(jiffies_to_msecs(port->close_delay));
585 spin_lock_irqsave(&port->driver_lock, flags); 596 spin_lock_irqsave(&port->port.lock, flags);
586 } 597 }
587 wake_up_interruptible(&port->port.open_wait); 598 wake_up_interruptible(&port->port.open_wait);
588 } 599 }
589 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING | ASYNC_INITIALIZED); 600 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING | ASYNC_INITIALIZED);
601 spin_unlock_irqrestore(&port->port.lock, flags);
590 wake_up_interruptible(&port->port.close_wait); 602 wake_up_interruptible(&port->port.close_wait);
591 603
592 func_exit (); 604 func_exit ();
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 0587b66d6fc7..5a8a4c28c867 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -529,7 +529,7 @@ static void hvc_set_winsz(struct work_struct *work)
529 tty = tty_kref_get(hp->tty); 529 tty = tty_kref_get(hp->tty);
530 spin_unlock_irqrestore(&hp->lock, hvc_flags); 530 spin_unlock_irqrestore(&hp->lock, hvc_flags);
531 531
532 tty_do_resize(tty, tty, &ws); 532 tty_do_resize(tty, &ws);
533 tty_kref_put(tty); 533 tty_kref_put(tty);
534} 534}
535 535
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index af055287271a..406f8742a260 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -997,14 +997,14 @@ out:
997 997
998static int hvsi_write_room(struct tty_struct *tty) 998static int hvsi_write_room(struct tty_struct *tty)
999{ 999{
1000 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1000 struct hvsi_struct *hp = tty->driver_data;
1001 1001
1002 return N_OUTBUF - hp->n_outbuf; 1002 return N_OUTBUF - hp->n_outbuf;
1003} 1003}
1004 1004
1005static int hvsi_chars_in_buffer(struct tty_struct *tty) 1005static int hvsi_chars_in_buffer(struct tty_struct *tty)
1006{ 1006{
1007 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1007 struct hvsi_struct *hp = tty->driver_data;
1008 1008
1009 return hp->n_outbuf; 1009 return hp->n_outbuf;
1010} 1010}
@@ -1070,7 +1070,7 @@ out:
1070 */ 1070 */
1071static void hvsi_throttle(struct tty_struct *tty) 1071static void hvsi_throttle(struct tty_struct *tty)
1072{ 1072{
1073 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1073 struct hvsi_struct *hp = tty->driver_data;
1074 1074
1075 pr_debug("%s\n", __func__); 1075 pr_debug("%s\n", __func__);
1076 1076
@@ -1079,7 +1079,7 @@ static void hvsi_throttle(struct tty_struct *tty)
1079 1079
1080static void hvsi_unthrottle(struct tty_struct *tty) 1080static void hvsi_unthrottle(struct tty_struct *tty)
1081{ 1081{
1082 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1082 struct hvsi_struct *hp = tty->driver_data;
1083 unsigned long flags; 1083 unsigned long flags;
1084 int shouldflip = 0; 1084 int shouldflip = 0;
1085 1085
@@ -1100,7 +1100,7 @@ static void hvsi_unthrottle(struct tty_struct *tty)
1100 1100
1101static int hvsi_tiocmget(struct tty_struct *tty, struct file *file) 1101static int hvsi_tiocmget(struct tty_struct *tty, struct file *file)
1102{ 1102{
1103 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1103 struct hvsi_struct *hp = tty->driver_data;
1104 1104
1105 hvsi_get_mctrl(hp); 1105 hvsi_get_mctrl(hp);
1106 return hp->mctrl; 1106 return hp->mctrl;
@@ -1109,7 +1109,7 @@ static int hvsi_tiocmget(struct tty_struct *tty, struct file *file)
1109static int hvsi_tiocmset(struct tty_struct *tty, struct file *file, 1109static int hvsi_tiocmset(struct tty_struct *tty, struct file *file,
1110 unsigned int set, unsigned int clear) 1110 unsigned int set, unsigned int clear)
1111{ 1111{
1112 struct hvsi_struct *hp = (struct hvsi_struct *)tty->driver_data; 1112 struct hvsi_struct *hp = tty->driver_data;
1113 unsigned long flags; 1113 unsigned long flags;
1114 uint16_t new_mctrl; 1114 uint16_t new_mctrl;
1115 1115
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 04e4549299ba..24aa6e88e223 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -328,11 +328,13 @@ static inline void drop_rts(struct isi_port *port)
328} 328}
329 329
330/* card->lock MUST NOT be held */ 330/* card->lock MUST NOT be held */
331static inline void raise_dtr_rts(struct isi_port *port) 331
332static void isicom_raise_dtr_rts(struct tty_port *port)
332{ 333{
333 struct isi_board *card = port->card; 334 struct isi_port *ip = container_of(port, struct isi_port, port);
335 struct isi_board *card = ip->card;
334 unsigned long base = card->base; 336 unsigned long base = card->base;
335 u16 channel = port->channel; 337 u16 channel = ip->channel;
336 338
337 if (!lock_card(card)) 339 if (!lock_card(card))
338 return; 340 return;
@@ -340,7 +342,7 @@ static inline void raise_dtr_rts(struct isi_port *port)
340 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 342 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
341 outw(0x0f04, base); 343 outw(0x0f04, base);
342 InterruptTheCard(base); 344 InterruptTheCard(base);
343 port->status |= (ISI_DTR | ISI_RTS); 345 ip->status |= (ISI_DTR | ISI_RTS);
344 unlock_card(card); 346 unlock_card(card);
345} 347}
346 348
@@ -830,80 +832,10 @@ static int isicom_setup_port(struct tty_struct *tty)
830 return 0; 832 return 0;
831} 833}
832 834
833static int block_til_ready(struct tty_struct *tty, struct file *filp, 835static int isicom_carrier_raised(struct tty_port *port)
834 struct isi_port *port)
835{ 836{
836 struct isi_board *card = port->card; 837 struct isi_port *ip = container_of(port, struct isi_port, port);
837 int do_clocal = 0, retval; 838 return (ip->status & ISI_DCD)?1 : 0;
838 unsigned long flags;
839 DECLARE_WAITQUEUE(wait, current);
840
841 /* block if port is in the process of being closed */
842
843 if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) {
844 pr_dbg("block_til_ready: close in progress.\n");
845 interruptible_sleep_on(&port->port.close_wait);
846 if (port->port.flags & ASYNC_HUP_NOTIFY)
847 return -EAGAIN;
848 else
849 return -ERESTARTSYS;
850 }
851
852 /* if non-blocking mode is set ... */
853
854 if ((filp->f_flags & O_NONBLOCK) ||
855 (tty->flags & (1 << TTY_IO_ERROR))) {
856 pr_dbg("block_til_ready: non-block mode.\n");
857 port->port.flags |= ASYNC_NORMAL_ACTIVE;
858 return 0;
859 }
860
861 if (C_CLOCAL(tty))
862 do_clocal = 1;
863
864 /* block waiting for DCD to be asserted, and while
865 callout dev is busy */
866 retval = 0;
867 add_wait_queue(&port->port.open_wait, &wait);
868
869 spin_lock_irqsave(&card->card_lock, flags);
870 if (!tty_hung_up_p(filp))
871 port->port.count--;
872 port->port.blocked_open++;
873 spin_unlock_irqrestore(&card->card_lock, flags);
874
875 while (1) {
876 raise_dtr_rts(port);
877
878 set_current_state(TASK_INTERRUPTIBLE);
879 if (tty_hung_up_p(filp) || !(port->port.flags & ASYNC_INITIALIZED)) {
880 if (port->port.flags & ASYNC_HUP_NOTIFY)
881 retval = -EAGAIN;
882 else
883 retval = -ERESTARTSYS;
884 break;
885 }
886 if (!(port->port.flags & ASYNC_CLOSING) &&
887 (do_clocal || (port->status & ISI_DCD))) {
888 break;
889 }
890 if (signal_pending(current)) {
891 retval = -ERESTARTSYS;
892 break;
893 }
894 schedule();
895 }
896 set_current_state(TASK_RUNNING);
897 remove_wait_queue(&port->port.open_wait, &wait);
898 spin_lock_irqsave(&card->card_lock, flags);
899 if (!tty_hung_up_p(filp))
900 port->port.count++;
901 port->port.blocked_open--;
902 spin_unlock_irqrestore(&card->card_lock, flags);
903 if (retval)
904 return retval;
905 port->port.flags |= ASYNC_NORMAL_ACTIVE;
906 return 0;
907} 839}
908 840
909static int isicom_open(struct tty_struct *tty, struct file *filp) 841static int isicom_open(struct tty_struct *tty, struct file *filp)
@@ -932,12 +864,13 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
932 864
933 isicom_setup_board(card); 865 isicom_setup_board(card);
934 866
867 /* FIXME: locking on port.count etc */
935 port->port.count++; 868 port->port.count++;
936 tty->driver_data = port; 869 tty->driver_data = port;
937 tty_port_tty_set(&port->port, tty); 870 tty_port_tty_set(&port->port, tty);
938 error = isicom_setup_port(tty); 871 error = isicom_setup_port(tty);
939 if (error == 0) 872 if (error == 0)
940 error = block_til_ready(tty, filp, port); 873 error = tty_port_block_til_ready(&port->port, tty, filp);
941 return error; 874 return error;
942} 875}
943 876
@@ -1012,76 +945,30 @@ static void isicom_flush_buffer(struct tty_struct *tty)
1012 945
1013static void isicom_close(struct tty_struct *tty, struct file *filp) 946static void isicom_close(struct tty_struct *tty, struct file *filp)
1014{ 947{
1015 struct isi_port *port = tty->driver_data; 948 struct isi_port *ip = tty->driver_data;
949 struct tty_port *port = &ip->port;
1016 struct isi_board *card; 950 struct isi_board *card;
1017 unsigned long flags; 951 unsigned long flags;
1018 952
1019 if (!port) 953 BUG_ON(!ip);
1020 return;
1021 card = port->card;
1022 if (isicom_paranoia_check(port, tty->name, "isicom_close"))
1023 return;
1024
1025 pr_dbg("Close start!!!.\n");
1026
1027 spin_lock_irqsave(&card->card_lock, flags);
1028 if (tty_hung_up_p(filp)) {
1029 spin_unlock_irqrestore(&card->card_lock, flags);
1030 return;
1031 }
1032
1033 if (tty->count == 1 && port->port.count != 1) {
1034 printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port "
1035 "count tty->count = 1 port count = %d.\n",
1036 card->base, port->port.count);
1037 port->port.count = 1;
1038 }
1039 if (--port->port.count < 0) {
1040 printk(KERN_WARNING "ISICOM:(0x%lx) isicom_close: bad port "
1041 "count for channel%d = %d", card->base, port->channel,
1042 port->port.count);
1043 port->port.count = 0;
1044 }
1045 954
1046 if (port->port.count) { 955 card = ip->card;
1047 spin_unlock_irqrestore(&card->card_lock, flags); 956 if (isicom_paranoia_check(ip, tty->name, "isicom_close"))
1048 return; 957 return;
1049 }
1050 port->port.flags |= ASYNC_CLOSING;
1051 tty->closing = 1;
1052 spin_unlock_irqrestore(&card->card_lock, flags);
1053 958
1054 if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
1055 tty_wait_until_sent(tty, port->port.closing_wait);
1056 /* indicate to the card that no more data can be received 959 /* indicate to the card that no more data can be received
1057 on this port */ 960 on this port */
1058 spin_lock_irqsave(&card->card_lock, flags); 961 spin_lock_irqsave(&card->card_lock, flags);
1059 if (port->port.flags & ASYNC_INITIALIZED) { 962 if (port->flags & ASYNC_INITIALIZED) {
1060 card->port_status &= ~(1 << port->channel); 963 card->port_status &= ~(1 << ip->channel);
1061 outw(card->port_status, card->base + 0x02); 964 outw(card->port_status, card->base + 0x02);
1062 } 965 }
1063 isicom_shutdown_port(port); 966 isicom_shutdown_port(ip);
1064 spin_unlock_irqrestore(&card->card_lock, flags); 967 spin_unlock_irqrestore(&card->card_lock, flags);
1065 968
1066 isicom_flush_buffer(tty); 969 isicom_flush_buffer(tty);
1067 tty_ldisc_flush(tty); 970
1068 971 tty_port_close_end(port, tty);
1069 spin_lock_irqsave(&card->card_lock, flags);
1070 tty->closing = 0;
1071
1072 if (port->port.blocked_open) {
1073 spin_unlock_irqrestore(&card->card_lock, flags);
1074 if (port->port.close_delay) {
1075 pr_dbg("scheduling until time out.\n");
1076 msleep_interruptible(
1077 jiffies_to_msecs(port->port.close_delay));
1078 }
1079 spin_lock_irqsave(&card->card_lock, flags);
1080 wake_up_interruptible(&port->port.open_wait);
1081 }
1082 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1083 wake_up_interruptible(&port->port.close_wait);
1084 spin_unlock_irqrestore(&card->card_lock, flags);
1085} 972}
1086 973
1087/* write et all */ 974/* write et all */
@@ -1420,10 +1307,7 @@ static void isicom_hangup(struct tty_struct *tty)
1420 isicom_shutdown_port(port); 1307 isicom_shutdown_port(port);
1421 spin_unlock_irqrestore(&port->card->card_lock, flags); 1308 spin_unlock_irqrestore(&port->card->card_lock, flags);
1422 1309
1423 port->port.count = 0; 1310 tty_port_hangup(&port->port);
1424 port->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1425 tty_port_tty_set(&port->port, NULL);
1426 wake_up_interruptible(&port->port.open_wait);
1427} 1311}
1428 1312
1429 1313
@@ -1452,6 +1336,11 @@ static const struct tty_operations isicom_ops = {
1452 .break_ctl = isicom_send_break, 1336 .break_ctl = isicom_send_break,
1453}; 1337};
1454 1338
1339static const struct tty_port_operations isicom_port_ops = {
1340 .carrier_raised = isicom_carrier_raised,
1341 .raise_dtr_rts = isicom_raise_dtr_rts,
1342};
1343
1455static int __devinit reset_card(struct pci_dev *pdev, 1344static int __devinit reset_card(struct pci_dev *pdev,
1456 const unsigned int card, unsigned int *signature) 1345 const unsigned int card, unsigned int *signature)
1457{ 1346{
@@ -1794,6 +1683,7 @@ static int __init isicom_init(void)
1794 spin_lock_init(&isi_card[idx].card_lock); 1683 spin_lock_init(&isi_card[idx].card_lock);
1795 for (channel = 0; channel < 16; channel++, port++) { 1684 for (channel = 0; channel < 16; channel++, port++) {
1796 tty_port_init(&port->port); 1685 tty_port_init(&port->port);
1686 port->port.ops = &isicom_port_ops;
1797 port->magic = ISICOM_MAGIC; 1687 port->magic = ISICOM_MAGIC;
1798 port->card = &isi_card[idx]; 1688 port->card = &isi_card[idx];
1799 port->channel = channel; 1689 port->channel = channel;
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 4b10770fa937..5c3dc6b8411c 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -151,7 +151,7 @@ static char *stli_drvversion = "5.6.0";
151static char *stli_serialname = "ttyE"; 151static char *stli_serialname = "ttyE";
152 152
153static struct tty_driver *stli_serial; 153static struct tty_driver *stli_serial;
154 154static const struct tty_port_operations stli_port_ops;
155 155
156#define STLI_TXBUFSIZE 4096 156#define STLI_TXBUFSIZE 4096
157 157
@@ -626,8 +626,6 @@ static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
626static int stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp); 626static int stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp);
627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); 627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); 628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
629static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp,
630 struct stliport *portp, struct file *filp);
631static int stli_setport(struct tty_struct *tty); 629static int stli_setport(struct tty_struct *tty);
632static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); 630static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
633static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); 631static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
@@ -769,7 +767,7 @@ static int stli_parsebrd(struct stlconf *confp, char **argp)
769 break; 767 break;
770 } 768 }
771 if (i == ARRAY_SIZE(stli_brdstr)) { 769 if (i == ARRAY_SIZE(stli_brdstr)) {
772 printk("STALLION: unknown board name, %s?\n", argp[0]); 770 printk(KERN_WARNING "istallion: unknown board name, %s?\n", argp[0]);
773 return 0; 771 return 0;
774 } 772 }
775 773
@@ -787,6 +785,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
787{ 785{
788 struct stlibrd *brdp; 786 struct stlibrd *brdp;
789 struct stliport *portp; 787 struct stliport *portp;
788 struct tty_port *port;
790 unsigned int minordev, brdnr, portnr; 789 unsigned int minordev, brdnr, portnr;
791 int rc; 790 int rc;
792 791
@@ -808,30 +807,19 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
808 return -ENODEV; 807 return -ENODEV;
809 if (portp->devnr < 1) 808 if (portp->devnr < 1)
810 return -ENODEV; 809 return -ENODEV;
811 810 port = &portp->port;
812
813/*
814 * Check if this port is in the middle of closing. If so then wait
815 * until it is closed then return error status based on flag settings.
816 * The sleep here does not need interrupt protection since the wakeup
817 * for it is done with the same context.
818 */
819 if (portp->port.flags & ASYNC_CLOSING) {
820 interruptible_sleep_on(&portp->port.close_wait);
821 if (portp->port.flags & ASYNC_HUP_NOTIFY)
822 return -EAGAIN;
823 return -ERESTARTSYS;
824 }
825 811
826/* 812/*
827 * On the first open of the device setup the port hardware, and 813 * On the first open of the device setup the port hardware, and
828 * initialize the per port data structure. Since initializing the port 814 * initialize the per port data structure. Since initializing the port
829 * requires several commands to the board we will need to wait for any 815 * requires several commands to the board we will need to wait for any
830 * other open that is already initializing the port. 816 * other open that is already initializing the port.
817 *
818 * Review - locking
831 */ 819 */
832 tty_port_tty_set(&portp->port, tty); 820 tty_port_tty_set(port, tty);
833 tty->driver_data = portp; 821 tty->driver_data = portp;
834 portp->port.count++; 822 port->count++;
835 823
836 wait_event_interruptible(portp->raw_wait, 824 wait_event_interruptible(portp->raw_wait,
837 !test_bit(ST_INITIALIZING, &portp->state)); 825 !test_bit(ST_INITIALIZING, &portp->state));
@@ -841,7 +829,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
841 if ((portp->port.flags & ASYNC_INITIALIZED) == 0) { 829 if ((portp->port.flags & ASYNC_INITIALIZED) == 0) {
842 set_bit(ST_INITIALIZING, &portp->state); 830 set_bit(ST_INITIALIZING, &portp->state);
843 if ((rc = stli_initopen(tty, brdp, portp)) >= 0) { 831 if ((rc = stli_initopen(tty, brdp, portp)) >= 0) {
844 portp->port.flags |= ASYNC_INITIALIZED; 832 /* Locking */
833 port->flags |= ASYNC_INITIALIZED;
845 clear_bit(TTY_IO_ERROR, &tty->flags); 834 clear_bit(TTY_IO_ERROR, &tty->flags);
846 } 835 }
847 clear_bit(ST_INITIALIZING, &portp->state); 836 clear_bit(ST_INITIALIZING, &portp->state);
@@ -849,31 +838,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
849 if (rc < 0) 838 if (rc < 0)
850 return rc; 839 return rc;
851 } 840 }
852 841 return tty_port_block_til_ready(&portp->port, tty, filp);
853/*
854 * Check if this port is in the middle of closing. If so then wait
855 * until it is closed then return error status, based on flag settings.
856 * The sleep here does not need interrupt protection since the wakeup
857 * for it is done with the same context.
858 */
859 if (portp->port.flags & ASYNC_CLOSING) {
860 interruptible_sleep_on(&portp->port.close_wait);
861 if (portp->port.flags & ASYNC_HUP_NOTIFY)
862 return -EAGAIN;
863 return -ERESTARTSYS;
864 }
865
866/*
867 * Based on type of open being done check if it can overlap with any
868 * previous opens still in effect. If we are a normal serial device
869 * then also we might have to wait for carrier.
870 */
871 if (!(filp->f_flags & O_NONBLOCK)) {
872 if ((rc = stli_waitcarrier(tty, brdp, portp, filp)) != 0)
873 return rc;
874 }
875 portp->port.flags |= ASYNC_NORMAL_ACTIVE;
876 return 0;
877} 842}
878 843
879/*****************************************************************************/ 844/*****************************************************************************/
@@ -882,25 +847,16 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
882{ 847{
883 struct stlibrd *brdp; 848 struct stlibrd *brdp;
884 struct stliport *portp; 849 struct stliport *portp;
850 struct tty_port *port;
885 unsigned long flags; 851 unsigned long flags;
886 852
887 portp = tty->driver_data; 853 portp = tty->driver_data;
888 if (portp == NULL) 854 if (portp == NULL)
889 return; 855 return;
856 port = &portp->port;
890 857
891 spin_lock_irqsave(&stli_lock, flags); 858 if (tty_port_close_start(port, tty, filp) == 0)
892 if (tty_hung_up_p(filp)) {
893 spin_unlock_irqrestore(&stli_lock, flags);
894 return;
895 }
896 if ((tty->count == 1) && (portp->port.count != 1))
897 portp->port.count = 1;
898 if (portp->port.count-- > 1) {
899 spin_unlock_irqrestore(&stli_lock, flags);
900 return; 859 return;
901 }
902
903 portp->port.flags |= ASYNC_CLOSING;
904 860
905/* 861/*
906 * May want to wait for data to drain before closing. The BUSY flag 862 * May want to wait for data to drain before closing. The BUSY flag
@@ -908,15 +864,19 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
908 * updated by messages from the slave - indicating when all chars 864 * updated by messages from the slave - indicating when all chars
909 * really have drained. 865 * really have drained.
910 */ 866 */
867 spin_lock_irqsave(&stli_lock, flags);
911 if (tty == stli_txcooktty) 868 if (tty == stli_txcooktty)
912 stli_flushchars(tty); 869 stli_flushchars(tty);
913 tty->closing = 1;
914 spin_unlock_irqrestore(&stli_lock, flags); 870 spin_unlock_irqrestore(&stli_lock, flags);
915 871
872 /* We end up doing this twice for the moment. This needs looking at
873 eventually. Note we still use portp->closing_wait as a result */
916 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) 874 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
917 tty_wait_until_sent(tty, portp->closing_wait); 875 tty_wait_until_sent(tty, portp->closing_wait);
918 876
919 portp->port.flags &= ~ASYNC_INITIALIZED; 877 /* FIXME: port locking here needs attending to */
878 port->flags &= ~ASYNC_INITIALIZED;
879
920 brdp = stli_brds[portp->brdnr]; 880 brdp = stli_brds[portp->brdnr];
921 stli_rawclose(brdp, portp, 0, 0); 881 stli_rawclose(brdp, portp, 0, 0);
922 if (tty->termios->c_cflag & HUPCL) { 882 if (tty->termios->c_cflag & HUPCL) {
@@ -934,17 +894,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
934 set_bit(ST_DOFLUSHRX, &portp->state); 894 set_bit(ST_DOFLUSHRX, &portp->state);
935 stli_flushbuffer(tty); 895 stli_flushbuffer(tty);
936 896
937 tty->closing = 0; 897 tty_port_close_end(port, tty);
938 tty_port_tty_set(&portp->port, NULL); 898 tty_port_tty_set(port, NULL);
939
940 if (portp->openwaitcnt) {
941 if (portp->close_delay)
942 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
943 wake_up_interruptible(&portp->port.open_wait);
944 }
945
946 portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
947 wake_up_interruptible(&portp->port.close_wait);
948} 899}
949 900
950/*****************************************************************************/ 901/*****************************************************************************/
@@ -1183,62 +1134,23 @@ static int stli_setport(struct tty_struct *tty)
1183 1134
1184/*****************************************************************************/ 1135/*****************************************************************************/
1185 1136
1186/* 1137static int stli_carrier_raised(struct tty_port *port)
1187 * Possibly need to wait for carrier (DCD signal) to come high. Say
1188 * maybe because if we are clocal then we don't need to wait...
1189 */
1190
1191static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp,
1192 struct stliport *portp, struct file *filp)
1193{ 1138{
1194 unsigned long flags; 1139 struct stliport *portp = container_of(port, struct stliport, port);
1195 int rc, doclocal; 1140 return (portp->sigs & TIOCM_CD) ? 1 : 0;
1196 1141}
1197 rc = 0;
1198 doclocal = 0;
1199
1200 if (tty->termios->c_cflag & CLOCAL)
1201 doclocal++;
1202
1203 spin_lock_irqsave(&stli_lock, flags);
1204 portp->openwaitcnt++;
1205 if (! tty_hung_up_p(filp))
1206 portp->port.count--;
1207 spin_unlock_irqrestore(&stli_lock, flags);
1208
1209 for (;;) {
1210 stli_mkasysigs(&portp->asig, 1, 1);
1211 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
1212 &portp->asig, sizeof(asysigs_t), 0)) < 0)
1213 break;
1214 if (tty_hung_up_p(filp) ||
1215 ((portp->port.flags & ASYNC_INITIALIZED) == 0)) {
1216 if (portp->port.flags & ASYNC_HUP_NOTIFY)
1217 rc = -EBUSY;
1218 else
1219 rc = -ERESTARTSYS;
1220 break;
1221 }
1222 if (((portp->port.flags & ASYNC_CLOSING) == 0) &&
1223 (doclocal || (portp->sigs & TIOCM_CD))) {
1224 break;
1225 }
1226 if (signal_pending(current)) {
1227 rc = -ERESTARTSYS;
1228 break;
1229 }
1230 interruptible_sleep_on(&portp->port.open_wait);
1231 }
1232
1233 spin_lock_irqsave(&stli_lock, flags);
1234 if (! tty_hung_up_p(filp))
1235 portp->port.count++;
1236 portp->openwaitcnt--;
1237 spin_unlock_irqrestore(&stli_lock, flags);
1238 1142
1239 return rc; 1143static void stli_raise_dtr_rts(struct tty_port *port)
1144{
1145 struct stliport *portp = container_of(port, struct stliport, port);
1146 struct stlibrd *brdp = stli_brds[portp->brdnr];
1147 stli_mkasysigs(&portp->asig, 1, 1);
1148 if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1149 sizeof(asysigs_t), 0) < 0)
1150 printk(KERN_WARNING "istallion: dtr raise failed.\n");
1240} 1151}
1241 1152
1153
1242/*****************************************************************************/ 1154/*****************************************************************************/
1243 1155
1244/* 1156/*
@@ -1550,7 +1462,7 @@ static int stli_getserial(struct stliport *portp, struct serial_struct __user *s
1550 sio.irq = 0; 1462 sio.irq = 0;
1551 sio.flags = portp->port.flags; 1463 sio.flags = portp->port.flags;
1552 sio.baud_base = portp->baud_base; 1464 sio.baud_base = portp->baud_base;
1553 sio.close_delay = portp->close_delay; 1465 sio.close_delay = portp->port.close_delay;
1554 sio.closing_wait = portp->closing_wait; 1466 sio.closing_wait = portp->closing_wait;
1555 sio.custom_divisor = portp->custom_divisor; 1467 sio.custom_divisor = portp->custom_divisor;
1556 sio.xmit_fifo_size = 0; 1468 sio.xmit_fifo_size = 0;
@@ -1582,7 +1494,7 @@ static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *s
1582 return -EFAULT; 1494 return -EFAULT;
1583 if (!capable(CAP_SYS_ADMIN)) { 1495 if (!capable(CAP_SYS_ADMIN)) {
1584 if ((sio.baud_base != portp->baud_base) || 1496 if ((sio.baud_base != portp->baud_base) ||
1585 (sio.close_delay != portp->close_delay) || 1497 (sio.close_delay != portp->port.close_delay) ||
1586 ((sio.flags & ~ASYNC_USR_MASK) != 1498 ((sio.flags & ~ASYNC_USR_MASK) !=
1587 (portp->port.flags & ~ASYNC_USR_MASK))) 1499 (portp->port.flags & ~ASYNC_USR_MASK)))
1588 return -EPERM; 1500 return -EPERM;
@@ -1591,7 +1503,7 @@ static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *s
1591 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) | 1503 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
1592 (sio.flags & ASYNC_USR_MASK); 1504 (sio.flags & ASYNC_USR_MASK);
1593 portp->baud_base = sio.baud_base; 1505 portp->baud_base = sio.baud_base;
1594 portp->close_delay = sio.close_delay; 1506 portp->port.close_delay = sio.close_delay;
1595 portp->closing_wait = sio.closing_wait; 1507 portp->closing_wait = sio.closing_wait;
1596 portp->custom_divisor = sio.custom_divisor; 1508 portp->custom_divisor = sio.custom_divisor;
1597 1509
@@ -1821,6 +1733,7 @@ static void stli_hangup(struct tty_struct *tty)
1821{ 1733{
1822 struct stliport *portp; 1734 struct stliport *portp;
1823 struct stlibrd *brdp; 1735 struct stlibrd *brdp;
1736 struct tty_port *port;
1824 unsigned long flags; 1737 unsigned long flags;
1825 1738
1826 portp = tty->driver_data; 1739 portp = tty->driver_data;
@@ -1831,8 +1744,11 @@ static void stli_hangup(struct tty_struct *tty)
1831 brdp = stli_brds[portp->brdnr]; 1744 brdp = stli_brds[portp->brdnr];
1832 if (brdp == NULL) 1745 if (brdp == NULL)
1833 return; 1746 return;
1747 port = &portp->port;
1834 1748
1835 portp->port.flags &= ~ASYNC_INITIALIZED; 1749 spin_lock_irqsave(&port->lock, flags);
1750 port->flags &= ~ASYNC_INITIALIZED;
1751 spin_unlock_irqrestore(&port->lock, flags);
1836 1752
1837 if (!test_bit(ST_CLOSING, &portp->state)) 1753 if (!test_bit(ST_CLOSING, &portp->state))
1838 stli_rawclose(brdp, portp, 0, 0); 1754 stli_rawclose(brdp, portp, 0, 0);
@@ -1853,12 +1769,9 @@ static void stli_hangup(struct tty_struct *tty)
1853 clear_bit(ST_TXBUSY, &portp->state); 1769 clear_bit(ST_TXBUSY, &portp->state);
1854 clear_bit(ST_RXSTOP, &portp->state); 1770 clear_bit(ST_RXSTOP, &portp->state);
1855 set_bit(TTY_IO_ERROR, &tty->flags); 1771 set_bit(TTY_IO_ERROR, &tty->flags);
1856 tty_port_tty_set(&portp->port, NULL);
1857 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1858 portp->port.count = 0;
1859 spin_unlock_irqrestore(&stli_lock, flags); 1772 spin_unlock_irqrestore(&stli_lock, flags);
1860 1773
1861 wake_up_interruptible(&portp->port.open_wait); 1774 tty_port_hangup(port);
1862} 1775}
1863 1776
1864/*****************************************************************************/ 1777/*****************************************************************************/
@@ -2132,7 +2045,7 @@ static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigne
2132 unsigned char __iomem *bits; 2045 unsigned char __iomem *bits;
2133 2046
2134 if (test_bit(ST_CMDING, &portp->state)) { 2047 if (test_bit(ST_CMDING, &portp->state)) {
2135 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n", 2048 printk(KERN_ERR "istallion: command already busy, cmd=%x!\n",
2136 (int) cmd); 2049 (int) cmd);
2137 return; 2050 return;
2138 } 2051 }
@@ -2692,16 +2605,17 @@ static int stli_initports(struct stlibrd *brdp)
2692 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 2605 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2693 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL); 2606 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
2694 if (!portp) { 2607 if (!portp) {
2695 printk("STALLION: failed to allocate port structure\n"); 2608 printk(KERN_WARNING "istallion: failed to allocate port structure\n");
2696 continue; 2609 continue;
2697 } 2610 }
2698 tty_port_init(&portp->port); 2611 tty_port_init(&portp->port);
2612 portp->port.ops = &stli_port_ops;
2699 portp->magic = STLI_PORTMAGIC; 2613 portp->magic = STLI_PORTMAGIC;
2700 portp->portnr = i; 2614 portp->portnr = i;
2701 portp->brdnr = brdp->brdnr; 2615 portp->brdnr = brdp->brdnr;
2702 portp->panelnr = panelnr; 2616 portp->panelnr = panelnr;
2703 portp->baud_base = STL_BAUDBASE; 2617 portp->baud_base = STL_BAUDBASE;
2704 portp->close_delay = STL_CLOSEDELAY; 2618 portp->port.close_delay = STL_CLOSEDELAY;
2705 portp->closing_wait = 30 * HZ; 2619 portp->closing_wait = 30 * HZ;
2706 init_waitqueue_head(&portp->port.open_wait); 2620 init_waitqueue_head(&portp->port.open_wait);
2707 init_waitqueue_head(&portp->port.close_wait); 2621 init_waitqueue_head(&portp->port.close_wait);
@@ -2758,7 +2672,7 @@ static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offse
2758 unsigned char val; 2672 unsigned char val;
2759 2673
2760 if (offset > brdp->memsize) { 2674 if (offset > brdp->memsize) {
2761 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2675 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2762 "range at line=%d(%d), brd=%d\n", 2676 "range at line=%d(%d), brd=%d\n",
2763 (int) offset, line, __LINE__, brdp->brdnr); 2677 (int) offset, line, __LINE__, brdp->brdnr);
2764 ptr = NULL; 2678 ptr = NULL;
@@ -2832,7 +2746,7 @@ static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long off
2832 unsigned char val; 2746 unsigned char val;
2833 2747
2834 if (offset > brdp->memsize) { 2748 if (offset > brdp->memsize) {
2835 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2749 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2836 "range at line=%d(%d), brd=%d\n", 2750 "range at line=%d(%d), brd=%d\n",
2837 (int) offset, line, __LINE__, brdp->brdnr); 2751 (int) offset, line, __LINE__, brdp->brdnr);
2838 ptr = NULL; 2752 ptr = NULL;
@@ -2884,7 +2798,7 @@ static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long off
2884 unsigned char val; 2798 unsigned char val;
2885 2799
2886 if (offset > brdp->memsize) { 2800 if (offset > brdp->memsize) {
2887 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2801 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2888 "range at line=%d(%d), brd=%d\n", 2802 "range at line=%d(%d), brd=%d\n",
2889 (int) offset, line, __LINE__, brdp->brdnr); 2803 (int) offset, line, __LINE__, brdp->brdnr);
2890 ptr = NULL; 2804 ptr = NULL;
@@ -2929,7 +2843,7 @@ static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long of
2929 unsigned char val; 2843 unsigned char val;
2930 2844
2931 if (offset > brdp->memsize) { 2845 if (offset > brdp->memsize) {
2932 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2846 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2933 "range at line=%d(%d), board=%d\n", 2847 "range at line=%d(%d), board=%d\n",
2934 (int) offset, line, __LINE__, brdp->brdnr); 2848 (int) offset, line, __LINE__, brdp->brdnr);
2935 ptr = NULL; 2849 ptr = NULL;
@@ -2994,7 +2908,7 @@ static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offse
2994 void __iomem *ptr; 2908 void __iomem *ptr;
2995 2909
2996 if (offset > brdp->memsize) { 2910 if (offset > brdp->memsize) {
2997 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2911 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
2998 "range at line=%d(%d), brd=%d\n", 2912 "range at line=%d(%d), brd=%d\n",
2999 (int) offset, line, __LINE__, brdp->brdnr); 2913 (int) offset, line, __LINE__, brdp->brdnr);
3000 ptr = NULL; 2914 ptr = NULL;
@@ -3060,7 +2974,7 @@ static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offs
3060 unsigned char val; 2974 unsigned char val;
3061 2975
3062 if (offset > brdp->memsize) { 2976 if (offset > brdp->memsize) {
3063 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2977 printk(KERN_ERR "istallion: shared memory pointer=%x out of "
3064 "range at line=%d(%d), brd=%d\n", 2978 "range at line=%d(%d), brd=%d\n",
3065 (int) offset, line, __LINE__, brdp->brdnr); 2979 (int) offset, line, __LINE__, brdp->brdnr);
3066 ptr = NULL; 2980 ptr = NULL;
@@ -3499,7 +3413,7 @@ static int stli_startbrd(struct stlibrd *brdp)
3499#endif 3413#endif
3500 3414
3501 if (nrdevs < (brdp->nrports + 1)) { 3415 if (nrdevs < (brdp->nrports + 1)) {
3502 printk(KERN_ERR "STALLION: slave failed to allocate memory for " 3416 printk(KERN_ERR "istallion: slave failed to allocate memory for "
3503 "all devices, devices=%d\n", nrdevs); 3417 "all devices, devices=%d\n", nrdevs);
3504 brdp->nrports = nrdevs - 1; 3418 brdp->nrports = nrdevs - 1;
3505 } 3419 }
@@ -3509,13 +3423,13 @@ static int stli_startbrd(struct stlibrd *brdp)
3509 brdp->bitsize = (nrdevs + 7) / 8; 3423 brdp->bitsize = (nrdevs + 7) / 8;
3510 memoff = readl(&hdrp->memp); 3424 memoff = readl(&hdrp->memp);
3511 if (memoff > brdp->memsize) { 3425 if (memoff > brdp->memsize) {
3512 printk(KERN_ERR "STALLION: corrupted shared memory region?\n"); 3426 printk(KERN_ERR "istallion: corrupted shared memory region?\n");
3513 rc = -EIO; 3427 rc = -EIO;
3514 goto stli_donestartup; 3428 goto stli_donestartup;
3515 } 3429 }
3516 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff); 3430 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
3517 if (readw(&memp->dtype) != TYP_ASYNCTRL) { 3431 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
3518 printk(KERN_ERR "STALLION: no slave control device found\n"); 3432 printk(KERN_ERR "istallion: no slave control device found\n");
3519 goto stli_donestartup; 3433 goto stli_donestartup;
3520 } 3434 }
3521 memp++; 3435 memp++;
@@ -3600,7 +3514,7 @@ static int __devinit stli_brdinit(struct stlibrd *brdp)
3600 retval = stli_initonb(brdp); 3514 retval = stli_initonb(brdp);
3601 break; 3515 break;
3602 default: 3516 default:
3603 printk(KERN_ERR "STALLION: board=%d is unknown board " 3517 printk(KERN_ERR "istallion: board=%d is unknown board "
3604 "type=%d\n", brdp->brdnr, brdp->brdtype); 3518 "type=%d\n", brdp->brdnr, brdp->brdtype);
3605 retval = -ENODEV; 3519 retval = -ENODEV;
3606 } 3520 }
@@ -3609,7 +3523,7 @@ static int __devinit stli_brdinit(struct stlibrd *brdp)
3609 return retval; 3523 return retval;
3610 3524
3611 stli_initports(brdp); 3525 stli_initports(brdp);
3612 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x " 3526 printk(KERN_INFO "istallion: %s found, board=%d io=%x mem=%x "
3613 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], 3527 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
3614 brdp->brdnr, brdp->iobase, (int) brdp->memaddr, 3528 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
3615 brdp->nrpanels, brdp->nrports); 3529 brdp->nrpanels, brdp->nrports);
@@ -3703,7 +3617,7 @@ static int stli_eisamemprobe(struct stlibrd *brdp)
3703 if (! foundit) { 3617 if (! foundit) {
3704 brdp->memaddr = 0; 3618 brdp->memaddr = 0;
3705 brdp->membase = NULL; 3619 brdp->membase = NULL;
3706 printk(KERN_ERR "STALLION: failed to probe shared memory " 3620 printk(KERN_ERR "istallion: failed to probe shared memory "
3707 "region for %s in EISA slot=%d\n", 3621 "region for %s in EISA slot=%d\n",
3708 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12)); 3622 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
3709 return -ENODEV; 3623 return -ENODEV;
@@ -3848,7 +3762,7 @@ static int __devinit stli_pciprobe(struct pci_dev *pdev,
3848 mutex_lock(&stli_brdslock); 3762 mutex_lock(&stli_brdslock);
3849 brdnr = stli_getbrdnr(); 3763 brdnr = stli_getbrdnr();
3850 if (brdnr < 0) { 3764 if (brdnr < 0) {
3851 printk(KERN_INFO "STALLION: too many boards found, " 3765 printk(KERN_INFO "istallion: too many boards found, "
3852 "maximum supported %d\n", STL_MAXBRDS); 3766 "maximum supported %d\n", STL_MAXBRDS);
3853 mutex_unlock(&stli_brdslock); 3767 mutex_unlock(&stli_brdslock);
3854 retval = -EIO; 3768 retval = -EIO;
@@ -3920,7 +3834,7 @@ static struct stlibrd *stli_allocbrd(void)
3920 3834
3921 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL); 3835 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
3922 if (!brdp) { 3836 if (!brdp) {
3923 printk(KERN_ERR "STALLION: failed to allocate memory " 3837 printk(KERN_ERR "istallion: failed to allocate memory "
3924 "(size=%Zd)\n", sizeof(struct stlibrd)); 3838 "(size=%Zd)\n", sizeof(struct stlibrd));
3925 return NULL; 3839 return NULL;
3926 } 3840 }
@@ -4518,6 +4432,11 @@ static const struct tty_operations stli_ops = {
4518 .tiocmset = stli_tiocmset, 4432 .tiocmset = stli_tiocmset,
4519}; 4433};
4520 4434
4435static const struct tty_port_operations stli_port_ops = {
4436 .carrier_raised = stli_carrier_raised,
4437 .raise_dtr_rts = stli_raise_dtr_rts,
4438};
4439
4521/*****************************************************************************/ 4440/*****************************************************************************/
4522/* 4441/*
4523 * Loadable module initialization stuff. 4442 * Loadable module initialization stuff.
@@ -4554,7 +4473,7 @@ static int __init istallion_module_init(void)
4554 4473
4555 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); 4474 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4556 if (!stli_txcookbuf) { 4475 if (!stli_txcookbuf) {
4557 printk(KERN_ERR "STALLION: failed to allocate memory " 4476 printk(KERN_ERR "istallion: failed to allocate memory "
4558 "(size=%d)\n", STLI_TXBUFSIZE); 4477 "(size=%d)\n", STLI_TXBUFSIZE);
4559 retval = -ENOMEM; 4478 retval = -ENOMEM;
4560 goto err; 4479 goto err;
@@ -4579,7 +4498,7 @@ static int __init istallion_module_init(void)
4579 4498
4580 retval = tty_register_driver(stli_serial); 4499 retval = tty_register_driver(stli_serial);
4581 if (retval) { 4500 if (retval) {
4582 printk(KERN_ERR "STALLION: failed to register serial driver\n"); 4501 printk(KERN_ERR "istallion: failed to register serial driver\n");
4583 goto err_ttyput; 4502 goto err_ttyput;
4584 } 4503 }
4585 4504
@@ -4593,7 +4512,7 @@ static int __init istallion_module_init(void)
4593 */ 4512 */
4594 retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem); 4513 retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem);
4595 if (retval) { 4514 if (retval) {
4596 printk(KERN_ERR "STALLION: failed to register serial memory " 4515 printk(KERN_ERR "istallion: failed to register serial memory "
4597 "device\n"); 4516 "device\n");
4598 goto err_deinit; 4517 goto err_deinit;
4599 } 4518 }
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 12d327a2c9ba..8b0da97d5293 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -206,6 +206,7 @@ static void moxa_poll(unsigned long);
206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); 206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
207static void moxa_setup_empty_event(struct tty_struct *); 207static void moxa_setup_empty_event(struct tty_struct *);
208static void moxa_shut_down(struct tty_struct *); 208static void moxa_shut_down(struct tty_struct *);
209static int moxa_carrier_raised(struct tty_port *);
209/* 210/*
210 * moxa board interface functions: 211 * moxa board interface functions:
211 */ 212 */
@@ -405,6 +406,10 @@ static const struct tty_operations moxa_ops = {
405 .tiocmset = moxa_tiocmset, 406 .tiocmset = moxa_tiocmset,
406}; 407};
407 408
409static const struct tty_port_operations moxa_port_ops = {
410 .carrier_raised = moxa_carrier_raised,
411};
412
408static struct tty_driver *moxaDriver; 413static struct tty_driver *moxaDriver;
409static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); 414static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
410static DEFINE_SPINLOCK(moxa_lock); 415static DEFINE_SPINLOCK(moxa_lock);
@@ -826,6 +831,7 @@ static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
826 831
827 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) { 832 for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) {
828 tty_port_init(&p->port); 833 tty_port_init(&p->port);
834 p->port.ops = &moxa_port_ops;
829 p->type = PORT_16550A; 835 p->type = PORT_16550A;
830 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 836 p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
831 } 837 }
@@ -1115,15 +1121,27 @@ static void moxa_close_port(struct tty_struct *tty)
1115 tty_port_tty_set(&ch->port, NULL); 1121 tty_port_tty_set(&ch->port, NULL);
1116} 1122}
1117 1123
1124static int moxa_carrier_raised(struct tty_port *port)
1125{
1126 struct moxa_port *ch = container_of(port, struct moxa_port, port);
1127 int dcd;
1128
1129 spin_lock_bh(&moxa_lock);
1130 dcd = ch->DCDState;
1131 spin_unlock_bh(&moxa_lock);
1132 return dcd;
1133}
1134
1118static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, 1135static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1119 struct moxa_port *ch) 1136 struct moxa_port *ch)
1120{ 1137{
1138 struct tty_port *port = &ch->port;
1121 DEFINE_WAIT(wait); 1139 DEFINE_WAIT(wait);
1122 int retval = 0; 1140 int retval = 0;
1123 u8 dcd; 1141 u8 dcd;
1124 1142
1125 while (1) { 1143 while (1) {
1126 prepare_to_wait(&ch->port.open_wait, &wait, TASK_INTERRUPTIBLE); 1144 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
1127 if (tty_hung_up_p(filp)) { 1145 if (tty_hung_up_p(filp)) {
1128#ifdef SERIAL_DO_RESTART 1146#ifdef SERIAL_DO_RESTART
1129 retval = -ERESTARTSYS; 1147 retval = -ERESTARTSYS;
@@ -1132,9 +1150,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1132#endif 1150#endif
1133 break; 1151 break;
1134 } 1152 }
1135 spin_lock_bh(&moxa_lock); 1153 dcd = tty_port_carrier_raised(port);
1136 dcd = ch->DCDState;
1137 spin_unlock_bh(&moxa_lock);
1138 if (dcd) 1154 if (dcd)
1139 break; 1155 break;
1140 1156
@@ -1144,7 +1160,7 @@ static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
1144 } 1160 }
1145 schedule(); 1161 schedule();
1146 } 1162 }
1147 finish_wait(&ch->port.open_wait, &wait); 1163 finish_wait(&port->open_wait, &wait);
1148 1164
1149 return retval; 1165 return retval;
1150} 1166}
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 047766915411..402c9f217f83 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -541,74 +541,21 @@ static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
541 return status; 541 return status;
542} 542}
543 543
544static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, 544static int mxser_carrier_raised(struct tty_port *port)
545 struct mxser_port *port)
546{ 545{
547 DECLARE_WAITQUEUE(wait, current); 546 struct mxser_port *mp = container_of(port, struct mxser_port, port);
548 int retval; 547 return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0;
549 int do_clocal = 0; 548}
550 unsigned long flags;
551
552 /*
553 * If non-blocking mode is set, or the port is not enabled,
554 * then make the check up front and then exit.
555 */
556 if ((filp->f_flags & O_NONBLOCK) ||
557 test_bit(TTY_IO_ERROR, &tty->flags)) {
558 port->port.flags |= ASYNC_NORMAL_ACTIVE;
559 return 0;
560 }
561 549
562 if (tty->termios->c_cflag & CLOCAL) 550static void mxser_raise_dtr_rts(struct tty_port *port)
563 do_clocal = 1; 551{
552 struct mxser_port *mp = container_of(port, struct mxser_port, port);
553 unsigned long flags;
564 554
565 /* 555 spin_lock_irqsave(&mp->slock, flags);
566 * Block waiting for the carrier detect and the line to become 556 outb(inb(mp->ioaddr + UART_MCR) |
567 * free (i.e., not in use by the callout). While we are in 557 UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR);
568 * this loop, port->port.count is dropped by one, so that 558 spin_unlock_irqrestore(&mp->slock, flags);
569 * mxser_close() knows when to free things. We restore it upon
570 * exit, either normal or abnormal.
571 */
572 retval = 0;
573 add_wait_queue(&port->port.open_wait, &wait);
574
575 spin_lock_irqsave(&port->slock, flags);
576 if (!tty_hung_up_p(filp))
577 port->port.count--;
578 spin_unlock_irqrestore(&port->slock, flags);
579 port->port.blocked_open++;
580 while (1) {
581 spin_lock_irqsave(&port->slock, flags);
582 outb(inb(port->ioaddr + UART_MCR) |
583 UART_MCR_DTR | UART_MCR_RTS, port->ioaddr + UART_MCR);
584 spin_unlock_irqrestore(&port->slock, flags);
585 set_current_state(TASK_INTERRUPTIBLE);
586 if (tty_hung_up_p(filp) || !(port->port.flags & ASYNC_INITIALIZED)) {
587 if (port->port.flags & ASYNC_HUP_NOTIFY)
588 retval = -EAGAIN;
589 else
590 retval = -ERESTARTSYS;
591 break;
592 }
593 if (!(port->port.flags & ASYNC_CLOSING) &&
594 (do_clocal ||
595 (inb(port->ioaddr + UART_MSR) & UART_MSR_DCD)))
596 break;
597 if (signal_pending(current)) {
598 retval = -ERESTARTSYS;
599 break;
600 }
601 schedule();
602 }
603 set_current_state(TASK_RUNNING);
604 remove_wait_queue(&port->port.open_wait, &wait);
605 if (!tty_hung_up_p(filp))
606 port->port.count++;
607 port->port.blocked_open--;
608 if (retval)
609 return retval;
610 port->port.flags |= ASYNC_NORMAL_ACTIVE;
611 return 0;
612} 559}
613 560
614static int mxser_set_baud(struct tty_struct *tty, long newspd) 561static int mxser_set_baud(struct tty_struct *tty, long newspd)
@@ -1087,14 +1034,14 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1087 /* 1034 /*
1088 * Start up serial port 1035 * Start up serial port
1089 */ 1036 */
1090 spin_lock_irqsave(&info->slock, flags); 1037 spin_lock_irqsave(&info->port.lock, flags);
1091 info->port.count++; 1038 info->port.count++;
1092 spin_unlock_irqrestore(&info->slock, flags); 1039 spin_unlock_irqrestore(&info->port.lock, flags);
1093 retval = mxser_startup(tty); 1040 retval = mxser_startup(tty);
1094 if (retval) 1041 if (retval)
1095 return retval; 1042 return retval;
1096 1043
1097 retval = mxser_block_til_ready(tty, filp, info); 1044 retval = tty_port_block_til_ready(&info->port, tty, filp);
1098 if (retval) 1045 if (retval)
1099 return retval; 1046 return retval;
1100 1047
@@ -1133,58 +1080,27 @@ static void mxser_flush_buffer(struct tty_struct *tty)
1133static void mxser_close(struct tty_struct *tty, struct file *filp) 1080static void mxser_close(struct tty_struct *tty, struct file *filp)
1134{ 1081{
1135 struct mxser_port *info = tty->driver_data; 1082 struct mxser_port *info = tty->driver_data;
1083 struct tty_port *port = &info->port;
1136 1084
1137 unsigned long timeout; 1085 unsigned long timeout;
1138 unsigned long flags;
1139 1086
1140 if (tty->index == MXSER_PORTS) 1087 if (tty->index == MXSER_PORTS)
1141 return; 1088 return;
1142 if (!info) 1089 if (!info)
1143 return; 1090 return;
1144 1091
1145 spin_lock_irqsave(&info->slock, flags); 1092 if (tty_port_close_start(port, tty, filp) == 0)
1146
1147 if (tty_hung_up_p(filp)) {
1148 spin_unlock_irqrestore(&info->slock, flags);
1149 return;
1150 }
1151 if ((tty->count == 1) && (info->port.count != 1)) {
1152 /*
1153 * Uh, oh. tty->count is 1, which means that the tty
1154 * structure will be freed. Info->port.count should always
1155 * be one in these conditions. If it's greater than
1156 * one, we've got real problems, since it means the
1157 * serial port won't be shutdown.
1158 */
1159 printk(KERN_ERR "mxser_close: bad serial port count; "
1160 "tty->count is 1, info->port.count is %d\n", info->port.count);
1161 info->port.count = 1;
1162 }
1163 if (--info->port.count < 0) {
1164 printk(KERN_ERR "mxser_close: bad serial port count for "
1165 "ttys%d: %d\n", tty->index, info->port.count);
1166 info->port.count = 0;
1167 }
1168 if (info->port.count) {
1169 spin_unlock_irqrestore(&info->slock, flags);
1170 return; 1093 return;
1171 } 1094
1172 info->port.flags |= ASYNC_CLOSING;
1173 spin_unlock_irqrestore(&info->slock, flags);
1174 /* 1095 /*
1175 * Save the termios structure, since this port may have 1096 * Save the termios structure, since this port may have
1176 * separate termios for callout and dialin. 1097 * separate termios for callout and dialin.
1098 *
1099 * FIXME: Can this go ?
1177 */ 1100 */
1178 if (info->port.flags & ASYNC_NORMAL_ACTIVE) 1101 if (info->port.flags & ASYNC_NORMAL_ACTIVE)
1179 info->normal_termios = *tty->termios; 1102 info->normal_termios = *tty->termios;
1180 /* 1103 /*
1181 * Now we wait for the transmit buffer to clear; and we notify
1182 * the line discipline to only process XON/XOFF characters.
1183 */
1184 tty->closing = 1;
1185 if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
1186 tty_wait_until_sent(tty, info->port.closing_wait);
1187 /*
1188 * At this point we stop accepting input. To do this, we 1104 * At this point we stop accepting input. To do this, we
1189 * disable the receive line status interrupts, and tell the 1105 * disable the receive line status interrupts, and tell the
1190 * interrupt driver to stop checking the data ready bit in the 1106 * interrupt driver to stop checking the data ready bit in the
@@ -1209,19 +1125,12 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1209 } 1125 }
1210 } 1126 }
1211 mxser_shutdown(tty); 1127 mxser_shutdown(tty);
1212
1213 mxser_flush_buffer(tty); 1128 mxser_flush_buffer(tty);
1214 tty_ldisc_flush(tty);
1215
1216 tty->closing = 0;
1217 tty_port_tty_set(&info->port, NULL);
1218 if (info->port.blocked_open) {
1219 if (info->port.close_delay)
1220 schedule_timeout_interruptible(info->port.close_delay);
1221 wake_up_interruptible(&info->port.open_wait);
1222 }
1223 1129
1224 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); 1130 /* Right now the tty_port set is done outside of the close_end helper
1131 as we don't yet have everyone using refcounts */
1132 tty_port_close_end(port, tty);
1133 tty_port_tty_set(port, NULL);
1225} 1134}
1226 1135
1227static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count) 1136static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
@@ -2146,10 +2055,7 @@ static void mxser_hangup(struct tty_struct *tty)
2146 2055
2147 mxser_flush_buffer(tty); 2056 mxser_flush_buffer(tty);
2148 mxser_shutdown(tty); 2057 mxser_shutdown(tty);
2149 info->port.count = 0; 2058 tty_port_hangup(&info->port);
2150 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2151 tty_port_tty_set(&info->port, NULL);
2152 wake_up_interruptible(&info->port.open_wait);
2153} 2059}
2154 2060
2155/* 2061/*
@@ -2449,6 +2355,11 @@ static const struct tty_operations mxser_ops = {
2449 .tiocmset = mxser_tiocmset, 2355 .tiocmset = mxser_tiocmset,
2450}; 2356};
2451 2357
2358struct tty_port_operations mxser_port_ops = {
2359 .carrier_raised = mxser_carrier_raised,
2360 .raise_dtr_rts = mxser_raise_dtr_rts,
2361};
2362
2452/* 2363/*
2453 * The MOXA Smartio/Industio serial driver boot-time initialization code! 2364 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2454 */ 2365 */
@@ -2482,6 +2393,7 @@ static int __devinit mxser_initbrd(struct mxser_board *brd,
2482 for (i = 0; i < brd->info->nports; i++) { 2393 for (i = 0; i < brd->info->nports; i++) {
2483 info = &brd->ports[i]; 2394 info = &brd->ports[i];
2484 tty_port_init(&info->port); 2395 tty_port_init(&info->port);
2396 info->port.ops = &mxser_port_ops;
2485 info->board = brd; 2397 info->board = brd;
2486 info->stop_rx = 0; 2398 info->stop_rx = 0;
2487 info->ldisc_stop_rx = 0; 2399 info->ldisc_stop_rx = 0;
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 4a8215a89ad3..d2e93e343226 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -1003,7 +1003,7 @@ static int r3964_open(struct tty_struct *tty)
1003 1003
1004static void r3964_close(struct tty_struct *tty) 1004static void r3964_close(struct tty_struct *tty)
1005{ 1005{
1006 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; 1006 struct r3964_info *pInfo = tty->disc_data;
1007 struct r3964_client_info *pClient, *pNext; 1007 struct r3964_client_info *pClient, *pNext;
1008 struct r3964_message *pMsg; 1008 struct r3964_message *pMsg;
1009 struct r3964_block_header *pHeader, *pNextHeader; 1009 struct r3964_block_header *pHeader, *pNextHeader;
@@ -1058,7 +1058,7 @@ static void r3964_close(struct tty_struct *tty)
1058static ssize_t r3964_read(struct tty_struct *tty, struct file *file, 1058static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1059 unsigned char __user * buf, size_t nr) 1059 unsigned char __user * buf, size_t nr)
1060{ 1060{
1061 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; 1061 struct r3964_info *pInfo = tty->disc_data;
1062 struct r3964_client_info *pClient; 1062 struct r3964_client_info *pClient;
1063 struct r3964_message *pMsg; 1063 struct r3964_message *pMsg;
1064 struct r3964_client_message theMsg; 1064 struct r3964_client_message theMsg;
@@ -1113,7 +1113,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1113static ssize_t r3964_write(struct tty_struct *tty, struct file *file, 1113static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1114 const unsigned char *data, size_t count) 1114 const unsigned char *data, size_t count)
1115{ 1115{
1116 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; 1116 struct r3964_info *pInfo = tty->disc_data;
1117 struct r3964_block_header *pHeader; 1117 struct r3964_block_header *pHeader;
1118 struct r3964_client_info *pClient; 1118 struct r3964_client_info *pClient;
1119 unsigned char *new_data; 1119 unsigned char *new_data;
@@ -1182,7 +1182,7 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1182static int r3964_ioctl(struct tty_struct *tty, struct file *file, 1182static int r3964_ioctl(struct tty_struct *tty, struct file *file,
1183 unsigned int cmd, unsigned long arg) 1183 unsigned int cmd, unsigned long arg)
1184{ 1184{
1185 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; 1185 struct r3964_info *pInfo = tty->disc_data;
1186 if (pInfo == NULL) 1186 if (pInfo == NULL)
1187 return -EINVAL; 1187 return -EINVAL;
1188 switch (cmd) { 1188 switch (cmd) {
@@ -1216,7 +1216,7 @@ static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old)
1216static unsigned int r3964_poll(struct tty_struct *tty, struct file *file, 1216static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
1217 struct poll_table_struct *wait) 1217 struct poll_table_struct *wait)
1218{ 1218{
1219 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; 1219 struct r3964_info *pInfo = tty->disc_data;
1220 struct r3964_client_info *pClient; 1220 struct r3964_client_info *pClient;
1221 struct r3964_message *pMsg = NULL; 1221 struct r3964_message *pMsg = NULL;
1222 unsigned long flags; 1222 unsigned long flags;
@@ -1241,7 +1241,7 @@ static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
1241static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 1241static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1242 char *fp, int count) 1242 char *fp, int count)
1243{ 1243{
1244 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data; 1244 struct r3964_info *pInfo = tty->disc_data;
1245 const unsigned char *p; 1245 const unsigned char *p;
1246 char *f, flags = 0; 1246 char *f, flags = 0;
1247 int i; 1247 int i;
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index efbfe9612658..f6f0e4ec2b51 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -47,8 +47,8 @@
47#include <linux/bitops.h> 47#include <linux/bitops.h>
48#include <linux/audit.h> 48#include <linux/audit.h>
49#include <linux/file.h> 49#include <linux/file.h>
50#include <linux/uaccess.h>
50 51
51#include <asm/uaccess.h>
52#include <asm/system.h> 52#include <asm/system.h>
53 53
54/* number of characters left in xmit buffer before select has we have room */ 54/* number of characters left in xmit buffer before select has we have room */
@@ -62,6 +62,17 @@
62#define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */ 62#define TTY_THRESHOLD_THROTTLE 128 /* now based on remaining room */
63#define TTY_THRESHOLD_UNTHROTTLE 128 63#define TTY_THRESHOLD_UNTHROTTLE 128
64 64
65/*
66 * Special byte codes used in the echo buffer to represent operations
67 * or special handling of characters. Bytes in the echo buffer that
68 * are not part of such special blocks are treated as normal character
69 * codes.
70 */
71#define ECHO_OP_START 0xff
72#define ECHO_OP_MOVE_BACK_COL 0x80
73#define ECHO_OP_SET_CANON_COL 0x81
74#define ECHO_OP_ERASE_TAB 0x82
75
65static inline unsigned char *alloc_buf(void) 76static inline unsigned char *alloc_buf(void)
66{ 77{
67 gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL; 78 gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
@@ -169,6 +180,7 @@ static void check_unthrottle(struct tty_struct *tty)
169 * 180 *
170 * Locking: tty_read_lock for read fields. 181 * Locking: tty_read_lock for read fields.
171 */ 182 */
183
172static void reset_buffer_flags(struct tty_struct *tty) 184static void reset_buffer_flags(struct tty_struct *tty)
173{ 185{
174 unsigned long flags; 186 unsigned long flags;
@@ -176,6 +188,11 @@ static void reset_buffer_flags(struct tty_struct *tty)
176 spin_lock_irqsave(&tty->read_lock, flags); 188 spin_lock_irqsave(&tty->read_lock, flags);
177 tty->read_head = tty->read_tail = tty->read_cnt = 0; 189 tty->read_head = tty->read_tail = tty->read_cnt = 0;
178 spin_unlock_irqrestore(&tty->read_lock, flags); 190 spin_unlock_irqrestore(&tty->read_lock, flags);
191
192 mutex_lock(&tty->echo_lock);
193 tty->echo_pos = tty->echo_cnt = tty->echo_overrun = 0;
194 mutex_unlock(&tty->echo_lock);
195
179 tty->canon_head = tty->canon_data = tty->erasing = 0; 196 tty->canon_head = tty->canon_data = tty->erasing = 0;
180 memset(&tty->read_flags, 0, sizeof tty->read_flags); 197 memset(&tty->read_flags, 0, sizeof tty->read_flags);
181 n_tty_set_room(tty); 198 n_tty_set_room(tty);
@@ -266,89 +283,118 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
266} 283}
267 284
268/** 285/**
269 * opost - output post processor 286 * do_output_char - output one character
270 * @c: character (or partial unicode symbol) 287 * @c: character (or partial unicode symbol)
271 * @tty: terminal device 288 * @tty: terminal device
289 * @space: space available in tty driver write buffer
272 * 290 *
273 * Perform OPOST processing. Returns -1 when the output device is 291 * This is a helper function that handles one output character
274 * full and the character must be retried. Note that Linux currently 292 * (including special characters like TAB, CR, LF, etc.),
275 * ignores TABDLY, CRDLY, VTDLY, FFDLY and NLDLY. They simply aren't 293 * putting the results in the tty driver's write buffer.
276 * relevant in the world today. If you ever need them, add them here. 294 *
295 * Note that Linux currently ignores TABDLY, CRDLY, VTDLY, FFDLY
296 * and NLDLY. They simply aren't relevant in the world today.
297 * If you ever need them, add them here.
298 *
299 * Returns the number of bytes of buffer space used or -1 if
300 * no space left.
277 * 301 *
278 * Called from both the receive and transmit sides and can be called 302 * Locking: should be called under the output_lock to protect
279 * re-entrantly. Relies on lock_kernel() for tty->column state. 303 * the column state and space left in the buffer
280 */ 304 */
281 305
282static int opost(unsigned char c, struct tty_struct *tty) 306static int do_output_char(unsigned char c, struct tty_struct *tty, int space)
283{ 307{
284 int space, spaces; 308 int spaces;
285 309
286 space = tty_write_room(tty);
287 if (!space) 310 if (!space)
288 return -1; 311 return -1;
289 312
290 lock_kernel(); 313 switch (c) {
291 if (O_OPOST(tty)) { 314 case '\n':
292 switch (c) { 315 if (O_ONLRET(tty))
293 case '\n': 316 tty->column = 0;
294 if (O_ONLRET(tty)) 317 if (O_ONLCR(tty)) {
295 tty->column = 0; 318 if (space < 2)
296 if (O_ONLCR(tty)) { 319 return -1;
297 if (space < 2) {
298 unlock_kernel();
299 return -1;
300 }
301 tty_put_char(tty, '\r');
302 tty->column = 0;
303 }
304 tty->canon_column = tty->column;
305 break;
306 case '\r':
307 if (O_ONOCR(tty) && tty->column == 0) {
308 unlock_kernel();
309 return 0;
310 }
311 if (O_OCRNL(tty)) {
312 c = '\n';
313 if (O_ONLRET(tty))
314 tty->canon_column = tty->column = 0;
315 break;
316 }
317 tty->canon_column = tty->column = 0; 320 tty->canon_column = tty->column = 0;
321 tty_put_char(tty, '\r');
322 tty_put_char(tty, c);
323 return 2;
324 }
325 tty->canon_column = tty->column;
326 break;
327 case '\r':
328 if (O_ONOCR(tty) && tty->column == 0)
329 return 0;
330 if (O_OCRNL(tty)) {
331 c = '\n';
332 if (O_ONLRET(tty))
333 tty->canon_column = tty->column = 0;
318 break; 334 break;
319 case '\t': 335 }
320 spaces = 8 - (tty->column & 7); 336 tty->canon_column = tty->column = 0;
321 if (O_TABDLY(tty) == XTABS) { 337 break;
322 if (space < spaces) { 338 case '\t':
323 unlock_kernel(); 339 spaces = 8 - (tty->column & 7);
324 return -1; 340 if (O_TABDLY(tty) == XTABS) {
325 } 341 if (space < spaces)
326 tty->column += spaces; 342 return -1;
327 tty->ops->write(tty, " ", spaces);
328 unlock_kernel();
329 return 0;
330 }
331 tty->column += spaces; 343 tty->column += spaces;
332 break; 344 tty->ops->write(tty, " ", spaces);
333 case '\b': 345 return spaces;
334 if (tty->column > 0) 346 }
335 tty->column--; 347 tty->column += spaces;
336 break; 348 break;
337 default: 349 case '\b':
350 if (tty->column > 0)
351 tty->column--;
352 break;
353 default:
354 if (!iscntrl(c)) {
338 if (O_OLCUC(tty)) 355 if (O_OLCUC(tty))
339 c = toupper(c); 356 c = toupper(c);
340 if (!iscntrl(c) && !is_continuation(c, tty)) 357 if (!is_continuation(c, tty))
341 tty->column++; 358 tty->column++;
342 break;
343 } 359 }
360 break;
344 } 361 }
362
345 tty_put_char(tty, c); 363 tty_put_char(tty, c);
346 unlock_kernel(); 364 return 1;
347 return 0;
348} 365}
349 366
350/** 367/**
351 * opost_block - block postprocess 368 * process_output - output post processor
369 * @c: character (or partial unicode symbol)
370 * @tty: terminal device
371 *
372 * Perform OPOST processing. Returns -1 when the output device is
373 * full and the character must be retried.
374 *
375 * Locking: output_lock to protect column state and space left
376 * (also, this is called from n_tty_write under the
377 * tty layer write lock)
378 */
379
380static int process_output(unsigned char c, struct tty_struct *tty)
381{
382 int space, retval;
383
384 mutex_lock(&tty->output_lock);
385
386 space = tty_write_room(tty);
387 retval = do_output_char(c, tty, space);
388
389 mutex_unlock(&tty->output_lock);
390 if (retval < 0)
391 return -1;
392 else
393 return 0;
394}
395
396/**
397 * process_output_block - block post processor
352 * @tty: terminal device 398 * @tty: terminal device
353 * @inbuf: user buffer 399 * @inbuf: user buffer
354 * @nr: number of bytes 400 * @nr: number of bytes
@@ -358,26 +404,32 @@ static int opost(unsigned char c, struct tty_struct *tty)
358 * the simple cases normally found and helps to generate blocks of 404 * the simple cases normally found and helps to generate blocks of
359 * symbols for the console driver and thus improve performance. 405 * symbols for the console driver and thus improve performance.
360 * 406 *
361 * Called from n_tty_write under the tty layer write lock. Relies 407 * Locking: output_lock to protect column state and space left
362 * on lock_kernel for the tty->column state. 408 * (also, this is called from n_tty_write under the
409 * tty layer write lock)
363 */ 410 */
364 411
365static ssize_t opost_block(struct tty_struct *tty, 412static ssize_t process_output_block(struct tty_struct *tty,
366 const unsigned char *buf, unsigned int nr) 413 const unsigned char *buf, unsigned int nr)
367{ 414{
368 int space; 415 int space;
369 int i; 416 int i;
370 const unsigned char *cp; 417 const unsigned char *cp;
371 418
419 mutex_lock(&tty->output_lock);
420
372 space = tty_write_room(tty); 421 space = tty_write_room(tty);
373 if (!space) 422 if (!space) {
423 mutex_unlock(&tty->output_lock);
374 return 0; 424 return 0;
425 }
375 if (nr > space) 426 if (nr > space)
376 nr = space; 427 nr = space;
377 428
378 lock_kernel();
379 for (i = 0, cp = buf; i < nr; i++, cp++) { 429 for (i = 0, cp = buf; i < nr; i++, cp++) {
380 switch (*cp) { 430 unsigned char c = *cp;
431
432 switch (c) {
381 case '\n': 433 case '\n':
382 if (O_ONLRET(tty)) 434 if (O_ONLRET(tty))
383 tty->column = 0; 435 tty->column = 0;
@@ -399,54 +451,403 @@ static ssize_t opost_block(struct tty_struct *tty,
399 tty->column--; 451 tty->column--;
400 break; 452 break;
401 default: 453 default:
402 if (O_OLCUC(tty)) 454 if (!iscntrl(c)) {
403 goto break_out; 455 if (O_OLCUC(tty))
404 if (!iscntrl(*cp)) 456 goto break_out;
405 tty->column++; 457 if (!is_continuation(c, tty))
458 tty->column++;
459 }
406 break; 460 break;
407 } 461 }
408 } 462 }
409break_out: 463break_out:
410 if (tty->ops->flush_chars)
411 tty->ops->flush_chars(tty);
412 i = tty->ops->write(tty, buf, i); 464 i = tty->ops->write(tty, buf, i);
413 unlock_kernel(); 465
466 mutex_unlock(&tty->output_lock);
414 return i; 467 return i;
415} 468}
416 469
470/**
471 * process_echoes - write pending echo characters
472 * @tty: terminal device
473 *
474 * Write previously buffered echo (and other ldisc-generated)
475 * characters to the tty.
476 *
477 * Characters generated by the ldisc (including echoes) need to
478 * be buffered because the driver's write buffer can fill during
479 * heavy program output. Echoing straight to the driver will
480 * often fail under these conditions, causing lost characters and
481 * resulting mismatches of ldisc state information.
482 *
483 * Since the ldisc state must represent the characters actually sent
484 * to the driver at the time of the write, operations like certain
485 * changes in column state are also saved in the buffer and executed
486 * here.
487 *
488 * A circular fifo buffer is used so that the most recent characters
489 * are prioritized. Also, when control characters are echoed with a
490 * prefixed "^", the pair is treated atomically and thus not separated.
491 *
492 * Locking: output_lock to protect column state and space left,
493 * echo_lock to protect the echo buffer
494 */
495
496static void process_echoes(struct tty_struct *tty)
497{
498 int space, nr;
499 unsigned char c;
500 unsigned char *cp, *buf_end;
501
502 if (!tty->echo_cnt)
503 return;
504
505 mutex_lock(&tty->output_lock);
506 mutex_lock(&tty->echo_lock);
507
508 space = tty_write_room(tty);
509
510 buf_end = tty->echo_buf + N_TTY_BUF_SIZE;
511 cp = tty->echo_buf + tty->echo_pos;
512 nr = tty->echo_cnt;
513 while (nr > 0) {
514 c = *cp;
515 if (c == ECHO_OP_START) {
516 unsigned char op;
517 unsigned char *opp;
518 int no_space_left = 0;
519
520 /*
521 * If the buffer byte is the start of a multi-byte
522 * operation, get the next byte, which is either the
523 * op code or a control character value.
524 */
525 opp = cp + 1;
526 if (opp == buf_end)
527 opp -= N_TTY_BUF_SIZE;
528 op = *opp;
529
530 switch (op) {
531 unsigned int num_chars, num_bs;
532
533 case ECHO_OP_ERASE_TAB:
534 if (++opp == buf_end)
535 opp -= N_TTY_BUF_SIZE;
536 num_chars = *opp;
537
538 /*
539 * Determine how many columns to go back
540 * in order to erase the tab.
541 * This depends on the number of columns
542 * used by other characters within the tab
543 * area. If this (modulo 8) count is from
544 * the start of input rather than from a
545 * previous tab, we offset by canon column.
546 * Otherwise, tab spacing is normal.
547 */
548 if (!(num_chars & 0x80))
549 num_chars += tty->canon_column;
550 num_bs = 8 - (num_chars & 7);
551
552 if (num_bs > space) {
553 no_space_left = 1;
554 break;
555 }
556 space -= num_bs;
557 while (num_bs--) {
558 tty_put_char(tty, '\b');
559 if (tty->column > 0)
560 tty->column--;
561 }
562 cp += 3;
563 nr -= 3;
564 break;
565
566 case ECHO_OP_SET_CANON_COL:
567 tty->canon_column = tty->column;
568 cp += 2;
569 nr -= 2;
570 break;
571
572 case ECHO_OP_MOVE_BACK_COL:
573 if (tty->column > 0)
574 tty->column--;
575 cp += 2;
576 nr -= 2;
577 break;
578
579 case ECHO_OP_START:
580 /* This is an escaped echo op start code */
581 if (!space) {
582 no_space_left = 1;
583 break;
584 }
585 tty_put_char(tty, ECHO_OP_START);
586 tty->column++;
587 space--;
588 cp += 2;
589 nr -= 2;
590 break;
591
592 default:
593 if (iscntrl(op)) {
594 if (L_ECHOCTL(tty)) {
595 /*
596 * Ensure there is enough space
597 * for the whole ctrl pair.
598 */
599 if (space < 2) {
600 no_space_left = 1;
601 break;
602 }
603 tty_put_char(tty, '^');
604 tty_put_char(tty, op ^ 0100);
605 tty->column += 2;
606 space -= 2;
607 } else {
608 if (!space) {
609 no_space_left = 1;
610 break;
611 }
612 tty_put_char(tty, op);
613 space--;
614 }
615 }
616 /*
617 * If above falls through, this was an
618 * undefined op.
619 */
620 cp += 2;
621 nr -= 2;
622 }
623
624 if (no_space_left)
625 break;
626 } else {
627 int retval;
628
629 retval = do_output_char(c, tty, space);
630 if (retval < 0)
631 break;
632 space -= retval;
633 cp += 1;
634 nr -= 1;
635 }
636
637 /* When end of circular buffer reached, wrap around */
638 if (cp >= buf_end)
639 cp -= N_TTY_BUF_SIZE;
640 }
641
642 if (nr == 0) {
643 tty->echo_pos = 0;
644 tty->echo_cnt = 0;
645 tty->echo_overrun = 0;
646 } else {
647 int num_processed = tty->echo_cnt - nr;
648 tty->echo_pos += num_processed;
649 tty->echo_pos &= N_TTY_BUF_SIZE - 1;
650 tty->echo_cnt = nr;
651 if (num_processed > 0)
652 tty->echo_overrun = 0;
653 }
654
655 mutex_unlock(&tty->echo_lock);
656 mutex_unlock(&tty->output_lock);
657
658 if (tty->ops->flush_chars)
659 tty->ops->flush_chars(tty);
660}
417 661
418/** 662/**
419 * echo_char - echo characters 663 * add_echo_byte - add a byte to the echo buffer
664 * @c: unicode byte to echo
665 * @tty: terminal device
666 *
667 * Add a character or operation byte to the echo buffer.
668 *
669 * Should be called under the echo lock to protect the echo buffer.
670 */
671
672static void add_echo_byte(unsigned char c, struct tty_struct *tty)
673{
674 int new_byte_pos;
675
676 if (tty->echo_cnt == N_TTY_BUF_SIZE) {
677 /* Circular buffer is already at capacity */
678 new_byte_pos = tty->echo_pos;
679
680 /*
681 * Since the buffer start position needs to be advanced,
682 * be sure to step by a whole operation byte group.
683 */
684 if (tty->echo_buf[tty->echo_pos] == ECHO_OP_START) {
685 if (tty->echo_buf[(tty->echo_pos + 1) &
686 (N_TTY_BUF_SIZE - 1)] ==
687 ECHO_OP_ERASE_TAB) {
688 tty->echo_pos += 3;
689 tty->echo_cnt -= 2;
690 } else {
691 tty->echo_pos += 2;
692 tty->echo_cnt -= 1;
693 }
694 } else {
695 tty->echo_pos++;
696 }
697 tty->echo_pos &= N_TTY_BUF_SIZE - 1;
698
699 tty->echo_overrun = 1;
700 } else {
701 new_byte_pos = tty->echo_pos + tty->echo_cnt;
702 new_byte_pos &= N_TTY_BUF_SIZE - 1;
703 tty->echo_cnt++;
704 }
705
706 tty->echo_buf[new_byte_pos] = c;
707}
708
709/**
710 * echo_move_back_col - add operation to move back a column
711 * @tty: terminal device
712 *
713 * Add an operation to the echo buffer to move back one column.
714 *
715 * Locking: echo_lock to protect the echo buffer
716 */
717
718static void echo_move_back_col(struct tty_struct *tty)
719{
720 mutex_lock(&tty->echo_lock);
721
722 add_echo_byte(ECHO_OP_START, tty);
723 add_echo_byte(ECHO_OP_MOVE_BACK_COL, tty);
724
725 mutex_unlock(&tty->echo_lock);
726}
727
728/**
729 * echo_set_canon_col - add operation to set the canon column
730 * @tty: terminal device
731 *
732 * Add an operation to the echo buffer to set the canon column
733 * to the current column.
734 *
735 * Locking: echo_lock to protect the echo buffer
736 */
737
738static void echo_set_canon_col(struct tty_struct *tty)
739{
740 mutex_lock(&tty->echo_lock);
741
742 add_echo_byte(ECHO_OP_START, tty);
743 add_echo_byte(ECHO_OP_SET_CANON_COL, tty);
744
745 mutex_unlock(&tty->echo_lock);
746}
747
748/**
749 * echo_erase_tab - add operation to erase a tab
750 * @num_chars: number of character columns already used
751 * @after_tab: true if num_chars starts after a previous tab
752 * @tty: terminal device
753 *
754 * Add an operation to the echo buffer to erase a tab.
755 *
756 * Called by the eraser function, which knows how many character
757 * columns have been used since either a previous tab or the start
758 * of input. This information will be used later, along with
759 * canon column (if applicable), to go back the correct number
760 * of columns.
761 *
762 * Locking: echo_lock to protect the echo buffer
763 */
764
765static void echo_erase_tab(unsigned int num_chars, int after_tab,
766 struct tty_struct *tty)
767{
768 mutex_lock(&tty->echo_lock);
769
770 add_echo_byte(ECHO_OP_START, tty);
771 add_echo_byte(ECHO_OP_ERASE_TAB, tty);
772
773 /* We only need to know this modulo 8 (tab spacing) */
774 num_chars &= 7;
775
776 /* Set the high bit as a flag if num_chars is after a previous tab */
777 if (after_tab)
778 num_chars |= 0x80;
779
780 add_echo_byte(num_chars, tty);
781
782 mutex_unlock(&tty->echo_lock);
783}
784
785/**
786 * echo_char_raw - echo a character raw
420 * @c: unicode byte to echo 787 * @c: unicode byte to echo
421 * @tty: terminal device 788 * @tty: terminal device
422 * 789 *
423 * Echo user input back onto the screen. This must be called only when 790 * Echo user input back onto the screen. This must be called only when
424 * L_ECHO(tty) is true. Called from the driver receive_buf path. 791 * L_ECHO(tty) is true. Called from the driver receive_buf path.
425 * 792 *
426 * Relies on BKL for tty column locking 793 * This variant does not treat control characters specially.
794 *
795 * Locking: echo_lock to protect the echo buffer
796 */
797
798static void echo_char_raw(unsigned char c, struct tty_struct *tty)
799{
800 mutex_lock(&tty->echo_lock);
801
802 if (c == ECHO_OP_START) {
803 add_echo_byte(ECHO_OP_START, tty);
804 add_echo_byte(ECHO_OP_START, tty);
805 } else {
806 add_echo_byte(c, tty);
807 }
808
809 mutex_unlock(&tty->echo_lock);
810}
811
812/**
813 * echo_char - echo a character
814 * @c: unicode byte to echo
815 * @tty: terminal device
816 *
817 * Echo user input back onto the screen. This must be called only when
818 * L_ECHO(tty) is true. Called from the driver receive_buf path.
819 *
820 * This variant tags control characters to be possibly echoed as
821 * as "^X" (where X is the letter representing the control char).
822 *
823 * Locking: echo_lock to protect the echo buffer
427 */ 824 */
428 825
429static void echo_char(unsigned char c, struct tty_struct *tty) 826static void echo_char(unsigned char c, struct tty_struct *tty)
430{ 827{
431 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') { 828 mutex_lock(&tty->echo_lock);
432 tty_put_char(tty, '^'); 829
433 tty_put_char(tty, c ^ 0100); 830 if (c == ECHO_OP_START) {
434 tty->column += 2; 831 add_echo_byte(ECHO_OP_START, tty);
435 } else 832 add_echo_byte(ECHO_OP_START, tty);
436 opost(c, tty); 833 } else {
834 if (iscntrl(c) && c != '\t')
835 add_echo_byte(ECHO_OP_START, tty);
836 add_echo_byte(c, tty);
837 }
838
839 mutex_unlock(&tty->echo_lock);
437} 840}
438 841
439/** 842/**
440 * finsh_erasing - complete erase 843 * finish_erasing - complete erase
441 * @tty: tty doing the erase 844 * @tty: tty doing the erase
442 *
443 * Relies on BKL for tty column locking
444 */ 845 */
846
445static inline void finish_erasing(struct tty_struct *tty) 847static inline void finish_erasing(struct tty_struct *tty)
446{ 848{
447 if (tty->erasing) { 849 if (tty->erasing) {
448 tty_put_char(tty, '/'); 850 echo_char_raw('/', tty);
449 tty->column++;
450 tty->erasing = 0; 851 tty->erasing = 0;
451 } 852 }
452} 853}
@@ -460,7 +861,7 @@ static inline void finish_erasing(struct tty_struct *tty)
460 * present in the stream from the driver layer. Handles the complexities 861 * present in the stream from the driver layer. Handles the complexities
461 * of UTF-8 multibyte symbols. 862 * of UTF-8 multibyte symbols.
462 * 863 *
463 * Locking: read_lock for tty buffers, BKL for column/erasing state 864 * Locking: read_lock for tty buffers
464 */ 865 */
465 866
466static void eraser(unsigned char c, struct tty_struct *tty) 867static void eraser(unsigned char c, struct tty_struct *tty)
@@ -471,7 +872,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
471 872
472 /* FIXME: locking needed ? */ 873 /* FIXME: locking needed ? */
473 if (tty->read_head == tty->canon_head) { 874 if (tty->read_head == tty->canon_head) {
474 /* opost('\a', tty); */ /* what do you think? */ 875 /* process_output('\a', tty); */ /* what do you think? */
475 return; 876 return;
476 } 877 }
477 if (c == ERASE_CHAR(tty)) 878 if (c == ERASE_CHAR(tty))
@@ -497,7 +898,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
497 echo_char(KILL_CHAR(tty), tty); 898 echo_char(KILL_CHAR(tty), tty);
498 /* Add a newline if ECHOK is on and ECHOKE is off. */ 899 /* Add a newline if ECHOK is on and ECHOKE is off. */
499 if (L_ECHOK(tty)) 900 if (L_ECHOK(tty))
500 opost('\n', tty); 901 echo_char_raw('\n', tty);
501 return; 902 return;
502 } 903 }
503 kill_type = KILL; 904 kill_type = KILL;
@@ -533,67 +934,61 @@ static void eraser(unsigned char c, struct tty_struct *tty)
533 if (L_ECHO(tty)) { 934 if (L_ECHO(tty)) {
534 if (L_ECHOPRT(tty)) { 935 if (L_ECHOPRT(tty)) {
535 if (!tty->erasing) { 936 if (!tty->erasing) {
536 tty_put_char(tty, '\\'); 937 echo_char_raw('\\', tty);
537 tty->column++;
538 tty->erasing = 1; 938 tty->erasing = 1;
539 } 939 }
540 /* if cnt > 1, output a multi-byte character */ 940 /* if cnt > 1, output a multi-byte character */
541 echo_char(c, tty); 941 echo_char(c, tty);
542 while (--cnt > 0) { 942 while (--cnt > 0) {
543 head = (head+1) & (N_TTY_BUF_SIZE-1); 943 head = (head+1) & (N_TTY_BUF_SIZE-1);
544 tty_put_char(tty, tty->read_buf[head]); 944 echo_char_raw(tty->read_buf[head], tty);
945 echo_move_back_col(tty);
545 } 946 }
546 } else if (kill_type == ERASE && !L_ECHOE(tty)) { 947 } else if (kill_type == ERASE && !L_ECHOE(tty)) {
547 echo_char(ERASE_CHAR(tty), tty); 948 echo_char(ERASE_CHAR(tty), tty);
548 } else if (c == '\t') { 949 } else if (c == '\t') {
549 unsigned int col = tty->canon_column; 950 unsigned int num_chars = 0;
550 unsigned long tail = tty->canon_head; 951 int after_tab = 0;
551 952 unsigned long tail = tty->read_head;
552 /* Find the column of the last char. */ 953
553 while (tail != tty->read_head) { 954 /*
955 * Count the columns used for characters
956 * since the start of input or after a
957 * previous tab.
958 * This info is used to go back the correct
959 * number of columns.
960 */
961 while (tail != tty->canon_head) {
962 tail = (tail-1) & (N_TTY_BUF_SIZE-1);
554 c = tty->read_buf[tail]; 963 c = tty->read_buf[tail];
555 if (c == '\t') 964 if (c == '\t') {
556 col = (col | 7) + 1; 965 after_tab = 1;
557 else if (iscntrl(c)) { 966 break;
967 } else if (iscntrl(c)) {
558 if (L_ECHOCTL(tty)) 968 if (L_ECHOCTL(tty))
559 col += 2; 969 num_chars += 2;
560 } else if (!is_continuation(c, tty)) 970 } else if (!is_continuation(c, tty)) {
561 col++; 971 num_chars++;
562 tail = (tail+1) & (N_TTY_BUF_SIZE-1); 972 }
563 }
564
565 /* should never happen */
566 if (tty->column > 0x80000000)
567 tty->column = 0;
568
569 /* Now backup to that column. */
570 while (tty->column > col) {
571 /* Can't use opost here. */
572 tty_put_char(tty, '\b');
573 if (tty->column > 0)
574 tty->column--;
575 } 973 }
974 echo_erase_tab(num_chars, after_tab, tty);
576 } else { 975 } else {
577 if (iscntrl(c) && L_ECHOCTL(tty)) { 976 if (iscntrl(c) && L_ECHOCTL(tty)) {
578 tty_put_char(tty, '\b'); 977 echo_char_raw('\b', tty);
579 tty_put_char(tty, ' '); 978 echo_char_raw(' ', tty);
580 tty_put_char(tty, '\b'); 979 echo_char_raw('\b', tty);
581 if (tty->column > 0)
582 tty->column--;
583 } 980 }
584 if (!iscntrl(c) || L_ECHOCTL(tty)) { 981 if (!iscntrl(c) || L_ECHOCTL(tty)) {
585 tty_put_char(tty, '\b'); 982 echo_char_raw('\b', tty);
586 tty_put_char(tty, ' '); 983 echo_char_raw(' ', tty);
587 tty_put_char(tty, '\b'); 984 echo_char_raw('\b', tty);
588 if (tty->column > 0)
589 tty->column--;
590 } 985 }
591 } 986 }
592 } 987 }
593 if (kill_type == ERASE) 988 if (kill_type == ERASE)
594 break; 989 break;
595 } 990 }
596 if (tty->read_head == tty->canon_head) 991 if (tty->read_head == tty->canon_head && L_ECHO(tty))
597 finish_erasing(tty); 992 finish_erasing(tty);
598} 993}
599 994
@@ -712,6 +1107,7 @@ static inline void n_tty_receive_parity_error(struct tty_struct *tty,
712static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) 1107static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
713{ 1108{
714 unsigned long flags; 1109 unsigned long flags;
1110 int parmrk;
715 1111
716 if (tty->raw) { 1112 if (tty->raw) {
717 put_tty_queue(c, tty); 1113 put_tty_queue(c, tty);
@@ -721,18 +1117,21 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
721 if (I_ISTRIP(tty)) 1117 if (I_ISTRIP(tty))
722 c &= 0x7f; 1118 c &= 0x7f;
723 if (I_IUCLC(tty) && L_IEXTEN(tty)) 1119 if (I_IUCLC(tty) && L_IEXTEN(tty))
724 c=tolower(c); 1120 c = tolower(c);
725 1121
726 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && 1122 if (tty->stopped && !tty->flow_stopped && I_IXON(tty) &&
727 ((I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty)) || 1123 I_IXANY(tty) && c != START_CHAR(tty) && c != STOP_CHAR(tty) &&
728 c == INTR_CHAR(tty) || c == QUIT_CHAR(tty) || c == SUSP_CHAR(tty))) 1124 c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) && c != SUSP_CHAR(tty)) {
729 start_tty(tty); 1125 start_tty(tty);
1126 process_echoes(tty);
1127 }
730 1128
731 if (tty->closing) { 1129 if (tty->closing) {
732 if (I_IXON(tty)) { 1130 if (I_IXON(tty)) {
733 if (c == START_CHAR(tty)) 1131 if (c == START_CHAR(tty)) {
734 start_tty(tty); 1132 start_tty(tty);
735 else if (c == STOP_CHAR(tty)) 1133 process_echoes(tty);
1134 } else if (c == STOP_CHAR(tty))
736 stop_tty(tty); 1135 stop_tty(tty);
737 } 1136 }
738 return; 1137 return;
@@ -745,19 +1144,23 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
745 * up. 1144 * up.
746 */ 1145 */
747 if (!test_bit(c, tty->process_char_map) || tty->lnext) { 1146 if (!test_bit(c, tty->process_char_map) || tty->lnext) {
748 finish_erasing(tty);
749 tty->lnext = 0; 1147 tty->lnext = 0;
1148 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1149 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1150 /* beep if no space */
1151 if (L_ECHO(tty))
1152 process_output('\a', tty);
1153 return;
1154 }
750 if (L_ECHO(tty)) { 1155 if (L_ECHO(tty)) {
751 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 1156 finish_erasing(tty);
752 tty_put_char(tty, '\a'); /* beep if no space */
753 return;
754 }
755 /* Record the column of first canon char. */ 1157 /* Record the column of first canon char. */
756 if (tty->canon_head == tty->read_head) 1158 if (tty->canon_head == tty->read_head)
757 tty->canon_column = tty->column; 1159 echo_set_canon_col(tty);
758 echo_char(c, tty); 1160 echo_char(c, tty);
1161 process_echoes(tty);
759 } 1162 }
760 if (I_PARMRK(tty) && c == (unsigned char) '\377') 1163 if (parmrk)
761 put_tty_queue(c, tty); 1164 put_tty_queue(c, tty);
762 put_tty_queue(c, tty); 1165 put_tty_queue(c, tty);
763 return; 1166 return;
@@ -766,6 +1169,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
766 if (I_IXON(tty)) { 1169 if (I_IXON(tty)) {
767 if (c == START_CHAR(tty)) { 1170 if (c == START_CHAR(tty)) {
768 start_tty(tty); 1171 start_tty(tty);
1172 process_echoes(tty);
769 return; 1173 return;
770 } 1174 }
771 if (c == STOP_CHAR(tty)) { 1175 if (c == STOP_CHAR(tty)) {
@@ -786,7 +1190,6 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
786 if (c == SUSP_CHAR(tty)) { 1190 if (c == SUSP_CHAR(tty)) {
787send_signal: 1191send_signal:
788 /* 1192 /*
789 * Echo character, and then send the signal.
790 * Note that we do not use isig() here because we want 1193 * Note that we do not use isig() here because we want
791 * the order to be: 1194 * the order to be:
792 * 1) flush, 2) echo, 3) signal 1195 * 1) flush, 2) echo, 3) signal
@@ -795,8 +1198,12 @@ send_signal:
795 n_tty_flush_buffer(tty); 1198 n_tty_flush_buffer(tty);
796 tty_driver_flush_buffer(tty); 1199 tty_driver_flush_buffer(tty);
797 } 1200 }
798 if (L_ECHO(tty)) 1201 if (I_IXON(tty))
1202 start_tty(tty);
1203 if (L_ECHO(tty)) {
799 echo_char(c, tty); 1204 echo_char(c, tty);
1205 process_echoes(tty);
1206 }
800 if (tty->pgrp) 1207 if (tty->pgrp)
801 kill_pgrp(tty->pgrp, signal, 1); 1208 kill_pgrp(tty->pgrp, signal, 1);
802 return; 1209 return;
@@ -815,6 +1222,7 @@ send_signal:
815 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || 1222 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) ||
816 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { 1223 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) {
817 eraser(c, tty); 1224 eraser(c, tty);
1225 process_echoes(tty);
818 return; 1226 return;
819 } 1227 }
820 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { 1228 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) {
@@ -822,8 +1230,9 @@ send_signal:
822 if (L_ECHO(tty)) { 1230 if (L_ECHO(tty)) {
823 finish_erasing(tty); 1231 finish_erasing(tty);
824 if (L_ECHOCTL(tty)) { 1232 if (L_ECHOCTL(tty)) {
825 tty_put_char(tty, '^'); 1233 echo_char_raw('^', tty);
826 tty_put_char(tty, '\b'); 1234 echo_char_raw('\b', tty);
1235 process_echoes(tty);
827 } 1236 }
828 } 1237 }
829 return; 1238 return;
@@ -834,22 +1243,29 @@ send_signal:
834 1243
835 finish_erasing(tty); 1244 finish_erasing(tty);
836 echo_char(c, tty); 1245 echo_char(c, tty);
837 opost('\n', tty); 1246 echo_char_raw('\n', tty);
838 while (tail != tty->read_head) { 1247 while (tail != tty->read_head) {
839 echo_char(tty->read_buf[tail], tty); 1248 echo_char(tty->read_buf[tail], tty);
840 tail = (tail+1) & (N_TTY_BUF_SIZE-1); 1249 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
841 } 1250 }
1251 process_echoes(tty);
842 return; 1252 return;
843 } 1253 }
844 if (c == '\n') { 1254 if (c == '\n') {
1255 if (tty->read_cnt >= N_TTY_BUF_SIZE) {
1256 if (L_ECHO(tty))
1257 process_output('\a', tty);
1258 return;
1259 }
845 if (L_ECHO(tty) || L_ECHONL(tty)) { 1260 if (L_ECHO(tty) || L_ECHONL(tty)) {
846 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) 1261 echo_char_raw('\n', tty);
847 tty_put_char(tty, '\a'); 1262 process_echoes(tty);
848 opost('\n', tty);
849 } 1263 }
850 goto handle_newline; 1264 goto handle_newline;
851 } 1265 }
852 if (c == EOF_CHAR(tty)) { 1266 if (c == EOF_CHAR(tty)) {
1267 if (tty->read_cnt >= N_TTY_BUF_SIZE)
1268 return;
853 if (tty->canon_head != tty->read_head) 1269 if (tty->canon_head != tty->read_head)
854 set_bit(TTY_PUSH, &tty->flags); 1270 set_bit(TTY_PUSH, &tty->flags);
855 c = __DISABLED_CHAR; 1271 c = __DISABLED_CHAR;
@@ -857,22 +1273,28 @@ send_signal:
857 } 1273 }
858 if ((c == EOL_CHAR(tty)) || 1274 if ((c == EOL_CHAR(tty)) ||
859 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { 1275 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) {
1276 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty))
1277 ? 1 : 0;
1278 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk)) {
1279 if (L_ECHO(tty))
1280 process_output('\a', tty);
1281 return;
1282 }
860 /* 1283 /*
861 * XXX are EOL_CHAR and EOL2_CHAR echoed?!? 1284 * XXX are EOL_CHAR and EOL2_CHAR echoed?!?
862 */ 1285 */
863 if (L_ECHO(tty)) { 1286 if (L_ECHO(tty)) {
864 if (tty->read_cnt >= N_TTY_BUF_SIZE-1)
865 tty_put_char(tty, '\a');
866 /* Record the column of first canon char. */ 1287 /* Record the column of first canon char. */
867 if (tty->canon_head == tty->read_head) 1288 if (tty->canon_head == tty->read_head)
868 tty->canon_column = tty->column; 1289 echo_set_canon_col(tty);
869 echo_char(c, tty); 1290 echo_char(c, tty);
1291 process_echoes(tty);
870 } 1292 }
871 /* 1293 /*
872 * XXX does PARMRK doubling happen for 1294 * XXX does PARMRK doubling happen for
873 * EOL_CHAR and EOL2_CHAR? 1295 * EOL_CHAR and EOL2_CHAR?
874 */ 1296 */
875 if (I_PARMRK(tty) && c == (unsigned char) '\377') 1297 if (parmrk)
876 put_tty_queue(c, tty); 1298 put_tty_queue(c, tty);
877 1299
878handle_newline: 1300handle_newline:
@@ -889,23 +1311,27 @@ handle_newline:
889 } 1311 }
890 } 1312 }
891 1313
892 finish_erasing(tty); 1314 parmrk = (c == (unsigned char) '\377' && I_PARMRK(tty)) ? 1 : 0;
1315 if (tty->read_cnt >= (N_TTY_BUF_SIZE - parmrk - 1)) {
1316 /* beep if no space */
1317 if (L_ECHO(tty))
1318 process_output('\a', tty);
1319 return;
1320 }
893 if (L_ECHO(tty)) { 1321 if (L_ECHO(tty)) {
894 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { 1322 finish_erasing(tty);
895 tty_put_char(tty, '\a'); /* beep if no space */
896 return;
897 }
898 if (c == '\n') 1323 if (c == '\n')
899 opost('\n', tty); 1324 echo_char_raw('\n', tty);
900 else { 1325 else {
901 /* Record the column of first canon char. */ 1326 /* Record the column of first canon char. */
902 if (tty->canon_head == tty->read_head) 1327 if (tty->canon_head == tty->read_head)
903 tty->canon_column = tty->column; 1328 echo_set_canon_col(tty);
904 echo_char(c, tty); 1329 echo_char(c, tty);
905 } 1330 }
1331 process_echoes(tty);
906 } 1332 }
907 1333
908 if (I_PARMRK(tty) && c == (unsigned char) '\377') 1334 if (parmrk)
909 put_tty_queue(c, tty); 1335 put_tty_queue(c, tty);
910 1336
911 put_tty_queue(c, tty); 1337 put_tty_queue(c, tty);
@@ -923,10 +1349,11 @@ handle_newline:
923 1349
924static void n_tty_write_wakeup(struct tty_struct *tty) 1350static void n_tty_write_wakeup(struct tty_struct *tty)
925{ 1351{
926 if (tty->fasync) { 1352 /* Write out any echoed characters that are still pending */
927 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 1353 process_echoes(tty);
1354
1355 if (tty->fasync && test_and_clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags))
928 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); 1356 kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
929 }
930} 1357}
931 1358
932/** 1359/**
@@ -1134,6 +1561,10 @@ static void n_tty_close(struct tty_struct *tty)
1134 free_buf(tty->read_buf); 1561 free_buf(tty->read_buf);
1135 tty->read_buf = NULL; 1562 tty->read_buf = NULL;
1136 } 1563 }
1564 if (tty->echo_buf) {
1565 free_buf(tty->echo_buf);
1566 tty->echo_buf = NULL;
1567 }
1137} 1568}
1138 1569
1139/** 1570/**
@@ -1151,13 +1582,19 @@ static int n_tty_open(struct tty_struct *tty)
1151 if (!tty) 1582 if (!tty)
1152 return -EINVAL; 1583 return -EINVAL;
1153 1584
1154 /* This one is ugly. Currently a malloc failure here can panic */ 1585 /* These are ugly. Currently a malloc failure here can panic */
1155 if (!tty->read_buf) { 1586 if (!tty->read_buf) {
1156 tty->read_buf = alloc_buf(); 1587 tty->read_buf = alloc_buf();
1157 if (!tty->read_buf) 1588 if (!tty->read_buf)
1158 return -ENOMEM; 1589 return -ENOMEM;
1159 } 1590 }
1591 if (!tty->echo_buf) {
1592 tty->echo_buf = alloc_buf();
1593 if (!tty->echo_buf)
1594 return -ENOMEM;
1595 }
1160 memset(tty->read_buf, 0, N_TTY_BUF_SIZE); 1596 memset(tty->read_buf, 0, N_TTY_BUF_SIZE);
1597 memset(tty->echo_buf, 0, N_TTY_BUF_SIZE);
1161 reset_buffer_flags(tty); 1598 reset_buffer_flags(tty);
1162 tty->column = 0; 1599 tty->column = 0;
1163 n_tty_set_termios(tty, NULL); 1600 n_tty_set_termios(tty, NULL);
@@ -1487,16 +1924,23 @@ do_it_again:
1487 * @buf: userspace buffer pointer 1924 * @buf: userspace buffer pointer
1488 * @nr: size of I/O 1925 * @nr: size of I/O
1489 * 1926 *
1490 * Write function of the terminal device. This is serialized with 1927 * Write function of the terminal device. This is serialized with
1491 * respect to other write callers but not to termios changes, reads 1928 * respect to other write callers but not to termios changes, reads
1492 * and other such events. We must be careful with N_TTY as the receive 1929 * and other such events. Since the receive code will echo characters,
1493 * code will echo characters, thus calling driver write methods. 1930 * thus calling driver write methods, the output_lock is used in
1931 * the output processing functions called here as well as in the
1932 * echo processing function to protect the column state and space
1933 * left in the buffer.
1494 * 1934 *
1495 * This code must be sure never to sleep through a hangup. 1935 * This code must be sure never to sleep through a hangup.
1936 *
1937 * Locking: output_lock to protect column state and space left
1938 * (note that the process_output*() functions take this
1939 * lock themselves)
1496 */ 1940 */
1497 1941
1498static ssize_t n_tty_write(struct tty_struct *tty, struct file *file, 1942static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1499 const unsigned char *buf, size_t nr) 1943 const unsigned char *buf, size_t nr)
1500{ 1944{
1501 const unsigned char *b = buf; 1945 const unsigned char *b = buf;
1502 DECLARE_WAITQUEUE(wait, current); 1946 DECLARE_WAITQUEUE(wait, current);
@@ -1510,6 +1954,9 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1510 return retval; 1954 return retval;
1511 } 1955 }
1512 1956
1957 /* Write out any echoed characters that are still pending */
1958 process_echoes(tty);
1959
1513 add_wait_queue(&tty->write_wait, &wait); 1960 add_wait_queue(&tty->write_wait, &wait);
1514 while (1) { 1961 while (1) {
1515 set_current_state(TASK_INTERRUPTIBLE); 1962 set_current_state(TASK_INTERRUPTIBLE);
@@ -1523,7 +1970,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1523 } 1970 }
1524 if (O_OPOST(tty) && !(test_bit(TTY_HW_COOK_OUT, &tty->flags))) { 1971 if (O_OPOST(tty) && !(test_bit(TTY_HW_COOK_OUT, &tty->flags))) {
1525 while (nr > 0) { 1972 while (nr > 0) {
1526 ssize_t num = opost_block(tty, b, nr); 1973 ssize_t num = process_output_block(tty, b, nr);
1527 if (num < 0) { 1974 if (num < 0) {
1528 if (num == -EAGAIN) 1975 if (num == -EAGAIN)
1529 break; 1976 break;
@@ -1535,7 +1982,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1535 if (nr == 0) 1982 if (nr == 0)
1536 break; 1983 break;
1537 c = *b; 1984 c = *b;
1538 if (opost(c, tty) < 0) 1985 if (process_output(c, tty) < 0)
1539 break; 1986 break;
1540 b++; nr--; 1987 b++; nr--;
1541 } 1988 }
@@ -1565,6 +2012,8 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1565break_out: 2012break_out:
1566 __set_current_state(TASK_RUNNING); 2013 __set_current_state(TASK_RUNNING);
1567 remove_wait_queue(&tty->write_wait, &wait); 2014 remove_wait_queue(&tty->write_wait, &wait);
2015 if (b - buf != nr && tty->fasync)
2016 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
1568 return (b - buf) ? b - buf : retval; 2017 return (b - buf) ? b - buf : retval;
1569} 2018}
1570 2019
@@ -1663,4 +2112,3 @@ struct tty_ldisc_ops tty_ldisc_N_TTY = {
1663 .receive_buf = n_tty_receive_buf, 2112 .receive_buf = n_tty_receive_buf,
1664 .write_wakeup = n_tty_write_wakeup 2113 .write_wakeup = n_tty_write_wakeup
1665}; 2114};
1666
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 9a34a1935283..d6102b644b55 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -353,6 +353,7 @@ struct ctrl_ul {
353 353
354/* This holds all information that is needed regarding a port */ 354/* This holds all information that is needed regarding a port */
355struct port { 355struct port {
356 struct tty_port port;
356 u8 update_flow_control; 357 u8 update_flow_control;
357 struct ctrl_ul ctrl_ul; 358 struct ctrl_ul ctrl_ul;
358 struct ctrl_dl ctrl_dl; 359 struct ctrl_dl ctrl_dl;
@@ -365,8 +366,6 @@ struct port {
365 u8 toggle_ul; 366 u8 toggle_ul;
366 u16 token_dl; 367 u16 token_dl;
367 368
368 struct tty_struct *tty;
369 int tty_open_count;
370 /* mutex to ensure one access patch to this port */ 369 /* mutex to ensure one access patch to this port */
371 struct mutex tty_sem; 370 struct mutex tty_sem;
372 wait_queue_head_t tty_wait; 371 wait_queue_head_t tty_wait;
@@ -788,14 +787,14 @@ static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
788 * Return 1 - send buffer to card and ack. 787 * Return 1 - send buffer to card and ack.
789 * Return 0 - don't ack, don't send buffer to card. 788 * Return 0 - don't ack, don't send buffer to card.
790 */ 789 */
791static int send_data(enum port_type index, const struct nozomi *dc) 790static int send_data(enum port_type index, struct nozomi *dc)
792{ 791{
793 u32 size = 0; 792 u32 size = 0;
794 const struct port *port = &dc->port[index]; 793 struct port *port = &dc->port[index];
795 const u8 toggle = port->toggle_ul; 794 const u8 toggle = port->toggle_ul;
796 void __iomem *addr = port->ul_addr[toggle]; 795 void __iomem *addr = port->ul_addr[toggle];
797 const u32 ul_size = port->ul_size[toggle]; 796 const u32 ul_size = port->ul_size[toggle];
798 struct tty_struct *tty = port->tty; 797 struct tty_struct *tty = tty_port_tty_get(&port->port);
799 798
800 /* Get data from tty and place in buf for now */ 799 /* Get data from tty and place in buf for now */
801 size = __kfifo_get(port->fifo_ul, dc->send_buf, 800 size = __kfifo_get(port->fifo_ul, dc->send_buf,
@@ -803,6 +802,7 @@ static int send_data(enum port_type index, const struct nozomi *dc)
803 802
804 if (size == 0) { 803 if (size == 0) {
805 DBG4("No more data to send, disable link:"); 804 DBG4("No more data to send, disable link:");
805 tty_kref_put(tty);
806 return 0; 806 return 0;
807 } 807 }
808 808
@@ -815,6 +815,7 @@ static int send_data(enum port_type index, const struct nozomi *dc)
815 if (tty) 815 if (tty)
816 tty_wakeup(tty); 816 tty_wakeup(tty);
817 817
818 tty_kref_put(tty);
818 return 1; 819 return 1;
819} 820}
820 821
@@ -826,7 +827,7 @@ static int receive_data(enum port_type index, struct nozomi *dc)
826 u32 offset = 4; 827 u32 offset = 4;
827 struct port *port = &dc->port[index]; 828 struct port *port = &dc->port[index];
828 void __iomem *addr = port->dl_addr[port->toggle_dl]; 829 void __iomem *addr = port->dl_addr[port->toggle_dl];
829 struct tty_struct *tty = port->tty; 830 struct tty_struct *tty = tty_port_tty_get(&port->port);
830 int i; 831 int i;
831 832
832 if (unlikely(!tty)) { 833 if (unlikely(!tty)) {
@@ -870,7 +871,7 @@ static int receive_data(enum port_type index, struct nozomi *dc)
870 } 871 }
871 872
872 set_bit(index, &dc->flip); 873 set_bit(index, &dc->flip);
873 874 tty_kref_put(tty);
874 return 1; 875 return 1;
875} 876}
876 877
@@ -1276,9 +1277,15 @@ static irqreturn_t interrupt_handler(int irq, void *dev_id)
1276 1277
1277exit_handler: 1278exit_handler:
1278 spin_unlock(&dc->spin_mutex); 1279 spin_unlock(&dc->spin_mutex);
1279 for (a = 0; a < NOZOMI_MAX_PORTS; a++) 1280 for (a = 0; a < NOZOMI_MAX_PORTS; a++) {
1280 if (test_and_clear_bit(a, &dc->flip)) 1281 struct tty_struct *tty;
1281 tty_flip_buffer_push(dc->port[a].tty); 1282 if (test_and_clear_bit(a, &dc->flip)) {
1283 tty = tty_port_tty_get(&dc->port[a].port);
1284 if (tty)
1285 tty_flip_buffer_push(tty);
1286 tty_kref_put(tty);
1287 }
1288 }
1282 return IRQ_HANDLED; 1289 return IRQ_HANDLED;
1283none: 1290none:
1284 spin_unlock(&dc->spin_mutex); 1291 spin_unlock(&dc->spin_mutex);
@@ -1453,12 +1460,10 @@ static int __devinit nozomi_card_init(struct pci_dev *pdev,
1453 1460
1454 for (i = 0; i < MAX_PORT; i++) { 1461 for (i = 0; i < MAX_PORT; i++) {
1455 mutex_init(&dc->port[i].tty_sem); 1462 mutex_init(&dc->port[i].tty_sem);
1456 dc->port[i].tty_open_count = 0; 1463 tty_port_init(&dc->port[i].port);
1457 dc->port[i].tty = NULL;
1458 tty_register_device(ntty_driver, dc->index_start + i, 1464 tty_register_device(ntty_driver, dc->index_start + i,
1459 &pdev->dev); 1465 &pdev->dev);
1460 } 1466 }
1461
1462 return 0; 1467 return 0;
1463 1468
1464err_free_sbuf: 1469err_free_sbuf:
@@ -1482,14 +1487,16 @@ static void __devexit tty_exit(struct nozomi *dc)
1482 1487
1483 flush_scheduled_work(); 1488 flush_scheduled_work();
1484 1489
1485 for (i = 0; i < MAX_PORT; ++i) 1490 for (i = 0; i < MAX_PORT; ++i) {
1486 if (dc->port[i].tty && \ 1491 struct tty_struct *tty = tty_port_tty_get(&dc->port[i].port);
1487 list_empty(&dc->port[i].tty->hangup_work.entry)) 1492 if (tty && list_empty(&tty->hangup_work.entry))
1488 tty_hangup(dc->port[i].tty); 1493 tty_hangup(tty);
1489 1494 tty_kref_put(tty);
1495 }
1496 /* Racy below - surely should wait for scheduled work to be done or
1497 complete off a hangup method ? */
1490 while (dc->open_ttys) 1498 while (dc->open_ttys)
1491 msleep(1); 1499 msleep(1);
1492
1493 for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i) 1500 for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
1494 tty_unregister_device(ntty_driver, i); 1501 tty_unregister_device(ntty_driver, i);
1495} 1502}
@@ -1579,23 +1586,22 @@ static int ntty_open(struct tty_struct *tty, struct file *file)
1579 if (mutex_lock_interruptible(&port->tty_sem)) 1586 if (mutex_lock_interruptible(&port->tty_sem))
1580 return -ERESTARTSYS; 1587 return -ERESTARTSYS;
1581 1588
1582 port->tty_open_count++; 1589 port->port.count++;
1583 dc->open_ttys++; 1590 dc->open_ttys++;
1584 1591
1585 /* Enable interrupt downlink for channel */ 1592 /* Enable interrupt downlink for channel */
1586 if (port->tty_open_count == 1) { 1593 if (port->port.count == 1) {
1594 /* FIXME: is this needed now ? */
1587 tty->low_latency = 1; 1595 tty->low_latency = 1;
1588 tty->driver_data = port; 1596 tty->driver_data = port;
1589 port->tty = tty; 1597 tty_port_tty_set(&port->port, tty);
1590 DBG1("open: %d", port->token_dl); 1598 DBG1("open: %d", port->token_dl);
1591 spin_lock_irqsave(&dc->spin_mutex, flags); 1599 spin_lock_irqsave(&dc->spin_mutex, flags);
1592 dc->last_ier = dc->last_ier | port->token_dl; 1600 dc->last_ier = dc->last_ier | port->token_dl;
1593 writew(dc->last_ier, dc->reg_ier); 1601 writew(dc->last_ier, dc->reg_ier);
1594 spin_unlock_irqrestore(&dc->spin_mutex, flags); 1602 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1595 } 1603 }
1596
1597 mutex_unlock(&port->tty_sem); 1604 mutex_unlock(&port->tty_sem);
1598
1599 return 0; 1605 return 0;
1600} 1606}
1601 1607
@@ -1606,31 +1612,30 @@ static int ntty_open(struct tty_struct *tty, struct file *file)
1606static void ntty_close(struct tty_struct *tty, struct file *file) 1612static void ntty_close(struct tty_struct *tty, struct file *file)
1607{ 1613{
1608 struct nozomi *dc = get_dc_by_tty(tty); 1614 struct nozomi *dc = get_dc_by_tty(tty);
1609 struct port *port = tty->driver_data; 1615 struct port *nport = tty->driver_data;
1616 struct tty_port *port = &nport->port;
1610 unsigned long flags; 1617 unsigned long flags;
1611 1618
1612 if (!dc || !port) 1619 if (!dc || !nport)
1613 return; 1620 return;
1614 1621
1615 if (mutex_lock_interruptible(&port->tty_sem)) 1622 /* Users cannot interrupt a close */
1616 return; 1623 mutex_lock(&nport->tty_sem);
1617 1624
1618 if (!port->tty_open_count) 1625 WARN_ON(!port->count);
1619 goto exit;
1620 1626
1621 dc->open_ttys--; 1627 dc->open_ttys--;
1622 port->tty_open_count--; 1628 port->count--;
1629 tty_port_tty_set(port, NULL);
1623 1630
1624 if (port->tty_open_count == 0) { 1631 if (port->count == 0) {
1625 DBG1("close: %d", port->token_dl); 1632 DBG1("close: %d", nport->token_dl);
1626 spin_lock_irqsave(&dc->spin_mutex, flags); 1633 spin_lock_irqsave(&dc->spin_mutex, flags);
1627 dc->last_ier &= ~(port->token_dl); 1634 dc->last_ier &= ~(nport->token_dl);
1628 writew(dc->last_ier, dc->reg_ier); 1635 writew(dc->last_ier, dc->reg_ier);
1629 spin_unlock_irqrestore(&dc->spin_mutex, flags); 1636 spin_unlock_irqrestore(&dc->spin_mutex, flags);
1630 } 1637 }
1631 1638 mutex_unlock(&nport->tty_sem);
1632exit:
1633 mutex_unlock(&port->tty_sem);
1634} 1639}
1635 1640
1636/* 1641/*
@@ -1660,7 +1665,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
1660 return -EAGAIN; 1665 return -EAGAIN;
1661 } 1666 }
1662 1667
1663 if (unlikely(!port->tty_open_count)) { 1668 if (unlikely(!port->port.count)) {
1664 DBG1(" "); 1669 DBG1(" ");
1665 goto exit; 1670 goto exit;
1666 } 1671 }
@@ -1710,7 +1715,7 @@ static int ntty_write_room(struct tty_struct *tty)
1710 if (!mutex_trylock(&port->tty_sem)) 1715 if (!mutex_trylock(&port->tty_sem))
1711 return 0; 1716 return 0;
1712 1717
1713 if (!port->tty_open_count) 1718 if (!port->port.count)
1714 goto exit; 1719 goto exit;
1715 1720
1716 room = port->fifo_ul->size - __kfifo_len(port->fifo_ul); 1721 room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
@@ -1866,7 +1871,7 @@ static s32 ntty_chars_in_buffer(struct tty_struct *tty)
1866 goto exit_in_buffer; 1871 goto exit_in_buffer;
1867 } 1872 }
1868 1873
1869 if (unlikely(!port->tty_open_count)) { 1874 if (unlikely(!port->port.count)) {
1870 dev_err(&dc->pdev->dev, "No tty open?\n"); 1875 dev_err(&dc->pdev->dev, "No tty open?\n");
1871 rval = -ENODEV; 1876 rval = -ENODEV;
1872 goto exit_in_buffer; 1877 goto exit_in_buffer;
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 4d64a02612a4..dc073e167abc 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -138,20 +138,15 @@ struct _input_signal_events {
138 */ 138 */
139 139
140typedef struct _mgslpc_info { 140typedef struct _mgslpc_info {
141 struct tty_port port;
141 void *if_ptr; /* General purpose pointer (used by SPPP) */ 142 void *if_ptr; /* General purpose pointer (used by SPPP) */
142 int magic; 143 int magic;
143 int flags;
144 int count; /* count of opens */
145 int line; 144 int line;
146 unsigned short close_delay;
147 unsigned short closing_wait; /* time to wait before closing */
148 145
149 struct mgsl_icount icount; 146 struct mgsl_icount icount;
150 147
151 struct tty_struct *tty;
152 int timeout; 148 int timeout;
153 int x_char; /* xon/xoff character */ 149 int x_char; /* xon/xoff character */
154 int blocked_open; /* # of blocked opens */
155 unsigned char read_status_mask; 150 unsigned char read_status_mask;
156 unsigned char ignore_status_mask; 151 unsigned char ignore_status_mask;
157 152
@@ -170,9 +165,6 @@ typedef struct _mgslpc_info {
170 int rx_buf_count; /* total number of rx buffers */ 165 int rx_buf_count; /* total number of rx buffers */
171 int rx_frame_count; /* number of full rx buffers */ 166 int rx_frame_count; /* number of full rx buffers */
172 167
173 wait_queue_head_t open_wait;
174 wait_queue_head_t close_wait;
175
176 wait_queue_head_t status_event_wait_q; 168 wait_queue_head_t status_event_wait_q;
177 wait_queue_head_t event_wait_q; 169 wait_queue_head_t event_wait_q;
178 struct timer_list tx_timer; /* HDLC transmit timeout timer */ 170 struct timer_list tx_timer; /* HDLC transmit timeout timer */
@@ -375,7 +367,7 @@ static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short
375static void rx_start(MGSLPC_INFO *info); 367static void rx_start(MGSLPC_INFO *info);
376static void rx_stop(MGSLPC_INFO *info); 368static void rx_stop(MGSLPC_INFO *info);
377 369
378static void tx_start(MGSLPC_INFO *info); 370static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty);
379static void tx_stop(MGSLPC_INFO *info); 371static void tx_stop(MGSLPC_INFO *info);
380static void tx_set_idle(MGSLPC_INFO *info); 372static void tx_set_idle(MGSLPC_INFO *info);
381 373
@@ -389,7 +381,8 @@ static void async_mode(MGSLPC_INFO *info);
389 381
390static void tx_timeout(unsigned long context); 382static void tx_timeout(unsigned long context);
391 383
392static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg); 384static int carrier_raised(struct tty_port *port);
385static void raise_dtr_rts(struct tty_port *port);
393 386
394#if SYNCLINK_GENERIC_HDLC 387#if SYNCLINK_GENERIC_HDLC
395#define dev_to_port(D) (dev_to_hdlc(D)->priv) 388#define dev_to_port(D) (dev_to_hdlc(D)->priv)
@@ -410,7 +403,7 @@ static void release_resources(MGSLPC_INFO *info);
410static void mgslpc_add_device(MGSLPC_INFO *info); 403static void mgslpc_add_device(MGSLPC_INFO *info);
411static void mgslpc_remove_device(MGSLPC_INFO *info); 404static void mgslpc_remove_device(MGSLPC_INFO *info);
412 405
413static bool rx_get_frame(MGSLPC_INFO *info); 406static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty);
414static void rx_reset_buffers(MGSLPC_INFO *info); 407static void rx_reset_buffers(MGSLPC_INFO *info);
415static int rx_alloc_buffers(MGSLPC_INFO *info); 408static int rx_alloc_buffers(MGSLPC_INFO *info);
416static void rx_free_buffers(MGSLPC_INFO *info); 409static void rx_free_buffers(MGSLPC_INFO *info);
@@ -421,7 +414,7 @@ static irqreturn_t mgslpc_isr(int irq, void *dev_id);
421 * Bottom half interrupt handlers 414 * Bottom half interrupt handlers
422 */ 415 */
423static void bh_handler(struct work_struct *work); 416static void bh_handler(struct work_struct *work);
424static void bh_transmit(MGSLPC_INFO *info); 417static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty);
425static void bh_status(MGSLPC_INFO *info); 418static void bh_status(MGSLPC_INFO *info);
426 419
427/* 420/*
@@ -432,10 +425,10 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
432 unsigned int set, unsigned int clear); 425 unsigned int set, unsigned int clear);
433static int get_stats(MGSLPC_INFO *info, struct mgsl_icount __user *user_icount); 426static int get_stats(MGSLPC_INFO *info, struct mgsl_icount __user *user_icount);
434static int get_params(MGSLPC_INFO *info, MGSL_PARAMS __user *user_params); 427static int get_params(MGSLPC_INFO *info, MGSL_PARAMS __user *user_params);
435static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params); 428static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params, struct tty_struct *tty);
436static int get_txidle(MGSLPC_INFO *info, int __user *idle_mode); 429static int get_txidle(MGSLPC_INFO *info, int __user *idle_mode);
437static int set_txidle(MGSLPC_INFO *info, int idle_mode); 430static int set_txidle(MGSLPC_INFO *info, int idle_mode);
438static int set_txenable(MGSLPC_INFO *info, int enable); 431static int set_txenable(MGSLPC_INFO *info, int enable, struct tty_struct *tty);
439static int tx_abort(MGSLPC_INFO *info); 432static int tx_abort(MGSLPC_INFO *info);
440static int set_rxenable(MGSLPC_INFO *info, int enable); 433static int set_rxenable(MGSLPC_INFO *info, int enable);
441static int wait_events(MGSLPC_INFO *info, int __user *mask); 434static int wait_events(MGSLPC_INFO *info, int __user *mask);
@@ -474,7 +467,7 @@ static struct tty_driver *serial_driver;
474/* number of characters left in xmit buffer before we ask for more */ 467/* number of characters left in xmit buffer before we ask for more */
475#define WAKEUP_CHARS 256 468#define WAKEUP_CHARS 256
476 469
477static void mgslpc_change_params(MGSLPC_INFO *info); 470static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty);
478static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout); 471static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
479 472
480/* PCMCIA prototypes */ 473/* PCMCIA prototypes */
@@ -517,6 +510,11 @@ static void ldisc_receive_buf(struct tty_struct *tty,
517 } 510 }
518} 511}
519 512
513static const struct tty_port_operations mgslpc_port_ops = {
514 .carrier_raised = carrier_raised,
515 .raise_dtr_rts = raise_dtr_rts
516};
517
520static int mgslpc_probe(struct pcmcia_device *link) 518static int mgslpc_probe(struct pcmcia_device *link)
521{ 519{
522 MGSLPC_INFO *info; 520 MGSLPC_INFO *info;
@@ -532,12 +530,12 @@ static int mgslpc_probe(struct pcmcia_device *link)
532 } 530 }
533 531
534 info->magic = MGSLPC_MAGIC; 532 info->magic = MGSLPC_MAGIC;
533 tty_port_init(&info->port);
534 info->port.ops = &mgslpc_port_ops;
535 INIT_WORK(&info->task, bh_handler); 535 INIT_WORK(&info->task, bh_handler);
536 info->max_frame_size = 4096; 536 info->max_frame_size = 4096;
537 info->close_delay = 5*HZ/10; 537 info->port.close_delay = 5*HZ/10;
538 info->closing_wait = 30*HZ; 538 info->port.closing_wait = 30*HZ;
539 init_waitqueue_head(&info->open_wait);
540 init_waitqueue_head(&info->close_wait);
541 init_waitqueue_head(&info->status_event_wait_q); 539 init_waitqueue_head(&info->status_event_wait_q);
542 init_waitqueue_head(&info->event_wait_q); 540 init_waitqueue_head(&info->event_wait_q);
543 spin_lock_init(&info->lock); 541 spin_lock_init(&info->lock);
@@ -784,7 +782,7 @@ static void tx_release(struct tty_struct *tty)
784 782
785 spin_lock_irqsave(&info->lock,flags); 783 spin_lock_irqsave(&info->lock,flags);
786 if (!info->tx_enabled) 784 if (!info->tx_enabled)
787 tx_start(info); 785 tx_start(info, tty);
788 spin_unlock_irqrestore(&info->lock,flags); 786 spin_unlock_irqrestore(&info->lock,flags);
789} 787}
790 788
@@ -823,6 +821,7 @@ static int bh_action(MGSLPC_INFO *info)
823static void bh_handler(struct work_struct *work) 821static void bh_handler(struct work_struct *work)
824{ 822{
825 MGSLPC_INFO *info = container_of(work, MGSLPC_INFO, task); 823 MGSLPC_INFO *info = container_of(work, MGSLPC_INFO, task);
824 struct tty_struct *tty;
826 int action; 825 int action;
827 826
828 if (!info) 827 if (!info)
@@ -833,6 +832,7 @@ static void bh_handler(struct work_struct *work)
833 __FILE__,__LINE__,info->device_name); 832 __FILE__,__LINE__,info->device_name);
834 833
835 info->bh_running = true; 834 info->bh_running = true;
835 tty = tty_port_tty_get(&info->port);
836 836
837 while((action = bh_action(info)) != 0) { 837 while((action = bh_action(info)) != 0) {
838 838
@@ -844,10 +844,10 @@ static void bh_handler(struct work_struct *work)
844 switch (action) { 844 switch (action) {
845 845
846 case BH_RECEIVE: 846 case BH_RECEIVE:
847 while(rx_get_frame(info)); 847 while(rx_get_frame(info, tty));
848 break; 848 break;
849 case BH_TRANSMIT: 849 case BH_TRANSMIT:
850 bh_transmit(info); 850 bh_transmit(info, tty);
851 break; 851 break;
852 case BH_STATUS: 852 case BH_STATUS:
853 bh_status(info); 853 bh_status(info);
@@ -859,14 +859,14 @@ static void bh_handler(struct work_struct *work)
859 } 859 }
860 } 860 }
861 861
862 tty_kref_put(tty);
862 if (debug_level >= DEBUG_LEVEL_BH) 863 if (debug_level >= DEBUG_LEVEL_BH)
863 printk( "%s(%d):bh_handler(%s) exit\n", 864 printk( "%s(%d):bh_handler(%s) exit\n",
864 __FILE__,__LINE__,info->device_name); 865 __FILE__,__LINE__,info->device_name);
865} 866}
866 867
867static void bh_transmit(MGSLPC_INFO *info) 868static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty)
868{ 869{
869 struct tty_struct *tty = info->tty;
870 if (debug_level >= DEBUG_LEVEL_BH) 870 if (debug_level >= DEBUG_LEVEL_BH)
871 printk("bh_transmit() entry on %s\n", info->device_name); 871 printk("bh_transmit() entry on %s\n", info->device_name);
872 872
@@ -945,12 +945,11 @@ static void rx_ready_hdlc(MGSLPC_INFO *info, int eom)
945 issue_command(info, CHA, CMD_RXFIFO); 945 issue_command(info, CHA, CMD_RXFIFO);
946} 946}
947 947
948static void rx_ready_async(MGSLPC_INFO *info, int tcd) 948static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty)
949{ 949{
950 unsigned char data, status, flag; 950 unsigned char data, status, flag;
951 int fifo_count; 951 int fifo_count;
952 int work = 0; 952 int work = 0;
953 struct tty_struct *tty = info->tty;
954 struct mgsl_icount *icount = &info->icount; 953 struct mgsl_icount *icount = &info->icount;
955 954
956 if (tcd) { 955 if (tcd) {
@@ -1013,7 +1012,7 @@ static void rx_ready_async(MGSLPC_INFO *info, int tcd)
1013} 1012}
1014 1013
1015 1014
1016static void tx_done(MGSLPC_INFO *info) 1015static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty)
1017{ 1016{
1018 if (!info->tx_active) 1017 if (!info->tx_active)
1019 return; 1018 return;
@@ -1042,7 +1041,7 @@ static void tx_done(MGSLPC_INFO *info)
1042 else 1041 else
1043#endif 1042#endif
1044 { 1043 {
1045 if (info->tty->stopped || info->tty->hw_stopped) { 1044 if (tty->stopped || tty->hw_stopped) {
1046 tx_stop(info); 1045 tx_stop(info);
1047 return; 1046 return;
1048 } 1047 }
@@ -1050,7 +1049,7 @@ static void tx_done(MGSLPC_INFO *info)
1050 } 1049 }
1051} 1050}
1052 1051
1053static void tx_ready(MGSLPC_INFO *info) 1052static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty)
1054{ 1053{
1055 unsigned char fifo_count = 32; 1054 unsigned char fifo_count = 32;
1056 int c; 1055 int c;
@@ -1062,7 +1061,7 @@ static void tx_ready(MGSLPC_INFO *info)
1062 if (!info->tx_active) 1061 if (!info->tx_active)
1063 return; 1062 return;
1064 } else { 1063 } else {
1065 if (info->tty->stopped || info->tty->hw_stopped) { 1064 if (tty->stopped || tty->hw_stopped) {
1066 tx_stop(info); 1065 tx_stop(info);
1067 return; 1066 return;
1068 } 1067 }
@@ -1099,7 +1098,7 @@ static void tx_ready(MGSLPC_INFO *info)
1099 } 1098 }
1100} 1099}
1101 1100
1102static void cts_change(MGSLPC_INFO *info) 1101static void cts_change(MGSLPC_INFO *info, struct tty_struct *tty)
1103{ 1102{
1104 get_signals(info); 1103 get_signals(info);
1105 if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) 1104 if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
@@ -1112,14 +1111,14 @@ static void cts_change(MGSLPC_INFO *info)
1112 wake_up_interruptible(&info->status_event_wait_q); 1111 wake_up_interruptible(&info->status_event_wait_q);
1113 wake_up_interruptible(&info->event_wait_q); 1112 wake_up_interruptible(&info->event_wait_q);
1114 1113
1115 if (info->flags & ASYNC_CTS_FLOW) { 1114 if (info->port.flags & ASYNC_CTS_FLOW) {
1116 if (info->tty->hw_stopped) { 1115 if (tty->hw_stopped) {
1117 if (info->serial_signals & SerialSignal_CTS) { 1116 if (info->serial_signals & SerialSignal_CTS) {
1118 if (debug_level >= DEBUG_LEVEL_ISR) 1117 if (debug_level >= DEBUG_LEVEL_ISR)
1119 printk("CTS tx start..."); 1118 printk("CTS tx start...");
1120 if (info->tty) 1119 if (tty)
1121 info->tty->hw_stopped = 0; 1120 tty->hw_stopped = 0;
1122 tx_start(info); 1121 tx_start(info, tty);
1123 info->pending_bh |= BH_TRANSMIT; 1122 info->pending_bh |= BH_TRANSMIT;
1124 return; 1123 return;
1125 } 1124 }
@@ -1127,8 +1126,8 @@ static void cts_change(MGSLPC_INFO *info)
1127 if (!(info->serial_signals & SerialSignal_CTS)) { 1126 if (!(info->serial_signals & SerialSignal_CTS)) {
1128 if (debug_level >= DEBUG_LEVEL_ISR) 1127 if (debug_level >= DEBUG_LEVEL_ISR)
1129 printk("CTS tx stop..."); 1128 printk("CTS tx stop...");
1130 if (info->tty) 1129 if (tty)
1131 info->tty->hw_stopped = 1; 1130 tty->hw_stopped = 1;
1132 tx_stop(info); 1131 tx_stop(info);
1133 } 1132 }
1134 } 1133 }
@@ -1136,7 +1135,7 @@ static void cts_change(MGSLPC_INFO *info)
1136 info->pending_bh |= BH_STATUS; 1135 info->pending_bh |= BH_STATUS;
1137} 1136}
1138 1137
1139static void dcd_change(MGSLPC_INFO *info) 1138static void dcd_change(MGSLPC_INFO *info, struct tty_struct *tty)
1140{ 1139{
1141 get_signals(info); 1140 get_signals(info);
1142 if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) 1141 if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
@@ -1158,17 +1157,17 @@ static void dcd_change(MGSLPC_INFO *info)
1158 wake_up_interruptible(&info->status_event_wait_q); 1157 wake_up_interruptible(&info->status_event_wait_q);
1159 wake_up_interruptible(&info->event_wait_q); 1158 wake_up_interruptible(&info->event_wait_q);
1160 1159
1161 if (info->flags & ASYNC_CHECK_CD) { 1160 if (info->port.flags & ASYNC_CHECK_CD) {
1162 if (debug_level >= DEBUG_LEVEL_ISR) 1161 if (debug_level >= DEBUG_LEVEL_ISR)
1163 printk("%s CD now %s...", info->device_name, 1162 printk("%s CD now %s...", info->device_name,
1164 (info->serial_signals & SerialSignal_DCD) ? "on" : "off"); 1163 (info->serial_signals & SerialSignal_DCD) ? "on" : "off");
1165 if (info->serial_signals & SerialSignal_DCD) 1164 if (info->serial_signals & SerialSignal_DCD)
1166 wake_up_interruptible(&info->open_wait); 1165 wake_up_interruptible(&info->port.open_wait);
1167 else { 1166 else {
1168 if (debug_level >= DEBUG_LEVEL_ISR) 1167 if (debug_level >= DEBUG_LEVEL_ISR)
1169 printk("doing serial hangup..."); 1168 printk("doing serial hangup...");
1170 if (info->tty) 1169 if (tty)
1171 tty_hangup(info->tty); 1170 tty_hangup(tty);
1172 } 1171 }
1173 } 1172 }
1174 info->pending_bh |= BH_STATUS; 1173 info->pending_bh |= BH_STATUS;
@@ -1214,6 +1213,7 @@ static void ri_change(MGSLPC_INFO *info)
1214static irqreturn_t mgslpc_isr(int dummy, void *dev_id) 1213static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1215{ 1214{
1216 MGSLPC_INFO *info = dev_id; 1215 MGSLPC_INFO *info = dev_id;
1216 struct tty_struct *tty;
1217 unsigned short isr; 1217 unsigned short isr;
1218 unsigned char gis, pis; 1218 unsigned char gis, pis;
1219 int count=0; 1219 int count=0;
@@ -1224,6 +1224,8 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1224 if (!(info->p_dev->_locked)) 1224 if (!(info->p_dev->_locked))
1225 return IRQ_HANDLED; 1225 return IRQ_HANDLED;
1226 1226
1227 tty = tty_port_tty_get(&info->port);
1228
1227 spin_lock(&info->lock); 1229 spin_lock(&info->lock);
1228 1230
1229 while ((gis = read_reg(info, CHA + GIS))) { 1231 while ((gis = read_reg(info, CHA + GIS))) {
@@ -1239,9 +1241,9 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1239 if (gis & (BIT1 + BIT0)) { 1241 if (gis & (BIT1 + BIT0)) {
1240 isr = read_reg16(info, CHB + ISR); 1242 isr = read_reg16(info, CHB + ISR);
1241 if (isr & IRQ_DCD) 1243 if (isr & IRQ_DCD)
1242 dcd_change(info); 1244 dcd_change(info, tty);
1243 if (isr & IRQ_CTS) 1245 if (isr & IRQ_CTS)
1244 cts_change(info); 1246 cts_change(info, tty);
1245 } 1247 }
1246 if (gis & (BIT3 + BIT2)) 1248 if (gis & (BIT3 + BIT2))
1247 { 1249 {
@@ -1258,8 +1260,8 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1258 } 1260 }
1259 if (isr & IRQ_BREAK_ON) { 1261 if (isr & IRQ_BREAK_ON) {
1260 info->icount.brk++; 1262 info->icount.brk++;
1261 if (info->flags & ASYNC_SAK) 1263 if (info->port.flags & ASYNC_SAK)
1262 do_SAK(info->tty); 1264 do_SAK(tty);
1263 } 1265 }
1264 if (isr & IRQ_RXTIME) { 1266 if (isr & IRQ_RXTIME) {
1265 issue_command(info, CHA, CMD_RXFIFO_READ); 1267 issue_command(info, CHA, CMD_RXFIFO_READ);
@@ -1268,7 +1270,7 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1268 if (info->params.mode == MGSL_MODE_HDLC) 1270 if (info->params.mode == MGSL_MODE_HDLC)
1269 rx_ready_hdlc(info, isr & IRQ_RXEOM); 1271 rx_ready_hdlc(info, isr & IRQ_RXEOM);
1270 else 1272 else
1271 rx_ready_async(info, isr & IRQ_RXEOM); 1273 rx_ready_async(info, isr & IRQ_RXEOM, tty);
1272 } 1274 }
1273 1275
1274 /* transmit IRQs */ 1276 /* transmit IRQs */
@@ -1277,14 +1279,14 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1277 info->icount.txabort++; 1279 info->icount.txabort++;
1278 else 1280 else
1279 info->icount.txunder++; 1281 info->icount.txunder++;
1280 tx_done(info); 1282 tx_done(info, tty);
1281 } 1283 }
1282 else if (isr & IRQ_ALLSENT) { 1284 else if (isr & IRQ_ALLSENT) {
1283 info->icount.txok++; 1285 info->icount.txok++;
1284 tx_done(info); 1286 tx_done(info, tty);
1285 } 1287 }
1286 else if (isr & IRQ_TXFIFO) 1288 else if (isr & IRQ_TXFIFO)
1287 tx_ready(info); 1289 tx_ready(info, tty);
1288 } 1290 }
1289 if (gis & BIT7) { 1291 if (gis & BIT7) {
1290 pis = read_reg(info, CHA + PIS); 1292 pis = read_reg(info, CHA + PIS);
@@ -1308,6 +1310,7 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1308 } 1310 }
1309 1311
1310 spin_unlock(&info->lock); 1312 spin_unlock(&info->lock);
1313 tty_kref_put(tty);
1311 1314
1312 if (debug_level >= DEBUG_LEVEL_ISR) 1315 if (debug_level >= DEBUG_LEVEL_ISR)
1313 printk("%s(%d):mgslpc_isr(%d)exit.\n", 1316 printk("%s(%d):mgslpc_isr(%d)exit.\n",
@@ -1318,14 +1321,14 @@ static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
1318 1321
1319/* Initialize and start device. 1322/* Initialize and start device.
1320 */ 1323 */
1321static int startup(MGSLPC_INFO * info) 1324static int startup(MGSLPC_INFO * info, struct tty_struct *tty)
1322{ 1325{
1323 int retval = 0; 1326 int retval = 0;
1324 1327
1325 if (debug_level >= DEBUG_LEVEL_INFO) 1328 if (debug_level >= DEBUG_LEVEL_INFO)
1326 printk("%s(%d):startup(%s)\n",__FILE__,__LINE__,info->device_name); 1329 printk("%s(%d):startup(%s)\n",__FILE__,__LINE__,info->device_name);
1327 1330
1328 if (info->flags & ASYNC_INITIALIZED) 1331 if (info->port.flags & ASYNC_INITIALIZED)
1329 return 0; 1332 return 0;
1330 1333
1331 if (!info->tx_buf) { 1334 if (!info->tx_buf) {
@@ -1352,30 +1355,30 @@ static int startup(MGSLPC_INFO * info)
1352 retval = adapter_test(info); 1355 retval = adapter_test(info);
1353 1356
1354 if ( retval ) { 1357 if ( retval ) {
1355 if (capable(CAP_SYS_ADMIN) && info->tty) 1358 if (capable(CAP_SYS_ADMIN) && tty)
1356 set_bit(TTY_IO_ERROR, &info->tty->flags); 1359 set_bit(TTY_IO_ERROR, &tty->flags);
1357 release_resources(info); 1360 release_resources(info);
1358 return retval; 1361 return retval;
1359 } 1362 }
1360 1363
1361 /* program hardware for current parameters */ 1364 /* program hardware for current parameters */
1362 mgslpc_change_params(info); 1365 mgslpc_change_params(info, tty);
1363 1366
1364 if (info->tty) 1367 if (tty)
1365 clear_bit(TTY_IO_ERROR, &info->tty->flags); 1368 clear_bit(TTY_IO_ERROR, &tty->flags);
1366 1369
1367 info->flags |= ASYNC_INITIALIZED; 1370 info->port.flags |= ASYNC_INITIALIZED;
1368 1371
1369 return 0; 1372 return 0;
1370} 1373}
1371 1374
1372/* Called by mgslpc_close() and mgslpc_hangup() to shutdown hardware 1375/* Called by mgslpc_close() and mgslpc_hangup() to shutdown hardware
1373 */ 1376 */
1374static void shutdown(MGSLPC_INFO * info) 1377static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty)
1375{ 1378{
1376 unsigned long flags; 1379 unsigned long flags;
1377 1380
1378 if (!(info->flags & ASYNC_INITIALIZED)) 1381 if (!(info->port.flags & ASYNC_INITIALIZED))
1379 return; 1382 return;
1380 1383
1381 if (debug_level >= DEBUG_LEVEL_INFO) 1384 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1402,7 +1405,7 @@ static void shutdown(MGSLPC_INFO * info)
1402 /* TODO:disable interrupts instead of reset to preserve signal states */ 1405 /* TODO:disable interrupts instead of reset to preserve signal states */
1403 reset_device(info); 1406 reset_device(info);
1404 1407
1405 if (!info->tty || info->tty->termios->c_cflag & HUPCL) { 1408 if (!tty || tty->termios->c_cflag & HUPCL) {
1406 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS); 1409 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
1407 set_signals(info); 1410 set_signals(info);
1408 } 1411 }
@@ -1411,13 +1414,13 @@ static void shutdown(MGSLPC_INFO * info)
1411 1414
1412 release_resources(info); 1415 release_resources(info);
1413 1416
1414 if (info->tty) 1417 if (tty)
1415 set_bit(TTY_IO_ERROR, &info->tty->flags); 1418 set_bit(TTY_IO_ERROR, &tty->flags);
1416 1419
1417 info->flags &= ~ASYNC_INITIALIZED; 1420 info->port.flags &= ~ASYNC_INITIALIZED;
1418} 1421}
1419 1422
1420static void mgslpc_program_hw(MGSLPC_INFO *info) 1423static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty)
1421{ 1424{
1422 unsigned long flags; 1425 unsigned long flags;
1423 1426
@@ -1443,7 +1446,7 @@ static void mgslpc_program_hw(MGSLPC_INFO *info)
1443 port_irq_enable(info, (unsigned char) PVR_DSR | PVR_RI); 1446 port_irq_enable(info, (unsigned char) PVR_DSR | PVR_RI);
1444 get_signals(info); 1447 get_signals(info);
1445 1448
1446 if (info->netcount || info->tty->termios->c_cflag & CREAD) 1449 if (info->netcount || (tty && (tty->termios->c_cflag & CREAD)))
1447 rx_start(info); 1450 rx_start(info);
1448 1451
1449 spin_unlock_irqrestore(&info->lock,flags); 1452 spin_unlock_irqrestore(&info->lock,flags);
@@ -1451,19 +1454,19 @@ static void mgslpc_program_hw(MGSLPC_INFO *info)
1451 1454
1452/* Reconfigure adapter based on new parameters 1455/* Reconfigure adapter based on new parameters
1453 */ 1456 */
1454static void mgslpc_change_params(MGSLPC_INFO *info) 1457static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty)
1455{ 1458{
1456 unsigned cflag; 1459 unsigned cflag;
1457 int bits_per_char; 1460 int bits_per_char;
1458 1461
1459 if (!info->tty || !info->tty->termios) 1462 if (!tty || !tty->termios)
1460 return; 1463 return;
1461 1464
1462 if (debug_level >= DEBUG_LEVEL_INFO) 1465 if (debug_level >= DEBUG_LEVEL_INFO)
1463 printk("%s(%d):mgslpc_change_params(%s)\n", 1466 printk("%s(%d):mgslpc_change_params(%s)\n",
1464 __FILE__,__LINE__, info->device_name ); 1467 __FILE__,__LINE__, info->device_name );
1465 1468
1466 cflag = info->tty->termios->c_cflag; 1469 cflag = tty->termios->c_cflag;
1467 1470
1468 /* if B0 rate (hangup) specified then negate DTR and RTS */ 1471 /* if B0 rate (hangup) specified then negate DTR and RTS */
1469 /* otherwise assert DTR and RTS */ 1472 /* otherwise assert DTR and RTS */
@@ -1510,7 +1513,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
1510 * current data rate. 1513 * current data rate.
1511 */ 1514 */
1512 if (info->params.data_rate <= 460800) { 1515 if (info->params.data_rate <= 460800) {
1513 info->params.data_rate = tty_get_baud_rate(info->tty); 1516 info->params.data_rate = tty_get_baud_rate(tty);
1514 } 1517 }
1515 1518
1516 if ( info->params.data_rate ) { 1519 if ( info->params.data_rate ) {
@@ -1520,24 +1523,24 @@ static void mgslpc_change_params(MGSLPC_INFO *info)
1520 info->timeout += HZ/50; /* Add .02 seconds of slop */ 1523 info->timeout += HZ/50; /* Add .02 seconds of slop */
1521 1524
1522 if (cflag & CRTSCTS) 1525 if (cflag & CRTSCTS)
1523 info->flags |= ASYNC_CTS_FLOW; 1526 info->port.flags |= ASYNC_CTS_FLOW;
1524 else 1527 else
1525 info->flags &= ~ASYNC_CTS_FLOW; 1528 info->port.flags &= ~ASYNC_CTS_FLOW;
1526 1529
1527 if (cflag & CLOCAL) 1530 if (cflag & CLOCAL)
1528 info->flags &= ~ASYNC_CHECK_CD; 1531 info->port.flags &= ~ASYNC_CHECK_CD;
1529 else 1532 else
1530 info->flags |= ASYNC_CHECK_CD; 1533 info->port.flags |= ASYNC_CHECK_CD;
1531 1534
1532 /* process tty input control flags */ 1535 /* process tty input control flags */
1533 1536
1534 info->read_status_mask = 0; 1537 info->read_status_mask = 0;
1535 if (I_INPCK(info->tty)) 1538 if (I_INPCK(tty))
1536 info->read_status_mask |= BIT7 | BIT6; 1539 info->read_status_mask |= BIT7 | BIT6;
1537 if (I_IGNPAR(info->tty)) 1540 if (I_IGNPAR(tty))
1538 info->ignore_status_mask |= BIT7 | BIT6; 1541 info->ignore_status_mask |= BIT7 | BIT6;
1539 1542
1540 mgslpc_program_hw(info); 1543 mgslpc_program_hw(info, tty);
1541} 1544}
1542 1545
1543/* Add a character to the transmit buffer 1546/* Add a character to the transmit buffer
@@ -1597,7 +1600,7 @@ static void mgslpc_flush_chars(struct tty_struct *tty)
1597 1600
1598 spin_lock_irqsave(&info->lock,flags); 1601 spin_lock_irqsave(&info->lock,flags);
1599 if (!info->tx_active) 1602 if (!info->tx_active)
1600 tx_start(info); 1603 tx_start(info, tty);
1601 spin_unlock_irqrestore(&info->lock,flags); 1604 spin_unlock_irqrestore(&info->lock,flags);
1602} 1605}
1603 1606
@@ -1659,7 +1662,7 @@ start:
1659 if (info->tx_count && !tty->stopped && !tty->hw_stopped) { 1662 if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
1660 spin_lock_irqsave(&info->lock,flags); 1663 spin_lock_irqsave(&info->lock,flags);
1661 if (!info->tx_active) 1664 if (!info->tx_active)
1662 tx_start(info); 1665 tx_start(info, tty);
1663 spin_unlock_irqrestore(&info->lock,flags); 1666 spin_unlock_irqrestore(&info->lock,flags);
1664 } 1667 }
1665cleanup: 1668cleanup:
@@ -1764,7 +1767,7 @@ static void mgslpc_send_xchar(struct tty_struct *tty, char ch)
1764 if (ch) { 1767 if (ch) {
1765 spin_lock_irqsave(&info->lock,flags); 1768 spin_lock_irqsave(&info->lock,flags);
1766 if (!info->tx_enabled) 1769 if (!info->tx_enabled)
1767 tx_start(info); 1770 tx_start(info, tty);
1768 spin_unlock_irqrestore(&info->lock,flags); 1771 spin_unlock_irqrestore(&info->lock,flags);
1769 } 1772 }
1770} 1773}
@@ -1862,7 +1865,7 @@ static int get_params(MGSLPC_INFO * info, MGSL_PARAMS __user *user_params)
1862 * 1865 *
1863 * Returns: 0 if success, otherwise error code 1866 * Returns: 0 if success, otherwise error code
1864 */ 1867 */
1865static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params) 1868static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, struct tty_struct *tty)
1866{ 1869{
1867 unsigned long flags; 1870 unsigned long flags;
1868 MGSL_PARAMS tmp_params; 1871 MGSL_PARAMS tmp_params;
@@ -1883,7 +1886,7 @@ static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params)
1883 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS)); 1886 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
1884 spin_unlock_irqrestore(&info->lock,flags); 1887 spin_unlock_irqrestore(&info->lock,flags);
1885 1888
1886 mgslpc_change_params(info); 1889 mgslpc_change_params(info, tty);
1887 1890
1888 return 0; 1891 return 0;
1889} 1892}
@@ -1944,7 +1947,7 @@ static int set_interface(MGSLPC_INFO * info, int if_mode)
1944 return 0; 1947 return 0;
1945} 1948}
1946 1949
1947static int set_txenable(MGSLPC_INFO * info, int enable) 1950static int set_txenable(MGSLPC_INFO * info, int enable, struct tty_struct *tty)
1948{ 1951{
1949 unsigned long flags; 1952 unsigned long flags;
1950 1953
@@ -1954,7 +1957,7 @@ static int set_txenable(MGSLPC_INFO * info, int enable)
1954 spin_lock_irqsave(&info->lock,flags); 1957 spin_lock_irqsave(&info->lock,flags);
1955 if (enable) { 1958 if (enable) {
1956 if (!info->tx_enabled) 1959 if (!info->tx_enabled)
1957 tx_start(info); 1960 tx_start(info, tty);
1958 } else { 1961 } else {
1959 if (info->tx_enabled) 1962 if (info->tx_enabled)
1960 tx_stop(info); 1963 tx_stop(info);
@@ -2263,6 +2266,11 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
2263 unsigned int cmd, unsigned long arg) 2266 unsigned int cmd, unsigned long arg)
2264{ 2267{
2265 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; 2268 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
2269 int error;
2270 struct mgsl_icount cnow; /* kernel counter temps */
2271 struct serial_icounter_struct __user *p_cuser; /* user space */
2272 void __user *argp = (void __user *)arg;
2273 unsigned long flags;
2266 2274
2267 if (debug_level >= DEBUG_LEVEL_INFO) 2275 if (debug_level >= DEBUG_LEVEL_INFO)
2268 printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__, 2276 printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
@@ -2277,22 +2285,11 @@ static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
2277 return -EIO; 2285 return -EIO;
2278 } 2286 }
2279 2287
2280 return ioctl_common(info, cmd, arg);
2281}
2282
2283static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
2284{
2285 int error;
2286 struct mgsl_icount cnow; /* kernel counter temps */
2287 struct serial_icounter_struct __user *p_cuser; /* user space */
2288 void __user *argp = (void __user *)arg;
2289 unsigned long flags;
2290
2291 switch (cmd) { 2288 switch (cmd) {
2292 case MGSL_IOCGPARAMS: 2289 case MGSL_IOCGPARAMS:
2293 return get_params(info, argp); 2290 return get_params(info, argp);
2294 case MGSL_IOCSPARAMS: 2291 case MGSL_IOCSPARAMS:
2295 return set_params(info, argp); 2292 return set_params(info, argp, tty);
2296 case MGSL_IOCGTXIDLE: 2293 case MGSL_IOCGTXIDLE:
2297 return get_txidle(info, argp); 2294 return get_txidle(info, argp);
2298 case MGSL_IOCSTXIDLE: 2295 case MGSL_IOCSTXIDLE:
@@ -2302,7 +2299,7 @@ static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
2302 case MGSL_IOCSIF: 2299 case MGSL_IOCSIF:
2303 return set_interface(info,(int)arg); 2300 return set_interface(info,(int)arg);
2304 case MGSL_IOCTXENABLE: 2301 case MGSL_IOCTXENABLE:
2305 return set_txenable(info,(int)arg); 2302 return set_txenable(info,(int)arg, tty);
2306 case MGSL_IOCRXENABLE: 2303 case MGSL_IOCRXENABLE:
2307 return set_rxenable(info,(int)arg); 2304 return set_rxenable(info,(int)arg);
2308 case MGSL_IOCTXABORT: 2305 case MGSL_IOCTXABORT:
@@ -2369,7 +2366,7 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_term
2369 == RELEVANT_IFLAG(old_termios->c_iflag))) 2366 == RELEVANT_IFLAG(old_termios->c_iflag)))
2370 return; 2367 return;
2371 2368
2372 mgslpc_change_params(info); 2369 mgslpc_change_params(info, tty);
2373 2370
2374 /* Handle transition to B0 status */ 2371 /* Handle transition to B0 status */
2375 if (old_termios->c_cflag & CBAUD && 2372 if (old_termios->c_cflag & CBAUD &&
@@ -2404,81 +2401,34 @@ static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_term
2404static void mgslpc_close(struct tty_struct *tty, struct file * filp) 2401static void mgslpc_close(struct tty_struct *tty, struct file * filp)
2405{ 2402{
2406 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data; 2403 MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
2404 struct tty_port *port = &info->port;
2407 2405
2408 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_close")) 2406 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_close"))
2409 return; 2407 return;
2410 2408
2411 if (debug_level >= DEBUG_LEVEL_INFO) 2409 if (debug_level >= DEBUG_LEVEL_INFO)
2412 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n", 2410 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
2413 __FILE__,__LINE__, info->device_name, info->count); 2411 __FILE__,__LINE__, info->device_name, port->count);
2414
2415 if (!info->count)
2416 return;
2417 2412
2418 if (tty_hung_up_p(filp)) 2413 WARN_ON(!port->count);
2419 goto cleanup;
2420
2421 if ((tty->count == 1) && (info->count != 1)) {
2422 /*
2423 * tty->count is 1 and the tty structure will be freed.
2424 * info->count should be one in this case.
2425 * if it's not, correct it so that the port is shutdown.
2426 */
2427 printk("mgslpc_close: bad refcount; tty->count is 1, "
2428 "info->count is %d\n", info->count);
2429 info->count = 1;
2430 }
2431 2414
2432 info->count--; 2415 if (tty_port_close_start(port, tty, filp) == 0)
2433
2434 /* if at least one open remaining, leave hardware active */
2435 if (info->count)
2436 goto cleanup; 2416 goto cleanup;
2437 2417
2438 info->flags |= ASYNC_CLOSING; 2418 if (port->flags & ASYNC_INITIALIZED)
2439
2440 /* set tty->closing to notify line discipline to
2441 * only process XON/XOFF characters. Only the N_TTY
2442 * discipline appears to use this (ppp does not).
2443 */
2444 tty->closing = 1;
2445
2446 /* wait for transmit data to clear all layers */
2447
2448 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
2449 if (debug_level >= DEBUG_LEVEL_INFO)
2450 printk("%s(%d):mgslpc_close(%s) calling tty_wait_until_sent\n",
2451 __FILE__,__LINE__, info->device_name );
2452 tty_wait_until_sent(tty, info->closing_wait);
2453 }
2454
2455 if (info->flags & ASYNC_INITIALIZED)
2456 mgslpc_wait_until_sent(tty, info->timeout); 2419 mgslpc_wait_until_sent(tty, info->timeout);
2457 2420
2458 mgslpc_flush_buffer(tty); 2421 mgslpc_flush_buffer(tty);
2459 2422
2460 tty_ldisc_flush(tty); 2423 tty_ldisc_flush(tty);
2461 2424 shutdown(info, tty);
2462 shutdown(info); 2425
2463 2426 tty_port_close_end(port, tty);
2464 tty->closing = 0; 2427 tty_port_tty_set(port, NULL);
2465 info->tty = NULL;
2466
2467 if (info->blocked_open) {
2468 if (info->close_delay) {
2469 msleep_interruptible(jiffies_to_msecs(info->close_delay));
2470 }
2471 wake_up_interruptible(&info->open_wait);
2472 }
2473
2474 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
2475
2476 wake_up_interruptible(&info->close_wait);
2477
2478cleanup: 2428cleanup:
2479 if (debug_level >= DEBUG_LEVEL_INFO) 2429 if (debug_level >= DEBUG_LEVEL_INFO)
2480 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__, 2430 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
2481 tty->driver->name, info->count); 2431 tty->driver->name, port->count);
2482} 2432}
2483 2433
2484/* Wait until the transmitter is empty. 2434/* Wait until the transmitter is empty.
@@ -2498,7 +2448,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout)
2498 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent")) 2448 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent"))
2499 return; 2449 return;
2500 2450
2501 if (!(info->flags & ASYNC_INITIALIZED)) 2451 if (!(info->port.flags & ASYNC_INITIALIZED))
2502 goto exit; 2452 goto exit;
2503 2453
2504 orig_jiffies = jiffies; 2454 orig_jiffies = jiffies;
@@ -2559,120 +2509,40 @@ static void mgslpc_hangup(struct tty_struct *tty)
2559 return; 2509 return;
2560 2510
2561 mgslpc_flush_buffer(tty); 2511 mgslpc_flush_buffer(tty);
2562 shutdown(info); 2512 shutdown(info, tty);
2563 2513 tty_port_hangup(&info->port);
2564 info->count = 0;
2565 info->flags &= ~ASYNC_NORMAL_ACTIVE;
2566 info->tty = NULL;
2567
2568 wake_up_interruptible(&info->open_wait);
2569} 2514}
2570 2515
2571/* Block the current process until the specified port 2516static int carrier_raised(struct tty_port *port)
2572 * is ready to be opened.
2573 */
2574static int block_til_ready(struct tty_struct *tty, struct file *filp,
2575 MGSLPC_INFO *info)
2576{ 2517{
2577 DECLARE_WAITQUEUE(wait, current); 2518 MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
2578 int retval; 2519 unsigned long flags;
2579 bool do_clocal = false;
2580 bool extra_count = false;
2581 unsigned long flags;
2582
2583 if (debug_level >= DEBUG_LEVEL_INFO)
2584 printk("%s(%d):block_til_ready on %s\n",
2585 __FILE__,__LINE__, tty->driver->name );
2586
2587 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
2588 /* nonblock mode is set or port is not enabled */
2589 /* just verify that callout device is not active */
2590 info->flags |= ASYNC_NORMAL_ACTIVE;
2591 return 0;
2592 }
2593
2594 if (tty->termios->c_cflag & CLOCAL)
2595 do_clocal = true;
2596
2597 /* Wait for carrier detect and the line to become
2598 * free (i.e., not in use by the callout). While we are in
2599 * this loop, info->count is dropped by one, so that
2600 * mgslpc_close() knows when to free things. We restore it upon
2601 * exit, either normal or abnormal.
2602 */
2603
2604 retval = 0;
2605 add_wait_queue(&info->open_wait, &wait);
2606
2607 if (debug_level >= DEBUG_LEVEL_INFO)
2608 printk("%s(%d):block_til_ready before block on %s count=%d\n",
2609 __FILE__,__LINE__, tty->driver->name, info->count );
2610
2611 spin_lock_irqsave(&info->lock, flags);
2612 if (!tty_hung_up_p(filp)) {
2613 extra_count = true;
2614 info->count--;
2615 }
2616 spin_unlock_irqrestore(&info->lock, flags);
2617 info->blocked_open++;
2618
2619 while (1) {
2620 if ((tty->termios->c_cflag & CBAUD)) {
2621 spin_lock_irqsave(&info->lock,flags);
2622 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
2623 set_signals(info);
2624 spin_unlock_irqrestore(&info->lock,flags);
2625 }
2626
2627 set_current_state(TASK_INTERRUPTIBLE);
2628
2629 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
2630 retval = (info->flags & ASYNC_HUP_NOTIFY) ?
2631 -EAGAIN : -ERESTARTSYS;
2632 break;
2633 }
2634
2635 spin_lock_irqsave(&info->lock,flags);
2636 get_signals(info);
2637 spin_unlock_irqrestore(&info->lock,flags);
2638
2639 if (!(info->flags & ASYNC_CLOSING) &&
2640 (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
2641 break;
2642 }
2643
2644 if (signal_pending(current)) {
2645 retval = -ERESTARTSYS;
2646 break;
2647 }
2648
2649 if (debug_level >= DEBUG_LEVEL_INFO)
2650 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
2651 __FILE__,__LINE__, tty->driver->name, info->count );
2652
2653 schedule();
2654 }
2655
2656 set_current_state(TASK_RUNNING);
2657 remove_wait_queue(&info->open_wait, &wait);
2658 2520
2659 if (extra_count) 2521 spin_lock_irqsave(&info->lock,flags);
2660 info->count++; 2522 get_signals(info);
2661 info->blocked_open--; 2523 spin_unlock_irqrestore(&info->lock,flags);
2662 2524
2663 if (debug_level >= DEBUG_LEVEL_INFO) 2525 if (info->serial_signals & SerialSignal_DCD)
2664 printk("%s(%d):block_til_ready after blocking on %s count=%d\n", 2526 return 1;
2665 __FILE__,__LINE__, tty->driver->name, info->count ); 2527 return 0;
2528}
2666 2529
2667 if (!retval) 2530static void raise_dtr_rts(struct tty_port *port)
2668 info->flags |= ASYNC_NORMAL_ACTIVE; 2531{
2532 MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
2533 unsigned long flags;
2669 2534
2670 return retval; 2535 spin_lock_irqsave(&info->lock,flags);
2536 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
2537 set_signals(info);
2538 spin_unlock_irqrestore(&info->lock,flags);
2671} 2539}
2672 2540
2541
2673static int mgslpc_open(struct tty_struct *tty, struct file * filp) 2542static int mgslpc_open(struct tty_struct *tty, struct file * filp)
2674{ 2543{
2675 MGSLPC_INFO *info; 2544 MGSLPC_INFO *info;
2545 struct tty_port *port;
2676 int retval, line; 2546 int retval, line;
2677 unsigned long flags; 2547 unsigned long flags;
2678 2548
@@ -2691,23 +2561,24 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
2691 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_open")) 2561 if (mgslpc_paranoia_check(info, tty->name, "mgslpc_open"))
2692 return -ENODEV; 2562 return -ENODEV;
2693 2563
2564 port = &info->port;
2694 tty->driver_data = info; 2565 tty->driver_data = info;
2695 info->tty = tty; 2566 tty_port_tty_set(port, tty);
2696 2567
2697 if (debug_level >= DEBUG_LEVEL_INFO) 2568 if (debug_level >= DEBUG_LEVEL_INFO)
2698 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n", 2569 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
2699 __FILE__,__LINE__,tty->driver->name, info->count); 2570 __FILE__,__LINE__,tty->driver->name, port->count);
2700 2571
2701 /* If port is closing, signal caller to try again */ 2572 /* If port is closing, signal caller to try again */
2702 if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){ 2573 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
2703 if (info->flags & ASYNC_CLOSING) 2574 if (port->flags & ASYNC_CLOSING)
2704 interruptible_sleep_on(&info->close_wait); 2575 interruptible_sleep_on(&port->close_wait);
2705 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2576 retval = ((port->flags & ASYNC_HUP_NOTIFY) ?
2706 -EAGAIN : -ERESTARTSYS); 2577 -EAGAIN : -ERESTARTSYS);
2707 goto cleanup; 2578 goto cleanup;
2708 } 2579 }
2709 2580
2710 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 2581 tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2711 2582
2712 spin_lock_irqsave(&info->netlock, flags); 2583 spin_lock_irqsave(&info->netlock, flags);
2713 if (info->netcount) { 2584 if (info->netcount) {
@@ -2715,17 +2586,19 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
2715 spin_unlock_irqrestore(&info->netlock, flags); 2586 spin_unlock_irqrestore(&info->netlock, flags);
2716 goto cleanup; 2587 goto cleanup;
2717 } 2588 }
2718 info->count++; 2589 spin_lock(&port->lock);
2590 port->count++;
2591 spin_unlock(&port->lock);
2719 spin_unlock_irqrestore(&info->netlock, flags); 2592 spin_unlock_irqrestore(&info->netlock, flags);
2720 2593
2721 if (info->count == 1) { 2594 if (port->count == 1) {
2722 /* 1st open on this device, init hardware */ 2595 /* 1st open on this device, init hardware */
2723 retval = startup(info); 2596 retval = startup(info, tty);
2724 if (retval < 0) 2597 if (retval < 0)
2725 goto cleanup; 2598 goto cleanup;
2726 } 2599 }
2727 2600
2728 retval = block_til_ready(tty, filp, info); 2601 retval = tty_port_block_til_ready(&info->port, tty, filp);
2729 if (retval) { 2602 if (retval) {
2730 if (debug_level >= DEBUG_LEVEL_INFO) 2603 if (debug_level >= DEBUG_LEVEL_INFO)
2731 printk("%s(%d):block_til_ready(%s) returned %d\n", 2604 printk("%s(%d):block_til_ready(%s) returned %d\n",
@@ -2739,13 +2612,6 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
2739 retval = 0; 2612 retval = 0;
2740 2613
2741cleanup: 2614cleanup:
2742 if (retval) {
2743 if (tty->count == 1)
2744 info->tty = NULL; /* tty layer will release tty struct */
2745 if(info->count)
2746 info->count--;
2747 }
2748
2749 return retval; 2615 return retval;
2750} 2616}
2751 2617
@@ -3500,7 +3366,7 @@ static void rx_start(MGSLPC_INFO *info)
3500 info->rx_enabled = true; 3366 info->rx_enabled = true;
3501} 3367}
3502 3368
3503static void tx_start(MGSLPC_INFO *info) 3369static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty)
3504{ 3370{
3505 if (debug_level >= DEBUG_LEVEL_ISR) 3371 if (debug_level >= DEBUG_LEVEL_ISR)
3506 printk("%s(%d):tx_start(%s)\n", 3372 printk("%s(%d):tx_start(%s)\n",
@@ -3524,11 +3390,11 @@ static void tx_start(MGSLPC_INFO *info)
3524 if (info->params.mode == MGSL_MODE_ASYNC) { 3390 if (info->params.mode == MGSL_MODE_ASYNC) {
3525 if (!info->tx_active) { 3391 if (!info->tx_active) {
3526 info->tx_active = true; 3392 info->tx_active = true;
3527 tx_ready(info); 3393 tx_ready(info, tty);
3528 } 3394 }
3529 } else { 3395 } else {
3530 info->tx_active = true; 3396 info->tx_active = true;
3531 tx_ready(info); 3397 tx_ready(info, tty);
3532 mod_timer(&info->tx_timer, jiffies + 3398 mod_timer(&info->tx_timer, jiffies +
3533 msecs_to_jiffies(5000)); 3399 msecs_to_jiffies(5000));
3534 } 3400 }
@@ -3849,13 +3715,12 @@ static void rx_reset_buffers(MGSLPC_INFO *info)
3849 * 3715 *
3850 * Returns true if frame returned, otherwise false 3716 * Returns true if frame returned, otherwise false
3851 */ 3717 */
3852static bool rx_get_frame(MGSLPC_INFO *info) 3718static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty)
3853{ 3719{
3854 unsigned short status; 3720 unsigned short status;
3855 RXBUF *buf; 3721 RXBUF *buf;
3856 unsigned int framesize = 0; 3722 unsigned int framesize = 0;
3857 unsigned long flags; 3723 unsigned long flags;
3858 struct tty_struct *tty = info->tty;
3859 bool return_frame = false; 3724 bool return_frame = false;
3860 3725
3861 if (info->rx_frame_count == 0) 3726 if (info->rx_frame_count == 0)
@@ -4075,7 +3940,11 @@ static void tx_timeout(unsigned long context)
4075 hdlcdev_tx_done(info); 3940 hdlcdev_tx_done(info);
4076 else 3941 else
4077#endif 3942#endif
4078 bh_transmit(info); 3943 {
3944 struct tty_struct *tty = tty_port_tty_get(&info->port);
3945 bh_transmit(info, tty);
3946 tty_kref_put(tty);
3947 }
4079} 3948}
4080 3949
4081#if SYNCLINK_GENERIC_HDLC 3950#if SYNCLINK_GENERIC_HDLC
@@ -4094,11 +3963,12 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
4094 unsigned short parity) 3963 unsigned short parity)
4095{ 3964{
4096 MGSLPC_INFO *info = dev_to_port(dev); 3965 MGSLPC_INFO *info = dev_to_port(dev);
3966 struct tty_struct *tty;
4097 unsigned char new_encoding; 3967 unsigned char new_encoding;
4098 unsigned short new_crctype; 3968 unsigned short new_crctype;
4099 3969
4100 /* return error if TTY interface open */ 3970 /* return error if TTY interface open */
4101 if (info->count) 3971 if (info->port.count)
4102 return -EBUSY; 3972 return -EBUSY;
4103 3973
4104 switch (encoding) 3974 switch (encoding)
@@ -4123,8 +3993,11 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
4123 info->params.crc_type = new_crctype; 3993 info->params.crc_type = new_crctype;
4124 3994
4125 /* if network interface up, reprogram hardware */ 3995 /* if network interface up, reprogram hardware */
4126 if (info->netcount) 3996 if (info->netcount) {
4127 mgslpc_program_hw(info); 3997 tty = tty_port_tty_get(&info->port);
3998 mgslpc_program_hw(info, tty);
3999 tty_kref_put(tty);
4000 }
4128 4001
4129 return 0; 4002 return 0;
4130} 4003}
@@ -4165,8 +4038,11 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
4165 4038
4166 /* start hardware transmitter if necessary */ 4039 /* start hardware transmitter if necessary */
4167 spin_lock_irqsave(&info->lock,flags); 4040 spin_lock_irqsave(&info->lock,flags);
4168 if (!info->tx_active) 4041 if (!info->tx_active) {
4169 tx_start(info); 4042 struct tty_struct *tty = tty_port_tty_get(&info->port);
4043 tx_start(info, tty);
4044 tty_kref_put(tty);
4045 }
4170 spin_unlock_irqrestore(&info->lock,flags); 4046 spin_unlock_irqrestore(&info->lock,flags);
4171 4047
4172 return 0; 4048 return 0;
@@ -4183,6 +4059,7 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
4183static int hdlcdev_open(struct net_device *dev) 4059static int hdlcdev_open(struct net_device *dev)
4184{ 4060{
4185 MGSLPC_INFO *info = dev_to_port(dev); 4061 MGSLPC_INFO *info = dev_to_port(dev);
4062 struct tty_struct *tty;
4186 int rc; 4063 int rc;
4187 unsigned long flags; 4064 unsigned long flags;
4188 4065
@@ -4195,7 +4072,7 @@ static int hdlcdev_open(struct net_device *dev)
4195 4072
4196 /* arbitrate between network and tty opens */ 4073 /* arbitrate between network and tty opens */
4197 spin_lock_irqsave(&info->netlock, flags); 4074 spin_lock_irqsave(&info->netlock, flags);
4198 if (info->count != 0 || info->netcount != 0) { 4075 if (info->port.count != 0 || info->netcount != 0) {
4199 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name); 4076 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
4200 spin_unlock_irqrestore(&info->netlock, flags); 4077 spin_unlock_irqrestore(&info->netlock, flags);
4201 return -EBUSY; 4078 return -EBUSY;
@@ -4203,17 +4080,19 @@ static int hdlcdev_open(struct net_device *dev)
4203 info->netcount=1; 4080 info->netcount=1;
4204 spin_unlock_irqrestore(&info->netlock, flags); 4081 spin_unlock_irqrestore(&info->netlock, flags);
4205 4082
4083 tty = tty_port_tty_get(&info->port);
4206 /* claim resources and init adapter */ 4084 /* claim resources and init adapter */
4207 if ((rc = startup(info)) != 0) { 4085 if ((rc = startup(info, tty)) != 0) {
4086 tty_kref_put(tty);
4208 spin_lock_irqsave(&info->netlock, flags); 4087 spin_lock_irqsave(&info->netlock, flags);
4209 info->netcount=0; 4088 info->netcount=0;
4210 spin_unlock_irqrestore(&info->netlock, flags); 4089 spin_unlock_irqrestore(&info->netlock, flags);
4211 return rc; 4090 return rc;
4212 } 4091 }
4213
4214 /* assert DTR and RTS, apply hardware settings */ 4092 /* assert DTR and RTS, apply hardware settings */
4215 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 4093 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
4216 mgslpc_program_hw(info); 4094 mgslpc_program_hw(info, tty);
4095 tty_kref_put(tty);
4217 4096
4218 /* enable network layer transmit */ 4097 /* enable network layer transmit */
4219 dev->trans_start = jiffies; 4098 dev->trans_start = jiffies;
@@ -4241,6 +4120,7 @@ static int hdlcdev_open(struct net_device *dev)
4241static int hdlcdev_close(struct net_device *dev) 4120static int hdlcdev_close(struct net_device *dev)
4242{ 4121{
4243 MGSLPC_INFO *info = dev_to_port(dev); 4122 MGSLPC_INFO *info = dev_to_port(dev);
4123 struct tty_struct *tty = tty_port_tty_get(&info->port);
4244 unsigned long flags; 4124 unsigned long flags;
4245 4125
4246 if (debug_level >= DEBUG_LEVEL_INFO) 4126 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -4249,8 +4129,8 @@ static int hdlcdev_close(struct net_device *dev)
4249 netif_stop_queue(dev); 4129 netif_stop_queue(dev);
4250 4130
4251 /* shutdown adapter and release resources */ 4131 /* shutdown adapter and release resources */
4252 shutdown(info); 4132 shutdown(info, tty);
4253 4133 tty_kref_put(tty);
4254 hdlc_close(dev); 4134 hdlc_close(dev);
4255 4135
4256 spin_lock_irqsave(&info->netlock, flags); 4136 spin_lock_irqsave(&info->netlock, flags);
@@ -4281,7 +4161,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4281 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name); 4161 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
4282 4162
4283 /* return error if TTY interface open */ 4163 /* return error if TTY interface open */
4284 if (info->count) 4164 if (info->port.count)
4285 return -EBUSY; 4165 return -EBUSY;
4286 4166
4287 if (cmd != SIOCWANDEV) 4167 if (cmd != SIOCWANDEV)
@@ -4354,8 +4234,11 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4354 info->params.clock_speed = 0; 4234 info->params.clock_speed = 0;
4355 4235
4356 /* if network interface up, reprogram hardware */ 4236 /* if network interface up, reprogram hardware */
4357 if (info->netcount) 4237 if (info->netcount) {
4358 mgslpc_program_hw(info); 4238 struct tty_struct *tty = tty_port_tty_get(&info->port);
4239 mgslpc_program_hw(info, tty);
4240 tty_kref_put(tty);
4241 }
4359 return 0; 4242 return 0;
4360 4243
4361 default: 4244 default:
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 6d4582712b1f..112a6ba9a96f 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -5,8 +5,6 @@
5 * 5 *
6 * Added support for a Unix98-style ptmx device. 6 * Added support for a Unix98-style ptmx device.
7 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998 7 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998
8 * Added TTY_DO_WRITE_WAKEUP to enable n_tty to send POLL_OUT to
9 * waiting writers -- Sapan Bhatia <sapan@corewars.org>
10 * 8 *
11 * When reading this code see also fs/devpts. In particular note that the 9 * When reading this code see also fs/devpts. In particular note that the
12 * driver_data field is used by the devpts side as a binding to the devpts 10 * driver_data field is used by the devpts side as a binding to the devpts
@@ -217,7 +215,6 @@ static int pty_open(struct tty_struct *tty, struct file *filp)
217 215
218 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags); 216 clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
219 set_bit(TTY_THROTTLED, &tty->flags); 217 set_bit(TTY_THROTTLED, &tty->flags);
220 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
221 retval = 0; 218 retval = 0;
222out: 219out:
223 return retval; 220 return retval;
@@ -230,6 +227,55 @@ static void pty_set_termios(struct tty_struct *tty,
230 tty->termios->c_cflag |= (CS8 | CREAD); 227 tty->termios->c_cflag |= (CS8 | CREAD);
231} 228}
232 229
230/**
231 * pty_do_resize - resize event
232 * @tty: tty being resized
233 * @real_tty: real tty (not the same as tty if using a pty/tty pair)
234 * @rows: rows (character)
235 * @cols: cols (character)
236 *
237 * Update the termios variables and send the neccessary signals to
238 * peform a terminal resize correctly
239 */
240
241int pty_resize(struct tty_struct *tty, struct winsize *ws)
242{
243 struct pid *pgrp, *rpgrp;
244 unsigned long flags;
245 struct tty_struct *pty = tty->link;
246
247 /* For a PTY we need to lock the tty side */
248 mutex_lock(&tty->termios_mutex);
249 if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
250 goto done;
251
252 /* Get the PID values and reference them so we can
253 avoid holding the tty ctrl lock while sending signals.
254 We need to lock these individually however. */
255
256 spin_lock_irqsave(&tty->ctrl_lock, flags);
257 pgrp = get_pid(tty->pgrp);
258 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
259
260 spin_lock_irqsave(&pty->ctrl_lock, flags);
261 rpgrp = get_pid(pty->pgrp);
262 spin_unlock_irqrestore(&pty->ctrl_lock, flags);
263
264 if (pgrp)
265 kill_pgrp(pgrp, SIGWINCH, 1);
266 if (rpgrp != pgrp && rpgrp)
267 kill_pgrp(rpgrp, SIGWINCH, 1);
268
269 put_pid(pgrp);
270 put_pid(rpgrp);
271
272 tty->winsize = *ws;
273 pty->winsize = *ws; /* Never used so will go away soon */
274done:
275 mutex_unlock(&tty->termios_mutex);
276 return 0;
277}
278
233static int pty_install(struct tty_driver *driver, struct tty_struct *tty) 279static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
234{ 280{
235 struct tty_struct *o_tty; 281 struct tty_struct *o_tty;
@@ -290,6 +336,7 @@ static const struct tty_operations pty_ops = {
290 .chars_in_buffer = pty_chars_in_buffer, 336 .chars_in_buffer = pty_chars_in_buffer,
291 .unthrottle = pty_unthrottle, 337 .unthrottle = pty_unthrottle,
292 .set_termios = pty_set_termios, 338 .set_termios = pty_set_termios,
339 .resize = pty_resize
293}; 340};
294 341
295/* Traditional BSD devices */ 342/* Traditional BSD devices */
@@ -319,6 +366,7 @@ static const struct tty_operations pty_ops_bsd = {
319 .unthrottle = pty_unthrottle, 366 .unthrottle = pty_unthrottle,
320 .set_termios = pty_set_termios, 367 .set_termios = pty_set_termios,
321 .ioctl = pty_bsd_ioctl, 368 .ioctl = pty_bsd_ioctl,
369 .resize = pty_resize
322}; 370};
323 371
324static void __init legacy_pty_init(void) 372static void __init legacy_pty_init(void)
@@ -561,7 +609,8 @@ static const struct tty_operations ptm_unix98_ops = {
561 .unthrottle = pty_unthrottle, 609 .unthrottle = pty_unthrottle,
562 .set_termios = pty_set_termios, 610 .set_termios = pty_set_termios,
563 .ioctl = pty_unix98_ioctl, 611 .ioctl = pty_unix98_ioctl,
564 .shutdown = pty_unix98_shutdown 612 .shutdown = pty_unix98_shutdown,
613 .resize = pty_resize
565}; 614};
566 615
567static const struct tty_operations pty_unix98_ops = { 616static const struct tty_operations pty_unix98_ops = {
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index a8f68a3f14dd..2e8a6eed34be 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -173,7 +173,7 @@ static void rio_disable_tx_interrupts(void *ptr);
173static void rio_enable_tx_interrupts(void *ptr); 173static void rio_enable_tx_interrupts(void *ptr);
174static void rio_disable_rx_interrupts(void *ptr); 174static void rio_disable_rx_interrupts(void *ptr);
175static void rio_enable_rx_interrupts(void *ptr); 175static void rio_enable_rx_interrupts(void *ptr);
176static int rio_get_CD(void *ptr); 176static int rio_carrier_raised(struct tty_port *port);
177static void rio_shutdown_port(void *ptr); 177static void rio_shutdown_port(void *ptr);
178static int rio_set_real_termios(void *ptr); 178static int rio_set_real_termios(void *ptr);
179static void rio_hungup(void *ptr); 179static void rio_hungup(void *ptr);
@@ -224,7 +224,6 @@ static struct real_driver rio_real_driver = {
224 rio_enable_tx_interrupts, 224 rio_enable_tx_interrupts,
225 rio_disable_rx_interrupts, 225 rio_disable_rx_interrupts,
226 rio_enable_rx_interrupts, 226 rio_enable_rx_interrupts,
227 rio_get_CD,
228 rio_shutdown_port, 227 rio_shutdown_port,
229 rio_set_real_termios, 228 rio_set_real_termios,
230 rio_chars_in_buffer, 229 rio_chars_in_buffer,
@@ -476,9 +475,9 @@ static void rio_enable_rx_interrupts(void *ptr)
476 475
477 476
478/* Jeez. Isn't this simple? */ 477/* Jeez. Isn't this simple? */
479static int rio_get_CD(void *ptr) 478static int rio_carrier_raised(struct tty_port *port)
480{ 479{
481 struct Port *PortP = ptr; 480 struct Port *PortP = container_of(port, struct Port, gs.port);
482 int rv; 481 int rv;
483 482
484 func_enter(); 483 func_enter();
@@ -797,16 +796,9 @@ static int rio_init_drivers(void)
797 return 1; 796 return 1;
798} 797}
799 798
800 799static const struct tty_port_operations rio_port_ops = {
801static void *ckmalloc(int size) 800 .carrier_raised = rio_carrier_raised,
802{ 801};
803 void *p;
804
805 p = kzalloc(size, GFP_KERNEL);
806 return p;
807}
808
809
810 802
811static int rio_init_datastructures(void) 803static int rio_init_datastructures(void)
812{ 804{
@@ -826,33 +818,30 @@ static int rio_init_datastructures(void)
826#define TMIO_SZ sizeof(struct termios *) 818#define TMIO_SZ sizeof(struct termios *)
827 rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ); 819 rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
828 820
829 if (!(p = ckmalloc(RI_SZ))) 821 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
830 goto free0; 822 goto free0;
831 if (!(p->RIOHosts = ckmalloc(RIO_HOSTS * HOST_SZ))) 823 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
832 goto free1; 824 goto free1;
833 if (!(p->RIOPortp = ckmalloc(RIO_PORTS * PORT_SZ))) 825 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
834 goto free2; 826 goto free2;
835 p->RIOConf = RIOConf; 827 p->RIOConf = RIOConf;
836 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp); 828 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
837 829
838#if 1 830#if 1
839 for (i = 0; i < RIO_PORTS; i++) { 831 for (i = 0; i < RIO_PORTS; i++) {
840 port = p->RIOPortp[i] = ckmalloc(sizeof(struct Port)); 832 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
841 if (!port) { 833 if (!port) {
842 goto free6; 834 goto free6;
843 } 835 }
844 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped); 836 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
837 tty_port_init(&port->gs.port);
838 port->gs.port.ops = &rio_port_ops;
845 port->PortNum = i; 839 port->PortNum = i;
846 port->gs.magic = RIO_MAGIC; 840 port->gs.magic = RIO_MAGIC;
847 port->gs.close_delay = HZ / 2; 841 port->gs.close_delay = HZ / 2;
848 port->gs.closing_wait = 30 * HZ; 842 port->gs.closing_wait = 30 * HZ;
849 port->gs.rd = &rio_real_driver; 843 port->gs.rd = &rio_real_driver;
850 spin_lock_init(&port->portSem); 844 spin_lock_init(&port->portSem);
851 /*
852 * Initializing wait queue
853 */
854 init_waitqueue_head(&port->gs.port.open_wait);
855 init_waitqueue_head(&port->gs.port.close_wait);
856 } 845 }
857#else 846#else
858 /* We could postpone initializing them to when they are configured. */ 847 /* We could postpone initializing them to when they are configured. */
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 2c6c8f33d6b4..9af8d74875bc 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -857,98 +857,21 @@ static void rc_shutdown_port(struct tty_struct *tty,
857 rc_shutdown_board(bp); 857 rc_shutdown_board(bp);
858} 858}
859 859
860static int block_til_ready(struct tty_struct *tty, struct file *filp, 860static int carrier_raised(struct tty_port *port)
861 struct riscom_port *port)
862{ 861{
863 DECLARE_WAITQUEUE(wait, current); 862 struct riscom_port *p = container_of(port, struct riscom_port, port);
864 struct riscom_board *bp = port_Board(port); 863 struct riscom_board *bp = port_Board(p);
865 int retval;
866 int do_clocal = 0;
867 int CD;
868 unsigned long flags; 864 unsigned long flags;
869 865 int CD;
870 /* 866
871 * If the device is in the middle of being closed, then block
872 * until it's done, and then try again.
873 */
874 if (tty_hung_up_p(filp) || port->port.flags & ASYNC_CLOSING) {
875 interruptible_sleep_on(&port->port.close_wait);
876 if (port->port.flags & ASYNC_HUP_NOTIFY)
877 return -EAGAIN;
878 else
879 return -ERESTARTSYS;
880 }
881
882 /*
883 * If non-blocking mode is set, or the port is not enabled,
884 * then make the check up front and then exit.
885 */
886 if ((filp->f_flags & O_NONBLOCK) ||
887 (tty->flags & (1 << TTY_IO_ERROR))) {
888 port->port.flags |= ASYNC_NORMAL_ACTIVE;
889 return 0;
890 }
891
892 if (C_CLOCAL(tty))
893 do_clocal = 1;
894
895 /*
896 * Block waiting for the carrier detect and the line to become
897 * free (i.e., not in use by the callout). While we are in
898 * this loop, info->count is dropped by one, so that
899 * rs_close() knows when to free things. We restore it upon
900 * exit, either normal or abnormal.
901 */
902 retval = 0;
903 add_wait_queue(&port->port.open_wait, &wait);
904
905 spin_lock_irqsave(&riscom_lock, flags); 867 spin_lock_irqsave(&riscom_lock, flags);
906 868 rc_out(bp, CD180_CAR, port_No(p));
907 if (!tty_hung_up_p(filp)) 869 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
908 port->port.count--; 870 rc_out(bp, CD180_MSVR, MSVR_RTS);
909 871 bp->DTR &= ~(1u << port_No(p));
872 rc_out(bp, RC_DTR, bp->DTR);
910 spin_unlock_irqrestore(&riscom_lock, flags); 873 spin_unlock_irqrestore(&riscom_lock, flags);
911 874 return CD;
912 port->port.blocked_open++;
913 while (1) {
914 spin_lock_irqsave(&riscom_lock, flags);
915
916 rc_out(bp, CD180_CAR, port_No(port));
917 CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
918 rc_out(bp, CD180_MSVR, MSVR_RTS);
919 bp->DTR &= ~(1u << port_No(port));
920 rc_out(bp, RC_DTR, bp->DTR);
921
922 spin_unlock_irqrestore(&riscom_lock, flags);
923
924 set_current_state(TASK_INTERRUPTIBLE);
925 if (tty_hung_up_p(filp) ||
926 !(port->port.flags & ASYNC_INITIALIZED)) {
927 if (port->port.flags & ASYNC_HUP_NOTIFY)
928 retval = -EAGAIN;
929 else
930 retval = -ERESTARTSYS;
931 break;
932 }
933 if (!(port->port.flags & ASYNC_CLOSING) &&
934 (do_clocal || CD))
935 break;
936 if (signal_pending(current)) {
937 retval = -ERESTARTSYS;
938 break;
939 }
940 schedule();
941 }
942 __set_current_state(TASK_RUNNING);
943 remove_wait_queue(&port->port.open_wait, &wait);
944 if (!tty_hung_up_p(filp))
945 port->port.count++;
946 port->port.blocked_open--;
947 if (retval)
948 return retval;
949
950 port->port.flags |= ASYNC_NORMAL_ACTIVE;
951 return 0;
952} 875}
953 876
954static int rc_open(struct tty_struct *tty, struct file *filp) 877static int rc_open(struct tty_struct *tty, struct file *filp)
@@ -977,13 +900,13 @@ static int rc_open(struct tty_struct *tty, struct file *filp)
977 900
978 error = rc_setup_port(bp, port); 901 error = rc_setup_port(bp, port);
979 if (error == 0) 902 if (error == 0)
980 error = block_til_ready(tty, filp, port); 903 error = tty_port_block_til_ready(&port->port, tty, filp);
981 return error; 904 return error;
982} 905}
983 906
984static void rc_flush_buffer(struct tty_struct *tty) 907static void rc_flush_buffer(struct tty_struct *tty)
985{ 908{
986 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 909 struct riscom_port *port = tty->driver_data;
987 unsigned long flags; 910 unsigned long flags;
988 911
989 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer")) 912 if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
@@ -998,7 +921,7 @@ static void rc_flush_buffer(struct tty_struct *tty)
998 921
999static void rc_close(struct tty_struct *tty, struct file *filp) 922static void rc_close(struct tty_struct *tty, struct file *filp)
1000{ 923{
1001 struct riscom_port *port = (struct riscom_port *) tty->driver_data; 924 struct riscom_port *port = tty->driver_data;
1002 struct riscom_board *bp; 925 struct riscom_board *bp;
1003 unsigned long flags; 926 unsigned long flags;
1004 unsigned long timeout; 927 unsigned long timeout;
@@ -1006,40 +929,19 @@ static void rc_close(struct tty_struct *tty, struct file *filp)
1006 if (!port || rc_paranoia_check(port, tty->name, "close")) 929 if (!port || rc_paranoia_check(port, tty->name, "close"))
1007 return; 930 return;
1008 931
1009 spin_lock_irqsave(&riscom_lock, flags);
1010
1011 if (tty_hung_up_p(filp))
1012 goto out;
1013
1014 bp = port_Board(port); 932 bp = port_Board(port);
1015 if ((tty->count == 1) && (port->port.count != 1)) { 933
1016 printk(KERN_INFO "rc%d: rc_close: bad port count;" 934 if (tty_port_close_start(&port->port, tty, filp) == 0)
1017 " tty->count is 1, port count is %d\n", 935 return;
1018 board_No(bp), port->port.count); 936
1019 port->port.count = 1;
1020 }
1021 if (--port->port.count < 0) {
1022 printk(KERN_INFO "rc%d: rc_close: bad port count "
1023 "for tty%d: %d\n",
1024 board_No(bp), port_No(port), port->port.count);
1025 port->port.count = 0;
1026 }
1027 if (port->port.count)
1028 goto out;
1029 port->port.flags |= ASYNC_CLOSING;
1030 /*
1031 * Now we wait for the transmit buffer to clear; and we notify
1032 * the line discipline to only process XON/XOFF characters.
1033 */
1034 tty->closing = 1;
1035 if (port->port.closing_wait != ASYNC_CLOSING_WAIT_NONE)
1036 tty_wait_until_sent(tty, port->port.closing_wait);
1037 /* 937 /*
1038 * At this point we stop accepting input. To do this, we 938 * At this point we stop accepting input. To do this, we
1039 * disable the receive line status interrupts, and tell the 939 * disable the receive line status interrupts, and tell the
1040 * interrupt driver to stop checking the data ready bit in the 940 * interrupt driver to stop checking the data ready bit in the
1041 * line status register. 941 * line status register.
1042 */ 942 */
943
944 spin_lock_irqsave(&riscom_lock, flags);
1043 port->IER &= ~IER_RXD; 945 port->IER &= ~IER_RXD;
1044 if (port->port.flags & ASYNC_INITIALIZED) { 946 if (port->port.flags & ASYNC_INITIALIZED) {
1045 port->IER &= ~IER_TXRDY; 947 port->IER &= ~IER_TXRDY;
@@ -1053,33 +955,24 @@ static void rc_close(struct tty_struct *tty, struct file *filp)
1053 */ 955 */
1054 timeout = jiffies + HZ; 956 timeout = jiffies + HZ;
1055 while (port->IER & IER_TXEMPTY) { 957 while (port->IER & IER_TXEMPTY) {
958 spin_unlock_irqrestore(&riscom_lock, flags);
1056 msleep_interruptible(jiffies_to_msecs(port->timeout)); 959 msleep_interruptible(jiffies_to_msecs(port->timeout));
960 spin_lock_irqsave(&riscom_lock, flags);
1057 if (time_after(jiffies, timeout)) 961 if (time_after(jiffies, timeout))
1058 break; 962 break;
1059 } 963 }
1060 } 964 }
1061 rc_shutdown_port(tty, bp, port); 965 rc_shutdown_port(tty, bp, port);
1062 rc_flush_buffer(tty); 966 rc_flush_buffer(tty);
1063 tty_ldisc_flush(tty);
1064
1065 tty->closing = 0;
1066 port->port.tty = NULL;
1067 if (port->port.blocked_open) {
1068 if (port->port.close_delay)
1069 msleep_interruptible(jiffies_to_msecs(port->port.close_delay));
1070 wake_up_interruptible(&port->port.open_wait);
1071 }
1072 port->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1073 wake_up_interruptible(&port->port.close_wait);
1074
1075out:
1076 spin_unlock_irqrestore(&riscom_lock, flags); 967 spin_unlock_irqrestore(&riscom_lock, flags);
968
969 tty_port_close_end(&port->port, tty);
1077} 970}
1078 971
1079static int rc_write(struct tty_struct *tty, 972static int rc_write(struct tty_struct *tty,
1080 const unsigned char *buf, int count) 973 const unsigned char *buf, int count)
1081{ 974{
1082 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 975 struct riscom_port *port = tty->driver_data;
1083 struct riscom_board *bp; 976 struct riscom_board *bp;
1084 int c, total = 0; 977 int c, total = 0;
1085 unsigned long flags; 978 unsigned long flags;
@@ -1122,7 +1015,7 @@ static int rc_write(struct tty_struct *tty,
1122 1015
1123static int rc_put_char(struct tty_struct *tty, unsigned char ch) 1016static int rc_put_char(struct tty_struct *tty, unsigned char ch)
1124{ 1017{
1125 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1018 struct riscom_port *port = tty->driver_data;
1126 unsigned long flags; 1019 unsigned long flags;
1127 int ret = 0; 1020 int ret = 0;
1128 1021
@@ -1146,7 +1039,7 @@ out:
1146 1039
1147static void rc_flush_chars(struct tty_struct *tty) 1040static void rc_flush_chars(struct tty_struct *tty)
1148{ 1041{
1149 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1042 struct riscom_port *port = tty->driver_data;
1150 unsigned long flags; 1043 unsigned long flags;
1151 1044
1152 if (rc_paranoia_check(port, tty->name, "rc_flush_chars")) 1045 if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
@@ -1166,7 +1059,7 @@ static void rc_flush_chars(struct tty_struct *tty)
1166 1059
1167static int rc_write_room(struct tty_struct *tty) 1060static int rc_write_room(struct tty_struct *tty)
1168{ 1061{
1169 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1062 struct riscom_port *port = tty->driver_data;
1170 int ret; 1063 int ret;
1171 1064
1172 if (rc_paranoia_check(port, tty->name, "rc_write_room")) 1065 if (rc_paranoia_check(port, tty->name, "rc_write_room"))
@@ -1180,7 +1073,7 @@ static int rc_write_room(struct tty_struct *tty)
1180 1073
1181static int rc_chars_in_buffer(struct tty_struct *tty) 1074static int rc_chars_in_buffer(struct tty_struct *tty)
1182{ 1075{
1183 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1076 struct riscom_port *port = tty->driver_data;
1184 1077
1185 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer")) 1078 if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
1186 return 0; 1079 return 0;
@@ -1190,7 +1083,7 @@ static int rc_chars_in_buffer(struct tty_struct *tty)
1190 1083
1191static int rc_tiocmget(struct tty_struct *tty, struct file *file) 1084static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1192{ 1085{
1193 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1086 struct riscom_port *port = tty->driver_data;
1194 struct riscom_board *bp; 1087 struct riscom_board *bp;
1195 unsigned char status; 1088 unsigned char status;
1196 unsigned int result; 1089 unsigned int result;
@@ -1220,7 +1113,7 @@ static int rc_tiocmget(struct tty_struct *tty, struct file *file)
1220static int rc_tiocmset(struct tty_struct *tty, struct file *file, 1113static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1221 unsigned int set, unsigned int clear) 1114 unsigned int set, unsigned int clear)
1222{ 1115{
1223 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1116 struct riscom_port *port = tty->driver_data;
1224 unsigned long flags; 1117 unsigned long flags;
1225 struct riscom_board *bp; 1118 struct riscom_board *bp;
1226 1119
@@ -1252,7 +1145,7 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
1252 1145
1253static int rc_send_break(struct tty_struct *tty, int length) 1146static int rc_send_break(struct tty_struct *tty, int length)
1254{ 1147{
1255 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1148 struct riscom_port *port = tty->driver_data;
1256 struct riscom_board *bp = port_Board(port); 1149 struct riscom_board *bp = port_Board(port);
1257 unsigned long flags; 1150 unsigned long flags;
1258 1151
@@ -1345,7 +1238,7 @@ static int rc_get_serial_info(struct riscom_port *port,
1345static int rc_ioctl(struct tty_struct *tty, struct file *filp, 1238static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1346 unsigned int cmd, unsigned long arg) 1239 unsigned int cmd, unsigned long arg)
1347{ 1240{
1348 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1241 struct riscom_port *port = tty->driver_data;
1349 void __user *argp = (void __user *)arg; 1242 void __user *argp = (void __user *)arg;
1350 int retval; 1243 int retval;
1351 1244
@@ -1371,7 +1264,7 @@ static int rc_ioctl(struct tty_struct *tty, struct file *filp,
1371 1264
1372static void rc_throttle(struct tty_struct *tty) 1265static void rc_throttle(struct tty_struct *tty)
1373{ 1266{
1374 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1267 struct riscom_port *port = tty->driver_data;
1375 struct riscom_board *bp; 1268 struct riscom_board *bp;
1376 unsigned long flags; 1269 unsigned long flags;
1377 1270
@@ -1393,7 +1286,7 @@ static void rc_throttle(struct tty_struct *tty)
1393 1286
1394static void rc_unthrottle(struct tty_struct *tty) 1287static void rc_unthrottle(struct tty_struct *tty)
1395{ 1288{
1396 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1289 struct riscom_port *port = tty->driver_data;
1397 struct riscom_board *bp; 1290 struct riscom_board *bp;
1398 unsigned long flags; 1291 unsigned long flags;
1399 1292
@@ -1415,7 +1308,7 @@ static void rc_unthrottle(struct tty_struct *tty)
1415 1308
1416static void rc_stop(struct tty_struct *tty) 1309static void rc_stop(struct tty_struct *tty)
1417{ 1310{
1418 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1311 struct riscom_port *port = tty->driver_data;
1419 struct riscom_board *bp; 1312 struct riscom_board *bp;
1420 unsigned long flags; 1313 unsigned long flags;
1421 1314
@@ -1433,7 +1326,7 @@ static void rc_stop(struct tty_struct *tty)
1433 1326
1434static void rc_start(struct tty_struct *tty) 1327static void rc_start(struct tty_struct *tty)
1435{ 1328{
1436 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1329 struct riscom_port *port = tty->driver_data;
1437 struct riscom_board *bp; 1330 struct riscom_board *bp;
1438 unsigned long flags; 1331 unsigned long flags;
1439 1332
@@ -1454,8 +1347,9 @@ static void rc_start(struct tty_struct *tty)
1454 1347
1455static void rc_hangup(struct tty_struct *tty) 1348static void rc_hangup(struct tty_struct *tty)
1456{ 1349{
1457 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1350 struct riscom_port *port = tty->driver_data;
1458 struct riscom_board *bp; 1351 struct riscom_board *bp;
1352 unsigned long flags;
1459 1353
1460 if (rc_paranoia_check(port, tty->name, "rc_hangup")) 1354 if (rc_paranoia_check(port, tty->name, "rc_hangup"))
1461 return; 1355 return;
@@ -1463,16 +1357,18 @@ static void rc_hangup(struct tty_struct *tty)
1463 bp = port_Board(port); 1357 bp = port_Board(port);
1464 1358
1465 rc_shutdown_port(tty, bp, port); 1359 rc_shutdown_port(tty, bp, port);
1360 spin_lock_irqsave(&port->port.lock, flags);
1466 port->port.count = 0; 1361 port->port.count = 0;
1467 port->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1362 port->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1468 port->port.tty = NULL; 1363 port->port.tty = NULL;
1469 wake_up_interruptible(&port->port.open_wait); 1364 wake_up_interruptible(&port->port.open_wait);
1365 spin_unlock_irqrestore(&port->port.lock, flags);
1470} 1366}
1471 1367
1472static void rc_set_termios(struct tty_struct *tty, 1368static void rc_set_termios(struct tty_struct *tty,
1473 struct ktermios *old_termios) 1369 struct ktermios *old_termios)
1474{ 1370{
1475 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1371 struct riscom_port *port = tty->driver_data;
1476 unsigned long flags; 1372 unsigned long flags;
1477 1373
1478 if (rc_paranoia_check(port, tty->name, "rc_set_termios")) 1374 if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
@@ -1510,6 +1406,11 @@ static const struct tty_operations riscom_ops = {
1510 .break_ctl = rc_send_break, 1406 .break_ctl = rc_send_break,
1511}; 1407};
1512 1408
1409static const struct tty_port_operations riscom_port_ops = {
1410 .carrier_raised = carrier_raised,
1411};
1412
1413
1513static int __init rc_init_drivers(void) 1414static int __init rc_init_drivers(void)
1514{ 1415{
1515 int error; 1416 int error;
@@ -1541,6 +1442,7 @@ static int __init rc_init_drivers(void)
1541 memset(rc_port, 0, sizeof(rc_port)); 1442 memset(rc_port, 0, sizeof(rc_port));
1542 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) { 1443 for (i = 0; i < RC_NPORT * RC_NBOARD; i++) {
1543 tty_port_init(&rc_port[i].port); 1444 tty_port_init(&rc_port[i].port);
1445 rc_port[i].port.ops = &riscom_port_ops;
1544 rc_port[i].magic = RISCOM8_MAGIC; 1446 rc_port[i].magic = RISCOM8_MAGIC;
1545 } 1447 }
1546 return 0; 1448 return 0;
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 584d791e84a6..f59fc5cea067 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -135,6 +135,7 @@ static int rcktpt_type[NUM_BOARDS];
135static int is_PCI[NUM_BOARDS]; 135static int is_PCI[NUM_BOARDS];
136static rocketModel_t rocketModel[NUM_BOARDS]; 136static rocketModel_t rocketModel[NUM_BOARDS];
137static int max_board; 137static int max_board;
138static const struct tty_port_operations rocket_port_ops;
138 139
139/* 140/*
140 * The following arrays define the interrupt bits corresponding to each AIOP. 141 * The following arrays define the interrupt bits corresponding to each AIOP.
@@ -435,15 +436,15 @@ static void rp_do_transmit(struct r_port *info)
435#endif 436#endif
436 if (!info) 437 if (!info)
437 return; 438 return;
438 if (!info->port.tty) { 439 tty = tty_port_tty_get(&info->port);
439 printk(KERN_WARNING "rp: WARNING %s called with " 440
440 "info->port.tty==NULL\n", __func__); 441 if (tty == NULL) {
442 printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__);
441 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 443 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
442 return; 444 return;
443 } 445 }
444 446
445 spin_lock_irqsave(&info->slock, flags); 447 spin_lock_irqsave(&info->slock, flags);
446 tty = info->port.tty;
447 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp); 448 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
448 449
449 /* Loop sending data to FIFO until done or FIFO full */ 450 /* Loop sending data to FIFO until done or FIFO full */
@@ -477,6 +478,7 @@ static void rp_do_transmit(struct r_port *info)
477 } 478 }
478 479
479 spin_unlock_irqrestore(&info->slock, flags); 480 spin_unlock_irqrestore(&info->slock, flags);
481 tty_kref_put(tty);
480 482
481#ifdef ROCKET_DEBUG_INTR 483#ifdef ROCKET_DEBUG_INTR
482 printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head, 484 printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
@@ -498,18 +500,18 @@ static void rp_handle_port(struct r_port *info)
498 if (!info) 500 if (!info)
499 return; 501 return;
500 502
501 if ((info->flags & ROCKET_INITIALIZED) == 0) { 503 if ((info->port.flags & ASYNC_INITIALIZED) == 0) {
502 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " 504 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
503 "info->flags & NOT_INIT\n"); 505 "info->flags & NOT_INIT\n");
504 return; 506 return;
505 } 507 }
506 if (!info->port.tty) { 508 tty = tty_port_tty_get(&info->port);
509 if (!tty) {
507 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " 510 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
508 "info->port.tty==NULL\n"); 511 "tty==NULL\n");
509 return; 512 return;
510 } 513 }
511 cp = &info->channel; 514 cp = &info->channel;
512 tty = info->port.tty;
513 515
514 IntMask = sGetChanIntID(cp) & info->intmask; 516 IntMask = sGetChanIntID(cp) & info->intmask;
515#ifdef ROCKET_DEBUG_INTR 517#ifdef ROCKET_DEBUG_INTR
@@ -541,6 +543,7 @@ static void rp_handle_port(struct r_port *info)
541 printk(KERN_INFO "DSR change...\n"); 543 printk(KERN_INFO "DSR change...\n");
542 } 544 }
543#endif 545#endif
546 tty_kref_put(tty);
544} 547}
545 548
546/* 549/*
@@ -649,9 +652,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
649 info->board = board; 652 info->board = board;
650 info->aiop = aiop; 653 info->aiop = aiop;
651 info->chan = chan; 654 info->chan = chan;
652 info->port.closing_wait = 3000; 655 tty_port_init(&info->port);
653 info->port.close_delay = 50; 656 info->port.ops = &rocket_port_ops;
654 init_waitqueue_head(&info->port.open_wait);
655 init_completion(&info->close_wait); 657 init_completion(&info->close_wait);
656 info->flags &= ~ROCKET_MODE_MASK; 658 info->flags &= ~ROCKET_MODE_MASK;
657 switch (pc104[board][line]) { 659 switch (pc104[board][line]) {
@@ -710,7 +712,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
710 * Configures a rocketport port according to its termio settings. Called from 712 * Configures a rocketport port according to its termio settings. Called from
711 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected. 713 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
712 */ 714 */
713static void configure_r_port(struct r_port *info, 715static void configure_r_port(struct tty_struct *tty, struct r_port *info,
714 struct ktermios *old_termios) 716 struct ktermios *old_termios)
715{ 717{
716 unsigned cflag; 718 unsigned cflag;
@@ -718,7 +720,7 @@ static void configure_r_port(struct r_port *info,
718 unsigned rocketMode; 720 unsigned rocketMode;
719 int bits, baud, divisor; 721 int bits, baud, divisor;
720 CHANNEL_t *cp; 722 CHANNEL_t *cp;
721 struct ktermios *t = info->port.tty->termios; 723 struct ktermios *t = tty->termios;
722 724
723 cp = &info->channel; 725 cp = &info->channel;
724 cflag = t->c_cflag; 726 cflag = t->c_cflag;
@@ -751,7 +753,7 @@ static void configure_r_port(struct r_port *info,
751 } 753 }
752 754
753 /* baud rate */ 755 /* baud rate */
754 baud = tty_get_baud_rate(info->port.tty); 756 baud = tty_get_baud_rate(tty);
755 if (!baud) 757 if (!baud)
756 baud = 9600; 758 baud = 9600;
757 divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1; 759 divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
@@ -769,7 +771,7 @@ static void configure_r_port(struct r_port *info,
769 sSetBaud(cp, divisor); 771 sSetBaud(cp, divisor);
770 772
771 /* FIXME: Should really back compute a baud rate from the divisor */ 773 /* FIXME: Should really back compute a baud rate from the divisor */
772 tty_encode_baud_rate(info->port.tty, baud, baud); 774 tty_encode_baud_rate(tty, baud, baud);
773 775
774 if (cflag & CRTSCTS) { 776 if (cflag & CRTSCTS) {
775 info->intmask |= DELTA_CTS; 777 info->intmask |= DELTA_CTS;
@@ -794,15 +796,15 @@ static void configure_r_port(struct r_port *info,
794 * Handle software flow control in the board 796 * Handle software flow control in the board
795 */ 797 */
796#ifdef ROCKET_SOFT_FLOW 798#ifdef ROCKET_SOFT_FLOW
797 if (I_IXON(info->port.tty)) { 799 if (I_IXON(tty)) {
798 sEnTxSoftFlowCtl(cp); 800 sEnTxSoftFlowCtl(cp);
799 if (I_IXANY(info->port.tty)) { 801 if (I_IXANY(tty)) {
800 sEnIXANY(cp); 802 sEnIXANY(cp);
801 } else { 803 } else {
802 sDisIXANY(cp); 804 sDisIXANY(cp);
803 } 805 }
804 sSetTxXONChar(cp, START_CHAR(info->port.tty)); 806 sSetTxXONChar(cp, START_CHAR(tty));
805 sSetTxXOFFChar(cp, STOP_CHAR(info->port.tty)); 807 sSetTxXOFFChar(cp, STOP_CHAR(tty));
806 } else { 808 } else {
807 sDisTxSoftFlowCtl(cp); 809 sDisTxSoftFlowCtl(cp);
808 sDisIXANY(cp); 810 sDisIXANY(cp);
@@ -814,24 +816,24 @@ static void configure_r_port(struct r_port *info,
814 * Set up ignore/read mask words 816 * Set up ignore/read mask words
815 */ 817 */
816 info->read_status_mask = STMRCVROVRH | 0xFF; 818 info->read_status_mask = STMRCVROVRH | 0xFF;
817 if (I_INPCK(info->port.tty)) 819 if (I_INPCK(tty))
818 info->read_status_mask |= STMFRAMEH | STMPARITYH; 820 info->read_status_mask |= STMFRAMEH | STMPARITYH;
819 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) 821 if (I_BRKINT(tty) || I_PARMRK(tty))
820 info->read_status_mask |= STMBREAKH; 822 info->read_status_mask |= STMBREAKH;
821 823
822 /* 824 /*
823 * Characters to ignore 825 * Characters to ignore
824 */ 826 */
825 info->ignore_status_mask = 0; 827 info->ignore_status_mask = 0;
826 if (I_IGNPAR(info->port.tty)) 828 if (I_IGNPAR(tty))
827 info->ignore_status_mask |= STMFRAMEH | STMPARITYH; 829 info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
828 if (I_IGNBRK(info->port.tty)) { 830 if (I_IGNBRK(tty)) {
829 info->ignore_status_mask |= STMBREAKH; 831 info->ignore_status_mask |= STMBREAKH;
830 /* 832 /*
831 * If we're ignoring parity and break indicators, 833 * If we're ignoring parity and break indicators,
832 * ignore overruns too. (For real raw support). 834 * ignore overruns too. (For real raw support).
833 */ 835 */
834 if (I_IGNPAR(info->port.tty)) 836 if (I_IGNPAR(tty))
835 info->ignore_status_mask |= STMRCVROVRH; 837 info->ignore_status_mask |= STMRCVROVRH;
836 } 838 }
837 839
@@ -864,106 +866,17 @@ static void configure_r_port(struct r_port *info,
864 } 866 }
865} 867}
866 868
867/* info->port.count is considered critical, protected by spinlocks. */ 869static int carrier_raised(struct tty_port *port)
868static int block_til_ready(struct tty_struct *tty, struct file *filp,
869 struct r_port *info)
870{ 870{
871 DECLARE_WAITQUEUE(wait, current); 871 struct r_port *info = container_of(port, struct r_port, port);
872 int retval; 872 return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
873 int do_clocal = 0, extra_count = 0; 873}
874 unsigned long flags;
875
876 /*
877 * If the device is in the middle of being closed, then block
878 * until it's done, and then try again.
879 */
880 if (tty_hung_up_p(filp))
881 return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
882 if (info->flags & ROCKET_CLOSING) {
883 if (wait_for_completion_interruptible(&info->close_wait))
884 return -ERESTARTSYS;
885 return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
886 }
887
888 /*
889 * If non-blocking mode is set, or the port is not enabled,
890 * then make the check up front and then exit.
891 */
892 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
893 info->flags |= ROCKET_NORMAL_ACTIVE;
894 return 0;
895 }
896 if (tty->termios->c_cflag & CLOCAL)
897 do_clocal = 1;
898
899 /*
900 * Block waiting for the carrier detect and the line to become free. While we are in
901 * this loop, info->port.count is dropped by one, so that rp_close() knows when to free things.
902 * We restore it upon exit, either normal or abnormal.
903 */
904 retval = 0;
905 add_wait_queue(&info->port.open_wait, &wait);
906#ifdef ROCKET_DEBUG_OPEN
907 printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, info->port.count);
908#endif
909 spin_lock_irqsave(&info->slock, flags);
910
911#ifdef ROCKET_DISABLE_SIMUSAGE
912 info->flags |= ROCKET_NORMAL_ACTIVE;
913#else
914 if (!tty_hung_up_p(filp)) {
915 extra_count = 1;
916 info->port.count--;
917 }
918#endif
919 info->port.blocked_open++;
920
921 spin_unlock_irqrestore(&info->slock, flags);
922
923 while (1) {
924 if (tty->termios->c_cflag & CBAUD) {
925 sSetDTR(&info->channel);
926 sSetRTS(&info->channel);
927 }
928 set_current_state(TASK_INTERRUPTIBLE);
929 if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) {
930 if (info->flags & ROCKET_HUP_NOTIFY)
931 retval = -EAGAIN;
932 else
933 retval = -ERESTARTSYS;
934 break;
935 }
936 if (!(info->flags & ROCKET_CLOSING) && (do_clocal || (sGetChanStatusLo(&info->channel) & CD_ACT)))
937 break;
938 if (signal_pending(current)) {
939 retval = -ERESTARTSYS;
940 break;
941 }
942#ifdef ROCKET_DEBUG_OPEN
943 printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n",
944 info->line, info->port.count, info->flags);
945#endif
946 schedule(); /* Don't hold spinlock here, will hang PC */
947 }
948 __set_current_state(TASK_RUNNING);
949 remove_wait_queue(&info->port.open_wait, &wait);
950
951 spin_lock_irqsave(&info->slock, flags);
952
953 if (extra_count)
954 info->port.count++;
955 info->port.blocked_open--;
956
957 spin_unlock_irqrestore(&info->slock, flags);
958 874
959#ifdef ROCKET_DEBUG_OPEN 875static void raise_dtr_rts(struct tty_port *port)
960 printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n", 876{
961 info->line, info->port.count); 877 struct r_port *info = container_of(port, struct r_port, port);
962#endif 878 sSetDTR(&info->channel);
963 if (retval) 879 sSetRTS(&info->channel);
964 return retval;
965 info->flags |= ROCKET_NORMAL_ACTIVE;
966 return 0;
967} 880}
968 881
969/* 882/*
@@ -973,24 +886,26 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
973static int rp_open(struct tty_struct *tty, struct file *filp) 886static int rp_open(struct tty_struct *tty, struct file *filp)
974{ 887{
975 struct r_port *info; 888 struct r_port *info;
889 struct tty_port *port;
976 int line = 0, retval; 890 int line = 0, retval;
977 CHANNEL_t *cp; 891 CHANNEL_t *cp;
978 unsigned long page; 892 unsigned long page;
979 893
980 line = tty->index; 894 line = tty->index;
981 if ((line < 0) || (line >= MAX_RP_PORTS) || ((info = rp_table[line]) == NULL)) 895 if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
982 return -ENXIO; 896 return -ENXIO;
983 897 port = &info->port;
898
984 page = __get_free_page(GFP_KERNEL); 899 page = __get_free_page(GFP_KERNEL);
985 if (!page) 900 if (!page)
986 return -ENOMEM; 901 return -ENOMEM;
987 902
988 if (info->flags & ROCKET_CLOSING) { 903 if (port->flags & ASYNC_CLOSING) {
989 retval = wait_for_completion_interruptible(&info->close_wait); 904 retval = wait_for_completion_interruptible(&info->close_wait);
990 free_page(page); 905 free_page(page);
991 if (retval) 906 if (retval)
992 return retval; 907 return retval;
993 return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 908 return ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
994 } 909 }
995 910
996 /* 911 /*
@@ -1002,9 +917,9 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1002 info->xmit_buf = (unsigned char *) page; 917 info->xmit_buf = (unsigned char *) page;
1003 918
1004 tty->driver_data = info; 919 tty->driver_data = info;
1005 info->port.tty = tty; 920 tty_port_tty_set(port, tty);
1006 921
1007 if (info->port.count++ == 0) { 922 if (port->count++ == 0) {
1008 atomic_inc(&rp_num_ports_open); 923 atomic_inc(&rp_num_ports_open);
1009 924
1010#ifdef ROCKET_DEBUG_OPEN 925#ifdef ROCKET_DEBUG_OPEN
@@ -1019,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1019 /* 934 /*
1020 * Info->count is now 1; so it's safe to sleep now. 935 * Info->count is now 1; so it's safe to sleep now.
1021 */ 936 */
1022 if ((info->flags & ROCKET_INITIALIZED) == 0) { 937 if (!test_bit(ASYNC_INITIALIZED, &port->flags)) {
1023 cp = &info->channel; 938 cp = &info->channel;
1024 sSetRxTrigger(cp, TRIG_1); 939 sSetRxTrigger(cp, TRIG_1);
1025 if (sGetChanStatus(cp) & CD_ACT) 940 if (sGetChanStatus(cp) & CD_ACT)
@@ -1043,21 +958,21 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1043 sEnRxFIFO(cp); 958 sEnRxFIFO(cp);
1044 sEnTransmit(cp); 959 sEnTransmit(cp);
1045 960
1046 info->flags |= ROCKET_INITIALIZED; 961 set_bit(ASYNC_INITIALIZED, &info->port.flags);
1047 962
1048 /* 963 /*
1049 * Set up the tty->alt_speed kludge 964 * Set up the tty->alt_speed kludge
1050 */ 965 */
1051 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI) 966 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
1052 info->port.tty->alt_speed = 57600; 967 tty->alt_speed = 57600;
1053 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI) 968 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
1054 info->port.tty->alt_speed = 115200; 969 tty->alt_speed = 115200;
1055 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI) 970 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
1056 info->port.tty->alt_speed = 230400; 971 tty->alt_speed = 230400;
1057 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) 972 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
1058 info->port.tty->alt_speed = 460800; 973 tty->alt_speed = 460800;
1059 974
1060 configure_r_port(info, NULL); 975 configure_r_port(tty, info, NULL);
1061 if (tty->termios->c_cflag & CBAUD) { 976 if (tty->termios->c_cflag & CBAUD) {
1062 sSetDTR(cp); 977 sSetDTR(cp);
1063 sSetRTS(cp); 978 sSetRTS(cp);
@@ -1066,7 +981,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1066 /* Starts (or resets) the maint polling loop */ 981 /* Starts (or resets) the maint polling loop */
1067 mod_timer(&rocket_timer, jiffies + POLL_PERIOD); 982 mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
1068 983
1069 retval = block_til_ready(tty, filp, info); 984 retval = tty_port_block_til_ready(port, tty, filp);
1070 if (retval) { 985 if (retval) {
1071#ifdef ROCKET_DEBUG_OPEN 986#ifdef ROCKET_DEBUG_OPEN
1072 printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval); 987 printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval);
@@ -1081,8 +996,8 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1081 */ 996 */
1082static void rp_close(struct tty_struct *tty, struct file *filp) 997static void rp_close(struct tty_struct *tty, struct file *filp)
1083{ 998{
1084 struct r_port *info = (struct r_port *) tty->driver_data; 999 struct r_port *info = tty->driver_data;
1085 unsigned long flags; 1000 struct tty_port *port = &info->port;
1086 int timeout; 1001 int timeout;
1087 CHANNEL_t *cp; 1002 CHANNEL_t *cp;
1088 1003
@@ -1093,53 +1008,10 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1093 printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count); 1008 printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count);
1094#endif 1009#endif
1095 1010
1096 if (tty_hung_up_p(filp)) 1011 if (tty_port_close_start(port, tty, filp) == 0)
1097 return;
1098 spin_lock_irqsave(&info->slock, flags);
1099
1100 if ((tty->count == 1) && (info->port.count != 1)) {
1101 /*
1102 * Uh, oh. tty->count is 1, which means that the tty
1103 * structure will be freed. Info->count should always
1104 * be one in these conditions. If it's greater than
1105 * one, we've got real problems, since it means the
1106 * serial port won't be shutdown.
1107 */
1108 printk(KERN_WARNING "rp_close: bad serial port count; "
1109 "tty->count is 1, info->port.count is %d\n", info->port.count);
1110 info->port.count = 1;
1111 }
1112 if (--info->port.count < 0) {
1113 printk(KERN_WARNING "rp_close: bad serial port count for "
1114 "ttyR%d: %d\n", info->line, info->port.count);
1115 info->port.count = 0;
1116 }
1117 if (info->port.count) {
1118 spin_unlock_irqrestore(&info->slock, flags);
1119 return; 1012 return;
1120 }
1121 info->flags |= ROCKET_CLOSING;
1122 spin_unlock_irqrestore(&info->slock, flags);
1123 1013
1124 cp = &info->channel; 1014 cp = &info->channel;
1125
1126 /*
1127 * Notify the line discpline to only process XON/XOFF characters
1128 */
1129 tty->closing = 1;
1130
1131 /*
1132 * If transmission was throttled by the application request,
1133 * just flush the xmit buffer.
1134 */
1135 if (tty->flow_stopped)
1136 rp_flush_buffer(tty);
1137
1138 /*
1139 * Wait for the transmit buffer to clear
1140 */
1141 if (info->port.closing_wait != ROCKET_CLOSING_WAIT_NONE)
1142 tty_wait_until_sent(tty, info->port.closing_wait);
1143 /* 1015 /*
1144 * Before we drop DTR, make sure the UART transmitter 1016 * Before we drop DTR, make sure the UART transmitter
1145 * has completely drained; this is especially 1017 * has completely drained; this is especially
@@ -1168,19 +1040,24 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1168 1040
1169 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 1041 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
1170 1042
1171 if (info->port.blocked_open) { 1043 /* We can't yet use tty_port_close_end as the buffer handling in this
1172 if (info->port.close_delay) { 1044 driver is a bit different to the usual */
1173 msleep_interruptible(jiffies_to_msecs(info->port.close_delay)); 1045
1046 if (port->blocked_open) {
1047 if (port->close_delay) {
1048 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1174 } 1049 }
1175 wake_up_interruptible(&info->port.open_wait); 1050 wake_up_interruptible(&port->open_wait);
1176 } else { 1051 } else {
1177 if (info->xmit_buf) { 1052 if (info->xmit_buf) {
1178 free_page((unsigned long) info->xmit_buf); 1053 free_page((unsigned long) info->xmit_buf);
1179 info->xmit_buf = NULL; 1054 info->xmit_buf = NULL;
1180 } 1055 }
1181 } 1056 }
1182 info->flags &= ~(ROCKET_INITIALIZED | ROCKET_CLOSING | ROCKET_NORMAL_ACTIVE); 1057 info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE);
1183 tty->closing = 0; 1058 tty->closing = 0;
1059 tty_port_tty_set(port, NULL);
1060 wake_up_interruptible(&port->close_wait);
1184 complete_all(&info->close_wait); 1061 complete_all(&info->close_wait);
1185 atomic_dec(&rp_num_ports_open); 1062 atomic_dec(&rp_num_ports_open);
1186 1063
@@ -1195,7 +1072,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1195static void rp_set_termios(struct tty_struct *tty, 1072static void rp_set_termios(struct tty_struct *tty,
1196 struct ktermios *old_termios) 1073 struct ktermios *old_termios)
1197{ 1074{
1198 struct r_port *info = (struct r_port *) tty->driver_data; 1075 struct r_port *info = tty->driver_data;
1199 CHANNEL_t *cp; 1076 CHANNEL_t *cp;
1200 unsigned cflag; 1077 unsigned cflag;
1201 1078
@@ -1213,7 +1090,7 @@ static void rp_set_termios(struct tty_struct *tty,
1213 /* Or CMSPAR */ 1090 /* Or CMSPAR */
1214 tty->termios->c_cflag &= ~CMSPAR; 1091 tty->termios->c_cflag &= ~CMSPAR;
1215 1092
1216 configure_r_port(info, old_termios); 1093 configure_r_port(tty, info, old_termios);
1217 1094
1218 cp = &info->channel; 1095 cp = &info->channel;
1219 1096
@@ -1238,7 +1115,7 @@ static void rp_set_termios(struct tty_struct *tty,
1238 1115
1239static int rp_break(struct tty_struct *tty, int break_state) 1116static int rp_break(struct tty_struct *tty, int break_state)
1240{ 1117{
1241 struct r_port *info = (struct r_port *) tty->driver_data; 1118 struct r_port *info = tty->driver_data;
1242 unsigned long flags; 1119 unsigned long flags;
1243 1120
1244 if (rocket_paranoia_check(info, "rp_break")) 1121 if (rocket_paranoia_check(info, "rp_break"))
@@ -1284,7 +1161,7 @@ static int sGetChanRI(CHANNEL_T * ChP)
1284 */ 1161 */
1285static int rp_tiocmget(struct tty_struct *tty, struct file *file) 1162static int rp_tiocmget(struct tty_struct *tty, struct file *file)
1286{ 1163{
1287 struct r_port *info = (struct r_port *)tty->driver_data; 1164 struct r_port *info = tty->driver_data;
1288 unsigned int control, result, ChanStatus; 1165 unsigned int control, result, ChanStatus;
1289 1166
1290 ChanStatus = sGetChanStatusLo(&info->channel); 1167 ChanStatus = sGetChanStatusLo(&info->channel);
@@ -1305,7 +1182,7 @@ static int rp_tiocmget(struct tty_struct *tty, struct file *file)
1305static int rp_tiocmset(struct tty_struct *tty, struct file *file, 1182static int rp_tiocmset(struct tty_struct *tty, struct file *file,
1306 unsigned int set, unsigned int clear) 1183 unsigned int set, unsigned int clear)
1307{ 1184{
1308 struct r_port *info = (struct r_port *)tty->driver_data; 1185 struct r_port *info = tty->driver_data;
1309 1186
1310 if (set & TIOCM_RTS) 1187 if (set & TIOCM_RTS)
1311 info->channel.TxControl[3] |= SET_RTS; 1188 info->channel.TxControl[3] |= SET_RTS;
@@ -1338,7 +1215,8 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
1338 return 0; 1215 return 0;
1339} 1216}
1340 1217
1341static int set_config(struct r_port *info, struct rocket_config __user *new_info) 1218static int set_config(struct tty_struct *tty, struct r_port *info,
1219 struct rocket_config __user *new_info)
1342{ 1220{
1343 struct rocket_config new_serial; 1221 struct rocket_config new_serial;
1344 1222
@@ -1350,7 +1228,7 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
1350 if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK)) 1228 if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
1351 return -EPERM; 1229 return -EPERM;
1352 info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK)); 1230 info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
1353 configure_r_port(info, NULL); 1231 configure_r_port(tty, info, NULL);
1354 return 0; 1232 return 0;
1355 } 1233 }
1356 1234
@@ -1359,15 +1237,15 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
1359 info->port.closing_wait = new_serial.closing_wait; 1237 info->port.closing_wait = new_serial.closing_wait;
1360 1238
1361 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI) 1239 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
1362 info->port.tty->alt_speed = 57600; 1240 tty->alt_speed = 57600;
1363 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI) 1241 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
1364 info->port.tty->alt_speed = 115200; 1242 tty->alt_speed = 115200;
1365 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI) 1243 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
1366 info->port.tty->alt_speed = 230400; 1244 tty->alt_speed = 230400;
1367 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) 1245 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
1368 info->port.tty->alt_speed = 460800; 1246 tty->alt_speed = 460800;
1369 1247
1370 configure_r_port(info, NULL); 1248 configure_r_port(tty, info, NULL);
1371 return 0; 1249 return 0;
1372} 1250}
1373 1251
@@ -1434,7 +1312,7 @@ static int get_version(struct r_port *info, struct rocket_version __user *retver
1434static int rp_ioctl(struct tty_struct *tty, struct file *file, 1312static int rp_ioctl(struct tty_struct *tty, struct file *file,
1435 unsigned int cmd, unsigned long arg) 1313 unsigned int cmd, unsigned long arg)
1436{ 1314{
1437 struct r_port *info = (struct r_port *) tty->driver_data; 1315 struct r_port *info = tty->driver_data;
1438 void __user *argp = (void __user *)arg; 1316 void __user *argp = (void __user *)arg;
1439 int ret = 0; 1317 int ret = 0;
1440 1318
@@ -1452,7 +1330,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1452 ret = get_config(info, argp); 1330 ret = get_config(info, argp);
1453 break; 1331 break;
1454 case RCKP_SET_CONFIG: 1332 case RCKP_SET_CONFIG:
1455 ret = set_config(info, argp); 1333 ret = set_config(tty, info, argp);
1456 break; 1334 break;
1457 case RCKP_GET_PORTS: 1335 case RCKP_GET_PORTS:
1458 ret = get_ports(info, argp); 1336 ret = get_ports(info, argp);
@@ -1472,7 +1350,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1472 1350
1473static void rp_send_xchar(struct tty_struct *tty, char ch) 1351static void rp_send_xchar(struct tty_struct *tty, char ch)
1474{ 1352{
1475 struct r_port *info = (struct r_port *) tty->driver_data; 1353 struct r_port *info = tty->driver_data;
1476 CHANNEL_t *cp; 1354 CHANNEL_t *cp;
1477 1355
1478 if (rocket_paranoia_check(info, "rp_send_xchar")) 1356 if (rocket_paranoia_check(info, "rp_send_xchar"))
@@ -1487,7 +1365,7 @@ static void rp_send_xchar(struct tty_struct *tty, char ch)
1487 1365
1488static void rp_throttle(struct tty_struct *tty) 1366static void rp_throttle(struct tty_struct *tty)
1489{ 1367{
1490 struct r_port *info = (struct r_port *) tty->driver_data; 1368 struct r_port *info = tty->driver_data;
1491 CHANNEL_t *cp; 1369 CHANNEL_t *cp;
1492 1370
1493#ifdef ROCKET_DEBUG_THROTTLE 1371#ifdef ROCKET_DEBUG_THROTTLE
@@ -1507,7 +1385,7 @@ static void rp_throttle(struct tty_struct *tty)
1507 1385
1508static void rp_unthrottle(struct tty_struct *tty) 1386static void rp_unthrottle(struct tty_struct *tty)
1509{ 1387{
1510 struct r_port *info = (struct r_port *) tty->driver_data; 1388 struct r_port *info = tty->driver_data;
1511 CHANNEL_t *cp; 1389 CHANNEL_t *cp;
1512#ifdef ROCKET_DEBUG_THROTTLE 1390#ifdef ROCKET_DEBUG_THROTTLE
1513 printk(KERN_INFO "unthrottle %s: %d....\n", tty->name, 1391 printk(KERN_INFO "unthrottle %s: %d....\n", tty->name,
@@ -1534,7 +1412,7 @@ static void rp_unthrottle(struct tty_struct *tty)
1534 */ 1412 */
1535static void rp_stop(struct tty_struct *tty) 1413static void rp_stop(struct tty_struct *tty)
1536{ 1414{
1537 struct r_port *info = (struct r_port *) tty->driver_data; 1415 struct r_port *info = tty->driver_data;
1538 1416
1539#ifdef ROCKET_DEBUG_FLOW 1417#ifdef ROCKET_DEBUG_FLOW
1540 printk(KERN_INFO "stop %s: %d %d....\n", tty->name, 1418 printk(KERN_INFO "stop %s: %d %d....\n", tty->name,
@@ -1550,7 +1428,7 @@ static void rp_stop(struct tty_struct *tty)
1550 1428
1551static void rp_start(struct tty_struct *tty) 1429static void rp_start(struct tty_struct *tty)
1552{ 1430{
1553 struct r_port *info = (struct r_port *) tty->driver_data; 1431 struct r_port *info = tty->driver_data;
1554 1432
1555#ifdef ROCKET_DEBUG_FLOW 1433#ifdef ROCKET_DEBUG_FLOW
1556 printk(KERN_INFO "start %s: %d %d....\n", tty->name, 1434 printk(KERN_INFO "start %s: %d %d....\n", tty->name,
@@ -1570,7 +1448,7 @@ static void rp_start(struct tty_struct *tty)
1570 */ 1448 */
1571static void rp_wait_until_sent(struct tty_struct *tty, int timeout) 1449static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1572{ 1450{
1573 struct r_port *info = (struct r_port *) tty->driver_data; 1451 struct r_port *info = tty->driver_data;
1574 CHANNEL_t *cp; 1452 CHANNEL_t *cp;
1575 unsigned long orig_jiffies; 1453 unsigned long orig_jiffies;
1576 int check_time, exit_time; 1454 int check_time, exit_time;
@@ -1627,7 +1505,7 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1627static void rp_hangup(struct tty_struct *tty) 1505static void rp_hangup(struct tty_struct *tty)
1628{ 1506{
1629 CHANNEL_t *cp; 1507 CHANNEL_t *cp;
1630 struct r_port *info = (struct r_port *) tty->driver_data; 1508 struct r_port *info = tty->driver_data;
1631 1509
1632 if (rocket_paranoia_check(info, "rp_hangup")) 1510 if (rocket_paranoia_check(info, "rp_hangup"))
1633 return; 1511 return;
@@ -1636,15 +1514,13 @@ static void rp_hangup(struct tty_struct *tty)
1636 printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line); 1514 printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
1637#endif 1515#endif
1638 rp_flush_buffer(tty); 1516 rp_flush_buffer(tty);
1639 if (info->flags & ROCKET_CLOSING) 1517 if (info->port.flags & ASYNC_CLOSING)
1640 return; 1518 return;
1641 if (info->port.count) 1519 if (info->port.count)
1642 atomic_dec(&rp_num_ports_open); 1520 atomic_dec(&rp_num_ports_open);
1643 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 1521 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
1644 1522
1645 info->port.count = 0; 1523 tty_port_hangup(&info->port);
1646 info->flags &= ~ROCKET_NORMAL_ACTIVE;
1647 info->port.tty = NULL;
1648 1524
1649 cp = &info->channel; 1525 cp = &info->channel;
1650 sDisRxFIFO(cp); 1526 sDisRxFIFO(cp);
@@ -1653,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
1653 sDisCTSFlowCtl(cp); 1529 sDisCTSFlowCtl(cp);
1654 sDisTxSoftFlowCtl(cp); 1530 sDisTxSoftFlowCtl(cp);
1655 sClrTxXOFF(cp); 1531 sClrTxXOFF(cp);
1656 info->flags &= ~ROCKET_INITIALIZED; 1532 info->port.flags &= ~ASYNC_INITIALIZED;
1657 1533
1658 wake_up_interruptible(&info->port.open_wait); 1534 wake_up_interruptible(&info->port.open_wait);
1659} 1535}
@@ -1667,7 +1543,7 @@ static void rp_hangup(struct tty_struct *tty)
1667 */ 1543 */
1668static int rp_put_char(struct tty_struct *tty, unsigned char ch) 1544static int rp_put_char(struct tty_struct *tty, unsigned char ch)
1669{ 1545{
1670 struct r_port *info = (struct r_port *) tty->driver_data; 1546 struct r_port *info = tty->driver_data;
1671 CHANNEL_t *cp; 1547 CHANNEL_t *cp;
1672 unsigned long flags; 1548 unsigned long flags;
1673 1549
@@ -1714,7 +1590,7 @@ static int rp_put_char(struct tty_struct *tty, unsigned char ch)
1714static int rp_write(struct tty_struct *tty, 1590static int rp_write(struct tty_struct *tty,
1715 const unsigned char *buf, int count) 1591 const unsigned char *buf, int count)
1716{ 1592{
1717 struct r_port *info = (struct r_port *) tty->driver_data; 1593 struct r_port *info = tty->driver_data;
1718 CHANNEL_t *cp; 1594 CHANNEL_t *cp;
1719 const unsigned char *b; 1595 const unsigned char *b;
1720 int c, retval = 0; 1596 int c, retval = 0;
@@ -1764,7 +1640,8 @@ static int rp_write(struct tty_struct *tty,
1764 1640
1765 /* Write remaining data into the port's xmit_buf */ 1641 /* Write remaining data into the port's xmit_buf */
1766 while (1) { 1642 while (1) {
1767 if (!info->port.tty) /* Seemingly obligatory check... */ 1643 /* Hung up ? */
1644 if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags))
1768 goto end; 1645 goto end;
1769 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); 1646 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
1770 c = min(c, XMIT_BUF_SIZE - info->xmit_head); 1647 c = min(c, XMIT_BUF_SIZE - info->xmit_head);
@@ -1806,7 +1683,7 @@ end:
1806 */ 1683 */
1807static int rp_write_room(struct tty_struct *tty) 1684static int rp_write_room(struct tty_struct *tty)
1808{ 1685{
1809 struct r_port *info = (struct r_port *) tty->driver_data; 1686 struct r_port *info = tty->driver_data;
1810 int ret; 1687 int ret;
1811 1688
1812 if (rocket_paranoia_check(info, "rp_write_room")) 1689 if (rocket_paranoia_check(info, "rp_write_room"))
@@ -1827,7 +1704,7 @@ static int rp_write_room(struct tty_struct *tty)
1827 */ 1704 */
1828static int rp_chars_in_buffer(struct tty_struct *tty) 1705static int rp_chars_in_buffer(struct tty_struct *tty)
1829{ 1706{
1830 struct r_port *info = (struct r_port *) tty->driver_data; 1707 struct r_port *info = tty->driver_data;
1831 CHANNEL_t *cp; 1708 CHANNEL_t *cp;
1832 1709
1833 if (rocket_paranoia_check(info, "rp_chars_in_buffer")) 1710 if (rocket_paranoia_check(info, "rp_chars_in_buffer"))
@@ -1848,7 +1725,7 @@ static int rp_chars_in_buffer(struct tty_struct *tty)
1848 */ 1725 */
1849static void rp_flush_buffer(struct tty_struct *tty) 1726static void rp_flush_buffer(struct tty_struct *tty)
1850{ 1727{
1851 struct r_port *info = (struct r_port *) tty->driver_data; 1728 struct r_port *info = tty->driver_data;
1852 CHANNEL_t *cp; 1729 CHANNEL_t *cp;
1853 unsigned long flags; 1730 unsigned long flags;
1854 1731
@@ -2371,6 +2248,11 @@ static const struct tty_operations rocket_ops = {
2371 .tiocmset = rp_tiocmset, 2248 .tiocmset = rp_tiocmset,
2372}; 2249};
2373 2250
2251static const struct tty_port_operations rocket_port_ops = {
2252 .carrier_raised = carrier_raised,
2253 .raise_dtr_rts = raise_dtr_rts,
2254};
2255
2374/* 2256/*
2375 * The module "startup" routine; it's run when the module is loaded. 2257 * The module "startup" routine; it's run when the module is loaded.
2376 */ 2258 */
diff --git a/drivers/char/rocket.h b/drivers/char/rocket.h
index a8b09195ebba..ec863f35f1a9 100644
--- a/drivers/char/rocket.h
+++ b/drivers/char/rocket.h
@@ -39,7 +39,7 @@ struct rocket_version {
39/* 39/*
40 * Rocketport flags 40 * Rocketport flags
41 */ 41 */
42#define ROCKET_CALLOUT_NOHUP 0x00000001 42/*#define ROCKET_CALLOUT_NOHUP 0x00000001 */
43#define ROCKET_FORCE_CD 0x00000002 43#define ROCKET_FORCE_CD 0x00000002
44#define ROCKET_HUP_NOTIFY 0x00000004 44#define ROCKET_HUP_NOTIFY 0x00000004
45#define ROCKET_SPLIT_TERMIOS 0x00000008 45#define ROCKET_SPLIT_TERMIOS 0x00000008
diff --git a/drivers/char/rocket_int.h b/drivers/char/rocket_int.h
index 21f3ff53ba32..67e0f1e778a2 100644
--- a/drivers/char/rocket_int.h
+++ b/drivers/char/rocket_int.h
@@ -1162,11 +1162,6 @@ struct r_port {
1162/* number of characters left in xmit buffer before we ask for more */ 1162/* number of characters left in xmit buffer before we ask for more */
1163#define WAKEUP_CHARS 256 1163#define WAKEUP_CHARS 256
1164 1164
1165/* Internal flags used only by the rocketport driver */
1166#define ROCKET_INITIALIZED 0x80000000 /* Port is active */
1167#define ROCKET_CLOSING 0x40000000 /* Serial port is closing */
1168#define ROCKET_NORMAL_ACTIVE 0x20000000 /* Normal port is active */
1169
1170/* 1165/*
1171 * Assigned major numbers for the Comtrol Rocketport 1166 * Assigned major numbers for the Comtrol Rocketport
1172 */ 1167 */
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 2978a49a172b..f29fbe9b8ed7 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -306,7 +306,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t
306 */ 306 */
307int paste_selection(struct tty_struct *tty) 307int paste_selection(struct tty_struct *tty)
308{ 308{
309 struct vc_data *vc = (struct vc_data *)tty->driver_data; 309 struct vc_data *vc = tty->driver_data;
310 int pasted = 0; 310 int pasted = 0;
311 unsigned int count; 311 unsigned int count;
312 struct tty_ldisc *ld; 312 struct tty_ldisc *ld;
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index 7b0c35207d9b..33872a219df6 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -122,7 +122,7 @@ static void a2232_disable_tx_interrupts(void *ptr);
122static void a2232_enable_tx_interrupts(void *ptr); 122static void a2232_enable_tx_interrupts(void *ptr);
123static void a2232_disable_rx_interrupts(void *ptr); 123static void a2232_disable_rx_interrupts(void *ptr);
124static void a2232_enable_rx_interrupts(void *ptr); 124static void a2232_enable_rx_interrupts(void *ptr);
125static int a2232_get_CD(void *ptr); 125static int a2232_carrier_raised(struct tty_port *port);
126static void a2232_shutdown_port(void *ptr); 126static void a2232_shutdown_port(void *ptr);
127static int a2232_set_real_termios(void *ptr); 127static int a2232_set_real_termios(void *ptr);
128static int a2232_chars_in_buffer(void *ptr); 128static int a2232_chars_in_buffer(void *ptr);
@@ -148,7 +148,6 @@ static struct real_driver a2232_real_driver = {
148 a2232_enable_tx_interrupts, 148 a2232_enable_tx_interrupts,
149 a2232_disable_rx_interrupts, 149 a2232_disable_rx_interrupts,
150 a2232_enable_rx_interrupts, 150 a2232_enable_rx_interrupts,
151 a2232_get_CD,
152 a2232_shutdown_port, 151 a2232_shutdown_port,
153 a2232_set_real_termios, 152 a2232_set_real_termios,
154 a2232_chars_in_buffer, 153 a2232_chars_in_buffer,
@@ -260,9 +259,10 @@ static void a2232_enable_rx_interrupts(void *ptr)
260 port->disable_rx = 0; 259 port->disable_rx = 0;
261} 260}
262 261
263static int a2232_get_CD(void *ptr) 262static int a2232_carrier_raised(struct tty_port *port)
264{ 263{
265 return ((struct a2232_port *) ptr)->cd_status; 264 struct a2232_port *ap = container_of(port, struct a2232_port, gs.port);
265 return ap->cd_status;
266} 266}
267 267
268static void a2232_shutdown_port(void *ptr) 268static void a2232_shutdown_port(void *ptr)
@@ -460,14 +460,14 @@ static void a2232_throttle(struct tty_struct *tty)
460 if switched on. So the only thing we can do at this 460 if switched on. So the only thing we can do at this
461 layer here is not taking any characters out of the 461 layer here is not taking any characters out of the
462 A2232 buffer any more. */ 462 A2232 buffer any more. */
463 struct a2232_port *port = (struct a2232_port *) tty->driver_data; 463 struct a2232_port *port = tty->driver_data;
464 port->throttle_input = -1; 464 port->throttle_input = -1;
465} 465}
466 466
467static void a2232_unthrottle(struct tty_struct *tty) 467static void a2232_unthrottle(struct tty_struct *tty)
468{ 468{
469/* Unthrottle: dual to "throttle()" above. */ 469/* Unthrottle: dual to "throttle()" above. */
470 struct a2232_port *port = (struct a2232_port *) tty->driver_data; 470 struct a2232_port *port = tty->driver_data;
471 port->throttle_input = 0; 471 port->throttle_input = 0;
472} 472}
473 473
@@ -638,6 +638,10 @@ int ch, err, n, p;
638 return IRQ_HANDLED; 638 return IRQ_HANDLED;
639} 639}
640 640
641static const struct tty_port_operations a2232_port_ops = {
642 .carrier_raised = a2232_carrier_raised,
643};
644
641static void a2232_init_portstructs(void) 645static void a2232_init_portstructs(void)
642{ 646{
643 struct a2232_port *port; 647 struct a2232_port *port;
@@ -645,6 +649,8 @@ static void a2232_init_portstructs(void)
645 649
646 for (i = 0; i < MAX_A2232_BOARDS*NUMLINES; i++) { 650 for (i = 0; i < MAX_A2232_BOARDS*NUMLINES; i++) {
647 port = a2232_ports + i; 651 port = a2232_ports + i;
652 tty_port_init(&port->gs.port);
653 port->gs.port.ops = &a2232_port_ops;
648 port->which_a2232 = i/NUMLINES; 654 port->which_a2232 = i/NUMLINES;
649 port->which_port_on_a2232 = i%NUMLINES; 655 port->which_port_on_a2232 = i%NUMLINES;
650 port->disable_rx = port->throttle_input = port->cd_status = 0; 656 port->disable_rx = port->throttle_input = port->cd_status = 0;
@@ -652,11 +658,6 @@ static void a2232_init_portstructs(void)
652 port->gs.close_delay = HZ/2; 658 port->gs.close_delay = HZ/2;
653 port->gs.closing_wait = 30 * HZ; 659 port->gs.closing_wait = 30 * HZ;
654 port->gs.rd = &a2232_real_driver; 660 port->gs.rd = &a2232_real_driver;
655#ifdef NEW_WRITE_LOCKING
656 mutex_init(&(port->gs.port_write_mutex));
657#endif
658 init_waitqueue_head(&port->gs.port.open_wait);
659 init_waitqueue_head(&port->gs.port.close_wait);
660 } 661 }
661} 662}
662 663
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index a8f15e6be594..f1f24f0ee26f 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -315,7 +315,7 @@ u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd)
315 315
316static void cy_stop(struct tty_struct *tty) 316static void cy_stop(struct tty_struct *tty)
317{ 317{
318 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 318 struct cyclades_port *info = tty->driver_data;
319 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 319 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
320 int channel; 320 int channel;
321 unsigned long flags; 321 unsigned long flags;
@@ -337,7 +337,7 @@ static void cy_stop(struct tty_struct *tty)
337 337
338static void cy_start(struct tty_struct *tty) 338static void cy_start(struct tty_struct *tty)
339{ 339{
340 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 340 struct cyclades_port *info = tty->driver_data;
341 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 341 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
342 int channel; 342 int channel;
343 unsigned long flags; 343 unsigned long flags;
@@ -1062,7 +1062,7 @@ static void config_setup(struct cyclades_port *info)
1062 1062
1063static int cy_put_char(struct tty_struct *tty, unsigned char ch) 1063static int cy_put_char(struct tty_struct *tty, unsigned char ch)
1064{ 1064{
1065 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1065 struct cyclades_port *info = tty->driver_data;
1066 unsigned long flags; 1066 unsigned long flags;
1067 1067
1068#ifdef SERIAL_DEBUG_IO 1068#ifdef SERIAL_DEBUG_IO
@@ -1090,7 +1090,7 @@ static int cy_put_char(struct tty_struct *tty, unsigned char ch)
1090 1090
1091static void cy_flush_chars(struct tty_struct *tty) 1091static void cy_flush_chars(struct tty_struct *tty)
1092{ 1092{
1093 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1093 struct cyclades_port *info = tty->driver_data;
1094 unsigned long flags; 1094 unsigned long flags;
1095 volatile unsigned char *base_addr = (u_char *) BASE_ADDR; 1095 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1096 int channel; 1096 int channel;
@@ -1122,7 +1122,7 @@ static void cy_flush_chars(struct tty_struct *tty)
1122 */ 1122 */
1123static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count) 1123static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
1124{ 1124{
1125 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1125 struct cyclades_port *info = tty->driver_data;
1126 unsigned long flags; 1126 unsigned long flags;
1127 int c, total = 0; 1127 int c, total = 0;
1128 1128
@@ -1166,7 +1166,7 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
1166 1166
1167static int cy_write_room(struct tty_struct *tty) 1167static int cy_write_room(struct tty_struct *tty)
1168{ 1168{
1169 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1169 struct cyclades_port *info = tty->driver_data;
1170 int ret; 1170 int ret;
1171 1171
1172#ifdef SERIAL_DEBUG_IO 1172#ifdef SERIAL_DEBUG_IO
@@ -1183,7 +1183,7 @@ static int cy_write_room(struct tty_struct *tty)
1183 1183
1184static int cy_chars_in_buffer(struct tty_struct *tty) 1184static int cy_chars_in_buffer(struct tty_struct *tty)
1185{ 1185{
1186 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1186 struct cyclades_port *info = tty->driver_data;
1187 1187
1188#ifdef SERIAL_DEBUG_IO 1188#ifdef SERIAL_DEBUG_IO
1189 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */ 1189 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
@@ -1197,7 +1197,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
1197 1197
1198static void cy_flush_buffer(struct tty_struct *tty) 1198static void cy_flush_buffer(struct tty_struct *tty)
1199{ 1199{
1200 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1200 struct cyclades_port *info = tty->driver_data;
1201 unsigned long flags; 1201 unsigned long flags;
1202 1202
1203#ifdef SERIAL_DEBUG_IO 1203#ifdef SERIAL_DEBUG_IO
@@ -1218,7 +1218,7 @@ static void cy_flush_buffer(struct tty_struct *tty)
1218 */ 1218 */
1219static void cy_throttle(struct tty_struct *tty) 1219static void cy_throttle(struct tty_struct *tty)
1220{ 1220{
1221 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1221 struct cyclades_port *info = tty->driver_data;
1222 unsigned long flags; 1222 unsigned long flags;
1223 volatile unsigned char *base_addr = (u_char *) BASE_ADDR; 1223 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1224 int channel; 1224 int channel;
@@ -1250,7 +1250,7 @@ static void cy_throttle(struct tty_struct *tty)
1250 1250
1251static void cy_unthrottle(struct tty_struct *tty) 1251static void cy_unthrottle(struct tty_struct *tty)
1252{ 1252{
1253 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1253 struct cyclades_port *info = tty->driver_data;
1254 unsigned long flags; 1254 unsigned long flags;
1255 volatile unsigned char *base_addr = (u_char *) BASE_ADDR; 1255 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1256 int channel; 1256 int channel;
@@ -1345,7 +1345,7 @@ check_and_exit:
1345 1345
1346static int cy_tiocmget(struct tty_struct *tty, struct file *file) 1346static int cy_tiocmget(struct tty_struct *tty, struct file *file)
1347{ 1347{
1348 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1348 struct cyclades_port *info = tty->driver_data;
1349 int channel; 1349 int channel;
1350 volatile unsigned char *base_addr = (u_char *) BASE_ADDR; 1350 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1351 unsigned long flags; 1351 unsigned long flags;
@@ -1369,7 +1369,7 @@ static int
1369cy_tiocmset(struct tty_struct *tty, struct file *file, 1369cy_tiocmset(struct tty_struct *tty, struct file *file,
1370 unsigned int set, unsigned int clear) 1370 unsigned int set, unsigned int clear)
1371{ 1371{
1372 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1372 struct cyclades_port *info = tty->driver_data;
1373 int channel; 1373 int channel;
1374 volatile unsigned char *base_addr = (u_char *) BASE_ADDR; 1374 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1375 unsigned long flags; 1375 unsigned long flags;
@@ -1532,7 +1532,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1532 unsigned int cmd, unsigned long arg) 1532 unsigned int cmd, unsigned long arg)
1533{ 1533{
1534 unsigned long val; 1534 unsigned long val;
1535 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1535 struct cyclades_port *info = tty->driver_data;
1536 int ret_val = 0; 1536 int ret_val = 0;
1537 void __user *argp = (void __user *)arg; 1537 void __user *argp = (void __user *)arg;
1538 1538
@@ -1607,7 +1607,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
1607 1607
1608static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 1608static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1609{ 1609{
1610 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1610 struct cyclades_port *info = tty->driver_data;
1611 1611
1612#ifdef SERIAL_DEBUG_OTHER 1612#ifdef SERIAL_DEBUG_OTHER
1613 printk("cy_set_termios %s\n", tty->name); 1613 printk("cy_set_termios %s\n", tty->name);
@@ -1631,7 +1631,7 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1631 1631
1632static void cy_close(struct tty_struct *tty, struct file *filp) 1632static void cy_close(struct tty_struct *tty, struct file *filp)
1633{ 1633{
1634 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1634 struct cyclades_port *info = tty->driver_data;
1635 1635
1636/* CP('C'); */ 1636/* CP('C'); */
1637#ifdef SERIAL_DEBUG_OTHER 1637#ifdef SERIAL_DEBUG_OTHER
@@ -1698,7 +1698,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
1698 */ 1698 */
1699void cy_hangup(struct tty_struct *tty) 1699void cy_hangup(struct tty_struct *tty)
1700{ 1700{
1701 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1701 struct cyclades_port *info = tty->driver_data;
1702 1702
1703#ifdef SERIAL_DEBUG_OTHER 1703#ifdef SERIAL_DEBUG_OTHER
1704 printk("cy_hangup %s\n", tty->name); /* */ 1704 printk("cy_hangup %s\n", tty->name); /* */
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index a16b94f12eb2..3c67c3d83de9 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -1450,7 +1450,7 @@ static int sx_open(struct tty_struct *tty, struct file *filp)
1450 1450
1451static void sx_flush_buffer(struct tty_struct *tty) 1451static void sx_flush_buffer(struct tty_struct *tty)
1452{ 1452{
1453 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1453 struct specialix_port *port = tty->driver_data;
1454 unsigned long flags; 1454 unsigned long flags;
1455 struct specialix_board *bp; 1455 struct specialix_board *bp;
1456 1456
@@ -1472,7 +1472,7 @@ static void sx_flush_buffer(struct tty_struct *tty)
1472 1472
1473static void sx_close(struct tty_struct *tty, struct file *filp) 1473static void sx_close(struct tty_struct *tty, struct file *filp)
1474{ 1474{
1475 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1475 struct specialix_port *port = tty->driver_data;
1476 struct specialix_board *bp; 1476 struct specialix_board *bp;
1477 unsigned long flags; 1477 unsigned long flags;
1478 unsigned long timeout; 1478 unsigned long timeout;
@@ -1585,7 +1585,7 @@ static void sx_close(struct tty_struct *tty, struct file *filp)
1585static int sx_write(struct tty_struct *tty, 1585static int sx_write(struct tty_struct *tty,
1586 const unsigned char *buf, int count) 1586 const unsigned char *buf, int count)
1587{ 1587{
1588 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1588 struct specialix_port *port = tty->driver_data;
1589 struct specialix_board *bp; 1589 struct specialix_board *bp;
1590 int c, total = 0; 1590 int c, total = 0;
1591 unsigned long flags; 1591 unsigned long flags;
@@ -1637,7 +1637,7 @@ static int sx_write(struct tty_struct *tty,
1637 1637
1638static int sx_put_char(struct tty_struct *tty, unsigned char ch) 1638static int sx_put_char(struct tty_struct *tty, unsigned char ch)
1639{ 1639{
1640 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1640 struct specialix_port *port = tty->driver_data;
1641 unsigned long flags; 1641 unsigned long flags;
1642 struct specialix_board *bp; 1642 struct specialix_board *bp;
1643 1643
@@ -1676,7 +1676,7 @@ static int sx_put_char(struct tty_struct *tty, unsigned char ch)
1676 1676
1677static void sx_flush_chars(struct tty_struct *tty) 1677static void sx_flush_chars(struct tty_struct *tty)
1678{ 1678{
1679 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1679 struct specialix_port *port = tty->driver_data;
1680 unsigned long flags; 1680 unsigned long flags;
1681 struct specialix_board *bp = port_Board(port); 1681 struct specialix_board *bp = port_Board(port);
1682 1682
@@ -1703,7 +1703,7 @@ static void sx_flush_chars(struct tty_struct *tty)
1703 1703
1704static int sx_write_room(struct tty_struct *tty) 1704static int sx_write_room(struct tty_struct *tty)
1705{ 1705{
1706 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1706 struct specialix_port *port = tty->driver_data;
1707 int ret; 1707 int ret;
1708 1708
1709 func_enter(); 1709 func_enter();
@@ -1724,7 +1724,7 @@ static int sx_write_room(struct tty_struct *tty)
1724 1724
1725static int sx_chars_in_buffer(struct tty_struct *tty) 1725static int sx_chars_in_buffer(struct tty_struct *tty)
1726{ 1726{
1727 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1727 struct specialix_port *port = tty->driver_data;
1728 1728
1729 func_enter(); 1729 func_enter();
1730 1730
@@ -1738,7 +1738,7 @@ static int sx_chars_in_buffer(struct tty_struct *tty)
1738 1738
1739static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1739static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1740{ 1740{
1741 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1741 struct specialix_port *port = tty->driver_data;
1742 struct specialix_board *bp; 1742 struct specialix_board *bp;
1743 unsigned char status; 1743 unsigned char status;
1744 unsigned int result; 1744 unsigned int result;
@@ -1780,7 +1780,7 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1780static int sx_tiocmset(struct tty_struct *tty, struct file *file, 1780static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1781 unsigned int set, unsigned int clear) 1781 unsigned int set, unsigned int clear)
1782{ 1782{
1783 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1783 struct specialix_port *port = tty->driver_data;
1784 unsigned long flags; 1784 unsigned long flags;
1785 struct specialix_board *bp; 1785 struct specialix_board *bp;
1786 1786
@@ -1820,7 +1820,7 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1820 1820
1821static int sx_send_break(struct tty_struct *tty, int length) 1821static int sx_send_break(struct tty_struct *tty, int length)
1822{ 1822{
1823 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1823 struct specialix_port *port = tty->driver_data;
1824 struct specialix_board *bp = port_Board(port); 1824 struct specialix_board *bp = port_Board(port);
1825 unsigned long flags; 1825 unsigned long flags;
1826 1826
@@ -1931,7 +1931,7 @@ static int sx_get_serial_info(struct specialix_port *port,
1931static int sx_ioctl(struct tty_struct *tty, struct file *filp, 1931static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1932 unsigned int cmd, unsigned long arg) 1932 unsigned int cmd, unsigned long arg)
1933{ 1933{
1934 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1934 struct specialix_port *port = tty->driver_data;
1935 void __user *argp = (void __user *)arg; 1935 void __user *argp = (void __user *)arg;
1936 1936
1937 func_enter(); 1937 func_enter();
@@ -1959,7 +1959,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1959 1959
1960static void sx_throttle(struct tty_struct *tty) 1960static void sx_throttle(struct tty_struct *tty)
1961{ 1961{
1962 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 1962 struct specialix_port *port = tty->driver_data;
1963 struct specialix_board *bp; 1963 struct specialix_board *bp;
1964 unsigned long flags; 1964 unsigned long flags;
1965 1965
@@ -2004,7 +2004,7 @@ static void sx_throttle(struct tty_struct *tty)
2004 2004
2005static void sx_unthrottle(struct tty_struct *tty) 2005static void sx_unthrottle(struct tty_struct *tty)
2006{ 2006{
2007 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2007 struct specialix_port *port = tty->driver_data;
2008 struct specialix_board *bp; 2008 struct specialix_board *bp;
2009 unsigned long flags; 2009 unsigned long flags;
2010 2010
@@ -2045,7 +2045,7 @@ static void sx_unthrottle(struct tty_struct *tty)
2045 2045
2046static void sx_stop(struct tty_struct *tty) 2046static void sx_stop(struct tty_struct *tty)
2047{ 2047{
2048 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2048 struct specialix_port *port = tty->driver_data;
2049 struct specialix_board *bp; 2049 struct specialix_board *bp;
2050 unsigned long flags; 2050 unsigned long flags;
2051 2051
@@ -2072,7 +2072,7 @@ static void sx_stop(struct tty_struct *tty)
2072 2072
2073static void sx_start(struct tty_struct *tty) 2073static void sx_start(struct tty_struct *tty)
2074{ 2074{
2075 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2075 struct specialix_port *port = tty->driver_data;
2076 struct specialix_board *bp; 2076 struct specialix_board *bp;
2077 unsigned long flags; 2077 unsigned long flags;
2078 2078
@@ -2100,7 +2100,7 @@ static void sx_start(struct tty_struct *tty)
2100 2100
2101static void sx_hangup(struct tty_struct *tty) 2101static void sx_hangup(struct tty_struct *tty)
2102{ 2102{
2103 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2103 struct specialix_port *port = tty->driver_data;
2104 struct specialix_board *bp; 2104 struct specialix_board *bp;
2105 unsigned long flags; 2105 unsigned long flags;
2106 2106
@@ -2135,7 +2135,7 @@ static void sx_hangup(struct tty_struct *tty)
2135static void sx_set_termios(struct tty_struct *tty, 2135static void sx_set_termios(struct tty_struct *tty,
2136 struct ktermios *old_termios) 2136 struct ktermios *old_termios)
2137{ 2137{
2138 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2138 struct specialix_port *port = tty->driver_data;
2139 unsigned long flags; 2139 unsigned long flags;
2140 struct specialix_board *bp; 2140 struct specialix_board *bp;
2141 2141
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 963b03fb29e5..e1e0dd89ac9a 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -130,6 +130,8 @@ static char stl_unwanted[SC26198_RXFIFOSIZE];
130static DEFINE_MUTEX(stl_brdslock); 130static DEFINE_MUTEX(stl_brdslock);
131static struct stlbrd *stl_brds[STL_MAXBRDS]; 131static struct stlbrd *stl_brds[STL_MAXBRDS];
132 132
133static const struct tty_port_operations stl_port_ops;
134
133/* 135/*
134 * Per board state flags. Used with the state field of the board struct. 136 * Per board state flags. Used with the state field of the board struct.
135 * Not really much here! 137 * Not really much here!
@@ -407,7 +409,6 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
407static int stl_brdinit(struct stlbrd *brdp); 409static int stl_brdinit(struct stlbrd *brdp);
408static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp); 410static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp);
409static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp); 411static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
410static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, struct file *filp);
411 412
412/* 413/*
413 * CD1400 uart specific handling functions. 414 * CD1400 uart specific handling functions.
@@ -703,8 +704,9 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
703{ 704{
704 struct stlport *portp; 705 struct stlport *portp;
705 struct stlbrd *brdp; 706 struct stlbrd *brdp;
707 struct tty_port *port;
706 unsigned int minordev, brdnr, panelnr; 708 unsigned int minordev, brdnr, panelnr;
707 int portnr, rc; 709 int portnr;
708 710
709 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name); 711 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
710 712
@@ -715,6 +717,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
715 brdp = stl_brds[brdnr]; 717 brdp = stl_brds[brdnr];
716 if (brdp == NULL) 718 if (brdp == NULL)
717 return -ENODEV; 719 return -ENODEV;
720
718 minordev = MINOR2PORT(minordev); 721 minordev = MINOR2PORT(minordev);
719 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) { 722 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
720 if (brdp->panels[panelnr] == NULL) 723 if (brdp->panels[panelnr] == NULL)
@@ -731,16 +734,17 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
731 portp = brdp->panels[panelnr]->ports[portnr]; 734 portp = brdp->panels[panelnr]->ports[portnr];
732 if (portp == NULL) 735 if (portp == NULL)
733 return -ENODEV; 736 return -ENODEV;
737 port = &portp->port;
734 738
735/* 739/*
736 * On the first open of the device setup the port hardware, and 740 * On the first open of the device setup the port hardware, and
737 * initialize the per port data structure. 741 * initialize the per port data structure.
738 */ 742 */
739 tty_port_tty_set(&portp->port, tty); 743 tty_port_tty_set(port, tty);
740 tty->driver_data = portp; 744 tty->driver_data = portp;
741 portp->port.count++; 745 port->count++;
742 746
743 if ((portp->port.flags & ASYNC_INITIALIZED) == 0) { 747 if ((port->flags & ASYNC_INITIALIZED) == 0) {
744 if (!portp->tx.buf) { 748 if (!portp->tx.buf) {
745 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL); 749 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
746 if (!portp->tx.buf) 750 if (!portp->tx.buf)
@@ -754,91 +758,24 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
754 stl_enablerxtx(portp, 1, 1); 758 stl_enablerxtx(portp, 1, 1);
755 stl_startrxtx(portp, 1, 0); 759 stl_startrxtx(portp, 1, 0);
756 clear_bit(TTY_IO_ERROR, &tty->flags); 760 clear_bit(TTY_IO_ERROR, &tty->flags);
757 portp->port.flags |= ASYNC_INITIALIZED; 761 port->flags |= ASYNC_INITIALIZED;
758 }
759
760/*
761 * Check if this port is in the middle of closing. If so then wait
762 * until it is closed then return error status, based on flag settings.
763 * The sleep here does not need interrupt protection since the wakeup
764 * for it is done with the same context.
765 */
766 if (portp->port.flags & ASYNC_CLOSING) {
767 interruptible_sleep_on(&portp->port.close_wait);
768 if (portp->port.flags & ASYNC_HUP_NOTIFY)
769 return -EAGAIN;
770 return -ERESTARTSYS;
771 } 762 }
772 763 return tty_port_block_til_ready(port, tty, filp);
773/*
774 * Based on type of open being done check if it can overlap with any
775 * previous opens still in effect. If we are a normal serial device
776 * then also we might have to wait for carrier.
777 */
778 if (!(filp->f_flags & O_NONBLOCK))
779 if ((rc = stl_waitcarrier(tty, portp, filp)) != 0)
780 return rc;
781
782 portp->port.flags |= ASYNC_NORMAL_ACTIVE;
783
784 return 0;
785} 764}
786 765
787/*****************************************************************************/ 766/*****************************************************************************/
788 767
789/* 768static int stl_carrier_raised(struct tty_port *port)
790 * Possibly need to wait for carrier (DCD signal) to come high. Say
791 * maybe because if we are clocal then we don't need to wait...
792 */
793
794static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp,
795 struct file *filp)
796{ 769{
797 unsigned long flags; 770 struct stlport *portp = container_of(port, struct stlport, port);
798 int rc, doclocal; 771 return (portp->sigs & TIOCM_CD) ? 1 : 0;
799 772}
800 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
801
802 rc = 0;
803 doclocal = 0;
804
805 spin_lock_irqsave(&stallion_lock, flags);
806
807 if (tty->termios->c_cflag & CLOCAL)
808 doclocal++;
809
810 portp->openwaitcnt++;
811 if (! tty_hung_up_p(filp))
812 portp->port.count--;
813
814 for (;;) {
815 /* Takes brd_lock internally */
816 stl_setsignals(portp, 1, 1);
817 if (tty_hung_up_p(filp) ||
818 ((portp->port.flags & ASYNC_INITIALIZED) == 0)) {
819 if (portp->port.flags & ASYNC_HUP_NOTIFY)
820 rc = -EBUSY;
821 else
822 rc = -ERESTARTSYS;
823 break;
824 }
825 if (((portp->port.flags & ASYNC_CLOSING) == 0) &&
826 (doclocal || (portp->sigs & TIOCM_CD)))
827 break;
828 if (signal_pending(current)) {
829 rc = -ERESTARTSYS;
830 break;
831 }
832 /* FIXME */
833 interruptible_sleep_on(&portp->port.open_wait);
834 }
835
836 if (! tty_hung_up_p(filp))
837 portp->port.count++;
838 portp->openwaitcnt--;
839 spin_unlock_irqrestore(&stallion_lock, flags);
840 773
841 return rc; 774static void stl_raise_dtr_rts(struct tty_port *port)
775{
776 struct stlport *portp = container_of(port, struct stlport, port);
777 /* Takes brd_lock internally */
778 stl_setsignals(portp, 1, 1);
842} 779}
843 780
844/*****************************************************************************/ 781/*****************************************************************************/
@@ -890,47 +827,29 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
890static void stl_close(struct tty_struct *tty, struct file *filp) 827static void stl_close(struct tty_struct *tty, struct file *filp)
891{ 828{
892 struct stlport *portp; 829 struct stlport *portp;
830 struct tty_port *port;
893 unsigned long flags; 831 unsigned long flags;
894 832
895 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp); 833 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
896 834
897 portp = tty->driver_data; 835 portp = tty->driver_data;
898 if (portp == NULL) 836 BUG_ON(portp == NULL);
899 return;
900 837
901 spin_lock_irqsave(&stallion_lock, flags); 838 port = &portp->port;
902 if (tty_hung_up_p(filp)) {
903 spin_unlock_irqrestore(&stallion_lock, flags);
904 return;
905 }
906 if ((tty->count == 1) && (portp->port.count != 1))
907 portp->port.count = 1;
908 if (portp->port.count-- > 1) {
909 spin_unlock_irqrestore(&stallion_lock, flags);
910 return;
911 }
912
913 portp->port.count = 0;
914 portp->port.flags |= ASYNC_CLOSING;
915 839
840 if (tty_port_close_start(port, tty, filp) == 0)
841 return;
916/* 842/*
917 * May want to wait for any data to drain before closing. The BUSY 843 * May want to wait for any data to drain before closing. The BUSY
918 * flag keeps track of whether we are still sending or not - it is 844 * flag keeps track of whether we are still sending or not - it is
919 * very accurate for the cd1400, not quite so for the sc26198. 845 * very accurate for the cd1400, not quite so for the sc26198.
920 * (The sc26198 has no "end-of-data" interrupt only empty FIFO) 846 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
921 */ 847 */
922 tty->closing = 1;
923
924 spin_unlock_irqrestore(&stallion_lock, flags);
925
926 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
927 tty_wait_until_sent(tty, portp->closing_wait);
928 stl_waituntilsent(tty, (HZ / 2)); 848 stl_waituntilsent(tty, (HZ / 2));
929 849
930 850 spin_lock_irqsave(&port->lock, flags);
931 spin_lock_irqsave(&stallion_lock, flags);
932 portp->port.flags &= ~ASYNC_INITIALIZED; 851 portp->port.flags &= ~ASYNC_INITIALIZED;
933 spin_unlock_irqrestore(&stallion_lock, flags); 852 spin_unlock_irqrestore(&port->lock, flags);
934 853
935 stl_disableintrs(portp); 854 stl_disableintrs(portp);
936 if (tty->termios->c_cflag & HUPCL) 855 if (tty->termios->c_cflag & HUPCL)
@@ -944,20 +863,9 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
944 portp->tx.head = NULL; 863 portp->tx.head = NULL;
945 portp->tx.tail = NULL; 864 portp->tx.tail = NULL;
946 } 865 }
947 set_bit(TTY_IO_ERROR, &tty->flags);
948 tty_ldisc_flush(tty);
949 866
950 tty->closing = 0; 867 tty_port_close_end(port, tty);
951 tty_port_tty_set(&portp->port, NULL); 868 tty_port_tty_set(port, NULL);
952
953 if (portp->openwaitcnt) {
954 if (portp->close_delay)
955 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
956 wake_up_interruptible(&portp->port.open_wait);
957 }
958
959 portp->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
960 wake_up_interruptible(&portp->port.close_wait);
961} 869}
962 870
963/*****************************************************************************/ 871/*****************************************************************************/
@@ -1405,14 +1313,20 @@ static void stl_stop(struct tty_struct *tty)
1405static void stl_hangup(struct tty_struct *tty) 1313static void stl_hangup(struct tty_struct *tty)
1406{ 1314{
1407 struct stlport *portp; 1315 struct stlport *portp;
1316 struct tty_port *port;
1317 unsigned long flags;
1408 1318
1409 pr_debug("stl_hangup(tty=%p)\n", tty); 1319 pr_debug("stl_hangup(tty=%p)\n", tty);
1410 1320
1411 portp = tty->driver_data; 1321 portp = tty->driver_data;
1412 if (portp == NULL) 1322 if (portp == NULL)
1413 return; 1323 return;
1324 port = &portp->port;
1325
1326 spin_lock_irqsave(&port->lock, flags);
1327 port->flags &= ~ASYNC_INITIALIZED;
1328 spin_unlock_irqrestore(&port->lock, flags);
1414 1329
1415 portp->port.flags &= ~ASYNC_INITIALIZED;
1416 stl_disableintrs(portp); 1330 stl_disableintrs(portp);
1417 if (tty->termios->c_cflag & HUPCL) 1331 if (tty->termios->c_cflag & HUPCL)
1418 stl_setsignals(portp, 0, 0); 1332 stl_setsignals(portp, 0, 0);
@@ -1426,10 +1340,7 @@ static void stl_hangup(struct tty_struct *tty)
1426 portp->tx.head = NULL; 1340 portp->tx.head = NULL;
1427 portp->tx.tail = NULL; 1341 portp->tx.tail = NULL;
1428 } 1342 }
1429 tty_port_tty_set(&portp->port, NULL); 1343 tty_port_hangup(port);
1430 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1431 portp->port.count = 0;
1432 wake_up_interruptible(&portp->port.open_wait);
1433} 1344}
1434 1345
1435/*****************************************************************************/ 1346/*****************************************************************************/
@@ -1776,6 +1687,7 @@ static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1776 break; 1687 break;
1777 } 1688 }
1778 tty_port_init(&portp->port); 1689 tty_port_init(&portp->port);
1690 portp->port.ops = &stl_port_ops;
1779 portp->magic = STL_PORTMAGIC; 1691 portp->magic = STL_PORTMAGIC;
1780 portp->portnr = i; 1692 portp->portnr = i;
1781 portp->brdnr = panelp->brdnr; 1693 portp->brdnr = panelp->brdnr;
@@ -2659,6 +2571,11 @@ static const struct tty_operations stl_ops = {
2659 .tiocmset = stl_tiocmset, 2571 .tiocmset = stl_tiocmset,
2660}; 2572};
2661 2573
2574static const struct tty_port_operations stl_port_ops = {
2575 .carrier_raised = stl_carrier_raised,
2576 .raise_dtr_rts = stl_raise_dtr_rts,
2577};
2578
2662/*****************************************************************************/ 2579/*****************************************************************************/
2663/* CD1400 HARDWARE FUNCTIONS */ 2580/* CD1400 HARDWARE FUNCTIONS */
2664/*****************************************************************************/ 2581/*****************************************************************************/
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index ba4e86281fbf..b60be7b0decf 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -279,7 +279,7 @@ static void sx_disable_tx_interrupts(void *ptr);
279static void sx_enable_tx_interrupts(void *ptr); 279static void sx_enable_tx_interrupts(void *ptr);
280static void sx_disable_rx_interrupts(void *ptr); 280static void sx_disable_rx_interrupts(void *ptr);
281static void sx_enable_rx_interrupts(void *ptr); 281static void sx_enable_rx_interrupts(void *ptr);
282static int sx_get_CD(void *ptr); 282static int sx_carrier_raised(struct tty_port *port);
283static void sx_shutdown_port(void *ptr); 283static void sx_shutdown_port(void *ptr);
284static int sx_set_real_termios(void *ptr); 284static int sx_set_real_termios(void *ptr);
285static void sx_close(void *ptr); 285static void sx_close(void *ptr);
@@ -360,7 +360,6 @@ static struct real_driver sx_real_driver = {
360 sx_enable_tx_interrupts, 360 sx_enable_tx_interrupts,
361 sx_disable_rx_interrupts, 361 sx_disable_rx_interrupts,
362 sx_enable_rx_interrupts, 362 sx_enable_rx_interrupts,
363 sx_get_CD,
364 sx_shutdown_port, 363 sx_shutdown_port,
365 sx_set_real_termios, 364 sx_set_real_termios,
366 sx_chars_in_buffer, 365 sx_chars_in_buffer,
@@ -791,7 +790,7 @@ static int sx_getsignals(struct sx_port *port)
791 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) " 790 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) "
792 "%02x/%02x\n", 791 "%02x/%02x\n",
793 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0, 792 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
794 port->c_dcd, sx_get_CD(port), 793 port->c_dcd, tty_port_carrier_raised(&port->gs.port),
795 sx_read_channel_byte(port, hi_ip), 794 sx_read_channel_byte(port, hi_ip),
796 sx_read_channel_byte(port, hi_state)); 795 sx_read_channel_byte(port, hi_state));
797 796
@@ -1190,7 +1189,7 @@ static inline void sx_check_modem_signals(struct sx_port *port)
1190 1189
1191 hi_state = sx_read_channel_byte(port, hi_state); 1190 hi_state = sx_read_channel_byte(port, hi_state);
1192 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n", 1191 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1193 port->c_dcd, sx_get_CD(port)); 1192 port->c_dcd, tty_port_carrier_raised(&port->gs.port));
1194 1193
1195 if (hi_state & ST_BREAK) { 1194 if (hi_state & ST_BREAK) {
1196 hi_state &= ~ST_BREAK; 1195 hi_state &= ~ST_BREAK;
@@ -1202,11 +1201,11 @@ static inline void sx_check_modem_signals(struct sx_port *port)
1202 hi_state &= ~ST_DCD; 1201 hi_state &= ~ST_DCD;
1203 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n"); 1202 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1204 sx_write_channel_byte(port, hi_state, hi_state); 1203 sx_write_channel_byte(port, hi_state, hi_state);
1205 c_dcd = sx_get_CD(port); 1204 c_dcd = tty_port_carrier_raised(&port->gs.port);
1206 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd); 1205 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
1207 if (c_dcd != port->c_dcd) { 1206 if (c_dcd != port->c_dcd) {
1208 port->c_dcd = c_dcd; 1207 port->c_dcd = c_dcd;
1209 if (sx_get_CD(port)) { 1208 if (tty_port_carrier_raised(&port->gs.port)) {
1210 /* DCD went UP */ 1209 /* DCD went UP */
1211 if ((sx_read_channel_byte(port, hi_hstat) != 1210 if ((sx_read_channel_byte(port, hi_hstat) !=
1212 HS_IDLE_CLOSED) && 1211 HS_IDLE_CLOSED) &&
@@ -1415,13 +1414,10 @@ static void sx_enable_rx_interrupts(void *ptr)
1415} 1414}
1416 1415
1417/* Jeez. Isn't this simple? */ 1416/* Jeez. Isn't this simple? */
1418static int sx_get_CD(void *ptr) 1417static int sx_carrier_raised(struct tty_port *port)
1419{ 1418{
1420 struct sx_port *port = ptr; 1419 struct sx_port *sp = container_of(port, struct sx_port, gs.port);
1421 func_enter2(); 1420 return ((sx_read_channel_byte(sp, hi_ip) & IP_DCD) != 0);
1422
1423 func_exit();
1424 return ((sx_read_channel_byte(port, hi_ip) & IP_DCD) != 0);
1425} 1421}
1426 1422
1427/* Jeez. Isn't this simple? */ 1423/* Jeez. Isn't this simple? */
@@ -1536,7 +1532,7 @@ static int sx_open(struct tty_struct *tty, struct file *filp)
1536 } 1532 }
1537 /* tty->low_latency = 1; */ 1533 /* tty->low_latency = 1; */
1538 1534
1539 port->c_dcd = sx_get_CD(port); 1535 port->c_dcd = sx_carrier_raised(&port->gs.port);
1540 sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd); 1536 sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
1541 1537
1542 func_exit(); 1538 func_exit();
@@ -1945,7 +1941,7 @@ static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1945 1941
1946static void sx_throttle(struct tty_struct *tty) 1942static void sx_throttle(struct tty_struct *tty)
1947{ 1943{
1948 struct sx_port *port = (struct sx_port *)tty->driver_data; 1944 struct sx_port *port = tty->driver_data;
1949 1945
1950 func_enter2(); 1946 func_enter2();
1951 /* If the port is using any type of input flow 1947 /* If the port is using any type of input flow
@@ -1959,7 +1955,7 @@ static void sx_throttle(struct tty_struct *tty)
1959 1955
1960static void sx_unthrottle(struct tty_struct *tty) 1956static void sx_unthrottle(struct tty_struct *tty)
1961{ 1957{
1962 struct sx_port *port = (struct sx_port *)tty->driver_data; 1958 struct sx_port *port = tty->driver_data;
1963 1959
1964 func_enter2(); 1960 func_enter2();
1965 /* Always unthrottle even if flow control is not enabled on 1961 /* Always unthrottle even if flow control is not enabled on
@@ -2354,6 +2350,10 @@ static const struct tty_operations sx_ops = {
2354 .tiocmset = sx_tiocmset, 2350 .tiocmset = sx_tiocmset,
2355}; 2351};
2356 2352
2353static const struct tty_port_operations sx_port_ops = {
2354 .carrier_raised = sx_carrier_raised,
2355};
2356
2357static int sx_init_drivers(void) 2357static int sx_init_drivers(void)
2358{ 2358{
2359 int error; 2359 int error;
@@ -2410,6 +2410,7 @@ static int sx_init_portstructs(int nboards, int nports)
2410 for (j = 0; j < boards[i].nports; j++) { 2410 for (j = 0; j < boards[i].nports; j++) {
2411 sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j); 2411 sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j);
2412 tty_port_init(&port->gs.port); 2412 tty_port_init(&port->gs.port);
2413 port->gs.port.ops = &sx_port_ops;
2413 port->gs.magic = SX_MAGIC; 2414 port->gs.magic = SX_MAGIC;
2414 port->gs.close_delay = HZ / 2; 2415 port->gs.close_delay = HZ / 2;
2415 port->gs.closing_wait = 30 * HZ; 2416 port->gs.closing_wait = 30 * HZ;
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 500f5176b6ba..b8063d4cad32 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -977,7 +977,7 @@ static void ldisc_receive_buf(struct tty_struct *tty,
977 */ 977 */
978static void mgsl_stop(struct tty_struct *tty) 978static void mgsl_stop(struct tty_struct *tty)
979{ 979{
980 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 980 struct mgsl_struct *info = tty->driver_data;
981 unsigned long flags; 981 unsigned long flags;
982 982
983 if (mgsl_paranoia_check(info, tty->name, "mgsl_stop")) 983 if (mgsl_paranoia_check(info, tty->name, "mgsl_stop"))
@@ -1000,7 +1000,7 @@ static void mgsl_stop(struct tty_struct *tty)
1000 */ 1000 */
1001static void mgsl_start(struct tty_struct *tty) 1001static void mgsl_start(struct tty_struct *tty)
1002{ 1002{
1003 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 1003 struct mgsl_struct *info = tty->driver_data;
1004 unsigned long flags; 1004 unsigned long flags;
1005 1005
1006 if (mgsl_paranoia_check(info, tty->name, "mgsl_start")) 1006 if (mgsl_paranoia_check(info, tty->name, "mgsl_start"))
@@ -2057,7 +2057,7 @@ static int mgsl_put_char(struct tty_struct *tty, unsigned char ch)
2057 */ 2057 */
2058static void mgsl_flush_chars(struct tty_struct *tty) 2058static void mgsl_flush_chars(struct tty_struct *tty)
2059{ 2059{
2060 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2060 struct mgsl_struct *info = tty->driver_data;
2061 unsigned long flags; 2061 unsigned long flags;
2062 2062
2063 if ( debug_level >= DEBUG_LEVEL_INFO ) 2063 if ( debug_level >= DEBUG_LEVEL_INFO )
@@ -2109,7 +2109,7 @@ static int mgsl_write(struct tty_struct * tty,
2109 const unsigned char *buf, int count) 2109 const unsigned char *buf, int count)
2110{ 2110{
2111 int c, ret = 0; 2111 int c, ret = 0;
2112 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2112 struct mgsl_struct *info = tty->driver_data;
2113 unsigned long flags; 2113 unsigned long flags;
2114 2114
2115 if ( debug_level >= DEBUG_LEVEL_INFO ) 2115 if ( debug_level >= DEBUG_LEVEL_INFO )
@@ -2232,7 +2232,7 @@ cleanup:
2232 */ 2232 */
2233static int mgsl_write_room(struct tty_struct *tty) 2233static int mgsl_write_room(struct tty_struct *tty)
2234{ 2234{
2235 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2235 struct mgsl_struct *info = tty->driver_data;
2236 int ret; 2236 int ret;
2237 2237
2238 if (mgsl_paranoia_check(info, tty->name, "mgsl_write_room")) 2238 if (mgsl_paranoia_check(info, tty->name, "mgsl_write_room"))
@@ -2267,7 +2267,7 @@ static int mgsl_write_room(struct tty_struct *tty)
2267 */ 2267 */
2268static int mgsl_chars_in_buffer(struct tty_struct *tty) 2268static int mgsl_chars_in_buffer(struct tty_struct *tty)
2269{ 2269{
2270 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2270 struct mgsl_struct *info = tty->driver_data;
2271 2271
2272 if (debug_level >= DEBUG_LEVEL_INFO) 2272 if (debug_level >= DEBUG_LEVEL_INFO)
2273 printk("%s(%d):mgsl_chars_in_buffer(%s)\n", 2273 printk("%s(%d):mgsl_chars_in_buffer(%s)\n",
@@ -2301,7 +2301,7 @@ static int mgsl_chars_in_buffer(struct tty_struct *tty)
2301 */ 2301 */
2302static void mgsl_flush_buffer(struct tty_struct *tty) 2302static void mgsl_flush_buffer(struct tty_struct *tty)
2303{ 2303{
2304 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2304 struct mgsl_struct *info = tty->driver_data;
2305 unsigned long flags; 2305 unsigned long flags;
2306 2306
2307 if (debug_level >= DEBUG_LEVEL_INFO) 2307 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2329,7 +2329,7 @@ static void mgsl_flush_buffer(struct tty_struct *tty)
2329 */ 2329 */
2330static void mgsl_send_xchar(struct tty_struct *tty, char ch) 2330static void mgsl_send_xchar(struct tty_struct *tty, char ch)
2331{ 2331{
2332 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2332 struct mgsl_struct *info = tty->driver_data;
2333 unsigned long flags; 2333 unsigned long flags;
2334 2334
2335 if (debug_level >= DEBUG_LEVEL_INFO) 2335 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2358,7 +2358,7 @@ static void mgsl_send_xchar(struct tty_struct *tty, char ch)
2358 */ 2358 */
2359static void mgsl_throttle(struct tty_struct * tty) 2359static void mgsl_throttle(struct tty_struct * tty)
2360{ 2360{
2361 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2361 struct mgsl_struct *info = tty->driver_data;
2362 unsigned long flags; 2362 unsigned long flags;
2363 2363
2364 if (debug_level >= DEBUG_LEVEL_INFO) 2364 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2388,7 +2388,7 @@ static void mgsl_throttle(struct tty_struct * tty)
2388 */ 2388 */
2389static void mgsl_unthrottle(struct tty_struct * tty) 2389static void mgsl_unthrottle(struct tty_struct * tty)
2390{ 2390{
2391 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2391 struct mgsl_struct *info = tty->driver_data;
2392 unsigned long flags; 2392 unsigned long flags;
2393 2393
2394 if (debug_level >= DEBUG_LEVEL_INFO) 2394 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2841,7 +2841,7 @@ static int modem_input_wait(struct mgsl_struct *info,int arg)
2841 */ 2841 */
2842static int tiocmget(struct tty_struct *tty, struct file *file) 2842static int tiocmget(struct tty_struct *tty, struct file *file)
2843{ 2843{
2844 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2844 struct mgsl_struct *info = tty->driver_data;
2845 unsigned int result; 2845 unsigned int result;
2846 unsigned long flags; 2846 unsigned long flags;
2847 2847
@@ -2867,7 +2867,7 @@ static int tiocmget(struct tty_struct *tty, struct file *file)
2867static int tiocmset(struct tty_struct *tty, struct file *file, 2867static int tiocmset(struct tty_struct *tty, struct file *file,
2868 unsigned int set, unsigned int clear) 2868 unsigned int set, unsigned int clear)
2869{ 2869{
2870 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 2870 struct mgsl_struct *info = tty->driver_data;
2871 unsigned long flags; 2871 unsigned long flags;
2872 2872
2873 if (debug_level >= DEBUG_LEVEL_INFO) 2873 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2898,7 +2898,7 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
2898 */ 2898 */
2899static int mgsl_break(struct tty_struct *tty, int break_state) 2899static int mgsl_break(struct tty_struct *tty, int break_state)
2900{ 2900{
2901 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 2901 struct mgsl_struct * info = tty->driver_data;
2902 unsigned long flags; 2902 unsigned long flags;
2903 2903
2904 if (debug_level >= DEBUG_LEVEL_INFO) 2904 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -2932,7 +2932,7 @@ static int mgsl_break(struct tty_struct *tty, int break_state)
2932static int mgsl_ioctl(struct tty_struct *tty, struct file * file, 2932static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2933 unsigned int cmd, unsigned long arg) 2933 unsigned int cmd, unsigned long arg)
2934{ 2934{
2935 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 2935 struct mgsl_struct * info = tty->driver_data;
2936 int ret; 2936 int ret;
2937 2937
2938 if (debug_level >= DEBUG_LEVEL_INFO) 2938 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -3042,7 +3042,7 @@ static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigne
3042 */ 3042 */
3043static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 3043static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3044{ 3044{
3045 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 3045 struct mgsl_struct *info = tty->driver_data;
3046 unsigned long flags; 3046 unsigned long flags;
3047 3047
3048 if (debug_level >= DEBUG_LEVEL_INFO) 3048 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -3096,7 +3096,7 @@ static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termio
3096 */ 3096 */
3097static void mgsl_close(struct tty_struct *tty, struct file * filp) 3097static void mgsl_close(struct tty_struct *tty, struct file * filp)
3098{ 3098{
3099 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 3099 struct mgsl_struct * info = tty->driver_data;
3100 3100
3101 if (mgsl_paranoia_check(info, tty->name, "mgsl_close")) 3101 if (mgsl_paranoia_check(info, tty->name, "mgsl_close"))
3102 return; 3102 return;
@@ -3104,70 +3104,18 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
3104 if (debug_level >= DEBUG_LEVEL_INFO) 3104 if (debug_level >= DEBUG_LEVEL_INFO)
3105 printk("%s(%d):mgsl_close(%s) entry, count=%d\n", 3105 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
3106 __FILE__,__LINE__, info->device_name, info->port.count); 3106 __FILE__,__LINE__, info->device_name, info->port.count);
3107
3108 if (!info->port.count)
3109 return;
3110 3107
3111 if (tty_hung_up_p(filp)) 3108 if (tty_port_close_start(&info->port, tty, filp) == 0)
3112 goto cleanup; 3109 goto cleanup;
3113 3110
3114 if ((tty->count == 1) && (info->port.count != 1)) {
3115 /*
3116 * tty->count is 1 and the tty structure will be freed.
3117 * info->port.count should be one in this case.
3118 * if it's not, correct it so that the port is shutdown.
3119 */
3120 printk("mgsl_close: bad refcount; tty->count is 1, "
3121 "info->port.count is %d\n", info->port.count);
3122 info->port.count = 1;
3123 }
3124
3125 info->port.count--;
3126
3127 /* if at least one open remaining, leave hardware active */
3128 if (info->port.count)
3129 goto cleanup;
3130
3131 info->port.flags |= ASYNC_CLOSING;
3132
3133 /* set tty->closing to notify line discipline to
3134 * only process XON/XOFF characters. Only the N_TTY
3135 * discipline appears to use this (ppp does not).
3136 */
3137 tty->closing = 1;
3138
3139 /* wait for transmit data to clear all layers */
3140
3141 if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) {
3142 if (debug_level >= DEBUG_LEVEL_INFO)
3143 printk("%s(%d):mgsl_close(%s) calling tty_wait_until_sent\n",
3144 __FILE__,__LINE__, info->device_name );
3145 tty_wait_until_sent(tty, info->port.closing_wait);
3146 }
3147
3148 if (info->port.flags & ASYNC_INITIALIZED) 3111 if (info->port.flags & ASYNC_INITIALIZED)
3149 mgsl_wait_until_sent(tty, info->timeout); 3112 mgsl_wait_until_sent(tty, info->timeout);
3150
3151 mgsl_flush_buffer(tty); 3113 mgsl_flush_buffer(tty);
3152
3153 tty_ldisc_flush(tty); 3114 tty_ldisc_flush(tty);
3154
3155 shutdown(info); 3115 shutdown(info);
3156 3116
3157 tty->closing = 0; 3117 tty_port_close_end(&info->port, tty);
3158 info->port.tty = NULL; 3118 info->port.tty = NULL;
3159
3160 if (info->port.blocked_open) {
3161 if (info->port.close_delay) {
3162 msleep_interruptible(jiffies_to_msecs(info->port.close_delay));
3163 }
3164 wake_up_interruptible(&info->port.open_wait);
3165 }
3166
3167 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
3168
3169 wake_up_interruptible(&info->port.close_wait);
3170
3171cleanup: 3119cleanup:
3172 if (debug_level >= DEBUG_LEVEL_INFO) 3120 if (debug_level >= DEBUG_LEVEL_INFO)
3173 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__, 3121 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
@@ -3188,7 +3136,7 @@ cleanup:
3188 */ 3136 */
3189static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout) 3137static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout)
3190{ 3138{
3191 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 3139 struct mgsl_struct * info = tty->driver_data;
3192 unsigned long orig_jiffies, char_time; 3140 unsigned long orig_jiffies, char_time;
3193 3141
3194 if (!info ) 3142 if (!info )
@@ -3261,7 +3209,7 @@ exit:
3261 */ 3209 */
3262static void mgsl_hangup(struct tty_struct *tty) 3210static void mgsl_hangup(struct tty_struct *tty)
3263{ 3211{
3264 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data; 3212 struct mgsl_struct * info = tty->driver_data;
3265 3213
3266 if (debug_level >= DEBUG_LEVEL_INFO) 3214 if (debug_level >= DEBUG_LEVEL_INFO)
3267 printk("%s(%d):mgsl_hangup(%s)\n", 3215 printk("%s(%d):mgsl_hangup(%s)\n",
@@ -3281,6 +3229,35 @@ static void mgsl_hangup(struct tty_struct *tty)
3281 3229
3282} /* end of mgsl_hangup() */ 3230} /* end of mgsl_hangup() */
3283 3231
3232/*
3233 * carrier_raised()
3234 *
3235 * Return true if carrier is raised
3236 */
3237
3238static int carrier_raised(struct tty_port *port)
3239{
3240 unsigned long flags;
3241 struct mgsl_struct *info = container_of(port, struct mgsl_struct, port);
3242
3243 spin_lock_irqsave(&info->irq_spinlock, flags);
3244 usc_get_serial_signals(info);
3245 spin_unlock_irqrestore(&info->irq_spinlock, flags);
3246 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
3247}
3248
3249static void raise_dtr_rts(struct tty_port *port)
3250{
3251 struct mgsl_struct *info = container_of(port, struct mgsl_struct, port);
3252 unsigned long flags;
3253
3254 spin_lock_irqsave(&info->irq_spinlock,flags);
3255 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3256 usc_set_serial_signals(info);
3257 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3258}
3259
3260
3284/* block_til_ready() 3261/* block_til_ready()
3285 * 3262 *
3286 * Block the current process until the specified port 3263 * Block the current process until the specified port
@@ -3302,6 +3279,8 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3302 bool do_clocal = false; 3279 bool do_clocal = false;
3303 bool extra_count = false; 3280 bool extra_count = false;
3304 unsigned long flags; 3281 unsigned long flags;
3282 int dcd;
3283 struct tty_port *port = &info->port;
3305 3284
3306 if (debug_level >= DEBUG_LEVEL_INFO) 3285 if (debug_level >= DEBUG_LEVEL_INFO)
3307 printk("%s(%d):block_til_ready on %s\n", 3286 printk("%s(%d):block_til_ready on %s\n",
@@ -3309,7 +3288,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3309 3288
3310 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 3289 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
3311 /* nonblock mode is set or port is not enabled */ 3290 /* nonblock mode is set or port is not enabled */
3312 info->port.flags |= ASYNC_NORMAL_ACTIVE; 3291 port->flags |= ASYNC_NORMAL_ACTIVE;
3313 return 0; 3292 return 0;
3314 } 3293 }
3315 3294
@@ -3318,50 +3297,42 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3318 3297
3319 /* Wait for carrier detect and the line to become 3298 /* Wait for carrier detect and the line to become
3320 * free (i.e., not in use by the callout). While we are in 3299 * free (i.e., not in use by the callout). While we are in
3321 * this loop, info->port.count is dropped by one, so that 3300 * this loop, port->count is dropped by one, so that
3322 * mgsl_close() knows when to free things. We restore it upon 3301 * mgsl_close() knows when to free things. We restore it upon
3323 * exit, either normal or abnormal. 3302 * exit, either normal or abnormal.
3324 */ 3303 */
3325 3304
3326 retval = 0; 3305 retval = 0;
3327 add_wait_queue(&info->port.open_wait, &wait); 3306 add_wait_queue(&port->open_wait, &wait);
3328 3307
3329 if (debug_level >= DEBUG_LEVEL_INFO) 3308 if (debug_level >= DEBUG_LEVEL_INFO)
3330 printk("%s(%d):block_til_ready before block on %s count=%d\n", 3309 printk("%s(%d):block_til_ready before block on %s count=%d\n",
3331 __FILE__,__LINE__, tty->driver->name, info->port.count ); 3310 __FILE__,__LINE__, tty->driver->name, port->count );
3332 3311
3333 spin_lock_irqsave(&info->irq_spinlock, flags); 3312 spin_lock_irqsave(&info->irq_spinlock, flags);
3334 if (!tty_hung_up_p(filp)) { 3313 if (!tty_hung_up_p(filp)) {
3335 extra_count = true; 3314 extra_count = true;
3336 info->port.count--; 3315 port->count--;
3337 } 3316 }
3338 spin_unlock_irqrestore(&info->irq_spinlock, flags); 3317 spin_unlock_irqrestore(&info->irq_spinlock, flags);
3339 info->port.blocked_open++; 3318 port->blocked_open++;
3340 3319
3341 while (1) { 3320 while (1) {
3342 if (tty->termios->c_cflag & CBAUD) { 3321 if (tty->termios->c_cflag & CBAUD)
3343 spin_lock_irqsave(&info->irq_spinlock,flags); 3322 tty_port_raise_dtr_rts(port);
3344 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3345 usc_set_serial_signals(info);
3346 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3347 }
3348 3323
3349 set_current_state(TASK_INTERRUPTIBLE); 3324 set_current_state(TASK_INTERRUPTIBLE);
3350 3325
3351 if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)){ 3326 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){
3352 retval = (info->port.flags & ASYNC_HUP_NOTIFY) ? 3327 retval = (port->flags & ASYNC_HUP_NOTIFY) ?
3353 -EAGAIN : -ERESTARTSYS; 3328 -EAGAIN : -ERESTARTSYS;
3354 break; 3329 break;
3355 } 3330 }
3356 3331
3357 spin_lock_irqsave(&info->irq_spinlock,flags); 3332 dcd = tty_port_carrier_raised(&info->port);
3358 usc_get_serial_signals(info);
3359 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3360 3333
3361 if (!(info->port.flags & ASYNC_CLOSING) && 3334 if (!(port->flags & ASYNC_CLOSING) && (do_clocal || dcd))
3362 (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
3363 break; 3335 break;
3364 }
3365 3336
3366 if (signal_pending(current)) { 3337 if (signal_pending(current)) {
3367 retval = -ERESTARTSYS; 3338 retval = -ERESTARTSYS;
@@ -3370,24 +3341,25 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
3370 3341
3371 if (debug_level >= DEBUG_LEVEL_INFO) 3342 if (debug_level >= DEBUG_LEVEL_INFO)
3372 printk("%s(%d):block_til_ready blocking on %s count=%d\n", 3343 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3373 __FILE__,__LINE__, tty->driver->name, info->port.count ); 3344 __FILE__,__LINE__, tty->driver->name, port->count );
3374 3345
3375 schedule(); 3346 schedule();
3376 } 3347 }
3377 3348
3378 set_current_state(TASK_RUNNING); 3349 set_current_state(TASK_RUNNING);
3379 remove_wait_queue(&info->port.open_wait, &wait); 3350 remove_wait_queue(&port->open_wait, &wait);
3380 3351
3352 /* FIXME: Racy on hangup during close wait */
3381 if (extra_count) 3353 if (extra_count)
3382 info->port.count++; 3354 port->count++;
3383 info->port.blocked_open--; 3355 port->blocked_open--;
3384 3356
3385 if (debug_level >= DEBUG_LEVEL_INFO) 3357 if (debug_level >= DEBUG_LEVEL_INFO)
3386 printk("%s(%d):block_til_ready after blocking on %s count=%d\n", 3358 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
3387 __FILE__,__LINE__, tty->driver->name, info->port.count ); 3359 __FILE__,__LINE__, tty->driver->name, port->count );
3388 3360
3389 if (!retval) 3361 if (!retval)
3390 info->port.flags |= ASYNC_NORMAL_ACTIVE; 3362 port->flags |= ASYNC_NORMAL_ACTIVE;
3391 3363
3392 return retval; 3364 return retval;
3393 3365
@@ -4304,6 +4276,12 @@ static void mgsl_add_device( struct mgsl_struct *info )
4304 4276
4305} /* end of mgsl_add_device() */ 4277} /* end of mgsl_add_device() */
4306 4278
4279static const struct tty_port_operations mgsl_port_ops = {
4280 .carrier_raised = carrier_raised,
4281 .raise_dtr_rts = raise_dtr_rts,
4282};
4283
4284
4307/* mgsl_allocate_device() 4285/* mgsl_allocate_device()
4308 * 4286 *
4309 * Allocate and initialize a device instance structure 4287 * Allocate and initialize a device instance structure
@@ -4322,6 +4300,7 @@ static struct mgsl_struct* mgsl_allocate_device(void)
4322 printk("Error can't allocate device instance data\n"); 4300 printk("Error can't allocate device instance data\n");
4323 } else { 4301 } else {
4324 tty_port_init(&info->port); 4302 tty_port_init(&info->port);
4303 info->port.ops = &mgsl_port_ops;
4325 info->magic = MGSL_MAGIC; 4304 info->magic = MGSL_MAGIC;
4326 INIT_WORK(&info->task, mgsl_bh_handler); 4305 INIT_WORK(&info->task, mgsl_bh_handler);
4327 info->max_frame_size = 4096; 4306 info->max_frame_size = 4096;
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 08911ed66494..53544e21f191 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -720,44 +720,9 @@ static void close(struct tty_struct *tty, struct file *filp)
720 return; 720 return;
721 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count)); 721 DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
722 722
723 if (!info->port.count) 723 if (tty_port_close_start(&info->port, tty, filp) == 0)
724 return;
725
726 if (tty_hung_up_p(filp))
727 goto cleanup;
728
729 if ((tty->count == 1) && (info->port.count != 1)) {
730 /*
731 * tty->count is 1 and the tty structure will be freed.
732 * info->port.count should be one in this case.
733 * if it's not, correct it so that the port is shutdown.
734 */
735 DBGERR(("%s close: bad refcount; tty->count=1, "
736 "info->port.count=%d\n", info->device_name, info->port.count));
737 info->port.count = 1;
738 }
739
740 info->port.count--;
741
742 /* if at least one open remaining, leave hardware active */
743 if (info->port.count)
744 goto cleanup; 724 goto cleanup;
745 725
746 info->port.flags |= ASYNC_CLOSING;
747
748 /* set tty->closing to notify line discipline to
749 * only process XON/XOFF characters. Only the N_TTY
750 * discipline appears to use this (ppp does not).
751 */
752 tty->closing = 1;
753
754 /* wait for transmit data to clear all layers */
755
756 if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) {
757 DBGINFO(("%s call tty_wait_until_sent\n", info->device_name));
758 tty_wait_until_sent(tty, info->port.closing_wait);
759 }
760
761 if (info->port.flags & ASYNC_INITIALIZED) 726 if (info->port.flags & ASYNC_INITIALIZED)
762 wait_until_sent(tty, info->timeout); 727 wait_until_sent(tty, info->timeout);
763 flush_buffer(tty); 728 flush_buffer(tty);
@@ -765,20 +730,8 @@ static void close(struct tty_struct *tty, struct file *filp)
765 730
766 shutdown(info); 731 shutdown(info);
767 732
768 tty->closing = 0; 733 tty_port_close_end(&info->port, tty);
769 info->port.tty = NULL; 734 info->port.tty = NULL;
770
771 if (info->port.blocked_open) {
772 if (info->port.close_delay) {
773 msleep_interruptible(jiffies_to_msecs(info->port.close_delay));
774 }
775 wake_up_interruptible(&info->port.open_wait);
776 }
777
778 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
779
780 wake_up_interruptible(&info->port.close_wait);
781
782cleanup: 735cleanup:
783 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count)); 736 DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
784} 737}
@@ -3132,6 +3085,29 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
3132 return 0; 3085 return 0;
3133} 3086}
3134 3087
3088static int carrier_raised(struct tty_port *port)
3089{
3090 unsigned long flags;
3091 struct slgt_info *info = container_of(port, struct slgt_info, port);
3092
3093 spin_lock_irqsave(&info->lock,flags);
3094 get_signals(info);
3095 spin_unlock_irqrestore(&info->lock,flags);
3096 return (info->signals & SerialSignal_DCD) ? 1 : 0;
3097}
3098
3099static void raise_dtr_rts(struct tty_port *port)
3100{
3101 unsigned long flags;
3102 struct slgt_info *info = container_of(port, struct slgt_info, port);
3103
3104 spin_lock_irqsave(&info->lock,flags);
3105 info->signals |= SerialSignal_RTS + SerialSignal_DTR;
3106 set_signals(info);
3107 spin_unlock_irqrestore(&info->lock,flags);
3108}
3109
3110
3135/* 3111/*
3136 * block current process until the device is ready to open 3112 * block current process until the device is ready to open
3137 */ 3113 */
@@ -3143,12 +3119,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3143 bool do_clocal = false; 3119 bool do_clocal = false;
3144 bool extra_count = false; 3120 bool extra_count = false;
3145 unsigned long flags; 3121 unsigned long flags;
3122 int cd;
3123 struct tty_port *port = &info->port;
3146 3124
3147 DBGINFO(("%s block_til_ready\n", tty->driver->name)); 3125 DBGINFO(("%s block_til_ready\n", tty->driver->name));
3148 3126
3149 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 3127 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
3150 /* nonblock mode is set or port is not enabled */ 3128 /* nonblock mode is set or port is not enabled */
3151 info->port.flags |= ASYNC_NORMAL_ACTIVE; 3129 port->flags |= ASYNC_NORMAL_ACTIVE;
3152 return 0; 3130 return 0;
3153 } 3131 }
3154 3132
@@ -3157,46 +3135,38 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3157 3135
3158 /* Wait for carrier detect and the line to become 3136 /* Wait for carrier detect and the line to become
3159 * free (i.e., not in use by the callout). While we are in 3137 * free (i.e., not in use by the callout). While we are in
3160 * this loop, info->port.count is dropped by one, so that 3138 * this loop, port->count is dropped by one, so that
3161 * close() knows when to free things. We restore it upon 3139 * close() knows when to free things. We restore it upon
3162 * exit, either normal or abnormal. 3140 * exit, either normal or abnormal.
3163 */ 3141 */
3164 3142
3165 retval = 0; 3143 retval = 0;
3166 add_wait_queue(&info->port.open_wait, &wait); 3144 add_wait_queue(&port->open_wait, &wait);
3167 3145
3168 spin_lock_irqsave(&info->lock, flags); 3146 spin_lock_irqsave(&info->lock, flags);
3169 if (!tty_hung_up_p(filp)) { 3147 if (!tty_hung_up_p(filp)) {
3170 extra_count = true; 3148 extra_count = true;
3171 info->port.count--; 3149 port->count--;
3172 } 3150 }
3173 spin_unlock_irqrestore(&info->lock, flags); 3151 spin_unlock_irqrestore(&info->lock, flags);
3174 info->port.blocked_open++; 3152 port->blocked_open++;
3175 3153
3176 while (1) { 3154 while (1) {
3177 if ((tty->termios->c_cflag & CBAUD)) { 3155 if ((tty->termios->c_cflag & CBAUD))
3178 spin_lock_irqsave(&info->lock,flags); 3156 tty_port_raise_dtr_rts(port);
3179 info->signals |= SerialSignal_RTS + SerialSignal_DTR;
3180 set_signals(info);
3181 spin_unlock_irqrestore(&info->lock,flags);
3182 }
3183 3157
3184 set_current_state(TASK_INTERRUPTIBLE); 3158 set_current_state(TASK_INTERRUPTIBLE);
3185 3159
3186 if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)){ 3160 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){
3187 retval = (info->port.flags & ASYNC_HUP_NOTIFY) ? 3161 retval = (port->flags & ASYNC_HUP_NOTIFY) ?
3188 -EAGAIN : -ERESTARTSYS; 3162 -EAGAIN : -ERESTARTSYS;
3189 break; 3163 break;
3190 } 3164 }
3191 3165
3192 spin_lock_irqsave(&info->lock,flags); 3166 cd = tty_port_carrier_raised(port);
3193 get_signals(info);
3194 spin_unlock_irqrestore(&info->lock,flags);
3195 3167
3196 if (!(info->port.flags & ASYNC_CLOSING) && 3168 if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd ))
3197 (do_clocal || (info->signals & SerialSignal_DCD)) ) {
3198 break; 3169 break;
3199 }
3200 3170
3201 if (signal_pending(current)) { 3171 if (signal_pending(current)) {
3202 retval = -ERESTARTSYS; 3172 retval = -ERESTARTSYS;
@@ -3208,14 +3178,14 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3208 } 3178 }
3209 3179
3210 set_current_state(TASK_RUNNING); 3180 set_current_state(TASK_RUNNING);
3211 remove_wait_queue(&info->port.open_wait, &wait); 3181 remove_wait_queue(&port->open_wait, &wait);
3212 3182
3213 if (extra_count) 3183 if (extra_count)
3214 info->port.count++; 3184 port->count++;
3215 info->port.blocked_open--; 3185 port->blocked_open--;
3216 3186
3217 if (!retval) 3187 if (!retval)
3218 info->port.flags |= ASYNC_NORMAL_ACTIVE; 3188 port->flags |= ASYNC_NORMAL_ACTIVE;
3219 3189
3220 DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval)); 3190 DBGINFO(("%s block_til_ready ready, rc=%d\n", tty->driver->name, retval));
3221 return retval; 3191 return retval;
@@ -3444,6 +3414,11 @@ static void add_device(struct slgt_info *info)
3444#endif 3414#endif
3445} 3415}
3446 3416
3417static const struct tty_port_operations slgt_port_ops = {
3418 .carrier_raised = carrier_raised,
3419 .raise_dtr_rts = raise_dtr_rts,
3420};
3421
3447/* 3422/*
3448 * allocate device instance structure, return NULL on failure 3423 * allocate device instance structure, return NULL on failure
3449 */ 3424 */
@@ -3458,6 +3433,7 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
3458 driver_name, adapter_num, port_num)); 3433 driver_name, adapter_num, port_num));
3459 } else { 3434 } else {
3460 tty_port_init(&info->port); 3435 tty_port_init(&info->port);
3436 info->port.ops = &slgt_port_ops;
3461 info->magic = MGSL_MAGIC; 3437 info->magic = MGSL_MAGIC;
3462 INIT_WORK(&info->task, bh_handler); 3438 INIT_WORK(&info->task, bh_handler);
3463 info->max_frame_size = 4096; 3439 info->max_frame_size = 4096;
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 6bdb44f7bec2..7b0c5b2dd263 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -558,6 +558,7 @@ static void release_resources(SLMP_INFO *info);
558 558
559static int startup(SLMP_INFO *info); 559static int startup(SLMP_INFO *info);
560static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info); 560static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
561static int carrier_raised(struct tty_port *port);
561static void shutdown(SLMP_INFO *info); 562static void shutdown(SLMP_INFO *info);
562static void program_hw(SLMP_INFO *info); 563static void program_hw(SLMP_INFO *info);
563static void change_params(SLMP_INFO *info); 564static void change_params(SLMP_INFO *info);
@@ -800,7 +801,7 @@ cleanup:
800 */ 801 */
801static void close(struct tty_struct *tty, struct file *filp) 802static void close(struct tty_struct *tty, struct file *filp)
802{ 803{
803 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; 804 SLMP_INFO * info = tty->driver_data;
804 805
805 if (sanity_check(info, tty->name, "close")) 806 if (sanity_check(info, tty->name, "close"))
806 return; 807 return;
@@ -809,70 +810,18 @@ static void close(struct tty_struct *tty, struct file *filp)
809 printk("%s(%d):%s close() entry, count=%d\n", 810 printk("%s(%d):%s close() entry, count=%d\n",
810 __FILE__,__LINE__, info->device_name, info->port.count); 811 __FILE__,__LINE__, info->device_name, info->port.count);
811 812
812 if (!info->port.count) 813 if (tty_port_close_start(&info->port, tty, filp) == 0)
813 return;
814
815 if (tty_hung_up_p(filp))
816 goto cleanup;
817
818 if ((tty->count == 1) && (info->port.count != 1)) {
819 /*
820 * tty->count is 1 and the tty structure will be freed.
821 * info->port.count should be one in this case.
822 * if it's not, correct it so that the port is shutdown.
823 */
824 printk("%s(%d):%s close: bad refcount; tty->count is 1, "
825 "info->port.count is %d\n",
826 __FILE__,__LINE__, info->device_name, info->port.count);
827 info->port.count = 1;
828 }
829
830 info->port.count--;
831
832 /* if at least one open remaining, leave hardware active */
833 if (info->port.count)
834 goto cleanup; 814 goto cleanup;
835 815
836 info->port.flags |= ASYNC_CLOSING;
837
838 /* set tty->closing to notify line discipline to
839 * only process XON/XOFF characters. Only the N_TTY
840 * discipline appears to use this (ppp does not).
841 */
842 tty->closing = 1;
843
844 /* wait for transmit data to clear all layers */
845
846 if (info->port.closing_wait != ASYNC_CLOSING_WAIT_NONE) {
847 if (debug_level >= DEBUG_LEVEL_INFO)
848 printk("%s(%d):%s close() calling tty_wait_until_sent\n",
849 __FILE__,__LINE__, info->device_name );
850 tty_wait_until_sent(tty, info->port.closing_wait);
851 }
852
853 if (info->port.flags & ASYNC_INITIALIZED) 816 if (info->port.flags & ASYNC_INITIALIZED)
854 wait_until_sent(tty, info->timeout); 817 wait_until_sent(tty, info->timeout);
855 818
856 flush_buffer(tty); 819 flush_buffer(tty);
857
858 tty_ldisc_flush(tty); 820 tty_ldisc_flush(tty);
859
860 shutdown(info); 821 shutdown(info);
861 822
862 tty->closing = 0; 823 tty_port_close_end(&info->port, tty);
863 info->port.tty = NULL; 824 info->port.tty = NULL;
864
865 if (info->port.blocked_open) {
866 if (info->port.close_delay) {
867 msleep_interruptible(jiffies_to_msecs(info->port.close_delay));
868 }
869 wake_up_interruptible(&info->port.open_wait);
870 }
871
872 info->port.flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
873
874 wake_up_interruptible(&info->port.close_wait);
875
876cleanup: 825cleanup:
877 if (debug_level >= DEBUG_LEVEL_INFO) 826 if (debug_level >= DEBUG_LEVEL_INFO)
878 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__, 827 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
@@ -884,7 +833,7 @@ cleanup:
884 */ 833 */
885static void hangup(struct tty_struct *tty) 834static void hangup(struct tty_struct *tty)
886{ 835{
887 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 836 SLMP_INFO *info = tty->driver_data;
888 837
889 if (debug_level >= DEBUG_LEVEL_INFO) 838 if (debug_level >= DEBUG_LEVEL_INFO)
890 printk("%s(%d):%s hangup()\n", 839 printk("%s(%d):%s hangup()\n",
@@ -907,7 +856,7 @@ static void hangup(struct tty_struct *tty)
907 */ 856 */
908static void set_termios(struct tty_struct *tty, struct ktermios *old_termios) 857static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
909{ 858{
910 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 859 SLMP_INFO *info = tty->driver_data;
911 unsigned long flags; 860 unsigned long flags;
912 861
913 if (debug_level >= DEBUG_LEVEL_INFO) 862 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -960,7 +909,7 @@ static int write(struct tty_struct *tty,
960 const unsigned char *buf, int count) 909 const unsigned char *buf, int count)
961{ 910{
962 int c, ret = 0; 911 int c, ret = 0;
963 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 912 SLMP_INFO *info = tty->driver_data;
964 unsigned long flags; 913 unsigned long flags;
965 914
966 if (debug_level >= DEBUG_LEVEL_INFO) 915 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1038,7 +987,7 @@ cleanup:
1038 */ 987 */
1039static int put_char(struct tty_struct *tty, unsigned char ch) 988static int put_char(struct tty_struct *tty, unsigned char ch)
1040{ 989{
1041 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 990 SLMP_INFO *info = tty->driver_data;
1042 unsigned long flags; 991 unsigned long flags;
1043 int ret = 0; 992 int ret = 0;
1044 993
@@ -1075,7 +1024,7 @@ static int put_char(struct tty_struct *tty, unsigned char ch)
1075 */ 1024 */
1076static void send_xchar(struct tty_struct *tty, char ch) 1025static void send_xchar(struct tty_struct *tty, char ch)
1077{ 1026{
1078 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1027 SLMP_INFO *info = tty->driver_data;
1079 unsigned long flags; 1028 unsigned long flags;
1080 1029
1081 if (debug_level >= DEBUG_LEVEL_INFO) 1030 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1099,7 +1048,7 @@ static void send_xchar(struct tty_struct *tty, char ch)
1099 */ 1048 */
1100static void wait_until_sent(struct tty_struct *tty, int timeout) 1049static void wait_until_sent(struct tty_struct *tty, int timeout)
1101{ 1050{
1102 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; 1051 SLMP_INFO * info = tty->driver_data;
1103 unsigned long orig_jiffies, char_time; 1052 unsigned long orig_jiffies, char_time;
1104 1053
1105 if (!info ) 1054 if (!info )
@@ -1166,7 +1115,7 @@ exit:
1166 */ 1115 */
1167static int write_room(struct tty_struct *tty) 1116static int write_room(struct tty_struct *tty)
1168{ 1117{
1169 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1118 SLMP_INFO *info = tty->driver_data;
1170 int ret; 1119 int ret;
1171 1120
1172 if (sanity_check(info, tty->name, "write_room")) 1121 if (sanity_check(info, tty->name, "write_room"))
@@ -1193,7 +1142,7 @@ static int write_room(struct tty_struct *tty)
1193 */ 1142 */
1194static void flush_chars(struct tty_struct *tty) 1143static void flush_chars(struct tty_struct *tty)
1195{ 1144{
1196 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1145 SLMP_INFO *info = tty->driver_data;
1197 unsigned long flags; 1146 unsigned long flags;
1198 1147
1199 if ( debug_level >= DEBUG_LEVEL_INFO ) 1148 if ( debug_level >= DEBUG_LEVEL_INFO )
@@ -1232,7 +1181,7 @@ static void flush_chars(struct tty_struct *tty)
1232 */ 1181 */
1233static void flush_buffer(struct tty_struct *tty) 1182static void flush_buffer(struct tty_struct *tty)
1234{ 1183{
1235 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1184 SLMP_INFO *info = tty->driver_data;
1236 unsigned long flags; 1185 unsigned long flags;
1237 1186
1238 if (debug_level >= DEBUG_LEVEL_INFO) 1187 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1254,7 +1203,7 @@ static void flush_buffer(struct tty_struct *tty)
1254 */ 1203 */
1255static void tx_hold(struct tty_struct *tty) 1204static void tx_hold(struct tty_struct *tty)
1256{ 1205{
1257 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1206 SLMP_INFO *info = tty->driver_data;
1258 unsigned long flags; 1207 unsigned long flags;
1259 1208
1260 if (sanity_check(info, tty->name, "tx_hold")) 1209 if (sanity_check(info, tty->name, "tx_hold"))
@@ -1274,7 +1223,7 @@ static void tx_hold(struct tty_struct *tty)
1274 */ 1223 */
1275static void tx_release(struct tty_struct *tty) 1224static void tx_release(struct tty_struct *tty)
1276{ 1225{
1277 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1226 SLMP_INFO *info = tty->driver_data;
1278 unsigned long flags; 1227 unsigned long flags;
1279 1228
1280 if (sanity_check(info, tty->name, "tx_release")) 1229 if (sanity_check(info, tty->name, "tx_release"))
@@ -1304,7 +1253,7 @@ static void tx_release(struct tty_struct *tty)
1304static int do_ioctl(struct tty_struct *tty, struct file *file, 1253static int do_ioctl(struct tty_struct *tty, struct file *file,
1305 unsigned int cmd, unsigned long arg) 1254 unsigned int cmd, unsigned long arg)
1306{ 1255{
1307 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1256 SLMP_INFO *info = tty->driver_data;
1308 int error; 1257 int error;
1309 struct mgsl_icount cnow; /* kernel counter temps */ 1258 struct mgsl_icount cnow; /* kernel counter temps */
1310 struct serial_icounter_struct __user *p_cuser; /* user space */ 1259 struct serial_icounter_struct __user *p_cuser; /* user space */
@@ -1515,7 +1464,7 @@ done:
1515 */ 1464 */
1516static int chars_in_buffer(struct tty_struct *tty) 1465static int chars_in_buffer(struct tty_struct *tty)
1517{ 1466{
1518 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1467 SLMP_INFO *info = tty->driver_data;
1519 1468
1520 if (sanity_check(info, tty->name, "chars_in_buffer")) 1469 if (sanity_check(info, tty->name, "chars_in_buffer"))
1521 return 0; 1470 return 0;
@@ -1531,7 +1480,7 @@ static int chars_in_buffer(struct tty_struct *tty)
1531 */ 1480 */
1532static void throttle(struct tty_struct * tty) 1481static void throttle(struct tty_struct * tty)
1533{ 1482{
1534 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1483 SLMP_INFO *info = tty->driver_data;
1535 unsigned long flags; 1484 unsigned long flags;
1536 1485
1537 if (debug_level >= DEBUG_LEVEL_INFO) 1486 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1556,7 +1505,7 @@ static void throttle(struct tty_struct * tty)
1556 */ 1505 */
1557static void unthrottle(struct tty_struct * tty) 1506static void unthrottle(struct tty_struct * tty)
1558{ 1507{
1559 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 1508 SLMP_INFO *info = tty->driver_data;
1560 unsigned long flags; 1509 unsigned long flags;
1561 1510
1562 if (debug_level >= DEBUG_LEVEL_INFO) 1511 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -1587,7 +1536,7 @@ static void unthrottle(struct tty_struct * tty)
1587static int set_break(struct tty_struct *tty, int break_state) 1536static int set_break(struct tty_struct *tty, int break_state)
1588{ 1537{
1589 unsigned char RegValue; 1538 unsigned char RegValue;
1590 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data; 1539 SLMP_INFO * info = tty->driver_data;
1591 unsigned long flags; 1540 unsigned long flags;
1592 1541
1593 if (debug_level >= DEBUG_LEVEL_INFO) 1542 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -3269,7 +3218,7 @@ static int modem_input_wait(SLMP_INFO *info,int arg)
3269 */ 3218 */
3270static int tiocmget(struct tty_struct *tty, struct file *file) 3219static int tiocmget(struct tty_struct *tty, struct file *file)
3271{ 3220{
3272 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 3221 SLMP_INFO *info = tty->driver_data;
3273 unsigned int result; 3222 unsigned int result;
3274 unsigned long flags; 3223 unsigned long flags;
3275 3224
@@ -3295,7 +3244,7 @@ static int tiocmget(struct tty_struct *tty, struct file *file)
3295static int tiocmset(struct tty_struct *tty, struct file *file, 3244static int tiocmset(struct tty_struct *tty, struct file *file,
3296 unsigned int set, unsigned int clear) 3245 unsigned int set, unsigned int clear)
3297{ 3246{
3298 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 3247 SLMP_INFO *info = tty->driver_data;
3299 unsigned long flags; 3248 unsigned long flags;
3300 3249
3301 if (debug_level >= DEBUG_LEVEL_INFO) 3250 if (debug_level >= DEBUG_LEVEL_INFO)
@@ -3318,7 +3267,28 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
3318 return 0; 3267 return 0;
3319} 3268}
3320 3269
3270static int carrier_raised(struct tty_port *port)
3271{
3272 SLMP_INFO *info = container_of(port, SLMP_INFO, port);
3273 unsigned long flags;
3274
3275 spin_lock_irqsave(&info->lock,flags);
3276 get_signals(info);
3277 spin_unlock_irqrestore(&info->lock,flags);
3321 3278
3279 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
3280}
3281
3282static void raise_dtr_rts(struct tty_port *port)
3283{
3284 SLMP_INFO *info = container_of(port, SLMP_INFO, port);
3285 unsigned long flags;
3286
3287 spin_lock_irqsave(&info->lock,flags);
3288 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3289 set_signals(info);
3290 spin_unlock_irqrestore(&info->lock,flags);
3291}
3322 3292
3323/* Block the current process until the specified port is ready to open. 3293/* Block the current process until the specified port is ready to open.
3324 */ 3294 */
@@ -3330,6 +3300,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3330 bool do_clocal = false; 3300 bool do_clocal = false;
3331 bool extra_count = false; 3301 bool extra_count = false;
3332 unsigned long flags; 3302 unsigned long flags;
3303 int cd;
3304 struct tty_port *port = &info->port;
3333 3305
3334 if (debug_level >= DEBUG_LEVEL_INFO) 3306 if (debug_level >= DEBUG_LEVEL_INFO)
3335 printk("%s(%d):%s block_til_ready()\n", 3307 printk("%s(%d):%s block_til_ready()\n",
@@ -3338,7 +3310,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3338 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){ 3310 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
3339 /* nonblock mode is set or port is not enabled */ 3311 /* nonblock mode is set or port is not enabled */
3340 /* just verify that callout device is not active */ 3312 /* just verify that callout device is not active */
3341 info->port.flags |= ASYNC_NORMAL_ACTIVE; 3313 port->flags |= ASYNC_NORMAL_ACTIVE;
3342 return 0; 3314 return 0;
3343 } 3315 }
3344 3316
@@ -3347,50 +3319,42 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3347 3319
3348 /* Wait for carrier detect and the line to become 3320 /* Wait for carrier detect and the line to become
3349 * free (i.e., not in use by the callout). While we are in 3321 * free (i.e., not in use by the callout). While we are in
3350 * this loop, info->port.count is dropped by one, so that 3322 * this loop, port->count is dropped by one, so that
3351 * close() knows when to free things. We restore it upon 3323 * close() knows when to free things. We restore it upon
3352 * exit, either normal or abnormal. 3324 * exit, either normal or abnormal.
3353 */ 3325 */
3354 3326
3355 retval = 0; 3327 retval = 0;
3356 add_wait_queue(&info->port.open_wait, &wait); 3328 add_wait_queue(&port->open_wait, &wait);
3357 3329
3358 if (debug_level >= DEBUG_LEVEL_INFO) 3330 if (debug_level >= DEBUG_LEVEL_INFO)
3359 printk("%s(%d):%s block_til_ready() before block, count=%d\n", 3331 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
3360 __FILE__,__LINE__, tty->driver->name, info->port.count ); 3332 __FILE__,__LINE__, tty->driver->name, port->count );
3361 3333
3362 spin_lock_irqsave(&info->lock, flags); 3334 spin_lock_irqsave(&info->lock, flags);
3363 if (!tty_hung_up_p(filp)) { 3335 if (!tty_hung_up_p(filp)) {
3364 extra_count = true; 3336 extra_count = true;
3365 info->port.count--; 3337 port->count--;
3366 } 3338 }
3367 spin_unlock_irqrestore(&info->lock, flags); 3339 spin_unlock_irqrestore(&info->lock, flags);
3368 info->port.blocked_open++; 3340 port->blocked_open++;
3369 3341
3370 while (1) { 3342 while (1) {
3371 if ((tty->termios->c_cflag & CBAUD)) { 3343 if (tty->termios->c_cflag & CBAUD)
3372 spin_lock_irqsave(&info->lock,flags); 3344 tty_port_raise_dtr_rts(port);
3373 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3374 set_signals(info);
3375 spin_unlock_irqrestore(&info->lock,flags);
3376 }
3377 3345
3378 set_current_state(TASK_INTERRUPTIBLE); 3346 set_current_state(TASK_INTERRUPTIBLE);
3379 3347
3380 if (tty_hung_up_p(filp) || !(info->port.flags & ASYNC_INITIALIZED)){ 3348 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)){
3381 retval = (info->port.flags & ASYNC_HUP_NOTIFY) ? 3349 retval = (port->flags & ASYNC_HUP_NOTIFY) ?
3382 -EAGAIN : -ERESTARTSYS; 3350 -EAGAIN : -ERESTARTSYS;
3383 break; 3351 break;
3384 } 3352 }
3385 3353
3386 spin_lock_irqsave(&info->lock,flags); 3354 cd = tty_port_carrier_raised(port);
3387 get_signals(info);
3388 spin_unlock_irqrestore(&info->lock,flags);
3389 3355
3390 if (!(info->port.flags & ASYNC_CLOSING) && 3356 if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd))
3391 (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
3392 break; 3357 break;
3393 }
3394 3358
3395 if (signal_pending(current)) { 3359 if (signal_pending(current)) {
3396 retval = -ERESTARTSYS; 3360 retval = -ERESTARTSYS;
@@ -3399,24 +3363,24 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
3399 3363
3400 if (debug_level >= DEBUG_LEVEL_INFO) 3364 if (debug_level >= DEBUG_LEVEL_INFO)
3401 printk("%s(%d):%s block_til_ready() count=%d\n", 3365 printk("%s(%d):%s block_til_ready() count=%d\n",
3402 __FILE__,__LINE__, tty->driver->name, info->port.count ); 3366 __FILE__,__LINE__, tty->driver->name, port->count );
3403 3367
3404 schedule(); 3368 schedule();
3405 } 3369 }
3406 3370
3407 set_current_state(TASK_RUNNING); 3371 set_current_state(TASK_RUNNING);
3408 remove_wait_queue(&info->port.open_wait, &wait); 3372 remove_wait_queue(&port->open_wait, &wait);
3409 3373
3410 if (extra_count) 3374 if (extra_count)
3411 info->port.count++; 3375 port->count++;
3412 info->port.blocked_open--; 3376 port->blocked_open--;
3413 3377
3414 if (debug_level >= DEBUG_LEVEL_INFO) 3378 if (debug_level >= DEBUG_LEVEL_INFO)
3415 printk("%s(%d):%s block_til_ready() after, count=%d\n", 3379 printk("%s(%d):%s block_til_ready() after, count=%d\n",
3416 __FILE__,__LINE__, tty->driver->name, info->port.count ); 3380 __FILE__,__LINE__, tty->driver->name, port->count );
3417 3381
3418 if (!retval) 3382 if (!retval)
3419 info->port.flags |= ASYNC_NORMAL_ACTIVE; 3383 port->flags |= ASYNC_NORMAL_ACTIVE;
3420 3384
3421 return retval; 3385 return retval;
3422} 3386}
@@ -3782,6 +3746,11 @@ static void add_device(SLMP_INFO *info)
3782#endif 3746#endif
3783} 3747}
3784 3748
3749static const struct tty_port_operations port_ops = {
3750 .carrier_raised = carrier_raised,
3751 .raise_dtr_rts = raise_dtr_rts,
3752};
3753
3785/* Allocate and initialize a device instance structure 3754/* Allocate and initialize a device instance structure
3786 * 3755 *
3787 * Return Value: pointer to SLMP_INFO if success, otherwise NULL 3756 * Return Value: pointer to SLMP_INFO if success, otherwise NULL
@@ -3798,6 +3767,7 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
3798 __FILE__,__LINE__, adapter_num, port_num); 3767 __FILE__,__LINE__, adapter_num, port_num);
3799 } else { 3768 } else {
3800 tty_port_init(&info->port); 3769 tty_port_init(&info->port);
3770 info->port.ops = &port_ops;
3801 info->magic = MGSL_MAGIC; 3771 info->magic = MGSL_MAGIC;
3802 INIT_WORK(&info->task, bh_handler); 3772 INIT_WORK(&info->task, bh_handler);
3803 info->max_frame_size = 4096; 3773 info->max_frame_size = 4096;
@@ -3940,6 +3910,7 @@ static const struct tty_operations ops = {
3940 .tiocmset = tiocmset, 3910 .tiocmset = tiocmset,
3941}; 3911};
3942 3912
3913
3943static void synclinkmp_cleanup(void) 3914static void synclinkmp_cleanup(void)
3944{ 3915{
3945 int rc; 3916 int rc;
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index db15f9ba7c0b..d33e5ab06177 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -1111,9 +1111,7 @@ void tty_write_message(struct tty_struct *tty, char *msg)
1111 * Locks the line discipline as required 1111 * Locks the line discipline as required
1112 * Writes to the tty driver are serialized by the atomic_write_lock 1112 * Writes to the tty driver are serialized by the atomic_write_lock
1113 * and are then processed in chunks to the device. The line discipline 1113 * and are then processed in chunks to the device. The line discipline
1114 * write method will not be involked in parallel for each device 1114 * write method will not be invoked in parallel for each device.
1115 * The line discipline write method is called under the big
1116 * kernel lock for historical reasons. New code should not rely on this.
1117 */ 1115 */
1118 1116
1119static ssize_t tty_write(struct file *file, const char __user *buf, 1117static ssize_t tty_write(struct file *file, const char __user *buf,
@@ -1213,7 +1211,7 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
1213 * be held until the 'fast-open' is also done. Will change once we 1211 * be held until the 'fast-open' is also done. Will change once we
1214 * have refcounting in the driver and per driver locking 1212 * have refcounting in the driver and per driver locking
1215 */ 1213 */
1216struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, 1214static struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
1217 struct inode *inode, int idx) 1215 struct inode *inode, int idx)
1218{ 1216{
1219 struct tty_struct *tty; 1217 struct tty_struct *tty;
@@ -2050,7 +2048,6 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
2050/** 2048/**
2051 * tty_do_resize - resize event 2049 * tty_do_resize - resize event
2052 * @tty: tty being resized 2050 * @tty: tty being resized
2053 * @real_tty: real tty (not the same as tty if using a pty/tty pair)
2054 * @rows: rows (character) 2051 * @rows: rows (character)
2055 * @cols: cols (character) 2052 * @cols: cols (character)
2056 * 2053 *
@@ -2058,41 +2055,34 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
2058 * peform a terminal resize correctly 2055 * peform a terminal resize correctly
2059 */ 2056 */
2060 2057
2061int tty_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, 2058int tty_do_resize(struct tty_struct *tty, struct winsize *ws)
2062 struct winsize *ws)
2063{ 2059{
2064 struct pid *pgrp, *rpgrp; 2060 struct pid *pgrp;
2065 unsigned long flags; 2061 unsigned long flags;
2066 2062
2067 /* For a PTY we need to lock the tty side */ 2063 /* Lock the tty */
2068 mutex_lock(&real_tty->termios_mutex); 2064 mutex_lock(&tty->termios_mutex);
2069 if (!memcmp(ws, &real_tty->winsize, sizeof(*ws))) 2065 if (!memcmp(ws, &tty->winsize, sizeof(*ws)))
2070 goto done; 2066 goto done;
2071 /* Get the PID values and reference them so we can 2067 /* Get the PID values and reference them so we can
2072 avoid holding the tty ctrl lock while sending signals */ 2068 avoid holding the tty ctrl lock while sending signals */
2073 spin_lock_irqsave(&tty->ctrl_lock, flags); 2069 spin_lock_irqsave(&tty->ctrl_lock, flags);
2074 pgrp = get_pid(tty->pgrp); 2070 pgrp = get_pid(tty->pgrp);
2075 rpgrp = get_pid(real_tty->pgrp);
2076 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 2071 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
2077 2072
2078 if (pgrp) 2073 if (pgrp)
2079 kill_pgrp(pgrp, SIGWINCH, 1); 2074 kill_pgrp(pgrp, SIGWINCH, 1);
2080 if (rpgrp != pgrp && rpgrp)
2081 kill_pgrp(rpgrp, SIGWINCH, 1);
2082
2083 put_pid(pgrp); 2075 put_pid(pgrp);
2084 put_pid(rpgrp);
2085 2076
2086 tty->winsize = *ws; 2077 tty->winsize = *ws;
2087 real_tty->winsize = *ws;
2088done: 2078done:
2089 mutex_unlock(&real_tty->termios_mutex); 2079 mutex_unlock(&tty->termios_mutex);
2090 return 0; 2080 return 0;
2091} 2081}
2092 2082
2093/** 2083/**
2094 * tiocswinsz - implement window size set ioctl 2084 * tiocswinsz - implement window size set ioctl
2095 * @tty; tty 2085 * @tty; tty side of tty
2096 * @arg: user buffer for result 2086 * @arg: user buffer for result
2097 * 2087 *
2098 * Copies the user idea of the window size to the kernel. Traditionally 2088 * Copies the user idea of the window size to the kernel. Traditionally
@@ -2105,17 +2095,16 @@ done:
2105 * then calls into the default method. 2095 * then calls into the default method.
2106 */ 2096 */
2107 2097
2108static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, 2098static int tiocswinsz(struct tty_struct *tty, struct winsize __user *arg)
2109 struct winsize __user *arg)
2110{ 2099{
2111 struct winsize tmp_ws; 2100 struct winsize tmp_ws;
2112 if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) 2101 if (copy_from_user(&tmp_ws, arg, sizeof(*arg)))
2113 return -EFAULT; 2102 return -EFAULT;
2114 2103
2115 if (tty->ops->resize) 2104 if (tty->ops->resize)
2116 return tty->ops->resize(tty, real_tty, &tmp_ws); 2105 return tty->ops->resize(tty, &tmp_ws);
2117 else 2106 else
2118 return tty_do_resize(tty, real_tty, &tmp_ws); 2107 return tty_do_resize(tty, &tmp_ws);
2119} 2108}
2120 2109
2121/** 2110/**
@@ -2540,7 +2529,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2540 case TIOCGWINSZ: 2529 case TIOCGWINSZ:
2541 return tiocgwinsz(real_tty, p); 2530 return tiocgwinsz(real_tty, p);
2542 case TIOCSWINSZ: 2531 case TIOCSWINSZ:
2543 return tiocswinsz(tty, real_tty, p); 2532 return tiocswinsz(real_tty, p);
2544 case TIOCCONS: 2533 case TIOCCONS:
2545 return real_tty != tty ? -EINVAL : tioccons(file); 2534 return real_tty != tty ? -EINVAL : tioccons(file);
2546 case FIONBIO: 2535 case FIONBIO:
@@ -2785,6 +2774,8 @@ void initialize_tty_struct(struct tty_struct *tty,
2785 INIT_WORK(&tty->hangup_work, do_tty_hangup); 2774 INIT_WORK(&tty->hangup_work, do_tty_hangup);
2786 mutex_init(&tty->atomic_read_lock); 2775 mutex_init(&tty->atomic_read_lock);
2787 mutex_init(&tty->atomic_write_lock); 2776 mutex_init(&tty->atomic_write_lock);
2777 mutex_init(&tty->output_lock);
2778 mutex_init(&tty->echo_lock);
2788 spin_lock_init(&tty->read_lock); 2779 spin_lock_init(&tty->read_lock);
2789 spin_lock_init(&tty->ctrl_lock); 2780 spin_lock_init(&tty->ctrl_lock);
2790 INIT_LIST_HEAD(&tty->tty_files); 2781 INIT_LIST_HEAD(&tty->tty_files);
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index f307f135cbfb..7a84b406a952 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -316,8 +316,7 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
316{ 316{
317 /* wait_event is a macro */ 317 /* wait_event is a macro */
318 wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); 318 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
319 if (tty->ldisc.refcount == 0) 319 WARN_ON(tty->ldisc.refcount == 0);
320 printk(KERN_ERR "tty_ldisc_ref_wait\n");
321 return &tty->ldisc; 320 return &tty->ldisc;
322} 321}
323 322
@@ -376,15 +375,17 @@ EXPORT_SYMBOL_GPL(tty_ldisc_deref);
376 * @tty: terminal to activate ldisc on 375 * @tty: terminal to activate ldisc on
377 * 376 *
378 * Set the TTY_LDISC flag when the line discipline can be called 377 * Set the TTY_LDISC flag when the line discipline can be called
379 * again. Do necessary wakeups for existing sleepers. 378 * again. Do necessary wakeups for existing sleepers. Clear the LDISC
379 * changing flag to indicate any ldisc change is now over.
380 * 380 *
381 * Note: nobody should set this bit except via this function. Clearing 381 * Note: nobody should set the TTY_LDISC bit except via this function.
382 * directly is allowed. 382 * Clearing directly is allowed.
383 */ 383 */
384 384
385void tty_ldisc_enable(struct tty_struct *tty) 385void tty_ldisc_enable(struct tty_struct *tty)
386{ 386{
387 set_bit(TTY_LDISC, &tty->flags); 387 set_bit(TTY_LDISC, &tty->flags);
388 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
388 wake_up(&tty_ldisc_wait); 389 wake_up(&tty_ldisc_wait);
389} 390}
390 391
@@ -496,7 +497,14 @@ restart:
496 * reference to the line discipline. The TTY_LDISC bit 497 * reference to the line discipline. The TTY_LDISC bit
497 * prevents anyone taking a reference once it is clear. 498 * prevents anyone taking a reference once it is clear.
498 * We need the lock to avoid racing reference takers. 499 * We need the lock to avoid racing reference takers.
500 *
501 * We must clear the TTY_LDISC bit here to avoid a livelock
502 * with a userspace app continually trying to use the tty in
503 * parallel to the change and re-referencing the tty.
499 */ 504 */
505 clear_bit(TTY_LDISC, &tty->flags);
506 if (o_tty)
507 clear_bit(TTY_LDISC, &o_tty->flags);
500 508
501 spin_lock_irqsave(&tty_ldisc_lock, flags); 509 spin_lock_irqsave(&tty_ldisc_lock, flags);
502 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { 510 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
@@ -528,7 +536,7 @@ restart:
528 * If the TTY_LDISC bit is set, then we are racing against 536 * If the TTY_LDISC bit is set, then we are racing against
529 * another ldisc change 537 * another ldisc change
530 */ 538 */
531 if (!test_bit(TTY_LDISC, &tty->flags)) { 539 if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
532 struct tty_ldisc *ld; 540 struct tty_ldisc *ld;
533 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 541 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
534 tty_ldisc_put(new_ldisc.ops); 542 tty_ldisc_put(new_ldisc.ops);
@@ -536,10 +544,14 @@ restart:
536 tty_ldisc_deref(ld); 544 tty_ldisc_deref(ld);
537 goto restart; 545 goto restart;
538 } 546 }
539 547 /*
540 clear_bit(TTY_LDISC, &tty->flags); 548 * This flag is used to avoid two parallel ldisc changes. Once
549 * open and close are fine grained locked this may work better
550 * as a mutex shared with the open/close/hup paths
551 */
552 set_bit(TTY_LDISC_CHANGING, &tty->flags);
541 if (o_tty) 553 if (o_tty)
542 clear_bit(TTY_LDISC, &o_tty->flags); 554 set_bit(TTY_LDISC_CHANGING, &o_tty->flags);
543 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 555 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
544 556
545 /* 557 /*
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index c8f8024cb40e..9b8004c72686 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/char/tty_port.c
@@ -7,6 +7,7 @@
7#include <linux/tty.h> 7#include <linux/tty.h>
8#include <linux/tty_driver.h> 8#include <linux/tty_driver.h>
9#include <linux/tty_flip.h> 9#include <linux/tty_flip.h>
10#include <linux/serial.h>
10#include <linux/timer.h> 11#include <linux/timer.h>
11#include <linux/string.h> 12#include <linux/string.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
@@ -94,3 +95,227 @@ void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
94 spin_unlock_irqrestore(&port->lock, flags); 95 spin_unlock_irqrestore(&port->lock, flags);
95} 96}
96EXPORT_SYMBOL(tty_port_tty_set); 97EXPORT_SYMBOL(tty_port_tty_set);
98
99/**
100 * tty_port_hangup - hangup helper
101 * @port: tty port
102 *
103 * Perform port level tty hangup flag and count changes. Drop the tty
104 * reference.
105 */
106
107void tty_port_hangup(struct tty_port *port)
108{
109 unsigned long flags;
110
111 spin_lock_irqsave(&port->lock, flags);
112 port->count = 0;
113 port->flags &= ~ASYNC_NORMAL_ACTIVE;
114 if (port->tty)
115 tty_kref_put(port->tty);
116 port->tty = NULL;
117 spin_unlock_irqrestore(&port->lock, flags);
118 wake_up_interruptible(&port->open_wait);
119}
120EXPORT_SYMBOL(tty_port_hangup);
121
122/**
123 * tty_port_carrier_raised - carrier raised check
124 * @port: tty port
125 *
126 * Wrapper for the carrier detect logic. For the moment this is used
127 * to hide some internal details. This will eventually become entirely
128 * internal to the tty port.
129 */
130
131int tty_port_carrier_raised(struct tty_port *port)
132{
133 if (port->ops->carrier_raised == NULL)
134 return 1;
135 return port->ops->carrier_raised(port);
136}
137EXPORT_SYMBOL(tty_port_carrier_raised);
138
139/**
140 * tty_port_raise_dtr_rts - Riase DTR/RTS
141 * @port: tty port
142 *
143 * Wrapper for the DTR/RTS raise logic. For the moment this is used
144 * to hide some internal details. This will eventually become entirely
145 * internal to the tty port.
146 */
147
148void tty_port_raise_dtr_rts(struct tty_port *port)
149{
150 if (port->ops->raise_dtr_rts)
151 port->ops->raise_dtr_rts(port);
152}
153EXPORT_SYMBOL(tty_port_raise_dtr_rts);
154
155/**
156 * tty_port_block_til_ready - Waiting logic for tty open
157 * @port: the tty port being opened
158 * @tty: the tty device being bound
159 * @filp: the file pointer of the opener
160 *
161 * Implement the core POSIX/SuS tty behaviour when opening a tty device.
162 * Handles:
163 * - hangup (both before and during)
164 * - non blocking open
165 * - rts/dtr/dcd
166 * - signals
167 * - port flags and counts
168 *
169 * The passed tty_port must implement the carrier_raised method if it can
170 * do carrier detect and the raise_dtr_rts method if it supports software
171 * management of these lines. Note that the dtr/rts raise is done each
172 * iteration as a hangup may have previously dropped them while we wait.
173 */
174
175int tty_port_block_til_ready(struct tty_port *port,
176 struct tty_struct *tty, struct file *filp)
177{
178 int do_clocal = 0, retval;
179 unsigned long flags;
180 DECLARE_WAITQUEUE(wait, current);
181 int cd;
182
183 /* block if port is in the process of being closed */
184 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
185 interruptible_sleep_on(&port->close_wait);
186 if (port->flags & ASYNC_HUP_NOTIFY)
187 return -EAGAIN;
188 else
189 return -ERESTARTSYS;
190 }
191
192 /* if non-blocking mode is set we can pass directly to open unless
193 the port has just hung up or is in another error state */
194 if ((filp->f_flags & O_NONBLOCK) ||
195 (tty->flags & (1 << TTY_IO_ERROR))) {
196 port->flags |= ASYNC_NORMAL_ACTIVE;
197 return 0;
198 }
199
200 if (C_CLOCAL(tty))
201 do_clocal = 1;
202
203 /* Block waiting until we can proceed. We may need to wait for the
204 carrier, but we must also wait for any close that is in progress
205 before the next open may complete */
206
207 retval = 0;
208 add_wait_queue(&port->open_wait, &wait);
209
210 /* The port lock protects the port counts */
211 spin_lock_irqsave(&port->lock, flags);
212 if (!tty_hung_up_p(filp))
213 port->count--;
214 port->blocked_open++;
215 spin_unlock_irqrestore(&port->lock, flags);
216
217 while (1) {
218 /* Indicate we are open */
219 if (tty->termios->c_cflag & CBAUD)
220 tty_port_raise_dtr_rts(port);
221
222 set_current_state(TASK_INTERRUPTIBLE);
223 /* Check for a hangup or uninitialised port. Return accordingly */
224 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
225 if (port->flags & ASYNC_HUP_NOTIFY)
226 retval = -EAGAIN;
227 else
228 retval = -ERESTARTSYS;
229 break;
230 }
231 /* Probe the carrier. For devices with no carrier detect this
232 will always return true */
233 cd = tty_port_carrier_raised(port);
234 if (!(port->flags & ASYNC_CLOSING) &&
235 (do_clocal || cd))
236 break;
237 if (signal_pending(current)) {
238 retval = -ERESTARTSYS;
239 break;
240 }
241 schedule();
242 }
243 set_current_state(TASK_RUNNING);
244 remove_wait_queue(&port->open_wait, &wait);
245
246 /* Update counts. A parallel hangup will have set count to zero and
247 we must not mess that up further */
248 spin_lock_irqsave(&port->lock, flags);
249 if (!tty_hung_up_p(filp))
250 port->count++;
251 port->blocked_open--;
252 if (retval == 0)
253 port->flags |= ASYNC_NORMAL_ACTIVE;
254 spin_unlock_irqrestore(&port->lock, flags);
255 return 0;
256
257}
258EXPORT_SYMBOL(tty_port_block_til_ready);
259
260int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct file *filp)
261{
262 unsigned long flags;
263
264 spin_lock_irqsave(&port->lock, flags);
265 if (tty_hung_up_p(filp)) {
266 spin_unlock_irqrestore(&port->lock, flags);
267 return 0;
268 }
269
270 if( tty->count == 1 && port->count != 1) {
271 printk(KERN_WARNING
272 "tty_port_close_start: tty->count = 1 port count = %d.\n",
273 port->count);
274 port->count = 1;
275 }
276 if (--port->count < 0) {
277 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
278 port->count);
279 port->count = 0;
280 }
281
282 if (port->count) {
283 spin_unlock_irqrestore(&port->lock, flags);
284 return 0;
285 }
286 port->flags |= ASYNC_CLOSING;
287 tty->closing = 1;
288 spin_unlock_irqrestore(&port->lock, flags);
289 /* Don't block on a stalled port, just pull the chain */
290 if (tty->flow_stopped)
291 tty_driver_flush_buffer(tty);
292 if (port->flags & ASYNC_INITIALIZED &&
293 port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
294 tty_wait_until_sent(tty, port->closing_wait);
295 return 1;
296}
297EXPORT_SYMBOL(tty_port_close_start);
298
299void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
300{
301 unsigned long flags;
302
303 tty_ldisc_flush(tty);
304
305 spin_lock_irqsave(&port->lock, flags);
306 tty->closing = 0;
307
308 if (port->blocked_open) {
309 spin_unlock_irqrestore(&port->lock, flags);
310 if (port->close_delay) {
311 msleep_interruptible(
312 jiffies_to_msecs(port->close_delay));
313 }
314 spin_lock_irqsave(&port->lock, flags);
315 wake_up_interruptible(&port->open_wait);
316 }
317 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
318 wake_up_interruptible(&port->close_wait);
319 spin_unlock_irqrestore(&port->lock, flags);
320}
321EXPORT_SYMBOL(tty_port_close_end);
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index 1718b3c481db..0e8234bd0e19 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -69,7 +69,7 @@ static void scc_disable_tx_interrupts(void * ptr);
69static void scc_enable_tx_interrupts(void * ptr); 69static void scc_enable_tx_interrupts(void * ptr);
70static void scc_disable_rx_interrupts(void * ptr); 70static void scc_disable_rx_interrupts(void * ptr);
71static void scc_enable_rx_interrupts(void * ptr); 71static void scc_enable_rx_interrupts(void * ptr);
72static int scc_get_CD(void * ptr); 72static int scc_carrier_raised(struct tty_port *port);
73static void scc_shutdown_port(void * ptr); 73static void scc_shutdown_port(void * ptr);
74static int scc_set_real_termios(void *ptr); 74static int scc_set_real_termios(void *ptr);
75static void scc_hungup(void *ptr); 75static void scc_hungup(void *ptr);
@@ -100,7 +100,6 @@ static struct real_driver scc_real_driver = {
100 scc_enable_tx_interrupts, 100 scc_enable_tx_interrupts,
101 scc_disable_rx_interrupts, 101 scc_disable_rx_interrupts,
102 scc_enable_rx_interrupts, 102 scc_enable_rx_interrupts,
103 scc_get_CD,
104 scc_shutdown_port, 103 scc_shutdown_port,
105 scc_set_real_termios, 104 scc_set_real_termios,
106 scc_chars_in_buffer, 105 scc_chars_in_buffer,
@@ -129,6 +128,10 @@ static const struct tty_operations scc_ops = {
129 .break_ctl = scc_break_ctl, 128 .break_ctl = scc_break_ctl,
130}; 129};
131 130
131static const struct tty_port_operations scc_port_ops = {
132 .carrier_raised = scc_carrier_raised,
133};
134
132/*---------------------------------------------------------------------------- 135/*----------------------------------------------------------------------------
133 * vme_scc_init() and support functions 136 * vme_scc_init() and support functions
134 *---------------------------------------------------------------------------*/ 137 *---------------------------------------------------------------------------*/
@@ -176,6 +179,8 @@ static void scc_init_portstructs(void)
176 179
177 for (i = 0; i < 2; i++) { 180 for (i = 0; i < 2; i++) {
178 port = scc_ports + i; 181 port = scc_ports + i;
182 tty_port_init(&port->gs.port);
183 port->gs.port.ops = &scc_port_ops;
179 port->gs.magic = SCC_MAGIC; 184 port->gs.magic = SCC_MAGIC;
180 port->gs.close_delay = HZ/2; 185 port->gs.close_delay = HZ/2;
181 port->gs.closing_wait = 30 * HZ; 186 port->gs.closing_wait = 30 * HZ;
@@ -624,10 +629,10 @@ static void scc_enable_rx_interrupts(void *ptr)
624} 629}
625 630
626 631
627static int scc_get_CD(void *ptr) 632static int scc_carrier_raised(struct tty_port *port)
628{ 633{
629 struct scc_port *port = ptr; 634 struct scc_port *sc = container_of(port, struct scc_port, gs.port);
630 unsigned channel = port->channel; 635 unsigned channel = sc->channel;
631 636
632 return !!(scc_last_status_reg[channel] & SR_DCD); 637 return !!(scc_last_status_reg[channel] & SR_DCD);
633} 638}
@@ -638,7 +643,7 @@ static void scc_shutdown_port(void *ptr)
638 struct scc_port *port = ptr; 643 struct scc_port *port = ptr;
639 644
640 port->gs.port.flags &= ~ GS_ACTIVE; 645 port->gs.port.flags &= ~ GS_ACTIVE;
641 if (port->gs.port.tty && port->gs.port.tty->termios->c_cflag & HUPCL) { 646 if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) {
642 scc_setsignals (port, 0, 0); 647 scc_setsignals (port, 0, 0);
643 } 648 }
644} 649}
@@ -779,7 +784,7 @@ static void scc_setsignals(struct scc_port *port, int dtr, int rts)
779 784
780static void scc_send_xchar(struct tty_struct *tty, char ch) 785static void scc_send_xchar(struct tty_struct *tty, char ch)
781{ 786{
782 struct scc_port *port = (struct scc_port *)tty->driver_data; 787 struct scc_port *port = tty->driver_data;
783 788
784 port->x_char = ch; 789 port->x_char = ch;
785 if (ch) 790 if (ch)
@@ -896,7 +901,7 @@ static int scc_open (struct tty_struct * tty, struct file * filp)
896 return retval; 901 return retval;
897 } 902 }
898 903
899 port->c_dcd = scc_get_CD (port); 904 port->c_dcd = tty_port_carrier_raised(&port->gs.port);
900 905
901 scc_enable_rx_interrupts(port); 906 scc_enable_rx_interrupts(port);
902 907
@@ -906,7 +911,7 @@ static int scc_open (struct tty_struct * tty, struct file * filp)
906 911
907static void scc_throttle (struct tty_struct * tty) 912static void scc_throttle (struct tty_struct * tty)
908{ 913{
909 struct scc_port *port = (struct scc_port *)tty->driver_data; 914 struct scc_port *port = tty->driver_data;
910 unsigned long flags; 915 unsigned long flags;
911 SCC_ACCESS_INIT(port); 916 SCC_ACCESS_INIT(port);
912 917
@@ -922,7 +927,7 @@ static void scc_throttle (struct tty_struct * tty)
922 927
923static void scc_unthrottle (struct tty_struct * tty) 928static void scc_unthrottle (struct tty_struct * tty)
924{ 929{
925 struct scc_port *port = (struct scc_port *)tty->driver_data; 930 struct scc_port *port = tty->driver_data;
926 unsigned long flags; 931 unsigned long flags;
927 SCC_ACCESS_INIT(port); 932 SCC_ACCESS_INIT(port);
928 933
@@ -945,7 +950,7 @@ static int scc_ioctl(struct tty_struct *tty, struct file *file,
945 950
946static int scc_break_ctl(struct tty_struct *tty, int break_state) 951static int scc_break_ctl(struct tty_struct *tty, int break_state)
947{ 952{
948 struct scc_port *port = (struct scc_port *)tty->driver_data; 953 struct scc_port *port = tty->driver_data;
949 unsigned long flags; 954 unsigned long flags;
950 SCC_ACCESS_INIT(port); 955 SCC_ACCESS_INIT(port);
951 956
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 008176edbd64..80014213fb53 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -819,8 +819,8 @@ static inline int resize_screen(struct vc_data *vc, int width, int height,
819 * ctrl_lock of the tty IFF a tty is passed. 819 * ctrl_lock of the tty IFF a tty is passed.
820 */ 820 */
821 821
822static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, 822static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
823 struct vc_data *vc, unsigned int cols, unsigned int lines) 823 unsigned int cols, unsigned int lines)
824{ 824{
825 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; 825 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
826 unsigned int old_cols, old_rows, old_row_size, old_screen_size; 826 unsigned int old_cols, old_rows, old_row_size, old_screen_size;
@@ -932,7 +932,7 @@ static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
932 ws.ws_row = vc->vc_rows; 932 ws.ws_row = vc->vc_rows;
933 ws.ws_col = vc->vc_cols; 933 ws.ws_col = vc->vc_cols;
934 ws.ws_ypixel = vc->vc_scan_lines; 934 ws.ws_ypixel = vc->vc_scan_lines;
935 tty_do_resize(tty, real_tty, &ws); 935 tty_do_resize(tty, &ws);
936 } 936 }
937 937
938 if (CON_IS_VISIBLE(vc)) 938 if (CON_IS_VISIBLE(vc))
@@ -954,13 +954,12 @@ static int vc_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
954 954
955int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) 955int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
956{ 956{
957 return vc_do_resize(vc->vc_tty, vc->vc_tty, vc, cols, rows); 957 return vc_do_resize(vc->vc_tty, vc, cols, rows);
958} 958}
959 959
960/** 960/**
961 * vt_resize - resize a VT 961 * vt_resize - resize a VT
962 * @tty: tty to resize 962 * @tty: tty to resize
963 * @real_tty: tty if a pty/tty pair
964 * @ws: winsize attributes 963 * @ws: winsize attributes
965 * 964 *
966 * Resize a virtual terminal. This is called by the tty layer as we 965 * Resize a virtual terminal. This is called by the tty layer as we
@@ -971,14 +970,13 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
971 * termios_mutex and the tty ctrl_lock in that order. 970 * termios_mutex and the tty ctrl_lock in that order.
972 */ 971 */
973 972
974int vt_resize(struct tty_struct *tty, struct tty_struct *real_tty, 973int vt_resize(struct tty_struct *tty, struct winsize *ws)
975 struct winsize *ws)
976{ 974{
977 struct vc_data *vc = tty->driver_data; 975 struct vc_data *vc = tty->driver_data;
978 int ret; 976 int ret;
979 977
980 acquire_console_sem(); 978 acquire_console_sem();
981 ret = vc_do_resize(tty, real_tty, vc, ws->ws_col, ws->ws_row); 979 ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row);
982 release_console_sem(); 980 release_console_sem();
983 return ret; 981 return ret;
984} 982}
@@ -2679,7 +2677,7 @@ static int con_write_room(struct tty_struct *tty)
2679{ 2677{
2680 if (tty->stopped) 2678 if (tty->stopped)
2681 return 0; 2679 return 0;
2682 return 4096; /* No limit, really; we're not buffering */ 2680 return 32768; /* No limit, really; we're not buffering */
2683} 2681}
2684 2682
2685static int con_chars_in_buffer(struct tty_struct *tty) 2683static int con_chars_in_buffer(struct tty_struct *tty)
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index 8944ce508e2f..a2dee0eb6dad 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -366,7 +366,7 @@ do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_
366int vt_ioctl(struct tty_struct *tty, struct file * file, 366int vt_ioctl(struct tty_struct *tty, struct file * file,
367 unsigned int cmd, unsigned long arg) 367 unsigned int cmd, unsigned long arg)
368{ 368{
369 struct vc_data *vc = (struct vc_data *)tty->driver_data; 369 struct vc_data *vc = tty->driver_data;
370 struct console_font_op op; /* used in multiple places here */ 370 struct console_font_op op; /* used in multiple places here */
371 struct kbd_struct * kbd; 371 struct kbd_struct * kbd;
372 unsigned int console; 372 unsigned int console;
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 9f7896a25f1b..c4918b86ed19 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -3,6 +3,8 @@
3 * Driver for Option High Speed Mobile Devices. 3 * Driver for Option High Speed Mobile Devices.
4 * 4 *
5 * Copyright (C) 2008 Option International 5 * Copyright (C) 2008 Option International
6 * Filip Aben <f.aben@option.com>
7 * Denis Joseph Barrow <d.barow@option.com>
6 * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd) 8 * Copyright (C) 2007 Andrew Bird (Sphere Systems Ltd)
7 * <ajb@spheresystems.co.uk> 9 * <ajb@spheresystems.co.uk>
8 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de> 10 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
@@ -39,8 +41,11 @@
39 * port is opened, as this have a huge impact on the network port 41 * port is opened, as this have a huge impact on the network port
40 * throughput. 42 * throughput.
41 * 43 *
42 * Interface 2: Standard modem interface - circuit switched interface, should 44 * Interface 2: Standard modem interface - circuit switched interface, this
43 * not be used. 45 * can be used to make a standard ppp connection however it
46 * should not be used in conjunction with the IP network interface
47 * enabled for USB performance reasons i.e. if using this set
48 * ideally disable_net=1.
44 * 49 *
45 *****************************************************************************/ 50 *****************************************************************************/
46 51
@@ -63,6 +68,8 @@
63#include <linux/usb/cdc.h> 68#include <linux/usb/cdc.h>
64#include <net/arp.h> 69#include <net/arp.h>
65#include <asm/byteorder.h> 70#include <asm/byteorder.h>
71#include <linux/serial_core.h>
72#include <linux/serial.h>
66 73
67 74
68#define DRIVER_VERSION "1.2" 75#define DRIVER_VERSION "1.2"
@@ -182,6 +189,41 @@ enum rx_ctrl_state{
182 RX_PENDING 189 RX_PENDING
183}; 190};
184 191
192#define BM_REQUEST_TYPE (0xa1)
193#define B_NOTIFICATION (0x20)
194#define W_VALUE (0x0)
195#define W_INDEX (0x2)
196#define W_LENGTH (0x2)
197
198#define B_OVERRUN (0x1<<6)
199#define B_PARITY (0x1<<5)
200#define B_FRAMING (0x1<<4)
201#define B_RING_SIGNAL (0x1<<3)
202#define B_BREAK (0x1<<2)
203#define B_TX_CARRIER (0x1<<1)
204#define B_RX_CARRIER (0x1<<0)
205
206struct hso_serial_state_notification {
207 u8 bmRequestType;
208 u8 bNotification;
209 u16 wValue;
210 u16 wIndex;
211 u16 wLength;
212 u16 UART_state_bitmap;
213} __attribute__((packed));
214
215struct hso_tiocmget {
216 struct mutex mutex;
217 wait_queue_head_t waitq;
218 int intr_completed;
219 struct usb_endpoint_descriptor *endp;
220 struct urb *urb;
221 struct hso_serial_state_notification serial_state_notification;
222 u16 prev_UART_state_bitmap;
223 struct uart_icount icount;
224};
225
226
185struct hso_serial { 227struct hso_serial {
186 struct hso_device *parent; 228 struct hso_device *parent;
187 int magic; 229 int magic;
@@ -219,6 +261,7 @@ struct hso_serial {
219 spinlock_t serial_lock; 261 spinlock_t serial_lock;
220 262
221 int (*write_data) (struct hso_serial *serial); 263 int (*write_data) (struct hso_serial *serial);
264 struct hso_tiocmget *tiocmget;
222 /* Hacks required to get flow control 265 /* Hacks required to get flow control
223 * working on the serial receive buffers 266 * working on the serial receive buffers
224 * so as not to drop characters on the floor. 267 * so as not to drop characters on the floor.
@@ -305,7 +348,7 @@ static void async_get_intf(struct work_struct *data);
305static void async_put_intf(struct work_struct *data); 348static void async_put_intf(struct work_struct *data);
306static int hso_put_activity(struct hso_device *hso_dev); 349static int hso_put_activity(struct hso_device *hso_dev);
307static int hso_get_activity(struct hso_device *hso_dev); 350static int hso_get_activity(struct hso_device *hso_dev);
308 351static void tiocmget_intr_callback(struct urb *urb);
309/*****************************************************************************/ 352/*****************************************************************************/
310/* Helping functions */ 353/* Helping functions */
311/*****************************************************************************/ 354/*****************************************************************************/
@@ -362,8 +405,6 @@ static struct tty_driver *tty_drv;
362static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS]; 405static struct hso_device *serial_table[HSO_SERIAL_TTY_MINORS];
363static struct hso_device *network_table[HSO_MAX_NET_DEVICES]; 406static struct hso_device *network_table[HSO_MAX_NET_DEVICES];
364static spinlock_t serial_table_lock; 407static spinlock_t serial_table_lock;
365static struct ktermios *hso_serial_termios[HSO_SERIAL_TTY_MINORS];
366static struct ktermios *hso_serial_termios_locked[HSO_SERIAL_TTY_MINORS];
367 408
368static const s32 default_port_spec[] = { 409static const s32 default_port_spec[] = {
369 HSO_INTF_MUX | HSO_PORT_NETWORK, 410 HSO_INTF_MUX | HSO_PORT_NETWORK,
@@ -1009,23 +1050,11 @@ static void read_bulk_callback(struct urb *urb)
1009 1050
1010/* Serial driver functions */ 1051/* Serial driver functions */
1011 1052
1012static void _hso_serial_set_termios(struct tty_struct *tty, 1053static void hso_init_termios(struct ktermios *termios)
1013 struct ktermios *old)
1014{ 1054{
1015 struct hso_serial *serial = get_serial_by_tty(tty);
1016 struct ktermios *termios;
1017
1018 if ((!tty) || (!tty->termios) || (!serial)) {
1019 printk(KERN_ERR "%s: no tty structures", __func__);
1020 return;
1021 }
1022
1023 D4("port %d", serial->minor);
1024
1025 /* 1055 /*
1026 * The default requirements for this device are: 1056 * The default requirements for this device are:
1027 */ 1057 */
1028 termios = tty->termios;
1029 termios->c_iflag &= 1058 termios->c_iflag &=
1030 ~(IGNBRK /* disable ignore break */ 1059 ~(IGNBRK /* disable ignore break */
1031 | BRKINT /* disable break causes interrupt */ 1060 | BRKINT /* disable break causes interrupt */
@@ -1057,15 +1086,38 @@ static void _hso_serial_set_termios(struct tty_struct *tty,
1057 termios->c_cflag |= CS8; /* character size 8 bits */ 1086 termios->c_cflag |= CS8; /* character size 8 bits */
1058 1087
1059 /* baud rate 115200 */ 1088 /* baud rate 115200 */
1060 tty_encode_baud_rate(serial->tty, 115200, 115200); 1089 tty_termios_encode_baud_rate(termios, 115200, 115200);
1090}
1091
1092static void _hso_serial_set_termios(struct tty_struct *tty,
1093 struct ktermios *old)
1094{
1095 struct hso_serial *serial = get_serial_by_tty(tty);
1096 struct ktermios *termios;
1097
1098 if (!serial) {
1099 printk(KERN_ERR "%s: no tty structures", __func__);
1100 return;
1101 }
1102
1103 D4("port %d", serial->minor);
1061 1104
1062 /* 1105 /*
1063 * Force low_latency on; otherwise the pushes are scheduled; 1106 * Fix up unsupported bits
1064 * this is bad as it opens up the possibility of dropping bytes
1065 * on the floor. We don't want to drop bytes on the floor. :)
1066 */ 1107 */
1067 serial->tty->low_latency = 1; 1108 termios = tty->termios;
1068 return; 1109 termios->c_iflag &= ~IXON; /* disable enable XON/XOFF flow control */
1110
1111 termios->c_cflag &=
1112 ~(CSIZE /* no size */
1113 | PARENB /* disable parity bit */
1114 | CBAUD /* clear current baud rate */
1115 | CBAUDEX); /* clear current buad rate */
1116
1117 termios->c_cflag |= CS8; /* character size 8 bits */
1118
1119 /* baud rate 115200 */
1120 tty_encode_baud_rate(tty, 115200, 115200);
1069} 1121}
1070 1122
1071static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb) 1123static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb)
@@ -1228,6 +1280,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1228 1280
1229 /* sanity check */ 1281 /* sanity check */
1230 if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) { 1282 if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) {
1283 WARN_ON(1);
1231 tty->driver_data = NULL; 1284 tty->driver_data = NULL;
1232 D1("Failed to open port"); 1285 D1("Failed to open port");
1233 return -ENODEV; 1286 return -ENODEV;
@@ -1242,8 +1295,10 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1242 kref_get(&serial->parent->ref); 1295 kref_get(&serial->parent->ref);
1243 1296
1244 /* setup */ 1297 /* setup */
1298 spin_lock_irq(&serial->serial_lock);
1245 tty->driver_data = serial; 1299 tty->driver_data = serial;
1246 serial->tty = tty; 1300 serial->tty = tty_kref_get(tty);
1301 spin_unlock_irq(&serial->serial_lock);
1247 1302
1248 /* check for port already opened, if not set the termios */ 1303 /* check for port already opened, if not set the termios */
1249 serial->open_count++; 1304 serial->open_count++;
@@ -1285,6 +1340,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1285 1340
1286 D1("Closing serial port"); 1341 D1("Closing serial port");
1287 1342
1343 /* Open failed, no close cleanup required */
1344 if (serial == NULL)
1345 return;
1346
1288 mutex_lock(&serial->parent->mutex); 1347 mutex_lock(&serial->parent->mutex);
1289 usb_gone = serial->parent->usb_gone; 1348 usb_gone = serial->parent->usb_gone;
1290 1349
@@ -1297,10 +1356,13 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1297 kref_put(&serial->parent->ref, hso_serial_ref_free); 1356 kref_put(&serial->parent->ref, hso_serial_ref_free);
1298 if (serial->open_count <= 0) { 1357 if (serial->open_count <= 0) {
1299 serial->open_count = 0; 1358 serial->open_count = 0;
1300 if (serial->tty) { 1359 spin_lock_irq(&serial->serial_lock);
1360 if (serial->tty == tty) {
1301 serial->tty->driver_data = NULL; 1361 serial->tty->driver_data = NULL;
1302 serial->tty = NULL; 1362 serial->tty = NULL;
1363 tty_kref_put(tty);
1303 } 1364 }
1365 spin_unlock_irq(&serial->serial_lock);
1304 if (!usb_gone) 1366 if (!usb_gone)
1305 hso_stop_serial_device(serial->parent); 1367 hso_stop_serial_device(serial->parent);
1306 tasklet_kill(&serial->unthrottle_tasklet); 1368 tasklet_kill(&serial->unthrottle_tasklet);
@@ -1400,25 +1462,217 @@ static int hso_serial_chars_in_buffer(struct tty_struct *tty)
1400 1462
1401 return chars; 1463 return chars;
1402} 1464}
1465int tiocmget_submit_urb(struct hso_serial *serial,
1466 struct hso_tiocmget *tiocmget,
1467 struct usb_device *usb)
1468{
1469 int result;
1470
1471 if (serial->parent->usb_gone)
1472 return -ENODEV;
1473 usb_fill_int_urb(tiocmget->urb, usb,
1474 usb_rcvintpipe(usb,
1475 tiocmget->endp->
1476 bEndpointAddress & 0x7F),
1477 &tiocmget->serial_state_notification,
1478 sizeof(struct hso_serial_state_notification),
1479 tiocmget_intr_callback, serial,
1480 tiocmget->endp->bInterval);
1481 result = usb_submit_urb(tiocmget->urb, GFP_ATOMIC);
1482 if (result) {
1483 dev_warn(&usb->dev, "%s usb_submit_urb failed %d\n", __func__,
1484 result);
1485 }
1486 return result;
1487
1488}
1489
1490static void tiocmget_intr_callback(struct urb *urb)
1491{
1492 struct hso_serial *serial = urb->context;
1493 struct hso_tiocmget *tiocmget;
1494 int status = urb->status;
1495 u16 UART_state_bitmap, prev_UART_state_bitmap;
1496 struct uart_icount *icount;
1497 struct hso_serial_state_notification *serial_state_notification;
1498 struct usb_device *usb;
1499
1500 /* Sanity checks */
1501 if (!serial)
1502 return;
1503 if (status) {
1504 log_usb_status(status, __func__);
1505 return;
1506 }
1507 tiocmget = serial->tiocmget;
1508 if (!tiocmget)
1509 return;
1510 usb = serial->parent->usb;
1511 serial_state_notification = &tiocmget->serial_state_notification;
1512 if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE ||
1513 serial_state_notification->bNotification != B_NOTIFICATION ||
1514 le16_to_cpu(serial_state_notification->wValue) != W_VALUE ||
1515 le16_to_cpu(serial_state_notification->wIndex) != W_INDEX ||
1516 le16_to_cpu(serial_state_notification->wLength) != W_LENGTH) {
1517 dev_warn(&usb->dev,
1518 "hso received invalid serial state notification\n");
1519 DUMP(serial_state_notification,
1520 sizeof(hso_serial_state_notifation))
1521 } else {
1522
1523 UART_state_bitmap = le16_to_cpu(serial_state_notification->
1524 UART_state_bitmap);
1525 prev_UART_state_bitmap = tiocmget->prev_UART_state_bitmap;
1526 icount = &tiocmget->icount;
1527 spin_lock(&serial->serial_lock);
1528 if ((UART_state_bitmap & B_OVERRUN) !=
1529 (prev_UART_state_bitmap & B_OVERRUN))
1530 icount->parity++;
1531 if ((UART_state_bitmap & B_PARITY) !=
1532 (prev_UART_state_bitmap & B_PARITY))
1533 icount->parity++;
1534 if ((UART_state_bitmap & B_FRAMING) !=
1535 (prev_UART_state_bitmap & B_FRAMING))
1536 icount->frame++;
1537 if ((UART_state_bitmap & B_RING_SIGNAL) &&
1538 !(prev_UART_state_bitmap & B_RING_SIGNAL))
1539 icount->rng++;
1540 if ((UART_state_bitmap & B_BREAK) !=
1541 (prev_UART_state_bitmap & B_BREAK))
1542 icount->brk++;
1543 if ((UART_state_bitmap & B_TX_CARRIER) !=
1544 (prev_UART_state_bitmap & B_TX_CARRIER))
1545 icount->dsr++;
1546 if ((UART_state_bitmap & B_RX_CARRIER) !=
1547 (prev_UART_state_bitmap & B_RX_CARRIER))
1548 icount->dcd++;
1549 tiocmget->prev_UART_state_bitmap = UART_state_bitmap;
1550 spin_unlock(&serial->serial_lock);
1551 tiocmget->intr_completed = 1;
1552 wake_up_interruptible(&tiocmget->waitq);
1553 }
1554 memset(serial_state_notification, 0,
1555 sizeof(struct hso_serial_state_notification));
1556 tiocmget_submit_urb(serial,
1557 tiocmget,
1558 serial->parent->usb);
1559}
1560
1561/*
1562 * next few functions largely stolen from drivers/serial/serial_core.c
1563 */
1564/* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1565 * - mask passed in arg for lines of interest
1566 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1567 * Caller should use TIOCGICOUNT to see which one it was
1568 */
1569static int
1570hso_wait_modem_status(struct hso_serial *serial, unsigned long arg)
1571{
1572 DECLARE_WAITQUEUE(wait, current);
1573 struct uart_icount cprev, cnow;
1574 struct hso_tiocmget *tiocmget;
1575 int ret;
1576
1577 tiocmget = serial->tiocmget;
1578 if (!tiocmget)
1579 return -ENOENT;
1580 /*
1581 * note the counters on entry
1582 */
1583 spin_lock_irq(&serial->serial_lock);
1584 memcpy(&cprev, &tiocmget->icount, sizeof(struct uart_icount));
1585 spin_unlock_irq(&serial->serial_lock);
1586 add_wait_queue(&tiocmget->waitq, &wait);
1587 for (;;) {
1588 spin_lock_irq(&serial->serial_lock);
1589 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
1590 spin_unlock_irq(&serial->serial_lock);
1591 set_current_state(TASK_INTERRUPTIBLE);
1592 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1593 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1594 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd))) {
1595 ret = 0;
1596 break;
1597 }
1598 schedule();
1599 /* see if a signal did it */
1600 if (signal_pending(current)) {
1601 ret = -ERESTARTSYS;
1602 break;
1603 }
1604 cprev = cnow;
1605 }
1606 current->state = TASK_RUNNING;
1607 remove_wait_queue(&tiocmget->waitq, &wait);
1608
1609 return ret;
1610}
1611
1612/*
1613 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1614 * Return: write counters to the user passed counter struct
1615 * NB: both 1->0 and 0->1 transitions are counted except for
1616 * RI where only 0->1 is counted.
1617 */
1618static int hso_get_count(struct hso_serial *serial,
1619 struct serial_icounter_struct __user *icnt)
1620{
1621 struct serial_icounter_struct icount;
1622 struct uart_icount cnow;
1623 struct hso_tiocmget *tiocmget = serial->tiocmget;
1624
1625 if (!tiocmget)
1626 return -ENOENT;
1627 spin_lock_irq(&serial->serial_lock);
1628 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount));
1629 spin_unlock_irq(&serial->serial_lock);
1630
1631 icount.cts = cnow.cts;
1632 icount.dsr = cnow.dsr;
1633 icount.rng = cnow.rng;
1634 icount.dcd = cnow.dcd;
1635 icount.rx = cnow.rx;
1636 icount.tx = cnow.tx;
1637 icount.frame = cnow.frame;
1638 icount.overrun = cnow.overrun;
1639 icount.parity = cnow.parity;
1640 icount.brk = cnow.brk;
1641 icount.buf_overrun = cnow.buf_overrun;
1642
1643 return copy_to_user(icnt, &icount, sizeof(icount)) ? -EFAULT : 0;
1644}
1645
1403 1646
1404static int hso_serial_tiocmget(struct tty_struct *tty, struct file *file) 1647static int hso_serial_tiocmget(struct tty_struct *tty, struct file *file)
1405{ 1648{
1406 unsigned int value; 1649 int retval;
1407 struct hso_serial *serial = get_serial_by_tty(tty); 1650 struct hso_serial *serial = get_serial_by_tty(tty);
1408 unsigned long flags; 1651 struct hso_tiocmget *tiocmget;
1652 u16 UART_state_bitmap;
1409 1653
1410 /* sanity check */ 1654 /* sanity check */
1411 if (!serial) { 1655 if (!serial) {
1412 D1("no tty structures"); 1656 D1("no tty structures");
1413 return -EINVAL; 1657 return -EINVAL;
1414 } 1658 }
1415 1659 spin_lock_irq(&serial->serial_lock);
1416 spin_lock_irqsave(&serial->serial_lock, flags); 1660 retval = ((serial->rts_state) ? TIOCM_RTS : 0) |
1417 value = ((serial->rts_state) ? TIOCM_RTS : 0) |
1418 ((serial->dtr_state) ? TIOCM_DTR : 0); 1661 ((serial->dtr_state) ? TIOCM_DTR : 0);
1419 spin_unlock_irqrestore(&serial->serial_lock, flags); 1662 tiocmget = serial->tiocmget;
1663 if (tiocmget) {
1420 1664
1421 return value; 1665 UART_state_bitmap = le16_to_cpu(
1666 tiocmget->prev_UART_state_bitmap);
1667 if (UART_state_bitmap & B_RING_SIGNAL)
1668 retval |= TIOCM_RNG;
1669 if (UART_state_bitmap & B_RX_CARRIER)
1670 retval |= TIOCM_CD;
1671 if (UART_state_bitmap & B_TX_CARRIER)
1672 retval |= TIOCM_DSR;
1673 }
1674 spin_unlock_irq(&serial->serial_lock);
1675 return retval;
1422} 1676}
1423 1677
1424static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file, 1678static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file,
@@ -1460,6 +1714,32 @@ static int hso_serial_tiocmset(struct tty_struct *tty, struct file *file,
1460 USB_CTRL_SET_TIMEOUT); 1714 USB_CTRL_SET_TIMEOUT);
1461} 1715}
1462 1716
1717static int hso_serial_ioctl(struct tty_struct *tty, struct file *file,
1718 unsigned int cmd, unsigned long arg)
1719{
1720 struct hso_serial *serial = get_serial_by_tty(tty);
1721 void __user *uarg = (void __user *)arg;
1722 int ret = 0;
1723 D4("IOCTL cmd: %d, arg: %ld", cmd, arg);
1724
1725 if (!serial)
1726 return -ENODEV;
1727 switch (cmd) {
1728 case TIOCMIWAIT:
1729 ret = hso_wait_modem_status(serial, arg);
1730 break;
1731
1732 case TIOCGICOUNT:
1733 ret = hso_get_count(serial, uarg);
1734 break;
1735 default:
1736 ret = -ENOIOCTLCMD;
1737 break;
1738 }
1739 return ret;
1740}
1741
1742
1463/* starts a transmit */ 1743/* starts a transmit */
1464static void hso_kick_transmit(struct hso_serial *serial) 1744static void hso_kick_transmit(struct hso_serial *serial)
1465{ 1745{
@@ -1653,6 +1933,7 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
1653{ 1933{
1654 struct hso_serial *serial = urb->context; 1934 struct hso_serial *serial = urb->context;
1655 int status = urb->status; 1935 int status = urb->status;
1936 struct tty_struct *tty;
1656 1937
1657 /* sanity check */ 1938 /* sanity check */
1658 if (!serial) { 1939 if (!serial) {
@@ -1662,14 +1943,18 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
1662 1943
1663 spin_lock(&serial->serial_lock); 1944 spin_lock(&serial->serial_lock);
1664 serial->tx_urb_used = 0; 1945 serial->tx_urb_used = 0;
1946 tty = tty_kref_get(serial->tty);
1665 spin_unlock(&serial->serial_lock); 1947 spin_unlock(&serial->serial_lock);
1666 if (status) { 1948 if (status) {
1667 log_usb_status(status, __func__); 1949 log_usb_status(status, __func__);
1950 tty_kref_put(tty);
1668 return; 1951 return;
1669 } 1952 }
1670 hso_put_activity(serial->parent); 1953 hso_put_activity(serial->parent);
1671 if (serial->tty) 1954 if (tty) {
1672 tty_wakeup(serial->tty); 1955 tty_wakeup(tty);
1956 tty_kref_put(tty);
1957 }
1673 hso_kick_transmit(serial); 1958 hso_kick_transmit(serial);
1674 1959
1675 D1(" "); 1960 D1(" ");
@@ -1706,6 +1991,7 @@ static void ctrl_callback(struct urb *urb)
1706 struct hso_serial *serial = urb->context; 1991 struct hso_serial *serial = urb->context;
1707 struct usb_ctrlrequest *req; 1992 struct usb_ctrlrequest *req;
1708 int status = urb->status; 1993 int status = urb->status;
1994 struct tty_struct *tty;
1709 1995
1710 /* sanity check */ 1996 /* sanity check */
1711 if (!serial) 1997 if (!serial)
@@ -1713,9 +1999,11 @@ static void ctrl_callback(struct urb *urb)
1713 1999
1714 spin_lock(&serial->serial_lock); 2000 spin_lock(&serial->serial_lock);
1715 serial->tx_urb_used = 0; 2001 serial->tx_urb_used = 0;
2002 tty = tty_kref_get(serial->tty);
1716 spin_unlock(&serial->serial_lock); 2003 spin_unlock(&serial->serial_lock);
1717 if (status) { 2004 if (status) {
1718 log_usb_status(status, __func__); 2005 log_usb_status(status, __func__);
2006 tty_kref_put(tty);
1719 return; 2007 return;
1720 } 2008 }
1721 2009
@@ -1734,25 +2022,31 @@ static void ctrl_callback(struct urb *urb)
1734 spin_unlock(&serial->serial_lock); 2022 spin_unlock(&serial->serial_lock);
1735 } else { 2023 } else {
1736 hso_put_activity(serial->parent); 2024 hso_put_activity(serial->parent);
1737 if (serial->tty) 2025 if (tty)
1738 tty_wakeup(serial->tty); 2026 tty_wakeup(tty);
1739 /* response to a write command */ 2027 /* response to a write command */
1740 hso_kick_transmit(serial); 2028 hso_kick_transmit(serial);
1741 } 2029 }
2030 tty_kref_put(tty);
1742} 2031}
1743 2032
1744/* handle RX data for serial port */ 2033/* handle RX data for serial port */
1745static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) 2034static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
1746{ 2035{
1747 struct tty_struct *tty = serial->tty; 2036 struct tty_struct *tty;
1748 int write_length_remaining = 0; 2037 int write_length_remaining = 0;
1749 int curr_write_len; 2038 int curr_write_len;
2039
1750 /* Sanity check */ 2040 /* Sanity check */
1751 if (urb == NULL || serial == NULL) { 2041 if (urb == NULL || serial == NULL) {
1752 D1("serial = NULL"); 2042 D1("serial = NULL");
1753 return -2; 2043 return -2;
1754 } 2044 }
1755 2045
2046 spin_lock(&serial->serial_lock);
2047 tty = tty_kref_get(serial->tty);
2048 spin_unlock(&serial->serial_lock);
2049
1756 /* Push data to tty */ 2050 /* Push data to tty */
1757 if (tty) { 2051 if (tty) {
1758 write_length_remaining = urb->actual_length - 2052 write_length_remaining = urb->actual_length -
@@ -1774,6 +2068,7 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
1774 serial->curr_rx_urb_offset = 0; 2068 serial->curr_rx_urb_offset = 0;
1775 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; 2069 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
1776 } 2070 }
2071 tty_kref_put(tty);
1777 return write_length_remaining; 2072 return write_length_remaining;
1778} 2073}
1779 2074
@@ -1922,7 +2217,10 @@ static int hso_start_serial_device(struct hso_device *hso_dev, gfp_t flags)
1922 serial->shared_int->use_count++; 2217 serial->shared_int->use_count++;
1923 mutex_unlock(&serial->shared_int->shared_int_lock); 2218 mutex_unlock(&serial->shared_int->shared_int_lock);
1924 } 2219 }
1925 2220 if (serial->tiocmget)
2221 tiocmget_submit_urb(serial,
2222 serial->tiocmget,
2223 serial->parent->usb);
1926 return result; 2224 return result;
1927} 2225}
1928 2226
@@ -1930,6 +2228,7 @@ static int hso_stop_serial_device(struct hso_device *hso_dev)
1930{ 2228{
1931 int i; 2229 int i;
1932 struct hso_serial *serial = dev2ser(hso_dev); 2230 struct hso_serial *serial = dev2ser(hso_dev);
2231 struct hso_tiocmget *tiocmget;
1933 2232
1934 if (!serial) 2233 if (!serial)
1935 return -ENODEV; 2234 return -ENODEV;
@@ -1958,6 +2257,11 @@ static int hso_stop_serial_device(struct hso_device *hso_dev)
1958 } 2257 }
1959 mutex_unlock(&serial->shared_int->shared_int_lock); 2258 mutex_unlock(&serial->shared_int->shared_int_lock);
1960 } 2259 }
2260 tiocmget = serial->tiocmget;
2261 if (tiocmget) {
2262 wake_up_interruptible(&tiocmget->waitq);
2263 usb_kill_urb(tiocmget->urb);
2264 }
1961 2265
1962 return 0; 2266 return 0;
1963} 2267}
@@ -2304,6 +2608,20 @@ exit:
2304 return NULL; 2608 return NULL;
2305} 2609}
2306 2610
2611static void hso_free_tiomget(struct hso_serial *serial)
2612{
2613 struct hso_tiocmget *tiocmget = serial->tiocmget;
2614 if (tiocmget) {
2615 kfree(tiocmget);
2616 if (tiocmget->urb) {
2617 usb_free_urb(tiocmget->urb);
2618 tiocmget->urb = NULL;
2619 }
2620 serial->tiocmget = NULL;
2621
2622 }
2623}
2624
2307/* Frees an AT channel ( goes for both mux and non-mux ) */ 2625/* Frees an AT channel ( goes for both mux and non-mux ) */
2308static void hso_free_serial_device(struct hso_device *hso_dev) 2626static void hso_free_serial_device(struct hso_device *hso_dev)
2309{ 2627{
@@ -2322,6 +2640,7 @@ static void hso_free_serial_device(struct hso_device *hso_dev)
2322 else 2640 else
2323 mutex_unlock(&serial->shared_int->shared_int_lock); 2641 mutex_unlock(&serial->shared_int->shared_int_lock);
2324 } 2642 }
2643 hso_free_tiomget(serial);
2325 kfree(serial); 2644 kfree(serial);
2326 hso_free_device(hso_dev); 2645 hso_free_device(hso_dev);
2327} 2646}
@@ -2333,6 +2652,7 @@ static struct hso_device *hso_create_bulk_serial_device(
2333 struct hso_device *hso_dev; 2652 struct hso_device *hso_dev;
2334 struct hso_serial *serial; 2653 struct hso_serial *serial;
2335 int num_urbs; 2654 int num_urbs;
2655 struct hso_tiocmget *tiocmget;
2336 2656
2337 hso_dev = hso_create_device(interface, port); 2657 hso_dev = hso_create_device(interface, port);
2338 if (!hso_dev) 2658 if (!hso_dev)
@@ -2345,8 +2665,27 @@ static struct hso_device *hso_create_bulk_serial_device(
2345 serial->parent = hso_dev; 2665 serial->parent = hso_dev;
2346 hso_dev->port_data.dev_serial = serial; 2666 hso_dev->port_data.dev_serial = serial;
2347 2667
2348 if (port & HSO_PORT_MODEM) 2668 if ((port & HSO_PORT_MASK) == HSO_PORT_MODEM) {
2349 num_urbs = 2; 2669 num_urbs = 2;
2670 serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget),
2671 GFP_KERNEL);
2672 /* it isn't going to break our heart if serial->tiocmget
2673 * allocation fails don't bother checking this.
2674 */
2675 if (serial->tiocmget) {
2676 tiocmget = serial->tiocmget;
2677 tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
2678 if (tiocmget->urb) {
2679 mutex_init(&tiocmget->mutex);
2680 init_waitqueue_head(&tiocmget->waitq);
2681 tiocmget->endp = hso_get_ep(
2682 interface,
2683 USB_ENDPOINT_XFER_INT,
2684 USB_DIR_IN);
2685 } else
2686 hso_free_tiomget(serial);
2687 }
2688 }
2350 else 2689 else
2351 num_urbs = 1; 2690 num_urbs = 1;
2352 2691
@@ -2382,6 +2721,7 @@ static struct hso_device *hso_create_bulk_serial_device(
2382exit2: 2721exit2:
2383 hso_serial_common_free(serial); 2722 hso_serial_common_free(serial);
2384exit: 2723exit:
2724 hso_free_tiomget(serial);
2385 kfree(serial); 2725 kfree(serial);
2386 hso_free_device(hso_dev); 2726 hso_free_device(hso_dev);
2387 return NULL; 2727 return NULL;
@@ -2786,15 +3126,20 @@ static void hso_serial_ref_free(struct kref *ref)
2786static void hso_free_interface(struct usb_interface *interface) 3126static void hso_free_interface(struct usb_interface *interface)
2787{ 3127{
2788 struct hso_serial *hso_dev; 3128 struct hso_serial *hso_dev;
3129 struct tty_struct *tty;
2789 int i; 3130 int i;
2790 3131
2791 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { 3132 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
2792 if (serial_table[i] 3133 if (serial_table[i]
2793 && (serial_table[i]->interface == interface)) { 3134 && (serial_table[i]->interface == interface)) {
2794 hso_dev = dev2ser(serial_table[i]); 3135 hso_dev = dev2ser(serial_table[i]);
2795 if (hso_dev->tty) 3136 spin_lock_irq(&hso_dev->serial_lock);
2796 tty_hangup(hso_dev->tty); 3137 tty = tty_kref_get(hso_dev->tty);
3138 spin_unlock_irq(&hso_dev->serial_lock);
3139 if (tty)
3140 tty_hangup(tty);
2797 mutex_lock(&hso_dev->parent->mutex); 3141 mutex_lock(&hso_dev->parent->mutex);
3142 tty_kref_put(tty);
2798 hso_dev->parent->usb_gone = 1; 3143 hso_dev->parent->usb_gone = 1;
2799 mutex_unlock(&hso_dev->parent->mutex); 3144 mutex_unlock(&hso_dev->parent->mutex);
2800 kref_put(&serial_table[i]->ref, hso_serial_ref_free); 3145 kref_put(&serial_table[i]->ref, hso_serial_ref_free);
@@ -2887,6 +3232,7 @@ static const struct tty_operations hso_serial_ops = {
2887 .close = hso_serial_close, 3232 .close = hso_serial_close,
2888 .write = hso_serial_write, 3233 .write = hso_serial_write,
2889 .write_room = hso_serial_write_room, 3234 .write_room = hso_serial_write_room,
3235 .ioctl = hso_serial_ioctl,
2890 .set_termios = hso_serial_set_termios, 3236 .set_termios = hso_serial_set_termios,
2891 .chars_in_buffer = hso_serial_chars_in_buffer, 3237 .chars_in_buffer = hso_serial_chars_in_buffer,
2892 .tiocmget = hso_serial_tiocmget, 3238 .tiocmget = hso_serial_tiocmget,
@@ -2939,9 +3285,7 @@ static int __init hso_init(void)
2939 tty_drv->subtype = SERIAL_TYPE_NORMAL; 3285 tty_drv->subtype = SERIAL_TYPE_NORMAL;
2940 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 3286 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2941 tty_drv->init_termios = tty_std_termios; 3287 tty_drv->init_termios = tty_std_termios;
2942 tty_drv->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 3288 hso_init_termios(&tty_drv->init_termios);
2943 tty_drv->termios = hso_serial_termios;
2944 tty_drv->termios_locked = hso_serial_termios_locked;
2945 tty_set_operations(tty_drv, &hso_serial_ops); 3289 tty_set_operations(tty_drv, &hso_serial_ops);
2946 3290
2947 /* register the tty driver */ 3291 /* register the tty driver */
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 303272af386e..daa00567bc44 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -279,6 +279,13 @@ static const struct serial8250_config uart_config[] = {
279 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 279 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
280 .flags = UART_CAP_FIFO, 280 .flags = UART_CAP_FIFO,
281 }, 281 },
282 [PORT_OCTEON] = {
283 .name = "OCTEON",
284 .fifo_size = 64,
285 .tx_loadsz = 64,
286 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
287 .flags = UART_CAP_FIFO,
288 },
282}; 289};
283 290
284#if defined (CONFIG_SERIAL_8250_AU1X00) 291#if defined (CONFIG_SERIAL_8250_AU1X00)
@@ -303,16 +310,16 @@ static const u8 au_io_out_map[] = {
303}; 310};
304 311
305/* sane hardware needs no mapping */ 312/* sane hardware needs no mapping */
306static inline int map_8250_in_reg(struct uart_8250_port *up, int offset) 313static inline int map_8250_in_reg(struct uart_port *p, int offset)
307{ 314{
308 if (up->port.iotype != UPIO_AU) 315 if (p->iotype != UPIO_AU)
309 return offset; 316 return offset;
310 return au_io_in_map[offset]; 317 return au_io_in_map[offset];
311} 318}
312 319
313static inline int map_8250_out_reg(struct uart_8250_port *up, int offset) 320static inline int map_8250_out_reg(struct uart_port *p, int offset)
314{ 321{
315 if (up->port.iotype != UPIO_AU) 322 if (p->iotype != UPIO_AU)
316 return offset; 323 return offset;
317 return au_io_out_map[offset]; 324 return au_io_out_map[offset];
318} 325}
@@ -341,16 +348,16 @@ static const u8
341 [UART_SCR] = 0x2c 348 [UART_SCR] = 0x2c
342 }; 349 };
343 350
344static inline int map_8250_in_reg(struct uart_8250_port *up, int offset) 351static inline int map_8250_in_reg(struct uart_port *p, int offset)
345{ 352{
346 if (up->port.iotype != UPIO_RM9000) 353 if (p->iotype != UPIO_RM9000)
347 return offset; 354 return offset;
348 return regmap_in[offset]; 355 return regmap_in[offset];
349} 356}
350 357
351static inline int map_8250_out_reg(struct uart_8250_port *up, int offset) 358static inline int map_8250_out_reg(struct uart_port *p, int offset)
352{ 359{
353 if (up->port.iotype != UPIO_RM9000) 360 if (p->iotype != UPIO_RM9000)
354 return offset; 361 return offset;
355 return regmap_out[offset]; 362 return regmap_out[offset];
356} 363}
@@ -363,108 +370,170 @@ static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
363 370
364#endif 371#endif
365 372
366static unsigned int serial_in(struct uart_8250_port *up, int offset) 373static unsigned int hub6_serial_in(struct uart_port *p, int offset)
367{ 374{
368 unsigned int tmp; 375 offset = map_8250_in_reg(p, offset) << p->regshift;
369 offset = map_8250_in_reg(up, offset) << up->port.regshift; 376 outb(p->hub6 - 1 + offset, p->iobase);
377 return inb(p->iobase + 1);
378}
370 379
371 switch (up->port.iotype) { 380static void hub6_serial_out(struct uart_port *p, int offset, int value)
372 case UPIO_HUB6: 381{
373 outb(up->port.hub6 - 1 + offset, up->port.iobase); 382 offset = map_8250_out_reg(p, offset) << p->regshift;
374 return inb(up->port.iobase + 1); 383 outb(p->hub6 - 1 + offset, p->iobase);
384 outb(value, p->iobase + 1);
385}
375 386
376 case UPIO_MEM: 387static unsigned int mem_serial_in(struct uart_port *p, int offset)
377 case UPIO_DWAPB: 388{
378 return readb(up->port.membase + offset); 389 offset = map_8250_in_reg(p, offset) << p->regshift;
390 return readb(p->membase + offset);
391}
379 392
380 case UPIO_RM9000: 393static void mem_serial_out(struct uart_port *p, int offset, int value)
381 case UPIO_MEM32: 394{
382 return readl(up->port.membase + offset); 395 offset = map_8250_out_reg(p, offset) << p->regshift;
396 writeb(value, p->membase + offset);
397}
398
399static void mem32_serial_out(struct uart_port *p, int offset, int value)
400{
401 offset = map_8250_out_reg(p, offset) << p->regshift;
402 writel(value, p->membase + offset);
403}
404
405static unsigned int mem32_serial_in(struct uart_port *p, int offset)
406{
407 offset = map_8250_in_reg(p, offset) << p->regshift;
408 return readl(p->membase + offset);
409}
383 410
384#ifdef CONFIG_SERIAL_8250_AU1X00 411#ifdef CONFIG_SERIAL_8250_AU1X00
385 case UPIO_AU: 412static unsigned int au_serial_in(struct uart_port *p, int offset)
386 return __raw_readl(up->port.membase + offset); 413{
414 offset = map_8250_in_reg(p, offset) << p->regshift;
415 return __raw_readl(p->membase + offset);
416}
417
418static void au_serial_out(struct uart_port *p, int offset, int value)
419{
420 offset = map_8250_out_reg(p, offset) << p->regshift;
421 __raw_writel(value, p->membase + offset);
422}
387#endif 423#endif
388 424
389 case UPIO_TSI: 425static unsigned int tsi_serial_in(struct uart_port *p, int offset)
390 if (offset == UART_IIR) { 426{
391 tmp = readl(up->port.membase + (UART_IIR & ~3)); 427 unsigned int tmp;
392 return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */ 428 offset = map_8250_in_reg(p, offset) << p->regshift;
393 } else 429 if (offset == UART_IIR) {
394 return readb(up->port.membase + offset); 430 tmp = readl(p->membase + (UART_IIR & ~3));
431 return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */
432 } else
433 return readb(p->membase + offset);
434}
395 435
396 default: 436static void tsi_serial_out(struct uart_port *p, int offset, int value)
397 return inb(up->port.iobase + offset); 437{
398 } 438 offset = map_8250_out_reg(p, offset) << p->regshift;
439 if (!((offset == UART_IER) && (value & UART_IER_UUE)))
440 writeb(value, p->membase + offset);
399} 441}
400 442
401static void 443static void dwapb_serial_out(struct uart_port *p, int offset, int value)
402serial_out(struct uart_8250_port *up, int offset, int value)
403{ 444{
404 /* Save the offset before it's remapped */
405 int save_offset = offset; 445 int save_offset = offset;
406 offset = map_8250_out_reg(up, offset) << up->port.regshift; 446 offset = map_8250_out_reg(p, offset) << p->regshift;
447 /* Save the LCR value so it can be re-written when a
448 * Busy Detect interrupt occurs. */
449 if (save_offset == UART_LCR) {
450 struct uart_8250_port *up = (struct uart_8250_port *)p;
451 up->lcr = value;
452 }
453 writeb(value, p->membase + offset);
454 /* Read the IER to ensure any interrupt is cleared before
455 * returning from ISR. */
456 if (save_offset == UART_TX || save_offset == UART_IER)
457 value = p->serial_in(p, UART_IER);
458}
407 459
408 switch (up->port.iotype) { 460static unsigned int io_serial_in(struct uart_port *p, int offset)
461{
462 offset = map_8250_in_reg(p, offset) << p->regshift;
463 return inb(p->iobase + offset);
464}
465
466static void io_serial_out(struct uart_port *p, int offset, int value)
467{
468 offset = map_8250_out_reg(p, offset) << p->regshift;
469 outb(value, p->iobase + offset);
470}
471
472static void set_io_from_upio(struct uart_port *p)
473{
474 switch (p->iotype) {
409 case UPIO_HUB6: 475 case UPIO_HUB6:
410 outb(up->port.hub6 - 1 + offset, up->port.iobase); 476 p->serial_in = hub6_serial_in;
411 outb(value, up->port.iobase + 1); 477 p->serial_out = hub6_serial_out;
412 break; 478 break;
413 479
414 case UPIO_MEM: 480 case UPIO_MEM:
415 writeb(value, up->port.membase + offset); 481 p->serial_in = mem_serial_in;
482 p->serial_out = mem_serial_out;
416 break; 483 break;
417 484
418 case UPIO_RM9000: 485 case UPIO_RM9000:
419 case UPIO_MEM32: 486 case UPIO_MEM32:
420 writel(value, up->port.membase + offset); 487 p->serial_in = mem32_serial_in;
488 p->serial_out = mem32_serial_out;
421 break; 489 break;
422 490
423#ifdef CONFIG_SERIAL_8250_AU1X00 491#ifdef CONFIG_SERIAL_8250_AU1X00
424 case UPIO_AU: 492 case UPIO_AU:
425 __raw_writel(value, up->port.membase + offset); 493 p->serial_in = au_serial_in;
494 p->serial_out = au_serial_out;
426 break; 495 break;
427#endif 496#endif
428 case UPIO_TSI: 497 case UPIO_TSI:
429 if (!((offset == UART_IER) && (value & UART_IER_UUE))) 498 p->serial_in = tsi_serial_in;
430 writeb(value, up->port.membase + offset); 499 p->serial_out = tsi_serial_out;
431 break; 500 break;
432 501
433 case UPIO_DWAPB: 502 case UPIO_DWAPB:
434 /* Save the LCR value so it can be re-written when a 503 p->serial_in = mem_serial_in;
435 * Busy Detect interrupt occurs. */ 504 p->serial_out = dwapb_serial_out;
436 if (save_offset == UART_LCR)
437 up->lcr = value;
438 writeb(value, up->port.membase + offset);
439 /* Read the IER to ensure any interrupt is cleared before
440 * returning from ISR. */
441 if (save_offset == UART_TX || save_offset == UART_IER)
442 value = serial_in(up, UART_IER);
443 break; 505 break;
444 506
445 default: 507 default:
446 outb(value, up->port.iobase + offset); 508 p->serial_in = io_serial_in;
509 p->serial_out = io_serial_out;
510 break;
447 } 511 }
448} 512}
449 513
450static void 514static void
451serial_out_sync(struct uart_8250_port *up, int offset, int value) 515serial_out_sync(struct uart_8250_port *up, int offset, int value)
452{ 516{
453 switch (up->port.iotype) { 517 struct uart_port *p = &up->port;
518 switch (p->iotype) {
454 case UPIO_MEM: 519 case UPIO_MEM:
455 case UPIO_MEM32: 520 case UPIO_MEM32:
456#ifdef CONFIG_SERIAL_8250_AU1X00 521#ifdef CONFIG_SERIAL_8250_AU1X00
457 case UPIO_AU: 522 case UPIO_AU:
458#endif 523#endif
459 case UPIO_DWAPB: 524 case UPIO_DWAPB:
460 serial_out(up, offset, value); 525 p->serial_out(p, offset, value);
461 serial_in(up, UART_LCR); /* safe, no side-effects */ 526 p->serial_in(p, UART_LCR); /* safe, no side-effects */
462 break; 527 break;
463 default: 528 default:
464 serial_out(up, offset, value); 529 p->serial_out(p, offset, value);
465 } 530 }
466} 531}
467 532
533#define serial_in(up, offset) \
534 (up->port.serial_in(&(up)->port, (offset)))
535#define serial_out(up, offset, value) \
536 (up->port.serial_out(&(up)->port, (offset), (value)))
468/* 537/*
469 * We used to support using pause I/O for certain machines. We 538 * We used to support using pause I/O for certain machines. We
470 * haven't supported this for a while, but just in case it's badly 539 * haven't supported this for a while, but just in case it's badly
@@ -2576,6 +2645,7 @@ static void __init serial8250_isa_init_ports(void)
2576 up->port.membase = old_serial_port[i].iomem_base; 2645 up->port.membase = old_serial_port[i].iomem_base;
2577 up->port.iotype = old_serial_port[i].io_type; 2646 up->port.iotype = old_serial_port[i].io_type;
2578 up->port.regshift = old_serial_port[i].iomem_reg_shift; 2647 up->port.regshift = old_serial_port[i].iomem_reg_shift;
2648 set_io_from_upio(&up->port);
2579 if (share_irqs) 2649 if (share_irqs)
2580 up->port.flags |= UPF_SHARE_IRQ; 2650 up->port.flags |= UPF_SHARE_IRQ;
2581 } 2651 }
@@ -2752,12 +2822,30 @@ static struct uart_driver serial8250_reg = {
2752 */ 2822 */
2753int __init early_serial_setup(struct uart_port *port) 2823int __init early_serial_setup(struct uart_port *port)
2754{ 2824{
2825 struct uart_port *p;
2826
2755 if (port->line >= ARRAY_SIZE(serial8250_ports)) 2827 if (port->line >= ARRAY_SIZE(serial8250_ports))
2756 return -ENODEV; 2828 return -ENODEV;
2757 2829
2758 serial8250_isa_init_ports(); 2830 serial8250_isa_init_ports();
2759 serial8250_ports[port->line].port = *port; 2831 p = &serial8250_ports[port->line].port;
2760 serial8250_ports[port->line].port.ops = &serial8250_pops; 2832 p->iobase = port->iobase;
2833 p->membase = port->membase;
2834 p->irq = port->irq;
2835 p->uartclk = port->uartclk;
2836 p->fifosize = port->fifosize;
2837 p->regshift = port->regshift;
2838 p->iotype = port->iotype;
2839 p->flags = port->flags;
2840 p->mapbase = port->mapbase;
2841 p->private_data = port->private_data;
2842
2843 set_io_from_upio(p);
2844 if (port->serial_in)
2845 p->serial_in = port->serial_in;
2846 if (port->serial_out)
2847 p->serial_out = port->serial_out;
2848
2761 return 0; 2849 return 0;
2762} 2850}
2763 2851
@@ -2822,6 +2910,9 @@ static int __devinit serial8250_probe(struct platform_device *dev)
2822 port.mapbase = p->mapbase; 2910 port.mapbase = p->mapbase;
2823 port.hub6 = p->hub6; 2911 port.hub6 = p->hub6;
2824 port.private_data = p->private_data; 2912 port.private_data = p->private_data;
2913 port.type = p->type;
2914 port.serial_in = p->serial_in;
2915 port.serial_out = p->serial_out;
2825 port.dev = &dev->dev; 2916 port.dev = &dev->dev;
2826 if (share_irqs) 2917 if (share_irqs)
2827 port.flags |= UPF_SHARE_IRQ; 2918 port.flags |= UPF_SHARE_IRQ;
@@ -2976,6 +3067,20 @@ int serial8250_register_port(struct uart_port *port)
2976 if (port->dev) 3067 if (port->dev)
2977 uart->port.dev = port->dev; 3068 uart->port.dev = port->dev;
2978 3069
3070 if (port->flags & UPF_FIXED_TYPE) {
3071 uart->port.type = port->type;
3072 uart->port.fifosize = uart_config[port->type].fifo_size;
3073 uart->capabilities = uart_config[port->type].flags;
3074 uart->tx_loadsz = uart_config[port->type].tx_loadsz;
3075 }
3076
3077 set_io_from_upio(&uart->port);
3078 /* Possibly override default I/O functions. */
3079 if (port->serial_in)
3080 uart->port.serial_in = port->serial_in;
3081 if (port->serial_out)
3082 uart->port.serial_out = port->serial_out;
3083
2979 ret = uart_add_one_port(&serial8250_reg, &uart->port); 3084 ret = uart_add_one_port(&serial8250_reg, &uart->port);
2980 if (ret == 0) 3085 if (ret == 0)
2981 ret = uart->port.line; 3086 ret = uart->port.line;
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 5450a0e5ecdb..c088146b7513 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -42,7 +42,8 @@ struct pci_serial_quirk {
42 u32 subvendor; 42 u32 subvendor;
43 u32 subdevice; 43 u32 subdevice;
44 int (*init)(struct pci_dev *dev); 44 int (*init)(struct pci_dev *dev);
45 int (*setup)(struct serial_private *, struct pciserial_board *, 45 int (*setup)(struct serial_private *,
46 const struct pciserial_board *,
46 struct uart_port *, int); 47 struct uart_port *, int);
47 void (*exit)(struct pci_dev *dev); 48 void (*exit)(struct pci_dev *dev);
48}; 49};
@@ -107,7 +108,7 @@ setup_port(struct serial_private *priv, struct uart_port *port,
107 * ADDI-DATA GmbH communication cards <info@addi-data.com> 108 * ADDI-DATA GmbH communication cards <info@addi-data.com>
108 */ 109 */
109static int addidata_apci7800_setup(struct serial_private *priv, 110static int addidata_apci7800_setup(struct serial_private *priv,
110 struct pciserial_board *board, 111 const struct pciserial_board *board,
111 struct uart_port *port, int idx) 112 struct uart_port *port, int idx)
112{ 113{
113 unsigned int bar = 0, offset = board->first_offset; 114 unsigned int bar = 0, offset = board->first_offset;
@@ -134,7 +135,7 @@ static int addidata_apci7800_setup(struct serial_private *priv,
134 * Not that ugly ;) -- HW 135 * Not that ugly ;) -- HW
135 */ 136 */
136static int 137static int
137afavlab_setup(struct serial_private *priv, struct pciserial_board *board, 138afavlab_setup(struct serial_private *priv, const struct pciserial_board *board,
138 struct uart_port *port, int idx) 139 struct uart_port *port, int idx)
139{ 140{
140 unsigned int bar, offset = board->first_offset; 141 unsigned int bar, offset = board->first_offset;
@@ -188,8 +189,9 @@ static int pci_hp_diva_init(struct pci_dev *dev)
188 * some serial ports are supposed to be hidden on certain models. 189 * some serial ports are supposed to be hidden on certain models.
189 */ 190 */
190static int 191static int
191pci_hp_diva_setup(struct serial_private *priv, struct pciserial_board *board, 192pci_hp_diva_setup(struct serial_private *priv,
192 struct uart_port *port, int idx) 193 const struct pciserial_board *board,
194 struct uart_port *port, int idx)
193{ 195{
194 unsigned int offset = board->first_offset; 196 unsigned int offset = board->first_offset;
195 unsigned int bar = FL_GET_BASE(board->flags); 197 unsigned int bar = FL_GET_BASE(board->flags);
@@ -306,7 +308,7 @@ static void __devexit pci_plx9050_exit(struct pci_dev *dev)
306 308
307/* SBS Technologies Inc. PMC-OCTPRO and P-OCTAL cards */ 309/* SBS Technologies Inc. PMC-OCTPRO and P-OCTAL cards */
308static int 310static int
309sbs_setup(struct serial_private *priv, struct pciserial_board *board, 311sbs_setup(struct serial_private *priv, const struct pciserial_board *board,
310 struct uart_port *port, int idx) 312 struct uart_port *port, int idx)
311{ 313{
312 unsigned int bar, offset = board->first_offset; 314 unsigned int bar, offset = board->first_offset;
@@ -463,7 +465,7 @@ static int pci_siig_init(struct pci_dev *dev)
463} 465}
464 466
465static int pci_siig_setup(struct serial_private *priv, 467static int pci_siig_setup(struct serial_private *priv,
466 struct pciserial_board *board, 468 const struct pciserial_board *board,
467 struct uart_port *port, int idx) 469 struct uart_port *port, int idx)
468{ 470{
469 unsigned int bar = FL_GET_BASE(board->flags) + idx, offset = 0; 471 unsigned int bar = FL_GET_BASE(board->flags) + idx, offset = 0;
@@ -534,7 +536,8 @@ static int pci_timedia_init(struct pci_dev *dev)
534 * Ugh, this is ugly as all hell --- TYT 536 * Ugh, this is ugly as all hell --- TYT
535 */ 537 */
536static int 538static int
537pci_timedia_setup(struct serial_private *priv, struct pciserial_board *board, 539pci_timedia_setup(struct serial_private *priv,
540 const struct pciserial_board *board,
538 struct uart_port *port, int idx) 541 struct uart_port *port, int idx)
539{ 542{
540 unsigned int bar = 0, offset = board->first_offset; 543 unsigned int bar = 0, offset = board->first_offset;
@@ -568,7 +571,7 @@ pci_timedia_setup(struct serial_private *priv, struct pciserial_board *board,
568 */ 571 */
569static int 572static int
570titan_400l_800l_setup(struct serial_private *priv, 573titan_400l_800l_setup(struct serial_private *priv,
571 struct pciserial_board *board, 574 const struct pciserial_board *board,
572 struct uart_port *port, int idx) 575 struct uart_port *port, int idx)
573{ 576{
574 unsigned int bar, offset = board->first_offset; 577 unsigned int bar, offset = board->first_offset;
@@ -737,8 +740,41 @@ static void __devexit pci_ite887x_exit(struct pci_dev *dev)
737 release_region(ioport, ITE_887x_IOSIZE); 740 release_region(ioport, ITE_887x_IOSIZE);
738} 741}
739 742
743/*
744 * Oxford Semiconductor Inc.
745 * Check that device is part of the Tornado range of devices, then determine
746 * the number of ports available on the device.
747 */
748static int pci_oxsemi_tornado_init(struct pci_dev *dev)
749{
750 u8 __iomem *p;
751 unsigned long deviceID;
752 unsigned int number_uarts = 0;
753
754 /* OxSemi Tornado devices are all 0xCxxx */
755 if (dev->vendor == PCI_VENDOR_ID_OXSEMI &&
756 (dev->device & 0xF000) != 0xC000)
757 return 0;
758
759 p = pci_iomap(dev, 0, 5);
760 if (p == NULL)
761 return -ENOMEM;
762
763 deviceID = ioread32(p);
764 /* Tornado device */
765 if (deviceID == 0x07000200) {
766 number_uarts = ioread8(p + 4);
767 printk(KERN_DEBUG
768 "%d ports detected on Oxford PCI Express device\n",
769 number_uarts);
770 }
771 pci_iounmap(dev, p);
772 return number_uarts;
773}
774
740static int 775static int
741pci_default_setup(struct serial_private *priv, struct pciserial_board *board, 776pci_default_setup(struct serial_private *priv,
777 const struct pciserial_board *board,
742 struct uart_port *port, int idx) 778 struct uart_port *port, int idx)
743{ 779{
744 unsigned int bar, offset = board->first_offset, maxnr; 780 unsigned int bar, offset = board->first_offset, maxnr;
@@ -1018,6 +1054,25 @@ static struct pci_serial_quirk pci_serial_quirks[] __refdata = {
1018 .setup = pci_default_setup, 1054 .setup = pci_default_setup,
1019 }, 1055 },
1020 /* 1056 /*
1057 * For Oxford Semiconductor and Mainpine
1058 */
1059 {
1060 .vendor = PCI_VENDOR_ID_OXSEMI,
1061 .device = PCI_ANY_ID,
1062 .subvendor = PCI_ANY_ID,
1063 .subdevice = PCI_ANY_ID,
1064 .init = pci_oxsemi_tornado_init,
1065 .setup = pci_default_setup,
1066 },
1067 {
1068 .vendor = PCI_VENDOR_ID_MAINPINE,
1069 .device = PCI_ANY_ID,
1070 .subvendor = PCI_ANY_ID,
1071 .subdevice = PCI_ANY_ID,
1072 .init = pci_oxsemi_tornado_init,
1073 .setup = pci_default_setup,
1074 },
1075 /*
1021 * Default "match everything" terminator entry 1076 * Default "match everything" terminator entry
1022 */ 1077 */
1023 { 1078 {
@@ -1048,7 +1103,7 @@ static struct pci_serial_quirk *find_quirk(struct pci_dev *dev)
1048} 1103}
1049 1104
1050static inline int get_pci_irq(struct pci_dev *dev, 1105static inline int get_pci_irq(struct pci_dev *dev,
1051 struct pciserial_board *board) 1106 const struct pciserial_board *board)
1052{ 1107{
1053 if (board->flags & FL_NOIRQ) 1108 if (board->flags & FL_NOIRQ)
1054 return 0; 1109 return 0;
@@ -1843,8 +1898,8 @@ serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
1843} 1898}
1844 1899
1845static inline int 1900static inline int
1846serial_pci_matches(struct pciserial_board *board, 1901serial_pci_matches(const struct pciserial_board *board,
1847 struct pciserial_board *guessed) 1902 const struct pciserial_board *guessed)
1848{ 1903{
1849 return 1904 return
1850 board->num_ports == guessed->num_ports && 1905 board->num_ports == guessed->num_ports &&
@@ -1854,54 +1909,14 @@ serial_pci_matches(struct pciserial_board *board,
1854 board->first_offset == guessed->first_offset; 1909 board->first_offset == guessed->first_offset;
1855} 1910}
1856 1911
1857/*
1858 * Oxford Semiconductor Inc.
1859 * Check that device is part of the Tornado range of devices, then determine
1860 * the number of ports available on the device.
1861 */
1862static int pci_oxsemi_tornado_init(struct pci_dev *dev, struct pciserial_board *board)
1863{
1864 u8 __iomem *p;
1865 unsigned long deviceID;
1866 unsigned int number_uarts;
1867
1868 /* OxSemi Tornado devices are all 0xCxxx */
1869 if (dev->vendor == PCI_VENDOR_ID_OXSEMI &&
1870 (dev->device & 0xF000) != 0xC000)
1871 return 0;
1872
1873 p = pci_iomap(dev, 0, 5);
1874 if (p == NULL)
1875 return -ENOMEM;
1876
1877 deviceID = ioread32(p);
1878 /* Tornado device */
1879 if (deviceID == 0x07000200) {
1880 number_uarts = ioread8(p + 4);
1881 board->num_ports = number_uarts;
1882 printk(KERN_DEBUG
1883 "%d ports detected on Oxford PCI Express device\n",
1884 number_uarts);
1885 }
1886 pci_iounmap(dev, p);
1887 return 0;
1888}
1889
1890struct serial_private * 1912struct serial_private *
1891pciserial_init_ports(struct pci_dev *dev, struct pciserial_board *board) 1913pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board)
1892{ 1914{
1893 struct uart_port serial_port; 1915 struct uart_port serial_port;
1894 struct serial_private *priv; 1916 struct serial_private *priv;
1895 struct pci_serial_quirk *quirk; 1917 struct pci_serial_quirk *quirk;
1896 int rc, nr_ports, i; 1918 int rc, nr_ports, i;
1897 1919
1898 /*
1899 * Find number of ports on board
1900 */
1901 if (dev->vendor == PCI_VENDOR_ID_OXSEMI ||
1902 dev->vendor == PCI_VENDOR_ID_MAINPINE)
1903 pci_oxsemi_tornado_init(dev, board);
1904
1905 nr_ports = board->num_ports; 1920 nr_ports = board->num_ports;
1906 1921
1907 /* 1922 /*
@@ -2028,7 +2043,8 @@ static int __devinit
2028pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent) 2043pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
2029{ 2044{
2030 struct serial_private *priv; 2045 struct serial_private *priv;
2031 struct pciserial_board *board, tmp; 2046 const struct pciserial_board *board;
2047 struct pciserial_board tmp;
2032 int rc; 2048 int rc;
2033 2049
2034 if (ent->driver_data >= ARRAY_SIZE(pci_boards)) { 2050 if (ent->driver_data >= ARRAY_SIZE(pci_boards)) {
@@ -2055,7 +2071,7 @@ pciserial_init_one(struct pci_dev *dev, const struct pci_device_id *ent)
2055 * We matched one of our class entries. Try to 2071 * We matched one of our class entries. Try to
2056 * determine the parameters of this board. 2072 * determine the parameters of this board.
2057 */ 2073 */
2058 rc = serial_pci_guess_board(dev, board); 2074 rc = serial_pci_guess_board(dev, &tmp);
2059 if (rc) 2075 if (rc)
2060 goto disable; 2076 goto disable;
2061 } else { 2077 } else {
@@ -2271,6 +2287,9 @@ static struct pci_device_id serial_pci_tbl[] = {
2271 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM8, 2287 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM8,
2272 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2288 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2273 pbn_b2_8_115200 }, 2289 pbn_b2_8_115200 },
2290 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_7803,
2291 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2292 pbn_b2_8_460800 },
2274 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM8, 2293 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM8,
2275 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2294 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2276 pbn_b2_8_115200 }, 2295 pbn_b2_8_115200 },
@@ -2372,6 +2391,9 @@ static struct pci_device_id serial_pci_tbl[] = {
2372 * For now just used the hex ID 0x950a. 2391 * For now just used the hex ID 0x950a.
2373 */ 2392 */
2374 { PCI_VENDOR_ID_OXSEMI, 0x950a, 2393 { PCI_VENDOR_ID_OXSEMI, 0x950a,
2394 PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_DUAL_SERIAL, 0, 0,
2395 pbn_b0_2_115200 },
2396 { PCI_VENDOR_ID_OXSEMI, 0x950a,
2375 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2397 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2376 pbn_b0_2_1130000 }, 2398 pbn_b0_2_1130000 },
2377 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, 2399 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 569f0e2476c6..318d69dce8e1 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -22,7 +22,8 @@
22#include <linux/tty_flip.h> 22#include <linux/tty_flip.h>
23#include <linux/serial_core.h> 23#include <linux/serial_core.h>
24 24
25#ifdef CONFIG_KGDB_UART 25#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
26 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
26#include <linux/kgdb.h> 27#include <linux/kgdb.h>
27#include <asm/irq_regs.h> 28#include <asm/irq_regs.h>
28#endif 29#endif
@@ -45,6 +46,16 @@
45static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS]; 46static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
46static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource); 47static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource);
47 48
49#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
50 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
51
52# ifndef CONFIG_SERIAL_BFIN_PIO
53# error KGDB only support UART in PIO mode.
54# endif
55
56static int kgdboc_port_line;
57static int kgdboc_break_enabled;
58#endif
48/* 59/*
49 * Setup for console. Argument comes from the menuconfig 60 * Setup for console. Argument comes from the menuconfig
50 */ 61 */
@@ -62,13 +73,17 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart);
62 73
63static void bfin_serial_mctrl_check(struct bfin_serial_port *uart); 74static void bfin_serial_mctrl_check(struct bfin_serial_port *uart);
64 75
76static void bfin_serial_reset_irda(struct uart_port *port);
77
65/* 78/*
66 * interrupts are disabled on entry 79 * interrupts are disabled on entry
67 */ 80 */
68static void bfin_serial_stop_tx(struct uart_port *port) 81static void bfin_serial_stop_tx(struct uart_port *port)
69{ 82{
70 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 83 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
84#ifdef CONFIG_SERIAL_BFIN_DMA
71 struct circ_buf *xmit = &uart->port.info->xmit; 85 struct circ_buf *xmit = &uart->port.info->xmit;
86#endif
72 87
73 while (!(UART_GET_LSR(uart) & TEMT)) 88 while (!(UART_GET_LSR(uart) & TEMT))
74 cpu_relax(); 89 cpu_relax();
@@ -94,6 +109,14 @@ static void bfin_serial_stop_tx(struct uart_port *port)
94static void bfin_serial_start_tx(struct uart_port *port) 109static void bfin_serial_start_tx(struct uart_port *port)
95{ 110{
96 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 111 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
112 struct tty_struct *tty = uart->port.info->port.tty;
113
114 /*
115 * To avoid losting RX interrupt, we reset IR function
116 * before sending data.
117 */
118 if (tty->termios->c_line == N_IRDA)
119 bfin_serial_reset_irda(port);
97 120
98#ifdef CONFIG_SERIAL_BFIN_DMA 121#ifdef CONFIG_SERIAL_BFIN_DMA
99 if (uart->tx_done) 122 if (uart->tx_done)
@@ -110,9 +133,7 @@ static void bfin_serial_start_tx(struct uart_port *port)
110static void bfin_serial_stop_rx(struct uart_port *port) 133static void bfin_serial_stop_rx(struct uart_port *port)
111{ 134{
112 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 135 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
113#ifdef CONFIG_KGDB_UART 136
114 if (uart->port.line != CONFIG_KGDB_UART_PORT)
115#endif
116 UART_CLEAR_IER(uart, ERBFI); 137 UART_CLEAR_IER(uart, ERBFI);
117} 138}
118 139
@@ -123,49 +144,6 @@ static void bfin_serial_enable_ms(struct uart_port *port)
123{ 144{
124} 145}
125 146
126#ifdef CONFIG_KGDB_UART
127static int kgdb_entry_state;
128
129void kgdb_put_debug_char(int chr)
130{
131 struct bfin_serial_port *uart;
132
133 if (CONFIG_KGDB_UART_PORT < 0
134 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
135 uart = &bfin_serial_ports[0];
136 else
137 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
138
139 while (!(UART_GET_LSR(uart) & THRE)) {
140 SSYNC();
141 }
142
143 UART_CLEAR_DLAB(uart);
144 UART_PUT_CHAR(uart, (unsigned char)chr);
145 SSYNC();
146}
147
148int kgdb_get_debug_char(void)
149{
150 struct bfin_serial_port *uart;
151 unsigned char chr;
152
153 if (CONFIG_KGDB_UART_PORT < 0
154 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
155 uart = &bfin_serial_ports[0];
156 else
157 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
158
159 while(!(UART_GET_LSR(uart) & DR)) {
160 SSYNC();
161 }
162 UART_CLEAR_DLAB(uart);
163 chr = UART_GET_CHAR(uart);
164 SSYNC();
165
166 return chr;
167}
168#endif
169 147
170#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO) 148#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
171# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold) 149# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
@@ -178,7 +156,7 @@ int kgdb_get_debug_char(void)
178#ifdef CONFIG_SERIAL_BFIN_PIO 156#ifdef CONFIG_SERIAL_BFIN_PIO
179static void bfin_serial_rx_chars(struct bfin_serial_port *uart) 157static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
180{ 158{
181 struct tty_struct *tty = uart->port.info->port.tty; 159 struct tty_struct *tty = NULL;
182 unsigned int status, ch, flg; 160 unsigned int status, ch, flg;
183 static struct timeval anomaly_start = { .tv_sec = 0 }; 161 static struct timeval anomaly_start = { .tv_sec = 0 };
184 162
@@ -188,27 +166,18 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
188 ch = UART_GET_CHAR(uart); 166 ch = UART_GET_CHAR(uart);
189 uart->port.icount.rx++; 167 uart->port.icount.rx++;
190 168
191#ifdef CONFIG_KGDB_UART 169#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
192 if (uart->port.line == CONFIG_KGDB_UART_PORT) { 170 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
193 struct pt_regs *regs = get_irq_regs(); 171 if (kgdb_connected && kgdboc_port_line == uart->port.line)
194 if (uart->port.cons->index == CONFIG_KGDB_UART_PORT && ch == 0x1) { /* Ctrl + A */ 172 if (ch == 0x3) {/* Ctrl + C */
195 kgdb_breakkey_pressed(regs); 173 kgdb_breakpoint();
196 return;
197 } else if (kgdb_entry_state == 0 && ch == '$') {/* connection from KGDB */
198 kgdb_entry_state = 1;
199 } else if (kgdb_entry_state == 1 && ch == 'q') {
200 kgdb_entry_state = 0;
201 kgdb_breakkey_pressed(regs);
202 return;
203 } else if (ch == 0x3) {/* Ctrl + C */
204 kgdb_entry_state = 0;
205 kgdb_breakkey_pressed(regs);
206 return; 174 return;
207 } else {
208 kgdb_entry_state = 0;
209 } 175 }
210 } 176
177 if (!uart->port.info || !uart->port.info->tty)
178 return;
211#endif 179#endif
180 tty = uart->port.info->tty;
212 181
213 if (ANOMALY_05000363) { 182 if (ANOMALY_05000363) {
214 /* The BF533 (and BF561) family of processors have a nice anomaly 183 /* The BF533 (and BF561) family of processors have a nice anomaly
@@ -250,6 +219,7 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
250 return; 219 return;
251 220
252 known_good_char: 221 known_good_char:
222 status &= ~BI;
253 anomaly_start.tv_sec = 0; 223 anomaly_start.tv_sec = 0;
254 } 224 }
255 } 225 }
@@ -445,7 +415,9 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
445 415
446void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) 416void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
447{ 417{
448 int x_pos, pos; 418 int x_pos, pos, flags;
419
420 spin_lock_irqsave(&uart->port.lock, flags);
449 421
450 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); 422 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
451 x_pos = get_dma_curr_xcount(uart->rx_dma_channel); 423 x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
@@ -463,6 +435,8 @@ void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
463 uart->rx_dma_buf.tail = uart->rx_dma_buf.head; 435 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
464 } 436 }
465 437
438 spin_unlock_irqrestore(&uart->port.lock, flags);
439
466 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); 440 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
467} 441}
468 442
@@ -497,10 +471,9 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
497 spin_lock(&uart->port.lock); 471 spin_lock(&uart->port.lock);
498 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); 472 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
499 clear_dma_irqstat(uart->rx_dma_channel); 473 clear_dma_irqstat(uart->rx_dma_channel);
474 bfin_serial_dma_rx_chars(uart);
500 spin_unlock(&uart->port.lock); 475 spin_unlock(&uart->port.lock);
501 476
502 mod_timer(&(uart->rx_dma_timer), jiffies);
503
504 return IRQ_HANDLED; 477 return IRQ_HANDLED;
505} 478}
506#endif 479#endif
@@ -630,16 +603,16 @@ static int bfin_serial_startup(struct uart_port *port)
630 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; 603 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
631 add_timer(&(uart->rx_dma_timer)); 604 add_timer(&(uart->rx_dma_timer));
632#else 605#else
606#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
607 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
608 if (kgdboc_port_line == uart->port.line && kgdboc_break_enabled)
609 kgdboc_break_enabled = 0;
610 else {
611# endif
633 if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED, 612 if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
634 "BFIN_UART_RX", uart)) { 613 "BFIN_UART_RX", uart)) {
635# ifdef CONFIG_KGDB_UART
636 if (uart->port.line != CONFIG_KGDB_UART_PORT) {
637# endif
638 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 614 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
639 return -EBUSY; 615 return -EBUSY;
640# ifdef CONFIG_KGDB_UART
641 }
642# endif
643 } 616 }
644 617
645 if (request_irq 618 if (request_irq
@@ -685,6 +658,10 @@ static int bfin_serial_startup(struct uart_port *port)
685 } 658 }
686 } 659 }
687# endif 660# endif
661#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
662 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
663 }
664# endif
688#endif 665#endif
689 UART_SET_IER(uart, ERBFI); 666 UART_SET_IER(uart, ERBFI);
690 return 0; 667 return 0;
@@ -716,9 +693,6 @@ static void bfin_serial_shutdown(struct uart_port *port)
716 break; 693 break;
717 }; 694 };
718#endif 695#endif
719#ifdef CONFIG_KGDB_UART
720 if (uart->port.line != CONFIG_KGDB_UART_PORT)
721#endif
722 free_irq(uart->port.irq, uart); 696 free_irq(uart->port.irq, uart);
723 free_irq(uart->port.irq+1, uart); 697 free_irq(uart->port.irq+1, uart);
724#endif 698#endif
@@ -887,6 +861,65 @@ static void bfin_serial_set_ldisc(struct uart_port *port)
887 } 861 }
888} 862}
889 863
864#ifdef CONFIG_CONSOLE_POLL
865static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr)
866{
867 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
868
869 while (!(UART_GET_LSR(uart) & THRE))
870 cpu_relax();
871
872 UART_CLEAR_DLAB(uart);
873 UART_PUT_CHAR(uart, (unsigned char)chr);
874}
875
876static int bfin_serial_poll_get_char(struct uart_port *port)
877{
878 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
879 unsigned char chr;
880
881 while (!(UART_GET_LSR(uart) & DR))
882 cpu_relax();
883
884 UART_CLEAR_DLAB(uart);
885 chr = UART_GET_CHAR(uart);
886
887 return chr;
888}
889#endif
890
891#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
892 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
893static void bfin_kgdboc_port_shutdown(struct uart_port *port)
894{
895 if (kgdboc_break_enabled) {
896 kgdboc_break_enabled = 0;
897 bfin_serial_shutdown(port);
898 }
899}
900
901static int bfin_kgdboc_port_startup(struct uart_port *port)
902{
903 kgdboc_port_line = port->line;
904 kgdboc_break_enabled = !bfin_serial_startup(port);
905 return 0;
906}
907#endif
908
909static void bfin_serial_reset_irda(struct uart_port *port)
910{
911 int line = port->line;
912 unsigned short val;
913
914 val = UART_GET_GCTL(&bfin_serial_ports[line]);
915 val &= ~(IREN | RPOLC);
916 UART_PUT_GCTL(&bfin_serial_ports[line], val);
917 SSYNC();
918 val |= (IREN | RPOLC);
919 UART_PUT_GCTL(&bfin_serial_ports[line], val);
920 SSYNC();
921}
922
890static struct uart_ops bfin_serial_pops = { 923static struct uart_ops bfin_serial_pops = {
891 .tx_empty = bfin_serial_tx_empty, 924 .tx_empty = bfin_serial_tx_empty,
892 .set_mctrl = bfin_serial_set_mctrl, 925 .set_mctrl = bfin_serial_set_mctrl,
@@ -905,6 +938,15 @@ static struct uart_ops bfin_serial_pops = {
905 .request_port = bfin_serial_request_port, 938 .request_port = bfin_serial_request_port,
906 .config_port = bfin_serial_config_port, 939 .config_port = bfin_serial_config_port,
907 .verify_port = bfin_serial_verify_port, 940 .verify_port = bfin_serial_verify_port,
941#if defined(CONFIG_KGDB_SERIAL_CONSOLE) || \
942 defined(CONFIG_KGDB_SERIAL_CONSOLE_MODULE)
943 .kgdboc_port_startup = bfin_kgdboc_port_startup,
944 .kgdboc_port_shutdown = bfin_kgdboc_port_shutdown,
945#endif
946#ifdef CONFIG_CONSOLE_POLL
947 .poll_put_char = bfin_serial_poll_put_char,
948 .poll_get_char = bfin_serial_poll_get_char,
949#endif
908}; 950};
909 951
910static void __init bfin_serial_init_ports(void) 952static void __init bfin_serial_init_ports(void)
@@ -950,7 +992,7 @@ static void __init bfin_serial_init_ports(void)
950 992
951} 993}
952 994
953#ifdef CONFIG_SERIAL_BFIN_CONSOLE 995#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
954/* 996/*
955 * If the port was already initialised (eg, by a boot loader), 997 * If the port was already initialised (eg, by a boot loader),
956 * try to determine the current setup. 998 * try to determine the current setup.
@@ -994,24 +1036,20 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
994 } 1036 }
995 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits); 1037 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __func__, *baud, *parity, *bits);
996} 1038}
997#endif
998 1039
999#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1000static struct uart_driver bfin_serial_reg; 1040static struct uart_driver bfin_serial_reg;
1001 1041
1002static int __init 1042static int __init
1003bfin_serial_console_setup(struct console *co, char *options) 1043bfin_serial_console_setup(struct console *co, char *options)
1004{ 1044{
1005 struct bfin_serial_port *uart; 1045 struct bfin_serial_port *uart;
1006# ifdef CONFIG_SERIAL_BFIN_CONSOLE
1007 int baud = 57600; 1046 int baud = 57600;
1008 int bits = 8; 1047 int bits = 8;
1009 int parity = 'n'; 1048 int parity = 'n';
1010# ifdef CONFIG_SERIAL_BFIN_CTSRTS 1049# ifdef CONFIG_SERIAL_BFIN_CTSRTS
1011 int flow = 'r'; 1050 int flow = 'r';
1012# else 1051# else
1013 int flow = 'n'; 1052 int flow = 'n';
1014# endif
1015# endif 1053# endif
1016 1054
1017 /* 1055 /*
@@ -1023,16 +1061,12 @@ bfin_serial_console_setup(struct console *co, char *options)
1023 co->index = 0; 1061 co->index = 0;
1024 uart = &bfin_serial_ports[co->index]; 1062 uart = &bfin_serial_ports[co->index];
1025 1063
1026# ifdef CONFIG_SERIAL_BFIN_CONSOLE
1027 if (options) 1064 if (options)
1028 uart_parse_options(options, &baud, &parity, &bits, &flow); 1065 uart_parse_options(options, &baud, &parity, &bits, &flow);
1029 else 1066 else
1030 bfin_serial_console_get_options(uart, &baud, &parity, &bits); 1067 bfin_serial_console_get_options(uart, &baud, &parity, &bits);
1031 1068
1032 return uart_set_options(&uart->port, co, baud, parity, bits, flow); 1069 return uart_set_options(&uart->port, co, baud, parity, bits, flow);
1033# else
1034 return 0;
1035# endif
1036} 1070}
1037#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) || 1071#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1038 defined (CONFIG_EARLY_PRINTK) */ 1072 defined (CONFIG_EARLY_PRINTK) */
@@ -1076,10 +1110,7 @@ static int __init bfin_serial_rs_console_init(void)
1076{ 1110{
1077 bfin_serial_init_ports(); 1111 bfin_serial_init_ports();
1078 register_console(&bfin_serial_console); 1112 register_console(&bfin_serial_console);
1079#ifdef CONFIG_KGDB_UART 1113
1080 kgdb_entry_state = 0;
1081 init_kgdb_uart();
1082#endif
1083 return 0; 1114 return 0;
1084} 1115}
1085console_initcall(bfin_serial_rs_console_init); 1116console_initcall(bfin_serial_rs_console_init);
@@ -1144,7 +1175,7 @@ struct console __init *bfin_earlyserial_init(unsigned int port,
1144 return &bfin_early_serial_console; 1175 return &bfin_early_serial_console;
1145} 1176}
1146 1177
1147#endif /* CONFIG_SERIAL_BFIN_CONSOLE */ 1178#endif /* CONFIG_EARLY_PRINTK */
1148 1179
1149static struct uart_driver bfin_serial_reg = { 1180static struct uart_driver bfin_serial_reg = {
1150 .owner = THIS_MODULE, 1181 .owner = THIS_MODULE,
@@ -1235,10 +1266,6 @@ static struct platform_driver bfin_serial_driver = {
1235static int __init bfin_serial_init(void) 1266static int __init bfin_serial_init(void)
1236{ 1267{
1237 int ret; 1268 int ret;
1238#ifdef CONFIG_KGDB_UART
1239 struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
1240 struct ktermios t;
1241#endif
1242 1269
1243 pr_info("Serial: Blackfin serial driver\n"); 1270 pr_info("Serial: Blackfin serial driver\n");
1244 1271
@@ -1252,21 +1279,6 @@ static int __init bfin_serial_init(void)
1252 uart_unregister_driver(&bfin_serial_reg); 1279 uart_unregister_driver(&bfin_serial_reg);
1253 } 1280 }
1254 } 1281 }
1255#ifdef CONFIG_KGDB_UART
1256 if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) {
1257 request_irq(uart->port.irq, bfin_serial_rx_int,
1258 IRQF_DISABLED, "BFIN_UART_RX", uart);
1259 pr_info("Request irq for kgdb uart port\n");
1260 UART_SET_IER(uart, ERBFI);
1261 SSYNC();
1262 t.c_cflag = CS8|B57600;
1263 t.c_iflag = 0;
1264 t.c_oflag = 0;
1265 t.c_lflag = ICANON;
1266 t.c_line = CONFIG_KGDB_UART_PORT;
1267 bfin_serial_set_termios(&uart->port, &t, &t);
1268 }
1269#endif
1270 return ret; 1282 return ret;
1271} 1283}
1272 1284
@@ -1276,6 +1288,7 @@ static void __exit bfin_serial_exit(void)
1276 uart_unregister_driver(&bfin_serial_reg); 1288 uart_unregister_driver(&bfin_serial_reg);
1277} 1289}
1278 1290
1291
1279module_init(bfin_serial_init); 1292module_init(bfin_serial_init);
1280module_exit(bfin_serial_exit); 1293module_exit(bfin_serial_exit);
1281 1294
diff --git a/drivers/serial/bfin_sport_uart.c b/drivers/serial/bfin_sport_uart.c
index dd8564d25051..529c0ff7952c 100644
--- a/drivers/serial/bfin_sport_uart.c
+++ b/drivers/serial/bfin_sport_uart.c
@@ -99,7 +99,7 @@ static void sport_stop_tx(struct uart_port *port);
99 99
100static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value) 100static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value)
101{ 101{
102 pr_debug("%s value:%x\n", __FUNCTION__, value); 102 pr_debug("%s value:%x\n", __func__, value);
103 /* Place a Start and Stop bit */ 103 /* Place a Start and Stop bit */
104 __asm__ volatile ( 104 __asm__ volatile (
105 "R2 = b#01111111100;\n\t" 105 "R2 = b#01111111100;\n\t"
@@ -110,7 +110,7 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value)
110 :"=r"(value) 110 :"=r"(value)
111 :"0"(value) 111 :"0"(value)
112 :"R2", "R3"); 112 :"R2", "R3");
113 pr_debug("%s value:%x\n", __FUNCTION__, value); 113 pr_debug("%s value:%x\n", __func__, value);
114 114
115 SPORT_PUT_TX(up, value); 115 SPORT_PUT_TX(up, value);
116} 116}
@@ -120,7 +120,7 @@ static inline unsigned int rx_one_byte(struct sport_uart_port *up)
120 unsigned int value, extract; 120 unsigned int value, extract;
121 121
122 value = SPORT_GET_RX32(up); 122 value = SPORT_GET_RX32(up);
123 pr_debug("%s value:%x\n", __FUNCTION__, value); 123 pr_debug("%s value:%x\n", __func__, value);
124 124
125 /* Extract 8 bits data */ 125 /* Extract 8 bits data */
126 __asm__ volatile ( 126 __asm__ volatile (
@@ -151,12 +151,12 @@ static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate)
151 /* Set TCR1 and TCR2 */ 151 /* Set TCR1 and TCR2 */
152 SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK)); 152 SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK));
153 SPORT_PUT_TCR2(up, 10); 153 SPORT_PUT_TCR2(up, 10);
154 pr_debug("%s TCR1:%x, TCR2:%x\n", __FUNCTION__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up)); 154 pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up));
155 155
156 /* Set RCR1 and RCR2 */ 156 /* Set RCR1 and RCR2 */
157 SPORT_PUT_RCR1(up, (RCKFE | LARFS | LRFS | RFSR | IRCLK)); 157 SPORT_PUT_RCR1(up, (RCKFE | LARFS | LRFS | RFSR | IRCLK));
158 SPORT_PUT_RCR2(up, 28); 158 SPORT_PUT_RCR2(up, 28);
159 pr_debug("%s RCR1:%x, RCR2:%x\n", __FUNCTION__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up)); 159 pr_debug("%s RCR1:%x, RCR2:%x\n", __func__, SPORT_GET_RCR1(up), SPORT_GET_RCR2(up));
160 160
161 tclkdiv = sclk/(2 * baud_rate) - 1; 161 tclkdiv = sclk/(2 * baud_rate) - 1;
162 tfsdiv = 12; 162 tfsdiv = 12;
@@ -166,7 +166,7 @@ static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate)
166 SPORT_PUT_RCLKDIV(up, rclkdiv); 166 SPORT_PUT_RCLKDIV(up, rclkdiv);
167 SSYNC(); 167 SSYNC();
168 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, tfsdiv:%d, rclkdiv:%d\n", 168 pr_debug("%s sclk:%d, baud_rate:%d, tclkdiv:%d, tfsdiv:%d, rclkdiv:%d\n",
169 __FUNCTION__, sclk, baud_rate, tclkdiv, tfsdiv, rclkdiv); 169 __func__, sclk, baud_rate, tclkdiv, tfsdiv, rclkdiv);
170 170
171 return 0; 171 return 0;
172} 172}
@@ -231,7 +231,7 @@ static int sport_startup(struct uart_port *port)
231 char buffer[20]; 231 char buffer[20];
232 int retval; 232 int retval;
233 233
234 pr_debug("%s enter\n", __FUNCTION__); 234 pr_debug("%s enter\n", __func__);
235 memset(buffer, 20, '\0'); 235 memset(buffer, 20, '\0');
236 snprintf(buffer, 20, "%s rx", up->name); 236 snprintf(buffer, 20, "%s rx", up->name);
237 retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up); 237 retval = request_irq(up->rx_irq, sport_uart_rx_irq, IRQF_SAMPLE_RANDOM, buffer, up);
@@ -320,7 +320,7 @@ static unsigned int sport_tx_empty(struct uart_port *port)
320 unsigned int stat; 320 unsigned int stat;
321 321
322 stat = SPORT_GET_STAT(up); 322 stat = SPORT_GET_STAT(up);
323 pr_debug("%s stat:%04x\n", __FUNCTION__, stat); 323 pr_debug("%s stat:%04x\n", __func__, stat);
324 if (stat & TXHRE) { 324 if (stat & TXHRE) {
325 return TIOCSER_TEMT; 325 return TIOCSER_TEMT;
326 } else 326 } else
@@ -329,13 +329,13 @@ static unsigned int sport_tx_empty(struct uart_port *port)
329 329
330static unsigned int sport_get_mctrl(struct uart_port *port) 330static unsigned int sport_get_mctrl(struct uart_port *port)
331{ 331{
332 pr_debug("%s enter\n", __FUNCTION__); 332 pr_debug("%s enter\n", __func__);
333 return (TIOCM_CTS | TIOCM_CD | TIOCM_DSR); 333 return (TIOCM_CTS | TIOCM_CD | TIOCM_DSR);
334} 334}
335 335
336static void sport_set_mctrl(struct uart_port *port, unsigned int mctrl) 336static void sport_set_mctrl(struct uart_port *port, unsigned int mctrl)
337{ 337{
338 pr_debug("%s enter\n", __FUNCTION__); 338 pr_debug("%s enter\n", __func__);
339} 339}
340 340
341static void sport_stop_tx(struct uart_port *port) 341static void sport_stop_tx(struct uart_port *port)
@@ -343,7 +343,7 @@ static void sport_stop_tx(struct uart_port *port)
343 struct sport_uart_port *up = (struct sport_uart_port *)port; 343 struct sport_uart_port *up = (struct sport_uart_port *)port;
344 unsigned int stat; 344 unsigned int stat;
345 345
346 pr_debug("%s enter\n", __FUNCTION__); 346 pr_debug("%s enter\n", __func__);
347 347
348 stat = SPORT_GET_STAT(up); 348 stat = SPORT_GET_STAT(up);
349 while(!(stat & TXHRE)) { 349 while(!(stat & TXHRE)) {
@@ -366,21 +366,21 @@ static void sport_start_tx(struct uart_port *port)
366{ 366{
367 struct sport_uart_port *up = (struct sport_uart_port *)port; 367 struct sport_uart_port *up = (struct sport_uart_port *)port;
368 368
369 pr_debug("%s enter\n", __FUNCTION__); 369 pr_debug("%s enter\n", __func__);
370 /* Write data into SPORT FIFO before enable SPROT to transmit */ 370 /* Write data into SPORT FIFO before enable SPROT to transmit */
371 sport_uart_tx_chars(up); 371 sport_uart_tx_chars(up);
372 372
373 /* Enable transmit, then an interrupt will generated */ 373 /* Enable transmit, then an interrupt will generated */
374 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) | TSPEN)); 374 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) | TSPEN));
375 SSYNC(); 375 SSYNC();
376 pr_debug("%s exit\n", __FUNCTION__); 376 pr_debug("%s exit\n", __func__);
377} 377}
378 378
379static void sport_stop_rx(struct uart_port *port) 379static void sport_stop_rx(struct uart_port *port)
380{ 380{
381 struct sport_uart_port *up = (struct sport_uart_port *)port; 381 struct sport_uart_port *up = (struct sport_uart_port *)port;
382 382
383 pr_debug("%s enter\n", __FUNCTION__); 383 pr_debug("%s enter\n", __func__);
384 /* Disable sport to stop rx */ 384 /* Disable sport to stop rx */
385 SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN)); 385 SPORT_PUT_RCR1(up, (SPORT_GET_RCR1(up) & ~RSPEN));
386 SSYNC(); 386 SSYNC();
@@ -388,19 +388,19 @@ static void sport_stop_rx(struct uart_port *port)
388 388
389static void sport_enable_ms(struct uart_port *port) 389static void sport_enable_ms(struct uart_port *port)
390{ 390{
391 pr_debug("%s enter\n", __FUNCTION__); 391 pr_debug("%s enter\n", __func__);
392} 392}
393 393
394static void sport_break_ctl(struct uart_port *port, int break_state) 394static void sport_break_ctl(struct uart_port *port, int break_state)
395{ 395{
396 pr_debug("%s enter\n", __FUNCTION__); 396 pr_debug("%s enter\n", __func__);
397} 397}
398 398
399static void sport_shutdown(struct uart_port *port) 399static void sport_shutdown(struct uart_port *port)
400{ 400{
401 struct sport_uart_port *up = (struct sport_uart_port *)port; 401 struct sport_uart_port *up = (struct sport_uart_port *)port;
402 402
403 pr_debug("%s enter\n", __FUNCTION__); 403 pr_debug("%s enter\n", __func__);
404 404
405 /* Disable sport */ 405 /* Disable sport */
406 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN)); 406 SPORT_PUT_TCR1(up, (SPORT_GET_TCR1(up) & ~TSPEN));
@@ -421,7 +421,7 @@ static void sport_shutdown(struct uart_port *port)
421static void sport_set_termios(struct uart_port *port, 421static void sport_set_termios(struct uart_port *port,
422 struct termios *termios, struct termios *old) 422 struct termios *termios, struct termios *old)
423{ 423{
424 pr_debug("%s enter, c_cflag:%08x\n", __FUNCTION__, termios->c_cflag); 424 pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag);
425 uart_update_timeout(port, CS8 ,port->uartclk); 425 uart_update_timeout(port, CS8 ,port->uartclk);
426} 426}
427 427
@@ -429,18 +429,18 @@ static const char *sport_type(struct uart_port *port)
429{ 429{
430 struct sport_uart_port *up = (struct sport_uart_port *)port; 430 struct sport_uart_port *up = (struct sport_uart_port *)port;
431 431
432 pr_debug("%s enter\n", __FUNCTION__); 432 pr_debug("%s enter\n", __func__);
433 return up->name; 433 return up->name;
434} 434}
435 435
436static void sport_release_port(struct uart_port *port) 436static void sport_release_port(struct uart_port *port)
437{ 437{
438 pr_debug("%s enter\n", __FUNCTION__); 438 pr_debug("%s enter\n", __func__);
439} 439}
440 440
441static int sport_request_port(struct uart_port *port) 441static int sport_request_port(struct uart_port *port)
442{ 442{
443 pr_debug("%s enter\n", __FUNCTION__); 443 pr_debug("%s enter\n", __func__);
444 return 0; 444 return 0;
445} 445}
446 446
@@ -448,13 +448,13 @@ static void sport_config_port(struct uart_port *port, int flags)
448{ 448{
449 struct sport_uart_port *up = (struct sport_uart_port *)port; 449 struct sport_uart_port *up = (struct sport_uart_port *)port;
450 450
451 pr_debug("%s enter\n", __FUNCTION__); 451 pr_debug("%s enter\n", __func__);
452 up->port.type = PORT_BFIN_SPORT; 452 up->port.type = PORT_BFIN_SPORT;
453} 453}
454 454
455static int sport_verify_port(struct uart_port *port, struct serial_struct *ser) 455static int sport_verify_port(struct uart_port *port, struct serial_struct *ser)
456{ 456{
457 pr_debug("%s enter\n", __FUNCTION__); 457 pr_debug("%s enter\n", __func__);
458 return 0; 458 return 0;
459} 459}
460 460
@@ -527,7 +527,7 @@ static int sport_uart_suspend(struct platform_device *dev, pm_message_t state)
527{ 527{
528 struct sport_uart_port *sport = platform_get_drvdata(dev); 528 struct sport_uart_port *sport = platform_get_drvdata(dev);
529 529
530 pr_debug("%s enter\n", __FUNCTION__); 530 pr_debug("%s enter\n", __func__);
531 if (sport) 531 if (sport)
532 uart_suspend_port(&sport_uart_reg, &sport->port); 532 uart_suspend_port(&sport_uart_reg, &sport->port);
533 533
@@ -538,7 +538,7 @@ static int sport_uart_resume(struct platform_device *dev)
538{ 538{
539 struct sport_uart_port *sport = platform_get_drvdata(dev); 539 struct sport_uart_port *sport = platform_get_drvdata(dev);
540 540
541 pr_debug("%s enter\n", __FUNCTION__); 541 pr_debug("%s enter\n", __func__);
542 if (sport) 542 if (sport)
543 uart_resume_port(&sport_uart_reg, &sport->port); 543 uart_resume_port(&sport_uart_reg, &sport->port);
544 544
@@ -547,7 +547,7 @@ static int sport_uart_resume(struct platform_device *dev)
547 547
548static int sport_uart_probe(struct platform_device *dev) 548static int sport_uart_probe(struct platform_device *dev)
549{ 549{
550 pr_debug("%s enter\n", __FUNCTION__); 550 pr_debug("%s enter\n", __func__);
551 sport_uart_ports[dev->id].port.dev = &dev->dev; 551 sport_uart_ports[dev->id].port.dev = &dev->dev;
552 uart_add_one_port(&sport_uart_reg, &sport_uart_ports[dev->id].port); 552 uart_add_one_port(&sport_uart_reg, &sport_uart_ports[dev->id].port);
553 platform_set_drvdata(dev, &sport_uart_ports[dev->id]); 553 platform_set_drvdata(dev, &sport_uart_ports[dev->id]);
@@ -559,7 +559,7 @@ static int sport_uart_remove(struct platform_device *dev)
559{ 559{
560 struct sport_uart_port *sport = platform_get_drvdata(dev); 560 struct sport_uart_port *sport = platform_get_drvdata(dev);
561 561
562 pr_debug("%s enter\n", __FUNCTION__); 562 pr_debug("%s enter\n", __func__);
563 platform_set_drvdata(dev, NULL); 563 platform_set_drvdata(dev, NULL);
564 564
565 if (sport) 565 if (sport)
@@ -582,7 +582,7 @@ static int __init sport_uart_init(void)
582{ 582{
583 int ret; 583 int ret;
584 584
585 pr_debug("%s enter\n", __FUNCTION__); 585 pr_debug("%s enter\n", __func__);
586 ret = uart_register_driver(&sport_uart_reg); 586 ret = uart_register_driver(&sport_uart_reg);
587 if (ret != 0) { 587 if (ret != 0) {
588 printk(KERN_ERR "Failed to register %s:%d\n", 588 printk(KERN_ERR "Failed to register %s:%d\n",
@@ -597,13 +597,13 @@ static int __init sport_uart_init(void)
597 } 597 }
598 598
599 599
600 pr_debug("%s exit\n", __FUNCTION__); 600 pr_debug("%s exit\n", __func__);
601 return ret; 601 return ret;
602} 602}
603 603
604static void __exit sport_uart_exit(void) 604static void __exit sport_uart_exit(void)
605{ 605{
606 pr_debug("%s enter\n", __FUNCTION__); 606 pr_debug("%s enter\n", __func__);
607 platform_driver_unregister(&sport_uart_driver); 607 platform_driver_unregister(&sport_uart_driver);
608 uart_unregister_driver(&sport_uart_reg); 608 uart_unregister_driver(&sport_uart_reg);
609} 609}
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index a697914ae3d0..3547558d2caf 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -272,7 +272,7 @@ static void jsm_tty_close(struct uart_port *port)
272 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "start\n"); 272 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "start\n");
273 273
274 bd = channel->ch_bd; 274 bd = channel->ch_bd;
275 ts = channel->uart_port.info->port.tty->termios; 275 ts = port->info->port.tty->termios;
276 276
277 channel->ch_flags &= ~(CH_STOPI); 277 channel->ch_flags &= ~(CH_STOPI);
278 278
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index 874786a11fe9..dc68b7e0c930 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -50,7 +50,7 @@ static struct lock_class_key port_lock_key;
50 50
51#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) 51#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
52 52
53#define uart_users(state) ((state)->count + ((state)->info ? (state)->info->port.blocked_open : 0)) 53#define uart_users(state) ((state)->count + (state)->info.port.blocked_open)
54 54
55#ifdef CONFIG_SERIAL_CORE_CONSOLE 55#ifdef CONFIG_SERIAL_CORE_CONSOLE
56#define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line) 56#define uart_console(port) ((port)->cons && (port)->cons->index == (port)->line)
@@ -94,7 +94,7 @@ static void __uart_start(struct tty_struct *tty)
94 struct uart_state *state = tty->driver_data; 94 struct uart_state *state = tty->driver_data;
95 struct uart_port *port = state->port; 95 struct uart_port *port = state->port;
96 96
97 if (!uart_circ_empty(&state->info->xmit) && state->info->xmit.buf && 97 if (!uart_circ_empty(&state->info.xmit) && state->info.xmit.buf &&
98 !tty->stopped && !tty->hw_stopped) 98 !tty->stopped && !tty->hw_stopped)
99 port->ops->start_tx(port); 99 port->ops->start_tx(port);
100} 100}
@@ -113,7 +113,7 @@ static void uart_start(struct tty_struct *tty)
113static void uart_tasklet_action(unsigned long data) 113static void uart_tasklet_action(unsigned long data)
114{ 114{
115 struct uart_state *state = (struct uart_state *)data; 115 struct uart_state *state = (struct uart_state *)data;
116 tty_wakeup(state->info->port.tty); 116 tty_wakeup(state->info.port.tty);
117} 117}
118 118
119static inline void 119static inline void
@@ -139,7 +139,7 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
139 */ 139 */
140static int uart_startup(struct uart_state *state, int init_hw) 140static int uart_startup(struct uart_state *state, int init_hw)
141{ 141{
142 struct uart_info *info = state->info; 142 struct uart_info *info = &state->info;
143 struct uart_port *port = state->port; 143 struct uart_port *port = state->port;
144 unsigned long page; 144 unsigned long page;
145 int retval = 0; 145 int retval = 0;
@@ -212,14 +212,15 @@ static int uart_startup(struct uart_state *state, int init_hw)
212 */ 212 */
213static void uart_shutdown(struct uart_state *state) 213static void uart_shutdown(struct uart_state *state)
214{ 214{
215 struct uart_info *info = state->info; 215 struct uart_info *info = &state->info;
216 struct uart_port *port = state->port; 216 struct uart_port *port = state->port;
217 struct tty_struct *tty = info->port.tty;
217 218
218 /* 219 /*
219 * Set the TTY IO error marker 220 * Set the TTY IO error marker
220 */ 221 */
221 if (info->port.tty) 222 if (tty)
222 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 223 set_bit(TTY_IO_ERROR, &tty->flags);
223 224
224 if (info->flags & UIF_INITIALIZED) { 225 if (info->flags & UIF_INITIALIZED) {
225 info->flags &= ~UIF_INITIALIZED; 226 info->flags &= ~UIF_INITIALIZED;
@@ -227,7 +228,7 @@ static void uart_shutdown(struct uart_state *state)
227 /* 228 /*
228 * Turn off DTR and RTS early. 229 * Turn off DTR and RTS early.
229 */ 230 */
230 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) 231 if (!tty || (tty->termios->c_cflag & HUPCL))
231 uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 232 uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
232 233
233 /* 234 /*
@@ -427,7 +428,7 @@ EXPORT_SYMBOL(uart_get_divisor);
427static void 428static void
428uart_change_speed(struct uart_state *state, struct ktermios *old_termios) 429uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
429{ 430{
430 struct tty_struct *tty = state->info->port.tty; 431 struct tty_struct *tty = state->info.port.tty;
431 struct uart_port *port = state->port; 432 struct uart_port *port = state->port;
432 struct ktermios *termios; 433 struct ktermios *termios;
433 434
@@ -444,14 +445,14 @@ uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
444 * Set flags based on termios cflag 445 * Set flags based on termios cflag
445 */ 446 */
446 if (termios->c_cflag & CRTSCTS) 447 if (termios->c_cflag & CRTSCTS)
447 state->info->flags |= UIF_CTS_FLOW; 448 state->info.flags |= UIF_CTS_FLOW;
448 else 449 else
449 state->info->flags &= ~UIF_CTS_FLOW; 450 state->info.flags &= ~UIF_CTS_FLOW;
450 451
451 if (termios->c_cflag & CLOCAL) 452 if (termios->c_cflag & CLOCAL)
452 state->info->flags &= ~UIF_CHECK_CD; 453 state->info.flags &= ~UIF_CHECK_CD;
453 else 454 else
454 state->info->flags |= UIF_CHECK_CD; 455 state->info.flags |= UIF_CHECK_CD;
455 456
456 port->ops->set_termios(port, termios, old_termios); 457 port->ops->set_termios(port, termios, old_termios);
457} 458}
@@ -479,7 +480,7 @@ static int uart_put_char(struct tty_struct *tty, unsigned char ch)
479{ 480{
480 struct uart_state *state = tty->driver_data; 481 struct uart_state *state = tty->driver_data;
481 482
482 return __uart_put_char(state->port, &state->info->xmit, ch); 483 return __uart_put_char(state->port, &state->info.xmit, ch);
483} 484}
484 485
485static void uart_flush_chars(struct tty_struct *tty) 486static void uart_flush_chars(struct tty_struct *tty)
@@ -500,13 +501,13 @@ uart_write(struct tty_struct *tty, const unsigned char *buf, int count)
500 * This means you called this function _after_ the port was 501 * This means you called this function _after_ the port was
501 * closed. No cookie for you. 502 * closed. No cookie for you.
502 */ 503 */
503 if (!state || !state->info) { 504 if (!state) {
504 WARN_ON(1); 505 WARN_ON(1);
505 return -EL3HLT; 506 return -EL3HLT;
506 } 507 }
507 508
508 port = state->port; 509 port = state->port;
509 circ = &state->info->xmit; 510 circ = &state->info.xmit;
510 511
511 if (!circ->buf) 512 if (!circ->buf)
512 return 0; 513 return 0;
@@ -537,7 +538,7 @@ static int uart_write_room(struct tty_struct *tty)
537 int ret; 538 int ret;
538 539
539 spin_lock_irqsave(&state->port->lock, flags); 540 spin_lock_irqsave(&state->port->lock, flags);
540 ret = uart_circ_chars_free(&state->info->xmit); 541 ret = uart_circ_chars_free(&state->info.xmit);
541 spin_unlock_irqrestore(&state->port->lock, flags); 542 spin_unlock_irqrestore(&state->port->lock, flags);
542 return ret; 543 return ret;
543} 544}
@@ -549,7 +550,7 @@ static int uart_chars_in_buffer(struct tty_struct *tty)
549 int ret; 550 int ret;
550 551
551 spin_lock_irqsave(&state->port->lock, flags); 552 spin_lock_irqsave(&state->port->lock, flags);
552 ret = uart_circ_chars_pending(&state->info->xmit); 553 ret = uart_circ_chars_pending(&state->info.xmit);
553 spin_unlock_irqrestore(&state->port->lock, flags); 554 spin_unlock_irqrestore(&state->port->lock, flags);
554 return ret; 555 return ret;
555} 556}
@@ -564,7 +565,7 @@ static void uart_flush_buffer(struct tty_struct *tty)
564 * This means you called this function _after_ the port was 565 * This means you called this function _after_ the port was
565 * closed. No cookie for you. 566 * closed. No cookie for you.
566 */ 567 */
567 if (!state || !state->info) { 568 if (!state) {
568 WARN_ON(1); 569 WARN_ON(1);
569 return; 570 return;
570 } 571 }
@@ -573,7 +574,7 @@ static void uart_flush_buffer(struct tty_struct *tty)
573 pr_debug("uart_flush_buffer(%d) called\n", tty->index); 574 pr_debug("uart_flush_buffer(%d) called\n", tty->index);
574 575
575 spin_lock_irqsave(&port->lock, flags); 576 spin_lock_irqsave(&port->lock, flags);
576 uart_circ_clear(&state->info->xmit); 577 uart_circ_clear(&state->info.xmit);
577 if (port->ops->flush_buffer) 578 if (port->ops->flush_buffer)
578 port->ops->flush_buffer(port); 579 port->ops->flush_buffer(port);
579 spin_unlock_irqrestore(&port->lock, flags); 580 spin_unlock_irqrestore(&port->lock, flags);
@@ -837,15 +838,15 @@ static int uart_set_info(struct uart_state *state,
837 state->closing_wait = closing_wait; 838 state->closing_wait = closing_wait;
838 if (new_serial.xmit_fifo_size) 839 if (new_serial.xmit_fifo_size)
839 port->fifosize = new_serial.xmit_fifo_size; 840 port->fifosize = new_serial.xmit_fifo_size;
840 if (state->info->port.tty) 841 if (state->info.port.tty)
841 state->info->port.tty->low_latency = 842 state->info.port.tty->low_latency =
842 (port->flags & UPF_LOW_LATENCY) ? 1 : 0; 843 (port->flags & UPF_LOW_LATENCY) ? 1 : 0;
843 844
844 check_and_exit: 845 check_and_exit:
845 retval = 0; 846 retval = 0;
846 if (port->type == PORT_UNKNOWN) 847 if (port->type == PORT_UNKNOWN)
847 goto exit; 848 goto exit;
848 if (state->info->flags & UIF_INITIALIZED) { 849 if (state->info.flags & UIF_INITIALIZED) {
849 if (((old_flags ^ port->flags) & UPF_SPD_MASK) || 850 if (((old_flags ^ port->flags) & UPF_SPD_MASK) ||
850 old_custom_divisor != port->custom_divisor) { 851 old_custom_divisor != port->custom_divisor) {
851 /* 852 /*
@@ -858,7 +859,7 @@ static int uart_set_info(struct uart_state *state,
858 printk(KERN_NOTICE 859 printk(KERN_NOTICE
859 "%s sets custom speed on %s. This " 860 "%s sets custom speed on %s. This "
860 "is deprecated.\n", current->comm, 861 "is deprecated.\n", current->comm,
861 tty_name(state->info->port.tty, buf)); 862 tty_name(state->info.port.tty, buf));
862 } 863 }
863 uart_change_speed(state, NULL); 864 uart_change_speed(state, NULL);
864 } 865 }
@@ -889,8 +890,8 @@ static int uart_get_lsr_info(struct uart_state *state,
889 * interrupt happens). 890 * interrupt happens).
890 */ 891 */
891 if (port->x_char || 892 if (port->x_char ||
892 ((uart_circ_chars_pending(&state->info->xmit) > 0) && 893 ((uart_circ_chars_pending(&state->info.xmit) > 0) &&
893 !state->info->port.tty->stopped && !state->info->port.tty->hw_stopped)) 894 !state->info.port.tty->stopped && !state->info.port.tty->hw_stopped))
894 result &= ~TIOCSER_TEMT; 895 result &= ~TIOCSER_TEMT;
895 896
896 return put_user(result, value); 897 return put_user(result, value);
@@ -1017,7 +1018,7 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1017 port->ops->enable_ms(port); 1018 port->ops->enable_ms(port);
1018 spin_unlock_irq(&port->lock); 1019 spin_unlock_irq(&port->lock);
1019 1020
1020 add_wait_queue(&state->info->delta_msr_wait, &wait); 1021 add_wait_queue(&state->info.delta_msr_wait, &wait);
1021 for (;;) { 1022 for (;;) {
1022 spin_lock_irq(&port->lock); 1023 spin_lock_irq(&port->lock);
1023 memcpy(&cnow, &port->icount, sizeof(struct uart_icount)); 1024 memcpy(&cnow, &port->icount, sizeof(struct uart_icount));
@@ -1045,7 +1046,7 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
1045 } 1046 }
1046 1047
1047 current->state = TASK_RUNNING; 1048 current->state = TASK_RUNNING;
1048 remove_wait_queue(&state->info->delta_msr_wait, &wait); 1049 remove_wait_queue(&state->info.delta_msr_wait, &wait);
1049 1050
1050 return ret; 1051 return ret;
1051} 1052}
@@ -1241,7 +1242,7 @@ static void uart_set_termios(struct tty_struct *tty,
1241 */ 1242 */
1242 if (!(old_termios->c_cflag & CLOCAL) && 1243 if (!(old_termios->c_cflag & CLOCAL) &&
1243 (tty->termios->c_cflag & CLOCAL)) 1244 (tty->termios->c_cflag & CLOCAL))
1244 wake_up_interruptible(&state->info->port.open_wait); 1245 wake_up_interruptible(&info->port.open_wait);
1245#endif 1246#endif
1246} 1247}
1247 1248
@@ -1303,7 +1304,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1303 * At this point, we stop accepting input. To do this, we 1304 * At this point, we stop accepting input. To do this, we
1304 * disable the receive line status interrupts. 1305 * disable the receive line status interrupts.
1305 */ 1306 */
1306 if (state->info->flags & UIF_INITIALIZED) { 1307 if (state->info.flags & UIF_INITIALIZED) {
1307 unsigned long flags; 1308 unsigned long flags;
1308 spin_lock_irqsave(&port->lock, flags); 1309 spin_lock_irqsave(&port->lock, flags);
1309 port->ops->stop_rx(port); 1310 port->ops->stop_rx(port);
@@ -1322,9 +1323,9 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1322 tty_ldisc_flush(tty); 1323 tty_ldisc_flush(tty);
1323 1324
1324 tty->closing = 0; 1325 tty->closing = 0;
1325 state->info->port.tty = NULL; 1326 state->info.port.tty = NULL;
1326 1327
1327 if (state->info->port.blocked_open) { 1328 if (state->info.port.blocked_open) {
1328 if (state->close_delay) 1329 if (state->close_delay)
1329 msleep_interruptible(state->close_delay); 1330 msleep_interruptible(state->close_delay);
1330 } else if (!uart_console(port)) { 1331 } else if (!uart_console(port)) {
@@ -1334,8 +1335,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
1334 /* 1335 /*
1335 * Wake up anyone trying to open this port. 1336 * Wake up anyone trying to open this port.
1336 */ 1337 */
1337 state->info->flags &= ~UIF_NORMAL_ACTIVE; 1338 state->info.flags &= ~UIF_NORMAL_ACTIVE;
1338 wake_up_interruptible(&state->info->port.open_wait); 1339 wake_up_interruptible(&state->info.port.open_wait);
1339 1340
1340 done: 1341 done:
1341 mutex_unlock(&state->mutex); 1342 mutex_unlock(&state->mutex);
@@ -1409,19 +1410,20 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
1409static void uart_hangup(struct tty_struct *tty) 1410static void uart_hangup(struct tty_struct *tty)
1410{ 1411{
1411 struct uart_state *state = tty->driver_data; 1412 struct uart_state *state = tty->driver_data;
1413 struct uart_info *info = &state->info;
1412 1414
1413 BUG_ON(!kernel_locked()); 1415 BUG_ON(!kernel_locked());
1414 pr_debug("uart_hangup(%d)\n", state->port->line); 1416 pr_debug("uart_hangup(%d)\n", state->port->line);
1415 1417
1416 mutex_lock(&state->mutex); 1418 mutex_lock(&state->mutex);
1417 if (state->info && state->info->flags & UIF_NORMAL_ACTIVE) { 1419 if (info->flags & UIF_NORMAL_ACTIVE) {
1418 uart_flush_buffer(tty); 1420 uart_flush_buffer(tty);
1419 uart_shutdown(state); 1421 uart_shutdown(state);
1420 state->count = 0; 1422 state->count = 0;
1421 state->info->flags &= ~UIF_NORMAL_ACTIVE; 1423 info->flags &= ~UIF_NORMAL_ACTIVE;
1422 state->info->port.tty = NULL; 1424 info->port.tty = NULL;
1423 wake_up_interruptible(&state->info->port.open_wait); 1425 wake_up_interruptible(&info->port.open_wait);
1424 wake_up_interruptible(&state->info->delta_msr_wait); 1426 wake_up_interruptible(&info->delta_msr_wait);
1425 } 1427 }
1426 mutex_unlock(&state->mutex); 1428 mutex_unlock(&state->mutex);
1427} 1429}
@@ -1434,7 +1436,7 @@ static void uart_hangup(struct tty_struct *tty)
1434 */ 1436 */
1435static void uart_update_termios(struct uart_state *state) 1437static void uart_update_termios(struct uart_state *state)
1436{ 1438{
1437 struct tty_struct *tty = state->info->port.tty; 1439 struct tty_struct *tty = state->info.port.tty;
1438 struct uart_port *port = state->port; 1440 struct uart_port *port = state->port;
1439 1441
1440 if (uart_console(port) && port->cons->cflag) { 1442 if (uart_console(port) && port->cons->cflag) {
@@ -1469,7 +1471,7 @@ static int
1469uart_block_til_ready(struct file *filp, struct uart_state *state) 1471uart_block_til_ready(struct file *filp, struct uart_state *state)
1470{ 1472{
1471 DECLARE_WAITQUEUE(wait, current); 1473 DECLARE_WAITQUEUE(wait, current);
1472 struct uart_info *info = state->info; 1474 struct uart_info *info = &state->info;
1473 struct uart_port *port = state->port; 1475 struct uart_port *port = state->port;
1474 unsigned int mctrl; 1476 unsigned int mctrl;
1475 1477
@@ -1563,28 +1565,6 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line)
1563 ret = -ENXIO; 1565 ret = -ENXIO;
1564 goto err_unlock; 1566 goto err_unlock;
1565 } 1567 }
1566
1567 /* BKL: RACE HERE - LEAK */
1568 /* We should move this into the uart_state structure and kill off
1569 this whole complexity */
1570 if (!state->info) {
1571 state->info = kzalloc(sizeof(struct uart_info), GFP_KERNEL);
1572 if (state->info) {
1573 init_waitqueue_head(&state->info->port.open_wait);
1574 init_waitqueue_head(&state->info->delta_msr_wait);
1575
1576 /*
1577 * Link the info into the other structures.
1578 */
1579 state->port->info = state->info;
1580
1581 tasklet_init(&state->info->tlet, uart_tasklet_action,
1582 (unsigned long)state);
1583 } else {
1584 ret = -ENOMEM;
1585 goto err_unlock;
1586 }
1587 }
1588 return state; 1568 return state;
1589 1569
1590 err_unlock: 1570 err_unlock:
@@ -1641,9 +1621,10 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1641 * Any failures from here onwards should not touch the count. 1621 * Any failures from here onwards should not touch the count.
1642 */ 1622 */
1643 tty->driver_data = state; 1623 tty->driver_data = state;
1624 state->port->info = &state->info;
1644 tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0; 1625 tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0;
1645 tty->alt_speed = 0; 1626 tty->alt_speed = 0;
1646 state->info->port.tty = tty; 1627 state->info.port.tty = tty;
1647 1628
1648 /* 1629 /*
1649 * If the port is in the middle of closing, bail out now. 1630 * If the port is in the middle of closing, bail out now.
@@ -1676,8 +1657,8 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
1676 /* 1657 /*
1677 * If this is the first open to succeed, adjust things to suit. 1658 * If this is the first open to succeed, adjust things to suit.
1678 */ 1659 */
1679 if (retval == 0 && !(state->info->flags & UIF_NORMAL_ACTIVE)) { 1660 if (retval == 0 && !(state->info.flags & UIF_NORMAL_ACTIVE)) {
1680 state->info->flags |= UIF_NORMAL_ACTIVE; 1661 state->info.flags |= UIF_NORMAL_ACTIVE;
1681 1662
1682 uart_update_termios(state); 1663 uart_update_termios(state);
1683 } 1664 }
@@ -2028,11 +2009,11 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
2028 } 2009 }
2029 port->suspended = 1; 2010 port->suspended = 1;
2030 2011
2031 if (state->info && state->info->flags & UIF_INITIALIZED) { 2012 if (state->info.flags & UIF_INITIALIZED) {
2032 const struct uart_ops *ops = port->ops; 2013 const struct uart_ops *ops = port->ops;
2033 int tries; 2014 int tries;
2034 2015
2035 state->info->flags = (state->info->flags & ~UIF_INITIALIZED) 2016 state->info.flags = (state->info.flags & ~UIF_INITIALIZED)
2036 | UIF_SUSPENDED; 2017 | UIF_SUSPENDED;
2037 2018
2038 spin_lock_irq(&port->lock); 2019 spin_lock_irq(&port->lock);
@@ -2107,15 +2088,15 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
2107 /* 2088 /*
2108 * If that's unset, use the tty termios setting. 2089 * If that's unset, use the tty termios setting.
2109 */ 2090 */
2110 if (state->info && state->info->port.tty && termios.c_cflag == 0) 2091 if (state->info.port.tty && termios.c_cflag == 0)
2111 termios = *state->info->port.tty->termios; 2092 termios = *state->info.port.tty->termios;
2112 2093
2113 uart_change_pm(state, 0); 2094 uart_change_pm(state, 0);
2114 port->ops->set_termios(port, &termios, NULL); 2095 port->ops->set_termios(port, &termios, NULL);
2115 console_start(port->cons); 2096 console_start(port->cons);
2116 } 2097 }
2117 2098
2118 if (state->info && state->info->flags & UIF_SUSPENDED) { 2099 if (state->info.flags & UIF_SUSPENDED) {
2119 const struct uart_ops *ops = port->ops; 2100 const struct uart_ops *ops = port->ops;
2120 int ret; 2101 int ret;
2121 2102
@@ -2130,7 +2111,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
2130 ops->set_mctrl(port, port->mctrl); 2111 ops->set_mctrl(port, port->mctrl);
2131 ops->start_tx(port); 2112 ops->start_tx(port);
2132 spin_unlock_irq(&port->lock); 2113 spin_unlock_irq(&port->lock);
2133 state->info->flags |= UIF_INITIALIZED; 2114 state->info.flags |= UIF_INITIALIZED;
2134 } else { 2115 } else {
2135 /* 2116 /*
2136 * Failed to resume - maybe hardware went away? 2117 * Failed to resume - maybe hardware went away?
@@ -2140,7 +2121,7 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
2140 uart_shutdown(state); 2121 uart_shutdown(state);
2141 } 2122 }
2142 2123
2143 state->info->flags &= ~UIF_SUSPENDED; 2124 state->info.flags &= ~UIF_SUSPENDED;
2144 } 2125 }
2145 2126
2146 mutex_unlock(&state->mutex); 2127 mutex_unlock(&state->mutex);
@@ -2198,11 +2179,14 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
2198 * Now do the auto configuration stuff. Note that config_port 2179 * Now do the auto configuration stuff. Note that config_port
2199 * is expected to claim the resources and map the port for us. 2180 * is expected to claim the resources and map the port for us.
2200 */ 2181 */
2201 flags = UART_CONFIG_TYPE; 2182 flags = 0;
2202 if (port->flags & UPF_AUTO_IRQ) 2183 if (port->flags & UPF_AUTO_IRQ)
2203 flags |= UART_CONFIG_IRQ; 2184 flags |= UART_CONFIG_IRQ;
2204 if (port->flags & UPF_BOOT_AUTOCONF) { 2185 if (port->flags & UPF_BOOT_AUTOCONF) {
2205 port->type = PORT_UNKNOWN; 2186 if (!(port->flags & UPF_FIXED_TYPE)) {
2187 port->type = PORT_UNKNOWN;
2188 flags |= UART_CONFIG_TYPE;
2189 }
2206 port->ops->config_port(port, flags); 2190 port->ops->config_port(port, flags);
2207 } 2191 }
2208 2192
@@ -2383,8 +2367,12 @@ int uart_register_driver(struct uart_driver *drv)
2383 2367
2384 state->close_delay = 500; /* .5 seconds */ 2368 state->close_delay = 500; /* .5 seconds */
2385 state->closing_wait = 30000; /* 30 seconds */ 2369 state->closing_wait = 30000; /* 30 seconds */
2386
2387 mutex_init(&state->mutex); 2370 mutex_init(&state->mutex);
2371
2372 tty_port_init(&state->info.port);
2373 init_waitqueue_head(&state->info.delta_msr_wait);
2374 tasklet_init(&state->info.tlet, uart_tasklet_action,
2375 (unsigned long)state);
2388 } 2376 }
2389 2377
2390 retval = tty_register_driver(normal); 2378 retval = tty_register_driver(normal);
@@ -2455,7 +2443,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *port)
2455 state->pm_state = -1; 2443 state->pm_state = -1;
2456 2444
2457 port->cons = drv->cons; 2445 port->cons = drv->cons;
2458 port->info = state->info; 2446 port->info = &state->info;
2459 2447
2460 /* 2448 /*
2461 * If this port is a console, then the spinlock is already 2449 * If this port is a console, then the spinlock is already
@@ -2527,18 +2515,11 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)
2527 */ 2515 */
2528 tty_unregister_device(drv->tty_driver, port->line); 2516 tty_unregister_device(drv->tty_driver, port->line);
2529 2517
2530 info = state->info; 2518 info = &state->info;
2531 if (info && info->port.tty) 2519 if (info && info->port.tty)
2532 tty_vhangup(info->port.tty); 2520 tty_vhangup(info->port.tty);
2533 2521
2534 /* 2522 /*
2535 * All users of this port should now be disconnected from
2536 * this driver, and the port shut down. We should be the
2537 * only thread fiddling with this port from now on.
2538 */
2539 state->info = NULL;
2540
2541 /*
2542 * Free the port IO and memory resources, if any. 2523 * Free the port IO and memory resources, if any.
2543 */ 2524 */
2544 if (port->type != PORT_UNKNOWN) 2525 if (port->type != PORT_UNKNOWN)
@@ -2552,10 +2533,8 @@ int uart_remove_one_port(struct uart_driver *drv, struct uart_port *port)
2552 /* 2533 /*
2553 * Kill the tasklet, and free resources. 2534 * Kill the tasklet, and free resources.
2554 */ 2535 */
2555 if (info) { 2536 if (info)
2556 tasklet_kill(&info->tlet); 2537 tasklet_kill(&info->tlet);
2557 kfree(info);
2558 }
2559 2538
2560 state->port = NULL; 2539 state->port = NULL;
2561 mutex_unlock(&port_mutex); 2540 mutex_unlock(&port_mutex);
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 5b95009d2fbb..19e24045b137 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -241,12 +241,25 @@ static void usb_console_write(struct console *co,
241 } 241 }
242} 242}
243 243
244static struct tty_driver *usb_console_device(struct console *co, int *index)
245{
246 struct tty_driver **p = (struct tty_driver **)co->data;
247
248 if (!*p)
249 return NULL;
250
251 *index = co->index;
252 return *p;
253}
254
244static struct console usbcons = { 255static struct console usbcons = {
245 .name = "ttyUSB", 256 .name = "ttyUSB",
246 .write = usb_console_write, 257 .write = usb_console_write,
258 .device = usb_console_device,
247 .setup = usb_console_setup, 259 .setup = usb_console_setup,
248 .flags = CON_PRINTBUFFER, 260 .flags = CON_PRINTBUFFER,
249 .index = -1, 261 .index = -1,
262 .data = &usb_serial_tty_driver,
250}; 263};
251 264
252void usb_serial_console_disconnect(struct usb_serial *serial) 265void usb_serial_console_disconnect(struct usb_serial *serial)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index fb6f2933b01b..ef6cfa5a447f 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1054,6 +1054,8 @@ static int set_serial_info(struct tty_struct *tty,
1054 1054
1055 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) 1055 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
1056 return -EFAULT; 1056 return -EFAULT;
1057
1058 lock_kernel();
1057 old_priv = *priv; 1059 old_priv = *priv;
1058 1060
1059 /* Do error checking and permission checking */ 1061 /* Do error checking and permission checking */
@@ -1069,8 +1071,10 @@ static int set_serial_info(struct tty_struct *tty,
1069 } 1071 }
1070 1072
1071 if ((new_serial.baud_base != priv->baud_base) && 1073 if ((new_serial.baud_base != priv->baud_base) &&
1072 (new_serial.baud_base < 9600)) 1074 (new_serial.baud_base < 9600)) {
1075 unlock_kernel();
1073 return -EINVAL; 1076 return -EINVAL;
1077 }
1074 1078
1075 /* Make the changes - these are privileged changes! */ 1079 /* Make the changes - these are privileged changes! */
1076 1080
@@ -1098,8 +1102,11 @@ check_and_exit:
1098 (priv->flags & ASYNC_SPD_MASK)) || 1102 (priv->flags & ASYNC_SPD_MASK)) ||
1099 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 1103 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
1100 (old_priv.custom_divisor != priv->custom_divisor))) { 1104 (old_priv.custom_divisor != priv->custom_divisor))) {
1105 unlock_kernel();
1101 change_speed(tty, port); 1106 change_speed(tty, port);
1102 } 1107 }
1108 else
1109 unlock_kernel();
1103 return 0; 1110 return 0;
1104 1111
1105} /* set_serial_info */ 1112} /* set_serial_info */
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index dc36a052766f..fcd9082f3e7f 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -878,6 +878,7 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
878 878
879 dbg("%sstate=%d", __func__, break_state); 879 dbg("%sstate=%d", __func__, break_state);
880 880
881 /* LOCKING */
881 if (break_state) 882 if (break_state)
882 lcr |= MCT_U232_SET_BREAK; 883 lcr |= MCT_U232_SET_BREAK;
883 884
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 07710cf31d0d..82930a7d5093 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -721,10 +721,10 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
721 721
722 spin_lock_irqsave(&priv->lock, flags); 722 spin_lock_irqsave(&priv->lock, flags);
723 lcr = priv->last_lcr; 723 lcr = priv->last_lcr;
724 spin_unlock_irqrestore(&priv->lock, flags);
725 724
726 if (break_state) 725 if (break_state)
727 lcr |= MCT_U232_SET_BREAK; 726 lcr |= MCT_U232_SET_BREAK;
727 spin_unlock_irqrestore(&priv->lock, flags);
728 728
729 mct_u232_set_line_ctrl(serial, lcr); 729 mct_u232_set_line_ctrl(serial, lcr);
730} /* mct_u232_break_ctl */ 730} /* mct_u232_break_ctl */
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index fda4a6421c44..96a8c7713212 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1343,6 +1343,7 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
1343 else 1343 else
1344 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK; 1344 data = mos7840_port->shadowLCR & ~LCR_SET_BREAK;
1345 1345
1346 /* FIXME: no locking on shadowLCR anywhere in driver */
1346 mos7840_port->shadowLCR = data; 1347 mos7840_port->shadowLCR = data;
1347 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n", 1348 dbg("mcs7840_break mos7840_port->shadowLCR is %x\n",
1348 mos7840_port->shadowLCR); 1349 mos7840_port->shadowLCR);
@@ -2214,10 +2215,12 @@ static int mos7840_set_modem_info(struct moschip_port *mos7840_port,
2214 break; 2215 break;
2215 } 2216 }
2216 2217
2218 lock_kernel();
2217 mos7840_port->shadowMCR = mcr; 2219 mos7840_port->shadowMCR = mcr;
2218 2220
2219 Data = mos7840_port->shadowMCR; 2221 Data = mos7840_port->shadowMCR;
2220 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data); 2222 status = mos7840_set_uart_reg(port, MODEM_CONTROL_REGISTER, Data);
2223 unlock_kernel();
2221 if (status < 0) { 2224 if (status < 0) {
2222 dbg("setting MODEM_CONTROL_REGISTER Failed\n"); 2225 dbg("setting MODEM_CONTROL_REGISTER Failed\n");
2223 return -1; 2226 return -1;
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 0f2b67244af6..d9bf9a5c20ec 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -442,7 +442,7 @@ static void sierra_indat_callback(struct urb *urb)
442 " endpoint %02x.", __func__, status, endpoint); 442 " endpoint %02x.", __func__, status, endpoint);
443 } else { 443 } else {
444 if (urb->actual_length) { 444 if (urb->actual_length) {
445 tty = tty_port_tty_get(&port->port); 445 tty = tty_port_tty_get(&port->port);
446 tty_buffer_request_room(tty, urb->actual_length); 446 tty_buffer_request_room(tty, urb->actual_length);
447 tty_insert_flip_string(tty, data, urb->actual_length); 447 tty_insert_flip_string(tty, data, urb->actual_length);
448 tty_flip_buffer_push(tty); 448 tty_flip_buffer_push(tty);
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 794b5ffe4397..080ade223d53 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -269,15 +269,19 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
269 return; 269 return;
270 } 270 }
271 271
272 --port->port.count; 272 if (port->port.count == 1)
273 if (port->port.count == 0)
274 /* only call the device specific close if this 273 /* only call the device specific close if this
275 * port is being closed by the last owner */ 274 * port is being closed by the last owner. Ensure we do
275 * this before we drop the port count. The call is protected
276 * by the port mutex
277 */
276 port->serial->type->close(tty, port, filp); 278 port->serial->type->close(tty, port, filp);
277 279
278 if (port->port.count == (port->console? 1 : 0)) { 280 if (port->port.count == (port->console ? 2 : 1)) {
279 struct tty_struct *tty = tty_port_tty_get(&port->port); 281 struct tty_struct *tty = tty_port_tty_get(&port->port);
280 if (tty) { 282 if (tty) {
283 /* We must do this before we drop the port count to
284 zero. */
281 if (tty->driver_data) 285 if (tty->driver_data)
282 tty->driver_data = NULL; 286 tty->driver_data = NULL;
283 tty_port_tty_set(&port->port, NULL); 287 tty_port_tty_set(&port->port, NULL);
@@ -285,13 +289,14 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
285 } 289 }
286 } 290 }
287 291
288 if (port->port.count == 0) { 292 if (port->port.count == 1) {
289 mutex_lock(&port->serial->disc_mutex); 293 mutex_lock(&port->serial->disc_mutex);
290 if (!port->serial->disconnected) 294 if (!port->serial->disconnected)
291 usb_autopm_put_interface(port->serial->interface); 295 usb_autopm_put_interface(port->serial->interface);
292 mutex_unlock(&port->serial->disc_mutex); 296 mutex_unlock(&port->serial->disc_mutex);
293 module_put(port->serial->type->driver.owner); 297 module_put(port->serial->type->driver.owner);
294 } 298 }
299 --port->port.count;
295 300
296 mutex_unlock(&port->mutex); 301 mutex_unlock(&port->mutex);
297 usb_serial_put(port->serial); 302 usb_serial_put(port->serial);
@@ -334,6 +339,10 @@ static int serial_chars_in_buffer(struct tty_struct *tty)
334 dbg("%s = port %d", __func__, port->number); 339 dbg("%s = port %d", __func__, port->number);
335 340
336 WARN_ON(!port->port.count); 341 WARN_ON(!port->port.count);
342 /* if the device was unplugged then any remaining characters
343 fell out of the connector ;) */
344 if (port->serial->disconnected)
345 return 0;
337 /* pass on to the driver specific version of this function */ 346 /* pass on to the driver specific version of this function */
338 return port->serial->type->chars_in_buffer(tty); 347 return port->serial->type->chars_in_buffer(tty);
339} 348}
@@ -373,9 +382,7 @@ static int serial_ioctl(struct tty_struct *tty, struct file *file,
373 /* pass on to the driver specific version of this function 382 /* pass on to the driver specific version of this function
374 if it is available */ 383 if it is available */
375 if (port->serial->type->ioctl) { 384 if (port->serial->type->ioctl) {
376 lock_kernel();
377 retval = port->serial->type->ioctl(tty, file, cmd, arg); 385 retval = port->serial->type->ioctl(tty, file, cmd, arg);
378 unlock_kernel();
379 } else 386 } else
380 retval = -ENOIOCTLCMD; 387 retval = -ENOIOCTLCMD;
381 return retval; 388 return retval;
@@ -404,11 +411,8 @@ static int serial_break(struct tty_struct *tty, int break_state)
404 WARN_ON(!port->port.count); 411 WARN_ON(!port->port.count);
405 /* pass on to the driver specific version of this function 412 /* pass on to the driver specific version of this function
406 if it is available */ 413 if it is available */
407 if (port->serial->type->break_ctl) { 414 if (port->serial->type->break_ctl)
408 lock_kernel();
409 port->serial->type->break_ctl(tty, break_state); 415 port->serial->type->break_ctl(tty, break_state);
410 unlock_kernel();
411 }
412 return 0; 416 return 0;
413} 417}
414 418
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 5d61b7c06e13..fff96e152c0c 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -27,25 +27,32 @@
27#define DEVPTS_SUPER_MAGIC 0x1cd1 27#define DEVPTS_SUPER_MAGIC 0x1cd1
28 28
29#define DEVPTS_DEFAULT_MODE 0600 29#define DEVPTS_DEFAULT_MODE 0600
30/*
31 * ptmx is a new node in /dev/pts and will be unused in legacy (single-
32 * instance) mode. To prevent surprises in user space, set permissions of
33 * ptmx to 0. Use 'chmod' or remount with '-o ptmxmode' to set meaningful
34 * permissions.
35 */
36#define DEVPTS_DEFAULT_PTMX_MODE 0000
30#define PTMX_MINOR 2 37#define PTMX_MINOR 2
31 38
32extern int pty_limit; /* Config limit on Unix98 ptys */ 39extern int pty_limit; /* Config limit on Unix98 ptys */
33static DEFINE_IDA(allocated_ptys);
34static DEFINE_MUTEX(allocated_ptys_lock); 40static DEFINE_MUTEX(allocated_ptys_lock);
35 41
36static struct vfsmount *devpts_mnt; 42static struct vfsmount *devpts_mnt;
37static struct dentry *devpts_root;
38 43
39static struct { 44struct pts_mount_opts {
40 int setuid; 45 int setuid;
41 int setgid; 46 int setgid;
42 uid_t uid; 47 uid_t uid;
43 gid_t gid; 48 gid_t gid;
44 umode_t mode; 49 umode_t mode;
45} config = {.mode = DEVPTS_DEFAULT_MODE}; 50 umode_t ptmxmode;
51 int newinstance;
52};
46 53
47enum { 54enum {
48 Opt_uid, Opt_gid, Opt_mode, 55 Opt_uid, Opt_gid, Opt_mode, Opt_ptmxmode, Opt_newinstance,
49 Opt_err 56 Opt_err
50}; 57};
51 58
@@ -53,18 +60,50 @@ static const match_table_t tokens = {
53 {Opt_uid, "uid=%u"}, 60 {Opt_uid, "uid=%u"},
54 {Opt_gid, "gid=%u"}, 61 {Opt_gid, "gid=%u"},
55 {Opt_mode, "mode=%o"}, 62 {Opt_mode, "mode=%o"},
63#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
64 {Opt_ptmxmode, "ptmxmode=%o"},
65 {Opt_newinstance, "newinstance"},
66#endif
56 {Opt_err, NULL} 67 {Opt_err, NULL}
57}; 68};
58 69
59static int devpts_remount(struct super_block *sb, int *flags, char *data) 70struct pts_fs_info {
71 struct ida allocated_ptys;
72 struct pts_mount_opts mount_opts;
73 struct dentry *ptmx_dentry;
74};
75
76static inline struct pts_fs_info *DEVPTS_SB(struct super_block *sb)
77{
78 return sb->s_fs_info;
79}
80
81static inline struct super_block *pts_sb_from_inode(struct inode *inode)
82{
83#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
84 if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
85 return inode->i_sb;
86#endif
87 return devpts_mnt->mnt_sb;
88}
89
90#define PARSE_MOUNT 0
91#define PARSE_REMOUNT 1
92
93static int parse_mount_options(char *data, int op, struct pts_mount_opts *opts)
60{ 94{
61 char *p; 95 char *p;
62 96
63 config.setuid = 0; 97 opts->setuid = 0;
64 config.setgid = 0; 98 opts->setgid = 0;
65 config.uid = 0; 99 opts->uid = 0;
66 config.gid = 0; 100 opts->gid = 0;
67 config.mode = DEVPTS_DEFAULT_MODE; 101 opts->mode = DEVPTS_DEFAULT_MODE;
102 opts->ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
103
104 /* newinstance makes sense only on initial mount */
105 if (op == PARSE_MOUNT)
106 opts->newinstance = 0;
68 107
69 while ((p = strsep(&data, ",")) != NULL) { 108 while ((p = strsep(&data, ",")) != NULL) {
70 substring_t args[MAX_OPT_ARGS]; 109 substring_t args[MAX_OPT_ARGS];
@@ -79,20 +118,32 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data)
79 case Opt_uid: 118 case Opt_uid:
80 if (match_int(&args[0], &option)) 119 if (match_int(&args[0], &option))
81 return -EINVAL; 120 return -EINVAL;
82 config.uid = option; 121 opts->uid = option;
83 config.setuid = 1; 122 opts->setuid = 1;
84 break; 123 break;
85 case Opt_gid: 124 case Opt_gid:
86 if (match_int(&args[0], &option)) 125 if (match_int(&args[0], &option))
87 return -EINVAL; 126 return -EINVAL;
88 config.gid = option; 127 opts->gid = option;
89 config.setgid = 1; 128 opts->setgid = 1;
90 break; 129 break;
91 case Opt_mode: 130 case Opt_mode:
92 if (match_octal(&args[0], &option)) 131 if (match_octal(&args[0], &option))
93 return -EINVAL; 132 return -EINVAL;
94 config.mode = option & S_IALLUGO; 133 opts->mode = option & S_IALLUGO;
134 break;
135#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
136 case Opt_ptmxmode:
137 if (match_octal(&args[0], &option))
138 return -EINVAL;
139 opts->ptmxmode = option & S_IALLUGO;
140 break;
141 case Opt_newinstance:
142 /* newinstance makes sense only on initial mount */
143 if (op == PARSE_MOUNT)
144 opts->newinstance = 1;
95 break; 145 break;
146#endif
96 default: 147 default:
97 printk(KERN_ERR "devpts: called with bogus options\n"); 148 printk(KERN_ERR "devpts: called with bogus options\n");
98 return -EINVAL; 149 return -EINVAL;
@@ -102,13 +153,108 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data)
102 return 0; 153 return 0;
103} 154}
104 155
156#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
157static int mknod_ptmx(struct super_block *sb)
158{
159 int mode;
160 int rc = -ENOMEM;
161 struct dentry *dentry;
162 struct inode *inode;
163 struct dentry *root = sb->s_root;
164 struct pts_fs_info *fsi = DEVPTS_SB(sb);
165 struct pts_mount_opts *opts = &fsi->mount_opts;
166
167 mutex_lock(&root->d_inode->i_mutex);
168
169 /* If we have already created ptmx node, return */
170 if (fsi->ptmx_dentry) {
171 rc = 0;
172 goto out;
173 }
174
175 dentry = d_alloc_name(root, "ptmx");
176 if (!dentry) {
177 printk(KERN_NOTICE "Unable to alloc dentry for ptmx node\n");
178 goto out;
179 }
180
181 /*
182 * Create a new 'ptmx' node in this mount of devpts.
183 */
184 inode = new_inode(sb);
185 if (!inode) {
186 printk(KERN_ERR "Unable to alloc inode for ptmx node\n");
187 dput(dentry);
188 goto out;
189 }
190
191 inode->i_ino = 2;
192 inode->i_uid = inode->i_gid = 0;
193 inode->i_blocks = 0;
194 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
195
196 mode = S_IFCHR|opts->ptmxmode;
197 init_special_inode(inode, mode, MKDEV(TTYAUX_MAJOR, 2));
198
199 d_add(dentry, inode);
200
201 fsi->ptmx_dentry = dentry;
202 rc = 0;
203
204 printk(KERN_DEBUG "Created ptmx node in devpts ino %lu\n",
205 inode->i_ino);
206out:
207 mutex_unlock(&root->d_inode->i_mutex);
208 return rc;
209}
210
211static void update_ptmx_mode(struct pts_fs_info *fsi)
212{
213 struct inode *inode;
214 if (fsi->ptmx_dentry) {
215 inode = fsi->ptmx_dentry->d_inode;
216 inode->i_mode = S_IFCHR|fsi->mount_opts.ptmxmode;
217 }
218}
219#else
220static inline void update_ptmx_mode(struct pts_fs_info *fsi)
221{
222 return;
223}
224#endif
225
226static int devpts_remount(struct super_block *sb, int *flags, char *data)
227{
228 int err;
229 struct pts_fs_info *fsi = DEVPTS_SB(sb);
230 struct pts_mount_opts *opts = &fsi->mount_opts;
231
232 err = parse_mount_options(data, PARSE_REMOUNT, opts);
233
234 /*
235 * parse_mount_options() restores options to default values
236 * before parsing and may have changed ptmxmode. So, update the
237 * mode in the inode too. Bogus options don't fail the remount,
238 * so do this even on error return.
239 */
240 update_ptmx_mode(fsi);
241
242 return err;
243}
244
105static int devpts_show_options(struct seq_file *seq, struct vfsmount *vfs) 245static int devpts_show_options(struct seq_file *seq, struct vfsmount *vfs)
106{ 246{
107 if (config.setuid) 247 struct pts_fs_info *fsi = DEVPTS_SB(vfs->mnt_sb);
108 seq_printf(seq, ",uid=%u", config.uid); 248 struct pts_mount_opts *opts = &fsi->mount_opts;
109 if (config.setgid) 249
110 seq_printf(seq, ",gid=%u", config.gid); 250 if (opts->setuid)
111 seq_printf(seq, ",mode=%03o", config.mode); 251 seq_printf(seq, ",uid=%u", opts->uid);
252 if (opts->setgid)
253 seq_printf(seq, ",gid=%u", opts->gid);
254 seq_printf(seq, ",mode=%03o", opts->mode);
255#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
256 seq_printf(seq, ",ptmxmode=%03o", opts->ptmxmode);
257#endif
112 258
113 return 0; 259 return 0;
114} 260}
@@ -119,10 +265,25 @@ static const struct super_operations devpts_sops = {
119 .show_options = devpts_show_options, 265 .show_options = devpts_show_options,
120}; 266};
121 267
268static void *new_pts_fs_info(void)
269{
270 struct pts_fs_info *fsi;
271
272 fsi = kzalloc(sizeof(struct pts_fs_info), GFP_KERNEL);
273 if (!fsi)
274 return NULL;
275
276 ida_init(&fsi->allocated_ptys);
277 fsi->mount_opts.mode = DEVPTS_DEFAULT_MODE;
278 fsi->mount_opts.ptmxmode = DEVPTS_DEFAULT_PTMX_MODE;
279
280 return fsi;
281}
282
122static int 283static int
123devpts_fill_super(struct super_block *s, void *data, int silent) 284devpts_fill_super(struct super_block *s, void *data, int silent)
124{ 285{
125 struct inode * inode; 286 struct inode *inode;
126 287
127 s->s_blocksize = 1024; 288 s->s_blocksize = 1024;
128 s->s_blocksize_bits = 10; 289 s->s_blocksize_bits = 10;
@@ -130,9 +291,13 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
130 s->s_op = &devpts_sops; 291 s->s_op = &devpts_sops;
131 s->s_time_gran = 1; 292 s->s_time_gran = 1;
132 293
294 s->s_fs_info = new_pts_fs_info();
295 if (!s->s_fs_info)
296 goto fail;
297
133 inode = new_inode(s); 298 inode = new_inode(s);
134 if (!inode) 299 if (!inode)
135 goto fail; 300 goto free_fsi;
136 inode->i_ino = 1; 301 inode->i_ino = 1;
137 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 302 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
138 inode->i_blocks = 0; 303 inode->i_blocks = 0;
@@ -142,27 +307,226 @@ devpts_fill_super(struct super_block *s, void *data, int silent)
142 inode->i_fop = &simple_dir_operations; 307 inode->i_fop = &simple_dir_operations;
143 inode->i_nlink = 2; 308 inode->i_nlink = 2;
144 309
145 devpts_root = s->s_root = d_alloc_root(inode); 310 s->s_root = d_alloc_root(inode);
146 if (s->s_root) 311 if (s->s_root)
147 return 0; 312 return 0;
148 313
149 printk("devpts: get root dentry failed\n"); 314 printk(KERN_ERR "devpts: get root dentry failed\n");
150 iput(inode); 315 iput(inode);
316
317free_fsi:
318 kfree(s->s_fs_info);
151fail: 319fail:
152 return -ENOMEM; 320 return -ENOMEM;
153} 321}
154 322
323#ifdef CONFIG_DEVPTS_MULTIPLE_INSTANCES
324static int compare_init_pts_sb(struct super_block *s, void *p)
325{
326 if (devpts_mnt)
327 return devpts_mnt->mnt_sb == s;
328 return 0;
329}
330
331/*
332 * Safely parse the mount options in @data and update @opts.
333 *
334 * devpts ends up parsing options two times during mount, due to the
335 * two modes of operation it supports. The first parse occurs in
336 * devpts_get_sb() when determining the mode (single-instance or
337 * multi-instance mode). The second parse happens in devpts_remount()
338 * or new_pts_mount() depending on the mode.
339 *
340 * Parsing of options modifies the @data making subsequent parsing
341 * incorrect. So make a local copy of @data and parse it.
342 *
343 * Return: 0 On success, -errno on error
344 */
345static int safe_parse_mount_options(void *data, struct pts_mount_opts *opts)
346{
347 int rc;
348 void *datacp;
349
350 if (!data)
351 return 0;
352
353 /* Use kstrdup() ? */
354 datacp = kmalloc(PAGE_SIZE, GFP_KERNEL);
355 if (!datacp)
356 return -ENOMEM;
357
358 memcpy(datacp, data, PAGE_SIZE);
359 rc = parse_mount_options((char *)datacp, PARSE_MOUNT, opts);
360 kfree(datacp);
361
362 return rc;
363}
364
365/*
366 * Mount a new (private) instance of devpts. PTYs created in this
367 * instance are independent of the PTYs in other devpts instances.
368 */
369static int new_pts_mount(struct file_system_type *fs_type, int flags,
370 void *data, struct vfsmount *mnt)
371{
372 int err;
373 struct pts_fs_info *fsi;
374 struct pts_mount_opts *opts;
375
376 printk(KERN_NOTICE "devpts: newinstance mount\n");
377
378 err = get_sb_nodev(fs_type, flags, data, devpts_fill_super, mnt);
379 if (err)
380 return err;
381
382 fsi = DEVPTS_SB(mnt->mnt_sb);
383 opts = &fsi->mount_opts;
384
385 err = parse_mount_options(data, PARSE_MOUNT, opts);
386 if (err)
387 goto fail;
388
389 err = mknod_ptmx(mnt->mnt_sb);
390 if (err)
391 goto fail;
392
393 return 0;
394
395fail:
396 dput(mnt->mnt_sb->s_root);
397 deactivate_super(mnt->mnt_sb);
398 return err;
399}
400
401/*
402 * Check if 'newinstance' mount option was specified in @data.
403 *
404 * Return: -errno on error (eg: invalid mount options specified)
405 * : 1 if 'newinstance' mount option was specified
406 * : 0 if 'newinstance' mount option was NOT specified
407 */
408static int is_new_instance_mount(void *data)
409{
410 int rc;
411 struct pts_mount_opts opts;
412
413 if (!data)
414 return 0;
415
416 rc = safe_parse_mount_options(data, &opts);
417 if (!rc)
418 rc = opts.newinstance;
419
420 return rc;
421}
422
423/*
424 * get_init_pts_sb()
425 *
426 * This interface is needed to support multiple namespace semantics in
427 * devpts while preserving backward compatibility of the current 'single-
428 * namespace' semantics. i.e all mounts of devpts without the 'newinstance'
429 * mount option should bind to the initial kernel mount, like
430 * get_sb_single().
431 *
432 * Mounts with 'newinstance' option create a new private namespace.
433 *
434 * But for single-mount semantics, devpts cannot use get_sb_single(),
435 * because get_sb_single()/sget() find and use the super-block from
436 * the most recent mount of devpts. But that recent mount may be a
437 * 'newinstance' mount and get_sb_single() would pick the newinstance
438 * super-block instead of the initial super-block.
439 *
440 * This interface is identical to get_sb_single() except that it
441 * consistently selects the 'single-namespace' superblock even in the
442 * presence of the private namespace (i.e 'newinstance') super-blocks.
443 */
444static int get_init_pts_sb(struct file_system_type *fs_type, int flags,
445 void *data, struct vfsmount *mnt)
446{
447 struct super_block *s;
448 int error;
449
450 s = sget(fs_type, compare_init_pts_sb, set_anon_super, NULL);
451 if (IS_ERR(s))
452 return PTR_ERR(s);
453
454 if (!s->s_root) {
455 s->s_flags = flags;
456 error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
457 if (error) {
458 up_write(&s->s_umount);
459 deactivate_super(s);
460 return error;
461 }
462 s->s_flags |= MS_ACTIVE;
463 }
464 do_remount_sb(s, flags, data, 0);
465 return simple_set_mnt(mnt, s);
466}
467
468/*
469 * Mount or remount the initial kernel mount of devpts. This type of
470 * mount maintains the legacy, single-instance semantics, while the
471 * kernel still allows multiple-instances.
472 */
473static int init_pts_mount(struct file_system_type *fs_type, int flags,
474 void *data, struct vfsmount *mnt)
475{
476 int err;
477
478 err = get_init_pts_sb(fs_type, flags, data, mnt);
479 if (err)
480 return err;
481
482 err = mknod_ptmx(mnt->mnt_sb);
483 if (err) {
484 dput(mnt->mnt_sb->s_root);
485 deactivate_super(mnt->mnt_sb);
486 }
487
488 return err;
489}
490
155static int devpts_get_sb(struct file_system_type *fs_type, 491static int devpts_get_sb(struct file_system_type *fs_type,
156 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 492 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
157{ 493{
494 int new;
495
496 new = is_new_instance_mount(data);
497 if (new < 0)
498 return new;
499
500 if (new)
501 return new_pts_mount(fs_type, flags, data, mnt);
502
503 return init_pts_mount(fs_type, flags, data, mnt);
504}
505#else
506/*
507 * This supports only the legacy single-instance semantics (no
508 * multiple-instance semantics)
509 */
510static int devpts_get_sb(struct file_system_type *fs_type, int flags,
511 const char *dev_name, void *data, struct vfsmount *mnt)
512{
158 return get_sb_single(fs_type, flags, data, devpts_fill_super, mnt); 513 return get_sb_single(fs_type, flags, data, devpts_fill_super, mnt);
159} 514}
515#endif
516
517static void devpts_kill_sb(struct super_block *sb)
518{
519 struct pts_fs_info *fsi = DEVPTS_SB(sb);
520
521 kfree(fsi);
522 kill_litter_super(sb);
523}
160 524
161static struct file_system_type devpts_fs_type = { 525static struct file_system_type devpts_fs_type = {
162 .owner = THIS_MODULE, 526 .owner = THIS_MODULE,
163 .name = "devpts", 527 .name = "devpts",
164 .get_sb = devpts_get_sb, 528 .get_sb = devpts_get_sb,
165 .kill_sb = kill_anon_super, 529 .kill_sb = devpts_kill_sb,
166}; 530};
167 531
168/* 532/*
@@ -172,16 +536,17 @@ static struct file_system_type devpts_fs_type = {
172 536
173int devpts_new_index(struct inode *ptmx_inode) 537int devpts_new_index(struct inode *ptmx_inode)
174{ 538{
539 struct super_block *sb = pts_sb_from_inode(ptmx_inode);
540 struct pts_fs_info *fsi = DEVPTS_SB(sb);
175 int index; 541 int index;
176 int ida_ret; 542 int ida_ret;
177 543
178retry: 544retry:
179 if (!ida_pre_get(&allocated_ptys, GFP_KERNEL)) { 545 if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL))
180 return -ENOMEM; 546 return -ENOMEM;
181 }
182 547
183 mutex_lock(&allocated_ptys_lock); 548 mutex_lock(&allocated_ptys_lock);
184 ida_ret = ida_get_new(&allocated_ptys, &index); 549 ida_ret = ida_get_new(&fsi->allocated_ptys, &index);
185 if (ida_ret < 0) { 550 if (ida_ret < 0) {
186 mutex_unlock(&allocated_ptys_lock); 551 mutex_unlock(&allocated_ptys_lock);
187 if (ida_ret == -EAGAIN) 552 if (ida_ret == -EAGAIN)
@@ -190,7 +555,7 @@ retry:
190 } 555 }
191 556
192 if (index >= pty_limit) { 557 if (index >= pty_limit) {
193 ida_remove(&allocated_ptys, index); 558 ida_remove(&fsi->allocated_ptys, index);
194 mutex_unlock(&allocated_ptys_lock); 559 mutex_unlock(&allocated_ptys_lock);
195 return -EIO; 560 return -EIO;
196 } 561 }
@@ -200,18 +565,26 @@ retry:
200 565
201void devpts_kill_index(struct inode *ptmx_inode, int idx) 566void devpts_kill_index(struct inode *ptmx_inode, int idx)
202{ 567{
568 struct super_block *sb = pts_sb_from_inode(ptmx_inode);
569 struct pts_fs_info *fsi = DEVPTS_SB(sb);
570
203 mutex_lock(&allocated_ptys_lock); 571 mutex_lock(&allocated_ptys_lock);
204 ida_remove(&allocated_ptys, idx); 572 ida_remove(&fsi->allocated_ptys, idx);
205 mutex_unlock(&allocated_ptys_lock); 573 mutex_unlock(&allocated_ptys_lock);
206} 574}
207 575
208int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) 576int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
209{ 577{
210 int number = tty->index; /* tty layer puts index from devpts_new_index() in here */ 578 /* tty layer puts index from devpts_new_index() in here */
579 int number = tty->index;
211 struct tty_driver *driver = tty->driver; 580 struct tty_driver *driver = tty->driver;
212 dev_t device = MKDEV(driver->major, driver->minor_start+number); 581 dev_t device = MKDEV(driver->major, driver->minor_start+number);
213 struct dentry *dentry; 582 struct dentry *dentry;
214 struct inode *inode = new_inode(devpts_mnt->mnt_sb); 583 struct super_block *sb = pts_sb_from_inode(ptmx_inode);
584 struct inode *inode = new_inode(sb);
585 struct dentry *root = sb->s_root;
586 struct pts_fs_info *fsi = DEVPTS_SB(sb);
587 struct pts_mount_opts *opts = &fsi->mount_opts;
215 char s[12]; 588 char s[12];
216 589
217 /* We're supposed to be given the slave end of a pty */ 590 /* We're supposed to be given the slave end of a pty */
@@ -221,25 +594,25 @@ int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
221 if (!inode) 594 if (!inode)
222 return -ENOMEM; 595 return -ENOMEM;
223 596
224 inode->i_ino = number+2; 597 inode->i_ino = number + 3;
225 inode->i_uid = config.setuid ? config.uid : current_fsuid(); 598 inode->i_uid = opts->setuid ? opts->uid : current_fsuid();
226 inode->i_gid = config.setgid ? config.gid : current_fsgid(); 599 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
227 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 600 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
228 init_special_inode(inode, S_IFCHR|config.mode, device); 601 init_special_inode(inode, S_IFCHR|opts->mode, device);
229 inode->i_private = tty; 602 inode->i_private = tty;
230 tty->driver_data = inode; 603 tty->driver_data = inode;
231 604
232 sprintf(s, "%d", number); 605 sprintf(s, "%d", number);
233 606
234 mutex_lock(&devpts_root->d_inode->i_mutex); 607 mutex_lock(&root->d_inode->i_mutex);
235 608
236 dentry = d_alloc_name(devpts_root, s); 609 dentry = d_alloc_name(root, s);
237 if (!IS_ERR(dentry)) { 610 if (!IS_ERR(dentry)) {
238 d_add(dentry, inode); 611 d_add(dentry, inode);
239 fsnotify_create(devpts_root->d_inode, dentry); 612 fsnotify_create(root->d_inode, dentry);
240 } 613 }
241 614
242 mutex_unlock(&devpts_root->d_inode->i_mutex); 615 mutex_unlock(&root->d_inode->i_mutex);
243 616
244 return 0; 617 return 0;
245} 618}
@@ -256,20 +629,27 @@ struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number)
256void devpts_pty_kill(struct tty_struct *tty) 629void devpts_pty_kill(struct tty_struct *tty)
257{ 630{
258 struct inode *inode = tty->driver_data; 631 struct inode *inode = tty->driver_data;
632 struct super_block *sb = pts_sb_from_inode(inode);
633 struct dentry *root = sb->s_root;
259 struct dentry *dentry; 634 struct dentry *dentry;
260 635
261 BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR)); 636 BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
262 637
263 mutex_lock(&devpts_root->d_inode->i_mutex); 638 mutex_lock(&root->d_inode->i_mutex);
264 639
265 dentry = d_find_alias(inode); 640 dentry = d_find_alias(inode);
266 if (dentry && !IS_ERR(dentry)) { 641 if (IS_ERR(dentry))
642 goto out;
643
644 if (dentry) {
267 inode->i_nlink--; 645 inode->i_nlink--;
268 d_delete(dentry); 646 d_delete(dentry);
269 dput(dentry); 647 dput(dentry); /* d_alloc_name() in devpts_pty_new() */
270 } 648 }
271 649
272 mutex_unlock(&devpts_root->d_inode->i_mutex); 650 dput(dentry); /* d_find_alias above */
651out:
652 mutex_unlock(&root->d_inode->i_mutex);
273} 653}
274 654
275static int __init init_devpts_fs(void) 655static int __init init_devpts_fs(void)
diff --git a/include/linux/8250_pci.h b/include/linux/8250_pci.h
index 3209dd46ea7d..b24ff086a662 100644
--- a/include/linux/8250_pci.h
+++ b/include/linux/8250_pci.h
@@ -31,7 +31,7 @@ struct pciserial_board {
31struct serial_private; 31struct serial_private;
32 32
33struct serial_private * 33struct serial_private *
34pciserial_init_ports(struct pci_dev *dev, struct pciserial_board *board); 34pciserial_init_ports(struct pci_dev *dev, const struct pciserial_board *board);
35void pciserial_remove_ports(struct serial_private *priv); 35void pciserial_remove_ports(struct serial_private *priv);
36void pciserial_suspend_ports(struct serial_private *priv); 36void pciserial_suspend_ports(struct serial_private *priv);
37void pciserial_resume_ports(struct serial_private *priv); 37void pciserial_resume_ports(struct serial_private *priv);
diff --git a/include/linux/generic_serial.h b/include/linux/generic_serial.h
index 4cc913939817..fadff28505bb 100644
--- a/include/linux/generic_serial.h
+++ b/include/linux/generic_serial.h
@@ -21,7 +21,6 @@ struct real_driver {
21 void (*enable_tx_interrupts) (void *); 21 void (*enable_tx_interrupts) (void *);
22 void (*disable_rx_interrupts) (void *); 22 void (*disable_rx_interrupts) (void *);
23 void (*enable_rx_interrupts) (void *); 23 void (*enable_rx_interrupts) (void *);
24 int (*get_CD) (void *);
25 void (*shutdown_port) (void*); 24 void (*shutdown_port) (void*);
26 int (*set_real_termios) (void*); 25 int (*set_real_termios) (void*);
27 int (*chars_in_buffer) (void*); 26 int (*chars_in_buffer) (void*);
diff --git a/include/linux/istallion.h b/include/linux/istallion.h
index 0d1840723249..7faca98c7d14 100644
--- a/include/linux/istallion.h
+++ b/include/linux/istallion.h
@@ -59,9 +59,7 @@ struct stliport {
59 unsigned int devnr; 59 unsigned int devnr;
60 int baud_base; 60 int baud_base;
61 int custom_divisor; 61 int custom_divisor;
62 int close_delay;
63 int closing_wait; 62 int closing_wait;
64 int openwaitcnt;
65 int rc; 63 int rc;
66 int argsize; 64 int argsize;
67 void *argp; 65 void *argp;
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index b6e694454280..218c73b1e6d4 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1766,6 +1766,7 @@
1766#define PCI_DEVICE_ID_SIIG_8S_20x_650 0x2081 1766#define PCI_DEVICE_ID_SIIG_8S_20x_650 0x2081
1767#define PCI_DEVICE_ID_SIIG_8S_20x_850 0x2082 1767#define PCI_DEVICE_ID_SIIG_8S_20x_850 0x2082
1768#define PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL 0x2050 1768#define PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL 0x2050
1769#define PCI_SUBDEVICE_ID_SIIG_DUAL_SERIAL 0x2530
1769 1770
1770#define PCI_VENDOR_ID_RADISYS 0x1331 1771#define PCI_VENDOR_ID_RADISYS 0x1331
1771 1772
@@ -1795,6 +1796,7 @@
1795#define PCI_DEVICE_ID_SEALEVEL_UCOMM232 0x7202 1796#define PCI_DEVICE_ID_SEALEVEL_UCOMM232 0x7202
1796#define PCI_DEVICE_ID_SEALEVEL_COMM4 0x7401 1797#define PCI_DEVICE_ID_SEALEVEL_COMM4 0x7401
1797#define PCI_DEVICE_ID_SEALEVEL_COMM8 0x7801 1798#define PCI_DEVICE_ID_SEALEVEL_COMM8 0x7801
1799#define PCI_DEVICE_ID_SEALEVEL_7803 0x7803
1798#define PCI_DEVICE_ID_SEALEVEL_UCOMM8 0x7804 1800#define PCI_DEVICE_ID_SEALEVEL_UCOMM8 0x7804
1799 1801
1800#define PCI_VENDOR_ID_HYPERCOPE 0x1365 1802#define PCI_VENDOR_ID_HYPERCOPE 0x1365
diff --git a/include/linux/serial.h b/include/linux/serial.h
index 1ea8d9265bf6..9136cc5608c3 100644
--- a/include/linux/serial.h
+++ b/include/linux/serial.h
@@ -10,8 +10,9 @@
10#ifndef _LINUX_SERIAL_H 10#ifndef _LINUX_SERIAL_H
11#define _LINUX_SERIAL_H 11#define _LINUX_SERIAL_H
12 12
13#ifdef __KERNEL__
14#include <linux/types.h> 13#include <linux/types.h>
14
15#ifdef __KERNEL__
15#include <asm/page.h> 16#include <asm/page.h>
16 17
17/* 18/*
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index 3d37c94abbc8..d4d2a78ad43e 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -28,6 +28,9 @@ struct plat_serial8250_port {
28 unsigned char iotype; /* UPIO_* */ 28 unsigned char iotype; /* UPIO_* */
29 unsigned char hub6; 29 unsigned char hub6;
30 upf_t flags; /* UPF_* flags */ 30 upf_t flags; /* UPF_* flags */
31 unsigned int type; /* If UPF_FIXED_TYPE */
32 unsigned int (*serial_in)(struct uart_port *, int);
33 void (*serial_out)(struct uart_port *, int, int);
31}; 34};
32 35
33/* 36/*
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index feb3b939ec4b..b4199841f1fc 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -40,7 +40,8 @@
40#define PORT_NS16550A 14 40#define PORT_NS16550A 14
41#define PORT_XSCALE 15 41#define PORT_XSCALE 15
42#define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */ 42#define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */
43#define PORT_MAX_8250 16 /* max port ID */ 43#define PORT_OCTEON 17 /* Cavium OCTEON internal UART */
44#define PORT_MAX_8250 17 /* max port ID */
44 45
45/* 46/*
46 * ARM specific type numbers. These are not currently guaranteed 47 * ARM specific type numbers. These are not currently guaranteed
@@ -248,6 +249,8 @@ struct uart_port {
248 spinlock_t lock; /* port lock */ 249 spinlock_t lock; /* port lock */
249 unsigned long iobase; /* in/out[bwl] */ 250 unsigned long iobase; /* in/out[bwl] */
250 unsigned char __iomem *membase; /* read/write[bwl] */ 251 unsigned char __iomem *membase; /* read/write[bwl] */
252 unsigned int (*serial_in)(struct uart_port *, int);
253 void (*serial_out)(struct uart_port *, int, int);
251 unsigned int irq; /* irq number */ 254 unsigned int irq; /* irq number */
252 unsigned int uartclk; /* base uart clock */ 255 unsigned int uartclk; /* base uart clock */
253 unsigned int fifosize; /* tx fifo size */ 256 unsigned int fifosize; /* tx fifo size */
@@ -293,6 +296,8 @@ struct uart_port {
293#define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16)) 296#define UPF_MAGIC_MULTIPLIER ((__force upf_t) (1 << 16))
294#define UPF_CONS_FLOW ((__force upf_t) (1 << 23)) 297#define UPF_CONS_FLOW ((__force upf_t) (1 << 23))
295#define UPF_SHARE_IRQ ((__force upf_t) (1 << 24)) 298#define UPF_SHARE_IRQ ((__force upf_t) (1 << 24))
299/* The exact UART type is known and should not be probed. */
300#define UPF_FIXED_TYPE ((__force upf_t) (1 << 27))
296#define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28)) 301#define UPF_BOOT_AUTOCONF ((__force upf_t) (1 << 28))
297#define UPF_FIXED_PORT ((__force upf_t) (1 << 29)) 302#define UPF_FIXED_PORT ((__force upf_t) (1 << 29))
298#define UPF_DEAD ((__force upf_t) (1 << 30)) 303#define UPF_DEAD ((__force upf_t) (1 << 30))
@@ -316,35 +321,13 @@ struct uart_port {
316}; 321};
317 322
318/* 323/*
319 * This is the state information which is persistent across opens.
320 * The low level driver must not to touch any elements contained
321 * within.
322 */
323struct uart_state {
324 unsigned int close_delay; /* msec */
325 unsigned int closing_wait; /* msec */
326
327#define USF_CLOSING_WAIT_INF (0)
328#define USF_CLOSING_WAIT_NONE (~0U)
329
330 int count;
331 int pm_state;
332 struct uart_info *info;
333 struct uart_port *port;
334
335 struct mutex mutex;
336};
337
338#define UART_XMIT_SIZE PAGE_SIZE
339
340typedef unsigned int __bitwise__ uif_t;
341
342/*
343 * This is the state information which is only valid when the port 324 * This is the state information which is only valid when the port
344 * is open; it may be freed by the core driver once the device has 325 * is open; it may be cleared the core driver once the device has
345 * been closed. Either the low level driver or the core can modify 326 * been closed. Either the low level driver or the core can modify
346 * stuff here. 327 * stuff here.
347 */ 328 */
329typedef unsigned int __bitwise__ uif_t;
330
348struct uart_info { 331struct uart_info {
349 struct tty_port port; 332 struct tty_port port;
350 struct circ_buf xmit; 333 struct circ_buf xmit;
@@ -366,6 +349,29 @@ struct uart_info {
366 wait_queue_head_t delta_msr_wait; 349 wait_queue_head_t delta_msr_wait;
367}; 350};
368 351
352/*
353 * This is the state information which is persistent across opens.
354 * The low level driver must not to touch any elements contained
355 * within.
356 */
357struct uart_state {
358 unsigned int close_delay; /* msec */
359 unsigned int closing_wait; /* msec */
360
361#define USF_CLOSING_WAIT_INF (0)
362#define USF_CLOSING_WAIT_NONE (~0U)
363
364 int count;
365 int pm_state;
366 struct uart_info info;
367 struct uart_port *port;
368
369 struct mutex mutex;
370};
371
372#define UART_XMIT_SIZE PAGE_SIZE
373
374
369/* number of characters left in xmit buffer before we ask for more */ 375/* number of characters left in xmit buffer before we ask for more */
370#define WAKEUP_CHARS 256 376#define WAKEUP_CHARS 256
371 377
@@ -439,8 +445,13 @@ int uart_resume_port(struct uart_driver *reg, struct uart_port *port);
439#define uart_circ_chars_free(circ) \ 445#define uart_circ_chars_free(circ) \
440 (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE)) 446 (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
441 447
442#define uart_tx_stopped(portp) \ 448static inline int uart_tx_stopped(struct uart_port *port)
443 ((portp)->info->port.tty->stopped || (portp)->info->port.tty->hw_stopped) 449{
450 struct tty_struct *tty = port->info->port.tty;
451 if(tty->stopped || tty->hw_stopped)
452 return 1;
453 return 0;
454}
444 455
445/* 456/*
446 * The following are helper functions for the low level drivers. 457 * The following are helper functions for the low level drivers.
@@ -451,7 +462,7 @@ uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
451#ifdef SUPPORT_SYSRQ 462#ifdef SUPPORT_SYSRQ
452 if (port->sysrq) { 463 if (port->sysrq) {
453 if (ch && time_before(jiffies, port->sysrq)) { 464 if (ch && time_before(jiffies, port->sysrq)) {
454 handle_sysrq(ch, port->info ? port->info->port.tty : NULL); 465 handle_sysrq(ch, port->info->port.tty);
455 port->sysrq = 0; 466 port->sysrq = 0;
456 return 1; 467 return 1;
457 } 468 }
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 3f4954c55e53..fc39db95499f 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -180,8 +180,17 @@ struct signal_struct;
180 * until a hangup so don't use the wrong path. 180 * until a hangup so don't use the wrong path.
181 */ 181 */
182 182
183struct tty_port;
184
185struct tty_port_operations {
186 /* Return 1 if the carrier is raised */
187 int (*carrier_raised)(struct tty_port *port);
188 void (*raise_dtr_rts)(struct tty_port *port);
189};
190
183struct tty_port { 191struct tty_port {
184 struct tty_struct *tty; /* Back pointer */ 192 struct tty_struct *tty; /* Back pointer */
193 const struct tty_port_operations *ops; /* Port operations */
185 spinlock_t lock; /* Lock protecting tty field */ 194 spinlock_t lock; /* Lock protecting tty field */
186 int blocked_open; /* Waiting to open */ 195 int blocked_open; /* Waiting to open */
187 int count; /* Usage count */ 196 int count; /* Usage count */
@@ -253,6 +262,7 @@ struct tty_struct {
253 unsigned int column; 262 unsigned int column;
254 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1; 263 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
255 unsigned char closing:1; 264 unsigned char closing:1;
265 unsigned char echo_overrun:1;
256 unsigned short minimum_to_wake; 266 unsigned short minimum_to_wake;
257 unsigned long overrun_time; 267 unsigned long overrun_time;
258 int num_overrun; 268 int num_overrun;
@@ -262,11 +272,16 @@ struct tty_struct {
262 int read_tail; 272 int read_tail;
263 int read_cnt; 273 int read_cnt;
264 unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))]; 274 unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))];
275 unsigned char *echo_buf;
276 unsigned int echo_pos;
277 unsigned int echo_cnt;
265 int canon_data; 278 int canon_data;
266 unsigned long canon_head; 279 unsigned long canon_head;
267 unsigned int canon_column; 280 unsigned int canon_column;
268 struct mutex atomic_read_lock; 281 struct mutex atomic_read_lock;
269 struct mutex atomic_write_lock; 282 struct mutex atomic_write_lock;
283 struct mutex output_lock;
284 struct mutex echo_lock;
270 unsigned char *write_buf; 285 unsigned char *write_buf;
271 int write_cnt; 286 int write_cnt;
272 spinlock_t read_lock; 287 spinlock_t read_lock;
@@ -295,6 +310,7 @@ struct tty_struct {
295#define TTY_PUSH 6 /* n_tty private */ 310#define TTY_PUSH 6 /* n_tty private */
296#define TTY_CLOSING 7 /* ->close() in progress */ 311#define TTY_CLOSING 7 /* ->close() in progress */
297#define TTY_LDISC 9 /* Line discipline attached */ 312#define TTY_LDISC 9 /* Line discipline attached */
313#define TTY_LDISC_CHANGING 10 /* Line discipline changing */
298#define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */ 314#define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */
299#define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */ 315#define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */
300#define TTY_PTY_LOCK 16 /* pty private */ 316#define TTY_PTY_LOCK 16 /* pty private */
@@ -354,8 +370,7 @@ extern int tty_write_room(struct tty_struct *tty);
354extern void tty_driver_flush_buffer(struct tty_struct *tty); 370extern void tty_driver_flush_buffer(struct tty_struct *tty);
355extern void tty_throttle(struct tty_struct *tty); 371extern void tty_throttle(struct tty_struct *tty);
356extern void tty_unthrottle(struct tty_struct *tty); 372extern void tty_unthrottle(struct tty_struct *tty);
357extern int tty_do_resize(struct tty_struct *tty, struct tty_struct *real_tty, 373extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
358 struct winsize *ws);
359extern void tty_shutdown(struct tty_struct *tty); 374extern void tty_shutdown(struct tty_struct *tty);
360extern void tty_free_termios(struct tty_struct *tty); 375extern void tty_free_termios(struct tty_struct *tty);
361extern int is_current_pgrp_orphaned(void); 376extern int is_current_pgrp_orphaned(void);
@@ -421,6 +436,14 @@ extern int tty_port_alloc_xmit_buf(struct tty_port *port);
421extern void tty_port_free_xmit_buf(struct tty_port *port); 436extern void tty_port_free_xmit_buf(struct tty_port *port);
422extern struct tty_struct *tty_port_tty_get(struct tty_port *port); 437extern struct tty_struct *tty_port_tty_get(struct tty_port *port);
423extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); 438extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty);
439extern int tty_port_carrier_raised(struct tty_port *port);
440extern void tty_port_raise_dtr_rts(struct tty_port *port);
441extern void tty_port_hangup(struct tty_port *port);
442extern int tty_port_block_til_ready(struct tty_port *port,
443 struct tty_struct *tty, struct file *filp);
444extern int tty_port_close_start(struct tty_port *port,
445 struct tty_struct *tty, struct file *filp);
446extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty);
424 447
425extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc); 448extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
426extern int tty_unregister_ldisc(int disc); 449extern int tty_unregister_ldisc(int disc);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 78416b901589..08e088334dba 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -196,8 +196,7 @@
196 * Optional: If not provided then the write method is called under 196 * Optional: If not provided then the write method is called under
197 * the atomic write lock to keep it serialized with the ldisc. 197 * the atomic write lock to keep it serialized with the ldisc.
198 * 198 *
199 * int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty, 199 * int (*resize)(struct tty_struct *tty, struct winsize *ws)
200 * unsigned int rows, unsigned int cols);
201 * 200 *
202 * Called when a termios request is issued which changes the 201 * Called when a termios request is issued which changes the
203 * requested terminal geometry. 202 * requested terminal geometry.
@@ -258,8 +257,7 @@ struct tty_operations {
258 int (*tiocmget)(struct tty_struct *tty, struct file *file); 257 int (*tiocmget)(struct tty_struct *tty, struct file *file);
259 int (*tiocmset)(struct tty_struct *tty, struct file *file, 258 int (*tiocmset)(struct tty_struct *tty, struct file *file,
260 unsigned int set, unsigned int clear); 259 unsigned int set, unsigned int clear);
261 int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty, 260 int (*resize)(struct tty_struct *tty, struct winsize *ws);
262 struct winsize *ws);
263 int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew); 261 int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
264#ifdef CONFIG_CONSOLE_POLL 262#ifdef CONFIG_CONSOLE_POLL
265 int (*poll_init)(struct tty_driver *driver, int line, char *options); 263 int (*poll_init)(struct tty_driver *driver, int line, char *options);
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index e4e2caeb9d82..086d5ef098fd 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -371,9 +371,8 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
371 IRDA_DEBUG(2, "%s()\n", __func__ ); 371 IRDA_DEBUG(2, "%s()\n", __func__ );
372 372
373 line = tty->index; 373 line = tty->index;
374 if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) { 374 if (line >= IRCOMM_TTY_PORTS)
375 return -ENODEV; 375 return -ENODEV;
376 }
377 376
378 /* Check if instance already exists */ 377 /* Check if instance already exists */
379 self = hashbin_lock_find(ircomm_tty, line, NULL); 378 self = hashbin_lock_find(ircomm_tty, line, NULL);
@@ -405,6 +404,8 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
405 * Force TTY into raw mode by default which is usually what 404 * Force TTY into raw mode by default which is usually what
406 * we want for IrCOMM and IrLPT. This way applications will 405 * we want for IrCOMM and IrLPT. This way applications will
407 * not have to twiddle with printcap etc. 406 * not have to twiddle with printcap etc.
407 *
408 * Note this is completely usafe and doesn't work properly
408 */ 409 */
409 tty->termios->c_iflag = 0; 410 tty->termios->c_iflag = 0;
410 tty->termios->c_oflag = 0; 411 tty->termios->c_oflag = 0;