All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Martin Kepplinger <martin.kepplinger@puri.sm>
Cc: linux-usb@vger.kernel.org
Subject: Re: USB device disconnects on resume
Date: Thu, 28 Apr 2022 15:13:24 -0400	[thread overview]
Message-ID: <YmrnVHA2/kttJQJa@rowland.harvard.edu> (raw)
In-Reply-To: <232334eeb9d7321df1632e453839a6d433e6be45.camel@puri.sm>

On Thu, Apr 28, 2022 at 09:01:50AM +0200, Martin Kepplinger wrote:
> Am Dienstag, dem 26.04.2022 um 10:58 -0400 schrieb Alan Stern:
> > Here's a quick low-level description of what's going on.
> > 
> > When a hub gets a disconnect event on one of its ports, it disables
> > the 
> > port.  The port then remains disabled, even if another device is
> > plugged 
> > in, until a successful port reset occurs.  In other words, the _only_
> > way to re-enable a port is to issue a reset.
> > 
> > The reset-resume mechanism in the kernel takes care of issuing the 
> > reset, and it checks to make sure that the device attached to the
> > port 
> > hasn't been changed (i.e., it's still the same device as before, not
> > a 
> > new one).  If that works, the device is put back in its former
> > operating 
> > state and should keep on functioning normally.  If that doesn't work,
> > or 
> > if there is a new device attached to the port, the kernel treats the 
> > event just like a normal disconnect + connect.
> > 
> > So what you want really _is_ a reset-resume.  If successful, it will 
> > give the behavior you mentioned above: continued transmission with
> > maybe 
> > some data loss and a big latency spike at one point.  Anything other 
> > than a successful reset-resume will cause the ttyUSB file to become 
> > unusable, exactly what you don't want.
> > 
> > So the real question you need to answer is why a reset-resume
> > sometimes 
> > fails with this modem.  I suspect the answer will be that the modem
> > is 
> > buggy, and there may not be any way to work around the bug.  But try 
> > putting the msleep(500) just before the usb_reset_and_verify_device()
> > call; maybe it will help.
> > 
> > Alan Stern
> 
> ok. thanks a lot for that suggestion! I added an extremely long
> msleep(5000) there and the behaviour indeed consistently changes a bit.
> (almost consistently, rarely I see the modem coming up as low-speed
> device, which is not allowed by hub.c and thus re-enumeration is
> triggered) but I added more debug messages and almost always that's how
> it looks like. I hope my added messages are understandable enough:
> 
> 11:43:50.800648: hub 1-1:1.0: hub_suspend
> 11:43:50.820074: usb 1-1: usb auto-suspend, wakeup 1
> 11:43:50.880637: usb 1-1: usb wakeup-resume
> 11:43:50.908646: usb 1-1: Waited 0ms for CONNECT
> 11:43:50.910445: usb 1-1: finish resume
> 11:43:50.911865: hub 1-1:1.0: hub_resume
> 11:43:50.913842: usb 1-1-port1: status 0507 change 0000
> 11:43:50.914026: usb 1-1-port2: status 0101 change 0005
> 11:43:51.020887: usb usb1-port1: resume, status 0
> 11:43:51.021205: hub 1-1:1.0: state 7 ports 3 chg 0004 evt 0000
> 11:43:51.048658: usb 1-1.2: usb wakeup-resume
> 11:43:51.076670: usb 1-1.2: Waited 0ms for CONNECT
> 11:43:51.078573: usb 1-1.2: finish reset-resume
> 11:43:56.305074: usb 1-1-port2: hub_port_reset: starting try 0 of 5
> 11:43:56.328683: hub 1-1:1.0: port_wait_reset: err = -11

-EAGAIN means that the modem disconnected around the time of the reset, 
so the reset failed.

> 11:43:56.333794: usb 1-1-port2: not enabled, trying reset again... 0 of
> 5. status=-11
> 11:43:56.334074: usb 1-1-port2: hub_port_reset: starting try 1 of 5
> 11:43:56.536645: usb 1-1-port2: hub_port_reset: no superspeed. status:
> 0. bail out

Not sure what that means.

> 11:43:56.628824: usb 1-1.2: reset high-speed USB device number 6 using
> xhci-hcd
> 11:43:56.640305: usb 1-1-port2: hub_port_reset: starting try 0 of 5
> 11:43:56.656735: usb 1-1-port2: hub_port_reset: no superspeed. status:
> 0. bail out
> 11:43:56.752738: usb 1-1-port2: resume, status 0

And it's hard to tell exactly what that refers to.

> 11:43:56.755442: usb 1-1-port2: port_event: call
> hub_port_connect_change because connect_change is 1
> 11:43:56.756663: usb 1-1-port2: status 0101, change 0004, 12 Mb/s
> 11:43:56.756942: usb 1-1.2: hub_port_connect_change: not resuscitating.
> 11:43:56.762495: usb 1-1-port2: hub_port_connect_change: could not
> revalidate the connection. call hub_port_connect.
> 11:43:56.762797: usb 1-1.2: USB disconnect, device number 6
> 11:43:56.765481: usb 1-1.2: unregistering device

It looks like these things happened after the reset-resume failed.  But 
the control flow isn't clear (more log messages might help).

> I'm sending this before analyzing it further. I'll do so soon but
> wanted to show you that already.

Okay.  But it seems that the modem refused to be reset properly.  When 
that happens there's no way to avoid disconnection.  And in fact I would 
expect that re-initialization and enumeration would then be impossible, 
since the first step of initialization is to perform a reset.

Alan Stern

  reply	other threads:[~2022-04-28 19:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-19  9:28 USB device disconnects on resume Martin Kepplinger
2022-04-19 14:32 ` Alan Stern
2022-04-20 10:37   ` Martin Kepplinger
2022-04-20 14:40     ` Alan Stern
2022-04-21 10:38       ` Martin Kepplinger
2022-04-21 14:24         ` Alan Stern
2022-04-25  9:45           ` Martin Kepplinger
2022-04-26 14:58             ` Alan Stern
2022-04-28  7:01               ` Martin Kepplinger
2022-04-28 19:13                 ` Alan Stern [this message]
2022-04-29 10:15                   ` Martin Kepplinger
2022-04-29 20:21                     ` Alan Stern
     [not found]                       ` <fdc8354e39f9162bcc63ab99f237bdbbe30d6017.camel@puri.sm>
2022-05-02 19:32                         ` Alan Stern
2022-05-03  7:36                           ` Oliver Neukum
2022-05-03 13:56                             ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YmrnVHA2/kttJQJa@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=linux-usb@vger.kernel.org \
    --cc=martin.kepplinger@puri.sm \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.