aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-08-06 05:36:23 -0400
committerJeff Garzik <jeff@garzik.org>2007-10-12 14:55:30 -0400
commit936fd7328657884d5a69a55666c74a55aa83ca27 (patch)
tree83a78a02d2c65ce835fe33882dfe5043d3240bff /drivers
parentf58229f8060055b08b34008ea08f31de1e2f003c (diff)
libata-link: linkify PHY-related functions
Make the following PHY-related functions to deal with ata_link instead of ata_port. * sata_print_link_status() * sata_down_spd_limit() * ata_set_sata_spd_limit() and friends * sata_link_debounce/resume() * sata_scr_valid/read/write/write_flush() * ata_link_on/offline() This patch introduces no behavior change. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ata/ahci.c4
-rw-r--r--drivers/ata/libata-core.c227
-rw-r--r--drivers/ata/libata-eh.c31
-rw-r--r--drivers/ata/libata-sff.c2
-rw-r--r--drivers/ata/libata.h4
-rw-r--r--drivers/ata/pata_scc.c2
-rw-r--r--drivers/ata/sata_inic162x.c4
-rw-r--r--drivers/ata/sata_mv.c26
-rw-r--r--drivers/ata/sata_promise.c4
-rw-r--r--drivers/ata/sata_sil24.c10
10 files changed, 165 insertions, 149 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index c72fa468a697..6e5f69a3a0c2 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -1052,7 +1052,7 @@ static int ahci_do_softreset(struct ata_port *ap, unsigned int *class,
1052 1052
1053 DPRINTK("ENTER\n"); 1053 DPRINTK("ENTER\n");
1054 1054
1055 if (ata_port_offline(ap)) { 1055 if (ata_link_offline(&ap->link)) {
1056 DPRINTK("PHY reports no device\n"); 1056 DPRINTK("PHY reports no device\n");
1057 *class = ATA_DEV_NONE; 1057 *class = ATA_DEV_NONE;
1058 return 0; 1058 return 0;
@@ -1140,7 +1140,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class,
1140 1140
1141 ahci_start_engine(ap); 1141 ahci_start_engine(ap);
1142 1142
1143 if (rc == 0 && ata_port_online(ap)) 1143 if (rc == 0 && ata_link_online(&ap->link))
1144 *class = ahci_dev_classify(ap); 1144 *class = ahci_dev_classify(ap);
1145 if (*class == ATA_DEV_UNKNOWN) 1145 if (*class == ATA_DEV_UNKNOWN)
1146 *class = ATA_DEV_NONE; 1146 *class = ATA_DEV_NONE;
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index f30c4771b3af..6f99dee6b6d2 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -2201,7 +2201,7 @@ int ata_bus_probe(struct ata_port *ap)
2201 /* This is the last chance, better to slow 2201 /* This is the last chance, better to slow
2202 * down than lose it. 2202 * down than lose it.
2203 */ 2203 */
2204 sata_down_spd_limit(ap); 2204 sata_down_spd_limit(&ap->link);
2205 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); 2205 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
2206 } 2206 }
2207 } 2207 }
@@ -2230,28 +2230,28 @@ void ata_port_probe(struct ata_port *ap)
2230 2230
2231/** 2231/**
2232 * sata_print_link_status - Print SATA link status 2232 * sata_print_link_status - Print SATA link status
2233 * @ap: SATA port to printk link status about 2233 * @link: SATA link to printk link status about
2234 * 2234 *
2235 * This function prints link speed and status of a SATA link. 2235 * This function prints link speed and status of a SATA link.
2236 * 2236 *
2237 * LOCKING: 2237 * LOCKING:
2238 * None. 2238 * None.
2239 */ 2239 */
2240void sata_print_link_status(struct ata_port *ap) 2240void sata_print_link_status(struct ata_link *link)
2241{ 2241{
2242 u32 sstatus, scontrol, tmp; 2242 u32 sstatus, scontrol, tmp;
2243 2243
2244 if (sata_scr_read(ap, SCR_STATUS, &sstatus)) 2244 if (sata_scr_read(link, SCR_STATUS, &sstatus))
2245 return; 2245 return;
2246 sata_scr_read(ap, SCR_CONTROL, &scontrol); 2246 sata_scr_read(link, SCR_CONTROL, &scontrol);
2247 2247
2248 if (ata_port_online(ap)) { 2248 if (ata_link_online(link)) {
2249 tmp = (sstatus >> 4) & 0xf; 2249 tmp = (sstatus >> 4) & 0xf;
2250 ata_port_printk(ap, KERN_INFO, 2250 ata_link_printk(link, KERN_INFO,
2251 "SATA link up %s (SStatus %X SControl %X)\n", 2251 "SATA link up %s (SStatus %X SControl %X)\n",
2252 sata_spd_string(tmp), sstatus, scontrol); 2252 sata_spd_string(tmp), sstatus, scontrol);
2253 } else { 2253 } else {
2254 ata_port_printk(ap, KERN_INFO, 2254 ata_link_printk(link, KERN_INFO,
2255 "SATA link down (SStatus %X SControl %X)\n", 2255 "SATA link down (SStatus %X SControl %X)\n",
2256 sstatus, scontrol); 2256 sstatus, scontrol);
2257 } 2257 }
@@ -2271,32 +2271,33 @@ void sata_print_link_status(struct ata_port *ap)
2271 */ 2271 */
2272void __sata_phy_reset(struct ata_port *ap) 2272void __sata_phy_reset(struct ata_port *ap)
2273{ 2273{
2274 u32 sstatus; 2274 struct ata_link *link = &ap->link;
2275 unsigned long timeout = jiffies + (HZ * 5); 2275 unsigned long timeout = jiffies + (HZ * 5);
2276 u32 sstatus;
2276 2277
2277 if (ap->flags & ATA_FLAG_SATA_RESET) { 2278 if (ap->flags & ATA_FLAG_SATA_RESET) {
2278 /* issue phy wake/reset */ 2279 /* issue phy wake/reset */
2279 sata_scr_write_flush(ap, SCR_CONTROL, 0x301); 2280 sata_scr_write_flush(link, SCR_CONTROL, 0x301);
2280 /* Couldn't find anything in SATA I/II specs, but 2281 /* Couldn't find anything in SATA I/II specs, but
2281 * AHCI-1.1 10.4.2 says at least 1 ms. */ 2282 * AHCI-1.1 10.4.2 says at least 1 ms. */
2282 mdelay(1); 2283 mdelay(1);
2283 } 2284 }
2284 /* phy wake/clear reset */ 2285 /* phy wake/clear reset */
2285 sata_scr_write_flush(ap, SCR_CONTROL, 0x300); 2286 sata_scr_write_flush(link, SCR_CONTROL, 0x300);
2286 2287
2287 /* wait for phy to become ready, if necessary */ 2288 /* wait for phy to become ready, if necessary */
2288 do { 2289 do {
2289 msleep(200); 2290 msleep(200);
2290 sata_scr_read(ap, SCR_STATUS, &sstatus); 2291 sata_scr_read(link, SCR_STATUS, &sstatus);
2291 if ((sstatus & 0xf) != 1) 2292 if ((sstatus & 0xf) != 1)
2292 break; 2293 break;
2293 } while (time_before(jiffies, timeout)); 2294 } while (time_before(jiffies, timeout));
2294 2295
2295 /* print link status */ 2296 /* print link status */
2296 sata_print_link_status(ap); 2297 sata_print_link_status(link);
2297 2298
2298 /* TODO: phy layer with polling, timeouts, etc. */ 2299 /* TODO: phy layer with polling, timeouts, etc. */
2299 if (!ata_port_offline(ap)) 2300 if (!ata_link_offline(link))
2300 ata_port_probe(ap); 2301 ata_port_probe(ap);
2301 else 2302 else
2302 ata_port_disable(ap); 2303 ata_port_disable(ap);
@@ -2370,9 +2371,9 @@ void ata_port_disable(struct ata_port *ap)
2370 2371
2371/** 2372/**
2372 * sata_down_spd_limit - adjust SATA spd limit downward 2373 * sata_down_spd_limit - adjust SATA spd limit downward
2373 * @ap: Port to adjust SATA spd limit for 2374 * @link: Link to adjust SATA spd limit for
2374 * 2375 *
2375 * Adjust SATA spd limit of @ap downward. Note that this 2376 * Adjust SATA spd limit of @link downward. Note that this
2376 * function only adjusts the limit. The change must be applied 2377 * function only adjusts the limit. The change must be applied
2377 * using sata_set_spd(). 2378 * using sata_set_spd().
2378 * 2379 *
@@ -2382,24 +2383,24 @@ void ata_port_disable(struct ata_port *ap)
2382 * RETURNS: 2383 * RETURNS:
2383 * 0 on success, negative errno on failure 2384 * 0 on success, negative errno on failure
2384 */ 2385 */
2385int sata_down_spd_limit(struct ata_port *ap) 2386int sata_down_spd_limit(struct ata_link *link)
2386{ 2387{
2387 u32 sstatus, spd, mask; 2388 u32 sstatus, spd, mask;
2388 int rc, highbit; 2389 int rc, highbit;
2389 2390
2390 if (!sata_scr_valid(ap)) 2391 if (!sata_scr_valid(link))
2391 return -EOPNOTSUPP; 2392 return -EOPNOTSUPP;
2392 2393
2393 /* If SCR can be read, use it to determine the current SPD. 2394 /* If SCR can be read, use it to determine the current SPD.
2394 * If not, use cached value in ap->sata_spd. 2395 * If not, use cached value in link->sata_spd.
2395 */ 2396 */
2396 rc = sata_scr_read(ap, SCR_STATUS, &sstatus); 2397 rc = sata_scr_read(link, SCR_STATUS, &sstatus);
2397 if (rc == 0) 2398 if (rc == 0)
2398 spd = (sstatus >> 4) & 0xf; 2399 spd = (sstatus >> 4) & 0xf;
2399 else 2400 else
2400 spd = ap->link.sata_spd; 2401 spd = link->sata_spd;
2401 2402
2402 mask = ap->link.sata_spd_limit; 2403 mask = link->sata_spd_limit;
2403 if (mask <= 1) 2404 if (mask <= 1)
2404 return -EINVAL; 2405 return -EINVAL;
2405 2406
@@ -2419,22 +2420,22 @@ int sata_down_spd_limit(struct ata_port *ap)
2419 if (!mask) 2420 if (!mask)
2420 return -EINVAL; 2421 return -EINVAL;
2421 2422
2422 ap->link.sata_spd_limit = mask; 2423 link->sata_spd_limit = mask;
2423 2424
2424 ata_port_printk(ap, KERN_WARNING, "limiting SATA link speed to %s\n", 2425 ata_link_printk(link, KERN_WARNING, "limiting SATA link speed to %s\n",
2425 sata_spd_string(fls(mask))); 2426 sata_spd_string(fls(mask)));
2426 2427
2427 return 0; 2428 return 0;
2428} 2429}
2429 2430
2430static int __sata_set_spd_needed(struct ata_port *ap, u32 *scontrol) 2431static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol)
2431{ 2432{
2432 u32 spd, limit; 2433 u32 spd, limit;
2433 2434
2434 if (ap->link.sata_spd_limit == UINT_MAX) 2435 if (link->sata_spd_limit == UINT_MAX)
2435 limit = 0; 2436 limit = 0;
2436 else 2437 else
2437 limit = fls(ap->link.sata_spd_limit); 2438 limit = fls(link->sata_spd_limit);
2438 2439
2439 spd = (*scontrol >> 4) & 0xf; 2440 spd = (*scontrol >> 4) & 0xf;
2440 *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4); 2441 *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4);
@@ -2444,10 +2445,10 @@ static int __sata_set_spd_needed(struct ata_port *ap, u32 *scontrol)
2444 2445
2445/** 2446/**
2446 * sata_set_spd_needed - is SATA spd configuration needed 2447 * sata_set_spd_needed - is SATA spd configuration needed
2447 * @ap: Port in question 2448 * @link: Link in question
2448 * 2449 *
2449 * Test whether the spd limit in SControl matches 2450 * Test whether the spd limit in SControl matches
2450 * @ap->link.sata_spd_limit. This function is used to determine 2451 * @link->sata_spd_limit. This function is used to determine
2451 * whether hardreset is necessary to apply SATA spd 2452 * whether hardreset is necessary to apply SATA spd
2452 * configuration. 2453 * configuration.
2453 * 2454 *
@@ -2457,21 +2458,21 @@ static int __sata_set_spd_needed(struct ata_port *ap, u32 *scontrol)
2457 * RETURNS: 2458 * RETURNS:
2458 * 1 if SATA spd configuration is needed, 0 otherwise. 2459 * 1 if SATA spd configuration is needed, 0 otherwise.
2459 */ 2460 */
2460int sata_set_spd_needed(struct ata_port *ap) 2461int sata_set_spd_needed(struct ata_link *link)
2461{ 2462{
2462 u32 scontrol; 2463 u32 scontrol;
2463 2464
2464 if (sata_scr_read(ap, SCR_CONTROL, &scontrol)) 2465 if (sata_scr_read(link, SCR_CONTROL, &scontrol))
2465 return 0; 2466 return 0;
2466 2467
2467 return __sata_set_spd_needed(ap, &scontrol); 2468 return __sata_set_spd_needed(link, &scontrol);
2468} 2469}
2469 2470
2470/** 2471/**
2471 * sata_set_spd - set SATA spd according to spd limit 2472 * sata_set_spd - set SATA spd according to spd limit
2472 * @ap: Port to set SATA spd for 2473 * @link: Link to set SATA spd for
2473 * 2474 *
2474 * Set SATA spd of @ap according to sata_spd_limit. 2475 * Set SATA spd of @link according to sata_spd_limit.
2475 * 2476 *
2476 * LOCKING: 2477 * LOCKING:
2477 * Inherited from caller. 2478 * Inherited from caller.
@@ -2480,18 +2481,18 @@ int sata_set_spd_needed(struct ata_port *ap)
2480 * 0 if spd doesn't need to be changed, 1 if spd has been 2481 * 0 if spd doesn't need to be changed, 1 if spd has been
2481 * changed. Negative errno if SCR registers are inaccessible. 2482 * changed. Negative errno if SCR registers are inaccessible.
2482 */ 2483 */
2483int sata_set_spd(struct ata_port *ap) 2484int sata_set_spd(struct ata_link *link)
2484{ 2485{
2485 u32 scontrol; 2486 u32 scontrol;
2486 int rc; 2487 int rc;
2487 2488
2488 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 2489 if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
2489 return rc; 2490 return rc;
2490 2491
2491 if (!__sata_set_spd_needed(ap, &scontrol)) 2492 if (!__sata_set_spd_needed(link, &scontrol))
2492 return 0; 2493 return 0;
2493 2494
2494 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 2495 if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
2495 return rc; 2496 return rc;
2496 2497
2497 return 1; 2498 return 1;
@@ -2997,7 +2998,7 @@ int ata_wait_ready(struct ata_port *ap, unsigned long deadline)
2997 2998
2998 if (!(status & ATA_BUSY)) 2999 if (!(status & ATA_BUSY))
2999 return 0; 3000 return 0;
3000 if (!ata_port_online(ap) && status == 0xff) 3001 if (!ata_link_online(&ap->link) && status == 0xff)
3001 return -ENODEV; 3002 return -ENODEV;
3002 if (time_after(now, deadline)) 3003 if (time_after(now, deadline))
3003 return -EBUSY; 3004 return -EBUSY;
@@ -3199,12 +3200,12 @@ err_out:
3199} 3200}
3200 3201
3201/** 3202/**
3202 * sata_phy_debounce - debounce SATA phy status 3203 * sata_link_debounce - debounce SATA phy status
3203 * @ap: ATA port to debounce SATA phy status for 3204 * @link: ATA link to debounce SATA phy status for
3204 * @params: timing parameters { interval, duratinon, timeout } in msec 3205 * @params: timing parameters { interval, duratinon, timeout } in msec
3205 * @deadline: deadline jiffies for the operation 3206 * @deadline: deadline jiffies for the operation
3206 * 3207 *
3207 * Make sure SStatus of @ap reaches stable state, determined by 3208* Make sure SStatus of @link reaches stable state, determined by
3208 * holding the same value where DET is not 1 for @duration polled 3209 * holding the same value where DET is not 1 for @duration polled
3209 * every @interval, before @timeout. Timeout constraints the 3210 * every @interval, before @timeout. Timeout constraints the
3210 * beginning of the stable state. Because DET gets stuck at 1 on 3211 * beginning of the stable state. Because DET gets stuck at 1 on
@@ -3220,8 +3221,8 @@ err_out:
3220 * RETURNS: 3221 * RETURNS:
3221 * 0 on success, -errno on failure. 3222 * 0 on success, -errno on failure.
3222 */ 3223 */
3223int sata_phy_debounce(struct ata_port *ap, const unsigned long *params, 3224int sata_link_debounce(struct ata_link *link, const unsigned long *params,
3224 unsigned long deadline) 3225 unsigned long deadline)
3225{ 3226{
3226 unsigned long interval_msec = params[0]; 3227 unsigned long interval_msec = params[0];
3227 unsigned long duration = msecs_to_jiffies(params[1]); 3228 unsigned long duration = msecs_to_jiffies(params[1]);
@@ -3233,7 +3234,7 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3233 if (time_before(t, deadline)) 3234 if (time_before(t, deadline))
3234 deadline = t; 3235 deadline = t;
3235 3236
3236 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur))) 3237 if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
3237 return rc; 3238 return rc;
3238 cur &= 0xf; 3239 cur &= 0xf;
3239 3240
@@ -3242,7 +3243,7 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3242 3243
3243 while (1) { 3244 while (1) {
3244 msleep(interval_msec); 3245 msleep(interval_msec);
3245 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur))) 3246 if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
3246 return rc; 3247 return rc;
3247 cur &= 0xf; 3248 cur &= 0xf;
3248 3249
@@ -3268,12 +3269,12 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3268} 3269}
3269 3270
3270/** 3271/**
3271 * sata_phy_resume - resume SATA phy 3272 * sata_link_resume - resume SATA link
3272 * @ap: ATA port to resume SATA phy for 3273 * @link: ATA link to resume SATA
3273 * @params: timing parameters { interval, duratinon, timeout } in msec 3274 * @params: timing parameters { interval, duratinon, timeout } in msec
3274 * @deadline: deadline jiffies for the operation 3275 * @deadline: deadline jiffies for the operation
3275 * 3276 *
3276 * Resume SATA phy of @ap and debounce it. 3277 * Resume SATA phy @link and debounce it.
3277 * 3278 *
3278 * LOCKING: 3279 * LOCKING:
3279 * Kernel thread context (may sleep) 3280 * Kernel thread context (may sleep)
@@ -3281,18 +3282,18 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3281 * RETURNS: 3282 * RETURNS:
3282 * 0 on success, -errno on failure. 3283 * 0 on success, -errno on failure.
3283 */ 3284 */
3284int sata_phy_resume(struct ata_port *ap, const unsigned long *params, 3285int sata_link_resume(struct ata_link *link, const unsigned long *params,
3285 unsigned long deadline) 3286 unsigned long deadline)
3286{ 3287{
3287 u32 scontrol; 3288 u32 scontrol;
3288 int rc; 3289 int rc;
3289 3290
3290 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 3291 if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
3291 return rc; 3292 return rc;
3292 3293
3293 scontrol = (scontrol & 0x0f0) | 0x300; 3294 scontrol = (scontrol & 0x0f0) | 0x300;
3294 3295
3295 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 3296 if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
3296 return rc; 3297 return rc;
3297 3298
3298 /* Some PHYs react badly if SStatus is pounded immediately 3299 /* Some PHYs react badly if SStatus is pounded immediately
@@ -3300,7 +3301,7 @@ int sata_phy_resume(struct ata_port *ap, const unsigned long *params,
3300 */ 3301 */
3301 msleep(200); 3302 msleep(200);
3302 3303
3303 return sata_phy_debounce(ap, params, deadline); 3304 return sata_link_debounce(link, params, deadline);
3304} 3305}
3305 3306
3306/** 3307/**
@@ -3322,7 +3323,8 @@ int sata_phy_resume(struct ata_port *ap, const unsigned long *params,
3322 */ 3323 */
3323int ata_std_prereset(struct ata_port *ap, unsigned long deadline) 3324int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
3324{ 3325{
3325 struct ata_eh_context *ehc = &ap->link.eh_context; 3326 struct ata_link *link = &ap->link;
3327 struct ata_eh_context *ehc = &link->eh_context;
3326 const unsigned long *timing = sata_ehc_deb_timing(ehc); 3328 const unsigned long *timing = sata_ehc_deb_timing(ehc);
3327 int rc; 3329 int rc;
3328 3330
@@ -3335,9 +3337,9 @@ int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
3335 if (ehc->i.action & ATA_EH_HARDRESET) 3337 if (ehc->i.action & ATA_EH_HARDRESET)
3336 return 0; 3338 return 0;
3337 3339
3338 /* if SATA, resume phy */ 3340 /* if SATA, resume link */
3339 if (ap->flags & ATA_FLAG_SATA) { 3341 if (ap->flags & ATA_FLAG_SATA) {
3340 rc = sata_phy_resume(ap, timing, deadline); 3342 rc = sata_link_resume(link, timing, deadline);
3341 /* whine about phy resume failure but proceed */ 3343 /* whine about phy resume failure but proceed */
3342 if (rc && rc != -EOPNOTSUPP) 3344 if (rc && rc != -EOPNOTSUPP)
3343 ata_port_printk(ap, KERN_WARNING, "failed to resume " 3345 ata_port_printk(ap, KERN_WARNING, "failed to resume "
@@ -3347,7 +3349,7 @@ int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
3347 /* Wait for !BSY if the controller can wait for the first D2H 3349 /* Wait for !BSY if the controller can wait for the first D2H
3348 * Reg FIS and we don't know that no device is attached. 3350 * Reg FIS and we don't know that no device is attached.
3349 */ 3351 */
3350 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap)) { 3352 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_link_offline(link)) {
3351 rc = ata_wait_ready(ap, deadline); 3353 rc = ata_wait_ready(ap, deadline);
3352 if (rc && rc != -ENODEV) { 3354 if (rc && rc != -ENODEV) {
3353 ata_port_printk(ap, KERN_WARNING, "device not ready " 3355 ata_port_printk(ap, KERN_WARNING, "device not ready "
@@ -3376,6 +3378,7 @@ int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
3376int ata_std_softreset(struct ata_port *ap, unsigned int *classes, 3378int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
3377 unsigned long deadline) 3379 unsigned long deadline)
3378{ 3380{
3381 struct ata_link *link = &ap->link;
3379 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 3382 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
3380 unsigned int devmask = 0; 3383 unsigned int devmask = 0;
3381 int rc; 3384 int rc;
@@ -3383,7 +3386,7 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
3383 3386
3384 DPRINTK("ENTER\n"); 3387 DPRINTK("ENTER\n");
3385 3388
3386 if (ata_port_offline(ap)) { 3389 if (ata_link_offline(link)) {
3387 classes[0] = ATA_DEV_NONE; 3390 classes[0] = ATA_DEV_NONE;
3388 goto out; 3391 goto out;
3389 } 3392 }
@@ -3401,7 +3404,7 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
3401 DPRINTK("about to softreset, devmask=%x\n", devmask); 3404 DPRINTK("about to softreset, devmask=%x\n", devmask);
3402 rc = ata_bus_softreset(ap, devmask, deadline); 3405 rc = ata_bus_softreset(ap, devmask, deadline);
3403 /* if link is occupied, -ENODEV too is an error */ 3406 /* if link is occupied, -ENODEV too is an error */
3404 if (rc && (rc != -ENODEV || sata_scr_valid(ap))) { 3407 if (rc && (rc != -ENODEV || sata_scr_valid(link))) {
3405 ata_port_printk(ap, KERN_ERR, "SRST failed (errno=%d)\n", rc); 3408 ata_port_printk(ap, KERN_ERR, "SRST failed (errno=%d)\n", rc);
3406 return rc; 3409 return rc;
3407 } 3410 }
@@ -3433,35 +3436,36 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
3433int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing, 3436int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing,
3434 unsigned long deadline) 3437 unsigned long deadline)
3435{ 3438{
3439 struct ata_link *link = &ap->link;
3436 u32 scontrol; 3440 u32 scontrol;
3437 int rc; 3441 int rc;
3438 3442
3439 DPRINTK("ENTER\n"); 3443 DPRINTK("ENTER\n");
3440 3444
3441 if (sata_set_spd_needed(ap)) { 3445 if (sata_set_spd_needed(link)) {
3442 /* SATA spec says nothing about how to reconfigure 3446 /* SATA spec says nothing about how to reconfigure
3443 * spd. To be on the safe side, turn off phy during 3447 * spd. To be on the safe side, turn off phy during
3444 * reconfiguration. This works for at least ICH7 AHCI 3448 * reconfiguration. This works for at least ICH7 AHCI
3445 * and Sil3124. 3449 * and Sil3124.
3446 */ 3450 */
3447 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 3451 if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
3448 goto out; 3452 goto out;
3449 3453
3450 scontrol = (scontrol & 0x0f0) | 0x304; 3454 scontrol = (scontrol & 0x0f0) | 0x304;
3451 3455
3452 if ((rc = sata_scr_write(ap, SCR_CONTROL, scontrol))) 3456 if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
3453 goto out; 3457 goto out;
3454 3458
3455 sata_set_spd(ap); 3459 sata_set_spd(link);
3456 } 3460 }
3457 3461
3458 /* issue phy wake/reset */ 3462 /* issue phy wake/reset */
3459 if ((rc = sata_scr_read(ap, SCR_CONTROL, &scontrol))) 3463 if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
3460 goto out; 3464 goto out;
3461 3465
3462 scontrol = (scontrol & 0x0f0) | 0x301; 3466 scontrol = (scontrol & 0x0f0) | 0x301;
3463 3467
3464 if ((rc = sata_scr_write_flush(ap, SCR_CONTROL, scontrol))) 3468 if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol)))
3465 goto out; 3469 goto out;
3466 3470
3467 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 3471 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
@@ -3469,8 +3473,8 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing,
3469 */ 3473 */
3470 msleep(1); 3474 msleep(1);
3471 3475
3472 /* bring phy back */ 3476 /* bring link back */
3473 rc = sata_phy_resume(ap, timing, deadline); 3477 rc = sata_link_resume(link, timing, deadline);
3474 out: 3478 out:
3475 DPRINTK("EXIT, rc=%d\n", rc); 3479 DPRINTK("EXIT, rc=%d\n", rc);
3476 return rc; 3480 return rc;
@@ -3494,7 +3498,8 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing,
3494int sata_std_hardreset(struct ata_port *ap, unsigned int *class, 3498int sata_std_hardreset(struct ata_port *ap, unsigned int *class,
3495 unsigned long deadline) 3499 unsigned long deadline)
3496{ 3500{
3497 const unsigned long *timing = sata_ehc_deb_timing(&ap->link.eh_context); 3501 struct ata_link *link = &ap->link;
3502 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
3498 int rc; 3503 int rc;
3499 3504
3500 DPRINTK("ENTER\n"); 3505 DPRINTK("ENTER\n");
@@ -3508,7 +3513,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class,
3508 } 3513 }
3509 3514
3510 /* TODO: phy layer with polling, timeouts, etc. */ 3515 /* TODO: phy layer with polling, timeouts, etc. */
3511 if (ata_port_offline(ap)) { 3516 if (ata_link_offline(link)) {
3512 *class = ATA_DEV_NONE; 3517 *class = ATA_DEV_NONE;
3513 DPRINTK("EXIT, link offline\n"); 3518 DPRINTK("EXIT, link offline\n");
3514 return 0; 3519 return 0;
@@ -3547,16 +3552,17 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class,
3547 */ 3552 */
3548void ata_std_postreset(struct ata_port *ap, unsigned int *classes) 3553void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
3549{ 3554{
3555 struct ata_link *link = &ap->link;
3550 u32 serror; 3556 u32 serror;
3551 3557
3552 DPRINTK("ENTER\n"); 3558 DPRINTK("ENTER\n");
3553 3559
3554 /* print link status */ 3560 /* print link status */
3555 sata_print_link_status(ap); 3561 sata_print_link_status(link);
3556 3562
3557 /* clear SError */ 3563 /* clear SError */
3558 if (sata_scr_read(ap, SCR_ERROR, &serror) == 0) 3564 if (sata_scr_read(link, SCR_ERROR, &serror) == 0)
3559 sata_scr_write(ap, SCR_ERROR, serror); 3565 sata_scr_write(link, SCR_ERROR, serror);
3560 3566
3561 /* is double-select really necessary? */ 3567 /* is double-select really necessary? */
3562 if (classes[0] != ATA_DEV_NONE) 3568 if (classes[0] != ATA_DEV_NONE)
@@ -5729,9 +5735,9 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance)
5729 5735
5730/** 5736/**
5731 * sata_scr_valid - test whether SCRs are accessible 5737 * sata_scr_valid - test whether SCRs are accessible
5732 * @ap: ATA port to test SCR accessibility for 5738 * @link: ATA link to test SCR accessibility for
5733 * 5739 *
5734 * Test whether SCRs are accessible for @ap. 5740 * Test whether SCRs are accessible for @link.
5735 * 5741 *
5736 * LOCKING: 5742 * LOCKING:
5737 * None. 5743 * None.
@@ -5739,18 +5745,20 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance)
5739 * RETURNS: 5745 * RETURNS:
5740 * 1 if SCRs are accessible, 0 otherwise. 5746 * 1 if SCRs are accessible, 0 otherwise.
5741 */ 5747 */
5742int sata_scr_valid(struct ata_port *ap) 5748int sata_scr_valid(struct ata_link *link)
5743{ 5749{
5750 struct ata_port *ap = link->ap;
5751
5744 return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read; 5752 return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read;
5745} 5753}
5746 5754
5747/** 5755/**
5748 * sata_scr_read - read SCR register of the specified port 5756 * sata_scr_read - read SCR register of the specified port
5749 * @ap: ATA port to read SCR for 5757 * @link: ATA link to read SCR for
5750 * @reg: SCR to read 5758 * @reg: SCR to read
5751 * @val: Place to store read value 5759 * @val: Place to store read value
5752 * 5760 *
5753 * Read SCR register @reg of @ap into *@val. This function is 5761 * Read SCR register @reg of @link into *@val. This function is
5754 * guaranteed to succeed if the cable type of the port is SATA 5762 * guaranteed to succeed if the cable type of the port is SATA
5755 * and the port implements ->scr_read. 5763 * and the port implements ->scr_read.
5756 * 5764 *
@@ -5760,20 +5768,22 @@ int sata_scr_valid(struct ata_port *ap)
5760 * RETURNS: 5768 * RETURNS:
5761 * 0 on success, negative errno on failure. 5769 * 0 on success, negative errno on failure.
5762 */ 5770 */
5763int sata_scr_read(struct ata_port *ap, int reg, u32 *val) 5771int sata_scr_read(struct ata_link *link, int reg, u32 *val)
5764{ 5772{
5765 if (sata_scr_valid(ap)) 5773 struct ata_port *ap = link->ap;
5774
5775 if (sata_scr_valid(link))
5766 return ap->ops->scr_read(ap, reg, val); 5776 return ap->ops->scr_read(ap, reg, val);
5767 return -EOPNOTSUPP; 5777 return -EOPNOTSUPP;
5768} 5778}
5769 5779
5770/** 5780/**
5771 * sata_scr_write - write SCR register of the specified port 5781 * sata_scr_write - write SCR register of the specified port
5772 * @ap: ATA port to write SCR for 5782 * @link: ATA link to write SCR for
5773 * @reg: SCR to write 5783 * @reg: SCR to write
5774 * @val: value to write 5784 * @val: value to write
5775 * 5785 *
5776 * Write @val to SCR register @reg of @ap. This function is 5786 * Write @val to SCR register @reg of @link. This function is
5777 * guaranteed to succeed if the cable type of the port is SATA 5787 * guaranteed to succeed if the cable type of the port is SATA
5778 * and the port implements ->scr_read. 5788 * and the port implements ->scr_read.
5779 * 5789 *
@@ -5783,16 +5793,18 @@ int sata_scr_read(struct ata_port *ap, int reg, u32 *val)
5783 * RETURNS: 5793 * RETURNS:
5784 * 0 on success, negative errno on failure. 5794 * 0 on success, negative errno on failure.
5785 */ 5795 */
5786int sata_scr_write(struct ata_port *ap, int reg, u32 val) 5796int sata_scr_write(struct ata_link *link, int reg, u32 val)
5787{ 5797{
5788 if (sata_scr_valid(ap)) 5798 struct ata_port *ap = link->ap;
5799
5800 if (sata_scr_valid(link))
5789 return ap->ops->scr_write(ap, reg, val); 5801 return ap->ops->scr_write(ap, reg, val);
5790 return -EOPNOTSUPP; 5802 return -EOPNOTSUPP;
5791} 5803}
5792 5804
5793/** 5805/**
5794 * sata_scr_write_flush - write SCR register of the specified port and flush 5806 * sata_scr_write_flush - write SCR register of the specified port and flush
5795 * @ap: ATA port to write SCR for 5807 * @link: ATA link to write SCR for
5796 * @reg: SCR to write 5808 * @reg: SCR to write
5797 * @val: value to write 5809 * @val: value to write
5798 * 5810 *
@@ -5805,11 +5817,12 @@ int sata_scr_write(struct ata_port *ap, int reg, u32 val)
5805 * RETURNS: 5817 * RETURNS:
5806 * 0 on success, negative errno on failure. 5818 * 0 on success, negative errno on failure.
5807 */ 5819 */
5808int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val) 5820int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
5809{ 5821{
5822 struct ata_port *ap = link->ap;
5810 int rc; 5823 int rc;
5811 5824
5812 if (sata_scr_valid(ap)) { 5825 if (sata_scr_valid(link)) {
5813 rc = ap->ops->scr_write(ap, reg, val); 5826 rc = ap->ops->scr_write(ap, reg, val);
5814 if (rc == 0) 5827 if (rc == 0)
5815 rc = ap->ops->scr_read(ap, reg, &val); 5828 rc = ap->ops->scr_read(ap, reg, &val);
@@ -5819,12 +5832,12 @@ int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val)
5819} 5832}
5820 5833
5821/** 5834/**
5822 * ata_port_online - test whether the given port is online 5835 * ata_link_online - test whether the given link is online
5823 * @ap: ATA port to test 5836 * @link: ATA link to test
5824 * 5837 *
5825 * Test whether @ap is online. Note that this function returns 0 5838 * Test whether @link is online. Note that this function returns
5826 * if online status of @ap cannot be obtained, so 5839 * 0 if online status of @link cannot be obtained, so
5827 * ata_port_online(ap) != !ata_port_offline(ap). 5840 * ata_link_online(link) != !ata_link_offline(link).
5828 * 5841 *
5829 * LOCKING: 5842 * LOCKING:
5830 * None. 5843 * None.
@@ -5832,22 +5845,23 @@ int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val)
5832 * RETURNS: 5845 * RETURNS:
5833 * 1 if the port online status is available and online. 5846 * 1 if the port online status is available and online.
5834 */ 5847 */
5835int ata_port_online(struct ata_port *ap) 5848int ata_link_online(struct ata_link *link)
5836{ 5849{
5837 u32 sstatus; 5850 u32 sstatus;
5838 5851
5839 if (!sata_scr_read(ap, SCR_STATUS, &sstatus) && (sstatus & 0xf) == 0x3) 5852 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
5853 (sstatus & 0xf) == 0x3)
5840 return 1; 5854 return 1;
5841 return 0; 5855 return 0;
5842} 5856}
5843 5857
5844/** 5858/**
5845 * ata_port_offline - test whether the given port is offline 5859 * ata_link_offline - test whether the given link is offline
5846 * @ap: ATA port to test 5860 * @link: ATA link to test
5847 * 5861 *
5848 * Test whether @ap is offline. Note that this function returns 5862 * Test whether @link is offline. Note that this function
5849 * 0 if offline status of @ap cannot be obtained, so 5863 * returns 0 if offline status of @link cannot be obtained, so
5850 * ata_port_online(ap) != !ata_port_offline(ap). 5864 * ata_link_online(link) != !ata_link_offline(link).
5851 * 5865 *
5852 * LOCKING: 5866 * LOCKING:
5853 * None. 5867 * None.
@@ -5855,11 +5869,12 @@ int ata_port_online(struct ata_port *ap)
5855 * RETURNS: 5869 * RETURNS:
5856 * 1 if the port offline status is available and offline. 5870 * 1 if the port offline status is available and offline.
5857 */ 5871 */
5858int ata_port_offline(struct ata_port *ap) 5872int ata_link_offline(struct ata_link *link)
5859{ 5873{
5860 u32 sstatus; 5874 u32 sstatus;
5861 5875
5862 if (!sata_scr_read(ap, SCR_STATUS, &sstatus) && (sstatus & 0xf) != 0x3) 5876 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 &&
5877 (sstatus & 0xf) != 0x3)
5863 return 1; 5878 return 1;
5864 return 0; 5879 return 0;
5865} 5880}
@@ -6397,7 +6412,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6397 ap->cbl = ATA_CBL_SATA; 6412 ap->cbl = ATA_CBL_SATA;
6398 6413
6399 /* init sata_spd_limit to the current value */ 6414 /* init sata_spd_limit to the current value */
6400 if (sata_scr_read(ap, SCR_CONTROL, &scontrol) == 0) { 6415 if (sata_scr_read(&ap->link, SCR_CONTROL, &scontrol) == 0) {
6401 int spd = (scontrol >> 4) & 0xf; 6416 int spd = (scontrol >> 4) & 0xf;
6402 if (spd) 6417 if (spd)
6403 ap->link.hw_sata_spd_limit &= (1 << spd) - 1; 6418 ap->link.hw_sata_spd_limit &= (1 << spd) - 1;
@@ -6924,8 +6939,8 @@ EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd);
6924EXPORT_SYMBOL_GPL(ata_port_probe); 6939EXPORT_SYMBOL_GPL(ata_port_probe);
6925EXPORT_SYMBOL_GPL(ata_dev_disable); 6940EXPORT_SYMBOL_GPL(ata_dev_disable);
6926EXPORT_SYMBOL_GPL(sata_set_spd); 6941EXPORT_SYMBOL_GPL(sata_set_spd);
6927EXPORT_SYMBOL_GPL(sata_phy_debounce); 6942EXPORT_SYMBOL_GPL(sata_link_debounce);
6928EXPORT_SYMBOL_GPL(sata_phy_resume); 6943EXPORT_SYMBOL_GPL(sata_link_resume);
6929EXPORT_SYMBOL_GPL(sata_phy_reset); 6944EXPORT_SYMBOL_GPL(sata_phy_reset);
6930EXPORT_SYMBOL_GPL(__sata_phy_reset); 6945EXPORT_SYMBOL_GPL(__sata_phy_reset);
6931EXPORT_SYMBOL_GPL(ata_bus_reset); 6946EXPORT_SYMBOL_GPL(ata_bus_reset);
@@ -6952,8 +6967,8 @@ EXPORT_SYMBOL_GPL(sata_scr_valid);
6952EXPORT_SYMBOL_GPL(sata_scr_read); 6967EXPORT_SYMBOL_GPL(sata_scr_read);
6953EXPORT_SYMBOL_GPL(sata_scr_write); 6968EXPORT_SYMBOL_GPL(sata_scr_write);
6954EXPORT_SYMBOL_GPL(sata_scr_write_flush); 6969EXPORT_SYMBOL_GPL(sata_scr_write_flush);
6955EXPORT_SYMBOL_GPL(ata_port_online); 6970EXPORT_SYMBOL_GPL(ata_link_online);
6956EXPORT_SYMBOL_GPL(ata_port_offline); 6971EXPORT_SYMBOL_GPL(ata_link_offline);
6957#ifdef CONFIG_PM 6972#ifdef CONFIG_PM
6958EXPORT_SYMBOL_GPL(ata_host_suspend); 6973EXPORT_SYMBOL_GPL(ata_host_suspend);
6959EXPORT_SYMBOL_GPL(ata_host_resume); 6974EXPORT_SYMBOL_GPL(ata_host_resume);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 8c37ec0bbf6c..48ca68b3979b 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1501,7 +1501,7 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
1501 /* speed down? */ 1501 /* speed down? */
1502 if (verdict & ATA_EH_SPDN_SPEED_DOWN) { 1502 if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
1503 /* speed down SATA link speed if possible */ 1503 /* speed down SATA link speed if possible */
1504 if (sata_down_spd_limit(dev->link->ap) == 0) { 1504 if (sata_down_spd_limit(dev->link) == 0) {
1505 action |= ATA_EH_HARDRESET; 1505 action |= ATA_EH_HARDRESET;
1506 goto done; 1506 goto done;
1507 } 1507 }
@@ -1561,7 +1561,8 @@ static unsigned int ata_eh_speed_down(struct ata_device *dev, int is_io,
1561 */ 1561 */
1562static void ata_eh_autopsy(struct ata_port *ap) 1562static void ata_eh_autopsy(struct ata_port *ap)
1563{ 1563{
1564 struct ata_eh_context *ehc = &ap->link.eh_context; 1564 struct ata_link *link = &ap->link;
1565 struct ata_eh_context *ehc = &link->eh_context;
1565 unsigned int all_err_mask = 0; 1566 unsigned int all_err_mask = 0;
1566 int tag, is_io = 0; 1567 int tag, is_io = 0;
1567 u32 serror; 1568 u32 serror;
@@ -1573,7 +1574,7 @@ static void ata_eh_autopsy(struct ata_port *ap)
1573 return; 1574 return;
1574 1575
1575 /* obtain and analyze SError */ 1576 /* obtain and analyze SError */
1576 rc = sata_scr_read(ap, SCR_ERROR, &serror); 1577 rc = sata_scr_read(link, SCR_ERROR, &serror);
1577 if (rc == 0) { 1578 if (rc == 0) {
1578 ehc->i.serror |= serror; 1579 ehc->i.serror |= serror;
1579 ata_eh_analyze_serror(ap); 1580 ata_eh_analyze_serror(ap);
@@ -1782,7 +1783,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1782 ata_prereset_fn_t prereset, ata_reset_fn_t softreset, 1783 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
1783 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset) 1784 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
1784{ 1785{
1785 struct ata_eh_context *ehc = &ap->link.eh_context; 1786 struct ata_link *link = &ap->link;
1787 struct ata_eh_context *ehc = &link->eh_context;
1786 unsigned int *classes = ehc->classes; 1788 unsigned int *classes = ehc->classes;
1787 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); 1789 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
1788 int try = 0; 1790 int try = 0;
@@ -1800,7 +1802,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1800 */ 1802 */
1801 action = ehc->i.action; 1803 action = ehc->i.action;
1802 ehc->i.action &= ~ATA_EH_RESET_MASK; 1804 ehc->i.action &= ~ATA_EH_RESET_MASK;
1803 if (softreset && (!hardreset || (!sata_set_spd_needed(ap) && 1805 if (softreset && (!hardreset || (!sata_set_spd_needed(link) &&
1804 !(action & ATA_EH_HARDRESET)))) 1806 !(action & ATA_EH_HARDRESET))))
1805 ehc->i.action |= ATA_EH_SOFTRESET; 1807 ehc->i.action |= ATA_EH_SOFTRESET;
1806 else 1808 else
@@ -1814,7 +1816,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1814 "port disabled. ignoring.\n"); 1816 "port disabled. ignoring.\n");
1815 ehc->i.action &= ~ATA_EH_RESET_MASK; 1817 ehc->i.action &= ~ATA_EH_RESET_MASK;
1816 1818
1817 ata_link_for_each_dev(dev, &ap->link) 1819 ata_link_for_each_dev(dev, link)
1818 classes[dev->devno] = ATA_DEV_NONE; 1820 classes[dev->devno] = ATA_DEV_NONE;
1819 1821
1820 rc = 0; 1822 rc = 0;
@@ -1832,7 +1834,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1832 reset = softreset; 1834 reset = softreset;
1833 else { 1835 else {
1834 /* prereset told us not to reset, bang classes and return */ 1836 /* prereset told us not to reset, bang classes and return */
1835 ata_link_for_each_dev(dev, &ap->link) 1837 ata_link_for_each_dev(dev, link)
1836 classes[dev->devno] = ATA_DEV_NONE; 1838 classes[dev->devno] = ATA_DEV_NONE;
1837 rc = 0; 1839 rc = 0;
1838 goto out; 1840 goto out;
@@ -1902,7 +1904,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1902 1904
1903 if (rc == -EPIPE || 1905 if (rc == -EPIPE ||
1904 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1) 1906 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1)
1905 sata_down_spd_limit(ap); 1907 sata_down_spd_limit(link);
1906 if (hardreset) 1908 if (hardreset)
1907 reset = hardreset; 1909 reset = hardreset;
1908 goto retry; 1910 goto retry;
@@ -1914,12 +1916,12 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1914 /* After the reset, the device state is PIO 0 and the 1916 /* After the reset, the device state is PIO 0 and the
1915 * controller state is undefined. Record the mode. 1917 * controller state is undefined. Record the mode.
1916 */ 1918 */
1917 ata_link_for_each_dev(dev, &ap->link) 1919 ata_link_for_each_dev(dev, link)
1918 dev->pio_mode = XFER_PIO_0; 1920 dev->pio_mode = XFER_PIO_0;
1919 1921
1920 /* record current link speed */ 1922 /* record current link speed */
1921 if (sata_scr_read(ap, SCR_STATUS, &sstatus) == 0) 1923 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
1922 ap->link.sata_spd = (sstatus >> 4) & 0xf; 1924 link->sata_spd = (sstatus >> 4) & 0xf;
1923 1925
1924 if (postreset) 1926 if (postreset)
1925 postreset(ap, classes); 1927 postreset(ap, classes);
@@ -1957,7 +1959,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1957 readid_flags |= ATA_READID_POSTRESET; 1959 readid_flags |= ATA_READID_POSTRESET;
1958 1960
1959 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) { 1961 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
1960 if (ata_port_offline(ap)) { 1962 if (ata_link_offline(&ap->link)) {
1961 rc = -EIO; 1963 rc = -EIO;
1962 goto err; 1964 goto err;
1963 } 1965 }
@@ -2079,7 +2081,6 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
2079 2081
2080static void ata_eh_handle_dev_fail(struct ata_device *dev, int err) 2082static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2081{ 2083{
2082 struct ata_port *ap = dev->link->ap;
2083 struct ata_eh_context *ehc = &dev->link->eh_context; 2084 struct ata_eh_context *ehc = &dev->link->eh_context;
2084 2085
2085 ehc->tries[dev->devno]--; 2086 ehc->tries[dev->devno]--;
@@ -2096,7 +2097,7 @@ static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2096 /* This is the last chance, better to slow 2097 /* This is the last chance, better to slow
2097 * down than lose it. 2098 * down than lose it.
2098 */ 2099 */
2099 sata_down_spd_limit(ap); 2100 sata_down_spd_limit(dev->link);
2100 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); 2101 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
2101 } 2102 }
2102 } 2103 }
@@ -2106,7 +2107,7 @@ static void ata_eh_handle_dev_fail(struct ata_device *dev, int err)
2106 ata_dev_disable(dev); 2107 ata_dev_disable(dev);
2107 2108
2108 /* detach if offline */ 2109 /* detach if offline */
2109 if (ata_port_offline(ap)) 2110 if (ata_link_offline(dev->link))
2110 ata_eh_detach_dev(dev); 2111 ata_eh_detach_dev(dev);
2111 2112
2112 /* probe if requested */ 2113 /* probe if requested */
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 2100cd61ed69..dd528dbd9ccf 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -500,7 +500,7 @@ void ata_bmdma_error_handler(struct ata_port *ap)
500 ata_reset_fn_t hardreset; 500 ata_reset_fn_t hardreset;
501 501
502 hardreset = NULL; 502 hardreset = NULL;
503 if (sata_scr_valid(ap)) 503 if (sata_scr_valid(&ap->link))
504 hardreset = sata_std_hardreset; 504 hardreset = sata_std_hardreset;
505 505
506 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, hardreset, 506 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, hardreset,
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 564cd234c805..700843a9f30a 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -78,8 +78,8 @@ extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
78extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags); 78extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags);
79extern int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags); 79extern int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags);
80extern int ata_dev_configure(struct ata_device *dev); 80extern int ata_dev_configure(struct ata_device *dev);
81extern int sata_down_spd_limit(struct ata_port *ap); 81extern int sata_down_spd_limit(struct ata_link *link);
82extern int sata_set_spd_needed(struct ata_port *ap); 82extern int sata_set_spd_needed(struct ata_link *link);
83extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); 83extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
84extern int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev); 84extern int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev);
85extern void ata_sg_clean(struct ata_queued_cmd *qc); 85extern void ata_sg_clean(struct ata_queued_cmd *qc);
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index aab068fbb7bc..63fe99a10cd1 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -612,7 +612,7 @@ static int scc_std_softreset (struct ata_port *ap, unsigned int *classes,
612 612
613 DPRINTK("ENTER\n"); 613 DPRINTK("ENTER\n");
614 614
615 if (ata_port_offline(ap)) { 615 if (ata_link_offline(&ap->link)) {
616 classes[0] = ATA_DEV_NONE; 616 classes[0] = ATA_DEV_NONE;
617 goto out; 617 goto out;
618 } 618 }
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index 3c0ef7a2f2fe..f2b1bea934bc 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -435,7 +435,7 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class,
435 msleep(1); 435 msleep(1);
436 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl); 436 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl);
437 437
438 rc = sata_phy_resume(ap, timing, deadline); 438 rc = sata_link_resume(&ap->link, timing, deadline);
439 if (rc) { 439 if (rc) {
440 ata_port_printk(ap, KERN_WARNING, "failed to resume " 440 ata_port_printk(ap, KERN_WARNING, "failed to resume "
441 "link after reset (errno=%d)\n", rc); 441 "link after reset (errno=%d)\n", rc);
@@ -443,7 +443,7 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class,
443 } 443 }
444 444
445 *class = ATA_DEV_NONE; 445 *class = ATA_DEV_NONE;
446 if (ata_port_online(ap)) { 446 if (ata_link_online(&ap->link)) {
447 struct ata_taskfile tf; 447 struct ata_taskfile tf;
448 448
449 /* wait a while before checking status */ 449 /* wait a while before checking status */
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 246e7c5fdce8..8e63c60adaff 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1423,8 +1423,8 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1423 /* just a guess: do we need to do this? should we 1423 /* just a guess: do we need to do this? should we
1424 * expand this, and do it in all cases? 1424 * expand this, and do it in all cases?
1425 */ 1425 */
1426 sata_scr_read(ap, SCR_ERROR, &serr); 1426 sata_scr_read(&ap->link, SCR_ERROR, &serr);
1427 sata_scr_write_flush(ap, SCR_ERROR, serr); 1427 sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
1428 } 1428 }
1429 1429
1430 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1430 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
@@ -1468,8 +1468,8 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1468 } 1468 }
1469 1469
1470 if (edma_err_cause & EDMA_ERR_SERR) { 1470 if (edma_err_cause & EDMA_ERR_SERR) {
1471 sata_scr_read(ap, SCR_ERROR, &serr); 1471 sata_scr_read(&ap->link, SCR_ERROR, &serr);
1472 sata_scr_write_flush(ap, SCR_ERROR, serr); 1472 sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
1473 err_mask = AC_ERR_ATA_BUS; 1473 err_mask = AC_ERR_ATA_BUS;
1474 action |= ATA_EH_HARDRESET; 1474 action |= ATA_EH_HARDRESET;
1475 } 1475 }
@@ -1687,7 +1687,7 @@ static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
1687 1687
1688 for (i = 0; i < host->n_ports; i++) { 1688 for (i = 0; i < host->n_ports; i++) {
1689 ap = host->ports[i]; 1689 ap = host->ports[i];
1690 if (!ata_port_offline(ap)) { 1690 if (!ata_link_offline(&ap->link)) {
1691 ehi = &ap->link.eh_info; 1691 ehi = &ap->link.eh_info;
1692 ata_ehi_clear_desc(ehi); 1692 ata_ehi_clear_desc(ehi);
1693 if (!printed++) 1693 if (!printed++)
@@ -2198,14 +2198,14 @@ static void mv_phy_reset(struct ata_port *ap, unsigned int *class,
2198 2198
2199 /* Issue COMRESET via SControl */ 2199 /* Issue COMRESET via SControl */
2200comreset_retry: 2200comreset_retry:
2201 sata_scr_write_flush(ap, SCR_CONTROL, 0x301); 2201 sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x301);
2202 msleep(1); 2202 msleep(1);
2203 2203
2204 sata_scr_write_flush(ap, SCR_CONTROL, 0x300); 2204 sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x300);
2205 msleep(20); 2205 msleep(20);
2206 2206
2207 do { 2207 do {
2208 sata_scr_read(ap, SCR_STATUS, &sstatus); 2208 sata_scr_read(&ap->link, SCR_STATUS, &sstatus);
2209 if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) 2209 if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0))
2210 break; 2210 break;
2211 2211
@@ -2230,7 +2230,7 @@ comreset_retry:
2230 } 2230 }
2231#endif 2231#endif
2232 2232
2233 if (ata_port_offline(ap)) { 2233 if (ata_link_offline(&ap->link)) {
2234 *class = ATA_DEV_NONE; 2234 *class = ATA_DEV_NONE;
2235 return; 2235 return;
2236 } 2236 }
@@ -2285,7 +2285,7 @@ static int mv_prereset(struct ata_port *ap, unsigned long deadline)
2285 if (ehc->i.action & ATA_EH_HARDRESET) 2285 if (ehc->i.action & ATA_EH_HARDRESET)
2286 return 0; 2286 return 0;
2287 2287
2288 if (ata_port_online(ap)) 2288 if (ata_link_online(&ap->link))
2289 rc = ata_wait_ready(ap, deadline); 2289 rc = ata_wait_ready(ap, deadline);
2290 else 2290 else
2291 rc = -ENODEV; 2291 rc = -ENODEV;
@@ -2313,11 +2313,11 @@ static void mv_postreset(struct ata_port *ap, unsigned int *classes)
2313 u32 serr; 2313 u32 serr;
2314 2314
2315 /* print link status */ 2315 /* print link status */
2316 sata_print_link_status(ap); 2316 sata_print_link_status(&ap->link);
2317 2317
2318 /* clear SError */ 2318 /* clear SError */
2319 sata_scr_read(ap, SCR_ERROR, &serr); 2319 sata_scr_read(&ap->link, SCR_ERROR, &serr);
2320 sata_scr_write_flush(ap, SCR_ERROR, serr); 2320 sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
2321 2321
2322 /* bail out if no device is present */ 2322 /* bail out if no device is present */
2323 if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { 2323 if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index 620d0675d18a..c7238ce83541 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -475,7 +475,7 @@ static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
475 buf32[2] = 0; /* no next-packet */ 475 buf32[2] = 0; /* no next-packet */
476 476
477 /* select drive */ 477 /* select drive */
478 if (sata_scr_valid(ap)) { 478 if (sata_scr_valid(&ap->link)) {
479 dev_sel = PDC_DEVICE_SATA; 479 dev_sel = PDC_DEVICE_SATA;
480 } else { 480 } else {
481 dev_sel = ATA_DEVICE_OBS; 481 dev_sel = ATA_DEVICE_OBS;
@@ -643,7 +643,7 @@ static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
643 | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR)) 643 | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR))
644 ac_err_mask |= AC_ERR_HOST_BUS; 644 ac_err_mask |= AC_ERR_HOST_BUS;
645 645
646 if (sata_scr_valid(ap)) { 646 if (sata_scr_valid(&ap->link)) {
647 u32 serror; 647 u32 serror;
648 648
649 pdc_sata_scr_read(ap, SCR_ERROR, &serror); 649 pdc_sata_scr_read(ap, SCR_ERROR, &serror);
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 2d8334e7921d..0cd40d5215fe 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -593,7 +593,7 @@ static int sil24_do_softreset(struct ata_port *ap, unsigned int *class,
593 593
594 DPRINTK("ENTER\n"); 594 DPRINTK("ENTER\n");
595 595
596 if (ata_port_offline(ap)) { 596 if (ata_link_offline(&ap->link)) {
597 DPRINTK("PHY reports no device\n"); 597 DPRINTK("PHY reports no device\n");
598 *class = ATA_DEV_NONE; 598 *class = ATA_DEV_NONE;
599 goto out; 599 goto out;
@@ -650,10 +650,10 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class,
650 u32 tmp; 650 u32 tmp;
651 651
652 /* sil24 does the right thing(tm) without any protection */ 652 /* sil24 does the right thing(tm) without any protection */
653 sata_set_spd(ap); 653 sata_set_spd(&ap->link);
654 654
655 tout_msec = 100; 655 tout_msec = 100;
656 if (ata_port_online(ap)) 656 if (ata_link_online(&ap->link))
657 tout_msec = 5000; 657 tout_msec = 5000;
658 658
659 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT); 659 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
@@ -663,14 +663,14 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class,
663 /* SStatus oscillates between zero and valid status after 663 /* SStatus oscillates between zero and valid status after
664 * DEV_RST, debounce it. 664 * DEV_RST, debounce it.
665 */ 665 */
666 rc = sata_phy_debounce(ap, sata_deb_timing_long, deadline); 666 rc = sata_link_debounce(&ap->link, sata_deb_timing_long, deadline);
667 if (rc) { 667 if (rc) {
668 reason = "PHY debouncing failed"; 668 reason = "PHY debouncing failed";
669 goto err; 669 goto err;
670 } 670 }
671 671
672 if (tmp & PORT_CS_DEV_RST) { 672 if (tmp & PORT_CS_DEV_RST) {
673 if (ata_port_offline(ap)) 673 if (ata_link_offline(&ap->link))
674 return 0; 674 return 0;
675 reason = "link not ready"; 675 reason = "link not ready";
676 goto err; 676 goto err;