17 Dec, 2018

1 commit

  • [ Upstream commit 1830b6eeda1fed42d85f2388f79c926331a9b2d0 ]

    During NVM upgrade process the host router is hot-removed for a short
    while. During this time it is possible that the root port is moved into
    D3cold which would be fine if the root port could trigger PME on itself.
    However, many systems actually do not implement it so what happens is
    that the root port goes into D3cold and never wakes up unless userspace
    does PCI config space access, such as running 'lscpi'.

    For this reason we explicitly prevent the root port from runtime
    suspending during NVM upgrade.

    Signed-off-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin

    Mika Westerberg
     

03 Oct, 2018

2 commits

  • If IOMMU is enabled and Thunderbolt driver is built into the kernel
    image, it will be probed before IOMMUs are attached to the PCI bus.
    Because of this DMA mappings the driver does will not go through IOMMU
    and start failing right after IOMMUs are enabled.

    For this reason move the Thunderbolt driver initialization happen at
    rootfs level.

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

    Mika Westerberg
     
  • If there is a long chain of devices connected when the driver is loaded
    ICM sends device connected event for each and those are put to tb->wq
    for later processing. Now if the driver gets unloaded in the middle, so
    that the work queue is not yet empty it gets flushed by tb_domain_stop().
    However, by that time the root switch is already removed so the driver
    crashes when it tries to dereference it in ICM event handling callbacks.

    Fix this by checking whether the root switch is already removed. If it
    is we know that the domain is stopped and we should merely skip handling
    the event.

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

    Mika Westerberg
     

25 Jul, 2018

7 commits

  • When Thunderbolt host controller is set to RTD3 mode (Runtime D3) it is
    present all the time. Because of this it is important to runtime suspend
    the controller whenever possible. In case of ICM we have following rules
    which all needs to be true before the host controller can be put to D3:

    - The controller firmware reports to support RTD3
    - All the connected devices announce support for RTD3
    - There is no active XDomain connection

    Implement this using standard Linux runtime PM APIs so that when all the
    children devices are runtime suspended, the Thunderbolt host controller
    PCI device is runtime suspended as well. The ICM firmware then starts
    powering down power domains towards RTD3 but it can prevent this if it
    detects that there is an active Display Port stream (this is not visible
    to the software, though).

    The Thunderbolt host controller will be runtime resumed either when
    there is a remote wake event (device is connected or disconnected), or
    when there is access from userspace that requires hardware access.

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

    Mika Westerberg
     
  • Variable 'approved' is being assigned but is never used hence it is
    redundant and can be removed.

    Cleans up clang warning:
    warning: variable 'approved' set but not used [-Wunused-but-set-variable]

    Signed-off-by: Colin Ian King
    Signed-off-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman

    Colin Ian King
     
  • The correct way to put the ICM into suspend state is to send it
    NHI_MAILBOX_DRV_UNLOADS mailbox command. NHI_MAILBOX_SAVE_DEVS is not
    needed on Intel Titan Ridge so we can skip it.

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

    Mika Westerberg
     
  • If the connection manager implementation needs to touch the domain
    structures it ought to take the lock itself. Currently only ICM
    implements these hooks and it does not need the lock because we there
    will be no notifications before driver ready message is sent to it.

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

    Mika Westerberg
     
  • This command is not really fast and can make resume time slower. We only
    need to get route again if the link was changed and during initial
    device connected message.

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

    Mika Westerberg
     
  • PCI defaults to 32-bit DMA mask but this device is capable of full
    64-bit addressing, so make sure we first try 64-bit DMA mask before
    falling back to the default 32-bit.

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

    Mika Westerberg
     
  • Fixes small variable name typo and the associated
    checkpatch spelling warning.

    Signed-off-by: Nathan Ciobanu
    Signed-off-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman

    Nathan Ciobanu
     

07 Jul, 2018

1 commit

  • The commit 9aaa3b8b4c56 ("thunderbolt: Add support for preboot ACL")
    introduced boot_acl attribute but missed the fact that now userspace
    needs to poll the attribute constantly to find out whether it has
    changed or not. Fix this by sending notification to the userspace
    whenever the boot_acl attribute is changed.

    Fixes: 9aaa3b8b4c56 ("thunderbolt: Add support for preboot ACL")
    Reported-and-tested-by: Christian Kellner
    Signed-off-by: Mika Westerberg
    Reviewed-by: Christian Kellner
    Acked-by: Yehezkel Bernat
    Cc: stable@vger.kernel.org
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     

16 May, 2018

1 commit

  • If the boot ACL entry is already NULL we should not fill in the upper
    two DWs with 0xfffffffff. Otherwise they are not shown as empty entries
    when the sysfs attribute is read.

    Fixes: 9aaa3b8b4c56 ("thunderbolt: Add support for preboot ACL")
    Signed-off-by: Mika Westerberg
    Acked-by: Yehezkel Bernat
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     

14 Mar, 2018

1 commit

  • On Lenovo ThinkPad Yoga 370 (and possibly some other Lenovo models as
    well) the Thunderbolt host controller sometimes comes up in such way
    that the ICM firmware is not running properly. This is most likely an
    issue in BIOS/firmware but as side-effect driver crashes the kernel due
    to NULL pointer dereference:

    BUG: unable to handle kernel NULL pointer dereference at 0000000000000980
    IP: pci_write_config_dword+0x5/0x20
    Call Trace:
    pcie2cio_write+0x3b/0x70 [thunderbolt]
    icm_driver_ready+0x168/0x260 [thunderbolt]
    ? tb_ctl_start+0x50/0x70 [thunderbolt]
    tb_domain_add+0x73/0xf0 [thunderbolt]
    nhi_probe+0x182/0x300 [thunderbolt]
    local_pci_probe+0x42/0xa0
    ? pci_match_device+0xd9/0x100
    pci_device_probe+0x146/0x1b0
    driver_probe_device+0x315/0x480
    ...

    Instead of crashing update the driver to bail out gracefully if we
    encounter such situation.

    Fixes: f67cf491175a ("thunderbolt: Add support for Internal Connection Manager (ICM)")
    Reported-by: Jordan Glover
    Signed-off-by: Mika Westerberg
    Acked-by: Yehezkel Bernat
    Cc: stable@vger.kernel.org

    Mika Westerberg
     

09 Mar, 2018

18 commits

  • Intel Titan Ridge is the next Thunderbolt 3 controller. The ICM firmware
    message format in Titan Ridge differs from Falcon Ridge and Alpine Ridge
    somewhat because it is using route strings addressing devices. In
    addition to that the DMA port of 4-channel (two port) controller is in
    different port number than the previous controllers. There are some
    other minor differences as well.

    This patch add support for Intel Titan Ridge and the new ICM firmware
    message format.

    Signed-off-by: Radion Mirchevsky
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Radion Mirchevsky
     
  • This new security level works so that it creates one PCIe tunnel to the
    connected Thunderbolt dock, removing PCIe links downstream of the dock.
    This leaves only the internal USB controller visible.

    Display Port tunnels are created normally.

    While there make sure security sysfs attribute returns "unknown" for any
    future security level.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • Preboot ACL is a mechanism that allows connecting Thunderbolt devices
    boot time in more secure way than the legacy Thunderbolt boot support.
    As with the legacy boot option, this also needs to be enabled from the
    BIOS before booting is allowed. Difference to the legacy mode is that
    the userspace software explicitly adds device UUIDs by sending a special
    message to the ICM firmware. Only the devices listed in the boot ACL are
    connected automatically during the boot. This works in both "user" and
    "secure" security levels.

    We implement this in Linux by exposing a new sysfs attribute (boot_acl)
    below each Thunderbolt domain. The userspace software can then update
    the full list as needed.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • In various cases, Thunderbolt device can be connected by ICM on boot
    without waiting for approval from user. Most cases are related to
    OEM-specific BIOS configurations. This information is interesting for
    user-space as if the device isn't in SW ACL, it may create a friction in
    the user experience where the device is automatically authorized if it's
    connected on boot but requires an explicit user action if connected
    after OS is up. User-space can use this information to suggest adding
    the device to SW ACL for auto-authorization on later connections.

    Signed-off-by: Yehezkel Bernat
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Yehezkel Bernat
     
  • Intel Titan Ridge uses slightly different format for ICM driver ready
    response, so add a new ->driver_ready() callback to struct icm and move
    the existing handling to a separate function which we then use in Falcon
    Ridge and Alpine Ridge.

    No functional changes intended.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • We will be using this from Titan Ridge support code as well so make it
    constant.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • This is needed by the new ICM interface to find xdomains by route string
    instead of link and depth.

    While there update existing tb_xdomain_find_* functions to use
    tb_xdomain_get() instead of open-coding the same.

    Signed-off-by: Radion Mirchevsky
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Radion Mirchevsky
     
  • With the new ICM messaging there is need for find switch by route string
    instead of link and depth. Add new function that makes it possible.

    Signed-off-by: Radion Mirchevsky
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Radion Mirchevsky
     
  • Sometimes there is need for increasing reference count of a switch as
    well. This also follows what we have for xdomains.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • Use correct name in kernel-doc of tb_switch_find_by_uuid().

    Signed-off-by: Radion Mirchevsky
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Radion Mirchevsky
     
  • The newer ICM will not use link and depth to address devices. Instead it
    uses route strings. In order to take advantage of the existing code
    factor out common operations so that we can use the same functions with
    the new ICM as well.

    No functional changes intended.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • The ICM firmware rejects devices if the maximum topology limit is
    exceeded (more than 6 devices are connected). If that happens just log a
    message to the kernel message buffer and bail out.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • Sometimes during cold boot ICM has not yet authenticated the active NVM
    image leading to timeout and failing the driver probe. Allow ICM to take
    some more time and increase the timeout to 3 seconds before we give up.

    While there fix icm_firmware_init() to return the real error code
    without overwriting it with -ENODEV.

    Fixes: f67cf491175a ("thunderbolt: Add support for Internal Connection Manager (ICM)")
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko
    Cc: stable@vger.kernel.org

    Mika Westerberg
     
  • In some case reading root switch config space takes longer than what we
    are currently waiting in the driver resulting timeout and failure.
    Increase number of retries to allow some more time for the root switch
    config space to become accesssible.

    Also log an error if the timeout is exceeded so we know why the driver
    probe failed.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • If the Thunderbolt domain adding fails for some reason we currently
    always return -EIO instead of the real error code. To make debugging
    easier return the actual error code instead.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko

    Mika Westerberg
     
  • If the system is suspended and user disconnects cable to another host
    and connects it to a Thunderbolt device instead we get a warning from
    driver core about adding duplicate sysfs attribute and adding the new
    device fails.

    Handle this properly so that we first remove the existing XDomain
    connection before adding new devices.

    Fixes: d1ff70241a27 ("thunderbolt: Add support for XDomain discovery protocol")
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko
    Cc: stable@vger.kernel.org

    Mika Westerberg
     
  • We need to make sure a new PCIe tunnel is not created in a middle of
    previous PCI rescan because otherwise the rescan code might find too
    much and fail to reconfigure devices properly. This is important when
    native PCIe hotplug is used. In BIOS assisted hotplug there should be no
    such issue.

    Fixes: f67cf491175a ("thunderbolt: Add support for Internal Connection Manager (ICM)")
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko
    Cc: Bjorn Helgaas
    Cc: stable@vger.kernel.org

    Mika Westerberg
     
  • The driver misses implementation of PM hook that undoes what
    ->freeze_noirq() does after the hibernation image is created. This means
    the control channel is not resumed properly and the Thunderbolt bus
    becomes useless in later stages of hibernation (when the image is stored
    or if the operation fails).

    Fix this by pointing ->thaw_noirq to driver nhi_resume_noirq(). This
    makes sure the control channel is resumed properly.

    Fixes: 23dd5bb49d98 ("thunderbolt: Add suspend/hibernate support")
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko
    Cc: stable@vger.kernel.org

    Mika Westerberg
     

16 Dec, 2017

1 commit

  • When ring enters polling mode we are expected to mask the ring interrupt
    before the callback is called. However, the current code actually
    unmasks it probably because of a copy-paste mistake.

    Mask the interrupt properly from now on.

    Fixes: 4ffe722eefcb ("thunderbolt: Add polling mode for rings")
    Signed-off-by: Mika Westerberg
    Acked-by: Yehezkel Bernat
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     

17 Nov, 2017

1 commit

  • …/git/gregkh/char-misc

    Pull char/misc updates from Greg KH:
    "Here is the big set of char/misc and other driver subsystem patches
    for 4.15-rc1.

    There are small changes all over here, hyperv driver updates, pcmcia
    driver updates, w1 driver updats, vme driver updates, nvmem driver
    updates, and lots of other little one-off driver updates as well. The
    shortlog has the full details.

    All of these have been in linux-next for quite a while with no
    reported issues"

    * tag 'char-misc-4.15-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (90 commits)
    VME: Return -EBUSY when DMA list in use
    w1: keep balance of mutex locks and refcnts
    MAINTAINERS: Update VME subsystem tree.
    nvmem: sunxi-sid: add support for A64/H5's SID controller
    nvmem: imx-ocotp: Update module description
    nvmem: imx-ocotp: Enable i.MX7D OTP write support
    nvmem: imx-ocotp: Add i.MX7D timing write clock setup support
    nvmem: imx-ocotp: Move i.MX6 write clock setup to dedicated function
    nvmem: imx-ocotp: Add support for banked OTP addressing
    nvmem: imx-ocotp: Pass parameters via a struct
    nvmem: imx-ocotp: Restrict OTP write to IMX6 processors
    nvmem: uniphier: add UniPhier eFuse driver
    dt-bindings: nvmem: add description for UniPhier eFuse
    nvmem: set nvmem->owner to nvmem->dev->driver->owner if unset
    nvmem: qfprom: fix different address space warnings of sparse
    nvmem: mtk-efuse: fix different address space warnings of sparse
    nvmem: mtk-efuse: use stack for nvmem_config instead of malloc'ing it
    nvmem: imx-iim: use stack for nvmem_config instead of malloc'ing it
    thunderbolt: tb: fix use after free in tb_activate_pcie_devices
    MAINTAINERS: Add git tree for Thunderbolt development
    ...

    Linus Torvalds
     

07 Nov, 2017

1 commit


04 Nov, 2017

1 commit


02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

27 Oct, 2017

1 commit

  • Commit 9a03c3d398c1 ("thunderbolt: Fix a couple right shifting to zero
    bugs") revealed an issue that was previously hidden because we never
    actually compared received XDomain message sequence numbers properly.
    The idea with these sequence numbers is that the responding host uses
    the same sequence number that was in the request packet which we can
    then check at the requesting host.

    However, testing against macOS it looks like it does not follow this but
    instead uses some other logic. Windows driver on the other hand handles
    it the same way than Linux.

    In order to be able to talk to macOS again, fix this so that we drop the
    whole sequence number check. This effectively works exactly the same
    than it worked before the aforementioned commit. This also follows the
    logic the original P2P networking code used.

    Signed-off-by: Mika Westerberg
    Signed-off-by: David S. Miller

    Mika Westerberg
     

19 Oct, 2017

1 commit

  • The problematic code looks like this:

    res_seq = res_hdr->xd_hdr.length_sn & TB_XDOMAIN_SN_MASK;
    res_seq >>= TB_XDOMAIN_SN_SHIFT;

    TB_XDOMAIN_SN_SHIFT is 27, and right shifting a u8 27 bits is always
    going to result in zero. The fix is to declare these variables as u32.

    Fixes: d1ff70241a27 ("thunderbolt: Add support for XDomain discovery protocol")
    Signed-off-by: Dan Carpenter
    Signed-off-by: David S. Miller

    Dan Carpenter
     

10 Oct, 2017

1 commit

  • The 0day kbuild robot reports following crash:

    BUG: unable to handle kernel NULL pointer dereference at 00000004
    IP: tb_property_find+0xe/0x41
    *pde = 00000000
    Oops: 0000 [#1]
    CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.0-rc1-00741-ge69b6c0 #412
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014
    task: 89c80000 task.stack: 89c7c000
    EIP: tb_property_find+0xe/0x41
    EFLAGS: 00210246 CPU: 0
    EAX: 00000000 EBX: 7a368f47 ECX: 00000044 EDX: 7a368f47
    ESI: 8851d340 EDI: 7a368f47 EBP: 89c7df0c ESP: 89c7defc
    DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068
    CR0: 80050033 CR2: 00000004 CR3: 027a2000 CR4: 00000690
    Call Trace:
    tb_register_property_dir+0x49/0xb9
    ? cdc_mbim_driver_init+0x1b/0x1b
    tbnet_init+0x77/0x9f
    ? cdc_mbim_driver_init+0x1b/0x1b
    do_one_initcall+0x7e/0x145
    ? parse_args+0x10c/0x1b3
    ? kernel_init_freeable+0xbe/0x159
    kernel_init_freeable+0xd1/0x159
    ? rest_init+0x110/0x110
    kernel_init+0xd/0xd0
    ret_from_fork+0x19/0x30

    The reason is that both Thunderbolt bus and thunderbolt-net are build
    into the kernel image, and the latter is linked first because
    drivers/net comes before drivers/thunderbolt. Since both use
    module_init() thunderbolt-net ends up calling Thunderbolt bus functions
    too early triggering the above crash.

    Fix this by moving Thunderbolt bus initialization to happen earlier to
    make sure all the data structures are ready when Thunderbolt service
    drivers are initialized. To be on the safe side also add a check for
    properly initialized xdomain_property_dir to tb_register_property_dir().

    Reported-by: kernel test robot
    Signed-off-by: Mika Westerberg
    Signed-off-by: David S. Miller

    Mika Westerberg
     

03 Oct, 2017

1 commit

  • Thunderbolt services should not care which HopID (ring) they use for
    sending and receiving packets over the high-speed DMA path, so make
    tb_ring_alloc_rx() and tb_ring_alloc_tx() accept negative HopID. This
    means that the NHI will allocate next available HopID for the caller
    automatically.

    These HopIDs will be allocated from the range which is not reserved for
    the Thunderbolt protocol (8 .. hop_count - 1).

    The allocated HopID can be retrieved from ring->hop field after the ring
    has been allocated successfully if needed.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Michael Jamet
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Andy Shevchenko
    Signed-off-by: David S. Miller

    Mika Westerberg