08 May, 2019

1 commit

  • …/git/gregkh/char-misc

    Pull char/misc update part 2 from Greg KH:
    "Here is the "real" big set of char/misc driver patches for 5.2-rc1

    Loads of different driver subsystem stuff in here, all over the places:
    - thunderbolt driver updates
    - habanalabs driver updates
    - nvmem driver updates
    - extcon driver updates
    - intel_th driver updates
    - mei driver updates
    - coresight driver updates
    - soundwire driver cleanups and updates
    - fastrpc driver updates
    - other minor driver updates
    - chardev minor fixups

    Feels like this tree is getting to be a dumping ground of "small
    driver subsystems" these days. Which is fine with me, if it makes
    things easier for those subsystem maintainers.

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

    * tag 'char-misc-5.2-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (255 commits)
    intel_th: msu: Add current window tracking
    intel_th: msu: Add a sysfs attribute to trigger window switch
    intel_th: msu: Correct the block wrap detection
    intel_th: Add switch triggering support
    intel_th: gth: Factor out trace start/stop
    intel_th: msu: Factor out pipeline draining
    intel_th: msu: Switch over to scatterlist
    intel_th: msu: Replace open-coded list_{first,last,next}_entry variants
    intel_th: Only report useful IRQs to subdevices
    intel_th: msu: Start handling IRQs
    intel_th: pci: Use MSI interrupt signalling
    intel_th: Communicate IRQ via resource
    intel_th: Add "rtit" source device
    intel_th: Skip subdevices if their MMIO is missing
    intel_th: Rework resource passing between glue layers and core
    intel_th: SPDX-ify the documentation
    intel_th: msu: Fix single mode with IOMMU
    coresight: funnel: Support static funnel
    dt-bindings: arm: coresight: Unify funnel DT binding
    coresight: replicator: Add new device id for static replicator
    ...

    Linus Torvalds
     

25 Apr, 2019

2 commits

  • Clang warns:

    drivers/thunderbolt/tunnel.c:504:17: warning: implicit truncation from
    'int' to bit-field changes value from 5 to -3
    [-Wbitfield-constant-conversion]
    path->priority = 5;
    ^ ~
    1 warning generated.

    The priority member in struct tb_path is only ever assigned a positive
    number:

    $ rg -n priority drivers/thunderbolt/path.c
    drivers/thunderbolt/tunnel.c:99: path->priority = 3;
    drivers/thunderbolt/tunnel.c:308: path->priority = 2;
    drivers/thunderbolt/tunnel.c:323: path->priority = 1;
    drivers/thunderbolt/tunnel.c:504: path->priority = 5;

    Furthermore, that value is only assigned to an unsigned integer in
    tb_path_activate (the priority member in struct tb_regs_hop).

    Fixes: 44242d6c9703 ("thunderbolt: Add support for DMA tunnels")
    Link: https://github.com/ClangBuiltLinux/linux/issues/454
    Signed-off-by: Nathan Chancellor
    Reviewed-by: Nick Desaulniers
    Signed-off-by: Mika Westerberg

    Nathan Chancellor
     
  • The flags field in 'struct shash_desc' never actually does anything.
    The only ostensibly supported flag is CRYPTO_TFM_REQ_MAY_SLEEP.
    However, no shash algorithm ever sleeps, making this flag a no-op.

    With this being the case, inevitably some users who can't sleep wrongly
    pass MAY_SLEEP. These would all need to be fixed if any shash algorithm
    actually started sleeping. For example, the shash_ahash_*() functions,
    which wrap a shash algorithm with the ahash API, pass through MAY_SLEEP
    from the ahash API to the shash API. However, the shash functions are
    called under kmap_atomic(), so actually they're assumed to never sleep.

    Even if it turns out that some users do need preemption points while
    hashing large buffers, we could easily provide a helper function
    crypto_shash_update_large() which divides the data into smaller chunks
    and calls crypto_shash_update() and cond_resched() for each chunk. It's
    not necessary to have a flag in 'struct shash_desc', nor is it necessary
    to make individual shash algorithms aware of this at all.

    Therefore, remove shash_desc::flags, and document that the
    crypto_shash_*() functions can be called from any context.

    Signed-off-by: Eric Biggers
    Signed-off-by: Herbert Xu

    Eric Biggers
     

18 Apr, 2019

35 commits

  • Titan Ridge flow to start the firmware is the same as Alpine Ridge so we
    can do the same on Titan Ridge based Apple systems.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • While tb_dump_hop() prints out necessary information it is in format
    that is quite hard to read from the logs especially when one needs to
    follow the path to see that the setup is correct.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Now that the driver can handle every possible tunnel types there is no
    point to log everything as info level so turn these to happen at debug
    level instead.

    While at it remove duplicated tunnel activation log message
    (tb_tunnel_activate() calls tb_tunnel_restart() which print the same
    message) and add one missing '\n' termination.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • The printing macros do not modify the passed object so make them
    const. While there make tb_route() to take const parameter as well.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Two domains (hosts) can be connected through a Thunderbolt cable and in
    that case they can start software services such as networking over the
    high-speed DMA paths. Now that we have all the basic building blocks in
    place to create DMA tunnels over the Thunderbolt fabric we can add this
    support to the software connection manager as well.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • In order to detect possible connections to other domains we need to be
    able to find out why tb_switch_alloc() fails so make it return ERR_PTR()
    instead. This allows the caller to differentiate between errors such as
    -ENOMEM which comes from the kernel and for instance -EIO which comes
    from the hardware when trying to access the possible switch.

    Convert all the current call sites to handle this properly.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • In addition to PCIe and Display Port tunnels it is also possible to
    create tunnels that forward DMA traffic from the host interface adapter
    (NHI) to a NULL port that is connected to another domain through a
    Thunderbolt cable. These tunnels can be used to carry software messages
    such as networking packets.

    To support this we introduce another tunnel type (TB_TUNNEL_DMA) that
    supports paths from NHI to NULL port and back.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Currently ICM has been handling XDomain UUID exchange so there was no
    need to have it in the driver yet. However, since now we are going to
    add the same capabilities to the software connection manager it needs to
    be handled properly.

    For this reason modify the driver XDomain protocol handling so that if
    the remote domain UUID is not filled in the core will query it first and
    only then start the normal property exchange flow.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • We run all XDomain requests during discovery in tb->wq and since it only
    runs one work at the time it means that sending back reply to the other
    domain may be delayed too much depending whether there is an active
    XDomain discovery request running.

    To make sure we can send reply to the other domain as soon as possible
    run tb_xdp_handle_request() in system workqueue instead. Since the
    device can be hot-removed in the middle we need to make sure the domain
    structure is still around when the function is run so increase reference
    count before we schedule the reply work.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Now that we have capability to discover existing tunnels during driver
    load there is no point tearing down tunnels when the driver gets
    unloaded. Instead we can just leave them running. If user disconnects
    devices while there is no Thunderbolt driver loaded, tunneled protocol
    hotplug happens and is handled by the corresponding driver (pciehp in
    case of PCIe tunnel, GFX driver in case of DP tunnel).

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Display Port tunnels are somewhat more complex than PCIe tunnels as it
    requires 3 tunnels (AUX Rx/Tx and Video). In addition we are not
    supposed to create the tunnels immediately when a DP OUT is enumerated.
    Instead we need to wait until we get hotplug event to that adapter port
    or check if the port has HPD set before tunnels can be established. This
    adds Display Port tunneling support to the software connection manager.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • NFC (non flow control) credits is actually 20-bit field so update
    tb_port_add_nfc_credits() to handle this properly. This allows us to set
    NFC credits for Display Port path in subsequent patches.

    Also make sure the function does not update the hardware if the
    underlying switch is already unplugged.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • We will be needing these routines to find Display Port adapters as well
    so modify them to take port type as the second parameter.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • The only way to expand Thunderbolt topology is through the NULL adapter
    ports (typically ports 1, 2, 3 and 4). There is no point handling
    Thunderbolt hotplug events on any other port.

    Add a helper function (tb_port_is_null()) that can be used to determine
    if the port is NULL port, and use it in software connection manager code
    when hotplug event is handled.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Currently the software connection manager (tb.c) has only supported
    creating a single PCIe tunnel, no PCIe device daisy chaining has been
    supported so far. This updates the software connection manager so that
    it now can create PCIe tunnels for full chain of six devices.

    Because PCIe allows DMA and opens possibility for DMA attacks we change
    security level to "user" meaning that PCIe tunneling requires that the
    userspace authorizes the devices first. This makes it possible to block
    PCIe tunneling completely while still allowing other types of tunnels to
    be automatically created.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • In Apple Macs the boot firmware (EFI) connects all devices automatically
    when the system is started, before it hands over to the OS. Instead of
    ignoring we discover all those PCIe tunnels and record them using our
    internal structures, just like we do when a device is connected after
    the OS is already up.

    By doing this we can properly tear down tunnels when devices are
    disconnected. Also this allows us to resume the existing tunnels after
    system suspend/resume cycle.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • State of the connected devices and tunnel configuration is not known
    during resume. For example some paths may not be complete anymore if the
    user has unplugged the related devices. So instead of marking all paths
    as inactive we go ahead and deactivate them explicitly before we restart
    them.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Now that we can allocate hop IDs per port on a path, we can take
    advantage of this and create tunnels covering longer paths than just
    between two adjacent switches. PCIe actually does not need this as it
    is typically a daisy chain between two adjacent switches but this way we
    do not need to hard-code creation of the tunnel.

    While there add name to struct tb_path to make debugging easier, and
    update kernel-doc comments.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • We need to be able to walk from one port to another when we are creating
    paths where there are multiple switches between two ports. For this
    reason introduce a new function tb_next_port_on_path().

    Signed-off-by: Mika Westerberg
    Reviewed-by: Lukas Wunner

    Mika Westerberg
     
  • Currently the driver only assigns remote port for the primary port if in
    case of dual link. This makes things such as walking from one port to
    another more complex than necessary because the code needs to change
    from secondary to primary port if the path that is established is
    created using secondary links.

    In order to always assign both remote pointers we need to prevent the
    scanning code from following the secondary link. Failing to do that
    might cause problems as the same switch may be enumerated twice (or
    removed in case of unplug). Handle that properly by introducing a new
    function tb_port_has_remote() that returns true only for the primary
    port. We also update tb_is_upstream_port() to support both dual link
    ports, make it take const port pointer and move it below
    tb_upstream_port() to keep similar functions close.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Each port has a separate path configuration space that is used for
    finding the next hop (switch) in the path. HopID is an index to this
    configuration space. HopIDs 0 - 7 are reserved by the protocol.

    In order to get next available HopID for each direction we provide two
    pairs of helper functions that can be used to allocate and release
    HopIDs for a given port.

    While there remove obsolete TODO comment.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • To be able to tunnel non-PCIe traffic, separate tunnel functionality
    into generic and PCIe specific parts. Rename struct tb_pci_tunnel to
    tb_tunnel, and make it hold an array of paths instead of just two.
    Update all the tunneling functions to take this structure as parameter.

    We also move tb_pci_port_active() to switch.c (and rename it) where we
    will be keeping all port and switch related functions.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • In order to tunnel non-PCIe traffic as well rename tunnel_pci.[ch] to
    tunnel.[ch] to reflect this fact. No functional changes.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • The adapter specific capability either is there or not if the port does
    not hold an adapter. Instead of always finding it on-demand we read the
    offset just once when the port is initialized.

    While there we update the struct port documentation to follow kernel-doc
    format.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • We need to wait until all buffers have been drained before the path can
    be considered disabled. Do this for every hop in a path.

    This adds another bit field to struct tb_regs_hop even if we are trying
    to get rid of them but we can clean them up another day.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Thunderbolt 2 devices and beyond link controller needs to be notified
    when a switch is going to be suspended by setting bit 31 in LC_SX_CTRL
    register. Add this functionality to the software connection manager.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Thunderbolt 2 devices and beyond need to have additional bits set in
    link controller specific registers. This includes two bits in LC_SX_CTRL
    that tell the link controller which lane is connected and whether it is
    upstream facing or not.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • We will be adding more link controller functionality in subsequent
    patches and it does not make sense to keep all that in switch.c, so
    separate LC functionality into its own file.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Light Ridge has an issue where reading the next capability pointer
    location in port config space the read data is not cleared. It is fine
    to read capabilities each after another so only thing we need to do is
    to make sure we issue dummy read after tb_port_find_cap() is finished to
    avoid the issue in next read.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Light Ridge and Eagle Ridge both need to have TMU access enabled before
    port space can be fully accessed so make sure it happens on those. This
    allows us to get rid of the offset quirk in tb_port_find_cap().

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • Maximum depth in Thunderbolt topology is 6 so make sure it is not
    possible to allocate switches that exceed the depth limit.

    While at it update tb_switch_alloc() to use upper/lower_32_bits()
    following tb_switch_alloc_safe_mode().

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • switch_lock was introduced because it allowed serialization of device
    authorization requests from userspace without need to take the big
    domain lock (tb->lock). This was fine because device authorization with
    ICM is just one command that is sent to the firmware. Now that we start
    to handle all tunneling in the driver switch_lock is not enough because
    we need to walk over the topology to establish paths.

    For this reason drop switch_lock from the driver completely in favour of
    big domain lock.

    There is one complication, though. If userspace is waiting for the lock
    in tb_switch_set_authorized(), it keeps the device_del() from removing
    the sysfs attribute because it waits for active users to release the
    attribute first which leads into following splat:

    INFO: task kworker/u8:3:73 blocked for more than 61 seconds.
    Tainted: G W 5.1.0-rc1+ #244
    "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
    kworker/u8:3 D12976 73 2 0x80000000
    Workqueue: thunderbolt0 tb_handle_hotplug [thunderbolt]
    Call Trace:
    ? __schedule+0x2e5/0x740
    ? _raw_spin_lock_irqsave+0x12/0x40
    ? prepare_to_wait_event+0xc5/0x160
    schedule+0x2d/0x80
    __kernfs_remove.part.17+0x183/0x1f0
    ? finish_wait+0x80/0x80
    kernfs_remove_by_name_ns+0x4a/0x90
    remove_files.isra.1+0x2b/0x60
    sysfs_remove_group+0x38/0x80
    sysfs_remove_groups+0x24/0x40
    device_remove_attrs+0x3d/0x70
    device_del+0x14c/0x360
    device_unregister+0x15/0x50
    tb_switch_remove+0x9e/0x1d0 [thunderbolt]
    tb_handle_hotplug+0x119/0x5a0 [thunderbolt]
    ? process_one_work+0x1b7/0x420
    process_one_work+0x1b7/0x420
    worker_thread+0x37/0x380
    ? _raw_spin_unlock_irqrestore+0xf/0x30
    ? process_one_work+0x420/0x420
    kthread+0x118/0x130
    ? kthread_create_on_node+0x60/0x60
    ret_from_fork+0x35/0x40

    We deal this by following what network stack did for some of their
    attributes and use mutex_trylock() with restart_syscall(). This makes
    userspace release the attribute allowing sysfs attribute removal to
    progress before the write is restarted and eventually fail when the
    attribute is removed.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • If switch is already disconnected there is no point sending it commands
    and waiting for timeout. Instead in that case return error immediately.

    Signed-off-by: Mika Westerberg

    Mika Westerberg
     
  • tb_switch_find_by_route() does the same already so use it instead and
    remove duplicated get_switch_at_route().

    Signed-off-by: Mika Westerberg
    Reviewed-by: Lukas Wunner

    Mika Westerberg
     
  • This field is not used anywhere so remove it.

    Reported-by: Lukas Wunner
    Signed-off-by: Mika Westerberg

    Mika Westerberg
     

28 Mar, 2019

2 commits