Posted by on Mag 22, 2016 in kernel, Linux, ModemManager |

USB device persistence is a very useful Linux kernel features mainly created (in my opinion) to simplify life for user-space applications with USB devices during system suspend.

Here you can find what the USB device persistence really is and which problems it is trying to solve: most of the times it is a really attractive feature, especially for mass-storage devices as described in the document, but sometimes it can cause unwanted behaviors.

USB device persistence

That’s what happened recently, when I had to deal with a custom embedded system, equipped with a 3G modem controlled through ModemManager.

The distinctive trait of this system was that, during power state S3, the modem was kept in reset state. After resume the modem was up again and, thanks to usb device persistence, all should have been working properly at the user-space level, but, unfortunately, it wasn’t.

Why USB device persistence was causing problems?

One of the effect of the usb device persistence in this situation was that the ttyACM devices created for the modem did not disappear during the S3 / Resume transition, so the ModemManager was behaving as nothing happened.

But in this specific scenario this was wrong due to two different issues:

  • Major issue: the modem port required the DTR signal to be set for returning answers to AT commands. After the S3 / Resume transition, the modem has been resetted, so on the modem side the port did not have DTR set, while on the host side, due to the serial port driver data structure persistence, DTR was considered high. The result was that host and modem were not able to communicate on a port that was open before the transition.
  • Secondary issue: ModemManager has an initialization sequence that is executed every time a new modem is found. This initialization sequence applies some setting in the modem (e.g. unsolicited notifications for network events). This settings are not saved in the NVM memory of the modem and should be applied again every time the modem is turned on. In that situation usb device persistence did not allow ModemManager to understand that the modem needed to be initialized again.

Both issues were solved disabling the usb device persistence for the modem.