History

Merge tag 'libata-5.5-20191226' of git://git.kernel.dk/linux-block

Pull libata fixes from Jens Axboe: "Two things in here: - First half of a series that fixes ahci_brcm, also marked for stable. The other part of the series is going into 5.6 (Florian) - sata_nv regression fix that is also marked for stable (Sascha)" * tag 'libata-5.5-20191226' of git://git.kernel.dk/linux-block: ata: ahci_brcm: Add missing clock management during recovery ata: ahci_brcm: BCM7425 AHCI requires AHCI_HFLAG_DELAY_ENGINE ata: ahci_brcm: Fix AHCI resources management ata: libahci_platform: Export again ahci_platform_<en/dis>able_phys() libata: Fix retrieving of active qcs

Linus Torvalds committed 6 years ago

Commit 0f710a52 parents 8ae40a6 bf0e5018 files · +128 −44Browse files

Unified · Split

8 files
  1. drivers/ata/ahci_brcm.c +94 −39
  2. drivers/ata/libahci_platform.c +4 −2
  3. drivers/ata/libata-core.c +24 −0
  4. drivers/ata/sata_fsl.c +1 −1
  5. drivers/ata/sata_mv.c +1 −1
  6. drivers/ata/sata_nv.c +1 −1
  7. include/linux/ahci_platform.h +2 −0
  8. include/linux/libata.h +1 −0
drivers/ata/ahci_brcm.c+94−39
@@ -76,8 +76,7 @@ enum brcm_ahci_version { · 75 unmodified lines
7676 };
7777
7878 enum brcm_ahci_quirks {
79− BRCM_AHCI_QUIRK_NO_NCQ = BIT(0),
80− BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE = BIT(1),
79+ BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE = BIT(0),
8180 };
8281
8382 struct brcm_ahci_priv {
@@ -213,19 +212,12 @@ static void brcm_sata_phys_disable(struct brcm_ahci_priv *priv) · 129 unmodified lines
213212 brcm_sata_phy_disable(priv, i);
214213 }
215214
216−static u32 brcm_ahci_get_portmask(struct platform_device *pdev,
215+static u32 brcm_ahci_get_portmask(struct ahci_host_priv *hpriv,
217216 struct brcm_ahci_priv *priv)
218217 {
219− void __iomem *ahci;
220− struct resource *res;
221218 u32 impl;
222219
223− res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ahci");
224− ahci = devm_ioremap_resource(&pdev->dev, res);
225− if (IS_ERR(ahci))
226− return 0;
227−
228− impl = readl(ahci + HOST_PORTS_IMPL);
220+ impl = readl(hpriv->mmio + HOST_PORTS_IMPL);
229221
230222 if (fls(impl) > SATA_TOP_MAX_PHYS)
231223 dev_warn(priv->dev, "warning: more ports than PHYs (%#x)\n",
@@ -233,9 +225,6 @@ static u32 brcm_ahci_get_portmask(struct platform_device *pdev, · 1 unmodified line
233225 else if (!impl)
234226 dev_info(priv->dev, "no ports found\n");
235227
236− devm_iounmap(&pdev->dev, ahci);
237− devm_release_mem_region(&pdev->dev, res->start, resource_size(res));
238−
239228 return impl;
240229 }
241230
@@ -285,6 +274,13 @@ static unsigned int brcm_ahci_read_id(struct ata_device *dev, · 43 unmodified lines
285274 /* Perform the SATA PHY reset sequence */
286275 brcm_sata_phy_disable(priv, ap->port_no);
287276
277+ /* Reset the SATA clock */
278+ ahci_platform_disable_clks(hpriv);
279+ msleep(10);
280+
281+ ahci_platform_enable_clks(hpriv);
282+ msleep(10);
283+
288284 /* Bring the PHY back on */
289285 brcm_sata_phy_enable(priv, ap->port_no);
290286
@@ -347,11 +343,10 @@ static int brcm_ahci_suspend(struct device *dev) · 56 unmodified lines
347343 struct ata_host *host = dev_get_drvdata(dev);
348344 struct ahci_host_priv *hpriv = host->private_data;
349345 struct brcm_ahci_priv *priv = hpriv->plat_data;
350− int ret;
351346
352− ret = ahci_platform_suspend(dev);
353347 brcm_sata_phys_disable(priv);
354− return ret;
348+
349+ return ahci_platform_suspend(dev);
355350 }
356351
357352 static int brcm_ahci_resume(struct device *dev)
@@ -359,11 +354,44 @@ static int brcm_ahci_resume(struct device *dev) · 1 unmodified line
359354 struct ata_host *host = dev_get_drvdata(dev);
360355 struct ahci_host_priv *hpriv = host->private_data;
361356 struct brcm_ahci_priv *priv = hpriv->plat_data;
357+ int ret;
358+
359+ /* Make sure clocks are turned on before re-configuration */
360+ ret = ahci_platform_enable_clks(hpriv);
361+ if (ret)
362+ return ret;
362363
363364 brcm_sata_init(priv);
364365 brcm_sata_phys_enable(priv);
365366 brcm_sata_alpm_init(hpriv);
366− return ahci_platform_resume(dev);
367+
368+ /* Since we had to enable clocks earlier on, we cannot use
369+ * ahci_platform_resume() as-is since a second call to
370+ * ahci_platform_enable_resources() would bump up the resources
371+ * (regulators, clocks, PHYs) count artificially so we copy the part
372+ * after ahci_platform_enable_resources().
373+ */
374+ ret = ahci_platform_enable_phys(hpriv);
375+ if (ret)
376+ goto out_disable_phys;
377+
378+ ret = ahci_platform_resume_host(dev);
379+ if (ret)
380+ goto out_disable_platform_phys;
381+
382+ /* We resumed so update PM runtime state */
383+ pm_runtime_disable(dev);
384+ pm_runtime_set_active(dev);
385+ pm_runtime_enable(dev);
386+
387+ return 0;
388+
389+out_disable_platform_phys:
390+ ahci_platform_disable_phys(hpriv);
391+out_disable_phys:
392+ brcm_sata_phys_disable(priv);
393+ ahci_platform_disable_clks(hpriv);
394+ return ret;
367395 }
368396 #endif
369397
@@ -410,44 +438,71 @@ static int brcm_ahci_probe(struct platform_device *pdev) · 40 unmodified lines
410438 if (!IS_ERR_OR_NULL(priv->rcdev))
411439 reset_control_deassert(priv->rcdev);
412440
413− if ((priv->version == BRCM_SATA_BCM7425) ||
414− (priv->version == BRCM_SATA_NSP)) {
415− priv->quirks |= BRCM_AHCI_QUIRK_NO_NCQ;
441+ hpriv = ahci_platform_get_resources(pdev, 0);
442+ if (IS_ERR(hpriv)) {
443+ ret = PTR_ERR(hpriv);
444+ goto out_reset;
445+ }
446+
447+ hpriv->plat_data = priv;
448+ hpriv->flags = AHCI_HFLAG_WAKE_BEFORE_STOP | AHCI_HFLAG_NO_WRITE_TO_RO;
449+
450+ switch (priv->version) {
451+ case BRCM_SATA_BCM7425:
452+ hpriv->flags |= AHCI_HFLAG_DELAY_ENGINE;
453+ /* fall through */
454+ case BRCM_SATA_NSP:
455+ hpriv->flags |= AHCI_HFLAG_NO_NCQ;
416456 priv->quirks |= BRCM_AHCI_QUIRK_SKIP_PHY_ENABLE;
457+ break;
458+ default:
459+ break;
417460 }
418461
462+ ret = ahci_platform_enable_clks(hpriv);
463+ if (ret)
464+ goto out_reset;
465+
466+ /* Must be first so as to configure endianness including that
467+ * of the standard AHCI register space.
468+ */
419469 brcm_sata_init(priv);
420470
421− priv->port_mask = brcm_ahci_get_portmask(pdev, priv);
422− if (!priv->port_mask)
423− return -ENODEV;
471+ /* Initializes priv->port_mask which is used below */
472+ priv->port_mask = brcm_ahci_get_portmask(hpriv, priv);
473+ if (!priv->port_mask) {
474+ ret = -ENODEV;
475+ goto out_disable_clks;
476+ }
424477
478+ /* Must be done before ahci_platform_enable_phys() */
425479 brcm_sata_phys_enable(priv);
426480
427− hpriv = ahci_platform_get_resources(pdev, 0);
428− if (IS_ERR(hpriv))
429− return PTR_ERR(hpriv);
430− hpriv->plat_data = priv;
431− hpriv->flags = AHCI_HFLAG_WAKE_BEFORE_STOP;
432−
433481 brcm_sata_alpm_init(hpriv);
434482
435− ret = ahci_platform_enable_resources(hpriv);
483+ ret = ahci_platform_enable_phys(hpriv);
436484 if (ret)
437− return ret;
438−
439− if (priv->quirks & BRCM_AHCI_QUIRK_NO_NCQ)
440− hpriv->flags |= AHCI_HFLAG_NO_NCQ;
441− hpriv->flags |= AHCI_HFLAG_NO_WRITE_TO_RO;
485+ goto out_disable_phys;
442486
443487 ret = ahci_platform_init_host(pdev, hpriv, &ahci_brcm_port_info,
444488 &ahci_platform_sht);
445489 if (ret)
446− return ret;
490+ goto out_disable_platform_phys;
447491
448492 dev_info(dev, "Broadcom AHCI SATA3 registered\n");
449493
450494 return 0;
495+
496+out_disable_platform_phys:
497+ ahci_platform_disable_phys(hpriv);
498+out_disable_phys:
499+ brcm_sata_phys_disable(priv);
500+out_disable_clks:
501+ ahci_platform_disable_clks(hpriv);
502+out_reset:
503+ if (!IS_ERR_OR_NULL(priv->rcdev))
504+ reset_control_assert(priv->rcdev);
505+ return ret;
451506 }
452507
453508 static int brcm_ahci_remove(struct platform_device *pdev)
@@ -457,12 +512,12 @@ static int brcm_ahci_remove(struct platform_device *pdev) · 3 unmodified lines
457512 struct brcm_ahci_priv *priv = hpriv->plat_data;
458513 int ret;
459514
515+ brcm_sata_phys_disable(priv);
516+
460517 ret = ata_platform_remove_one(pdev);
461518 if (ret)
462519 return ret;
463520
464− brcm_sata_phys_disable(priv);
465−
466521 return 0;
467522 }
468523
drivers/ata/libahci_platform.c+4−2
@@ -43,7 +43,7 @@ EXPORT_SYMBOL_GPL(ahci_platform_ops); · 42 unmodified lines
4343 * RETURNS:
4444 * 0 on success otherwise a negative error code
4545 */
46−static int ahci_platform_enable_phys(struct ahci_host_priv *hpriv)
46+int ahci_platform_enable_phys(struct ahci_host_priv *hpriv)
4747 {
4848 int rc, i;
4949
@@ -74,6 +74,7 @@ disable_phys: · 24 unmodified lines
7474 }
7575 return rc;
7676 }
77+EXPORT_SYMBOL_GPL(ahci_platform_enable_phys);
7778
7879 /**
7980 * ahci_platform_disable_phys - Disable PHYs
@@ -81,7 +82,7 @@ disable_phys: · 1 unmodified line
8182 *
8283 * This function disables all PHYs found in hpriv->phys.
8384 */
84−static void ahci_platform_disable_phys(struct ahci_host_priv *hpriv)
85+void ahci_platform_disable_phys(struct ahci_host_priv *hpriv)
8586 {
8687 int i;
8788
@@ -90,6 +91,7 @@ static void ahci_platform_disable_phys(struct ahci_host_priv *hpriv) · 2 unmodified lines
9091 phy_exit(hpriv->phys[i]);
9192 }
9293 }
94+EXPORT_SYMBOL_GPL(ahci_platform_disable_phys);
9395
9496 /**
9597 * ahci_platform_enable_clks - Enable platform clocks
drivers/ata/libata-core.c+24−0
@@ -5328,6 +5328,30 @@ void ata_qc_complete(struct ata_queued_cmd *qc) · 5327 unmodified lines
53285328 }
53295329 }
53305330
5331+/**
5332+ * ata_qc_get_active - get bitmask of active qcs
5333+ * @ap: port in question
5334+ *
5335+ * LOCKING:
5336+ * spin_lock_irqsave(host lock)
5337+ *
5338+ * RETURNS:
5339+ * Bitmask of active qcs
5340+ */
5341+u64 ata_qc_get_active(struct ata_port *ap)
5342+{
5343+ u64 qc_active = ap->qc_active;
5344+
5345+ /* ATA_TAG_INTERNAL is sent to hw as tag 0 */
5346+ if (qc_active & (1ULL << ATA_TAG_INTERNAL)) {
5347+ qc_active |= (1 << 0);
5348+ qc_active &= ~(1ULL << ATA_TAG_INTERNAL);
5349+ }
5350+
5351+ return qc_active;
5352+}
5353+EXPORT_SYMBOL_GPL(ata_qc_get_active);
5354+
53315355 /**
53325356 * ata_qc_complete_multiple - Complete multiple qcs successfully
53335357 * @ap: port in question
drivers/ata/sata_fsl.c+1−1
@@ -1280,7 +1280,7 @@ static void sata_fsl_host_intr(struct ata_port *ap) · 1279 unmodified lines
12801280 i, ioread32(hcr_base + CC),
12811281 ioread32(hcr_base + CA));
12821282 }
1283− ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
1283+ ata_qc_complete_multiple(ap, ata_qc_get_active(ap) ^ done_mask);
12841284 return;
12851285
12861286 } else if ((ap->qc_active & (1ULL << ATA_TAG_INTERNAL))) {
drivers/ata/sata_mv.c+1−1
@@ -2829,7 +2829,7 @@ static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp · 2828 unmodified lines
28292829 }
28302830
28312831 if (work_done) {
2832− ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
2832+ ata_qc_complete_multiple(ap, ata_qc_get_active(ap) ^ done_mask);
28332833
28342834 /* Update the software queue position index in hardware */
28352835 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) |
drivers/ata/sata_nv.c+1−1
@@ -984,7 +984,7 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance) · 983 unmodified lines
984984 check_commands = 0;
985985 check_commands &= ~(1 << pos);
986986 }
987− ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
987+ ata_qc_complete_multiple(ap, ata_qc_get_active(ap) ^ done_mask);
988988 }
989989 }
990990
include/linux/ahci_platform.h+2−0
@@ -19,6 +19,8 @@ struct ahci_host_priv; · 18 unmodified lines
1919 struct platform_device;
2020 struct scsi_host_template;
2121
22+int ahci_platform_enable_phys(struct ahci_host_priv *hpriv);
23+void ahci_platform_disable_phys(struct ahci_host_priv *hpriv);
2224 int ahci_platform_enable_clks(struct ahci_host_priv *hpriv);
2325 void ahci_platform_disable_clks(struct ahci_host_priv *hpriv);
2426 int ahci_platform_enable_regulators(struct ahci_host_priv *hpriv);
include/linux/libata.h+1−0
@@ -1175,6 +1175,7 @@ extern unsigned int ata_do_dev_read_id(struct ata_device *dev, · 1174 unmodified lines
11751175 struct ata_taskfile *tf, u16 *id);
11761176 extern void ata_qc_complete(struct ata_queued_cmd *qc);
11771177 extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
1178+extern u64 ata_qc_get_active(struct ata_port *ap);
11781179 extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
11791180 extern int ata_std_bios_param(struct scsi_device *sdev,
11801181 struct block_device *bdev,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t