thunderbolt.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. =============
  2. Thunderbolt
  3. =============
  4. The interface presented here is not meant for end users. Instead there
  5. should be a userspace tool that handles all the low-level details, keeps
  6. a database of the authorized devices and prompts users for new connections.
  7. More details about the sysfs interface for Thunderbolt devices can be
  8. found in ``Documentation/ABI/testing/sysfs-bus-thunderbolt``.
  9. Those users who just want to connect any device without any sort of
  10. manual work can add following line to
  11. ``/etc/udev/rules.d/99-local.rules``::
  12. ACTION=="add", SUBSYSTEM=="thunderbolt", ATTR{authorized}=="0", ATTR{authorized}="1"
  13. This will authorize all devices automatically when they appear. However,
  14. keep in mind that this bypasses the security levels and makes the system
  15. vulnerable to DMA attacks.
  16. Security levels and how to use them
  17. -----------------------------------
  18. Starting with Intel Falcon Ridge Thunderbolt controller there are 4
  19. security levels available. Intel Titan Ridge added one more security level
  20. (usbonly). The reason for these is the fact that the connected devices can
  21. be DMA masters and thus read contents of the host memory without CPU and OS
  22. knowing about it. There are ways to prevent this by setting up an IOMMU but
  23. it is not always available for various reasons.
  24. The security levels are as follows:
  25. none
  26. All devices are automatically connected by the firmware. No user
  27. approval is needed. In BIOS settings this is typically called
  28. *Legacy mode*.
  29. user
  30. User is asked whether the device is allowed to be connected.
  31. Based on the device identification information available through
  32. ``/sys/bus/thunderbolt/devices``, the user then can make the decision.
  33. In BIOS settings this is typically called *Unique ID*.
  34. secure
  35. User is asked whether the device is allowed to be connected. In
  36. addition to UUID the device (if it supports secure connect) is sent
  37. a challenge that should match the expected one based on a random key
  38. written to the ``key`` sysfs attribute. In BIOS settings this is
  39. typically called *One time saved key*.
  40. dponly
  41. The firmware automatically creates tunnels for Display Port and
  42. USB. No PCIe tunneling is done. In BIOS settings this is
  43. typically called *Display Port Only*.
  44. usbonly
  45. The firmware automatically creates tunnels for the USB controller and
  46. Display Port in a dock. All PCIe links downstream of the dock are
  47. removed.
  48. The current security level can be read from
  49. ``/sys/bus/thunderbolt/devices/domainX/security`` where ``domainX`` is
  50. the Thunderbolt domain the host controller manages. There is typically
  51. one domain per Thunderbolt host controller.
  52. If the security level reads as ``user`` or ``secure`` the connected
  53. device must be authorized by the user before PCIe tunnels are created
  54. (e.g the PCIe device appears).
  55. Each Thunderbolt device plugged in will appear in sysfs under
  56. ``/sys/bus/thunderbolt/devices``. The device directory carries
  57. information that can be used to identify the particular device,
  58. including its name and UUID.
  59. Authorizing devices when security level is ``user`` or ``secure``
  60. -----------------------------------------------------------------
  61. When a device is plugged in it will appear in sysfs as follows::
  62. /sys/bus/thunderbolt/devices/0-1/authorized - 0
  63. /sys/bus/thunderbolt/devices/0-1/device - 0x8004
  64. /sys/bus/thunderbolt/devices/0-1/device_name - Thunderbolt to FireWire Adapter
  65. /sys/bus/thunderbolt/devices/0-1/vendor - 0x1
  66. /sys/bus/thunderbolt/devices/0-1/vendor_name - Apple, Inc.
  67. /sys/bus/thunderbolt/devices/0-1/unique_id - e0376f00-0300-0100-ffff-ffffffffffff
  68. The ``authorized`` attribute reads 0 which means no PCIe tunnels are
  69. created yet. The user can authorize the device by simply entering::
  70. # echo 1 > /sys/bus/thunderbolt/devices/0-1/authorized
  71. This will create the PCIe tunnels and the device is now connected.
  72. If the device supports secure connect, and the domain security level is
  73. set to ``secure``, it has an additional attribute ``key`` which can hold
  74. a random 32-byte value used for authorization and challenging the device in
  75. future connects::
  76. /sys/bus/thunderbolt/devices/0-3/authorized - 0
  77. /sys/bus/thunderbolt/devices/0-3/device - 0x305
  78. /sys/bus/thunderbolt/devices/0-3/device_name - AKiTiO Thunder3 PCIe Box
  79. /sys/bus/thunderbolt/devices/0-3/key -
  80. /sys/bus/thunderbolt/devices/0-3/vendor - 0x41
  81. /sys/bus/thunderbolt/devices/0-3/vendor_name - inXtron
  82. /sys/bus/thunderbolt/devices/0-3/unique_id - dc010000-0000-8508-a22d-32ca6421cb16
  83. Notice the key is empty by default.
  84. If the user does not want to use secure connect they can just ``echo 1``
  85. to the ``authorized`` attribute and the PCIe tunnels will be created in
  86. the same way as in the ``user`` security level.
  87. If the user wants to use secure connect, the first time the device is
  88. plugged a key needs to be created and sent to the device::
  89. # key=$(openssl rand -hex 32)
  90. # echo $key > /sys/bus/thunderbolt/devices/0-3/key
  91. # echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized
  92. Now the device is connected (PCIe tunnels are created) and in addition
  93. the key is stored on the device NVM.
  94. Next time the device is plugged in the user can verify (challenge) the
  95. device using the same key::
  96. # echo $key > /sys/bus/thunderbolt/devices/0-3/key
  97. # echo 2 > /sys/bus/thunderbolt/devices/0-3/authorized
  98. If the challenge the device returns back matches the one we expect based
  99. on the key, the device is connected and the PCIe tunnels are created.
  100. However, if the challenge fails no tunnels are created and error is
  101. returned to the user.
  102. If the user still wants to connect the device they can either approve
  103. the device without a key or write a new key and write 1 to the
  104. ``authorized`` file to get the new key stored on the device NVM.
  105. Upgrading NVM on Thunderbolt device or host
  106. -------------------------------------------
  107. Since most of the functionality is handled in firmware running on a
  108. host controller or a device, it is important that the firmware can be
  109. upgraded to the latest where possible bugs in it have been fixed.
  110. Typically OEMs provide this firmware from their support site.
  111. There is also a central site which has links where to download firmware
  112. for some machines:
  113. `Thunderbolt Updates <https://thunderbolttechnology.net/updates>`_
  114. Before you upgrade firmware on a device or host, please make sure it is a
  115. suitable upgrade. Failing to do that may render the device (or host) in a
  116. state where it cannot be used properly anymore without special tools!
  117. Host NVM upgrade on Apple Macs is not supported.
  118. Once the NVM image has been downloaded, you need to plug in a
  119. Thunderbolt device so that the host controller appears. It does not
  120. matter which device is connected (unless you are upgrading NVM on a
  121. device - then you need to connect that particular device).
  122. Note an OEM-specific method to power the controller up ("force power") may
  123. be available for your system in which case there is no need to plug in a
  124. Thunderbolt device.
  125. After that we can write the firmware to the non-active parts of the NVM
  126. of the host or device. As an example here is how Intel NUC6i7KYK (Skull
  127. Canyon) Thunderbolt controller NVM is upgraded::
  128. # dd if=KYK_TBT_FW_0018.bin of=/sys/bus/thunderbolt/devices/0-0/nvm_non_active0/nvmem
  129. Once the operation completes we can trigger NVM authentication and
  130. upgrade process as follows::
  131. # echo 1 > /sys/bus/thunderbolt/devices/0-0/nvm_authenticate
  132. If no errors are returned, the host controller shortly disappears. Once
  133. it comes back the driver notices it and initiates a full power cycle.
  134. After a while the host controller appears again and this time it should
  135. be fully functional.
  136. We can verify that the new NVM firmware is active by running the following
  137. commands::
  138. # cat /sys/bus/thunderbolt/devices/0-0/nvm_authenticate
  139. 0x0
  140. # cat /sys/bus/thunderbolt/devices/0-0/nvm_version
  141. 18.0
  142. If ``nvm_authenticate`` contains anything other than 0x0 it is the error
  143. code from the last authentication cycle, which means the authentication
  144. of the NVM image failed.
  145. Note names of the NVMem devices ``nvm_activeN`` and ``nvm_non_activeN``
  146. depend on the order they are registered in the NVMem subsystem. N in
  147. the name is the identifier added by the NVMem subsystem.
  148. Upgrading NVM when host controller is in safe mode
  149. --------------------------------------------------
  150. If the existing NVM is not properly authenticated (or is missing) the
  151. host controller goes into safe mode which means that the only available
  152. functionality is flashing a new NVM image. When in this mode, reading
  153. ``nvm_version`` fails with ``ENODATA`` and the device identification
  154. information is missing.
  155. To recover from this mode, one needs to flash a valid NVM image to the
  156. host controller in the same way it is done in the previous chapter.
  157. Networking over Thunderbolt cable
  158. ---------------------------------
  159. Thunderbolt technology allows software communication between two hosts
  160. connected by a Thunderbolt cable.
  161. It is possible to tunnel any kind of traffic over a Thunderbolt link but
  162. currently we only support Apple ThunderboltIP protocol.
  163. If the other host is running Windows or macOS, the only thing you need to
  164. do is to connect a Thunderbolt cable between the two hosts; the
  165. ``thunderbolt-net`` driver is loaded automatically. If the other host is
  166. also Linux you should load ``thunderbolt-net`` manually on one host (it
  167. does not matter which one)::
  168. # modprobe thunderbolt-net
  169. This triggers module load on the other host automatically. If the driver
  170. is built-in to the kernel image, there is no need to do anything.
  171. The driver will create one virtual ethernet interface per Thunderbolt
  172. port which are named like ``thunderbolt0`` and so on. From this point
  173. you can either use standard userspace tools like ``ifconfig`` to
  174. configure the interface or let your GUI handle it automatically.
  175. Forcing power
  176. -------------
  177. Many OEMs include a method that can be used to force the power of a
  178. Thunderbolt controller to an "On" state even if nothing is connected.
  179. If supported by your machine this will be exposed by the WMI bus with
  180. a sysfs attribute called "force_power".
  181. For example the intel-wmi-thunderbolt driver exposes this attribute in:
  182. /sys/bus/wmi/devices/86CCFD48-205E-4A77-9C48-2021CBEDE341/force_power
  183. To force the power to on, write 1 to this attribute file.
  184. To disable force power, write 0 to this attribute file.
  185. Note: it's currently not possible to query the force power state of a platform.