Commit 4f348a8d authored by Hans de Goede's avatar Hans de Goede Committed by Jiri Slaby

libahci: Allow drivers to override start_engine

commit 039ece38 upstream.

Allwinner A10 and A20 ARM SoCs have an AHCI sata controller which needs a
special register to be poked before starting the DMA engine.

This register gets reset on an ahci_stop_engine call, so there is no other
place then ahci_start_engine where this poking can be done.

This commit allows drivers to override ahci_start_engine behavior for use by
the Allwinner AHCI driver (and potentially other drivers in the future).
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent f94234c7
...@@ -608,6 +608,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class, ...@@ -608,6 +608,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
unsigned long deadline) unsigned long deadline)
{ {
struct ata_port *ap = link->ap; struct ata_port *ap = link->ap;
struct ahci_host_priv *hpriv = ap->host->private_data;
bool online; bool online;
int rc; int rc;
...@@ -618,7 +619,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class, ...@@ -618,7 +619,7 @@ static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context), rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
deadline, &online, NULL); deadline, &online, NULL);
ahci_start_engine(ap); hpriv->start_engine(ap);
DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class); DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
...@@ -633,6 +634,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class, ...@@ -633,6 +634,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
{ {
struct ata_port *ap = link->ap; struct ata_port *ap = link->ap;
struct ahci_port_priv *pp = ap->private_data; struct ahci_port_priv *pp = ap->private_data;
struct ahci_host_priv *hpriv = ap->host->private_data;
u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
struct ata_taskfile tf; struct ata_taskfile tf;
bool online; bool online;
...@@ -648,7 +650,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class, ...@@ -648,7 +650,7 @@ static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context), rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
deadline, &online, NULL); deadline, &online, NULL);
ahci_start_engine(ap); hpriv->start_engine(ap);
/* The pseudo configuration device on SIMG4726 attached to /* The pseudo configuration device on SIMG4726 attached to
* ASUS P5W-DH Deluxe doesn't send signature FIS after * ASUS P5W-DH Deluxe doesn't send signature FIS after
......
...@@ -323,6 +323,12 @@ struct ahci_host_priv { ...@@ -323,6 +323,12 @@ struct ahci_host_priv {
u32 em_msg_type; /* EM message type */ u32 em_msg_type; /* EM message type */
struct clk *clk; /* Only for platforms supporting clk */ struct clk *clk; /* Only for platforms supporting clk */
void *plat_data; /* Other platform data */ void *plat_data; /* Other platform data */
/*
* Optional ahci_start_engine override, if not set this gets set to the
* default ahci_start_engine during ahci_save_initial_config, this can
* be overridden anytime before the host is activated.
*/
void (*start_engine)(struct ata_port *ap);
}; };
extern int ahci_ignore_sss; extern int ahci_ignore_sss;
......
...@@ -394,6 +394,9 @@ static ssize_t ahci_show_em_supported(struct device *dev, ...@@ -394,6 +394,9 @@ static ssize_t ahci_show_em_supported(struct device *dev,
* *
* If inconsistent, config values are fixed up by this function. * If inconsistent, config values are fixed up by this function.
* *
* If it is not set already this function sets hpriv->start_engine to
* ahci_start_engine.
*
* LOCKING: * LOCKING:
* None. * None.
*/ */
...@@ -500,6 +503,9 @@ void ahci_save_initial_config(struct device *dev, ...@@ -500,6 +503,9 @@ void ahci_save_initial_config(struct device *dev,
hpriv->cap = cap; hpriv->cap = cap;
hpriv->cap2 = cap2; hpriv->cap2 = cap2;
hpriv->port_map = port_map; hpriv->port_map = port_map;
if (!hpriv->start_engine)
hpriv->start_engine = ahci_start_engine;
} }
EXPORT_SYMBOL_GPL(ahci_save_initial_config); EXPORT_SYMBOL_GPL(ahci_save_initial_config);
...@@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_port *ap) ...@@ -766,7 +772,7 @@ static void ahci_start_port(struct ata_port *ap)
/* enable DMA */ /* enable DMA */
if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE)) if (!(hpriv->flags & AHCI_HFLAG_DELAY_ENGINE))
ahci_start_engine(ap); hpriv->start_engine(ap);
/* turn on LEDs */ /* turn on LEDs */
if (ap->flags & ATA_FLAG_EM) { if (ap->flags & ATA_FLAG_EM) {
...@@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap) ...@@ -1234,7 +1240,7 @@ int ahci_kick_engine(struct ata_port *ap)
/* restart engine */ /* restart engine */
out_restart: out_restart:
ahci_start_engine(ap); hpriv->start_engine(ap);
return rc; return rc;
} }
EXPORT_SYMBOL_GPL(ahci_kick_engine); EXPORT_SYMBOL_GPL(ahci_kick_engine);
...@@ -1426,6 +1432,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class, ...@@ -1426,6 +1432,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
struct ata_port *ap = link->ap; struct ata_port *ap = link->ap;
struct ahci_port_priv *pp = ap->private_data; struct ahci_port_priv *pp = ap->private_data;
struct ahci_host_priv *hpriv = ap->host->private_data;
u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
struct ata_taskfile tf; struct ata_taskfile tf;
bool online; bool online;
...@@ -1443,7 +1450,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class, ...@@ -1443,7 +1450,7 @@ static int ahci_hardreset(struct ata_link *link, unsigned int *class,
rc = sata_link_hardreset(link, timing, deadline, &online, rc = sata_link_hardreset(link, timing, deadline, &online,
ahci_check_ready); ahci_check_ready);
ahci_start_engine(ap); hpriv->start_engine(ap);
if (online) if (online)
*class = ahci_dev_classify(ap); *class = ahci_dev_classify(ap);
...@@ -2006,10 +2013,12 @@ static void ahci_thaw(struct ata_port *ap) ...@@ -2006,10 +2013,12 @@ static void ahci_thaw(struct ata_port *ap)
static void ahci_error_handler(struct ata_port *ap) static void ahci_error_handler(struct ata_port *ap)
{ {
struct ahci_host_priv *hpriv = ap->host->private_data;
if (!(ap->pflags & ATA_PFLAG_FROZEN)) { if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
/* restart engine */ /* restart engine */
ahci_stop_engine(ap); ahci_stop_engine(ap);
ahci_start_engine(ap); hpriv->start_engine(ap);
} }
sata_pmp_error_handler(ap); sata_pmp_error_handler(ap);
...@@ -2029,6 +2038,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc) ...@@ -2029,6 +2038,7 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
{ {
struct ahci_host_priv *hpriv = ap->host->private_data;
void __iomem *port_mmio = ahci_port_base(ap); void __iomem *port_mmio = ahci_port_base(ap);
struct ata_device *dev = ap->link.device; struct ata_device *dev = ap->link.device;
u32 devslp, dm, dito, mdat, deto; u32 devslp, dm, dito, mdat, deto;
...@@ -2092,7 +2102,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) ...@@ -2092,7 +2102,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
PORT_DEVSLP_ADSE); PORT_DEVSLP_ADSE);
writel(devslp, port_mmio + PORT_DEVSLP); writel(devslp, port_mmio + PORT_DEVSLP);
ahci_start_engine(ap); hpriv->start_engine(ap);
/* enable device sleep feature for the drive */ /* enable device sleep feature for the drive */
err_mask = ata_dev_set_feature(dev, err_mask = ata_dev_set_feature(dev,
...@@ -2104,6 +2114,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep) ...@@ -2104,6 +2114,7 @@ static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
static void ahci_enable_fbs(struct ata_port *ap) static void ahci_enable_fbs(struct ata_port *ap)
{ {
struct ahci_host_priv *hpriv = ap->host->private_data;
struct ahci_port_priv *pp = ap->private_data; struct ahci_port_priv *pp = ap->private_data;
void __iomem *port_mmio = ahci_port_base(ap); void __iomem *port_mmio = ahci_port_base(ap);
u32 fbs; u32 fbs;
...@@ -2132,11 +2143,12 @@ static void ahci_enable_fbs(struct ata_port *ap) ...@@ -2132,11 +2143,12 @@ static void ahci_enable_fbs(struct ata_port *ap)
} else } else
dev_err(ap->host->dev, "Failed to enable FBS\n"); dev_err(ap->host->dev, "Failed to enable FBS\n");
ahci_start_engine(ap); hpriv->start_engine(ap);
} }
static void ahci_disable_fbs(struct ata_port *ap) static void ahci_disable_fbs(struct ata_port *ap)
{ {
struct ahci_host_priv *hpriv = ap->host->private_data;
struct ahci_port_priv *pp = ap->private_data; struct ahci_port_priv *pp = ap->private_data;
void __iomem *port_mmio = ahci_port_base(ap); void __iomem *port_mmio = ahci_port_base(ap);
u32 fbs; u32 fbs;
...@@ -2164,7 +2176,7 @@ static void ahci_disable_fbs(struct ata_port *ap) ...@@ -2164,7 +2176,7 @@ static void ahci_disable_fbs(struct ata_port *ap)
pp->fbs_enabled = false; pp->fbs_enabled = false;
} }
ahci_start_engine(ap); hpriv->start_engine(ap);
} }
static void ahci_pmp_attach(struct ata_port *ap) static void ahci_pmp_attach(struct ata_port *ap)
......
...@@ -406,6 +406,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class, ...@@ -406,6 +406,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
static const unsigned long timing[] = { 5, 100, 500}; static const unsigned long timing[] = { 5, 100, 500};
struct ata_port *ap = link->ap; struct ata_port *ap = link->ap;
struct ahci_port_priv *pp = ap->private_data; struct ahci_port_priv *pp = ap->private_data;
struct ahci_host_priv *hpriv = ap->host->private_data;
u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
struct ata_taskfile tf; struct ata_taskfile tf;
bool online; bool online;
...@@ -434,7 +435,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class, ...@@ -434,7 +435,7 @@ static int ahci_highbank_hardreset(struct ata_link *link, unsigned int *class,
break; break;
} while (!online && retry--); } while (!online && retry--);
ahci_start_engine(ap); hpriv->start_engine(ap);
if (online) if (online)
*class = ahci_dev_classify(ap); *class = ahci_dev_classify(ap);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment