aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:58:20 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:58:20 -0400
commit4750def52cb2c21732dda9aa1d43a07db37b0186 (patch)
tree29fd6223665faabb593f8ae1f4f626685f425ff9 /drivers/ata
parent9028780a3e6d2c3dd940e89b377765cca008b6df (diff)
parent27c78b372d05e47bbd059c9bb003c6d716abff54 (diff)
Merge branch 'reset-seq' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev
* 'reset-seq' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev: [libata reset-seq] build and merge fixes libata: reimplement reset sequencing libata: improve ata_std_prereset() libata: improve 0xff status handling libata: add deadline support to prereset and reset methods
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/ahci.c28
-rw-r--r--drivers/ata/ata_piix.c6
-rw-r--r--drivers/ata/libata-core.c225
-rw-r--r--drivers/ata/libata-eh.c62
-rw-r--r--drivers/ata/pata_amd.c11
-rw-r--r--drivers/ata/pata_artop.c11
-rw-r--r--drivers/ata/pata_atiixp.c4
-rw-r--r--drivers/ata/pata_cs5535.c1
-rw-r--r--drivers/ata/pata_efar.c5
-rw-r--r--drivers/ata/pata_hpt366.c4
-rw-r--r--drivers/ata/pata_hpt37x.c9
-rw-r--r--drivers/ata/pata_hpt3x2n.c5
-rw-r--r--drivers/ata/pata_it8213.c6
-rw-r--r--drivers/ata/pata_jmicron.c7
-rw-r--r--drivers/ata/pata_marvell.c7
-rw-r--r--drivers/ata/pata_mpiix.c5
-rw-r--r--drivers/ata/pata_ns87410.c6
-rw-r--r--drivers/ata/pata_oldpiix.c6
-rw-r--r--drivers/ata/pata_opti.c6
-rw-r--r--drivers/ata/pata_optidma.c5
-rw-r--r--drivers/ata/pata_pdc2027x.c5
-rw-r--r--drivers/ata/pata_serverworks.c4
-rw-r--r--drivers/ata/pata_sil680.c6
-rw-r--r--drivers/ata/pata_sis.c8
-rw-r--r--drivers/ata/pata_sl82c105.c5
-rw-r--r--drivers/ata/pata_triflex.c6
-rw-r--r--drivers/ata/pata_via.c5
-rw-r--r--drivers/ata/sata_inic162x.c15
-rw-r--r--drivers/ata/sata_nv.c5
-rw-r--r--drivers/ata/sata_sil24.c10
-rw-r--r--drivers/ata/sata_via.c5
31 files changed, 306 insertions, 187 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 34c5534ed64c..d9617892fc23 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -874,7 +874,8 @@ static int ahci_clo(struct ata_port *ap)
874 return 0; 874 return 0;
875} 875}
876 876
877static int ahci_softreset(struct ata_port *ap, unsigned int *class) 877static int ahci_softreset(struct ata_port *ap, unsigned int *class,
878 unsigned long deadline)
878{ 879{
879 struct ahci_port_priv *pp = ap->private_data; 880 struct ahci_port_priv *pp = ap->private_data;
880 void __iomem *port_mmio = ahci_port_base(ap); 881 void __iomem *port_mmio = ahci_port_base(ap);
@@ -959,15 +960,13 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
959 */ 960 */
960 msleep(150); 961 msleep(150);
961 962
962 *class = ATA_DEV_NONE; 963 rc = ata_wait_ready(ap, deadline);
963 if (ata_port_online(ap)) { 964 /* link occupied, -ENODEV too is an error */
964 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 965 if (rc) {
965 rc = -EIO; 966 reason = "device not ready";
966 reason = "device not ready"; 967 goto fail;
967 goto fail;
968 }
969 *class = ahci_dev_classify(ap);
970 } 968 }
969 *class = ahci_dev_classify(ap);
971 970
972 DPRINTK("EXIT, class=%u\n", *class); 971 DPRINTK("EXIT, class=%u\n", *class);
973 return 0; 972 return 0;
@@ -979,7 +978,8 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
979 return rc; 978 return rc;
980} 979}
981 980
982static int ahci_hardreset(struct ata_port *ap, unsigned int *class) 981static int ahci_hardreset(struct ata_port *ap, unsigned int *class,
982 unsigned long deadline)
983{ 983{
984 struct ahci_port_priv *pp = ap->private_data; 984 struct ahci_port_priv *pp = ap->private_data;
985 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 985 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
@@ -995,7 +995,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
995 tf.command = 0x80; 995 tf.command = 0x80;
996 ata_tf_to_fis(&tf, d2h_fis, 0); 996 ata_tf_to_fis(&tf, d2h_fis, 0);
997 997
998 rc = sata_std_hardreset(ap, class); 998 rc = sata_std_hardreset(ap, class, deadline);
999 999
1000 ahci_start_engine(ap); 1000 ahci_start_engine(ap);
1001 1001
@@ -1008,7 +1008,8 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
1008 return rc; 1008 return rc;
1009} 1009}
1010 1010
1011static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class) 1011static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class,
1012 unsigned long deadline)
1012{ 1013{
1013 int rc; 1014 int rc;
1014 1015
@@ -1016,7 +1017,8 @@ static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class)
1016 1017
1017 ahci_stop_engine(ap); 1018 ahci_stop_engine(ap);
1018 1019
1019 rc = sata_port_hardreset(ap, sata_ehc_deb_timing(&ap->eh_context)); 1020 rc = sata_port_hardreset(ap, sata_ehc_deb_timing(&ap->eh_context),
1021 deadline);
1020 1022
1021 /* vt8251 needs SError cleared for the port to operate */ 1023 /* vt8251 needs SError cleared for the port to operate */
1022 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR)); 1024 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR));
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 55d306a3e538..4a795fdb6a02 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -625,17 +625,18 @@ static int ich_pata_cable_detect(struct ata_port *ap)
625/** 625/**
626 * piix_pata_prereset - prereset for PATA host controller 626 * piix_pata_prereset - prereset for PATA host controller
627 * @ap: Target port 627 * @ap: Target port
628 * @deadline: deadline jiffies for the operation
628 * 629 *
629 * LOCKING: 630 * LOCKING:
630 * None (inherited from caller). 631 * None (inherited from caller).
631 */ 632 */
632static int piix_pata_prereset(struct ata_port *ap) 633static int piix_pata_prereset(struct ata_port *ap, unsigned long deadline)
633{ 634{
634 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 635 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
635 636
636 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) 637 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
637 return -ENOENT; 638 return -ENOENT;
638 return ata_std_prereset(ap); 639 return ata_std_prereset(ap, deadline);
639} 640}
640 641
641static void piix_pata_error_handler(struct ata_port *ap) 642static void piix_pata_error_handler(struct ata_port *ap)
@@ -644,7 +645,6 @@ static void piix_pata_error_handler(struct ata_port *ap)
644 ata_std_postreset); 645 ata_std_postreset);
645} 646}
646 647
647
648static void piix_sata_error_handler(struct ata_port *ap) 648static void piix_sata_error_handler(struct ata_port *ap)
649{ 649{
650 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL, 650 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL,
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index ca67484af1eb..a7950885d18e 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2979,23 +2979,71 @@ int ata_busy_sleep(struct ata_port *ap,
2979 return 0; 2979 return 0;
2980} 2980}
2981 2981
2982static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask) 2982/**
2983 * ata_wait_ready - sleep until BSY clears, or timeout
2984 * @ap: port containing status register to be polled
2985 * @deadline: deadline jiffies for the operation
2986 *
2987 * Sleep until ATA Status register bit BSY clears, or timeout
2988 * occurs.
2989 *
2990 * LOCKING:
2991 * Kernel thread context (may sleep).
2992 *
2993 * RETURNS:
2994 * 0 on success, -errno otherwise.
2995 */
2996int ata_wait_ready(struct ata_port *ap, unsigned long deadline)
2997{
2998 unsigned long start = jiffies;
2999 int warned = 0;
3000
3001 while (1) {
3002 u8 status = ata_chk_status(ap);
3003 unsigned long now = jiffies;
3004
3005 if (!(status & ATA_BUSY))
3006 return 0;
3007 if (status == 0xff)
3008 return -ENODEV;
3009 if (time_after(now, deadline))
3010 return -EBUSY;
3011
3012 if (!warned && time_after(now, start + 5 * HZ) &&
3013 (deadline - now > 3 * HZ)) {
3014 ata_port_printk(ap, KERN_WARNING,
3015 "port is slow to respond, please be patient "
3016 "(Status 0x%x)\n", status);
3017 warned = 1;
3018 }
3019
3020 msleep(50);
3021 }
3022}
3023
3024static int ata_bus_post_reset(struct ata_port *ap, unsigned int devmask,
3025 unsigned long deadline)
2983{ 3026{
2984 struct ata_ioports *ioaddr = &ap->ioaddr; 3027 struct ata_ioports *ioaddr = &ap->ioaddr;
2985 unsigned int dev0 = devmask & (1 << 0); 3028 unsigned int dev0 = devmask & (1 << 0);
2986 unsigned int dev1 = devmask & (1 << 1); 3029 unsigned int dev1 = devmask & (1 << 1);
2987 unsigned long timeout; 3030 int rc, ret = 0;
2988 3031
2989 /* if device 0 was found in ata_devchk, wait for its 3032 /* if device 0 was found in ata_devchk, wait for its
2990 * BSY bit to clear 3033 * BSY bit to clear
2991 */ 3034 */
2992 if (dev0) 3035 if (dev0) {
2993 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 3036 rc = ata_wait_ready(ap, deadline);
3037 if (rc) {
3038 if (rc != -ENODEV)
3039 return rc;
3040 ret = rc;
3041 }
3042 }
2994 3043
2995 /* if device 1 was found in ata_devchk, wait for 3044 /* if device 1 was found in ata_devchk, wait for
2996 * register access, then wait for BSY to clear 3045 * register access, then wait for BSY to clear
2997 */ 3046 */
2998 timeout = jiffies + ATA_TMOUT_BOOT;
2999 while (dev1) { 3047 while (dev1) {
3000 u8 nsect, lbal; 3048 u8 nsect, lbal;
3001 3049
@@ -3004,14 +3052,18 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
3004 lbal = ioread8(ioaddr->lbal_addr); 3052 lbal = ioread8(ioaddr->lbal_addr);
3005 if ((nsect == 1) && (lbal == 1)) 3053 if ((nsect == 1) && (lbal == 1))
3006 break; 3054 break;
3007 if (time_after(jiffies, timeout)) { 3055 if (time_after(jiffies, deadline))
3008 dev1 = 0; 3056 return -EBUSY;
3009 break;
3010 }
3011 msleep(50); /* give drive a breather */ 3057 msleep(50); /* give drive a breather */
3012 } 3058 }
3013 if (dev1) 3059 if (dev1) {
3014 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 3060 rc = ata_wait_ready(ap, deadline);
3061 if (rc) {
3062 if (rc != -ENODEV)
3063 return rc;
3064 ret = rc;
3065 }
3066 }
3015 3067
3016 /* is all this really necessary? */ 3068 /* is all this really necessary? */
3017 ap->ops->dev_select(ap, 0); 3069 ap->ops->dev_select(ap, 0);
@@ -3019,10 +3071,12 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
3019 ap->ops->dev_select(ap, 1); 3071 ap->ops->dev_select(ap, 1);
3020 if (dev0) 3072 if (dev0)
3021 ap->ops->dev_select(ap, 0); 3073 ap->ops->dev_select(ap, 0);
3074
3075 return ret;
3022} 3076}
3023 3077
3024static unsigned int ata_bus_softreset(struct ata_port *ap, 3078static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
3025 unsigned int devmask) 3079 unsigned long deadline)
3026{ 3080{
3027 struct ata_ioports *ioaddr = &ap->ioaddr; 3081 struct ata_ioports *ioaddr = &ap->ioaddr;
3028 3082
@@ -3052,11 +3106,9 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
3052 * pulldown resistor. 3106 * pulldown resistor.
3053 */ 3107 */
3054 if (ata_check_status(ap) == 0xFF) 3108 if (ata_check_status(ap) == 0xFF)
3055 return 0; 3109 return -ENODEV;
3056
3057 ata_bus_post_reset(ap, devmask);
3058 3110
3059 return 0; 3111 return ata_bus_post_reset(ap, devmask, deadline);
3060} 3112}
3061 3113
3062/** 3114/**
@@ -3085,6 +3137,7 @@ void ata_bus_reset(struct ata_port *ap)
3085 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 3137 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
3086 u8 err; 3138 u8 err;
3087 unsigned int dev0, dev1 = 0, devmask = 0; 3139 unsigned int dev0, dev1 = 0, devmask = 0;
3140 int rc;
3088 3141
3089 DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no); 3142 DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no);
3090 3143
@@ -3106,9 +3159,11 @@ void ata_bus_reset(struct ata_port *ap)
3106 ap->ops->dev_select(ap, 0); 3159 ap->ops->dev_select(ap, 0);
3107 3160
3108 /* issue bus reset */ 3161 /* issue bus reset */
3109 if (ap->flags & ATA_FLAG_SRST) 3162 if (ap->flags & ATA_FLAG_SRST) {
3110 if (ata_bus_softreset(ap, devmask)) 3163 rc = ata_bus_softreset(ap, devmask, jiffies + 40 * HZ);
3164 if (rc && rc != -ENODEV)
3111 goto err_out; 3165 goto err_out;
3166 }
3112 3167
3113 /* 3168 /*
3114 * determine by signature whether we have ATA or ATAPI devices 3169 * determine by signature whether we have ATA or ATAPI devices
@@ -3150,29 +3205,37 @@ err_out:
3150 * sata_phy_debounce - debounce SATA phy status 3205 * sata_phy_debounce - debounce SATA phy status
3151 * @ap: ATA port to debounce SATA phy status for 3206 * @ap: ATA port to debounce SATA phy status for
3152 * @params: timing parameters { interval, duratinon, timeout } in msec 3207 * @params: timing parameters { interval, duratinon, timeout } in msec
3208 * @deadline: deadline jiffies for the operation
3153 * 3209 *
3154 * Make sure SStatus of @ap reaches stable state, determined by 3210 * Make sure SStatus of @ap reaches stable state, determined by
3155 * holding the same value where DET is not 1 for @duration polled 3211 * holding the same value where DET is not 1 for @duration polled
3156 * every @interval, before @timeout. Timeout constraints the 3212 * every @interval, before @timeout. Timeout constraints the
3157 * beginning of the stable state. Because, after hot unplugging, 3213 * beginning of the stable state. Because DET gets stuck at 1 on
3158 * DET gets stuck at 1 on some controllers, this functions waits 3214 * some controllers after hot unplugging, this functions waits
3159 * until timeout then returns 0 if DET is stable at 1. 3215 * until timeout then returns 0 if DET is stable at 1.
3160 * 3216 *
3217 * @timeout is further limited by @deadline. The sooner of the
3218 * two is used.
3219 *
3161 * LOCKING: 3220 * LOCKING:
3162 * Kernel thread context (may sleep) 3221 * Kernel thread context (may sleep)
3163 * 3222 *
3164 * RETURNS: 3223 * RETURNS:
3165 * 0 on success, -errno on failure. 3224 * 0 on success, -errno on failure.
3166 */ 3225 */
3167int sata_phy_debounce(struct ata_port *ap, const unsigned long *params) 3226int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3227 unsigned long deadline)
3168{ 3228{
3169 unsigned long interval_msec = params[0]; 3229 unsigned long interval_msec = params[0];
3170 unsigned long duration = params[1] * HZ / 1000; 3230 unsigned long duration = msecs_to_jiffies(params[1]);
3171 unsigned long timeout = jiffies + params[2] * HZ / 1000; 3231 unsigned long last_jiffies, t;
3172 unsigned long last_jiffies;
3173 u32 last, cur; 3232 u32 last, cur;
3174 int rc; 3233 int rc;
3175 3234
3235 t = jiffies + msecs_to_jiffies(params[2]);
3236 if (time_before(t, deadline))
3237 deadline = t;
3238
3176 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur))) 3239 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur)))
3177 return rc; 3240 return rc;
3178 cur &= 0xf; 3241 cur &= 0xf;
@@ -3188,7 +3251,7 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3188 3251
3189 /* DET stable? */ 3252 /* DET stable? */
3190 if (cur == last) { 3253 if (cur == last) {
3191 if (cur == 1 && time_before(jiffies, timeout)) 3254 if (cur == 1 && time_before(jiffies, deadline))
3192 continue; 3255 continue;
3193 if (time_after(jiffies, last_jiffies + duration)) 3256 if (time_after(jiffies, last_jiffies + duration))
3194 return 0; 3257 return 0;
@@ -3199,8 +3262,8 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3199 last = cur; 3262 last = cur;
3200 last_jiffies = jiffies; 3263 last_jiffies = jiffies;
3201 3264
3202 /* check timeout */ 3265 /* check deadline */
3203 if (time_after(jiffies, timeout)) 3266 if (time_after(jiffies, deadline))
3204 return -EBUSY; 3267 return -EBUSY;
3205 } 3268 }
3206} 3269}
@@ -3209,6 +3272,7 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3209 * sata_phy_resume - resume SATA phy 3272 * sata_phy_resume - resume SATA phy
3210 * @ap: ATA port to resume SATA phy for 3273 * @ap: ATA port to resume SATA phy for
3211 * @params: timing parameters { interval, duratinon, timeout } in msec 3274 * @params: timing parameters { interval, duratinon, timeout } in msec
3275 * @deadline: deadline jiffies for the operation
3212 * 3276 *
3213 * Resume SATA phy of @ap and debounce it. 3277 * Resume SATA phy of @ap and debounce it.
3214 * 3278 *
@@ -3218,7 +3282,8 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3218 * RETURNS: 3282 * RETURNS:
3219 * 0 on success, -errno on failure. 3283 * 0 on success, -errno on failure.
3220 */ 3284 */
3221int sata_phy_resume(struct ata_port *ap, const unsigned long *params) 3285int sata_phy_resume(struct ata_port *ap, const unsigned long *params,
3286 unsigned long deadline)
3222{ 3287{
3223 u32 scontrol; 3288 u32 scontrol;
3224 int rc; 3289 int rc;
@@ -3236,43 +3301,19 @@ int sata_phy_resume(struct ata_port *ap, const unsigned long *params)
3236 */ 3301 */
3237 msleep(200); 3302 msleep(200);
3238 3303
3239 return sata_phy_debounce(ap, params); 3304 return sata_phy_debounce(ap, params, deadline);
3240}
3241
3242static void ata_wait_spinup(struct ata_port *ap)
3243{
3244 struct ata_eh_context *ehc = &ap->eh_context;
3245 unsigned long end, secs;
3246 int rc;
3247
3248 /* first, debounce phy if SATA */
3249 if (ap->cbl == ATA_CBL_SATA) {
3250 rc = sata_phy_debounce(ap, sata_deb_timing_hotplug);
3251
3252 /* if debounced successfully and offline, no need to wait */
3253 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap))
3254 return;
3255 }
3256
3257 /* okay, let's give the drive time to spin up */
3258 end = ehc->i.hotplug_timestamp + ATA_SPINUP_WAIT * HZ / 1000;
3259 secs = ((end - jiffies) + HZ - 1) / HZ;
3260
3261 if (time_after(jiffies, end))
3262 return;
3263
3264 if (secs > 5)
3265 ata_port_printk(ap, KERN_INFO, "waiting for device to spin up "
3266 "(%lu secs)\n", secs);
3267
3268 schedule_timeout_uninterruptible(end - jiffies);
3269} 3305}
3270 3306
3271/** 3307/**
3272 * ata_std_prereset - prepare for reset 3308 * ata_std_prereset - prepare for reset
3273 * @ap: ATA port to be reset 3309 * @ap: ATA port to be reset
3310 * @deadline: deadline jiffies for the operation
3274 * 3311 *
3275 * @ap is about to be reset. Initialize it. 3312 * @ap is about to be reset. Initialize it. Failure from
3313 * prereset makes libata abort whole reset sequence and give up
3314 * that port, so prereset should be best-effort. It does its
3315 * best to prepare for reset sequence but if things go wrong, it
3316 * should just whine, not fail.
3276 * 3317 *
3277 * LOCKING: 3318 * LOCKING:
3278 * Kernel thread context (may sleep) 3319 * Kernel thread context (may sleep)
@@ -3280,41 +3321,41 @@ static void ata_wait_spinup(struct ata_port *ap)
3280 * RETURNS: 3321 * RETURNS:
3281 * 0 on success, -errno otherwise. 3322 * 0 on success, -errno otherwise.
3282 */ 3323 */
3283int ata_std_prereset(struct ata_port *ap) 3324int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
3284{ 3325{
3285 struct ata_eh_context *ehc = &ap->eh_context; 3326 struct ata_eh_context *ehc = &ap->eh_context;
3286 const unsigned long *timing = sata_ehc_deb_timing(ehc); 3327 const unsigned long *timing = sata_ehc_deb_timing(ehc);
3287 int rc; 3328 int rc;
3288 3329
3289 /* handle link resume & hotplug spinup */ 3330 /* handle link resume */
3290 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) && 3331 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) &&
3291 (ap->flags & ATA_FLAG_HRST_TO_RESUME)) 3332 (ap->flags & ATA_FLAG_HRST_TO_RESUME))
3292 ehc->i.action |= ATA_EH_HARDRESET; 3333 ehc->i.action |= ATA_EH_HARDRESET;
3293 3334
3294 if ((ehc->i.flags & ATA_EHI_HOTPLUGGED) &&
3295 (ap->flags & ATA_FLAG_SKIP_D2H_BSY))
3296 ata_wait_spinup(ap);
3297
3298 /* if we're about to do hardreset, nothing more to do */ 3335 /* if we're about to do hardreset, nothing more to do */
3299 if (ehc->i.action & ATA_EH_HARDRESET) 3336 if (ehc->i.action & ATA_EH_HARDRESET)
3300 return 0; 3337 return 0;
3301 3338
3302 /* if SATA, resume phy */ 3339 /* if SATA, resume phy */
3303 if (ap->cbl == ATA_CBL_SATA) { 3340 if (ap->cbl == ATA_CBL_SATA) {
3304 rc = sata_phy_resume(ap, timing); 3341 rc = sata_phy_resume(ap, timing, deadline);
3305 if (rc && rc != -EOPNOTSUPP) { 3342 /* whine about phy resume failure but proceed */
3306 /* phy resume failed */ 3343 if (rc && rc != -EOPNOTSUPP)
3307 ata_port_printk(ap, KERN_WARNING, "failed to resume " 3344 ata_port_printk(ap, KERN_WARNING, "failed to resume "
3308 "link for reset (errno=%d)\n", rc); 3345 "link for reset (errno=%d)\n", rc);
3309 return rc;
3310 }
3311 } 3346 }
3312 3347
3313 /* Wait for !BSY if the controller can wait for the first D2H 3348 /* Wait for !BSY if the controller can wait for the first D2H
3314 * Reg FIS and we don't know that no device is attached. 3349 * Reg FIS and we don't know that no device is attached.
3315 */ 3350 */
3316 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap)) 3351 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap)) {
3317 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 3352 rc = ata_wait_ready(ap, deadline);
3353 if (rc) {
3354 ata_port_printk(ap, KERN_WARNING, "device not ready "
3355 "(errno=%d), forcing hardreset\n", rc);
3356 ehc->i.action |= ATA_EH_HARDRESET;
3357 }
3358 }
3318 3359
3319 return 0; 3360 return 0;
3320} 3361}
@@ -3323,6 +3364,7 @@ int ata_std_prereset(struct ata_port *ap)
3323 * ata_std_softreset - reset host port via ATA SRST 3364 * ata_std_softreset - reset host port via ATA SRST
3324 * @ap: port to reset 3365 * @ap: port to reset
3325 * @classes: resulting classes of attached devices 3366 * @classes: resulting classes of attached devices
3367 * @deadline: deadline jiffies for the operation
3326 * 3368 *
3327 * Reset host port using ATA SRST. 3369 * Reset host port using ATA SRST.
3328 * 3370 *
@@ -3332,10 +3374,12 @@ int ata_std_prereset(struct ata_port *ap)
3332 * RETURNS: 3374 * RETURNS:
3333 * 0 on success, -errno otherwise. 3375 * 0 on success, -errno otherwise.
3334 */ 3376 */
3335int ata_std_softreset(struct ata_port *ap, unsigned int *classes) 3377int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
3378 unsigned long deadline)
3336{ 3379{
3337 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 3380 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
3338 unsigned int devmask = 0, err_mask; 3381 unsigned int devmask = 0;
3382 int rc;
3339 u8 err; 3383 u8 err;
3340 3384
3341 DPRINTK("ENTER\n"); 3385 DPRINTK("ENTER\n");
@@ -3356,11 +3400,11 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
3356 3400
3357 /* issue bus reset */ 3401 /* issue bus reset */
3358 DPRINTK("about to softreset, devmask=%x\n", devmask); 3402 DPRINTK("about to softreset, devmask=%x\n", devmask);
3359 err_mask = ata_bus_softreset(ap, devmask); 3403 rc = ata_bus_softreset(ap, devmask, deadline);
3360 if (err_mask) { 3404 /* if link is occupied, -ENODEV too is an error */
3361 ata_port_printk(ap, KERN_ERR, "SRST failed (err_mask=0x%x)\n", 3405 if (rc && (rc != -ENODEV || sata_scr_valid(ap))) {
3362 err_mask); 3406 ata_port_printk(ap, KERN_ERR, "SRST failed (errno=%d)\n", rc);
3363 return -EIO; 3407 return rc;
3364 } 3408 }
3365 3409
3366 /* determine by signature whether we have ATA or ATAPI devices */ 3410 /* determine by signature whether we have ATA or ATAPI devices */
@@ -3377,6 +3421,7 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
3377 * sata_port_hardreset - reset port via SATA phy reset 3421 * sata_port_hardreset - reset port via SATA phy reset
3378 * @ap: port to reset 3422 * @ap: port to reset
3379 * @timing: timing parameters { interval, duratinon, timeout } in msec 3423 * @timing: timing parameters { interval, duratinon, timeout } in msec
3424 * @deadline: deadline jiffies for the operation
3380 * 3425 *
3381 * SATA phy-reset host port using DET bits of SControl register. 3426 * SATA phy-reset host port using DET bits of SControl register.
3382 * 3427 *
@@ -3386,7 +3431,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
3386 * RETURNS: 3431 * RETURNS:
3387 * 0 on success, -errno otherwise. 3432 * 0 on success, -errno otherwise.
3388 */ 3433 */
3389int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing) 3434int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing,
3435 unsigned long deadline)
3390{ 3436{
3391 u32 scontrol; 3437 u32 scontrol;
3392 int rc; 3438 int rc;
@@ -3425,7 +3471,7 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
3425 msleep(1); 3471 msleep(1);
3426 3472
3427 /* bring phy back */ 3473 /* bring phy back */
3428 rc = sata_phy_resume(ap, timing); 3474 rc = sata_phy_resume(ap, timing, deadline);
3429 out: 3475 out:
3430 DPRINTK("EXIT, rc=%d\n", rc); 3476 DPRINTK("EXIT, rc=%d\n", rc);
3431 return rc; 3477 return rc;
@@ -3435,6 +3481,7 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
3435 * sata_std_hardreset - reset host port via SATA phy reset 3481 * sata_std_hardreset - reset host port via SATA phy reset
3436 * @ap: port to reset 3482 * @ap: port to reset
3437 * @class: resulting class of attached device 3483 * @class: resulting class of attached device
3484 * @deadline: deadline jiffies for the operation
3438 * 3485 *
3439 * SATA phy-reset host port using DET bits of SControl register, 3486 * SATA phy-reset host port using DET bits of SControl register,
3440 * wait for !BSY and classify the attached device. 3487 * wait for !BSY and classify the attached device.
@@ -3445,7 +3492,8 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
3445 * RETURNS: 3492 * RETURNS:
3446 * 0 on success, -errno otherwise. 3493 * 0 on success, -errno otherwise.
3447 */ 3494 */
3448int sata_std_hardreset(struct ata_port *ap, unsigned int *class) 3495int sata_std_hardreset(struct ata_port *ap, unsigned int *class,
3496 unsigned long deadline)
3449{ 3497{
3450 const unsigned long *timing = sata_ehc_deb_timing(&ap->eh_context); 3498 const unsigned long *timing = sata_ehc_deb_timing(&ap->eh_context);
3451 int rc; 3499 int rc;
@@ -3453,7 +3501,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
3453 DPRINTK("ENTER\n"); 3501 DPRINTK("ENTER\n");
3454 3502
3455 /* do hardreset */ 3503 /* do hardreset */
3456 rc = sata_port_hardreset(ap, timing); 3504 rc = sata_port_hardreset(ap, timing, deadline);
3457 if (rc) { 3505 if (rc) {
3458 ata_port_printk(ap, KERN_ERR, 3506 ata_port_printk(ap, KERN_ERR,
3459 "COMRESET failed (errno=%d)\n", rc); 3507 "COMRESET failed (errno=%d)\n", rc);
@@ -3470,10 +3518,12 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
3470 /* wait a while before checking status, see SRST for more info */ 3518 /* wait a while before checking status, see SRST for more info */
3471 msleep(150); 3519 msleep(150);
3472 3520
3473 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 3521 rc = ata_wait_ready(ap, deadline);
3522 /* link occupied, -ENODEV too is an error */
3523 if (rc) {
3474 ata_port_printk(ap, KERN_ERR, 3524 ata_port_printk(ap, KERN_ERR,
3475 "COMRESET failed (device not ready)\n"); 3525 "COMRESET failed (errno=%d)\n", rc);
3476 return -EIO; 3526 return rc;
3477 } 3527 }
3478 3528
3479 ap->ops->dev_select(ap, 0); /* probably unnecessary */ 3529 ap->ops->dev_select(ap, 0); /* probably unnecessary */
@@ -6793,6 +6843,7 @@ EXPORT_SYMBOL_GPL(ata_port_disable);
6793EXPORT_SYMBOL_GPL(ata_ratelimit); 6843EXPORT_SYMBOL_GPL(ata_ratelimit);
6794EXPORT_SYMBOL_GPL(ata_wait_register); 6844EXPORT_SYMBOL_GPL(ata_wait_register);
6795EXPORT_SYMBOL_GPL(ata_busy_sleep); 6845EXPORT_SYMBOL_GPL(ata_busy_sleep);
6846EXPORT_SYMBOL_GPL(ata_wait_ready);
6796EXPORT_SYMBOL_GPL(ata_port_queue_task); 6847EXPORT_SYMBOL_GPL(ata_port_queue_task);
6797EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 6848EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
6798EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 6849EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 2bff9adcacf1..8256655ce7d9 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -50,6 +50,28 @@ enum {
50 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2), 50 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2),
51}; 51};
52 52
53/* Waiting in ->prereset can never be reliable. It's sometimes nice
54 * to wait there but it can't be depended upon; otherwise, we wouldn't
55 * be resetting. Just give it enough time for most drives to spin up.
56 */
57enum {
58 ATA_EH_PRERESET_TIMEOUT = 10 * HZ,
59};
60
61/* The following table determines how we sequence resets. Each entry
62 * represents timeout for that try. The first try can be soft or
63 * hardreset. All others are hardreset if available. In most cases
64 * the first reset w/ 10sec timeout should succeed. Following entries
65 * are mostly for error handling, hotplug and retarded devices.
66 */
67static const unsigned long ata_eh_reset_timeouts[] = {
68 10 * HZ, /* most drives spin up by 10sec */
69 10 * HZ, /* > 99% working drives spin up before 20sec */
70 35 * HZ, /* give > 30 secs of idleness for retarded devices */
71 5 * HZ, /* and sweet one last chance */
72 /* > 1 min has elapsed, give up */
73};
74
53static void __ata_port_freeze(struct ata_port *ap); 75static void __ata_port_freeze(struct ata_port *ap);
54static void ata_eh_finish(struct ata_port *ap); 76static void ata_eh_finish(struct ata_port *ap);
55#ifdef CONFIG_PM 77#ifdef CONFIG_PM
@@ -1558,14 +1580,14 @@ static void ata_eh_report(struct ata_port *ap)
1558} 1580}
1559 1581
1560static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset, 1582static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset,
1561 unsigned int *classes) 1583 unsigned int *classes, unsigned long deadline)
1562{ 1584{
1563 int i, rc; 1585 int i, rc;
1564 1586
1565 for (i = 0; i < ATA_MAX_DEVICES; i++) 1587 for (i = 0; i < ATA_MAX_DEVICES; i++)
1566 classes[i] = ATA_DEV_UNKNOWN; 1588 classes[i] = ATA_DEV_UNKNOWN;
1567 1589
1568 rc = reset(ap, classes); 1590 rc = reset(ap, classes, deadline);
1569 if (rc) 1591 if (rc)
1570 return rc; 1592 return rc;
1571 1593
@@ -1603,8 +1625,9 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1603{ 1625{
1604 struct ata_eh_context *ehc = &ap->eh_context; 1626 struct ata_eh_context *ehc = &ap->eh_context;
1605 unsigned int *classes = ehc->classes; 1627 unsigned int *classes = ehc->classes;
1606 int tries = ATA_EH_RESET_TRIES;
1607 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); 1628 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
1629 int try = 0;
1630 unsigned long deadline;
1608 unsigned int action; 1631 unsigned int action;
1609 ata_reset_fn_t reset; 1632 ata_reset_fn_t reset;
1610 int i, did_followup_srst, rc; 1633 int i, did_followup_srst, rc;
@@ -1624,7 +1647,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1624 ehc->i.action |= ATA_EH_HARDRESET; 1647 ehc->i.action |= ATA_EH_HARDRESET;
1625 1648
1626 if (prereset) { 1649 if (prereset) {
1627 rc = prereset(ap); 1650 rc = prereset(ap, jiffies + ATA_EH_PRERESET_TIMEOUT);
1628 if (rc) { 1651 if (rc) {
1629 if (rc == -ENOENT) { 1652 if (rc == -ENOENT) {
1630 ata_port_printk(ap, KERN_DEBUG, 1653 ata_port_printk(ap, KERN_DEBUG,
@@ -1665,6 +1688,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1665 } 1688 }
1666 1689
1667 retry: 1690 retry:
1691 deadline = jiffies + ata_eh_reset_timeouts[try++];
1692
1668 /* shut up during boot probing */ 1693 /* shut up during boot probing */
1669 if (verbose) 1694 if (verbose)
1670 ata_port_printk(ap, KERN_INFO, "%s resetting port\n", 1695 ata_port_printk(ap, KERN_INFO, "%s resetting port\n",
@@ -1676,7 +1701,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1676 else 1701 else
1677 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; 1702 ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
1678 1703
1679 rc = ata_do_reset(ap, reset, classes); 1704 rc = ata_do_reset(ap, reset, classes, deadline);
1680 1705
1681 did_followup_srst = 0; 1706 did_followup_srst = 0;
1682 if (reset == hardreset && 1707 if (reset == hardreset &&
@@ -1693,7 +1718,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1693 } 1718 }
1694 1719
1695 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK); 1720 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK);
1696 rc = ata_do_reset(ap, reset, classes); 1721 rc = ata_do_reset(ap, reset, classes, deadline);
1697 1722
1698 if (rc == 0 && classify && 1723 if (rc == 0 && classify &&
1699 classes[0] == ATA_DEV_UNKNOWN) { 1724 classes[0] == ATA_DEV_UNKNOWN) {
@@ -1703,22 +1728,21 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1703 } 1728 }
1704 } 1729 }
1705 1730
1706 if (rc && --tries) { 1731 if (rc && try < ARRAY_SIZE(ata_eh_reset_timeouts)) {
1707 const char *type; 1732 unsigned long now = jiffies;
1708 1733
1709 if (reset == softreset) { 1734 if (time_before(now, deadline)) {
1710 if (did_followup_srst) 1735 unsigned long delta = deadline - jiffies;
1711 type = "follow-up soft";
1712 else
1713 type = "soft";
1714 } else
1715 type = "hard";
1716 1736
1717 ata_port_printk(ap, KERN_WARNING, 1737 ata_port_printk(ap, KERN_WARNING, "reset failed "
1718 "%sreset failed, retrying in 5 secs\n", type); 1738 "(errno=%d), retrying in %u secs\n",
1719 ssleep(5); 1739 rc, (jiffies_to_msecs(delta) + 999) / 1000);
1740
1741 schedule_timeout_uninterruptible(delta);
1742 }
1720 1743
1721 if (reset == hardreset) 1744 if (reset == hardreset &&
1745 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1)
1722 sata_down_spd_limit(ap); 1746 sata_down_spd_limit(ap);
1723 if (hardreset) 1747 if (hardreset)
1724 reset = hardreset; 1748 reset = hardreset;
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 536ee892ab72..67c7e87dec04 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -121,12 +121,13 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
121/** 121/**
122 * amd_probe_init - perform reset handling 122 * amd_probe_init - perform reset handling
123 * @ap: ATA port 123 * @ap: ATA port
124 * @deadline: deadline jiffies for the operation
124 * 125 *
125 * Reset sequence checking enable bits to see which ports are 126 * Reset sequence checking enable bits to see which ports are
126 * active. 127 * active.
127 */ 128 */
128 129
129static int amd_pre_reset(struct ata_port *ap) 130static int amd_pre_reset(struct ata_port *ap, unsigned long deadline)
130{ 131{
131 static const struct pci_bits amd_enable_bits[] = { 132 static const struct pci_bits amd_enable_bits[] = {
132 { 0x40, 1, 0x02, 0x02 }, 133 { 0x40, 1, 0x02, 0x02 },
@@ -138,8 +139,7 @@ static int amd_pre_reset(struct ata_port *ap)
138 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) 139 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
139 return -ENOENT; 140 return -ENOENT;
140 141
141 return ata_std_prereset(ap); 142 return ata_std_prereset(ap, deadline);
142
143} 143}
144 144
145static void amd_error_handler(struct ata_port *ap) 145static void amd_error_handler(struct ata_port *ap)
@@ -227,7 +227,8 @@ static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
227 * space for us. 227 * space for us.
228 */ 228 */
229 229
230static int nv_pre_reset(struct ata_port *ap) { 230static int nv_pre_reset(struct ata_port *ap, unsigned long deadline)
231{
231 static const struct pci_bits nv_enable_bits[] = { 232 static const struct pci_bits nv_enable_bits[] = {
232 { 0x50, 1, 0x02, 0x02 }, 233 { 0x50, 1, 0x02, 0x02 },
233 { 0x50, 1, 0x01, 0x01 } 234 { 0x50, 1, 0x01, 0x01 }
@@ -238,7 +239,7 @@ static int nv_pre_reset(struct ata_port *ap) {
238 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no])) 239 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
239 return -ENOENT; 240 return -ENOENT;
240 241
241 return ata_std_prereset(ap); 242 return ata_std_prereset(ap, deadline);
242} 243}
243 244
244static void nv_error_handler(struct ata_port *ap) 245static void nv_error_handler(struct ata_port *ap)
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index 00e9ec342db0..ef51940c3adb 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -39,7 +39,7 @@
39 39
40static int clock = 0; 40static int clock = 0;
41 41
42static int artop6210_pre_reset(struct ata_port *ap) 42static int artop6210_pre_reset(struct ata_port *ap, unsigned long deadline)
43{ 43{
44 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 44 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
45 const struct pci_bits artop_enable_bits[] = { 45 const struct pci_bits artop_enable_bits[] = {
@@ -49,7 +49,8 @@ static int artop6210_pre_reset(struct ata_port *ap)
49 49
50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) 50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
51 return -ENOENT; 51 return -ENOENT;
52 return ata_std_prereset(ap); 52
53 return ata_std_prereset(ap, deadline);
53} 54}
54 55
55/** 56/**
@@ -70,12 +71,13 @@ static void artop6210_error_handler(struct ata_port *ap)
70/** 71/**
71 * artop6260_pre_reset - check for 40/80 pin 72 * artop6260_pre_reset - check for 40/80 pin
72 * @ap: Port 73 * @ap: Port
74 * @deadline: deadline jiffies for the operation
73 * 75 *
74 * The ARTOP hardware reports the cable detect bits in register 0x49. 76 * The ARTOP hardware reports the cable detect bits in register 0x49.
75 * Nothing complicated needed here. 77 * Nothing complicated needed here.
76 */ 78 */
77 79
78static int artop6260_pre_reset(struct ata_port *ap) 80static int artop6260_pre_reset(struct ata_port *ap, unsigned long deadline)
79{ 81{
80 static const struct pci_bits artop_enable_bits[] = { 82 static const struct pci_bits artop_enable_bits[] = {
81 { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */ 83 { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */
@@ -87,7 +89,8 @@ static int artop6260_pre_reset(struct ata_port *ap)
87 /* Odd numbered device ids are the units with enable bits (the -R cards) */ 89 /* Odd numbered device ids are the units with enable bits (the -R cards) */
88 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) 90 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
89 return -ENOENT; 91 return -ENOENT;
90 return ata_std_prereset(ap); 92
93 return ata_std_prereset(ap, deadline);
91} 94}
92 95
93/** 96/**
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 39c871a3ddac..21515381b5b3 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -33,7 +33,7 @@ enum {
33 ATIIXP_IDE_UDMA_MODE = 0x56 33 ATIIXP_IDE_UDMA_MODE = 0x56
34}; 34};
35 35
36static int atiixp_pre_reset(struct ata_port *ap) 36static int atiixp_pre_reset(struct ata_port *ap, unsigned long deadline)
37{ 37{
38 static const struct pci_bits atiixp_enable_bits[] = { 38 static const struct pci_bits atiixp_enable_bits[] = {
39 { 0x48, 1, 0x01, 0x00 }, 39 { 0x48, 1, 0x01, 0x00 },
@@ -44,7 +44,7 @@ static int atiixp_pre_reset(struct ata_port *ap)
44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no])) 44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no]))
45 return -ENOENT; 45 return -ENOENT;
46 46
47 return ata_std_prereset(ap); 47 return ata_std_prereset(ap, deadline);
48} 48}
49 49
50static void atiixp_error_handler(struct ata_port *ap) 50static void atiixp_error_handler(struct ata_port *ap)
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 08cccc9c659b..22006ae71941 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -72,6 +72,7 @@
72/** 72/**
73 * cs5535_cable_detect - detect cable type 73 * cs5535_cable_detect - detect cable type
74 * @ap: Port to detect on 74 * @ap: Port to detect on
75 * @deadline: deadline jiffies for the operation
75 * 76 *
76 * Perform cable detection for ATA66 capable cable. Return a libata 77 * Perform cable detection for ATA66 capable cable. Return a libata
77 * cable type. 78 * cable type.
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index a3216850bba1..d0f52e034906 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -27,12 +27,13 @@
27/** 27/**
28 * efar_pre_reset - Enable bits 28 * efar_pre_reset - Enable bits
29 * @ap: Port 29 * @ap: Port
30 * @deadline: deadline jiffies for the operation
30 * 31 *
31 * Perform cable detection for the EFAR ATA interface. This is 32 * Perform cable detection for the EFAR ATA interface. This is
32 * different to the PIIX arrangement 33 * different to the PIIX arrangement
33 */ 34 */
34 35
35static int efar_pre_reset(struct ata_port *ap) 36static int efar_pre_reset(struct ata_port *ap, unsigned long deadline)
36{ 37{
37 static const struct pci_bits efar_enable_bits[] = { 38 static const struct pci_bits efar_enable_bits[] = {
38 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */ 39 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
@@ -43,7 +44,7 @@ static int efar_pre_reset(struct ata_port *ap)
43 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no])) 44 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no]))
44 return -ENOENT; 45 return -ENOENT;
45 46
46 return ata_std_prereset(ap); 47 return ata_std_prereset(ap, deadline);
47} 48}
48 49
49/** 50/**
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 93cfa6d300a5..e64e05e5c7fe 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -220,7 +220,7 @@ static int hpt36x_cable_detect(struct ata_port *ap)
220 return ATA_CBL_PATA80; 220 return ATA_CBL_PATA80;
221} 221}
222 222
223static int hpt36x_pre_reset(struct ata_port *ap) 223static int hpt36x_pre_reset(struct ata_port *ap, unsigned long deadline)
224{ 224{
225 static const struct pci_bits hpt36x_enable_bits[] = { 225 static const struct pci_bits hpt36x_enable_bits[] = {
226 { 0x50, 1, 0x04, 0x04 }, 226 { 0x50, 1, 0x04, 0x04 },
@@ -231,7 +231,7 @@ static int hpt36x_pre_reset(struct ata_port *ap)
231 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no])) 231 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no]))
232 return -ENOENT; 232 return -ENOENT;
233 233
234 return ata_std_prereset(ap); 234 return ata_std_prereset(ap, deadline);
235} 235}
236 236
237/** 237/**
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 41d831296347..1614e8c822a4 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -307,11 +307,12 @@ static unsigned long hpt370a_filter(struct ata_device *adev, unsigned long mask)
307/** 307/**
308 * hpt37x_pre_reset - reset the hpt37x bus 308 * hpt37x_pre_reset - reset the hpt37x bus
309 * @ap: ATA port to reset 309 * @ap: ATA port to reset
310 * @deadline: deadline jiffies for the operation
310 * 311 *
311 * Perform the initial reset handling for the 370/372 and 374 func 0 312 * Perform the initial reset handling for the 370/372 and 374 func 0
312 */ 313 */
313 314
314static int hpt37x_pre_reset(struct ata_port *ap) 315static int hpt37x_pre_reset(struct ata_port *ap, unsigned long deadline)
315{ 316{
316 u8 scr2, ata66; 317 u8 scr2, ata66;
317 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 318 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -338,7 +339,7 @@ static int hpt37x_pre_reset(struct ata_port *ap)
338 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 339 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
339 udelay(100); 340 udelay(100);
340 341
341 return ata_std_prereset(ap); 342 return ata_std_prereset(ap, deadline);
342} 343}
343 344
344/** 345/**
@@ -353,7 +354,7 @@ static void hpt37x_error_handler(struct ata_port *ap)
353 ata_bmdma_drive_eh(ap, hpt37x_pre_reset, ata_std_softreset, NULL, ata_std_postreset); 354 ata_bmdma_drive_eh(ap, hpt37x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
354} 355}
355 356
356static int hpt374_pre_reset(struct ata_port *ap) 357static int hpt374_pre_reset(struct ata_port *ap, unsigned long deadline)
357{ 358{
358 static const struct pci_bits hpt37x_enable_bits[] = { 359 static const struct pci_bits hpt37x_enable_bits[] = {
359 { 0x50, 1, 0x04, 0x04 }, 360 { 0x50, 1, 0x04, 0x04 },
@@ -388,7 +389,7 @@ static int hpt374_pre_reset(struct ata_port *ap)
388 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 389 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
389 udelay(100); 390 udelay(100);
390 391
391 return ata_std_prereset(ap); 392 return ata_std_prereset(ap, deadline);
392} 393}
393 394
394/** 395/**
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 6a34521b9e01..ea1037d67860 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -148,13 +148,14 @@ static int hpt3x2n_cable_detect(struct ata_port *ap)
148 * Reset the hardware and state machine, 148 * Reset the hardware and state machine,
149 */ 149 */
150 150
151static int hpt3xn_pre_reset(struct ata_port *ap) 151static int hpt3xn_pre_reset(struct ata_port *ap, unsigned long deadline)
152{ 152{
153 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 153 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
154 /* Reset the state machine */ 154 /* Reset the state machine */
155 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 155 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
156 udelay(100); 156 udelay(100);
157 return ata_std_prereset(ap); 157
158 return ata_std_prereset(ap, deadline);
158} 159}
159 160
160/** 161/**
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
index 011306ef8334..17bf9f3ed013 100644
--- a/drivers/ata/pata_it8213.c
+++ b/drivers/ata/pata_it8213.c
@@ -24,12 +24,13 @@
24/** 24/**
25 * it8213_pre_reset - check for 40/80 pin 25 * it8213_pre_reset - check for 40/80 pin
26 * @ap: Port 26 * @ap: Port
27 * @deadline: deadline jiffies for the operation
27 * 28 *
28 * Filter out ports by the enable bits before doing the normal reset 29 * Filter out ports by the enable bits before doing the normal reset
29 * and probe. 30 * and probe.
30 */ 31 */
31 32
32static int it8213_pre_reset(struct ata_port *ap) 33static int it8213_pre_reset(struct ata_port *ap, unsigned long deadline)
33{ 34{
34 static const struct pci_bits it8213_enable_bits[] = { 35 static const struct pci_bits it8213_enable_bits[] = {
35 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */ 36 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
@@ -37,7 +38,8 @@ static int it8213_pre_reset(struct ata_port *ap)
37 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 38 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
38 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no])) 39 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no]))
39 return -ENOENT; 40 return -ENOENT;
40 return ata_std_prereset(ap); 41
42 return ata_std_prereset(ap, deadline);
41} 43}
42 44
43/** 45/**
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 43763c99ea02..1daf78ac6efb 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -30,16 +30,17 @@ typedef enum {
30/** 30/**
31 * jmicron_pre_reset - check for 40/80 pin 31 * jmicron_pre_reset - check for 40/80 pin
32 * @ap: Port 32 * @ap: Port
33 * @deadline: deadline jiffies for the operation
33 * 34 *
34 * Perform the PATA port setup we need. 35 * Perform the PATA port setup we need.
35 36 *
36 * On the Jmicron 361/363 there is a single PATA port that can be mapped 37 * On the Jmicron 361/363 there is a single PATA port that can be mapped
37 * either as primary or secondary (or neither). We don't do any policy 38 * either as primary or secondary (or neither). We don't do any policy
38 * and setup here. We assume that has been done by init_one and the 39 * and setup here. We assume that has been done by init_one and the
39 * BIOS. 40 * BIOS.
40 */ 41 */
41 42
42static int jmicron_pre_reset(struct ata_port *ap) 43static int jmicron_pre_reset(struct ata_port *ap, unsigned long deadline)
43{ 44{
44 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 45 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
45 u32 control; 46 u32 control;
@@ -102,7 +103,7 @@ static int jmicron_pre_reset(struct ata_port *ap)
102 ap->cbl = ATA_CBL_SATA; 103 ap->cbl = ATA_CBL_SATA;
103 break; 104 break;
104 } 105 }
105 return ata_std_prereset(ap); 106 return ata_std_prereset(ap, deadline);
106} 107}
107 108
108/** 109/**
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index d9b94a1b6954..837b7fe77dc7 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -25,11 +25,12 @@
25/** 25/**
26 * marvell_pre_reset - check for 40/80 pin 26 * marvell_pre_reset - check for 40/80 pin
27 * @ap: Port 27 * @ap: Port
28 * @deadline: deadline jiffies for the operation
28 * 29 *
29 * Perform the PATA port setup we need. 30 * Perform the PATA port setup we need.
30 */ 31 */
31 32
32static int marvell_pre_reset(struct ata_port *ap) 33static int marvell_pre_reset(struct ata_port *ap, unsigned long deadline)
33{ 34{
34 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 35 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
35 u32 devices; 36 u32 devices;
@@ -52,7 +53,8 @@ static int marvell_pre_reset(struct ata_port *ap)
52 if ((pdev->device == 0x6145) && (ap->port_no == 0) && 53 if ((pdev->device == 0x6145) && (ap->port_no == 0) &&
53 (!(devices & 0x10))) /* PATA enable ? */ 54 (!(devices & 0x10))) /* PATA enable ? */
54 return -ENOENT; 55 return -ENOENT;
55 return ata_std_prereset(ap); 56
57 return ata_std_prereset(ap, deadline);
56} 58}
57 59
58static int marvell_cable_detect(struct ata_port *ap) 60static int marvell_cable_detect(struct ata_port *ap)
@@ -67,6 +69,7 @@ static int marvell_cable_detect(struct ata_port *ap)
67 case 1: /* Legacy SATA port */ 69 case 1: /* Legacy SATA port */
68 return ATA_CBL_SATA; 70 return ATA_CBL_SATA;
69 } 71 }
72
70 BUG(); 73 BUG();
71 return 0; /* Our BUG macro needs the right markup */ 74 return 0; /* Our BUG macro needs the right markup */
72} 75}
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 987c5fafab08..3bfbd495f643 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -46,14 +46,15 @@ enum {
46 SECONDARY = (1 << 14) 46 SECONDARY = (1 << 14)
47}; 47};
48 48
49static int mpiix_pre_reset(struct ata_port *ap) 49static int mpiix_pre_reset(struct ata_port *ap, unsigned long deadline)
50{ 50{
51 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 51 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
52 static const struct pci_bits mpiix_enable_bits = { 0x6D, 1, 0x80, 0x80 }; 52 static const struct pci_bits mpiix_enable_bits = { 0x6D, 1, 0x80, 0x80 };
53 53
54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits)) 54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits))
55 return -ENOENT; 55 return -ENOENT;
56 return ata_std_prereset(ap); 56
57 return ata_std_prereset(ap, deadline);
57} 58}
58 59
59/** 60/**
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 078aeda9cf8d..ebc58a907d26 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -33,11 +33,12 @@
33/** 33/**
34 * ns87410_pre_reset - probe begin 34 * ns87410_pre_reset - probe begin
35 * @ap: ATA port 35 * @ap: ATA port
36 * @deadline: deadline jiffies for the operation
36 * 37 *
37 * Check enabled ports 38 * Check enabled ports
38 */ 39 */
39 40
40static int ns87410_pre_reset(struct ata_port *ap) 41static int ns87410_pre_reset(struct ata_port *ap, unsigned long deadline)
41{ 42{
42 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 43 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
43 static const struct pci_bits ns87410_enable_bits[] = { 44 static const struct pci_bits ns87410_enable_bits[] = {
@@ -47,7 +48,8 @@ static int ns87410_pre_reset(struct ata_port *ap)
47 48
48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no])) 49 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no]))
49 return -ENOENT; 50 return -ENOENT;
50 return ata_std_prereset(ap); 51
52 return ata_std_prereset(ap, deadline);
51} 53}
52 54
53/** 55/**
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index dea4690340d1..4d75d32e5826 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -30,11 +30,12 @@
30/** 30/**
31 * oldpiix_pre_reset - probe begin 31 * oldpiix_pre_reset - probe begin
32 * @ap: ATA port 32 * @ap: ATA port
33 * @deadline: deadline jiffies for the operation
33 * 34 *
34 * Set up cable type and use generic probe init 35 * Set up cable type and use generic probe init
35 */ 36 */
36 37
37static int oldpiix_pre_reset(struct ata_port *ap) 38static int oldpiix_pre_reset(struct ata_port *ap, unsigned long deadline)
38{ 39{
39 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 40 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
40 static const struct pci_bits oldpiix_enable_bits[] = { 41 static const struct pci_bits oldpiix_enable_bits[] = {
@@ -44,7 +45,8 @@ static int oldpiix_pre_reset(struct ata_port *ap)
44 45
45 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no])) 46 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
46 return -ENOENT; 47 return -ENOENT;
47 return ata_std_prereset(ap); 48
49 return ata_std_prereset(ap, deadline);
48} 50}
49 51
50/** 52/**
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index 13b63e21838d..0af8a2c77cc9 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -47,11 +47,12 @@ enum {
47/** 47/**
48 * opti_pre_reset - probe begin 48 * opti_pre_reset - probe begin
49 * @ap: ATA port 49 * @ap: ATA port
50 * @deadline: deadline jiffies for the operation
50 * 51 *
51 * Set up cable type and use generic probe init 52 * Set up cable type and use generic probe init
52 */ 53 */
53 54
54static int opti_pre_reset(struct ata_port *ap) 55static int opti_pre_reset(struct ata_port *ap, unsigned long deadline)
55{ 56{
56 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 57 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
57 static const struct pci_bits opti_enable_bits[] = { 58 static const struct pci_bits opti_enable_bits[] = {
@@ -61,7 +62,8 @@ static int opti_pre_reset(struct ata_port *ap)
61 62
62 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no])) 63 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no]))
63 return -ENOENT; 64 return -ENOENT;
64 return ata_std_prereset(ap); 65
66 return ata_std_prereset(ap, deadline);
65} 67}
66 68
67/** 69/**
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index b70e04c144df..2843e480f216 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -48,11 +48,12 @@ static int pci_clock; /* 0 = 33 1 = 25 */
48/** 48/**
49 * optidma_pre_reset - probe begin 49 * optidma_pre_reset - probe begin
50 * @ap: ATA port 50 * @ap: ATA port
51 * @deadline: deadline jiffies for the operation
51 * 52 *
52 * Set up cable type and use generic probe init 53 * Set up cable type and use generic probe init
53 */ 54 */
54 55
55static int optidma_pre_reset(struct ata_port *ap) 56static int optidma_pre_reset(struct ata_port *ap, unsigned long deadline)
56{ 57{
57 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 58 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
58 static const struct pci_bits optidma_enable_bits = { 59 static const struct pci_bits optidma_enable_bits = {
@@ -62,7 +63,7 @@ static int optidma_pre_reset(struct ata_port *ap)
62 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits)) 63 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits))
63 return -ENOENT; 64 return -ENOENT;
64 65
65 return ata_std_prereset(ap); 66 return ata_std_prereset(ap, deadline);
66} 67}
67 68
68/** 69/**
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index a61cbc110688..0d2cc49fde4b 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -301,6 +301,7 @@ static inline int pdc2027x_port_enabled(struct ata_port *ap)
301/** 301/**
302 * pdc2027x_prereset - prereset for PATA host controller 302 * pdc2027x_prereset - prereset for PATA host controller
303 * @ap: Target port 303 * @ap: Target port
304 * @deadline: deadline jiffies for the operation
304 * 305 *
305 * Probeinit including cable detection. 306 * Probeinit including cable detection.
306 * 307 *
@@ -308,12 +309,12 @@ static inline int pdc2027x_port_enabled(struct ata_port *ap)
308 * None (inherited from caller). 309 * None (inherited from caller).
309 */ 310 */
310 311
311static int pdc2027x_prereset(struct ata_port *ap) 312static int pdc2027x_prereset(struct ata_port *ap, unsigned long deadline)
312{ 313{
313 /* Check whether port enabled */ 314 /* Check whether port enabled */
314 if (!pdc2027x_port_enabled(ap)) 315 if (!pdc2027x_port_enabled(ap))
315 return -ENOENT; 316 return -ENOENT;
316 return ata_std_prereset(ap); 317 return ata_std_prereset(ap, deadline);
317} 318}
318 319
319/** 320/**
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index 3956ef26936d..b6e020383dd9 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -139,12 +139,14 @@ static struct sv_cable_table cable_detect[] = {
139/** 139/**
140 * serverworks_cable_detect - cable detection 140 * serverworks_cable_detect - cable detection
141 * @ap: ATA port 141 * @ap: ATA port
142 * @deadline: deadline jiffies for the operation
142 * 143 *
143 * Perform cable detection according to the device and subvendor 144 * Perform cable detection according to the device and subvendor
144 * identifications 145 * identifications
145 */ 146 */
146 147
147static int serverworks_cable_detect(struct ata_port *ap) { 148static int serverworks_cable_detect(struct ata_port *ap)
149{
148 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 150 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
149 struct sv_cable_table *cb = cable_detect; 151 struct sv_cable_table *cb = cable_detect;
150 152
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 6770820cfca9..a5886f061c0b 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -94,11 +94,13 @@ static int sil680_cable_detect(struct ata_port *ap) {
94/** 94/**
95 * sil680_bus_reset - reset the SIL680 bus 95 * sil680_bus_reset - reset the SIL680 bus
96 * @ap: ATA port to reset 96 * @ap: ATA port to reset
97 * @deadline: deadline jiffies for the operation
97 * 98 *
98 * Perform the SIL680 housekeeping when doing an ATA bus reset 99 * Perform the SIL680 housekeeping when doing an ATA bus reset
99 */ 100 */
100 101
101static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes) 102static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes,
103 unsigned long deadline)
102{ 104{
103 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 105 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
104 unsigned long addr = sil680_selreg(ap, 0); 106 unsigned long addr = sil680_selreg(ap, 0);
@@ -108,7 +110,7 @@ static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes)
108 pci_write_config_byte(pdev, addr, reset | 0x03); 110 pci_write_config_byte(pdev, addr, reset | 0x03);
109 udelay(25); 111 udelay(25);
110 pci_write_config_byte(pdev, addr, reset); 112 pci_write_config_byte(pdev, addr, reset);
111 return ata_std_softreset(ap, classes); 113 return ata_std_softreset(ap, classes, deadline);
112} 114}
113 115
114static void sil680_error_handler(struct ata_port *ap) 116static void sil680_error_handler(struct ata_port *ap)
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index a3fbcee6fb33..f5838cc11728 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -88,6 +88,7 @@ static int sis_port_base(struct ata_device *adev)
88/** 88/**
89 * sis_133_cable_detect - check for 40/80 pin 89 * sis_133_cable_detect - check for 40/80 pin
90 * @ap: Port 90 * @ap: Port
91 * @deadline: deadline jiffies for the operation
91 * 92 *
92 * Perform cable detection for the later UDMA133 capable 93 * Perform cable detection for the later UDMA133 capable
93 * SiS chipset. 94 * SiS chipset.
@@ -108,6 +109,7 @@ static int sis_133_cable_detect(struct ata_port *ap)
108/** 109/**
109 * sis_66_cable_detect - check for 40/80 pin 110 * sis_66_cable_detect - check for 40/80 pin
110 * @ap: Port 111 * @ap: Port
112 * @deadline: deadline jiffies for the operation
111 * 113 *
112 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133 114 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
113 * SiS IDE controllers. 115 * SiS IDE controllers.
@@ -130,11 +132,12 @@ static int sis_66_cable_detect(struct ata_port *ap)
130/** 132/**
131 * sis_pre_reset - probe begin 133 * sis_pre_reset - probe begin
132 * @ap: ATA port 134 * @ap: ATA port
135 * @deadline: deadline jiffies for the operation
133 * 136 *
134 * Set up cable type and use generic probe init 137 * Set up cable type and use generic probe init
135 */ 138 */
136 139
137static int sis_pre_reset(struct ata_port *ap) 140static int sis_pre_reset(struct ata_port *ap, unsigned long deadline)
138{ 141{
139 static const struct pci_bits sis_enable_bits[] = { 142 static const struct pci_bits sis_enable_bits[] = {
140 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */ 143 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
@@ -145,7 +148,8 @@ static int sis_pre_reset(struct ata_port *ap)
145 148
146 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) 149 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
147 return -ENOENT; 150 return -ENOENT;
148 return ata_std_prereset(ap); 151
152 return ata_std_prereset(ap, deadline);
149} 153}
150 154
151 155
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index da9e22b25753..9aeffdbe2829 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -44,11 +44,12 @@ enum {
44/** 44/**
45 * sl82c105_pre_reset - probe begin 45 * sl82c105_pre_reset - probe begin
46 * @ap: ATA port 46 * @ap: ATA port
47 * @deadline: deadline jiffies for the operation
47 * 48 *
48 * Set up cable type and use generic probe init 49 * Set up cable type and use generic probe init
49 */ 50 */
50 51
51static int sl82c105_pre_reset(struct ata_port *ap) 52static int sl82c105_pre_reset(struct ata_port *ap, unsigned long deadline)
52{ 53{
53 static const struct pci_bits sl82c105_enable_bits[] = { 54 static const struct pci_bits sl82c105_enable_bits[] = {
54 { 0x40, 1, 0x01, 0x01 }, 55 { 0x40, 1, 0x01, 0x01 },
@@ -58,7 +59,7 @@ static int sl82c105_pre_reset(struct ata_port *ap)
58 59
59 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no])) 60 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no]))
60 return -ENOENT; 61 return -ENOENT;
61 return ata_std_prereset(ap); 62 return ata_std_prereset(ap, deadline);
62} 63}
63 64
64 65
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index e618ffd6e944..349887bf5b93 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -48,11 +48,12 @@
48/** 48/**
49 * triflex_prereset - probe begin 49 * triflex_prereset - probe begin
50 * @ap: ATA port 50 * @ap: ATA port
51 * @deadline: deadline jiffies for the operation
51 * 52 *
52 * Set up cable type and use generic probe init 53 * Set up cable type and use generic probe init
53 */ 54 */
54 55
55static int triflex_prereset(struct ata_port *ap) 56static int triflex_prereset(struct ata_port *ap, unsigned long deadline)
56{ 57{
57 static const struct pci_bits triflex_enable_bits[] = { 58 static const struct pci_bits triflex_enable_bits[] = {
58 { 0x80, 1, 0x01, 0x01 }, 59 { 0x80, 1, 0x01, 0x01 },
@@ -63,7 +64,8 @@ static int triflex_prereset(struct ata_port *ap)
63 64
64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no])) 65 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
65 return -ENOENT; 66 return -ENOENT;
66 return ata_std_prereset(ap); 67
68 return ata_std_prereset(ap, deadline);
67} 69}
68 70
69 71
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index 96b71791d2f4..362beb2f489c 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -154,7 +154,7 @@ static int via_cable_detect(struct ata_port *ap) {
154 return ATA_CBL_PATA40; 154 return ATA_CBL_PATA40;
155} 155}
156 156
157static int via_pre_reset(struct ata_port *ap) 157static int via_pre_reset(struct ata_port *ap, unsigned long deadline)
158{ 158{
159 const struct via_isa_bridge *config = ap->host->private_data; 159 const struct via_isa_bridge *config = ap->host->private_data;
160 160
@@ -167,7 +167,8 @@ static int via_pre_reset(struct ata_port *ap)
167 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no])) 167 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
168 return -ENOENT; 168 return -ENOENT;
169 } 169 }
170 return ata_std_prereset(ap); 170
171 return ata_std_prereset(ap, deadline);
171} 172}
172 173
173 174
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index f099a1d83a00..b3b62e985f19 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -420,7 +420,8 @@ static void inic_thaw(struct ata_port *ap)
420 * SRST and SControl hardreset don't give valid signature on this 420 * SRST and SControl hardreset don't give valid signature on this
421 * controller. Only controller specific hardreset mechanism works. 421 * controller. Only controller specific hardreset mechanism works.
422 */ 422 */
423static int inic_hardreset(struct ata_port *ap, unsigned int *class) 423static int inic_hardreset(struct ata_port *ap, unsigned int *class,
424 unsigned long deadline)
424{ 425{
425 void __iomem *port_base = inic_port_base(ap); 426 void __iomem *port_base = inic_port_base(ap);
426 void __iomem *idma_ctl = port_base + PORT_IDMA_CTL; 427 void __iomem *idma_ctl = port_base + PORT_IDMA_CTL;
@@ -437,7 +438,7 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class)
437 msleep(1); 438 msleep(1);
438 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl); 439 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl);
439 440
440 rc = sata_phy_resume(ap, timing); 441 rc = sata_phy_resume(ap, timing, deadline);
441 if (rc) { 442 if (rc) {
442 ata_port_printk(ap, KERN_WARNING, "failed to resume " 443 ata_port_printk(ap, KERN_WARNING, "failed to resume "
443 "link after reset (errno=%d)\n", rc); 444 "link after reset (errno=%d)\n", rc);
@@ -451,10 +452,12 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class)
451 /* wait a while before checking status */ 452 /* wait a while before checking status */
452 msleep(150); 453 msleep(150);
453 454
454 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 455 rc = ata_wait_ready(ap, deadline);
455 ata_port_printk(ap, KERN_WARNING, 456 /* link occupied, -ENODEV too is an error */
456 "device busy after hardreset\n"); 457 if (rc) {
457 return -EIO; 458 ata_port_printk(ap, KERN_WARNING, "device not ready "
459 "after hardreset (errno=%d)\n", rc);
460 return rc;
458 } 461 }
459 462
460 ata_tf_read(ap, &tf); 463 ata_tf_read(ap, &tf);
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 02169740ed24..e2e795e58236 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -1405,7 +1405,8 @@ static void nv_ck804_thaw(struct ata_port *ap)
1405 writeb(mask, mmio_base + NV_INT_ENABLE_CK804); 1405 writeb(mask, mmio_base + NV_INT_ENABLE_CK804);
1406} 1406}
1407 1407
1408static int nv_hardreset(struct ata_port *ap, unsigned int *class) 1408static int nv_hardreset(struct ata_port *ap, unsigned int *class,
1409 unsigned long deadline)
1409{ 1410{
1410 unsigned int dummy; 1411 unsigned int dummy;
1411 1412
@@ -1413,7 +1414,7 @@ static int nv_hardreset(struct ata_port *ap, unsigned int *class)
1413 * some controllers. Don't classify on hardreset. For more 1414 * some controllers. Don't classify on hardreset. For more
1414 * info, see http://bugme.osdl.org/show_bug.cgi?id=3352 1415 * info, see http://bugme.osdl.org/show_bug.cgi?id=3352
1415 */ 1416 */
1416 return sata_std_hardreset(ap, &dummy); 1417 return sata_std_hardreset(ap, &dummy, deadline);
1417} 1418}
1418 1419
1419static void nv_error_handler(struct ata_port *ap) 1420static void nv_error_handler(struct ata_port *ap)
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index e6223ba667da..b97ee9f31aec 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -534,7 +534,8 @@ static int sil24_init_port(struct ata_port *ap)
534 return 0; 534 return 0;
535} 535}
536 536
537static int sil24_softreset(struct ata_port *ap, unsigned int *class) 537static int sil24_softreset(struct ata_port *ap, unsigned int *class,
538 unsigned long deadline)
538{ 539{
539 void __iomem *port = ap->ioaddr.cmd_addr; 540 void __iomem *port = ap->ioaddr.cmd_addr;
540 struct sil24_port_priv *pp = ap->private_data; 541 struct sil24_port_priv *pp = ap->private_data;
@@ -566,7 +567,7 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class)
566 567
567 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; 568 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT;
568 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0, 569 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0,
569 100, ATA_TMOUT_BOOT / HZ * 1000); 570 100, jiffies_to_msecs(deadline - jiffies));
570 571
571 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */ 572 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */
572 irq_stat >>= PORT_IRQ_RAW_SHIFT; 573 irq_stat >>= PORT_IRQ_RAW_SHIFT;
@@ -594,7 +595,8 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class)
594 return -EIO; 595 return -EIO;
595} 596}
596 597
597static int sil24_hardreset(struct ata_port *ap, unsigned int *class) 598static int sil24_hardreset(struct ata_port *ap, unsigned int *class,
599 unsigned long deadline)
598{ 600{
599 void __iomem *port = ap->ioaddr.cmd_addr; 601 void __iomem *port = ap->ioaddr.cmd_addr;
600 const char *reason; 602 const char *reason;
@@ -615,7 +617,7 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
615 /* SStatus oscillates between zero and valid status after 617 /* SStatus oscillates between zero and valid status after
616 * DEV_RST, debounce it. 618 * DEV_RST, debounce it.
617 */ 619 */
618 rc = sata_phy_debounce(ap, sata_deb_timing_long); 620 rc = sata_phy_debounce(ap, sata_deb_timing_long, deadline);
619 if (rc) { 621 if (rc) {
620 reason = "PHY debouncing failed"; 622 reason = "PHY debouncing failed";
621 goto err; 623 goto err;
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 1d855f55f5f7..305ab7c68ca5 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -268,6 +268,7 @@ static void svia_noop_freeze(struct ata_port *ap)
268/** 268/**
269 * vt6420_prereset - prereset for vt6420 269 * vt6420_prereset - prereset for vt6420
270 * @ap: target ATA port 270 * @ap: target ATA port
271 * @deadline: deadline jiffies for the operation
271 * 272 *
272 * SCR registers on vt6420 are pieces of shit and may hang the 273 * SCR registers on vt6420 are pieces of shit and may hang the
273 * whole machine completely if accessed with the wrong timing. 274 * whole machine completely if accessed with the wrong timing.
@@ -284,7 +285,7 @@ static void svia_noop_freeze(struct ata_port *ap)
284 * RETURNS: 285 * RETURNS:
285 * 0 on success, -errno otherwise. 286 * 0 on success, -errno otherwise.
286 */ 287 */
287static int vt6420_prereset(struct ata_port *ap) 288static int vt6420_prereset(struct ata_port *ap, unsigned long deadline)
288{ 289{
289 struct ata_eh_context *ehc = &ap->eh_context; 290 struct ata_eh_context *ehc = &ap->eh_context;
290 unsigned long timeout = jiffies + (HZ * 5); 291 unsigned long timeout = jiffies + (HZ * 5);
@@ -329,7 +330,7 @@ static int vt6420_prereset(struct ata_port *ap)
329 330
330 skip_scr: 331 skip_scr:
331 /* wait for !BSY */ 332 /* wait for !BSY */
332 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 333 ata_wait_ready(ap, deadline);
333 334
334 return 0; 335 return 0;
335} 336}