ata: ahci_brcmstb: ALPM support
Subsystems (2)
cover ata: ahci_brcmstb: ALPM support
Hi Tejun,
This patch series contains a bunch of changes to the Broadcom AHCI driver to support ALPM, disable DIPM (not supported) and updates the core libata to account for driver-specific ALPM-resume procedure.
The last patch in this series allows some particular drivers, which are known not to need the debounce delay while resuming SATA links to skip these, which yields a faster resume time.
This is against your ata/for-next branch, thanks!
Danesh Petigara (4):
ata: ahci_brcmstb: enable support for ALPM
ata: ahci_brcmstb: disable DIPM support
drivers: ata: wake port before DMA stop for ALPM
libata: skip debounce delay on link resume
drivers/ata/ahci.h | 6 ++++++ drivers/ata/ahci_brcmstb.c | 40 ++++++++++++++++++++++++++++++++++- drivers/ata/libahci.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 4 +++- include/linux/libata.h | 5 +++++ 5 files changed, 105 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/4 ata: ahci_brcmstb: enable support for ALPM
From: Danesh Petigara <[email protected]>
Enable support for ALPM in the host controller's capabilities register. Also adjust the PLL timeout to give it enough time to lock when the port exits slumber mode.
--- drivers/ata/ahci_brcmstb.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/ata/ahci_brcmstb.c +36 -0
@@ -53,6 +53,10 @@#define SATA_TOP_CTRL_PHY_OFFS 0x8#define SATA_TOP_MAX_PHYS 2 +#define SATA_FIRST_PORT_CTRL 0x700 +#define SATA_NEXT_PORT_CTRL_OFFSET 0x80 +#define SATA_PORT_PCTRL6 (reg_base) (reg_base + 0x18) +/* On big-endian MIPS, buses are reversed to big endian, so switch them back */ #if defined(CONFIG_MIPS ) && defined(__BIG_ENDIAN)#define DATA_ENDIAN 2/* AHCI->DDR inbound accesses */
@@ -111,6 +115,35 @@ static inline void brcm_sata_writereg(u32 val, void __iomem *addr)writel_relaxed (val, addr); } +static void brcm_sata_alpm_init (struct ahci_host_priv *hpriv) +{ +int i; +u32 bus_ctrl, port_ctrl, host_caps; +struct brcm_ahci_priv *priv = hpriv->plat_data; + +/*Enable support for ALPM */ + bus_ctrl =brcm_sata_readreg (priv->top_ctrl + +SATA_TOP_CTRL_BUS_CTRL ); +brcm_sata_writereg (bus_ctrl |OVERRIDE_HWINIT , + priv->top_ctrl +SATA_TOP_CTRL_BUS_CTRL ); + host_caps =readl (hpriv->mmio +HOST_CAP ); +writel (host_caps |HOST_CAP_ALPM , hpriv->mmio); +brcm_sata_writereg (bus_ctrl, + priv->top_ctrl +SATA_TOP_CTRL_BUS_CTRL ); + +/* +* Adjust timeout to allow PLL sufficient time to lock while waking +* up from slumber mode. +*/ +for (i =0 , port_ctrl =SATA_FIRST_PORT_CTRL ; + i <SATA_TOP_MAX_PHYS ; + i++, port_ctrl +=SATA_NEXT_PORT_CTRL_OFFSET ) { +if (priv->port_mask &BIT (i)) +writel (0xff1003fc , + hpriv->mmio +SATA_PORT_PCTRL6 (port_ctrl)); + } +} +static void brcm_sata_phy_enable (struct brcm_ahci_priv *priv,int port) { void __iomem *phyctrl = priv->top_ctrl + SATA_TOP_CTRL_PHY_CTRL +
@@ -240,6 +273,7 @@ static int brcm_ahci_resume(struct device *dev)brcm_sata_init (priv);brcm_sata_phys_enable (priv); +brcm_sata_alpm_init (hpriv); return ahci_platform_resume(dev); }#endif
@@ -284,6 +318,8 @@ static int brcm_ahci_probe(struct platform_device *pdev)return PTR_ERR (hpriv); hpriv->plat_data = priv; +brcm_sata_alpm_init (hpriv); + ret =ahci_platform_enable_resources (hpriv);if (ret)return ret;
Signature · 1 line
2.1.0
Tejun Heo
AppliedRe: [PATCH 1/4] ata: ahci_brcmstb: enable support for ALPM
Quoted 5 lines · Florian Fainelli
From: Danesh Petigara <[email protected]>
Enable support for ALPM in the host controller's capabilities register. Also adjust the PLL timeout to give it enough time to lock when the port exits slumber mode.
Applied to libata/for-4.5 w/ minor style adjustments.
Thanks.
Signature · 1 line
tejun
PATCH 2/4 ata: ahci_brcmstb: disable DIPM support
In reply to Florian FainelliFrom: Danesh Petigara <[email protected]>
The Broadcom STB SATA host controller does not support device initiated power management. Disable support for this feature so the driver never sends SETFEATURES commands to the device to enable/disable DIPM.
--- drivers/ata/ahci_brcmstb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/ahci_brcmstb.c +1 -1
@@ -84,7 +84,7 @@ struct brcm_ahci_priv { };static const struct ata_port_info ahci_brcm_port_info = { - .flags =AHCI_FLAG_COMMON , + .flags =AHCI_FLAG_COMMON |ATA_FLAG_NO_DIPM , .pio_mask =ATA_PIO4 , .udma_mask =ATA_UDMA6 , .port_ops = &ahci_platform_ops,
Signature · 1 line
2.1.0
Tejun Heo
AppliedRe: [PATCH 2/4] ata: ahci_brcmstb: disable DIPM support
Quoted 9 lines · Florian Fainelli
From: Danesh Petigara <[email protected]>
The Broadcom STB SATA host controller does not support device initiated power management. Disable support for this feature so the driver never sends SETFEATURES commands to the device to enable/disable DIPM.
Signed-off-by Danesh Petigara <[email protected]>Signed-off-by Florian Fainelli <[email protected]>
Applied to libata/for-4.5.
Thanks.
Signature · 1 line
tejun
PATCH 3/4 drivers: ata: wake port before DMA stop for ALPM
In reply to Florian FainelliFrom: Danesh Petigara <[email protected]>
The AHCI driver code stops and starts port DMA engines at will without considering the power state of the particular port. The AHCI specification isn't very clear on how to handle this scenario, leaving implementation open to interpretation.
Broadcom's STB SATA host controller is unable to handle port DMA controller restarts when the port in question is in low power mode. When a port enters partial or slumber mode, it's PHY is powered down. When a controller restart is requested, the controller's internal state machine expects the PHY to be brought back up by software which never happens in this case, resulting in failures.
To avoid this situation, logic is added to manually wake up the port just before it's DMA engine is stopped, if the port happens to be in a low power state. HBA initiated power management ensures that the port eventually returns to it's configured low power state, when the link is idle (as per the conditions listed in the spec). A new host flag is also added to ensure this logic is only exercised for hosts with the above limitation.
--- drivers/ata/ahci.h | 6 ++++++ drivers/ata/ahci_brcmstb.c | 1 + drivers/ata/libahci.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/ata/libata-core.c | 1 + include/linux/libata.h | 4 ++++ 5 files changed, 64 insertions(+)
drivers/ata/ahci.h +6 -0
@@ -198,6 +198,12 @@ enum {PORT_CMD_ICC_PARTIAL = (0x2 <<28 ),/* Put i/f in partial state */ PORT_CMD_ICC_SLUMBER = (0x6 <<28 ),/* Put i/f in slumber state */ +/* PORT SCR STAT bits */ +PORT_SCR_STAT_IPM_MASK = (0xf <<8 ),/* i/f IPM state mask */ +PORT_SCR_STAT_IPM_ACTIVE = (0x1 <<8 ),/* i/f in active state */ +PORT_SCR_STAT_IPM_PARTIAL = (0x2 <<8 ),/* i/f in partial state */ +PORT_SCR_STAT_IPM_SLUMBER = (0x6 <<8 ),/* i/f in slumber state */ +/* PORT_FBS bits */ PORT_FBS_DWE_OFFSET =16 ,/* FBS device with error offset */ PORT_FBS_ADO_OFFSET = 12, /* FBS active dev optimization offset */
drivers/ata/ahci_brcmstb.c +1 -0
@@ -85,6 +85,7 @@ struct brcm_ahci_priv {static const struct ata_port_info ahci_brcm_port_info = { .flags =AHCI_FLAG_COMMON |ATA_FLAG_NO_DIPM , + .flags2 =ATA_FLAG2_WAKE_BEFORE_STOP , .pio_mask =ATA_PIO4 , .udma_mask =ATA_UDMA6 , .port_ops = &ahci_platform_ops,
drivers/ata/libahci.c +52 -0
58 lines not on this page · raw message
drivers/ata/libata-core.c +1 -0
@@ -5803,6 +5803,7 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev, ap->mwdma_mask = pi->mwdma_mask; ap->udma_mask = pi->udma_mask; ap->flags |= pi->flags; + ap->flags2 |= pi->flags2; ap->link.flags |= pi->link_flags; ap->ops = pi->port_ops;
include/linux/libata.h +4 -0
@@ -236,6 +236,8 @@ enum {/* bits 24:31 of ap->flags are reserved for LLD specific flags */ +/* struct ata_port flags2 */ +ATA_FLAG2_WAKE_BEFORE_STOP = (1 <<0 ),/* wake link before DMA stop */ /* struct ata_port pflags */ ATA_PFLAG_EH_PENDING = (1 << 0), /* EH pending */
@@ -812,6 +814,7 @@ struct ata_port {/* Flags owned by the EH context. Only EH should touch these once the port is active */ unsigned long flags;/* ATA_FLAG_xxx */ +unsigned long flags2;/* ATA_FLAG2_xxx */ /* Flags that change dynamically, protected by ap->lock */ unsigned int pflags;/* ATA_PFLAG_xxx */ unsigned int print_id;/* user visible unique port ID */
@@ -996,6 +999,7 @@ struct ata_port_operations {struct ata_port_info {unsigned long flags; +unsigned long flags2;unsigned long link_flags;unsigned long pio_mask;unsigned long mwdma_mask;
Signature · 1 line
2.1.0
Re: [PATCH 3/4] drivers: ata: wake port before DMA stop for ALPM
Hello,
Quoted 6 lines · Florian Fainelli
drivers/ata/libahci.c +0
-0@@ -595,6 +595,58 @@ int ahci_stop_engine(struct ata_port *ap)void __iomem *port_mmio =ahci_port_base (ap);
drivers/ata/libahci.c int ahci_stop_engine(struct ata_port *ap) · line 605
Quoted 10 lines
drivers/ata/libahci.c +8
-0u32 tmp; +/* +* On some controllers, stopping a port's DMA engine +* while the port is in ALPM state (partial or slumber) +* results in failures on subsequent DMA engine starts. +* For those controllers, put the port back in active +* state before stopping it's DMA engine. +*/ +if (ap->flags2 &ATA_FLAG2_WAKE_BEFORE_STOP ) {
...
So, I'm not too comfortable with open coding ALPM switching in ahci_stop_engine(). Shouldn't it be possible to update and/or refactor and reuse ahci_set_lpm()?
include/linux/libata.h enum { · line 240
Quoted 8 lines
include/linux/libata.h +2
-0@@ -236,6 +236,8 @@ enum {/* bits 24:31 of ap->flags are reserved for LLD specific flags */ +/* struct ata_port flags2 */ + ATA_FLAG2_WAKE_BEFORE_STOP = (1 << 0), /* wake link before DMA stop */
What's wrong with bits 2-5 in ATA_FLAG_* space? Also, should this be a ahci priv flag?
Thanks.
Signature · 1 line
tejun
Re: [PATCH 3/4] drivers: ata: wake port before DMA stop for ALPM
Hi Tejun,
Quoted 21 lines · Tejun Heo
Hello,
Quoted 16 lines · Florian Fainelli
drivers/ata/libahci.c +8
-0@@ -595,6 +595,58 @@ int ahci_stop_engine(struct ata_port *ap)void __iomem *port_mmio =ahci_port_base (ap);u32 tmp; +/* +* On some controllers, stopping a port's DMA engine +* while the port is in ALPM state (partial or slumber) +* results in failures on subsequent DMA engine starts. +* For those controllers, put the port back in active +* state before stopping it's DMA engine. +*/ +if (ap->flags2 &ATA_FLAG2_WAKE_BEFORE_STOP ) {...
Quoted 4 lines
So, I'm not too comfortable with open coding ALPM switching in
ahci_stop_engine(). Shouldn't it be possible to update and/or refactor and reuseahci_set_lpm()?
ahci_set_lpm in it's current form cannot be used here as it also modifies the ALPE/ASP bits. The idea is to wake the link before DMA stop without changing the ALPM bits so the link can return to it's configured low power state when it's idle.
We could however update that function by introducing a new hints flag that allows us to skip unneeded logic for this scenario. ahci_set_lpm can then be called from ahci_stop_engine.
Quoted 11 lines
include/linux/libata.h enum { · line 240
Quoted 8 lines
include/linux/libata.h +2
-0@@ -236,6 +236,8 @@ enum {/* bits 24:31 of ap->flags are reserved for LLD specific flags */ +/* struct ata_port flags2 */ + ATA_FLAG2_WAKE_BEFORE_STOP = (1 << 0), /* wake link before DMA stop */What's wrong with bits 2-5 in ATA_FLAG_* space? Also, should this be a ahci priv flag?
I wasn't sure whether those bits were left unused on purpose, so I did not use them. The point to make this a AHCI_HFLAG_ flag makes perfect sense.
Quoted 3 lines
Thanks.
Thanks for the feedback.
Danesh
Re: [PATCH 3/4] drivers: ata: wake port before DMA stop for ALPM
Hello, Danesh.
Quoted 8 lines · Danesh Petigara
ahci_set_lpmin it's current form cannot be used here as it also modifies the ALPE/ASP bits. The idea is to wake the link before DMA stop without changing the ALPM bits so the link can return to it's configured low power state when it's idle.We could however update that function by introducing a new hints flag that allows us to skip unneeded logic for this scenario.
ahci_set_lpmcan then be called fromahci_stop_engine.
Yeah, please either update the function or factor the necessary part out.
Thanks.
Signature · 1 line
tejun
PATCH 4/4 libata: skip debounce delay on link resume
In reply to Florian FainelliFrom: Danesh Petigara <[email protected]>
The link resume logic uses a 200msec delay while debouncing the SControl register. The rationale behind that delay is to accommodate some PHYs that behave badly if their SStatus/ SControl registers are pounded immediately on resume. The Broadcom STB SATA PHY does not seem to have this issue. This patch introduces a new link flag that allows platforms to skip the debounce delay if it isn't needed.
--- drivers/ata/ahci_brcmstb.c | 1 + drivers/ata/libata-core.c | 3 ++- include/linux/libata.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-)
drivers/ata/ahci_brcmstb.c +1 -0
@@ -86,6 +86,7 @@ struct brcm_ahci_priv {static const struct ata_port_info ahci_brcm_port_info = { .flags =AHCI_FLAG_COMMON |ATA_FLAG_NO_DIPM , .flags2 =ATA_FLAG2_WAKE_BEFORE_STOP , + .link_flags =ATA_LFLAG_NO_DB_DELAY , .pio_mask =ATA_PIO4 , .udma_mask =ATA_UDMA6 , .port_ops = &ahci_platform_ops,
drivers/ata/libata-core.c +2 -1
@@ -3597,7 +3597,8 @@ int sata_link_resume(struct ata_link *link, const unsigned long *params,* immediately after resuming. Delay 200ms before * debouncing. */ -ata_msleep (link->ap,200 ); +if (!(link->flags &ATA_LFLAG_NO_DB_DELAY )) +ata_msleep (link->ap,200 );/* is SControl restored correctly? */ if ((rc =sata_scr_read (link,SCR_CONTROL , &scontrol)))
include/linux/libata.h +1 -0
@@ -205,6 +205,7 @@ enum {ATA_LFLAG_NO_LPM = (1 <<8 ),/* disable LPM on this link */ ATA_LFLAG_RST_ONCE = (1 <<9 ),/* limit recovery to one reset */ ATA_LFLAG_CHANGED = (1 <<10 ),/* LPM state changed on this link */ +ATA_LFLAG_NO_DB_DELAY = (1 <<11 ),/* no debounce delay on link resume */ /* struct ata_port flags */ ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
Signature · 1 line
2.1.0
Tejun Heo
AppliedRe: [PATCH 4/4] libata: skip debounce delay on link resume
Quoted 10 lines · Florian Fainelli
From: Danesh Petigara <[email protected]>
The link resume logic uses a 200msec delay while debouncing the SControl register. The rationale behind that delay is to accommodate some PHYs that behave badly if their SStatus/ SControl registers are pounded immediately on resume. The Broadcom STB SATA PHY does not seem to have this issue. This patch introduces a new link flag that allows platforms to skip the debounce delay if it isn't needed.
Quoted 2 lines
Signed-off-by Danesh Petigara <[email protected]>Signed-off-by Florian Fainelli <[email protected]>
Applied to libata/for-4.5.
Thanks.
Signature · 1 line
tejun