19 Nov, 2020

1 commit

  • Paulian reported a crash that happens when a dock is unplugged during
    hibernation:

    [78436.228217] thunderbolt 0-1: device disconnected
    [78436.228365] BUG: kernel NULL pointer dereference, address: 00000000000001e0
    ...
    [78436.228397] RIP: 0010:icm_free_unplugged_children+0x109/0x1a0
    ...
    [78436.228432] Call Trace:
    [78436.228439] icm_rescan_work+0x24/0x30
    [78436.228444] process_one_work+0x1a3/0x3a0
    [78436.228449] worker_thread+0x30/0x370
    [78436.228454] ? process_one_work+0x3a0/0x3a0
    [78436.228457] kthread+0x13d/0x160
    [78436.228461] ? kthread_park+0x90/0x90
    [78436.228465] ret_from_fork+0x1f/0x30

    This happens because remove_unplugged_switch() calls tb_switch_remove()
    that releases the memory pointed by sw so the following lines reference
    to a memory that might be released already.

    Fix this by saving pointer to the parent device before calling
    tb_switch_remove().

    Reported-by: Paulian Bogdan Marinca
    Fixes: 4f7c2e0d8765 ("thunderbolt: Make sure device runtime resume completes before taking domain lock")
    Cc: stable@vger.kernel.org
    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     

06 Nov, 2020

1 commit


05 Nov, 2020

3 commits


26 Oct, 2020

1 commit


30 Sep, 2020

1 commit

  • …el/git/westeri/thunderbolt into usb-next

    Mika writes:

    thunderbolt: Changes for v5.10 merge window

    This includes following Thunderbolt/USB4 changes for v5.10 merge window:

    * A couple of optimizations around Tiger Lake force power logic and
    NHI (Native Host Interface) LC (Link Controller) mailbox command
    processing

    * Power management improvements for Software Connection Manager

    * Debugfs support

    * Allow KUnit tests to be enabled also when Thunderbolt driver is
    configured as module.

    * Few minor cleanups and fixes

    All these have been in linux-next with no reported issues.

    * tag 'thunderbolt-for-v5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt: (37 commits)
    thunderbolt: Capitalize comment on top of QUIRK_FORCE_POWER_LINK_CONTROLLER
    thunderbolt: Correct tb_check_quirks() kernel-doc
    thunderbolt: Log correct zeroX entries in decode_error()
    thunderbolt: Handle ERR_LOCK notification
    thunderbolt: Use "if USB4" instead of "depends on" in Kconfig
    thunderbolt: Allow KUnit tests to be built also when CONFIG_USB4=m
    thunderbolt: Only stop control channel when entering freeze
    thunderbolt: debugfs: Fix uninitialized return in counters_write()
    thunderbolt: Add debugfs interface
    thunderbolt: No need to warn in TB_CFG_ERROR_INVALID_CONFIG_SPACE
    thunderbolt: Introduce tb_switch_is_tiger_lake()
    thunderbolt: Introduce tb_switch_is_ice_lake()
    thunderbolt: Check for Intel vendor ID when identifying controller
    thunderbolt: Introduce tb_port_is_nhi()
    thunderbolt: Introduce tb_switch_next_cap()
    thunderbolt: Introduce tb_port_next_cap()
    thunderbolt: Move struct tb_cap_any to tb_regs.h
    thunderbolt: Add runtime PM for Software CM
    thunderbolt: Create device links from ACPI description
    ACPI: Export acpi_get_first_physical_node() to modules
    ...

    Greg Kroah-Hartman
     

16 Sep, 2020

7 commits


15 Sep, 2020

1 commit


11 Sep, 2020

1 commit


09 Sep, 2020

1 commit

  • Kai-Heng reported that sometimes DROM parsing of ASUS PA27AC Thunderbolt 3
    monitor fails. This makes the driver to fail to add the device so only
    DisplayPort tunneling is functional.

    It is not clear what exactly happens but waiting for 100 ms and retrying
    the read seems to work this around so we do that here.

    Link: https://bugzilla.kernel.org/show_bug.cgi?id=206493
    Reported-by: Kai-Heng Feng
    Tested-by: Kai-Heng Feng
    Cc: stable@vger.kernel.org
    Signed-off-by: Mika Westerberg

    Mika Westerberg
     

03 Sep, 2020

23 commits

  • This adds debugfs interface that can be used for debugging possible
    issues in hardware/software. It exposes router and adapter config spaces
    through files like this:

    /sys/kernel/debug/thunderbolt//regs
    /sys/kernel/debug/thunderbolt///regs
    /sys/kernel/debug/thunderbolt///path
    /sys/kernel/debug/thunderbolt///counters
    /sys/kernel/debug/thunderbolt///regs
    /sys/kernel/debug/thunderbolt///path
    /sys/kernel/debug/thunderbolt///counters
    ...

    The "regs" is either the router or port configuration space register
    dump. The "path" is the port path configuration space and "counters" is
    the optional counters configuration space.

    These files contains one register per line so it should be easy to use
    normal filtering tools to find the registers of interest if needed.

    The router and adapter regs file becomes writable when
    CONFIG_USB4_DEBUGFS_WRITE is enabled (which is not supposed to be done
    in production systems) and in this case the developer can write "offset
    value" lines there to modify the hardware directly. For convenience this
    also supports the long format the read side produces (but ignores the
    additional fields). The counters file can be written even when
    CONFIG_USB4_DEBUGFS_WRITE is not enabled and it is only used to clear
    the counter values.

    Signed-off-by: Gil Fine
    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Gil Fine
     
  • This may be returned for example when accessing some of the vendor
    specific capabilities. It is not fatal by any means so instead of WARN()
    just log it as debug level. The caller gets error back anyway and is
    expected to handle it accordingly.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • This is needed to differentiate Tiger Lake from other controllers.

    Signed-off-by: Gil Fine
    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Gil Fine
     
  • This is needed to differentiate Ice Lake from other controllers.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • With USB4 there will be other vendors so make sure the current checks
    for different Intel controllers will not accidentally match those.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • This is useful if one needs to check if adapter (port) is the host
    interface (NHI). Make tb_port_alloc_hopid() take advantage of this.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • This is similar to tb_port_next_cap() but instead allows walking
    capability list of a switch (router). Convert tb_switch_find_cap() and
    tb_switch_find_vse_cap() to use this as well.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • This function is useful for walking port config space (adapter)
    capability lists. Convert the tb_port_find_cap() to use this as well.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • This structure will be needed by the debugfs implementation so make it
    available outside of cap.c.

    While there add kernel-doc comments to the structure.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • This adds runtime PM support for the Software Connection Manager parts
    of the driver. This allows to save power when either there is no device
    attached at all or there is a device attached and all following
    conditions are true:

    - Tunneled PCIe root/downstream ports are runtime suspended
    - Tunneled USB3 ports are runtime suspended
    - No active DisplayPort stream
    - No active XDomain connection

    For the first two we take advantage of device links that were added in
    previous patch. Difference for the system sleep case is that we also
    enable wakes when something is geting plugged in/out of the Thunderbolt
    ports.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • The new way to describe relationship between tunneled ports and USB4 NHI
    (Native Host Interface) is with ACPI _DSD looking like below for a PCIe
    downstream port:

    Scope (\_SB.PCI0)
    {
    Device (NHI0) { } // Thunderbolt NHI

    Device (DSB0) // Hotplug downstream port
    {
    Name (_DSD, Package () {
    ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
    Package () {
    Package () {"usb4-host-interface", \_SB.PCI0.NHI0},
    ...
    }
    })
    }
    }

    This is "documented" in these [1] USB-IF slides and being used on
    systems that ship with Windows.

    The _DSD can be added to tunneled USB3 and PCIe ports, and is needed to
    make sure the USB4 NHI is resumed before any of the tunneled ports so
    the protocol tunnels get established properly before the actual port
    itself is resumed. Othwerwise the USB/PCI core find the link may not be
    established and starts tearing down the device stack.

    This parses the ACPI description each time NHI is probed and tries to
    find devices that has the property and it references the NHI in
    question. For each matching device a device link from that device to the
    NHI is created.

    Since USB3 ports themselves do not get runtime suspended with the parent
    device (hub) we do not add the link from the USB3 port to USB4 NHI but
    instead we add the link from the xHCI device. This makes the device link
    usable for runtime PM as well.

    [1] https://www.usb.org/sites/default/files/D1T2-2%20-%20USB4%20on%20Windows.pdf

    Signed-off-by: Mika Westerberg
    Acked-by: Rafael J. Wysocki

    Mika Westerberg
     
  • On older Apple systems there is currently a PCI quirk in place to block
    resume of tunneled PCIe ports until NHI (Thunderbolt controller) is
    resumed. This makes sure the PCIe tunnels are re-established before PCI
    core notices it.

    With device links the same thing can be done without quirks. The driver
    core will make sure the supplier (NHI) is resumed before consumers (PCIe
    downstream ports).

    For this reason switch the Thunderbolt driver to use device links and
    remove the PCI quirk.

    Signed-off-by: Mika Westerberg
    Acked-by: Bjorn Helgaas

    Mika Westerberg
     
  • In order for the router and the whole domain to wake up from system
    suspend states we need to enable wakes for the connected routers. For
    device routers we enable wakes from PCIe and USB 3.x. This allows
    devices such as keyboards connected to USB 3.x hub that is tunneled to
    wake the system up as expected. For all routers we enabled wake on USB4
    for each connected ports. This is used to propagate the wake from router
    to another.

    Do the same for legacy routers through link controller vendor specific
    registers as documented in USB4 spec chapter 13.

    While there correct kernel-doc of usb4_switch_set_sleep() -- it does not
    enable wakes instead there is a separate function (usb4_switch_set_wake())
    that does.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • USB4 spec mandates that the lane 1 should be disabled if lanes are not
    bonded. For host-to-host connections (XDomain) we don't support lane
    bonding so in order to be compatible with the spec, disable lane 1 when
    another host is connected.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • When the port is connected to another host it should be marked as such
    in the USB4 port capability. This information is used by the router
    during sleep and wakeup.

    Also do the same for legacy switches via link controller vendor specific
    registers.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Both ends of the link needs to have this set. Otherwise the link is not
    re-established properly after sleep. Now since it is possible to have
    mixed USB4 and Thunderbolt 1, 2 and 3 devices we need to split the link
    configuration functionality to happen per port so we can pick the
    correct implementation.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • During testing it was noticed that the link is not properly restored
    after the domain exits sleep if the link configured bits are set before
    lane bonding is enabled. The USB4 spec does not say in which order these
    need to be set but setting link configured afterwards makes the link
    restoration work so we do that instead.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Some early stage USB4 devices do not like that any of the enumerating
    router config space fields (ROUTER_CS_1 - ROUTER_CS_4) are written after
    the initial enumeration for example when entering sleep states. The
    default timeout by the USB4 spec is 10 ms which should be fine for the
    driver to handle.

    For this reason do not change the notification timeout from the default
    10 ms for USB4 routers.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • The TMU will be reset after router exits sleep so in order to
    re-configure it upon resume make sure the structure is initialized again
    based on the current hardware state.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • DP tunnels do not need the same kind of treatment as others because they
    are created based on hot-plug events on DP adapter ports, and the
    display stack does not need the tunnels to be enabled when resuming from
    suspend. Also Tiger Lake Thunderbolt controller sends unplug event on D3
    exit so this avoids that as well.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • First generation routers may need the reset command upon resume but it
    is not supported by newer generations.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • The function already logs an error if it fails so get rid of the
    duplication.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • USB4 spec says that NFC buffers field is not used for protocol adapters,
    only for lane adapters so make tb_port_add_nfc_credits() skip non-lane
    adapters in order to follow the spec.

    Signed-off-by: Mika Westerberg

    Mika Westerberg