diff options
author | Tejun Heo <htejun@gmail.com> | 2007-08-06 05:36:23 -0400 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2007-10-12 14:55:30 -0400 |
commit | 936fd7328657884d5a69a55666c74a55aa83ca27 (patch) | |
tree | 83a78a02d2c65ce835fe33882dfe5043d3240bff /drivers/ata/libata-core.c | |
parent | f58229f8060055b08b34008ea08f31de1e2f003c (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/ata/libata-core.c')
-rw-r--r-- | drivers/ata/libata-core.c | 227 |
1 files changed, 121 insertions, 106 deletions
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 | */ |
2240 | void sata_print_link_status(struct ata_port *ap) | 2240 | void 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 | */ |
2272 | void __sata_phy_reset(struct ata_port *ap) | 2272 | void __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 | */ |
2385 | int sata_down_spd_limit(struct ata_port *ap) | 2386 | int 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 | ||
2430 | static int __sata_set_spd_needed(struct ata_port *ap, u32 *scontrol) | 2431 | static 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 | */ |
2460 | int sata_set_spd_needed(struct ata_port *ap) | 2461 | int 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 | */ |
2483 | int sata_set_spd(struct ata_port *ap) | 2484 | int 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 | */ |
3223 | int sata_phy_debounce(struct ata_port *ap, const unsigned long *params, | 3224 | int 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 | */ |
3284 | int sata_phy_resume(struct ata_port *ap, const unsigned long *params, | 3285 | int 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 | */ |
3323 | int ata_std_prereset(struct ata_port *ap, unsigned long deadline) | 3324 | int 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) | |||
3376 | int ata_std_softreset(struct ata_port *ap, unsigned int *classes, | 3378 | int 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, | |||
3433 | int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing, | 3436 | int 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, | |||
3494 | int sata_std_hardreset(struct ata_port *ap, unsigned int *class, | 3498 | int 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 | */ |
3548 | void ata_std_postreset(struct ata_port *ap, unsigned int *classes) | 3553 | void 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 | */ |
5742 | int sata_scr_valid(struct ata_port *ap) | 5748 | int 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 | */ |
5763 | int sata_scr_read(struct ata_port *ap, int reg, u32 *val) | 5771 | int 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 | */ |
5786 | int sata_scr_write(struct ata_port *ap, int reg, u32 val) | 5796 | int 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 | */ |
5808 | int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val) | 5820 | int 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 | */ |
5835 | int ata_port_online(struct ata_port *ap) | 5848 | int 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 | */ |
5858 | int ata_port_offline(struct ata_port *ap) | 5872 | int 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); | |||
6924 | EXPORT_SYMBOL_GPL(ata_port_probe); | 6939 | EXPORT_SYMBOL_GPL(ata_port_probe); |
6925 | EXPORT_SYMBOL_GPL(ata_dev_disable); | 6940 | EXPORT_SYMBOL_GPL(ata_dev_disable); |
6926 | EXPORT_SYMBOL_GPL(sata_set_spd); | 6941 | EXPORT_SYMBOL_GPL(sata_set_spd); |
6927 | EXPORT_SYMBOL_GPL(sata_phy_debounce); | 6942 | EXPORT_SYMBOL_GPL(sata_link_debounce); |
6928 | EXPORT_SYMBOL_GPL(sata_phy_resume); | 6943 | EXPORT_SYMBOL_GPL(sata_link_resume); |
6929 | EXPORT_SYMBOL_GPL(sata_phy_reset); | 6944 | EXPORT_SYMBOL_GPL(sata_phy_reset); |
6930 | EXPORT_SYMBOL_GPL(__sata_phy_reset); | 6945 | EXPORT_SYMBOL_GPL(__sata_phy_reset); |
6931 | EXPORT_SYMBOL_GPL(ata_bus_reset); | 6946 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
@@ -6952,8 +6967,8 @@ EXPORT_SYMBOL_GPL(sata_scr_valid); | |||
6952 | EXPORT_SYMBOL_GPL(sata_scr_read); | 6967 | EXPORT_SYMBOL_GPL(sata_scr_read); |
6953 | EXPORT_SYMBOL_GPL(sata_scr_write); | 6968 | EXPORT_SYMBOL_GPL(sata_scr_write); |
6954 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); | 6969 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); |
6955 | EXPORT_SYMBOL_GPL(ata_port_online); | 6970 | EXPORT_SYMBOL_GPL(ata_link_online); |
6956 | EXPORT_SYMBOL_GPL(ata_port_offline); | 6971 | EXPORT_SYMBOL_GPL(ata_link_offline); |
6957 | #ifdef CONFIG_PM | 6972 | #ifdef CONFIG_PM |
6958 | EXPORT_SYMBOL_GPL(ata_host_suspend); | 6973 | EXPORT_SYMBOL_GPL(ata_host_suspend); |
6959 | EXPORT_SYMBOL_GPL(ata_host_resume); | 6974 | EXPORT_SYMBOL_GPL(ata_host_resume); |