libata: separate out ata_sata_print_link_status
PATCH 1/5 libata: separate out ata_sata_print_link_status
Separate out ata_sata_print_link_status() from __sata_phy_reset().
Signed-off-by Tejun Heo <[email protected]>
drivers/scsi/libata-core.c +41 -18
@@ -1466,6 +1466,41 @@ void ata_port_probe(struct ata_port *ap) }/** +* ata_sata_print_link_status - Print SATA link status +* @ap: SATA port to printk link status about +* +* This function prints link speed and status of a SATA link. +* +* LOCKING: +* None. +*/ +void ata_sata_print_link_status (struct ata_port *ap) +{ +u32 sstatus, tmp; +const char *speed; + +if (!ap->ops->scr_read) +return ; + + sstatus =scr_read (ap,SCR_STATUS ); + +if (sata_dev_present (ap)) { + tmp = (sstatus >>4 ) &0xf ; +if (tmp & (1 <<0 )) + speed ="1.5" ; +else if (tmp & (1 <<1 )) + speed ="3.0" ; +else + speed ="<unknown>" ; +printk (KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n" , + ap->id, speed, sstatus); + }else { +printk (KERN_INFO "ata%u: SATA link down (SStatus %X)\n" , + ap->id, sstatus); + } +} + +/** * __sata_phy_reset - Wake/reset a low-level SATA PHY * @ap: SATA port associated with target SATA PHY. *
@@ -1499,27 +1534,14 @@ void __sata_phy_reset(struct ata_port *abreak ; }while (time_before (jiffies, timeout)); -/* TODO: phy layer with polling, timeouts, etc. */ - sstatus =scr_read (ap,SCR_STATUS ); -if (sata_dev_present (ap)) { -const char *speed; -u32 tmp; +/* print link status */ +ata_sata_print_link_status (ap); - tmp = (sstatus >>4 ) &0xf ; -if (tmp & (1 <<0 )) - speed ="1.5" ; -else if (tmp & (1 <<1 )) - speed ="3.0" ; -else - speed ="<unknown>" ; -printk (KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n" , - ap->id, speed, sstatus); +/* TODO: phy layer with polling, timeouts, etc. */ +if (sata_dev_present (ap))ata_port_probe (ap); - }else { -printk (KERN_INFO "ata%u: SATA link down (SStatus %X)\n" , - ap->id, sstatus); +else ata_port_disable (ap); - }if (ap->flags &ATA_FLAG_PORT_DISABLED )return ;
@@ -4980,6 +5002,7 @@ EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear);EXPORT_SYMBOL_GPL (ata_bmdma_status);EXPORT_SYMBOL_GPL (ata_bmdma_stop);EXPORT_SYMBOL_GPL (ata_port_probe); +EXPORT_SYMBOL_GPL (ata_sata_print_link_status);EXPORT_SYMBOL_GPL (sata_phy_reset);EXPORT_SYMBOL_GPL (__sata_phy_reset);EXPORT_SYMBOL_GPL (ata_bus_reset);
include/linux/libata.h +1 -0
@@ -427,6 +427,7 @@ struct ata_timing {#define FIT (v,vmin,vmax) max_t(short,min_t(short,v,vmax),vmin)extern void ata_port_probe (struct ata_port *); +extern void ata_sata_print_link_status (struct ata_port *ap);extern void __sata_phy_reset (struct ata_port *ap);extern void sata_phy_reset (struct ata_port *ap);extern void ata_bus_reset (struct ata_port *ap);
PATCH 2/5 libata: export ata_busy_sleep
Export ata_busy_sleep().
Signed-off-by Tejun Heo <[email protected]>
drivers/scsi/libata-core.c +3 -6
@@ -61,9 +61,6 @@#include "libata.h" -static unsigned int ata_busy_sleep (struct ata_port *ap, -unsigned long tmout_pat, -unsigned long tmout);static void ata_dev_reread_id (struct ata_port *ap,struct ata_device *dev);static void ata_dev_init_params (struct ata_port *ap,struct ata_device *dev);static void ata_set_mode (struct ata_port *ap);
@@ -1896,9 +1893,8 @@ err_out:* */ -static unsigned int ata_busy_sleep (struct ata_port *ap, -unsigned long tmout_pat, -unsigned long tmout) +unsigned int ata_busy_sleep (struct ata_port *ap, +unsigned long tmout_pat,unsigned long tmout) {unsigned long timer_start, timeout;u8 status;
@@ -5008,6 +5004,7 @@ EXPORT_SYMBOL_GPL(__sata_phy_reset);EXPORT_SYMBOL_GPL (ata_bus_reset);EXPORT_SYMBOL_GPL (ata_port_disable);EXPORT_SYMBOL_GPL (ata_ratelimit); +EXPORT_SYMBOL_GPL (ata_busy_sleep);EXPORT_SYMBOL_GPL (ata_scsi_ioctl);EXPORT_SYMBOL_GPL (ata_scsi_queuecmd);EXPORT_SYMBOL_GPL (ata_scsi_error);
include/linux/libata.h +3 -0
@@ -447,6 +447,9 @@ extern int ata_scsi_error(struct Scsi_Hoextern int ata_scsi_release (struct Scsi_Host *host);extern unsigned int ata_host_intr (struct ata_port *ap,struct ata_queued_cmd *qc);extern int ata_ratelimit (void ); +extern unsigned int ata_busy_sleep (struct ata_port *ap, +unsigned long timeout_pat, +unsigned long timeout);/* * Default driver ops implementations
PATCH 3/5 ahci: separate out ahci_stop/start_engine
In reply to Tejun HeoSeparate out ahci_stop/start_engine().
Signed-off-by Tejun Heo <[email protected]>
drivers/scsi/ahci.c +39 -19
@@ -437,6 +437,43 @@ static void ahci_scr_write (struct ata_pwritel (val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg *4 )); } +static int ahci_stop_engine (struct ata_port *ap) +{ +void __iomem *mmio = ap->host_set->mmio_base; +void __iomem *port_mmio =ahci_port_base (mmio, ap->port_no); +int work; +u32 tmp; + + tmp =readl (port_mmio +PORT_CMD ); + tmp &= ~PORT_CMD_START ; +writel (tmp, port_mmio +PORT_CMD ); + +/* wait for engine to stop. TODO: this could be +* as long as 500 msec +*/ + work =1000 ; +while (work-- >0 ) { + tmp =readl (port_mmio +PORT_CMD ); +if ((tmp &PORT_CMD_LIST_ON ) ==0 ) +return 0 ; +udelay (10 ); + } + +return -EIO ; +} + +static void ahci_start_engine (struct ata_port *ap) +{ +void __iomem *mmio = ap->host_set->mmio_base; +void __iomem *port_mmio =ahci_port_base (mmio, ap->port_no); +u32 tmp; + + tmp =readl (port_mmio +PORT_CMD ); + tmp |=PORT_CMD_START ; +writel (tmp, port_mmio +PORT_CMD ); +readl (port_mmio +PORT_CMD );/* flush */ +} +static void ahci_phy_reset (struct ata_port *ap) {void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
@@ -563,7 +600,6 @@ static void ahci_restart_port(struct atavoid __iomem *mmio = ap->host_set->mmio_base;void __iomem *port_mmio =ahci_port_base (mmio, ap->port_no);u32 tmp; -int work;if ((ap->device[0 ].class !=ATA_DEV_ATAPI ) || ((irq_stat &PORT_IRQ_TF_ERR ) ==0 ))
@@ -579,20 +615,7 @@ static void ahci_restart_port(struct ata readl(port_mmio + PORT_SCR_ERR));/* stop DMA */ - tmp =readl (port_mmio +PORT_CMD ); - tmp &= ~PORT_CMD_START ; -writel (tmp, port_mmio +PORT_CMD ); - -/* wait for engine to stop. TODO: this could be -* as long as 500 msec -*/ - work =1000 ; -while (work-- >0 ) { - tmp =readl (port_mmio +PORT_CMD ); -if ((tmp &PORT_CMD_LIST_ON ) ==0 ) -break ; -udelay (10 ); - } +ahci_stop_engine (ap);/* clear SATA phy error, if any */ tmp =readl (port_mmio +PORT_SCR_ERR );
@@ -611,10 +634,7 @@ static void ahci_restart_port(struct ata }/* re-start DMA */ - tmp =readl (port_mmio +PORT_CMD ); - tmp |=PORT_CMD_START ; -writel (tmp, port_mmio +PORT_CMD ); -readl (port_mmio +PORT_CMD );/* flush */ +ahci_start_engine (ap); }static void ahci_eng_timeout (struct ata_port *ap)
PATCH 4/5 ahci: separate out ahci_dev_classify
In reply to Tejun HeoSeparate out ahci_dev_classify().
Signed-off-by Tejun Heo <[email protected]>
drivers/scsi/ahci.c +16 -8
@@ -474,10 +474,24 @@ static void ahci_start_engine(struct atareadl (port_mmio +PORT_CMD );/* flush */ } -static void ahci_phy_reset (struct ata_port *ap) +static unsigned int ahci_dev_classify (struct ata_port *ap) {void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;struct ata_taskfile tf; +u32 tmp; + + tmp =readl (port_mmio +PORT_SIG ); + tf.lbah = (tmp >>24 ) &0xff ; + tf.lbam = (tmp >>16 ) &0xff ; + tf.lbal = (tmp >>8 ) &0xff ; + tf.nsect = (tmp) &0xff ; + +return ata_dev_classify (&tf); +} + +static void ahci_phy_reset (struct ata_port *ap) +{ +void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;struct ata_device *dev = &ap->device[0 ];u32 new_tmp, tmp;
@@ -486,13 +500,7 @@ static void ahci_phy_reset(struct ata_poif (ap->flags &ATA_FLAG_PORT_DISABLED )return ; - tmp =readl (port_mmio +PORT_SIG ); - tf.lbah = (tmp >>24 ) &0xff ; - tf.lbam = (tmp >>16 ) &0xff ; - tf.lbal = (tmp >>8 ) &0xff ; - tf.nsect = (tmp) &0xff ; - - dev->class =ata_dev_classify (&tf); + dev->class =ahci_dev_classify (ap);if (!ata_dev_present (dev)) {ata_port_disable (ap);return ;
PATCH 5/5 ahci: rewrite ahci_phy_reset
In reply to Tejun HeoRewrite ahci_phy_reset such that engine is stopped while phy reset is in progress as AHCI specification mandates.
Signed-off-by Tejun Heo <[email protected]>
drivers/scsi/ahci.c +64 -8
@@ -489,22 +489,72 @@ static unsigned int ahci_dev_classify(streturn ata_dev_classify (&tf); } +static int ahci_wait_for_bit (void __iomem *reg,u32 mask,u32 val, +unsigned long interval_msec, +unsigned long timeout_msec) +{ +unsigned long timeout; +u32 tmp; + + timeout = jiffies + (timeout_msec *HZ ) /1000 ; +do { + tmp =readl (reg); +if ((tmp & mask) != val) +return 0 ; +msleep (interval_msec); + }while (time_before (jiffies, timeout)); + +return -1 ; +} +static void ahci_phy_reset (struct ata_port *ap) { -void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; +void __iomem *mmio = ap->host_set->mmio_base; +void __iomem *port_mmio =ahci_port_base (mmio, ap->port_no);struct ata_device *dev = &ap->device[0 ];u32 new_tmp, tmp; -__sata_phy_reset (ap); +/* stop engine */ +ahci_stop_engine (ap); -if (ap->flags &ATA_FLAG_PORT_DISABLED ) -return ; +/* Issue COMRESET. On AHCI, DET bits are cleared by COMRESET +* and it may take quite some millisecs before they are turned +* on again. Wait longer if device is present. +*/ + tmp =readl (port_mmio +PORT_SCR_STAT ); + +writel (0x301 , port_mmio +PORT_SCR_CTL ); +readl (port_mmio +PORT_SCR_CTL );/* flush */ +msleep (1 ); +writel (0x300 , port_mmio +PORT_SCR_CTL ); +readl (port_mmio +PORT_SCR_CTL );/* flush */ + +msleep (200 ); +if (tmp &0xf ) +ahci_wait_for_bit (port_mmio +PORT_SCR_STAT ,0xf ,0x0 ,10 ,5000 ); +ahci_wait_for_bit (port_mmio +PORT_SCR_STAT ,0xf ,0x1 ,10 ,5000 ); + +/* clear SATA phy error, if any */ + tmp =readl (port_mmio +PORT_SCR_ERR ); +writel (tmp, port_mmio +PORT_SCR_ERR ); + +/* re-start engine */ +ahci_start_engine (ap); + +/* print link status & classify */ +ata_sata_print_link_status (ap); + +if (!sata_dev_present (ap)) + goto out_disable; + +if (ata_busy_sleep (ap,ATA_TMOUT_BOOT_QUICK ,ATA_TMOUT_BOOT )) + goto out_disable; dev->class =ahci_dev_classify (ap); -if (!ata_dev_present (dev)) { -ata_port_disable (ap); -return ; - } +if (!ata_dev_present (dev)) + goto out_disable; + +ata_port_probe (ap);/* Make sure port's ATAPI bit is set appropriately */ new_tmp = tmp =readl (port_mmio +PORT_CMD );
@@ -516,6 +566,12 @@ static void ahci_phy_reset(struct ata_powritel (new_tmp, port_mmio +PORT_CMD );readl (port_mmio +PORT_CMD );/* flush */ } + + ap->cbl =ATA_CBL_SATA ; +return ; + + out_disable: +ata_port_disable (ap); }static u8 ahci_check_status (struct ata_port *ap)
Jeff Garzik
AppliedQuoted 3 lines · Tejun Heo
Separate out
ata_sata_print_link_status()from__sata_phy_reset().Signed-off-by Tejun Heo <[email protected]>
applied patches 1, 3, 4 to 'upstream-2.6.17' branch