Bug 210695 - USB on RPi Zero doesn't notice device disappearance
Summary: USB on RPi Zero doesn't notice device disappearance
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm Any
: --- Affects Only Me
Assignee: freebsd-arm (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-29 12:34 UTC by Edward Tomasz Napierala
Modified: 2016-07-11 12:59 UTC (History)
1 user (show)

See Also:


Attachments
Debug log (84.44 KB, text/plain)
2016-06-29 15:01 UTC, Edward Tomasz Napierala
no flags Details
DWC OTG patch (425 bytes, patch)
2016-06-30 19:32 UTC, Hans Petter Selasky
no flags Details | Diff
DWC OTG patch (660 bytes, patch)
2016-06-30 20:22 UTC, Hans Petter Selasky
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-06-29 12:34:05 UTC
FreeBSD 11.0-CURRENT, when running on Raspberry Pi Zero ("bcm283x_dwcotg0: <DWC OTG 2.0 integrated USB controller (bcm283x)> mem 0x980000-0x99ffff irq 10029 on simplebus0"), doesn't seem to "notice" the device got unplugged.  In other words, after disconnecting the USB memory stick from the USB cable, "usbconfig" claims the device is still there:

root@rpi-b:~ # usbconfig 
ugen0.1: <OTG Root HUB DWCOTG> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.2: <DataTraveler 3.0 Kingston> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (300mA)
Comment 1 Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-06-29 12:36:31 UTC
Forgot to mention: "usbconfig reset" clears the situation.
Comment 2 Hans Petter Selasky freebsd_committer freebsd_triage 2016-06-29 12:39:35 UTC
Hi,

It is likely some OTG interrupt which is not handled by the driver.

We need to emulate the port status.

Can you enable first:

hw.usb.uhub.debug=16

Any disconnect messages when you unplug.

Then enabled the debug knob for the dwc otg just before you disconnect for like 1-2 seconds. It produces a lot of messages too. See if there is an OTG interrupt and write down the values.

Thank you!

--HPS
Comment 3 Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-06-29 15:01:27 UTC
Created attachment 171946 [details]
Debug log
Comment 4 Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-06-29 15:02:17 UTC
After disconnection:

usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
usb_bus_powerd: Recomputing power masks
uhub_explore: udev=0xc2b12000 addr=1
uhub_read_port_status: port 1, wPortStatus=0x0500, wPortChange=0x0000, err=USB_ERR_NORMAL_COMPLETION
usbd_transfer_power_ref: Adding type 2 to power state
usbd_transfer_power_ref: needs power
usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
uhub_explore: udev=0xc2b12000 addr=1
uhub_read_port_status: port 1, wPortStatus=0x0500, wPortChange=0x0000, err=USB_ERR_NORMAL_COMPLETION
usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
usb_bus_powerd: Recomputing power masks
uhub_explore: udev=0xc2b12000 addr=1
uhub_read_port_status: port 1, wPortStatus=0x0500, wPortChange=0x0000, err=USB_ERR_NORMAL_COMPLETION
usbd_transfer_power_ref: Adding type 0 to power state
usbd_transfer_power_ref: needs power
usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
usb_bus_powerd: Recomputing power masks
uhub_explore: udev=0xc2b12000 addr=1
uhub_read_port_status: port 1, wPortStatus=0x0500, wPortChange=0x0000, err=USB_ERR_NORMAL_COMPLETION
usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
usb_bus_powerd: Recomputing power masks
uhub_explore: udev=0xc2b12000 addr=1
uhub_read_port_status: port 1, wPortStatus=0x0500, wPortChange=0x0000, err=USB_ERR_NORMAL_COMPLETION
usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
uhub_explore: udev=0xc2b12000 addr=1
uhub_read_port_status: port 1, wPortStatus=0x0500, wPortChange=0x0000, err=USB_ERR_NORMAL_COMPLETION
usb_needs_explore: 
usb_bus_powerd: bus=0xc28e8000
usb_bus_powerd: Recomputing power masks
uhub_explore: udev=0xc2b12000 addr=1

Note that the messages seem to came from some sort of one-second timer.  The second log, with dwc_otg debug level set to 1000, is attached.
Comment 5 Hans Petter Selasky freebsd_committer freebsd_triage 2016-06-30 19:32:07 UTC
Created attachment 171981 [details]
DWC OTG patch

Can you test the attached patch?
Comment 6 Hans Petter Selasky freebsd_committer freebsd_triage 2016-06-30 20:22:35 UTC
Created attachment 171982 [details]
DWC OTG patch

Needed to mask the port change event on plug - but not unplug.
Comment 7 Edward Tomasz Napierala freebsd_committer freebsd_triage 2016-07-01 07:20:30 UTC
The patch fixes the problem.  Thanks :-)
Comment 8 commit-hook freebsd_committer freebsd_triage 2016-07-01 07:28:16 UTC
A commit references this bug:

Author: hselasky
Date: Fri Jul  1 07:27:33 UTC 2016
New revision: 302306
URL: https://svnweb.freebsd.org/changeset/base/302306

Log:
  Fix detection of USB device disconnects in USB host mode when the USB
  device is connected directly to the USB port of the DWC OTG, in this
  case a RPI-zero.

  PR:		210695
  Approved by:	re (gjb)
  MFC after:	1 week

Changes:
  head/sys/dev/usb/controller/dwc_otg.c
Comment 9 commit-hook freebsd_committer freebsd_triage 2016-07-11 12:59:47 UTC
A commit references this bug:

Author: hselasky
Date: Mon Jul 11 12:59:23 UTC 2016
New revision: 302562
URL: https://svnweb.freebsd.org/changeset/base/302562

Log:
  MFC r302306:
  Fix detection of USB device disconnects in USB host mode when the USB
  device is connected directly to the USB port of the DWC OTG, in this
  case a RPI-zero.

  PR:		210695

Changes:
_U  stable/10/
  stable/10/sys/dev/usb/controller/dwc_otg.c