Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions arch/arm64/boot/dts/apple/t8010.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,13 @@
reg = <0x0 0x0 0x0 0x0 0x0>;
reset-gpios = <&pinctrl_ap 12 GPIO_ACTIVE_LOW>;
clkreq-gpios = <&pinctrl_ap 16 GPIO_ACTIVE_LOW>;
/*
* Port 0 keeps CLKREQ# in software GPIO input
* mode rather than hardware PCIe pinmux, so
* block L1 PM Substates (L1.1/L1.2) while
* still allowing ASPM L1.
*/
aspm-no-l1ss;

#address-cells = <3>;
#size-cells = <2>;
Expand Down
68 changes: 57 additions & 11 deletions drivers/nvme/host/pci-apple-ans.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct apple_ans_nvme_req {
* @sleep_stop: the controller's port loses power in system sleep: stop the
* controller first, as iOS (AppleEmbeddedNVMeController) does,
* and bring it up from reset on resume
* @l1ss_enable: allow PCIe L1 PM Substates (L1.1/L1.2) on links whose root
* port has hardware CLKREQ# pinmux and REFCLK gating
* @read_only: diagnostic host rejects media changes and optional feature setup
* @primary_ns_writes: diagnostic exception for namespace 1 Write and Flush
*/
Expand All @@ -67,10 +69,15 @@ struct apple_ans_host {
unsigned int rdy_timeout_ms;
bool late_bus_master;
bool sleep_stop;
bool l1ss_enable;
bool read_only;
bool primary_ns_writes;
};

/*
* S8000/S8001/S8003 keep REFCLK ungated (S8003_RC_PORT_PWR_REFCLK_NOGATE), so
* leave l1ss_enable false.
*/
static const struct apple_ans_host apple_ans_host_s8003 = {
.l1ss_ctl1 = APPLE_ANS_L1SS_CTL1_S8003,
/*
Expand All @@ -93,15 +100,30 @@ static const struct apple_ans_host apple_ans_host_s8001 = {
.read_only = true,
};

/*
* T8010 keeps port 0 CLKREQ# in software GPIO input mode (clkreq-gpios)
* rather than hardware PCIe pinmux, so leave l1ss_enable false.
*/
static const struct apple_ans_host apple_ans_host_t8010 = {
.l1ss_ctl1 = APPLE_ANS_L1SS_CTL1_T8010,
.sleep_stop = true,
};

/* J120 uses the same L1SS control, verified against its native port data. */
/*
* T8011 pinmuxes port 0 CLKREQ# to the PCIe controller and allows REFCLK
* gating, so ASPM L1.1/L1.2 work on the ANS link.
*/
static const struct apple_ans_host apple_ans_host_t8011 = {
.l1ss_ctl1 = APPLE_ANS_L1SS_CTL1_T8010,
.sleep_stop = true,
.l1ss_enable = true,
};

/* J120 is a T8011 board with the same hardware CLKREQ# pinmux and L1SS support. */
static const struct apple_ans_host apple_ans_host_j120 = {
.l1ss_ctl1 = APPLE_ANS_L1SS_CTL1_T8010,
.sleep_stop = true,
.l1ss_enable = true,
/* Namespace writes and their recovery path are not yet qualified. */
.read_only = true,
/* Isolated write-qualification candidate; never enable auxiliary writes. */
Expand Down Expand Up @@ -134,8 +156,7 @@ static const struct of_device_id nvme_pci_apple_ans_hosts[] = {
{ .compatible = "apple,s8001-pcie", .data = &apple_ans_host_s8001 },
{ .compatible = "apple,s8003-pcie", .data = &apple_ans_host_s8003 },
{ .compatible = "apple,t8010-pcie", .data = &apple_ans_host_t8010 },
/* The A10X storage port carries the A10's ANS controller. */
{ .compatible = "apple,t8011-pcie", .data = &apple_ans_host_t8010 },
{ .compatible = "apple,t8011-pcie", .data = &apple_ans_host_t8011 },
{ }
};

Expand Down Expand Up @@ -182,10 +203,11 @@ unsigned long nvme_pci_apple_ans_quirks(struct pci_dev *pdev)

static int nvme_pci_apple_ans_init(struct nvme_dev *dev, int node)
{
struct pci_dev *pdev = to_pci_dev(dev->dev);
const struct of_device_id *match;
struct apple_ans_nvme *ans;

match = nvme_pci_apple_ans_host_match(to_pci_dev(dev->dev));
match = nvme_pci_apple_ans_host_match(pdev);
if (!match)
return -ENODEV;

Expand All @@ -198,6 +220,27 @@ static int nvme_pci_apple_ans_init(struct nvme_dev *dev, int node)
dev->sleep_stop = ans->host->sleep_stop;
spin_lock_init(&ans->req_lock);
dev->dma_data = ans;

/*
* Configure L1 PM Substates once during probe, before reset_work is
* queued (avoiding pci_bus_sem recursion under AER recovery) and
* before pci_enable_device_mem() applies ASPM policy.
*/
if (ans->host->l1ss_enable) {
pci_set_power_state(pdev, PCI_D0);
pci_enable_link_state(pdev,
PCIE_LINK_STATE_L1 |
PCIE_LINK_STATE_L1_1 |
PCIE_LINK_STATE_L1_2 |
PCIE_LINK_STATE_L1_1_PCIPM |
PCIE_LINK_STATE_L1_2_PCIPM);
} else {
pci_disable_link_state(pdev,
PCIE_LINK_STATE_L1_1 |
PCIE_LINK_STATE_L1_2 |
PCIE_LINK_STATE_L1_1_PCIPM |
PCIE_LINK_STATE_L1_2_PCIPM);
}
return 0;
}

Expand Down Expand Up @@ -286,7 +329,7 @@ static int nvme_pci_apple_ans_config(struct nvme_dev *dev)
{
struct apple_ans_nvme *ans = nvme_pci_apple_ans(dev);
struct pci_dev *pdev = to_pci_dev(dev->dev);
u16 ltr, l1ss;
u16 ltr;

if (pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40))
return -EIO;
Expand All @@ -296,12 +339,15 @@ static int nvme_pci_apple_ans_config(struct nvme_dev *dev)
APPLE_ANS_LTR_MAX_LATENCY))
return -EIO;

l1ss = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_L1SS);
if (l1ss &&
(pci_write_config_dword(pdev, l1ss + PCI_L1SS_CTL2, 0) ||
pci_write_config_dword(pdev, l1ss + PCI_L1SS_CTL1,
ans->host->l1ss_ctl1)))
return -EIO;
if (!ans->host->l1ss_enable) {
u16 l1ss = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_L1SS);

if (l1ss &&
(pci_write_config_dword(pdev, l1ss + PCI_L1SS_CTL2, 0) ||
pci_write_config_dword(pdev, l1ss + PCI_L1SS_CTL1,
ans->host->l1ss_ctl1)))
return -EIO;
}

return 0;
}
Expand Down
8 changes: 8 additions & 0 deletions drivers/pci/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -6332,6 +6332,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56b0, aspm_l1_acceptable_latency
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56b1, aspm_l1_acceptable_latency);
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c0, aspm_l1_acceptable_latency);
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c1, aspm_l1_acceptable_latency);

/*
* Apple S3E (ANS) NVMe controllers (106b:2002) advertise an L1 acceptable
* latency of <32us (0x5) in DevCap while pairing exclusively with Apple
* H8/H9 root ports that report <64us (0x6) L1 exit latency, preventing
* ASPM L1 from being enabled despite the controller supporting L1/L1SS.
*/
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_APPLE, 0x2002, aspm_l1_acceptable_latency);
#endif

#ifdef CONFIG_PCIE_DPC
Expand Down
Loading