Skip to content

Commit ab24d15

Browse files
edimoldovanclaude
andcommitted
PCI: apple: T6050 adopted ports: no ASPM, and a shutdown that holds the port
On the J714c the one-boot kernel (aurora's adopt path, the N1 in its ROM personality without firmware) froze 20-40 s after boot: user space first, then the whole SoC; a boot with pcie_aspm=off ran clean, a boot with the PCIe node disabled ran clean. The bus notifier that strips ASPM L1 from tunneled root ports now serves adopt_link hosts too and strips L0s and L1 from the adopted root ports, so the link stays in L0. A restart with the adopted link alive never came back to m1n1 (hard reset needed), while the same restart with the PCIe node disabled did. The platform driver gets a shutdown that puts each adopted port back into the boot stage's cold state: bridge decoding off, PME_Turn_Off and L2, PERST# asserted, the port and its lane clocks stopped (the first half of apple_pcie_t6050_reset_root_port, without the restart). Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 3ced3c2 commit ab24d15

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

‎drivers/pci/controller/pcie-apple.c‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3109,11 +3109,24 @@ static int apple_pcie_tunnel_pci_notify(struct notifier_block *nb,
31093109

31103110
switch (action) {
31113111
case BUS_NOTIFY_ADD_DEVICE:
3112+
/*
3113+
* T6050 adopted ports: no ASPM at all. On the J714c the N1 in its ROM
3114+
* personality (no firmware yet) takes the SoC down 20-40 s after the link
3115+
* first idles into L1; pcie_aspm=off runs clean.
3116+
*/
3117+
if (pcie->hw->adopt_link) {
3118+
if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT)
3119+
pcie_aspm_remove_cap(pdev, PCI_EXP_LNKCAP_ASPM_L0S |
3120+
PCI_EXP_LNKCAP_ASPM_L1);
3121+
break;
3122+
}
31123123
pm_runtime_get_noresume(&pdev->dev);
31133124
if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT)
31143125
pcie_aspm_remove_cap(pdev, PCI_EXP_LNKCAP_ASPM_L1);
31153126
break;
31163127
case BUS_NOTIFY_DEL_DEVICE:
3128+
if (pcie->hw->adopt_link)
3129+
break;
31173130
pm_runtime_put_noidle(&pdev->dev);
31183131
break;
31193132
}
@@ -3499,7 +3512,7 @@ static int apple_pcie_probe(struct platform_device *pdev)
34993512
}
35003513

35013514
/* Every function is added after this and removed before devres runs. */
3502-
if (pcie->tunnel_cold_init) {
3515+
if (pcie->tunnel_cold_init || pcie->hw->adopt_link) {
35033516
pcie->tunnel_pci_nb.notifier_call = apple_pcie_tunnel_pci_notify;
35043517
ret = bus_register_notifier(&pci_bus_type, &pcie->tunnel_pci_nb);
35053518
if (ret)
@@ -4055,6 +4068,48 @@ static void apple_pcie_remove(struct platform_device *pdev)
40554068
pci_unlock_rescan_remove();
40564069
}
40574070

4071+
/*
4072+
* A restart with an adopted port's link alive never reaches m1n1 on the J714c (hard
4073+
* reset needed). Put each adopted port back the way the boot stage leaves it on a
4074+
* cold start: bridge decoding off, link to L2, PERST# asserted, port and lane clocks
4075+
* stopped (the first half of apple_pcie_t6050_reset_root_port, without the restart).
4076+
*/
4077+
static void apple_pcie_shutdown(struct platform_device *pdev)
4078+
{
4079+
struct pci_host_bridge *bridge = platform_get_drvdata(pdev);
4080+
struct apple_pcie *pcie = pci_host_bridge_priv(bridge);
4081+
struct apple_pcie_port *port;
4082+
struct pci_dev *rp;
4083+
u32 value;
4084+
4085+
if (!pcie->hw->adopt_link)
4086+
return;
4087+
mutex_lock(&pcie->lock);
4088+
list_for_each_entry(port, &pcie->ports, entry) {
4089+
if (!port->perst || !port->base || !port->phy)
4090+
continue;
4091+
rp = pci_get_domain_bus_and_slot(pci_domain_nr(bridge->bus), 0,
4092+
PCI_DEVFN(port->idx, 0));
4093+
if (!rp)
4094+
continue;
4095+
pci_write_config_word(rp, PCI_COMMAND, 0);
4096+
if (!pci_read_config_dword(rp, PCI_PRIMARY_BUS, &value))
4097+
pci_write_config_dword(rp, PCI_PRIMARY_BUS, value & 0xff0000ff);
4098+
apple_pcie_port_writel(port, apple_pcie_port_readl(port, PORT_APPCLK) | 0x100,
4099+
PORT_APPCLK);
4100+
apple_pcie_port_writel(port, 0x11, 0x88);
4101+
apple_pcie_t6050_wait(port, port->base, 0x88, 1, 0, 500000);
4102+
apple_pcie_t6050_wait(port, port->base, PORT_LINKSTS, BIT(6), BIT(6), 500000);
4103+
WRITE_ONCE(port->link_failed, true);
4104+
apple_pcie_t6050_perst(port, true);
4105+
writel(readl(port->phy) & ~BIT(31), port->phy);
4106+
apple_pcie_t6050_port_disable(port, rp);
4107+
dev_info(pcie->dev, "port %d held for the restart\n", port->idx);
4108+
pci_dev_put(rp);
4109+
}
4110+
mutex_unlock(&pcie->lock);
4111+
}
4112+
40584113
static int apple_pcie_mark_power_lost(struct pci_dev *pdev, void *unused)
40594114
{
40604115
/*
@@ -4312,6 +4367,7 @@ MODULE_DEVICE_TABLE(of, apple_pcie_of_match);
43124367
static struct platform_driver apple_pcie_driver = {
43134368
.probe = apple_pcie_probe,
43144369
.remove = apple_pcie_remove,
4370+
.shutdown = apple_pcie_shutdown,
43154371
.driver = {
43164372
.name = "pcie-apple",
43174373
.of_match_table = apple_pcie_of_match,

0 commit comments

Comments
 (0)