aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-23 12:39:23 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-23 12:39:23 -0400
commit10af77c193681398e5dbe830db181d86047fcd41 (patch)
treeb843eb8dae09a53efb410dd11d2132dba4fe4d15
parent66f75a5d028beaf67c931435fdc3e7823125730c (diff)
parent5f1a38952b7e932a1c169c28917b9a831f641bcc (diff)
Merge 3.4-rc4 into tty-next
This resolves the merge problem with: drivers/tty/serial/pch_uart.c Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--arch/arm/mach-omap2/serial.c8
-rw-r--r--arch/arm/mach-tegra/board-harmony.c2
-rw-r--r--arch/arm/mach-tegra/board-paz00.c3
-rw-r--r--arch/arm/mach-tegra/board-seaboard.c2
-rw-r--r--arch/arm/mach-tegra/board-trimslice.c2
-rw-r--r--arch/arm/plat-omap/include/plat/omap-serial.h1
-rw-r--r--drivers/isdn/i4l/isdn_common.c5
-rw-r--r--drivers/isdn/i4l/isdn_tty.c466
-rw-r--r--drivers/net/usb/hso.c105
-rw-r--r--drivers/s390/char/con3215.c142
-rw-r--r--drivers/s390/char/keyboard.c30
-rw-r--r--drivers/s390/char/keyboard.h14
-rw-r--r--drivers/s390/char/sclp_tty.c33
-rw-r--r--drivers/s390/char/sclp_vt220.c33
-rw-r--r--drivers/s390/char/tty3270.c121
-rw-r--r--drivers/tty/bfin_jtag_comm.c44
-rw-r--r--drivers/tty/hvc/hvc_console.c96
-rw-r--r--drivers/tty/hvc/hvc_console.h4
-rw-r--r--drivers/tty/hvc/hvcs.c74
-rw-r--r--drivers/tty/hvc/hvsi.c128
-rw-r--r--drivers/tty/hvc/hvsi_lib.c2
-rw-r--r--drivers/tty/ipwireless/tty.c81
-rw-r--r--drivers/tty/serial/68328serial.c383
-rw-r--r--drivers/tty/serial/68328serial.h186
-rw-r--r--drivers/tty/serial/8250/8250.c44
-rw-r--r--drivers/tty/serial/8250/8250.h2
-rw-r--r--drivers/tty/serial/8250/8250_pci.c45
-rw-r--r--drivers/tty/serial/amba-pl011.c109
-rw-r--r--drivers/tty/serial/crisv10.c28
-rw-r--r--drivers/tty/serial/of_serial.c26
-rw-r--r--drivers/tty/serial/omap-serial.c74
-rw-r--r--drivers/tty/serial/pch_uart.c53
-rw-r--r--drivers/tty/tty_buffer.c85
-rw-r--r--drivers/tty/vt/vt.c68
-rw-r--r--drivers/usb/gadget/u_serial.c51
-rw-r--r--include/linux/generic_serial.h64
-rw-r--r--include/linux/isdn.h26
-rw-r--r--include/linux/of_serial.h17
-rw-r--r--include/linux/serial_8250.h1
-rw-r--r--include/linux/serial_core.h5
-rw-r--r--net/bluetooth/rfcomm/tty.c133
41 files changed, 1191 insertions, 1605 deletions
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c
index 9fc2f44188cb..de74e05dd929 100644
--- a/arch/arm/mach-omap2/serial.c
+++ b/arch/arm/mach-omap2/serial.c
@@ -245,14 +245,6 @@ void __init omap_serial_init_port(struct omap_board_data *bdata,
245 omap_up.dma_rx_poll_rate = info->dma_rx_poll_rate; 245 omap_up.dma_rx_poll_rate = info->dma_rx_poll_rate;
246 omap_up.autosuspend_timeout = info->autosuspend_timeout; 246 omap_up.autosuspend_timeout = info->autosuspend_timeout;
247 247
248 /* Enable the MDR1 Errata i202 for OMAP2430/3xxx/44xx */
249 if (!cpu_is_omap2420() && !cpu_is_ti816x())
250 omap_up.errata |= UART_ERRATA_i202_MDR1_ACCESS;
251
252 /* Enable DMA Mode Force Idle Errata i291 for omap34xx/3630 */
253 if (cpu_is_omap34xx() || cpu_is_omap3630())
254 omap_up.errata |= UART_ERRATA_i291_DMA_FORCEIDLE;
255
256 pdata = &omap_up; 248 pdata = &omap_up;
257 pdata_size = sizeof(struct omap_uart_port_info); 249 pdata_size = sizeof(struct omap_uart_port_info);
258 250
diff --git a/arch/arm/mach-tegra/board-harmony.c b/arch/arm/mach-tegra/board-harmony.c
index c00aadb01e09..222182e00226 100644
--- a/arch/arm/mach-tegra/board-harmony.c
+++ b/arch/arm/mach-tegra/board-harmony.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/serial_8250.h> 21#include <linux/serial_8250.h>
22#include <linux/of_serial.h>
22#include <linux/clk.h> 23#include <linux/clk.h>
23#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
24#include <linux/pda_power.h> 25#include <linux/pda_power.h>
@@ -52,6 +53,7 @@ static struct plat_serial8250_port debug_uart_platform_data[] = {
52 .irq = INT_UARTD, 53 .irq = INT_UARTD,
53 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 54 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
54 .type = PORT_TEGRA, 55 .type = PORT_TEGRA,
56 .handle_break = tegra_serial_handle_break,
55 .iotype = UPIO_MEM, 57 .iotype = UPIO_MEM,
56 .regshift = 2, 58 .regshift = 2,
57 .uartclk = 216000000, 59 .uartclk = 216000000,
diff --git a/arch/arm/mach-tegra/board-paz00.c b/arch/arm/mach-tegra/board-paz00.c
index 330afdfa2475..d0735c70d688 100644
--- a/arch/arm/mach-tegra/board-paz00.c
+++ b/arch/arm/mach-tegra/board-paz00.c
@@ -21,6 +21,7 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/serial_8250.h> 23#include <linux/serial_8250.h>
24#include <linux/of_serial.h>
24#include <linux/clk.h> 25#include <linux/clk.h>
25#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
26#include <linux/gpio_keys.h> 27#include <linux/gpio_keys.h>
@@ -55,6 +56,7 @@ static struct plat_serial8250_port debug_uart_platform_data[] = {
55 .irq = INT_UARTA, 56 .irq = INT_UARTA,
56 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 57 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
57 .type = PORT_TEGRA, 58 .type = PORT_TEGRA,
59 .handle_break = tegra_serial_handle_break,
58 .iotype = UPIO_MEM, 60 .iotype = UPIO_MEM,
59 .regshift = 2, 61 .regshift = 2,
60 .uartclk = 216000000, 62 .uartclk = 216000000,
@@ -65,6 +67,7 @@ static struct plat_serial8250_port debug_uart_platform_data[] = {
65 .irq = INT_UARTC, 67 .irq = INT_UARTC,
66 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 68 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
67 .type = PORT_TEGRA, 69 .type = PORT_TEGRA,
70 .handle_break = tegra_serial_handle_break,
68 .iotype = UPIO_MEM, 71 .iotype = UPIO_MEM,
69 .regshift = 2, 72 .regshift = 2,
70 .uartclk = 216000000, 73 .uartclk = 216000000,
diff --git a/arch/arm/mach-tegra/board-seaboard.c b/arch/arm/mach-tegra/board-seaboard.c
index d669847f0485..5b687b8258c0 100644
--- a/arch/arm/mach-tegra/board-seaboard.c
+++ b/arch/arm/mach-tegra/board-seaboard.c
@@ -18,6 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/serial_8250.h> 20#include <linux/serial_8250.h>
21#include <linux/of_serial.h>
21#include <linux/i2c.h> 22#include <linux/i2c.h>
22#include <linux/delay.h> 23#include <linux/delay.h>
23#include <linux/input.h> 24#include <linux/input.h>
@@ -47,6 +48,7 @@ static struct plat_serial8250_port debug_uart_platform_data[] = {
47 /* Memory and IRQ filled in before registration */ 48 /* Memory and IRQ filled in before registration */
48 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 49 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
49 .type = PORT_TEGRA, 50 .type = PORT_TEGRA,
51 .handle_break = tegra_serial_handle_break,
50 .iotype = UPIO_MEM, 52 .iotype = UPIO_MEM,
51 .regshift = 2, 53 .regshift = 2,
52 .uartclk = 216000000, 54 .uartclk = 216000000,
diff --git a/arch/arm/mach-tegra/board-trimslice.c b/arch/arm/mach-tegra/board-trimslice.c
index cd52820a3e37..f7358586b523 100644
--- a/arch/arm/mach-tegra/board-trimslice.c
+++ b/arch/arm/mach-tegra/board-trimslice.c
@@ -22,6 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/serial_8250.h> 24#include <linux/serial_8250.h>
25#include <linux/of_serial.h>
25#include <linux/io.h> 26#include <linux/io.h>
26#include <linux/i2c.h> 27#include <linux/i2c.h>
27#include <linux/gpio.h> 28#include <linux/gpio.h>
@@ -48,6 +49,7 @@ static struct plat_serial8250_port debug_uart_platform_data[] = {
48 .irq = INT_UARTA, 49 .irq = INT_UARTA,
49 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE, 50 .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
50 .type = PORT_TEGRA, 51 .type = PORT_TEGRA,
52 .handle_break = tegra_serial_handle_break,
51 .iotype = UPIO_MEM, 53 .iotype = UPIO_MEM,
52 .regshift = 2, 54 .regshift = 2,
53 .uartclk = 216000000, 55 .uartclk = 216000000,
diff --git a/arch/arm/plat-omap/include/plat/omap-serial.h b/arch/arm/plat-omap/include/plat/omap-serial.h
index 9ff444469f3d..1a52725ffcf2 100644
--- a/arch/arm/plat-omap/include/plat/omap-serial.h
+++ b/arch/arm/plat-omap/include/plat/omap-serial.h
@@ -65,7 +65,6 @@ struct omap_uart_port_info {
65 bool dma_enabled; /* To specify DMA Mode */ 65 bool dma_enabled; /* To specify DMA Mode */
66 unsigned int uartclk; /* UART clock rate */ 66 unsigned int uartclk; /* UART clock rate */
67 upf_t flags; /* UPF_* flags */ 67 upf_t flags; /* UPF_* flags */
68 u32 errata;
69 unsigned int dma_rx_buf_size; 68 unsigned int dma_rx_buf_size;
70 unsigned int dma_rx_timeout; 69 unsigned int dma_rx_timeout;
71 unsigned int autosuspend_timeout; 70 unsigned int autosuspend_timeout;
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index d9f5524593fb..8c610fa6782b 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -46,7 +46,6 @@ static DEFINE_MUTEX(isdn_mutex);
46static char *isdn_revision = "$Revision: 1.1.2.3 $"; 46static char *isdn_revision = "$Revision: 1.1.2.3 $";
47 47
48extern char *isdn_net_revision; 48extern char *isdn_net_revision;
49extern char *isdn_tty_revision;
50#ifdef CONFIG_ISDN_PPP 49#ifdef CONFIG_ISDN_PPP
51extern char *isdn_ppp_revision; 50extern char *isdn_ppp_revision;
52#else 51#else
@@ -2327,8 +2326,6 @@ static int __init isdn_init(void)
2327 dev->chanmap[i] = -1; 2326 dev->chanmap[i] = -1;
2328 dev->m_idx[i] = -1; 2327 dev->m_idx[i] = -1;
2329 strcpy(dev->num[i], "???"); 2328 strcpy(dev->num[i], "???");
2330 init_waitqueue_head(&dev->mdm.info[i].open_wait);
2331 init_waitqueue_head(&dev->mdm.info[i].close_wait);
2332 } 2329 }
2333 if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) { 2330 if (register_chrdev(ISDN_MAJOR, "isdn", &isdn_fops)) {
2334 printk(KERN_WARNING "isdn: Could not register control devices\n"); 2331 printk(KERN_WARNING "isdn: Could not register control devices\n");
@@ -2353,8 +2350,6 @@ static int __init isdn_init(void)
2353 2350
2354 strcpy(tmprev, isdn_revision); 2351 strcpy(tmprev, isdn_revision);
2355 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev)); 2352 printk(KERN_NOTICE "ISDN subsystem Rev: %s/", isdn_getrev(tmprev));
2356 strcpy(tmprev, isdn_tty_revision);
2357 printk("%s/", isdn_getrev(tmprev));
2358 strcpy(tmprev, isdn_net_revision); 2353 strcpy(tmprev, isdn_net_revision);
2359 printk("%s/", isdn_getrev(tmprev)); 2354 printk("%s/", isdn_getrev(tmprev));
2360 strcpy(tmprev, isdn_ppp_revision); 2355 strcpy(tmprev, isdn_ppp_revision);
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 3831abdbc66f..7bc50670d7d9 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1,5 +1,4 @@
1/* $Id: isdn_tty.c,v 1.1.2.3 2004/02/10 01:07:13 keil Exp $ 1/*
2 *
3 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel). 2 * Linux ISDN subsystem, tty functions and AT-command emulator (linklevel).
4 * 3 *
5 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de) 4 * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
@@ -12,6 +11,7 @@
12#undef ISDN_TTY_STAT_DEBUG 11#undef ISDN_TTY_STAT_DEBUG
13 12
14#include <linux/isdn.h> 13#include <linux/isdn.h>
14#include <linux/serial.h> /* ASYNC_* flags */
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
@@ -48,9 +48,6 @@ static int bit2si[8] =
48static int si2bit[8] = 48static int si2bit[8] =
49{4, 1, 4, 4, 4, 4, 4, 4}; 49{4, 1, 4, 4, 4, 4, 4, 4};
50 50
51char *isdn_tty_revision = "$Revision: 1.1.2.3 $";
52
53
54/* isdn_tty_try_read() is called from within isdn_tty_rcv_skb() 51/* isdn_tty_try_read() is called from within isdn_tty_rcv_skb()
55 * to stuff incoming data directly into a tty's flip-buffer. This 52 * to stuff incoming data directly into a tty's flip-buffer. This
56 * is done to speed up tty-receiving if the receive-queue is empty. 53 * is done to speed up tty-receiving if the receive-queue is empty.
@@ -68,49 +65,54 @@ isdn_tty_try_read(modem_info *info, struct sk_buff *skb)
68 struct tty_struct *tty; 65 struct tty_struct *tty;
69 char last; 66 char last;
70 67
71 if (info->online) { 68 if (!info->online)
72 if ((tty = info->tty)) { 69 return 0;
73 if (info->mcr & UART_MCR_RTS) { 70
74 len = skb->len 71 tty = info->port.tty;
72 if (!tty)
73 return 0;
74
75 if (!(info->mcr & UART_MCR_RTS))
76 return 0;
77
78 len = skb->len
75#ifdef CONFIG_ISDN_AUDIO 79#ifdef CONFIG_ISDN_AUDIO
76 + ISDN_AUDIO_SKB_DLECOUNT(skb) 80 + ISDN_AUDIO_SKB_DLECOUNT(skb)
77#endif 81#endif
78 ; 82 ;
83
84 c = tty_buffer_request_room(tty, len);
85 if (c < len)
86 return 0;
79 87
80 c = tty_buffer_request_room(tty, len);
81 if (c >= len) {
82#ifdef CONFIG_ISDN_AUDIO
83 if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
84 int l = skb->len;
85 unsigned char *dp = skb->data;
86 while (--l) {
87 if (*dp == DLE)
88 tty_insert_flip_char(tty, DLE, 0);
89 tty_insert_flip_char(tty, *dp++, 0);
90 }
91 if (*dp == DLE)
92 tty_insert_flip_char(tty, DLE, 0);
93 last = *dp;
94 } else {
95#endif
96 if (len > 1)
97 tty_insert_flip_string(tty, skb->data, len - 1);
98 last = skb->data[len - 1];
99#ifdef CONFIG_ISDN_AUDIO 88#ifdef CONFIG_ISDN_AUDIO
100 } 89 if (ISDN_AUDIO_SKB_DLECOUNT(skb)) {
90 int l = skb->len;
91 unsigned char *dp = skb->data;
92 while (--l) {
93 if (*dp == DLE)
94 tty_insert_flip_char(tty, DLE, 0);
95 tty_insert_flip_char(tty, *dp++, 0);
96 }
97 if (*dp == DLE)
98 tty_insert_flip_char(tty, DLE, 0);
99 last = *dp;
100 } else {
101#endif 101#endif
102 if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP) 102 if (len > 1)
103 tty_insert_flip_char(tty, last, 0xFF); 103 tty_insert_flip_string(tty, skb->data, len - 1);
104 else 104 last = skb->data[len - 1];
105 tty_insert_flip_char(tty, last, TTY_NORMAL); 105#ifdef CONFIG_ISDN_AUDIO
106 tty_flip_buffer_push(tty);
107 kfree_skb(skb);
108 return 1;
109 }
110 }
111 }
112 } 106 }
113 return 0; 107#endif
108 if (info->emu.mdmreg[REG_CPPP] & BIT_CPPP)
109 tty_insert_flip_char(tty, last, 0xFF);
110 else
111 tty_insert_flip_char(tty, last, TTY_NORMAL);
112 tty_flip_buffer_push(tty);
113 kfree_skb(skb);
114
115 return 1;
114} 116}
115 117
116/* isdn_tty_readmodem() is called periodically from within timer-interrupt. 118/* isdn_tty_readmodem() is called periodically from within timer-interrupt.
@@ -128,35 +130,39 @@ isdn_tty_readmodem(void)
128 modem_info *info; 130 modem_info *info;
129 131
130 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 132 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
131 if ((midx = dev->m_idx[i]) >= 0) { 133 midx = dev->m_idx[i];
132 info = &dev->mdm.info[midx]; 134 if (midx < 0)
133 if (info->online) { 135 continue;
134 r = 0; 136
137 info = &dev->mdm.info[midx];
138 if (!info->online)
139 continue;
140
141 r = 0;
135#ifdef CONFIG_ISDN_AUDIO 142#ifdef CONFIG_ISDN_AUDIO
136 isdn_audio_eval_dtmf(info); 143 isdn_audio_eval_dtmf(info);
137 if ((info->vonline & 1) && (info->emu.vpar[1])) 144 if ((info->vonline & 1) && (info->emu.vpar[1]))
138 isdn_audio_eval_silence(info); 145 isdn_audio_eval_silence(info);
139#endif 146#endif
140 if ((tty = info->tty)) { 147 tty = info->port.tty;
141 if (info->mcr & UART_MCR_RTS) { 148 if (tty) {
142 /* CISCO AsyncPPP Hack */ 149 if (info->mcr & UART_MCR_RTS) {
143 if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP)) 150 /* CISCO AsyncPPP Hack */
144 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0); 151 if (!(info->emu.mdmreg[REG_CPPP] & BIT_CPPP))
145 else 152 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 0);
146 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1); 153 else
147 if (r) 154 r = isdn_readbchan_tty(info->isdn_driver, info->isdn_channel, tty, 1);
148 tty_flip_buffer_push(tty); 155 if (r)
149 } else 156 tty_flip_buffer_push(tty);
150 r = 1; 157 } else
151 } else 158 r = 1;
152 r = 1; 159 } else
153 if (r) { 160 r = 1;
154 info->rcvsched = 0; 161 if (r) {
155 resched = 1; 162 info->rcvsched = 0;
156 } else 163 resched = 1;
157 info->rcvsched = 1; 164 } else
158 } 165 info->rcvsched = 1;
159 }
160 } 166 }
161 if (!resched) 167 if (!resched)
162 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0); 168 isdn_timer_ctrl(ISDN_TIMER_MODEMREAD, 0);
@@ -294,7 +300,7 @@ isdn_tty_tint(modem_info *info)
294 len = skb->len; 300 len = skb->len;
295 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver, 301 if ((slen = isdn_writebuf_skb_stub(info->isdn_driver,
296 info->isdn_channel, 1, skb)) == len) { 302 info->isdn_channel, 1, skb)) == len) {
297 struct tty_struct *tty = info->tty; 303 struct tty_struct *tty = info->port.tty;
298 info->send_outstanding++; 304 info->send_outstanding++;
299 info->msr &= ~UART_MSR_CTS; 305 info->msr &= ~UART_MSR_CTS;
300 info->lsr &= ~UART_LSR_TEMT; 306 info->lsr &= ~UART_LSR_TEMT;
@@ -327,7 +333,7 @@ isdn_tty_countDLE(unsigned char *buf, int len)
327static int 333static int
328isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len) 334isdn_tty_handleDLEdown(modem_info *info, atemu *m, int len)
329{ 335{
330 unsigned char *p = &info->xmit_buf[info->xmit_count]; 336 unsigned char *p = &info->port.xmit_buf[info->xmit_count];
331 int count = 0; 337 int count = 0;
332 338
333 while (len > 0) { 339 while (len > 0) {
@@ -471,7 +477,7 @@ isdn_tty_senddown(modem_info *info)
471 return; 477 return;
472 } 478 }
473 skb_reserve(skb, skb_res); 479 skb_reserve(skb, skb_res);
474 memcpy(skb_put(skb, buflen), info->xmit_buf, buflen); 480 memcpy(skb_put(skb, buflen), info->port.xmit_buf, buflen);
475 info->xmit_count = 0; 481 info->xmit_count = 0;
476#ifdef CONFIG_ISDN_AUDIO 482#ifdef CONFIG_ISDN_AUDIO
477 if (info->vonline & 2) { 483 if (info->vonline & 2) {
@@ -699,7 +705,7 @@ isdn_tty_modem_hup(modem_info *info, int local)
699 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line); 705 printk(KERN_DEBUG "Mhup ttyI%d\n", info->line);
700#endif 706#endif
701 info->rcvsched = 0; 707 info->rcvsched = 0;
702 isdn_tty_flush_buffer(info->tty); 708 isdn_tty_flush_buffer(info->port.tty);
703 if (info->online) { 709 if (info->online) {
704 info->last_lhup = local; 710 info->last_lhup = local;
705 info->online = 0; 711 info->online = 0;
@@ -997,20 +1003,21 @@ isdn_tty_paranoia_check(modem_info *info, char *name, const char *routine)
997static void 1003static void
998isdn_tty_change_speed(modem_info *info) 1004isdn_tty_change_speed(modem_info *info)
999{ 1005{
1006 struct tty_port *port = &info->port;
1000 uint cflag, 1007 uint cflag,
1001 cval, 1008 cval,
1002 quot; 1009 quot;
1003 int i; 1010 int i;
1004 1011
1005 if (!info->tty || !info->tty->termios) 1012 if (!port->tty || !port->tty->termios)
1006 return; 1013 return;
1007 cflag = info->tty->termios->c_cflag; 1014 cflag = port->tty->termios->c_cflag;
1008 1015
1009 quot = i = cflag & CBAUD; 1016 quot = i = cflag & CBAUD;
1010 if (i & CBAUDEX) { 1017 if (i & CBAUDEX) {
1011 i &= ~CBAUDEX; 1018 i &= ~CBAUDEX;
1012 if (i < 1 || i > 2) 1019 if (i < 1 || i > 2)
1013 info->tty->termios->c_cflag &= ~CBAUDEX; 1020 port->tty->termios->c_cflag &= ~CBAUDEX;
1014 else 1021 else
1015 i += 15; 1022 i += 15;
1016 } 1023 }
@@ -1040,20 +1047,20 @@ isdn_tty_change_speed(modem_info *info)
1040 1047
1041 /* CTS flow control flag and modem status interrupts */ 1048 /* CTS flow control flag and modem status interrupts */
1042 if (cflag & CRTSCTS) { 1049 if (cflag & CRTSCTS) {
1043 info->flags |= ISDN_ASYNC_CTS_FLOW; 1050 port->flags |= ASYNC_CTS_FLOW;
1044 } else 1051 } else
1045 info->flags &= ~ISDN_ASYNC_CTS_FLOW; 1052 port->flags &= ~ASYNC_CTS_FLOW;
1046 if (cflag & CLOCAL) 1053 if (cflag & CLOCAL)
1047 info->flags &= ~ISDN_ASYNC_CHECK_CD; 1054 port->flags &= ~ASYNC_CHECK_CD;
1048 else { 1055 else {
1049 info->flags |= ISDN_ASYNC_CHECK_CD; 1056 port->flags |= ASYNC_CHECK_CD;
1050 } 1057 }
1051} 1058}
1052 1059
1053static int 1060static int
1054isdn_tty_startup(modem_info *info) 1061isdn_tty_startup(modem_info *info)
1055{ 1062{
1056 if (info->flags & ISDN_ASYNC_INITIALIZED) 1063 if (info->port.flags & ASYNC_INITIALIZED)
1057 return 0; 1064 return 0;
1058 isdn_lock_drivers(); 1065 isdn_lock_drivers();
1059#ifdef ISDN_DEBUG_MODEM_OPEN 1066#ifdef ISDN_DEBUG_MODEM_OPEN
@@ -1063,14 +1070,14 @@ isdn_tty_startup(modem_info *info)
1063 * Now, initialize the UART 1070 * Now, initialize the UART
1064 */ 1071 */
1065 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2; 1072 info->mcr = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
1066 if (info->tty) 1073 if (info->port.tty)
1067 clear_bit(TTY_IO_ERROR, &info->tty->flags); 1074 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
1068 /* 1075 /*
1069 * and set the speed of the serial port 1076 * and set the speed of the serial port
1070 */ 1077 */
1071 isdn_tty_change_speed(info); 1078 isdn_tty_change_speed(info);
1072 1079
1073 info->flags |= ISDN_ASYNC_INITIALIZED; 1080 info->port.flags |= ASYNC_INITIALIZED;
1074 info->msr |= (UART_MSR_DSR | UART_MSR_CTS); 1081 info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
1075 info->send_outstanding = 0; 1082 info->send_outstanding = 0;
1076 return 0; 1083 return 0;
@@ -1083,14 +1090,14 @@ isdn_tty_startup(modem_info *info)
1083static void 1090static void
1084isdn_tty_shutdown(modem_info *info) 1091isdn_tty_shutdown(modem_info *info)
1085{ 1092{
1086 if (!(info->flags & ISDN_ASYNC_INITIALIZED)) 1093 if (!(info->port.flags & ASYNC_INITIALIZED))
1087 return; 1094 return;
1088#ifdef ISDN_DEBUG_MODEM_OPEN 1095#ifdef ISDN_DEBUG_MODEM_OPEN
1089 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); 1096 printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
1090#endif 1097#endif
1091 isdn_unlock_drivers(); 1098 isdn_unlock_drivers();
1092 info->msr &= ~UART_MSR_RI; 1099 info->msr &= ~UART_MSR_RI;
1093 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 1100 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) {
1094 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS); 1101 info->mcr &= ~(UART_MCR_DTR | UART_MCR_RTS);
1095 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) { 1102 if (info->emu.mdmreg[REG_DTRHUP] & BIT_DTRHUP) {
1096 isdn_tty_modem_reset_regs(info, 0); 1103 isdn_tty_modem_reset_regs(info, 0);
@@ -1100,10 +1107,10 @@ isdn_tty_shutdown(modem_info *info)
1100 isdn_tty_modem_hup(info, 1); 1107 isdn_tty_modem_hup(info, 1);
1101 } 1108 }
1102 } 1109 }
1103 if (info->tty) 1110 if (info->port.tty)
1104 set_bit(TTY_IO_ERROR, &info->tty->flags); 1111 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
1105 1112
1106 info->flags &= ~ISDN_ASYNC_INITIALIZED; 1113 info->port.flags &= ~ASYNC_INITIALIZED;
1107} 1114}
1108 1115
1109/* isdn_tty_write() is the main send-routine. It is called from the upper 1116/* isdn_tty_write() is the main send-routine. It is called from the upper
@@ -1146,7 +1153,7 @@ isdn_tty_write(struct tty_struct *tty, const u_char *buf, int count)
1146 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c, 1153 isdn_tty_check_esc(buf, m->mdmreg[REG_ESC], c,
1147 &(m->pluscount), 1154 &(m->pluscount),
1148 &(m->lastplus)); 1155 &(m->lastplus));
1149 memcpy(&(info->xmit_buf[info->xmit_count]), buf, c); 1156 memcpy(&info->port.xmit_buf[info->xmit_count], buf, c);
1150#ifdef CONFIG_ISDN_AUDIO 1157#ifdef CONFIG_ISDN_AUDIO
1151 if (info->vonline) { 1158 if (info->vonline) {
1152 int cc = isdn_tty_handleDLEdown(info, m, c); 1159 int cc = isdn_tty_handleDLEdown(info, m, c);
@@ -1478,107 +1485,6 @@ isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1478 * isdn_tty_open() and friends 1485 * isdn_tty_open() and friends
1479 * ------------------------------------------------------------ 1486 * ------------------------------------------------------------
1480 */ 1487 */
1481static int
1482isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info *info)
1483{
1484 DECLARE_WAITQUEUE(wait, NULL);
1485 int do_clocal = 0;
1486 int retval;
1487
1488 /*
1489 * If the device is in the middle of being closed, then block
1490 * until it's done, and then try again.
1491 */
1492 if (tty_hung_up_p(filp) ||
1493 (info->flags & ISDN_ASYNC_CLOSING)) {
1494 if (info->flags & ISDN_ASYNC_CLOSING)
1495 interruptible_sleep_on(&info->close_wait);
1496#ifdef MODEM_DO_RESTART
1497 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1498 return -EAGAIN;
1499 else
1500 return -ERESTARTSYS;
1501#else
1502 return -EAGAIN;
1503#endif
1504 }
1505 /*
1506 * If non-blocking mode is set, then make the check up front
1507 * and then exit.
1508 */
1509 if ((filp->f_flags & O_NONBLOCK) ||
1510 (tty->flags & (1 << TTY_IO_ERROR))) {
1511 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1512 return -EBUSY;
1513 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1514 return 0;
1515 }
1516 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) {
1517 if (info->normal_termios.c_cflag & CLOCAL)
1518 do_clocal = 1;
1519 } else {
1520 if (tty->termios->c_cflag & CLOCAL)
1521 do_clocal = 1;
1522 }
1523 /*
1524 * Block waiting for the carrier detect and the line to become
1525 * free (i.e., not in use by the callout). While we are in
1526 * this loop, info->count is dropped by one, so that
1527 * isdn_tty_close() knows when to free things. We restore it upon
1528 * exit, either normal or abnormal.
1529 */
1530 retval = 0;
1531 add_wait_queue(&info->open_wait, &wait);
1532#ifdef ISDN_DEBUG_MODEM_OPEN
1533 printk(KERN_DEBUG "isdn_tty_block_til_ready before block: ttyi%d, count = %d\n",
1534 info->line, info->count);
1535#endif
1536 if (!(tty_hung_up_p(filp)))
1537 info->count--;
1538 info->blocked_open++;
1539 while (1) {
1540 set_current_state(TASK_INTERRUPTIBLE);
1541 if (tty_hung_up_p(filp) ||
1542 !(info->flags & ISDN_ASYNC_INITIALIZED)) {
1543#ifdef MODEM_DO_RESTART
1544 if (info->flags & ISDN_ASYNC_HUP_NOTIFY)
1545 retval = -EAGAIN;
1546 else
1547 retval = -ERESTARTSYS;
1548#else
1549 retval = -EAGAIN;
1550#endif
1551 break;
1552 }
1553 if (!(info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) &&
1554 !(info->flags & ISDN_ASYNC_CLOSING) &&
1555 (do_clocal || (info->msr & UART_MSR_DCD))) {
1556 break;
1557 }
1558 if (signal_pending(current)) {
1559 retval = -ERESTARTSYS;
1560 break;
1561 }
1562#ifdef ISDN_DEBUG_MODEM_OPEN
1563 printk(KERN_DEBUG "isdn_tty_block_til_ready blocking: ttyi%d, count = %d\n",
1564 info->line, info->count);
1565#endif
1566 schedule();
1567 }
1568 current->state = TASK_RUNNING;
1569 remove_wait_queue(&info->open_wait, &wait);
1570 if (!tty_hung_up_p(filp))
1571 info->count++;
1572 info->blocked_open--;
1573#ifdef ISDN_DEBUG_MODEM_OPEN
1574 printk(KERN_DEBUG "isdn_tty_block_til_ready after blocking: ttyi%d, count = %d\n",
1575 info->line, info->count);
1576#endif
1577 if (retval)
1578 return retval;
1579 info->flags |= ISDN_ASYNC_NORMAL_ACTIVE;
1580 return 0;
1581}
1582 1488
1583/* 1489/*
1584 * This routine is called whenever a serial port is opened. It 1490 * This routine is called whenever a serial port is opened. It
@@ -1589,23 +1495,22 @@ isdn_tty_block_til_ready(struct tty_struct *tty, struct file *filp, modem_info *
1589static int 1495static int
1590isdn_tty_open(struct tty_struct *tty, struct file *filp) 1496isdn_tty_open(struct tty_struct *tty, struct file *filp)
1591{ 1497{
1498 struct tty_port *port;
1592 modem_info *info; 1499 modem_info *info;
1593 int retval; 1500 int retval;
1594 1501
1595 info = &dev->mdm.info[tty->index]; 1502 info = &dev->mdm.info[tty->index];
1596 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open")) 1503 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_open"))
1597 return -ENODEV; 1504 return -ENODEV;
1598 if (!try_module_get(info->owner)) { 1505 port = &info->port;
1599 printk(KERN_WARNING "%s: cannot reserve module\n", __func__);
1600 return -ENODEV;
1601 }
1602#ifdef ISDN_DEBUG_MODEM_OPEN 1506#ifdef ISDN_DEBUG_MODEM_OPEN
1603 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name, 1507 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
1604 info->count); 1508 port->count);
1605#endif 1509#endif
1606 info->count++; 1510 port->count++;
1607 tty->driver_data = info; 1511 tty->driver_data = info;
1608 info->tty = tty; 1512 port->tty = tty;
1513 tty->port = port;
1609 /* 1514 /*
1610 * Start up serial port 1515 * Start up serial port
1611 */ 1516 */
@@ -1614,15 +1519,13 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
1614#ifdef ISDN_DEBUG_MODEM_OPEN 1519#ifdef ISDN_DEBUG_MODEM_OPEN
1615 printk(KERN_DEBUG "isdn_tty_open return after startup\n"); 1520 printk(KERN_DEBUG "isdn_tty_open return after startup\n");
1616#endif 1521#endif
1617 module_put(info->owner);
1618 return retval; 1522 return retval;
1619 } 1523 }
1620 retval = isdn_tty_block_til_ready(tty, filp, info); 1524 retval = tty_port_block_til_ready(port, tty, filp);
1621 if (retval) { 1525 if (retval) {
1622#ifdef ISDN_DEBUG_MODEM_OPEN 1526#ifdef ISDN_DEBUG_MODEM_OPEN
1623 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n"); 1527 printk(KERN_DEBUG "isdn_tty_open return after isdn_tty_block_til_ready \n");
1624#endif 1528#endif
1625 module_put(info->owner);
1626 return retval; 1529 return retval;
1627 } 1530 }
1628#ifdef ISDN_DEBUG_MODEM_OPEN 1531#ifdef ISDN_DEBUG_MODEM_OPEN
@@ -1639,6 +1542,7 @@ static void
1639isdn_tty_close(struct tty_struct *tty, struct file *filp) 1542isdn_tty_close(struct tty_struct *tty, struct file *filp)
1640{ 1543{
1641 modem_info *info = (modem_info *) tty->driver_data; 1544 modem_info *info = (modem_info *) tty->driver_data;
1545 struct tty_port *port = &info->port;
1642 ulong timeout; 1546 ulong timeout;
1643 1547
1644 if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close")) 1548 if (!info || isdn_tty_paranoia_check(info, tty->name, "isdn_tty_close"))
@@ -1649,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
1649#endif 1553#endif
1650 return; 1554 return;
1651 } 1555 }
1652 if ((tty->count == 1) && (info->count != 1)) { 1556 if ((tty->count == 1) && (port->count != 1)) {
1653 /* 1557 /*
1654 * Uh, oh. tty->count is 1, which means that the tty 1558 * Uh, oh. tty->count is 1, which means that the tty
1655 * structure will be freed. Info->count should always 1559 * structure will be freed. Info->count should always
@@ -1658,30 +1562,21 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
1658 * serial port won't be shutdown. 1562 * serial port won't be shutdown.
1659 */ 1563 */
1660 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, " 1564 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
1661 "info->count is %d\n", info->count); 1565 "info->count is %d\n", port->count);
1662 info->count = 1; 1566 port->count = 1;
1663 } 1567 }
1664 if (--info->count < 0) { 1568 if (--port->count < 0) {
1665 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n", 1569 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
1666 info->line, info->count); 1570 info->line, port->count);
1667 info->count = 0; 1571 port->count = 0;
1668 } 1572 }
1669 if (info->count) { 1573 if (port->count) {
1670#ifdef ISDN_DEBUG_MODEM_OPEN 1574#ifdef ISDN_DEBUG_MODEM_OPEN
1671 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n"); 1575 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
1672#endif 1576#endif
1673 module_put(info->owner);
1674 return; 1577 return;
1675 } 1578 }
1676 info->flags |= ISDN_ASYNC_CLOSING; 1579 port->flags |= ASYNC_CLOSING;
1677 /*
1678 * Save the termios structure, since this port may have
1679 * separate termios for callout and dialin.
1680 */
1681 if (info->flags & ISDN_ASYNC_NORMAL_ACTIVE)
1682 info->normal_termios = *tty->termios;
1683 if (info->flags & ISDN_ASYNC_CALLOUT_ACTIVE)
1684 info->callout_termios = *tty->termios;
1685 1580
1686 tty->closing = 1; 1581 tty->closing = 1;
1687 /* 1582 /*
@@ -1690,7 +1585,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
1690 * interrupt driver to stop checking the data ready bit in the 1585 * interrupt driver to stop checking the data ready bit in the
1691 * line status register. 1586 * line status register.
1692 */ 1587 */
1693 if (info->flags & ISDN_ASYNC_INITIALIZED) { 1588 if (port->flags & ASYNC_INITIALIZED) {
1694 tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */ 1589 tty_wait_until_sent_from_close(tty, 3000); /* 30 seconds timeout */
1695 /* 1590 /*
1696 * Before we drop DTR, make sure the UART transmitter 1591 * Before we drop DTR, make sure the UART transmitter
@@ -1708,16 +1603,10 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
1708 isdn_tty_shutdown(info); 1603 isdn_tty_shutdown(info);
1709 isdn_tty_flush_buffer(tty); 1604 isdn_tty_flush_buffer(tty);
1710 tty_ldisc_flush(tty); 1605 tty_ldisc_flush(tty);
1711 info->tty = NULL; 1606 port->tty = NULL;
1712 info->ncarrier = 0; 1607 info->ncarrier = 0;
1713 tty->closing = 0; 1608
1714 module_put(info->owner); 1609 tty_port_close_end(port, tty);
1715 if (info->blocked_open) {
1716 msleep_interruptible(500);
1717 wake_up_interruptible(&info->open_wait);
1718 }
1719 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CLOSING);
1720 wake_up_interruptible(&info->close_wait);
1721#ifdef ISDN_DEBUG_MODEM_OPEN 1610#ifdef ISDN_DEBUG_MODEM_OPEN
1722 printk(KERN_DEBUG "isdn_tty_close normal exit\n"); 1611 printk(KERN_DEBUG "isdn_tty_close normal exit\n");
1723#endif 1612#endif
@@ -1730,14 +1619,15 @@ static void
1730isdn_tty_hangup(struct tty_struct *tty) 1619isdn_tty_hangup(struct tty_struct *tty)
1731{ 1620{
1732 modem_info *info = (modem_info *) tty->driver_data; 1621 modem_info *info = (modem_info *) tty->driver_data;
1622 struct tty_port *port = &info->port;
1733 1623
1734 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup")) 1624 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
1735 return; 1625 return;
1736 isdn_tty_shutdown(info); 1626 isdn_tty_shutdown(info);
1737 info->count = 0; 1627 port->count = 0;
1738 info->flags &= ~(ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE); 1628 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1739 info->tty = NULL; 1629 port->tty = NULL;
1740 wake_up_interruptible(&info->open_wait); 1630 wake_up_interruptible(&port->open_wait);
1741} 1631}
1742 1632
1743/* This routine initializes all emulator-data. 1633/* This routine initializes all emulator-data.
@@ -1864,6 +1754,16 @@ static const struct tty_operations modem_ops = {
1864 .tiocmset = isdn_tty_tiocmset, 1754 .tiocmset = isdn_tty_tiocmset,
1865}; 1755};
1866 1756
1757static int isdn_tty_carrier_raised(struct tty_port *port)
1758{
1759 modem_info *info = container_of(port, modem_info, port);
1760 return info->msr & UART_MSR_DCD;
1761}
1762
1763static const struct tty_port_operations isdn_tty_port_ops = {
1764 .carrier_raised = isdn_tty_carrier_raised,
1765};
1766
1867int 1767int
1868isdn_tty_modem_init(void) 1768isdn_tty_modem_init(void)
1869{ 1769{
@@ -1899,9 +1799,8 @@ isdn_tty_modem_init(void)
1899 goto err_unregister; 1799 goto err_unregister;
1900 } 1800 }
1901#endif 1801#endif
1902#ifdef MODULE 1802 tty_port_init(&info->port);
1903 info->owner = THIS_MODULE; 1803 info->port.ops = &isdn_tty_port_ops;
1904#endif
1905 spin_lock_init(&info->readlock); 1804 spin_lock_init(&info->readlock);
1906 sprintf(info->last_cause, "0000"); 1805 sprintf(info->last_cause, "0000");
1907 sprintf(info->last_num, "none"); 1806 sprintf(info->last_num, "none");
@@ -1913,12 +1812,7 @@ isdn_tty_modem_init(void)
1913 isdn_tty_modem_reset_regs(info, 1); 1812 isdn_tty_modem_reset_regs(info, 1);
1914 info->magic = ISDN_ASYNC_MAGIC; 1813 info->magic = ISDN_ASYNC_MAGIC;
1915 info->line = i; 1814 info->line = i;
1916 info->tty = NULL;
1917 info->x_char = 0; 1815 info->x_char = 0;
1918 info->count = 0;
1919 info->blocked_open = 0;
1920 init_waitqueue_head(&info->open_wait);
1921 init_waitqueue_head(&info->close_wait);
1922 info->isdn_driver = -1; 1816 info->isdn_driver = -1;
1923 info->isdn_channel = -1; 1817 info->isdn_channel = -1;
1924 info->drv_index = -1; 1818 info->drv_index = -1;
@@ -1930,13 +1824,15 @@ isdn_tty_modem_init(void)
1930#ifdef CONFIG_ISDN_AUDIO 1824#ifdef CONFIG_ISDN_AUDIO
1931 skb_queue_head_init(&info->dtmf_queue); 1825 skb_queue_head_init(&info->dtmf_queue);
1932#endif 1826#endif
1933 if (!(info->xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5, GFP_KERNEL))) { 1827 info->port.xmit_buf = kmalloc(ISDN_SERIAL_XMIT_MAX + 5,
1828 GFP_KERNEL);
1829 if (!info->port.xmit_buf) {
1934 printk(KERN_ERR "Could not allocate modem xmit-buffer\n"); 1830 printk(KERN_ERR "Could not allocate modem xmit-buffer\n");
1935 retval = -ENOMEM; 1831 retval = -ENOMEM;
1936 goto err_unregister; 1832 goto err_unregister;
1937 } 1833 }
1938 /* Make room for T.70 header */ 1834 /* Make room for T.70 header */
1939 info->xmit_buf += 4; 1835 info->port.xmit_buf += 4;
1940 } 1836 }
1941 return 0; 1837 return 0;
1942err_unregister: 1838err_unregister:
@@ -1945,7 +1841,7 @@ err_unregister:
1945#ifdef CONFIG_ISDN_TTY_FAX 1841#ifdef CONFIG_ISDN_TTY_FAX
1946 kfree(info->fax); 1842 kfree(info->fax);
1947#endif 1843#endif
1948 kfree(info->xmit_buf - 4); 1844 kfree(info->port.xmit_buf - 4);
1949 } 1845 }
1950 tty_unregister_driver(m->tty_modem); 1846 tty_unregister_driver(m->tty_modem);
1951err: 1847err:
@@ -1966,7 +1862,7 @@ isdn_tty_exit(void)
1966#ifdef CONFIG_ISDN_TTY_FAX 1862#ifdef CONFIG_ISDN_TTY_FAX
1967 kfree(info->fax); 1863 kfree(info->fax);
1968#endif 1864#endif
1969 kfree(info->xmit_buf - 4); 1865 kfree(info->port.xmit_buf - 4);
1970 } 1866 }
1971 tty_unregister_driver(dev->mdm.tty_modem); 1867 tty_unregister_driver(dev->mdm.tty_modem);
1972 put_tty_driver(dev->mdm.tty_modem); 1868 put_tty_driver(dev->mdm.tty_modem);
@@ -2068,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
2068 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 1964 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
2069 modem_info *info = &dev->mdm.info[i]; 1965 modem_info *info = &dev->mdm.info[i];
2070 1966
2071 if (info->count == 0) 1967 if (info->port.count == 0)
2072 continue; 1968 continue;
2073 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */ 1969 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
2074 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */ 1970 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
@@ -2076,12 +1972,12 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
2076#ifdef ISDN_DEBUG_MODEM_ICALL 1972#ifdef ISDN_DEBUG_MODEM_ICALL
2077 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret); 1973 printk(KERN_DEBUG "m_fi: match1 wret=%d\n", wret);
2078 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx, 1974 printk(KERN_DEBUG "m_fi: idx=%d flags=%08lx drv=%d ch=%d usg=%d\n", idx,
2079 info->flags, info->isdn_driver, info->isdn_channel, 1975 info->port.flags, info->isdn_driver,
2080 dev->usage[idx]); 1976 info->isdn_channel, dev->usage[idx]);
2081#endif 1977#endif
2082 if ( 1978 if (
2083#ifndef FIX_FILE_TRANSFER 1979#ifndef FIX_FILE_TRANSFER
2084 (info->flags & ISDN_ASYNC_NORMAL_ACTIVE) && 1980 (info->port.flags & ASYNC_NORMAL_ACTIVE) &&
2085#endif 1981#endif
2086 (info->isdn_driver == -1) && 1982 (info->isdn_driver == -1) &&
2087 (info->isdn_channel == -1) && 1983 (info->isdn_channel == -1) &&
@@ -2120,8 +2016,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
2120 return (wret == 2) ? 3 : 0; 2016 return (wret == 2) ? 3 : 0;
2121} 2017}
2122 2018
2123#define TTY_IS_ACTIVE(info) \ 2019#define TTY_IS_ACTIVE(info) (info->port.flags & ASYNC_NORMAL_ACTIVE)
2124 (info->flags & (ISDN_ASYNC_NORMAL_ACTIVE | ISDN_ASYNC_CALLOUT_ACTIVE))
2125 2020
2126int 2021int
2127isdn_tty_stat_callback(int i, isdn_ctrl *c) 2022isdn_tty_stat_callback(int i, isdn_ctrl *c)
@@ -2212,9 +2107,9 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
2212 * for incoming call of this device when 2107 * for incoming call of this device when
2213 * DCD follow the state of incoming carrier 2108 * DCD follow the state of incoming carrier
2214 */ 2109 */
2215 if (info->blocked_open && 2110 if (info->port.blocked_open &&
2216 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) { 2111 (info->emu.mdmreg[REG_DCD] & BIT_DCD)) {
2217 wake_up_interruptible(&info->open_wait); 2112 wake_up_interruptible(&info->port.open_wait);
2218 } 2113 }
2219 2114
2220 /* Schedule CONNECT-Message to any tty 2115 /* Schedule CONNECT-Message to any tty
@@ -2222,7 +2117,8 @@ isdn_tty_stat_callback(int i, isdn_ctrl *c)
2222 * set DCD-bit of its modem-status. 2117 * set DCD-bit of its modem-status.
2223 */ 2118 */
2224 if (TTY_IS_ACTIVE(info) || 2119 if (TTY_IS_ACTIVE(info) ||
2225 (info->blocked_open && (info->emu.mdmreg[REG_DCD] & BIT_DCD))) { 2120 (info->port.blocked_open &&
2121 (info->emu.mdmreg[REG_DCD] & BIT_DCD))) {
2226 info->msr |= UART_MSR_DCD; 2122 info->msr |= UART_MSR_DCD;
2227 info->emu.charge = 0; 2123 info->emu.charge = 0;
2228 if (info->dialing & 0xf) 2124 if (info->dialing & 0xf)
@@ -2339,8 +2235,8 @@ isdn_tty_at_cout(char *msg, modem_info *info)
2339 l = strlen(msg); 2235 l = strlen(msg);
2340 2236
2341 spin_lock_irqsave(&info->readlock, flags); 2237 spin_lock_irqsave(&info->readlock, flags);
2342 tty = info->tty; 2238 tty = info->port.tty;
2343 if ((info->flags & ISDN_ASYNC_CLOSING) || (!tty)) { 2239 if ((info->port.flags & ASYNC_CLOSING) || (!tty)) {
2344 spin_unlock_irqrestore(&info->readlock, flags); 2240 spin_unlock_irqrestore(&info->readlock, flags);
2345 return; 2241 return;
2346 } 2242 }
@@ -2490,15 +2386,15 @@ isdn_tty_modem_result(int code, modem_info *info)
2490 case RESULT_NO_CARRIER: 2386 case RESULT_NO_CARRIER:
2491#ifdef ISDN_DEBUG_MODEM_HUP 2387#ifdef ISDN_DEBUG_MODEM_HUP
2492 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n", 2388 printk(KERN_DEBUG "modem_result: NO CARRIER %d %d\n",
2493 (info->flags & ISDN_ASYNC_CLOSING), 2389 (info->port.flags & ASYNC_CLOSING),
2494 (!info->tty)); 2390 (!info->port.tty));
2495#endif 2391#endif
2496 m->mdmreg[REG_RINGCNT] = 0; 2392 m->mdmreg[REG_RINGCNT] = 0;
2497 del_timer(&info->nc_timer); 2393 del_timer(&info->nc_timer);
2498 info->ncarrier = 0; 2394 info->ncarrier = 0;
2499 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) { 2395 if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty))
2500 return; 2396 return;
2501 } 2397
2502#ifdef CONFIG_ISDN_AUDIO 2398#ifdef CONFIG_ISDN_AUDIO
2503 if (info->vonline & 1) { 2399 if (info->vonline & 1) {
2504#ifdef ISDN_DEBUG_MODEM_VOICE 2400#ifdef ISDN_DEBUG_MODEM_VOICE
@@ -2629,14 +2525,11 @@ isdn_tty_modem_result(int code, modem_info *info)
2629 } 2525 }
2630 } 2526 }
2631 if (code == RESULT_NO_CARRIER) { 2527 if (code == RESULT_NO_CARRIER) {
2632 if ((info->flags & ISDN_ASYNC_CLOSING) || (!info->tty)) { 2528 if ((info->port.flags & ASYNC_CLOSING) || (!info->port.tty))
2633 return; 2529 return;
2634 } 2530
2635 if ((info->flags & ISDN_ASYNC_CHECK_CD) && 2531 if (info->port.flags & ASYNC_CHECK_CD)
2636 (!((info->flags & ISDN_ASYNC_CALLOUT_ACTIVE) && 2532 tty_hangup(info->port.tty);
2637 (info->flags & ISDN_ASYNC_CALLOUT_NOHUP)))) {
2638 tty_hangup(info->tty);
2639 }
2640 } 2533 }
2641} 2534}
2642 2535
@@ -3803,19 +3696,19 @@ isdn_tty_modem_escape(void)
3803 int midx; 3696 int midx;
3804 3697
3805 for (i = 0; i < ISDN_MAX_CHANNELS; i++) 3698 for (i = 0; i < ISDN_MAX_CHANNELS; i++)
3806 if (USG_MODEM(dev->usage[i])) 3699 if (USG_MODEM(dev->usage[i]) && (midx = dev->m_idx[i]) >= 0) {
3807 if ((midx = dev->m_idx[i]) >= 0) { 3700 modem_info *info = &dev->mdm.info[midx];
3808 modem_info *info = &dev->mdm.info[midx]; 3701 if (info->online) {
3809 if (info->online) { 3702 ton = 1;
3810 ton = 1; 3703 if ((info->emu.pluscount == 3) &&
3811 if ((info->emu.pluscount == 3) && 3704 time_after(jiffies,
3812 time_after(jiffies , info->emu.lastplus + PLUSWAIT2)) { 3705 info->emu.lastplus + PLUSWAIT2)) {
3813 info->emu.pluscount = 0; 3706 info->emu.pluscount = 0;
3814 info->online = 0; 3707 info->online = 0;
3815 isdn_tty_modem_result(RESULT_OK, info); 3708 isdn_tty_modem_result(RESULT_OK, info);
3816 }
3817 } 3709 }
3818 } 3710 }
3711 }
3819 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton); 3712 isdn_timer_ctrl(ISDN_TIMER_MODEMPLUS, ton);
3820} 3713}
3821 3714
@@ -3873,15 +3766,14 @@ isdn_tty_carrier_timeout(void)
3873 3766
3874 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 3767 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
3875 modem_info *info = &dev->mdm.info[i]; 3768 modem_info *info = &dev->mdm.info[i];
3876 if (info->dialing) { 3769 if (!info->dialing)
3877 if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) { 3770 continue;
3878 info->dialing = 0; 3771 if (info->emu.carrierwait++ > info->emu.mdmreg[REG_WAITC]) {
3879 isdn_tty_modem_result(RESULT_NO_CARRIER, info); 3772 info->dialing = 0;
3880 isdn_tty_modem_hup(info, 1); 3773 isdn_tty_modem_result(RESULT_NO_CARRIER, info);
3881 } 3774 isdn_tty_modem_hup(info, 1);
3882 else 3775 } else
3883 ton = 1; 3776 ton = 1;
3884 }
3885 } 3777 }
3886 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton); 3778 isdn_timer_ctrl(ISDN_TIMER_CARRIER, ton);
3887} 3779}
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 2d2a6882ba33..813d70946d39 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -106,13 +106,6 @@
106 106
107#define MAX_RX_URBS 2 107#define MAX_RX_URBS 2
108 108
109static inline struct hso_serial *get_serial_by_tty(struct tty_struct *tty)
110{
111 if (tty)
112 return tty->driver_data;
113 return NULL;
114}
115
116/*****************************************************************************/ 109/*****************************************************************************/
117/* Debugging functions */ 110/* Debugging functions */
118/*****************************************************************************/ 111/*****************************************************************************/
@@ -255,9 +248,8 @@ struct hso_serial {
255 u8 dtr_state; 248 u8 dtr_state;
256 unsigned tx_urb_used:1; 249 unsigned tx_urb_used:1;
257 250
251 struct tty_port port;
258 /* from usb_serial_port */ 252 /* from usb_serial_port */
259 struct tty_struct *tty;
260 int open_count;
261 spinlock_t serial_lock; 253 spinlock_t serial_lock;
262 254
263 int (*write_data) (struct hso_serial *serial); 255 int (*write_data) (struct hso_serial *serial);
@@ -1114,7 +1106,7 @@ static void hso_init_termios(struct ktermios *termios)
1114static void _hso_serial_set_termios(struct tty_struct *tty, 1106static void _hso_serial_set_termios(struct tty_struct *tty,
1115 struct ktermios *old) 1107 struct ktermios *old)
1116{ 1108{
1117 struct hso_serial *serial = get_serial_by_tty(tty); 1109 struct hso_serial *serial = tty->driver_data;
1118 struct ktermios *termios; 1110 struct ktermios *termios;
1119 1111
1120 if (!serial) { 1112 if (!serial) {
@@ -1190,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
1190 struct urb *urb; 1182 struct urb *urb;
1191 1183
1192 urb = serial->rx_urb[0]; 1184 urb = serial->rx_urb[0];
1193 if (serial->open_count > 0) { 1185 if (serial->port.count > 0) {
1194 count = put_rxbuf_data(urb, serial); 1186 count = put_rxbuf_data(urb, serial);
1195 if (count == -1) 1187 if (count == -1)
1196 return; 1188 return;
@@ -1226,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
1226 DUMP1(urb->transfer_buffer, urb->actual_length); 1218 DUMP1(urb->transfer_buffer, urb->actual_length);
1227 1219
1228 /* Anyone listening? */ 1220 /* Anyone listening? */
1229 if (serial->open_count == 0) 1221 if (serial->port.count == 0)
1230 return; 1222 return;
1231 1223
1232 if (status == 0) { 1224 if (status == 0) {
@@ -1268,7 +1260,7 @@ static void hso_unthrottle_tasklet(struct hso_serial *serial)
1268 1260
1269static void hso_unthrottle(struct tty_struct *tty) 1261static void hso_unthrottle(struct tty_struct *tty)
1270{ 1262{
1271 struct hso_serial *serial = get_serial_by_tty(tty); 1263 struct hso_serial *serial = tty->driver_data;
1272 1264
1273 tasklet_hi_schedule(&serial->unthrottle_tasklet); 1265 tasklet_hi_schedule(&serial->unthrottle_tasklet);
1274} 1266}
@@ -1304,15 +1296,12 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1304 kref_get(&serial->parent->ref); 1296 kref_get(&serial->parent->ref);
1305 1297
1306 /* setup */ 1298 /* setup */
1307 spin_lock_irq(&serial->serial_lock);
1308 tty->driver_data = serial; 1299 tty->driver_data = serial;
1309 tty_kref_put(serial->tty); 1300 tty_port_tty_set(&serial->port, tty);
1310 serial->tty = tty_kref_get(tty);
1311 spin_unlock_irq(&serial->serial_lock);
1312 1301
1313 /* check for port already opened, if not set the termios */ 1302 /* check for port already opened, if not set the termios */
1314 serial->open_count++; 1303 serial->port.count++;
1315 if (serial->open_count == 1) { 1304 if (serial->port.count == 1) {
1316 serial->rx_state = RX_IDLE; 1305 serial->rx_state = RX_IDLE;
1317 /* Force default termio settings */ 1306 /* Force default termio settings */
1318 _hso_serial_set_termios(tty, NULL); 1307 _hso_serial_set_termios(tty, NULL);
@@ -1324,7 +1313,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
1324 result = hso_start_serial_device(serial->parent, GFP_KERNEL); 1313 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
1325 if (result) { 1314 if (result) {
1326 hso_stop_serial_device(serial->parent); 1315 hso_stop_serial_device(serial->parent);
1327 serial->open_count--; 1316 serial->port.count--;
1328 kref_put(&serial->parent->ref, hso_serial_ref_free); 1317 kref_put(&serial->parent->ref, hso_serial_ref_free);
1329 } 1318 }
1330 } else { 1319 } else {
@@ -1361,17 +1350,11 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1361 1350
1362 /* reset the rts and dtr */ 1351 /* reset the rts and dtr */
1363 /* do the actual close */ 1352 /* do the actual close */
1364 serial->open_count--; 1353 serial->port.count--;
1365 1354
1366 if (serial->open_count <= 0) { 1355 if (serial->port.count <= 0) {
1367 serial->open_count = 0; 1356 serial->port.count = 0;
1368 spin_lock_irq(&serial->serial_lock); 1357 tty_port_tty_set(&serial->port, NULL);
1369 if (serial->tty == tty) {
1370 serial->tty->driver_data = NULL;
1371 serial->tty = NULL;
1372 tty_kref_put(tty);
1373 }
1374 spin_unlock_irq(&serial->serial_lock);
1375 if (!usb_gone) 1358 if (!usb_gone)
1376 hso_stop_serial_device(serial->parent); 1359 hso_stop_serial_device(serial->parent);
1377 tasklet_kill(&serial->unthrottle_tasklet); 1360 tasklet_kill(&serial->unthrottle_tasklet);
@@ -1390,7 +1373,7 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
1390static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf, 1373static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
1391 int count) 1374 int count)
1392{ 1375{
1393 struct hso_serial *serial = get_serial_by_tty(tty); 1376 struct hso_serial *serial = tty->driver_data;
1394 int space, tx_bytes; 1377 int space, tx_bytes;
1395 unsigned long flags; 1378 unsigned long flags;
1396 1379
@@ -1422,7 +1405,7 @@ out:
1422/* how much room is there for writing */ 1405/* how much room is there for writing */
1423static int hso_serial_write_room(struct tty_struct *tty) 1406static int hso_serial_write_room(struct tty_struct *tty)
1424{ 1407{
1425 struct hso_serial *serial = get_serial_by_tty(tty); 1408 struct hso_serial *serial = tty->driver_data;
1426 int room; 1409 int room;
1427 unsigned long flags; 1410 unsigned long flags;
1428 1411
@@ -1437,7 +1420,7 @@ static int hso_serial_write_room(struct tty_struct *tty)
1437/* setup the term */ 1420/* setup the term */
1438static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old) 1421static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
1439{ 1422{
1440 struct hso_serial *serial = get_serial_by_tty(tty); 1423 struct hso_serial *serial = tty->driver_data;
1441 unsigned long flags; 1424 unsigned long flags;
1442 1425
1443 if (old) 1426 if (old)
@@ -1446,7 +1429,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
1446 1429
1447 /* the actual setup */ 1430 /* the actual setup */
1448 spin_lock_irqsave(&serial->serial_lock, flags); 1431 spin_lock_irqsave(&serial->serial_lock, flags);
1449 if (serial->open_count) 1432 if (serial->port.count)
1450 _hso_serial_set_termios(tty, old); 1433 _hso_serial_set_termios(tty, old);
1451 else 1434 else
1452 tty->termios = old; 1435 tty->termios = old;
@@ -1458,7 +1441,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
1458/* how many characters in the buffer */ 1441/* how many characters in the buffer */
1459static int hso_serial_chars_in_buffer(struct tty_struct *tty) 1442static int hso_serial_chars_in_buffer(struct tty_struct *tty)
1460{ 1443{
1461 struct hso_serial *serial = get_serial_by_tty(tty); 1444 struct hso_serial *serial = tty->driver_data;
1462 int chars; 1445 int chars;
1463 unsigned long flags; 1446 unsigned long flags;
1464 1447
@@ -1629,7 +1612,7 @@ static int hso_get_count(struct tty_struct *tty,
1629 struct serial_icounter_struct *icount) 1612 struct serial_icounter_struct *icount)
1630{ 1613{
1631 struct uart_icount cnow; 1614 struct uart_icount cnow;
1632 struct hso_serial *serial = get_serial_by_tty(tty); 1615 struct hso_serial *serial = tty->driver_data;
1633 struct hso_tiocmget *tiocmget = serial->tiocmget; 1616 struct hso_tiocmget *tiocmget = serial->tiocmget;
1634 1617
1635 memset(icount, 0, sizeof(struct serial_icounter_struct)); 1618 memset(icount, 0, sizeof(struct serial_icounter_struct));
@@ -1659,7 +1642,7 @@ static int hso_get_count(struct tty_struct *tty,
1659static int hso_serial_tiocmget(struct tty_struct *tty) 1642static int hso_serial_tiocmget(struct tty_struct *tty)
1660{ 1643{
1661 int retval; 1644 int retval;
1662 struct hso_serial *serial = get_serial_by_tty(tty); 1645 struct hso_serial *serial = tty->driver_data;
1663 struct hso_tiocmget *tiocmget; 1646 struct hso_tiocmget *tiocmget;
1664 u16 UART_state_bitmap; 1647 u16 UART_state_bitmap;
1665 1648
@@ -1693,7 +1676,7 @@ static int hso_serial_tiocmset(struct tty_struct *tty,
1693 int val = 0; 1676 int val = 0;
1694 unsigned long flags; 1677 unsigned long flags;
1695 int if_num; 1678 int if_num;
1696 struct hso_serial *serial = get_serial_by_tty(tty); 1679 struct hso_serial *serial = tty->driver_data;
1697 1680
1698 /* sanity check */ 1681 /* sanity check */
1699 if (!serial) { 1682 if (!serial) {
@@ -1733,7 +1716,7 @@ static int hso_serial_tiocmset(struct tty_struct *tty,
1733static int hso_serial_ioctl(struct tty_struct *tty, 1716static int hso_serial_ioctl(struct tty_struct *tty,
1734 unsigned int cmd, unsigned long arg) 1717 unsigned int cmd, unsigned long arg)
1735{ 1718{
1736 struct hso_serial *serial = get_serial_by_tty(tty); 1719 struct hso_serial *serial = tty->driver_data;
1737 int ret = 0; 1720 int ret = 0;
1738 D4("IOCTL cmd: %d, arg: %ld", cmd, arg); 1721 D4("IOCTL cmd: %d, arg: %ld", cmd, arg);
1739 1722
@@ -1905,7 +1888,7 @@ static void intr_callback(struct urb *urb)
1905 D1("Pending read interrupt on port %d\n", i); 1888 D1("Pending read interrupt on port %d\n", i);
1906 spin_lock(&serial->serial_lock); 1889 spin_lock(&serial->serial_lock);
1907 if (serial->rx_state == RX_IDLE && 1890 if (serial->rx_state == RX_IDLE &&
1908 serial->open_count > 0) { 1891 serial->port.count > 0) {
1909 /* Setup and send a ctrl req read on 1892 /* Setup and send a ctrl req read on
1910 * port i */ 1893 * port i */
1911 if (!serial->rx_urb_filled[0]) { 1894 if (!serial->rx_urb_filled[0]) {
@@ -1954,14 +1937,13 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
1954 1937
1955 spin_lock(&serial->serial_lock); 1938 spin_lock(&serial->serial_lock);
1956 serial->tx_urb_used = 0; 1939 serial->tx_urb_used = 0;
1957 tty = tty_kref_get(serial->tty);
1958 spin_unlock(&serial->serial_lock); 1940 spin_unlock(&serial->serial_lock);
1959 if (status) { 1941 if (status) {
1960 handle_usb_error(status, __func__, serial->parent); 1942 handle_usb_error(status, __func__, serial->parent);
1961 tty_kref_put(tty);
1962 return; 1943 return;
1963 } 1944 }
1964 hso_put_activity(serial->parent); 1945 hso_put_activity(serial->parent);
1946 tty = tty_port_tty_get(&serial->port);
1965 if (tty) { 1947 if (tty) {
1966 tty_wakeup(tty); 1948 tty_wakeup(tty);
1967 tty_kref_put(tty); 1949 tty_kref_put(tty);
@@ -2001,7 +1983,6 @@ static void ctrl_callback(struct urb *urb)
2001 struct hso_serial *serial = urb->context; 1983 struct hso_serial *serial = urb->context;
2002 struct usb_ctrlrequest *req; 1984 struct usb_ctrlrequest *req;
2003 int status = urb->status; 1985 int status = urb->status;
2004 struct tty_struct *tty;
2005 1986
2006 /* sanity check */ 1987 /* sanity check */
2007 if (!serial) 1988 if (!serial)
@@ -2009,11 +1990,9 @@ static void ctrl_callback(struct urb *urb)
2009 1990
2010 spin_lock(&serial->serial_lock); 1991 spin_lock(&serial->serial_lock);
2011 serial->tx_urb_used = 0; 1992 serial->tx_urb_used = 0;
2012 tty = tty_kref_get(serial->tty);
2013 spin_unlock(&serial->serial_lock); 1993 spin_unlock(&serial->serial_lock);
2014 if (status) { 1994 if (status) {
2015 handle_usb_error(status, __func__, serial->parent); 1995 handle_usb_error(status, __func__, serial->parent);
2016 tty_kref_put(tty);
2017 return; 1996 return;
2018 } 1997 }
2019 1998
@@ -2031,13 +2010,15 @@ static void ctrl_callback(struct urb *urb)
2031 put_rxbuf_data_and_resubmit_ctrl_urb(serial); 2010 put_rxbuf_data_and_resubmit_ctrl_urb(serial);
2032 spin_unlock(&serial->serial_lock); 2011 spin_unlock(&serial->serial_lock);
2033 } else { 2012 } else {
2013 struct tty_struct *tty = tty_port_tty_get(&serial->port);
2034 hso_put_activity(serial->parent); 2014 hso_put_activity(serial->parent);
2035 if (tty) 2015 if (tty) {
2036 tty_wakeup(tty); 2016 tty_wakeup(tty);
2017 tty_kref_put(tty);
2018 }
2037 /* response to a write command */ 2019 /* response to a write command */
2038 hso_kick_transmit(serial); 2020 hso_kick_transmit(serial);
2039 } 2021 }
2040 tty_kref_put(tty);
2041} 2022}
2042 2023
2043/* handle RX data for serial port */ 2024/* handle RX data for serial port */
@@ -2053,8 +2034,7 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
2053 return -2; 2034 return -2;
2054 } 2035 }
2055 2036
2056 /* All callers to put_rxbuf_data hold serial_lock */ 2037 tty = tty_port_tty_get(&serial->port);
2057 tty = tty_kref_get(serial->tty);
2058 2038
2059 /* Push data to tty */ 2039 /* Push data to tty */
2060 if (tty) { 2040 if (tty) {
@@ -2074,12 +2054,12 @@ static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial)
2074 write_length_remaining -= curr_write_len; 2054 write_length_remaining -= curr_write_len;
2075 tty_flip_buffer_push(tty); 2055 tty_flip_buffer_push(tty);
2076 } 2056 }
2057 tty_kref_put(tty);
2077 } 2058 }
2078 if (write_length_remaining == 0) { 2059 if (write_length_remaining == 0) {
2079 serial->curr_rx_urb_offset = 0; 2060 serial->curr_rx_urb_offset = 0;
2080 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; 2061 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0;
2081 } 2062 }
2082 tty_kref_put(tty);
2083 return write_length_remaining; 2063 return write_length_remaining;
2084} 2064}
2085 2065
@@ -2320,6 +2300,7 @@ static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
2320 serial->minor = minor; 2300 serial->minor = minor;
2321 serial->magic = HSO_SERIAL_MAGIC; 2301 serial->magic = HSO_SERIAL_MAGIC;
2322 spin_lock_init(&serial->serial_lock); 2302 spin_lock_init(&serial->serial_lock);
2303 tty_port_init(&serial->port);
2323 serial->num_rx_urbs = num_urbs; 2304 serial->num_rx_urbs = num_urbs;
2324 2305
2325 /* RX, allocate urb and initialize */ 2306 /* RX, allocate urb and initialize */
@@ -3098,7 +3079,7 @@ static int hso_resume(struct usb_interface *iface)
3098 /* Start all serial ports */ 3079 /* Start all serial ports */
3099 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) { 3080 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
3100 if (serial_table[i] && (serial_table[i]->interface == iface)) { 3081 if (serial_table[i] && (serial_table[i]->interface == iface)) {
3101 if (dev2ser(serial_table[i])->open_count) { 3082 if (dev2ser(serial_table[i])->port.count) {
3102 result = 3083 result =
3103 hso_start_serial_device(serial_table[i], GFP_NOIO); 3084 hso_start_serial_device(serial_table[i], GFP_NOIO);
3104 hso_kick_transmit(dev2ser(serial_table[i])); 3085 hso_kick_transmit(dev2ser(serial_table[i]));
@@ -3172,13 +3153,12 @@ static void hso_free_interface(struct usb_interface *interface)
3172 if (serial_table[i] && 3153 if (serial_table[i] &&
3173 (serial_table[i]->interface == interface)) { 3154 (serial_table[i]->interface == interface)) {
3174 hso_dev = dev2ser(serial_table[i]); 3155 hso_dev = dev2ser(serial_table[i]);
3175 spin_lock_irq(&hso_dev->serial_lock); 3156 tty = tty_port_tty_get(&hso_dev->port);
3176 tty = tty_kref_get(hso_dev->tty); 3157 if (tty) {
3177 spin_unlock_irq(&hso_dev->serial_lock);
3178 if (tty)
3179 tty_hangup(tty); 3158 tty_hangup(tty);
3159 tty_kref_put(tty);
3160 }
3180 mutex_lock(&hso_dev->parent->mutex); 3161 mutex_lock(&hso_dev->parent->mutex);
3181 tty_kref_put(tty);
3182 hso_dev->parent->usb_gone = 1; 3162 hso_dev->parent->usb_gone = 1;
3183 mutex_unlock(&hso_dev->parent->mutex); 3163 mutex_unlock(&hso_dev->parent->mutex);
3184 kref_put(&serial_table[i]->ref, hso_serial_ref_free); 3164 kref_put(&serial_table[i]->ref, hso_serial_ref_free);
@@ -3312,7 +3292,6 @@ static int __init hso_init(void)
3312 return -ENOMEM; 3292 return -ENOMEM;
3313 3293
3314 /* fill in all needed values */ 3294 /* fill in all needed values */
3315 tty_drv->magic = TTY_DRIVER_MAGIC;
3316 tty_drv->driver_name = driver_name; 3295 tty_drv->driver_name = driver_name;
3317 tty_drv->name = tty_filename; 3296 tty_drv->name = tty_filename;
3318 3297
@@ -3333,7 +3312,7 @@ static int __init hso_init(void)
3333 if (result) { 3312 if (result) {
3334 printk(KERN_ERR "%s - tty_register_driver failed(%d)\n", 3313 printk(KERN_ERR "%s - tty_register_driver failed(%d)\n",
3335 __func__, result); 3314 __func__, result);
3336 return result; 3315 goto err_free_tty;
3337 } 3316 }
3338 3317
3339 /* register this module as an usb driver */ 3318 /* register this module as an usb driver */
@@ -3341,13 +3320,16 @@ static int __init hso_init(void)
3341 if (result) { 3320 if (result) {
3342 printk(KERN_ERR "Could not register hso driver? error: %d\n", 3321 printk(KERN_ERR "Could not register hso driver? error: %d\n",
3343 result); 3322 result);
3344 /* cleanup serial interface */ 3323 goto err_unreg_tty;
3345 tty_unregister_driver(tty_drv);
3346 return result;
3347 } 3324 }
3348 3325
3349 /* done */ 3326 /* done */
3350 return 0; 3327 return 0;
3328err_unreg_tty:
3329 tty_unregister_driver(tty_drv);
3330err_free_tty:
3331 put_tty_driver(tty_drv);
3332 return result;
3351} 3333}
3352 3334
3353static void __exit hso_exit(void) 3335static void __exit hso_exit(void)
@@ -3355,6 +3337,7 @@ static void __exit hso_exit(void)
3355 printk(KERN_INFO "hso: unloaded\n"); 3337 printk(KERN_INFO "hso: unloaded\n");
3356 3338
3357 tty_unregister_driver(tty_drv); 3339 tty_unregister_driver(tty_drv);
3340 put_tty_driver(tty_drv);
3358 /* deregister the usb driver */ 3341 /* deregister the usb driver */
3359 usb_deregister(&hso_driver); 3342 usb_deregister(&hso_driver);
3360} 3343}
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 4f9f1dcc1551..6c0116d48c74 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -20,6 +20,7 @@
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/reboot.h> 22#include <linux/reboot.h>
23#include <linux/serial.h> /* ASYNC_* flags */
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <asm/ccwdev.h> 25#include <asm/ccwdev.h>
25#include <asm/cio.h> 26#include <asm/cio.h>
@@ -44,14 +45,11 @@
44#define RAW3215_TIMEOUT HZ/10 /* time for delayed output */ 45#define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
45 46
46#define RAW3215_FIXED 1 /* 3215 console device is not be freed */ 47#define RAW3215_FIXED 1 /* 3215 console device is not be freed */
47#define RAW3215_ACTIVE 2 /* set if the device is in use */
48#define RAW3215_WORKING 4 /* set if a request is being worked on */ 48#define RAW3215_WORKING 4 /* set if a request is being worked on */
49#define RAW3215_THROTTLED 8 /* set if reading is disabled */ 49#define RAW3215_THROTTLED 8 /* set if reading is disabled */
50#define RAW3215_STOPPED 16 /* set if writing is disabled */ 50#define RAW3215_STOPPED 16 /* set if writing is disabled */
51#define RAW3215_CLOSING 32 /* set while in close process */
52#define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */ 51#define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
53#define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */ 52#define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
54#define RAW3215_FROZEN 256 /* set if 3215 is frozen for suspend */
55 53
56#define TAB_STOP_SIZE 8 /* tab stop size */ 54#define TAB_STOP_SIZE 8 /* tab stop size */
57 55
@@ -76,6 +74,7 @@ struct raw3215_req {
76} __attribute__ ((aligned(8))); 74} __attribute__ ((aligned(8)));
77 75
78struct raw3215_info { 76struct raw3215_info {
77 struct tty_port port;
79 struct ccw_device *cdev; /* device for tty driver */ 78 struct ccw_device *cdev; /* device for tty driver */
80 spinlock_t *lock; /* pointer to irq lock */ 79 spinlock_t *lock; /* pointer to irq lock */
81 int flags; /* state flags */ 80 int flags; /* state flags */
@@ -84,7 +83,6 @@ struct raw3215_info {
84 int head; /* first free byte in output buffer */ 83 int head; /* first free byte in output buffer */
85 int count; /* number of bytes in output buffer */ 84 int count; /* number of bytes in output buffer */
86 int written; /* number of bytes in write requests */ 85 int written; /* number of bytes in write requests */
87 struct tty_struct *tty; /* pointer to tty structure if present */
88 struct raw3215_req *queued_read; /* pointer to queued read requests */ 86 struct raw3215_req *queued_read; /* pointer to queued read requests */
89 struct raw3215_req *queued_write;/* pointer to queued write requests */ 87 struct raw3215_req *queued_write;/* pointer to queued write requests */
90 struct tasklet_struct tlet; /* tasklet to invoke tty_wakeup */ 88 struct tasklet_struct tlet; /* tasklet to invoke tty_wakeup */
@@ -293,7 +291,7 @@ static void raw3215_timeout(unsigned long __data)
293 if (raw->flags & RAW3215_TIMER_RUNS) { 291 if (raw->flags & RAW3215_TIMER_RUNS) {
294 del_timer(&raw->timer); 292 del_timer(&raw->timer);
295 raw->flags &= ~RAW3215_TIMER_RUNS; 293 raw->flags &= ~RAW3215_TIMER_RUNS;
296 if (!(raw->flags & RAW3215_FROZEN)) { 294 if (!(raw->port.flags & ASYNC_SUSPENDED)) {
297 raw3215_mk_write_req(raw); 295 raw3215_mk_write_req(raw);
298 raw3215_start_io(raw); 296 raw3215_start_io(raw);
299 } 297 }
@@ -309,7 +307,8 @@ static void raw3215_timeout(unsigned long __data)
309 */ 307 */
310static inline void raw3215_try_io(struct raw3215_info *raw) 308static inline void raw3215_try_io(struct raw3215_info *raw)
311{ 309{
312 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FROZEN)) 310 if (!(raw->port.flags & ASYNC_INITIALIZED) ||
311 (raw->port.flags & ASYNC_SUSPENDED))
313 return; 312 return;
314 if (raw->queued_read != NULL) 313 if (raw->queued_read != NULL)
315 raw3215_start_io(raw); 314 raw3215_start_io(raw);
@@ -324,10 +323,7 @@ static inline void raw3215_try_io(struct raw3215_info *raw)
324 } 323 }
325 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) { 324 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
326 /* delay small writes */ 325 /* delay small writes */
327 init_timer(&raw->timer);
328 raw->timer.expires = RAW3215_TIMEOUT + jiffies; 326 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
329 raw->timer.data = (unsigned long) raw;
330 raw->timer.function = raw3215_timeout;
331 add_timer(&raw->timer); 327 add_timer(&raw->timer);
332 raw->flags |= RAW3215_TIMER_RUNS; 328 raw->flags |= RAW3215_TIMER_RUNS;
333 } 329 }
@@ -340,17 +336,21 @@ static inline void raw3215_try_io(struct raw3215_info *raw)
340static void raw3215_wakeup(unsigned long data) 336static void raw3215_wakeup(unsigned long data)
341{ 337{
342 struct raw3215_info *raw = (struct raw3215_info *) data; 338 struct raw3215_info *raw = (struct raw3215_info *) data;
343 tty_wakeup(raw->tty); 339 struct tty_struct *tty;
340
341 tty = tty_port_tty_get(&raw->port);
342 tty_wakeup(tty);
343 tty_kref_put(tty);
344} 344}
345 345
346/* 346/*
347 * Try to start the next IO and wake up processes waiting on the tty. 347 * Try to start the next IO and wake up processes waiting on the tty.
348 */ 348 */
349static void raw3215_next_io(struct raw3215_info *raw) 349static void raw3215_next_io(struct raw3215_info *raw, struct tty_struct *tty)
350{ 350{
351 raw3215_mk_write_req(raw); 351 raw3215_mk_write_req(raw);
352 raw3215_try_io(raw); 352 raw3215_try_io(raw);
353 if (raw->tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) 353 if (tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE)
354 tasklet_schedule(&raw->tlet); 354 tasklet_schedule(&raw->tlet);
355} 355}
356 356
@@ -368,10 +368,11 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
368 368
369 raw = dev_get_drvdata(&cdev->dev); 369 raw = dev_get_drvdata(&cdev->dev);
370 req = (struct raw3215_req *) intparm; 370 req = (struct raw3215_req *) intparm;
371 tty = tty_port_tty_get(&raw->port);
371 cstat = irb->scsw.cmd.cstat; 372 cstat = irb->scsw.cmd.cstat;
372 dstat = irb->scsw.cmd.dstat; 373 dstat = irb->scsw.cmd.dstat;
373 if (cstat != 0) 374 if (cstat != 0)
374 raw3215_next_io(raw); 375 raw3215_next_io(raw, tty);
375 if (dstat & 0x01) { /* we got a unit exception */ 376 if (dstat & 0x01) { /* we got a unit exception */
376 dstat &= ~0x01; /* we can ignore it */ 377 dstat &= ~0x01; /* we can ignore it */
377 } 378 }
@@ -381,13 +382,13 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
381 break; 382 break;
382 /* Attention interrupt, someone hit the enter key */ 383 /* Attention interrupt, someone hit the enter key */
383 raw3215_mk_read_req(raw); 384 raw3215_mk_read_req(raw);
384 raw3215_next_io(raw); 385 raw3215_next_io(raw, tty);
385 break; 386 break;
386 case 0x08: 387 case 0x08:
387 case 0x0C: 388 case 0x0C:
388 /* Channel end interrupt. */ 389 /* Channel end interrupt. */
389 if ((raw = req->info) == NULL) 390 if ((raw = req->info) == NULL)
390 return; /* That shouldn't happen ... */ 391 goto put_tty; /* That shouldn't happen ... */
391 if (req->type == RAW3215_READ) { 392 if (req->type == RAW3215_READ) {
392 /* store residual count, then wait for device end */ 393 /* store residual count, then wait for device end */
393 req->residual = irb->scsw.cmd.count; 394 req->residual = irb->scsw.cmd.count;
@@ -397,11 +398,10 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
397 case 0x04: 398 case 0x04:
398 /* Device end interrupt. */ 399 /* Device end interrupt. */
399 if ((raw = req->info) == NULL) 400 if ((raw = req->info) == NULL)
400 return; /* That shouldn't happen ... */ 401 goto put_tty; /* That shouldn't happen ... */
401 if (req->type == RAW3215_READ && raw->tty != NULL) { 402 if (req->type == RAW3215_READ && tty != NULL) {
402 unsigned int cchar; 403 unsigned int cchar;
403 404
404 tty = raw->tty;
405 count = 160 - req->residual; 405 count = 160 - req->residual;
406 EBCASC(raw->inbuf, count); 406 EBCASC(raw->inbuf, count);
407 cchar = ctrlchar_handle(raw->inbuf, count, tty); 407 cchar = ctrlchar_handle(raw->inbuf, count, tty);
@@ -411,7 +411,7 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
411 411
412 case CTRLCHAR_CTRL: 412 case CTRLCHAR_CTRL:
413 tty_insert_flip_char(tty, cchar, TTY_NORMAL); 413 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
414 tty_flip_buffer_push(raw->tty); 414 tty_flip_buffer_push(tty);
415 break; 415 break;
416 416
417 case CTRLCHAR_NONE: 417 case CTRLCHAR_NONE:
@@ -424,7 +424,7 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
424 } else 424 } else
425 count -= 2; 425 count -= 2;
426 tty_insert_flip_string(tty, raw->inbuf, count); 426 tty_insert_flip_string(tty, raw->inbuf, count);
427 tty_flip_buffer_push(raw->tty); 427 tty_flip_buffer_push(tty);
428 break; 428 break;
429 } 429 }
430 } else if (req->type == RAW3215_WRITE) { 430 } else if (req->type == RAW3215_WRITE) {
@@ -439,7 +439,7 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
439 raw->queued_read == NULL) { 439 raw->queued_read == NULL) {
440 wake_up_interruptible(&raw->empty_wait); 440 wake_up_interruptible(&raw->empty_wait);
441 } 441 }
442 raw3215_next_io(raw); 442 raw3215_next_io(raw, tty);
443 break; 443 break;
444 default: 444 default:
445 /* Strange interrupt, I'll do my best to clean up */ 445 /* Strange interrupt, I'll do my best to clean up */
@@ -451,9 +451,10 @@ static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
451 raw->flags &= ~RAW3215_WORKING; 451 raw->flags &= ~RAW3215_WORKING;
452 raw3215_free_req(req); 452 raw3215_free_req(req);
453 } 453 }
454 raw3215_next_io(raw); 454 raw3215_next_io(raw, tty);
455 } 455 }
456 return; 456put_tty:
457 tty_kref_put(tty);
457} 458}
458 459
459/* 460/*
@@ -487,7 +488,7 @@ static void raw3215_make_room(struct raw3215_info *raw, unsigned int length)
487 /* While console is frozen for suspend we have no other 488 /* While console is frozen for suspend we have no other
488 * choice but to drop message from the buffer to make 489 * choice but to drop message from the buffer to make
489 * room for even more messages. */ 490 * room for even more messages. */
490 if (raw->flags & RAW3215_FROZEN) { 491 if (raw->port.flags & ASYNC_SUSPENDED) {
491 raw3215_drop_line(raw); 492 raw3215_drop_line(raw);
492 continue; 493 continue;
493 } 494 }
@@ -609,10 +610,10 @@ static int raw3215_startup(struct raw3215_info *raw)
609{ 610{
610 unsigned long flags; 611 unsigned long flags;
611 612
612 if (raw->flags & RAW3215_ACTIVE) 613 if (raw->port.flags & ASYNC_INITIALIZED)
613 return 0; 614 return 0;
614 raw->line_pos = 0; 615 raw->line_pos = 0;
615 raw->flags |= RAW3215_ACTIVE; 616 raw->port.flags |= ASYNC_INITIALIZED;
616 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 617 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
617 raw3215_try_io(raw); 618 raw3215_try_io(raw);
618 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 619 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
@@ -628,14 +629,15 @@ static void raw3215_shutdown(struct raw3215_info *raw)
628 DECLARE_WAITQUEUE(wait, current); 629 DECLARE_WAITQUEUE(wait, current);
629 unsigned long flags; 630 unsigned long flags;
630 631
631 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED)) 632 if (!(raw->port.flags & ASYNC_INITIALIZED) ||
633 (raw->flags & RAW3215_FIXED))
632 return; 634 return;
633 /* Wait for outstanding requests, then free irq */ 635 /* Wait for outstanding requests, then free irq */
634 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 636 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
635 if ((raw->flags & RAW3215_WORKING) || 637 if ((raw->flags & RAW3215_WORKING) ||
636 raw->queued_write != NULL || 638 raw->queued_write != NULL ||
637 raw->queued_read != NULL) { 639 raw->queued_read != NULL) {
638 raw->flags |= RAW3215_CLOSING; 640 raw->port.flags |= ASYNC_CLOSING;
639 add_wait_queue(&raw->empty_wait, &wait); 641 add_wait_queue(&raw->empty_wait, &wait);
640 set_current_state(TASK_INTERRUPTIBLE); 642 set_current_state(TASK_INTERRUPTIBLE);
641 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 643 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
@@ -643,11 +645,41 @@ static void raw3215_shutdown(struct raw3215_info *raw)
643 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 645 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
644 remove_wait_queue(&raw->empty_wait, &wait); 646 remove_wait_queue(&raw->empty_wait, &wait);
645 set_current_state(TASK_RUNNING); 647 set_current_state(TASK_RUNNING);
646 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING); 648 raw->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING);
647 } 649 }
648 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 650 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
649} 651}
650 652
653static struct raw3215_info *raw3215_alloc_info(void)
654{
655 struct raw3215_info *info;
656
657 info = kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA);
658 if (!info)
659 return NULL;
660
661 info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
662 info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA);
663 if (!info->buffer || !info->inbuf) {
664 kfree(info);
665 return NULL;
666 }
667
668 setup_timer(&info->timer, raw3215_timeout, (unsigned long)info);
669 init_waitqueue_head(&info->empty_wait);
670 tasklet_init(&info->tlet, raw3215_wakeup, (unsigned long)info);
671 tty_port_init(&info->port);
672
673 return info;
674}
675
676static void raw3215_free_info(struct raw3215_info *raw)
677{
678 kfree(raw->inbuf);
679 kfree(raw->buffer);
680 kfree(raw);
681}
682
651static int raw3215_probe (struct ccw_device *cdev) 683static int raw3215_probe (struct ccw_device *cdev)
652{ 684{
653 struct raw3215_info *raw; 685 struct raw3215_info *raw;
@@ -656,11 +688,15 @@ static int raw3215_probe (struct ccw_device *cdev)
656 /* Console is special. */ 688 /* Console is special. */
657 if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev))) 689 if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev)))
658 return 0; 690 return 0;
659 raw = kmalloc(sizeof(struct raw3215_info) + 691
660 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA); 692 raw = raw3215_alloc_info();
661 if (raw == NULL) 693 if (raw == NULL)
662 return -ENOMEM; 694 return -ENOMEM;
663 695
696 raw->cdev = cdev;
697 dev_set_drvdata(&cdev->dev, raw);
698 cdev->handler = raw3215_irq;
699
664 spin_lock(&raw3215_device_lock); 700 spin_lock(&raw3215_device_lock);
665 for (line = 0; line < NR_3215; line++) { 701 for (line = 0; line < NR_3215; line++) {
666 if (!raw3215[line]) { 702 if (!raw3215[line]) {
@@ -670,28 +706,10 @@ static int raw3215_probe (struct ccw_device *cdev)
670 } 706 }
671 spin_unlock(&raw3215_device_lock); 707 spin_unlock(&raw3215_device_lock);
672 if (line == NR_3215) { 708 if (line == NR_3215) {
673 kfree(raw); 709 raw3215_free_info(raw);
674 return -ENODEV; 710 return -ENODEV;
675 } 711 }
676 712
677 raw->cdev = cdev;
678 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
679 memset(raw, 0, sizeof(struct raw3215_info));
680 raw->buffer = kmalloc(RAW3215_BUFFER_SIZE,
681 GFP_KERNEL|GFP_DMA);
682 if (raw->buffer == NULL) {
683 spin_lock(&raw3215_device_lock);
684 raw3215[line] = NULL;
685 spin_unlock(&raw3215_device_lock);
686 kfree(raw);
687 return -ENOMEM;
688 }
689 init_waitqueue_head(&raw->empty_wait);
690 tasklet_init(&raw->tlet, raw3215_wakeup, (unsigned long) raw);
691
692 dev_set_drvdata(&cdev->dev, raw);
693 cdev->handler = raw3215_irq;
694
695 return 0; 713 return 0;
696} 714}
697 715
@@ -703,8 +721,7 @@ static void raw3215_remove (struct ccw_device *cdev)
703 raw = dev_get_drvdata(&cdev->dev); 721 raw = dev_get_drvdata(&cdev->dev);
704 if (raw) { 722 if (raw) {
705 dev_set_drvdata(&cdev->dev, NULL); 723 dev_set_drvdata(&cdev->dev, NULL);
706 kfree(raw->buffer); 724 raw3215_free_info(raw);
707 kfree(raw);
708 } 725 }
709} 726}
710 727
@@ -741,7 +758,7 @@ static int raw3215_pm_stop(struct ccw_device *cdev)
741 raw = dev_get_drvdata(&cdev->dev); 758 raw = dev_get_drvdata(&cdev->dev);
742 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 759 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
743 raw3215_make_room(raw, RAW3215_BUFFER_SIZE); 760 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
744 raw->flags |= RAW3215_FROZEN; 761 raw->port.flags |= ASYNC_SUSPENDED;
745 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); 762 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
746 return 0; 763 return 0;
747} 764}
@@ -754,7 +771,7 @@ static int raw3215_pm_start(struct ccw_device *cdev)
754 /* Allow I/O again and flush output buffer. */ 771 /* Allow I/O again and flush output buffer. */
755 raw = dev_get_drvdata(&cdev->dev); 772 raw = dev_get_drvdata(&cdev->dev);
756 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); 773 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
757 raw->flags &= ~RAW3215_FROZEN; 774 raw->port.flags &= ~ASYNC_SUSPENDED;
758 raw->flags |= RAW3215_FLUSHING; 775 raw->flags |= RAW3215_FLUSHING;
759 raw3215_try_io(raw); 776 raw3215_try_io(raw);
760 raw->flags &= ~RAW3215_FLUSHING; 777 raw->flags &= ~RAW3215_FLUSHING;
@@ -827,7 +844,7 @@ static void con3215_flush(void)
827 unsigned long flags; 844 unsigned long flags;
828 845
829 raw = raw3215[0]; /* console 3215 is the first one */ 846 raw = raw3215[0]; /* console 3215 is the first one */
830 if (raw->flags & RAW3215_FROZEN) 847 if (raw->port.flags & ASYNC_SUSPENDED)
831 /* The console is still frozen for suspend. */ 848 /* The console is still frozen for suspend. */
832 if (ccw_device_force_console()) 849 if (ccw_device_force_console())
833 /* Forcing didn't work, no panic message .. */ 850 /* Forcing didn't work, no panic message .. */
@@ -897,23 +914,16 @@ static int __init con3215_init(void)
897 if (IS_ERR(cdev)) 914 if (IS_ERR(cdev))
898 return -ENODEV; 915 return -ENODEV;
899 916
900 raw3215[0] = raw = (struct raw3215_info *) 917 raw3215[0] = raw = raw3215_alloc_info();
901 kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA);
902 raw->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
903 raw->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA);
904 raw->cdev = cdev; 918 raw->cdev = cdev;
905 dev_set_drvdata(&cdev->dev, raw); 919 dev_set_drvdata(&cdev->dev, raw);
906 cdev->handler = raw3215_irq; 920 cdev->handler = raw3215_irq;
907 921
908 raw->flags |= RAW3215_FIXED; 922 raw->flags |= RAW3215_FIXED;
909 init_waitqueue_head(&raw->empty_wait);
910 tasklet_init(&raw->tlet, raw3215_wakeup, (unsigned long) raw);
911 923
912 /* Request the console irq */ 924 /* Request the console irq */
913 if (raw3215_startup(raw) != 0) { 925 if (raw3215_startup(raw) != 0) {
914 kfree(raw->inbuf); 926 raw3215_free_info(raw);
915 kfree(raw->buffer);
916 kfree(raw);
917 raw3215[0] = NULL; 927 raw3215[0] = NULL;
918 return -ENODEV; 928 return -ENODEV;
919 } 929 }
@@ -940,7 +950,7 @@ static int tty3215_open(struct tty_struct *tty, struct file * filp)
940 return -ENODEV; 950 return -ENODEV;
941 951
942 tty->driver_data = raw; 952 tty->driver_data = raw;
943 raw->tty = tty; 953 tty_port_tty_set(&raw->port, tty);
944 954
945 tty->low_latency = 0; /* don't use bottom half for pushing chars */ 955 tty->low_latency = 0; /* don't use bottom half for pushing chars */
946 /* 956 /*
@@ -971,7 +981,7 @@ static void tty3215_close(struct tty_struct *tty, struct file * filp)
971 raw3215_shutdown(raw); 981 raw3215_shutdown(raw);
972 tasklet_kill(&raw->tlet); 982 tasklet_kill(&raw->tlet);
973 tty->closing = 0; 983 tty->closing = 0;
974 raw->tty = NULL; 984 tty_port_tty_set(&raw->port, NULL);
975} 985}
976 986
977/* 987/*
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index 806588192483..7ef9cfdc17d8 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -199,7 +199,7 @@ handle_diacr(struct kbd_data *kbd, unsigned int ch)
199 if (ch == ' ' || ch == d) 199 if (ch == ' ' || ch == d)
200 return d; 200 return d;
201 201
202 kbd_put_queue(kbd->tty, d); 202 kbd_put_queue(kbd->port, d);
203 return ch; 203 return ch;
204} 204}
205 205
@@ -221,7 +221,7 @@ k_self(struct kbd_data *kbd, unsigned char value)
221{ 221{
222 if (kbd->diacr) 222 if (kbd->diacr)
223 value = handle_diacr(kbd, value); 223 value = handle_diacr(kbd, value);
224 kbd_put_queue(kbd->tty, value); 224 kbd_put_queue(kbd->port, value);
225} 225}
226 226
227/* 227/*
@@ -239,7 +239,7 @@ static void
239k_fn(struct kbd_data *kbd, unsigned char value) 239k_fn(struct kbd_data *kbd, unsigned char value)
240{ 240{
241 if (kbd->func_table[value]) 241 if (kbd->func_table[value])
242 kbd_puts_queue(kbd->tty, kbd->func_table[value]); 242 kbd_puts_queue(kbd->port, kbd->func_table[value]);
243} 243}
244 244
245static void 245static void
@@ -257,20 +257,20 @@ k_spec(struct kbd_data *kbd, unsigned char value)
257 * but we need only 16 bits here 257 * but we need only 16 bits here
258 */ 258 */
259static void 259static void
260to_utf8(struct tty_struct *tty, ushort c) 260to_utf8(struct tty_port *port, ushort c)
261{ 261{
262 if (c < 0x80) 262 if (c < 0x80)
263 /* 0******* */ 263 /* 0******* */
264 kbd_put_queue(tty, c); 264 kbd_put_queue(port, c);
265 else if (c < 0x800) { 265 else if (c < 0x800) {
266 /* 110***** 10****** */ 266 /* 110***** 10****** */
267 kbd_put_queue(tty, 0xc0 | (c >> 6)); 267 kbd_put_queue(port, 0xc0 | (c >> 6));
268 kbd_put_queue(tty, 0x80 | (c & 0x3f)); 268 kbd_put_queue(port, 0x80 | (c & 0x3f));
269 } else { 269 } else {
270 /* 1110**** 10****** 10****** */ 270 /* 1110**** 10****** 10****** */
271 kbd_put_queue(tty, 0xe0 | (c >> 12)); 271 kbd_put_queue(port, 0xe0 | (c >> 12));
272 kbd_put_queue(tty, 0x80 | ((c >> 6) & 0x3f)); 272 kbd_put_queue(port, 0x80 | ((c >> 6) & 0x3f));
273 kbd_put_queue(tty, 0x80 | (c & 0x3f)); 273 kbd_put_queue(port, 0x80 | (c & 0x3f));
274 } 274 }
275} 275}
276 276
@@ -283,7 +283,7 @@ kbd_keycode(struct kbd_data *kbd, unsigned int keycode)
283 unsigned short keysym; 283 unsigned short keysym;
284 unsigned char type, value; 284 unsigned char type, value;
285 285
286 if (!kbd || !kbd->tty) 286 if (!kbd)
287 return; 287 return;
288 288
289 if (keycode >= 384) 289 if (keycode >= 384)
@@ -323,7 +323,7 @@ kbd_keycode(struct kbd_data *kbd, unsigned int keycode)
323#endif 323#endif
324 (*k_handler[type])(kbd, value); 324 (*k_handler[type])(kbd, value);
325 } else 325 } else
326 to_utf8(kbd->tty, keysym); 326 to_utf8(kbd->port, keysym);
327} 327}
328 328
329/* 329/*
@@ -457,6 +457,7 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs,
457 457
458int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg) 458int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg)
459{ 459{
460 struct tty_struct *tty;
460 void __user *argp; 461 void __user *argp;
461 unsigned int ct; 462 unsigned int ct;
462 int perm; 463 int perm;
@@ -467,7 +468,10 @@ int kbd_ioctl(struct kbd_data *kbd, unsigned int cmd, unsigned long arg)
467 * To have permissions to do most of the vt ioctls, we either have 468 * To have permissions to do most of the vt ioctls, we either have
468 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. 469 * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG.
469 */ 470 */
470 perm = current->signal->tty == kbd->tty || capable(CAP_SYS_TTY_CONFIG); 471 tty = tty_port_tty_get(kbd->port);
472 /* FIXME this test is pretty racy */
473 perm = current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG);
474 tty_kref_put(tty);
471 switch (cmd) { 475 switch (cmd) {
472 case KDGKBTYPE: 476 case KDGKBTYPE:
473 return put_user(KB_101, (char __user *)argp); 477 return put_user(KB_101, (char __user *)argp);
diff --git a/drivers/s390/char/keyboard.h b/drivers/s390/char/keyboard.h
index 7e736aaeae6e..f682f4e49680 100644
--- a/drivers/s390/char/keyboard.h
+++ b/drivers/s390/char/keyboard.h
@@ -21,7 +21,7 @@ typedef void (fn_handler_fn)(struct kbd_data *);
21 */ 21 */
22 22
23struct kbd_data { 23struct kbd_data {
24 struct tty_struct *tty; 24 struct tty_port *port;
25 unsigned short **key_maps; 25 unsigned short **key_maps;
26 char **func_table; 26 char **func_table;
27 fn_handler_fn **fn_handler; 27 fn_handler_fn **fn_handler;
@@ -42,16 +42,24 @@ int kbd_ioctl(struct kbd_data *, unsigned int, unsigned long);
42 * Helper Functions. 42 * Helper Functions.
43 */ 43 */
44static inline void 44static inline void
45kbd_put_queue(struct tty_struct *tty, int ch) 45kbd_put_queue(struct tty_port *port, int ch)
46{ 46{
47 struct tty_struct *tty = tty_port_tty_get(port);
48 if (!tty)
49 return;
47 tty_insert_flip_char(tty, ch, 0); 50 tty_insert_flip_char(tty, ch, 0);
48 tty_schedule_flip(tty); 51 tty_schedule_flip(tty);
52 tty_kref_put(tty);
49} 53}
50 54
51static inline void 55static inline void
52kbd_puts_queue(struct tty_struct *tty, char *cp) 56kbd_puts_queue(struct tty_port *port, char *cp)
53{ 57{
58 struct tty_struct *tty = tty_port_tty_get(port);
59 if (!tty)
60 return;
54 while (*cp) 61 while (*cp)
55 tty_insert_flip_char(tty, *cp++, 0); 62 tty_insert_flip_char(tty, *cp++, 0);
56 tty_schedule_flip(tty); 63 tty_schedule_flip(tty);
64 tty_kref_put(tty);
57} 65}
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index 40a9d69c898e..e66a75b3822c 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -48,7 +48,7 @@ static struct sclp_buffer *sclp_ttybuf;
48/* Timer for delayed output of console messages. */ 48/* Timer for delayed output of console messages. */
49static struct timer_list sclp_tty_timer; 49static struct timer_list sclp_tty_timer;
50 50
51static struct tty_struct *sclp_tty; 51static struct tty_port sclp_port;
52static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE]; 52static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE];
53static unsigned short int sclp_tty_chars_count; 53static unsigned short int sclp_tty_chars_count;
54 54
@@ -64,7 +64,7 @@ static int sclp_tty_columns = 80;
64static int 64static int
65sclp_tty_open(struct tty_struct *tty, struct file *filp) 65sclp_tty_open(struct tty_struct *tty, struct file *filp)
66{ 66{
67 sclp_tty = tty; 67 tty_port_tty_set(&sclp_port, tty);
68 tty->driver_data = NULL; 68 tty->driver_data = NULL;
69 tty->low_latency = 0; 69 tty->low_latency = 0;
70 return 0; 70 return 0;
@@ -76,7 +76,7 @@ sclp_tty_close(struct tty_struct *tty, struct file *filp)
76{ 76{
77 if (tty->count > 1) 77 if (tty->count > 1)
78 return; 78 return;
79 sclp_tty = NULL; 79 tty_port_tty_set(&sclp_port, NULL);
80} 80}
81 81
82/* 82/*
@@ -108,6 +108,7 @@ sclp_tty_write_room (struct tty_struct *tty)
108static void 108static void
109sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc) 109sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
110{ 110{
111 struct tty_struct *tty;
111 unsigned long flags; 112 unsigned long flags;
112 void *page; 113 void *page;
113 114
@@ -126,8 +127,10 @@ sclp_ttybuf_callback(struct sclp_buffer *buffer, int rc)
126 spin_unlock_irqrestore(&sclp_tty_lock, flags); 127 spin_unlock_irqrestore(&sclp_tty_lock, flags);
127 } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback)); 128 } while (buffer && sclp_emit_buffer(buffer, sclp_ttybuf_callback));
128 /* check if the tty needs a wake up call */ 129 /* check if the tty needs a wake up call */
129 if (sclp_tty != NULL) { 130 tty = tty_port_tty_get(&sclp_port);
130 tty_wakeup(sclp_tty); 131 if (tty != NULL) {
132 tty_wakeup(tty);
133 tty_kref_put(tty);
131 } 134 }
132} 135}
133 136
@@ -326,21 +329,22 @@ sclp_tty_flush_buffer(struct tty_struct *tty)
326static void 329static void
327sclp_tty_input(unsigned char* buf, unsigned int count) 330sclp_tty_input(unsigned char* buf, unsigned int count)
328{ 331{
332 struct tty_struct *tty = tty_port_tty_get(&sclp_port);
329 unsigned int cchar; 333 unsigned int cchar;
330 334
331 /* 335 /*
332 * If this tty driver is currently closed 336 * If this tty driver is currently closed
333 * then throw the received input away. 337 * then throw the received input away.
334 */ 338 */
335 if (sclp_tty == NULL) 339 if (tty == NULL)
336 return; 340 return;
337 cchar = ctrlchar_handle(buf, count, sclp_tty); 341 cchar = ctrlchar_handle(buf, count, tty);
338 switch (cchar & CTRLCHAR_MASK) { 342 switch (cchar & CTRLCHAR_MASK) {
339 case CTRLCHAR_SYSRQ: 343 case CTRLCHAR_SYSRQ:
340 break; 344 break;
341 case CTRLCHAR_CTRL: 345 case CTRLCHAR_CTRL:
342 tty_insert_flip_char(sclp_tty, cchar, TTY_NORMAL); 346 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
343 tty_flip_buffer_push(sclp_tty); 347 tty_flip_buffer_push(tty);
344 break; 348 break;
345 case CTRLCHAR_NONE: 349 case CTRLCHAR_NONE:
346 /* send (normal) input to line discipline */ 350 /* send (normal) input to line discipline */
@@ -348,13 +352,14 @@ sclp_tty_input(unsigned char* buf, unsigned int count)
348 (strncmp((const char *) buf + count - 2, "^n", 2) && 352 (strncmp((const char *) buf + count - 2, "^n", 2) &&
349 strncmp((const char *) buf + count - 2, "\252n", 2))) { 353 strncmp((const char *) buf + count - 2, "\252n", 2))) {
350 /* add the auto \n */ 354 /* add the auto \n */
351 tty_insert_flip_string(sclp_tty, buf, count); 355 tty_insert_flip_string(tty, buf, count);
352 tty_insert_flip_char(sclp_tty, '\n', TTY_NORMAL); 356 tty_insert_flip_char(tty, '\n', TTY_NORMAL);
353 } else 357 } else
354 tty_insert_flip_string(sclp_tty, buf, count - 2); 358 tty_insert_flip_string(tty, buf, count - 2);
355 tty_flip_buffer_push(sclp_tty); 359 tty_flip_buffer_push(tty);
356 break; 360 break;
357 } 361 }
362 tty_kref_put(tty);
358} 363}
359 364
360/* 365/*
@@ -543,7 +548,7 @@ sclp_tty_init(void)
543 sclp_tty_tolower = 1; 548 sclp_tty_tolower = 1;
544 } 549 }
545 sclp_tty_chars_count = 0; 550 sclp_tty_chars_count = 0;
546 sclp_tty = NULL; 551 tty_port_init(&sclp_port);
547 552
548 rc = sclp_register(&sclp_input_event); 553 rc = sclp_register(&sclp_input_event);
549 if (rc) { 554 if (rc) {
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index b635472ae660..edfc0fd73dc6 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -34,7 +34,6 @@
34#define SCLP_VT220_DEVICE_NAME "ttysclp" 34#define SCLP_VT220_DEVICE_NAME "ttysclp"
35#define SCLP_VT220_CONSOLE_NAME "ttyS" 35#define SCLP_VT220_CONSOLE_NAME "ttyS"
36#define SCLP_VT220_CONSOLE_INDEX 1 /* console=ttyS1 */ 36#define SCLP_VT220_CONSOLE_INDEX 1 /* console=ttyS1 */
37#define SCLP_VT220_BUF_SIZE 80
38 37
39/* Representation of a single write request */ 38/* Representation of a single write request */
40struct sclp_vt220_request { 39struct sclp_vt220_request {
@@ -56,8 +55,7 @@ struct sclp_vt220_sccb {
56/* Structures and data needed to register tty driver */ 55/* Structures and data needed to register tty driver */
57static struct tty_driver *sclp_vt220_driver; 56static struct tty_driver *sclp_vt220_driver;
58 57
59/* The tty_struct that the kernel associated with us */ 58static struct tty_port sclp_vt220_port;
60static struct tty_struct *sclp_vt220_tty;
61 59
62/* Lock to protect internal data from concurrent access */ 60/* Lock to protect internal data from concurrent access */
63static spinlock_t sclp_vt220_lock; 61static spinlock_t sclp_vt220_lock;
@@ -116,6 +114,7 @@ static struct sclp_register sclp_vt220_register = {
116static void 114static void
117sclp_vt220_process_queue(struct sclp_vt220_request *request) 115sclp_vt220_process_queue(struct sclp_vt220_request *request)
118{ 116{
117 struct tty_struct *tty;
119 unsigned long flags; 118 unsigned long flags;
120 void *page; 119 void *page;
121 120
@@ -141,8 +140,10 @@ sclp_vt220_process_queue(struct sclp_vt220_request *request)
141 if (request == NULL && sclp_vt220_flush_later) 140 if (request == NULL && sclp_vt220_flush_later)
142 sclp_vt220_emit_current(); 141 sclp_vt220_emit_current();
143 /* Check if the tty needs a wake up call */ 142 /* Check if the tty needs a wake up call */
144 if (sclp_vt220_tty != NULL) { 143 tty = tty_port_tty_get(&sclp_vt220_port);
145 tty_wakeup(sclp_vt220_tty); 144 if (tty) {
145 tty_wakeup(tty);
146 tty_kref_put(tty);
146 } 147 }
147} 148}
148 149
@@ -460,11 +461,12 @@ sclp_vt220_write(struct tty_struct *tty, const unsigned char *buf, int count)
460static void 461static void
461sclp_vt220_receiver_fn(struct evbuf_header *evbuf) 462sclp_vt220_receiver_fn(struct evbuf_header *evbuf)
462{ 463{
464 struct tty_struct *tty = tty_port_tty_get(&sclp_vt220_port);
463 char *buffer; 465 char *buffer;
464 unsigned int count; 466 unsigned int count;
465 467
466 /* Ignore input if device is not open */ 468 /* Ignore input if device is not open */
467 if (sclp_vt220_tty == NULL) 469 if (tty == NULL)
468 return; 470 return;
469 471
470 buffer = (char *) ((addr_t) evbuf + sizeof(struct evbuf_header)); 472 buffer = (char *) ((addr_t) evbuf + sizeof(struct evbuf_header));
@@ -478,10 +480,11 @@ sclp_vt220_receiver_fn(struct evbuf_header *evbuf)
478 /* Send input to line discipline */ 480 /* Send input to line discipline */
479 buffer++; 481 buffer++;
480 count--; 482 count--;
481 tty_insert_flip_string(sclp_vt220_tty, buffer, count); 483 tty_insert_flip_string(tty, buffer, count);
482 tty_flip_buffer_push(sclp_vt220_tty); 484 tty_flip_buffer_push(tty);
483 break; 485 break;
484 } 486 }
487 tty_kref_put(tty);
485} 488}
486 489
487/* 490/*
@@ -491,10 +494,7 @@ static int
491sclp_vt220_open(struct tty_struct *tty, struct file *filp) 494sclp_vt220_open(struct tty_struct *tty, struct file *filp)
492{ 495{
493 if (tty->count == 1) { 496 if (tty->count == 1) {
494 sclp_vt220_tty = tty; 497 tty_port_tty_set(&sclp_vt220_port, tty);
495 tty->driver_data = kmalloc(SCLP_VT220_BUF_SIZE, GFP_KERNEL);
496 if (tty->driver_data == NULL)
497 return -ENOMEM;
498 tty->low_latency = 0; 498 tty->low_latency = 0;
499 if (!tty->winsize.ws_row && !tty->winsize.ws_col) { 499 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
500 tty->winsize.ws_row = 24; 500 tty->winsize.ws_row = 24;
@@ -510,11 +510,8 @@ sclp_vt220_open(struct tty_struct *tty, struct file *filp)
510static void 510static void
511sclp_vt220_close(struct tty_struct *tty, struct file *filp) 511sclp_vt220_close(struct tty_struct *tty, struct file *filp)
512{ 512{
513 if (tty->count == 1) { 513 if (tty->count == 1)
514 sclp_vt220_tty = NULL; 514 tty_port_tty_set(&sclp_vt220_port, NULL);
515 kfree(tty->driver_data);
516 tty->driver_data = NULL;
517 }
518} 515}
519 516
520/* 517/*
@@ -635,9 +632,9 @@ static int __init __sclp_vt220_init(int num_pages)
635 INIT_LIST_HEAD(&sclp_vt220_empty); 632 INIT_LIST_HEAD(&sclp_vt220_empty);
636 INIT_LIST_HEAD(&sclp_vt220_outqueue); 633 INIT_LIST_HEAD(&sclp_vt220_outqueue);
637 init_timer(&sclp_vt220_timer); 634 init_timer(&sclp_vt220_timer);
635 tty_port_init(&sclp_vt220_port);
638 sclp_vt220_current_request = NULL; 636 sclp_vt220_current_request = NULL;
639 sclp_vt220_buffered_chars = 0; 637 sclp_vt220_buffered_chars = 0;
640 sclp_vt220_tty = NULL;
641 sclp_vt220_flush_later = 0; 638 sclp_vt220_flush_later = 0;
642 639
643 /* Allocate pages for output buffering */ 640 /* Allocate pages for output buffering */
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index b43445a55cb6..10ec690197cb 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -61,7 +61,7 @@ struct tty3270_line {
61 */ 61 */
62struct tty3270 { 62struct tty3270 {
63 struct raw3270_view view; 63 struct raw3270_view view;
64 struct tty_struct *tty; /* Pointer to tty structure */ 64 struct tty_port port;
65 void **freemem_pages; /* Array of pages used for freemem. */ 65 void **freemem_pages; /* Array of pages used for freemem. */
66 struct list_head freemem; /* List of free memory for strings. */ 66 struct list_head freemem; /* List of free memory for strings. */
67 67
@@ -324,9 +324,8 @@ tty3270_blank_line(struct tty3270 *tp)
324static void 324static void
325tty3270_write_callback(struct raw3270_request *rq, void *data) 325tty3270_write_callback(struct raw3270_request *rq, void *data)
326{ 326{
327 struct tty3270 *tp; 327 struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
328 328
329 tp = (struct tty3270 *) rq->view;
330 if (rq->rc != 0) { 329 if (rq->rc != 0) {
331 /* Write wasn't successful. Refresh all. */ 330 /* Write wasn't successful. Refresh all. */
332 tp->update_flags = TTY_UPDATE_ALL; 331 tp->update_flags = TTY_UPDATE_ALL;
@@ -450,10 +449,9 @@ tty3270_rcl_add(struct tty3270 *tp, char *input, int len)
450static void 449static void
451tty3270_rcl_backward(struct kbd_data *kbd) 450tty3270_rcl_backward(struct kbd_data *kbd)
452{ 451{
453 struct tty3270 *tp; 452 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
454 struct string *s; 453 struct string *s;
455 454
456 tp = kbd->tty->driver_data;
457 spin_lock_bh(&tp->view.lock); 455 spin_lock_bh(&tp->view.lock);
458 if (tp->inattr == TF_INPUT) { 456 if (tp->inattr == TF_INPUT) {
459 if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines) 457 if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines)
@@ -478,9 +476,8 @@ tty3270_rcl_backward(struct kbd_data *kbd)
478static void 476static void
479tty3270_exit_tty(struct kbd_data *kbd) 477tty3270_exit_tty(struct kbd_data *kbd)
480{ 478{
481 struct tty3270 *tp; 479 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
482 480
483 tp = kbd->tty->driver_data;
484 raw3270_deactivate_view(&tp->view); 481 raw3270_deactivate_view(&tp->view);
485} 482}
486 483
@@ -490,10 +487,9 @@ tty3270_exit_tty(struct kbd_data *kbd)
490static void 487static void
491tty3270_scroll_forward(struct kbd_data *kbd) 488tty3270_scroll_forward(struct kbd_data *kbd)
492{ 489{
493 struct tty3270 *tp; 490 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
494 int nr_up; 491 int nr_up;
495 492
496 tp = kbd->tty->driver_data;
497 spin_lock_bh(&tp->view.lock); 493 spin_lock_bh(&tp->view.lock);
498 nr_up = tp->nr_up - tp->view.rows + 2; 494 nr_up = tp->nr_up - tp->view.rows + 2;
499 if (nr_up < 0) 495 if (nr_up < 0)
@@ -513,10 +509,9 @@ tty3270_scroll_forward(struct kbd_data *kbd)
513static void 509static void
514tty3270_scroll_backward(struct kbd_data *kbd) 510tty3270_scroll_backward(struct kbd_data *kbd)
515{ 511{
516 struct tty3270 *tp; 512 struct tty3270 *tp = container_of(kbd->port, struct tty3270, port);
517 int nr_up; 513 int nr_up;
518 514
519 tp = kbd->tty->driver_data;
520 spin_lock_bh(&tp->view.lock); 515 spin_lock_bh(&tp->view.lock);
521 nr_up = tp->nr_up + tp->view.rows - 2; 516 nr_up = tp->nr_up + tp->view.rows - 2;
522 if (nr_up + tp->view.rows - 2 > tp->nr_lines) 517 if (nr_up + tp->view.rows - 2 > tp->nr_lines)
@@ -537,11 +532,10 @@ static void
537tty3270_read_tasklet(struct raw3270_request *rrq) 532tty3270_read_tasklet(struct raw3270_request *rrq)
538{ 533{
539 static char kreset_data = TW_KR; 534 static char kreset_data = TW_KR;
540 struct tty3270 *tp; 535 struct tty3270 *tp = container_of(rrq->view, struct tty3270, view);
541 char *input; 536 char *input;
542 int len; 537 int len;
543 538
544 tp = (struct tty3270 *) rrq->view;
545 spin_lock_bh(&tp->view.lock); 539 spin_lock_bh(&tp->view.lock);
546 /* 540 /*
547 * Two AID keys are special: For 0x7d (enter) the input line 541 * Two AID keys are special: For 0x7d (enter) the input line
@@ -577,13 +571,10 @@ tty3270_read_tasklet(struct raw3270_request *rrq)
577 raw3270_request_add_data(tp->kreset, &kreset_data, 1); 571 raw3270_request_add_data(tp->kreset, &kreset_data, 1);
578 raw3270_start(&tp->view, tp->kreset); 572 raw3270_start(&tp->view, tp->kreset);
579 573
580 /* Emit input string. */ 574 while (len-- > 0)
581 if (tp->tty) { 575 kbd_keycode(tp->kbd, *input++);
582 while (len-- > 0) 576 /* Emit keycode for AID byte. */
583 kbd_keycode(tp->kbd, *input++); 577 kbd_keycode(tp->kbd, 256 + tp->input->string[0]);
584 /* Emit keycode for AID byte. */
585 kbd_keycode(tp->kbd, 256 + tp->input->string[0]);
586 }
587 578
588 raw3270_request_reset(rrq); 579 raw3270_request_reset(rrq);
589 xchg(&tp->read, rrq); 580 xchg(&tp->read, rrq);
@@ -596,9 +587,10 @@ tty3270_read_tasklet(struct raw3270_request *rrq)
596static void 587static void
597tty3270_read_callback(struct raw3270_request *rq, void *data) 588tty3270_read_callback(struct raw3270_request *rq, void *data)
598{ 589{
590 struct tty3270 *tp = container_of(rq->view, struct tty3270, view);
599 raw3270_get_view(rq->view); 591 raw3270_get_view(rq->view);
600 /* Schedule tasklet to pass input to tty. */ 592 /* Schedule tasklet to pass input to tty. */
601 tasklet_schedule(&((struct tty3270 *) rq->view)->readlet); 593 tasklet_schedule(&tp->readlet);
602} 594}
603 595
604/* 596/*
@@ -635,9 +627,8 @@ tty3270_issue_read(struct tty3270 *tp, int lock)
635static int 627static int
636tty3270_activate(struct raw3270_view *view) 628tty3270_activate(struct raw3270_view *view)
637{ 629{
638 struct tty3270 *tp; 630 struct tty3270 *tp = container_of(view, struct tty3270, view);
639 631
640 tp = (struct tty3270 *) view;
641 tp->update_flags = TTY_UPDATE_ALL; 632 tp->update_flags = TTY_UPDATE_ALL;
642 tty3270_set_timer(tp, 1); 633 tty3270_set_timer(tp, 1);
643 return 0; 634 return 0;
@@ -646,9 +637,8 @@ tty3270_activate(struct raw3270_view *view)
646static void 637static void
647tty3270_deactivate(struct raw3270_view *view) 638tty3270_deactivate(struct raw3270_view *view)
648{ 639{
649 struct tty3270 *tp; 640 struct tty3270 *tp = container_of(view, struct tty3270, view);
650 641
651 tp = (struct tty3270 *) view;
652 del_timer(&tp->timer); 642 del_timer(&tp->timer);
653} 643}
654 644
@@ -690,6 +680,17 @@ tty3270_alloc_view(void)
690 if (!tp->freemem_pages) 680 if (!tp->freemem_pages)
691 goto out_tp; 681 goto out_tp;
692 INIT_LIST_HEAD(&tp->freemem); 682 INIT_LIST_HEAD(&tp->freemem);
683 INIT_LIST_HEAD(&tp->lines);
684 INIT_LIST_HEAD(&tp->update);
685 INIT_LIST_HEAD(&tp->rcl_lines);
686 tp->rcl_max = 20;
687 tty_port_init(&tp->port);
688 setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update,
689 (unsigned long) tp);
690 tasklet_init(&tp->readlet,
691 (void (*)(unsigned long)) tty3270_read_tasklet,
692 (unsigned long) tp->read);
693
693 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) { 694 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) {
694 tp->freemem_pages[pages] = (void *) 695 tp->freemem_pages[pages] = (void *)
695 __get_free_pages(GFP_KERNEL|GFP_DMA, 0); 696 __get_free_pages(GFP_KERNEL|GFP_DMA, 0);
@@ -794,16 +795,15 @@ tty3270_free_screen(struct tty3270 *tp)
794static void 795static void
795tty3270_release(struct raw3270_view *view) 796tty3270_release(struct raw3270_view *view)
796{ 797{
797 struct tty3270 *tp; 798 struct tty3270 *tp = container_of(view, struct tty3270, view);
798 struct tty_struct *tty; 799 struct tty_struct *tty = tty_port_tty_get(&tp->port);
799 800
800 tp = (struct tty3270 *) view;
801 tty = tp->tty;
802 if (tty) { 801 if (tty) {
803 tty->driver_data = NULL; 802 tty->driver_data = NULL;
804 tp->tty = tp->kbd->tty = NULL; 803 tty_port_tty_set(&tp->port, NULL);
805 tty_hangup(tty); 804 tty_hangup(tty);
806 raw3270_put_view(&tp->view); 805 raw3270_put_view(&tp->view);
806 tty_kref_put(tty);
807 } 807 }
808} 808}
809 809
@@ -813,8 +813,9 @@ tty3270_release(struct raw3270_view *view)
813static void 813static void
814tty3270_free(struct raw3270_view *view) 814tty3270_free(struct raw3270_view *view)
815{ 815{
816 tty3270_free_screen((struct tty3270 *) view); 816 struct tty3270 *tp = container_of(view, struct tty3270, view);
817 tty3270_free_view((struct tty3270 *) view); 817 tty3270_free_screen(tp);
818 tty3270_free_view(tp);
818} 819}
819 820
820/* 821/*
@@ -823,14 +824,13 @@ tty3270_free(struct raw3270_view *view)
823static void 824static void
824tty3270_del_views(void) 825tty3270_del_views(void)
825{ 826{
826 struct tty3270 *tp;
827 int i; 827 int i;
828 828
829 for (i = 0; i < tty3270_max_index; i++) { 829 for (i = 0; i < tty3270_max_index; i++) {
830 tp = (struct tty3270 *) 830 struct raw3270_view *view =
831 raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR); 831 raw3270_find_view(&tty3270_fn, i + RAW3270_FIRSTMINOR);
832 if (!IS_ERR(tp)) 832 if (!IS_ERR(view))
833 raw3270_del_view(&tp->view); 833 raw3270_del_view(view);
834 } 834 }
835} 835}
836 836
@@ -848,22 +848,23 @@ static struct raw3270_fn tty3270_fn = {
848static int 848static int
849tty3270_open(struct tty_struct *tty, struct file * filp) 849tty3270_open(struct tty_struct *tty, struct file * filp)
850{ 850{
851 struct raw3270_view *view;
851 struct tty3270 *tp; 852 struct tty3270 *tp;
852 int i, rc; 853 int i, rc;
853 854
854 if (tty->count > 1) 855 if (tty->count > 1)
855 return 0; 856 return 0;
856 /* Check if the tty3270 is already there. */ 857 /* Check if the tty3270 is already there. */
857 tp = (struct tty3270 *) 858 view = raw3270_find_view(&tty3270_fn,
858 raw3270_find_view(&tty3270_fn,
859 tty->index + RAW3270_FIRSTMINOR); 859 tty->index + RAW3270_FIRSTMINOR);
860 if (!IS_ERR(tp)) { 860 if (!IS_ERR(view)) {
861 tp = container_of(view, struct tty3270, view);
861 tty->driver_data = tp; 862 tty->driver_data = tp;
862 tty->winsize.ws_row = tp->view.rows - 2; 863 tty->winsize.ws_row = tp->view.rows - 2;
863 tty->winsize.ws_col = tp->view.cols; 864 tty->winsize.ws_col = tp->view.cols;
864 tty->low_latency = 0; 865 tty->low_latency = 0;
865 tp->tty = tty; 866 /* why to reassign? */
866 tp->kbd->tty = tty; 867 tty_port_tty_set(&tp->port, tty);
867 tp->inattr = TF_INPUT; 868 tp->inattr = TF_INPUT;
868 return 0; 869 return 0;
869 } 870 }
@@ -871,7 +872,7 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
871 tty3270_max_index = tty->index + 1; 872 tty3270_max_index = tty->index + 1;
872 873
873 /* Quick exit if there is no device for tty->index. */ 874 /* Quick exit if there is no device for tty->index. */
874 if (PTR_ERR(tp) == -ENODEV) 875 if (PTR_ERR(view) == -ENODEV)
875 return -ENODEV; 876 return -ENODEV;
876 877
877 /* Allocate tty3270 structure on first open. */ 878 /* Allocate tty3270 structure on first open. */
@@ -879,16 +880,6 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
879 if (IS_ERR(tp)) 880 if (IS_ERR(tp))
880 return PTR_ERR(tp); 881 return PTR_ERR(tp);
881 882
882 INIT_LIST_HEAD(&tp->lines);
883 INIT_LIST_HEAD(&tp->update);
884 INIT_LIST_HEAD(&tp->rcl_lines);
885 tp->rcl_max = 20;
886 setup_timer(&tp->timer, (void (*)(unsigned long)) tty3270_update,
887 (unsigned long) tp);
888 tasklet_init(&tp->readlet,
889 (void (*)(unsigned long)) tty3270_read_tasklet,
890 (unsigned long) tp->read);
891
892 rc = raw3270_add_view(&tp->view, &tty3270_fn, 883 rc = raw3270_add_view(&tp->view, &tty3270_fn,
893 tty->index + RAW3270_FIRSTMINOR); 884 tty->index + RAW3270_FIRSTMINOR);
894 if (rc) { 885 if (rc) {
@@ -903,7 +894,7 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
903 return rc; 894 return rc;
904 } 895 }
905 896
906 tp->tty = tty; 897 tty_port_tty_set(&tp->port, tty);
907 tty->low_latency = 0; 898 tty->low_latency = 0;
908 tty->driver_data = tp; 899 tty->driver_data = tp;
909 tty->winsize.ws_row = tp->view.rows - 2; 900 tty->winsize.ws_row = tp->view.rows - 2;
@@ -917,7 +908,7 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
917 for (i = 0; i < tp->view.rows - 2; i++) 908 for (i = 0; i < tp->view.rows - 2; i++)
918 tty3270_blank_line(tp); 909 tty3270_blank_line(tp);
919 910
920 tp->kbd->tty = tty; 911 tp->kbd->port = &tp->port;
921 tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty; 912 tp->kbd->fn_handler[KVAL(K_INCRCONSOLE)] = tty3270_exit_tty;
922 tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward; 913 tp->kbd->fn_handler[KVAL(K_SCROLLBACK)] = tty3270_scroll_backward;
923 tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward; 914 tp->kbd->fn_handler[KVAL(K_SCROLLFORW)] = tty3270_scroll_forward;
@@ -935,14 +926,13 @@ tty3270_open(struct tty_struct *tty, struct file * filp)
935static void 926static void
936tty3270_close(struct tty_struct *tty, struct file * filp) 927tty3270_close(struct tty_struct *tty, struct file * filp)
937{ 928{
938 struct tty3270 *tp; 929 struct tty3270 *tp = tty->driver_data;
939 930
940 if (tty->count > 1) 931 if (tty->count > 1)
941 return; 932 return;
942 tp = (struct tty3270 *) tty->driver_data;
943 if (tp) { 933 if (tp) {
944 tty->driver_data = NULL; 934 tty->driver_data = NULL;
945 tp->tty = tp->kbd->tty = NULL; 935 tty_port_tty_set(&tp->port, NULL);
946 raw3270_put_view(&tp->view); 936 raw3270_put_view(&tp->view);
947 } 937 }
948} 938}
@@ -1391,7 +1381,7 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch)
1391 tty3270_lf(tp); 1381 tty3270_lf(tp);
1392 break; 1382 break;
1393 case 'Z': /* Respond ID. */ 1383 case 'Z': /* Respond ID. */
1394 kbd_puts_queue(tp->tty, "\033[?6c"); 1384 kbd_puts_queue(&tp->port, "\033[?6c");
1395 break; 1385 break;
1396 case '7': /* Save cursor position. */ 1386 case '7': /* Save cursor position. */
1397 tp->saved_cx = tp->cx; 1387 tp->saved_cx = tp->cx;
@@ -1437,11 +1427,11 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch)
1437 tp->esc_state = ESnormal; 1427 tp->esc_state = ESnormal;
1438 if (ch == 'n' && !tp->esc_ques) { 1428 if (ch == 'n' && !tp->esc_ques) {
1439 if (tp->esc_par[0] == 5) /* Status report. */ 1429 if (tp->esc_par[0] == 5) /* Status report. */
1440 kbd_puts_queue(tp->tty, "\033[0n"); 1430 kbd_puts_queue(&tp->port, "\033[0n");
1441 else if (tp->esc_par[0] == 6) { /* Cursor report. */ 1431 else if (tp->esc_par[0] == 6) { /* Cursor report. */
1442 char buf[40]; 1432 char buf[40];
1443 sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1); 1433 sprintf(buf, "\033[%d;%dR", tp->cy + 1, tp->cx + 1);
1444 kbd_puts_queue(tp->tty, buf); 1434 kbd_puts_queue(&tp->port, buf);
1445 } 1435 }
1446 return; 1436 return;
1447 } 1437 }
@@ -1513,12 +1503,13 @@ tty3270_escape_sequence(struct tty3270 *tp, char ch)
1513 * String write routine for 3270 ttys 1503 * String write routine for 3270 ttys
1514 */ 1504 */
1515static void 1505static void
1516tty3270_do_write(struct tty3270 *tp, const unsigned char *buf, int count) 1506tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
1507 const unsigned char *buf, int count)
1517{ 1508{
1518 int i_msg, i; 1509 int i_msg, i;
1519 1510
1520 spin_lock_bh(&tp->view.lock); 1511 spin_lock_bh(&tp->view.lock);
1521 for (i_msg = 0; !tp->tty->stopped && i_msg < count; i_msg++) { 1512 for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) {
1522 if (tp->esc_state != 0) { 1513 if (tp->esc_state != 0) {
1523 /* Continue escape sequence. */ 1514 /* Continue escape sequence. */
1524 tty3270_escape_sequence(tp, buf[i_msg]); 1515 tty3270_escape_sequence(tp, buf[i_msg]);
@@ -1595,10 +1586,10 @@ tty3270_write(struct tty_struct * tty,
1595 if (!tp) 1586 if (!tp)
1596 return 0; 1587 return 0;
1597 if (tp->char_count > 0) { 1588 if (tp->char_count > 0) {
1598 tty3270_do_write(tp, tp->char_buf, tp->char_count); 1589 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count);
1599 tp->char_count = 0; 1590 tp->char_count = 0;
1600 } 1591 }
1601 tty3270_do_write(tp, buf, count); 1592 tty3270_do_write(tp, tty, buf, count);
1602 return count; 1593 return count;
1603} 1594}
1604 1595
@@ -1629,7 +1620,7 @@ tty3270_flush_chars(struct tty_struct *tty)
1629 if (!tp) 1620 if (!tp)
1630 return; 1621 return;
1631 if (tp->char_count > 0) { 1622 if (tp->char_count > 0) {
1632 tty3270_do_write(tp, tp->char_buf, tp->char_count); 1623 tty3270_do_write(tp, tty, tp->char_buf, tp->char_count);
1633 tp->char_count = 0; 1624 tp->char_count = 0;
1634 } 1625 }
1635} 1626}
diff --git a/drivers/tty/bfin_jtag_comm.c b/drivers/tty/bfin_jtag_comm.c
index 946f799861f5..61fc74fe1747 100644
--- a/drivers/tty/bfin_jtag_comm.c
+++ b/drivers/tty/bfin_jtag_comm.c
@@ -62,9 +62,7 @@ static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d)
62 62
63static struct tty_driver *bfin_jc_driver; 63static struct tty_driver *bfin_jc_driver;
64static struct task_struct *bfin_jc_kthread; 64static struct task_struct *bfin_jc_kthread;
65static struct tty_struct * volatile bfin_jc_tty; 65static struct tty_port port;
66static unsigned long bfin_jc_count;
67static DEFINE_MUTEX(bfin_jc_tty_mutex);
68static volatile struct circ_buf bfin_jc_write_buf; 66static volatile struct circ_buf bfin_jc_write_buf;
69 67
70static int 68static int
@@ -73,18 +71,21 @@ bfin_jc_emudat_manager(void *arg)
73 uint32_t inbound_len = 0, outbound_len = 0; 71 uint32_t inbound_len = 0, outbound_len = 0;
74 72
75 while (!kthread_should_stop()) { 73 while (!kthread_should_stop()) {
74 struct tty_struct *tty = tty_port_tty_get(&port);
76 /* no one left to give data to, so sleep */ 75 /* no one left to give data to, so sleep */
77 if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) { 76 if (tty == NULL && circ_empty(&bfin_jc_write_buf)) {
78 pr_debug("waiting for readers\n"); 77 pr_debug("waiting for readers\n");
79 __set_current_state(TASK_UNINTERRUPTIBLE); 78 __set_current_state(TASK_UNINTERRUPTIBLE);
80 schedule(); 79 schedule();
81 __set_current_state(TASK_RUNNING); 80 __set_current_state(TASK_RUNNING);
81 continue;
82 } 82 }
83 83
84 /* no data available, so just chill */ 84 /* no data available, so just chill */
85 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) { 85 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) {
86 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n", 86 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n",
87 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head); 87 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head);
88 tty_kref_put(tty);
88 if (inbound_len) 89 if (inbound_len)
89 schedule(); 90 schedule();
90 else 91 else
@@ -94,9 +95,6 @@ bfin_jc_emudat_manager(void *arg)
94 95
95 /* if incoming data is ready, eat it */ 96 /* if incoming data is ready, eat it */
96 if (bfin_read_DBGSTAT() & EMUDIF) { 97 if (bfin_read_DBGSTAT() & EMUDIF) {
97 struct tty_struct *tty;
98 mutex_lock(&bfin_jc_tty_mutex);
99 tty = (struct tty_struct *)bfin_jc_tty;
100 if (tty != NULL) { 98 if (tty != NULL) {
101 uint32_t emudat = bfin_read_emudat(); 99 uint32_t emudat = bfin_read_emudat();
102 if (inbound_len == 0) { 100 if (inbound_len == 0) {
@@ -110,7 +108,6 @@ bfin_jc_emudat_manager(void *arg)
110 tty_flip_buffer_push(tty); 108 tty_flip_buffer_push(tty);
111 } 109 }
112 } 110 }
113 mutex_unlock(&bfin_jc_tty_mutex);
114 } 111 }
115 112
116 /* if outgoing data is ready, post it */ 113 /* if outgoing data is ready, post it */
@@ -120,7 +117,6 @@ bfin_jc_emudat_manager(void *arg)
120 bfin_write_emudat(outbound_len); 117 bfin_write_emudat(outbound_len);
121 pr_debug("outgoing length: 0x%08x\n", outbound_len); 118 pr_debug("outgoing length: 0x%08x\n", outbound_len);
122 } else { 119 } else {
123 struct tty_struct *tty;
124 int tail = bfin_jc_write_buf.tail; 120 int tail = bfin_jc_write_buf.tail;
125 size_t ate = (4 <= outbound_len ? 4 : outbound_len); 121 size_t ate = (4 <= outbound_len ? 4 : outbound_len);
126 uint32_t emudat = 122 uint32_t emudat =
@@ -132,14 +128,12 @@ bfin_jc_emudat_manager(void *arg)
132 ); 128 );
133 bfin_jc_write_buf.tail += ate; 129 bfin_jc_write_buf.tail += ate;
134 outbound_len -= ate; 130 outbound_len -= ate;
135 mutex_lock(&bfin_jc_tty_mutex);
136 tty = (struct tty_struct *)bfin_jc_tty;
137 if (tty) 131 if (tty)
138 tty_wakeup(tty); 132 tty_wakeup(tty);
139 mutex_unlock(&bfin_jc_tty_mutex);
140 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate); 133 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate);
141 } 134 }
142 } 135 }
136 tty_kref_put(tty);
143 } 137 }
144 138
145 __set_current_state(TASK_RUNNING); 139 __set_current_state(TASK_RUNNING);
@@ -149,24 +143,28 @@ bfin_jc_emudat_manager(void *arg)
149static int 143static int
150bfin_jc_open(struct tty_struct *tty, struct file *filp) 144bfin_jc_open(struct tty_struct *tty, struct file *filp)
151{ 145{
152 mutex_lock(&bfin_jc_tty_mutex); 146 unsigned long flags;
153 pr_debug("open %lu\n", bfin_jc_count); 147
154 ++bfin_jc_count; 148 spin_lock_irqsave(&port.lock, flags);
155 bfin_jc_tty = tty; 149 port.count++;
150 spin_unlock_irqrestore(&port.lock, flags);
151 tty_port_tty_set(&port, tty);
156 wake_up_process(bfin_jc_kthread); 152 wake_up_process(bfin_jc_kthread);
157 mutex_unlock(&bfin_jc_tty_mutex);
158 return 0; 153 return 0;
159} 154}
160 155
161static void 156static void
162bfin_jc_close(struct tty_struct *tty, struct file *filp) 157bfin_jc_close(struct tty_struct *tty, struct file *filp)
163{ 158{
164 mutex_lock(&bfin_jc_tty_mutex); 159 unsigned long flags;
165 pr_debug("close %lu\n", bfin_jc_count); 160 bool last;
166 if (--bfin_jc_count == 0) 161
167 bfin_jc_tty = NULL; 162 spin_lock_irqsave(&port.lock, flags);
163 last = --port.count == 0;
164 spin_unlock_irqrestore(&port.lock, flags);
165 if (last)
166 tty_port_tty_set(&port, NULL);
168 wake_up_process(bfin_jc_kthread); 167 wake_up_process(bfin_jc_kthread);
169 mutex_unlock(&bfin_jc_tty_mutex);
170} 168}
171 169
172/* XXX: we dont handle the put_char() case where we must handle count = 1 */ 170/* XXX: we dont handle the put_char() case where we must handle count = 1 */
@@ -242,6 +240,8 @@ static int __init bfin_jc_init(void)
242{ 240{
243 int ret; 241 int ret;
244 242
243 tty_port_init(&port);
244
245 bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME); 245 bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME);
246 if (IS_ERR(bfin_jc_kthread)) 246 if (IS_ERR(bfin_jc_kthread))
247 return PTR_ERR(bfin_jc_kthread); 247 return PTR_ERR(bfin_jc_kthread);
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index 8880adf5fc6f..2d691eb7c40a 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -107,7 +107,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
107 list_for_each_entry(hp, &hvc_structs, next) { 107 list_for_each_entry(hp, &hvc_structs, next) {
108 spin_lock_irqsave(&hp->lock, flags); 108 spin_lock_irqsave(&hp->lock, flags);
109 if (hp->index == index) { 109 if (hp->index == index) {
110 kref_get(&hp->kref); 110 tty_port_get(&hp->port);
111 spin_unlock_irqrestore(&hp->lock, flags); 111 spin_unlock_irqrestore(&hp->lock, flags);
112 spin_unlock(&hvc_structs_lock); 112 spin_unlock(&hvc_structs_lock);
113 return hp; 113 return hp;
@@ -229,9 +229,9 @@ static int __init hvc_console_init(void)
229console_initcall(hvc_console_init); 229console_initcall(hvc_console_init);
230 230
231/* callback when the kboject ref count reaches zero. */ 231/* callback when the kboject ref count reaches zero. */
232static void destroy_hvc_struct(struct kref *kref) 232static void hvc_port_destruct(struct tty_port *port)
233{ 233{
234 struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref); 234 struct hvc_struct *hp = container_of(port, struct hvc_struct, port);
235 unsigned long flags; 235 unsigned long flags;
236 236
237 spin_lock(&hvc_structs_lock); 237 spin_lock(&hvc_structs_lock);
@@ -264,7 +264,7 @@ int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
264 /* make sure no no tty has been registered in this index */ 264 /* make sure no no tty has been registered in this index */
265 hp = hvc_get_by_index(index); 265 hp = hvc_get_by_index(index);
266 if (hp) { 266 if (hp) {
267 kref_put(&hp->kref, destroy_hvc_struct); 267 tty_port_put(&hp->port);
268 return -1; 268 return -1;
269 } 269 }
270 270
@@ -313,20 +313,17 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
313 if (!(hp = hvc_get_by_index(tty->index))) 313 if (!(hp = hvc_get_by_index(tty->index)))
314 return -ENODEV; 314 return -ENODEV;
315 315
316 spin_lock_irqsave(&hp->lock, flags); 316 spin_lock_irqsave(&hp->port.lock, flags);
317 /* Check and then increment for fast path open. */ 317 /* Check and then increment for fast path open. */
318 if (hp->count++ > 0) { 318 if (hp->port.count++ > 0) {
319 tty_kref_get(tty); 319 spin_unlock_irqrestore(&hp->port.lock, flags);
320 spin_unlock_irqrestore(&hp->lock, flags);
321 hvc_kick(); 320 hvc_kick();
322 return 0; 321 return 0;
323 } /* else count == 0 */ 322 } /* else count == 0 */
323 spin_unlock_irqrestore(&hp->port.lock, flags);
324 324
325 tty->driver_data = hp; 325 tty->driver_data = hp;
326 326 tty_port_tty_set(&hp->port, tty);
327 hp->tty = tty_kref_get(tty);
328
329 spin_unlock_irqrestore(&hp->lock, flags);
330 327
331 if (hp->ops->notifier_add) 328 if (hp->ops->notifier_add)
332 rc = hp->ops->notifier_add(hp, hp->data); 329 rc = hp->ops->notifier_add(hp, hp->data);
@@ -338,12 +335,9 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
338 * tty fields and return the kref reference. 335 * tty fields and return the kref reference.
339 */ 336 */
340 if (rc) { 337 if (rc) {
341 spin_lock_irqsave(&hp->lock, flags); 338 tty_port_tty_set(&hp->port, NULL);
342 hp->tty = NULL;
343 spin_unlock_irqrestore(&hp->lock, flags);
344 tty_kref_put(tty);
345 tty->driver_data = NULL; 339 tty->driver_data = NULL;
346 kref_put(&hp->kref, destroy_hvc_struct); 340 tty_port_put(&hp->port);
347 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); 341 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
348 } 342 }
349 /* Force wakeup of the polling thread */ 343 /* Force wakeup of the polling thread */
@@ -370,12 +364,12 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
370 364
371 hp = tty->driver_data; 365 hp = tty->driver_data;
372 366
373 spin_lock_irqsave(&hp->lock, flags); 367 spin_lock_irqsave(&hp->port.lock, flags);
374 368
375 if (--hp->count == 0) { 369 if (--hp->port.count == 0) {
370 spin_unlock_irqrestore(&hp->port.lock, flags);
376 /* We are done with the tty pointer now. */ 371 /* We are done with the tty pointer now. */
377 hp->tty = NULL; 372 tty_port_tty_set(&hp->port, NULL);
378 spin_unlock_irqrestore(&hp->lock, flags);
379 373
380 if (hp->ops->notifier_del) 374 if (hp->ops->notifier_del)
381 hp->ops->notifier_del(hp, hp->data); 375 hp->ops->notifier_del(hp, hp->data);
@@ -390,14 +384,13 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
390 */ 384 */
391 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); 385 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
392 } else { 386 } else {
393 if (hp->count < 0) 387 if (hp->port.count < 0)
394 printk(KERN_ERR "hvc_close %X: oops, count is %d\n", 388 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
395 hp->vtermno, hp->count); 389 hp->vtermno, hp->port.count);
396 spin_unlock_irqrestore(&hp->lock, flags); 390 spin_unlock_irqrestore(&hp->port.lock, flags);
397 } 391 }
398 392
399 tty_kref_put(tty); 393 tty_port_put(&hp->port);
400 kref_put(&hp->kref, destroy_hvc_struct);
401} 394}
402 395
403static void hvc_hangup(struct tty_struct *tty) 396static void hvc_hangup(struct tty_struct *tty)
@@ -412,32 +405,31 @@ static void hvc_hangup(struct tty_struct *tty)
412 /* cancel pending tty resize work */ 405 /* cancel pending tty resize work */
413 cancel_work_sync(&hp->tty_resize); 406 cancel_work_sync(&hp->tty_resize);
414 407
415 spin_lock_irqsave(&hp->lock, flags); 408 spin_lock_irqsave(&hp->port.lock, flags);
416 409
417 /* 410 /*
418 * The N_TTY line discipline has problems such that in a close vs 411 * The N_TTY line discipline has problems such that in a close vs
419 * open->hangup case this can be called after the final close so prevent 412 * open->hangup case this can be called after the final close so prevent
420 * that from happening for now. 413 * that from happening for now.
421 */ 414 */
422 if (hp->count <= 0) { 415 if (hp->port.count <= 0) {
423 spin_unlock_irqrestore(&hp->lock, flags); 416 spin_unlock_irqrestore(&hp->port.lock, flags);
424 return; 417 return;
425 } 418 }
426 419
427 temp_open_count = hp->count; 420 temp_open_count = hp->port.count;
428 hp->count = 0; 421 hp->port.count = 0;
429 hp->n_outbuf = 0; 422 spin_unlock_irqrestore(&hp->port.lock, flags);
430 hp->tty = NULL; 423 tty_port_tty_set(&hp->port, NULL);
431 424
432 spin_unlock_irqrestore(&hp->lock, flags); 425 hp->n_outbuf = 0;
433 426
434 if (hp->ops->notifier_hangup) 427 if (hp->ops->notifier_hangup)
435 hp->ops->notifier_hangup(hp, hp->data); 428 hp->ops->notifier_hangup(hp, hp->data);
436 429
437 while(temp_open_count) { 430 while(temp_open_count) {
438 --temp_open_count; 431 --temp_open_count;
439 tty_kref_put(tty); 432 tty_port_put(&hp->port);
440 kref_put(&hp->kref, destroy_hvc_struct);
441 } 433 }
442} 434}
443 435
@@ -478,7 +470,8 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
478 if (!hp) 470 if (!hp)
479 return -EPIPE; 471 return -EPIPE;
480 472
481 if (hp->count <= 0) 473 /* FIXME what's this (unprotected) check for? */
474 if (hp->port.count <= 0)
482 return -EIO; 475 return -EIO;
483 476
484 spin_lock_irqsave(&hp->lock, flags); 477 spin_lock_irqsave(&hp->lock, flags);
@@ -526,13 +519,12 @@ static void hvc_set_winsz(struct work_struct *work)
526 519
527 hp = container_of(work, struct hvc_struct, tty_resize); 520 hp = container_of(work, struct hvc_struct, tty_resize);
528 521
529 spin_lock_irqsave(&hp->lock, hvc_flags); 522 tty = tty_port_tty_get(&hp->port);
530 if (!hp->tty) { 523 if (!tty)
531 spin_unlock_irqrestore(&hp->lock, hvc_flags);
532 return; 524 return;
533 } 525
534 ws = hp->ws; 526 spin_lock_irqsave(&hp->lock, hvc_flags);
535 tty = tty_kref_get(hp->tty); 527 ws = hp->ws;
536 spin_unlock_irqrestore(&hp->lock, hvc_flags); 528 spin_unlock_irqrestore(&hp->lock, hvc_flags);
537 529
538 tty_do_resize(tty, &ws); 530 tty_do_resize(tty, &ws);
@@ -601,7 +593,7 @@ int hvc_poll(struct hvc_struct *hp)
601 } 593 }
602 594
603 /* No tty attached, just skip */ 595 /* No tty attached, just skip */
604 tty = tty_kref_get(hp->tty); 596 tty = tty_port_tty_get(&hp->port);
605 if (tty == NULL) 597 if (tty == NULL)
606 goto bail; 598 goto bail;
607 599
@@ -681,8 +673,7 @@ int hvc_poll(struct hvc_struct *hp)
681 673
682 tty_flip_buffer_push(tty); 674 tty_flip_buffer_push(tty);
683 } 675 }
684 if (tty) 676 tty_kref_put(tty);
685 tty_kref_put(tty);
686 677
687 return poll_mask; 678 return poll_mask;
688} 679}
@@ -817,6 +808,10 @@ static const struct tty_operations hvc_ops = {
817#endif 808#endif
818}; 809};
819 810
811static const struct tty_port_operations hvc_port_ops = {
812 .destruct = hvc_port_destruct,
813};
814
820struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, 815struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
821 const struct hv_ops *ops, 816 const struct hv_ops *ops,
822 int outbuf_size) 817 int outbuf_size)
@@ -842,7 +837,8 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
842 hp->outbuf_size = outbuf_size; 837 hp->outbuf_size = outbuf_size;
843 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))]; 838 hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];
844 839
845 kref_init(&hp->kref); 840 tty_port_init(&hp->port);
841 hp->port.ops = &hvc_port_ops;
846 842
847 INIT_WORK(&hp->tty_resize, hvc_set_winsz); 843 INIT_WORK(&hp->tty_resize, hvc_set_winsz);
848 spin_lock_init(&hp->lock); 844 spin_lock_init(&hp->lock);
@@ -875,9 +871,9 @@ int hvc_remove(struct hvc_struct *hp)
875 unsigned long flags; 871 unsigned long flags;
876 struct tty_struct *tty; 872 struct tty_struct *tty;
877 873
878 spin_lock_irqsave(&hp->lock, flags); 874 tty = tty_port_tty_get(&hp->port);
879 tty = tty_kref_get(hp->tty);
880 875
876 spin_lock_irqsave(&hp->lock, flags);
881 if (hp->index < MAX_NR_HVC_CONSOLES) 877 if (hp->index < MAX_NR_HVC_CONSOLES)
882 vtermnos[hp->index] = -1; 878 vtermnos[hp->index] = -1;
883 879
@@ -891,7 +887,7 @@ int hvc_remove(struct hvc_struct *hp)
891 * kref cause it to be removed, which will probably be the tty_vhangup 887 * kref cause it to be removed, which will probably be the tty_vhangup
892 * below. 888 * below.
893 */ 889 */
894 kref_put(&hp->kref, destroy_hvc_struct); 890 tty_port_put(&hp->port);
895 891
896 /* 892 /*
897 * This function call will auto chain call hvc_hangup. 893 * This function call will auto chain call hvc_hangup.
diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h
index c335a1492a54..674d23cb919a 100644
--- a/drivers/tty/hvc/hvc_console.h
+++ b/drivers/tty/hvc/hvc_console.h
@@ -46,10 +46,9 @@
46#define HVC_ALLOC_TTY_ADAPTERS 8 46#define HVC_ALLOC_TTY_ADAPTERS 8
47 47
48struct hvc_struct { 48struct hvc_struct {
49 struct tty_port port;
49 spinlock_t lock; 50 spinlock_t lock;
50 int index; 51 int index;
51 struct tty_struct *tty;
52 int count;
53 int do_wakeup; 52 int do_wakeup;
54 char *outbuf; 53 char *outbuf;
55 int outbuf_size; 54 int outbuf_size;
@@ -61,7 +60,6 @@ struct hvc_struct {
61 struct winsize ws; 60 struct winsize ws;
62 struct work_struct tty_resize; 61 struct work_struct tty_resize;
63 struct list_head next; 62 struct list_head next;
64 struct kref kref; /* ref count & hvc_struct lifetime */
65}; 63};
66 64
67/* implemented by a low level driver */ 65/* implemented by a low level driver */
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 3436436fe2d7..d56788c83974 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -261,6 +261,7 @@ static DEFINE_SPINLOCK(hvcs_pi_lock);
261 261
262/* One vty-server per hvcs_struct */ 262/* One vty-server per hvcs_struct */
263struct hvcs_struct { 263struct hvcs_struct {
264 struct tty_port port;
264 spinlock_t lock; 265 spinlock_t lock;
265 266
266 /* 267 /*
@@ -269,9 +270,6 @@ struct hvcs_struct {
269 */ 270 */
270 unsigned int index; 271 unsigned int index;
271 272
272 struct tty_struct *tty;
273 int open_count;
274
275 /* 273 /*
276 * Used to tell the driver kernel_thread what operations need to take 274 * Used to tell the driver kernel_thread what operations need to take
277 * place upon this hvcs_struct instance. 275 * place upon this hvcs_struct instance.
@@ -290,12 +288,11 @@ struct hvcs_struct {
290 int chars_in_buffer; 288 int chars_in_buffer;
291 289
292 /* 290 /*
293 * Any variable below the kref is valid before a tty is connected and 291 * Any variable below is valid before a tty is connected and
294 * stays valid after the tty is disconnected. These shouldn't be 292 * stays valid after the tty is disconnected. These shouldn't be
295 * whacked until the kobject refcount reaches zero though some entries 293 * whacked until the kobject refcount reaches zero though some entries
296 * may be changed via sysfs initiatives. 294 * may be changed via sysfs initiatives.
297 */ 295 */
298 struct kref kref; /* ref count & hvcs_struct lifetime */
299 int connected; /* is the vty-server currently connected to a vty? */ 296 int connected; /* is the vty-server currently connected to a vty? */
300 uint32_t p_unit_address; /* partner unit address */ 297 uint32_t p_unit_address; /* partner unit address */
301 uint32_t p_partition_ID; /* partner partition ID */ 298 uint32_t p_partition_ID; /* partner partition ID */
@@ -304,9 +301,6 @@ struct hvcs_struct {
304 struct vio_dev *vdev; 301 struct vio_dev *vdev;
305}; 302};
306 303
307/* Required to back map a kref to its containing object */
308#define from_kref(k) container_of(k, struct hvcs_struct, kref)
309
310static LIST_HEAD(hvcs_structs); 304static LIST_HEAD(hvcs_structs);
311static DEFINE_SPINLOCK(hvcs_structs_lock); 305static DEFINE_SPINLOCK(hvcs_structs_lock);
312static DEFINE_MUTEX(hvcs_init_mutex); 306static DEFINE_MUTEX(hvcs_init_mutex);
@@ -422,7 +416,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
422 416
423 spin_lock_irqsave(&hvcsd->lock, flags); 417 spin_lock_irqsave(&hvcsd->lock, flags);
424 418
425 if (hvcsd->open_count > 0) { 419 if (hvcsd->port.count > 0) {
426 spin_unlock_irqrestore(&hvcsd->lock, flags); 420 spin_unlock_irqrestore(&hvcsd->lock, flags);
427 printk(KERN_INFO "HVCS: vterm state unchanged. " 421 printk(KERN_INFO "HVCS: vterm state unchanged. "
428 "The hvcs device node is still in use.\n"); 422 "The hvcs device node is still in use.\n");
@@ -564,7 +558,7 @@ static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance)
564static void hvcs_try_write(struct hvcs_struct *hvcsd) 558static void hvcs_try_write(struct hvcs_struct *hvcsd)
565{ 559{
566 uint32_t unit_address = hvcsd->vdev->unit_address; 560 uint32_t unit_address = hvcsd->vdev->unit_address;
567 struct tty_struct *tty = hvcsd->tty; 561 struct tty_struct *tty = hvcsd->port.tty;
568 int sent; 562 int sent;
569 563
570 if (hvcsd->todo_mask & HVCS_TRY_WRITE) { 564 if (hvcsd->todo_mask & HVCS_TRY_WRITE) {
@@ -602,7 +596,7 @@ static int hvcs_io(struct hvcs_struct *hvcsd)
602 spin_lock_irqsave(&hvcsd->lock, flags); 596 spin_lock_irqsave(&hvcsd->lock, flags);
603 597
604 unit_address = hvcsd->vdev->unit_address; 598 unit_address = hvcsd->vdev->unit_address;
605 tty = hvcsd->tty; 599 tty = hvcsd->port.tty;
606 600
607 hvcs_try_write(hvcsd); 601 hvcs_try_write(hvcsd);
608 602
@@ -701,10 +695,9 @@ static void hvcs_return_index(int index)
701 hvcs_index_list[index] = -1; 695 hvcs_index_list[index] = -1;
702} 696}
703 697
704/* callback when the kref ref count reaches zero */ 698static void hvcs_destruct_port(struct tty_port *p)
705static void destroy_hvcs_struct(struct kref *kref)
706{ 699{
707 struct hvcs_struct *hvcsd = from_kref(kref); 700 struct hvcs_struct *hvcsd = container_of(p, struct hvcs_struct, port);
708 struct vio_dev *vdev; 701 struct vio_dev *vdev;
709 unsigned long flags; 702 unsigned long flags;
710 703
@@ -741,6 +734,10 @@ static void destroy_hvcs_struct(struct kref *kref)
741 kfree(hvcsd); 734 kfree(hvcsd);
742} 735}
743 736
737static const struct tty_port_operations hvcs_port_ops = {
738 .destruct = hvcs_destruct_port,
739};
740
744static int hvcs_get_index(void) 741static int hvcs_get_index(void)
745{ 742{
746 int i; 743 int i;
@@ -789,10 +786,9 @@ static int __devinit hvcs_probe(
789 if (!hvcsd) 786 if (!hvcsd)
790 return -ENODEV; 787 return -ENODEV;
791 788
792 789 tty_port_init(&hvcsd->port);
790 hvcsd->port.ops = &hvcs_port_ops;
793 spin_lock_init(&hvcsd->lock); 791 spin_lock_init(&hvcsd->lock);
794 /* Automatically incs the refcount the first time */
795 kref_init(&hvcsd->kref);
796 792
797 hvcsd->vdev = dev; 793 hvcsd->vdev = dev;
798 dev_set_drvdata(&dev->dev, hvcsd); 794 dev_set_drvdata(&dev->dev, hvcsd);
@@ -852,7 +848,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
852 848
853 spin_lock_irqsave(&hvcsd->lock, flags); 849 spin_lock_irqsave(&hvcsd->lock, flags);
854 850
855 tty = hvcsd->tty; 851 tty = hvcsd->port.tty;
856 852
857 spin_unlock_irqrestore(&hvcsd->lock, flags); 853 spin_unlock_irqrestore(&hvcsd->lock, flags);
858 854
@@ -860,7 +856,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
860 * Let the last holder of this object cause it to be removed, which 856 * Let the last holder of this object cause it to be removed, which
861 * would probably be tty_hangup below. 857 * would probably be tty_hangup below.
862 */ 858 */
863 kref_put(&hvcsd->kref, destroy_hvcs_struct); 859 tty_port_put(&hvcsd->port);
864 860
865 /* 861 /*
866 * The hangup is a scheduled function which will auto chain call 862 * The hangup is a scheduled function which will auto chain call
@@ -1094,7 +1090,7 @@ static struct hvcs_struct *hvcs_get_by_index(int index)
1094 list_for_each_entry(hvcsd, &hvcs_structs, next) { 1090 list_for_each_entry(hvcsd, &hvcs_structs, next) {
1095 spin_lock_irqsave(&hvcsd->lock, flags); 1091 spin_lock_irqsave(&hvcsd->lock, flags);
1096 if (hvcsd->index == index) { 1092 if (hvcsd->index == index) {
1097 kref_get(&hvcsd->kref); 1093 tty_port_get(&hvcsd->port);
1098 spin_unlock_irqrestore(&hvcsd->lock, flags); 1094 spin_unlock_irqrestore(&hvcsd->lock, flags);
1099 spin_unlock(&hvcs_structs_lock); 1095 spin_unlock(&hvcs_structs_lock);
1100 return hvcsd; 1096 return hvcsd;
@@ -1138,8 +1134,8 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
1138 if ((retval = hvcs_partner_connect(hvcsd))) 1134 if ((retval = hvcs_partner_connect(hvcsd)))
1139 goto error_release; 1135 goto error_release;
1140 1136
1141 hvcsd->open_count = 1; 1137 hvcsd->port.count = 1;
1142 hvcsd->tty = tty; 1138 hvcsd->port.tty = tty;
1143 tty->driver_data = hvcsd; 1139 tty->driver_data = hvcsd;
1144 1140
1145 memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN); 1141 memset(&hvcsd->buffer[0], 0x00, HVCS_BUFF_LEN);
@@ -1160,7 +1156,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
1160 * and will grab the spinlock and free the connection if it fails. 1156 * and will grab the spinlock and free the connection if it fails.
1161 */ 1157 */
1162 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) { 1158 if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) {
1163 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1159 tty_port_put(&hvcsd->port);
1164 printk(KERN_WARNING "HVCS: enable device failed.\n"); 1160 printk(KERN_WARNING "HVCS: enable device failed.\n");
1165 return rc; 1161 return rc;
1166 } 1162 }
@@ -1171,8 +1167,8 @@ fast_open:
1171 hvcsd = tty->driver_data; 1167 hvcsd = tty->driver_data;
1172 1168
1173 spin_lock_irqsave(&hvcsd->lock, flags); 1169 spin_lock_irqsave(&hvcsd->lock, flags);
1174 kref_get(&hvcsd->kref); 1170 tty_port_get(&hvcsd->port);
1175 hvcsd->open_count++; 1171 hvcsd->port.count++;
1176 hvcsd->todo_mask |= HVCS_SCHED_READ; 1172 hvcsd->todo_mask |= HVCS_SCHED_READ;
1177 spin_unlock_irqrestore(&hvcsd->lock, flags); 1173 spin_unlock_irqrestore(&hvcsd->lock, flags);
1178 1174
@@ -1186,7 +1182,7 @@ open_success:
1186 1182
1187error_release: 1183error_release:
1188 spin_unlock_irqrestore(&hvcsd->lock, flags); 1184 spin_unlock_irqrestore(&hvcsd->lock, flags);
1189 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1185 tty_port_put(&hvcsd->port);
1190 1186
1191 printk(KERN_WARNING "HVCS: partner connect failed.\n"); 1187 printk(KERN_WARNING "HVCS: partner connect failed.\n");
1192 return retval; 1188 return retval;
@@ -1216,7 +1212,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1216 hvcsd = tty->driver_data; 1212 hvcsd = tty->driver_data;
1217 1213
1218 spin_lock_irqsave(&hvcsd->lock, flags); 1214 spin_lock_irqsave(&hvcsd->lock, flags);
1219 if (--hvcsd->open_count == 0) { 1215 if (--hvcsd->port.count == 0) {
1220 1216
1221 vio_disable_interrupts(hvcsd->vdev); 1217 vio_disable_interrupts(hvcsd->vdev);
1222 1218
@@ -1225,7 +1221,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1225 * execute any operations on the TTY even though it is obligated 1221 * execute any operations on the TTY even though it is obligated
1226 * to deliver any pending I/O to the hypervisor. 1222 * to deliver any pending I/O to the hypervisor.
1227 */ 1223 */
1228 hvcsd->tty = NULL; 1224 hvcsd->port.tty = NULL;
1229 1225
1230 irq = hvcsd->vdev->irq; 1226 irq = hvcsd->vdev->irq;
1231 spin_unlock_irqrestore(&hvcsd->lock, flags); 1227 spin_unlock_irqrestore(&hvcsd->lock, flags);
@@ -1240,16 +1236,16 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
1240 tty->driver_data = NULL; 1236 tty->driver_data = NULL;
1241 1237
1242 free_irq(irq, hvcsd); 1238 free_irq(irq, hvcsd);
1243 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1239 tty_port_put(&hvcsd->port);
1244 return; 1240 return;
1245 } else if (hvcsd->open_count < 0) { 1241 } else if (hvcsd->port.count < 0) {
1246 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d" 1242 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
1247 " is missmanaged.\n", 1243 " is missmanaged.\n",
1248 hvcsd->vdev->unit_address, hvcsd->open_count); 1244 hvcsd->vdev->unit_address, hvcsd->port.count);
1249 } 1245 }
1250 1246
1251 spin_unlock_irqrestore(&hvcsd->lock, flags); 1247 spin_unlock_irqrestore(&hvcsd->lock, flags);
1252 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1248 tty_port_put(&hvcsd->port);
1253} 1249}
1254 1250
1255static void hvcs_hangup(struct tty_struct * tty) 1251static void hvcs_hangup(struct tty_struct * tty)
@@ -1261,7 +1257,7 @@ static void hvcs_hangup(struct tty_struct * tty)
1261 1257
1262 spin_lock_irqsave(&hvcsd->lock, flags); 1258 spin_lock_irqsave(&hvcsd->lock, flags);
1263 /* Preserve this so that we know how many kref refs to put */ 1259 /* Preserve this so that we know how many kref refs to put */
1264 temp_open_count = hvcsd->open_count; 1260 temp_open_count = hvcsd->port.count;
1265 1261
1266 /* 1262 /*
1267 * Don't kref put inside the spinlock because the destruction 1263 * Don't kref put inside the spinlock because the destruction
@@ -1273,10 +1269,10 @@ static void hvcs_hangup(struct tty_struct * tty)
1273 hvcsd->todo_mask = 0; 1269 hvcsd->todo_mask = 0;
1274 1270
1275 /* I don't think the tty needs the hvcs_struct pointer after a hangup */ 1271 /* I don't think the tty needs the hvcs_struct pointer after a hangup */
1276 hvcsd->tty->driver_data = NULL; 1272 tty->driver_data = NULL;
1277 hvcsd->tty = NULL; 1273 hvcsd->port.tty = NULL;
1278 1274
1279 hvcsd->open_count = 0; 1275 hvcsd->port.count = 0;
1280 1276
1281 /* This will drop any buffered data on the floor which is OK in a hangup 1277 /* This will drop any buffered data on the floor which is OK in a hangup
1282 * scenario. */ 1278 * scenario. */
@@ -1301,7 +1297,7 @@ static void hvcs_hangup(struct tty_struct * tty)
1301 * NOTE: If this hangup was signaled from user space then the 1297 * NOTE: If this hangup was signaled from user space then the
1302 * final put will never happen. 1298 * final put will never happen.
1303 */ 1299 */
1304 kref_put(&hvcsd->kref, destroy_hvcs_struct); 1300 tty_port_put(&hvcsd->port);
1305 } 1301 }
1306} 1302}
1307 1303
@@ -1347,7 +1343,7 @@ static int hvcs_write(struct tty_struct *tty,
1347 * the middle of a write operation? This is a crummy place to do this 1343 * the middle of a write operation? This is a crummy place to do this
1348 * but we want to keep it all in the spinlock. 1344 * but we want to keep it all in the spinlock.
1349 */ 1345 */
1350 if (hvcsd->open_count <= 0) { 1346 if (hvcsd->port.count <= 0) {
1351 spin_unlock_irqrestore(&hvcsd->lock, flags); 1347 spin_unlock_irqrestore(&hvcsd->lock, flags);
1352 return -ENODEV; 1348 return -ENODEV;
1353 } 1349 }
@@ -1421,7 +1417,7 @@ static int hvcs_write_room(struct tty_struct *tty)
1421{ 1417{
1422 struct hvcs_struct *hvcsd = tty->driver_data; 1418 struct hvcs_struct *hvcsd = tty->driver_data;
1423 1419
1424 if (!hvcsd || hvcsd->open_count <= 0) 1420 if (!hvcsd || hvcsd->port.count <= 0)
1425 return 0; 1421 return 0;
1426 1422
1427 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer; 1423 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index a7488b748647..6f5bc49c441f 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -69,14 +69,13 @@
69#define __ALIGNED__ __attribute__((__aligned__(sizeof(long)))) 69#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
70 70
71struct hvsi_struct { 71struct hvsi_struct {
72 struct tty_port port;
72 struct delayed_work writer; 73 struct delayed_work writer;
73 struct work_struct handshaker; 74 struct work_struct handshaker;
74 wait_queue_head_t emptyq; /* woken when outbuf is emptied */ 75 wait_queue_head_t emptyq; /* woken when outbuf is emptied */
75 wait_queue_head_t stateq; /* woken when HVSI state changes */ 76 wait_queue_head_t stateq; /* woken when HVSI state changes */
76 spinlock_t lock; 77 spinlock_t lock;
77 int index; 78 int index;
78 struct tty_struct *tty;
79 int count;
80 uint8_t throttle_buf[128]; 79 uint8_t throttle_buf[128];
81 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */ 80 uint8_t outbuf[N_OUTBUF]; /* to implement write_room and chars_in_buffer */
82 /* inbuf is for packet reassembly. leave a little room for leftovers. */ 81 /* inbuf is for packet reassembly. leave a little room for leftovers. */
@@ -237,7 +236,7 @@ static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
237} 236}
238 237
239static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet, 238static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
240 struct tty_struct **to_hangup, struct hvsi_struct **to_handshake) 239 struct tty_struct *tty, struct hvsi_struct **to_handshake)
241{ 240{
242 struct hvsi_control *header = (struct hvsi_control *)packet; 241 struct hvsi_control *header = (struct hvsi_control *)packet;
243 242
@@ -247,9 +246,8 @@ static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
247 /* CD went away; no more connection */ 246 /* CD went away; no more connection */
248 pr_debug("hvsi%i: CD dropped\n", hp->index); 247 pr_debug("hvsi%i: CD dropped\n", hp->index);
249 hp->mctrl &= TIOCM_CD; 248 hp->mctrl &= TIOCM_CD;
250 /* If userland hasn't done an open(2) yet, hp->tty is NULL. */ 249 if (tty && !C_CLOCAL(tty))
251 if (hp->tty && !(hp->tty->flags & CLOCAL)) 250 tty_hangup(tty);
252 *to_hangup = hp->tty;
253 } 251 }
254 break; 252 break;
255 case VSV_CLOSE_PROTOCOL: 253 case VSV_CLOSE_PROTOCOL:
@@ -331,7 +329,8 @@ static void hvsi_recv_query(struct hvsi_struct *hp, uint8_t *packet)
331 } 329 }
332} 330}
333 331
334static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len) 332static void hvsi_insert_chars(struct hvsi_struct *hp, struct tty_struct *tty,
333 const char *buf, int len)
335{ 334{
336 int i; 335 int i;
337 336
@@ -347,7 +346,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
347 continue; 346 continue;
348 } 347 }
349#endif /* CONFIG_MAGIC_SYSRQ */ 348#endif /* CONFIG_MAGIC_SYSRQ */
350 tty_insert_flip_char(hp->tty, c, 0); 349 tty_insert_flip_char(tty, c, 0);
351 } 350 }
352} 351}
353 352
@@ -360,7 +359,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len)
360 * revisited. 359 * revisited.
361 */ 360 */
362#define TTY_THRESHOLD_THROTTLE 128 361#define TTY_THRESHOLD_THROTTLE 128
363static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp, 362static bool hvsi_recv_data(struct hvsi_struct *hp, struct tty_struct *tty,
364 const uint8_t *packet) 363 const uint8_t *packet)
365{ 364{
366 const struct hvsi_header *header = (const struct hvsi_header *)packet; 365 const struct hvsi_header *header = (const struct hvsi_header *)packet;
@@ -371,14 +370,14 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
371 pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data); 370 pr_debug("queueing %i chars '%.*s'\n", datalen, datalen, data);
372 371
373 if (datalen == 0) 372 if (datalen == 0)
374 return NULL; 373 return false;
375 374
376 if (overflow > 0) { 375 if (overflow > 0) {
377 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__); 376 pr_debug("%s: got >TTY_THRESHOLD_THROTTLE bytes\n", __func__);
378 datalen = TTY_THRESHOLD_THROTTLE; 377 datalen = TTY_THRESHOLD_THROTTLE;
379 } 378 }
380 379
381 hvsi_insert_chars(hp, data, datalen); 380 hvsi_insert_chars(hp, tty, data, datalen);
382 381
383 if (overflow > 0) { 382 if (overflow > 0) {
384 /* 383 /*
@@ -390,7 +389,7 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
390 hp->n_throttle = overflow; 389 hp->n_throttle = overflow;
391 } 390 }
392 391
393 return hp->tty; 392 return true;
394} 393}
395 394
396/* 395/*
@@ -399,14 +398,13 @@ static struct tty_struct *hvsi_recv_data(struct hvsi_struct *hp,
399 * machine during console handshaking (in which case tty = NULL and we ignore 398 * machine during console handshaking (in which case tty = NULL and we ignore
400 * incoming data). 399 * incoming data).
401 */ 400 */
402static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip, 401static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct *tty,
403 struct tty_struct **hangup, struct hvsi_struct **handshake) 402 struct hvsi_struct **handshake)
404{ 403{
405 uint8_t *packet = hp->inbuf; 404 uint8_t *packet = hp->inbuf;
406 int chunklen; 405 int chunklen;
406 bool flip = false;
407 407
408 *flip = NULL;
409 *hangup = NULL;
410 *handshake = NULL; 408 *handshake = NULL;
411 409
412 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ); 410 chunklen = hvsi_read(hp, hp->inbuf_end, HVSI_MAX_READ);
@@ -440,12 +438,12 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
440 case VS_DATA_PACKET_HEADER: 438 case VS_DATA_PACKET_HEADER:
441 if (!is_open(hp)) 439 if (!is_open(hp))
442 break; 440 break;
443 if (hp->tty == NULL) 441 if (tty == NULL)
444 break; /* no tty buffer to put data in */ 442 break; /* no tty buffer to put data in */
445 *flip = hvsi_recv_data(hp, packet); 443 flip = hvsi_recv_data(hp, tty, packet);
446 break; 444 break;
447 case VS_CONTROL_PACKET_HEADER: 445 case VS_CONTROL_PACKET_HEADER:
448 hvsi_recv_control(hp, packet, hangup, handshake); 446 hvsi_recv_control(hp, packet, tty, handshake);
449 break; 447 break;
450 case VS_QUERY_RESPONSE_PACKET_HEADER: 448 case VS_QUERY_RESPONSE_PACKET_HEADER:
451 hvsi_recv_response(hp, packet); 449 hvsi_recv_response(hp, packet);
@@ -462,28 +460,26 @@ static int hvsi_load_chunk(struct hvsi_struct *hp, struct tty_struct **flip,
462 460
463 packet += len_packet(packet); 461 packet += len_packet(packet);
464 462
465 if (*hangup || *handshake) { 463 if (*handshake) {
466 pr_debug("%s: hangup or handshake\n", __func__); 464 pr_debug("%s: handshake\n", __func__);
467 /*
468 * we need to send the hangup now before receiving any more data.
469 * If we get "data, hangup, data", we can't deliver the second
470 * data before the hangup.
471 */
472 break; 465 break;
473 } 466 }
474 } 467 }
475 468
476 compact_inbuf(hp, packet); 469 compact_inbuf(hp, packet);
477 470
471 if (flip)
472 tty_flip_buffer_push(tty);
473
478 return 1; 474 return 1;
479} 475}
480 476
481static void hvsi_send_overflow(struct hvsi_struct *hp) 477static void hvsi_send_overflow(struct hvsi_struct *hp, struct tty_struct *tty)
482{ 478{
483 pr_debug("%s: delivering %i bytes overflow\n", __func__, 479 pr_debug("%s: delivering %i bytes overflow\n", __func__,
484 hp->n_throttle); 480 hp->n_throttle);
485 481
486 hvsi_insert_chars(hp, hp->throttle_buf, hp->n_throttle); 482 hvsi_insert_chars(hp, tty, hp->throttle_buf, hp->n_throttle);
487 hp->n_throttle = 0; 483 hp->n_throttle = 0;
488} 484}
489 485
@@ -494,35 +490,20 @@ static void hvsi_send_overflow(struct hvsi_struct *hp)
494static irqreturn_t hvsi_interrupt(int irq, void *arg) 490static irqreturn_t hvsi_interrupt(int irq, void *arg)
495{ 491{
496 struct hvsi_struct *hp = (struct hvsi_struct *)arg; 492 struct hvsi_struct *hp = (struct hvsi_struct *)arg;
497 struct tty_struct *flip;
498 struct tty_struct *hangup;
499 struct hvsi_struct *handshake; 493 struct hvsi_struct *handshake;
494 struct tty_struct *tty;
500 unsigned long flags; 495 unsigned long flags;
501 int again = 1; 496 int again = 1;
502 497
503 pr_debug("%s\n", __func__); 498 pr_debug("%s\n", __func__);
504 499
500 tty = tty_port_tty_get(&hp->port);
501
505 while (again) { 502 while (again) {
506 spin_lock_irqsave(&hp->lock, flags); 503 spin_lock_irqsave(&hp->lock, flags);
507 again = hvsi_load_chunk(hp, &flip, &hangup, &handshake); 504 again = hvsi_load_chunk(hp, tty, &handshake);
508 spin_unlock_irqrestore(&hp->lock, flags); 505 spin_unlock_irqrestore(&hp->lock, flags);
509 506
510 /*
511 * we have to call tty_flip_buffer_push() and tty_hangup() outside our
512 * spinlock. But we also have to keep going until we've read all the
513 * available data.
514 */
515
516 if (flip) {
517 /* there was data put in the tty flip buffer */
518 tty_flip_buffer_push(flip);
519 flip = NULL;
520 }
521
522 if (hangup) {
523 tty_hangup(hangup);
524 }
525
526 if (handshake) { 507 if (handshake) {
527 pr_debug("hvsi%i: attempting re-handshake\n", handshake->index); 508 pr_debug("hvsi%i: attempting re-handshake\n", handshake->index);
528 schedule_work(&handshake->handshaker); 509 schedule_work(&handshake->handshaker);
@@ -530,18 +511,15 @@ static irqreturn_t hvsi_interrupt(int irq, void *arg)
530 } 511 }
531 512
532 spin_lock_irqsave(&hp->lock, flags); 513 spin_lock_irqsave(&hp->lock, flags);
533 if (hp->tty && hp->n_throttle 514 if (tty && hp->n_throttle && !test_bit(TTY_THROTTLED, &tty->flags)) {
534 && (!test_bit(TTY_THROTTLED, &hp->tty->flags))) { 515 /* we weren't hung up and we weren't throttled, so we can
535 /* we weren't hung up and we weren't throttled, so we can deliver the 516 * deliver the rest now */
536 * rest now */ 517 hvsi_send_overflow(hp, tty);
537 flip = hp->tty; 518 tty_flip_buffer_push(tty);
538 hvsi_send_overflow(hp);
539 } 519 }
540 spin_unlock_irqrestore(&hp->lock, flags); 520 spin_unlock_irqrestore(&hp->lock, flags);
541 521
542 if (flip) { 522 tty_kref_put(tty);
543 tty_flip_buffer_push(flip);
544 }
545 523
546 return IRQ_HANDLED; 524 return IRQ_HANDLED;
547} 525}
@@ -749,9 +727,9 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
749 if (hp->state == HVSI_FSP_DIED) 727 if (hp->state == HVSI_FSP_DIED)
750 return -EIO; 728 return -EIO;
751 729
730 tty_port_tty_set(&hp->port, tty);
752 spin_lock_irqsave(&hp->lock, flags); 731 spin_lock_irqsave(&hp->lock, flags);
753 hp->tty = tty; 732 hp->port.count++;
754 hp->count++;
755 atomic_set(&hp->seqno, 0); 733 atomic_set(&hp->seqno, 0);
756 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); 734 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
757 spin_unlock_irqrestore(&hp->lock, flags); 735 spin_unlock_irqrestore(&hp->lock, flags);
@@ -808,8 +786,8 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
808 786
809 spin_lock_irqsave(&hp->lock, flags); 787 spin_lock_irqsave(&hp->lock, flags);
810 788
811 if (--hp->count == 0) { 789 if (--hp->port.count == 0) {
812 hp->tty = NULL; 790 tty_port_tty_set(&hp->port, NULL);
813 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */ 791 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
814 792
815 /* only close down connection if it is not the console */ 793 /* only close down connection if it is not the console */
@@ -841,9 +819,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
841 819
842 spin_lock_irqsave(&hp->lock, flags); 820 spin_lock_irqsave(&hp->lock, flags);
843 } 821 }
844 } else if (hp->count < 0) 822 } else if (hp->port.count < 0)
845 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n", 823 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
846 hp - hvsi_ports, hp->count); 824 hp - hvsi_ports, hp->port.count);
847 825
848 spin_unlock_irqrestore(&hp->lock, flags); 826 spin_unlock_irqrestore(&hp->lock, flags);
849} 827}
@@ -855,12 +833,11 @@ static void hvsi_hangup(struct tty_struct *tty)
855 833
856 pr_debug("%s\n", __func__); 834 pr_debug("%s\n", __func__);
857 835
858 spin_lock_irqsave(&hp->lock, flags); 836 tty_port_tty_set(&hp->port, NULL);
859 837
860 hp->count = 0; 838 spin_lock_irqsave(&hp->lock, flags);
839 hp->port.count = 0;
861 hp->n_outbuf = 0; 840 hp->n_outbuf = 0;
862 hp->tty = NULL;
863
864 spin_unlock_irqrestore(&hp->lock, flags); 841 spin_unlock_irqrestore(&hp->lock, flags);
865} 842}
866 843
@@ -888,6 +865,7 @@ static void hvsi_write_worker(struct work_struct *work)
888{ 865{
889 struct hvsi_struct *hp = 866 struct hvsi_struct *hp =
890 container_of(work, struct hvsi_struct, writer.work); 867 container_of(work, struct hvsi_struct, writer.work);
868 struct tty_struct *tty;
891 unsigned long flags; 869 unsigned long flags;
892#ifdef DEBUG 870#ifdef DEBUG
893 static long start_j = 0; 871 static long start_j = 0;
@@ -921,7 +899,11 @@ static void hvsi_write_worker(struct work_struct *work)
921 start_j = 0; 899 start_j = 0;
922#endif /* DEBUG */ 900#endif /* DEBUG */
923 wake_up_all(&hp->emptyq); 901 wake_up_all(&hp->emptyq);
924 tty_wakeup(hp->tty); 902 tty = tty_port_tty_get(&hp->port);
903 if (tty) {
904 tty_wakeup(tty);
905 tty_kref_put(tty);
906 }
925 } 907 }
926 908
927out: 909out:
@@ -966,8 +948,8 @@ static int hvsi_write(struct tty_struct *tty,
966 * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls 948 * and hvsi_write_worker will be scheduled. subsequent hvsi_write() calls
967 * will see there is no room in outbuf and return. 949 * will see there is no room in outbuf and return.
968 */ 950 */
969 while ((count > 0) && (hvsi_write_room(hp->tty) > 0)) { 951 while ((count > 0) && (hvsi_write_room(tty) > 0)) {
970 int chunksize = min(count, hvsi_write_room(hp->tty)); 952 int chunksize = min(count, hvsi_write_room(tty));
971 953
972 BUG_ON(hp->n_outbuf < 0); 954 BUG_ON(hp->n_outbuf < 0);
973 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize); 955 memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
@@ -1014,19 +996,16 @@ static void hvsi_unthrottle(struct tty_struct *tty)
1014{ 996{
1015 struct hvsi_struct *hp = tty->driver_data; 997 struct hvsi_struct *hp = tty->driver_data;
1016 unsigned long flags; 998 unsigned long flags;
1017 int shouldflip = 0;
1018 999
1019 pr_debug("%s\n", __func__); 1000 pr_debug("%s\n", __func__);
1020 1001
1021 spin_lock_irqsave(&hp->lock, flags); 1002 spin_lock_irqsave(&hp->lock, flags);
1022 if (hp->n_throttle) { 1003 if (hp->n_throttle) {
1023 hvsi_send_overflow(hp); 1004 hvsi_send_overflow(hp, tty);
1024 shouldflip = 1; 1005 tty_flip_buffer_push(tty);
1025 } 1006 }
1026 spin_unlock_irqrestore(&hp->lock, flags); 1007 spin_unlock_irqrestore(&hp->lock, flags);
1027 1008
1028 if (shouldflip)
1029 tty_flip_buffer_push(hp->tty);
1030 1009
1031 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE); 1010 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
1032} 1011}
@@ -1228,6 +1207,7 @@ static int __init hvsi_console_init(void)
1228 init_waitqueue_head(&hp->emptyq); 1207 init_waitqueue_head(&hp->emptyq);
1229 init_waitqueue_head(&hp->stateq); 1208 init_waitqueue_head(&hp->stateq);
1230 spin_lock_init(&hp->lock); 1209 spin_lock_init(&hp->lock);
1210 tty_port_init(&hp->port);
1231 hp->index = hvsi_count; 1211 hp->index = hvsi_count;
1232 hp->inbuf_end = hp->inbuf; 1212 hp->inbuf_end = hp->inbuf;
1233 hp->state = HVSI_CLOSED; 1213 hp->state = HVSI_CLOSED;
diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
index 6f4dd83d8695..59c135dd5d20 100644
--- a/drivers/tty/hvc/hvsi_lib.c
+++ b/drivers/tty/hvc/hvsi_lib.c
@@ -377,7 +377,7 @@ int hvsilib_open(struct hvsi_priv *pv, struct hvc_struct *hp)
377 pr_devel("HVSI@%x: open !\n", pv->termno); 377 pr_devel("HVSI@%x: open !\n", pv->termno);
378 378
379 /* Keep track of the tty data structure */ 379 /* Keep track of the tty data structure */
380 pv->tty = tty_kref_get(hp->tty); 380 pv->tty = tty_port_tty_get(&hp->port);
381 381
382 hvsilib_establish(pv); 382 hvsilib_establish(pv);
383 383
diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
index 4daf962f7055..f8b5fa0093a3 100644
--- a/drivers/tty/ipwireless/tty.c
+++ b/drivers/tty/ipwireless/tty.c
@@ -44,14 +44,13 @@
44#define TTYTYPE_RAS_RAW (2) 44#define TTYTYPE_RAS_RAW (2)
45 45
46struct ipw_tty { 46struct ipw_tty {
47 struct tty_port port;
47 int index; 48 int index;
48 struct ipw_hardware *hardware; 49 struct ipw_hardware *hardware;
49 unsigned int channel_idx; 50 unsigned int channel_idx;
50 unsigned int secondary_channel_idx; 51 unsigned int secondary_channel_idx;
51 int tty_type; 52 int tty_type;
52 struct ipw_network *network; 53 struct ipw_network *network;
53 struct tty_struct *linux_tty;
54 int open_count;
55 unsigned int control_lines; 54 unsigned int control_lines;
56 struct mutex ipw_tty_mutex; 55 struct mutex ipw_tty_mutex;
57 int tx_bytes_queued; 56 int tx_bytes_queued;
@@ -73,23 +72,6 @@ static char *tty_type_name(int tty_type)
73 return channel_names[tty_type]; 72 return channel_names[tty_type];
74} 73}
75 74
76static void report_registering(struct ipw_tty *tty)
77{
78 char *iftype = tty_type_name(tty->tty_type);
79
80 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
81 ": registering %s device ttyIPWp%d\n", iftype, tty->index);
82}
83
84static void report_deregistering(struct ipw_tty *tty)
85{
86 char *iftype = tty_type_name(tty->tty_type);
87
88 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
89 ": deregistering %s device ttyIPWp%d\n", iftype,
90 tty->index);
91}
92
93static struct ipw_tty *get_tty(int index) 75static struct ipw_tty *get_tty(int index)
94{ 76{
95 /* 77 /*
@@ -117,12 +99,12 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
117 mutex_unlock(&tty->ipw_tty_mutex); 99 mutex_unlock(&tty->ipw_tty_mutex);
118 return -ENODEV; 100 return -ENODEV;
119 } 101 }
120 if (tty->open_count == 0) 102 if (tty->port.count == 0)
121 tty->tx_bytes_queued = 0; 103 tty->tx_bytes_queued = 0;
122 104
123 tty->open_count++; 105 tty->port.count++;
124 106
125 tty->linux_tty = linux_tty; 107 tty->port.tty = linux_tty;
126 linux_tty->driver_data = tty; 108 linux_tty->driver_data = tty;
127 linux_tty->low_latency = 1; 109 linux_tty->low_latency = 1;
128 110
@@ -136,13 +118,13 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
136 118
137static void do_ipw_close(struct ipw_tty *tty) 119static void do_ipw_close(struct ipw_tty *tty)
138{ 120{
139 tty->open_count--; 121 tty->port.count--;
140 122
141 if (tty->open_count == 0) { 123 if (tty->port.count == 0) {
142 struct tty_struct *linux_tty = tty->linux_tty; 124 struct tty_struct *linux_tty = tty->port.tty;
143 125
144 if (linux_tty != NULL) { 126 if (linux_tty != NULL) {
145 tty->linux_tty = NULL; 127 tty->port.tty = NULL;
146 linux_tty->driver_data = NULL; 128 linux_tty->driver_data = NULL;
147 129
148 if (tty->tty_type == TTYTYPE_MODEM) 130 if (tty->tty_type == TTYTYPE_MODEM)
@@ -159,7 +141,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
159 return; 141 return;
160 142
161 mutex_lock(&tty->ipw_tty_mutex); 143 mutex_lock(&tty->ipw_tty_mutex);
162 if (tty->open_count == 0) { 144 if (tty->port.count == 0) {
163 mutex_unlock(&tty->ipw_tty_mutex); 145 mutex_unlock(&tty->ipw_tty_mutex);
164 return; 146 return;
165 } 147 }
@@ -182,13 +164,13 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
182 int work = 0; 164 int work = 0;
183 165
184 mutex_lock(&tty->ipw_tty_mutex); 166 mutex_lock(&tty->ipw_tty_mutex);
185 linux_tty = tty->linux_tty; 167 linux_tty = tty->port.tty;
186 if (linux_tty == NULL) { 168 if (linux_tty == NULL) {
187 mutex_unlock(&tty->ipw_tty_mutex); 169 mutex_unlock(&tty->ipw_tty_mutex);
188 return; 170 return;
189 } 171 }
190 172
191 if (!tty->open_count) { 173 if (!tty->port.count) {
192 mutex_unlock(&tty->ipw_tty_mutex); 174 mutex_unlock(&tty->ipw_tty_mutex);
193 return; 175 return;
194 } 176 }
@@ -230,7 +212,7 @@ static int ipw_write(struct tty_struct *linux_tty,
230 return -ENODEV; 212 return -ENODEV;
231 213
232 mutex_lock(&tty->ipw_tty_mutex); 214 mutex_lock(&tty->ipw_tty_mutex);
233 if (!tty->open_count) { 215 if (!tty->port.count) {
234 mutex_unlock(&tty->ipw_tty_mutex); 216 mutex_unlock(&tty->ipw_tty_mutex);
235 return -EINVAL; 217 return -EINVAL;
236 } 218 }
@@ -270,7 +252,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
270 if (!tty) 252 if (!tty)
271 return -ENODEV; 253 return -ENODEV;
272 254
273 if (!tty->open_count) 255 if (!tty->port.count)
274 return -EINVAL; 256 return -EINVAL;
275 257
276 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued; 258 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
@@ -312,7 +294,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
312 if (!tty) 294 if (!tty)
313 return 0; 295 return 0;
314 296
315 if (!tty->open_count) 297 if (!tty->port.count)
316 return 0; 298 return 0;
317 299
318 return tty->tx_bytes_queued; 300 return tty->tx_bytes_queued;
@@ -393,7 +375,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
393 if (!tty) 375 if (!tty)
394 return -ENODEV; 376 return -ENODEV;
395 377
396 if (!tty->open_count) 378 if (!tty->port.count)
397 return -EINVAL; 379 return -EINVAL;
398 380
399 return get_control_lines(tty); 381 return get_control_lines(tty);
@@ -409,7 +391,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
409 if (!tty) 391 if (!tty)
410 return -ENODEV; 392 return -ENODEV;
411 393
412 if (!tty->open_count) 394 if (!tty->port.count)
413 return -EINVAL; 395 return -EINVAL;
414 396
415 return set_control_lines(tty, set, clear); 397 return set_control_lines(tty, set, clear);
@@ -423,7 +405,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
423 if (!tty) 405 if (!tty)
424 return -ENODEV; 406 return -ENODEV;
425 407
426 if (!tty->open_count) 408 if (!tty->port.count)
427 return -EINVAL; 409 return -EINVAL;
428 410
429 /* FIXME: Exactly how is the tty object locked here .. */ 411 /* FIXME: Exactly how is the tty object locked here .. */
@@ -492,6 +474,7 @@ static int add_tty(int j,
492 ttys[j]->network = network; 474 ttys[j]->network = network;
493 ttys[j]->tty_type = tty_type; 475 ttys[j]->tty_type = tty_type;
494 mutex_init(&ttys[j]->ipw_tty_mutex); 476 mutex_init(&ttys[j]->ipw_tty_mutex);
477 tty_port_init(&ttys[j]->port);
495 478
496 tty_register_device(ipw_tty_driver, j, NULL); 479 tty_register_device(ipw_tty_driver, j, NULL);
497 ipwireless_associate_network_tty(network, channel_idx, ttys[j]); 480 ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
@@ -500,8 +483,12 @@ static int add_tty(int j,
500 ipwireless_associate_network_tty(network, 483 ipwireless_associate_network_tty(network,
501 secondary_channel_idx, 484 secondary_channel_idx,
502 ttys[j]); 485 ttys[j]);
503 if (get_tty(j) == ttys[j]) 486 /* check if we provide raw device (if loopback is enabled) */
504 report_registering(ttys[j]); 487 if (get_tty(j))
488 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
489 ": registering %s device ttyIPWp%d\n",
490 tty_type_name(tty_type), j);
491
505 return 0; 492 return 0;
506} 493}
507 494
@@ -560,19 +547,21 @@ void ipwireless_tty_free(struct ipw_tty *tty)
560 547
561 if (ttyj) { 548 if (ttyj) {
562 mutex_lock(&ttyj->ipw_tty_mutex); 549 mutex_lock(&ttyj->ipw_tty_mutex);
563 if (get_tty(j) == ttyj) 550 if (get_tty(j))
564 report_deregistering(ttyj); 551 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
552 ": deregistering %s device ttyIPWp%d\n",
553 tty_type_name(ttyj->tty_type), j);
565 ttyj->closing = 1; 554 ttyj->closing = 1;
566 if (ttyj->linux_tty != NULL) { 555 if (ttyj->port.tty != NULL) {
567 mutex_unlock(&ttyj->ipw_tty_mutex); 556 mutex_unlock(&ttyj->ipw_tty_mutex);
568 tty_hangup(ttyj->linux_tty); 557 tty_vhangup(ttyj->port.tty);
569 /* Wait till the tty_hangup has completed */
570 flush_work_sync(&ttyj->linux_tty->hangup_work);
571 /* FIXME: Exactly how is the tty object locked here 558 /* FIXME: Exactly how is the tty object locked here
572 against a parallel ioctl etc */ 559 against a parallel ioctl etc */
560 /* FIXME2: hangup does not mean all processes
561 * are gone */
573 mutex_lock(&ttyj->ipw_tty_mutex); 562 mutex_lock(&ttyj->ipw_tty_mutex);
574 } 563 }
575 while (ttyj->open_count) 564 while (ttyj->port.count)
576 do_ipw_close(ttyj); 565 do_ipw_close(ttyj);
577 ipwireless_disassociate_network_ttys(network, 566 ipwireless_disassociate_network_ttys(network,
578 ttyj->channel_idx); 567 ttyj->channel_idx);
@@ -661,8 +650,8 @@ ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
661 */ 650 */
662 if ((old_control_lines & IPW_CONTROL_LINE_DCD) 651 if ((old_control_lines & IPW_CONTROL_LINE_DCD)
663 && !(tty->control_lines & IPW_CONTROL_LINE_DCD) 652 && !(tty->control_lines & IPW_CONTROL_LINE_DCD)
664 && tty->linux_tty) { 653 && tty->port.tty) {
665 tty_hangup(tty->linux_tty); 654 tty_hangup(tty->port.tty);
666 } 655 }
667} 656}
668 657
diff --git a/drivers/tty/serial/68328serial.c b/drivers/tty/serial/68328serial.c
index 5ce782529d65..3ed20e435e59 100644
--- a/drivers/tty/serial/68328serial.c
+++ b/drivers/tty/serial/68328serial.c
@@ -17,6 +17,7 @@
17#include <asm/dbg.h> 17#include <asm/dbg.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/serial.h>
20#include <linux/signal.h> 21#include <linux/signal.h>
21#include <linux/sched.h> 22#include <linux/sched.h>
22#include <linux/timer.h> 23#include <linux/timer.h>
@@ -56,8 +57,6 @@
56#endif /* CONFIG_M68VZ328 */ 57#endif /* CONFIG_M68VZ328 */
57#endif /* CONFIG_M68EZ328 */ 58#endif /* CONFIG_M68EZ328 */
58 59
59#include "68328serial.h"
60
61/* Turn off usage of real serial interrupt code, to "support" Copilot */ 60/* Turn off usage of real serial interrupt code, to "support" Copilot */
62#ifdef CONFIG_XCOPILOT_BUGS 61#ifdef CONFIG_XCOPILOT_BUGS
63#undef USE_INTS 62#undef USE_INTS
@@ -65,33 +64,82 @@
65#define USE_INTS 64#define USE_INTS
66#endif 65#endif
67 66
68static struct m68k_serial m68k_soft[NR_PORTS]; 67/*
68 * I believe this is the optimal setting that reduces the number of interrupts.
69 * At high speeds the output might become a little "bursted" (use USTCNT_TXHE
70 * if that bothers you), but in most cases it will not, since we try to
71 * transmit characters every time rs_interrupt is called. Thus, quite often
72 * you'll see that a receive interrupt occures before the transmit one.
73 * -- Vladimir Gurevich
74 */
75#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
69 76
70static unsigned int uart_irqs[NR_PORTS] = UART_IRQ_DEFNS; 77/*
78 * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special
79 * "Old data interrupt" which occures whenever the data stay in the FIFO
80 * longer than 30 bits time. This allows us to use FIFO without compromising
81 * latency. '328 does not have this feature and without the real 328-based
82 * board I would assume that RXRE is the safest setting.
83 *
84 * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of
85 * interrupts. RXFE (receive queue full) causes the system to lose data
86 * at least at 115200 baud
87 *
88 * If your board is busy doing other stuff, you might consider to use
89 * RXRE (data ready intrrupt) instead.
90 *
91 * The other option is to make these INTR masks run-time configurable, so
92 * that people can dynamically adapt them according to the current usage.
93 * -- Vladimir Gurevich
94 */
71 95
72/* multiple ports are contiguous in memory */ 96/* (es) */
73m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR; 97#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
98#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
99#elif defined(CONFIG_M68328)
100#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
101#else
102#error Please, define the Rx interrupt events for your CPU
103#endif
104/* (/es) */
74 105
75struct tty_struct m68k_ttys; 106/*
76struct m68k_serial *m68k_consinfo = 0; 107 * This is our internal structure for each serial port's state.
108 */
109struct m68k_serial {
110 struct tty_port tport;
111 char is_cons; /* Is this our console. */
112 int magic;
113 int baud_base;
114 int port;
115 int irq;
116 int type; /* UART type */
117 int custom_divisor;
118 int x_char; /* xon/xoff character */
119 int line;
120 unsigned char *xmit_buf;
121 int xmit_head;
122 int xmit_tail;
123 int xmit_cnt;
124};
77 125
78#define M68K_CLOCK (16667000) /* FIXME: 16MHz is likely wrong */ 126#define SERIAL_MAGIC 0x5301
79 127
80struct tty_driver *serial_driver; 128/*
129 * Define the number of ports supported and their irqs.
130 */
131#define NR_PORTS 1
81 132
82/* number of characters left in xmit buffer before we ask for more */ 133static struct m68k_serial m68k_soft[NR_PORTS];
83#define WAKEUP_CHARS 256
84 134
85/* Debugging... DEBUG_INTR is bad to use when one of the zs 135static unsigned int uart_irqs[NR_PORTS] = { UART_IRQ_NUM };
86 * lines is your console ;(
87 */
88#undef SERIAL_DEBUG_INTR
89#undef SERIAL_DEBUG_OPEN
90#undef SERIAL_DEBUG_FLOW
91 136
92#define RS_ISR_PASS_LIMIT 256 137/* multiple ports are contiguous in memory */
138m68328_uart *uart_addr = (m68328_uart *)USTCNT_ADDR;
139
140struct tty_driver *serial_driver;
93 141
94static void change_speed(struct m68k_serial *info); 142static void change_speed(struct m68k_serial *info, struct tty_struct *tty);
95 143
96/* 144/*
97 * Setup for console. Argument comes from the boot command line. 145 * Setup for console. Argument comes from the boot command line.
@@ -143,17 +191,6 @@ static int baud_table[] = {
143 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 191 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
144 9600, 19200, 38400, 57600, 115200, 0 }; 192 9600, 19200, 38400, 57600, 115200, 0 };
145 193
146/* Sets or clears DTR/RTS on the requested line */
147static inline void m68k_rtsdtr(struct m68k_serial *ss, int set)
148{
149 if (set) {
150 /* set the RTS/CTS line */
151 } else {
152 /* clear it */
153 }
154 return;
155}
156
157/* Utility routines */ 194/* Utility routines */
158static inline int get_baud(struct m68k_serial *ss) 195static inline int get_baud(struct m68k_serial *ss)
159{ 196{
@@ -189,7 +226,8 @@ static void rs_stop(struct tty_struct *tty)
189 226
190static int rs_put_char(char ch) 227static int rs_put_char(char ch)
191{ 228{
192 int flags, loops = 0; 229 unsigned long flags;
230 int loops = 0;
193 231
194 local_irq_save(flags); 232 local_irq_save(flags);
195 233
@@ -224,28 +262,9 @@ static void rs_start(struct tty_struct *tty)
224 local_irq_restore(flags); 262 local_irq_restore(flags);
225} 263}
226 264
227/* Drop into either the boot monitor or kadb upon receiving a break 265static void receive_chars(struct m68k_serial *info, struct tty_struct *tty,
228 * from keyboard/console input. 266 unsigned short rx)
229 */
230static void batten_down_hatches(void)
231{
232 /* Drop into the debugger */
233}
234
235static void status_handle(struct m68k_serial *info, unsigned short status)
236{ 267{
237 /* If this is console input and this is a
238 * 'break asserted' status change interrupt
239 * see if we can drop into the debugger
240 */
241 if((status & URX_BREAK) && info->break_abort)
242 batten_down_hatches();
243 return;
244}
245
246static void receive_chars(struct m68k_serial *info, unsigned short rx)
247{
248 struct tty_struct *tty = info->tty;
249 m68328_uart *uart = &uart_addr[info->line]; 268 m68328_uart *uart = &uart_addr[info->line];
250 unsigned char ch, flag; 269 unsigned char ch, flag;
251 270
@@ -259,7 +278,6 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx)
259 278
260 if(info->is_cons) { 279 if(info->is_cons) {
261 if(URX_BREAK & rx) { /* whee, break received */ 280 if(URX_BREAK & rx) { /* whee, break received */
262 status_handle(info, rx);
263 return; 281 return;
264#ifdef CONFIG_MAGIC_SYSRQ 282#ifdef CONFIG_MAGIC_SYSRQ
265 } else if (ch == 0x10) { /* ^P */ 283 } else if (ch == 0x10) { /* ^P */
@@ -280,16 +298,13 @@ static void receive_chars(struct m68k_serial *info, unsigned short rx)
280 298
281 flag = TTY_NORMAL; 299 flag = TTY_NORMAL;
282 300
283 if(rx & URX_PARITY_ERROR) { 301 if (rx & URX_PARITY_ERROR)
284 flag = TTY_PARITY; 302 flag = TTY_PARITY;
285 status_handle(info, rx); 303 else if (rx & URX_OVRUN)
286 } else if(rx & URX_OVRUN) {
287 flag = TTY_OVERRUN; 304 flag = TTY_OVERRUN;
288 status_handle(info, rx); 305 else if (rx & URX_FRAME_ERROR)
289 } else if(rx & URX_FRAME_ERROR) {
290 flag = TTY_FRAME; 306 flag = TTY_FRAME;
291 status_handle(info, rx); 307
292 }
293 tty_insert_flip_char(tty, ch, flag); 308 tty_insert_flip_char(tty, ch, flag);
294#ifndef CONFIG_XCOPILOT_BUGS 309#ifndef CONFIG_XCOPILOT_BUGS
295 } while((rx = uart->urx.w) & URX_DATA_READY); 310 } while((rx = uart->urx.w) & URX_DATA_READY);
@@ -301,7 +316,7 @@ clear_and_exit:
301 return; 316 return;
302} 317}
303 318
304static void transmit_chars(struct m68k_serial *info) 319static void transmit_chars(struct m68k_serial *info, struct tty_struct *tty)
305{ 320{
306 m68328_uart *uart = &uart_addr[info->line]; 321 m68328_uart *uart = &uart_addr[info->line];
307 322
@@ -312,7 +327,7 @@ static void transmit_chars(struct m68k_serial *info)
312 goto clear_and_return; 327 goto clear_and_return;
313 } 328 }
314 329
315 if((info->xmit_cnt <= 0) || info->tty->stopped) { 330 if ((info->xmit_cnt <= 0) || !tty || tty->stopped) {
316 /* That's peculiar... TX ints off */ 331 /* That's peculiar... TX ints off */
317 uart->ustcnt &= ~USTCNT_TX_INTR_MASK; 332 uart->ustcnt &= ~USTCNT_TX_INTR_MASK;
318 goto clear_and_return; 333 goto clear_and_return;
@@ -340,6 +355,7 @@ clear_and_return:
340irqreturn_t rs_interrupt(int irq, void *dev_id) 355irqreturn_t rs_interrupt(int irq, void *dev_id)
341{ 356{
342 struct m68k_serial *info = dev_id; 357 struct m68k_serial *info = dev_id;
358 struct tty_struct *tty = tty_port_tty_get(&info->tport);
343 m68328_uart *uart; 359 m68328_uart *uart;
344 unsigned short rx; 360 unsigned short rx;
345 unsigned short tx; 361 unsigned short tx;
@@ -350,20 +366,24 @@ irqreturn_t rs_interrupt(int irq, void *dev_id)
350#ifdef USE_INTS 366#ifdef USE_INTS
351 tx = uart->utx.w; 367 tx = uart->utx.w;
352 368
353 if (rx & URX_DATA_READY) receive_chars(info, rx); 369 if (rx & URX_DATA_READY)
354 if (tx & UTX_TX_AVAIL) transmit_chars(info); 370 receive_chars(info, tty, rx);
371 if (tx & UTX_TX_AVAIL)
372 transmit_chars(info, tty);
355#else 373#else
356 receive_chars(info, rx); 374 receive_chars(info, tty, rx);
357#endif 375#endif
376 tty_kref_put(tty);
377
358 return IRQ_HANDLED; 378 return IRQ_HANDLED;
359} 379}
360 380
361static int startup(struct m68k_serial * info) 381static int startup(struct m68k_serial *info, struct tty_struct *tty)
362{ 382{
363 m68328_uart *uart = &uart_addr[info->line]; 383 m68328_uart *uart = &uart_addr[info->line];
364 unsigned long flags; 384 unsigned long flags;
365 385
366 if (info->flags & S_INITIALIZED) 386 if (info->tport.flags & ASYNC_INITIALIZED)
367 return 0; 387 return 0;
368 388
369 if (!info->xmit_buf) { 389 if (!info->xmit_buf) {
@@ -380,7 +400,6 @@ static int startup(struct m68k_serial * info)
380 */ 400 */
381 401
382 uart->ustcnt = USTCNT_UEN; 402 uart->ustcnt = USTCNT_UEN;
383 info->xmit_fifo_size = 1;
384 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN; 403 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_TXEN;
385 (void)uart->urx.w; 404 (void)uart->urx.w;
386 405
@@ -394,17 +413,17 @@ static int startup(struct m68k_serial * info)
394 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK; 413 uart->ustcnt = USTCNT_UEN | USTCNT_RXEN | USTCNT_RX_INTR_MASK;
395#endif 414#endif
396 415
397 if (info->tty) 416 if (tty)
398 clear_bit(TTY_IO_ERROR, &info->tty->flags); 417 clear_bit(TTY_IO_ERROR, &tty->flags);
399 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 418 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
400 419
401 /* 420 /*
402 * and set the speed of the serial port 421 * and set the speed of the serial port
403 */ 422 */
404 423
405 change_speed(info); 424 change_speed(info, tty);
406 425
407 info->flags |= S_INITIALIZED; 426 info->tport.flags |= ASYNC_INITIALIZED;
408 local_irq_restore(flags); 427 local_irq_restore(flags);
409 return 0; 428 return 0;
410} 429}
@@ -413,13 +432,13 @@ static int startup(struct m68k_serial * info)
413 * This routine will shutdown a serial port; interrupts are disabled, and 432 * This routine will shutdown a serial port; interrupts are disabled, and
414 * DTR is dropped if the hangup on close termio flag is on. 433 * DTR is dropped if the hangup on close termio flag is on.
415 */ 434 */
416static void shutdown(struct m68k_serial * info) 435static void shutdown(struct m68k_serial *info, struct tty_struct *tty)
417{ 436{
418 m68328_uart *uart = &uart_addr[info->line]; 437 m68328_uart *uart = &uart_addr[info->line];
419 unsigned long flags; 438 unsigned long flags;
420 439
421 uart->ustcnt = 0; /* All off! */ 440 uart->ustcnt = 0; /* All off! */
422 if (!(info->flags & S_INITIALIZED)) 441 if (!(info->tport.flags & ASYNC_INITIALIZED))
423 return; 442 return;
424 443
425 local_irq_save(flags); 444 local_irq_save(flags);
@@ -429,10 +448,10 @@ static void shutdown(struct m68k_serial * info)
429 info->xmit_buf = 0; 448 info->xmit_buf = 0;
430 } 449 }
431 450
432 if (info->tty) 451 if (tty)
433 set_bit(TTY_IO_ERROR, &info->tty->flags); 452 set_bit(TTY_IO_ERROR, &tty->flags);
434 453
435 info->flags &= ~S_INITIALIZED; 454 info->tport.flags &= ~ASYNC_INITIALIZED;
436 local_irq_restore(flags); 455 local_irq_restore(flags);
437} 456}
438 457
@@ -488,7 +507,7 @@ struct {
488 * This routine is called to set the UART divisor registers to match 507 * This routine is called to set the UART divisor registers to match
489 * the specified baud rate for a serial port. 508 * the specified baud rate for a serial port.
490 */ 509 */
491static void change_speed(struct m68k_serial *info) 510static void change_speed(struct m68k_serial *info, struct tty_struct *tty)
492{ 511{
493 m68328_uart *uart = &uart_addr[info->line]; 512 m68328_uart *uart = &uart_addr[info->line];
494 unsigned short port; 513 unsigned short port;
@@ -496,9 +515,7 @@ static void change_speed(struct m68k_serial *info)
496 unsigned cflag; 515 unsigned cflag;
497 int i; 516 int i;
498 517
499 if (!info->tty || !info->tty->termios) 518 cflag = tty->termios->c_cflag;
500 return;
501 cflag = info->tty->termios->c_cflag;
502 if (!(port = info->port)) 519 if (!(port = info->port))
503 return; 520 return;
504 521
@@ -510,7 +527,6 @@ static void change_speed(struct m68k_serial *info)
510 i = (i & ~CBAUDEX) + B38400; 527 i = (i & ~CBAUDEX) + B38400;
511 } 528 }
512 529
513 info->baud = baud_table[i];
514 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) | 530 uart->ubaud = PUT_FIELD(UBAUD_DIVIDE, hw_baud_table[i].divisor) |
515 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale); 531 PUT_FIELD(UBAUD_PRESCALER, hw_baud_table[i].prescale);
516 532
@@ -807,10 +823,10 @@ static int get_serial_info(struct m68k_serial * info,
807 tmp.line = info->line; 823 tmp.line = info->line;
808 tmp.port = info->port; 824 tmp.port = info->port;
809 tmp.irq = info->irq; 825 tmp.irq = info->irq;
810 tmp.flags = info->flags; 826 tmp.flags = info->tport.flags;
811 tmp.baud_base = info->baud_base; 827 tmp.baud_base = info->baud_base;
812 tmp.close_delay = info->close_delay; 828 tmp.close_delay = info->tport.close_delay;
813 tmp.closing_wait = info->closing_wait; 829 tmp.closing_wait = info->tport.closing_wait;
814 tmp.custom_divisor = info->custom_divisor; 830 tmp.custom_divisor = info->custom_divisor;
815 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 831 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
816 return -EFAULT; 832 return -EFAULT;
@@ -818,9 +834,10 @@ static int get_serial_info(struct m68k_serial * info,
818 return 0; 834 return 0;
819} 835}
820 836
821static int set_serial_info(struct m68k_serial * info, 837static int set_serial_info(struct m68k_serial *info, struct tty_struct *tty,
822 struct serial_struct * new_info) 838 struct serial_struct * new_info)
823{ 839{
840 struct tty_port *port = &info->tport;
824 struct serial_struct new_serial; 841 struct serial_struct new_serial;
825 struct m68k_serial old_info; 842 struct m68k_serial old_info;
826 int retval = 0; 843 int retval = 0;
@@ -834,17 +851,17 @@ static int set_serial_info(struct m68k_serial * info,
834 if (!capable(CAP_SYS_ADMIN)) { 851 if (!capable(CAP_SYS_ADMIN)) {
835 if ((new_serial.baud_base != info->baud_base) || 852 if ((new_serial.baud_base != info->baud_base) ||
836 (new_serial.type != info->type) || 853 (new_serial.type != info->type) ||
837 (new_serial.close_delay != info->close_delay) || 854 (new_serial.close_delay != port->close_delay) ||
838 ((new_serial.flags & ~S_USR_MASK) != 855 ((new_serial.flags & ~ASYNC_USR_MASK) !=
839 (info->flags & ~S_USR_MASK))) 856 (port->flags & ~ASYNC_USR_MASK)))
840 return -EPERM; 857 return -EPERM;
841 info->flags = ((info->flags & ~S_USR_MASK) | 858 port->flags = ((port->flags & ~ASYNC_USR_MASK) |
842 (new_serial.flags & S_USR_MASK)); 859 (new_serial.flags & ASYNC_USR_MASK));
843 info->custom_divisor = new_serial.custom_divisor; 860 info->custom_divisor = new_serial.custom_divisor;
844 goto check_and_exit; 861 goto check_and_exit;
845 } 862 }
846 863
847 if (info->count > 1) 864 if (port->count > 1)
848 return -EBUSY; 865 return -EBUSY;
849 866
850 /* 867 /*
@@ -853,14 +870,14 @@ static int set_serial_info(struct m68k_serial * info,
853 */ 870 */
854 871
855 info->baud_base = new_serial.baud_base; 872 info->baud_base = new_serial.baud_base;
856 info->flags = ((info->flags & ~S_FLAGS) | 873 port->flags = ((port->flags & ~ASYNC_FLAGS) |
857 (new_serial.flags & S_FLAGS)); 874 (new_serial.flags & ASYNC_FLAGS));
858 info->type = new_serial.type; 875 info->type = new_serial.type;
859 info->close_delay = new_serial.close_delay; 876 port->close_delay = new_serial.close_delay;
860 info->closing_wait = new_serial.closing_wait; 877 port->closing_wait = new_serial.closing_wait;
861 878
862check_and_exit: 879check_and_exit:
863 retval = startup(info); 880 retval = startup(info, tty);
864 return retval; 881 return retval;
865} 882}
866 883
@@ -946,7 +963,7 @@ static int rs_ioctl(struct tty_struct *tty,
946 return get_serial_info(info, 963 return get_serial_info(info,
947 (struct serial_struct *) arg); 964 (struct serial_struct *) arg);
948 case TIOCSSERIAL: 965 case TIOCSSERIAL:
949 return set_serial_info(info, 966 return set_serial_info(info, tty,
950 (struct serial_struct *) arg); 967 (struct serial_struct *) arg);
951 case TIOCSERGETLSR: /* Get line status register */ 968 case TIOCSERGETLSR: /* Get line status register */
952 return get_lsr_info(info, (unsigned int *) arg); 969 return get_lsr_info(info, (unsigned int *) arg);
@@ -965,7 +982,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
965{ 982{
966 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 983 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
967 984
968 change_speed(info); 985 change_speed(info, tty);
969 986
970 if ((old_termios->c_cflag & CRTSCTS) && 987 if ((old_termios->c_cflag & CRTSCTS) &&
971 !(tty->termios->c_cflag & CRTSCTS)) { 988 !(tty->termios->c_cflag & CRTSCTS)) {
@@ -988,6 +1005,7 @@ static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
988static void rs_close(struct tty_struct *tty, struct file * filp) 1005static void rs_close(struct tty_struct *tty, struct file * filp)
989{ 1006{
990 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data; 1007 struct m68k_serial * info = (struct m68k_serial *)tty->driver_data;
1008 struct tty_port *port = &info->tport;
991 m68328_uart *uart = &uart_addr[info->line]; 1009 m68328_uart *uart = &uart_addr[info->line];
992 unsigned long flags; 1010 unsigned long flags;
993 1011
@@ -1001,7 +1019,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1001 return; 1019 return;
1002 } 1020 }
1003 1021
1004 if ((tty->count == 1) && (info->count != 1)) { 1022 if ((tty->count == 1) && (port->count != 1)) {
1005 /* 1023 /*
1006 * Uh, oh. tty->count is 1, which means that the tty 1024 * Uh, oh. tty->count is 1, which means that the tty
1007 * structure will be freed. Info->count should always 1025 * structure will be freed. Info->count should always
@@ -1010,26 +1028,26 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1010 * serial port won't be shutdown. 1028 * serial port won't be shutdown.
1011 */ 1029 */
1012 printk("rs_close: bad serial port count; tty->count is 1, " 1030 printk("rs_close: bad serial port count; tty->count is 1, "
1013 "info->count is %d\n", info->count); 1031 "port->count is %d\n", port->count);
1014 info->count = 1; 1032 port->count = 1;
1015 } 1033 }
1016 if (--info->count < 0) { 1034 if (--port->count < 0) {
1017 printk("rs_close: bad serial port count for ttyS%d: %d\n", 1035 printk("rs_close: bad serial port count for ttyS%d: %d\n",
1018 info->line, info->count); 1036 info->line, port->count);
1019 info->count = 0; 1037 port->count = 0;
1020 } 1038 }
1021 if (info->count) { 1039 if (port->count) {
1022 local_irq_restore(flags); 1040 local_irq_restore(flags);
1023 return; 1041 return;
1024 } 1042 }
1025 info->flags |= S_CLOSING; 1043 port->flags |= ASYNC_CLOSING;
1026 /* 1044 /*
1027 * Now we wait for the transmit buffer to clear; and we notify 1045 * Now we wait for the transmit buffer to clear; and we notify
1028 * the line discipline to only process XON/XOFF characters. 1046 * the line discipline to only process XON/XOFF characters.
1029 */ 1047 */
1030 tty->closing = 1; 1048 tty->closing = 1;
1031 if (info->closing_wait != S_CLOSING_WAIT_NONE) 1049 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1032 tty_wait_until_sent(tty, info->closing_wait); 1050 tty_wait_until_sent(tty, port->closing_wait);
1033 /* 1051 /*
1034 * At this point we stop accepting input. To do this, we 1052 * At this point we stop accepting input. To do this, we
1035 * disable the receive line status interrupts, and tell the 1053 * disable the receive line status interrupts, and tell the
@@ -1040,13 +1058,12 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1040 uart->ustcnt &= ~USTCNT_RXEN; 1058 uart->ustcnt &= ~USTCNT_RXEN;
1041 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK); 1059 uart->ustcnt &= ~(USTCNT_RXEN | USTCNT_RX_INTR_MASK);
1042 1060
1043 shutdown(info); 1061 shutdown(info, tty);
1044 rs_flush_buffer(tty); 1062 rs_flush_buffer(tty);
1045 1063
1046 tty_ldisc_flush(tty); 1064 tty_ldisc_flush(tty);
1047 tty->closing = 0; 1065 tty->closing = 0;
1048 info->event = 0; 1066 tty_port_tty_set(&info->tport, NULL);
1049 info->tty = NULL;
1050#warning "This is not and has never been valid so fix it" 1067#warning "This is not and has never been valid so fix it"
1051#if 0 1068#if 0
1052 if (tty->ldisc.num != ldiscs[N_TTY].num) { 1069 if (tty->ldisc.num != ldiscs[N_TTY].num) {
@@ -1058,14 +1075,13 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
1058 (tty->ldisc.open)(tty); 1075 (tty->ldisc.open)(tty);
1059 } 1076 }
1060#endif 1077#endif
1061 if (info->blocked_open) { 1078 if (port->blocked_open) {
1062 if (info->close_delay) { 1079 if (port->close_delay)
1063 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1080 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1064 } 1081 wake_up_interruptible(&port->open_wait);
1065 wake_up_interruptible(&info->open_wait);
1066 } 1082 }
1067 info->flags &= ~(S_NORMAL_ACTIVE|S_CLOSING); 1083 port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1068 wake_up_interruptible(&info->close_wait); 1084 wake_up_interruptible(&port->close_wait);
1069 local_irq_restore(flags); 1085 local_irq_restore(flags);
1070} 1086}
1071 1087
@@ -1080,107 +1096,14 @@ void rs_hangup(struct tty_struct *tty)
1080 return; 1096 return;
1081 1097
1082 rs_flush_buffer(tty); 1098 rs_flush_buffer(tty);
1083 shutdown(info); 1099 shutdown(info, tty);
1084 info->event = 0; 1100 info->tport.count = 0;
1085 info->count = 0; 1101 info->tport.flags &= ~ASYNC_NORMAL_ACTIVE;
1086 info->flags &= ~S_NORMAL_ACTIVE; 1102 tty_port_tty_set(&info->tport, NULL);
1087 info->tty = NULL; 1103 wake_up_interruptible(&info->tport.open_wait);
1088 wake_up_interruptible(&info->open_wait);
1089} 1104}
1090 1105
1091/* 1106/*
1092 * ------------------------------------------------------------
1093 * rs_open() and friends
1094 * ------------------------------------------------------------
1095 */
1096static int block_til_ready(struct tty_struct *tty, struct file * filp,
1097 struct m68k_serial *info)
1098{
1099 DECLARE_WAITQUEUE(wait, current);
1100 int retval;
1101 int do_clocal = 0;
1102
1103 /*
1104 * If the device is in the middle of being closed, then block
1105 * until it's done, and then try again.
1106 */
1107 if (info->flags & S_CLOSING) {
1108 interruptible_sleep_on(&info->close_wait);
1109#ifdef SERIAL_DO_RESTART
1110 if (info->flags & S_HUP_NOTIFY)
1111 return -EAGAIN;
1112 else
1113 return -ERESTARTSYS;
1114#else
1115 return -EAGAIN;
1116#endif
1117 }
1118
1119 /*
1120 * If non-blocking mode is set, or the port is not enabled,
1121 * then make the check up front and then exit.
1122 */
1123 if ((filp->f_flags & O_NONBLOCK) ||
1124 (tty->flags & (1 << TTY_IO_ERROR))) {
1125 info->flags |= S_NORMAL_ACTIVE;
1126 return 0;
1127 }
1128
1129 if (tty->termios->c_cflag & CLOCAL)
1130 do_clocal = 1;
1131
1132 /*
1133 * Block waiting for the carrier detect and the line to become
1134 * free (i.e., not in use by the callout). While we are in
1135 * this loop, info->count is dropped by one, so that
1136 * rs_close() knows when to free things. We restore it upon
1137 * exit, either normal or abnormal.
1138 */
1139 retval = 0;
1140 add_wait_queue(&info->open_wait, &wait);
1141
1142 info->count--;
1143 info->blocked_open++;
1144 while (1) {
1145 local_irq_disable();
1146 m68k_rtsdtr(info, 1);
1147 local_irq_enable();
1148 current->state = TASK_INTERRUPTIBLE;
1149 if (tty_hung_up_p(filp) ||
1150 !(info->flags & S_INITIALIZED)) {
1151#ifdef SERIAL_DO_RESTART
1152 if (info->flags & S_HUP_NOTIFY)
1153 retval = -EAGAIN;
1154 else
1155 retval = -ERESTARTSYS;
1156#else
1157 retval = -EAGAIN;
1158#endif
1159 break;
1160 }
1161 if (!(info->flags & S_CLOSING) && do_clocal)
1162 break;
1163 if (signal_pending(current)) {
1164 retval = -ERESTARTSYS;
1165 break;
1166 }
1167 tty_unlock();
1168 schedule();
1169 tty_lock();
1170 }
1171 current->state = TASK_RUNNING;
1172 remove_wait_queue(&info->open_wait, &wait);
1173 if (!tty_hung_up_p(filp))
1174 info->count++;
1175 info->blocked_open--;
1176
1177 if (retval)
1178 return retval;
1179 info->flags |= S_NORMAL_ACTIVE;
1180 return 0;
1181}
1182
1183/*
1184 * This routine is called whenever a serial port is opened. It 1107 * This routine is called whenever a serial port is opened. It
1185 * enables interrupts for a serial port, linking in its S structure into 1108 * enables interrupts for a serial port, linking in its S structure into
1186 * the IRQ chain. It also performs the serial-specific 1109 * the IRQ chain. It also performs the serial-specific
@@ -1196,18 +1119,18 @@ int rs_open(struct tty_struct *tty, struct file * filp)
1196 if (serial_paranoia_check(info, tty->name, "rs_open")) 1119 if (serial_paranoia_check(info, tty->name, "rs_open"))
1197 return -ENODEV; 1120 return -ENODEV;
1198 1121
1199 info->count++; 1122 info->tport.count++;
1200 tty->driver_data = info; 1123 tty->driver_data = info;
1201 info->tty = tty; 1124 tty_port_tty_set(&info->tport, tty);
1202 1125
1203 /* 1126 /*
1204 * Start up serial port 1127 * Start up serial port
1205 */ 1128 */
1206 retval = startup(info); 1129 retval = startup(info, tty);
1207 if (retval) 1130 if (retval)
1208 return retval; 1131 return retval;
1209 1132
1210 return block_til_ready(tty, filp, info); 1133 return tty_port_block_til_ready(&info->tport, tty, filp);
1211} 1134}
1212 1135
1213/* Finally, routines used to initialize the serial driver. */ 1136/* Finally, routines used to initialize the serial driver. */
@@ -1235,11 +1158,15 @@ static const struct tty_operations rs_ops = {
1235 .set_ldisc = rs_set_ldisc, 1158 .set_ldisc = rs_set_ldisc,
1236}; 1159};
1237 1160
1161static const struct tty_port_operations rs_port_ops = {
1162};
1163
1238/* rs_init inits the driver */ 1164/* rs_init inits the driver */
1239static int __init 1165static int __init
1240rs68328_init(void) 1166rs68328_init(void)
1241{ 1167{
1242 int flags, i; 1168 unsigned long flags;
1169 int i;
1243 struct m68k_serial *info; 1170 struct m68k_serial *info;
1244 1171
1245 serial_driver = alloc_tty_driver(NR_PORTS); 1172 serial_driver = alloc_tty_driver(NR_PORTS);
@@ -1273,19 +1200,13 @@ rs68328_init(void)
1273 for(i=0;i<NR_PORTS;i++) { 1200 for(i=0;i<NR_PORTS;i++) {
1274 1201
1275 info = &m68k_soft[i]; 1202 info = &m68k_soft[i];
1203 tty_port_init(&info->tport);
1204 info->tport.ops = &rs_port_ops;
1276 info->magic = SERIAL_MAGIC; 1205 info->magic = SERIAL_MAGIC;
1277 info->port = (int) &uart_addr[i]; 1206 info->port = (int) &uart_addr[i];
1278 info->tty = NULL;
1279 info->irq = uart_irqs[i]; 1207 info->irq = uart_irqs[i];
1280 info->custom_divisor = 16; 1208 info->custom_divisor = 16;
1281 info->close_delay = 50;
1282 info->closing_wait = 3000;
1283 info->x_char = 0; 1209 info->x_char = 0;
1284 info->event = 0;
1285 info->count = 0;
1286 info->blocked_open = 0;
1287 init_waitqueue_head(&info->open_wait);
1288 init_waitqueue_head(&info->close_wait);
1289 info->line = i; 1210 info->line = i;
1290 info->is_cons = 1; /* Means shortcuts work */ 1211 info->is_cons = 1; /* Means shortcuts work */
1291 1212
diff --git a/drivers/tty/serial/68328serial.h b/drivers/tty/serial/68328serial.h
deleted file mode 100644
index 3d2faabd766f..000000000000
--- a/drivers/tty/serial/68328serial.h
+++ /dev/null
@@ -1,186 +0,0 @@
1/* 68328serial.h: Definitions for the mc68328 serial driver.
2 *
3 * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
4 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
5 * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
6 * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
7 *
8 * VZ Support/Fixes Evan Stawnyczy <e@lineo.ca>
9 */
10
11#ifndef _MC683XX_SERIAL_H
12#define _MC683XX_SERIAL_H
13
14
15struct serial_struct {
16 int type;
17 int line;
18 int port;
19 int irq;
20 int flags;
21 int xmit_fifo_size;
22 int custom_divisor;
23 int baud_base;
24 unsigned short close_delay;
25 char reserved_char[2];
26 int hub6; /* FIXME: We don't have AT&T Hub6 boards! */
27 unsigned short closing_wait; /* time to wait before closing */
28 unsigned short closing_wait2; /* no longer used... */
29 int reserved[4];
30};
31
32/*
33 * For the close wait times, 0 means wait forever for serial port to
34 * flush its output. 65535 means don't wait at all.
35 */
36#define S_CLOSING_WAIT_INF 0
37#define S_CLOSING_WAIT_NONE 65535
38
39/*
40 * Definitions for S_struct (and serial_struct) flags field
41 */
42#define S_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes
43 on the callout port */
44#define S_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */
45#define S_SAK 0x0004 /* Secure Attention Key (Orange book) */
46#define S_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
47
48#define S_SPD_MASK 0x0030
49#define S_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */
50
51#define S_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */
52#define S_SPD_CUST 0x0030 /* Use user-specified divisor */
53
54#define S_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
55#define S_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */
56#define S_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
57#define S_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */
58#define S_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */
59
60#define S_FLAGS 0x0FFF /* Possible legal S flags */
61#define S_USR_MASK 0x0430 /* Legal flags that non-privileged
62 * users can set or reset */
63
64/* Internal flags used only by kernel/chr_drv/serial.c */
65#define S_INITIALIZED 0x80000000 /* Serial port was initialized */
66#define S_CALLOUT_ACTIVE 0x40000000 /* Call out device is active */
67#define S_NORMAL_ACTIVE 0x20000000 /* Normal device is active */
68#define S_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */
69#define S_CLOSING 0x08000000 /* Serial port is closing */
70#define S_CTS_FLOW 0x04000000 /* Do CTS flow control */
71#define S_CHECK_CD 0x02000000 /* i.e., CLOCAL */
72
73/* Software state per channel */
74
75#ifdef __KERNEL__
76
77/*
78 * I believe this is the optimal setting that reduces the number of interrupts.
79 * At high speeds the output might become a little "bursted" (use USTCNT_TXHE
80 * if that bothers you), but in most cases it will not, since we try to
81 * transmit characters every time rs_interrupt is called. Thus, quite often
82 * you'll see that a receive interrupt occures before the transmit one.
83 * -- Vladimir Gurevich
84 */
85#define USTCNT_TX_INTR_MASK (USTCNT_TXEE)
86
87/*
88 * 68328 and 68EZ328 UARTS are a little bit different. EZ328 has special
89 * "Old data interrupt" which occures whenever the data stay in the FIFO
90 * longer than 30 bits time. This allows us to use FIFO without compromising
91 * latency. '328 does not have this feature and without the real 328-based
92 * board I would assume that RXRE is the safest setting.
93 *
94 * For EZ328 I use RXHE (Half empty) interrupt to reduce the number of
95 * interrupts. RXFE (receive queue full) causes the system to lose data
96 * at least at 115200 baud
97 *
98 * If your board is busy doing other stuff, you might consider to use
99 * RXRE (data ready intrrupt) instead.
100 *
101 * The other option is to make these INTR masks run-time configurable, so
102 * that people can dynamically adapt them according to the current usage.
103 * -- Vladimir Gurevich
104 */
105
106/* (es) */
107#if defined(CONFIG_M68EZ328) || defined(CONFIG_M68VZ328)
108#define USTCNT_RX_INTR_MASK (USTCNT_RXHE | USTCNT_ODEN)
109#elif defined(CONFIG_M68328)
110#define USTCNT_RX_INTR_MASK (USTCNT_RXRE)
111#else
112#error Please, define the Rx interrupt events for your CPU
113#endif
114/* (/es) */
115
116/*
117 * This is our internal structure for each serial port's state.
118 *
119 * Many fields are paralleled by the structure used by the serial_struct
120 * structure.
121 *
122 * For definitions of the flags field, see tty.h
123 */
124
125struct m68k_serial {
126 char soft_carrier; /* Use soft carrier on this channel */
127 char break_abort; /* Is serial console in, so process brk/abrt */
128 char is_cons; /* Is this our console. */
129
130 /* We need to know the current clock divisor
131 * to read the bps rate the chip has currently
132 * loaded.
133 */
134 unsigned char clk_divisor; /* May be 1, 16, 32, or 64 */
135 int baud;
136 int magic;
137 int baud_base;
138 int port;
139 int irq;
140 int flags; /* defined in tty.h */
141 int type; /* UART type */
142 struct tty_struct *tty;
143 int read_status_mask;
144 int ignore_status_mask;
145 int timeout;
146 int xmit_fifo_size;
147 int custom_divisor;
148 int x_char; /* xon/xoff character */
149 int close_delay;
150 unsigned short closing_wait;
151 unsigned short closing_wait2;
152 unsigned long event;
153 unsigned long last_active;
154 int line;
155 int count; /* # of fd on device */
156 int blocked_open; /* # of blocked opens */
157 unsigned char *xmit_buf;
158 int xmit_head;
159 int xmit_tail;
160 int xmit_cnt;
161 wait_queue_head_t open_wait;
162 wait_queue_head_t close_wait;
163};
164
165
166#define SERIAL_MAGIC 0x5301
167
168/*
169 * The size of the serial xmit buffer is 1 page, or 4096 bytes
170 */
171#define SERIAL_XMIT_SIZE 4096
172
173/*
174 * Events are used to schedule things to happen at timer-interrupt
175 * time, instead of at rs interrupt time.
176 */
177#define RS_EVENT_WRITE_WAKEUP 0
178
179/*
180 * Define the number of ports supported and their irqs.
181 */
182#define NR_PORTS 1
183#define UART_IRQ_DEFNS {UART_IRQ_NUM}
184
185#endif /* __KERNEL__ */
186#endif /* !(_MC683XX_SERIAL_H) */
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c
index 5c27f7e6c9f1..182efcc90e2e 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250.c
@@ -568,6 +568,16 @@ static void serial8250_clear_fifos(struct uart_8250_port *p)
568 } 568 }
569} 569}
570 570
571void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p)
572{
573 unsigned char fcr;
574
575 serial8250_clear_fifos(p);
576 fcr = uart_config[p->port.type].fcr;
577 serial_out(p, UART_FCR, fcr);
578}
579EXPORT_SYMBOL_GPL(serial8250_clear_and_reinit_fifos);
580
571/* 581/*
572 * IER sleep support. UARTs which have EFRs need the "extended 582 * IER sleep support. UARTs which have EFRs need the "extended
573 * capability" bit enabled. Note that on XR16C850s, we need to 583 * capability" bit enabled. Note that on XR16C850s, we need to
@@ -1332,27 +1342,6 @@ static void serial8250_enable_ms(struct uart_port *port)
1332} 1342}
1333 1343
1334/* 1344/*
1335 * Clear the Tegra rx fifo after a break
1336 *
1337 * FIXME: This needs to become a port specific callback once we have a
1338 * framework for this
1339 */
1340static void clear_rx_fifo(struct uart_8250_port *up)
1341{
1342 unsigned int status, tmout = 10000;
1343 do {
1344 status = serial_in(up, UART_LSR);
1345 if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))
1346 status = serial_in(up, UART_RX);
1347 else
1348 break;
1349 if (--tmout == 0)
1350 break;
1351 udelay(1);
1352 } while (1);
1353}
1354
1355/*
1356 * serial8250_rx_chars: processes according to the passed in LSR 1345 * serial8250_rx_chars: processes according to the passed in LSR
1357 * value, and returns the remaining LSR bits not handled 1346 * value, and returns the remaining LSR bits not handled
1358 * by this Rx routine. 1347 * by this Rx routine.
@@ -1386,20 +1375,10 @@ serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr)
1386 up->lsr_saved_flags = 0; 1375 up->lsr_saved_flags = 0;
1387 1376
1388 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) { 1377 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
1389 /*
1390 * For statistics only
1391 */
1392 if (lsr & UART_LSR_BI) { 1378 if (lsr & UART_LSR_BI) {
1393 lsr &= ~(UART_LSR_FE | UART_LSR_PE); 1379 lsr &= ~(UART_LSR_FE | UART_LSR_PE);
1394 port->icount.brk++; 1380 port->icount.brk++;
1395 /* 1381 /*
1396 * If tegra port then clear the rx fifo to
1397 * accept another break/character.
1398 */
1399 if (port->type == PORT_TEGRA)
1400 clear_rx_fifo(up);
1401
1402 /*
1403 * We do the SysRQ and SAK checking 1382 * We do the SysRQ and SAK checking
1404 * here because otherwise the break 1383 * here because otherwise the break
1405 * may get masked by ignore_status_mask 1384 * may get masked by ignore_status_mask
@@ -3037,6 +3016,7 @@ static int __devinit serial8250_probe(struct platform_device *dev)
3037 port.serial_in = p->serial_in; 3016 port.serial_in = p->serial_in;
3038 port.serial_out = p->serial_out; 3017 port.serial_out = p->serial_out;
3039 port.handle_irq = p->handle_irq; 3018 port.handle_irq = p->handle_irq;
3019 port.handle_break = p->handle_break;
3040 port.set_termios = p->set_termios; 3020 port.set_termios = p->set_termios;
3041 port.pm = p->pm; 3021 port.pm = p->pm;
3042 port.dev = &dev->dev; 3022 port.dev = &dev->dev;
@@ -3209,6 +3189,8 @@ int serial8250_register_port(struct uart_port *port)
3209 uart->port.set_termios = port->set_termios; 3189 uart->port.set_termios = port->set_termios;
3210 if (port->pm) 3190 if (port->pm)
3211 uart->port.pm = port->pm; 3191 uart->port.pm = port->pm;
3192 if (port->handle_break)
3193 uart->port.handle_break = port->handle_break;
3212 3194
3213 if (serial8250_isa_config != NULL) 3195 if (serial8250_isa_config != NULL)
3214 serial8250_isa_config(0, &uart->port, 3196 serial8250_isa_config(0, &uart->port,
diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index 2868a1da254d..c9d0ebe952fc 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -96,6 +96,8 @@ static inline void serial_out(struct uart_8250_port *up, int offset, int value)
96 up->port.serial_out(&up->port, offset, value); 96 up->port.serial_out(&up->port, offset, value);
97} 97}
98 98
99void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
100
99#if defined(__alpha__) && !defined(CONFIG_PCI) 101#if defined(__alpha__) && !defined(CONFIG_PCI)
100/* 102/*
101 * Digital did something really horribly wrong with the OUT1 and OUT2 103 * Digital did something really horribly wrong with the OUT1 and OUT2
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 858dca865d6a..24ea98c6e77a 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/tty.h> 19#include <linux/tty.h>
20#include <linux/serial_reg.h>
20#include <linux/serial_core.h> 21#include <linux/serial_core.h>
21#include <linux/8250_pci.h> 22#include <linux/8250_pci.h>
22#include <linux/bitops.h> 23#include <linux/bitops.h>
@@ -1092,11 +1093,49 @@ static int skip_tx_en_setup(struct serial_private *priv,
1092 return pci_default_setup(priv, board, port, idx); 1093 return pci_default_setup(priv, board, port, idx);
1093} 1094}
1094 1095
1096static void kt_handle_break(struct uart_port *p)
1097{
1098 struct uart_8250_port *up =
1099 container_of(p, struct uart_8250_port, port);
1100 /*
1101 * On receipt of a BI, serial device in Intel ME (Intel
1102 * management engine) needs to have its fifos cleared for sane
1103 * SOL (Serial Over Lan) output.
1104 */
1105 serial8250_clear_and_reinit_fifos(up);
1106}
1107
1108static unsigned int kt_serial_in(struct uart_port *p, int offset)
1109{
1110 struct uart_8250_port *up =
1111 container_of(p, struct uart_8250_port, port);
1112 unsigned int val;
1113
1114 /*
1115 * When the Intel ME (management engine) gets reset its serial
1116 * port registers could return 0 momentarily. Functions like
1117 * serial8250_console_write, read and save the IER, perform
1118 * some operation and then restore it. In order to avoid
1119 * setting IER register inadvertently to 0, if the value read
1120 * is 0, double check with ier value in uart_8250_port and use
1121 * that instead. up->ier should be the same value as what is
1122 * currently configured.
1123 */
1124 val = inb(p->iobase + offset);
1125 if (offset == UART_IER) {
1126 if (val == 0)
1127 val = up->ier;
1128 }
1129 return val;
1130}
1131
1095static int kt_serial_setup(struct serial_private *priv, 1132static int kt_serial_setup(struct serial_private *priv,
1096 const struct pciserial_board *board, 1133 const struct pciserial_board *board,
1097 struct uart_port *port, int idx) 1134 struct uart_port *port, int idx)
1098{ 1135{
1099 port->flags |= UPF_BUG_THRE; 1136 port->flags |= UPF_BUG_THRE;
1137 port->serial_in = kt_serial_in;
1138 port->handle_break = kt_handle_break;
1100 return skip_tx_en_setup(priv, board, port, idx); 1139 return skip_tx_en_setup(priv, board, port, idx);
1101} 1140}
1102 1141
@@ -2775,6 +2814,12 @@ void pciserial_suspend_ports(struct serial_private *priv)
2775 for (i = 0; i < priv->nr; i++) 2814 for (i = 0; i < priv->nr; i++)
2776 if (priv->line[i] >= 0) 2815 if (priv->line[i] >= 0)
2777 serial8250_suspend_port(priv->line[i]); 2816 serial8250_suspend_port(priv->line[i]);
2817
2818 /*
2819 * Ensure that every init quirk is properly torn down
2820 */
2821 if (priv->quirk->exit)
2822 priv->quirk->exit(priv->dev);
2778} 2823}
2779EXPORT_SYMBOL_GPL(pciserial_suspend_ports); 2824EXPORT_SYMBOL_GPL(pciserial_suspend_ports);
2780 2825
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 3d569cd68f58..2d139141de8c 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -67,30 +67,6 @@
67#define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE) 67#define UART_DR_ERROR (UART011_DR_OE|UART011_DR_BE|UART011_DR_PE|UART011_DR_FE)
68#define UART_DUMMY_DR_RX (1 << 16) 68#define UART_DUMMY_DR_RX (1 << 16)
69 69
70
71#define UART_WA_SAVE_NR 14
72
73static void pl011_lockup_wa(unsigned long data);
74static const u32 uart_wa_reg[UART_WA_SAVE_NR] = {
75 ST_UART011_DMAWM,
76 ST_UART011_TIMEOUT,
77 ST_UART011_LCRH_RX,
78 UART011_IBRD,
79 UART011_FBRD,
80 ST_UART011_LCRH_TX,
81 UART011_IFLS,
82 ST_UART011_XFCR,
83 ST_UART011_XON1,
84 ST_UART011_XON2,
85 ST_UART011_XOFF1,
86 ST_UART011_XOFF2,
87 UART011_CR,
88 UART011_IMSC
89};
90
91static u32 uart_wa_regdata[UART_WA_SAVE_NR];
92static DECLARE_TASKLET(pl011_lockup_tlet, pl011_lockup_wa, 0);
93
94/* There is by now at least one vendor with differing details, so handle it */ 70/* There is by now at least one vendor with differing details, so handle it */
95struct vendor_data { 71struct vendor_data {
96 unsigned int ifls; 72 unsigned int ifls;
@@ -100,6 +76,7 @@ struct vendor_data {
100 bool oversampling; 76 bool oversampling;
101 bool interrupt_may_hang; /* vendor-specific */ 77 bool interrupt_may_hang; /* vendor-specific */
102 bool dma_threshold; 78 bool dma_threshold;
79 bool cts_event_workaround;
103}; 80};
104 81
105static struct vendor_data vendor_arm = { 82static struct vendor_data vendor_arm = {
@@ -109,6 +86,7 @@ static struct vendor_data vendor_arm = {
109 .lcrh_rx = UART011_LCRH, 86 .lcrh_rx = UART011_LCRH,
110 .oversampling = false, 87 .oversampling = false,
111 .dma_threshold = false, 88 .dma_threshold = false,
89 .cts_event_workaround = false,
112}; 90};
113 91
114static struct vendor_data vendor_st = { 92static struct vendor_data vendor_st = {
@@ -119,6 +97,7 @@ static struct vendor_data vendor_st = {
119 .oversampling = true, 97 .oversampling = true,
120 .interrupt_may_hang = true, 98 .interrupt_may_hang = true,
121 .dma_threshold = true, 99 .dma_threshold = true,
100 .cts_event_workaround = true,
122}; 101};
123 102
124static struct uart_amba_port *amba_ports[UART_NR]; 103static struct uart_amba_port *amba_ports[UART_NR];
@@ -1054,69 +1033,6 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap)
1054#define pl011_dma_flush_buffer NULL 1033#define pl011_dma_flush_buffer NULL
1055#endif 1034#endif
1056 1035
1057
1058/*
1059 * pl011_lockup_wa
1060 * This workaround aims to break the deadlock situation
1061 * when after long transfer over uart in hardware flow
1062 * control, uart interrupt registers cannot be cleared.
1063 * Hence uart transfer gets blocked.
1064 *
1065 * It is seen that during such deadlock condition ICR
1066 * don't get cleared even on multiple write. This leads
1067 * pass_counter to decrease and finally reach zero. This
1068 * can be taken as trigger point to run this UART_BT_WA.
1069 *
1070 */
1071static void pl011_lockup_wa(unsigned long data)
1072{
1073 struct uart_amba_port *uap = amba_ports[0];
1074 void __iomem *base = uap->port.membase;
1075 struct circ_buf *xmit = &uap->port.state->xmit;
1076 struct tty_struct *tty = uap->port.state->port.tty;
1077 int buf_empty_retries = 200;
1078 int loop;
1079
1080 /* Stop HCI layer from submitting data for tx */
1081 tty->hw_stopped = 1;
1082 while (!uart_circ_empty(xmit)) {
1083 if (buf_empty_retries-- == 0)
1084 break;
1085 udelay(100);
1086 }
1087
1088 /* Backup registers */
1089 for (loop = 0; loop < UART_WA_SAVE_NR; loop++)
1090 uart_wa_regdata[loop] = readl(base + uart_wa_reg[loop]);
1091
1092 /* Disable UART so that FIFO data is flushed out */
1093 writew(0x00, uap->port.membase + UART011_CR);
1094
1095 /* Soft reset UART module */
1096 if (uap->port.dev->platform_data) {
1097 struct amba_pl011_data *plat;
1098
1099 plat = uap->port.dev->platform_data;
1100 if (plat->reset)
1101 plat->reset();
1102 }
1103
1104 /* Restore registers */
1105 for (loop = 0; loop < UART_WA_SAVE_NR; loop++)
1106 writew(uart_wa_regdata[loop] ,
1107 uap->port.membase + uart_wa_reg[loop]);
1108
1109 /* Initialise the old status of the modem signals */
1110 uap->old_status = readw(uap->port.membase + UART01x_FR) &
1111 UART01x_FR_MODEM_ANY;
1112
1113 if (readl(base + UART011_MIS) & 0x2)
1114 printk(KERN_EMERG "UART_BT_WA: ***FAILED***\n");
1115
1116 /* Start Tx/Rx */
1117 tty->hw_stopped = 0;
1118}
1119
1120static void pl011_stop_tx(struct uart_port *port) 1036static void pl011_stop_tx(struct uart_port *port)
1121{ 1037{
1122 struct uart_amba_port *uap = (struct uart_amba_port *)port; 1038 struct uart_amba_port *uap = (struct uart_amba_port *)port;
@@ -1245,12 +1161,26 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1245 unsigned long flags; 1161 unsigned long flags;
1246 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT; 1162 unsigned int status, pass_counter = AMBA_ISR_PASS_LIMIT;
1247 int handled = 0; 1163 int handled = 0;
1164 unsigned int dummy_read;
1248 1165
1249 spin_lock_irqsave(&uap->port.lock, flags); 1166 spin_lock_irqsave(&uap->port.lock, flags);
1250 1167
1251 status = readw(uap->port.membase + UART011_MIS); 1168 status = readw(uap->port.membase + UART011_MIS);
1252 if (status) { 1169 if (status) {
1253 do { 1170 do {
1171 if (uap->vendor->cts_event_workaround) {
1172 /* workaround to make sure that all bits are unlocked.. */
1173 writew(0x00, uap->port.membase + UART011_ICR);
1174
1175 /*
1176 * WA: introduce 26ns(1 uart clk) delay before W1C;
1177 * single apb access will incur 2 pclk(133.12Mhz) delay,
1178 * so add 2 dummy reads
1179 */
1180 dummy_read = readw(uap->port.membase + UART011_ICR);
1181 dummy_read = readw(uap->port.membase + UART011_ICR);
1182 }
1183
1254 writew(status & ~(UART011_TXIS|UART011_RTIS| 1184 writew(status & ~(UART011_TXIS|UART011_RTIS|
1255 UART011_RXIS), 1185 UART011_RXIS),
1256 uap->port.membase + UART011_ICR); 1186 uap->port.membase + UART011_ICR);
@@ -1267,11 +1197,8 @@ static irqreturn_t pl011_int(int irq, void *dev_id)
1267 if (status & UART011_TXIS) 1197 if (status & UART011_TXIS)
1268 pl011_tx_chars(uap); 1198 pl011_tx_chars(uap);
1269 1199
1270 if (pass_counter-- == 0) { 1200 if (pass_counter-- == 0)
1271 if (uap->interrupt_may_hang)
1272 tasklet_schedule(&pl011_lockup_tlet);
1273 break; 1201 break;
1274 }
1275 1202
1276 status = readw(uap->port.membase + UART011_MIS); 1203 status = readw(uap->port.membase + UART011_MIS);
1277 } while (status != 0); 1204 } while (status != 0);
diff --git a/drivers/tty/serial/crisv10.c b/drivers/tty/serial/crisv10.c
index 5b07c0c3a10c..80b6b1b1f725 100644
--- a/drivers/tty/serial/crisv10.c
+++ b/drivers/tty/serial/crisv10.c
@@ -952,19 +952,6 @@ static const struct control_pins e100_modem_pins[NR_PORTS] =
952/* Input */ 952/* Input */
953#define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask) 953#define E100_DSR_GET(info) ((*e100_modem_pins[(info)->line].dsr_port) & e100_modem_pins[(info)->line].dsr_mask)
954 954
955
956/*
957 * tmp_buf is used as a temporary buffer by serial_write. We need to
958 * lock it in case the memcpy_fromfs blocks while swapping in a page,
959 * and some other program tries to do a serial write at the same time.
960 * Since the lock will only come under contention when the system is
961 * swapping and available memory is low, it makes sense to share one
962 * buffer across all the serial ports, since it significantly saves
963 * memory if large numbers of serial ports are open.
964 */
965static unsigned char *tmp_buf;
966static DEFINE_MUTEX(tmp_buf_mutex);
967
968/* Calculate the chartime depending on baudrate, numbor of bits etc. */ 955/* Calculate the chartime depending on baudrate, numbor of bits etc. */
969static void update_char_time(struct e100_serial * info) 956static void update_char_time(struct e100_serial * info)
970{ 957{
@@ -3150,7 +3137,7 @@ static int rs_raw_write(struct tty_struct *tty,
3150 3137
3151 /* first some sanity checks */ 3138 /* first some sanity checks */
3152 3139
3153 if (!tty || !info->xmit.buf || !tmp_buf) 3140 if (!tty || !info->xmit.buf)
3154 return 0; 3141 return 0;
3155 3142
3156#ifdef SERIAL_DEBUG_DATA 3143#ifdef SERIAL_DEBUG_DATA
@@ -4106,7 +4093,6 @@ rs_open(struct tty_struct *tty, struct file * filp)
4106{ 4093{
4107 struct e100_serial *info; 4094 struct e100_serial *info;
4108 int retval; 4095 int retval;
4109 unsigned long page;
4110 int allocated_resources = 0; 4096 int allocated_resources = 0;
4111 4097
4112 info = rs_table + tty->index; 4098 info = rs_table + tty->index;
@@ -4124,17 +4110,6 @@ rs_open(struct tty_struct *tty, struct file * filp)
4124 4110
4125 tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY); 4111 tty->low_latency = !!(info->flags & ASYNC_LOW_LATENCY);
4126 4112
4127 if (!tmp_buf) {
4128 page = get_zeroed_page(GFP_KERNEL);
4129 if (!page) {
4130 return -ENOMEM;
4131 }
4132 if (tmp_buf)
4133 free_page(page);
4134 else
4135 tmp_buf = (unsigned char *) page;
4136 }
4137
4138 /* 4113 /*
4139 * If the port is in the middle of closing, bail out now 4114 * If the port is in the middle of closing, bail out now
4140 */ 4115 */
@@ -4487,6 +4462,7 @@ static int __init rs_init(void)
4487 info->enabled = 0; 4462 info->enabled = 0;
4488 } 4463 }
4489 } 4464 }
4465 tty_port_init(&info->port);
4490 info->uses_dma_in = 0; 4466 info->uses_dma_in = 0;
4491 info->uses_dma_out = 0; 4467 info->uses_dma_out = 0;
4492 info->line = i; 4468 info->line = i;
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index e8c9cee07d00..5410c0637266 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -12,10 +12,13 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/delay.h>
15#include <linux/serial_core.h> 16#include <linux/serial_core.h>
16#include <linux/serial_8250.h> 17#include <linux/serial_8250.h>
18#include <linux/serial_reg.h>
17#include <linux/of_address.h> 19#include <linux/of_address.h>
18#include <linux/of_irq.h> 20#include <linux/of_irq.h>
21#include <linux/of_serial.h>
19#include <linux/of_platform.h> 22#include <linux/of_platform.h>
20#include <linux/nwpserial.h> 23#include <linux/nwpserial.h>
21 24
@@ -24,6 +27,26 @@ struct of_serial_info {
24 int line; 27 int line;
25}; 28};
26 29
30#ifdef CONFIG_ARCH_TEGRA
31void tegra_serial_handle_break(struct uart_port *p)
32{
33 unsigned int status, tmout = 10000;
34
35 do {
36 status = p->serial_in(p, UART_LSR);
37 if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))
38 status = p->serial_in(p, UART_RX);
39 else
40 break;
41 if (--tmout == 0)
42 break;
43 udelay(1);
44 } while (1);
45}
46/* FIXME remove this export when tegra finishes conversion to open firmware */
47EXPORT_SYMBOL_GPL(tegra_serial_handle_break);
48#endif
49
27/* 50/*
28 * Fill a struct uart_port for a given device node 51 * Fill a struct uart_port for a given device node
29 */ 52 */
@@ -84,6 +107,9 @@ static int __devinit of_platform_serial_setup(struct platform_device *ofdev,
84 | UPF_FIXED_PORT | UPF_FIXED_TYPE; 107 | UPF_FIXED_PORT | UPF_FIXED_TYPE;
85 port->dev = &ofdev->dev; 108 port->dev = &ofdev->dev;
86 109
110 if (type == PORT_TEGRA)
111 port->handle_break = tegra_serial_handle_break;
112
87 return 0; 113 return 0;
88} 114}
89 115
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index d00b38eb268e..d3cda0cb2df0 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -44,6 +44,13 @@
44#include <plat/dmtimer.h> 44#include <plat/dmtimer.h>
45#include <plat/omap-serial.h> 45#include <plat/omap-serial.h>
46 46
47#define UART_BUILD_REVISION(x, y) (((x) << 8) | (y))
48
49#define OMAP_UART_REV_42 0x0402
50#define OMAP_UART_REV_46 0x0406
51#define OMAP_UART_REV_52 0x0502
52#define OMAP_UART_REV_63 0x0603
53
47#define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/ 54#define DEFAULT_CLK_SPEED 48000000 /* 48Mhz*/
48 55
49/* SCR register bitmasks */ 56/* SCR register bitmasks */
@@ -53,6 +60,17 @@
53#define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6 60#define OMAP_UART_FCR_RX_FIFO_TRIG_SHIFT 6
54#define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6) 61#define OMAP_UART_FCR_RX_FIFO_TRIG_MASK (0x3 << 6)
55 62
63/* MVR register bitmasks */
64#define OMAP_UART_MVR_SCHEME_SHIFT 30
65
66#define OMAP_UART_LEGACY_MVR_MAJ_MASK 0xf0
67#define OMAP_UART_LEGACY_MVR_MAJ_SHIFT 4
68#define OMAP_UART_LEGACY_MVR_MIN_MASK 0x0f
69
70#define OMAP_UART_MVR_MAJ_MASK 0x700
71#define OMAP_UART_MVR_MAJ_SHIFT 8
72#define OMAP_UART_MVR_MIN_MASK 0x3f
73
56static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS]; 74static struct uart_omap_port *ui[OMAP_MAX_HSUART_PORTS];
57 75
58/* Forward declaration of functions */ 76/* Forward declaration of functions */
@@ -1346,6 +1364,59 @@ static void uart_tx_dma_callback(int lch, u16 ch_status, void *data)
1346 return; 1364 return;
1347} 1365}
1348 1366
1367static void omap_serial_fill_features_erratas(struct uart_omap_port *up)
1368{
1369 u32 mvr, scheme;
1370 u16 revision, major, minor;
1371
1372 mvr = serial_in(up, UART_OMAP_MVER);
1373
1374 /* Check revision register scheme */
1375 scheme = mvr >> OMAP_UART_MVR_SCHEME_SHIFT;
1376
1377 switch (scheme) {
1378 case 0: /* Legacy Scheme: OMAP2/3 */
1379 /* MINOR_REV[0:4], MAJOR_REV[4:7] */
1380 major = (mvr & OMAP_UART_LEGACY_MVR_MAJ_MASK) >>
1381 OMAP_UART_LEGACY_MVR_MAJ_SHIFT;
1382 minor = (mvr & OMAP_UART_LEGACY_MVR_MIN_MASK);
1383 break;
1384 case 1:
1385 /* New Scheme: OMAP4+ */
1386 /* MINOR_REV[0:5], MAJOR_REV[8:10] */
1387 major = (mvr & OMAP_UART_MVR_MAJ_MASK) >>
1388 OMAP_UART_MVR_MAJ_SHIFT;
1389 minor = (mvr & OMAP_UART_MVR_MIN_MASK);
1390 break;
1391 default:
1392 dev_warn(&up->pdev->dev,
1393 "Unknown %s revision, defaulting to highest\n",
1394 up->name);
1395 /* highest possible revision */
1396 major = 0xff;
1397 minor = 0xff;
1398 }
1399
1400 /* normalize revision for the driver */
1401 revision = UART_BUILD_REVISION(major, minor);
1402
1403 switch (revision) {
1404 case OMAP_UART_REV_46:
1405 up->errata |= (UART_ERRATA_i202_MDR1_ACCESS |
1406 UART_ERRATA_i291_DMA_FORCEIDLE);
1407 break;
1408 case OMAP_UART_REV_52:
1409 up->errata |= (UART_ERRATA_i202_MDR1_ACCESS |
1410 UART_ERRATA_i291_DMA_FORCEIDLE);
1411 break;
1412 case OMAP_UART_REV_63:
1413 up->errata |= UART_ERRATA_i202_MDR1_ACCESS;
1414 break;
1415 default:
1416 break;
1417 }
1418}
1419
1349static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev) 1420static struct omap_uart_port_info *of_get_uart_port_info(struct device *dev)
1350{ 1421{
1351 struct omap_uart_port_info *omap_up_info; 1422 struct omap_uart_port_info *omap_up_info;
@@ -1439,7 +1510,6 @@ static int serial_omap_probe(struct platform_device *pdev)
1439 "%d\n", DEFAULT_CLK_SPEED); 1510 "%d\n", DEFAULT_CLK_SPEED);
1440 } 1511 }
1441 up->uart_dma.uart_base = mem->start; 1512 up->uart_dma.uart_base = mem->start;
1442 up->errata = omap_up_info->errata;
1443 1513
1444 if (omap_up_info->dma_enabled) { 1514 if (omap_up_info->dma_enabled) {
1445 up->uart_dma.uart_dma_tx = dma_tx->start; 1515 up->uart_dma.uart_dma_tx = dma_tx->start;
@@ -1469,6 +1539,8 @@ static int serial_omap_probe(struct platform_device *pdev)
1469 pm_runtime_enable(&pdev->dev); 1539 pm_runtime_enable(&pdev->dev);
1470 pm_runtime_get_sync(&pdev->dev); 1540 pm_runtime_get_sync(&pdev->dev);
1471 1541
1542 omap_serial_fill_features_erratas(up);
1543
1472 ui[up->port.line] = up; 1544 ui[up->port.line] = up;
1473 serial_omap_add_console_port(up); 1545 serial_omap_add_console_port(up);
1474 1546
diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index c2816f494807..4fdec6a6b758 100644
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -39,6 +39,7 @@ enum {
39 PCH_UART_HANDLED_RX_ERR_INT_SHIFT, 39 PCH_UART_HANDLED_RX_ERR_INT_SHIFT,
40 PCH_UART_HANDLED_RX_TRG_INT_SHIFT, 40 PCH_UART_HANDLED_RX_TRG_INT_SHIFT,
41 PCH_UART_HANDLED_MS_INT_SHIFT, 41 PCH_UART_HANDLED_MS_INT_SHIFT,
42 PCH_UART_HANDLED_LS_INT_SHIFT,
42}; 43};
43 44
44enum { 45enum {
@@ -63,6 +64,8 @@ enum {
63 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1)) 64 PCH_UART_HANDLED_RX_TRG_INT_SHIFT)<<1))
64#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1)) 65#define PCH_UART_HANDLED_MS_INT (1<<((PCH_UART_HANDLED_MS_INT_SHIFT)<<1))
65 66
67#define PCH_UART_HANDLED_LS_INT (1<<((PCH_UART_HANDLED_LS_INT_SHIFT)<<1))
68
66#define PCH_UART_RBR 0x00 69#define PCH_UART_RBR 0x00
67#define PCH_UART_THR 0x00 70#define PCH_UART_THR 0x00
68 71
@@ -229,7 +232,6 @@ struct eg20t_port {
229 int start_tx; 232 int start_tx;
230 int start_rx; 233 int start_rx;
231 int tx_empty; 234 int tx_empty;
232 int int_dis_flag;
233 int trigger; 235 int trigger;
234 int trigger_level; 236 int trigger_level;
235 struct pch_uart_buffer rxbuf; 237 struct pch_uart_buffer rxbuf;
@@ -237,7 +239,6 @@ struct eg20t_port {
237 unsigned int fcr; 239 unsigned int fcr;
238 unsigned int mcr; 240 unsigned int mcr;
239 unsigned int use_dma; 241 unsigned int use_dma;
240 unsigned int use_dma_flag;
241 struct dma_async_tx_descriptor *desc_tx; 242 struct dma_async_tx_descriptor *desc_tx;
242 struct dma_async_tx_descriptor *desc_rx; 243 struct dma_async_tx_descriptor *desc_rx;
243 struct pch_dma_slave param_tx; 244 struct pch_dma_slave param_tx;
@@ -560,14 +561,10 @@ static int pch_uart_hal_read(struct eg20t_port *priv, unsigned char *buf,
560 return i; 561 return i;
561} 562}
562 563
563static unsigned int pch_uart_hal_get_iid(struct eg20t_port *priv) 564static unsigned char pch_uart_hal_get_iid(struct eg20t_port *priv)
564{ 565{
565 unsigned int iir; 566 return ioread8(priv->membase + UART_IIR) &\
566 int ret; 567 (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP);
567
568 iir = ioread8(priv->membase + UART_IIR);
569 ret = (iir & (PCH_UART_IIR_IID | PCH_UART_IIR_TOI | PCH_UART_IIR_IP));
570 return ret;
571} 568}
572 569
573static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv) 570static u8 pch_uart_hal_get_line_status(struct eg20t_port *priv)
@@ -666,10 +663,13 @@ static void pch_free_dma(struct uart_port *port)
666 dma_release_channel(priv->chan_rx); 663 dma_release_channel(priv->chan_rx);
667 priv->chan_rx = NULL; 664 priv->chan_rx = NULL;
668 } 665 }
669 if (sg_dma_address(&priv->sg_rx)) 666
670 dma_free_coherent(port->dev, port->fifosize, 667 if (priv->rx_buf_dma) {
671 sg_virt(&priv->sg_rx), 668 dma_free_coherent(port->dev, port->fifosize, priv->rx_buf_virt,
672 sg_dma_address(&priv->sg_rx)); 669 priv->rx_buf_dma);
670 priv->rx_buf_virt = NULL;
671 priv->rx_buf_dma = 0;
672 }
673 673
674 return; 674 return;
675} 675}
@@ -1053,12 +1053,17 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1053 unsigned int handled; 1053 unsigned int handled;
1054 u8 lsr; 1054 u8 lsr;
1055 int ret = 0; 1055 int ret = 0;
1056 unsigned int iid; 1056 unsigned char iid;
1057 unsigned long flags; 1057 unsigned long flags;
1058 int next = 1;
1059 u8 msr;
1058 1060
1059 spin_lock_irqsave(&priv->port.lock, flags); 1061 spin_lock_irqsave(&priv->port.lock, flags);
1060 handled = 0; 1062 handled = 0;
1061 while ((iid = pch_uart_hal_get_iid(priv)) > 1) { 1063 while (next) {
1064 iid = pch_uart_hal_get_iid(priv);
1065 if (iid & PCH_UART_IIR_IP) /* No Interrupt */
1066 break;
1062 switch (iid) { 1067 switch (iid) {
1063 case PCH_UART_IID_RLS: /* Receiver Line Status */ 1068 case PCH_UART_IID_RLS: /* Receiver Line Status */
1064 lsr = pch_uart_hal_get_line_status(priv); 1069 lsr = pch_uart_hal_get_line_status(priv);
@@ -1066,6 +1071,8 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1066 UART_LSR_PE | UART_LSR_OE)) { 1071 UART_LSR_PE | UART_LSR_OE)) {
1067 pch_uart_err_ir(priv, lsr); 1072 pch_uart_err_ir(priv, lsr);
1068 ret = PCH_UART_HANDLED_RX_ERR_INT; 1073 ret = PCH_UART_HANDLED_RX_ERR_INT;
1074 } else {
1075 ret = PCH_UART_HANDLED_LS_INT;
1069 } 1076 }
1070 break; 1077 break;
1071 case PCH_UART_IID_RDR: /* Received Data Ready */ 1078 case PCH_UART_IID_RDR: /* Received Data Ready */
@@ -1092,20 +1099,22 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
1092 ret = handle_tx(priv); 1099 ret = handle_tx(priv);
1093 break; 1100 break;
1094 case PCH_UART_IID_MS: /* Modem Status */ 1101 case PCH_UART_IID_MS: /* Modem Status */
1095 ret = PCH_UART_HANDLED_MS_INT; 1102 msr = pch_uart_hal_get_modem(priv);
1103 next = 0; /* MS ir prioirty is the lowest. So, MS ir
1104 means final interrupt */
1105 if ((msr & UART_MSR_ANY_DELTA) == 0)
1106 break;
1107 ret |= PCH_UART_HANDLED_MS_INT;
1096 break; 1108 break;
1097 default: /* Never junp to this label */ 1109 default: /* Never junp to this label */
1098 dev_err(priv->port.dev, "%s:iid=%d (%lu)\n", __func__, 1110 dev_err(priv->port.dev, "%s:iid=%02x (%lu)\n", __func__,
1099 iid, jiffies); 1111 iid, jiffies);
1100 ret = -1; 1112 ret = -1;
1113 next = 0;
1101 break; 1114 break;
1102 } 1115 }
1103 handled |= (unsigned int)ret; 1116 handled |= (unsigned int)ret;
1104 } 1117 }
1105 if (handled == 0 && iid <= 1) {
1106 if (priv->int_dis_flag)
1107 priv->int_dis_flag = 0;
1108 }
1109 1118
1110 spin_unlock_irqrestore(&priv->port.lock, flags); 1119 spin_unlock_irqrestore(&priv->port.lock, flags);
1111 return IRQ_RETVAL(handled); 1120 return IRQ_RETVAL(handled);
@@ -1200,7 +1209,6 @@ static void pch_uart_stop_rx(struct uart_port *port)
1200 priv = container_of(port, struct eg20t_port, port); 1209 priv = container_of(port, struct eg20t_port, port);
1201 priv->start_rx = 0; 1210 priv->start_rx = 0;
1202 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT); 1211 pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
1203 priv->int_dis_flag = 1;
1204} 1212}
1205 1213
1206/* Enable the modem status interrupts. */ 1214/* Enable the modem status interrupts. */
@@ -1447,7 +1455,6 @@ static int pch_uart_verify_port(struct uart_port *port,
1447 __func__); 1455 __func__);
1448 return -EOPNOTSUPP; 1456 return -EOPNOTSUPP;
1449#endif 1457#endif
1450 priv->use_dma_flag = 1;
1451 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n"); 1458 dev_info(priv->port.dev, "PCH UART : Use DMA Mode\n");
1452 if (!priv->use_dma) 1459 if (!priv->use_dma)
1453 pch_request_dma(port); 1460 pch_request_dma(port);
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 6c9b7cd6778a..91e326ffe7db 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -185,25 +185,19 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
185 /* Should possibly check if this fails for the largest buffer we 185 /* Should possibly check if this fails for the largest buffer we
186 have queued and recycle that ? */ 186 have queued and recycle that ? */
187} 187}
188
189/** 188/**
190 * tty_buffer_request_room - grow tty buffer if needed 189 * __tty_buffer_request_room - grow tty buffer if needed
191 * @tty: tty structure 190 * @tty: tty structure
192 * @size: size desired 191 * @size: size desired
193 * 192 *
194 * Make at least size bytes of linear space available for the tty 193 * Make at least size bytes of linear space available for the tty
195 * buffer. If we fail return the size we managed to find. 194 * buffer. If we fail return the size we managed to find.
196 * 195 * Locking: Caller must hold tty->buf.lock
197 * Locking: Takes tty->buf.lock
198 */ 196 */
199int tty_buffer_request_room(struct tty_struct *tty, size_t size) 197static int __tty_buffer_request_room(struct tty_struct *tty, size_t size)
200{ 198{
201 struct tty_buffer *b, *n; 199 struct tty_buffer *b, *n;
202 int left; 200 int left;
203 unsigned long flags;
204
205 spin_lock_irqsave(&tty->buf.lock, flags);
206
207 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to 201 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
208 remove this conditional if its worth it. This would be invisible 202 remove this conditional if its worth it. This would be invisible
209 to the callers */ 203 to the callers */
@@ -225,9 +219,30 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
225 size = left; 219 size = left;
226 } 220 }
227 221
228 spin_unlock_irqrestore(&tty->buf.lock, flags);
229 return size; 222 return size;
230} 223}
224
225
226/**
227 * tty_buffer_request_room - grow tty buffer if needed
228 * @tty: tty structure
229 * @size: size desired
230 *
231 * Make at least size bytes of linear space available for the tty
232 * buffer. If we fail return the size we managed to find.
233 *
234 * Locking: Takes tty->buf.lock
235 */
236int tty_buffer_request_room(struct tty_struct *tty, size_t size)
237{
238 unsigned long flags;
239 int length;
240
241 spin_lock_irqsave(&tty->buf.lock, flags);
242 length = __tty_buffer_request_room(tty, size);
243 spin_unlock_irqrestore(&tty->buf.lock, flags);
244 return length;
245}
231EXPORT_SYMBOL_GPL(tty_buffer_request_room); 246EXPORT_SYMBOL_GPL(tty_buffer_request_room);
232 247
233/** 248/**
@@ -249,14 +264,22 @@ int tty_insert_flip_string_fixed_flag(struct tty_struct *tty,
249 int copied = 0; 264 int copied = 0;
250 do { 265 do {
251 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 266 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
252 int space = tty_buffer_request_room(tty, goal); 267 int space;
253 struct tty_buffer *tb = tty->buf.tail; 268 unsigned long flags;
269 struct tty_buffer *tb;
270
271 spin_lock_irqsave(&tty->buf.lock, flags);
272 space = __tty_buffer_request_room(tty, goal);
273 tb = tty->buf.tail;
254 /* If there is no space then tb may be NULL */ 274 /* If there is no space then tb may be NULL */
255 if (unlikely(space == 0)) 275 if (unlikely(space == 0)) {
276 spin_unlock_irqrestore(&tty->buf.lock, flags);
256 break; 277 break;
278 }
257 memcpy(tb->char_buf_ptr + tb->used, chars, space); 279 memcpy(tb->char_buf_ptr + tb->used, chars, space);
258 memset(tb->flag_buf_ptr + tb->used, flag, space); 280 memset(tb->flag_buf_ptr + tb->used, flag, space);
259 tb->used += space; 281 tb->used += space;
282 spin_unlock_irqrestore(&tty->buf.lock, flags);
260 copied += space; 283 copied += space;
261 chars += space; 284 chars += space;
262 /* There is a small chance that we need to split the data over 285 /* There is a small chance that we need to split the data over
@@ -286,14 +309,22 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
286 int copied = 0; 309 int copied = 0;
287 do { 310 do {
288 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 311 int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE);
289 int space = tty_buffer_request_room(tty, goal); 312 int space;
290 struct tty_buffer *tb = tty->buf.tail; 313 unsigned long __flags;
314 struct tty_buffer *tb;
315
316 spin_lock_irqsave(&tty->buf.lock, __flags);
317 space = __tty_buffer_request_room(tty, goal);
318 tb = tty->buf.tail;
291 /* If there is no space then tb may be NULL */ 319 /* If there is no space then tb may be NULL */
292 if (unlikely(space == 0)) 320 if (unlikely(space == 0)) {
321 spin_unlock_irqrestore(&tty->buf.lock, __flags);
293 break; 322 break;
323 }
294 memcpy(tb->char_buf_ptr + tb->used, chars, space); 324 memcpy(tb->char_buf_ptr + tb->used, chars, space);
295 memcpy(tb->flag_buf_ptr + tb->used, flags, space); 325 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
296 tb->used += space; 326 tb->used += space;
327 spin_unlock_irqrestore(&tty->buf.lock, __flags);
297 copied += space; 328 copied += space;
298 chars += space; 329 chars += space;
299 flags += space; 330 flags += space;
@@ -344,13 +375,20 @@ EXPORT_SYMBOL(tty_schedule_flip);
344int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, 375int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
345 size_t size) 376 size_t size)
346{ 377{
347 int space = tty_buffer_request_room(tty, size); 378 int space;
379 unsigned long flags;
380 struct tty_buffer *tb;
381
382 spin_lock_irqsave(&tty->buf.lock, flags);
383 space = __tty_buffer_request_room(tty, size);
384
385 tb = tty->buf.tail;
348 if (likely(space)) { 386 if (likely(space)) {
349 struct tty_buffer *tb = tty->buf.tail;
350 *chars = tb->char_buf_ptr + tb->used; 387 *chars = tb->char_buf_ptr + tb->used;
351 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space); 388 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
352 tb->used += space; 389 tb->used += space;
353 } 390 }
391 spin_unlock_irqrestore(&tty->buf.lock, flags);
354 return space; 392 return space;
355} 393}
356EXPORT_SYMBOL_GPL(tty_prepare_flip_string); 394EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
@@ -374,13 +412,20 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
374int tty_prepare_flip_string_flags(struct tty_struct *tty, 412int tty_prepare_flip_string_flags(struct tty_struct *tty,
375 unsigned char **chars, char **flags, size_t size) 413 unsigned char **chars, char **flags, size_t size)
376{ 414{
377 int space = tty_buffer_request_room(tty, size); 415 int space;
416 unsigned long __flags;
417 struct tty_buffer *tb;
418
419 spin_lock_irqsave(&tty->buf.lock, __flags);
420 space = __tty_buffer_request_room(tty, size);
421
422 tb = tty->buf.tail;
378 if (likely(space)) { 423 if (likely(space)) {
379 struct tty_buffer *tb = tty->buf.tail;
380 *chars = tb->char_buf_ptr + tb->used; 424 *chars = tb->char_buf_ptr + tb->used;
381 *flags = tb->flag_buf_ptr + tb->used; 425 *flags = tb->flag_buf_ptr + tb->used;
382 tb->used += space; 426 tb->used += space;
383 } 427 }
428 spin_unlock_irqrestore(&tty->buf.lock, __flags);
384 return space; 429 return space;
385} 430}
386EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); 431EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 2156188db4a6..84cbf298c094 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3892,36 +3892,6 @@ static void set_palette(struct vc_data *vc)
3892 vc->vc_sw->con_set_palette(vc, color_table); 3892 vc->vc_sw->con_set_palette(vc, color_table);
3893} 3893}
3894 3894
3895static int set_get_cmap(unsigned char __user *arg, int set)
3896{
3897 int i, j, k;
3898
3899 WARN_CONSOLE_UNLOCKED();
3900
3901 for (i = 0; i < 16; i++)
3902 if (set) {
3903 get_user(default_red[i], arg++);
3904 get_user(default_grn[i], arg++);
3905 get_user(default_blu[i], arg++);
3906 } else {
3907 put_user(default_red[i], arg++);
3908 put_user(default_grn[i], arg++);
3909 put_user(default_blu[i], arg++);
3910 }
3911 if (set) {
3912 for (i = 0; i < MAX_NR_CONSOLES; i++)
3913 if (vc_cons_allocated(i)) {
3914 for (j = k = 0; j < 16; j++) {
3915 vc_cons[i].d->vc_palette[k++] = default_red[j];
3916 vc_cons[i].d->vc_palette[k++] = default_grn[j];
3917 vc_cons[i].d->vc_palette[k++] = default_blu[j];
3918 }
3919 set_palette(vc_cons[i].d);
3920 }
3921 }
3922 return 0;
3923}
3924
3925/* 3895/*
3926 * Load palette into the DAC registers. arg points to a colour 3896 * Load palette into the DAC registers. arg points to a colour
3927 * map, 3 bytes per colour, 16 colours, range from 0 to 255. 3897 * map, 3 bytes per colour, 16 colours, range from 0 to 255.
@@ -3929,24 +3899,50 @@ static int set_get_cmap(unsigned char __user *arg, int set)
3929 3899
3930int con_set_cmap(unsigned char __user *arg) 3900int con_set_cmap(unsigned char __user *arg)
3931{ 3901{
3932 int rc; 3902 int i, j, k;
3903 unsigned char colormap[3*16];
3904
3905 if (copy_from_user(colormap, arg, sizeof(colormap)))
3906 return -EFAULT;
3933 3907
3934 console_lock(); 3908 console_lock();
3935 rc = set_get_cmap (arg,1); 3909 for (i = k = 0; i < 16; i++) {
3910 default_red[i] = colormap[k++];
3911 default_grn[i] = colormap[k++];
3912 default_blu[i] = colormap[k++];
3913 }
3914 for (i = 0; i < MAX_NR_CONSOLES; i++) {
3915 if (!vc_cons_allocated(i))
3916 continue;
3917 for (j = k = 0; j < 16; j++) {
3918 vc_cons[i].d->vc_palette[k++] = default_red[j];
3919 vc_cons[i].d->vc_palette[k++] = default_grn[j];
3920 vc_cons[i].d->vc_palette[k++] = default_blu[j];
3921 }
3922 set_palette(vc_cons[i].d);
3923 }
3936 console_unlock(); 3924 console_unlock();
3937 3925
3938 return rc; 3926 return 0;
3939} 3927}
3940 3928
3941int con_get_cmap(unsigned char __user *arg) 3929int con_get_cmap(unsigned char __user *arg)
3942{ 3930{
3943 int rc; 3931 int i, k;
3932 unsigned char colormap[3*16];
3944 3933
3945 console_lock(); 3934 console_lock();
3946 rc = set_get_cmap (arg,0); 3935 for (i = k = 0; i < 16; i++) {
3936 colormap[k++] = default_red[i];
3937 colormap[k++] = default_grn[i];
3938 colormap[k++] = default_blu[i];
3939 }
3947 console_unlock(); 3940 console_unlock();
3948 3941
3949 return rc; 3942 if (copy_to_user(arg, colormap, sizeof(colormap)))
3943 return -EFAULT;
3944
3945 return 0;
3950} 3946}
3951 3947
3952void reset_palette(struct vc_data *vc) 3948void reset_palette(struct vc_data *vc)
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 6c23938d2711..71ecae743cd2 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -94,17 +94,14 @@ struct gs_buf {
94 * (and thus for each /dev/ node). 94 * (and thus for each /dev/ node).
95 */ 95 */
96struct gs_port { 96struct gs_port {
97 struct tty_port port;
97 spinlock_t port_lock; /* guard port_* access */ 98 spinlock_t port_lock; /* guard port_* access */
98 99
99 struct gserial *port_usb; 100 struct gserial *port_usb;
100 struct tty_struct *port_tty;
101 101
102 unsigned open_count;
103 bool openclose; /* open/close in progress */ 102 bool openclose; /* open/close in progress */
104 u8 port_num; 103 u8 port_num;
105 104
106 wait_queue_head_t close_wait; /* wait for last close */
107
108 struct list_head read_pool; 105 struct list_head read_pool;
109 int read_started; 106 int read_started;
110 int read_allocated; 107 int read_allocated;
@@ -412,8 +409,8 @@ __acquires(&port->port_lock)
412 break; 409 break;
413 } 410 }
414 411
415 if (do_tty_wake && port->port_tty) 412 if (do_tty_wake && port->port.tty)
416 tty_wakeup(port->port_tty); 413 tty_wakeup(port->port.tty);
417 return status; 414 return status;
418} 415}
419 416
@@ -435,7 +432,7 @@ __acquires(&port->port_lock)
435 struct tty_struct *tty; 432 struct tty_struct *tty;
436 433
437 /* no more rx if closed */ 434 /* no more rx if closed */
438 tty = port->port_tty; 435 tty = port->port.tty;
439 if (!tty) 436 if (!tty)
440 break; 437 break;
441 438
@@ -488,7 +485,7 @@ static void gs_rx_push(unsigned long _port)
488 485
489 /* hand any queued data to the tty */ 486 /* hand any queued data to the tty */
490 spin_lock_irq(&port->port_lock); 487 spin_lock_irq(&port->port_lock);
491 tty = port->port_tty; 488 tty = port->port.tty;
492 while (!list_empty(queue)) { 489 while (!list_empty(queue)) {
493 struct usb_request *req; 490 struct usb_request *req;
494 491
@@ -699,7 +696,7 @@ static int gs_start_io(struct gs_port *port)
699 696
700 /* unblock any pending writes into our circular buffer */ 697 /* unblock any pending writes into our circular buffer */
701 if (started) { 698 if (started) {
702 tty_wakeup(port->port_tty); 699 tty_wakeup(port->port.tty);
703 } else { 700 } else {
704 gs_free_requests(ep, head, &port->read_allocated); 701 gs_free_requests(ep, head, &port->read_allocated);
705 gs_free_requests(port->port_usb->in, &port->write_pool, 702 gs_free_requests(port->port_usb->in, &port->write_pool,
@@ -734,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
734 spin_lock_irq(&port->port_lock); 731 spin_lock_irq(&port->port_lock);
735 732
736 /* already open? Great. */ 733 /* already open? Great. */
737 if (port->open_count) { 734 if (port->port.count) {
738 status = 0; 735 status = 0;
739 port->open_count++; 736 port->port.count++;
740 737
741 /* currently opening/closing? wait ... */ 738 /* currently opening/closing? wait ... */
742 } else if (port->openclose) { 739 } else if (port->openclose) {
@@ -793,9 +790,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
793 /* REVISIT maybe wait for "carrier detect" */ 790 /* REVISIT maybe wait for "carrier detect" */
794 791
795 tty->driver_data = port; 792 tty->driver_data = port;
796 port->port_tty = tty; 793 port->port.tty = tty;
797 794
798 port->open_count = 1; 795 port->port.count = 1;
799 port->openclose = false; 796 port->openclose = false;
800 797
801 /* if connected, start the I/O stream */ 798 /* if connected, start the I/O stream */
@@ -837,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
837 834
838 spin_lock_irq(&port->port_lock); 835 spin_lock_irq(&port->port_lock);
839 836
840 if (port->open_count != 1) { 837 if (port->port.count != 1) {
841 if (port->open_count == 0) 838 if (port->port.count == 0)
842 WARN_ON(1); 839 WARN_ON(1);
843 else 840 else
844 --port->open_count; 841 --port->port.count;
845 goto exit; 842 goto exit;
846 } 843 }
847 844
@@ -851,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
851 * and sleep if necessary 848 * and sleep if necessary
852 */ 849 */
853 port->openclose = true; 850 port->openclose = true;
854 port->open_count = 0; 851 port->port.count = 0;
855 852
856 gser = port->port_usb; 853 gser = port->port_usb;
857 if (gser && gser->disconnect) 854 if (gser && gser->disconnect)
@@ -879,14 +876,14 @@ static void gs_close(struct tty_struct *tty, struct file *file)
879 gs_buf_clear(&port->port_write_buf); 876 gs_buf_clear(&port->port_write_buf);
880 877
881 tty->driver_data = NULL; 878 tty->driver_data = NULL;
882 port->port_tty = NULL; 879 port->port.tty = NULL;
883 880
884 port->openclose = false; 881 port->openclose = false;
885 882
886 pr_debug("gs_close: ttyGS%d (%p,%p) done!\n", 883 pr_debug("gs_close: ttyGS%d (%p,%p) done!\n",
887 port->port_num, tty, file); 884 port->port_num, tty, file);
888 885
889 wake_up_interruptible(&port->close_wait); 886 wake_up_interruptible(&port->port.close_wait);
890exit: 887exit:
891 spin_unlock_irq(&port->port_lock); 888 spin_unlock_irq(&port->port_lock);
892} 889}
@@ -1034,8 +1031,8 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
1034 if (port == NULL) 1031 if (port == NULL)
1035 return -ENOMEM; 1032 return -ENOMEM;
1036 1033
1034 tty_port_init(&port->port);
1037 spin_lock_init(&port->port_lock); 1035 spin_lock_init(&port->port_lock);
1038 init_waitqueue_head(&port->close_wait);
1039 init_waitqueue_head(&port->drain_wait); 1036 init_waitqueue_head(&port->drain_wait);
1040 1037
1041 tasklet_init(&port->push, gs_rx_push, (unsigned long) port); 1038 tasklet_init(&port->push, gs_rx_push, (unsigned long) port);
@@ -1155,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
1155 int cond; 1152 int cond;
1156 1153
1157 spin_lock_irq(&port->port_lock); 1154 spin_lock_irq(&port->port_lock);
1158 cond = (port->open_count == 0) && !port->openclose; 1155 cond = (port->port.count == 0) && !port->openclose;
1159 spin_unlock_irq(&port->port_lock); 1156 spin_unlock_irq(&port->port_lock);
1160 return cond; 1157 return cond;
1161} 1158}
@@ -1194,7 +1191,7 @@ void gserial_cleanup(void)
1194 tasklet_kill(&port->push); 1191 tasklet_kill(&port->push);
1195 1192
1196 /* wait for old opens to finish */ 1193 /* wait for old opens to finish */
1197 wait_event(port->close_wait, gs_closed(port)); 1194 wait_event(port->port.close_wait, gs_closed(port));
1198 1195
1199 WARN_ON(port->port_usb != NULL); 1196 WARN_ON(port->port_usb != NULL);
1200 1197
@@ -1268,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
1268 /* if it's already open, start I/O ... and notify the serial 1265 /* if it's already open, start I/O ... and notify the serial
1269 * protocol about open/close status (connect/disconnect). 1266 * protocol about open/close status (connect/disconnect).
1270 */ 1267 */
1271 if (port->open_count) { 1268 if (port->port.count) {
1272 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); 1269 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
1273 gs_start_io(port); 1270 gs_start_io(port);
1274 if (gser->connect) 1271 if (gser->connect)
@@ -1315,10 +1312,10 @@ void gserial_disconnect(struct gserial *gser)
1315 1312
1316 port->port_usb = NULL; 1313 port->port_usb = NULL;
1317 gser->ioport = NULL; 1314 gser->ioport = NULL;
1318 if (port->open_count > 0 || port->openclose) { 1315 if (port->port.count > 0 || port->openclose) {
1319 wake_up_interruptible(&port->drain_wait); 1316 wake_up_interruptible(&port->drain_wait);
1320 if (port->port_tty) 1317 if (port->port.tty)
1321 tty_hangup(port->port_tty); 1318 tty_hangup(port->port.tty);
1322 } 1319 }
1323 spin_unlock_irqrestore(&port->port_lock, flags); 1320 spin_unlock_irqrestore(&port->port_lock, flags);
1324 1321
@@ -1331,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
1331 1328
1332 /* finally, free any unused/unusable I/O buffers */ 1329 /* finally, free any unused/unusable I/O buffers */
1333 spin_lock_irqsave(&port->port_lock, flags); 1330 spin_lock_irqsave(&port->port_lock, flags);
1334 if (port->open_count == 0 && !port->openclose) 1331 if (port->port.count == 0 && !port->openclose)
1335 gs_buf_free(&port->port_write_buf); 1332 gs_buf_free(&port->port_write_buf);
1336 gs_free_requests(gser->out, &port->read_pool, NULL); 1333 gs_free_requests(gser->out, &port->read_pool, NULL);
1337 gs_free_requests(gser->out, &port->read_queue, NULL); 1334 gs_free_requests(gser->out, &port->read_queue, NULL);
diff --git a/include/linux/generic_serial.h b/include/linux/generic_serial.h
index fadff28505bb..79b3eb37243a 100644
--- a/include/linux/generic_serial.h
+++ b/include/linux/generic_serial.h
@@ -4,7 +4,6 @@
4 * Copyright (C) 1998 R.E.Wolff@BitWizard.nl 4 * Copyright (C) 1998 R.E.Wolff@BitWizard.nl
5 * 5 *
6 * written for the SX serial driver. 6 * written for the SX serial driver.
7 * Contains the code that should be shared over all the serial drivers.
8 * 7 *
9 * Version 0.1 -- December, 1998. 8 * Version 0.1 -- December, 1998.
10 */ 9 */
@@ -12,45 +11,8 @@
12#ifndef GENERIC_SERIAL_H 11#ifndef GENERIC_SERIAL_H
13#define GENERIC_SERIAL_H 12#define GENERIC_SERIAL_H
14 13
15#ifdef __KERNEL__ 14#warning Use of this header is deprecated.
16#include <linux/mutex.h> 15#warning Since nobody sets the constants defined here for you, you should not, in any case, use them. Including the header is thus pointless.
17#include <linux/tty.h>
18
19struct real_driver {
20 void (*disable_tx_interrupts) (void *);
21 void (*enable_tx_interrupts) (void *);
22 void (*disable_rx_interrupts) (void *);
23 void (*enable_rx_interrupts) (void *);
24 void (*shutdown_port) (void*);
25 int (*set_real_termios) (void*);
26 int (*chars_in_buffer) (void*);
27 void (*close) (void*);
28 void (*hungup) (void*);
29 void (*getserial) (void*, struct serial_struct *sp);
30};
31
32
33
34struct gs_port {
35 int magic;
36 struct tty_port port;
37 unsigned char *xmit_buf;
38 int xmit_head;
39 int xmit_tail;
40 int xmit_cnt;
41 struct mutex port_write_mutex;
42 unsigned long event;
43 unsigned short closing_wait;
44 int close_delay;
45 struct real_driver *rd;
46 int wakeup_chars;
47 int baud_base;
48 int baud;
49 int custom_divisor;
50 spinlock_t driver_lock;
51};
52
53#endif /* __KERNEL__ */
54 16
55/* Flags */ 17/* Flags */
56/* Warning: serial.h defines some ASYNC_ flags, they say they are "only" 18/* Warning: serial.h defines some ASYNC_ flags, they say they are "only"
@@ -60,8 +22,6 @@ struct gs_port {
60#define GS_RX_INTEN 0x00400000 22#define GS_RX_INTEN 0x00400000
61#define GS_ACTIVE 0x00200000 23#define GS_ACTIVE 0x00200000
62 24
63
64
65#define GS_TYPE_NORMAL 1 25#define GS_TYPE_NORMAL 1
66 26
67#define GS_DEBUG_FLUSH 0x00000001 27#define GS_DEBUG_FLUSH 0x00000001
@@ -72,24 +32,4 @@ struct gs_port {
72#define GS_DEBUG_FLOW 0x00000020 32#define GS_DEBUG_FLOW 0x00000020
73#define GS_DEBUG_WRITE 0x00000040 33#define GS_DEBUG_WRITE 0x00000040
74 34
75#ifdef __KERNEL__
76int gs_put_char(struct tty_struct *tty, unsigned char ch);
77int gs_write(struct tty_struct *tty,
78 const unsigned char *buf, int count);
79int gs_write_room(struct tty_struct *tty);
80int gs_chars_in_buffer(struct tty_struct *tty);
81void gs_flush_buffer(struct tty_struct *tty);
82void gs_flush_chars(struct tty_struct *tty);
83void gs_stop(struct tty_struct *tty);
84void gs_start(struct tty_struct *tty);
85void gs_hangup(struct tty_struct *tty);
86int gs_block_til_ready(void *port, struct file *filp);
87void gs_close(struct tty_struct *tty, struct file *filp);
88void gs_set_termios (struct tty_struct * tty,
89 struct ktermios * old_termios);
90int gs_init_port(struct gs_port *port);
91int gs_setserial(struct gs_port *port, struct serial_struct __user *sp);
92int gs_getserial(struct gs_port *port, struct serial_struct __user *sp);
93void gs_got_break(struct gs_port *port);
94#endif /* __KERNEL__ */
95#endif 35#endif
diff --git a/include/linux/isdn.h b/include/linux/isdn.h
index 292f27a793d4..215c41602af8 100644
--- a/include/linux/isdn.h
+++ b/include/linux/isdn.h
@@ -15,6 +15,7 @@
15#define __ISDN_H__ 15#define __ISDN_H__
16 16
17#include <linux/ioctl.h> 17#include <linux/ioctl.h>
18#include <linux/tty.h>
18 19
19#define ISDN_MAX_DRIVERS 32 20#define ISDN_MAX_DRIVERS 32
20#define ISDN_MAX_CHANNELS 64 21#define ISDN_MAX_CHANNELS 64
@@ -392,21 +393,8 @@ typedef struct isdn_net_dev_s {
392/*======================= Start of ISDN-tty stuff ===========================*/ 393/*======================= Start of ISDN-tty stuff ===========================*/
393 394
394#define ISDN_ASYNC_MAGIC 0x49344C01 /* for paranoia-checking */ 395#define ISDN_ASYNC_MAGIC 0x49344C01 /* for paranoia-checking */
395#define ISDN_ASYNC_INITIALIZED 0x80000000 /* port was initialized */
396#define ISDN_ASYNC_CALLOUT_ACTIVE 0x40000000 /* Call out device active */
397#define ISDN_ASYNC_NORMAL_ACTIVE 0x20000000 /* Normal device active */
398#define ISDN_ASYNC_CLOSING 0x08000000 /* Serial port is closing */
399#define ISDN_ASYNC_CTS_FLOW 0x04000000 /* Do CTS flow control */
400#define ISDN_ASYNC_CHECK_CD 0x02000000 /* i.e., CLOCAL */
401#define ISDN_ASYNC_HUP_NOTIFY 0x0001 /* Notify tty on hangups/closes */
402#define ISDN_ASYNC_SESSION_LOCKOUT 0x0100 /* Lock cua opens on session */
403#define ISDN_ASYNC_PGRP_LOCKOUT 0x0200 /* Lock cua opens on pgrp */
404#define ISDN_ASYNC_CALLOUT_NOHUP 0x0400 /* No hangup for cui */
405#define ISDN_ASYNC_SPLIT_TERMIOS 0x0008 /* Sep. termios for dialin/out */
406#define ISDN_SERIAL_XMIT_SIZE 1024 /* Default bufsize for write */ 396#define ISDN_SERIAL_XMIT_SIZE 1024 /* Default bufsize for write */
407#define ISDN_SERIAL_XMIT_MAX 4000 /* Maximum bufsize for write */ 397#define ISDN_SERIAL_XMIT_MAX 4000 /* Maximum bufsize for write */
408#define ISDN_SERIAL_TYPE_NORMAL 1
409#define ISDN_SERIAL_TYPE_CALLOUT 2
410 398
411#ifdef CONFIG_ISDN_AUDIO 399#ifdef CONFIG_ISDN_AUDIO
412/* For using sk_buffs with audio we need some private variables 400/* For using sk_buffs with audio we need some private variables
@@ -448,17 +436,12 @@ typedef struct atemu {
448/* Private data (similar to async_struct in <linux/serial.h>) */ 436/* Private data (similar to async_struct in <linux/serial.h>) */
449typedef struct modem_info { 437typedef struct modem_info {
450 int magic; 438 int magic;
451 struct module *owner; 439 struct tty_port port;
452 int flags; /* defined in tty.h */
453 int x_char; /* xon/xoff character */ 440 int x_char; /* xon/xoff character */
454 int mcr; /* Modem control register */ 441 int mcr; /* Modem control register */
455 int msr; /* Modem status register */ 442 int msr; /* Modem status register */
456 int lsr; /* Line status register */ 443 int lsr; /* Line status register */
457 int line; 444 int line;
458 int count; /* # of fd on device */
459 int blocked_open; /* # of blocked opens */
460 long session; /* Session of opening process */
461 long pgrp; /* pgrp of opening process */
462 int online; /* 1 = B-Channel is up, drop data */ 445 int online; /* 1 = B-Channel is up, drop data */
463 /* 2 = B-Channel is up, deliver d.*/ 446 /* 2 = B-Channel is up, deliver d.*/
464 int dialing; /* Dial in progress or ATA */ 447 int dialing; /* Dial in progress or ATA */
@@ -478,7 +461,6 @@ typedef struct modem_info {
478 int send_outstanding;/* # of outstanding send-requests */ 461 int send_outstanding;/* # of outstanding send-requests */
479 int xmit_size; /* max. # of chars in xmit_buf */ 462 int xmit_size; /* max. # of chars in xmit_buf */
480 int xmit_count; /* # of chars in xmit_buf */ 463 int xmit_count; /* # of chars in xmit_buf */
481 unsigned char *xmit_buf; /* transmit buffer */
482 struct sk_buff_head xmit_queue; /* transmit queue */ 464 struct sk_buff_head xmit_queue; /* transmit queue */
483 atomic_t xmit_lock; /* Semaphore for isdn_tty_write */ 465 atomic_t xmit_lock; /* Semaphore for isdn_tty_write */
484#ifdef CONFIG_ISDN_AUDIO 466#ifdef CONFIG_ISDN_AUDIO
@@ -496,11 +478,7 @@ typedef struct modem_info {
496 struct T30_s *fax; /* T30 Fax Group 3 data/interface */ 478 struct T30_s *fax; /* T30 Fax Group 3 data/interface */
497 int faxonline; /* Fax-channel status */ 479 int faxonline; /* Fax-channel status */
498#endif 480#endif
499 struct tty_struct *tty; /* Pointer to corresponding tty */
500 atemu emu; /* AT-emulator data */ 481 atemu emu; /* AT-emulator data */
501 struct ktermios normal_termios; /* For saving termios structs */
502 struct ktermios callout_termios;
503 wait_queue_head_t open_wait, close_wait;
504 spinlock_t readlock; 482 spinlock_t readlock;
505} modem_info; 483} modem_info;
506 484
diff --git a/include/linux/of_serial.h b/include/linux/of_serial.h
new file mode 100644
index 000000000000..4a73ed80b4c0
--- /dev/null
+++ b/include/linux/of_serial.h
@@ -0,0 +1,17 @@
1#ifndef __LINUX_OF_SERIAL_H
2#define __LINUX_OF_SERIAL_H
3
4/*
5 * FIXME remove this file when tegra finishes conversion to open firmware,
6 * expectation is that all quirks will then be self-contained in
7 * drivers/tty/serial/of_serial.c.
8 */
9#ifdef CONFIG_ARCH_TEGRA
10extern void tegra_serial_handle_break(struct uart_port *port);
11#else
12static inline void tegra_serial_handle_break(struct uart_port *port)
13{
14}
15#endif
16
17#endif /* __LINUX_OF_SERIAL */
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index 8f012f8ac8e9..a522fd977aad 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -38,6 +38,7 @@ struct plat_serial8250_port {
38 int (*handle_irq)(struct uart_port *); 38 int (*handle_irq)(struct uart_port *);
39 void (*pm)(struct uart_port *, unsigned int state, 39 void (*pm)(struct uart_port *, unsigned int state,
40 unsigned old); 40 unsigned old);
41 void (*handle_break)(struct uart_port *);
41}; 42};
42 43
43/* 44/*
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 2db407a40051..65db9928e15f 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -310,6 +310,7 @@ struct uart_port {
310 int (*handle_irq)(struct uart_port *); 310 int (*handle_irq)(struct uart_port *);
311 void (*pm)(struct uart_port *, unsigned int state, 311 void (*pm)(struct uart_port *, unsigned int state,
312 unsigned int old); 312 unsigned int old);
313 void (*handle_break)(struct uart_port *);
313 unsigned int irq; /* irq number */ 314 unsigned int irq; /* irq number */
314 unsigned long irqflags; /* irq flags */ 315 unsigned long irqflags; /* irq flags */
315 unsigned int uartclk; /* base uart clock */ 316 unsigned int uartclk; /* base uart clock */
@@ -533,6 +534,10 @@ uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
533static inline int uart_handle_break(struct uart_port *port) 534static inline int uart_handle_break(struct uart_port *port)
534{ 535{
535 struct uart_state *state = port->state; 536 struct uart_state *state = port->state;
537
538 if (port->handle_break)
539 port->handle_break(port);
540
536#ifdef SUPPORT_SYSRQ 541#ifdef SUPPORT_SYSRQ
537 if (port->cons && port->cons->index == port->line) { 542 if (port->cons && port->cons->index == port->line) {
538 if (!port->sysrq) { 543 if (!port->sysrq) {
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 4bf54b377255..d1820ff14aee 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -48,13 +48,12 @@
48static struct tty_driver *rfcomm_tty_driver; 48static struct tty_driver *rfcomm_tty_driver;
49 49
50struct rfcomm_dev { 50struct rfcomm_dev {
51 struct tty_port port;
51 struct list_head list; 52 struct list_head list;
52 atomic_t refcnt;
53 53
54 char name[12]; 54 char name[12];
55 int id; 55 int id;
56 unsigned long flags; 56 unsigned long flags;
57 atomic_t opened;
58 int err; 57 int err;
59 58
60 bdaddr_t src; 59 bdaddr_t src;
@@ -64,9 +63,7 @@ struct rfcomm_dev {
64 uint modem_status; 63 uint modem_status;
65 64
66 struct rfcomm_dlc *dlc; 65 struct rfcomm_dlc *dlc;
67 struct tty_struct *tty;
68 wait_queue_head_t wait; 66 wait_queue_head_t wait;
69 struct work_struct wakeup_task;
70 67
71 struct device *tty_dev; 68 struct device *tty_dev;
72 69
@@ -82,11 +79,18 @@ static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb);
82static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err); 79static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);
83static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig); 80static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig);
84 81
85static void rfcomm_tty_wakeup(struct work_struct *work);
86
87/* ---- Device functions ---- */ 82/* ---- Device functions ---- */
88static void rfcomm_dev_destruct(struct rfcomm_dev *dev) 83
84/*
85 * The reason this isn't actually a race, as you no doubt have a little voice
86 * screaming at you in your head, is that the refcount should never actually
87 * reach zero unless the device has already been taken off the list, in
88 * rfcomm_dev_del(). And if that's not true, we'll hit the BUG() in
89 * rfcomm_dev_destruct() anyway.
90 */
91static void rfcomm_dev_destruct(struct tty_port *port)
89{ 92{
93 struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
90 struct rfcomm_dlc *dlc = dev->dlc; 94 struct rfcomm_dlc *dlc = dev->dlc;
91 95
92 BT_DBG("dev %p dlc %p", dev, dlc); 96 BT_DBG("dev %p dlc %p", dev, dlc);
@@ -113,23 +117,9 @@ static void rfcomm_dev_destruct(struct rfcomm_dev *dev)
113 module_put(THIS_MODULE); 117 module_put(THIS_MODULE);
114} 118}
115 119
116static inline void rfcomm_dev_hold(struct rfcomm_dev *dev) 120static const struct tty_port_operations rfcomm_port_ops = {
117{ 121 .destruct = rfcomm_dev_destruct,
118 atomic_inc(&dev->refcnt); 122};
119}
120
121static inline void rfcomm_dev_put(struct rfcomm_dev *dev)
122{
123 /* The reason this isn't actually a race, as you no
124 doubt have a little voice screaming at you in your
125 head, is that the refcount should never actually
126 reach zero unless the device has already been taken
127 off the list, in rfcomm_dev_del(). And if that's not
128 true, we'll hit the BUG() in rfcomm_dev_destruct()
129 anyway. */
130 if (atomic_dec_and_test(&dev->refcnt))
131 rfcomm_dev_destruct(dev);
132}
133 123
134static struct rfcomm_dev *__rfcomm_dev_get(int id) 124static struct rfcomm_dev *__rfcomm_dev_get(int id)
135{ 125{
@@ -154,7 +144,7 @@ static inline struct rfcomm_dev *rfcomm_dev_get(int id)
154 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) 144 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags))
155 dev = NULL; 145 dev = NULL;
156 else 146 else
157 rfcomm_dev_hold(dev); 147 tty_port_get(&dev->port);
158 } 148 }
159 149
160 spin_unlock(&rfcomm_dev_lock); 150 spin_unlock(&rfcomm_dev_lock);
@@ -241,7 +231,6 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
241 sprintf(dev->name, "rfcomm%d", dev->id); 231 sprintf(dev->name, "rfcomm%d", dev->id);
242 232
243 list_add(&dev->list, head); 233 list_add(&dev->list, head);
244 atomic_set(&dev->refcnt, 1);
245 234
246 bacpy(&dev->src, &req->src); 235 bacpy(&dev->src, &req->src);
247 bacpy(&dev->dst, &req->dst); 236 bacpy(&dev->dst, &req->dst);
@@ -250,10 +239,9 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
250 dev->flags = req->flags & 239 dev->flags = req->flags &
251 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC)); 240 ((1 << RFCOMM_RELEASE_ONHUP) | (1 << RFCOMM_REUSE_DLC));
252 241
253 atomic_set(&dev->opened, 0); 242 tty_port_init(&dev->port);
254 243 dev->port.ops = &rfcomm_port_ops;
255 init_waitqueue_head(&dev->wait); 244 init_waitqueue_head(&dev->wait);
256 INIT_WORK(&dev->wakeup_task, rfcomm_tty_wakeup);
257 245
258 skb_queue_head_init(&dev->pending); 246 skb_queue_head_init(&dev->pending);
259 247
@@ -320,18 +308,23 @@ free:
320 308
321static void rfcomm_dev_del(struct rfcomm_dev *dev) 309static void rfcomm_dev_del(struct rfcomm_dev *dev)
322{ 310{
311 unsigned long flags;
323 BT_DBG("dev %p", dev); 312 BT_DBG("dev %p", dev);
324 313
325 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags)); 314 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
326 315
327 if (atomic_read(&dev->opened) > 0) 316 spin_lock_irqsave(&dev->port.lock, flags);
317 if (dev->port.count > 0) {
318 spin_unlock_irqrestore(&dev->port.lock, flags);
328 return; 319 return;
320 }
321 spin_unlock_irqrestore(&dev->port.lock, flags);
329 322
330 spin_lock(&rfcomm_dev_lock); 323 spin_lock(&rfcomm_dev_lock);
331 list_del_init(&dev->list); 324 list_del_init(&dev->list);
332 spin_unlock(&rfcomm_dev_lock); 325 spin_unlock(&rfcomm_dev_lock);
333 326
334 rfcomm_dev_put(dev); 327 tty_port_put(&dev->port);
335} 328}
336 329
337/* ---- Send buffer ---- */ 330/* ---- Send buffer ---- */
@@ -345,15 +338,16 @@ static inline unsigned int rfcomm_room(struct rfcomm_dlc *dlc)
345static void rfcomm_wfree(struct sk_buff *skb) 338static void rfcomm_wfree(struct sk_buff *skb)
346{ 339{
347 struct rfcomm_dev *dev = (void *) skb->sk; 340 struct rfcomm_dev *dev = (void *) skb->sk;
341 struct tty_struct *tty = dev->port.tty;
348 atomic_sub(skb->truesize, &dev->wmem_alloc); 342 atomic_sub(skb->truesize, &dev->wmem_alloc);
349 if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags)) 343 if (test_bit(RFCOMM_TTY_ATTACHED, &dev->flags) && tty)
350 queue_work(system_nrt_wq, &dev->wakeup_task); 344 tty_wakeup(tty);
351 rfcomm_dev_put(dev); 345 tty_port_put(&dev->port);
352} 346}
353 347
354static inline void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev) 348static inline void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev)
355{ 349{
356 rfcomm_dev_hold(dev); 350 tty_port_get(&dev->port);
357 atomic_add(skb->truesize, &dev->wmem_alloc); 351 atomic_add(skb->truesize, &dev->wmem_alloc);
358 skb->sk = (void *) dev; 352 skb->sk = (void *) dev;
359 skb->destructor = rfcomm_wfree; 353 skb->destructor = rfcomm_wfree;
@@ -432,7 +426,7 @@ static int rfcomm_release_dev(void __user *arg)
432 return -ENODEV; 426 return -ENODEV;
433 427
434 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) { 428 if (dev->flags != NOCAP_FLAGS && !capable(CAP_NET_ADMIN)) {
435 rfcomm_dev_put(dev); 429 tty_port_put(&dev->port);
436 return -EPERM; 430 return -EPERM;
437 } 431 }
438 432
@@ -440,12 +434,12 @@ static int rfcomm_release_dev(void __user *arg)
440 rfcomm_dlc_close(dev->dlc, 0); 434 rfcomm_dlc_close(dev->dlc, 0);
441 435
442 /* Shut down TTY synchronously before freeing rfcomm_dev */ 436 /* Shut down TTY synchronously before freeing rfcomm_dev */
443 if (dev->tty) 437 if (dev->port.tty)
444 tty_vhangup(dev->tty); 438 tty_vhangup(dev->port.tty);
445 439
446 if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) 440 if (!test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags))
447 rfcomm_dev_del(dev); 441 rfcomm_dev_del(dev);
448 rfcomm_dev_put(dev); 442 tty_port_put(&dev->port);
449 return 0; 443 return 0;
450} 444}
451 445
@@ -523,7 +517,7 @@ static int rfcomm_get_dev_info(void __user *arg)
523 if (copy_to_user(arg, &di, sizeof(di))) 517 if (copy_to_user(arg, &di, sizeof(di)))
524 err = -EFAULT; 518 err = -EFAULT;
525 519
526 rfcomm_dev_put(dev); 520 tty_port_put(&dev->port);
527 return err; 521 return err;
528} 522}
529 523
@@ -559,7 +553,7 @@ static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb)
559 return; 553 return;
560 } 554 }
561 555
562 tty = dev->tty; 556 tty = dev->port.tty;
563 if (!tty || !skb_queue_empty(&dev->pending)) { 557 if (!tty || !skb_queue_empty(&dev->pending)) {
564 skb_queue_tail(&dev->pending, skb); 558 skb_queue_tail(&dev->pending, skb);
565 return; 559 return;
@@ -585,13 +579,13 @@ static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err)
585 wake_up_interruptible(&dev->wait); 579 wake_up_interruptible(&dev->wait);
586 580
587 if (dlc->state == BT_CLOSED) { 581 if (dlc->state == BT_CLOSED) {
588 if (!dev->tty) { 582 if (!dev->port.tty) {
589 if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) { 583 if (test_bit(RFCOMM_RELEASE_ONHUP, &dev->flags)) {
590 /* Drop DLC lock here to avoid deadlock 584 /* Drop DLC lock here to avoid deadlock
591 * 1. rfcomm_dev_get will take rfcomm_dev_lock 585 * 1. rfcomm_dev_get will take rfcomm_dev_lock
592 * but in rfcomm_dev_add there's lock order: 586 * but in rfcomm_dev_add there's lock order:
593 * rfcomm_dev_lock -> dlc lock 587 * rfcomm_dev_lock -> dlc lock
594 * 2. rfcomm_dev_put will deadlock if it's 588 * 2. tty_port_put will deadlock if it's
595 * the last reference 589 * the last reference
596 */ 590 */
597 rfcomm_dlc_unlock(dlc); 591 rfcomm_dlc_unlock(dlc);
@@ -601,11 +595,11 @@ static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err)
601 } 595 }
602 596
603 rfcomm_dev_del(dev); 597 rfcomm_dev_del(dev);
604 rfcomm_dev_put(dev); 598 tty_port_put(&dev->port);
605 rfcomm_dlc_lock(dlc); 599 rfcomm_dlc_lock(dlc);
606 } 600 }
607 } else 601 } else
608 tty_hangup(dev->tty); 602 tty_hangup(dev->port.tty);
609 } 603 }
610} 604}
611 605
@@ -618,8 +612,8 @@ static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig)
618 BT_DBG("dlc %p dev %p v24_sig 0x%02x", dlc, dev, v24_sig); 612 BT_DBG("dlc %p dev %p v24_sig 0x%02x", dlc, dev, v24_sig);
619 613
620 if ((dev->modem_status & TIOCM_CD) && !(v24_sig & RFCOMM_V24_DV)) { 614 if ((dev->modem_status & TIOCM_CD) && !(v24_sig & RFCOMM_V24_DV)) {
621 if (dev->tty && !C_CLOCAL(dev->tty)) 615 if (dev->port.tty && !C_CLOCAL(dev->port.tty))
622 tty_hangup(dev->tty); 616 tty_hangup(dev->port.tty);
623 } 617 }
624 618
625 dev->modem_status = 619 dev->modem_status =
@@ -630,21 +624,9 @@ static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig)
630} 624}
631 625
632/* ---- TTY functions ---- */ 626/* ---- TTY functions ---- */
633static void rfcomm_tty_wakeup(struct work_struct *work)
634{
635 struct rfcomm_dev *dev = container_of(work, struct rfcomm_dev,
636 wakeup_task);
637 struct tty_struct *tty = dev->tty;
638 if (!tty)
639 return;
640
641 BT_DBG("dev %p tty %p", dev, tty);
642 tty_wakeup(tty);
643}
644
645static void rfcomm_tty_copy_pending(struct rfcomm_dev *dev) 627static void rfcomm_tty_copy_pending(struct rfcomm_dev *dev)
646{ 628{
647 struct tty_struct *tty = dev->tty; 629 struct tty_struct *tty = dev->port.tty;
648 struct sk_buff *skb; 630 struct sk_buff *skb;
649 int inserted = 0; 631 int inserted = 0;
650 632
@@ -671,6 +653,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
671 DECLARE_WAITQUEUE(wait, current); 653 DECLARE_WAITQUEUE(wait, current);
672 struct rfcomm_dev *dev; 654 struct rfcomm_dev *dev;
673 struct rfcomm_dlc *dlc; 655 struct rfcomm_dlc *dlc;
656 unsigned long flags;
674 int err, id; 657 int err, id;
675 658
676 id = tty->index; 659 id = tty->index;
@@ -686,10 +669,14 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
686 return -ENODEV; 669 return -ENODEV;
687 670
688 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst), 671 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
689 dev->channel, atomic_read(&dev->opened)); 672 dev->channel, dev->port.count);
690 673
691 if (atomic_inc_return(&dev->opened) > 1) 674 spin_lock_irqsave(&dev->port.lock, flags);
675 if (++dev->port.count > 1) {
676 spin_unlock_irqrestore(&dev->port.lock, flags);
692 return 0; 677 return 0;
678 }
679 spin_unlock_irqrestore(&dev->port.lock, flags);
693 680
694 dlc = dev->dlc; 681 dlc = dev->dlc;
695 682
@@ -697,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
697 684
698 rfcomm_dlc_lock(dlc); 685 rfcomm_dlc_lock(dlc);
699 tty->driver_data = dev; 686 tty->driver_data = dev;
700 dev->tty = tty; 687 dev->port.tty = tty;
701 rfcomm_dlc_unlock(dlc); 688 rfcomm_dlc_unlock(dlc);
702 set_bit(RFCOMM_TTY_ATTACHED, &dev->flags); 689 set_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
703 690
@@ -744,13 +731,17 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
744static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp) 731static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
745{ 732{
746 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data; 733 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
734 unsigned long flags;
735
747 if (!dev) 736 if (!dev)
748 return; 737 return;
749 738
750 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc, 739 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
751 atomic_read(&dev->opened)); 740 dev->port.count);
752 741
753 if (atomic_dec_and_test(&dev->opened)) { 742 spin_lock_irqsave(&dev->port.lock, flags);
743 if (!--dev->port.count) {
744 spin_unlock_irqrestore(&dev->port.lock, flags);
754 if (dev->tty_dev->parent) 745 if (dev->tty_dev->parent)
755 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST); 746 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
756 747
@@ -758,11 +749,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
758 rfcomm_dlc_close(dev->dlc, 0); 749 rfcomm_dlc_close(dev->dlc, 0);
759 750
760 clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags); 751 clear_bit(RFCOMM_TTY_ATTACHED, &dev->flags);
761 cancel_work_sync(&dev->wakeup_task);
762 752
763 rfcomm_dlc_lock(dev->dlc); 753 rfcomm_dlc_lock(dev->dlc);
764 tty->driver_data = NULL; 754 tty->driver_data = NULL;
765 dev->tty = NULL; 755 dev->port.tty = NULL;
766 rfcomm_dlc_unlock(dev->dlc); 756 rfcomm_dlc_unlock(dev->dlc);
767 757
768 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) { 758 if (test_bit(RFCOMM_TTY_RELEASED, &dev->flags)) {
@@ -770,11 +760,12 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
770 list_del_init(&dev->list); 760 list_del_init(&dev->list);
771 spin_unlock(&rfcomm_dev_lock); 761 spin_unlock(&rfcomm_dev_lock);
772 762
773 rfcomm_dev_put(dev); 763 tty_port_put(&dev->port);
774 } 764 }
775 } 765 } else
766 spin_unlock_irqrestore(&dev->port.lock, flags);
776 767
777 rfcomm_dev_put(dev); 768 tty_port_put(&dev->port);
778} 769}
779 770
780static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) 771static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
@@ -1083,7 +1074,7 @@ static void rfcomm_tty_hangup(struct tty_struct *tty)
1083 if (rfcomm_dev_get(dev->id) == NULL) 1074 if (rfcomm_dev_get(dev->id) == NULL)
1084 return; 1075 return;
1085 rfcomm_dev_del(dev); 1076 rfcomm_dev_del(dev);
1086 rfcomm_dev_put(dev); 1077 tty_port_put(&dev->port);
1087 } 1078 }
1088} 1079}
1089 1080