Commit 6f6a407a authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

Merge tag 'usb-serial-5.2-rc1' of...

Merge tag 'usb-serial-5.2-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial

 into usb-next

Johan writes:

USB-serial updates for 5.2-rc1

Here are the USB-serial updates for 5.2-rc1, including:

 - flow-control related fixes for pl2303
 - fix for an initial-termios issue
 - fix for a couple of unthrottle() races
 - fix for f81232 interrupt-handling issues
 - improved f81232 overrun handling
 - support for higher f81232 line speeds
 - support for f81232 break control

Included are also various clean ups.

All but the last four commits have been in linux-next and with no
reported issues.

Signed-off-by: default avatarJohan Hovold <johan@kernel.org>

* tag 'usb-serial-5.2-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: (22 commits)
  USB: serial: f81232: implement break control
  USB: serial: f81232: add high baud rate support
  USB: serial: f81232: clear overrun flag
  USB: serial: f81232: fix interrupt worker not stop
  USB: serial: io_edgeport: fix up switch fall-through comments
  USB: serial: drop unused iflag macro
  USB: serial: drop unnecessary goto
  USB: serial: clean up throttle handling
  USB: serial: fix unthrottle races
  USB: serial: spcp8x5: simplify init_termios
  USB: serial: oti6858: simplify init_termios
  USB: serial: iuu_phoenix: simplify init_termios
  USB: serial: iuu_phoenix: drop bogus initial cflag
  USB: serial: cypress_m8: clean up initial-termios handling
  USB: serial: cypress_m8: drop unused termios
  USB: serial: cypress_m8: drop unused driver data flag
  USB: serial: ark3116: drop redundant init_termios
  USB: serial: fix initial-termios handling
  USB: serial: digi_acceleport: clean up set_termios
  USB: serial: digi_acceleport: clean up modem-control handling
  ...
parents 6e7adf3e 7f6fc502
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -189,16 +189,6 @@ static int ark3116_port_remove(struct usb_serial_port *port)
	return 0;
}

static void ark3116_init_termios(struct tty_struct *tty)
{
	struct ktermios *termios = &tty->termios;
	*termios = tty_std_termios;
	termios->c_cflag = B9600 | CS8
				      | CREAD | HUPCL | CLOCAL;
	termios->c_ispeed = 9600;
	termios->c_ospeed = 9600;
}

static void ark3116_set_termios(struct tty_struct *tty,
				struct usb_serial_port *port,
				struct ktermios *old_termios)
@@ -645,7 +635,6 @@ static struct usb_serial_driver ark3116_device = {
	.port_probe =		ark3116_port_probe,
	.port_remove =		ark3116_port_remove,
	.set_termios =		ark3116_set_termios,
	.init_termios =		ark3116_init_termios,
	.get_serial =		ark3116_get_serial_info,
	.tiocmget =		ark3116_tiocmget,
	.tiocmset =		ark3116_tiocmset,
+8 −41
Original line number Diff line number Diff line
@@ -98,7 +98,6 @@ struct cypress_private {
	int write_urb_interval;            /* interval to use for write urb */
	int read_urb_interval;             /* interval to use for read urb */
	int comm_is_ok;                    /* true if communication is (still) ok */
	int termios_initialized;
	__u8 line_control;	   	   /* holds dtr / rts value */
	__u8 current_status;	   	   /* received from last read - info on dsr,cts,cd,ri,etc */
	__u8 current_config;	   	   /* stores the current configuration byte */
@@ -107,11 +106,7 @@ struct cypress_private {
	int get_cfg_unsafe;		   /* If true, the CYPRESS_GET_CONFIG is unsafe */
	int baud_rate;			   /* stores current baud rate in
					      integer form */
	int isthrottled;		   /* if throttled, discard reads */
	char prev_status;		   /* used for TIOCMIWAIT */
	/* we pass a pointer to this as the argument sent to
	   cypress_set_termios old_termios */
	struct ktermios tmp_termios; 	   /* stores the old termios settings */
};

/* function prototypes for the Cypress USB to serial device */
@@ -126,6 +121,7 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
			const unsigned char *buf, int count);
static void cypress_send(struct usb_serial_port *port);
static int  cypress_write_room(struct tty_struct *tty);
static void cypress_earthmate_init_termios(struct tty_struct *tty);
static void cypress_set_termios(struct tty_struct *tty,
			struct usb_serial_port *port, struct ktermios *old);
static int  cypress_tiocmget(struct tty_struct *tty);
@@ -153,6 +149,7 @@ static struct usb_serial_driver cypress_earthmate_device = {
	.dtr_rts =			cypress_dtr_rts,
	.write =			cypress_write,
	.write_room =			cypress_write_room,
	.init_termios =			cypress_earthmate_init_termios,
	.set_termios =			cypress_set_termios,
	.tiocmget =			cypress_tiocmget,
	.tiocmset =			cypress_tiocmset,
@@ -467,7 +464,6 @@ static int cypress_generic_port_probe(struct usb_serial_port *port)

	priv->cmd_ctrl = 0;
	priv->line_control = 0;
	priv->termios_initialized = 0;
	priv->rx_flags = 0;
	/* Default packet format setting is determined by packet size.
	   Anything with a size larger then 9 must have a separate
@@ -604,7 +600,7 @@ static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
	cypress_send(port);

	if (tty)
		cypress_set_termios(tty, port, &priv->tmp_termios);
		cypress_set_termios(tty, port, NULL);

	/* setup the port and start reading from the device */
	usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
@@ -857,6 +853,11 @@ static int cypress_tiocmset(struct tty_struct *tty,
	return cypress_write(tty, port, NULL, 0);
}

static void cypress_earthmate_init_termios(struct tty_struct *tty)
{
	tty_encode_baud_rate(tty, 4800, 4800);
}

static void cypress_set_termios(struct tty_struct *tty,
	struct usb_serial_port *port, struct ktermios *old_termios)
{
@@ -868,45 +869,11 @@ static void cypress_set_termios(struct tty_struct *tty,
	__u8 oldlines;
	int linechange = 0;

	spin_lock_irqsave(&priv->lock, flags);
	/* We can't clean this one up as we don't know the device type
	   early enough */
	if (!priv->termios_initialized) {
		if (priv->chiptype == CT_EARTHMATE) {
			tty->termios = tty_std_termios;
			tty->termios.c_cflag = B4800 | CS8 | CREAD | HUPCL |
				CLOCAL;
			tty->termios.c_ispeed = 4800;
			tty->termios.c_ospeed = 4800;
		} else if (priv->chiptype == CT_CYPHIDCOM) {
			tty->termios = tty_std_termios;
			tty->termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
				CLOCAL;
			tty->termios.c_ispeed = 9600;
			tty->termios.c_ospeed = 9600;
		} else if (priv->chiptype == CT_CA42V2) {
			tty->termios = tty_std_termios;
			tty->termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
				CLOCAL;
			tty->termios.c_ispeed = 9600;
			tty->termios.c_ospeed = 9600;
		}
		priv->termios_initialized = 1;
	}
	spin_unlock_irqrestore(&priv->lock, flags);

	/* Unsupported features need clearing */
	tty->termios.c_cflag &= ~(CMSPAR|CRTSCTS);

	cflag = tty->termios.c_cflag;

	/* check if there are new settings */
	if (old_termios) {
		spin_lock_irqsave(&priv->lock, flags);
		priv->tmp_termios = tty->termios;
		spin_unlock_irqrestore(&priv->lock, flags);
	}

	/* set number of data bits, parity, stop bits */
	/* when parity is disabled the parity type bit is ignored */

+20 −21
Original line number Diff line number Diff line
@@ -569,9 +569,9 @@ static int digi_set_modem_signals(struct usb_serial_port *port,
	ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
	if (ret == 0) {
		oob_priv->dp_write_urb_in_use = 1;
		port_priv->dp_modem_signals =
			(port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
			| (modem_signals&(TIOCM_DTR|TIOCM_RTS));
		port_priv->dp_modem_signals &= ~(TIOCM_DTR | TIOCM_RTS);
		port_priv->dp_modem_signals |=
				modem_signals & (TIOCM_DTR | TIOCM_RTS);
	}
	spin_unlock(&port_priv->dp_port_lock);
	spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
@@ -765,7 +765,7 @@ static void digi_set_termios(struct tty_struct *tty,
		default:
			dev_dbg(dev,
				"digi_set_termios: can't handle word size %d\n",
				(cflag&CSIZE));
				cflag & CSIZE);
			break;
		}

@@ -794,8 +794,8 @@ static void digi_set_termios(struct tty_struct *tty,
	}

	/* set input flow control */
	if ((iflag&IXOFF) != (old_iflag&IXOFF)
	    || (cflag&CRTSCTS) != (old_cflag&CRTSCTS)) {
	if ((iflag & IXOFF) != (old_iflag & IXOFF) ||
			(cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
		arg = 0;
		if (iflag & IXOFF)
			arg |= DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
@@ -822,19 +822,18 @@ static void digi_set_termios(struct tty_struct *tty,
	}

	/* set output flow control */
	if ((iflag & IXON) != (old_iflag & IXON)
	    || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
	if ((iflag & IXON) != (old_iflag & IXON) ||
			(cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
		arg = 0;
		if (iflag & IXON)
			arg |= DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
		else
			arg &= ~DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;

		if (cflag & CRTSCTS) {
		if (cflag & CRTSCTS)
			arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS;
		} else {
		else
			arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS;
		}

		buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
		buf[i++] = priv->dp_port_num;
+181 −17
Original line number Diff line number Diff line
@@ -28,7 +28,8 @@ static const struct usb_device_id id_table[] = {
MODULE_DEVICE_TABLE(usb, id_table);

/* Maximum baudrate for F81232 */
#define F81232_MAX_BAUDRATE		115200
#define F81232_MAX_BAUDRATE		1500000
#define F81232_DEF_BAUDRATE		9600

/* USB Control EP parameter */
#define F81232_REGISTER_REQUEST		0xa0
@@ -41,19 +42,46 @@ MODULE_DEVICE_TABLE(usb, id_table);
#define FIFO_CONTROL_REGISTER		(0x02 + SERIAL_BASE_ADDRESS)
#define LINE_CONTROL_REGISTER		(0x03 + SERIAL_BASE_ADDRESS)
#define MODEM_CONTROL_REGISTER		(0x04 + SERIAL_BASE_ADDRESS)
#define LINE_STATUS_REGISTER		(0x05 + SERIAL_BASE_ADDRESS)
#define MODEM_STATUS_REGISTER		(0x06 + SERIAL_BASE_ADDRESS)

/*
 * F81232 Clock registers (106h)
 *
 * Bit1-0:	Clock source selector
 *			00: 1.846MHz.
 *			01: 18.46MHz.
 *			10: 24MHz.
 *			11: 14.77MHz.
 */
#define F81232_CLK_REGISTER		0x106
#define F81232_CLK_1_846_MHZ		0
#define F81232_CLK_18_46_MHZ		BIT(0)
#define F81232_CLK_24_MHZ		BIT(1)
#define F81232_CLK_14_77_MHZ		(BIT(1) | BIT(0))
#define F81232_CLK_MASK			GENMASK(1, 0)

struct f81232_private {
	struct mutex lock;
	u8 modem_control;
	u8 modem_status;
	u8 shadow_lcr;
	speed_t baud_base;
	struct work_struct lsr_work;
	struct work_struct interrupt_work;
	struct usb_serial_port *port;
};

static int calc_baud_divisor(speed_t baudrate)
static u32 const baudrate_table[] = { 115200, 921600, 1152000, 1500000 };
static u8 const clock_table[] = { F81232_CLK_1_846_MHZ, F81232_CLK_14_77_MHZ,
				F81232_CLK_18_46_MHZ, F81232_CLK_24_MHZ };

static int calc_baud_divisor(speed_t baudrate, speed_t clockrate)
{
	return DIV_ROUND_CLOSEST(F81232_MAX_BAUDRATE, baudrate);
	if (!baudrate)
		return 0;

	return DIV_ROUND_CLOSEST(clockrate, baudrate);
}

static int f81232_get_register(struct usb_serial_port *port, u16 reg, u8 *val)
@@ -127,6 +155,21 @@ static int f81232_set_register(struct usb_serial_port *port, u16 reg, u8 val)
	return status;
}

static int f81232_set_mask_register(struct usb_serial_port *port, u16 reg,
					u8 mask, u8 val)
{
	int status;
	u8 tmp;

	status = f81232_get_register(port, reg, &tmp);
	if (status)
		return status;

	tmp = (tmp & ~mask) | (val & mask);

	return f81232_set_register(port, reg, tmp);
}

static void f81232_read_msr(struct usb_serial_port *port)
{
	int status;
@@ -282,6 +325,7 @@ exit:
static void f81232_process_read_urb(struct urb *urb)
{
	struct usb_serial_port *port = urb->context;
	struct f81232_private *priv = usb_get_serial_port_data(port);
	unsigned char *data = urb->transfer_buffer;
	char tty_flag;
	unsigned int i;
@@ -315,6 +359,7 @@ static void f81232_process_read_urb(struct urb *urb)

			if (lsr & UART_LSR_OE) {
				port->icount.overrun++;
				schedule_work(&priv->lsr_work);
				tty_insert_flip_char(&port->port, 0,
						TTY_OVERRUN);
			}
@@ -333,22 +378,72 @@ static void f81232_process_read_urb(struct urb *urb)

static void f81232_break_ctl(struct tty_struct *tty, int break_state)
{
	/* FIXME - Stubbed out for now */
	struct usb_serial_port *port = tty->driver_data;
	struct f81232_private *priv = usb_get_serial_port_data(port);
	int status;

	/*
	 * break_state = -1 to turn on break, and 0 to turn off break
	 * see drivers/char/tty_io.c to see it used.
	 * last_set_data_urb_value NEVER has the break bit set in it.
	 */
	mutex_lock(&priv->lock);

	if (break_state)
		priv->shadow_lcr |= UART_LCR_SBC;
	else
		priv->shadow_lcr &= ~UART_LCR_SBC;

	status = f81232_set_register(port, LINE_CONTROL_REGISTER,
					priv->shadow_lcr);
	if (status)
		dev_err(&port->dev, "set break failed: %d\n", status);

	mutex_unlock(&priv->lock);
}

static int f81232_find_clk(speed_t baudrate)
{
	int idx;

	for (idx = 0; idx < ARRAY_SIZE(baudrate_table); ++idx) {
		if (baudrate <= baudrate_table[idx] &&
				baudrate_table[idx] % baudrate == 0)
			return idx;
	}

	return -EINVAL;
}

static void f81232_set_baudrate(struct usb_serial_port *port, speed_t baudrate)
static void f81232_set_baudrate(struct tty_struct *tty,
				struct usb_serial_port *port, speed_t baudrate,
				speed_t old_baudrate)
{
	struct f81232_private *priv = usb_get_serial_port_data(port);
	u8 lcr;
	int divisor;
	int status = 0;
	int i;
	int idx;
	speed_t baud_list[] = { baudrate, old_baudrate, F81232_DEF_BAUDRATE };

	for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {
		idx = f81232_find_clk(baud_list[i]);
		if (idx >= 0) {
			baudrate = baud_list[i];
			tty_encode_baud_rate(tty, baudrate, baudrate);
			break;
		}
	}

	divisor = calc_baud_divisor(baudrate);
	if (idx < 0)
		return;

	priv->baud_base = baudrate_table[idx];
	divisor = calc_baud_divisor(baudrate, priv->baud_base);

	status = f81232_set_mask_register(port, F81232_CLK_REGISTER,
			F81232_CLK_MASK, clock_table[idx]);
	if (status) {
		dev_err(&port->dev, "%s failed to set CLK_REG: %d\n",
			__func__, status);
		return;
	}

	status = f81232_get_register(port, LINE_CONTROL_REGISTER,
			 &lcr); /* get LCR */
@@ -435,9 +530,11 @@ static int f81232_port_disable(struct usb_serial_port *port)
static void f81232_set_termios(struct tty_struct *tty,
		struct usb_serial_port *port, struct ktermios *old_termios)
{
	struct f81232_private *priv = usb_get_serial_port_data(port);
	u8 new_lcr = 0;
	int status = 0;
	speed_t baudrate;
	speed_t old_baud;

	/* Don't change anything if nothing has changed */
	if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios))
@@ -450,11 +547,12 @@ static void f81232_set_termios(struct tty_struct *tty,

	baudrate = tty_get_baud_rate(tty);
	if (baudrate > 0) {
		if (baudrate > F81232_MAX_BAUDRATE) {
			baudrate = F81232_MAX_BAUDRATE;
			tty_encode_baud_rate(tty, baudrate, baudrate);
		}
		f81232_set_baudrate(port, baudrate);
		if (old_termios)
			old_baud = tty_termios_baud_rate(old_termios);
		else
			old_baud = F81232_DEF_BAUDRATE;

		f81232_set_baudrate(tty, port, baudrate, old_baud);
	}

	if (C_PARENB(tty)) {
@@ -486,11 +584,18 @@ static void f81232_set_termios(struct tty_struct *tty,
		break;
	}

	mutex_lock(&priv->lock);

	new_lcr |= (priv->shadow_lcr & UART_LCR_SBC);
	status = f81232_set_register(port, LINE_CONTROL_REGISTER, new_lcr);
	if (status) {
		dev_err(&port->dev, "%s failed to set LCR: %d\n",
			__func__, status);
	}

	priv->shadow_lcr = new_lcr;

	mutex_unlock(&priv->lock);
}

static int f81232_tiocmget(struct tty_struct *tty)
@@ -556,9 +661,13 @@ static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port)

static void f81232_close(struct usb_serial_port *port)
{
	struct f81232_private *port_priv = usb_get_serial_port_data(port);

	f81232_port_disable(port);
	usb_serial_generic_close(port);
	usb_kill_urb(port->interrupt_in_urb);
	flush_work(&port_priv->interrupt_work);
	flush_work(&port_priv->lsr_work);
}

static void f81232_dtr_rts(struct usb_serial_port *port, int on)
@@ -587,11 +696,12 @@ static int f81232_get_serial_info(struct tty_struct *tty,
		struct serial_struct *ss)
{
	struct usb_serial_port *port = tty->driver_data;
	struct f81232_private *priv = usb_get_serial_port_data(port);

	ss->type = PORT_16550A;
	ss->line = port->minor;
	ss->port = port->port_number;
	ss->baud_base = F81232_MAX_BAUDRATE;
	ss->baud_base = priv->baud_base;
	return 0;
}

@@ -603,6 +713,21 @@ static void f81232_interrupt_work(struct work_struct *work)
	f81232_read_msr(priv->port);
}

static void f81232_lsr_worker(struct work_struct *work)
{
	struct f81232_private *priv;
	struct usb_serial_port *port;
	int status;
	u8 tmp;

	priv = container_of(work, struct f81232_private, lsr_work);
	port = priv->port;

	status = f81232_get_register(port, LINE_STATUS_REGISTER, &tmp);
	if (status)
		dev_warn(&port->dev, "read LSR failed: %d\n", status);
}

static int f81232_port_probe(struct usb_serial_port *port)
{
	struct f81232_private *priv;
@@ -613,6 +738,7 @@ static int f81232_port_probe(struct usb_serial_port *port)

	mutex_init(&priv->lock);
	INIT_WORK(&priv->interrupt_work,  f81232_interrupt_work);
	INIT_WORK(&priv->lsr_work, f81232_lsr_worker);

	usb_set_serial_port_data(port, priv);

@@ -632,6 +758,42 @@ static int f81232_port_remove(struct usb_serial_port *port)
	return 0;
}

static int f81232_suspend(struct usb_serial *serial, pm_message_t message)
{
	struct usb_serial_port *port = serial->port[0];
	struct f81232_private *port_priv = usb_get_serial_port_data(port);
	int i;

	for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
		usb_kill_urb(port->read_urbs[i]);

	usb_kill_urb(port->interrupt_in_urb);

	if (port_priv) {
		flush_work(&port_priv->interrupt_work);
		flush_work(&port_priv->lsr_work);
	}

	return 0;
}

static int f81232_resume(struct usb_serial *serial)
{
	struct usb_serial_port *port = serial->port[0];
	int result;

	if (tty_port_initialized(&port->port)) {
		result = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
		if (result) {
			dev_err(&port->dev, "submit interrupt urb failed: %d\n",
					result);
			return result;
		}
	}

	return usb_serial_generic_resume(serial);
}

static struct usb_serial_driver f81232_device = {
	.driver = {
		.owner =	THIS_MODULE,
@@ -655,6 +817,8 @@ static struct usb_serial_driver f81232_device = {
	.read_int_callback =	f81232_read_int_callback,
	.port_probe =		f81232_port_probe,
	.port_remove =		f81232_port_remove,
	.suspend =		f81232_suspend,
	.resume =		f81232_resume,
};

static struct usb_serial_driver * const serial_drivers[] = {
+41 −35
Original line number Diff line number Diff line
@@ -106,12 +106,8 @@ void usb_serial_generic_deregister(void)
int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port)
{
	int result = 0;
	unsigned long flags;

	spin_lock_irqsave(&port->lock, flags);
	port->throttled = 0;
	port->throttle_req = 0;
	spin_unlock_irqrestore(&port->lock, flags);
	clear_bit(USB_SERIAL_THROTTLED, &port->flags);

	if (port->bulk_in_size)
		result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
@@ -375,7 +371,7 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb)
{
	struct usb_serial_port *port = urb->context;
	unsigned char *data = urb->transfer_buffer;
	unsigned long flags;
	bool stopped = false;
	int status = urb->status;
	int i;

@@ -383,42 +379,55 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb)
		if (urb == port->read_urbs[i])
			break;
	}
	set_bit(i, &port->read_urbs_free);

	dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i,
							urb->actual_length);
	switch (status) {
	case 0:
		usb_serial_debug_data(&port->dev, __func__, urb->actual_length,
							data);
		port->serial->type->process_read_urb(urb);
		break;
	case -ENOENT:
	case -ECONNRESET:
	case -ESHUTDOWN:
		dev_dbg(&port->dev, "%s - urb stopped: %d\n",
							__func__, status);
		return;
		stopped = true;
		break;
	case -EPIPE:
		dev_err(&port->dev, "%s - urb stopped: %d\n",
							__func__, status);
		return;
		stopped = true;
		break;
	default:
		dev_dbg(&port->dev, "%s - nonzero urb status: %d\n",
							__func__, status);
		goto resubmit;
		break;
	}

	usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
	port->serial->type->process_read_urb(urb);
	/*
	 * Make sure URB processing is done before marking as free to avoid
	 * racing with unthrottle() on another CPU. Matches the barriers
	 * implied by the test_and_clear_bit() in
	 * usb_serial_generic_submit_read_urb().
	 */
	smp_mb__before_atomic();
	set_bit(i, &port->read_urbs_free);
	/*
	 * Make sure URB is marked as free before checking the throttled flag
	 * to avoid racing with unthrottle() on another CPU. Matches the
	 * smp_mb() in unthrottle().
	 */
	smp_mb__after_atomic();

	if (stopped)
		return;

	if (test_bit(USB_SERIAL_THROTTLED, &port->flags))
		return;

resubmit:
	/* Throttle the device if requested by tty */
	spin_lock_irqsave(&port->lock, flags);
	port->throttled = port->throttle_req;
	if (!port->throttled) {
		spin_unlock_irqrestore(&port->lock, flags);
	usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
	} else {
		spin_unlock_irqrestore(&port->lock, flags);
	}
}
EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);

@@ -454,10 +463,9 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
	default:
		dev_err_console(port, "%s - nonzero urb status: %d\n",
							__func__, status);
		goto resubmit;
		break;
	}

resubmit:
	usb_serial_generic_write_start(port, GFP_ATOMIC);
	usb_serial_port_softint(port);
}
@@ -466,25 +474,23 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
void usb_serial_generic_throttle(struct tty_struct *tty)
{
	struct usb_serial_port *port = tty->driver_data;
	unsigned long flags;

	spin_lock_irqsave(&port->lock, flags);
	port->throttle_req = 1;
	spin_unlock_irqrestore(&port->lock, flags);
	set_bit(USB_SERIAL_THROTTLED, &port->flags);
}
EXPORT_SYMBOL_GPL(usb_serial_generic_throttle);

void usb_serial_generic_unthrottle(struct tty_struct *tty)
{
	struct usb_serial_port *port = tty->driver_data;
	int was_throttled;

	spin_lock_irq(&port->lock);
	was_throttled = port->throttled;
	port->throttled = port->throttle_req = 0;
	spin_unlock_irq(&port->lock);
	clear_bit(USB_SERIAL_THROTTLED, &port->flags);

	/*
	 * Matches the smp_mb__after_atomic() in
	 * usb_serial_generic_read_bulk_callback().
	 */
	smp_mb();

	if (was_throttled)
	usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
}
EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
Loading