1163f1511SMika Westerberg============= 2163f1511SMika Westerberg Thunderbolt 3163f1511SMika Westerberg============= 4163f1511SMika WesterbergThe interface presented here is not meant for end users. Instead there 5163f1511SMika Westerbergshould be a userspace tool that handles all the low-level details, keeps 6163f1511SMika Westerbergdatabase of the authorized devices and prompts user for new connections. 7163f1511SMika Westerberg 8163f1511SMika WesterbergMore details about the sysfs interface for Thunderbolt devices can be 9163f1511SMika Westerbergfound in ``Documentation/ABI/testing/sysfs-bus-thunderbolt``. 10163f1511SMika Westerberg 11163f1511SMika WesterbergThose users who just want to connect any device without any sort of 12163f1511SMika Westerbergmanual work, can add following line to 13163f1511SMika Westerberg``/etc/udev/rules.d/99-local.rules``:: 14163f1511SMika Westerberg 15163f1511SMika Westerberg ACTION=="add", SUBSYSTEM=="thunderbolt", ATTR{authorized}=="0", ATTR{authorized}="1" 16163f1511SMika Westerberg 17163f1511SMika WesterbergThis will authorize all devices automatically when they appear. However, 18163f1511SMika Westerbergkeep in mind that this bypasses the security levels and makes the system 19163f1511SMika Westerbergvulnerable to DMA attacks. 20163f1511SMika Westerberg 21163f1511SMika WesterbergSecurity levels and how to use them 22163f1511SMika Westerberg----------------------------------- 23163f1511SMika WesterbergStarting from Intel Falcon Ridge Thunderbolt controller there are 4 24163f1511SMika Westerbergsecurity levels available. The reason for these is the fact that the 25163f1511SMika Westerbergconnected devices can be DMA masters and thus read contents of the host 26163f1511SMika Westerbergmemory without CPU and OS knowing about it. There are ways to prevent 27163f1511SMika Westerbergthis by setting up an IOMMU but it is not always available for various 28163f1511SMika Westerbergreasons. 29163f1511SMika Westerberg 30163f1511SMika WesterbergThe security levels are as follows: 31163f1511SMika Westerberg 32163f1511SMika Westerberg none 33163f1511SMika Westerberg All devices are automatically connected by the firmware. No user 34163f1511SMika Westerberg approval is needed. In BIOS settings this is typically called 35163f1511SMika Westerberg *Legacy mode*. 36163f1511SMika Westerberg 37163f1511SMika Westerberg user 38163f1511SMika Westerberg User is asked whether the device is allowed to be connected. 39163f1511SMika Westerberg Based on the device identification information available through 40163f1511SMika Westerberg ``/sys/bus/thunderbolt/devices``. user then can do the decision. 41163f1511SMika Westerberg In BIOS settings this is typically called *Unique ID*. 42163f1511SMika Westerberg 43163f1511SMika Westerberg secure 44163f1511SMika Westerberg User is asked whether the device is allowed to be connected. In 45163f1511SMika Westerberg addition to UUID the device (if it supports secure connect) is sent 46163f1511SMika Westerberg a challenge that should match the expected one based on a random key 47163f1511SMika Westerberg written to ``key`` sysfs attribute. In BIOS settings this is 48163f1511SMika Westerberg typically called *One time saved key*. 49163f1511SMika Westerberg 50163f1511SMika Westerberg dponly 51163f1511SMika Westerberg The firmware automatically creates tunnels for Display Port and 52163f1511SMika Westerberg USB. No PCIe tunneling is done. In BIOS settings this is 53163f1511SMika Westerberg typically called *Display Port Only*. 54163f1511SMika Westerberg 55163f1511SMika WesterbergThe current security level can be read from 56163f1511SMika Westerberg``/sys/bus/thunderbolt/devices/domainX/security`` where ``domainX`` is 57163f1511SMika Westerbergthe Thunderbolt domain the host controller manages. There is typically 58163f1511SMika Westerbergone domain per Thunderbolt host controller. 59163f1511SMika Westerberg 60163f1511SMika WesterbergIf the security level reads as ``user`` or ``secure`` the connected 61163f1511SMika Westerbergdevice must be authorized by the user before PCIe tunnels are created 62163f1511SMika Westerberg(e.g the PCIe device appears). 63163f1511SMika Westerberg 64163f1511SMika WesterbergEach Thunderbolt device plugged in will appear in sysfs under 65163f1511SMika Westerberg``/sys/bus/thunderbolt/devices``. The device directory carries 66163f1511SMika Westerberginformation that can be used to identify the particular device, 67163f1511SMika Westerbergincluding its name and UUID. 68163f1511SMika Westerberg 69163f1511SMika WesterbergAuthorizing devices when security level is ``user`` or ``secure`` 70163f1511SMika Westerberg----------------------------------------------------------------- 71163f1511SMika WesterbergWhen a device is plugged in it will appear in sysfs as follows:: 72163f1511SMika Westerberg 73163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-1/authorized - 0 74163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-1/device - 0x8004 75163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-1/device_name - Thunderbolt to FireWire Adapter 76163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-1/vendor - 0x1 77163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-1/vendor_name - Apple, Inc. 78163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-1/unique_id - e0376f00-0300-0100-ffff-ffffffffffff 79163f1511SMika Westerberg 80163f1511SMika WesterbergThe ``authorized`` attribute reads 0 which means no PCIe tunnels are 81163f1511SMika Westerbergcreated yet. The user can authorize the device by simply:: 82163f1511SMika Westerberg 83163f1511SMika Westerberg # echo 1 > /sys/bus/thunderbolt/devices/0-1/authorized 84163f1511SMika Westerberg 85163f1511SMika WesterbergThis will create the PCIe tunnels and the device is now connected. 86163f1511SMika Westerberg 87163f1511SMika WesterbergIf the device supports secure connect, and the domain security level is 88163f1511SMika Westerbergset to ``secure``, it has an additional attribute ``key`` which can hold 89163f1511SMika Westerberga random 32 byte value used for authorization and challenging the device in 90163f1511SMika Westerbergfuture connects:: 91163f1511SMika Westerberg 92163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/authorized - 0 93163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/device - 0x305 94163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/device_name - AKiTiO Thunder3 PCIe Box 95163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/key - 96163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/vendor - 0x41 97163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/vendor_name - inXtron 98163f1511SMika Westerberg /sys/bus/thunderbolt/devices/0-3/unique_id - dc010000-0000-8508-a22d-32ca6421cb16 99163f1511SMika Westerberg 100163f1511SMika WesterbergNotice the key is empty by default. 101163f1511SMika Westerberg 102163f1511SMika WesterbergIf the user does not want to use secure connect it can just ``echo 1`` 103163f1511SMika Westerbergto the ``authorized`` attribute and the PCIe tunnels will be created in 104163f1511SMika Westerbergthe same way than in ``user`` security level. 105163f1511SMika Westerberg 106163f1511SMika WesterbergIf the user wants to use secure connect, the first time the device is 107163f1511SMika Westerbergplugged a key needs to be created and send to the device:: 108163f1511SMika Westerberg 109163f1511SMika Westerberg # key=$(openssl rand -hex 32) 110163f1511SMika Westerberg # echo $key > /sys/bus/thunderbolt/devices/0-3/key 111163f1511SMika Westerberg # echo 1 > /sys/bus/thunderbolt/devices/0-3/authorized 112163f1511SMika Westerberg 113163f1511SMika WesterbergNow the device is connected (PCIe tunnels are created) and in addition 114163f1511SMika Westerbergthe key is stored on the device NVM. 115163f1511SMika Westerberg 116163f1511SMika WesterbergNext time the device is plugged in the user can verify (challenge) the 117163f1511SMika Westerbergdevice using the same key:: 118163f1511SMika Westerberg 119163f1511SMika Westerberg # echo $key > /sys/bus/thunderbolt/devices/0-3/key 120163f1511SMika Westerberg # echo 2 > /sys/bus/thunderbolt/devices/0-3/authorized 121163f1511SMika Westerberg 122163f1511SMika WesterbergIf the challenge the device returns back matches the one we expect based 123163f1511SMika Westerbergon the key, the device is connected and the PCIe tunnels are created. 124163f1511SMika WesterbergHowever, if the challenge failed no tunnels are created and error is 125163f1511SMika Westerbergreturned to the user. 126163f1511SMika Westerberg 127163f1511SMika WesterbergIf the user still wants to connect the device it can either approve 128163f1511SMika Westerbergthe device without a key or write new key and write 1 to the 129163f1511SMika Westerberg``authorized`` file to get the new key stored on the device NVM. 130163f1511SMika Westerberg 131163f1511SMika WesterbergUpgrading NVM on Thunderbolt device or host 132163f1511SMika Westerberg------------------------------------------- 133163f1511SMika WesterbergSince most of the functionality is handled in a firmware running on a 134163f1511SMika Westerberghost controller or a device, it is important that the firmware can be 135163f1511SMika Westerbergupgraded to the latest where possible bugs in it have been fixed. 136163f1511SMika WesterbergTypically OEMs provide this firmware from their support site. 137163f1511SMika Westerberg 138163f1511SMika WesterbergThere is also a central site which has links where to download firmwares 139163f1511SMika Westerbergfor some machines: 140163f1511SMika Westerberg 141163f1511SMika Westerberg `Thunderbolt Updates <https://thunderbolttechnology.net/updates>`_ 142163f1511SMika Westerberg 143163f1511SMika WesterbergBefore you upgrade firmware on a device or host, please make sure it is 144163f1511SMika Westerbergthe suitable. Failing to do that may render the device (or host) in a 145163f1511SMika Westerbergstate where it cannot be used properly anymore without special tools! 146163f1511SMika Westerberg 147163f1511SMika WesterbergHost NVM upgrade on Apple Macs is not supported. 148163f1511SMika Westerberg 149163f1511SMika WesterbergOnce the NVM image has been downloaded, you need to plug in a 150163f1511SMika WesterbergThunderbolt device so that the host controller appears. It does not 151163f1511SMika Westerbergmatter which device is connected (unless you are upgrading NVM on a 152163f1511SMika Westerbergdevice - then you need to connect that particular device). 153163f1511SMika Westerberg 154163f1511SMika WesterbergNote OEM-specific method to power the controller up ("force power") may 155163f1511SMika Westerbergbe available for your system in which case there is no need to plug in a 156163f1511SMika WesterbergThunderbolt device. 157163f1511SMika Westerberg 158163f1511SMika WesterbergAfter that we can write the firmware to the non-active parts of the NVM 159163f1511SMika Westerbergof the host or device. As an example here is how Intel NUC6i7KYK (Skull 160163f1511SMika WesterbergCanyon) Thunderbolt controller NVM is upgraded:: 161163f1511SMika Westerberg 162163f1511SMika Westerberg # dd if=KYK_TBT_FW_0018.bin of=/sys/bus/thunderbolt/devices/0-0/nvm_non_active0/nvmem 163163f1511SMika Westerberg 164163f1511SMika WesterbergOnce the operation completes we can trigger NVM authentication and 165163f1511SMika Westerbergupgrade process as follows:: 166163f1511SMika Westerberg 167163f1511SMika Westerberg # echo 1 > /sys/bus/thunderbolt/devices/0-0/nvm_authenticate 168163f1511SMika Westerberg 169163f1511SMika WesterbergIf no errors are returned, the host controller shortly disappears. Once 170163f1511SMika Westerbergit comes back the driver notices it and initiates a full power cycle. 171163f1511SMika WesterbergAfter a while the host controller appears again and this time it should 172163f1511SMika Westerbergbe fully functional. 173163f1511SMika Westerberg 174163f1511SMika WesterbergWe can verify that the new NVM firmware is active by running following 175163f1511SMika Westerbergcommands:: 176163f1511SMika Westerberg 177163f1511SMika Westerberg # cat /sys/bus/thunderbolt/devices/0-0/nvm_authenticate 178163f1511SMika Westerberg 0x0 179163f1511SMika Westerberg # cat /sys/bus/thunderbolt/devices/0-0/nvm_version 180163f1511SMika Westerberg 18.0 181163f1511SMika Westerberg 182163f1511SMika WesterbergIf ``nvm_authenticate`` contains anything else than 0x0 it is the error 183163f1511SMika Westerbergcode from the last authentication cycle, which means the authentication 184163f1511SMika Westerbergof the NVM image failed. 185163f1511SMika Westerberg 186163f1511SMika WesterbergNote names of the NVMem devices ``nvm_activeN`` and ``nvm_non_activeN`` 187163f1511SMika Westerbergdepends on the order they are registered in the NVMem subsystem. N in 188163f1511SMika Westerbergthe name is the identifier added by the NVMem subsystem. 189163f1511SMika Westerberg 190163f1511SMika WesterbergUpgrading NVM when host controller is in safe mode 191163f1511SMika Westerberg-------------------------------------------------- 192163f1511SMika WesterbergIf the existing NVM is not properly authenticated (or is missing) the 193163f1511SMika Westerberghost controller goes into safe mode which means that only available 194163f1511SMika Westerbergfunctionality is flashing new NVM image. When in this mode the reading 195163f1511SMika Westerberg``nvm_version`` fails with ``ENODATA`` and the device identification 196163f1511SMika Westerberginformation is missing. 197163f1511SMika Westerberg 198163f1511SMika WesterbergTo recover from this mode, one needs to flash a valid NVM image to the 199163f1511SMika Westerberghost host controller in the same way it is done in the previous chapter. 200e69b6c02SAmir Levy 201e69b6c02SAmir LevyNetworking over Thunderbolt cable 202e69b6c02SAmir Levy--------------------------------- 203e69b6c02SAmir LevyThunderbolt technology allows software communication across two hosts 204e69b6c02SAmir Levyconnected by a Thunderbolt cable. 205e69b6c02SAmir Levy 206e69b6c02SAmir LevyIt is possible to tunnel any kind of traffic over Thunderbolt link but 207e69b6c02SAmir Levycurrently we only support Apple ThunderboltIP protocol. 208e69b6c02SAmir Levy 209e69b6c02SAmir LevyIf the other host is running Windows or macOS only thing you need to 210e69b6c02SAmir Levydo is to connect Thunderbolt cable between the two hosts, the 211e69b6c02SAmir Levy``thunderbolt-net`` is loaded automatically. If the other host is also 212e69b6c02SAmir LevyLinux you should load ``thunderbolt-net`` manually on one host (it does 213e69b6c02SAmir Levynot matter which one):: 214e69b6c02SAmir Levy 215e69b6c02SAmir Levy # modprobe thunderbolt-net 216e69b6c02SAmir Levy 217e69b6c02SAmir LevyThis triggers module load on the other host automatically. If the driver 218e69b6c02SAmir Levyis built-in to the kernel image, there is no need to do anything. 219e69b6c02SAmir Levy 220e69b6c02SAmir LevyThe driver will create one virtual ethernet interface per Thunderbolt 221e69b6c02SAmir Levyport which are named like ``thunderbolt0`` and so on. From this point 222e69b6c02SAmir Levyyou can either use standard userspace tools like ``ifconfig`` to 223e69b6c02SAmir Levyconfigure the interface or let your GUI to handle it automatically. 224*07c455eeSLinus Torvalds 225ce6a9002SMario LimoncielloForcing power 226ce6a9002SMario Limonciello------------- 227ce6a9002SMario LimoncielloMany OEMs include a method that can be used to force the power of a 228ce6a9002SMario Limonciellothunderbolt controller to an "On" state even if nothing is connected. 229ce6a9002SMario LimoncielloIf supported by your machine this will be exposed by the WMI bus with 230ce6a9002SMario Limoncielloa sysfs attribute called "force_power". 231ce6a9002SMario Limonciello 232ce6a9002SMario LimoncielloFor example the intel-wmi-thunderbolt driver exposes this attribute in: 233ce6a9002SMario Limonciello /sys/devices/platform/PNP0C14:00/wmi_bus/wmi_bus-PNP0C14:00/86CCFD48-205E-4A77-9C48-2021CBEDE341/force_power 234ce6a9002SMario Limonciello 235ce6a9002SMario Limonciello To force the power to on, write 1 to this attribute file. 236ce6a9002SMario Limonciello To disable force power, write 0 to this attribute file. 237ce6a9002SMario Limonciello 238ce6a9002SMario LimoncielloNote: it's currently not possible to query the force power state of a platform. 239