aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/rocket.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/rocket.c')
-rw-r--r--drivers/char/rocket.c320
1 files changed, 101 insertions, 219 deletions
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 584d791e84a6..f59fc5cea067 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -135,6 +135,7 @@ static int rcktpt_type[NUM_BOARDS];
135static int is_PCI[NUM_BOARDS]; 135static int is_PCI[NUM_BOARDS];
136static rocketModel_t rocketModel[NUM_BOARDS]; 136static rocketModel_t rocketModel[NUM_BOARDS];
137static int max_board; 137static int max_board;
138static const struct tty_port_operations rocket_port_ops;
138 139
139/* 140/*
140 * The following arrays define the interrupt bits corresponding to each AIOP. 141 * The following arrays define the interrupt bits corresponding to each AIOP.
@@ -435,15 +436,15 @@ static void rp_do_transmit(struct r_port *info)
435#endif 436#endif
436 if (!info) 437 if (!info)
437 return; 438 return;
438 if (!info->port.tty) { 439 tty = tty_port_tty_get(&info->port);
439 printk(KERN_WARNING "rp: WARNING %s called with " 440
440 "info->port.tty==NULL\n", __func__); 441 if (tty == NULL) {
442 printk(KERN_WARNING "rp: WARNING %s called with tty==NULL\n", __func__);
441 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 443 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
442 return; 444 return;
443 } 445 }
444 446
445 spin_lock_irqsave(&info->slock, flags); 447 spin_lock_irqsave(&info->slock, flags);
446 tty = info->port.tty;
447 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp); 448 info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
448 449
449 /* Loop sending data to FIFO until done or FIFO full */ 450 /* Loop sending data to FIFO until done or FIFO full */
@@ -477,6 +478,7 @@ static void rp_do_transmit(struct r_port *info)
477 } 478 }
478 479
479 spin_unlock_irqrestore(&info->slock, flags); 480 spin_unlock_irqrestore(&info->slock, flags);
481 tty_kref_put(tty);
480 482
481#ifdef ROCKET_DEBUG_INTR 483#ifdef ROCKET_DEBUG_INTR
482 printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head, 484 printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
@@ -498,18 +500,18 @@ static void rp_handle_port(struct r_port *info)
498 if (!info) 500 if (!info)
499 return; 501 return;
500 502
501 if ((info->flags & ROCKET_INITIALIZED) == 0) { 503 if ((info->port.flags & ASYNC_INITIALIZED) == 0) {
502 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " 504 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
503 "info->flags & NOT_INIT\n"); 505 "info->flags & NOT_INIT\n");
504 return; 506 return;
505 } 507 }
506 if (!info->port.tty) { 508 tty = tty_port_tty_get(&info->port);
509 if (!tty) {
507 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with " 510 printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
508 "info->port.tty==NULL\n"); 511 "tty==NULL\n");
509 return; 512 return;
510 } 513 }
511 cp = &info->channel; 514 cp = &info->channel;
512 tty = info->port.tty;
513 515
514 IntMask = sGetChanIntID(cp) & info->intmask; 516 IntMask = sGetChanIntID(cp) & info->intmask;
515#ifdef ROCKET_DEBUG_INTR 517#ifdef ROCKET_DEBUG_INTR
@@ -541,6 +543,7 @@ static void rp_handle_port(struct r_port *info)
541 printk(KERN_INFO "DSR change...\n"); 543 printk(KERN_INFO "DSR change...\n");
542 } 544 }
543#endif 545#endif
546 tty_kref_put(tty);
544} 547}
545 548
546/* 549/*
@@ -649,9 +652,8 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
649 info->board = board; 652 info->board = board;
650 info->aiop = aiop; 653 info->aiop = aiop;
651 info->chan = chan; 654 info->chan = chan;
652 info->port.closing_wait = 3000; 655 tty_port_init(&info->port);
653 info->port.close_delay = 50; 656 info->port.ops = &rocket_port_ops;
654 init_waitqueue_head(&info->port.open_wait);
655 init_completion(&info->close_wait); 657 init_completion(&info->close_wait);
656 info->flags &= ~ROCKET_MODE_MASK; 658 info->flags &= ~ROCKET_MODE_MASK;
657 switch (pc104[board][line]) { 659 switch (pc104[board][line]) {
@@ -710,7 +712,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
710 * Configures a rocketport port according to its termio settings. Called from 712 * Configures a rocketport port according to its termio settings. Called from
711 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected. 713 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
712 */ 714 */
713static void configure_r_port(struct r_port *info, 715static void configure_r_port(struct tty_struct *tty, struct r_port *info,
714 struct ktermios *old_termios) 716 struct ktermios *old_termios)
715{ 717{
716 unsigned cflag; 718 unsigned cflag;
@@ -718,7 +720,7 @@ static void configure_r_port(struct r_port *info,
718 unsigned rocketMode; 720 unsigned rocketMode;
719 int bits, baud, divisor; 721 int bits, baud, divisor;
720 CHANNEL_t *cp; 722 CHANNEL_t *cp;
721 struct ktermios *t = info->port.tty->termios; 723 struct ktermios *t = tty->termios;
722 724
723 cp = &info->channel; 725 cp = &info->channel;
724 cflag = t->c_cflag; 726 cflag = t->c_cflag;
@@ -751,7 +753,7 @@ static void configure_r_port(struct r_port *info,
751 } 753 }
752 754
753 /* baud rate */ 755 /* baud rate */
754 baud = tty_get_baud_rate(info->port.tty); 756 baud = tty_get_baud_rate(tty);
755 if (!baud) 757 if (!baud)
756 baud = 9600; 758 baud = 9600;
757 divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1; 759 divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
@@ -769,7 +771,7 @@ static void configure_r_port(struct r_port *info,
769 sSetBaud(cp, divisor); 771 sSetBaud(cp, divisor);
770 772
771 /* FIXME: Should really back compute a baud rate from the divisor */ 773 /* FIXME: Should really back compute a baud rate from the divisor */
772 tty_encode_baud_rate(info->port.tty, baud, baud); 774 tty_encode_baud_rate(tty, baud, baud);
773 775
774 if (cflag & CRTSCTS) { 776 if (cflag & CRTSCTS) {
775 info->intmask |= DELTA_CTS; 777 info->intmask |= DELTA_CTS;
@@ -794,15 +796,15 @@ static void configure_r_port(struct r_port *info,
794 * Handle software flow control in the board 796 * Handle software flow control in the board
795 */ 797 */
796#ifdef ROCKET_SOFT_FLOW 798#ifdef ROCKET_SOFT_FLOW
797 if (I_IXON(info->port.tty)) { 799 if (I_IXON(tty)) {
798 sEnTxSoftFlowCtl(cp); 800 sEnTxSoftFlowCtl(cp);
799 if (I_IXANY(info->port.tty)) { 801 if (I_IXANY(tty)) {
800 sEnIXANY(cp); 802 sEnIXANY(cp);
801 } else { 803 } else {
802 sDisIXANY(cp); 804 sDisIXANY(cp);
803 } 805 }
804 sSetTxXONChar(cp, START_CHAR(info->port.tty)); 806 sSetTxXONChar(cp, START_CHAR(tty));
805 sSetTxXOFFChar(cp, STOP_CHAR(info->port.tty)); 807 sSetTxXOFFChar(cp, STOP_CHAR(tty));
806 } else { 808 } else {
807 sDisTxSoftFlowCtl(cp); 809 sDisTxSoftFlowCtl(cp);
808 sDisIXANY(cp); 810 sDisIXANY(cp);
@@ -814,24 +816,24 @@ static void configure_r_port(struct r_port *info,
814 * Set up ignore/read mask words 816 * Set up ignore/read mask words
815 */ 817 */
816 info->read_status_mask = STMRCVROVRH | 0xFF; 818 info->read_status_mask = STMRCVROVRH | 0xFF;
817 if (I_INPCK(info->port.tty)) 819 if (I_INPCK(tty))
818 info->read_status_mask |= STMFRAMEH | STMPARITYH; 820 info->read_status_mask |= STMFRAMEH | STMPARITYH;
819 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) 821 if (I_BRKINT(tty) || I_PARMRK(tty))
820 info->read_status_mask |= STMBREAKH; 822 info->read_status_mask |= STMBREAKH;
821 823
822 /* 824 /*
823 * Characters to ignore 825 * Characters to ignore
824 */ 826 */
825 info->ignore_status_mask = 0; 827 info->ignore_status_mask = 0;
826 if (I_IGNPAR(info->port.tty)) 828 if (I_IGNPAR(tty))
827 info->ignore_status_mask |= STMFRAMEH | STMPARITYH; 829 info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
828 if (I_IGNBRK(info->port.tty)) { 830 if (I_IGNBRK(tty)) {
829 info->ignore_status_mask |= STMBREAKH; 831 info->ignore_status_mask |= STMBREAKH;
830 /* 832 /*
831 * If we're ignoring parity and break indicators, 833 * If we're ignoring parity and break indicators,
832 * ignore overruns too. (For real raw support). 834 * ignore overruns too. (For real raw support).
833 */ 835 */
834 if (I_IGNPAR(info->port.tty)) 836 if (I_IGNPAR(tty))
835 info->ignore_status_mask |= STMRCVROVRH; 837 info->ignore_status_mask |= STMRCVROVRH;
836 } 838 }
837 839
@@ -864,106 +866,17 @@ static void configure_r_port(struct r_port *info,
864 } 866 }
865} 867}
866 868
867/* info->port.count is considered critical, protected by spinlocks. */ 869static int carrier_raised(struct tty_port *port)
868static int block_til_ready(struct tty_struct *tty, struct file *filp,
869 struct r_port *info)
870{ 870{
871 DECLARE_WAITQUEUE(wait, current); 871 struct r_port *info = container_of(port, struct r_port, port);
872 int retval; 872 return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
873 int do_clocal = 0, extra_count = 0; 873}
874 unsigned long flags;
875
876 /*
877 * If the device is in the middle of being closed, then block
878 * until it's done, and then try again.
879 */
880 if (tty_hung_up_p(filp))
881 return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
882 if (info->flags & ROCKET_CLOSING) {
883 if (wait_for_completion_interruptible(&info->close_wait))
884 return -ERESTARTSYS;
885 return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
886 }
887
888 /*
889 * If non-blocking mode is set, or the port is not enabled,
890 * then make the check up front and then exit.
891 */
892 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
893 info->flags |= ROCKET_NORMAL_ACTIVE;
894 return 0;
895 }
896 if (tty->termios->c_cflag & CLOCAL)
897 do_clocal = 1;
898
899 /*
900 * Block waiting for the carrier detect and the line to become free. While we are in
901 * this loop, info->port.count is dropped by one, so that rp_close() knows when to free things.
902 * We restore it upon exit, either normal or abnormal.
903 */
904 retval = 0;
905 add_wait_queue(&info->port.open_wait, &wait);
906#ifdef ROCKET_DEBUG_OPEN
907 printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, info->port.count);
908#endif
909 spin_lock_irqsave(&info->slock, flags);
910
911#ifdef ROCKET_DISABLE_SIMUSAGE
912 info->flags |= ROCKET_NORMAL_ACTIVE;
913#else
914 if (!tty_hung_up_p(filp)) {
915 extra_count = 1;
916 info->port.count--;
917 }
918#endif
919 info->port.blocked_open++;
920
921 spin_unlock_irqrestore(&info->slock, flags);
922
923 while (1) {
924 if (tty->termios->c_cflag & CBAUD) {
925 sSetDTR(&info->channel);
926 sSetRTS(&info->channel);
927 }
928 set_current_state(TASK_INTERRUPTIBLE);
929 if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) {
930 if (info->flags & ROCKET_HUP_NOTIFY)
931 retval = -EAGAIN;
932 else
933 retval = -ERESTARTSYS;
934 break;
935 }
936 if (!(info->flags & ROCKET_CLOSING) && (do_clocal || (sGetChanStatusLo(&info->channel) & CD_ACT)))
937 break;
938 if (signal_pending(current)) {
939 retval = -ERESTARTSYS;
940 break;
941 }
942#ifdef ROCKET_DEBUG_OPEN
943 printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n",
944 info->line, info->port.count, info->flags);
945#endif
946 schedule(); /* Don't hold spinlock here, will hang PC */
947 }
948 __set_current_state(TASK_RUNNING);
949 remove_wait_queue(&info->port.open_wait, &wait);
950
951 spin_lock_irqsave(&info->slock, flags);
952
953 if (extra_count)
954 info->port.count++;
955 info->port.blocked_open--;
956
957 spin_unlock_irqrestore(&info->slock, flags);
958 874
959#ifdef ROCKET_DEBUG_OPEN 875static void raise_dtr_rts(struct tty_port *port)
960 printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n", 876{
961 info->line, info->port.count); 877 struct r_port *info = container_of(port, struct r_port, port);
962#endif 878 sSetDTR(&info->channel);
963 if (retval) 879 sSetRTS(&info->channel);
964 return retval;
965 info->flags |= ROCKET_NORMAL_ACTIVE;
966 return 0;
967} 880}
968 881
969/* 882/*
@@ -973,24 +886,26 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
973static int rp_open(struct tty_struct *tty, struct file *filp) 886static int rp_open(struct tty_struct *tty, struct file *filp)
974{ 887{
975 struct r_port *info; 888 struct r_port *info;
889 struct tty_port *port;
976 int line = 0, retval; 890 int line = 0, retval;
977 CHANNEL_t *cp; 891 CHANNEL_t *cp;
978 unsigned long page; 892 unsigned long page;
979 893
980 line = tty->index; 894 line = tty->index;
981 if ((line < 0) || (line >= MAX_RP_PORTS) || ((info = rp_table[line]) == NULL)) 895 if (line < 0 || line >= MAX_RP_PORTS || ((info = rp_table[line]) == NULL))
982 return -ENXIO; 896 return -ENXIO;
983 897 port = &info->port;
898
984 page = __get_free_page(GFP_KERNEL); 899 page = __get_free_page(GFP_KERNEL);
985 if (!page) 900 if (!page)
986 return -ENOMEM; 901 return -ENOMEM;
987 902
988 if (info->flags & ROCKET_CLOSING) { 903 if (port->flags & ASYNC_CLOSING) {
989 retval = wait_for_completion_interruptible(&info->close_wait); 904 retval = wait_for_completion_interruptible(&info->close_wait);
990 free_page(page); 905 free_page(page);
991 if (retval) 906 if (retval)
992 return retval; 907 return retval;
993 return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 908 return ((port->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
994 } 909 }
995 910
996 /* 911 /*
@@ -1002,9 +917,9 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1002 info->xmit_buf = (unsigned char *) page; 917 info->xmit_buf = (unsigned char *) page;
1003 918
1004 tty->driver_data = info; 919 tty->driver_data = info;
1005 info->port.tty = tty; 920 tty_port_tty_set(port, tty);
1006 921
1007 if (info->port.count++ == 0) { 922 if (port->count++ == 0) {
1008 atomic_inc(&rp_num_ports_open); 923 atomic_inc(&rp_num_ports_open);
1009 924
1010#ifdef ROCKET_DEBUG_OPEN 925#ifdef ROCKET_DEBUG_OPEN
@@ -1019,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1019 /* 934 /*
1020 * Info->count is now 1; so it's safe to sleep now. 935 * Info->count is now 1; so it's safe to sleep now.
1021 */ 936 */
1022 if ((info->flags & ROCKET_INITIALIZED) == 0) { 937 if (!test_bit(ASYNC_INITIALIZED, &port->flags)) {
1023 cp = &info->channel; 938 cp = &info->channel;
1024 sSetRxTrigger(cp, TRIG_1); 939 sSetRxTrigger(cp, TRIG_1);
1025 if (sGetChanStatus(cp) & CD_ACT) 940 if (sGetChanStatus(cp) & CD_ACT)
@@ -1043,21 +958,21 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1043 sEnRxFIFO(cp); 958 sEnRxFIFO(cp);
1044 sEnTransmit(cp); 959 sEnTransmit(cp);
1045 960
1046 info->flags |= ROCKET_INITIALIZED; 961 set_bit(ASYNC_INITIALIZED, &info->port.flags);
1047 962
1048 /* 963 /*
1049 * Set up the tty->alt_speed kludge 964 * Set up the tty->alt_speed kludge
1050 */ 965 */
1051 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI) 966 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
1052 info->port.tty->alt_speed = 57600; 967 tty->alt_speed = 57600;
1053 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI) 968 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
1054 info->port.tty->alt_speed = 115200; 969 tty->alt_speed = 115200;
1055 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI) 970 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
1056 info->port.tty->alt_speed = 230400; 971 tty->alt_speed = 230400;
1057 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) 972 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
1058 info->port.tty->alt_speed = 460800; 973 tty->alt_speed = 460800;
1059 974
1060 configure_r_port(info, NULL); 975 configure_r_port(tty, info, NULL);
1061 if (tty->termios->c_cflag & CBAUD) { 976 if (tty->termios->c_cflag & CBAUD) {
1062 sSetDTR(cp); 977 sSetDTR(cp);
1063 sSetRTS(cp); 978 sSetRTS(cp);
@@ -1066,7 +981,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1066 /* Starts (or resets) the maint polling loop */ 981 /* Starts (or resets) the maint polling loop */
1067 mod_timer(&rocket_timer, jiffies + POLL_PERIOD); 982 mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
1068 983
1069 retval = block_til_ready(tty, filp, info); 984 retval = tty_port_block_til_ready(port, tty, filp);
1070 if (retval) { 985 if (retval) {
1071#ifdef ROCKET_DEBUG_OPEN 986#ifdef ROCKET_DEBUG_OPEN
1072 printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval); 987 printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval);
@@ -1081,8 +996,8 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1081 */ 996 */
1082static void rp_close(struct tty_struct *tty, struct file *filp) 997static void rp_close(struct tty_struct *tty, struct file *filp)
1083{ 998{
1084 struct r_port *info = (struct r_port *) tty->driver_data; 999 struct r_port *info = tty->driver_data;
1085 unsigned long flags; 1000 struct tty_port *port = &info->port;
1086 int timeout; 1001 int timeout;
1087 CHANNEL_t *cp; 1002 CHANNEL_t *cp;
1088 1003
@@ -1093,53 +1008,10 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1093 printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count); 1008 printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->port.count);
1094#endif 1009#endif
1095 1010
1096 if (tty_hung_up_p(filp)) 1011 if (tty_port_close_start(port, tty, filp) == 0)
1097 return;
1098 spin_lock_irqsave(&info->slock, flags);
1099
1100 if ((tty->count == 1) && (info->port.count != 1)) {
1101 /*
1102 * Uh, oh. tty->count is 1, which means that the tty
1103 * structure will be freed. Info->count should always
1104 * be one in these conditions. If it's greater than
1105 * one, we've got real problems, since it means the
1106 * serial port won't be shutdown.
1107 */
1108 printk(KERN_WARNING "rp_close: bad serial port count; "
1109 "tty->count is 1, info->port.count is %d\n", info->port.count);
1110 info->port.count = 1;
1111 }
1112 if (--info->port.count < 0) {
1113 printk(KERN_WARNING "rp_close: bad serial port count for "
1114 "ttyR%d: %d\n", info->line, info->port.count);
1115 info->port.count = 0;
1116 }
1117 if (info->port.count) {
1118 spin_unlock_irqrestore(&info->slock, flags);
1119 return; 1012 return;
1120 }
1121 info->flags |= ROCKET_CLOSING;
1122 spin_unlock_irqrestore(&info->slock, flags);
1123 1013
1124 cp = &info->channel; 1014 cp = &info->channel;
1125
1126 /*
1127 * Notify the line discpline to only process XON/XOFF characters
1128 */
1129 tty->closing = 1;
1130
1131 /*
1132 * If transmission was throttled by the application request,
1133 * just flush the xmit buffer.
1134 */
1135 if (tty->flow_stopped)
1136 rp_flush_buffer(tty);
1137
1138 /*
1139 * Wait for the transmit buffer to clear
1140 */
1141 if (info->port.closing_wait != ROCKET_CLOSING_WAIT_NONE)
1142 tty_wait_until_sent(tty, info->port.closing_wait);
1143 /* 1015 /*
1144 * Before we drop DTR, make sure the UART transmitter 1016 * Before we drop DTR, make sure the UART transmitter
1145 * has completely drained; this is especially 1017 * has completely drained; this is especially
@@ -1168,19 +1040,24 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1168 1040
1169 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 1041 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
1170 1042
1171 if (info->port.blocked_open) { 1043 /* We can't yet use tty_port_close_end as the buffer handling in this
1172 if (info->port.close_delay) { 1044 driver is a bit different to the usual */
1173 msleep_interruptible(jiffies_to_msecs(info->port.close_delay)); 1045
1046 if (port->blocked_open) {
1047 if (port->close_delay) {
1048 msleep_interruptible(jiffies_to_msecs(port->close_delay));
1174 } 1049 }
1175 wake_up_interruptible(&info->port.open_wait); 1050 wake_up_interruptible(&port->open_wait);
1176 } else { 1051 } else {
1177 if (info->xmit_buf) { 1052 if (info->xmit_buf) {
1178 free_page((unsigned long) info->xmit_buf); 1053 free_page((unsigned long) info->xmit_buf);
1179 info->xmit_buf = NULL; 1054 info->xmit_buf = NULL;
1180 } 1055 }
1181 } 1056 }
1182 info->flags &= ~(ROCKET_INITIALIZED | ROCKET_CLOSING | ROCKET_NORMAL_ACTIVE); 1057 info->port.flags &= ~(ASYNC_INITIALIZED | ASYNC_CLOSING | ASYNC_NORMAL_ACTIVE);
1183 tty->closing = 0; 1058 tty->closing = 0;
1059 tty_port_tty_set(port, NULL);
1060 wake_up_interruptible(&port->close_wait);
1184 complete_all(&info->close_wait); 1061 complete_all(&info->close_wait);
1185 atomic_dec(&rp_num_ports_open); 1062 atomic_dec(&rp_num_ports_open);
1186 1063
@@ -1195,7 +1072,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1195static void rp_set_termios(struct tty_struct *tty, 1072static void rp_set_termios(struct tty_struct *tty,
1196 struct ktermios *old_termios) 1073 struct ktermios *old_termios)
1197{ 1074{
1198 struct r_port *info = (struct r_port *) tty->driver_data; 1075 struct r_port *info = tty->driver_data;
1199 CHANNEL_t *cp; 1076 CHANNEL_t *cp;
1200 unsigned cflag; 1077 unsigned cflag;
1201 1078
@@ -1213,7 +1090,7 @@ static void rp_set_termios(struct tty_struct *tty,
1213 /* Or CMSPAR */ 1090 /* Or CMSPAR */
1214 tty->termios->c_cflag &= ~CMSPAR; 1091 tty->termios->c_cflag &= ~CMSPAR;
1215 1092
1216 configure_r_port(info, old_termios); 1093 configure_r_port(tty, info, old_termios);
1217 1094
1218 cp = &info->channel; 1095 cp = &info->channel;
1219 1096
@@ -1238,7 +1115,7 @@ static void rp_set_termios(struct tty_struct *tty,
1238 1115
1239static int rp_break(struct tty_struct *tty, int break_state) 1116static int rp_break(struct tty_struct *tty, int break_state)
1240{ 1117{
1241 struct r_port *info = (struct r_port *) tty->driver_data; 1118 struct r_port *info = tty->driver_data;
1242 unsigned long flags; 1119 unsigned long flags;
1243 1120
1244 if (rocket_paranoia_check(info, "rp_break")) 1121 if (rocket_paranoia_check(info, "rp_break"))
@@ -1284,7 +1161,7 @@ static int sGetChanRI(CHANNEL_T * ChP)
1284 */ 1161 */
1285static int rp_tiocmget(struct tty_struct *tty, struct file *file) 1162static int rp_tiocmget(struct tty_struct *tty, struct file *file)
1286{ 1163{
1287 struct r_port *info = (struct r_port *)tty->driver_data; 1164 struct r_port *info = tty->driver_data;
1288 unsigned int control, result, ChanStatus; 1165 unsigned int control, result, ChanStatus;
1289 1166
1290 ChanStatus = sGetChanStatusLo(&info->channel); 1167 ChanStatus = sGetChanStatusLo(&info->channel);
@@ -1305,7 +1182,7 @@ static int rp_tiocmget(struct tty_struct *tty, struct file *file)
1305static int rp_tiocmset(struct tty_struct *tty, struct file *file, 1182static int rp_tiocmset(struct tty_struct *tty, struct file *file,
1306 unsigned int set, unsigned int clear) 1183 unsigned int set, unsigned int clear)
1307{ 1184{
1308 struct r_port *info = (struct r_port *)tty->driver_data; 1185 struct r_port *info = tty->driver_data;
1309 1186
1310 if (set & TIOCM_RTS) 1187 if (set & TIOCM_RTS)
1311 info->channel.TxControl[3] |= SET_RTS; 1188 info->channel.TxControl[3] |= SET_RTS;
@@ -1338,7 +1215,8 @@ static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
1338 return 0; 1215 return 0;
1339} 1216}
1340 1217
1341static int set_config(struct r_port *info, struct rocket_config __user *new_info) 1218static int set_config(struct tty_struct *tty, struct r_port *info,
1219 struct rocket_config __user *new_info)
1342{ 1220{
1343 struct rocket_config new_serial; 1221 struct rocket_config new_serial;
1344 1222
@@ -1350,7 +1228,7 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
1350 if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK)) 1228 if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
1351 return -EPERM; 1229 return -EPERM;
1352 info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK)); 1230 info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
1353 configure_r_port(info, NULL); 1231 configure_r_port(tty, info, NULL);
1354 return 0; 1232 return 0;
1355 } 1233 }
1356 1234
@@ -1359,15 +1237,15 @@ static int set_config(struct r_port *info, struct rocket_config __user *new_info
1359 info->port.closing_wait = new_serial.closing_wait; 1237 info->port.closing_wait = new_serial.closing_wait;
1360 1238
1361 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI) 1239 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
1362 info->port.tty->alt_speed = 57600; 1240 tty->alt_speed = 57600;
1363 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI) 1241 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
1364 info->port.tty->alt_speed = 115200; 1242 tty->alt_speed = 115200;
1365 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI) 1243 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
1366 info->port.tty->alt_speed = 230400; 1244 tty->alt_speed = 230400;
1367 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP) 1245 if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
1368 info->port.tty->alt_speed = 460800; 1246 tty->alt_speed = 460800;
1369 1247
1370 configure_r_port(info, NULL); 1248 configure_r_port(tty, info, NULL);
1371 return 0; 1249 return 0;
1372} 1250}
1373 1251
@@ -1434,7 +1312,7 @@ static int get_version(struct r_port *info, struct rocket_version __user *retver
1434static int rp_ioctl(struct tty_struct *tty, struct file *file, 1312static int rp_ioctl(struct tty_struct *tty, struct file *file,
1435 unsigned int cmd, unsigned long arg) 1313 unsigned int cmd, unsigned long arg)
1436{ 1314{
1437 struct r_port *info = (struct r_port *) tty->driver_data; 1315 struct r_port *info = tty->driver_data;
1438 void __user *argp = (void __user *)arg; 1316 void __user *argp = (void __user *)arg;
1439 int ret = 0; 1317 int ret = 0;
1440 1318
@@ -1452,7 +1330,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1452 ret = get_config(info, argp); 1330 ret = get_config(info, argp);
1453 break; 1331 break;
1454 case RCKP_SET_CONFIG: 1332 case RCKP_SET_CONFIG:
1455 ret = set_config(info, argp); 1333 ret = set_config(tty, info, argp);
1456 break; 1334 break;
1457 case RCKP_GET_PORTS: 1335 case RCKP_GET_PORTS:
1458 ret = get_ports(info, argp); 1336 ret = get_ports(info, argp);
@@ -1472,7 +1350,7 @@ static int rp_ioctl(struct tty_struct *tty, struct file *file,
1472 1350
1473static void rp_send_xchar(struct tty_struct *tty, char ch) 1351static void rp_send_xchar(struct tty_struct *tty, char ch)
1474{ 1352{
1475 struct r_port *info = (struct r_port *) tty->driver_data; 1353 struct r_port *info = tty->driver_data;
1476 CHANNEL_t *cp; 1354 CHANNEL_t *cp;
1477 1355
1478 if (rocket_paranoia_check(info, "rp_send_xchar")) 1356 if (rocket_paranoia_check(info, "rp_send_xchar"))
@@ -1487,7 +1365,7 @@ static void rp_send_xchar(struct tty_struct *tty, char ch)
1487 1365
1488static void rp_throttle(struct tty_struct *tty) 1366static void rp_throttle(struct tty_struct *tty)
1489{ 1367{
1490 struct r_port *info = (struct r_port *) tty->driver_data; 1368 struct r_port *info = tty->driver_data;
1491 CHANNEL_t *cp; 1369 CHANNEL_t *cp;
1492 1370
1493#ifdef ROCKET_DEBUG_THROTTLE 1371#ifdef ROCKET_DEBUG_THROTTLE
@@ -1507,7 +1385,7 @@ static void rp_throttle(struct tty_struct *tty)
1507 1385
1508static void rp_unthrottle(struct tty_struct *tty) 1386static void rp_unthrottle(struct tty_struct *tty)
1509{ 1387{
1510 struct r_port *info = (struct r_port *) tty->driver_data; 1388 struct r_port *info = tty->driver_data;
1511 CHANNEL_t *cp; 1389 CHANNEL_t *cp;
1512#ifdef ROCKET_DEBUG_THROTTLE 1390#ifdef ROCKET_DEBUG_THROTTLE
1513 printk(KERN_INFO "unthrottle %s: %d....\n", tty->name, 1391 printk(KERN_INFO "unthrottle %s: %d....\n", tty->name,
@@ -1534,7 +1412,7 @@ static void rp_unthrottle(struct tty_struct *tty)
1534 */ 1412 */
1535static void rp_stop(struct tty_struct *tty) 1413static void rp_stop(struct tty_struct *tty)
1536{ 1414{
1537 struct r_port *info = (struct r_port *) tty->driver_data; 1415 struct r_port *info = tty->driver_data;
1538 1416
1539#ifdef ROCKET_DEBUG_FLOW 1417#ifdef ROCKET_DEBUG_FLOW
1540 printk(KERN_INFO "stop %s: %d %d....\n", tty->name, 1418 printk(KERN_INFO "stop %s: %d %d....\n", tty->name,
@@ -1550,7 +1428,7 @@ static void rp_stop(struct tty_struct *tty)
1550 1428
1551static void rp_start(struct tty_struct *tty) 1429static void rp_start(struct tty_struct *tty)
1552{ 1430{
1553 struct r_port *info = (struct r_port *) tty->driver_data; 1431 struct r_port *info = tty->driver_data;
1554 1432
1555#ifdef ROCKET_DEBUG_FLOW 1433#ifdef ROCKET_DEBUG_FLOW
1556 printk(KERN_INFO "start %s: %d %d....\n", tty->name, 1434 printk(KERN_INFO "start %s: %d %d....\n", tty->name,
@@ -1570,7 +1448,7 @@ static void rp_start(struct tty_struct *tty)
1570 */ 1448 */
1571static void rp_wait_until_sent(struct tty_struct *tty, int timeout) 1449static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1572{ 1450{
1573 struct r_port *info = (struct r_port *) tty->driver_data; 1451 struct r_port *info = tty->driver_data;
1574 CHANNEL_t *cp; 1452 CHANNEL_t *cp;
1575 unsigned long orig_jiffies; 1453 unsigned long orig_jiffies;
1576 int check_time, exit_time; 1454 int check_time, exit_time;
@@ -1627,7 +1505,7 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1627static void rp_hangup(struct tty_struct *tty) 1505static void rp_hangup(struct tty_struct *tty)
1628{ 1506{
1629 CHANNEL_t *cp; 1507 CHANNEL_t *cp;
1630 struct r_port *info = (struct r_port *) tty->driver_data; 1508 struct r_port *info = tty->driver_data;
1631 1509
1632 if (rocket_paranoia_check(info, "rp_hangup")) 1510 if (rocket_paranoia_check(info, "rp_hangup"))
1633 return; 1511 return;
@@ -1636,15 +1514,13 @@ static void rp_hangup(struct tty_struct *tty)
1636 printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line); 1514 printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
1637#endif 1515#endif
1638 rp_flush_buffer(tty); 1516 rp_flush_buffer(tty);
1639 if (info->flags & ROCKET_CLOSING) 1517 if (info->port.flags & ASYNC_CLOSING)
1640 return; 1518 return;
1641 if (info->port.count) 1519 if (info->port.count)
1642 atomic_dec(&rp_num_ports_open); 1520 atomic_dec(&rp_num_ports_open);
1643 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]); 1521 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
1644 1522
1645 info->port.count = 0; 1523 tty_port_hangup(&info->port);
1646 info->flags &= ~ROCKET_NORMAL_ACTIVE;
1647 info->port.tty = NULL;
1648 1524
1649 cp = &info->channel; 1525 cp = &info->channel;
1650 sDisRxFIFO(cp); 1526 sDisRxFIFO(cp);
@@ -1653,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
1653 sDisCTSFlowCtl(cp); 1529 sDisCTSFlowCtl(cp);
1654 sDisTxSoftFlowCtl(cp); 1530 sDisTxSoftFlowCtl(cp);
1655 sClrTxXOFF(cp); 1531 sClrTxXOFF(cp);
1656 info->flags &= ~ROCKET_INITIALIZED; 1532 info->port.flags &= ~ASYNC_INITIALIZED;
1657 1533
1658 wake_up_interruptible(&info->port.open_wait); 1534 wake_up_interruptible(&info->port.open_wait);
1659} 1535}
@@ -1667,7 +1543,7 @@ static void rp_hangup(struct tty_struct *tty)
1667 */ 1543 */
1668static int rp_put_char(struct tty_struct *tty, unsigned char ch) 1544static int rp_put_char(struct tty_struct *tty, unsigned char ch)
1669{ 1545{
1670 struct r_port *info = (struct r_port *) tty->driver_data; 1546 struct r_port *info = tty->driver_data;
1671 CHANNEL_t *cp; 1547 CHANNEL_t *cp;
1672 unsigned long flags; 1548 unsigned long flags;
1673 1549
@@ -1714,7 +1590,7 @@ static int rp_put_char(struct tty_struct *tty, unsigned char ch)
1714static int rp_write(struct tty_struct *tty, 1590static int rp_write(struct tty_struct *tty,
1715 const unsigned char *buf, int count) 1591 const unsigned char *buf, int count)
1716{ 1592{
1717 struct r_port *info = (struct r_port *) tty->driver_data; 1593 struct r_port *info = tty->driver_data;
1718 CHANNEL_t *cp; 1594 CHANNEL_t *cp;
1719 const unsigned char *b; 1595 const unsigned char *b;
1720 int c, retval = 0; 1596 int c, retval = 0;
@@ -1764,7 +1640,8 @@ static int rp_write(struct tty_struct *tty,
1764 1640
1765 /* Write remaining data into the port's xmit_buf */ 1641 /* Write remaining data into the port's xmit_buf */
1766 while (1) { 1642 while (1) {
1767 if (!info->port.tty) /* Seemingly obligatory check... */ 1643 /* Hung up ? */
1644 if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags))
1768 goto end; 1645 goto end;
1769 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); 1646 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
1770 c = min(c, XMIT_BUF_SIZE - info->xmit_head); 1647 c = min(c, XMIT_BUF_SIZE - info->xmit_head);
@@ -1806,7 +1683,7 @@ end:
1806 */ 1683 */
1807static int rp_write_room(struct tty_struct *tty) 1684static int rp_write_room(struct tty_struct *tty)
1808{ 1685{
1809 struct r_port *info = (struct r_port *) tty->driver_data; 1686 struct r_port *info = tty->driver_data;
1810 int ret; 1687 int ret;
1811 1688
1812 if (rocket_paranoia_check(info, "rp_write_room")) 1689 if (rocket_paranoia_check(info, "rp_write_room"))
@@ -1827,7 +1704,7 @@ static int rp_write_room(struct tty_struct *tty)
1827 */ 1704 */
1828static int rp_chars_in_buffer(struct tty_struct *tty) 1705static int rp_chars_in_buffer(struct tty_struct *tty)
1829{ 1706{
1830 struct r_port *info = (struct r_port *) tty->driver_data; 1707 struct r_port *info = tty->driver_data;
1831 CHANNEL_t *cp; 1708 CHANNEL_t *cp;
1832 1709
1833 if (rocket_paranoia_check(info, "rp_chars_in_buffer")) 1710 if (rocket_paranoia_check(info, "rp_chars_in_buffer"))
@@ -1848,7 +1725,7 @@ static int rp_chars_in_buffer(struct tty_struct *tty)
1848 */ 1725 */
1849static void rp_flush_buffer(struct tty_struct *tty) 1726static void rp_flush_buffer(struct tty_struct *tty)
1850{ 1727{
1851 struct r_port *info = (struct r_port *) tty->driver_data; 1728 struct r_port *info = tty->driver_data;
1852 CHANNEL_t *cp; 1729 CHANNEL_t *cp;
1853 unsigned long flags; 1730 unsigned long flags;
1854 1731
@@ -2371,6 +2248,11 @@ static const struct tty_operations rocket_ops = {
2371 .tiocmset = rp_tiocmset, 2248 .tiocmset = rp_tiocmset,
2372}; 2249};
2373 2250
2251static const struct tty_port_operations rocket_port_ops = {
2252 .carrier_raised = carrier_raised,
2253 .raise_dtr_rts = raise_dtr_rts,
2254};
2255
2374/* 2256/*
2375 * The module "startup" routine; it's run when the module is loaded. 2257 * The module "startup" routine; it's run when the module is loaded.
2376 */ 2258 */