1. 02 Jun, 2014 1 commit
  2. 29 May, 2014 9 commits
  3. 28 May, 2014 9 commits
  4. 27 May, 2014 21 commits
    • Dan Williams's avatar
      usb: hub_handle_remote_wakeup() depends on CONFIG_PM_RUNTIME=y · 7e73be22
      Dan Williams authored
      Per Alan:
      "You mean from within hub_handle_remote_wakeup()?  That routine will
      never get called if CONFIG_PM_RUNTIME isn't enabled, because khubd
      never sees wakeup requests if they arise during system suspend.
      
      In fact, that routine ought to go inside the "#ifdef CONFIG_PM_RUNTIME"
      portion of hub.c, along with the other suspend/resume code."
      Suggested-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7e73be22
    • Dan Williams's avatar
      usb: introduce port status lock · 5c79a1e3
      Dan Williams authored
      In general we do not want khubd to act on port status changes that are
      the result of in progress resets or USB runtime PM operations.
      Specifically port power control testing has been able to trigger an
      unintended disconnect in hub_port_connect_change(), paraphrasing:
      
      	if ((portstatus & USB_PORT_STAT_CONNECTION) && udev &&
      	    udev->state != USB_STATE_NOTATTACHED) {
      		if (portstatus & USB_PORT_STAT_ENABLE) {
      			/* Nothing to do */
      		} else if (udev->state == USB_STATE_SUSPENDED &&
      				udev->persist_enabled) {
      			...
      		} else {
      			/* Don't resuscitate */;
      		}
      	}
      
      ...by falling to the "Don't resuscitate" path or missing
      USB_PORT_STAT_CONNECTION because usb_port_resume() was in the middle of
      modifying the port status.
      
      So, we want a new lock to hold off khubd for a given port while the
      child device is being suspended, resumed, or reset.  The lock ordering
      rules are now usb_lock_device() => usb_lock_port().  This is mandated by
      the device core which may hold the device_lock on the usb_device before
      invoking usb_port_{suspend|resume} which in turn take the status_lock on
      the usb_port.  We attempt to hold the status_lock for the duration of a
      port_event() run, and drop/re-acquire it when needing to take the
      device_lock.  The lock is also dropped/re-acquired during
      hub_port_reconnect().
      
      This patch also deletes hub->busy_bits as all use cases are now covered
      by port PM runtime synchronization or the port->status_lock and it
      pushes down usb_device_lock() into usb_remote_wakeup().
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5c79a1e3
    • Dan Williams's avatar
      usb: synchronize port poweroff and khubd · 097a155f
      Dan Williams authored
      If a port is powered-off, or in the process of being powered-off, prevent
      khubd from operating on it.  Otherwise, the following sequence of events
      leading to an unintended disconnect may occur:
      
      Events:
      (0) <set pm_qos_no_poweroff to '0' for port1>
      (1) hub 2-2:1.0: hub_resume
      (2) hub 2-2:1.0: port 1: status 0301 change 0000
      (3) hub 2-2:1.0: state 7 ports 4 chg 0002 evt 0000
      (4) hub 2-2:1.0: port 1, power off status 0000, change 0000, 12 Mb/s
      (5) usb 2-2.1: USB disconnect, device number 5
      
      Description:
      (1) hub is resumed before sending a ClearPortFeature request
      (2) hub_activate() notices the port is connected and sets
          hub->change_bits for the port
      (3) hub_events() starts, but at the same time the port suspends
      (4) hub_connect_change() sees the disabled port and triggers disconnect
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      097a155f
    • Dan Williams's avatar
      usb: refactor port handling in hub_events() · af376a46
      Dan Williams authored
      In preparation for synchronizing port handling with pm_runtime
      transitions refactor port handling into its own subroutine.
      
      We expect that clearing some status flags will be required regardless of
      the port state, so handle those first and group all non-trivial actions
      at the bottom of the routine.
      
      This also splits off the bottom half of hub_port_connect_change() into
      hub_port_reconnect() in prepartion for introducing a port->status_lock.
      hub_port_reconnect() will expect the port lock to not be held while
      hub_port_connect_change() expects to enter with it held.
      
      Other cleanups include:
      1/ reflowing to 80 columns
      2/ replacing redundant usages of 'hub->hdev' with 'hdev'
      3/ consolidate clearing of ->change_bits() in hub_port_connect_change
      4/ consolidate calls to usb_reset_device
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      af376a46
    • Dan Williams's avatar
      usb: usb3 ports do not support FEAT_C_ENABLE · 69080584
      Dan Williams authored
      The port pm_runtime implementation unconditionally clears FEAT_C_ENABLE
      after clearing PORT_POWER, but the bit is reserved on usb3 hub ports.
      We expect khubd to be prevented from running because the port state is
      not RPM_ACTIVE, so we need to clear any errors for usb2 ports.
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      69080584
    • Dan Williams's avatar
      usb: don't clear FEAT_C_ENABLE on usb_port_runtime_resume failure · 7c604079
      Dan Williams authored
      Three reasons:
      1/ It's an invalid operation on usb3 ports
      2/ There's no guarantee of when / if a usb2 port has entered an error
         state relative to PORT_POWER request
      3/ The port is active / powered at this point, so khubd will clear it as
         a matter of course
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7c604079
    • Dan Williams's avatar
      usb: block suspension of superspeed port while hispeed peer is active · 7ad3c470
      Dan Williams authored
      ClearPortFeature(PORT_POWER) on a usb3 port places the port in either a
      DSPORT.Powered-off-detect / DSPORT.Powered-off-reset loop, or the
      DSPORT.Powered-off state.  There is no way to ensure that RX
      terminations will persist in this state, so it is possible a device will
      degrade to its usb2 connection.  Prevent this by blocking power-off of a
      usb3 port while its usb2 peer is active, and powering on a usb3 port
      before its usb2 peer.
      
      By default the latency between peer power-on events is 0.  In order for
      the device to not see usb2 active while usb3 is still powering up inject
      the hub recommended power_on_good delay.  In support of satisfying the
      power_on_good delay outside of hub_power_on() refactor the places where
      the delay is consumed to call a new hub_power_on_good_delay() helper.
      
      Finally, because this introduces several new checks for whether a port
      is_superspeed, cache that disctinction at port creation so that we don't
      need to keep looking up the parent hub device.
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      [alan]: add a 'superspeed' flag to the port
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7ad3c470
    • Dan Williams's avatar
      usb: make usb_port flags atomic, rename did_runtime_put to child_usage · d5c3834e
      Dan Williams authored
      We want to manipulate ->did_runtime_put in usb_port_runtime_resume(),
      but we don't want that to collide with other updates.  Move usb_port
      flags to new port-bitmap fields in usb_hub. "did_runtime_put" is renamed
      "child_usage_bits" to reflect that it is strictly standing in for the
      fact that usb_devices are not the device_model children of their parent
      port.
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d5c3834e
    • Dan Williams's avatar
      usb: sysfs link peer ports · b7e38eac
      Dan Williams authored
      The usb topology after this change will have symlinks between usb3 ports
      and their usb2 peers, for example:
      
      usb2/2-1/2-1:1.0/2-1-port1/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port1
      usb2/2-1/2-1:1.0/2-1-port2/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port2
      usb2/2-1/2-1:1.0/2-1-port3/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port3
      usb2/2-1/2-1:1.0/2-1-port4/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port4
      usb2/2-0:1.0/usb2-port1/peer    => ../../../usb3/3-0:1.0/usb3-port1
      usb2/2-0:1.0/usb2-port2/peer    => ../../../usb3/3-0:1.0/usb3-port2
      usb2/2-0:1.0/usb2-port3/peer    => ../../../usb3/3-0:1.0/usb3-port3
      usb2/2-0:1.0/usb2-port4/peer    => ../../../usb3/3-0:1.0/usb3-port4
      
      usb3/3-1/3-1:1.0/usb3-1-port1/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port1
      usb3/3-1/3-1:1.0/usb3-1-port2/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port2
      usb3/3-1/3-1:1.0/usb3-1-port3/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port3
      usb3/3-1/3-1:1.0/usb3-1-port4/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port4
      usb3/3-0:1.0/usb3-port1/peer       => ../../../usb2/2-0:1.0/usb2-port1
      usb3/3-0:1.0/usb3-port2/peer       => ../../../usb2/2-0:1.0/usb2-port2
      usb3/3-0:1.0/usb3-port3/peer       => ../../../usb2/2-0:1.0/usb2-port3
      usb3/3-0:1.0/usb3-port4/peer       => ../../../usb2/2-0:1.0/usb2-port4
      
      Introduce link_peers_report() to notify on all link_peers() failure
      cases.
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b7e38eac
    • Dan Williams's avatar
      usb: find internal hub tier mismatch via acpi · 3bfd659b
      Dan Williams authored
      ACPI identifies peer ports by setting their 'group_token' and
      'group_position' _PLD data to the same value.  If a platform has tier
      mismatch [1] , ACPI can override the default (USB3 defined) peer port
      association for internal hubs.  External hubs follow the default peer
      association scheme.
      
      Location data is cached as an opaque cookie in usb_port_location data.
      
      Note that we only consider the group_token and group_position attributes
      from the _PLD data as ACPI specifies that group_token is a unique
      identifier.
      
      When we find port location data for a port then we assume that the
      firmware will also describe its peer port.  This allows the
      implementation to only ever set the peer once.  This leads to a question
      about what happens when a pm runtime event occurs while the peer
      associations are still resolving.  Since we only ever set the peer
      information once, a USB3 port needs to be prevented from suspending
      while its ->peer pointer is NULL (implemented in a subsequent patch).
      
      There is always the possibility that firmware mis-identifies the ports,
      but there is not much the kernel can do in that case.
      
      [1]: xhci 1.1 appendix D figure 131
      [2]: acpi 5 section 6.1.8
      
      [alan]: don't do default peering when acpi data present
      Suggested-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3bfd659b
    • Dan Williams's avatar
      usb: assign usb3 external hub port peers · 8b1ba80c
      Dan Williams authored
      Given that root hub port peers are already established, external hub peer
      ports can be determined by traversing the device topology:
      
      1/ ascend to the parent hub and find the upstream port_dev
      
      2/ walk ->peer to find the peer port
      
      3/ descend to the peer hub via ->child
      
      4/ find the port with the matching port id
      
      Note that this assumes the port labeling scheme required by the
      specification [1].
      
      [1]: usb3 3.1 section 10.3.3
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8b1ba80c
    • Dan Williams's avatar
      usb: assign default peer ports for root hubs · d8521afe
      Dan Williams authored
      Assume that the peer of a superspeed port is the port with the same id
      on the shared_hcd root hub.  This identification scheme is required of
      external hubs by the USB3 spec [1].  However, for root hubs, tier mismatch
      may be in effect [2].  Tier mismatch can only be enumerated via platform
      firmware.  For now, simply perform the nominal association.
      
      A new lock 'usb_port_peer_mutex' is introduced to synchronize port
      device add/remove with peer lookups.  It protects peering against
      changes to hcd->shared_hcd, hcd->self.root_hub, hdev->maxchild, and
      port_dev->child pointers.
      
      [1]: usb 3.1 section 10.3.3
      [2]: xhci 1.1 appendix D
      
      Cc: Alan Stern <stern@rowland.harvard.edu>
      [alan: usb_port_peer_mutex locking scheme]
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d8521afe
    • Dan Williams's avatar
      usb: cleanup setting udev->removable from port_dev->connect_type · a4204ff0
      Dan Williams authored
      Once usb-acpi has set the port's connect type the usb_device's
      ->removable attribute can be set in the standard location
      set_usb_port_removable().
      
      This also changes behavior in the case where the firmware says that the
      port connect type is unknown.  In that case just use the default setting
      determined from the hub descriptor.
      
      Note, we no longer pass udev->portnum to acpi_find_child_device() in the
      root hub case since:
      1/ the usb-core sets this to zero
      2/ acpi always expects zero
      ...just pass zero.
      Suggested-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a4204ff0
    • Dan Williams's avatar
      usb: rename usb_port device objects · d99f6b41
      Dan Williams authored
      The current port name "portX" is ambiguous.  Before adding more port
      messages rename ports to "<hub-device-name>-portX"
      
      This is an ABI change, but the suspicion is that it will go unnoticed as
      the port power control implementation has been broken since its
      introduction.  If however, someone was relying on the old name we can
      add sysfs links from the old name to the new name.
      
      Additionally, it unifies/simplifies port dev_printk messages and modifies
      instances of:
      	dev_XXX(hub->intfdev, ..."port %d"...
      	dev_XXX(&hdev->dev, ..."port%d"...
      into:
      	dev_XXX(&port_dev->dev, ...
      
      Now that the names are unique usb_port devices it would be nice if they
      could be included in /sys/bus/usb.  However, it turns out that this
      breaks 'lsusb -t'.  For now, create a dummy port driver so that print
      messages are prefixed "usb 1-1-port3" rather than the
      subsystem-ambiguous " 1-1-port3".
      
      Finally, it corrects an odd usage of sscanf("port%d") in usb-acpi.c.
      Suggested-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d99f6b41
    • Dan Williams's avatar
      usb: disable port power control if not supported in wHubCharacteristics · 9262c19d
      Dan Williams authored
      A hub indicates whether it supports per-port power control via the
      wHubCharacteristics field in its descriptor.  If it is not supported
      a hub will still emulate ClearPortPower(PORT_POWER) requests by
      stopping the link state machine.  However, since this does not save
      power do not bother suspending.
      
      This also consolidates support checks into a
      hub_is_port_power_switchable() helper.
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9262c19d
    • Alan Stern's avatar
      USB: mutual exclusion for resetting a hub and power-managing a port · 600856c2
      Alan Stern authored
      The USB core doesn't properly handle mutual exclusion between
      resetting a hub and changing the power states of the hub's ports.  We
      need to avoid sending port-power requests to the hub while it is being
      reset, because such requests cannot succeed.
      
      This patch fixes the problem by keeping track of when a reset is in
      progress.  At such times, attempts to suspend (power-off) a port will
      fail immediately with -EBUSY, and calls to usb_port_runtime_resume()
      will update the power_is_on flag and return immediately.  When the
      reset is complete, hub_activate() will automatically restore each port
      to the proper power state.
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarDan Williams <dan.j.williams@intel.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      600856c2
    • Konrad Zapalowicz's avatar
      usb: pci_quirks: fix sparse 'symbol not declared' warning · 342a7493
      Konrad Zapalowicz authored
      This commit fixes the following sparse warning:
      
      drivers/usb/host/pci-quirks.c:
          - 252: warning: symbol 'usb_hcd_amd_remote_wakeup_quirk' was not
            declared. Should it be static?
      
      This function is exported so the fix was to add it's declaration to the
      header file.
      Signed-off-by: default avatarKonrad Zapalowicz <bergo.torino@gmail.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      342a7493
    • Paul Bolle's avatar
      usb: gadget: rename CONFIG_USB_GADGET_PXA25X · d30f2065
      Paul Bolle authored
      Commit 193ab2a6 ("usb: gadget: allow multiple gadgets to be built")
      basically renamed the Kconfig symbol USB_GADGET_PXA25X to USB_PXA25X. It
      did not rename the related macros in use at that time. Commit
      c0a39151 ("ARM: pxa: fix inconsistent CONFIG_USB_PXA27X") did so for
      all but one macro. Rename that last macro too now.
      
      Fixes: 193ab2a6 ("usb: gadget: allow multiple gadgets to be built")
      Signed-off-by: default avatarPaul Bolle <pebolle@tiscali.nl>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d30f2065
    • Benoit Taine's avatar
      USB: storage: ene_ub6250: Use kmemdup instead of kmalloc + memcpy · a328512d
      Benoit Taine authored
      This issue was reported by coccicheck using the semantic patch
      at scripts/coccinelle/api/memdup.cocci
      Signed-off-by: default avatarBenoit Taine <benoit.taine@lip6.fr>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a328512d
    • Huang Rui's avatar
      usb: usbtest: add pattern check on pipe in phase of unlink read · a7683eb3
      Huang Rui authored
      TEST 11 unlinks the URB read request for N times. When host and gadget
      both initialize pattern 1 (mod 63) data series to do IN transfer, the
      host side function should check the data buffer if it is as mod 63
      series, because the data packet which host receivced will follow
      pattern 1. So this patch adds this checking action.
      Signed-off-by: default avatarHuang Rui <ray.huang@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a7683eb3
    • Huang Rui's avatar
      usb: usbtest: fix unlink write error with pattern 1 · e4d58f5d
      Huang Rui authored
      TEST 12 and TEST 24 unlinks the URB write request for N times. When
      host and gadget both initialize pattern 1 (mod 63) data series to
      transfer, the gadget side will complain the wrong data which is not
      expected.  Because in host side, usbtest doesn't fill the data buffer
      as mod 63 and this patch fixed it.
      
      [20285.488974] dwc3 dwc3.0.auto: ep1out-bulk: Transfer Not Ready
      [20285.489181] dwc3 dwc3.0.auto: ep1out-bulk: reason Transfer Not Active
      [20285.489423] dwc3 dwc3.0.auto: ep1out-bulk: req ffff8800aa6cb480 dma aeb50800 length 512 last
      [20285.489727] dwc3 dwc3.0.auto: ep1out-bulk: cmd 'Start Transfer' params 00000000 a9eaf000 00000000
      [20285.490055] dwc3 dwc3.0.auto: Command Complete --> 0
      [20285.490281] dwc3 dwc3.0.auto: ep1out-bulk: Transfer Not Ready
      [20285.490492] dwc3 dwc3.0.auto: ep1out-bulk: reason Transfer Active
      [20285.490713] dwc3 dwc3.0.auto: ep1out-bulk: endpoint busy
      [20285.490909] dwc3 dwc3.0.auto: ep1out-bulk: Transfer Complete
      [20285.491117] dwc3 dwc3.0.auto: request ffff8800aa6cb480 from ep1out-bulk completed 512/512 ===> 0
      [20285.491431] zero gadget: bad OUT byte, buf[1] = 0
      [20285.491605] dwc3 dwc3.0.auto: ep1out-bulk: cmd 'Set Stall' params 00000000 00000000 00000000
      [20285.491915] dwc3 dwc3.0.auto: Command Complete --> 0
      [20285.492099] dwc3 dwc3.0.auto: queing request ffff8800aa6cb480 to ep1out-bulk length 512
      [20285.492387] dwc3 dwc3.0.auto: ep1out-bulk: Transfer Not Ready
      [20285.492595] dwc3 dwc3.0.auto: ep1out-bulk: reason Transfer Not Active
      [20285.492830] dwc3 dwc3.0.auto: ep1out-bulk: req ffff8800aa6cb480 dma aeb51000 length 512 last
      [20285.493135] dwc3 dwc3.0.auto: ep1out-bulk: cmd 'Start Transfer' params 00000000 a9eaf000 00000000
      [20285.493465] dwc3 dwc3.0.auto: Command Complete --> 0
      
      Cc: <stable@vger.kernel.org>
      Signed-off-by: default avatarHuang Rui <ray.huang@amd.com>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e4d58f5d