Skip to content

Commit fa89f53

Browse files
Evan Wanghtejun
authored andcommitted
libahci: Allow drivers to override stop_engine
Marvell armada37xx, armada7k and armada8k share the same AHCI sata controller IP, and currently there is an issue (Errata Ref#226)that the SATA can not be detected via SATA Port-MultiPlayer(PMP). After debugging, the reason is found that the value of Port-x FIS-based Switching Control (PxFBS@0x40) became wrong. According to design, the bits[11:8, 0] of register PxFBS are cleared when Port Command and Status (0x18) bit[0] changes its value from 1 to 0, i.e. falling edge of Port Command and Status bit[0] sends PULSE that resets PxFBS bits[11:8; 0]. So it needs save the port PxFBS register before PxCMD ST write and restore the port PxFBS register afterwards in ahci_stop_engine(). This commit allows drivers to override ahci_stop_engine behavior for use by the Marvell AHCI driver(and potentially other drivers in the future). Signed-off-by: Evan Wang <xswang@marvell.com> Cc: Ofer Heifetz <oferh@marvell.com> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent fd17ed6 commit fa89f53

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

drivers/ata/ahci.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
698698

699699
DPRINTK("ENTER\n");
700700

701-
ahci_stop_engine(ap);
701+
hpriv->stop_engine(ap);
702702

703703
rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
704704
deadline, &online, NULL);
@@ -724,7 +724,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
724724
bool online;
725725
int rc;
726726

727-
ahci_stop_engine(ap);
727+
hpriv->stop_engine(ap);
728728

729729
/* clear D2H reception area to properly wait for D2H FIS */
730730
ata_tf_init(link->device, &tf);
@@ -788,7 +788,7 @@ static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
788788

789789
DPRINTK("ENTER\n");
790790

791-
ahci_stop_engine(ap);
791+
hpriv->stop_engine(ap);
792792

793793
for (i = 0; i < 2; i++) {
794794
u16 val;

drivers/ata/ahci.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ struct ahci_host_priv {
365365
* be overridden anytime before the host is activated.
366366
*/
367367
void (*start_engine)(struct ata_port *ap);
368+
/*
369+
* Optional ahci_stop_engine override, if not set this gets set to the
370+
* default ahci_stop_engine during ahci_save_initial_config, this can
371+
* be overridden anytime before the host is activated.
372+
*/
373+
int (*stop_engine)(struct ata_port *ap);
374+
368375
irqreturn_t (*irq_handler)(int irq, void *dev_instance);
369376

370377
/* only required for per-port MSI(-X) support */

drivers/ata/ahci_qoriq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int ahci_qoriq_hardreset(struct ata_link *link, unsigned int *class,
9696

9797
DPRINTK("ENTER\n");
9898

99-
ahci_stop_engine(ap);
99+
hpriv->stop_engine(ap);
100100

101101
/*
102102
* There is a errata on ls1021a Rev1.0 and Rev2.0 which is:

drivers/ata/ahci_xgene.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static int xgene_ahci_restart_engine(struct ata_port *ap)
165165
PORT_CMD_ISSUE, 0x0, 1, 100))
166166
return -EBUSY;
167167

168-
ahci_stop_engine(ap);
168+
hpriv->stop_engine(ap);
169169
ahci_start_fis_rx(ap);
170170

171171
/*
@@ -421,7 +421,7 @@ static int xgene_ahci_hardreset(struct ata_link *link, unsigned int *class,
421421
portrxfis_saved = readl(port_mmio + PORT_FIS_ADDR);
422422
portrxfishi_saved = readl(port_mmio + PORT_FIS_ADDR_HI);
423423

424-
ahci_stop_engine(ap);
424+
hpriv->stop_engine(ap);
425425

426426
rc = xgene_ahci_do_hardreset(link, deadline, &online);
427427

drivers/ata/libahci.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ void ahci_save_initial_config(struct device *dev, struct ahci_host_priv *hpriv)
560560
if (!hpriv->start_engine)
561561
hpriv->start_engine = ahci_start_engine;
562562

563+
if (!hpriv->stop_engine)
564+
hpriv->stop_engine = ahci_stop_engine;
565+
563566
if (!hpriv->irq_handler)
564567
hpriv->irq_handler = ahci_single_level_irq_intr;
565568
}
@@ -897,9 +900,10 @@ static void ahci_start_port(struct ata_port *ap)
897900
static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
898901
{
899902
int rc;
903+
struct ahci_host_priv *hpriv = ap->host->private_data;
900904

901905
/* disable DMA */
902-
rc = ahci_stop_engine(ap);
906+
rc = hpriv->stop_engine(ap);
903907
if (rc) {
904908
*emsg = "failed to stop engine";
905909
return rc;
@@ -1310,7 +1314,7 @@ int ahci_kick_engine(struct ata_port *ap)
13101314
int busy, rc;
13111315

13121316
/* stop engine */
1313-
rc = ahci_stop_engine(ap);
1317+
rc = hpriv->stop_engine(ap);
13141318
if (rc)
13151319
goto out_restart;
13161320

@@ -1549,7 +1553,7 @@ int ahci_do_hardreset(struct ata_link *link, unsigned int *class,
15491553

15501554
DPRINTK("ENTER\n");
15511555

1552-
ahci_stop_engine(ap);
1556+
hpriv->stop_engine(ap);
15531557

15541558
/* clear D2H reception area to properly wait for D2H FIS */
15551559
ata_tf_init(link->device, &tf);
@@ -2075,14 +2079,14 @@ void ahci_error_handler(struct ata_port *ap)
20752079

20762080
if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
20772081
/* restart engine */
2078-
ahci_stop_engine(ap);
2082+
hpriv->stop_engine(ap);
20792083
hpriv->start_engine(ap);
20802084
}
20812085

20822086
sata_pmp_error_handler(ap);
20832087

20842088
if (!ata_dev_enabled(ap->link.device))
2085-
ahci_stop_engine(ap);
2089+
hpriv->stop_engine(ap);
20862090
}
20872091
EXPORT_SYMBOL_GPL(ahci_error_handler);
20882092

@@ -2129,7 +2133,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
21292133
return;
21302134

21312135
/* set DITO, MDAT, DETO and enable DevSlp, need to stop engine first */
2132-
rc = ahci_stop_engine(ap);
2136+
rc = hpriv->stop_engine(ap);
21332137
if (rc)
21342138
return;
21352139

@@ -2189,7 +2193,7 @@ static void ahci_enable_fbs(struct ata_port *ap)
21892193
return;
21902194
}
21912195

2192-
rc = ahci_stop_engine(ap);
2196+
rc = hpriv->stop_engine(ap);
21932197
if (rc)
21942198
return;
21952199

@@ -2222,7 +2226,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
22222226
return;
22232227
}
22242228

2225-
rc = ahci_stop_engine(ap);
2229+
rc = hpriv->stop_engine(ap);
22262230
if (rc)
22272231
return;
22282232

drivers/ata/sata_highbank.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
410410
int rc;
411411
int retry = 100;
412412

413-
ahci_stop_engine(ap);
413+
hpriv->stop_engine(ap);
414414

415415
/* clear D2H reception area to properly wait for D2H FIS */
416416
ata_tf_init(link->device, &tf);

0 commit comments

Comments
 (0)