usb-serial: Use tty_port version console instead of usb_serial_port
[firefly-linux-kernel-4.4.55.git] / drivers / usb / serial / generic.c
index e560d1d7f628197a58e4539b247ce7b01874255b..ba61c745df0b1e686338b0a71777eeb04d3507d3 100644 (file)
@@ -130,7 +130,7 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
        spin_unlock_irqrestore(&port->lock, flags);
 
        /* if we have a bulk endpoint, start reading from it */
-       if (serial->num_bulk_in) {
+       if (port->bulk_in_size) {
                /* Start reading from the device */
                usb_fill_bulk_urb(port->read_urb, serial->dev,
                                   usb_rcvbulkpipe(serial->dev,
@@ -159,10 +159,10 @@ static void generic_cleanup(struct usb_serial_port *port)
        dbg("%s - port %d", __func__, port->number);
 
        if (serial->dev) {
-               /* shutdown any bulk reads that might be going on */
-               if (serial->num_bulk_out)
+               /* shutdown any bulk transfers that might be going on */
+               if (port->bulk_out_size)
                        usb_kill_urb(port->write_urb);
-               if (serial->num_bulk_in)
+               if (port->bulk_in_size)
                        usb_kill_urb(port->read_urb);
        }
 }
@@ -333,15 +333,15 @@ int usb_serial_generic_write(struct tty_struct *tty,
 
        dbg("%s - port %d", __func__, port->number);
 
+       /* only do something if we have a bulk out endpoint */
+       if (!port->bulk_out_size)
+               return -ENODEV;
+
        if (count == 0) {
                dbg("%s - write request of 0 bytes", __func__);
                return 0;
        }
 
-       /* only do something if we have a bulk out endpoint */
-       if (!serial->num_bulk_out)
-               return 0;
-
        if (serial->type->max_in_flight_urbs)
                return usb_serial_multi_urb_write(tty, port,
                                                  buf, count);
@@ -364,14 +364,19 @@ int usb_serial_generic_write_room(struct tty_struct *tty)
        int room = 0;
 
        dbg("%s - port %d", __func__, port->number);
+
+       if (!port->bulk_out_size)
+               return 0;
+
        spin_lock_irqsave(&port->lock, flags);
        if (serial->type->max_in_flight_urbs) {
                if (port->urbs_in_flight < serial->type->max_in_flight_urbs)
                        room = port->bulk_out_size *
                                (serial->type->max_in_flight_urbs -
                                 port->urbs_in_flight);
-       } else if (serial->num_bulk_out)
+       } else {
                room = kfifo_avail(&port->write_fifo);
+       }
        spin_unlock_irqrestore(&port->lock, flags);
 
        dbg("%s - returns %d", __func__, room);
@@ -382,15 +387,18 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
 {
        struct usb_serial_port *port = tty->driver_data;
        struct usb_serial *serial = port->serial;
-       int chars = 0;
        unsigned long flags;
+       int chars;
 
        dbg("%s - port %d", __func__, port->number);
 
+       if (!port->bulk_out_size)
+               return 0;
+
        spin_lock_irqsave(&port->lock, flags);
        if (serial->type->max_in_flight_urbs)
                chars = port->tx_bytes_flight;
-       else if (serial->num_bulk_out)
+       else
                chars = kfifo_len(&port->write_fifo);
        spin_unlock_irqrestore(&port->lock, flags);
 
@@ -439,7 +447,7 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
        /* The per character mucking around with sysrq path it too slow for
           stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases
           where the USB serial is not a console anyway */
-       if (!port->console || !port->sysrq)
+       if (!port->port.console || !port->sysrq)
                tty_insert_flip_string(tty, ch, urb->actual_length);
        else {
                /* Push data to tty */
@@ -500,23 +508,18 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
                if (port->urbs_in_flight < 0)
                        port->urbs_in_flight = 0;
                spin_unlock_irqrestore(&port->lock, flags);
-
-               if (status) {
-                       dbg("%s - nonzero multi-urb write bulk status "
-                               "received: %d", __func__, status);
-                       return;
-               }
        } else {
                port->write_urb_busy = 0;
 
-               if (status) {
-                       dbg("%s - nonzero multi-urb write bulk status "
-                               "received: %d", __func__, status);
+               if (status)
                        kfifo_reset_out(&port->write_fifo);
-               else
+               else
                        usb_serial_generic_write_start(port);
        }
 
+       if (status)
+               dbg("%s - non-zero urb status: %d", __func__, status);
+
        usb_serial_port_softint(port);
 }
 EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
@@ -558,7 +561,7 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)
 int usb_serial_handle_sysrq_char(struct tty_struct *tty,
                        struct usb_serial_port *port, unsigned int ch)
 {
-       if (port->sysrq && port->console) {
+       if (port->sysrq && port->port.console) {
                if (ch && time_before(jiffies, port->sysrq)) {
                        handle_sysrq(ch, tty);
                        port->sysrq = 0;