Add Apple T2 NHI Device links
Subsystems (2)
v8 cover Add Apple T2 NHI Device links
This series adds support for Device linking on Titan ridge, and Icelake, which are used exclusively on Apple T2 machines.
Changes in v8:
- Shifted tb_apple_add_links to pci.c
Changes in v7:
- Used pci_lock_rescan_remove to prevent race conditons.
- Fixed patch format.
Changes in v6:
- Used for_each_pci_bridge in Icelake section
- Removed has_apple_t2_chip as its not required now
Changes in v5:
- Used Icelake root PCI IDs for detection of root ports instead of TRP
Changes in v4:
- Limited TRP check to T2 Icelake systems only
- Optimized has_apple_t2_chip check
- Included pci.h to drivers/thunderbolt/tb.c
- Used __free(pci_dev_put) to avoid label
Changes in v3:
- Fix build errors with non-x86 machines
- Used __initconst for apple_t2_devices
- Removed UEFI_QUIRK_SKIP_CERT as its unused now
- Used IS_ENABLED(CONFIG_ACPI) in tb_apple_add_links for the T2 part
- Removed !bid check to remove warning with -Waddress
Changes in v2:
- Used a less generic name for has_t2_chip
- Used DMI instead of PCI for has_apple_t2_chip to avoid PCI problems
- Initialized ret in tb_apple_add_links
Link to v7:
https://lore.kernel.org/all/[email protected]/
Link to v6:
https://lore.kernel.org/all/[email protected]/
Link to v5:
https://lore.kernel.org/all/[email protected]/
Link to v4:
https://lore.kernel.org/all/[email protected]/
Link to v3:
https://lore.kernel.org/all/[email protected]/
Link to v2:
https://lore.kernel.org/all/[email protected]/
Link to v1:
https://lore.kernel.org/all/[email protected]/
Atharva Tiwari (3):
thunderbolt: Shift tb_apple_add_links to pci.c
thunderbolt: Add device links for Apple machines with Titan Ridge
thunderbolt: Add device links for Apple systems with Icelake
thunderbolt
drivers/thunderbolt/pci.c | 119 ++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.c | 72 +---------------------- drivers/thunderbolt/tb.h | 1 + 3 files changed, 121 insertions(+), 71 deletions(-)
Signature · 1 line
2.43.0
PATCH v8 1/3 thunderbolt: Shift tb_apple_add_links to pci.c
Shift tb_apple_add_links to pci.c as tb_apple_add_links calls pci functions.
--- drivers/thunderbolt/pci.c | 73 +++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.c | 72 +------------------------------------- drivers/thunderbolt/tb.h | 1 + 3 files changed, 75 insertions(+), 71 deletions(-)
drivers/thunderbolt/pci.c +73 -0
@@ -18,6 +18,7 @@#include <linux/property.h> #include <linux/string_helpers.h> #include <linux/suspend.h> +#include <linux/platform_data/x86/apple.h> #include "nhi.h" #include "nhi_regs.h"
@@ -261,6 +262,53 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .init_interrupts = nhi_pci_init_msi, }; +static bool tb_pci_add_links_discrete (struct pci_dev *nhi_pdev) +{ +struct pci_dev *pdev, *upstream =pci_upstream_bridge (nhi_pdev); +bool ret = false; + +while (upstream) { +if (!pci_is_pcie (upstream)) +return false; +if (pci_pcie_type (upstream) ==PCI_EXP_TYPE_UPSTREAM ) +break ; + upstream =pci_upstream_bridge (upstream); + } + +if (!upstream) +return false; + +/* +* For each hotplug downstream port, create add device link +* back to NHI so that PCIe tunnels can be re-established after +* sleep. +*/ +pci_lock_rescan_remove (); +for_each_pci_bridge (pdev, upstream->subordinate) { +const struct device_link *link; + +if (!pci_is_pcie (pdev)) +continue ; +if (pci_pcie_type (pdev) !=PCI_EXP_TYPE_DOWNSTREAM || + !pdev->is_pciehp) +continue ; + + link =device_link_add (&pdev->dev, &nhi_pdev->dev, +DL_FLAG_AUTOREMOVE_SUPPLIER | +DL_FLAG_PM_RUNTIME ); +if (link) { +dev_dbg (&nhi_pdev->dev,"created link from %s\n" , +dev_name (&pdev->dev)); + ret = true; + }else { +dev_warn (&nhi_pdev->dev,"device link creation from %s failed\n" , +dev_name (&pdev->dev)); + } + } +pci_unlock_rescan_remove (); + +return ret; +}/* Ice Lake specific NHI operations */ #define ICL_LC_MAILBOX_TIMEOUT 500/* ms */
@@ -444,6 +492,31 @@ static const struct tb_nhi_ops icl_nhi_ops = { .init_interrupts = nhi_pci_init_msi, }; +/* +* During suspend the Thunderbolt controller is reset and all PCIe +* tunnels are lost. The NHI driver will try to reestablish all tunnels +* during resume. This adds device links between the tunneled PCIe +* downstream ports and the NHI so that the device core will make sure +* NHI is resumed first before the rest. +*/ +bool tb_pci_add_links (struct tb_nhi *nhi) +{ +struct pci_dev *nhi_pdev =to_pci_dev (nhi->dev); + +if (!x86_apple_machine) +return false; + +switch (nhi_pdev->device) { +case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE : +case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C : +case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI : +case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI : +return tb_pci_add_links_discrete (nhi_pdev); +default : +return false; + } +} +static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct device *dev = &pdev->dev;
drivers/thunderbolt/tb.c +1 -71
90 lines not on this page · raw message
drivers/thunderbolt/tb.h +1 -0
@@ -1506,6 +1506,7 @@ static inline bool usb4_port_device_is_offline(const struct usb4_port *usb4) }void tb_check_quirks (struct tb_switch *sw); +bool tb_pci_add_links (struct tb_nhi *nhi);#ifdef CONFIG_ACPI bool tb_acpi_add_links (struct tb_nhi *nhi);
Signature · 1 line
2.43.0
Re: [PATCH v8 1/3] thunderbolt: Shift tb_apple_add_links to pci.c
Quoted 39 lines · Atharva Tiwari
Shift
tb_apple_add_linkstopci.castb_apple_add_linkscalls pci functions.Suggested-by Mika Westerberg <[email protected]>Signed-off-by Atharva Tiwari <[email protected]>--- drivers/thunderbolt/pci.c | 73 +++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/tb.c | 72 +------------------------------------- drivers/thunderbolt/tb.h | 1 + 3 files changed, 75 insertions(+), 71 deletions(-)drivers/thunderbolt/pci.c +13
-0@@ -18,6 +18,7 @@#include <linux/property.h> #include <linux/string_helpers.h> #include <linux/suspend.h> +#include <linux/platform_data/x86/apple.h> #include "nhi.h" #include "nhi_regs.h" @@ -261,6 +262,53 @@ static const struct tb_nhi_ops pci_nhi_default_ops = { .init_interrupts = nhi_pci_init_msi, }; +static bool tb_pci_add_links_discrete (struct pci_dev *nhi_pdev) +{ +struct pci_dev *pdev, *upstream =pci_upstream_bridge (nhi_pdev); +bool ret = false; + +while (upstream) { +if (!pci_is_pcie (upstream)) +return false; +if (pci_pcie_type (upstream) ==PCI_EXP_TYPE_UPSTREAM ) +break ; + upstream =pci_upstream_bridge (upstream); + }
drivers/thunderbolt/pci.c static const struct tb_nhi_ops pci_nhi_default_ops = { · line 286
Quoted 10 lines
drivers/thunderbolt/pci.c +10
-0+ +if (!upstream) +return false; + +/* +* For each hotplug downstream port, create add device link +* back to NHI so that PCIe tunnels can be re-established after +* sleep. +*/ +pci_lock_rescan_remove ();
Is this really needed? We are not running any of the PCI rescan or removal functionality, I would expect it is enough to hold the references during this.
If this turns out to be needed please add a line to the commit message explaining why it is needed.
Quoted 171 lines
drivers/thunderbolt/pci.c +50
-0+for_each_pci_bridge (pdev, upstream->subordinate) { +const struct device_link *link; + +if (!pci_is_pcie (pdev)) +continue ; +if (pci_pcie_type (pdev) !=PCI_EXP_TYPE_DOWNSTREAM || + !pdev->is_pciehp) +continue ; + + link =device_link_add (&pdev->dev, &nhi_pdev->dev, +DL_FLAG_AUTOREMOVE_SUPPLIER | +DL_FLAG_PM_RUNTIME ); +if (link) { +dev_dbg (&nhi_pdev->dev,"created link from %s\n" , +dev_name (&pdev->dev)); + ret = true; + }else { +dev_warn (&nhi_pdev->dev,"device link creation from %s failed\n" , +dev_name (&pdev->dev)); + } + } +pci_unlock_rescan_remove (); + +return ret; +}/* Ice Lake specific NHI operations */ #define ICL_LC_MAILBOX_TIMEOUT 500/* ms */ @@ -444,6 +492,31 @@ static const struct tb_nhi_ops icl_nhi_ops = { .init_interrupts = nhi_pci_init_msi, }; +/* +* During suspend the Thunderbolt controller is reset and all PCIe +* tunnels are lost. The NHI driver will try to reestablish all tunnels +* during resume. This adds device links between the tunneled PCIe +* downstream ports and the NHI so that the device core will make sure +* NHI is resumed first before the rest. +*/ +bool tb_pci_add_links (struct tb_nhi *nhi) +{ +struct pci_dev *nhi_pdev =to_pci_dev (nhi->dev); + +if (!x86_apple_machine) +return false; + +switch (nhi_pdev->device) { +case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE : +case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C : +case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI : +case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI : +return tb_pci_add_links_discrete (nhi_pdev); +default : +return false; + } +} +static int nhi_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct device *dev = &pdev->dev;drivers/thunderbolt/tb.c +1
-71@@ -10,7 +10,6 @@#include <linux/errno.h> #include <linux/delay.h> #include <linux/pm_runtime.h> -#include <linux/platform_data/x86/apple.h> #include "tb.h" #include "tb_regs.h" @@ -3302,75 +3301,6 @@ static const struct tb_cm_ops tb_cm_ops = { .disconnect_xdomain_paths = tb_disconnect_xdomain_paths, }; -/* -* During suspend the Thunderbolt controller is reset and all PCIe -* tunnels are lost. The NHI driver will try to reestablish all tunnels -* during resume. This adds device links between the tunneled PCIe -* downstream ports and the NHI so that the device core will make sure -* NHI is resumed first before the rest. -*/ -static bool tb_apple_add_links (struct tb_nhi *nhi) -{ -struct pci_dev *nhi_pdev =to_pci_dev (nhi->dev); -struct pci_dev *upstream, *pdev; -bool ret; - -if (!x86_apple_machine) -return false; - -switch (nhi_pdev->device) { -case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE : -case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C : -case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI : -case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI : -break ; -default : -return false; - } - - upstream =pci_upstream_bridge (nhi_pdev); -while (upstream) { -if (!pci_is_pcie (upstream)) -return false; -if (pci_pcie_type (upstream) ==PCI_EXP_TYPE_UPSTREAM ) -break ; - upstream =pci_upstream_bridge (upstream); - } - -if (!upstream) -return false; - -/* -* For each hotplug downstream port, create add device link -* back to NHI so that PCIe tunnels can be re-established after -* sleep. -*/ - ret = false; -for_each_pci_bridge (pdev, upstream->subordinate) { -const struct device_link *link; - -if (!pci_is_pcie (pdev)) -continue ; -if (pci_pcie_type (pdev) !=PCI_EXP_TYPE_DOWNSTREAM || - !pdev->is_pciehp) -continue ; - - link =device_link_add (&pdev->dev, nhi->dev, -DL_FLAG_AUTOREMOVE_SUPPLIER | -DL_FLAG_PM_RUNTIME ); -if (link) { -dev_dbg (nhi->dev,"created link from %s\n" , -dev_name (&pdev->dev)); - ret = true; - }else { -dev_warn (nhi->dev,"device link creation from %s failed\n" , -dev_name (&pdev->dev)); - } - } - -return ret; -} -struct tb *tb_probe (struct tb_nhi *nhi) {struct tb_cm *tcm;@@ -3400,7 +3330,7 @@ struct tb *tb_probe(struct tb_nhi *nhi)* before the PCIe/USB stack is resumed so complain here if we * found them missing. */ -if (!tb_apple_add_links (nhi) && !tb_acpi_add_links (nhi)) +if (!tb_pci_add_links (nhi) && !tb_acpi_add_links (nhi))tb_warn (tb,"device links to tunneled native ports are missing!\n" );return tb;drivers/thunderbolt/tb.h +1
-0@@ -1506,6 +1506,7 @@ static inline bool usb4_port_device_is_offline(const struct usb4_port *usb4) }void tb_check_quirks (struct tb_switch *sw); +bool tb_pci_add_links (struct tb_nhi *nhi);#ifdef CONFIG_ACPI bool tb_acpi_add_links (struct tb_nhi *nhi);Signature · 1 line
2.43.0
PATCH v8 2/3 thunderbolt: Add device links for Apple machines with Titan Ridge
In reply to Atharva TiwariAdd device links for Apple machines with the
Titan Ridge thunderbolt controller.
To add device links on Titan ridge, the discrete method is used.
--- drivers/thunderbolt/pci.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/thunderbolt/pci.c +2 -0
@@ -511,6 +511,8 @@ bool tb_pci_add_links(struct tb_nhi *nhi)case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C :case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI :case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI : +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_NHI : +case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_NHI :return tb_pci_add_links_discrete (nhi_pdev);default :return false;
Signature · 1 line
2.43.0
PATCH v8 3/3 thunderbolt: Add device links for Apple systems with Icelake thunderbolt
In reply to Atharva TiwariIce Lake Thunderbolt NHI That are on some Macs. The NHI and its associated PCIe Root Ports all sit directly on the Root Complex with no upstream port. Identify the tunneled PCIe Root Ports by their PCI IDs and create device links back to the NHI so that PCIe tunnels can be re-established after sleep.
--- drivers/thunderbolt/pci.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
drivers/thunderbolt/pci.c +44 -0
@@ -492,6 +492,47 @@ static const struct tb_nhi_ops icl_nhi_ops = { .init_interrupts = nhi_pci_init_msi, }; +static bool tb_pci_add_links_icl (struct pci_dev *nhi_pdev) +{ +struct pci_dev *pdev; +const struct device_link *link; +bool ret = false; + +pci_lock_rescan_remove (); +for_each_pci_bridge (pdev, nhi_pdev->bus) { +if (!pci_is_pcie (pdev) || +pci_pcie_type (pdev) !=PCI_EXP_TYPE_ROOT_PORT ) +continue ; + +switch (pdev->device) { +/* Ice Lake Thunderbolt 3 PCIe Root Ports */ +case 0x8a1d : +case 0x8a1f : +case 0x8a21 : +case 0x8a23 : +break ; +default : +continue ; + } + + link =device_link_add (&pdev->dev, &nhi_pdev->dev, +DL_FLAG_AUTOREMOVE_SUPPLIER | +DL_FLAG_PM_RUNTIME ); +if (link) { +dev_dbg (&nhi_pdev->dev,"created link from %s\n" , +dev_name (&pdev->dev)); + ret = true; + }else { +dev_warn (&nhi_pdev->dev, +"device link creation from %s failed\n" , +dev_name (&pdev->dev)); + } + } +pci_unlock_rescan_remove (); + +return ret; +} +/* * During suspend the Thunderbolt controller is reset and all PCIe * tunnels are lost. The NHI driver will try to reestablish all tunnels
@@ -514,6 +555,9 @@ bool tb_pci_add_links(struct tb_nhi *nhi)case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_NHI :case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_NHI :return tb_pci_add_links_discrete (nhi_pdev); +case PCI_DEVICE_ID_INTEL_ICL_NHI0 : +case PCI_DEVICE_ID_INTEL_ICL_NHI1 : +return tb_pci_add_links_icl (nhi_pdev);default :return false; }
Signature · 1 line
2.43.0
Re: [PATCH v8 3/3] thunderbolt: Add device links for Apple systems with Icelake thunderbolt
Quoted 21 lines · Atharva Tiwari
Ice Lake Thunderbolt NHI That are on some Macs. The NHI and its associated PCIe Root Ports all sit directly on the Root Complex with no upstream port. Identify the tunneled PCIe Root Ports by their PCI IDs and create device links back to the NHI so that PCIe tunnels can be re-established after sleep.
Tested-by Alexander Fischer <[email protected]>Co-developed-by Andre Eikmeyer <[email protected]>Signed-off-by Andre Eikmeyer <[email protected]>Signed-off-by Atharva Tiwari <[email protected]>--- drivers/thunderbolt/pci.c | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/thunderbolt/pci.c +0
-0
drivers/thunderbolt/pci.c static const struct tb_nhi_ops icl_nhi_ops = { · line 501
Quoted 10 lines
drivers/thunderbolt/pci.c +7
-0@@ -492,6 +492,47 @@ static const struct tb_nhi_ops icl_nhi_ops = { .init_interrupts = nhi_pci_init_msi, }; +static bool tb_pci_add_links_icl (struct pci_dev *nhi_pdev) +{ +struct pci_dev *pdev; +const struct device_link *link; +bool ret = false; + +pci_lock_rescan_remove ();
Same comment here.
Otherwise this series looks good to me.
Quoted 49 lines
drivers/thunderbolt/pci.c +37
-0+for_each_pci_bridge (pdev, nhi_pdev->bus) { +if (!pci_is_pcie (pdev) || +pci_pcie_type (pdev) !=PCI_EXP_TYPE_ROOT_PORT ) +continue ; + +switch (pdev->device) { +/* Ice Lake Thunderbolt 3 PCIe Root Ports */ +case 0x8a1d : +case 0x8a1f : +case 0x8a21 : +case 0x8a23 : +break ; +default : +continue ; + } + + link =device_link_add (&pdev->dev, &nhi_pdev->dev, +DL_FLAG_AUTOREMOVE_SUPPLIER | +DL_FLAG_PM_RUNTIME ); +if (link) { +dev_dbg (&nhi_pdev->dev,"created link from %s\n" , +dev_name (&pdev->dev)); + ret = true; + }else { +dev_warn (&nhi_pdev->dev, +"device link creation from %s failed\n" , +dev_name (&pdev->dev)); + } + } +pci_unlock_rescan_remove (); + +return ret; +} +/* * During suspend the Thunderbolt controller is reset and all PCIe * tunnels are lost. The NHI driver will try to reestablish all tunnels @@ -514,6 +555,9 @@ bool tb_pci_add_links(struct tb_nhi *nhi)case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_NHI :case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_NHI :return tb_pci_add_links_discrete (nhi_pdev); +case PCI_DEVICE_ID_INTEL_ICL_NHI0 : +case PCI_DEVICE_ID_INTEL_ICL_NHI1 : +return tb_pci_add_links_icl (nhi_pdev);default :return false; }Signature · 1 line
2.43.0