aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/epca.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/epca.c')
-rw-r--r--drivers/char/epca.c267
1 files changed, 77 insertions, 190 deletions
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index cf2461d34e5f..af7c13ca9493 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -69,7 +69,9 @@ static int invalid_lilo_config;
69 69
70/* 70/*
71 * The ISA boards do window flipping into the same spaces so its only sane with 71 * The ISA boards do window flipping into the same spaces so its only sane with
72 * a single lock. It's still pretty efficient. 72 * a single lock. It's still pretty efficient. This lock guards the hardware
73 * and the tty_port lock guards the kernel side stuff like use counts. Take
74 * this lock inside the port lock if you must take both.
73 */ 75 */
74static DEFINE_SPINLOCK(epca_lock); 76static DEFINE_SPINLOCK(epca_lock);
75 77
@@ -156,14 +158,12 @@ static struct channel *verifyChannel(struct tty_struct *);
156static void pc_sched_event(struct channel *, int); 158static void pc_sched_event(struct channel *, int);
157static void epca_error(int, char *); 159static void epca_error(int, char *);
158static void pc_close(struct tty_struct *, struct file *); 160static void pc_close(struct tty_struct *, struct file *);
159static void shutdown(struct channel *); 161static void shutdown(struct channel *, struct tty_struct *tty);
160static void pc_hangup(struct tty_struct *); 162static void pc_hangup(struct tty_struct *);
161static int pc_write_room(struct tty_struct *); 163static int pc_write_room(struct tty_struct *);
162static int pc_chars_in_buffer(struct tty_struct *); 164static int pc_chars_in_buffer(struct tty_struct *);
163static void pc_flush_buffer(struct tty_struct *); 165static void pc_flush_buffer(struct tty_struct *);
164static void pc_flush_chars(struct tty_struct *); 166static void pc_flush_chars(struct tty_struct *);
165static int block_til_ready(struct tty_struct *, struct file *,
166 struct channel *);
167static int pc_open(struct tty_struct *, struct file *); 167static int pc_open(struct tty_struct *, struct file *);
168static void post_fep_init(unsigned int crd); 168static void post_fep_init(unsigned int crd);
169static void epcapoll(unsigned long); 169static void epcapoll(unsigned long);
@@ -173,7 +173,7 @@ static unsigned termios2digi_h(struct channel *ch, unsigned);
173static unsigned termios2digi_i(struct channel *ch, unsigned); 173static unsigned termios2digi_i(struct channel *ch, unsigned);
174static unsigned termios2digi_c(struct channel *ch, unsigned); 174static unsigned termios2digi_c(struct channel *ch, unsigned);
175static void epcaparam(struct tty_struct *, struct channel *); 175static void epcaparam(struct tty_struct *, struct channel *);
176static void receive_data(struct channel *); 176static void receive_data(struct channel *, struct tty_struct *tty);
177static int pc_ioctl(struct tty_struct *, struct file *, 177static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long); 178 unsigned int, unsigned long);
179static int info_ioctl(struct tty_struct *, struct file *, 179static int info_ioctl(struct tty_struct *, struct file *,
@@ -392,7 +392,7 @@ static struct channel *verifyChannel(struct tty_struct *tty)
392 * through tty->driver_data this should catch it. 392 * through tty->driver_data this should catch it.
393 */ 393 */
394 if (tty) { 394 if (tty) {
395 struct channel *ch = (struct channel *)tty->driver_data; 395 struct channel *ch = tty->driver_data;
396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) { 396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
397 if (ch->magic == EPCA_MAGIC) 397 if (ch->magic == EPCA_MAGIC)
398 return ch; 398 return ch;
@@ -419,76 +419,34 @@ static void epca_error(int line, char *msg)
419static void pc_close(struct tty_struct *tty, struct file *filp) 419static void pc_close(struct tty_struct *tty, struct file *filp)
420{ 420{
421 struct channel *ch; 421 struct channel *ch;
422 unsigned long flags; 422 struct tty_port *port;
423 /* 423 /*
424 * verifyChannel returns the channel from the tty struct if it is 424 * verifyChannel returns the channel from the tty struct if it is
425 * valid. This serves as a sanity check. 425 * valid. This serves as a sanity check.
426 */ 426 */
427 ch = verifyChannel(tty); 427 ch = verifyChannel(tty);
428 if (ch != NULL) { 428 if (ch == NULL)
429 spin_lock_irqsave(&epca_lock, flags); 429 return;
430 if (tty_hung_up_p(filp)) { 430 port = &ch->port;
431 spin_unlock_irqrestore(&epca_lock, flags);
432 return;
433 }
434 if (ch->port.count-- > 1) {
435 /* Begin channel is open more than once */
436 /*
437 * Return without doing anything. Someone might still
438 * be using the channel.
439 */
440 spin_unlock_irqrestore(&epca_lock, flags);
441 return;
442 }
443 /* Port open only once go ahead with shutdown & reset */
444 BUG_ON(ch->port.count < 0);
445
446 /*
447 * Let the rest of the driver know the channel is being closed.
448 * This becomes important if an open is attempted before close
449 * is finished.
450 */
451 ch->port.flags |= ASYNC_CLOSING;
452 tty->closing = 1;
453
454 spin_unlock_irqrestore(&epca_lock, flags);
455
456 if (ch->port.flags & ASYNC_INITIALIZED) {
457 /* Setup an event to indicate when the
458 transmit buffer empties */
459 setup_empty_event(tty, ch);
460 /* 30 seconds timeout */
461 tty_wait_until_sent(tty, 3000);
462 }
463 pc_flush_buffer(tty);
464 431
465 tty_ldisc_flush(tty); 432 if (tty_port_close_start(port, tty, filp) == 0)
466 shutdown(ch); 433 return;
467 434
468 spin_lock_irqsave(&epca_lock, flags); 435 pc_flush_buffer(tty);
469 tty->closing = 0; 436 shutdown(ch, tty);
470 ch->event = 0;
471 ch->port.tty = NULL;
472 spin_unlock_irqrestore(&epca_lock, flags);
473 437
474 if (ch->port.blocked_open) { 438 tty_port_close_end(port, tty);
475 if (ch->close_delay) 439 ch->event = 0; /* FIXME: review ch->event locking */
476 msleep_interruptible(jiffies_to_msecs(ch->close_delay)); 440 tty_port_tty_set(port, NULL);
477 wake_up_interruptible(&ch->port.open_wait);
478 }
479 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
480 ASYNC_CLOSING);
481 wake_up_interruptible(&ch->port.close_wait);
482 }
483} 441}
484 442
485static void shutdown(struct channel *ch) 443static void shutdown(struct channel *ch, struct tty_struct *tty)
486{ 444{
487 unsigned long flags; 445 unsigned long flags;
488 struct tty_struct *tty;
489 struct board_chan __iomem *bc; 446 struct board_chan __iomem *bc;
447 struct tty_port *port = &ch->port;
490 448
491 if (!(ch->port.flags & ASYNC_INITIALIZED)) 449 if (!(port->flags & ASYNC_INITIALIZED))
492 return; 450 return;
493 451
494 spin_lock_irqsave(&epca_lock, flags); 452 spin_lock_irqsave(&epca_lock, flags);
@@ -503,7 +461,6 @@ static void shutdown(struct channel *ch)
503 */ 461 */
504 if (bc) 462 if (bc)
505 writeb(0, &bc->idata); 463 writeb(0, &bc->idata);
506 tty = ch->port.tty;
507 464
508 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */ 465 /* If we're a modem control device and HUPCL is on, drop RTS & DTR. */
509 if (tty->termios->c_cflag & HUPCL) { 466 if (tty->termios->c_cflag & HUPCL) {
@@ -517,32 +474,26 @@ static void shutdown(struct channel *ch)
517 * will have to reinitialized. Set a flag to indicate this. 474 * will have to reinitialized. Set a flag to indicate this.
518 */ 475 */
519 /* Prevent future Digi programmed interrupts from coming active */ 476 /* Prevent future Digi programmed interrupts from coming active */
520 ch->port.flags &= ~ASYNC_INITIALIZED; 477 port->flags &= ~ASYNC_INITIALIZED;
521 spin_unlock_irqrestore(&epca_lock, flags); 478 spin_unlock_irqrestore(&epca_lock, flags);
522} 479}
523 480
524static void pc_hangup(struct tty_struct *tty) 481static void pc_hangup(struct tty_struct *tty)
525{ 482{
526 struct channel *ch; 483 struct channel *ch;
484
527 /* 485 /*
528 * verifyChannel returns the channel from the tty struct if it is 486 * verifyChannel returns the channel from the tty struct if it is
529 * valid. This serves as a sanity check. 487 * valid. This serves as a sanity check.
530 */ 488 */
531 ch = verifyChannel(tty); 489 ch = verifyChannel(tty);
532 if (ch != NULL) { 490 if (ch != NULL) {
533 unsigned long flags;
534
535 pc_flush_buffer(tty); 491 pc_flush_buffer(tty);
536 tty_ldisc_flush(tty); 492 tty_ldisc_flush(tty);
537 shutdown(ch); 493 shutdown(ch, tty);
538 494
539 spin_lock_irqsave(&epca_lock, flags); 495 ch->event = 0; /* FIXME: review locking of ch->event */
540 ch->port.tty = NULL; 496 tty_port_hangup(&ch->port);
541 ch->event = 0;
542 ch->port.count = 0;
543 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
544 spin_unlock_irqrestore(&epca_lock, flags);
545 wake_up_interruptible(&ch->port.open_wait);
546 } 497 }
547} 498}
548 499
@@ -786,100 +737,22 @@ static void pc_flush_chars(struct tty_struct *tty)
786 } 737 }
787} 738}
788 739
789static int block_til_ready(struct tty_struct *tty, 740static int epca_carrier_raised(struct tty_port *port)
790 struct file *filp, struct channel *ch)
791{ 741{
792 DECLARE_WAITQUEUE(wait, current); 742 struct channel *ch = container_of(port, struct channel, port);
793 int retval, do_clocal = 0; 743 if (ch->imodem & ch->dcd)
794 unsigned long flags; 744 return 1;
795
796 if (tty_hung_up_p(filp)) {
797 if (ch->port.flags & ASYNC_HUP_NOTIFY)
798 retval = -EAGAIN;
799 else
800 retval = -ERESTARTSYS;
801 return retval;
802 }
803
804 /*
805 * If the device is in the middle of being closed, then block until
806 * it's done, and then try again.
807 */
808 if (ch->port.flags & ASYNC_CLOSING) {
809 interruptible_sleep_on(&ch->port.close_wait);
810
811 if (ch->port.flags & ASYNC_HUP_NOTIFY)
812 return -EAGAIN;
813 else
814 return -ERESTARTSYS;
815 }
816
817 if (filp->f_flags & O_NONBLOCK) {
818 /*
819 * If non-blocking mode is set, then make the check up front
820 * and then exit.
821 */
822 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
823 return 0;
824 }
825 if (tty->termios->c_cflag & CLOCAL)
826 do_clocal = 1;
827 /* Block waiting for the carrier detect and the line to become free */
828
829 retval = 0;
830 add_wait_queue(&ch->port.open_wait, &wait);
831
832 spin_lock_irqsave(&epca_lock, flags);
833 /* We dec count so that pc_close will know when to free things */
834 if (!tty_hung_up_p(filp))
835 ch->port.count--;
836 ch->port.blocked_open++;
837 while (1) {
838 set_current_state(TASK_INTERRUPTIBLE);
839 if (tty_hung_up_p(filp) ||
840 !(ch->port.flags & ASYNC_INITIALIZED)) {
841 if (ch->port.flags & ASYNC_HUP_NOTIFY)
842 retval = -EAGAIN;
843 else
844 retval = -ERESTARTSYS;
845 break;
846 }
847 if (!(ch->port.flags & ASYNC_CLOSING) &&
848 (do_clocal || (ch->imodem & ch->dcd)))
849 break;
850 if (signal_pending(current)) {
851 retval = -ERESTARTSYS;
852 break;
853 }
854 spin_unlock_irqrestore(&epca_lock, flags);
855 /*
856 * Allow someone else to be scheduled. We will occasionally go
857 * through this loop until one of the above conditions change.
858 * The below schedule call will allow other processes to enter
859 * and prevent this loop from hogging the cpu.
860 */
861 schedule();
862 spin_lock_irqsave(&epca_lock, flags);
863 }
864
865 __set_current_state(TASK_RUNNING);
866 remove_wait_queue(&ch->port.open_wait, &wait);
867 if (!tty_hung_up_p(filp))
868 ch->port.count++;
869 ch->port.blocked_open--;
870
871 spin_unlock_irqrestore(&epca_lock, flags);
872
873 if (retval)
874 return retval;
875
876 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
877 return 0; 745 return 0;
878} 746}
879 747
748static void epca_raise_dtr_rts(struct tty_port *port)
749{
750}
751
880static int pc_open(struct tty_struct *tty, struct file *filp) 752static int pc_open(struct tty_struct *tty, struct file *filp)
881{ 753{
882 struct channel *ch; 754 struct channel *ch;
755 struct tty_port *port;
883 unsigned long flags; 756 unsigned long flags;
884 int line, retval, boardnum; 757 int line, retval, boardnum;
885 struct board_chan __iomem *bc; 758 struct board_chan __iomem *bc;
@@ -890,12 +763,13 @@ static int pc_open(struct tty_struct *tty, struct file *filp)
890 return -ENODEV; 763 return -ENODEV;
891 764
892 ch = &digi_channels[line]; 765 ch = &digi_channels[line];
766 port = &ch->port;
893 boardnum = ch->boardnum; 767 boardnum = ch->boardnum;
894 768
895 /* Check status of board configured in system. */ 769 /* Check status of board configured in system. */
896 770
897 /* 771 /*
898 * I check to see if the epca_setup routine detected an user error. It 772 * I check to see if the epca_setup routine detected a user error. It
899 * might be better to put this in pc_init, but for the moment it goes 773 * might be better to put this in pc_init, but for the moment it goes
900 * here. 774 * here.
901 */ 775 */
@@ -926,22 +800,24 @@ static int pc_open(struct tty_struct *tty, struct file *filp)
926 return -ENODEV; 800 return -ENODEV;
927 } 801 }
928 802
929 spin_lock_irqsave(&epca_lock, flags); 803 spin_lock_irqsave(&port->lock, flags);
930 /* 804 /*
931 * Every time a channel is opened, increment a counter. This is 805 * Every time a channel is opened, increment a counter. This is
932 * necessary because we do not wish to flush and shutdown the channel 806 * necessary because we do not wish to flush and shutdown the channel
933 * until the last app holding the channel open, closes it. 807 * until the last app holding the channel open, closes it.
934 */ 808 */
935 ch->port.count++; 809 port->count++;
936 /* 810 /*
937 * Set a kernel structures pointer to our local channel structure. This 811 * Set a kernel structures pointer to our local channel structure. This
938 * way we can get to it when passed only a tty struct. 812 * way we can get to it when passed only a tty struct.
939 */ 813 */
940 tty->driver_data = ch; 814 tty->driver_data = ch;
815 port->tty = tty;
941 /* 816 /*
942 * If this is the first time the channel has been opened, initialize 817 * If this is the first time the channel has been opened, initialize
943 * the tty->termios struct otherwise let pc_close handle it. 818 * the tty->termios struct otherwise let pc_close handle it.
944 */ 819 */
820 spin_lock(&epca_lock);
945 globalwinon(ch); 821 globalwinon(ch);
946 ch->statusflags = 0; 822 ch->statusflags = 0;
947 823
@@ -956,31 +832,33 @@ static int pc_open(struct tty_struct *tty, struct file *filp)
956 writew(head, &bc->rout); 832 writew(head, &bc->rout);
957 833
958 /* Set the channels associated tty structure */ 834 /* Set the channels associated tty structure */
959 ch->port.tty = tty;
960 835
961 /* 836 /*
962 * The below routine generally sets up parity, baud, flow control 837 * The below routine generally sets up parity, baud, flow control
963 * issues, etc.... It effect both control flags and input flags. 838 * issues, etc.... It effect both control flags and input flags.
964 */ 839 */
965 epcaparam(tty, ch); 840 epcaparam(tty, ch);
966 ch->port.flags |= ASYNC_INITIALIZED;
967 memoff(ch); 841 memoff(ch);
968 spin_unlock_irqrestore(&epca_lock, flags); 842 spin_unlock(&epca_lock);
843 port->flags |= ASYNC_INITIALIZED;
844 spin_unlock_irqrestore(&port->lock, flags);
969 845
970 retval = block_til_ready(tty, filp, ch); 846 retval = tty_port_block_til_ready(port, tty, filp);
971 if (retval) 847 if (retval)
972 return retval; 848 return retval;
973 /* 849 /*
974 * Set this again in case a hangup set it to zero while this open() was 850 * Set this again in case a hangup set it to zero while this open() was
975 * waiting for the line... 851 * waiting for the line...
976 */ 852 */
977 spin_lock_irqsave(&epca_lock, flags); 853 spin_lock_irqsave(&port->lock, flags);
978 ch->port.tty = tty; 854 port->tty = tty;
855 spin_lock(&epca_lock);
979 globalwinon(ch); 856 globalwinon(ch);
980 /* Enable Digi Data events */ 857 /* Enable Digi Data events */
981 writeb(1, &bc->idata); 858 writeb(1, &bc->idata);
982 memoff(ch); 859 memoff(ch);
983 spin_unlock_irqrestore(&epca_lock, flags); 860 spin_unlock(&epca_lock);
861 spin_unlock_irqrestore(&port->lock, flags);
984 return 0; 862 return 0;
985} 863}
986 864
@@ -1016,8 +894,11 @@ static void __exit epca_module_exit(void)
1016 } 894 }
1017 ch = card_ptr[crd]; 895 ch = card_ptr[crd];
1018 for (count = 0; count < bd->numports; count++, ch++) { 896 for (count = 0; count < bd->numports; count++, ch++) {
1019 if (ch && ch->port.tty) 897 struct tty_struct *tty = tty_port_tty_get(&ch->port);
1020 tty_hangup(ch->port.tty); 898 if (tty) {
899 tty_hangup(tty);
900 tty_kref_put(tty);
901 }
1021 } 902 }
1022 } 903 }
1023 pci_unregister_driver(&epca_driver); 904 pci_unregister_driver(&epca_driver);
@@ -1042,6 +923,11 @@ static const struct tty_operations pc_ops = {
1042 .break_ctl = pc_send_break 923 .break_ctl = pc_send_break
1043}; 924};
1044 925
926static const struct tty_port_operations epca_port_ops = {
927 .carrier_raised = epca_carrier_raised,
928 .raise_dtr_rts = epca_raise_dtr_rts,
929};
930
1045static int info_open(struct tty_struct *tty, struct file *filp) 931static int info_open(struct tty_struct *tty, struct file *filp)
1046{ 932{
1047 return 0; 933 return 0;
@@ -1377,6 +1263,7 @@ static void post_fep_init(unsigned int crd)
1377 u16 tseg, rseg; 1263 u16 tseg, rseg;
1378 1264
1379 tty_port_init(&ch->port); 1265 tty_port_init(&ch->port);
1266 ch->port.ops = &epca_port_ops;
1380 ch->brdchan = bc; 1267 ch->brdchan = bc;
1381 ch->mailbox = gd; 1268 ch->mailbox = gd;
1382 INIT_WORK(&ch->tqueue, do_softint); 1269 INIT_WORK(&ch->tqueue, do_softint);
@@ -1428,7 +1315,7 @@ static void post_fep_init(unsigned int crd)
1428 ch->boardnum = crd; 1315 ch->boardnum = crd;
1429 ch->channelnum = i; 1316 ch->channelnum = i;
1430 ch->magic = EPCA_MAGIC; 1317 ch->magic = EPCA_MAGIC;
1431 ch->port.tty = NULL; 1318 tty_port_tty_set(&ch->port, NULL);
1432 1319
1433 if (shrinkmem) { 1320 if (shrinkmem) {
1434 fepcmd(ch, SETBUFFER, 32, 0, 0, 0); 1321 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
@@ -1510,7 +1397,7 @@ static void post_fep_init(unsigned int crd)
1510 ch->fepstartca = 0; 1397 ch->fepstartca = 0;
1511 ch->fepstopca = 0; 1398 ch->fepstopca = 0;
1512 1399
1513 ch->close_delay = 50; 1400 ch->port.close_delay = 50;
1514 1401
1515 spin_unlock_irqrestore(&epca_lock, flags); 1402 spin_unlock_irqrestore(&epca_lock, flags);
1516 } 1403 }
@@ -1622,15 +1509,16 @@ static void doevent(int crd)
1622 if (bc == NULL) 1509 if (bc == NULL)
1623 goto next; 1510 goto next;
1624 1511
1512 tty = tty_port_tty_get(&ch->port);
1625 if (event & DATA_IND) { /* Begin DATA_IND */ 1513 if (event & DATA_IND) { /* Begin DATA_IND */
1626 receive_data(ch); 1514 receive_data(ch, tty);
1627 assertgwinon(ch); 1515 assertgwinon(ch);
1628 } /* End DATA_IND */ 1516 } /* End DATA_IND */
1629 /* else *//* Fix for DCD transition missed bug */ 1517 /* else *//* Fix for DCD transition missed bug */
1630 if (event & MODEMCHG_IND) { 1518 if (event & MODEMCHG_IND) {
1631 /* A modem signal change has been indicated */ 1519 /* A modem signal change has been indicated */
1632 ch->imodem = mstat; 1520 ch->imodem = mstat;
1633 if (ch->port.flags & ASYNC_CHECK_CD) { 1521 if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) {
1634 /* We are now receiving dcd */ 1522 /* We are now receiving dcd */
1635 if (mstat & ch->dcd) 1523 if (mstat & ch->dcd)
1636 wake_up_interruptible(&ch->port.open_wait); 1524 wake_up_interruptible(&ch->port.open_wait);
@@ -1638,7 +1526,6 @@ static void doevent(int crd)
1638 pc_sched_event(ch, EPCA_EVENT_HANGUP); 1526 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1639 } 1527 }
1640 } 1528 }
1641 tty = ch->port.tty;
1642 if (tty) { 1529 if (tty) {
1643 if (event & BREAK_IND) { 1530 if (event & BREAK_IND) {
1644 /* A break has been indicated */ 1531 /* A break has been indicated */
@@ -1658,6 +1545,7 @@ static void doevent(int crd)
1658 tty_wakeup(tty); 1545 tty_wakeup(tty);
1659 } 1546 }
1660 } 1547 }
1548 tty_kref_put(tty);
1661 } 1549 }
1662next: 1550next:
1663 globalwinon(ch); 1551 globalwinon(ch);
@@ -1877,9 +1765,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1877 * that the driver will wait on carrier detect. 1765 * that the driver will wait on carrier detect.
1878 */ 1766 */
1879 if (ts->c_cflag & CLOCAL) 1767 if (ts->c_cflag & CLOCAL)
1880 ch->port.flags &= ~ASYNC_CHECK_CD; 1768 clear_bit(ASYNC_CHECK_CD, &ch->port.flags);
1881 else 1769 else
1882 ch->port.flags |= ASYNC_CHECK_CD; 1770 set_bit(ASYNC_CHECK_CD, &ch->port.flags);
1883 mval = ch->m_dtr | ch->m_rts; 1771 mval = ch->m_dtr | ch->m_rts;
1884 } /* End CBAUD not detected */ 1772 } /* End CBAUD not detected */
1885 iflag = termios2digi_i(ch, ts->c_iflag); 1773 iflag = termios2digi_i(ch, ts->c_iflag);
@@ -1952,11 +1840,10 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1952} 1840}
1953 1841
1954/* Caller holds lock */ 1842/* Caller holds lock */
1955static void receive_data(struct channel *ch) 1843static void receive_data(struct channel *ch, struct tty_struct *tty)
1956{ 1844{
1957 unchar *rptr; 1845 unchar *rptr;
1958 struct ktermios *ts = NULL; 1846 struct ktermios *ts = NULL;
1959 struct tty_struct *tty;
1960 struct board_chan __iomem *bc; 1847 struct board_chan __iomem *bc;
1961 int dataToRead, wrapgap, bytesAvailable; 1848 int dataToRead, wrapgap, bytesAvailable;
1962 unsigned int tail, head; 1849 unsigned int tail, head;
@@ -1969,7 +1856,6 @@ static void receive_data(struct channel *ch)
1969 globalwinon(ch); 1856 globalwinon(ch);
1970 if (ch->statusflags & RXSTOPPED) 1857 if (ch->statusflags & RXSTOPPED)
1971 return; 1858 return;
1972 tty = ch->port.tty;
1973 if (tty) 1859 if (tty)
1974 ts = tty->termios; 1860 ts = tty->termios;
1975 bc = ch->brdchan; 1861 bc = ch->brdchan;
@@ -2029,7 +1915,7 @@ static void receive_data(struct channel *ch)
2029 globalwinon(ch); 1915 globalwinon(ch);
2030 writew(tail, &bc->rout); 1916 writew(tail, &bc->rout);
2031 /* Must be called with global data */ 1917 /* Must be called with global data */
2032 tty_schedule_flip(ch->port.tty); 1918 tty_schedule_flip(tty);
2033} 1919}
2034 1920
2035static int info_ioctl(struct tty_struct *tty, struct file *file, 1921static int info_ioctl(struct tty_struct *tty, struct file *file,
@@ -2097,7 +1983,7 @@ static int info_ioctl(struct tty_struct *tty, struct file *file,
2097 1983
2098static int pc_tiocmget(struct tty_struct *tty, struct file *file) 1984static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2099{ 1985{
2100 struct channel *ch = (struct channel *) tty->driver_data; 1986 struct channel *ch = tty->driver_data;
2101 struct board_chan __iomem *bc; 1987 struct board_chan __iomem *bc;
2102 unsigned int mstat, mflag = 0; 1988 unsigned int mstat, mflag = 0;
2103 unsigned long flags; 1989 unsigned long flags;
@@ -2131,7 +2017,7 @@ static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2131static int pc_tiocmset(struct tty_struct *tty, struct file *file, 2017static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2132 unsigned int set, unsigned int clear) 2018 unsigned int set, unsigned int clear)
2133{ 2019{
2134 struct channel *ch = (struct channel *) tty->driver_data; 2020 struct channel *ch = tty->driver_data;
2135 unsigned long flags; 2021 unsigned long flags;
2136 2022
2137 if (!ch) 2023 if (!ch)
@@ -2178,7 +2064,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2178 unsigned int mflag, mstat; 2064 unsigned int mflag, mstat;
2179 unsigned char startc, stopc; 2065 unsigned char startc, stopc;
2180 struct board_chan __iomem *bc; 2066 struct board_chan __iomem *bc;
2181 struct channel *ch = (struct channel *) tty->driver_data; 2067 struct channel *ch = tty->driver_data;
2182 void __user *argp = (void __user *)arg; 2068 void __user *argp = (void __user *)arg;
2183 2069
2184 if (ch) 2070 if (ch)
@@ -2352,15 +2238,16 @@ static void do_softint(struct work_struct *work)
2352 struct channel *ch = container_of(work, struct channel, tqueue); 2238 struct channel *ch = container_of(work, struct channel, tqueue);
2353 /* Called in response to a modem change event */ 2239 /* Called in response to a modem change event */
2354 if (ch && ch->magic == EPCA_MAGIC) { 2240 if (ch && ch->magic == EPCA_MAGIC) {
2355 struct tty_struct *tty = ch->port.tty; 2241 struct tty_struct *tty = tty_port_tty_get(&ch->port);;
2356 2242
2357 if (tty && tty->driver_data) { 2243 if (tty && tty->driver_data) {
2358 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { 2244 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2359 tty_hangup(tty); 2245 tty_hangup(tty);
2360 wake_up_interruptible(&ch->port.open_wait); 2246 wake_up_interruptible(&ch->port.open_wait);
2361 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; 2247 clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags);
2362 } 2248 }
2363 } 2249 }
2250 tty_kref_put(tty);
2364 } 2251 }
2365} 2252}
2366 2253
@@ -2473,7 +2360,7 @@ static void pc_unthrottle(struct tty_struct *tty)
2473 2360
2474static int pc_send_break(struct tty_struct *tty, int msec) 2361static int pc_send_break(struct tty_struct *tty, int msec)
2475{ 2362{
2476 struct channel *ch = (struct channel *) tty->driver_data; 2363 struct channel *ch = tty->driver_data;
2477 unsigned long flags; 2364 unsigned long flags;
2478 2365
2479 if (msec == -1) 2366 if (msec == -1)