Skip to contentSkip to conversation

USB: serial: ftdi_sio: Fix serial port stall after resume

PATCH In review Helge Deller 2 participants 6 messages Sep 29, 2020 – Oct 29, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: serial: ftdi_sio: Fix serial port stall after resume

With a 4-port serial USB HUB with FT232BM chips the serial ports stop working after a software suspend/resume cycle.
Rewriting the latency timer during the resume phase fixes it.

drivers/usb/serial/ftdi_sio.c +12 -0
index 9823bb424abd..8ee6cf6215c1 100644
@@ -1092,6 +1092,7 @@ static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
 static u32 ftdi_232bm_baud_to_divisor(int baud);
 static u32 ftdi_2232h_baud_base_to_divisor(int baud, int base);
 static u32 ftdi_2232h_baud_to_divisor(int baud);
+static int ftdi_reset_resume(struct usb_serial *serial);
 
 static struct usb_serial_driver ftdi_sio_device = {
 	.driver = {
@@ -1122,6 +1123,7 @@ static struct usb_serial_driver ftdi_sio_device = {
 	.set_termios =		ftdi_set_termios,
 	.break_ctl =		ftdi_break_ctl,
 	.tx_empty =		ftdi_tx_empty,
+	.reset_resume =		ftdi_reset_resume,
 };
 
 static struct usb_serial_driver * const serial_drivers[] = {
@@ -2379,6 +2381,16 @@ static int ftdi_stmclite_probe(struct usb_serial *serial)
 	return 0;
 }
 
+static int ftdi_reset_resume(struct usb_serial *serial)
+{
+	struct usb_serial_port *port = serial->port[0];
+
+	if (tty_port_initialized(&port->port))
+		write_latency_timer(port);
+
+	return usb_serial_generic_resume(serial);
+}
+
 static int ftdi_sio_port_remove(struct usb_serial_port *port)
 {
 	struct ftdi_private *priv = usb_get_serial_port_data(port);
maintainer
#1 lore raw
Quoted 3 lines · Helge Deller

With a 4-port serial USB HUB with FT232BM chips the serial ports stop working after a software suspend/resume cycle.
Rewriting the latency timer during the resume phase fixes it.

Hmm. This sounds weird. Why would the latency timer make such a difference?

Quoted 24 lines
drivers/usb/serial/ftdi_sio.c +2 -0
index 9823bb424abd..8ee6cf6215c1 100644
@@ -1092,6 +1092,7 @@ static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
 static u32 ftdi_232bm_baud_to_divisor(int baud);
 static u32 ftdi_2232h_baud_base_to_divisor(int baud, int base);
 static u32 ftdi_2232h_baud_to_divisor(int baud);
+static int ftdi_reset_resume(struct usb_serial *serial);
 
 static struct usb_serial_driver ftdi_sio_device = {
 	.driver = {
@@ -1122,6 +1123,7 @@ static struct usb_serial_driver ftdi_sio_device = {
 	.set_termios =		ftdi_set_termios,
 	.break_ctl =		ftdi_break_ctl,
 	.tx_empty =		ftdi_tx_empty,
+	.reset_resume =		ftdi_reset_resume,
 };
 
 static struct usb_serial_driver * const serial_drivers[] = {

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2389

Quoted 9 lines
drivers/usb/serial/ftdi_sio.c +6 -0
@@ -2379,6 +2381,16 @@ static int ftdi_stmclite_probe(struct usb_serial *serial)
 	return 0;
 }
 
+static int ftdi_reset_resume(struct usb_serial *serial)
+{
+	struct usb_serial_port *port = serial->port[0];
+
+	if (tty_port_initialized(&port->port))
+		write_latency_timer(port);

Why are you only doing this for open ports?

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2392

Quoted 3 lines
drivers/usb/serial/ftdi_sio.c +3 -0
+
+	return usb_serial_generic_resume(serial);
+}

And if the device has been reset there may need to reconfigured the termios settings for open ports.

Could you expand a bit on what the problem is here?

Johan

#2 lore raw
Quoted 7 lines · Johan Hovold
Quoted 3 lines · Helge Deller

With a 4-port serial USB HUB with FT232BM chips the serial ports stop working after a software suspend/resume cycle.
Rewriting the latency timer during the resume phase fixes it.

Hmm. This sounds weird. Why would the latency timer make such a difference?

Actually, I don't know.
My assumption is, that by setting the latency timer, the USB transmissions somehow starts again. Maybe the integrated HUB is involved as well? I'm no expert on this driver, the only thing I did is to compare what is being configured when the device is detected and initialized and when what happens when it's waked up.
Setting the latency timer seemed to me to be the only difference, and it actually worked then.

But I agree, it seems weird. If you have other ideas, I'm happy to test.

Quoted 27 lines
Quoted 27 lines
drivers/usb/serial/ftdi_sio.c +2 -0
index 9823bb424abd..8ee6cf6215c1 100644
@@ -1092,6 +1092,7 @@ static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base);
 static u32 ftdi_232bm_baud_to_divisor(int baud);
 static u32 ftdi_2232h_baud_base_to_divisor(int baud, int base);
 static u32 ftdi_2232h_baud_to_divisor(int baud);
+static int ftdi_reset_resume(struct usb_serial *serial);
 
 static struct usb_serial_driver ftdi_sio_device = {
 	.driver = {
@@ -1122,6 +1123,7 @@ static struct usb_serial_driver ftdi_sio_device = {
 	.set_termios =		ftdi_set_termios,
 	.break_ctl =		ftdi_break_ctl,
 	.tx_empty =		ftdi_tx_empty,
+	.reset_resume =		ftdi_reset_resume,
 };
 
 static struct usb_serial_driver * const serial_drivers[] = {
@@ -2379,6 +2381,16 @@ static int ftdi_stmclite_probe(struct usb_serial *serial)
 	return 0;
 }
 
Quoted 8 lines

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2389

Quoted 6 lines
drivers/usb/serial/ftdi_sio.c +6 -0
+static int ftdi_reset_resume(struct usb_serial *serial)
+{
+	struct usb_serial_port *port = serial->port[0];
+
+	if (tty_port_initialized(&port->port))
+		write_latency_timer(port);

Why are you only doing this for open ports?

I more or less copied it from another driver....

Quoted 8 lines

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2392

Quoted 3 lines
drivers/usb/serial/ftdi_sio.c +3 -0
+
+	return usb_serial_generic_resume(serial);
+}

And if the device has been reset there may need to reconfigured the termios settings for open ports.

Could you expand a bit on what the problem is here?

My testcase is pretty simple:
1. I use e.g. "minicom -D /dev/ttyUSB2". Serial connection works.
2. I exit minicom.
3. I suspend the workstation: "systemctl suspend"
4. I wake up the machine and wait a few seconds.
5. I start "minicom -D /dev/ttyUSB2" again. No transfers on the serial port.

With my patch the minicom serial communications does work.
Another way to wake up the connection is to rmmod the driver and insmod it again.

Helge

maintainer
#3 lore raw
Quoted 33 lines · Helge Deller
Quoted 5 lines · Johan Hovold
Quoted 3 lines · Helge Deller

With a 4-port serial USB HUB with FT232BM chips the serial ports stop working after a software suspend/resume cycle.
Rewriting the latency timer during the resume phase fixes it.

Quoted 8 lines

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2389

Quoted 6 lines
drivers/usb/serial/ftdi_sio.c +6 -0
+static int ftdi_reset_resume(struct usb_serial *serial)
+{
+	struct usb_serial_port *port = serial->port[0];
+
+	if (tty_port_initialized(&port->port))
+		write_latency_timer(port);

Why are you only doing this for open ports?

I more or less copied it from another driver....

Quoted 8 lines

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2392

Quoted 3 lines
drivers/usb/serial/ftdi_sio.c +3 -0
+
+	return usb_serial_generic_resume(serial);
+}

And if the device has been reset there may need to reconfigured the termios settings for open ports.

Could you expand a bit on what the problem is here?

My testcase is pretty simple:
1. I use e.g. "minicom -D /dev/ttyUSB2". Serial connection works.
2. I exit minicom.
3. I suspend the workstation: "systemctl suspend"
4. I wake up the machine and wait a few seconds.
5. I start "minicom -D /dev/ttyUSB2" again. No transfers on the serial port.

Quoted 3 lines

With my patch the minicom serial communications does work. Another way to wake up the connection is to rmmod the driver and insmod it again.

Weird indeed. If you exit minicom before suspend and no other process is keeping the port open, then that write_latency_timer() above would never be executed.

Could you enable some debugging and provide a dmesg log from a test cycle (open/close minicom, suspend/resume, open minicom)?

echo file usb-serial.c +p > /sys/kernel/debug/dynamic_debug/control

Johan

#4 lore raw
Quoted 38 lines · Johan Hovold
Quoted 33 lines · Helge Deller
Quoted 5 lines · Johan Hovold
Quoted 3 lines · Helge Deller

With a 4-port serial USB HUB with FT232BM chips the serial ports stop working after a software suspend/resume cycle.
Rewriting the latency timer during the resume phase fixes it.

Quoted 8 lines

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2389

Quoted 6 lines
drivers/usb/serial/ftdi_sio.c +6 -0
+static int ftdi_reset_resume(struct usb_serial *serial)
+{
+	struct usb_serial_port *port = serial->port[0];
+
+	if (tty_port_initialized(&port->port))
+		write_latency_timer(port);

Why are you only doing this for open ports?

I more or less copied it from another driver....

Quoted 8 lines

drivers/usb/serial/ftdi_sio.c static int ftdi_stmclite_probe(struct usb_serial *serial) · line 2392

Quoted 3 lines
drivers/usb/serial/ftdi_sio.c +3 -0
+
+	return usb_serial_generic_resume(serial);
+}

And if the device has been reset there may need to reconfigured the termios settings for open ports.

Could you expand a bit on what the problem is here?

My testcase is pretty simple:
1. I use e.g. "minicom -D /dev/ttyUSB2". Serial connection works.
2. I exit minicom.
3. I suspend the workstation: "systemctl suspend"
4. I wake up the machine and wait a few seconds.
5. I start "minicom -D /dev/ttyUSB2" again. No transfers on the serial port.

Quoted 3 lines

With my patch the minicom serial communications does work. Another way to wake up the connection is to rmmod the driver and insmod it again.

Quoted 8 lines

Weird indeed. If you exit minicom before suspend and no other process is keeping the port open, then that write_latency_timer() above would never be executed.

Could you enable some debugging and provide a dmesg log from a test cycle (open/close minicom, suspend/resume, open minicom)?

echo file usb-serial.c +p > /sys/kernel/debug/dynamic_debug/control

I enabled the debugging and tried a few times, but somehow I can not reproduce the issue any longer.

So, please drop my patch for now.

Thanks!
Helge

maintainer
#5 lore raw
Quoted 21 lines · Helge Deller
Quoted 20 lines · Johan Hovold
Quoted 10 lines · Helge Deller

My testcase is pretty simple:
1. I use e.g. "minicom -D /dev/ttyUSB2". Serial connection works.
2. I exit minicom.
3. I suspend the workstation: "systemctl suspend"
4. I wake up the machine and wait a few seconds.
5. I start "minicom -D /dev/ttyUSB2" again. No transfers on the serial port.

With my patch the minicom serial communications does work. Another way to wake up the connection is to rmmod the driver and insmod it again.

Weird indeed. If you exit minicom before suspend and no other process is keeping the port open, then that write_latency_timer() above would never be executed.

Could you enable some debugging and provide a dmesg log from a test cycle (open/close minicom, suspend/resume, open minicom)?

Quoted 6 lines
Quoted 1 line

echo file usb-serial.c +p > /sys/kernel/debug/dynamic_debug/control

I enabled the debugging and tried a few times, but somehow I can not reproduce the issue any longer.

So, please drop my patch for now.

Good to hear the problem's gone. :) Let us know if you run into it again.

Johan