Commit d41861ca authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman

tty: Replace ASYNC_INITIALIZED bit and update atomically

Replace ASYNC_INITIALIZED bit in the tty_port::flags field with
TTY_PORT_INITIALIZED bit in the tty_port::iflags field. Introduce helpers
tty_port_set_initialized() and tty_port_initialized() to abstract
atomic bit ops.

Note: the transforms for test_and_set_bit() and test_and_clear_bit()
are unnecessary as the state transitions are already mutually exclusive;
the tty lock prevents concurrent open/close/hangup.
Signed-off-by: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 80f02d54
...@@ -1272,7 +1272,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty) ...@@ -1272,7 +1272,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty)
if (debug_level >= DEBUG_LEVEL_INFO) if (debug_level >= DEBUG_LEVEL_INFO)
printk("%s(%d):startup(%s)\n", __FILE__, __LINE__, info->device_name); printk("%s(%d):startup(%s)\n", __FILE__, __LINE__, info->device_name);
if (info->port.flags & ASYNC_INITIALIZED) if (tty_port_initialized(&info->port))
return 0; return 0;
if (!info->tx_buf) { if (!info->tx_buf) {
...@@ -1311,7 +1311,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty) ...@@ -1311,7 +1311,7 @@ static int startup(MGSLPC_INFO * info, struct tty_struct *tty)
if (tty) if (tty)
clear_bit(TTY_IO_ERROR, &tty->flags); clear_bit(TTY_IO_ERROR, &tty->flags);
info->port.flags |= ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 1);
return 0; return 0;
} }
...@@ -1322,7 +1322,7 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty) ...@@ -1322,7 +1322,7 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty)
{ {
unsigned long flags; unsigned long flags;
if (!(info->port.flags & ASYNC_INITIALIZED)) if (!tty_port_initialized(&info->port))
return; return;
if (debug_level >= DEBUG_LEVEL_INFO) if (debug_level >= DEBUG_LEVEL_INFO)
...@@ -1361,7 +1361,7 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty) ...@@ -1361,7 +1361,7 @@ static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty)
if (tty) if (tty)
set_bit(TTY_IO_ERROR, &tty->flags); set_bit(TTY_IO_ERROR, &tty->flags);
info->port.flags &= ~ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 0);
} }
static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty) static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty)
...@@ -2338,7 +2338,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp) ...@@ -2338,7 +2338,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
if (tty_port_close_start(port, tty, filp) == 0) if (tty_port_close_start(port, tty, filp) == 0)
goto cleanup; goto cleanup;
if (port->flags & ASYNC_INITIALIZED) if (tty_port_initialized(port))
mgslpc_wait_until_sent(tty, info->timeout); mgslpc_wait_until_sent(tty, info->timeout);
mgslpc_flush_buffer(tty); mgslpc_flush_buffer(tty);
...@@ -2371,7 +2371,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout) ...@@ -2371,7 +2371,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout)
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent")) if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent"))
return; return;
if (!(info->port.flags & ASYNC_INITIALIZED)) if (!tty_port_initialized(&info->port))
goto exit; goto exit;
orig_jiffies = jiffies; orig_jiffies = jiffies;
......
...@@ -629,8 +629,7 @@ static void ipoctal_hangup(struct tty_struct *tty) ...@@ -629,8 +629,7 @@ static void ipoctal_hangup(struct tty_struct *tty)
tty_port_hangup(&channel->tty_port); tty_port_hangup(&channel->tty_port);
ipoctal_reset_channel(channel); ipoctal_reset_channel(channel);
tty_port_set_initialized(&channel->tty_port, 0);
clear_bit(ASYNCB_INITIALIZED, &channel->tty_port.flags);
wake_up_interruptible(&channel->tty_port.open_wait); wake_up_interruptible(&channel->tty_port.open_wait);
} }
...@@ -642,7 +641,7 @@ static void ipoctal_shutdown(struct tty_struct *tty) ...@@ -642,7 +641,7 @@ static void ipoctal_shutdown(struct tty_struct *tty)
return; return;
ipoctal_reset_channel(channel); ipoctal_reset_channel(channel);
clear_bit(ASYNCB_INITIALIZED, &channel->tty_port.flags); tty_port_set_initialized(&channel->tty_port, 0);
} }
static void ipoctal_cleanup(struct tty_struct *tty) static void ipoctal_cleanup(struct tty_struct *tty)
......
...@@ -1049,7 +1049,7 @@ isdn_tty_change_speed(modem_info *info) ...@@ -1049,7 +1049,7 @@ isdn_tty_change_speed(modem_info *info)
static int static int
isdn_tty_startup(modem_info *info) isdn_tty_startup(modem_info *info)
{ {
if (info->port.flags & ASYNC_INITIALIZED) if (tty_port_initialized(&info->port))
return 0; return 0;
isdn_lock_drivers(); isdn_lock_drivers();
#ifdef ISDN_DEBUG_MODEM_OPEN #ifdef ISDN_DEBUG_MODEM_OPEN
...@@ -1066,7 +1066,7 @@ isdn_tty_startup(modem_info *info) ...@@ -1066,7 +1066,7 @@ isdn_tty_startup(modem_info *info)
*/ */
isdn_tty_change_speed(info); isdn_tty_change_speed(info);
info->port.flags |= ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 1);
info->msr |= (UART_MSR_DSR | UART_MSR_CTS); info->msr |= (UART_MSR_DSR | UART_MSR_CTS);
info->send_outstanding = 0; info->send_outstanding = 0;
return 0; return 0;
...@@ -1079,7 +1079,7 @@ isdn_tty_startup(modem_info *info) ...@@ -1079,7 +1079,7 @@ isdn_tty_startup(modem_info *info)
static void static void
isdn_tty_shutdown(modem_info *info) isdn_tty_shutdown(modem_info *info)
{ {
if (!(info->port.flags & ASYNC_INITIALIZED)) if (!tty_port_initialized(&info->port))
return; return;
#ifdef ISDN_DEBUG_MODEM_OPEN #ifdef ISDN_DEBUG_MODEM_OPEN
printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line); printk(KERN_DEBUG "Shutting down isdnmodem port %d ....\n", info->line);
...@@ -1099,7 +1099,7 @@ isdn_tty_shutdown(modem_info *info) ...@@ -1099,7 +1099,7 @@ isdn_tty_shutdown(modem_info *info)
if (info->port.tty) if (info->port.tty)
set_bit(TTY_IO_ERROR, &info->port.tty->flags); set_bit(TTY_IO_ERROR, &info->port.tty->flags);
info->port.flags &= ~ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 0);
} }
/* isdn_tty_write() is the main send-routine. It is called from the upper /* isdn_tty_write() is the main send-routine. It is called from the upper
...@@ -1577,7 +1577,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp) ...@@ -1577,7 +1577,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
* interrupt driver to stop checking the data ready bit in the * interrupt driver to stop checking the data ready bit in the
* line status register. * line status register.
*/ */
if (port->flags & ASYNC_INITIALIZED) { if (tty_port_initialized(port)) {
tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */ tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
/* /*
* Before we drop DTR, make sure the UART transmitter * Before we drop DTR, make sure the UART transmitter
......
...@@ -311,8 +311,7 @@ static void raw3215_timeout(unsigned long __data) ...@@ -311,8 +311,7 @@ static void raw3215_timeout(unsigned long __data)
*/ */
static inline void raw3215_try_io(struct raw3215_info *raw) static inline void raw3215_try_io(struct raw3215_info *raw)
{ {
if (!(raw->port.flags & ASYNC_INITIALIZED) || if (!tty_port_initialized(&raw->port) || tty_port_suspended(&raw->port))
tty_port_suspended(&raw->port))
return; return;
if (raw->queued_read != NULL) if (raw->queued_read != NULL)
raw3215_start_io(raw); raw3215_start_io(raw);
...@@ -616,10 +615,10 @@ static int raw3215_startup(struct raw3215_info *raw) ...@@ -616,10 +615,10 @@ static int raw3215_startup(struct raw3215_info *raw)
{ {
unsigned long flags; unsigned long flags;
if (raw->port.flags & ASYNC_INITIALIZED) if (tty_port_initialized(&raw->port))
return 0; return 0;
raw->line_pos = 0; raw->line_pos = 0;
raw->port.flags |= ASYNC_INITIALIZED; tty_port_set_initialized(&raw->port, 1);
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
raw3215_try_io(raw); raw3215_try_io(raw);
spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
...@@ -635,8 +634,7 @@ static void raw3215_shutdown(struct raw3215_info *raw) ...@@ -635,8 +634,7 @@ static void raw3215_shutdown(struct raw3215_info *raw)
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
unsigned long flags; unsigned long flags;
if (!(raw->port.flags & ASYNC_INITIALIZED) || if (!tty_port_initialized(&raw->port) || (raw->flags & RAW3215_FIXED))
(raw->flags & RAW3215_FIXED))
return; return;
/* Wait for outstanding requests, then free irq */ /* Wait for outstanding requests, then free irq */
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
...@@ -650,7 +648,7 @@ static void raw3215_shutdown(struct raw3215_info *raw) ...@@ -650,7 +648,7 @@ static void raw3215_shutdown(struct raw3215_info *raw)
spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags); spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
remove_wait_queue(&raw->empty_wait, &wait); remove_wait_queue(&raw->empty_wait, &wait);
set_current_state(TASK_RUNNING); set_current_state(TASK_RUNNING);
raw->port.flags &= ~ASYNC_INITIALIZED; tty_port_set_initialized(&raw->port, 1);
} }
spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags); spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
} }
......
...@@ -525,7 +525,7 @@ static int startup(struct tty_struct *tty, struct serial_state *info) ...@@ -525,7 +525,7 @@ static int startup(struct tty_struct *tty, struct serial_state *info)
local_irq_save(flags); local_irq_save(flags);
if (port->flags & ASYNC_INITIALIZED) { if (tty_port_initialized(port)) {
free_page(page); free_page(page);
goto errout; goto errout;
} }
...@@ -586,7 +586,7 @@ static int startup(struct tty_struct *tty, struct serial_state *info) ...@@ -586,7 +586,7 @@ static int startup(struct tty_struct *tty, struct serial_state *info)
*/ */
change_speed(tty, info, NULL); change_speed(tty, info, NULL);
port->flags |= ASYNC_INITIALIZED; tty_port_set_initialized(port, 1);
local_irq_restore(flags); local_irq_restore(flags);
return 0; return 0;
...@@ -604,7 +604,7 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info) ...@@ -604,7 +604,7 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info)
unsigned long flags; unsigned long flags;
struct serial_state *state; struct serial_state *state;
if (!(info->tport.flags & ASYNC_INITIALIZED)) if (!tty_port_initialized(&info->tport))
return; return;
state = info; state = info;
...@@ -645,7 +645,7 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info) ...@@ -645,7 +645,7 @@ static void shutdown(struct tty_struct *tty, struct serial_state *info)
set_bit(TTY_IO_ERROR, &tty->flags); set_bit(TTY_IO_ERROR, &tty->flags);
info->tport.flags &= ~ASYNC_INITIALIZED; tty_port_set_initialized(&info->tport, 0);
local_irq_restore(flags); local_irq_restore(flags);
} }
...@@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state, ...@@ -1084,7 +1084,7 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
check_and_exit: check_and_exit:
if (port->flags & ASYNC_INITIALIZED) { if (tty_port_initialized(port)) {
if (change_spd) { if (change_spd) {
if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
tty->alt_speed = 57600; tty->alt_speed = 57600;
...@@ -1390,7 +1390,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp) ...@@ -1390,7 +1390,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
* line status register. * line status register.
*/ */
state->read_status_mask &= ~UART_LSR_DR; state->read_status_mask &= ~UART_LSR_DR;
if (port->flags & ASYNC_INITIALIZED) { if (tty_port_initialized(port)) {
/* disable receive interrupts */ /* disable receive interrupts */
custom.intena = IF_RBF; custom.intena = IF_RBF;
mb(); mb();
...@@ -1538,7 +1538,7 @@ static inline void line_info(struct seq_file *m, int line, ...@@ -1538,7 +1538,7 @@ static inline void line_info(struct seq_file *m, int line,
local_irq_save(flags); local_irq_save(flags);
status = ciab.pra; status = ciab.pra;
control = (state->tport.flags & ASYNC_INITIALIZED) ? state->MCR : status; control = tty_port_initialized(&state->tport) ? state->MCR : status;
local_irq_restore(flags); local_irq_restore(flags);
stat_buf[0] = 0; stat_buf[0] = 0;
......
...@@ -1279,7 +1279,7 @@ static int cy_startup(struct cyclades_port *info, struct tty_struct *tty) ...@@ -1279,7 +1279,7 @@ static int cy_startup(struct cyclades_port *info, struct tty_struct *tty)
spin_lock_irqsave(&card->card_lock, flags); spin_lock_irqsave(&card->card_lock, flags);
if (info->port.flags & ASYNC_INITIALIZED) if (tty_port_initialized(&info->port))
goto errout; goto errout;
if (!info->type) { if (!info->type) {
...@@ -1364,7 +1364,7 @@ static int cy_startup(struct cyclades_port *info, struct tty_struct *tty) ...@@ -1364,7 +1364,7 @@ static int cy_startup(struct cyclades_port *info, struct tty_struct *tty)
/* enable send, recv, modem !!! */ /* enable send, recv, modem !!! */
} }
info->port.flags |= ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 1);
clear_bit(TTY_IO_ERROR, &tty->flags); clear_bit(TTY_IO_ERROR, &tty->flags);
info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
...@@ -1424,7 +1424,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty) ...@@ -1424,7 +1424,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
struct cyclades_card *card; struct cyclades_card *card;
unsigned long flags; unsigned long flags;
if (!(info->port.flags & ASYNC_INITIALIZED)) if (!tty_port_initialized(&info->port))
return; return;
card = info->card; card = info->card;
...@@ -1448,7 +1448,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty) ...@@ -1448,7 +1448,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
some later date (after testing)!!! */ some later date (after testing)!!! */
set_bit(TTY_IO_ERROR, &tty->flags); set_bit(TTY_IO_ERROR, &tty->flags);
info->port.flags &= ~ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 0);
spin_unlock_irqrestore(&card->card_lock, flags); spin_unlock_irqrestore(&card->card_lock, flags);
} else { } else {
#ifdef CY_DEBUG_OPEN #ifdef CY_DEBUG_OPEN
...@@ -1473,7 +1473,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty) ...@@ -1473,7 +1473,7 @@ static void cy_shutdown(struct cyclades_port *info, struct tty_struct *tty)
tty_port_lower_dtr_rts(&info->port); tty_port_lower_dtr_rts(&info->port);
set_bit(TTY_IO_ERROR, &tty->flags); set_bit(TTY_IO_ERROR, &tty->flags);
info->port.flags &= ~ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 0);
spin_unlock_irqrestore(&card->card_lock, flags); spin_unlock_irqrestore(&card->card_lock, flags);
} }
...@@ -1711,7 +1711,7 @@ static void cy_do_close(struct tty_port *port) ...@@ -1711,7 +1711,7 @@ static void cy_do_close(struct tty_port *port)
/* Stop accepting input */ /* Stop accepting input */
cyy_writeb(info, CyCAR, channel & 0x03); cyy_writeb(info, CyCAR, channel & 0x03);
cyy_writeb(info, CySRER, cyy_readb(info, CySRER) & ~CyRxData); cyy_writeb(info, CySRER, cyy_readb(info, CySRER) & ~CyRxData);
if (info->port.flags & ASYNC_INITIALIZED) { if (tty_port_initialized(&info->port)) {
/* Waiting for on-board buffers to be empty before /* Waiting for on-board buffers to be empty before
closing the port */ closing the port */
spin_unlock_irqrestore(&card->card_lock, flags); spin_unlock_irqrestore(&card->card_lock, flags);
...@@ -2334,7 +2334,7 @@ cy_set_serial_info(struct cyclades_port *info, struct tty_struct *tty, ...@@ -2334,7 +2334,7 @@ cy_set_serial_info(struct cyclades_port *info, struct tty_struct *tty,
info->port.closing_wait = new_serial.closing_wait * HZ / 100; info->port.closing_wait = new_serial.closing_wait * HZ / 100;
check_and_exit: check_and_exit:
if (info->port.flags & ASYNC_INITIALIZED) { if (tty_port_initialized(&info->port)) {
cy_set_line_char(info, tty); cy_set_line_char(info, tty);
ret = 0; ret = 0;
} else { } else {
......
...@@ -438,8 +438,8 @@ static void isicom_tx(unsigned long _data) ...@@ -438,8 +438,8 @@ static void isicom_tx(unsigned long _data)
for (; count > 0; count--, port++) { for (; count > 0; count--, port++) {
/* port not active or tx disabled to force flow control */ /* port not active or tx disabled to force flow control */
if (!(port->port.flags & ASYNC_INITIALIZED) || if (!tty_port_initialized(&port->port) ||
!(port->status & ISI_TXOK)) !(port->status & ISI_TXOK))
continue; continue;
txcount = min_t(short, TX_SIZE, port->xmit_cnt); txcount = min_t(short, TX_SIZE, port->xmit_cnt);
...@@ -553,7 +553,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id) ...@@ -553,7 +553,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
port = card->ports + channel; port = card->ports + channel;
if (!(port->port.flags & ASYNC_INITIALIZED)) { if (!tty_port_initialized(&port->port)) {
outw(0x0000, base+0x04); /* enable interrupts */ outw(0x0000, base+0x04); /* enable interrupts */
spin_unlock(&card->card_lock); spin_unlock(&card->card_lock);
return IRQ_HANDLED; return IRQ_HANDLED;
......
...@@ -912,7 +912,7 @@ static void moxa_board_deinit(struct moxa_board_conf *brd) ...@@ -912,7 +912,7 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
/* pci hot-un-plug support */ /* pci hot-un-plug support */
for (a = 0; a < brd->numPorts; a++) for (a = 0; a < brd->numPorts; a++)
if (brd->ports[a].port.flags & ASYNC_INITIALIZED) if (tty_port_initialized(&brd->ports[a].port))
tty_port_tty_hangup(&brd->ports[a].port, false); tty_port_tty_hangup(&brd->ports[a].port, false);
for (a = 0; a < MAX_PORTS_PER_BOARD; a++) for (a = 0; a < MAX_PORTS_PER_BOARD; a++)
...@@ -921,7 +921,7 @@ static void moxa_board_deinit(struct moxa_board_conf *brd) ...@@ -921,7 +921,7 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
while (1) { while (1) {
opened = 0; opened = 0;
for (a = 0; a < brd->numPorts; a++) for (a = 0; a < brd->numPorts; a++)
if (brd->ports[a].port.flags & ASYNC_INITIALIZED) if (tty_port_initialized(&brd->ports[a].port))
opened++; opened++;
mutex_unlock(&moxa_openlock); mutex_unlock(&moxa_openlock);
if (!opened) if (!opened)
...@@ -1192,13 +1192,13 @@ static int moxa_open(struct tty_struct *tty, struct file *filp) ...@@ -1192,13 +1192,13 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
tty->driver_data = ch; tty->driver_data = ch;
tty_port_tty_set(&ch->port, tty); tty_port_tty_set(&ch->port, tty);
mutex_lock(&ch->port.mutex); mutex_lock(&ch->port.mutex);
if (!(ch->port.flags & ASYNC_INITIALIZED)) { if (!tty_port_initialized(&ch->port)) {
ch->statusflags = 0; ch->statusflags = 0;
moxa_set_tty_param(tty, &tty->termios); moxa_set_tty_param(tty, &tty->termios);
MoxaPortLineCtrl(ch, 1, 1); MoxaPortLineCtrl(ch, 1, 1);
MoxaPortEnable(ch); MoxaPortEnable(ch);
MoxaSetFifo(ch, ch->type == PORT_16550A); MoxaSetFifo(ch, ch->type == PORT_16550A);
ch->port.flags |= ASYNC_INITIALIZED; tty_port_set_initialized(&ch->port, 1);
} }
mutex_unlock(&ch->port.mutex); mutex_unlock(&ch->port.mutex);
mutex_unlock(&moxa_openlock); mutex_unlock(&moxa_openlock);
...@@ -1379,7 +1379,7 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle, ...@@ -1379,7 +1379,7 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
{ {
struct tty_struct *tty = tty_port_tty_get(&p->port); struct tty_struct *tty = tty_port_tty_get(&p->port);
void __iomem *ofsAddr; void __iomem *ofsAddr;
unsigned int inited = p->port.flags & ASYNC_INITIALIZED; unsigned int inited = tty_port_initialized(&p->port);
u16 intr; u16 intr;
if (tty) { if (tty) {
......
...@@ -1081,12 +1081,10 @@ static void mxser_close(struct tty_struct *tty, struct file *filp) ...@@ -1081,12 +1081,10 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
mutex_lock(&port->mutex); mutex_lock(&port->mutex);
mxser_close_port(port); mxser_close_port(port);
mxser_flush_buffer(tty); mxser_flush_buffer(tty);
if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { if (tty_port_initialized(port) && C_HUPCL(tty))
if (C_HUPCL(tty)) tty_port_lower_dtr_rts(port);
tty_port_lower_dtr_rts(port);
}
mxser_shutdown_port(port); mxser_shutdown_port(port);
clear_bit(ASYNCB_INITIALIZED, &port->flags); tty_port_set_initialized(port, 0);
mutex_unlock(&port->mutex); mutex_unlock(&port->mutex);
info->closing = 0; info->closing = 0;
/* Right now the tty_port set is done outside of the close_end helper /* Right now the tty_port set is done outside of the close_end helper
...@@ -1282,7 +1280,7 @@ static int mxser_set_serial_info(struct tty_struct *tty, ...@@ -1282,7 +1280,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
process_txrx_fifo(info); process_txrx_fifo(info);
if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { if (tty_port_initialized(port)) {
if (flags != (port->flags & ASYNC_SPD_MASK)) { if (flags != (port->flags & ASYNC_SPD_MASK)) {
spin_lock_irqsave(&info->slock, sl_flags); spin_lock_irqsave(&info->slock, sl_flags);
mxser_change_speed(tty, NULL); mxser_change_speed(tty, NULL);
...@@ -1291,7 +1289,7 @@ static int mxser_set_serial_info(struct tty_struct *tty, ...@@ -1291,7 +1289,7 @@ static int mxser_set_serial_info(struct tty_struct *tty,
} else { } else {
retval = mxser_activate(port, tty); retval = mxser_activate(port, tty);
if (retval == 0) if (retval == 0)
set_bit(ASYNCB_INITIALIZED, &port->flags); tty_port_set_initialized(port, 1);
} }
return retval; return retval;
} }
...@@ -2251,7 +2249,7 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id) ...@@ -2251,7 +2249,7 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
iir &= MOXA_MUST_IIR_MASK; iir &= MOXA_MUST_IIR_MASK;
tty = tty_port_tty_get(&port->port); tty = tty_port_tty_get(&port->port);
if (!tty || port->closing || if (!tty || port->closing ||
!(port->port.flags & ASYNC_INITIALIZED)) { !tty_port_initialized(&port->port)) {
status = inb(port->ioaddr + UART_LSR); status = inb(port->ioaddr + UART_LSR);
outb(0x27, port->ioaddr + UART_FCR); outb(0x27, port->ioaddr + UART_FCR);
inb(port->ioaddr + UART_MSR); inb(port->ioaddr + UART_MSR);
......
...@@ -2949,7 +2949,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp) ...@@ -2949,7 +2949,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
dlci->modem_rx = 0; dlci->modem_rx = 0;
/* We could in theory open and close before we wait - eg if we get /* We could in theory open and close before we wait - eg if we get
a DM straight back. This is ok as that will have caused a hangup */ a DM straight back. This is ok as that will have caused a hangup */
set_bit(ASYNCB_INITIALIZED, &port->flags); tty_port_set_initialized(port, 1);
/* Start sending off SABM messages */ /* Start sending off SABM messages */
gsm_dlci_begin_open(dlci); gsm_dlci_begin_open(dlci);
/* And wait for virtual carrier */ /* And wait for virtual carrier */
...@@ -2972,10 +2972,8 @@ static void gsmtty_close(struct tty_struct *tty, struct file *filp) ...@@ -2972,10 +2972,8 @@ static void gsmtty_close(struct tty_struct *tty, struct file *filp)
if (tty_port_close_start(&dlci->port, tty, filp) == 0) if (tty_port_close_start(&dlci->port, tty, filp) == 0)
return; return;
gsm_dlci_begin_close(dlci); gsm_dlci_begin_close(dlci);
if (test_bit(ASYNCB_INITIALIZED, &dlci->port.flags)) { if (tty_port_initialized(&dlci->port) && C_HUPCL(tty))
if (C_HUPCL(tty)) tty_port_lower_dtr_rts(&dlci->port);
tty_port_lower_dtr_rts(&dlci->port);
}
tty_port_close_end(&dlci->port, tty); tty_port_close_end(&dlci->port, tty);
tty_port_tty_set(&dlci->port, NULL); tty_port_tty_set(&dlci->port, NULL);
return; return;
......
...@@ -495,7 +495,7 @@ static void rp_handle_port(struct r_port *info) ...@@ -495,7 +495,7 @@ static void rp_handle_port(struct r_port *info)
if (!info) if (!info)
return; return;
if ((info->port.flags & ASYNC_INITIALIZED) == 0) { if (!tty_port_initialized(&info->port)) {
printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
"info->flags & NOT_INIT\n"); "info->flags & NOT_INIT\n");
return; return;
...@@ -920,7 +920,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) ...@@ -920,7 +920,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
/* /*
* Info->count is now 1; so it's safe to sleep now. * Info->count is now 1; so it's safe to sleep now.
*/ */
if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { if (!tty_port_initialized(port)) {
cp = &info->channel; cp = &info->channel;
sSetRxTrigger(cp, TRIG_1); sSetRxTrigger(cp, TRIG_1);
if (sGetChanStatus(cp) & CD_ACT) if (sGetChanStatus(cp) & CD_ACT)
...@@ -944,7 +944,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) ...@@ -944,7 +944,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
sEnRxFIFO(cp); sEnRxFIFO(cp);
sEnTransmit(cp); sEnTransmit(cp);
set_bit(ASYNCB_INITIALIZED, &info->port.flags); tty_port_set_initialized(&info->port, 1);
/* /*
* Set up the tty->alt_speed kludge * Set up the tty->alt_speed kludge
...@@ -1042,9 +1042,9 @@ static void rp_close(struct tty_struct *tty, struct file *filp) ...@@ -1042,9 +1042,9 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
} }
} }
spin_lock_irq(&port->lock); spin_lock_irq(&port->lock);
port->flags &= ~ASYNC_INITIALIZED;
tty->closing = 0; tty->closing = 0;
spin_unlock_irq(&port->lock); spin_unlock_irq(&port->lock);
tty_port_set_initialized(port, 0);
tty_port_set_active(port, 0); tty_port_set_active(port, 0);
mutex_unlock(&port->mutex); mutex_unlock(&port->mutex);
tty_port_tty_set(port, NULL); tty_port_tty_set(port, NULL);
...@@ -1513,7 +1513,7 @@ static void rp_hangup(struct tty_struct *tty) ...@@ -1513,7 +1513,7 @@ static void rp_hangup(struct tty_struct *tty)
sDisCTSFlowCtl(cp); sDisCTSFlowCtl(cp);
sDisTxSoftFlowCtl(cp); sDisTxSoftFlowCtl(cp);
sClrTxXOFF(cp); sClrTxXOFF(cp);
clear_bit(ASYNCB_INITIALIZED, &info->port.flags); tty_port_set_initialized(&info->port, 0);
wake_up_interruptible(&info->port.open_wait); wake_up_interruptible(&info->port.open_wait);
} }
......
...@@ -2599,7 +2599,7 @@ startup(struct e100_serial * info) ...@@ -2599,7 +2599,7 @@ startup(struct e100_serial * info)
/* if it was already initialized, skip this */ /* if it was already initialized, skip this */
if (info->port.flags & ASYNC_INITIALIZED) { if (tty_port_initialized(&info->port)) {
local_irq_restore(flags); local_irq_restore(flags);
free_page(xmit_page); free_page(xmit_page);
return 0; return 0;
...@@ -2703,7 +2703,7 @@ startup(struct e100_serial * info) ...@@ -2703,7 +2703,7 @@ startup(struct e100_serial * info)
e100_rts(info, 1); e100_rts(info, 1);
e100_dtr(info, 1); e100_dtr(info, 1);
info->port.flags |= ASYNC_INITIALIZED; tty_port_set_initialized(&info->port, 1);
local_irq_restore(flags); local_irq_restore(flags);
return 0;