aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/mct_u232.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:09:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:22 -0400
commit95da310e66ee8090119596c70ca8432e57f9a97f (patch)
tree7f18c30e9c9ad4d7d53df6453fa338be06f09a85 /drivers/usb/serial/mct_u232.c
parent1aa3692da57c773e5c76de55c5c4a953962d360e (diff)
usb_serial: API all change
USB serial likes to use port->tty back pointers for the real work it does and to do so without any actual locking. Unfortunately when you consider hangup events, hangup/parallel reopen or even worse hangup followed by parallel close events the tty->port and port->tty pointers are not guaranteed to be the same as port->tty is the active tty while tty->port is the port the tty may or may not still be attached to. So rework the entire API to pass the tty struct. For console cases we need to pass both for now. This shows up multiple drivers that immediately crash with USB console some of which have been fixed in the process. Longer term we need a proper tty as console abstraction Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial/mct_u232.c')
-rw-r--r--drivers/usb/serial/mct_u232.c121
1 files changed, 49 insertions, 72 deletions
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 5fc2cef30e39..7bce4302a5f9 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -92,26 +92,25 @@ static int debug;
92 */ 92 */
93static int mct_u232_startup (struct usb_serial *serial); 93static int mct_u232_startup (struct usb_serial *serial);
94static void mct_u232_shutdown (struct usb_serial *serial); 94static void mct_u232_shutdown (struct usb_serial *serial);
95static int mct_u232_open (struct usb_serial_port *port, 95static int mct_u232_open (struct tty_struct *tty,
96 struct usb_serial_port *port,
96 struct file *filp); 97 struct file *filp);
97static void mct_u232_close (struct usb_serial_port *port, 98static void mct_u232_close (struct tty_struct *tty,
99 struct usb_serial_port *port,
98 struct file *filp); 100 struct file *filp);
99static void mct_u232_read_int_callback (struct urb *urb); 101static void mct_u232_read_int_callback (struct urb *urb);
100static void mct_u232_set_termios (struct usb_serial_port *port, 102static void mct_u232_set_termios (struct tty_struct *tty,
103 struct usb_serial_port *port,
101 struct ktermios * old); 104 struct ktermios * old);
102static int mct_u232_ioctl (struct usb_serial_port *port, 105static void mct_u232_break_ctl (struct tty_struct *tty,
103 struct file * file,
104 unsigned int cmd,
105 unsigned long arg);
106static void mct_u232_break_ctl (struct usb_serial_port *port,
107 int break_state ); 106 int break_state );
108static int mct_u232_tiocmget (struct usb_serial_port *port, 107static int mct_u232_tiocmget (struct tty_struct *tty,
109 struct file *file); 108 struct file *file);
110static int mct_u232_tiocmset (struct usb_serial_port *port, 109static int mct_u232_tiocmset (struct tty_struct *tty,
111 struct file *file, unsigned int set, 110 struct file *file, unsigned int set,
112 unsigned int clear); 111 unsigned int clear);
113static void mct_u232_throttle (struct usb_serial_port *port); 112static void mct_u232_throttle (struct tty_struct *tty);
114static void mct_u232_unthrottle (struct usb_serial_port *port); 113static void mct_u232_unthrottle (struct tty_struct *tty);
115 114
116 115
117/* 116/*
@@ -149,7 +148,6 @@ static struct usb_serial_driver mct_u232_device = {
149 .throttle = mct_u232_throttle, 148 .throttle = mct_u232_throttle,
150 .unthrottle = mct_u232_unthrottle, 149 .unthrottle = mct_u232_unthrottle,
151 .read_int_callback = mct_u232_read_int_callback, 150 .read_int_callback = mct_u232_read_int_callback,
152 .ioctl = mct_u232_ioctl,
153 .set_termios = mct_u232_set_termios, 151 .set_termios = mct_u232_set_termios,
154 .break_ctl = mct_u232_break_ctl, 152 .break_ctl = mct_u232_break_ctl,
155 .tiocmget = mct_u232_tiocmget, 153 .tiocmget = mct_u232_tiocmget,
@@ -224,8 +222,8 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
224 } 222 }
225} 223}
226 224
227static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_port *port, 225static int mct_u232_set_baud_rate(struct tty_struct *tty,
228 speed_t value) 226 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
229{ 227{
230 __le32 divisor; 228 __le32 divisor;
231 int rc; 229 int rc;
@@ -243,7 +241,7 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p
243 if (rc < 0) /*FIXME: What value speed results */ 241 if (rc < 0) /*FIXME: What value speed results */
244 err("Set BAUD RATE %d failed (error = %d)", value, rc); 242 err("Set BAUD RATE %d failed (error = %d)", value, rc);
245 else 243 else
246 tty_encode_baud_rate(port->tty, speed, speed); 244 tty_encode_baud_rate(tty, speed, speed);
247 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor); 245 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
248 246
249 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which 247 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
@@ -272,7 +270,7 @@ static int mct_u232_set_baud_rate(struct usb_serial *serial, struct usb_serial_p
272 err("Sending USB device request code %d failed (error = %d)", 270 err("Sending USB device request code %d failed (error = %d)",
273 MCT_U232_SET_UNKNOWN1_REQUEST, rc); 271 MCT_U232_SET_UNKNOWN1_REQUEST, rc);
274 272
275 if (port && C_CRTSCTS(port->tty)) { 273 if (port && C_CRTSCTS(tty)) {
276 cts_enable_byte = 1; 274 cts_enable_byte = 1;
277 } 275 }
278 276
@@ -411,7 +409,8 @@ static void mct_u232_shutdown (struct usb_serial *serial)
411 } 409 }
412} /* mct_u232_shutdown */ 410} /* mct_u232_shutdown */
413 411
414static int mct_u232_open (struct usb_serial_port *port, struct file *filp) 412static int mct_u232_open (struct tty_struct *tty,
413 struct usb_serial_port *port, struct file *filp)
415{ 414{
416 struct usb_serial *serial = port->serial; 415 struct usb_serial *serial = port->serial;
417 struct mct_u232_private *priv = usb_get_serial_port_data(port); 416 struct mct_u232_private *priv = usb_get_serial_port_data(port);
@@ -437,7 +436,7 @@ static int mct_u232_open (struct usb_serial_port *port, struct file *filp)
437 * either. 436 * either.
438 */ 437 */
439 spin_lock_irqsave(&priv->lock, flags); 438 spin_lock_irqsave(&priv->lock, flags);
440 if (port->tty->termios->c_cflag & CBAUD) 439 if (tty && (tty->termios->c_cflag & CBAUD))
441 priv->control_state = TIOCM_DTR | TIOCM_RTS; 440 priv->control_state = TIOCM_DTR | TIOCM_RTS;
442 else 441 else
443 priv->control_state = 0; 442 priv->control_state = 0;
@@ -481,15 +480,16 @@ error:
481} /* mct_u232_open */ 480} /* mct_u232_open */
482 481
483 482
484static void mct_u232_close (struct usb_serial_port *port, struct file *filp) 483static void mct_u232_close(struct tty_struct *tty,
484 struct usb_serial_port *port, struct file *filp)
485{ 485{
486 unsigned int c_cflag; 486 unsigned int c_cflag;
487 unsigned int control_state; 487 unsigned int control_state;
488 struct mct_u232_private *priv = usb_get_serial_port_data(port); 488 struct mct_u232_private *priv = usb_get_serial_port_data(port);
489 dbg("%s port %d", __func__, port->number); 489 dbg("%s port %d", __func__, port->number);
490 490
491 if (port->tty) { 491 if (tty) {
492 c_cflag = port->tty->termios->c_cflag; 492 c_cflag = tty->termios->c_cflag;
493 mutex_lock(&port->serial->disc_mutex); 493 mutex_lock(&port->serial->disc_mutex);
494 if (c_cflag & HUPCL && !port->serial->disconnected) { 494 if (c_cflag & HUPCL && !port->serial->disconnected) {
495 /* drop DTR and RTS */ 495 /* drop DTR and RTS */
@@ -553,7 +553,7 @@ static void mct_u232_read_int_callback (struct urb *urb)
553 */ 553 */
554 if (urb->transfer_buffer_length > 2) { 554 if (urb->transfer_buffer_length > 2) {
555 int i; 555 int i;
556 tty = port->tty; 556 tty = port->port.tty;
557 if (urb->actual_length) { 557 if (urb->actual_length) {
558 for (i = 0; i < urb->actual_length ; ++i) { 558 for (i = 0; i < urb->actual_length ; ++i) {
559 tty_insert_flip_char(tty, data[i], 0); 559 tty_insert_flip_char(tty, data[i], 0);
@@ -583,7 +583,7 @@ static void mct_u232_read_int_callback (struct urb *urb)
583 * to look in to this before committing any code. 583 * to look in to this before committing any code.
584 */ 584 */
585 if (priv->last_lsr & MCT_U232_LSR_ERR) { 585 if (priv->last_lsr & MCT_U232_LSR_ERR) {
586 tty = port->tty; 586 tty = port->port.tty;
587 /* Overrun Error */ 587 /* Overrun Error */
588 if (priv->last_lsr & MCT_U232_LSR_OE) { 588 if (priv->last_lsr & MCT_U232_LSR_OE) {
589 } 589 }
@@ -606,12 +606,13 @@ exit:
606 __func__, retval); 606 __func__, retval);
607} /* mct_u232_read_int_callback */ 607} /* mct_u232_read_int_callback */
608 608
609static void mct_u232_set_termios (struct usb_serial_port *port, 609static void mct_u232_set_termios (struct tty_struct *tty,
610 struct usb_serial_port *port,
610 struct ktermios *old_termios) 611 struct ktermios *old_termios)
611{ 612{
612 struct usb_serial *serial = port->serial; 613 struct usb_serial *serial = port->serial;
613 struct mct_u232_private *priv = usb_get_serial_port_data(port); 614 struct mct_u232_private *priv = usb_get_serial_port_data(port);
614 struct ktermios *termios = port->tty->termios; 615 struct ktermios *termios = tty->termios;
615 unsigned int cflag = termios->c_cflag; 616 unsigned int cflag = termios->c_cflag;
616 unsigned int old_cflag = old_termios->c_cflag; 617 unsigned int old_cflag = old_termios->c_cflag;
617 unsigned long flags; 618 unsigned long flags;
@@ -638,7 +639,7 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
638 mct_u232_set_modem_ctrl(serial, control_state); 639 mct_u232_set_modem_ctrl(serial, control_state);
639 } 640 }
640 641
641 mct_u232_set_baud_rate(serial, port, tty_get_baud_rate(port->tty)); 642 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
642 643
643 if ((cflag & CBAUD) == B0 ) { 644 if ((cflag & CBAUD) == B0 ) {
644 dbg("%s: baud is B0", __func__); 645 dbg("%s: baud is B0", __func__);
@@ -689,8 +690,9 @@ static void mct_u232_set_termios (struct usb_serial_port *port,
689 spin_unlock_irqrestore(&priv->lock, flags); 690 spin_unlock_irqrestore(&priv->lock, flags);
690} /* mct_u232_set_termios */ 691} /* mct_u232_set_termios */
691 692
692static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state ) 693static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
693{ 694{
695 struct usb_serial_port *port = tty->driver_data;
694 struct usb_serial *serial = port->serial; 696 struct usb_serial *serial = port->serial;
695 struct mct_u232_private *priv = usb_get_serial_port_data(port); 697 struct mct_u232_private *priv = usb_get_serial_port_data(port);
696 unsigned char lcr; 698 unsigned char lcr;
@@ -709,8 +711,9 @@ static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
709} /* mct_u232_break_ctl */ 711} /* mct_u232_break_ctl */
710 712
711 713
712static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file) 714static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
713{ 715{
716 struct usb_serial_port *port = tty->driver_data;
714 struct mct_u232_private *priv = usb_get_serial_port_data(port); 717 struct mct_u232_private *priv = usb_get_serial_port_data(port);
715 unsigned int control_state; 718 unsigned int control_state;
716 unsigned long flags; 719 unsigned long flags;
@@ -724,9 +727,10 @@ static int mct_u232_tiocmget (struct usb_serial_port *port, struct file *file)
724 return control_state; 727 return control_state;
725} 728}
726 729
727static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file, 730static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
728 unsigned int set, unsigned int clear) 731 unsigned int set, unsigned int clear)
729{ 732{
733 struct usb_serial_port *port = tty->driver_data;
730 struct usb_serial *serial = port->serial; 734 struct usb_serial *serial = port->serial;
731 struct mct_u232_private *priv = usb_get_serial_port_data(port); 735 struct mct_u232_private *priv = usb_get_serial_port_data(port);
732 unsigned int control_state; 736 unsigned int control_state;
@@ -751,73 +755,46 @@ static int mct_u232_tiocmset (struct usb_serial_port *port, struct file *file,
751 return mct_u232_set_modem_ctrl(serial, control_state); 755 return mct_u232_set_modem_ctrl(serial, control_state);
752} 756}
753 757
754static int mct_u232_ioctl (struct usb_serial_port *port, struct file * file, 758static void mct_u232_throttle(struct tty_struct *tty)
755 unsigned int cmd, unsigned long arg)
756{
757 dbg("%scmd=0x%x", __func__, cmd);
758
759 /* Based on code from acm.c and others */
760 switch (cmd) {
761 case TIOCMIWAIT:
762 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
763 /* TODO */
764 return( 0 );
765
766 case TIOCGICOUNT:
767 /* return count of modemline transitions */
768 /* TODO */
769 return 0;
770
771 default:
772 dbg("%s: arg not supported - 0x%04x", __func__,cmd);
773 return(-ENOIOCTLCMD);
774 break;
775 }
776 return 0;
777} /* mct_u232_ioctl */
778
779static void mct_u232_throttle (struct usb_serial_port *port)
780{ 759{
760 struct usb_serial_port *port = tty->driver_data;
781 struct mct_u232_private *priv = usb_get_serial_port_data(port); 761 struct mct_u232_private *priv = usb_get_serial_port_data(port);
782 unsigned long flags; 762 unsigned long flags;
783 unsigned int control_state; 763 unsigned int control_state;
784 struct tty_struct *tty;
785 764
786 tty = port->tty;
787 dbg("%s - port %d", __func__, port->number); 765 dbg("%s - port %d", __func__, port->number);
788 766
789 spin_lock_irqsave(&priv->lock, flags); 767 spin_lock_irqsave(&priv->lock, flags);
790 priv->rx_flags |= THROTTLED; 768 priv->rx_flags |= THROTTLED;
791 if (C_CRTSCTS(tty)) { 769 if (C_CRTSCTS(tty)) {
792 priv->control_state &= ~TIOCM_RTS; 770 priv->control_state &= ~TIOCM_RTS;
793 control_state = priv->control_state; 771 control_state = priv->control_state;
794 spin_unlock_irqrestore(&priv->lock, flags); 772 spin_unlock_irqrestore(&priv->lock, flags);
795 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 773 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
796 } else { 774 } else {
797 spin_unlock_irqrestore(&priv->lock, flags); 775 spin_unlock_irqrestore(&priv->lock, flags);
798 } 776 }
799} 777}
800 778
801 779
802static void mct_u232_unthrottle (struct usb_serial_port *port) 780static void mct_u232_unthrottle(struct tty_struct *tty)
803{ 781{
782 struct usb_serial_port *port = tty->driver_data;
804 struct mct_u232_private *priv = usb_get_serial_port_data(port); 783 struct mct_u232_private *priv = usb_get_serial_port_data(port);
805 unsigned long flags; 784 unsigned long flags;
806 unsigned int control_state; 785 unsigned int control_state;
807 struct tty_struct *tty;
808 786
809 dbg("%s - port %d", __func__, port->number); 787 dbg("%s - port %d", __func__, port->number);
810 788
811 tty = port->tty;
812 spin_lock_irqsave(&priv->lock, flags); 789 spin_lock_irqsave(&priv->lock, flags);
813 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) { 790 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
814 priv->rx_flags &= ~THROTTLED; 791 priv->rx_flags &= ~THROTTLED;
815 priv->control_state |= TIOCM_RTS; 792 priv->control_state |= TIOCM_RTS;
816 control_state = priv->control_state; 793 control_state = priv->control_state;
817 spin_unlock_irqrestore(&priv->lock, flags); 794 spin_unlock_irqrestore(&priv->lock, flags);
818 (void) mct_u232_set_modem_ctrl(port->serial, control_state); 795 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
819 } else { 796 } else {
820 spin_unlock_irqrestore(&priv->lock, flags); 797 spin_unlock_irqrestore(&priv->lock, flags);
821 } 798 }
822} 799}
823 800