24 Apr, 2018

4 commits

  • commit ea9d7bb798900096f26c585957d6ad9c532417e6 upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • commit f2a659f7d8d5da803836583aa16df06bdf324252 upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • commit a03e828915c00ed0ea5aa40647c81472cfa7a984 upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • commit e4be8c9b6a512e274cb6bbac4ac869d73880a8b3 upstream.

    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
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     

20 Dec, 2017

1 commit

  • [ Upstream commit a2e373438f72391493a4425efc1b82030b6b4fd5 ]

    Add a ̣̣continue statement in order to avoid using a previously
    free'd pointer tunnel in list_add.

    Addresses-Coverity-ID: 1415336
    Fixes: 9d3cce0b6136 ("thunderbolt: Introduce thunderbolt bus and connection manager")
    Signed-off-by: Gustavo A. R. Silva
    Acked-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin
    Signed-off-by: Greg Kroah-Hartman

    Gustavo A. R. Silva
     

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
     

06 Sep, 2017

1 commit

  • Pull ACPI updates from Rafael Wysocki:
    "These include a usual ACPICA code update (this time to upstream
    revision 20170728), a fix for a boot crash on some systems with
    Thunderbolt devices connected at boot time, a rework of the handling
    of PCI bridges when setting up device wakeup, new support for Apple
    device properties, support for DMA configurations reported via ACPI on
    ARM64, APEI-related updates, ACPI EC driver updates and assorted minor
    modifications in several places.

    Specifics:

    - Update the ACPICA code in the kernel to upstream revision 20170728
    including:
    * Alias operator handling update (Bob Moore).
    * Deferred resolution of reference package elements (Bob Moore).
    * Support for the _DMA method in walk resources (Bob Moore).
    * Tables handling update and support for deferred table
    verification (Lv Zheng).
    * Update of SMMU models for IORT (Robin Murphy).
    * Compiler and disassembler updates (Alex James, Erik Schmauss,
    Ganapatrao Kulkarni, James Morse).
    * Tools updates (Erik Schmauss, Lv Zheng).
    * Assorted minor fixes and cleanups (Bob Moore, Kees Cook, Lv
    Zheng, Shao Ming).

    - Rework the initialization of non-wakeup GPEs with method handlers
    in order to address a boot crash on some systems with Thunderbolt
    devices connected at boot time where we miss an early hotplug event
    due to a delay in GPE enabling (Rafael Wysocki).

    - Rework the handling of PCI bridges when setting up ACPI-based
    device wakeup in order to avoid disabling wakeup for bridges
    prematurely (Rafael Wysocki).

    - Consolidate Apple DMI checks throughout the tree, add support for
    Apple device properties to the device properties framework and use
    these properties for the handling of I2C and SPI devices on Apple
    systems (Lukas Wunner).

    - Add support for _DMA to the ACPI-based device properties lookup
    code and make it possible to use the information from there to
    configure DMA regions on ARM64 systems (Lorenzo Pieralisi).

    - Fix several issues in the APEI code, add support for exporting the
    BERT error region over sysfs and update APEI MAINTAINERS entry with
    reviewers information (Borislav Petkov, Dongjiu Geng, Loc Ho, Punit
    Agrawal, Tony Luck, Yazen Ghannam).

    - Fix a potential initialization ordering issue in the ACPI EC driver
    and clean it up somewhat (Lv Zheng).

    - Update the ACPI SPCR driver to extend the existing XGENE 8250
    workaround in it to a new platform (m400) and to work around an
    Xgene UART clock issue (Graeme Gregory).

    - Add a new utility function to the ACPI core to support using ACPI
    OEM ID / OEM Table ID / Revision for system identification in
    blacklisting or similar and switch over the existing code already
    using this information to this new interface (Toshi Kani).

    - Fix an xpower PMIC issue related to GPADC reads that always return
    0 without extra pin manipulations (Hans de Goede).

    - Add statements to print debug messages in a couple of places in the
    ACPI core for easier diagnostics (Rafael Wysocki).

    - Clean up the ACPI processor driver slightly (Colin Ian King, Hanjun
    Guo).

    - Clean up the ACPI x86 boot code somewhat (Andy Shevchenko).

    - Add a quirk for Dell OptiPlex 9020M to the ACPI backlight driver
    (Alex Hung).

    - Assorted fixes, cleanups and updates related to ACPI (Amitoj Kaur
    Chawla, Bhumika Goyal, Frank Rowand, Jean Delvare, Punit Agrawal,
    Ronald Tschalär, Sumeet Pawnikar)"

    * tag 'acpi-4.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (75 commits)
    ACPI / APEI: Suppress message if HEST not present
    intel_pstate: convert to use acpi_match_platform_list()
    ACPI / blacklist: add acpi_match_platform_list()
    ACPI, APEI, EINJ: Subtract any matching Register Region from Trigger resources
    ACPI: make device_attribute const
    ACPI / sysfs: Extend ACPI sysfs to provide access to boot error region
    ACPI: APEI: fix the wrong iteration of generic error status block
    ACPI / processor: make function acpi_processor_check_duplicates() static
    ACPI / EC: Clean up EC GPE mask flag
    ACPI: EC: Fix possible issues related to EC initialization order
    ACPI / PM: Add debug statements to acpi_pm_notify_handler()
    ACPI: Add debug statements to acpi_global_event_handler()
    ACPI / scan: Enable GPEs before scanning the namespace
    ACPICA: Make it possible to enable runtime GPEs earlier
    ACPICA: Dispatch active GPEs at init time
    ACPI: SPCR: work around clock issue on xgene UART
    ACPI: SPCR: extend XGENE 8250 workaround to m400
    ACPI / LPSS: Don't abort ACPI scan on missing mem resource
    mailbox: pcc: Drop uninformative output during boot
    ACPI/IORT: Add IORT named component memory address limits
    ...

    Linus Torvalds
     

04 Sep, 2017

1 commit

  • * acpi-x86:
    ACPI / boot: Add number of legacy IRQs to debug output
    ACPI / boot: Correct address space of __acpi_map_table()
    ACPI / boot: Don't define unused variables

    * acpi-soc:
    ACPI / LPSS: Don't abort ACPI scan on missing mem resource

    * acpi-pmic:
    ACPI / PMIC: xpower: Do pinswitch magic when reading GPADC

    * acpi-apple:
    spi: Use Apple device properties in absence of ACPI resources
    ACPI / scan: Recognize Apple SPI and I2C slaves
    ACPI / property: Support Apple _DSM properties
    ACPI / property: Don't evaluate objects for devices w/o handle
    treewide: Consolidate Apple DMI checks

    Rafael J. Wysocki
     

28 Aug, 2017

4 commits

  • There is a mistake here where we accidentally use sizeof(TB_CFG_PKG_RESET)
    instead of just TB_CFG_PKG_RESET. The size of an int is 4 so it's the
    same as TB_CFG_PKG_NOTIFY_ACK.

    Fixes: d7f781bfdbf4 ("thunderbolt: Rework control channel to be more reliable")
    Reported-by: Colin King
    Signed-off-by: Dan Carpenter
    Acked-by: Mika Westerberg
    Cc: stable # 4.13
    Signed-off-by: Greg Kroah-Hartman

    Dan Carpenter
     
  • If secure authentication of a devices fails, either because the device
    already has another key uploaded, or there is some other error sending
    challenge to the device, and the user only wants to approve the device
    just once (without a new key being uploaded to the device) the current
    implementation does not allow this because the key cannot be cleared
    once set even if we allow it to be changed.

    Make this scenario possible and allow clearing the key by writing
    empty string to the key sysfs file.

    Signed-off-by: Yehezkel Bernat
    Acked-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman

    Bernat, Yehezkel
     
  • Non-root user may read the key back after root wrote it there.
    This removes read access to everyone but root.

    Signed-off-by: Yehezkel Bernat
    Acked-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman

    Bernat, Yehezkel
     
  • The key size is tested by hex2bin() already (as '\0' isn't an hex digit)

    Suggested-by: Andy Shevchenko
    Signed-off-by: Yehezkel Bernat
    Acked-by: Mika Westerberg
    Signed-off-by: Greg Kroah-Hartman

    Bernat, Yehezkel
     

14 Aug, 2017

1 commit


11 Aug, 2017

1 commit

  • Some Alpine Ridge LP DROMs (there might be others) erroneusly list more
    ports than the controller actually has. Most probably because DROM of
    the full Dual/Single port Thunderbolt controller was reused for LP
    version. The current DROM parser does not check the upper bound thus it
    leads to crash when sw->ports[] is accessed over bounds:

    BUG: unable to handle kernel NULL pointer dereference at 00000000000002ec
    IP: tb_drom_read+0x383/0x890 [thunderbolt]
    PGD 0
    P4D 0
    Oops: 0000 [#1] SMP
    CPU: 3 PID: 12248 Comm: systemd-udevd Not tainted 4.13.0-rc1-next-20170719 #1
    Hardware name: LENOVO 20HF000YGE/20HF000YGE, BIOS N1WET32W (1.11 ) 05/23/2017
    task: ffff8a293e4bcd80 task.stack: ffffa698027a8000
    RIP: 0010:tb_drom_read+0x383/0x890 [thunderbolt]
    RSP: 0018:ffffa698027ab990 EFLAGS: 00010246
    RAX: 0000000000000000 RBX: ffff8a2940af7800 RCX: 0000000000000000
    RDX: ffff8a2940ebb400 RSI: 0000000000000000 RDI: ffffa698027ab9a0
    RBP: ffffa698027ab9d0 R08: 0000000000000001 R09: 0000000000000002
    R10: ffff8a2940ebb5b0 R11: 0000000000000000 R12: ffff8a293bfa968c
    R13: 000000000000002c R14: 0000000000000056 R15: 0000000000000056
    FS: 00007f0a945a38c0(0000) GS:ffff8a2961580000(0000) knlGS:0000000000000000
    CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000000002ec CR3: 000000043e785000 CR4: 00000000003606e0
    DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
    DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
    Call Trace:
    tb_switch_add+0x9d/0x730 [thunderbolt]
    ? tb_switch_alloc+0x3cd/0x4d0 [thunderbolt]
    icm_start+0x5a/0xa0 [thunderbolt]
    tb_domain_add+0xc3/0xf0 [thunderbolt]
    nhi_probe+0x19e/0x310 [thunderbolt]
    local_pci_probe+0x42/0xa0
    pci_device_probe+0x18d/0x1a0
    driver_probe_device+0x2ff/0x450
    __driver_attach+0xa4/0xe0
    ? driver_probe_device+0x450/0x450
    bus_for_each_dev+0x6e/0xb0
    driver_attach+0x1e/0x20
    bus_add_driver+0x1d0/0x270
    ? 0xffffffffc0bbb000
    driver_register+0x60/0xe0
    ? 0xffffffffc0bbb000
    __pci_register_driver+0x4c/0x50
    nhi_init+0x28/0x1000 [thunderbolt]
    do_one_initcall+0x50/0x190
    ? __vunmap+0x81/0xb0
    ? _cond_resched+0x1a/0x50
    ? kmem_cache_alloc_trace+0x15f/0x1c0
    ? do_init_module+0x27/0x1e9
    do_init_module+0x5f/0x1e9
    load_module+0x24e7/0x2a60
    ? vfs_read+0x115/0x130
    SYSC_finit_module+0xfc/0x120
    ? SYSC_finit_module+0xfc/0x120
    SyS_finit_module+0xe/0x10
    do_syscall_64+0x67/0x170
    entry_SYSCALL64_slow_path+0x25/0x25

    Fix this by making sure we only enumerate DROM port entries the hardware
    actually has.

    Reported-by: Christian Kellner
    Signed-off-by: Mika Westerberg
    Reviewed-by: Lukas Wunner
    Tested-by: Christian Kellner
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     

04 Aug, 2017

2 commits

  • We're about to amend ACPI bus scan with DMI checks whether we're running
    on a Mac to support Apple device properties in AML. The DMI checks are
    performed for every single device, adding overhead for everything x86
    that isn't Apple, which is the majority. Rafael and Andy therefore
    request to perform the DMI match only once and cache the result.

    Outside of ACPI various other Apple DMI checks exist and it seems
    reasonable to use the cached value there as well. Rafael, Andy and
    Darren suggest performing the DMI check in arch code and making it
    available with a header in include/linux/platform_data/x86/.

    To this end, add early_platform_quirks() to arch/x86/kernel/quirks.c
    to perform the DMI check and invoke it from setup_arch(). Switch over
    all existing Apple DMI checks, thereby fixing two deficiencies:

    * They are now #defined to false on non-x86 arches and can thus be
    optimized away if they're located in cross-arch code.

    * Some of them only match "Apple Inc." but not "Apple Computer, Inc.",
    which is used by BIOSes released between January 2006 (when the first
    x86 Macs started shipping) and January 2007 (when the company name
    changed upon introduction of the iPhone).

    Suggested-by: Andy Shevchenko
    Suggested-by: Rafael J. Wysocki
    Suggested-by: Darren Hart
    Signed-off-by: Lukas Wunner
    Acked-by: Mika Westerberg
    Signed-off-by: Rafael J. Wysocki

    Lukas Wunner
     
  • * pm-core:
    PM / runtime: Document new pm_runtime_set_suspended() constraint

    * pm-misc:
    thunderbolt: icm: Ignore mailbox errors in icm_suspend()

    Rafael J. Wysocki
     

31 Jul, 2017

1 commit

  • On one of my test machines nhi_mailbox_cmd() called from icm_suspend()
    times out and returnes an error which then is propagated to the
    caller and causes the entire system suspend to be aborted which isn't
    very useful.

    Instead of aborting system suspend, print the error into the log
    and continue.

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

    Rafael J. Wysocki
     

26 Jul, 2017

1 commit


24 Jul, 2017

1 commit


17 Jul, 2017

1 commit

  • Firmware upgrade tools that decide which NVM image should be uploaded to
    the Thunderbolt controller need to access active parts of the NVM even
    if they are not run as root. The information in active NVM is not
    considered security critical so we can use the default permissions set
    by the NVMem framework.

    Writing the NVM image is still left as root only operation.

    While there mark the active NVM as read-only in the filesystem.

    Reported-by: Yehezkel Bernat
    Signed-off-by: Mika Westerberg
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     

09 Jun, 2017

20 commits

  • Trivial fix to spelling mistake in tb_sw_warn warning message

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

    Colin Ian King
     
  • Starting from Intel Falcon Ridge the NVM firmware can be upgraded by
    using DMA configuration based mailbox commands. If we detect that the
    host or device (device support starts from Intel Alpine Ridge) has the
    DMA configuration based mailbox we expose NVM information to the
    userspace as two separate Linux NVMem devices: nvm_active and
    nvm_non_active. The former is read-only portion of the active NVM which
    firmware upgrade tools can be use to find out suitable NVM image if the
    device identification strings are not enough.

    The latter is write-only portion where the new NVM image is to be
    written by the userspace. It is up to the userspace to find out right
    NVM image (the kernel does very minimal validation). The ICM firmware
    itself authenticates the new NVM firmware and fails the operation if it
    is not what is expected.

    We also expose two new sysfs files per each switch: nvm_version and
    nvm_authenticate which can be used to read the active NVM version and
    start the upgrade process.

    We also introduce safe mode which is the mode a switch goes when it does
    not have properly authenticated firmware. In this mode the switch only
    accepts a couple of commands including flashing a new NVM firmware image
    and triggering power cycle.

    This code is based on the work done by Amir Levy and Michael Jamet.

    Signed-off-by: Michael Jamet
    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Starting from Intel Falcon Ridge the internal connection manager running
    on the Thunderbolt host controller has been supporting 4 security
    levels. One reason for this is to prevent DMA attacks and only allow
    connecting devices the user trusts.

    The internal connection manager (ICM) is the preferred way of connecting
    Thunderbolt devices over software only implementation typically used on
    Macs. The driver communicates with ICM using special Thunderbolt ring 0
    (control channel) messages. In order to handle these messages we add
    support for the ICM messages to the control channel.

    The security levels are as follows:

    none - No security, all tunnels are created automatically
    user - User needs to approve the device before tunnels are created
    secure - User need to approve the device before tunnels are created.
    The device is sent a challenge on future connects to be able
    to verify it is actually the approved device.
    dponly - Only Display Port and USB tunnels can be created and those
    are created automatically.

    The security levels are typically configurable from the system BIOS and
    by default it is set to "user" on many systems.

    In this patch each Thunderbolt device will have either one or two new
    sysfs attributes: authorized and key. The latter appears for devices
    that support secure connect.

    In order to identify the device the user can read identication
    information, including UUID and name of the device from sysfs and based
    on that make a decision to authorize the device. The device is
    authorized by simply writing 1 to the "authorized" sysfs attribute. This
    is following the USB bus device authorization mechanism. The secure
    connect requires an additional challenge step (writing 2 to the
    "authorized" attribute) in future connects when the key has already been
    stored to the NVM of the device.

    Non-ICM systems (before Alpine Ridge) continue to use the existing
    functionality and the security level is set to none. For systems with
    Alpine Ridge, even on Apple hardware, we will use ICM.

    This code is based on the work done by Amir Levy and Michael Jamet.

    Signed-off-by: Michael Jamet
    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • On PCs the NHI host controller is only present when there is a device
    connected. When the last device is disconnected the host controller will
    dissappear shortly (within 10s). Now if that happens when we are
    suspended we should not try to touch the hardware anymore, so add a flag
    for this and check it before we re-enable rings.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • The DMA (NHI) port of a switch provides access to the NVM of the host
    controller (and devices starting from Intel Alpine Ridge). The NVM
    contains also more complete DROM for the root switch including vendor
    and device identification strings.

    This will look for the DMA port capability for each switch and if found
    populates sw->dma_port. We then teach tb_drom_read() to read the DROM
    information from NVM if available for the root switch.

    The DMA port capability also supports upgrading the NVM for both host
    controller and devices which will be added in subsequent patches.

    This code is based on the work done by Amir Levy and Michael Jamet.

    Signed-off-by: Michael Jamet
    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • In some cases it is useful to know what is the Thunderbolt generation
    the switch supports. This introduces a new field to struct switch that
    stores the generation of the switch based on the device ID. Unknown
    switches (there should be none) are assumed to be first generation to be
    on the safe side.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • The host controller includes two sets of registers that are used to
    communicate with the firmware. Add functions that can be used to access
    these registers.

    This code is based on the work done by Amir Levy and Michael Jamet.

    Signed-off-by: Michael Jamet
    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Add Intel Win Ridge (Thunderbolt 2) and Alpine Ridge (Thunderbolt 3)
    controller PCI IDs to the list of supported devices.

    This code is based on the work done by Amir Levy and Michael Jamet.

    Signed-off-by: Michael Jamet
    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • If a request times out the response might arrive right after the request
    is failed. This response is pushed to the kfifo and next request will
    read it instead. Since it most likely will not pass our validation
    checks in parse_header() the next request will fail as well, and
    response to that request will be pushed to the kfifo, ad infinitum.

    We end up in a situation where all requests fail and no devices can be
    added anymore until the driver is unloaded and reloaded again.

    To overcome this, rework the control channel so that we will have a
    queue of outstanding requests. Each request will be handled in turn and
    the response is validated against what is expected. Unexpected packets
    (for example responses for requests that have been timed out) are
    dropped. This model is copied from Greybus implementation with small
    changes here and there to get it cope with Thunderbolt control packets.

    In addition the configuration packets support sequence number which the
    switch is supposed to copy from the request to response. We use this to
    drop responses that are already timed out. Taking advantage of the
    sequence number, we automatically retry configuration read/write 4 times
    before giving up.

    Also timeout is not a programming error so there is no need to trigger a
    scary backtrace (WARN), instead we just log a warning. After all
    Thunderbolt devices are hot-pluggable by definition which means user can
    unplug a device any time and that is totally acceptable.

    With this change there is no need to take the global domain lock when
    sending configuration packets anymore. This is useful when we add
    support for cross-domain (XDomain) communication later on.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Currently the control channel (ctl.c) handles the one supported
    notification (PLUG_EVENT) and sends back ACK accordingly. However, we
    are going to add support for the internal connection manager (ICM) that
    needs to handle a different notifications. So instead of dealing
    everything in the control channel, we change the callback to take an
    arbitrary thunderbolt packet and convert the native connection manager
    to handle the event itself.

    In addition we only push replies we know of to the response FIFO.
    Everything else is treated as notification (or request) and is expected
    to be dealt by the connection manager implementation.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • We will be using this function in files introduced in subsequent
    patches. While there the function is renamed to tb_cfg_make_header()
    following tb_cfg_get_route().

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • We are going to use it when we change the connection manager to handle
    events itself. Also rename it to follow naming convention used in
    functions exposed in ctl.h.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • We will be forwarding notifications received from the control channel to
    the connection manager implementations. This way they can decide what to
    do if anything when a notification is received.

    To be able to use control channel messages from other files, move them
    to tb_msgs.h.

    No functional changes intended.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • The device DROM contains name of the vendor and device among other
    things. Extract this information and expose it to the userspace via two
    new attributes.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Currently tb_drom_parse_entry() is only able to parse drom entries of
    type TB_DROM_ENTRY_PORT. Rename it to tb_drom_parse_entry_port().
    Fold tb_drom_parse_port_entry() into it.

    Its return value is currently ignored. Evaluate it and abort parsing on
    error.

    Change tb_drom_parse_entries() to accommodate for parsing of other entry
    types than TB_DROM_ENTRY_PORT.

    Signed-off-by: Lukas Wunner
    Signed-off-by: Mika Westerberg
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Lukas Wunner
     
  • There are devices out there where CRC32 of the DROM is not correct. One
    reason for this is that the ICM firmware does not validate it and it
    seems that neither does the Apple driver. To be able to support such
    devices we continue parsing the DROM contents regardless of whether
    CRC32 failed or not. We still keep the warning there.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • All non-root switches are expected to have DROM so if the operation
    fails, it might be due the user unlugging the device. There is no point
    continuing adding the switch further in that case. Just bail out.

    For root switches (hosts) the DROM is either retrieved from a EFI
    variable, NVM or hard-coded.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Thunderbolt domain consists of switches that are connected to each
    other, forming a bus. This will convert each switch into a real Linux
    device structure and adds them to the domain. The advantage here is
    that we get all the goodies from the driver core, like reference
    counting and sysfs hierarchy for free.

    Also expose device identification information to the userspace via new
    sysfs attributes.

    In order to support internal connection manager (ICM) we separate switch
    configuration into its own function (tb_switch_configure()) which is
    only called by the existing native connection manager implementation
    used on Macs.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Thunderbolt fabric consists of one or more switches. This fabric is
    called domain and it is controlled by an entity called connection
    manager. The connection manager can be either internal (driven by a
    firmware running on the host controller) or external (software driver).
    This driver currently implements support for the latter.

    In order to manage switches and their properties more easily we model
    this domain structure as a Linux bus. Each host controller adds a domain
    device to this bus, and these devices are named as domainN where N
    stands for index or id of the current domain.

    We then abstract connection manager specific operations into a new
    structure tb_cm_ops and convert the existing tb.c to fill those
    accordingly. This makes it easier to add support for the internal
    connection manager in subsequent patches.

    Signed-off-by: Mika Westerberg
    Reviewed-by: Yehezkel Bernat
    Reviewed-by: Michael Jamet
    Reviewed-by: Andy Shevchenko
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg
     
  • Following the usual pattern used in many places, we allow passing NULL
    pointer to tb_ctl_free(). Then the user can call the function regardless
    if it has allocated control channel or not making the code bit simpler.

    Suggested-by: Andy Shevchenko
    Signed-off-by: Mika Westerberg
    Signed-off-by: Andreas Noever
    Signed-off-by: Greg Kroah-Hartman

    Mika Westerberg