diff --git a/drivers/nvme/host/apple-m5-sleep.h b/drivers/nvme/host/apple-m5-sleep.h index ee54f86486e87..3326fd068bd28 100644 --- a/drivers/nvme/host/apple-m5-sleep.h +++ b/drivers/nvme/host/apple-m5-sleep.h @@ -149,7 +149,7 @@ static int apple_nvme_m5_resources(struct apple_nvme *anv) if (!anv->hw->has_separate_nvmmu || !anv->lsq_in_nvmmu || !anv->hw->needs_ioq_registers || anv->hw->max_queue_depth != 64 || anv->hw->cold_reset || !anv->sart || - !(anv->hw->quirks & NVME_QUIRK_BROKEN_FUA)) + !(anv->ctrl.quirks & NVME_QUIRK_BROKEN_FUA)) return -EINVAL; for (i = 0; i < ARRAY_SIZE(required); i++) { struct resource *r = platform_get_resource_byname(pdev, diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index abb1d059eb98c..c2d527994b481 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -409,10 +409,16 @@ static inline void apple_nvme_writeq(struct apple_nvme *anv, u64 value, writeq(value, addr); } -unsigned int flush_interval = 1000; +/* + * A non-zero grace period completes a flush that arrives within it at once, + * before the data reaches the drive, and sends one flush when the period + * ends. A power loss in between loses data the filesystem was told is safe, + * so every flush goes to the drive unless the user opts in. + */ +static unsigned int flush_interval; module_param(flush_interval, uint, 0644); MODULE_PARM_DESC(flush_interval, - "Grace period in msecs between flushes (ignored on post-M4 ANS)"); + "Grace period in msecs between flushes; a non-zero value acknowledges flushes before they reach the drive (default 0, read when the controller probes, ignored on post-M4 ANS)"); /* * Stop ANS for a deep sleep on a controller whose sleep path was never run. Off by default: @@ -3409,9 +3415,18 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) anv->crypto_profile.dev = dev; } + /* + * ANS acknowledges a Write with FUA set while the data is still only in + * its volatile cache: on T8112 FUA writes acknowledged up to ~360 ms + * before an abrupt reset were gone after it, and on T8140 an fsynced + * overwrite reverted the same way, as on T8132. Every ANS is treated + * the same, so the block layer follows each FUA write with a flush. + * The T6050 sleep checks for this quirk in ctrl.quirks. + */ ret = nvme_init_ctrl(&anv->ctrl, anv->dev, &nvme_ctrl_ops, NVME_QUIRK_SKIP_CID_GEN | NVME_QUIRK_IDENTIFY_CNS | - NVME_QUIRK_ADMIN_PAGE_ALIGN | anv->hw->quirks); + NVME_QUIRK_ADMIN_PAGE_ALIGN | NVME_QUIRK_BROKEN_FUA | + anv->hw->quirks); if (ret) { dev_err_probe(dev, ret, "Failed to initialize nvme_ctrl"); goto out_detach_genpd; @@ -4051,8 +4066,6 @@ static const struct apple_nvme_hw apple_nvme_t8132_hw = { .sleep_epmap_last_mask = BIT(0), .sleep_flush_max_nsid = 1, .sleep_shn = NVME_CC_SHN_MASK, - /* Explicit flushes are required for writes to survive a reset on J713. */ - .quirks = NVME_QUIRK_BROKEN_FUA, }; static const struct apple_nvme_hw apple_nvme_t8140_hw = { @@ -4064,12 +4077,6 @@ static const struct apple_nvme_hw apple_nvme_t8140_hw = { .sleep_epmap_last_mask = BIT(0), .sleep_flush_max_nsid = 1, .sleep_shn = NVME_CC_SHN_MASK, - /* - * An fsynced overwrite completed and later reverted after an abrupt - * reset; explicit flushes persisted the preceding data. Let the block - * layer follow each FUA write with a flush. - */ - .quirks = NVME_QUIRK_BROKEN_FUA, }; /* @@ -4086,7 +4093,6 @@ static const struct apple_nvme_hw apple_nvme_t8142_hw = { .sleep_epmap_last_mask = BIT(0), .sleep_flush_max_nsid = 1, .sleep_shn = NVME_CC_SHN_MASK, - .quirks = NVME_QUIRK_BROKEN_FUA, }; /* @@ -4121,8 +4127,7 @@ static const struct apple_nvme_hw apple_nvme_t6050_hw = { .lsq_in_nvmmu = true, .reset_optional = true, .max_queue_depth = 64, - /* FUA is not shown durable on this ANS: flush instead. */ - .quirks = NVME_QUIRK_NO_APST | NVME_QUIRK_BROKEN_FUA, + .quirks = NVME_QUIRK_NO_APST, }; /* @@ -4138,7 +4143,6 @@ static const struct apple_nvme_hw apple_nvme_t8152_hw = { .secure_reg_layout = true, .shutdown_notify = true, .max_queue_depth = 64, - .quirks = NVME_QUIRK_BROKEN_FUA, }; static const struct of_device_id apple_nvme_of_match[] = {