void usb_serial_generic_write_bulk_callback(struct urb *urb) { unsigned long flags; struct usb_serial_port *port = urb->context; int status = urb->status; int i; for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) if (port->write_urbs[i] == urb) break; spin_lock_irqsave(&port->lock, flags); port->tx_bytes -= urb->transfer_buffer_length; set_bit(i, &port->write_urbs_free); spin_unlock_irqrestore(&port->lock, flags); if (status) { dev_dbg(&port->dev, "%s - non-zero urb status: %d\n", __func__, status); spin_lock_irqsave(&port->lock, flags); kfifo_reset_out(&port->write_fifo); spin_unlock_irqrestore(&port->lock, flags); } else { usb_serial_generic_write_start(port); } usb_serial_port_softint(port); }
int usb_serial_generic_resume(struct usb_serial *serial) { struct usb_serial_port *port; int i, c = 0, r; for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) continue; if (port->bulk_in_size) { r = usb_serial_generic_submit_read_urbs(port, GFP_NOIO); if (r < 0) c++; } if (port->bulk_out_size) { r = usb_serial_generic_write_start(port); if (r < 0) c++; } } return c ? -EIO : 0; }
int usb_serial_generic_resume(struct usb_serial *serial) { struct usb_serial_port *port; int i, c = 0, r; for (i = 0; i < serial->num_ports; i++) { port = serial->port[i]; if (!port->port.count) continue; if (port->read_urb) { r = usb_submit_urb(port->read_urb, GFP_NOIO); if (r < 0) c++; } if (port->write_urb) { r = usb_serial_generic_write_start(port); if (r < 0) c++; } } return c ? -EIO : 0; }
/** * usb_serial_generic_write - generic write function for serial USB devices * @tty: Pointer to &struct tty_struct for the device * @port: Pointer to the &usb_serial_port structure for the device * @buf: Pointer to the data to write * @count: Number of bytes to write * * Returns the number of characters actually written, which may be anything * from zero to @count. If an error occurs, it returns the negative errno * value. */ int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { struct usb_serial *serial = port->serial; int result; dbg("%s - port %d", __func__, port->number); 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); count = kfifo_put(port->write_fifo, buf, count); result = usb_serial_generic_write_start(port); if (result >= 0) result = count; return result; }
void usb_serial_generic_write_bulk_callback(struct urb *urb) { unsigned long flags; struct usb_serial_port *port = urb->context; int status = urb->status; dbg("%s - port %d", __func__, port->number); if (port->serial->type->max_in_flight_urbs) { kfree(urb->transfer_buffer); spin_lock_irqsave(&port->lock, flags); --port->urbs_in_flight; port->tx_bytes_flight -= urb->transfer_buffer_length; if (port->urbs_in_flight < 0) port->urbs_in_flight = 0; spin_unlock_irqrestore(&port->lock, flags); } else { port->write_urb_busy = 0; if (status) kfifo_reset_out(&port->write_fifo); else usb_serial_generic_write_start(port); } if (status) dbg("%s - non-zero urb status: %d", __func__, status); usb_serial_port_softint(port); }
/** * usb_serial_generic_write - generic write function * @tty: tty for the port * @port: usb-serial port * @buf: data to write * @count: number of bytes to write * * Return: The number of characters buffered, which may be anything from * zero to @count, or a negative errno value. */ int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { int result; if (!port->bulk_out_size) return -ENODEV; if (!count) return 0; count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); result = usb_serial_generic_write_start(port, GFP_ATOMIC); if (result) return result; return count; }
/** * usb_serial_generic_write - generic write function for serial USB devices * @tty: Pointer to &struct tty_struct for the device * @port: Pointer to the &usb_serial_port structure for the device * @buf: Pointer to the data to write * @count: Number of bytes to write * * Returns the number of characters actually written, which may be anything * from zero to @count. If an error occurs, it returns the negative errno * value. */ int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) { int result; /* only do something if we have a bulk out endpoint */ if (!port->bulk_out_size) return -ENODEV; if (!count) return 0; count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); result = usb_serial_generic_write_start(port); if (result) return result; return count; }