Commit Graph

65 Commits

Author SHA1 Message Date
Gil Fine
ccd8450211 thunderbolt: Calculate DisplayPort tunnel bandwidth after DPRX capabilities read
According to USB4 Connection Manager guide, after DisplayPort tunnel was
setup, the DPRX capabilities read is performed by the DPTX. According to
VESA spec, this shall be completed within 5 seconds after the DisplayPort
tunnel was setup. Hence, if the bit: DPRX Capabilities Read Done, was
not set to '1' by this time, we timeout and fail calculating DisplayPort
tunnel consumed bandwidth.

Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2024-02-16 12:29:23 +02:00
Mika Westerberg
769da9708a thunderbolt: Introduce tb_tunnel_direction_downstream()
This helper takes tunnel as parameter. Convert existing code to call
this where possible.

No functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2024-02-16 12:29:23 +02:00
Mika Westerberg
7b5e0bfc03 thunderbolt: Use DP_LOCAL_CAP for maximum bandwidth calculation
The DisplayPort IN adapter DP_LOCAL_CAP holds the aggregated
capabilities and gets updated after graphics side does the DPRX
capabilities read so we should use this to figure out the maximum
possible bandwidth for the DisplayPort tunnel.

While there make the variable name to match better what it is used for
and add kernel-doc comment to the function.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2024-02-16 12:29:22 +02:00
Gil Fine
2b3a6239d2 thunderbolt: Disable PCIe extended encapsulation upon teardown properly
In case of PCIe tunnel teardown (including if caused by router unplug),
PCIe extended encapsulation bit should be cleared in downstream and
upstream routers accordingly.

Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-12-14 08:07:45 +02:00
Gil Fine
54967f4177 thunderbolt: Make PCIe tunnel setup and teardown follow CM guide
The USB4 Connection Manager guide suggests that the PCIe paths are
enabled from the upstream adapter to the downstream adapter and vice
versa on disable so make the driver follows this sequence.

Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-12-14 08:07:45 +02:00
Mika Westerberg
97e0a21ce8 thunderbolt: Use tb_dp_read_cap() to read DP_COMMON_CAP as well
There is no point doing this separately as the register layout is the
same. For this reason rename tb_dp_read_dprx() to tb_dp_wait_dprx() and
call tb_dp_read_cap() instead.

While there add debug log if the DPRX capability read times out.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-12-14 08:07:45 +02:00
Colin Ian King
655b8af57d thunderbolt: Remove duplicated re-assignment of pointer 'out'
The pointer 'out' is initialized and then a few statements later being
re-assigned the same value. The second re-assignment is redundant and
can be removed.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-11-14 14:17:29 +02:00
Gil Fine
2bfeca73e9 thunderbolt: Introduce tb_port_path_direction_downstream()
Introduce tb_port_path_direction_downstream() to check if path from
source adapter to destination adapter is directed towards downstream.
Convert existing users to call this helper instead of open-coding.

No functional changes.

Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-20 18:18:01 +03:00
Mika Westerberg
ce91d793ab thunderbolt: Set path power management packet support bit for USB4 v2 routers
USB4 v2 spec allows USB4 links that are part of a pass through tunnel
(such as DisplayPort and USB 3.x Gen T) to enter lower CL states, which
provide better power management. For this USB4 v2 routers in their path
config space of lane 0 adapter include a new bit PMPS (PM packet
support) that needs to be set.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-20 18:18:01 +03:00
Gil Fine
582e70b0d3 thunderbolt: Change bandwidth reservations to comply USB4 v2
USB4 v2 Connection Manager guide (section 6.1.2.3) suggests to reserve
bandwidth in a sligthly different manner. It suggests to keep minimum of
1500 Mb/s for each path that carry a bulk traffic. Here we change the
bandwidth reservations to comply to the above for USB 3.x and PCIe
protocols over Gen 4 link, taking weights into account (that's 1500 Mb/s
for PCIe and 3000 Mb/s for USB 3.x).

For Gen 3 and below we use the existing reservation.

Signed-off-by: Gil Fine <gil.fine@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-20 18:18:01 +03:00
Mika Westerberg
4d24db0c80 thunderbolt: Use weight constants in tb_usb3_consumed_bandwidth()
Instead of magic numbers use the constants we introduced in the previous
commit to make the code more readable. No functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-20 18:18:00 +03:00
Mika Westerberg
f73edddfa2 thunderbolt: Use constants for path weight and priority
Makes it easier to follow and update. No functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-20 18:18:00 +03:00
Mika Westerberg
d27bd2c37d thunderbolt: Expose tb_tunnel_xxx() log macros to the rest of the driver
In order to allow more consistent logging of tunnel related information
make these logging macros available to the rest of the driver.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-13 08:49:13 +03:00
Mika Westerberg
fe8a0293c9 thunderbolt: Use tb_tunnel_dbg() where possible to make logging more consistent
This makes it easier to find out the tunnel in question. Also drop a
couple of lines that generate duplicate information.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-13 08:49:13 +03:00
Mika Westerberg
92b8f7a1b1 thunderbolt: Get rid of usb4_usb3_port_actual_link_rate()
It turns out there is no need to use the actual link rate when
reclaiming bandwidth for USB 3.x. The reason is that we use consumed
bandwidth which is coming from xHCI when releasing bandwidth (for
example for DisplayPort tunneling) and this can be anything between
1000 Mb/s to maximum, so when reclaiming we can just bump it up back to
maximum instead of actual link rate (which is always <= maximum).

This allows us to get rid of couple of unnecessary lines of code.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-10-13 08:49:13 +03:00
Mika Westerberg
2d7e047297 thunderbolt: Add DisplayPort 2.x tunneling support
This adds support for the UHBR (Ultra High Bit Rate) bandwidths
introduced with DisplayPort 2.0 (and refined in 2.1). These can go up to
80 Gbit/s and their support is represent in additional bits in the DP IN
capability.

This updates the DisplayPort tunneling to support these new rates too.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-06-16 09:53:29 +03:00
Mika Westerberg
8d73f6b8e0 thunderbolt: Make bandwidth allocation mode function names consistent
Make sure the DisplayPort bandwidth allocation mode function names are
consistent with the existing ones, such as USB3.

No functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-06-16 09:53:29 +03:00
Gil Fine
6e19d48ea0 thunderbolt: Enable USB4 v2 PCIe TLP/DLLP extended encapsulation
USB4 v2 spec introduces modified encapsulation of PCIe TLP and DLLP
packets. This improves the PCIe tunneled traffic usage by reducing
overhead. Enable this if both sides of the link support it.

Signed-off-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-06-16 09:53:28 +03:00
Mika Westerberg
ef65afa074 Merge branch 'thunderbolt/fixes' into thunderbolt/next
We need Thunderbolt/USB4 fixes here as well.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-06-09 12:06:52 +03:00
Mika Westerberg
033c2d8ab2 thunderbolt: Log DisplayPort adapter rate and lanes on discovery
This may be helpful when debugging possible issues around DisplayPort
port tunneling.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-05-30 09:12:21 +03:00
Mika Westerberg
b6d572aeb5 thunderbolt: Increase DisplayPort Connection Manager handshake timeout
It turns out that when plugging in VGA cable through USB-C to VGA/DVI
dongle the Connection Manager handshake can take longer time, at least
on Intel Titan Ridge based docks such as Dell WD91TB. This leads to
following error in the dmesg:

  thunderbolt 0000:00:0d.3: 3:10: DP tunnel activation failed, aborting

and the display stays blank (because we failed to establish the tunnel).
For this reason increase the timeout to 3s.

Reported-by: Koba Ko <koba.ko@canonical.com>
Cc: stable@vger.kernel.org
Acked-By: Yehezkel Bernat <YehezkelShB@gmail.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-05-29 12:49:00 +03:00
Mika Westerberg
7ee20d0afb thunderbolt: Allow specifying custom credits for DMA tunnels
The default ones should be find but this allows the user to tweak the
credits to get more performance out of the P2P connection.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-05-24 09:39:35 +03:00
Mika Westerberg
814c96c959 thunderbolt: Check for ring 0 in tb_tunnel_alloc_dma()
Ring 0 cannot be used for anything else than control channel messages.
For this reason add a check to tb_tunnel_alloc_dma() and fail if someone
tries to do that.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-05-24 09:39:34 +03:00
Greg Kroah-Hartman
88e054e8df thunderbolt: Changes for v6.3 merge window
This includes following Thunderbolt/USB4 changes for the v6.3 merge
 window:
 
   - Add support for DisplayPort bandwidth allocation mode
   - Debug logging improvements
   - Minor cleanups.
 
 All these have been in linux-next with no reported issues.
 -----BEGIN PGP SIGNATURE-----
 
 iQJUBAABCgA+FiEEVTdhRGBbNzLrSUBaAP2fSd+ZWKAFAmPjS/4gHG1pa2Eud2Vz
 dGVyYmVyZ0BsaW51eC5pbnRlbC5jb20ACgkQAP2fSd+ZWKD7xhAAiye8RAaV2KkV
 u5ZxF14fY4mIholmBeq5da7wgERcsQlsbKJRBlNHwJAEWzJRYU1ujPERLYOob0zV
 rx/yopbg8x7VtiHHnnQ7FooZOL2oCOTsSMgQldmcHG7U3oVc/vNVB/YDlGresE5F
 TvllRtvCOQWanUfv021G7nVPHdubospkjaS6inK3l/wp6RCpO7Kdyg0JOkeYiRLb
 MkuO9Eb7E/Ppg8Zq1d8eOtTddKqb9v7AmsejyuBWZcJfuTHBIOM017T06URYtUJz
 VN5zS3mM3LVSVxtHotlPHsuQtGBXzSZxKZx46BsrEZ3EWquDeE0F7s8L9FhRkB5y
 K2H7B8k/TKVUGiHSBmYa0u0hX1dRY5EOvgIngIXy+LWAEGjdpAmKgyokgDaP4W0c
 Ms/bm4FhakNX8/UkgBcy/1TWW4yk7dlvdZzBI8xTdzgcFuOxiOf2OnAy1nnkCQG2
 g8p0c8JasIXPgYtZ+mWMKfdKeUB+GzKD/h18M3rLxcEP+i+pVUXr27EeYzR6yLZ5
 7oVxbJK0pZbPitaYBIKZV39MW47i6JWyl4ubkccp2R1rLqaCCqaESlcc2Qb67Z3i
 aBsUdviH70jIoi27CBhOnMb0vELlr/ZUNe4znMjW/kPoZOquR4EilBmrV254LOOK
 VJcEaXVnV59e7hPzbdT+FXH96UBRf/Y=
 =Kegw
 -----END PGP SIGNATURE-----

Merge tag 'thunderbolt-for-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-next

Mika writes:

thunderbolt: Changes for v6.3 merge window

This includes following Thunderbolt/USB4 changes for the v6.3 merge
window:

  - Add support for DisplayPort bandwidth allocation mode
  - Debug logging improvements
  - Minor cleanups.

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

* tag 'thunderbolt-for-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt:
  thunderbolt: Add missing kernel-doc comment to tb_tunnel_maximum_bandwidth()
  thunderbolt: Handle bandwidth allocation mode enablement notification
  thunderbolt: Add support for DisplayPort bandwidth allocation mode
  thunderbolt: Include the additional DP IN double word in debugfs dump
  thunderbolt: Add functions to support DisplayPort bandwidth allocation mode
  thunderbolt: Increase timeout of DP OUT adapter handshake
  thunderbolt: Take CL states into account when waiting for link to come up
  thunderbolt: Improve debug logging in tb_available_bandwidth()
  thunderbolt: Log DP adapter type
  thunderbolt: Use decimal port number in control and tunnel logs too
  thunderbolt: Refactor tb_acpi_add_link()
  thunderbolt: Use correct type in tb_port_is_clx_enabled() prototype
2023-02-08 12:49:26 +01:00
Mika Westerberg
06cbcbfaa6 thunderbolt: Add missing kernel-doc comment to tb_tunnel_maximum_bandwidth()
These were missing from the original commit so add them now. No
functional changes.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-01-27 08:25:59 +02:00
Mika Westerberg
6ce3563520 thunderbolt: Add support for DisplayPort bandwidth allocation mode
The USB4 spec defines an optional feature that allows the connection
manager to negotiate with the graphics through DPCD registers changes in
the bandwidth allocation dynamically. This is referred as "bandwidth
allocation mode" in the spec. The connection manager uses DP IN adapters
registers to communicate with the graphics, and also gets notifications
from these adapters when the graphics wants to change the bandwidth
allocation. Both the connection manager and the graphics driver needs to
support this.

We check if the DP IN adapter supports this and if it does enable it
before establishing a DP tunnel. Then we react on DP_BW notifications
coming from the DP IN adapter and update the bandwidth allocation
accordingly (within the maximum common capabilities the DP IN/OUT
support).

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-01-17 11:37:16 +02:00
Mika Westerberg
fe1a1cf7c9 thunderbolt: Increase timeout of DP OUT adapter handshake
Sometimes the current timeout is not enough so increase it to 1500 ms
and while there make the loop use ktime instead.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-01-17 11:37:00 +02:00
Mika Westerberg
49f2b350f3 thunderbolt: Use decimal port number in control and tunnel logs too
Use decimal number instead of hex in port numbers as we have been doing
with other logging functions too. This makes the output more consistent.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-01-17 11:36:39 +02:00
Mika Westerberg
e8ff07fb33 thunderbolt: Use correct function to calculate maximum USB3 link rate
We need to take minimum of both sides of the USB3 link into consideration,
not just the downstream port. Fix this by calling tb_usb3_max_link_rate()
instead.

Fixes: 0bd680cd90 ("thunderbolt: Add USB3 bandwidth management")
Cc: stable@vger.kernel.org
Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2023-01-09 10:44:23 +02:00
Gil Fine
93bf344f66 thunderbolt: Fix buffer allocation of devices with no DisplayPort adapters
For the case of a device without DisplayPort adapters we calculate
incorrectly the amount of buffers. Fix the calculation for this case.

Signed-off-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2022-05-12 09:22:11 +03:00
Mika Westerberg
9d2d0a5cf0 thunderbolt: Use different lane for second DisplayPort tunnel
Brad reported that on Apple hardware with Light Ridge or Falcon Ridge
controller, plugging in a chain of Thunderbolt displays (Light Ridge
based controllers) causes all kinds of tearing and flickering. The
reason for this is that on Thunderbolt 1 hardware there is no lane
bonding so we have two independent 10 Gb/s lanes, and currently Linux
tunnels both displays through the lane 1. This makes the displays to
share the 10 Gb/s bandwidth which may not be enough for higher
resolutions.

For this reason make the second tunnel go through the lane 0 instead.
This seems to match what the macOS connection manager is also doing.

Reported-by: Brad Campbell <lists2009@fnarfbargle.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Brad Campbell <lists2009@fnarfbargle.com>
2022-04-19 10:26:18 +03:00
Mika Westerberg
3eddfc121f thunderbolt: Disable LTTPR on Intel Titan Ridge
Intel Titan Ridge does not disable AUX timers when it gets SET_CONFIG
with SET_LTTPR_MODE set which makes DP tunneling to fail. For this
reason disable LTTPR on Titan Ridge device side.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2022-02-02 13:56:38 +03:00
Mika Westerberg
43bddb26e2 thunderbolt: Tear down existing tunnels when resuming from hibernate
If the boot firmware implements connection manager of its own it may not
create the paths in the same way or order we do. For example it may
create first PCIe tunnel and then USB3 tunnel. When we restore our
tunnels (first de-activating them) we may be doing that over completely
different tunnels and that leaves them possibly non-functional. For this
reason we re-use the tunnel discovery functionality and find out all the
existing tunnels, and tear them down. Once that is done we can restore
our tunnels.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2021-12-07 15:18:33 +03:00
Mika Westerberg
6ed541c53e thunderbolt: Allocate credits according to router preferences
The USB4 Connection Manager guide provides detailed information how the
USB4 router buffer (credit) allocation information should be used by the
connection manager when it allocates buffers for different paths. This
patch implements it for Linux. For USB 3.x and DisplayPort we use
directly the router preferences. The rest of the buffer space is then
used for PCIe and DMA (peer-to-peer, XDomain) traffic. DMA tunnels
require at least one buffer and PCIe six, so if there is not enough
buffers we fail the tunnel creation.

For the legacy Thunderbolt 1-3 devices we use the existing hard-coded
scheme except for DMA where we use the values suggested by the USB4 spec
chapter 13.

Co-developed-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Gil Fine <gil.fine@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2021-06-01 10:48:59 +03:00
Mika Westerberg
02c5e7c2db thunderbolt: Move nfc_credits field to struct tb_path_hop
With the USB4 buffer allocation the number of credits (and non-flow
credits) may be different depending on the router buffer allocation
preferences. To allow this move the nfc_credits field to struct
tb_path_hop.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2021-06-01 10:48:59 +03:00
Mika Westerberg
180b068942 thunderbolt: Allow multiple DMA tunnels over a single XDomain connection
Currently we have had an artificial limitation of a single DMA tunnel
per XDomain connection. However, hardware wise there is no such limit
and software based connection manager can take advantage of all the DMA
rings available on the host to establish tunnels.

For this reason make the tb_xdomain_[enable|disable]_paths() to take the
DMA ring and HopID as parameter instead of storing them in the struct
tb_xdomain. We also add API functions to allocate input and output
HopIDs of the XDomain connection that the service drivers can use
instead of hard-coding.

Also convert the two existing service drivers over to this API.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2021-03-18 18:25:31 +03:00
Mika Westerberg
e5876559b5 thunderbolt: Use dedicated flow control for DMA tunnels
The USB4 inter-domain service spec recommends using dedicated flow
control scheme so update the driver accordingly.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2021-03-18 18:25:31 +03:00
Mika Westerberg
c6da62a219 thunderbolt: Add support for native USB4 _OSC
ACPI 6.4 introduced a new _OSC capability used to negotiate whether the
OS is supposed to use Software (native) or Firmware based Connection
Manager. If the native support is granted then there are set of bits
that enable/disable different tunnel types that the Software Connection
Manager is allowed to tunnel.

This adds support for this new USB4 _OSC accordingly. When PCIe
tunneling is disabled then the driver switches security level to be
"nopcie" following the security level 5 used in Firmware based
Connection Manager.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com>
2021-02-04 10:45:25 +03:00
Lee Jones
a27ea0dfc1 thunderbolt: tunnel: Fix misspelling of 'receive_path'
Fixes the following W=1 kernel build warning(s):

 drivers/thunderbolt/tunnel.c:841: warning: Function parameter or member 'receive_path' not described in 'tb_tunnel_alloc_dma'
 drivers/thunderbolt/tunnel.c:841: warning: Excess function parameter 'reveive_path' description in 'tb_tunnel_alloc_dma'

Cc: Andreas Noever <andreas.noever@gmail.com>
Cc: Michael Jamet <michael.jamet@intel.com>
Cc: Yehezkel Bernat <YehezkelShB@gmail.com>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2021-01-28 13:57:06 +03:00
Mika Westerberg
5bf722df5d thunderbolt: Make it possible to allocate one directional DMA tunnel
With DMA tunnels it is possible that the service using it does not
require bi-directional paths so make RX and TX optional (but of course
one of them needs to be set).

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-11-11 10:20:16 +03:00
Greg Kroah-Hartman
6b6c71e897 thunderbolt: Fixes for v5.9-rc4
This includes two fixes, one that fixes a regression around reboot and
 other that uses a correct link rate when USB3 bandwidth is reclaimed
 when the link is not up.
 
 Both have been in linux-next with no reported issues.
 -----BEGIN PGP SIGNATURE-----
 
 iQJUBAABCgA+FiEEVTdhRGBbNzLrSUBaAP2fSd+ZWKAFAl9N9lMgHG1pa2Eud2Vz
 dGVyYmVyZ0BsaW51eC5pbnRlbC5jb20ACgkQAP2fSd+ZWKDqFg//Rm8xBbFp+DFF
 LysW8K6ZCEbwUVZa0CvrDv2fSG/E//yYKstMOIuIZBs49LENNEGtQeyPwRkZmeyk
 LA1n6lxOefyLDHw/7Q4pd6mrxFTUBQoLYrTofuTck5b7HVABv1CpyhWjBmEijTy0
 wKcSEE2LWDJ4e6ROMrk6X6hYSYAIgfjWyjiiswqETuPB7s62Nnpv14cLc6//2thc
 OzRaa5qKJ3ldwswJZzjFDWriDIyIBQiEHHP8YM+QfiMNs+Fb/pP1Uxyg0OJSk6g3
 1qMV8b2VmSXdnT0APF0oyxkkB3zELvJo33RhRKgW9OTAhFkPSeqdxbydAe//MdVo
 AWjJ8hvRcFCxnXF9cKzA3HagUX4CVP/IXSH3L8kWR9PprRJvsGXKNA4Xna9Cx4FI
 qfPatQ73ATIBM2iwsFiYweawuO0Ti5JcPpRBfm1D4rG0yv/r7rN+3fBatHsrdYi4
 FMT+kRZI/GUi5LQFXLcG6UE8BesGipJJvGJTIkuKu7GQJ3RlLrZRLMkmM/wTx6be
 aahVT25OXUeZJ77y+RhgVQuikSWDTLS4TjXBa7/t0y+JuEkBjtoPlDbWn3IFGaRr
 oPnCkNnpFvTA8pnv7KWt9X8J5pZW3WNd35OmPlTilXBz1gbrH6+U0sSE5KsC6ii1
 EYewgZI+e8qZXGcwDw0qBBXJ8RqFWPI=
 =vxwa
 -----END PGP SIGNATURE-----

Merge tag 'thunderbolt-for-v5.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt into usb-linus

Mika writes:

thunderbolt: Fixes for v5.9-rc4

This includes two fixes, one that fixes a regression around reboot and
other that uses a correct link rate when USB3 bandwidth is reclaimed
when the link is not up.

Both have been in linux-next with no reported issues.

* tag 'thunderbolt-for-v5.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/westeri/thunderbolt:
  thunderbolt: Use maximum USB3 link rate when reclaiming if link is not up
  thunderbolt: Disable ports that are not implemented
2020-09-01 09:48:28 +02:00
Mika Westerberg
813050e0a9 thunderbolt: Use maximum USB3 link rate when reclaiming if link is not up
If the USB3 link is not up the actual link rate is 0 so when reclaiming
bandwidth we should look at maximum supported link rate instead.

Cc: stable@vger.kernel.org
Fixes: 0bd680cd90 ("thunderbolt: Add USB3 bandwidth management")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2020-08-25 11:29:01 +03:00
Gustavo A. R. Silva
df561f6688 treewide: Use fallthrough pseudo-keyword
Replace the existing /* fall through */ comments and its variants with
the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
fall-through markings when it is the case.

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
2020-08-23 17:36:59 -05:00
Mika Westerberg
0bd680cd90 thunderbolt: Add USB3 bandwidth management
USB3 supports both isochronous and non-isochronous traffic. The former
requires guaranteed bandwidth and can take up to 90% of the total
bandwidth. With USB4 USB3 is tunneled over USB4 fabric which means that
we need to make sure there is enough bandwidth allocated for the USB3
tunnels in addition to DisplayPort tunnels.

Whereas DisplayPort bandwidth management is static and done before the
DP tunnel is established, the USB3 bandwidth management is dynamic and
allows increasing and decreasing the allocated bandwidth according to
what is currently consumed. This is done through host router USB3
downstream adapter registers.

This adds USB3 bandwidth management to the software connection manager
so that we always try to allocate maximum bandwidth for DP tunnels and
what is left is allocated for USB3.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2020-06-22 19:58:20 +03:00
Mika Westerberg
acf815b867 thunderbolt: Increase DP DPRX wait timeout
Sometimes it takes longer for DPRX to be set so increase the timeout to
cope with this.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2020-06-22 19:58:20 +03:00
Mika Westerberg
7c0ee8fd3b thunderbolt: Report consumed bandwidth in both directions
Whereas DisplayPort bandwidth is consumed only in one direction (from DP
IN adapter to DP OUT adapter), USB3 adds separate bandwidth for both
upstream and downstream directions.

For this reason extend the tunnel consumed bandwidth routines to support
both directions and implement this for DP.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2020-06-22 19:58:20 +03:00
Mika Westerberg
75ab3f06a1 thunderbolt: Handle incomplete PCIe/USB3 paths correctly in discovery
If the path is not complete when we do discovery the number of hops may
be less than with the full path. As an example when this can happen is
that user unloads the driver, disconnects the topology, and loads the
driver back. If there is PCIe or USB3 tunnel involved this may happen.

Take this into account in tb_pcie_init_path() and tb_usb3_init_path()
and prevent potential access over array limits.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
2020-06-22 19:58:20 +03:00
Mika Westerberg
783735f84f thunderbolt: Fix path indices used in USB3 tunnel discovery
The USB3 discovery used wrong indices when tunnel is discovered. It
should use TB_USB3_PATH_DOWN for path that flows downstream and
TB_USB3_PATH_UP when it flows upstream. This should not affect the
functionality but better to fix it.

Fixes: e6f8185857 ("thunderbolt: Add support for USB 3.x tunnels")
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: stable@vger.kernel.org # v5.6+
2020-06-22 19:58:19 +03:00
Rajmohan Mani
e6f8185857 thunderbolt: Add support for USB 3.x tunnels
USB4 added a capability to tunnel USB 3.x protocol over the USB4
fabric. USB4 device routers may include integrated SuperSpeed HUB or a
function or both. USB tunneling follows PCIe so that the tunnel is
created between the parent and the child router from USB3 downstream
adapter port to USB3 upstream adapter port over a single USB4 link.

This adds support for USB 3.x tunneling and also capability to discover
existing USB 3.x tunnels (for example created by connection manager in
boot firmware).

Signed-off-by: Rajmohan Mani <rajmohan.mani@intel.com>
Co-developed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Link: https://lore.kernel.org/r/20191217123345.31850-9-mika.westerberg@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-18 15:41:40 +01:00
Mika Westerberg
b04079837b thunderbolt: Add initial support for USB4
USB4 is the public specification based on Thunderbolt 3 protocol. There
are some differences in register layouts and flows. In addition to PCIe
and DP tunneling, USB4 supports tunneling of USB 3.x. USB4 is also
backward compatible with Thunderbolt 3 (and older generations but the
spec only talks about 3rd generation). USB4 compliant devices can be
identified by checking USB4 version field in router configuration space.

This patch adds initial support for USB4 compliant hosts and devices
which enables following features provided by the existing functionality
in the driver:

  - PCIe tunneling
  - Display Port tunneling
  - Host and device NVM firmware upgrade
  - P2P networking

This brings the USB4 support to the same level that we already have for
Thunderbolt 1, 2 and 3 devices.

Note the spec talks about host and device "routers" but in the driver we
still use term "switch" in most places. Both can be used interchangeably.

Co-developed-by: Rajmohan Mani <rajmohan.mani@intel.com>
Signed-off-by: Rajmohan Mani <rajmohan.mani@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Link: https://lore.kernel.org/r/20191217123345.31850-5-mika.westerberg@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-18 15:38:55 +01:00