libata: Ignore spurious PHY event on LPM policy change
v2 cover libata: Ignore spurious PHY event on LPM policy change
Changes since v1:
- Added generic helper to keep the logic in one place
Gabriele Mazzotta (2):
libata: Add helper to determine when PHY events should be ignored
libata: Ignore spurious PHY event on LPM policy change
drivers/ata/libahci.c | 3 +-- drivers/ata/libata-core.c | 32 ++++++++++++++++++++++++++++++++ drivers/ata/libata-eh.c | 3 +++ include/linux/libata.h | 10 ++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/2 libata: Add helper to determine when PHY events should be ignored
This is a preparation commit that will allow to add other criteria according to which PHY events should be dropped.
--- drivers/ata/libahci.c | 3 +-- drivers/ata/libata-core.c | 19 +++++++++++++++++++ include/linux/libata.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-)
drivers/ata/libahci.c +1 -2
@@ -1707,8 +1707,7 @@ static void ahci_handle_port_interrupt(struct ata_port *ap,if (unlikely (resetting)) status &= ~PORT_IRQ_BAD_PMP ; -/* if LPM is enabled, PHYRDY doesn't mean anything */ -if (ap->link.lpm_policy >ATA_LPM_MAX_POWER ) { +if (sata_lpm_ignore_phy_events (&ap->link)) { status &= ~PORT_IRQ_PHYRDY ;ahci_scr_write (&ap->link,SCR_ERROR ,SERR_PHYRDY_CHG ); }
drivers/ata/libata-core.c +19 -0
@@ -6752,6 +6752,25 @@ u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,return tmp; } +/** +* sata_lpm_ignore_phy_events - test if PHY event should be ignored +* @link: Link receiving the event +* +* Test whether the received PHY event has to be ignored or not. +* +* LOCKING: +* None: +* +* RETURNS: +* True if the event has to be ignored. +*/ +bool sata_lpm_ignore_phy_events (struct ata_link *link) +{ +/* if LPM is enabled, PHYRDY doesn't mean anything */ +return !!(link->lpm_policy >ATA_LPM_MAX_POWER ); +} +EXPORT_SYMBOL_GPL (sata_lpm_ignore_phy_events); +/* * Dummy port_ops */
include/linux/libata.h +1 -0
@@ -1201,6 +1201,7 @@ extern struct ata_device *ata_dev_pair(struct ata_device *adev);extern int ata_do_set_mode (struct ata_link *link,struct ata_device **r_failed_dev);extern void ata_scsi_port_error_handler (struct Scsi_Host *host,struct ata_port *ap);extern void ata_scsi_cmd_error_handler (struct Scsi_Host *host,struct ata_port *ap,struct list_head *eh_q); +extern bool sata_lpm_ignore_phy_events (struct ata_link *link);extern int ata_cable_40wire (struct ata_port *ap);extern int ata_cable_80wire (struct ata_port *ap);
Signature · 1 line
2.1.4
Re: [PATCH v2 1/2] libata: Add helper to determine when PHY events should be ignored
drivers/ata/libata-core.c u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val, · line 6770
Quoted 4 lines · Gabriele Mazzotta
drivers/ata/libata-core.c +4
-0+bool sata_lpm_ignore_phy_events (struct ata_link *link) +{ +/* if LPM is enabled, PHYRDY doesn't mean anything */ +return !!(link->lpm_policy >ATA_LPM_MAX_POWER );
This gets removed by the next patch so it doesn't matter but there's no need to do !! here. The expression is already bool and even if not casting to bool can't yield any other result.
Thanks.
Signature · 1 line
tejun
PATCH v2 2/2 libata: Ignore spurious PHY event on LPM policy change
In reply to Gabriele MazzottaWhen the LPM policy is set to ATA_LPM_MAX_POWER, the device might generate a spurious PHY event that cuases errors on the link. Ignore this event if it occured within 10s after the policy change.
The timeout was chosen observing that on a Dell XPS13 9333 these spurious events can occur up to roughly 6s after the policy change.
--- drivers/ata/libata-core.c | 15 ++++++++++++++- drivers/ata/libata-eh.c | 3 +++ include/linux/libata.h | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +14 -1
@@ -6766,8 +6766,21 @@ u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,*/ bool sata_lpm_ignore_phy_events (struct ata_link *link) { +unsigned long lpm_timeout = link->last_lpm_change + +msecs_to_jiffies (ATA_TMOUT_SPURIOUS_PHY ); +/* if LPM is enabled, PHYRDY doesn't mean anything */ -return !!(link->lpm_policy >ATA_LPM_MAX_POWER ); +if (link->lpm_policy >ATA_LPM_MAX_POWER ) +return true; + +/* ignore the first PHY event after the LPM policy changed +* as it is might be spurious +*/ +if ((link->flags &ATA_LFLAG_CHANGED ) && +time_before (jiffies, lpm_timeout)) +return true; + +return false; }EXPORT_SYMBOL_GPL (sata_lpm_ignore_phy_events);
drivers/ata/libata-eh.c +3 -0
@@ -3597,6 +3597,9 @@ static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy, } } + link->last_lpm_change = jiffies; + link->flags |=ATA_LFLAG_CHANGED ; +return 0 ; fail:
include/linux/libata.h +9 -0
@@ -205,6 +205,7 @@ enum {ATA_LFLAG_SW_ACTIVITY = (1 <<7 ),/* keep activity stats */ 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 */ /* struct ata_port flags */ ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
@@ -309,6 +310,12 @@ enum {*/ ATA_TMOUT_PMP_SRST_WAIT =5000 , +/* When the LPM policy is set to ATA_LPM_MAX_POWER, there might +* be a spurious PHY event, so ignore the first PHY event that +* occurs within 10s after the policy change. +*/ +ATA_TMOUT_SPURIOUS_PHY =10000 , +/* ATA bus states */ BUS_UNKNOWN =0 , BUS_DMA = 1,
@@ -788,6 +795,8 @@ struct ata_link {struct ata_eh_context eh_context;struct ata_device device[ATA_MAX_DEVICES ]; + +unsigned long last_lpm_change;/* when last LPM change happened */ };#define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)#define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
Signature · 1 line
2.1.4
Quoted 9 lines · Gabriele Mazzotta
When the LPM policy is set to
ATA_LPM_MAX_POWER, the device might generate a spurious PHY event that cuases errors on the link. Ignore this event if it occured within 10s after the policy change.The timeout was chosen observing that on a Dell XPS13 9333 these spurious events can occur up to roughly 6s after the policy change.
Applied 1-2 to libata/for-4.1-fixes w/ stable cc'd.
Thanks a lot.
Signature · 1 line
tejun