Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Garzik | af36d7f | 2005-08-28 20:18:39 -0400 | [diff] [blame] | 2 | * libata-core.c - helper library for ATA |
| 3 | * |
| 4 | * Maintained by: Jeff Garzik <jgarzik@pobox.com> |
| 5 | * Please ALWAYS copy linux-ide@vger.kernel.org |
| 6 | * on emails. |
| 7 | * |
| 8 | * Copyright 2003-2004 Red Hat, Inc. All rights reserved. |
| 9 | * Copyright 2003-2004 Jeff Garzik |
| 10 | * |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; see the file COPYING. If not, write to |
| 24 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
| 26 | * |
| 27 | * libata documentation is available via 'make {ps|pdf}docs', |
| 28 | * as Documentation/DocBook/libata.* |
| 29 | * |
| 30 | * Hardware documentation available from http://www.t13.org/ and |
| 31 | * http://www.sata-io.org/ |
| 32 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/kernel.h> |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/pci.h> |
| 38 | #include <linux/init.h> |
| 39 | #include <linux/list.h> |
| 40 | #include <linux/mm.h> |
| 41 | #include <linux/highmem.h> |
| 42 | #include <linux/spinlock.h> |
| 43 | #include <linux/blkdev.h> |
| 44 | #include <linux/delay.h> |
| 45 | #include <linux/timer.h> |
| 46 | #include <linux/interrupt.h> |
| 47 | #include <linux/completion.h> |
| 48 | #include <linux/suspend.h> |
| 49 | #include <linux/workqueue.h> |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 50 | #include <linux/jiffies.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 51 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <scsi/scsi.h> |
Jeff Garzik | 193515d | 2005-11-07 00:59:37 -0500 | [diff] [blame] | 53 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <scsi/scsi_host.h> |
| 55 | #include <linux/libata.h> |
| 56 | #include <asm/io.h> |
| 57 | #include <asm/semaphore.h> |
| 58 | #include <asm/byteorder.h> |
| 59 | |
| 60 | #include "libata.h" |
| 61 | |
Jeff Garzik | 8bc3fc4 | 2007-05-21 20:26:38 -0400 | [diff] [blame] | 62 | #define DRV_VERSION "2.21" /* must be exactly four chars */ |
Jeff Garzik | fda0efc | 2007-01-31 07:43:15 -0500 | [diff] [blame] | 63 | |
| 64 | |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 65 | /* debounce timing parameters in msecs { interval, duration, timeout } */ |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 66 | const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; |
| 67 | const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 }; |
| 68 | const unsigned long sata_deb_timing_long[] = { 100, 2000, 5000 }; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 69 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 70 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
| 71 | u16 heads, u16 sectors); |
| 72 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev); |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 73 | static unsigned int ata_dev_set_AN(struct ata_device *dev, u8 enable); |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 74 | static void ata_dev_xfermask(struct ata_device *dev); |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 75 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 77 | unsigned int ata_print_id = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static struct workqueue_struct *ata_wq; |
| 79 | |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 80 | struct workqueue_struct *ata_aux_wq; |
| 81 | |
Jeff Garzik | 418dc1f | 2006-03-11 20:50:08 -0500 | [diff] [blame] | 82 | int atapi_enabled = 1; |
Jeff Garzik | 1623c81 | 2005-08-30 03:37:42 -0400 | [diff] [blame] | 83 | module_param(atapi_enabled, int, 0444); |
| 84 | MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); |
| 85 | |
Albert Lee | 95de719 | 2006-04-04 10:57:18 +0800 | [diff] [blame] | 86 | int atapi_dmadir = 0; |
| 87 | module_param(atapi_dmadir, int, 0444); |
| 88 | MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)"); |
| 89 | |
Mark Lord | baf4fdf | 2007-08-08 01:08:45 +0900 | [diff] [blame] | 90 | int atapi_passthru16 = 1; |
| 91 | module_param(atapi_passthru16, int, 0444); |
| 92 | MODULE_PARM_DESC(atapi_passthru16, "Enable ATA_16 passthru for ATAPI devices; on by default (0=off, 1=on)"); |
| 93 | |
Jeff Garzik | c3c013a | 2006-02-27 22:31:19 -0500 | [diff] [blame] | 94 | int libata_fua = 0; |
| 95 | module_param_named(fua, libata_fua, int, 0444); |
| 96 | MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); |
| 97 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 98 | static int ata_ignore_hpa = 0; |
| 99 | module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644); |
| 100 | MODULE_PARM_DESC(ignore_hpa, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)"); |
| 101 | |
Andrew Morton | a8601e5 | 2006-06-25 01:36:52 -0700 | [diff] [blame] | 102 | static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ; |
| 103 | module_param(ata_probe_timeout, int, 0444); |
| 104 | MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)"); |
| 105 | |
Jeff Garzik | d7d0dad | 2007-03-28 01:57:37 -0400 | [diff] [blame] | 106 | int libata_noacpi = 1; |
| 107 | module_param_named(noacpi, libata_noacpi, int, 0444); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 108 | MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set"); |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | MODULE_AUTHOR("Jeff Garzik"); |
| 111 | MODULE_DESCRIPTION("Library module for ATA devices"); |
| 112 | MODULE_LICENSE("GPL"); |
| 113 | MODULE_VERSION(DRV_VERSION); |
| 114 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 115 | |
| 116 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure |
| 118 | * @tf: Taskfile to convert |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | * @pmp: Port multiplier port |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 120 | * @is_cmd: This FIS is for command |
| 121 | * @fis: Buffer into which data will output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | * |
| 123 | * Converts a standard ATA taskfile to a Serial ATA |
| 124 | * FIS structure (Register - Host to Device). |
| 125 | * |
| 126 | * LOCKING: |
| 127 | * Inherited from caller. |
| 128 | */ |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 129 | void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 131 | fis[0] = 0x27; /* Register - Host to Device FIS */ |
| 132 | fis[1] = pmp & 0xf; /* Port multiplier number*/ |
| 133 | if (is_cmd) |
| 134 | fis[1] |= (1 << 7); /* bit 7 indicates Command FIS */ |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | fis[2] = tf->command; |
| 137 | fis[3] = tf->feature; |
| 138 | |
| 139 | fis[4] = tf->lbal; |
| 140 | fis[5] = tf->lbam; |
| 141 | fis[6] = tf->lbah; |
| 142 | fis[7] = tf->device; |
| 143 | |
| 144 | fis[8] = tf->hob_lbal; |
| 145 | fis[9] = tf->hob_lbam; |
| 146 | fis[10] = tf->hob_lbah; |
| 147 | fis[11] = tf->hob_feature; |
| 148 | |
| 149 | fis[12] = tf->nsect; |
| 150 | fis[13] = tf->hob_nsect; |
| 151 | fis[14] = 0; |
| 152 | fis[15] = tf->ctl; |
| 153 | |
| 154 | fis[16] = 0; |
| 155 | fis[17] = 0; |
| 156 | fis[18] = 0; |
| 157 | fis[19] = 0; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * ata_tf_from_fis - Convert SATA FIS to ATA taskfile |
| 162 | * @fis: Buffer from which data will be input |
| 163 | * @tf: Taskfile to output |
| 164 | * |
Mark Lord | e12a1be | 2005-11-12 18:55:45 -0500 | [diff] [blame] | 165 | * Converts a serial ATA FIS structure to a standard ATA taskfile. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | * |
| 167 | * LOCKING: |
| 168 | * Inherited from caller. |
| 169 | */ |
| 170 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 171 | void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { |
| 173 | tf->command = fis[2]; /* status */ |
| 174 | tf->feature = fis[3]; /* error */ |
| 175 | |
| 176 | tf->lbal = fis[4]; |
| 177 | tf->lbam = fis[5]; |
| 178 | tf->lbah = fis[6]; |
| 179 | tf->device = fis[7]; |
| 180 | |
| 181 | tf->hob_lbal = fis[8]; |
| 182 | tf->hob_lbam = fis[9]; |
| 183 | tf->hob_lbah = fis[10]; |
| 184 | |
| 185 | tf->nsect = fis[12]; |
| 186 | tf->hob_nsect = fis[13]; |
| 187 | } |
| 188 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 189 | static const u8 ata_rw_cmds[] = { |
| 190 | /* pio multi */ |
| 191 | ATA_CMD_READ_MULTI, |
| 192 | ATA_CMD_WRITE_MULTI, |
| 193 | ATA_CMD_READ_MULTI_EXT, |
| 194 | ATA_CMD_WRITE_MULTI_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 195 | 0, |
| 196 | 0, |
| 197 | 0, |
| 198 | ATA_CMD_WRITE_MULTI_FUA_EXT, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 199 | /* pio */ |
| 200 | ATA_CMD_PIO_READ, |
| 201 | ATA_CMD_PIO_WRITE, |
| 202 | ATA_CMD_PIO_READ_EXT, |
| 203 | ATA_CMD_PIO_WRITE_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 204 | 0, |
| 205 | 0, |
| 206 | 0, |
| 207 | 0, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 208 | /* dma */ |
| 209 | ATA_CMD_READ, |
| 210 | ATA_CMD_WRITE, |
| 211 | ATA_CMD_READ_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 212 | ATA_CMD_WRITE_EXT, |
| 213 | 0, |
| 214 | 0, |
| 215 | 0, |
| 216 | ATA_CMD_WRITE_FUA_EXT |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 217 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | /** |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 220 | * ata_rwcmd_protocol - set taskfile r/w commands and protocol |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 221 | * @tf: command to examine and configure |
| 222 | * @dev: device tf belongs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | * |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 224 | * Examine the device configuration and tf->flags to calculate |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 225 | * the proper read/write commands and protocol to use. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | * |
| 227 | * LOCKING: |
| 228 | * caller. |
| 229 | */ |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 230 | static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 232 | u8 cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 234 | int index, fua, lba48, write; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 235 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 236 | fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 237 | lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; |
| 238 | write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 240 | if (dev->flags & ATA_DFLAG_PIO) { |
| 241 | tf->protocol = ATA_PROT_PIO; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 242 | index = dev->multi_count ? 0 : 8; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 243 | } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { |
Alan Cox | 8d238e0 | 2006-01-17 20:50:31 +0000 | [diff] [blame] | 244 | /* Unable to use DMA due to host limitation */ |
| 245 | tf->protocol = ATA_PROT_PIO; |
Albert Lee | 0565c26 | 2006-02-13 18:55:25 +0800 | [diff] [blame] | 246 | index = dev->multi_count ? 0 : 8; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 247 | } else { |
| 248 | tf->protocol = ATA_PROT_DMA; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 249 | index = 16; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 252 | cmd = ata_rw_cmds[index + fua + lba48 + write]; |
| 253 | if (cmd) { |
| 254 | tf->command = cmd; |
| 255 | return 0; |
| 256 | } |
| 257 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 260 | /** |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 261 | * ata_tf_read_block - Read block address from ATA taskfile |
| 262 | * @tf: ATA taskfile of interest |
| 263 | * @dev: ATA device @tf belongs to |
| 264 | * |
| 265 | * LOCKING: |
| 266 | * None. |
| 267 | * |
| 268 | * Read block address from @tf. This function can handle all |
| 269 | * three address formats - LBA, LBA48 and CHS. tf->protocol and |
| 270 | * flags select the address format to use. |
| 271 | * |
| 272 | * RETURNS: |
| 273 | * Block address read from @tf. |
| 274 | */ |
| 275 | u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev) |
| 276 | { |
| 277 | u64 block = 0; |
| 278 | |
| 279 | if (tf->flags & ATA_TFLAG_LBA) { |
| 280 | if (tf->flags & ATA_TFLAG_LBA48) { |
| 281 | block |= (u64)tf->hob_lbah << 40; |
| 282 | block |= (u64)tf->hob_lbam << 32; |
| 283 | block |= tf->hob_lbal << 24; |
| 284 | } else |
| 285 | block |= (tf->device & 0xf) << 24; |
| 286 | |
| 287 | block |= tf->lbah << 16; |
| 288 | block |= tf->lbam << 8; |
| 289 | block |= tf->lbal; |
| 290 | } else { |
| 291 | u32 cyl, head, sect; |
| 292 | |
| 293 | cyl = tf->lbam | (tf->lbah << 8); |
| 294 | head = tf->device & 0xf; |
| 295 | sect = tf->lbal; |
| 296 | |
| 297 | block = (cyl * dev->heads + head) * dev->sectors + sect; |
| 298 | } |
| 299 | |
| 300 | return block; |
| 301 | } |
| 302 | |
| 303 | /** |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 304 | * ata_build_rw_tf - Build ATA taskfile for given read/write request |
| 305 | * @tf: Target ATA taskfile |
| 306 | * @dev: ATA device @tf belongs to |
| 307 | * @block: Block address |
| 308 | * @n_block: Number of blocks |
| 309 | * @tf_flags: RW/FUA etc... |
| 310 | * @tag: tag |
| 311 | * |
| 312 | * LOCKING: |
| 313 | * None. |
| 314 | * |
| 315 | * Build ATA taskfile @tf for read/write request described by |
| 316 | * @block, @n_block, @tf_flags and @tag on @dev. |
| 317 | * |
| 318 | * RETURNS: |
| 319 | * |
| 320 | * 0 on success, -ERANGE if the request is too large for @dev, |
| 321 | * -EINVAL if the request is invalid. |
| 322 | */ |
| 323 | int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, |
| 324 | u64 block, u32 n_block, unsigned int tf_flags, |
| 325 | unsigned int tag) |
| 326 | { |
| 327 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 328 | tf->flags |= tf_flags; |
| 329 | |
Tejun Heo | 6d1245b | 2007-02-20 23:20:27 +0900 | [diff] [blame] | 330 | if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) { |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 331 | /* yay, NCQ */ |
| 332 | if (!lba_48_ok(block, n_block)) |
| 333 | return -ERANGE; |
| 334 | |
| 335 | tf->protocol = ATA_PROT_NCQ; |
| 336 | tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; |
| 337 | |
| 338 | if (tf->flags & ATA_TFLAG_WRITE) |
| 339 | tf->command = ATA_CMD_FPDMA_WRITE; |
| 340 | else |
| 341 | tf->command = ATA_CMD_FPDMA_READ; |
| 342 | |
| 343 | tf->nsect = tag << 3; |
| 344 | tf->hob_feature = (n_block >> 8) & 0xff; |
| 345 | tf->feature = n_block & 0xff; |
| 346 | |
| 347 | tf->hob_lbah = (block >> 40) & 0xff; |
| 348 | tf->hob_lbam = (block >> 32) & 0xff; |
| 349 | tf->hob_lbal = (block >> 24) & 0xff; |
| 350 | tf->lbah = (block >> 16) & 0xff; |
| 351 | tf->lbam = (block >> 8) & 0xff; |
| 352 | tf->lbal = block & 0xff; |
| 353 | |
| 354 | tf->device = 1 << 6; |
| 355 | if (tf->flags & ATA_TFLAG_FUA) |
| 356 | tf->device |= 1 << 7; |
| 357 | } else if (dev->flags & ATA_DFLAG_LBA) { |
| 358 | tf->flags |= ATA_TFLAG_LBA; |
| 359 | |
| 360 | if (lba_28_ok(block, n_block)) { |
| 361 | /* use LBA28 */ |
| 362 | tf->device |= (block >> 24) & 0xf; |
| 363 | } else if (lba_48_ok(block, n_block)) { |
| 364 | if (!(dev->flags & ATA_DFLAG_LBA48)) |
| 365 | return -ERANGE; |
| 366 | |
| 367 | /* use LBA48 */ |
| 368 | tf->flags |= ATA_TFLAG_LBA48; |
| 369 | |
| 370 | tf->hob_nsect = (n_block >> 8) & 0xff; |
| 371 | |
| 372 | tf->hob_lbah = (block >> 40) & 0xff; |
| 373 | tf->hob_lbam = (block >> 32) & 0xff; |
| 374 | tf->hob_lbal = (block >> 24) & 0xff; |
| 375 | } else |
| 376 | /* request too large even for LBA48 */ |
| 377 | return -ERANGE; |
| 378 | |
| 379 | if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) |
| 380 | return -EINVAL; |
| 381 | |
| 382 | tf->nsect = n_block & 0xff; |
| 383 | |
| 384 | tf->lbah = (block >> 16) & 0xff; |
| 385 | tf->lbam = (block >> 8) & 0xff; |
| 386 | tf->lbal = block & 0xff; |
| 387 | |
| 388 | tf->device |= ATA_LBA; |
| 389 | } else { |
| 390 | /* CHS */ |
| 391 | u32 sect, head, cyl, track; |
| 392 | |
| 393 | /* The request -may- be too large for CHS addressing. */ |
| 394 | if (!lba_28_ok(block, n_block)) |
| 395 | return -ERANGE; |
| 396 | |
| 397 | if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | /* Convert LBA to CHS */ |
| 401 | track = (u32)block / dev->sectors; |
| 402 | cyl = track / dev->heads; |
| 403 | head = track % dev->heads; |
| 404 | sect = (u32)block % dev->sectors + 1; |
| 405 | |
| 406 | DPRINTK("block %u track %u cyl %u head %u sect %u\n", |
| 407 | (u32)block, track, cyl, head, sect); |
| 408 | |
| 409 | /* Check whether the converted CHS can fit. |
| 410 | Cylinder: 0-65535 |
| 411 | Head: 0-15 |
| 412 | Sector: 1-255*/ |
| 413 | if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) |
| 414 | return -ERANGE; |
| 415 | |
| 416 | tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ |
| 417 | tf->lbal = sect; |
| 418 | tf->lbam = cyl; |
| 419 | tf->lbah = cyl >> 8; |
| 420 | tf->device |= head; |
| 421 | } |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /** |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 427 | * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask |
| 428 | * @pio_mask: pio_mask |
| 429 | * @mwdma_mask: mwdma_mask |
| 430 | * @udma_mask: udma_mask |
| 431 | * |
| 432 | * Pack @pio_mask, @mwdma_mask and @udma_mask into a single |
| 433 | * unsigned int xfer_mask. |
| 434 | * |
| 435 | * LOCKING: |
| 436 | * None. |
| 437 | * |
| 438 | * RETURNS: |
| 439 | * Packed xfer_mask. |
| 440 | */ |
| 441 | static unsigned int ata_pack_xfermask(unsigned int pio_mask, |
| 442 | unsigned int mwdma_mask, |
| 443 | unsigned int udma_mask) |
| 444 | { |
| 445 | return ((pio_mask << ATA_SHIFT_PIO) & ATA_MASK_PIO) | |
| 446 | ((mwdma_mask << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA) | |
| 447 | ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA); |
| 448 | } |
| 449 | |
Tejun Heo | c0489e4 | 2006-03-24 14:07:49 +0900 | [diff] [blame] | 450 | /** |
| 451 | * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks |
| 452 | * @xfer_mask: xfer_mask to unpack |
| 453 | * @pio_mask: resulting pio_mask |
| 454 | * @mwdma_mask: resulting mwdma_mask |
| 455 | * @udma_mask: resulting udma_mask |
| 456 | * |
| 457 | * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask. |
| 458 | * Any NULL distination masks will be ignored. |
| 459 | */ |
| 460 | static void ata_unpack_xfermask(unsigned int xfer_mask, |
| 461 | unsigned int *pio_mask, |
| 462 | unsigned int *mwdma_mask, |
| 463 | unsigned int *udma_mask) |
| 464 | { |
| 465 | if (pio_mask) |
| 466 | *pio_mask = (xfer_mask & ATA_MASK_PIO) >> ATA_SHIFT_PIO; |
| 467 | if (mwdma_mask) |
| 468 | *mwdma_mask = (xfer_mask & ATA_MASK_MWDMA) >> ATA_SHIFT_MWDMA; |
| 469 | if (udma_mask) |
| 470 | *udma_mask = (xfer_mask & ATA_MASK_UDMA) >> ATA_SHIFT_UDMA; |
| 471 | } |
| 472 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 473 | static const struct ata_xfer_ent { |
Tejun Heo | be9a50c8 | 2006-03-31 22:48:52 +0900 | [diff] [blame] | 474 | int shift, bits; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 475 | u8 base; |
| 476 | } ata_xfer_tbl[] = { |
| 477 | { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 }, |
| 478 | { ATA_SHIFT_MWDMA, ATA_BITS_MWDMA, XFER_MW_DMA_0 }, |
| 479 | { ATA_SHIFT_UDMA, ATA_BITS_UDMA, XFER_UDMA_0 }, |
| 480 | { -1, }, |
| 481 | }; |
| 482 | |
| 483 | /** |
| 484 | * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask |
| 485 | * @xfer_mask: xfer_mask of interest |
| 486 | * |
| 487 | * Return matching XFER_* value for @xfer_mask. Only the highest |
| 488 | * bit of @xfer_mask is considered. |
| 489 | * |
| 490 | * LOCKING: |
| 491 | * None. |
| 492 | * |
| 493 | * RETURNS: |
| 494 | * Matching XFER_* value, 0 if no match found. |
| 495 | */ |
| 496 | static u8 ata_xfer_mask2mode(unsigned int xfer_mask) |
| 497 | { |
| 498 | int highbit = fls(xfer_mask) - 1; |
| 499 | const struct ata_xfer_ent *ent; |
| 500 | |
| 501 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 502 | if (highbit >= ent->shift && highbit < ent->shift + ent->bits) |
| 503 | return ent->base + highbit - ent->shift; |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * ata_xfer_mode2mask - Find matching xfer_mask for XFER_* |
| 509 | * @xfer_mode: XFER_* of interest |
| 510 | * |
| 511 | * Return matching xfer_mask for @xfer_mode. |
| 512 | * |
| 513 | * LOCKING: |
| 514 | * None. |
| 515 | * |
| 516 | * RETURNS: |
| 517 | * Matching xfer_mask, 0 if no match found. |
| 518 | */ |
| 519 | static unsigned int ata_xfer_mode2mask(u8 xfer_mode) |
| 520 | { |
| 521 | const struct ata_xfer_ent *ent; |
| 522 | |
| 523 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 524 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
| 525 | return 1 << (ent->shift + xfer_mode - ent->base); |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * ata_xfer_mode2shift - Find matching xfer_shift for XFER_* |
| 531 | * @xfer_mode: XFER_* of interest |
| 532 | * |
| 533 | * Return matching xfer_shift for @xfer_mode. |
| 534 | * |
| 535 | * LOCKING: |
| 536 | * None. |
| 537 | * |
| 538 | * RETURNS: |
| 539 | * Matching xfer_shift, -1 if no match found. |
| 540 | */ |
| 541 | static int ata_xfer_mode2shift(unsigned int xfer_mode) |
| 542 | { |
| 543 | const struct ata_xfer_ent *ent; |
| 544 | |
| 545 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 546 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
| 547 | return ent->shift; |
| 548 | return -1; |
| 549 | } |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /** |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 552 | * ata_mode_string - convert xfer_mask to string |
| 553 | * @xfer_mask: mask of bits supported; only highest bit counts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | * |
| 555 | * Determine string which represents the highest speed |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 556 | * (highest bit in @modemask). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | * |
| 558 | * LOCKING: |
| 559 | * None. |
| 560 | * |
| 561 | * RETURNS: |
| 562 | * Constant C string representing highest speed listed in |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 563 | * @mode_mask, or the constant C string "<n/a>". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | */ |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 565 | static const char *ata_mode_string(unsigned int xfer_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | { |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 567 | static const char * const xfer_mode_str[] = { |
| 568 | "PIO0", |
| 569 | "PIO1", |
| 570 | "PIO2", |
| 571 | "PIO3", |
| 572 | "PIO4", |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 573 | "PIO5", |
| 574 | "PIO6", |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 575 | "MWDMA0", |
| 576 | "MWDMA1", |
| 577 | "MWDMA2", |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 578 | "MWDMA3", |
| 579 | "MWDMA4", |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 580 | "UDMA/16", |
| 581 | "UDMA/25", |
| 582 | "UDMA/33", |
| 583 | "UDMA/44", |
| 584 | "UDMA/66", |
| 585 | "UDMA/100", |
| 586 | "UDMA/133", |
| 587 | "UDMA7", |
| 588 | }; |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 589 | int highbit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 591 | highbit = fls(xfer_mask) - 1; |
| 592 | if (highbit >= 0 && highbit < ARRAY_SIZE(xfer_mode_str)) |
| 593 | return xfer_mode_str[highbit]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return "<n/a>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Tejun Heo | 4c360c8 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 597 | static const char *sata_spd_string(unsigned int spd) |
| 598 | { |
| 599 | static const char * const spd_str[] = { |
| 600 | "1.5 Gbps", |
| 601 | "3.0 Gbps", |
| 602 | }; |
| 603 | |
| 604 | if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) |
| 605 | return "<unknown>"; |
| 606 | return spd_str[spd - 1]; |
| 607 | } |
| 608 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 609 | void ata_dev_disable(struct ata_device *dev) |
Tejun Heo | 0b8efb0 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 610 | { |
Tejun Heo | 09d7f9b | 2007-06-25 23:34:02 +0900 | [diff] [blame] | 611 | if (ata_dev_enabled(dev)) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 612 | if (ata_msg_drv(dev->link->ap)) |
Tejun Heo | 09d7f9b | 2007-06-25 23:34:02 +0900 | [diff] [blame] | 613 | ata_dev_printk(dev, KERN_WARNING, "disabled\n"); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 614 | ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | |
| 615 | ATA_DNXFER_QUIET); |
Tejun Heo | 0b8efb0 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 616 | dev->class++; |
| 617 | } |
| 618 | } |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | * ata_devchk - PATA device presence detection |
| 622 | * @ap: ATA channel to examine |
| 623 | * @device: Device to examine (starting at zero) |
| 624 | * |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 625 | * This technique was originally described in |
| 626 | * Hale Landis's ATADRVR (www.ata-atapi.com), and |
| 627 | * later found its way into the ATA/ATAPI spec. |
| 628 | * |
| 629 | * Write a pattern to the ATA shadow registers, |
| 630 | * and if a device is present, it will respond by |
| 631 | * correctly storing and echoing back the |
| 632 | * ATA shadow register contents. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | * |
| 634 | * LOCKING: |
| 635 | * caller. |
| 636 | */ |
| 637 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 638 | static unsigned int ata_devchk(struct ata_port *ap, unsigned int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 640 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 641 | u8 nsect, lbal; |
| 642 | |
| 643 | ap->ops->dev_select(ap, device); |
| 644 | |
| 645 | iowrite8(0x55, ioaddr->nsect_addr); |
| 646 | iowrite8(0xaa, ioaddr->lbal_addr); |
| 647 | |
| 648 | iowrite8(0xaa, ioaddr->nsect_addr); |
| 649 | iowrite8(0x55, ioaddr->lbal_addr); |
| 650 | |
| 651 | iowrite8(0x55, ioaddr->nsect_addr); |
| 652 | iowrite8(0xaa, ioaddr->lbal_addr); |
| 653 | |
| 654 | nsect = ioread8(ioaddr->nsect_addr); |
| 655 | lbal = ioread8(ioaddr->lbal_addr); |
| 656 | |
| 657 | if ((nsect == 0x55) && (lbal == 0xaa)) |
| 658 | return 1; /* we found a device */ |
| 659 | |
| 660 | return 0; /* nothing found */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /** |
| 664 | * ata_dev_classify - determine device type based on ATA-spec signature |
| 665 | * @tf: ATA taskfile register set for device to be identified |
| 666 | * |
| 667 | * Determine from taskfile register contents whether a device is |
| 668 | * ATA or ATAPI, as per "Signature and persistence" section |
| 669 | * of ATA/PI spec (volume 1, sect 5.14). |
| 670 | * |
| 671 | * LOCKING: |
| 672 | * None. |
| 673 | * |
| 674 | * RETURNS: |
| 675 | * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, or %ATA_DEV_UNKNOWN |
| 676 | * the event of failure. |
| 677 | */ |
| 678 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 679 | unsigned int ata_dev_classify(const struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | { |
| 681 | /* Apple's open source Darwin code hints that some devices only |
| 682 | * put a proper signature into the LBA mid/high registers, |
| 683 | * So, we only check those. It's sufficient for uniqueness. |
| 684 | */ |
| 685 | |
| 686 | if (((tf->lbam == 0) && (tf->lbah == 0)) || |
| 687 | ((tf->lbam == 0x3c) && (tf->lbah == 0xc3))) { |
| 688 | DPRINTK("found ATA device by sig\n"); |
| 689 | return ATA_DEV_ATA; |
| 690 | } |
| 691 | |
| 692 | if (((tf->lbam == 0x14) && (tf->lbah == 0xeb)) || |
| 693 | ((tf->lbam == 0x69) && (tf->lbah == 0x96))) { |
| 694 | DPRINTK("found ATAPI device by sig\n"); |
| 695 | return ATA_DEV_ATAPI; |
| 696 | } |
| 697 | |
| 698 | DPRINTK("unknown device\n"); |
| 699 | return ATA_DEV_UNKNOWN; |
| 700 | } |
| 701 | |
| 702 | /** |
| 703 | * ata_dev_try_classify - Parse returned ATA device signature |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 704 | * @dev: ATA device to classify (starting at zero) |
| 705 | * @present: device seems present |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 706 | * @r_err: Value of error register on completion |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | * |
| 708 | * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs, |
| 709 | * an ATA/ATAPI-defined set of values is placed in the ATA |
| 710 | * shadow registers, indicating the results of device detection |
| 711 | * and diagnostics. |
| 712 | * |
| 713 | * Select the ATA device, and read the values from the ATA shadow |
| 714 | * registers. Then parse according to the Error register value, |
| 715 | * and the spec-defined values examined by ata_dev_classify(). |
| 716 | * |
| 717 | * LOCKING: |
| 718 | * caller. |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 719 | * |
| 720 | * RETURNS: |
| 721 | * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | */ |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 723 | unsigned int ata_dev_try_classify(struct ata_device *dev, int present, |
| 724 | u8 *r_err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 726 | struct ata_port *ap = dev->link->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | struct ata_taskfile tf; |
| 728 | unsigned int class; |
| 729 | u8 err; |
| 730 | |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 731 | ap->ops->dev_select(ap, dev->devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
| 733 | memset(&tf, 0, sizeof(tf)); |
| 734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | ap->ops->tf_read(ap, &tf); |
Jeff Garzik | 0169e28 | 2005-10-29 21:25:10 -0400 | [diff] [blame] | 736 | err = tf.feature; |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 737 | if (r_err) |
| 738 | *r_err = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
Alan Cox | 9359085 | 2006-09-12 16:55:12 +0100 | [diff] [blame] | 740 | /* see if device passed diags: if master then continue and warn later */ |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 741 | if (err == 0 && dev->devno == 0) |
Alan Cox | 9359085 | 2006-09-12 16:55:12 +0100 | [diff] [blame] | 742 | /* diagnostic fail : do nothing _YET_ */ |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 743 | dev->horkage |= ATA_HORKAGE_DIAGNOSTIC; |
Alan Cox | 9359085 | 2006-09-12 16:55:12 +0100 | [diff] [blame] | 744 | else if (err == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | /* do nothing */ ; |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 746 | else if ((dev->devno == 0) && (err == 0x81)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | /* do nothing */ ; |
| 748 | else |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 749 | return ATA_DEV_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 751 | /* determine if device is ATA or ATAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | class = ata_dev_classify(&tf); |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | if (class == ATA_DEV_UNKNOWN) |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 755 | return ATA_DEV_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0)) |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 757 | return ATA_DEV_NONE; |
| 758 | return class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 762 | * ata_id_string - Convert IDENTIFY DEVICE page into string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | * @id: IDENTIFY DEVICE results we will examine |
| 764 | * @s: string into which data is output |
| 765 | * @ofs: offset into identify device page |
| 766 | * @len: length of string to return. must be an even number. |
| 767 | * |
| 768 | * The strings in the IDENTIFY DEVICE page are broken up into |
| 769 | * 16-bit chunks. Run through the string, and output each |
| 770 | * 8-bit chunk linearly, regardless of platform. |
| 771 | * |
| 772 | * LOCKING: |
| 773 | * caller. |
| 774 | */ |
| 775 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 776 | void ata_id_string(const u16 *id, unsigned char *s, |
| 777 | unsigned int ofs, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | { |
| 779 | unsigned int c; |
| 780 | |
| 781 | while (len > 0) { |
| 782 | c = id[ofs] >> 8; |
| 783 | *s = c; |
| 784 | s++; |
| 785 | |
| 786 | c = id[ofs] & 0xff; |
| 787 | *s = c; |
| 788 | s++; |
| 789 | |
| 790 | ofs++; |
| 791 | len -= 2; |
| 792 | } |
| 793 | } |
| 794 | |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 795 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 796 | * ata_id_c_string - Convert IDENTIFY DEVICE page into C string |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 797 | * @id: IDENTIFY DEVICE results we will examine |
| 798 | * @s: string into which data is output |
| 799 | * @ofs: offset into identify device page |
| 800 | * @len: length of string to return. must be an odd number. |
| 801 | * |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 802 | * This function is identical to ata_id_string except that it |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 803 | * trims trailing spaces and terminates the resulting string with |
| 804 | * null. @len must be actual maximum length (even number) + 1. |
| 805 | * |
| 806 | * LOCKING: |
| 807 | * caller. |
| 808 | */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 809 | void ata_id_c_string(const u16 *id, unsigned char *s, |
| 810 | unsigned int ofs, unsigned int len) |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 811 | { |
| 812 | unsigned char *p; |
| 813 | |
| 814 | WARN_ON(!(len & 1)); |
| 815 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 816 | ata_id_string(id, s, ofs, len - 1); |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 817 | |
| 818 | p = s + strnlen(s, len - 1); |
| 819 | while (p > s && p[-1] == ' ') |
| 820 | p--; |
| 821 | *p = '\0'; |
| 822 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 823 | |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 824 | static u64 ata_id_n_sectors(const u16 *id) |
| 825 | { |
| 826 | if (ata_id_has_lba(id)) { |
| 827 | if (ata_id_has_lba48(id)) |
| 828 | return ata_id_u64(id, 100); |
| 829 | else |
| 830 | return ata_id_u32(id, 60); |
| 831 | } else { |
| 832 | if (ata_id_current_chs_valid(id)) |
| 833 | return ata_id_u32(id, 57); |
| 834 | else |
| 835 | return id[1] * id[3] * id[6]; |
| 836 | } |
| 837 | } |
| 838 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 839 | static u64 ata_tf_to_lba48(struct ata_taskfile *tf) |
| 840 | { |
| 841 | u64 sectors = 0; |
| 842 | |
| 843 | sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; |
| 844 | sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; |
| 845 | sectors |= (tf->hob_lbal & 0xff) << 24; |
| 846 | sectors |= (tf->lbah & 0xff) << 16; |
| 847 | sectors |= (tf->lbam & 0xff) << 8; |
| 848 | sectors |= (tf->lbal & 0xff); |
| 849 | |
| 850 | return ++sectors; |
| 851 | } |
| 852 | |
| 853 | static u64 ata_tf_to_lba(struct ata_taskfile *tf) |
| 854 | { |
| 855 | u64 sectors = 0; |
| 856 | |
| 857 | sectors |= (tf->device & 0x0f) << 24; |
| 858 | sectors |= (tf->lbah & 0xff) << 16; |
| 859 | sectors |= (tf->lbam & 0xff) << 8; |
| 860 | sectors |= (tf->lbal & 0xff); |
| 861 | |
| 862 | return ++sectors; |
| 863 | } |
| 864 | |
| 865 | /** |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 866 | * ata_read_native_max_address - Read native max address |
| 867 | * @dev: target device |
| 868 | * @max_sectors: out parameter for the result native max address |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 869 | * |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 870 | * Perform an LBA48 or LBA28 native size query upon the device in |
| 871 | * question. |
| 872 | * |
| 873 | * RETURNS: |
| 874 | * 0 on success, -EACCES if command is aborted by the drive. |
| 875 | * -EIO on other errors. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 876 | */ |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 877 | static int ata_read_native_max_address(struct ata_device *dev, u64 *max_sectors) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 878 | { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 879 | unsigned int err_mask; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 880 | struct ata_taskfile tf; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 881 | int lba48 = ata_id_has_lba48(dev->id); |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 882 | |
| 883 | ata_tf_init(dev, &tf); |
| 884 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 885 | /* always clear all address registers */ |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 886 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 887 | |
| 888 | if (lba48) { |
| 889 | tf.command = ATA_CMD_READ_NATIVE_MAX_EXT; |
| 890 | tf.flags |= ATA_TFLAG_LBA48; |
| 891 | } else |
| 892 | tf.command = ATA_CMD_READ_NATIVE_MAX; |
| 893 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 894 | tf.protocol |= ATA_PROT_NODATA; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 895 | tf.device |= ATA_LBA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 896 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 897 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
| 898 | if (err_mask) { |
| 899 | ata_dev_printk(dev, KERN_WARNING, "failed to read native " |
| 900 | "max address (err_mask=0x%x)\n", err_mask); |
| 901 | if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) |
| 902 | return -EACCES; |
| 903 | return -EIO; |
| 904 | } |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 905 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 906 | if (lba48) |
| 907 | *max_sectors = ata_tf_to_lba48(&tf); |
| 908 | else |
| 909 | *max_sectors = ata_tf_to_lba(&tf); |
| 910 | |
| 911 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | /** |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 915 | * ata_set_max_sectors - Set max sectors |
| 916 | * @dev: target device |
Randy Dunlap | 6b38d1d | 2007-05-01 17:35:55 -0700 | [diff] [blame] | 917 | * @new_sectors: new max sectors value to set for the device |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 918 | * |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 919 | * Set max sectors of @dev to @new_sectors. |
| 920 | * |
| 921 | * RETURNS: |
| 922 | * 0 on success, -EACCES if command is aborted or denied (due to |
| 923 | * previous non-volatile SET_MAX) by the drive. -EIO on other |
| 924 | * errors. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 925 | */ |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 926 | static int ata_set_max_sectors(struct ata_device *dev, u64 new_sectors) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 927 | { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 928 | unsigned int err_mask; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 929 | struct ata_taskfile tf; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 930 | int lba48 = ata_id_has_lba48(dev->id); |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 931 | |
| 932 | new_sectors--; |
| 933 | |
| 934 | ata_tf_init(dev, &tf); |
| 935 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 936 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 937 | |
| 938 | if (lba48) { |
| 939 | tf.command = ATA_CMD_SET_MAX_EXT; |
| 940 | tf.flags |= ATA_TFLAG_LBA48; |
| 941 | |
| 942 | tf.hob_lbal = (new_sectors >> 24) & 0xff; |
| 943 | tf.hob_lbam = (new_sectors >> 32) & 0xff; |
| 944 | tf.hob_lbah = (new_sectors >> 40) & 0xff; |
| 945 | } else |
| 946 | tf.command = ATA_CMD_SET_MAX; |
| 947 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 948 | tf.protocol |= ATA_PROT_NODATA; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 949 | tf.device |= ATA_LBA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 950 | |
| 951 | tf.lbal = (new_sectors >> 0) & 0xff; |
| 952 | tf.lbam = (new_sectors >> 8) & 0xff; |
| 953 | tf.lbah = (new_sectors >> 16) & 0xff; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 954 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 955 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
| 956 | if (err_mask) { |
| 957 | ata_dev_printk(dev, KERN_WARNING, "failed to set " |
| 958 | "max address (err_mask=0x%x)\n", err_mask); |
| 959 | if (err_mask == AC_ERR_DEV && |
| 960 | (tf.feature & (ATA_ABORTED | ATA_IDNF))) |
| 961 | return -EACCES; |
| 962 | return -EIO; |
| 963 | } |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 964 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 965 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /** |
| 969 | * ata_hpa_resize - Resize a device with an HPA set |
| 970 | * @dev: Device to resize |
| 971 | * |
| 972 | * Read the size of an LBA28 or LBA48 disk with HPA features and resize |
| 973 | * it if required to the full size of the media. The caller must check |
| 974 | * the drive has the HPA feature set enabled. |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 975 | * |
| 976 | * RETURNS: |
| 977 | * 0 on success, -errno on failure. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 978 | */ |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 979 | static int ata_hpa_resize(struct ata_device *dev) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 980 | { |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 981 | struct ata_eh_context *ehc = &dev->link->eh_context; |
| 982 | int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; |
| 983 | u64 sectors = ata_id_n_sectors(dev->id); |
| 984 | u64 native_sectors; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 985 | int rc; |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 986 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 987 | /* do we need to do it? */ |
| 988 | if (dev->class != ATA_DEV_ATA || |
| 989 | !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || |
| 990 | (dev->horkage & ATA_HORKAGE_BROKEN_HPA)) |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 991 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 992 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 993 | /* read native max address */ |
| 994 | rc = ata_read_native_max_address(dev, &native_sectors); |
| 995 | if (rc) { |
| 996 | /* If HPA isn't going to be unlocked, skip HPA |
| 997 | * resizing from the next try. |
| 998 | */ |
| 999 | if (!ata_ignore_hpa) { |
| 1000 | ata_dev_printk(dev, KERN_WARNING, "HPA support seems " |
| 1001 | "broken, will skip HPA handling\n"); |
| 1002 | dev->horkage |= ATA_HORKAGE_BROKEN_HPA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1003 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1004 | /* we can continue if device aborted the command */ |
| 1005 | if (rc == -EACCES) |
| 1006 | rc = 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1007 | } |
Tejun Heo | 37301a5 | 2007-06-25 20:45:54 +0900 | [diff] [blame] | 1008 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1009 | return rc; |
| 1010 | } |
| 1011 | |
| 1012 | /* nothing to do? */ |
| 1013 | if (native_sectors <= sectors || !ata_ignore_hpa) { |
| 1014 | if (!print_info || native_sectors == sectors) |
| 1015 | return 0; |
| 1016 | |
| 1017 | if (native_sectors > sectors) |
| 1018 | ata_dev_printk(dev, KERN_INFO, |
| 1019 | "HPA detected: current %llu, native %llu\n", |
| 1020 | (unsigned long long)sectors, |
| 1021 | (unsigned long long)native_sectors); |
| 1022 | else if (native_sectors < sectors) |
| 1023 | ata_dev_printk(dev, KERN_WARNING, |
| 1024 | "native sectors (%llu) is smaller than " |
| 1025 | "sectors (%llu)\n", |
| 1026 | (unsigned long long)native_sectors, |
| 1027 | (unsigned long long)sectors); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | /* let's unlock HPA */ |
| 1032 | rc = ata_set_max_sectors(dev, native_sectors); |
| 1033 | if (rc == -EACCES) { |
| 1034 | /* if device aborted the command, skip HPA resizing */ |
| 1035 | ata_dev_printk(dev, KERN_WARNING, "device aborted resize " |
| 1036 | "(%llu -> %llu), skipping HPA handling\n", |
| 1037 | (unsigned long long)sectors, |
| 1038 | (unsigned long long)native_sectors); |
| 1039 | dev->horkage |= ATA_HORKAGE_BROKEN_HPA; |
| 1040 | return 0; |
| 1041 | } else if (rc) |
| 1042 | return rc; |
| 1043 | |
| 1044 | /* re-read IDENTIFY data */ |
| 1045 | rc = ata_dev_reread_id(dev, 0); |
| 1046 | if (rc) { |
| 1047 | ata_dev_printk(dev, KERN_ERR, "failed to re-read IDENTIFY " |
| 1048 | "data after HPA resizing\n"); |
| 1049 | return rc; |
| 1050 | } |
| 1051 | |
| 1052 | if (print_info) { |
| 1053 | u64 new_sectors = ata_id_n_sectors(dev->id); |
| 1054 | ata_dev_printk(dev, KERN_INFO, |
| 1055 | "HPA unlocked: %llu -> %llu, native %llu\n", |
| 1056 | (unsigned long long)sectors, |
| 1057 | (unsigned long long)new_sectors, |
| 1058 | (unsigned long long)native_sectors); |
| 1059 | } |
| 1060 | |
| 1061 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1064 | /** |
Alan | 10305f0 | 2007-02-20 18:01:59 +0000 | [diff] [blame] | 1065 | * ata_id_to_dma_mode - Identify DMA mode from id block |
| 1066 | * @dev: device to identify |
Randy Dunlap | cc26126 | 2007-03-16 19:55:47 -0700 | [diff] [blame] | 1067 | * @unknown: mode to assume if we cannot tell |
Alan | 10305f0 | 2007-02-20 18:01:59 +0000 | [diff] [blame] | 1068 | * |
| 1069 | * Set up the timing values for the device based upon the identify |
| 1070 | * reported values for the DMA mode. This function is used by drivers |
| 1071 | * which rely upon firmware configured modes, but wish to report the |
| 1072 | * mode correctly when possible. |
| 1073 | * |
| 1074 | * In addition we emit similarly formatted messages to the default |
| 1075 | * ata_dev_set_mode handler, in order to provide consistency of |
| 1076 | * presentation. |
| 1077 | */ |
| 1078 | |
| 1079 | void ata_id_to_dma_mode(struct ata_device *dev, u8 unknown) |
| 1080 | { |
| 1081 | unsigned int mask; |
| 1082 | u8 mode; |
| 1083 | |
| 1084 | /* Pack the DMA modes */ |
| 1085 | mask = ((dev->id[63] >> 8) << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA; |
| 1086 | if (dev->id[53] & 0x04) |
| 1087 | mask |= ((dev->id[88] >> 8) << ATA_SHIFT_UDMA) & ATA_MASK_UDMA; |
| 1088 | |
| 1089 | /* Select the mode in use */ |
| 1090 | mode = ata_xfer_mask2mode(mask); |
| 1091 | |
| 1092 | if (mode != 0) { |
| 1093 | ata_dev_printk(dev, KERN_INFO, "configured for %s\n", |
| 1094 | ata_mode_string(mask)); |
| 1095 | } else { |
| 1096 | /* SWDMA perhaps ? */ |
| 1097 | mode = unknown; |
| 1098 | ata_dev_printk(dev, KERN_INFO, "configured for DMA\n"); |
| 1099 | } |
| 1100 | |
| 1101 | /* Configure the device reporting */ |
| 1102 | dev->xfer_mode = mode; |
| 1103 | dev->xfer_shift = ata_xfer_mode2shift(mode); |
| 1104 | } |
| 1105 | |
| 1106 | /** |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1107 | * ata_noop_dev_select - Select device 0/1 on ATA bus |
| 1108 | * @ap: ATA channel to manipulate |
| 1109 | * @device: ATA device (numbered from zero) to select |
| 1110 | * |
| 1111 | * This function performs no actual function. |
| 1112 | * |
| 1113 | * May be used as the dev_select() entry in ata_port_operations. |
| 1114 | * |
| 1115 | * LOCKING: |
| 1116 | * caller. |
| 1117 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | void ata_noop_dev_select (struct ata_port *ap, unsigned int device) |
| 1119 | { |
| 1120 | } |
| 1121 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | /** |
| 1124 | * ata_std_dev_select - Select device 0/1 on ATA bus |
| 1125 | * @ap: ATA channel to manipulate |
| 1126 | * @device: ATA device (numbered from zero) to select |
| 1127 | * |
| 1128 | * Use the method defined in the ATA specification to |
| 1129 | * make either device 0, or device 1, active on the |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1130 | * ATA channel. Works with both PIO and MMIO. |
| 1131 | * |
| 1132 | * May be used as the dev_select() entry in ata_port_operations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | * |
| 1134 | * LOCKING: |
| 1135 | * caller. |
| 1136 | */ |
| 1137 | |
| 1138 | void ata_std_dev_select (struct ata_port *ap, unsigned int device) |
| 1139 | { |
| 1140 | u8 tmp; |
| 1141 | |
| 1142 | if (device == 0) |
| 1143 | tmp = ATA_DEVICE_OBS; |
| 1144 | else |
| 1145 | tmp = ATA_DEVICE_OBS | ATA_DEV1; |
| 1146 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 1147 | iowrite8(tmp, ap->ioaddr.device_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | ata_pause(ap); /* needed; also flushes, for mmio */ |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * ata_dev_select - Select device 0/1 on ATA bus |
| 1153 | * @ap: ATA channel to manipulate |
| 1154 | * @device: ATA device (numbered from zero) to select |
| 1155 | * @wait: non-zero to wait for Status register BSY bit to clear |
| 1156 | * @can_sleep: non-zero if context allows sleeping |
| 1157 | * |
| 1158 | * Use the method defined in the ATA specification to |
| 1159 | * make either device 0, or device 1, active on the |
| 1160 | * ATA channel. |
| 1161 | * |
| 1162 | * This is a high-level version of ata_std_dev_select(), |
| 1163 | * which additionally provides the services of inserting |
| 1164 | * the proper pauses and status polling, where needed. |
| 1165 | * |
| 1166 | * LOCKING: |
| 1167 | * caller. |
| 1168 | */ |
| 1169 | |
| 1170 | void ata_dev_select(struct ata_port *ap, unsigned int device, |
| 1171 | unsigned int wait, unsigned int can_sleep) |
| 1172 | { |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1173 | if (ata_msg_probe(ap)) |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 1174 | ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, " |
| 1175 | "device %u, wait %u\n", device, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
| 1177 | if (wait) |
| 1178 | ata_wait_idle(ap); |
| 1179 | |
| 1180 | ap->ops->dev_select(ap, device); |
| 1181 | |
| 1182 | if (wait) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1183 | if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | msleep(150); |
| 1185 | ata_wait_idle(ap); |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * ata_dump_id - IDENTIFY DEVICE info debugging output |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1191 | * @id: IDENTIFY DEVICE page to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | * |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1193 | * Dump selected 16-bit words from the given IDENTIFY DEVICE |
| 1194 | * page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | * |
| 1196 | * LOCKING: |
| 1197 | * caller. |
| 1198 | */ |
| 1199 | |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1200 | static inline void ata_dump_id(const u16 *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | { |
| 1202 | DPRINTK("49==0x%04x " |
| 1203 | "53==0x%04x " |
| 1204 | "63==0x%04x " |
| 1205 | "64==0x%04x " |
| 1206 | "75==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1207 | id[49], |
| 1208 | id[53], |
| 1209 | id[63], |
| 1210 | id[64], |
| 1211 | id[75]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | DPRINTK("80==0x%04x " |
| 1213 | "81==0x%04x " |
| 1214 | "82==0x%04x " |
| 1215 | "83==0x%04x " |
| 1216 | "84==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1217 | id[80], |
| 1218 | id[81], |
| 1219 | id[82], |
| 1220 | id[83], |
| 1221 | id[84]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | DPRINTK("88==0x%04x " |
| 1223 | "93==0x%04x\n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1224 | id[88], |
| 1225 | id[93]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1228 | /** |
| 1229 | * ata_id_xfermask - Compute xfermask from the given IDENTIFY data |
| 1230 | * @id: IDENTIFY data to compute xfer mask from |
| 1231 | * |
| 1232 | * Compute the xfermask for this device. This is not as trivial |
| 1233 | * as it seems if we must consider early devices correctly. |
| 1234 | * |
| 1235 | * FIXME: pre IDE drive timing (do we care ?). |
| 1236 | * |
| 1237 | * LOCKING: |
| 1238 | * None. |
| 1239 | * |
| 1240 | * RETURNS: |
| 1241 | * Computed xfermask |
| 1242 | */ |
| 1243 | static unsigned int ata_id_xfermask(const u16 *id) |
| 1244 | { |
| 1245 | unsigned int pio_mask, mwdma_mask, udma_mask; |
| 1246 | |
| 1247 | /* Usual case. Word 53 indicates word 64 is valid */ |
| 1248 | if (id[ATA_ID_FIELD_VALID] & (1 << 1)) { |
| 1249 | pio_mask = id[ATA_ID_PIO_MODES] & 0x03; |
| 1250 | pio_mask <<= 3; |
| 1251 | pio_mask |= 0x7; |
| 1252 | } else { |
| 1253 | /* If word 64 isn't valid then Word 51 high byte holds |
| 1254 | * the PIO timing number for the maximum. Turn it into |
| 1255 | * a mask. |
| 1256 | */ |
Lennert Buytenhek | 7a0f1c8 | 2007-01-29 13:28:47 +0100 | [diff] [blame] | 1257 | u8 mode = (id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF; |
Alan Cox | 46767aeb | 2006-09-29 18:26:47 +0100 | [diff] [blame] | 1258 | if (mode < 5) /* Valid PIO range */ |
| 1259 | pio_mask = (2 << mode) - 1; |
| 1260 | else |
| 1261 | pio_mask = 1; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1262 | |
| 1263 | /* But wait.. there's more. Design your standards by |
| 1264 | * committee and you too can get a free iordy field to |
| 1265 | * process. However its the speeds not the modes that |
| 1266 | * are supported... Note drivers using the timing API |
| 1267 | * will get this right anyway |
| 1268 | */ |
| 1269 | } |
| 1270 | |
| 1271 | mwdma_mask = id[ATA_ID_MWDMA_MODES] & 0x07; |
Tejun Heo | fb21f0d | 2006-03-12 12:34:35 +0900 | [diff] [blame] | 1272 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1273 | if (ata_id_is_cfa(id)) { |
| 1274 | /* |
| 1275 | * Process compact flash extended modes |
| 1276 | */ |
| 1277 | int pio = id[163] & 0x7; |
| 1278 | int dma = (id[163] >> 3) & 7; |
| 1279 | |
| 1280 | if (pio) |
| 1281 | pio_mask |= (1 << 5); |
| 1282 | if (pio > 1) |
| 1283 | pio_mask |= (1 << 6); |
| 1284 | if (dma) |
| 1285 | mwdma_mask |= (1 << 3); |
| 1286 | if (dma > 1) |
| 1287 | mwdma_mask |= (1 << 4); |
| 1288 | } |
| 1289 | |
Tejun Heo | fb21f0d | 2006-03-12 12:34:35 +0900 | [diff] [blame] | 1290 | udma_mask = 0; |
| 1291 | if (id[ATA_ID_FIELD_VALID] & (1 << 2)) |
| 1292 | udma_mask = id[ATA_ID_UDMA_MODES] & 0xff; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1293 | |
| 1294 | return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 1295 | } |
| 1296 | |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1297 | /** |
| 1298 | * ata_port_queue_task - Queue port_task |
| 1299 | * @ap: The ata_port to queue port_task for |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 1300 | * @fn: workqueue function to be scheduled |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1301 | * @data: data for @fn to use |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 1302 | * @delay: delay time for workqueue function |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1303 | * |
| 1304 | * Schedule @fn(@data) for execution after @delay jiffies using |
| 1305 | * port_task. There is one port_task per port and it's the |
| 1306 | * user(low level driver)'s responsibility to make sure that only |
| 1307 | * one task is active at any given time. |
| 1308 | * |
| 1309 | * libata core layer takes care of synchronization between |
| 1310 | * port_task and EH. ata_port_queue_task() may be ignored for EH |
| 1311 | * synchronization. |
| 1312 | * |
| 1313 | * LOCKING: |
| 1314 | * Inherited from caller. |
| 1315 | */ |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1316 | void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data, |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1317 | unsigned long delay) |
| 1318 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1319 | PREPARE_DELAYED_WORK(&ap->port_task, fn); |
| 1320 | ap->port_task_data = data; |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1321 | |
Oleg Nesterov | 45a66c1 | 2007-07-09 11:46:13 -0700 | [diff] [blame] | 1322 | /* may fail if ata_port_flush_task() in progress */ |
| 1323 | queue_delayed_work(ata_wq, &ap->port_task, delay); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * ata_port_flush_task - Flush port_task |
| 1328 | * @ap: The ata_port to flush port_task for |
| 1329 | * |
| 1330 | * After this function completes, port_task is guranteed not to |
| 1331 | * be running or scheduled. |
| 1332 | * |
| 1333 | * LOCKING: |
| 1334 | * Kernel thread context (may sleep) |
| 1335 | */ |
| 1336 | void ata_port_flush_task(struct ata_port *ap) |
| 1337 | { |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1338 | DPRINTK("ENTER\n"); |
| 1339 | |
Oleg Nesterov | 45a66c1 | 2007-07-09 11:46:13 -0700 | [diff] [blame] | 1340 | cancel_rearming_delayed_work(&ap->port_task); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1341 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1342 | if (ata_msg_ctl(ap)) |
| 1343 | ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1344 | } |
| 1345 | |
Adrian Bunk | 7102d23 | 2007-01-04 00:09:36 +0100 | [diff] [blame] | 1346 | static void ata_qc_complete_internal(struct ata_queued_cmd *qc) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1347 | { |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1348 | struct completion *waiting = qc->private_data; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1349 | |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1350 | complete(waiting); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | /** |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1354 | * ata_exec_internal_sg - execute libata internal command |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1355 | * @dev: Device to which the command is sent |
| 1356 | * @tf: Taskfile registers for the command and the result |
Tejun Heo | d69cf37 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1357 | * @cdb: CDB for packet command |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1358 | * @dma_dir: Data tranfer direction of the command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1359 | * @sg: sg list for the data buffer of the command |
| 1360 | * @n_elem: Number of sg entries |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1361 | * |
| 1362 | * Executes libata internal command with timeout. @tf contains |
| 1363 | * command on entry and result on return. Timeout and error |
| 1364 | * conditions are reported via return value. No recovery action |
| 1365 | * is taken after a command times out. It's caller's duty to |
| 1366 | * clean up after timeout. |
| 1367 | * |
| 1368 | * LOCKING: |
| 1369 | * None. Should be called with kernel context, might sleep. |
Tejun Heo | 551e888 | 2006-06-12 14:09:49 +0900 | [diff] [blame] | 1370 | * |
| 1371 | * RETURNS: |
| 1372 | * Zero on success, AC_ERR_* mask on failure |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1373 | */ |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1374 | unsigned ata_exec_internal_sg(struct ata_device *dev, |
| 1375 | struct ata_taskfile *tf, const u8 *cdb, |
| 1376 | int dma_dir, struct scatterlist *sg, |
| 1377 | unsigned int n_elem) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1378 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1379 | struct ata_link *link = dev->link; |
| 1380 | struct ata_port *ap = link->ap; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1381 | u8 command = tf->command; |
| 1382 | struct ata_queued_cmd *qc; |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1383 | unsigned int tag, preempted_tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1384 | u32 preempted_sactive, preempted_qc_active; |
Ingo Molnar | 60be6b9 | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 1385 | DECLARE_COMPLETION_ONSTACK(wait); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1386 | unsigned long flags; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1387 | unsigned int err_mask; |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1388 | int rc; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1389 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1390 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1391 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 1392 | /* no internal command while frozen */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1393 | if (ap->pflags & ATA_PFLAG_FROZEN) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1394 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 1395 | return AC_ERR_SYSTEM; |
| 1396 | } |
| 1397 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1398 | /* initialize internal qc */ |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1399 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1400 | /* XXX: Tag 0 is used for drivers with legacy EH as some |
| 1401 | * drivers choke if any other tag is given. This breaks |
| 1402 | * ata_tag_internal() test for those drivers. Don't use new |
| 1403 | * EH stuff without converting to it. |
| 1404 | */ |
| 1405 | if (ap->ops->error_handler) |
| 1406 | tag = ATA_TAG_INTERNAL; |
| 1407 | else |
| 1408 | tag = 0; |
| 1409 | |
Tejun Heo | 6cec4a3 | 2006-05-15 21:03:41 +0900 | [diff] [blame] | 1410 | if (test_and_set_bit(tag, &ap->qc_allocated)) |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1411 | BUG(); |
Tejun Heo | f69499f | 2006-05-15 20:58:03 +0900 | [diff] [blame] | 1412 | qc = __ata_qc_from_tag(ap, tag); |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1413 | |
| 1414 | qc->tag = tag; |
| 1415 | qc->scsicmd = NULL; |
| 1416 | qc->ap = ap; |
| 1417 | qc->dev = dev; |
| 1418 | ata_qc_reinit(qc); |
| 1419 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1420 | preempted_tag = link->active_tag; |
| 1421 | preempted_sactive = link->sactive; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1422 | preempted_qc_active = ap->qc_active; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1423 | link->active_tag = ATA_TAG_POISON; |
| 1424 | link->sactive = 0; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1425 | ap->qc_active = 0; |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1426 | |
| 1427 | /* prepare & issue qc */ |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1428 | qc->tf = *tf; |
Tejun Heo | d69cf37 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1429 | if (cdb) |
| 1430 | memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); |
Tejun Heo | e61e067 | 2006-05-15 20:57:40 +0900 | [diff] [blame] | 1431 | qc->flags |= ATA_QCFLAG_RESULT_TF; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1432 | qc->dma_dir = dma_dir; |
| 1433 | if (dma_dir != DMA_NONE) { |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1434 | unsigned int i, buflen = 0; |
| 1435 | |
| 1436 | for (i = 0; i < n_elem; i++) |
| 1437 | buflen += sg[i].length; |
| 1438 | |
| 1439 | ata_sg_init(qc, sg, n_elem); |
Brian King | 49c8042 | 2007-01-30 11:32:26 -0600 | [diff] [blame] | 1440 | qc->nbytes = buflen; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1441 | } |
| 1442 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1443 | qc->private_data = &wait; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1444 | qc->complete_fn = ata_qc_complete_internal; |
| 1445 | |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 1446 | ata_qc_issue(qc); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1447 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1448 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1449 | |
Andrew Morton | a8601e5 | 2006-06-25 01:36:52 -0700 | [diff] [blame] | 1450 | rc = wait_for_completion_timeout(&wait, ata_probe_timeout); |
Albert Lee | 41ade50 | 2006-03-14 11:19:04 +0800 | [diff] [blame] | 1451 | |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1452 | ata_port_flush_task(ap); |
| 1453 | |
| 1454 | if (!rc) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1455 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1456 | |
| 1457 | /* We're racing with irq here. If we lose, the |
| 1458 | * following test prevents us from completing the qc |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1459 | * twice. If we win, the port is frozen and will be |
| 1460 | * cleaned up by ->post_internal_cmd(). |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1461 | */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1462 | if (qc->flags & ATA_QCFLAG_ACTIVE) { |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1463 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 1464 | |
| 1465 | if (ap->ops->error_handler) |
| 1466 | ata_port_freeze(ap); |
| 1467 | else |
| 1468 | ata_qc_complete(qc); |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 1469 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1470 | if (ata_msg_warn(ap)) |
| 1471 | ata_dev_printk(dev, KERN_WARNING, |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1472 | "qc timeout (cmd 0x%x)\n", command); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1473 | } |
| 1474 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1475 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1476 | } |
| 1477 | |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1478 | /* do post_internal_cmd */ |
| 1479 | if (ap->ops->post_internal_cmd) |
| 1480 | ap->ops->post_internal_cmd(qc); |
| 1481 | |
Tejun Heo | a51d644 | 2007-03-20 15:24:11 +0900 | [diff] [blame] | 1482 | /* perform minimal error analysis */ |
| 1483 | if (qc->flags & ATA_QCFLAG_FAILED) { |
| 1484 | if (qc->result_tf.command & (ATA_ERR | ATA_DF)) |
| 1485 | qc->err_mask |= AC_ERR_DEV; |
| 1486 | |
| 1487 | if (!qc->err_mask) |
| 1488 | qc->err_mask |= AC_ERR_OTHER; |
| 1489 | |
| 1490 | if (qc->err_mask & ~AC_ERR_OTHER) |
| 1491 | qc->err_mask &= ~AC_ERR_OTHER; |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1492 | } |
| 1493 | |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1494 | /* finish up */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1495 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1496 | |
Tejun Heo | e61e067 | 2006-05-15 20:57:40 +0900 | [diff] [blame] | 1497 | *tf = qc->result_tf; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1498 | err_mask = qc->err_mask; |
| 1499 | |
| 1500 | ata_qc_free(qc); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1501 | link->active_tag = preempted_tag; |
| 1502 | link->sactive = preempted_sactive; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1503 | ap->qc_active = preempted_qc_active; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1504 | |
Tejun Heo | 1f7dd3e | 2006-03-24 15:25:30 +0900 | [diff] [blame] | 1505 | /* XXX - Some LLDDs (sata_mv) disable port on command failure. |
| 1506 | * Until those drivers are fixed, we detect the condition |
| 1507 | * here, fail the command with AC_ERR_SYSTEM and reenable the |
| 1508 | * port. |
| 1509 | * |
| 1510 | * Note that this doesn't change any behavior as internal |
| 1511 | * command failure results in disabling the device in the |
| 1512 | * higher layer for LLDDs without new reset/EH callbacks. |
| 1513 | * |
| 1514 | * Kill the following code as soon as those drivers are fixed. |
| 1515 | */ |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 1516 | if (ap->flags & ATA_FLAG_DISABLED) { |
Tejun Heo | 1f7dd3e | 2006-03-24 15:25:30 +0900 | [diff] [blame] | 1517 | err_mask |= AC_ERR_SYSTEM; |
| 1518 | ata_port_probe(ap); |
| 1519 | } |
| 1520 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1521 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1522 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1523 | return err_mask; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1524 | } |
| 1525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | /** |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1527 | * ata_exec_internal - execute libata internal command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1528 | * @dev: Device to which the command is sent |
| 1529 | * @tf: Taskfile registers for the command and the result |
| 1530 | * @cdb: CDB for packet command |
| 1531 | * @dma_dir: Data tranfer direction of the command |
| 1532 | * @buf: Data buffer of the command |
| 1533 | * @buflen: Length of data buffer |
| 1534 | * |
| 1535 | * Wrapper around ata_exec_internal_sg() which takes simple |
| 1536 | * buffer instead of sg list. |
| 1537 | * |
| 1538 | * LOCKING: |
| 1539 | * None. Should be called with kernel context, might sleep. |
| 1540 | * |
| 1541 | * RETURNS: |
| 1542 | * Zero on success, AC_ERR_* mask on failure |
| 1543 | */ |
| 1544 | unsigned ata_exec_internal(struct ata_device *dev, |
| 1545 | struct ata_taskfile *tf, const u8 *cdb, |
| 1546 | int dma_dir, void *buf, unsigned int buflen) |
| 1547 | { |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1548 | struct scatterlist *psg = NULL, sg; |
| 1549 | unsigned int n_elem = 0; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1550 | |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1551 | if (dma_dir != DMA_NONE) { |
| 1552 | WARN_ON(!buf); |
| 1553 | sg_init_one(&sg, buf, buflen); |
| 1554 | psg = &sg; |
| 1555 | n_elem++; |
| 1556 | } |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1557 | |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1558 | return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem); |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | /** |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1562 | * ata_do_simple_cmd - execute simple internal command |
| 1563 | * @dev: Device to which the command is sent |
| 1564 | * @cmd: Opcode to execute |
| 1565 | * |
| 1566 | * Execute a 'simple' command, that only consists of the opcode |
| 1567 | * 'cmd' itself, without filling any other registers |
| 1568 | * |
| 1569 | * LOCKING: |
| 1570 | * Kernel thread context (may sleep). |
| 1571 | * |
| 1572 | * RETURNS: |
| 1573 | * Zero on success, AC_ERR_* mask on failure |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1574 | */ |
Tejun Heo | 77b08fb | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1575 | unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd) |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1576 | { |
| 1577 | struct ata_taskfile tf; |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1578 | |
| 1579 | ata_tf_init(dev, &tf); |
| 1580 | |
| 1581 | tf.command = cmd; |
| 1582 | tf.flags |= ATA_TFLAG_DEVICE; |
| 1583 | tf.protocol = ATA_PROT_NODATA; |
| 1584 | |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1585 | return ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1586 | } |
| 1587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | /** |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1589 | * ata_pio_need_iordy - check if iordy needed |
| 1590 | * @adev: ATA device |
| 1591 | * |
| 1592 | * Check if the current speed of the device requires IORDY. Used |
| 1593 | * by various controllers for chip configuration. |
| 1594 | */ |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1595 | |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1596 | unsigned int ata_pio_need_iordy(const struct ata_device *adev) |
| 1597 | { |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1598 | /* Controller doesn't support IORDY. Probably a pointless check |
| 1599 | as the caller should know this */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1600 | if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1601 | return 0; |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1602 | /* PIO3 and higher it is mandatory */ |
| 1603 | if (adev->pio_mode > XFER_PIO_2) |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1604 | return 1; |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1605 | /* We turn it on when possible */ |
| 1606 | if (ata_id_has_iordy(adev->id)) |
| 1607 | return 1; |
| 1608 | return 0; |
| 1609 | } |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 1610 | |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1611 | /** |
| 1612 | * ata_pio_mask_no_iordy - Return the non IORDY mask |
| 1613 | * @adev: ATA device |
| 1614 | * |
| 1615 | * Compute the highest mode possible if we are not using iordy. Return |
| 1616 | * -1 if no iordy mode is available. |
| 1617 | */ |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1618 | |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1619 | static u32 ata_pio_mask_no_iordy(const struct ata_device *adev) |
| 1620 | { |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1621 | /* If we have no drive specific rule, then PIO 2 is non IORDY */ |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1622 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1623 | u16 pio = adev->id[ATA_ID_EIDE_PIO]; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1624 | /* Is the speed faster than the drive allows non IORDY ? */ |
| 1625 | if (pio) { |
| 1626 | /* This is cycle times not frequency - watch the logic! */ |
| 1627 | if (pio > 240) /* PIO2 is 240nS per cycle */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1628 | return 3 << ATA_SHIFT_PIO; |
| 1629 | return 7 << ATA_SHIFT_PIO; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1630 | } |
| 1631 | } |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1632 | return 3 << ATA_SHIFT_PIO; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | /** |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1636 | * ata_dev_read_id - Read ID data from the specified device |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1637 | * @dev: target device |
| 1638 | * @p_class: pointer to class of the target device (may be changed) |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1639 | * @flags: ATA_READID_* flags |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 1640 | * @id: buffer to read IDENTIFY data into |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1641 | * |
| 1642 | * Read ID data from the specified device. ATA_CMD_ID_ATA is |
| 1643 | * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI |
Tejun Heo | aec5c3c | 2006-03-25 01:33:34 +0900 | [diff] [blame] | 1644 | * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS |
| 1645 | * for pre-ATA4 drives. |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1646 | * |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1647 | * FIXME: ATA_CMD_ID_ATA is optional for early drives and right |
| 1648 | * now we abort if we hit that case. |
| 1649 | * |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1650 | * LOCKING: |
| 1651 | * Kernel thread context (may sleep) |
| 1652 | * |
| 1653 | * RETURNS: |
| 1654 | * 0 on success, -errno otherwise. |
| 1655 | */ |
Tejun Heo | a9beec9 | 2006-05-31 18:27:44 +0900 | [diff] [blame] | 1656 | int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class, |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1657 | unsigned int flags, u16 *id) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1658 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1659 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1660 | unsigned int class = *p_class; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1661 | struct ata_taskfile tf; |
| 1662 | unsigned int err_mask = 0; |
| 1663 | const char *reason; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1664 | int may_fallback = 1, tried_spinup = 0; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1665 | int rc; |
| 1666 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1667 | if (ata_msg_ctl(ap)) |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 1668 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1669 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1670 | ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */ |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1671 | retry: |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1672 | ata_tf_init(dev, &tf); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1673 | |
| 1674 | switch (class) { |
| 1675 | case ATA_DEV_ATA: |
| 1676 | tf.command = ATA_CMD_ID_ATA; |
| 1677 | break; |
| 1678 | case ATA_DEV_ATAPI: |
| 1679 | tf.command = ATA_CMD_ID_ATAPI; |
| 1680 | break; |
| 1681 | default: |
| 1682 | rc = -ENODEV; |
| 1683 | reason = "unsupported class"; |
| 1684 | goto err_out; |
| 1685 | } |
| 1686 | |
| 1687 | tf.protocol = ATA_PROT_PIO; |
Tejun Heo | 81afe89 | 2007-02-07 12:37:41 -0800 | [diff] [blame] | 1688 | |
| 1689 | /* Some devices choke if TF registers contain garbage. Make |
| 1690 | * sure those are properly initialized. |
| 1691 | */ |
| 1692 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 1693 | |
| 1694 | /* Device presence detection is unreliable on some |
| 1695 | * controllers. Always poll IDENTIFY if available. |
| 1696 | */ |
| 1697 | tf.flags |= ATA_TFLAG_POLLING; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1698 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1699 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1700 | id, sizeof(id[0]) * ATA_ID_WORDS); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1701 | if (err_mask) { |
Tejun Heo | 800b399 | 2006-12-03 21:34:13 +0900 | [diff] [blame] | 1702 | if (err_mask & AC_ERR_NODEV_HINT) { |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1703 | DPRINTK("ata%u.%d: NODEV after polling detection\n", |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 1704 | ap->print_id, dev->devno); |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1705 | return -ENOENT; |
| 1706 | } |
| 1707 | |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1708 | /* Device or controller might have reported the wrong |
| 1709 | * device class. Give a shot at the other IDENTIFY if |
| 1710 | * the current one is aborted by the device. |
| 1711 | */ |
| 1712 | if (may_fallback && |
| 1713 | (err_mask == AC_ERR_DEV) && (tf.feature & ATA_ABORTED)) { |
| 1714 | may_fallback = 0; |
| 1715 | |
| 1716 | if (class == ATA_DEV_ATA) |
| 1717 | class = ATA_DEV_ATAPI; |
| 1718 | else |
| 1719 | class = ATA_DEV_ATA; |
| 1720 | goto retry; |
| 1721 | } |
| 1722 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1723 | rc = -EIO; |
| 1724 | reason = "I/O error"; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1725 | goto err_out; |
| 1726 | } |
| 1727 | |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1728 | /* Falling back doesn't make sense if ID data was read |
| 1729 | * successfully at least once. |
| 1730 | */ |
| 1731 | may_fallback = 0; |
| 1732 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1733 | swap_buf_le16(id, ATA_ID_WORDS); |
| 1734 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1735 | /* sanity check */ |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 1736 | rc = -EINVAL; |
Alan Cox | 6070068 | 2007-06-07 16:13:55 +0100 | [diff] [blame] | 1737 | reason = "device reports invalid type"; |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 1738 | |
| 1739 | if (class == ATA_DEV_ATA) { |
| 1740 | if (!ata_id_is_ata(id) && !ata_id_is_cfa(id)) |
| 1741 | goto err_out; |
| 1742 | } else { |
| 1743 | if (ata_id_is_ata(id)) |
| 1744 | goto err_out; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1745 | } |
| 1746 | |
Mark Lord | 169439c | 2007-04-17 18:26:07 -0400 | [diff] [blame] | 1747 | if (!tried_spinup && (id[2] == 0x37c8 || id[2] == 0x738c)) { |
| 1748 | tried_spinup = 1; |
| 1749 | /* |
| 1750 | * Drive powered-up in standby mode, and requires a specific |
| 1751 | * SET_FEATURES spin-up subcommand before it will accept |
| 1752 | * anything other than the original IDENTIFY command. |
| 1753 | */ |
| 1754 | ata_tf_init(dev, &tf); |
| 1755 | tf.command = ATA_CMD_SET_FEATURES; |
| 1756 | tf.feature = SETFEATURES_SPINUP; |
| 1757 | tf.protocol = ATA_PROT_NODATA; |
| 1758 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 1759 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
Ryan Power | fb0582f9 | 2007-08-10 13:59:35 -0700 | [diff] [blame] | 1760 | if (err_mask && id[2] != 0x738c) { |
Mark Lord | 169439c | 2007-04-17 18:26:07 -0400 | [diff] [blame] | 1761 | rc = -EIO; |
| 1762 | reason = "SPINUP failed"; |
| 1763 | goto err_out; |
| 1764 | } |
| 1765 | /* |
| 1766 | * If the drive initially returned incomplete IDENTIFY info, |
| 1767 | * we now must reissue the IDENTIFY command. |
| 1768 | */ |
| 1769 | if (id[2] == 0x37c8) |
| 1770 | goto retry; |
| 1771 | } |
| 1772 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1773 | if ((flags & ATA_READID_POSTRESET) && class == ATA_DEV_ATA) { |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1774 | /* |
| 1775 | * The exact sequence expected by certain pre-ATA4 drives is: |
| 1776 | * SRST RESET |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1777 | * IDENTIFY (optional in early ATA) |
| 1778 | * INITIALIZE DEVICE PARAMETERS (later IDE and ATA) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1779 | * anything else.. |
| 1780 | * Some drives were very specific about that exact sequence. |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1781 | * |
| 1782 | * Note that ATA4 says lba is mandatory so the second check |
| 1783 | * shoud never trigger. |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1784 | */ |
| 1785 | if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) { |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1786 | err_mask = ata_dev_init_params(dev, id[3], id[6]); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1787 | if (err_mask) { |
| 1788 | rc = -EIO; |
| 1789 | reason = "INIT_DEV_PARAMS failed"; |
| 1790 | goto err_out; |
| 1791 | } |
| 1792 | |
| 1793 | /* current CHS translation info (id[53-58]) might be |
| 1794 | * changed. reread the identify device info. |
| 1795 | */ |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1796 | flags &= ~ATA_READID_POSTRESET; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1797 | goto retry; |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | *p_class = class; |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 1802 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1803 | return 0; |
| 1804 | |
| 1805 | err_out: |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1806 | if (ata_msg_warn(ap)) |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1807 | ata_dev_printk(dev, KERN_WARNING, "failed to IDENTIFY " |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1808 | "(%s, err_mask=0x%x)\n", reason, err_mask); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1809 | return rc; |
| 1810 | } |
| 1811 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1812 | static inline u8 ata_dev_knobble(struct ata_device *dev) |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1813 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1814 | struct ata_port *ap = dev->link->ap; |
| 1815 | return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1816 | } |
| 1817 | |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 1818 | static void ata_dev_config_ncq(struct ata_device *dev, |
| 1819 | char *desc, size_t desc_sz) |
| 1820 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1821 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 1822 | int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); |
| 1823 | |
| 1824 | if (!ata_id_has_ncq(dev->id)) { |
| 1825 | desc[0] = '\0'; |
| 1826 | return; |
| 1827 | } |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 1828 | if (dev->horkage & ATA_HORKAGE_NONCQ) { |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 1829 | snprintf(desc, desc_sz, "NCQ (not used)"); |
| 1830 | return; |
| 1831 | } |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 1832 | if (ap->flags & ATA_FLAG_NCQ) { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 1833 | hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 1834 | dev->flags |= ATA_DFLAG_NCQ; |
| 1835 | } |
| 1836 | |
| 1837 | if (hdepth >= ddepth) |
| 1838 | snprintf(desc, desc_sz, "NCQ (depth %d)", ddepth); |
| 1839 | else |
| 1840 | snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth); |
| 1841 | } |
| 1842 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1843 | /** |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1844 | * ata_dev_configure - Configure the specified ATA/ATAPI device |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1845 | * @dev: Target device to configure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | * |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1847 | * Configure @dev according to @dev->id. Generic and low-level |
| 1848 | * driver specific fixups are also applied. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | * |
| 1850 | * LOCKING: |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1851 | * Kernel thread context (may sleep) |
| 1852 | * |
| 1853 | * RETURNS: |
| 1854 | * 0 on success, -errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | */ |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 1856 | int ata_dev_configure(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1858 | struct ata_port *ap = dev->link->ap; |
| 1859 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1860 | int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1861 | const u16 *id = dev->id; |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1862 | unsigned int xfer_mask; |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1863 | char revbuf[7]; /* XYZ-99\0 */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1864 | char fwrevbuf[ATA_ID_FW_REV_LEN+1]; |
| 1865 | char modelbuf[ATA_ID_PROD_LEN+1]; |
Brian King | e6d902a | 2006-06-28 08:30:31 -0500 | [diff] [blame] | 1866 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1868 | if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 1869 | ata_dev_printk(dev, KERN_INFO, "%s: ENTER/EXIT -- nodev\n", |
| 1870 | __FUNCTION__); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1871 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1874 | if (ata_msg_probe(ap)) |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 1875 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 1877 | /* set horkage */ |
| 1878 | dev->horkage |= ata_dev_blacklisted(dev); |
| 1879 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 1880 | /* let ACPI work its magic */ |
| 1881 | rc = ata_acpi_on_devcfg(dev); |
| 1882 | if (rc) |
| 1883 | return rc; |
Kristen Carlson Accardi | 08573a8 | 2006-11-10 16:14:47 -0800 | [diff] [blame] | 1884 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1885 | /* massage HPA, do it early as it might change IDENTIFY data */ |
| 1886 | rc = ata_hpa_resize(dev); |
| 1887 | if (rc) |
| 1888 | return rc; |
| 1889 | |
Tejun Heo | c39f5eb | 2006-03-13 19:51:19 +0900 | [diff] [blame] | 1890 | /* print device capabilities */ |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1891 | if (ata_msg_probe(ap)) |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1892 | ata_dev_printk(dev, KERN_DEBUG, |
| 1893 | "%s: cfg 49:%04x 82:%04x 83:%04x 84:%04x " |
| 1894 | "85:%04x 86:%04x 87:%04x 88:%04x\n", |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1895 | __FUNCTION__, |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 1896 | id[49], id[82], id[83], id[84], |
| 1897 | id[85], id[86], id[87], id[88]); |
Tejun Heo | c39f5eb | 2006-03-13 19:51:19 +0900 | [diff] [blame] | 1898 | |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1899 | /* initialize to-be-configured parameters */ |
Tejun Heo | ea1dd4e | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1900 | dev->flags &= ~ATA_DFLAG_CFG_MASK; |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1901 | dev->max_sectors = 0; |
| 1902 | dev->cdb_len = 0; |
| 1903 | dev->n_sectors = 0; |
| 1904 | dev->cylinders = 0; |
| 1905 | dev->heads = 0; |
| 1906 | dev->sectors = 0; |
| 1907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | /* |
| 1909 | * common ATA, ATAPI feature tests |
| 1910 | */ |
| 1911 | |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1912 | /* find max transfer mode; for printk only */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1913 | xfer_mask = ata_id_xfermask(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1915 | if (ata_msg_probe(ap)) |
| 1916 | ata_dump_id(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | |
Albert Lee | ef143d5 | 2007-06-05 13:01:33 +0800 | [diff] [blame] | 1918 | /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ |
| 1919 | ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, |
| 1920 | sizeof(fwrevbuf)); |
| 1921 | |
| 1922 | ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, |
| 1923 | sizeof(modelbuf)); |
| 1924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | /* ATA-specific feature tests */ |
| 1926 | if (dev->class == ATA_DEV_ATA) { |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1927 | if (ata_id_is_cfa(id)) { |
| 1928 | if (id[162] & 1) /* CPRM may make this media unusable */ |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 1929 | ata_dev_printk(dev, KERN_WARNING, |
| 1930 | "supports DRM functions and may " |
| 1931 | "not be fully accessable.\n"); |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1932 | snprintf(revbuf, 7, "CFA"); |
| 1933 | } |
| 1934 | else |
| 1935 | snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); |
| 1936 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1937 | dev->n_sectors = ata_id_n_sectors(id); |
Tejun Heo | 2940740 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1938 | |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1939 | if (dev->id[59] & 0x100) |
| 1940 | dev->multi_count = dev->id[59] & 0xff; |
| 1941 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1942 | if (ata_id_has_lba(id)) { |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1943 | const char *lba_desc; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 1944 | char ncq_desc[20]; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1945 | |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1946 | lba_desc = "LBA"; |
| 1947 | dev->flags |= ATA_DFLAG_LBA; |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1948 | if (ata_id_has_lba48(id)) { |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1949 | dev->flags |= ATA_DFLAG_LBA48; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1950 | lba_desc = "LBA48"; |
Tejun Heo | 6fc49ad | 2006-11-11 20:10:45 +0900 | [diff] [blame] | 1951 | |
| 1952 | if (dev->n_sectors >= (1UL << 28) && |
| 1953 | ata_id_has_flush_ext(id)) |
| 1954 | dev->flags |= ATA_DFLAG_FLUSH_EXT; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1955 | } |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1956 | |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 1957 | /* config NCQ */ |
| 1958 | ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); |
| 1959 | |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1960 | /* print device info to dmesg */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1961 | if (ata_msg_drv(ap) && print_info) { |
| 1962 | ata_dev_printk(dev, KERN_INFO, |
| 1963 | "%s: %s, %s, max %s\n", |
| 1964 | revbuf, modelbuf, fwrevbuf, |
| 1965 | ata_mode_string(xfer_mask)); |
| 1966 | ata_dev_printk(dev, KERN_INFO, |
| 1967 | "%Lu sectors, multi %u: %s %s\n", |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 1968 | (unsigned long long)dev->n_sectors, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1969 | dev->multi_count, lba_desc, ncq_desc); |
| 1970 | } |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1971 | } else { |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1972 | /* CHS */ |
| 1973 | |
| 1974 | /* Default translation */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1975 | dev->cylinders = id[1]; |
| 1976 | dev->heads = id[3]; |
| 1977 | dev->sectors = id[6]; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1978 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1979 | if (ata_id_current_chs_valid(id)) { |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1980 | /* Current CHS translation is valid. */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 1981 | dev->cylinders = id[54]; |
| 1982 | dev->heads = id[55]; |
| 1983 | dev->sectors = id[56]; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | /* print device info to dmesg */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1987 | if (ata_msg_drv(ap) && print_info) { |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1988 | ata_dev_printk(dev, KERN_INFO, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1989 | "%s: %s, %s, max %s\n", |
| 1990 | revbuf, modelbuf, fwrevbuf, |
| 1991 | ata_mode_string(xfer_mask)); |
Jeff Garzik | a84471f | 2007-02-26 05:51:33 -0500 | [diff] [blame] | 1992 | ata_dev_printk(dev, KERN_INFO, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 1993 | "%Lu sectors, multi %u, CHS %u/%u/%u\n", |
| 1994 | (unsigned long long)dev->n_sectors, |
| 1995 | dev->multi_count, dev->cylinders, |
| 1996 | dev->heads, dev->sectors); |
| 1997 | } |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 1998 | } |
| 1999 | |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 2000 | dev->cdb_len = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | /* ATAPI-specific feature tests */ |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 2004 | else if (dev->class == ATA_DEV_ATAPI) { |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2005 | char *cdb_intr_string = ""; |
| 2006 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2007 | rc = atapi_cdb_len(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | if ((rc < 12) || (rc > ATAPI_CDB_LEN)) { |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2009 | if (ata_msg_warn(ap)) |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2010 | ata_dev_printk(dev, KERN_WARNING, |
| 2011 | "unsupported CDB len\n"); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2012 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | goto err_out_nosup; |
| 2014 | } |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 2015 | dev->cdb_len = (unsigned int) rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2017 | /* |
| 2018 | * check to see if this ATAPI device supports |
| 2019 | * Asynchronous Notification |
| 2020 | */ |
| 2021 | if ((ap->flags & ATA_FLAG_AN) && ata_id_has_AN(id)) { |
| 2022 | int err; |
| 2023 | /* issue SET feature command to turn this on */ |
| 2024 | err = ata_dev_set_AN(dev, SETFEATURES_SATA_ENABLE); |
| 2025 | if (err) |
| 2026 | ata_dev_printk(dev, KERN_ERR, |
| 2027 | "unable to set AN, err %x\n", |
| 2028 | err); |
| 2029 | else |
| 2030 | dev->flags |= ATA_DFLAG_AN; |
| 2031 | } |
| 2032 | |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2033 | if (ata_id_cdb_intr(dev->id)) { |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 2034 | dev->flags |= ATA_DFLAG_CDB_INTR; |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2035 | cdb_intr_string = ", CDB intr"; |
| 2036 | } |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 2037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | /* print device info to dmesg */ |
Borislav Petkov | 5afc814 | 2006-06-27 14:51:25 +0200 | [diff] [blame] | 2039 | if (ata_msg_drv(ap) && print_info) |
Albert Lee | ef143d5 | 2007-06-05 13:01:33 +0800 | [diff] [blame] | 2040 | ata_dev_printk(dev, KERN_INFO, |
| 2041 | "ATAPI: %s, %s, max %s%s\n", |
| 2042 | modelbuf, fwrevbuf, |
Tejun Heo | 12436c3 | 2006-05-15 20:59:15 +0900 | [diff] [blame] | 2043 | ata_mode_string(xfer_mask), |
| 2044 | cdb_intr_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Tejun Heo | 914ed35 | 2006-11-01 18:39:55 +0900 | [diff] [blame] | 2047 | /* determine max_sectors */ |
| 2048 | dev->max_sectors = ATA_MAX_SECTORS; |
| 2049 | if (dev->flags & ATA_DFLAG_LBA48) |
| 2050 | dev->max_sectors = ATA_MAX_SECTORS_LBA48; |
| 2051 | |
Alan Cox | 9359085 | 2006-09-12 16:55:12 +0100 | [diff] [blame] | 2052 | if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { |
| 2053 | /* Let the user know. We don't want to disallow opens for |
| 2054 | rescue purposes, or in case the vendor is just a blithering |
| 2055 | idiot */ |
| 2056 | if (print_info) { |
| 2057 | ata_dev_printk(dev, KERN_WARNING, |
| 2058 | "Drive reports diagnostics failure. This may indicate a drive\n"); |
| 2059 | ata_dev_printk(dev, KERN_WARNING, |
| 2060 | "fault or invalid emulation. Contact drive vendor for information.\n"); |
| 2061 | } |
| 2062 | } |
| 2063 | |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2064 | /* limit bridge transfers to udma5, 200 sectors */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2065 | if (ata_dev_knobble(dev)) { |
Borislav Petkov | 5afc814 | 2006-06-27 14:51:25 +0200 | [diff] [blame] | 2066 | if (ata_msg_drv(ap) && print_info) |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2067 | ata_dev_printk(dev, KERN_INFO, |
| 2068 | "applying bridge limits\n"); |
Tejun Heo | 5a52913 | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 2069 | dev->udma_mask &= ATA_UDMA5; |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2070 | dev->max_sectors = ATA_MAX_SECTORS; |
| 2071 | } |
| 2072 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2073 | if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) |
Tejun Heo | 03ec52d | 2007-04-12 13:38:11 +0900 | [diff] [blame] | 2074 | dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, |
| 2075 | dev->max_sectors); |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 2076 | |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2077 | if (ap->ops->dev_config) |
Alan | cd0d3bb | 2007-03-02 00:56:15 +0000 | [diff] [blame] | 2078 | ap->ops->dev_config(dev); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2079 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2080 | if (ata_msg_probe(ap)) |
| 2081 | ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n", |
| 2082 | __FUNCTION__, ata_chk_status(ap)); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2083 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | |
| 2085 | err_out_nosup: |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2086 | if (ata_msg_probe(ap)) |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2087 | ata_dev_printk(dev, KERN_DEBUG, |
| 2088 | "%s: EXIT, err\n", __FUNCTION__); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2089 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | /** |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2093 | * ata_cable_40wire - return 40 wire cable type |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2094 | * @ap: port |
| 2095 | * |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2096 | * Helper method for drivers which want to hardwire 40 wire cable |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2097 | * detection. |
| 2098 | */ |
| 2099 | |
| 2100 | int ata_cable_40wire(struct ata_port *ap) |
| 2101 | { |
| 2102 | return ATA_CBL_PATA40; |
| 2103 | } |
| 2104 | |
| 2105 | /** |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2106 | * ata_cable_80wire - return 80 wire cable type |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2107 | * @ap: port |
| 2108 | * |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2109 | * Helper method for drivers which want to hardwire 80 wire cable |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2110 | * detection. |
| 2111 | */ |
| 2112 | |
| 2113 | int ata_cable_80wire(struct ata_port *ap) |
| 2114 | { |
| 2115 | return ATA_CBL_PATA80; |
| 2116 | } |
| 2117 | |
| 2118 | /** |
| 2119 | * ata_cable_unknown - return unknown PATA cable. |
| 2120 | * @ap: port |
| 2121 | * |
| 2122 | * Helper method for drivers which have no PATA cable detection. |
| 2123 | */ |
| 2124 | |
| 2125 | int ata_cable_unknown(struct ata_port *ap) |
| 2126 | { |
| 2127 | return ATA_CBL_PATA_UNK; |
| 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * ata_cable_sata - return SATA cable type |
| 2132 | * @ap: port |
| 2133 | * |
| 2134 | * Helper method for drivers which have SATA cables |
| 2135 | */ |
| 2136 | |
| 2137 | int ata_cable_sata(struct ata_port *ap) |
| 2138 | { |
| 2139 | return ATA_CBL_SATA; |
| 2140 | } |
| 2141 | |
| 2142 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | * ata_bus_probe - Reset and probe ATA bus |
| 2144 | * @ap: Bus to probe |
| 2145 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2146 | * Master ATA bus probing function. Initiates a hardware-dependent |
| 2147 | * bus reset, then attempts to identify any devices found on |
| 2148 | * the bus. |
| 2149 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2151 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | * |
| 2153 | * RETURNS: |
Tejun Heo | 96072e6 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2154 | * Zero on success, negative errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | */ |
| 2156 | |
Brian King | 8028916 | 2006-08-07 14:27:31 -0500 | [diff] [blame] | 2157 | int ata_bus_probe(struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | { |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2159 | unsigned int classes[ATA_MAX_DEVICES]; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2160 | int tries[ATA_MAX_DEVICES]; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2161 | int rc; |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2162 | struct ata_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2164 | ata_port_probe(ap); |
| 2165 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2166 | ata_link_for_each_dev(dev, &ap->link) |
| 2167 | tries[dev->devno] = ATA_PROBE_MAX_TRIES; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2168 | |
| 2169 | retry: |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2170 | /* reset and determine device classes */ |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2171 | ap->ops->phy_reset(ap); |
Tejun Heo | 2061a47 | 2006-03-12 00:57:39 +0900 | [diff] [blame] | 2172 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2173 | ata_link_for_each_dev(dev, &ap->link) { |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2174 | if (!(ap->flags & ATA_FLAG_DISABLED) && |
| 2175 | dev->class != ATA_DEV_UNKNOWN) |
| 2176 | classes[dev->devno] = dev->class; |
| 2177 | else |
| 2178 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2179 | |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2180 | dev->class = ATA_DEV_UNKNOWN; |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2183 | ata_port_probe(ap); |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2184 | |
Alan Cox | b6079ca | 2006-05-22 16:52:06 +0100 | [diff] [blame] | 2185 | /* after the reset the device state is PIO 0 and the controller |
| 2186 | state is undefined. Record the mode */ |
| 2187 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2188 | ata_link_for_each_dev(dev, &ap->link) |
| 2189 | dev->pio_mode = XFER_PIO_0; |
Alan Cox | b6079ca | 2006-05-22 16:52:06 +0100 | [diff] [blame] | 2190 | |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2191 | /* read IDENTIFY page and configure devices. We have to do the identify |
| 2192 | specific sequence bass-ackwards so that PDIAG- is released by |
| 2193 | the slave device */ |
| 2194 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2195 | ata_link_for_each_dev(dev, &ap->link) { |
| 2196 | if (tries[dev->devno]) |
| 2197 | dev->class = classes[dev->devno]; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2198 | |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2199 | if (!ata_dev_enabled(dev)) |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2200 | continue; |
| 2201 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2202 | rc = ata_dev_read_id(dev, &dev->class, ATA_READID_POSTRESET, |
| 2203 | dev->id); |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2204 | if (rc) |
| 2205 | goto fail; |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2206 | } |
| 2207 | |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2208 | /* Now ask for the cable type as PDIAG- should have been released */ |
| 2209 | if (ap->ops->cable_detect) |
| 2210 | ap->cbl = ap->ops->cable_detect(ap); |
| 2211 | |
Alan Cox | 614fe29 | 2007-08-22 23:22:45 +0100 | [diff] [blame] | 2212 | /* We may have SATA bridge glue hiding here irrespective of the |
| 2213 | reported cable types and sensed types */ |
| 2214 | ata_link_for_each_dev(dev, &ap->link) { |
| 2215 | if (!ata_dev_enabled(dev)) |
| 2216 | continue; |
| 2217 | /* SATA drives indicate we have a bridge. We don't know which |
| 2218 | end of the link the bridge is which is a problem */ |
| 2219 | if (ata_id_is_sata(dev->id)) |
| 2220 | ap->cbl = ATA_CBL_SATA; |
| 2221 | } |
| 2222 | |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2223 | /* After the identify sequence we can now set up the devices. We do |
| 2224 | this in the normal order so that the user doesn't get confused */ |
| 2225 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2226 | ata_link_for_each_dev(dev, &ap->link) { |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2227 | if (!ata_dev_enabled(dev)) |
| 2228 | continue; |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2229 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2230 | ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO; |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 2231 | rc = ata_dev_configure(dev); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2232 | ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2233 | if (rc) |
| 2234 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2237 | /* configure transfer mode */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2238 | rc = ata_set_mode(&ap->link, &dev); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2239 | if (rc) |
Tejun Heo | 51713d3 | 2006-04-11 22:26:29 +0900 | [diff] [blame] | 2240 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2242 | ata_link_for_each_dev(dev, &ap->link) |
| 2243 | if (ata_dev_enabled(dev)) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2244 | return 0; |
Alan Cox | e35a9e0 | 2006-03-27 18:46:37 +0100 | [diff] [blame] | 2245 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2246 | /* no device present, disable port */ |
| 2247 | ata_port_disable(ap); |
Tejun Heo | 96072e6 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2248 | return -ENODEV; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2249 | |
| 2250 | fail: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2251 | tries[dev->devno]--; |
| 2252 | |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2253 | switch (rc) { |
| 2254 | case -EINVAL: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2255 | /* eeek, something went very wrong, give up */ |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2256 | tries[dev->devno] = 0; |
| 2257 | break; |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2258 | |
| 2259 | case -ENODEV: |
| 2260 | /* give it just one more chance */ |
| 2261 | tries[dev->devno] = min(tries[dev->devno], 1); |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2262 | case -EIO: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2263 | if (tries[dev->devno] == 1) { |
| 2264 | /* This is the last chance, better to slow |
| 2265 | * down than lose it. |
| 2266 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2267 | sata_down_spd_limit(&ap->link); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2268 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); |
| 2269 | } |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2270 | } |
| 2271 | |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2272 | if (!tries[dev->devno]) |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2273 | ata_dev_disable(dev); |
Tejun Heo | ec57375 | 2006-04-11 22:26:29 +0900 | [diff] [blame] | 2274 | |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2275 | goto retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2279 | * ata_port_probe - Mark port as enabled |
| 2280 | * @ap: Port for which we indicate enablement |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2281 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2282 | * Modify @ap data structure such that the system |
| 2283 | * thinks that the entire port is enabled. |
| 2284 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2285 | * LOCKING: host lock, or some other form of |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2286 | * serialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | */ |
| 2288 | |
| 2289 | void ata_port_probe(struct ata_port *ap) |
| 2290 | { |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2291 | ap->flags &= ~ATA_FLAG_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /** |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2295 | * sata_print_link_status - Print SATA link status |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2296 | * @link: SATA link to printk link status about |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2297 | * |
| 2298 | * This function prints link speed and status of a SATA link. |
| 2299 | * |
| 2300 | * LOCKING: |
| 2301 | * None. |
| 2302 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2303 | void sata_print_link_status(struct ata_link *link) |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2304 | { |
Tejun Heo | 6d5f973 | 2006-04-03 00:09:41 +0900 | [diff] [blame] | 2305 | u32 sstatus, scontrol, tmp; |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2306 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2307 | if (sata_scr_read(link, SCR_STATUS, &sstatus)) |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2308 | return; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2309 | sata_scr_read(link, SCR_CONTROL, &scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2310 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2311 | if (ata_link_online(link)) { |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2312 | tmp = (sstatus >> 4) & 0xf; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2313 | ata_link_printk(link, KERN_INFO, |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2314 | "SATA link up %s (SStatus %X SControl %X)\n", |
| 2315 | sata_spd_string(tmp), sstatus, scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2316 | } else { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2317 | ata_link_printk(link, KERN_INFO, |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2318 | "SATA link down (SStatus %X SControl %X)\n", |
| 2319 | sstatus, scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2324 | * __sata_phy_reset - Wake/reset a low-level SATA PHY |
| 2325 | * @ap: SATA port associated with target SATA PHY. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2327 | * This function issues commands to standard SATA Sxxx |
| 2328 | * PHY registers, to wake up the phy (and device), and |
| 2329 | * clear any reset condition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | * |
| 2331 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2332 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | * |
| 2334 | */ |
| 2335 | void __sata_phy_reset(struct ata_port *ap) |
| 2336 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2337 | struct ata_link *link = &ap->link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | unsigned long timeout = jiffies + (HZ * 5); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2339 | u32 sstatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
| 2341 | if (ap->flags & ATA_FLAG_SATA_RESET) { |
Brett Russ | cdcca89 | 2005-03-28 15:10:27 -0500 | [diff] [blame] | 2342 | /* issue phy wake/reset */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2343 | sata_scr_write_flush(link, SCR_CONTROL, 0x301); |
Tejun Heo | 62ba284 | 2005-06-26 23:27:19 +0900 | [diff] [blame] | 2344 | /* Couldn't find anything in SATA I/II specs, but |
| 2345 | * AHCI-1.1 10.4.2 says at least 1 ms. */ |
| 2346 | mdelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | } |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2348 | /* phy wake/clear reset */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2349 | sata_scr_write_flush(link, SCR_CONTROL, 0x300); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | |
| 2351 | /* wait for phy to become ready, if necessary */ |
| 2352 | do { |
| 2353 | msleep(200); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2354 | sata_scr_read(link, SCR_STATUS, &sstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | if ((sstatus & 0xf) != 1) |
| 2356 | break; |
| 2357 | } while (time_before(jiffies, timeout)); |
| 2358 | |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2359 | /* print link status */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2360 | sata_print_link_status(link); |
Jeff Garzik | 656563e | 2005-11-20 03:36:45 -0500 | [diff] [blame] | 2361 | |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2362 | /* TODO: phy layer with polling, timeouts, etc. */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2363 | if (!ata_link_offline(link)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | ata_port_probe(ap); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2365 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | ata_port_disable(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2368 | if (ap->flags & ATA_FLAG_DISABLED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | return; |
| 2370 | |
| 2371 | if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { |
| 2372 | ata_port_disable(ap); |
| 2373 | return; |
| 2374 | } |
| 2375 | |
| 2376 | ap->cbl = ATA_CBL_SATA; |
| 2377 | } |
| 2378 | |
| 2379 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2380 | * sata_phy_reset - Reset SATA bus. |
| 2381 | * @ap: SATA port associated with target SATA PHY. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2383 | * This function resets the SATA bus, and then probes |
| 2384 | * the bus for devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | * |
| 2386 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2387 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | * |
| 2389 | */ |
| 2390 | void sata_phy_reset(struct ata_port *ap) |
| 2391 | { |
| 2392 | __sata_phy_reset(ap); |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2393 | if (ap->flags & ATA_FLAG_DISABLED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | return; |
| 2395 | ata_bus_reset(ap); |
| 2396 | } |
| 2397 | |
| 2398 | /** |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2399 | * ata_dev_pair - return other device on cable |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2400 | * @adev: device |
| 2401 | * |
| 2402 | * Obtain the other device on the same cable, or if none is |
| 2403 | * present NULL is returned |
| 2404 | */ |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2405 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2406 | struct ata_device *ata_dev_pair(struct ata_device *adev) |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2407 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2408 | struct ata_link *link = adev->link; |
| 2409 | struct ata_device *pair = &link->device[1 - adev->devno]; |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2410 | if (!ata_dev_enabled(pair)) |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2411 | return NULL; |
| 2412 | return pair; |
| 2413 | } |
| 2414 | |
| 2415 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2416 | * ata_port_disable - Disable port. |
| 2417 | * @ap: Port to be disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2419 | * Modify @ap data structure such that the system |
| 2420 | * thinks that the entire port is disabled, and should |
| 2421 | * never attempt to probe or communicate with devices |
| 2422 | * on this port. |
| 2423 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2424 | * LOCKING: host lock, or some other form of |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2425 | * serialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | */ |
| 2427 | |
| 2428 | void ata_port_disable(struct ata_port *ap) |
| 2429 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2430 | ap->link.device[0].class = ATA_DEV_NONE; |
| 2431 | ap->link.device[1].class = ATA_DEV_NONE; |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2432 | ap->flags |= ATA_FLAG_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2435 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2436 | * sata_down_spd_limit - adjust SATA spd limit downward |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2437 | * @link: Link to adjust SATA spd limit for |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2438 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2439 | * Adjust SATA spd limit of @link downward. Note that this |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2440 | * function only adjusts the limit. The change must be applied |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2441 | * using sata_set_spd(). |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2442 | * |
| 2443 | * LOCKING: |
| 2444 | * Inherited from caller. |
| 2445 | * |
| 2446 | * RETURNS: |
| 2447 | * 0 on success, negative errno on failure |
| 2448 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2449 | int sata_down_spd_limit(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2450 | { |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2451 | u32 sstatus, spd, mask; |
| 2452 | int rc, highbit; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2453 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2454 | if (!sata_scr_valid(link)) |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2455 | return -EOPNOTSUPP; |
| 2456 | |
| 2457 | /* If SCR can be read, use it to determine the current SPD. |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2458 | * If not, use cached value in link->sata_spd. |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2459 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2460 | rc = sata_scr_read(link, SCR_STATUS, &sstatus); |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2461 | if (rc == 0) |
| 2462 | spd = (sstatus >> 4) & 0xf; |
| 2463 | else |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2464 | spd = link->sata_spd; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2465 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2466 | mask = link->sata_spd_limit; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2467 | if (mask <= 1) |
| 2468 | return -EINVAL; |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2469 | |
| 2470 | /* unconditionally mask off the highest bit */ |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2471 | highbit = fls(mask) - 1; |
| 2472 | mask &= ~(1 << highbit); |
| 2473 | |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2474 | /* Mask off all speeds higher than or equal to the current |
| 2475 | * one. Force 1.5Gbps if current SPD is not available. |
| 2476 | */ |
| 2477 | if (spd > 1) |
| 2478 | mask &= (1 << (spd - 1)) - 1; |
| 2479 | else |
| 2480 | mask &= 1; |
| 2481 | |
| 2482 | /* were we already at the bottom? */ |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2483 | if (!mask) |
| 2484 | return -EINVAL; |
| 2485 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2486 | link->sata_spd_limit = mask; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2487 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2488 | ata_link_printk(link, KERN_WARNING, "limiting SATA link speed to %s\n", |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2489 | sata_spd_string(fls(mask))); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2490 | |
| 2491 | return 0; |
| 2492 | } |
| 2493 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2494 | static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2495 | { |
| 2496 | u32 spd, limit; |
| 2497 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2498 | if (link->sata_spd_limit == UINT_MAX) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2499 | limit = 0; |
| 2500 | else |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2501 | limit = fls(link->sata_spd_limit); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2502 | |
| 2503 | spd = (*scontrol >> 4) & 0xf; |
| 2504 | *scontrol = (*scontrol & ~0xf0) | ((limit & 0xf) << 4); |
| 2505 | |
| 2506 | return spd != limit; |
| 2507 | } |
| 2508 | |
| 2509 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2510 | * sata_set_spd_needed - is SATA spd configuration needed |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2511 | * @link: Link in question |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2512 | * |
| 2513 | * Test whether the spd limit in SControl matches |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2514 | * @link->sata_spd_limit. This function is used to determine |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2515 | * whether hardreset is necessary to apply SATA spd |
| 2516 | * configuration. |
| 2517 | * |
| 2518 | * LOCKING: |
| 2519 | * Inherited from caller. |
| 2520 | * |
| 2521 | * RETURNS: |
| 2522 | * 1 if SATA spd configuration is needed, 0 otherwise. |
| 2523 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2524 | int sata_set_spd_needed(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2525 | { |
| 2526 | u32 scontrol; |
| 2527 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2528 | if (sata_scr_read(link, SCR_CONTROL, &scontrol)) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2529 | return 0; |
| 2530 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2531 | return __sata_set_spd_needed(link, &scontrol); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2535 | * sata_set_spd - set SATA spd according to spd limit |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2536 | * @link: Link to set SATA spd for |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2537 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2538 | * Set SATA spd of @link according to sata_spd_limit. |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2539 | * |
| 2540 | * LOCKING: |
| 2541 | * Inherited from caller. |
| 2542 | * |
| 2543 | * RETURNS: |
| 2544 | * 0 if spd doesn't need to be changed, 1 if spd has been |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2545 | * changed. Negative errno if SCR registers are inaccessible. |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2546 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2547 | int sata_set_spd(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2548 | { |
| 2549 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2550 | int rc; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2551 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2552 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2553 | return rc; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2554 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2555 | if (!__sata_set_spd_needed(link, &scontrol)) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2556 | return 0; |
| 2557 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2558 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2559 | return rc; |
| 2560 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2561 | return 1; |
| 2562 | } |
| 2563 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2564 | /* |
| 2565 | * This mode timing computation functionality is ported over from |
| 2566 | * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik |
| 2567 | */ |
| 2568 | /* |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2569 | * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2570 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2571 | * for UDMA6, which is currently supported only by Maxtor drives. |
| 2572 | * |
| 2573 | * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2574 | */ |
| 2575 | |
| 2576 | static const struct ata_timing ata_timing[] = { |
| 2577 | |
| 2578 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 }, |
| 2579 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 }, |
| 2580 | { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 }, |
| 2581 | { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 }, |
| 2582 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2583 | { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 80, 0 }, |
| 2584 | { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 100, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2585 | { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 }, |
| 2586 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, |
| 2587 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, |
| 2588 | |
| 2589 | /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2590 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2591 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, |
| 2592 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, |
| 2593 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2594 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2595 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, |
| 2596 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, |
| 2597 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, |
| 2598 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2599 | { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 80, 0 }, |
| 2600 | { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 100, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2601 | { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 }, |
| 2602 | { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 }, |
| 2603 | |
| 2604 | { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 }, |
| 2605 | { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 }, |
| 2606 | { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 }, |
| 2607 | |
| 2608 | /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */ |
| 2609 | |
| 2610 | { 0xFF } |
| 2611 | }; |
| 2612 | |
| 2613 | #define ENOUGH(v,unit) (((v)-1)/(unit)+1) |
| 2614 | #define EZ(v,unit) ((v)?ENOUGH(v,unit):0) |
| 2615 | |
| 2616 | static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT) |
| 2617 | { |
| 2618 | q->setup = EZ(t->setup * 1000, T); |
| 2619 | q->act8b = EZ(t->act8b * 1000, T); |
| 2620 | q->rec8b = EZ(t->rec8b * 1000, T); |
| 2621 | q->cyc8b = EZ(t->cyc8b * 1000, T); |
| 2622 | q->active = EZ(t->active * 1000, T); |
| 2623 | q->recover = EZ(t->recover * 1000, T); |
| 2624 | q->cycle = EZ(t->cycle * 1000, T); |
| 2625 | q->udma = EZ(t->udma * 1000, UT); |
| 2626 | } |
| 2627 | |
| 2628 | void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, |
| 2629 | struct ata_timing *m, unsigned int what) |
| 2630 | { |
| 2631 | if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup); |
| 2632 | if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b); |
| 2633 | if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b); |
| 2634 | if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b); |
| 2635 | if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active); |
| 2636 | if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover); |
| 2637 | if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle); |
| 2638 | if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma); |
| 2639 | } |
| 2640 | |
| 2641 | static const struct ata_timing* ata_timing_find_mode(unsigned short speed) |
| 2642 | { |
| 2643 | const struct ata_timing *t; |
| 2644 | |
| 2645 | for (t = ata_timing; t->mode != speed; t++) |
Alan Cox | 9119075 | 2005-10-26 12:17:46 -0400 | [diff] [blame] | 2646 | if (t->mode == 0xFF) |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2647 | return NULL; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2648 | return t; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2649 | } |
| 2650 | |
| 2651 | int ata_timing_compute(struct ata_device *adev, unsigned short speed, |
| 2652 | struct ata_timing *t, int T, int UT) |
| 2653 | { |
| 2654 | const struct ata_timing *s; |
| 2655 | struct ata_timing p; |
| 2656 | |
| 2657 | /* |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2658 | * Find the mode. |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 2659 | */ |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2660 | |
| 2661 | if (!(s = ata_timing_find_mode(speed))) |
| 2662 | return -EINVAL; |
| 2663 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 2664 | memcpy(t, s, sizeof(*s)); |
| 2665 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2666 | /* |
| 2667 | * If the drive is an EIDE drive, it can tell us it needs extended |
| 2668 | * PIO/MW_DMA cycle timing. |
| 2669 | */ |
| 2670 | |
| 2671 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ |
| 2672 | memset(&p, 0, sizeof(p)); |
| 2673 | if(speed >= XFER_PIO_0 && speed <= XFER_SW_DMA_0) { |
| 2674 | if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO]; |
| 2675 | else p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO_IORDY]; |
| 2676 | } else if(speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) { |
| 2677 | p.cycle = adev->id[ATA_ID_EIDE_DMA_MIN]; |
| 2678 | } |
| 2679 | ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); |
| 2680 | } |
| 2681 | |
| 2682 | /* |
| 2683 | * Convert the timing to bus clock counts. |
| 2684 | */ |
| 2685 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 2686 | ata_timing_quantize(t, t, T, UT); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2687 | |
| 2688 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 2689 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, |
| 2690 | * S.M.A.R.T * and some other commands. We have to ensure that the |
| 2691 | * DMA cycle timing is slower/equal than the fastest PIO timing. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2692 | */ |
| 2693 | |
Alan | fd3367a | 2006-12-07 12:41:18 +0000 | [diff] [blame] | 2694 | if (speed > XFER_PIO_6) { |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2695 | ata_timing_compute(adev, adev->pio_mode, &p, T, UT); |
| 2696 | ata_timing_merge(&p, t, t, ATA_TIMING_ALL); |
| 2697 | } |
| 2698 | |
| 2699 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 2700 | * Lengthen active & recovery time so that cycle time is correct. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2701 | */ |
| 2702 | |
| 2703 | if (t->act8b + t->rec8b < t->cyc8b) { |
| 2704 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; |
| 2705 | t->rec8b = t->cyc8b - t->act8b; |
| 2706 | } |
| 2707 | |
| 2708 | if (t->active + t->recover < t->cycle) { |
| 2709 | t->active += (t->cycle - (t->active + t->recover)) / 2; |
| 2710 | t->recover = t->cycle - t->active; |
| 2711 | } |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 2712 | |
Alan Cox | 4f701d1 | 2007-04-23 11:55:36 +0100 | [diff] [blame] | 2713 | /* In a few cases quantisation may produce enough errors to |
| 2714 | leave t->cycle too low for the sum of active and recovery |
| 2715 | if so we must correct this */ |
| 2716 | if (t->active + t->recover > t->cycle) |
| 2717 | t->cycle = t->active + t->recover; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2718 | |
| 2719 | return 0; |
| 2720 | } |
| 2721 | |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2722 | /** |
| 2723 | * ata_down_xfermask_limit - adjust dev xfer masks downward |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2724 | * @dev: Device to adjust xfer masks |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2725 | * @sel: ATA_DNXFER_* selector |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2726 | * |
| 2727 | * Adjust xfer masks of @dev downward. Note that this function |
| 2728 | * does not apply the change. Invoking ata_set_mode() afterwards |
| 2729 | * will apply the limit. |
| 2730 | * |
| 2731 | * LOCKING: |
| 2732 | * Inherited from caller. |
| 2733 | * |
| 2734 | * RETURNS: |
| 2735 | * 0 on success, negative errno on failure |
| 2736 | */ |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2737 | int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel) |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2738 | { |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2739 | char buf[32]; |
| 2740 | unsigned int orig_mask, xfer_mask; |
| 2741 | unsigned int pio_mask, mwdma_mask, udma_mask; |
| 2742 | int quiet, highbit; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2743 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2744 | quiet = !!(sel & ATA_DNXFER_QUIET); |
| 2745 | sel &= ~ATA_DNXFER_QUIET; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2746 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2747 | xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, |
| 2748 | dev->mwdma_mask, |
| 2749 | dev->udma_mask); |
| 2750 | ata_unpack_xfermask(xfer_mask, &pio_mask, &mwdma_mask, &udma_mask); |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2751 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2752 | switch (sel) { |
| 2753 | case ATA_DNXFER_PIO: |
| 2754 | highbit = fls(pio_mask) - 1; |
| 2755 | pio_mask &= ~(1 << highbit); |
| 2756 | break; |
| 2757 | |
| 2758 | case ATA_DNXFER_DMA: |
| 2759 | if (udma_mask) { |
| 2760 | highbit = fls(udma_mask) - 1; |
| 2761 | udma_mask &= ~(1 << highbit); |
| 2762 | if (!udma_mask) |
| 2763 | return -ENOENT; |
| 2764 | } else if (mwdma_mask) { |
| 2765 | highbit = fls(mwdma_mask) - 1; |
| 2766 | mwdma_mask &= ~(1 << highbit); |
| 2767 | if (!mwdma_mask) |
| 2768 | return -ENOENT; |
| 2769 | } |
| 2770 | break; |
| 2771 | |
| 2772 | case ATA_DNXFER_40C: |
| 2773 | udma_mask &= ATA_UDMA_MASK_40C; |
| 2774 | break; |
| 2775 | |
| 2776 | case ATA_DNXFER_FORCE_PIO0: |
| 2777 | pio_mask &= 1; |
| 2778 | case ATA_DNXFER_FORCE_PIO: |
| 2779 | mwdma_mask = 0; |
| 2780 | udma_mask = 0; |
| 2781 | break; |
| 2782 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2783 | default: |
| 2784 | BUG(); |
| 2785 | } |
| 2786 | |
| 2787 | xfer_mask &= ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 2788 | |
| 2789 | if (!(xfer_mask & ATA_MASK_PIO) || xfer_mask == orig_mask) |
| 2790 | return -ENOENT; |
| 2791 | |
| 2792 | if (!quiet) { |
| 2793 | if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA)) |
| 2794 | snprintf(buf, sizeof(buf), "%s:%s", |
| 2795 | ata_mode_string(xfer_mask), |
| 2796 | ata_mode_string(xfer_mask & ATA_MASK_PIO)); |
| 2797 | else |
| 2798 | snprintf(buf, sizeof(buf), "%s", |
| 2799 | ata_mode_string(xfer_mask)); |
| 2800 | |
| 2801 | ata_dev_printk(dev, KERN_WARNING, |
| 2802 | "limiting speed to %s\n", buf); |
| 2803 | } |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2804 | |
| 2805 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, |
| 2806 | &dev->udma_mask); |
| 2807 | |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2808 | return 0; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2809 | } |
| 2810 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2811 | static int ata_dev_set_mode(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2813 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2814 | unsigned int err_mask; |
| 2815 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | |
Tejun Heo | e838460 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 2817 | dev->flags &= ~ATA_DFLAG_PIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | if (dev->xfer_shift == ATA_SHIFT_PIO) |
| 2819 | dev->flags |= ATA_DFLAG_PIO; |
| 2820 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2821 | err_mask = ata_dev_set_xfermode(dev); |
Alan | 11750a4 | 2007-02-05 16:28:30 +0000 | [diff] [blame] | 2822 | /* Old CFA may refuse this command, which is just fine */ |
| 2823 | if (dev->xfer_shift == ATA_SHIFT_PIO && ata_id_is_cfa(dev->id)) |
| 2824 | err_mask &= ~AC_ERR_DEV; |
Alan Cox | 0bc2a79 | 2007-07-31 14:01:48 +0100 | [diff] [blame] | 2825 | /* Some very old devices and some bad newer ones fail any kind of |
| 2826 | SET_XFERMODE request but support PIO0-2 timings and no IORDY */ |
| 2827 | if (dev->xfer_shift == ATA_SHIFT_PIO && !ata_id_has_iordy(dev->id) && |
| 2828 | dev->pio_mode <= XFER_PIO_2) |
| 2829 | err_mask &= ~AC_ERR_DEV; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2830 | if (err_mask) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2831 | ata_dev_printk(dev, KERN_ERR, "failed to set xfermode " |
| 2832 | "(err_mask=0x%x)\n", err_mask); |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2833 | return -EIO; |
| 2834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 2836 | ehc->i.flags |= ATA_EHI_POST_SETMODE; |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2837 | rc = ata_dev_revalidate(dev, 0); |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 2838 | ehc->i.flags &= ~ATA_EHI_POST_SETMODE; |
Tejun Heo | 5eb45c0 | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2839 | if (rc) |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2840 | return rc; |
Tejun Heo | 48a8a14 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2841 | |
Tejun Heo | 23e71c3 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2842 | DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", |
| 2843 | dev->xfer_shift, (int)dev->xfer_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2845 | ata_dev_printk(dev, KERN_INFO, "configured for %s\n", |
| 2846 | ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode))); |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2847 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | /** |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2851 | * ata_do_set_mode - Program timings and issue SET FEATURES - XFER |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2852 | * @link: link on which timings will be programmed |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2853 | * @r_failed_dev: out paramter for failed device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | * |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2855 | * Standard implementation of the function used to tune and set |
| 2856 | * ATA device disk transfer mode (PIO3, UDMA6, etc.). If |
| 2857 | * ata_dev_set_mode() fails, pointer to the failing device is |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2858 | * returned in @r_failed_dev. |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2859 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2861 | * PCI/etc. bus probe sem. |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2862 | * |
| 2863 | * RETURNS: |
| 2864 | * 0 on success, negative errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | */ |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2866 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2867 | int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2869 | struct ata_port *ap = link->ap; |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2870 | struct ata_device *dev; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2871 | int rc = 0, used_dma = 0, found = 0; |
Tejun Heo | 3adcebb | 2006-05-15 20:57:37 +0900 | [diff] [blame] | 2872 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2873 | /* step 1: calculate xfer_mask */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2874 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 2875 | unsigned int pio_mask, dma_mask; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2876 | |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2877 | if (!ata_dev_enabled(dev)) |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2878 | continue; |
| 2879 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2880 | ata_dev_xfermask(dev); |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2881 | |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 2882 | pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); |
| 2883 | dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); |
| 2884 | dev->pio_mode = ata_xfer_mask2mode(pio_mask); |
| 2885 | dev->dma_mode = ata_xfer_mask2mode(dma_mask); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 2886 | |
Tejun Heo | 4f65977 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2887 | found = 1; |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 2888 | if (dev->dma_mode) |
| 2889 | used_dma = 1; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2890 | } |
Tejun Heo | 4f65977 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2891 | if (!found) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2892 | goto out; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2893 | |
| 2894 | /* step 2: always set host PIO timings */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2895 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2896 | if (!ata_dev_enabled(dev)) |
| 2897 | continue; |
| 2898 | |
| 2899 | if (!dev->pio_mode) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2900 | ata_dev_printk(dev, KERN_WARNING, "no PIO support\n"); |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2901 | rc = -EINVAL; |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2902 | goto out; |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | dev->xfer_mode = dev->pio_mode; |
| 2906 | dev->xfer_shift = ATA_SHIFT_PIO; |
| 2907 | if (ap->ops->set_piomode) |
| 2908 | ap->ops->set_piomode(ap, dev); |
| 2909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 2911 | /* step 3: set host DMA timings */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2912 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2913 | if (!ata_dev_enabled(dev) || !dev->dma_mode) |
| 2914 | continue; |
| 2915 | |
| 2916 | dev->xfer_mode = dev->dma_mode; |
| 2917 | dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); |
| 2918 | if (ap->ops->set_dmamode) |
| 2919 | ap->ops->set_dmamode(ap, dev); |
| 2920 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | |
| 2922 | /* step 4: update devices' xfer mode */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2923 | ata_link_for_each_dev(dev, link) { |
Alan | 18d90de | 2007-01-24 11:42:38 +0000 | [diff] [blame] | 2924 | /* don't update suspended devices' xfer mode */ |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 2925 | if (!ata_dev_enabled(dev)) |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2926 | continue; |
| 2927 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2928 | rc = ata_dev_set_mode(dev); |
Tejun Heo | 5bbc53f | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2929 | if (rc) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2930 | goto out; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 2931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2933 | /* Record simplex status. If we selected DMA then the other |
| 2934 | * host channels are not permitted to do so. |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 2935 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2936 | if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) |
Alan | 032af1c | 2007-03-01 17:36:46 +0000 | [diff] [blame] | 2937 | ap->host->simplex_claimed = ap; |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 2938 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2939 | out: |
| 2940 | if (rc) |
| 2941 | *r_failed_dev = dev; |
| 2942 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | /** |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2946 | * ata_set_mode - Program timings and issue SET FEATURES - XFER |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2947 | * @link: link on which timings will be programmed |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2948 | * @r_failed_dev: out paramter for failed device |
| 2949 | * |
| 2950 | * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If |
| 2951 | * ata_set_mode() fails, pointer to the failing device is |
| 2952 | * returned in @r_failed_dev. |
| 2953 | * |
| 2954 | * LOCKING: |
| 2955 | * PCI/etc. bus probe sem. |
| 2956 | * |
| 2957 | * RETURNS: |
| 2958 | * 0 on success, negative errno otherwise |
| 2959 | */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2960 | int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev) |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2961 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2962 | struct ata_port *ap = link->ap; |
| 2963 | |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2964 | /* has private set_mode? */ |
| 2965 | if (ap->ops->set_mode) |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2966 | return ap->ops->set_mode(link, r_failed_dev); |
| 2967 | return ata_do_set_mode(link, r_failed_dev); |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | /** |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2971 | * ata_tf_to_host - issue ATA taskfile to host controller |
| 2972 | * @ap: port to which command is being issued |
| 2973 | * @tf: ATA taskfile register set |
| 2974 | * |
| 2975 | * Issues ATA taskfile register set to ATA host controller, |
| 2976 | * with proper synchronization with interrupt handler and |
| 2977 | * other threads. |
| 2978 | * |
| 2979 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2980 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2981 | */ |
| 2982 | |
| 2983 | static inline void ata_tf_to_host(struct ata_port *ap, |
| 2984 | const struct ata_taskfile *tf) |
| 2985 | { |
| 2986 | ap->ops->tf_load(ap, tf); |
| 2987 | ap->ops->exec_command(ap, tf); |
| 2988 | } |
| 2989 | |
| 2990 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | * ata_busy_sleep - sleep until BSY clears, or timeout |
| 2992 | * @ap: port containing status register to be polled |
| 2993 | * @tmout_pat: impatience timeout |
| 2994 | * @tmout: overall timeout |
| 2995 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2996 | * Sleep until ATA Status register bit BSY clears, |
| 2997 | * or a timeout occurs. |
| 2998 | * |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 2999 | * LOCKING: |
| 3000 | * Kernel thread context (may sleep). |
| 3001 | * |
| 3002 | * RETURNS: |
| 3003 | * 0 on success, -errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | */ |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3005 | int ata_busy_sleep(struct ata_port *ap, |
| 3006 | unsigned long tmout_pat, unsigned long tmout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | { |
| 3008 | unsigned long timer_start, timeout; |
| 3009 | u8 status; |
| 3010 | |
| 3011 | status = ata_busy_wait(ap, ATA_BUSY, 300); |
| 3012 | timer_start = jiffies; |
| 3013 | timeout = timer_start + tmout_pat; |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3014 | while (status != 0xff && (status & ATA_BUSY) && |
| 3015 | time_before(jiffies, timeout)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | msleep(50); |
| 3017 | status = ata_busy_wait(ap, ATA_BUSY, 3); |
| 3018 | } |
| 3019 | |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3020 | if (status != 0xff && (status & ATA_BUSY)) |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3021 | ata_port_printk(ap, KERN_WARNING, |
Jeff Garzik | 35aa7a4 | 2006-09-28 06:50:24 -0400 | [diff] [blame] | 3022 | "port is slow to respond, please be patient " |
| 3023 | "(Status 0x%x)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3024 | |
| 3025 | timeout = timer_start + tmout; |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3026 | while (status != 0xff && (status & ATA_BUSY) && |
| 3027 | time_before(jiffies, timeout)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | msleep(50); |
| 3029 | status = ata_chk_status(ap); |
| 3030 | } |
| 3031 | |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3032 | if (status == 0xff) |
| 3033 | return -ENODEV; |
| 3034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | if (status & ATA_BUSY) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3036 | ata_port_printk(ap, KERN_ERR, "port failed to respond " |
Jeff Garzik | 35aa7a4 | 2006-09-28 06:50:24 -0400 | [diff] [blame] | 3037 | "(%lu secs, Status 0x%x)\n", |
| 3038 | tmout / HZ, status); |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3039 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | return 0; |
| 3043 | } |
| 3044 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3045 | /** |
| 3046 | * ata_wait_ready - sleep until BSY clears, or timeout |
| 3047 | * @ap: port containing status register to be polled |
| 3048 | * @deadline: deadline jiffies for the operation |
| 3049 | * |
| 3050 | * Sleep until ATA Status register bit BSY clears, or timeout |
| 3051 | * occurs. |
| 3052 | * |
| 3053 | * LOCKING: |
| 3054 | * Kernel thread context (may sleep). |
| 3055 | * |
| 3056 | * RETURNS: |
| 3057 | * 0 on success, -errno otherwise. |
| 3058 | */ |
| 3059 | int ata_wait_ready(struct ata_port *ap, unsigned long deadline) |
| 3060 | { |
| 3061 | unsigned long start = jiffies; |
| 3062 | int warned = 0; |
| 3063 | |
| 3064 | while (1) { |
| 3065 | u8 status = ata_chk_status(ap); |
| 3066 | unsigned long now = jiffies; |
| 3067 | |
| 3068 | if (!(status & ATA_BUSY)) |
| 3069 | return 0; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3070 | if (!ata_link_online(&ap->link) && status == 0xff) |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3071 | return -ENODEV; |
| 3072 | if (time_after(now, deadline)) |
| 3073 | return -EBUSY; |
| 3074 | |
| 3075 | if (!warned && time_after(now, start + 5 * HZ) && |
| 3076 | (deadline - now > 3 * HZ)) { |
| 3077 | ata_port_printk(ap, KERN_WARNING, |
| 3078 | "port is slow to respond, please be patient " |
| 3079 | "(Status 0x%x)\n", status); |
| 3080 | warned = 1; |
| 3081 | } |
| 3082 | |
| 3083 | msleep(50); |
| 3084 | } |
| 3085 | } |
| 3086 | |
| 3087 | static int ata_bus_post_reset(struct ata_port *ap, unsigned int devmask, |
| 3088 | unsigned long deadline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3089 | { |
| 3090 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 3091 | unsigned int dev0 = devmask & (1 << 0); |
| 3092 | unsigned int dev1 = devmask & (1 << 1); |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3093 | int rc, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | |
| 3095 | /* if device 0 was found in ata_devchk, wait for its |
| 3096 | * BSY bit to clear |
| 3097 | */ |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3098 | if (dev0) { |
| 3099 | rc = ata_wait_ready(ap, deadline); |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3100 | if (rc) { |
| 3101 | if (rc != -ENODEV) |
| 3102 | return rc; |
| 3103 | ret = rc; |
| 3104 | } |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | |
Tejun Heo | e141d99 | 2007-06-10 14:26:20 +0900 | [diff] [blame] | 3107 | /* if device 1 was found in ata_devchk, wait for register |
| 3108 | * access briefly, then wait for BSY to clear. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | */ |
Tejun Heo | e141d99 | 2007-06-10 14:26:20 +0900 | [diff] [blame] | 3110 | if (dev1) { |
| 3111 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | |
| 3113 | ap->ops->dev_select(ap, 1); |
Tejun Heo | e141d99 | 2007-06-10 14:26:20 +0900 | [diff] [blame] | 3114 | |
| 3115 | /* Wait for register access. Some ATAPI devices fail |
| 3116 | * to set nsect/lbal after reset, so don't waste too |
| 3117 | * much time on it. We're gonna wait for !BSY anyway. |
| 3118 | */ |
| 3119 | for (i = 0; i < 2; i++) { |
| 3120 | u8 nsect, lbal; |
| 3121 | |
| 3122 | nsect = ioread8(ioaddr->nsect_addr); |
| 3123 | lbal = ioread8(ioaddr->lbal_addr); |
| 3124 | if ((nsect == 1) && (lbal == 1)) |
| 3125 | break; |
| 3126 | msleep(50); /* give drive a breather */ |
| 3127 | } |
| 3128 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3129 | rc = ata_wait_ready(ap, deadline); |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3130 | if (rc) { |
| 3131 | if (rc != -ENODEV) |
| 3132 | return rc; |
| 3133 | ret = rc; |
| 3134 | } |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | |
| 3137 | /* is all this really necessary? */ |
| 3138 | ap->ops->dev_select(ap, 0); |
| 3139 | if (dev1) |
| 3140 | ap->ops->dev_select(ap, 1); |
| 3141 | if (dev0) |
| 3142 | ap->ops->dev_select(ap, 0); |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3143 | |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3144 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3147 | static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask, |
| 3148 | unsigned long deadline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | { |
| 3150 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 3151 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 3152 | DPRINTK("ata%u: bus reset via SRST\n", ap->print_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | |
| 3154 | /* software reset. causes dev0 to be selected */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 3155 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
| 3156 | udelay(20); /* FIXME: flush */ |
| 3157 | iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); |
| 3158 | udelay(20); /* FIXME: flush */ |
| 3159 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | |
| 3161 | /* spec mandates ">= 2ms" before checking status. |
| 3162 | * We wait 150ms, because that was the magic delay used for |
| 3163 | * ATAPI devices in Hale Landis's ATADRVR, for the period of time |
| 3164 | * between when the ATA command register is written, and then |
| 3165 | * status is checked. Because waiting for "a while" before |
| 3166 | * checking status is fine, post SRST, we perform this magic |
| 3167 | * delay here as well. |
Alan Cox | 09c7ad7 | 2006-03-22 15:52:40 +0000 | [diff] [blame] | 3168 | * |
| 3169 | * Old drivers/ide uses the 2mS rule and then waits for ready |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | */ |
| 3171 | msleep(150); |
| 3172 | |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 3173 | /* Before we perform post reset processing we want to see if |
Tejun Heo | 298a41c | 2006-03-25 02:58:13 +0900 | [diff] [blame] | 3174 | * the bus shows 0xFF because the odd clown forgets the D7 |
| 3175 | * pulldown resistor. |
| 3176 | */ |
Tejun Heo | d1adc1b | 2006-10-09 18:32:15 +0900 | [diff] [blame] | 3177 | if (ata_check_status(ap) == 0xFF) |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3178 | return -ENODEV; |
Alan Cox | 09c7ad7 | 2006-03-22 15:52:40 +0000 | [diff] [blame] | 3179 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3180 | return ata_bus_post_reset(ap, devmask, deadline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | /** |
| 3184 | * ata_bus_reset - reset host port and associated ATA channel |
| 3185 | * @ap: port to reset |
| 3186 | * |
| 3187 | * This is typically the first time we actually start issuing |
| 3188 | * commands to the ATA channel. We wait for BSY to clear, then |
| 3189 | * issue EXECUTE DEVICE DIAGNOSTIC command, polling for its |
| 3190 | * result. Determine what devices, if any, are on the channel |
| 3191 | * by looking at the device 0/1 error register. Look at the signature |
| 3192 | * stored in each device's taskfile registers, to determine if |
| 3193 | * the device is ATA or ATAPI. |
| 3194 | * |
| 3195 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3196 | * PCI/etc. bus probe sem. |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 3197 | * Obtains host lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | * |
| 3199 | * SIDE EFFECTS: |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 3200 | * Sets ATA_FLAG_DISABLED if bus reset fails. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | */ |
| 3202 | |
| 3203 | void ata_bus_reset(struct ata_port *ap) |
| 3204 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3205 | struct ata_device *device = ap->link.device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 3207 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; |
| 3208 | u8 err; |
Tejun Heo | aec5c3c | 2006-03-25 01:33:34 +0900 | [diff] [blame] | 3209 | unsigned int dev0, dev1 = 0, devmask = 0; |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3210 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 3212 | DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
| 3214 | /* determine if device 0/1 are present */ |
| 3215 | if (ap->flags & ATA_FLAG_SATA_RESET) |
| 3216 | dev0 = 1; |
| 3217 | else { |
| 3218 | dev0 = ata_devchk(ap, 0); |
| 3219 | if (slave_possible) |
| 3220 | dev1 = ata_devchk(ap, 1); |
| 3221 | } |
| 3222 | |
| 3223 | if (dev0) |
| 3224 | devmask |= (1 << 0); |
| 3225 | if (dev1) |
| 3226 | devmask |= (1 << 1); |
| 3227 | |
| 3228 | /* select device 0 again */ |
| 3229 | ap->ops->dev_select(ap, 0); |
| 3230 | |
| 3231 | /* issue bus reset */ |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3232 | if (ap->flags & ATA_FLAG_SRST) { |
| 3233 | rc = ata_bus_softreset(ap, devmask, jiffies + 40 * HZ); |
| 3234 | if (rc && rc != -ENODEV) |
Tejun Heo | aec5c3c | 2006-03-25 01:33:34 +0900 | [diff] [blame] | 3235 | goto err_out; |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | |
| 3238 | /* |
| 3239 | * determine by signature whether we have ATA or ATAPI devices |
| 3240 | */ |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 3241 | device[0].class = ata_dev_try_classify(&device[0], dev0, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | if ((slave_possible) && (err != 0x81)) |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 3243 | device[1].class = ata_dev_try_classify(&device[1], dev1, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | /* is double-select really necessary? */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3246 | if (device[1].class != ATA_DEV_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | ap->ops->dev_select(ap, 1); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3248 | if (device[0].class != ATA_DEV_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | ap->ops->dev_select(ap, 0); |
| 3250 | |
| 3251 | /* if no devices were detected, disable this port */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3252 | if ((device[0].class == ATA_DEV_NONE) && |
| 3253 | (device[1].class == ATA_DEV_NONE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | goto err_out; |
| 3255 | |
| 3256 | if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) { |
| 3257 | /* set up device control for ATA_FLAG_SATA_RESET */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 3258 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | DPRINTK("EXIT\n"); |
| 3262 | return; |
| 3263 | |
| 3264 | err_out: |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3265 | ata_port_printk(ap, KERN_ERR, "disabling port\n"); |
Jeff Garzik | ac8869d | 2007-08-16 03:17:03 -0400 | [diff] [blame] | 3266 | ata_port_disable(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
| 3268 | DPRINTK("EXIT\n"); |
| 3269 | } |
| 3270 | |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3271 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3272 | * sata_link_debounce - debounce SATA phy status |
| 3273 | * @link: ATA link to debounce SATA phy status for |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3274 | * @params: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3275 | * @deadline: deadline jiffies for the operation |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3276 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3277 | * Make sure SStatus of @link reaches stable state, determined by |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3278 | * holding the same value where DET is not 1 for @duration polled |
| 3279 | * every @interval, before @timeout. Timeout constraints the |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3280 | * beginning of the stable state. Because DET gets stuck at 1 on |
| 3281 | * some controllers after hot unplugging, this functions waits |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3282 | * until timeout then returns 0 if DET is stable at 1. |
| 3283 | * |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3284 | * @timeout is further limited by @deadline. The sooner of the |
| 3285 | * two is used. |
| 3286 | * |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3287 | * LOCKING: |
| 3288 | * Kernel thread context (may sleep) |
| 3289 | * |
| 3290 | * RETURNS: |
| 3291 | * 0 on success, -errno on failure. |
| 3292 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3293 | int sata_link_debounce(struct ata_link *link, const unsigned long *params, |
| 3294 | unsigned long deadline) |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3295 | { |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3296 | unsigned long interval_msec = params[0]; |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3297 | unsigned long duration = msecs_to_jiffies(params[1]); |
| 3298 | unsigned long last_jiffies, t; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3299 | u32 last, cur; |
| 3300 | int rc; |
| 3301 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3302 | t = jiffies + msecs_to_jiffies(params[2]); |
| 3303 | if (time_before(t, deadline)) |
| 3304 | deadline = t; |
| 3305 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3306 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3307 | return rc; |
| 3308 | cur &= 0xf; |
| 3309 | |
| 3310 | last = cur; |
| 3311 | last_jiffies = jiffies; |
| 3312 | |
| 3313 | while (1) { |
| 3314 | msleep(interval_msec); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3315 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3316 | return rc; |
| 3317 | cur &= 0xf; |
| 3318 | |
| 3319 | /* DET stable? */ |
| 3320 | if (cur == last) { |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3321 | if (cur == 1 && time_before(jiffies, deadline)) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3322 | continue; |
| 3323 | if (time_after(jiffies, last_jiffies + duration)) |
| 3324 | return 0; |
| 3325 | continue; |
| 3326 | } |
| 3327 | |
| 3328 | /* unstable, start over */ |
| 3329 | last = cur; |
| 3330 | last_jiffies = jiffies; |
| 3331 | |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 3332 | /* Check deadline. If debouncing failed, return |
| 3333 | * -EPIPE to tell upper layer to lower link speed. |
| 3334 | */ |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3335 | if (time_after(jiffies, deadline)) |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 3336 | return -EPIPE; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3341 | * sata_link_resume - resume SATA link |
| 3342 | * @link: ATA link to resume SATA |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3343 | * @params: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3344 | * @deadline: deadline jiffies for the operation |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3345 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3346 | * Resume SATA phy @link and debounce it. |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3347 | * |
| 3348 | * LOCKING: |
| 3349 | * Kernel thread context (may sleep) |
| 3350 | * |
| 3351 | * RETURNS: |
| 3352 | * 0 on success, -errno on failure. |
| 3353 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3354 | int sata_link_resume(struct ata_link *link, const unsigned long *params, |
| 3355 | unsigned long deadline) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3356 | { |
| 3357 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3358 | int rc; |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3359 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3360 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3361 | return rc; |
| 3362 | |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3363 | scontrol = (scontrol & 0x0f0) | 0x300; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3364 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3365 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3366 | return rc; |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3367 | |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3368 | /* Some PHYs react badly if SStatus is pounded immediately |
| 3369 | * after resuming. Delay 200ms before debouncing. |
| 3370 | */ |
| 3371 | msleep(200); |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3372 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3373 | return sata_link_debounce(link, params, deadline); |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3374 | } |
| 3375 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3376 | /** |
| 3377 | * ata_std_prereset - prepare for reset |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3378 | * @link: ATA link to be reset |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3379 | * @deadline: deadline jiffies for the operation |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3380 | * |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3381 | * @link is about to be reset. Initialize it. Failure from |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3382 | * prereset makes libata abort whole reset sequence and give up |
| 3383 | * that port, so prereset should be best-effort. It does its |
| 3384 | * best to prepare for reset sequence but if things go wrong, it |
| 3385 | * should just whine, not fail. |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3386 | * |
| 3387 | * LOCKING: |
| 3388 | * Kernel thread context (may sleep) |
| 3389 | * |
| 3390 | * RETURNS: |
| 3391 | * 0 on success, -errno otherwise. |
| 3392 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3393 | int ata_std_prereset(struct ata_link *link, unsigned long deadline) |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3394 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3395 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3396 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 3397 | const unsigned long *timing = sata_ehc_deb_timing(ehc); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3398 | int rc; |
| 3399 | |
Tejun Heo | 31daabd | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3400 | /* handle link resume */ |
Tejun Heo | 2832430 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 3401 | if ((ehc->i.flags & ATA_EHI_RESUME_LINK) && |
Tejun Heo | 0c88758 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3402 | (link->flags & ATA_LFLAG_HRST_TO_RESUME)) |
Tejun Heo | 2832430 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 3403 | ehc->i.action |= ATA_EH_HARDRESET; |
| 3404 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3405 | /* if we're about to do hardreset, nothing more to do */ |
| 3406 | if (ehc->i.action & ATA_EH_HARDRESET) |
| 3407 | return 0; |
| 3408 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3409 | /* if SATA, resume link */ |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 3410 | if (ap->flags & ATA_FLAG_SATA) { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3411 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3412 | /* whine about phy resume failure but proceed */ |
| 3413 | if (rc && rc != -EOPNOTSUPP) |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3414 | ata_link_printk(link, KERN_WARNING, "failed to resume " |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3415 | "link for reset (errno=%d)\n", rc); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | /* Wait for !BSY if the controller can wait for the first D2H |
| 3419 | * Reg FIS and we don't know that no device is attached. |
| 3420 | */ |
Tejun Heo | 0c88758 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3421 | if (!(link->flags & ATA_LFLAG_SKIP_D2H_BSY) && !ata_link_offline(link)) { |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3422 | rc = ata_wait_ready(ap, deadline); |
Tejun Heo | 6dffaf6 | 2007-05-23 11:58:52 +0200 | [diff] [blame] | 3423 | if (rc && rc != -ENODEV) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3424 | ata_link_printk(link, KERN_WARNING, "device not ready " |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3425 | "(errno=%d), forcing hardreset\n", rc); |
| 3426 | ehc->i.action |= ATA_EH_HARDRESET; |
| 3427 | } |
| 3428 | } |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3429 | |
| 3430 | return 0; |
| 3431 | } |
| 3432 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3433 | /** |
| 3434 | * ata_std_softreset - reset host port via ATA SRST |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3435 | * @link: ATA link to reset |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3436 | * @classes: resulting classes of attached devices |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3437 | * @deadline: deadline jiffies for the operation |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3438 | * |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 3439 | * Reset host port using ATA SRST. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3440 | * |
| 3441 | * LOCKING: |
| 3442 | * Kernel thread context (may sleep) |
| 3443 | * |
| 3444 | * RETURNS: |
| 3445 | * 0 on success, -errno otherwise. |
| 3446 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3447 | int ata_std_softreset(struct ata_link *link, unsigned int *classes, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3448 | unsigned long deadline) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3449 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3450 | struct ata_port *ap = link->ap; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3451 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3452 | unsigned int devmask = 0; |
| 3453 | int rc; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3454 | u8 err; |
| 3455 | |
| 3456 | DPRINTK("ENTER\n"); |
| 3457 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3458 | if (ata_link_offline(link)) { |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 3459 | classes[0] = ATA_DEV_NONE; |
| 3460 | goto out; |
| 3461 | } |
| 3462 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3463 | /* determine if device 0/1 are present */ |
| 3464 | if (ata_devchk(ap, 0)) |
| 3465 | devmask |= (1 << 0); |
| 3466 | if (slave_possible && ata_devchk(ap, 1)) |
| 3467 | devmask |= (1 << 1); |
| 3468 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3469 | /* select device 0 again */ |
| 3470 | ap->ops->dev_select(ap, 0); |
| 3471 | |
| 3472 | /* issue bus reset */ |
| 3473 | DPRINTK("about to softreset, devmask=%x\n", devmask); |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3474 | rc = ata_bus_softreset(ap, devmask, deadline); |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3475 | /* if link is occupied, -ENODEV too is an error */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3476 | if (rc && (rc != -ENODEV || sata_scr_valid(link))) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3477 | ata_link_printk(link, KERN_ERR, "SRST failed (errno=%d)\n", rc); |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3478 | return rc; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | /* determine by signature whether we have ATA or ATAPI devices */ |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 3482 | classes[0] = ata_dev_try_classify(&link->device[0], |
| 3483 | devmask & (1 << 0), &err); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3484 | if (slave_possible && err != 0x81) |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 3485 | classes[1] = ata_dev_try_classify(&link->device[1], |
| 3486 | devmask & (1 << 1), &err); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3487 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 3488 | out: |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3489 | DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]); |
| 3490 | return 0; |
| 3491 | } |
| 3492 | |
| 3493 | /** |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3494 | * sata_link_hardreset - reset link via SATA phy reset |
| 3495 | * @link: link to reset |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3496 | * @timing: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3497 | * @deadline: deadline jiffies for the operation |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3498 | * |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3499 | * SATA phy-reset @link using DET bits of SControl register. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3500 | * |
| 3501 | * LOCKING: |
| 3502 | * Kernel thread context (may sleep) |
| 3503 | * |
| 3504 | * RETURNS: |
| 3505 | * 0 on success, -errno otherwise. |
| 3506 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3507 | int sata_link_hardreset(struct ata_link *link, const unsigned long *timing, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3508 | unsigned long deadline) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3509 | { |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3510 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3511 | int rc; |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3512 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3513 | DPRINTK("ENTER\n"); |
| 3514 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3515 | if (sata_set_spd_needed(link)) { |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3516 | /* SATA spec says nothing about how to reconfigure |
| 3517 | * spd. To be on the safe side, turn off phy during |
| 3518 | * reconfiguration. This works for at least ICH7 AHCI |
| 3519 | * and Sil3124. |
| 3520 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3521 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3522 | goto out; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3523 | |
Martin Hicks | a34b6fc | 2006-07-05 15:06:13 -0400 | [diff] [blame] | 3524 | scontrol = (scontrol & 0x0f0) | 0x304; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3525 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3526 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3527 | goto out; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3528 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3529 | sata_set_spd(link); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | /* issue phy wake/reset */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3533 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3534 | goto out; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3535 | |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3536 | scontrol = (scontrol & 0x0f0) | 0x301; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3537 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3538 | if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3539 | goto out; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3540 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3541 | /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3542 | * 10.4.2 says at least 1 ms. |
| 3543 | */ |
| 3544 | msleep(1); |
| 3545 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3546 | /* bring link back */ |
| 3547 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3548 | out: |
| 3549 | DPRINTK("EXIT, rc=%d\n", rc); |
| 3550 | return rc; |
| 3551 | } |
| 3552 | |
| 3553 | /** |
| 3554 | * sata_std_hardreset - reset host port via SATA phy reset |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3555 | * @link: link to reset |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3556 | * @class: resulting class of attached device |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3557 | * @deadline: deadline jiffies for the operation |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3558 | * |
| 3559 | * SATA phy-reset host port using DET bits of SControl register, |
| 3560 | * wait for !BSY and classify the attached device. |
| 3561 | * |
| 3562 | * LOCKING: |
| 3563 | * Kernel thread context (may sleep) |
| 3564 | * |
| 3565 | * RETURNS: |
| 3566 | * 0 on success, -errno otherwise. |
| 3567 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3568 | int sata_std_hardreset(struct ata_link *link, unsigned int *class, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3569 | unsigned long deadline) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3570 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3571 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3572 | const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3573 | int rc; |
| 3574 | |
| 3575 | DPRINTK("ENTER\n"); |
| 3576 | |
| 3577 | /* do hardreset */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3578 | rc = sata_link_hardreset(link, timing, deadline); |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3579 | if (rc) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3580 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3581 | "COMRESET failed (errno=%d)\n", rc); |
| 3582 | return rc; |
| 3583 | } |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3584 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3585 | /* TODO: phy layer with polling, timeouts, etc. */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3586 | if (ata_link_offline(link)) { |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3587 | *class = ATA_DEV_NONE; |
| 3588 | DPRINTK("EXIT, link offline\n"); |
| 3589 | return 0; |
| 3590 | } |
| 3591 | |
Tejun Heo | 34fee22 | 2007-02-02 15:29:27 +0900 | [diff] [blame] | 3592 | /* wait a while before checking status, see SRST for more info */ |
| 3593 | msleep(150); |
| 3594 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3595 | rc = ata_wait_ready(ap, deadline); |
Tejun Heo | 9b89391 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3596 | /* link occupied, -ENODEV too is an error */ |
| 3597 | if (rc) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3598 | ata_link_printk(link, KERN_ERR, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3599 | "COMRESET failed (errno=%d)\n", rc); |
| 3600 | return rc; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3601 | } |
| 3602 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 3603 | ap->ops->dev_select(ap, 0); /* probably unnecessary */ |
| 3604 | |
Tejun Heo | 3f19859 | 2007-09-02 23:23:57 +0900 | [diff] [blame^] | 3605 | *class = ata_dev_try_classify(link->device, 1, NULL); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3606 | |
| 3607 | DPRINTK("EXIT, class=%u\n", *class); |
| 3608 | return 0; |
| 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * ata_std_postreset - standard postreset callback |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3613 | * @link: the target ata_link |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3614 | * @classes: classes of attached devices |
| 3615 | * |
| 3616 | * This function is invoked after a successful reset. Note that |
| 3617 | * the device might have been reset more than once using |
| 3618 | * different reset methods before postreset is invoked. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3619 | * |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3620 | * LOCKING: |
| 3621 | * Kernel thread context (may sleep) |
| 3622 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3623 | void ata_std_postreset(struct ata_link *link, unsigned int *classes) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3624 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3625 | struct ata_port *ap = link->ap; |
Tejun Heo | dc2b351 | 2006-05-15 20:58:00 +0900 | [diff] [blame] | 3626 | u32 serror; |
| 3627 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3628 | DPRINTK("ENTER\n"); |
| 3629 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3630 | /* print link status */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3631 | sata_print_link_status(link); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3632 | |
Tejun Heo | dc2b351 | 2006-05-15 20:58:00 +0900 | [diff] [blame] | 3633 | /* clear SError */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3634 | if (sata_scr_read(link, SCR_ERROR, &serror) == 0) |
| 3635 | sata_scr_write(link, SCR_ERROR, serror); |
Tejun Heo | dc2b351 | 2006-05-15 20:58:00 +0900 | [diff] [blame] | 3636 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3637 | /* is double-select really necessary? */ |
| 3638 | if (classes[0] != ATA_DEV_NONE) |
| 3639 | ap->ops->dev_select(ap, 1); |
| 3640 | if (classes[1] != ATA_DEV_NONE) |
| 3641 | ap->ops->dev_select(ap, 0); |
| 3642 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 3643 | /* bail out if no device is present */ |
| 3644 | if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { |
| 3645 | DPRINTK("EXIT, no device\n"); |
| 3646 | return; |
| 3647 | } |
| 3648 | |
| 3649 | /* set up device control */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 3650 | if (ap->ioaddr.ctl_addr) |
| 3651 | iowrite8(ap->ctl, ap->ioaddr.ctl_addr); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3652 | |
| 3653 | DPRINTK("EXIT\n"); |
| 3654 | } |
| 3655 | |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3656 | /** |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3657 | * ata_dev_same_device - Determine whether new ID matches configured device |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3658 | * @dev: device to compare against |
| 3659 | * @new_class: class of the new device |
| 3660 | * @new_id: IDENTIFY page of the new device |
| 3661 | * |
| 3662 | * Compare @new_class and @new_id against @dev and determine |
| 3663 | * whether @dev is the device indicated by @new_class and |
| 3664 | * @new_id. |
| 3665 | * |
| 3666 | * LOCKING: |
| 3667 | * None. |
| 3668 | * |
| 3669 | * RETURNS: |
| 3670 | * 1 if @dev matches @new_class and @new_id, 0 otherwise. |
| 3671 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3672 | static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class, |
| 3673 | const u16 *new_id) |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3674 | { |
| 3675 | const u16 *old_id = dev->id; |
Tejun Heo | a0cf733 | 2007-01-02 20:18:49 +0900 | [diff] [blame] | 3676 | unsigned char model[2][ATA_ID_PROD_LEN + 1]; |
| 3677 | unsigned char serial[2][ATA_ID_SERNO_LEN + 1]; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3678 | |
| 3679 | if (dev->class != new_class) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3680 | ata_dev_printk(dev, KERN_INFO, "class mismatch %d != %d\n", |
| 3681 | dev->class, new_class); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3682 | return 0; |
| 3683 | } |
| 3684 | |
Tejun Heo | a0cf733 | 2007-01-02 20:18:49 +0900 | [diff] [blame] | 3685 | ata_id_c_string(old_id, model[0], ATA_ID_PROD, sizeof(model[0])); |
| 3686 | ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1])); |
| 3687 | ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0])); |
| 3688 | ata_id_c_string(new_id, serial[1], ATA_ID_SERNO, sizeof(serial[1])); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3689 | |
| 3690 | if (strcmp(model[0], model[1])) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3691 | ata_dev_printk(dev, KERN_INFO, "model number mismatch " |
| 3692 | "'%s' != '%s'\n", model[0], model[1]); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3693 | return 0; |
| 3694 | } |
| 3695 | |
| 3696 | if (strcmp(serial[0], serial[1])) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3697 | ata_dev_printk(dev, KERN_INFO, "serial number mismatch " |
| 3698 | "'%s' != '%s'\n", serial[0], serial[1]); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3699 | return 0; |
| 3700 | } |
| 3701 | |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3702 | return 1; |
| 3703 | } |
| 3704 | |
| 3705 | /** |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3706 | * ata_dev_reread_id - Re-read IDENTIFY data |
Henrik Kretzschmar | 3fae450 | 2007-06-19 10:10:50 +0200 | [diff] [blame] | 3707 | * @dev: target ATA device |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 3708 | * @readid_flags: read ID flags |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3709 | * |
| 3710 | * Re-read IDENTIFY page and make sure @dev is still attached to |
| 3711 | * the port. |
| 3712 | * |
| 3713 | * LOCKING: |
| 3714 | * Kernel thread context (may sleep) |
| 3715 | * |
| 3716 | * RETURNS: |
| 3717 | * 0 on success, negative errno otherwise |
| 3718 | */ |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3719 | int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags) |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3720 | { |
Tejun Heo | 5eb45c0 | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 3721 | unsigned int class = dev->class; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3722 | u16 *id = (void *)dev->link->ap->sector_buf; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3723 | int rc; |
| 3724 | |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 3725 | /* read ID data */ |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 3726 | rc = ata_dev_read_id(dev, &class, readid_flags, id); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3727 | if (rc) |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3728 | return rc; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3729 | |
| 3730 | /* is the device still there? */ |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3731 | if (!ata_dev_same_device(dev, class, id)) |
| 3732 | return -ENODEV; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3733 | |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 3734 | memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3735 | return 0; |
| 3736 | } |
| 3737 | |
| 3738 | /** |
| 3739 | * ata_dev_revalidate - Revalidate ATA device |
| 3740 | * @dev: device to revalidate |
| 3741 | * @readid_flags: read ID flags |
| 3742 | * |
| 3743 | * Re-read IDENTIFY page, make sure @dev is still attached to the |
| 3744 | * port and reconfigure it according to the new IDENTIFY page. |
| 3745 | * |
| 3746 | * LOCKING: |
| 3747 | * Kernel thread context (may sleep) |
| 3748 | * |
| 3749 | * RETURNS: |
| 3750 | * 0 on success, negative errno otherwise |
| 3751 | */ |
| 3752 | int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags) |
| 3753 | { |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3754 | u64 n_sectors = dev->n_sectors; |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3755 | int rc; |
| 3756 | |
| 3757 | if (!ata_dev_enabled(dev)) |
| 3758 | return -ENODEV; |
| 3759 | |
| 3760 | /* re-read ID */ |
| 3761 | rc = ata_dev_reread_id(dev, readid_flags); |
| 3762 | if (rc) |
| 3763 | goto fail; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3764 | |
| 3765 | /* configure device according to the new ID */ |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 3766 | rc = ata_dev_configure(dev); |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3767 | if (rc) |
| 3768 | goto fail; |
| 3769 | |
| 3770 | /* verify n_sectors hasn't changed */ |
Tejun Heo | b54eebd | 2007-08-17 18:46:51 +0900 | [diff] [blame] | 3771 | if (dev->class == ATA_DEV_ATA && n_sectors && |
| 3772 | dev->n_sectors != n_sectors) { |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3773 | ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch " |
| 3774 | "%llu != %llu\n", |
| 3775 | (unsigned long long)n_sectors, |
| 3776 | (unsigned long long)dev->n_sectors); |
Tejun Heo | 8270bec | 2007-08-16 03:02:22 +0900 | [diff] [blame] | 3777 | |
| 3778 | /* restore original n_sectors */ |
| 3779 | dev->n_sectors = n_sectors; |
| 3780 | |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3781 | rc = -ENODEV; |
| 3782 | goto fail; |
| 3783 | } |
| 3784 | |
| 3785 | return 0; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3786 | |
| 3787 | fail: |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3788 | ata_dev_printk(dev, KERN_ERR, "revalidation failed (errno=%d)\n", rc); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3789 | return rc; |
| 3790 | } |
| 3791 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3792 | struct ata_blacklist_entry { |
| 3793 | const char *model_num; |
| 3794 | const char *model_rev; |
| 3795 | unsigned long horkage; |
| 3796 | }; |
| 3797 | |
| 3798 | static const struct ata_blacklist_entry ata_device_blacklist [] = { |
| 3799 | /* Devices with DMA related problems under Linux */ |
| 3800 | { "WDC AC11000H", NULL, ATA_HORKAGE_NODMA }, |
| 3801 | { "WDC AC22100H", NULL, ATA_HORKAGE_NODMA }, |
| 3802 | { "WDC AC32500H", NULL, ATA_HORKAGE_NODMA }, |
| 3803 | { "WDC AC33100H", NULL, ATA_HORKAGE_NODMA }, |
| 3804 | { "WDC AC31600H", NULL, ATA_HORKAGE_NODMA }, |
| 3805 | { "WDC AC32100H", "24.09P07", ATA_HORKAGE_NODMA }, |
| 3806 | { "WDC AC23200L", "21.10N21", ATA_HORKAGE_NODMA }, |
| 3807 | { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA }, |
| 3808 | { "CRD-8400B", NULL, ATA_HORKAGE_NODMA }, |
| 3809 | { "CRD-8480B", NULL, ATA_HORKAGE_NODMA }, |
| 3810 | { "CRD-8482B", NULL, ATA_HORKAGE_NODMA }, |
| 3811 | { "CRD-84", NULL, ATA_HORKAGE_NODMA }, |
| 3812 | { "SanDisk SDP3B", NULL, ATA_HORKAGE_NODMA }, |
| 3813 | { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA }, |
| 3814 | { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA }, |
| 3815 | { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA }, |
| 3816 | { "HITACHI CDR-8335", NULL, ATA_HORKAGE_NODMA }, |
| 3817 | { "HITACHI CDR-8435", NULL, ATA_HORKAGE_NODMA }, |
| 3818 | { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA }, |
| 3819 | { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA }, |
| 3820 | { "CD-532E-A", NULL, ATA_HORKAGE_NODMA }, |
| 3821 | { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA }, |
| 3822 | { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA }, |
| 3823 | { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA }, |
| 3824 | { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA }, |
| 3825 | { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3826 | { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA }, |
| 3827 | { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA }, |
| 3828 | { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA }, |
Dave Jones | 39f1988 | 2007-05-21 14:31:03 -0400 | [diff] [blame] | 3829 | { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA }, |
Tejun Heo | 5acd50f | 2007-06-10 14:52:36 +0900 | [diff] [blame] | 3830 | { "IOMEGA ZIP 250 ATAPI", NULL, ATA_HORKAGE_NODMA }, /* temporary fix */ |
Tejun Heo | 39ce712 | 2007-07-05 12:31:31 +0900 | [diff] [blame] | 3831 | { "IOMEGA ZIP 250 ATAPI Floppy", |
| 3832 | NULL, ATA_HORKAGE_NODMA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3833 | |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 3834 | /* Weird ATAPI devices */ |
Tejun Heo | 40a1d53 | 2007-06-27 02:49:38 +0900 | [diff] [blame] | 3835 | { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 }, |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 3836 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3837 | /* Devices we expect to fail diagnostics */ |
| 3838 | |
| 3839 | /* Devices where NCQ should be avoided */ |
| 3840 | /* NCQ is slow */ |
| 3841 | { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ }, |
Tejun Heo | 09125ea | 2007-02-28 15:21:23 +0900 | [diff] [blame] | 3842 | /* http://thread.gmane.org/gmane.linux.ide/14907 */ |
| 3843 | { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ }, |
Paul Rolland | 7acfaf3 | 2007-03-26 21:43:44 -0800 | [diff] [blame] | 3844 | /* NCQ is broken */ |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3845 | { "Maxtor *", "BANC*", ATA_HORKAGE_NONCQ }, |
Alan Cox | 0e3dbc0 | 2007-09-20 15:22:47 +0100 | [diff] [blame] | 3846 | { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ }, |
Prarit Bhargava | 2f8d90a | 2007-07-10 18:13:28 -0400 | [diff] [blame] | 3847 | { "HITACHI HDS7250SASUN500G 0621KTAWSD", "K2AOAJ0AHITACHI", |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3848 | ATA_HORKAGE_NONCQ }, |
| 3849 | |
Robert Hancock | 36e337d | 2007-04-02 22:05:29 -0600 | [diff] [blame] | 3850 | /* Blacklist entries taken from Silicon Image 3124/3132 |
| 3851 | Windows driver .inf file - also several Linux problem reports */ |
| 3852 | { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ, }, |
| 3853 | { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ, }, |
| 3854 | { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ, }, |
Tejun Heo | bd9c5a3 | 2007-06-08 22:20:59 +0900 | [diff] [blame] | 3855 | /* Drives which do spurious command completion */ |
| 3856 | { "HTS541680J9SA00", "SB2IC7EP", ATA_HORKAGE_NONCQ, }, |
Tejun Heo | 2f8fceb | 2007-06-18 14:38:41 +0900 | [diff] [blame] | 3857 | { "HTS541612J9SA00", "SBDIC7JP", ATA_HORKAGE_NONCQ, }, |
Tejun Heo | e14cbfa | 2007-06-25 11:28:59 +0900 | [diff] [blame] | 3858 | { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, }, |
Tejun Heo | 2f8fceb | 2007-06-18 14:38:41 +0900 | [diff] [blame] | 3859 | { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, |
Tejun Heo | a520f26 | 2007-07-10 16:16:18 +0900 | [diff] [blame] | 3860 | { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, }, |
Tejun Heo | 3fb6589 | 2007-07-20 12:49:38 +0900 | [diff] [blame] | 3861 | { "ST9160821AS", "3.CLF", ATA_HORKAGE_NONCQ, }, |
Alan Cox | 0e3dbc0 | 2007-09-20 15:22:47 +0100 | [diff] [blame] | 3862 | { "ST3160812AS", "3.AD", ATA_HORKAGE_NONCQ, }, |
Tejun Heo | 5d6aca8 | 2007-07-28 16:25:25 +0900 | [diff] [blame] | 3863 | { "SAMSUNG HD401LJ", "ZZ100-15", ATA_HORKAGE_NONCQ, }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3864 | |
Tejun Heo | 16c55b0 | 2007-08-29 11:58:33 +0900 | [diff] [blame] | 3865 | /* devices which puke on READ_NATIVE_MAX */ |
| 3866 | { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, }, |
| 3867 | { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA }, |
| 3868 | { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA }, |
| 3869 | { "MAXTOR 6L080L4", "A93.0500", ATA_HORKAGE_BROKEN_HPA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3870 | |
| 3871 | /* End Marker */ |
| 3872 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | }; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 3874 | |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3875 | int strn_pattern_cmp(const char *patt, const char *name, int wildchar) |
| 3876 | { |
| 3877 | const char *p; |
| 3878 | int len; |
| 3879 | |
| 3880 | /* |
| 3881 | * check for trailing wildcard: *\0 |
| 3882 | */ |
| 3883 | p = strchr(patt, wildchar); |
| 3884 | if (p && ((*(p + 1)) == 0)) |
| 3885 | len = p - patt; |
| 3886 | else |
| 3887 | len = strlen(name); |
| 3888 | |
| 3889 | return strncmp(patt, name, len); |
| 3890 | } |
| 3891 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 3892 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | { |
Tejun Heo | 8bfa79f | 2007-01-02 20:19:40 +0900 | [diff] [blame] | 3894 | unsigned char model_num[ATA_ID_PROD_LEN + 1]; |
| 3895 | unsigned char model_rev[ATA_ID_FW_REV_LEN + 1]; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3896 | const struct ata_blacklist_entry *ad = ata_device_blacklist; |
Albert Lee | 3a77827 | 2006-06-22 13:00:25 +0800 | [diff] [blame] | 3897 | |
Tejun Heo | 8bfa79f | 2007-01-02 20:19:40 +0900 | [diff] [blame] | 3898 | ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); |
| 3899 | ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3900 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3901 | while (ad->model_num) { |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3902 | if (!strn_pattern_cmp(ad->model_num, model_num, '*')) { |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3903 | if (ad->model_rev == NULL) |
| 3904 | return ad->horkage; |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3905 | if (!strn_pattern_cmp(ad->model_rev, model_rev, '*')) |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3906 | return ad->horkage; |
Alan Cox | f4b15fe | 2006-03-22 15:54:04 +0000 | [diff] [blame] | 3907 | } |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3908 | ad++; |
Alan Cox | f4b15fe | 2006-03-22 15:54:04 +0000 | [diff] [blame] | 3909 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | return 0; |
| 3911 | } |
| 3912 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3913 | static int ata_dma_blacklisted(const struct ata_device *dev) |
| 3914 | { |
| 3915 | /* We don't support polling DMA. |
| 3916 | * DMA blacklist those ATAPI devices with CDB-intr (and use PIO) |
| 3917 | * if the LLDD handles only interrupts in the HSM_ST_LAST state. |
| 3918 | */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3919 | if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3920 | (dev->flags & ATA_DFLAG_CDB_INTR)) |
| 3921 | return 1; |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 3922 | return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3923 | } |
| 3924 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3925 | /** |
| 3926 | * ata_dev_xfermask - Compute supported xfermask of the given device |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3927 | * @dev: Device to compute xfermask for |
| 3928 | * |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 3929 | * Compute supported xfermask of @dev and store it in |
| 3930 | * dev->*_mask. This function is responsible for applying all |
| 3931 | * known limits including host controller limits, device |
| 3932 | * blacklist, etc... |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3933 | * |
| 3934 | * LOCKING: |
| 3935 | * None. |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3936 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3937 | static void ata_dev_xfermask(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3939 | struct ata_link *link = dev->link; |
| 3940 | struct ata_port *ap = link->ap; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 3941 | struct ata_host *host = ap->host; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3942 | unsigned long xfer_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3944 | /* controller modes available */ |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3945 | xfer_mask = ata_pack_xfermask(ap->pio_mask, |
| 3946 | ap->mwdma_mask, ap->udma_mask); |
| 3947 | |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 3948 | /* drive modes available */ |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3949 | xfer_mask &= ata_pack_xfermask(dev->pio_mask, |
| 3950 | dev->mwdma_mask, dev->udma_mask); |
| 3951 | xfer_mask &= ata_id_xfermask(dev->id); |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3952 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 3953 | /* |
| 3954 | * CFA Advanced TrueIDE timings are not allowed on a shared |
| 3955 | * cable |
| 3956 | */ |
| 3957 | if (ata_dev_pair(dev)) { |
| 3958 | /* No PIO5 or PIO6 */ |
| 3959 | xfer_mask &= ~(0x03 << (ATA_SHIFT_PIO + 5)); |
| 3960 | /* No MWDMA3 or MWDMA 4 */ |
| 3961 | xfer_mask &= ~(0x03 << (ATA_SHIFT_MWDMA + 3)); |
| 3962 | } |
| 3963 | |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3964 | if (ata_dma_blacklisted(dev)) { |
| 3965 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3966 | ata_dev_printk(dev, KERN_WARNING, |
| 3967 | "device is on DMA blacklist, disabling DMA\n"); |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3968 | } |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3969 | |
Petr Vandrovec | 14d66ab | 2007-03-08 10:12:12 +0100 | [diff] [blame] | 3970 | if ((host->flags & ATA_HOST_SIMPLEX) && |
| 3971 | host->simplex_claimed && host->simplex_claimed != ap) { |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3972 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
| 3973 | ata_dev_printk(dev, KERN_WARNING, "simplex DMA is claimed by " |
| 3974 | "other device, disabling DMA\n"); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3975 | } |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3976 | |
Jeff Garzik | e424675 | 2007-03-09 09:56:46 -0500 | [diff] [blame] | 3977 | if (ap->flags & ATA_FLAG_NO_IORDY) |
| 3978 | xfer_mask &= ata_pio_mask_no_iordy(dev); |
| 3979 | |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3980 | if (ap->ops->mode_filter) |
Alan Cox | a76b62c | 2007-03-09 09:34:07 -0500 | [diff] [blame] | 3981 | xfer_mask = ap->ops->mode_filter(dev, xfer_mask); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3982 | |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 3983 | /* Apply cable rule here. Don't apply it early because when |
| 3984 | * we handle hot plug the cable type can itself change. |
| 3985 | * Check this last so that we know if the transfer rate was |
| 3986 | * solely limited by the cable. |
| 3987 | * Unknown or 80 wire cables reported host side are checked |
| 3988 | * drive side as well. Cases where we know a 40wire cable |
| 3989 | * is used safely for 80 are not checked here. |
| 3990 | */ |
| 3991 | if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA)) |
| 3992 | /* UDMA/44 or higher would be available */ |
| 3993 | if((ap->cbl == ATA_CBL_PATA40) || |
| 3994 | (ata_drive_40wire(dev->id) && |
| 3995 | (ap->cbl == ATA_CBL_PATA_UNK || |
| 3996 | ap->cbl == ATA_CBL_PATA80))) { |
| 3997 | ata_dev_printk(dev, KERN_WARNING, |
| 3998 | "limited to UDMA/33 due to 40-wire cable\n"); |
| 3999 | xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); |
| 4000 | } |
| 4001 | |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 4002 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, |
| 4003 | &dev->mwdma_mask, &dev->udma_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4007 | * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | * @dev: Device to which command will be sent |
| 4009 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4010 | * Issue SET FEATURES - XFER MODE command to device @dev |
| 4011 | * on port @ap. |
| 4012 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4014 | * PCI/etc. bus probe sem. |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4015 | * |
| 4016 | * RETURNS: |
| 4017 | * 0 on success, AC_ERR_* mask otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | */ |
| 4019 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4020 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4022 | struct ata_taskfile tf; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4023 | unsigned int err_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | |
| 4025 | /* set up set-features taskfile */ |
| 4026 | DPRINTK("set features - xfer mode\n"); |
| 4027 | |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 4028 | /* Some controllers and ATAPI devices show flaky interrupt |
| 4029 | * behavior after setting xfer mode. Use polling instead. |
| 4030 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4031 | ata_tf_init(dev, &tf); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4032 | tf.command = ATA_CMD_SET_FEATURES; |
| 4033 | tf.feature = SETFEATURES_XFER; |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 4034 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_POLLING; |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4035 | tf.protocol = ATA_PROT_NODATA; |
| 4036 | tf.nsect = dev->xfer_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4037 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4038 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4040 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4041 | return err_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
| 4044 | /** |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4045 | * ata_dev_set_AN - Issue SET FEATURES - SATA FEATURES |
| 4046 | * @dev: Device to which command will be sent |
| 4047 | * @enable: Whether to enable or disable the feature |
| 4048 | * |
| 4049 | * Issue SET FEATURES - SATA FEATURES command to device @dev |
| 4050 | * on port @ap with sector count set to indicate Asynchronous |
| 4051 | * Notification feature |
| 4052 | * |
| 4053 | * LOCKING: |
| 4054 | * PCI/etc. bus probe sem. |
| 4055 | * |
| 4056 | * RETURNS: |
| 4057 | * 0 on success, AC_ERR_* mask otherwise. |
| 4058 | */ |
| 4059 | static unsigned int ata_dev_set_AN(struct ata_device *dev, u8 enable) |
| 4060 | { |
| 4061 | struct ata_taskfile tf; |
| 4062 | unsigned int err_mask; |
| 4063 | |
| 4064 | /* set up set-features taskfile */ |
| 4065 | DPRINTK("set features - SATA features\n"); |
| 4066 | |
| 4067 | ata_tf_init(dev, &tf); |
| 4068 | tf.command = ATA_CMD_SET_FEATURES; |
| 4069 | tf.feature = enable; |
| 4070 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 4071 | tf.protocol = ATA_PROT_NODATA; |
| 4072 | tf.nsect = SATA_AN; |
| 4073 | |
| 4074 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
| 4075 | |
| 4076 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4077 | return err_mask; |
| 4078 | } |
| 4079 | |
| 4080 | /** |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4081 | * ata_dev_init_params - Issue INIT DEV PARAMS command |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4082 | * @dev: Device to which command will be sent |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 4083 | * @heads: Number of heads (taskfile parameter) |
| 4084 | * @sectors: Number of sectors (taskfile parameter) |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4085 | * |
| 4086 | * LOCKING: |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4087 | * Kernel thread context (may sleep) |
| 4088 | * |
| 4089 | * RETURNS: |
| 4090 | * 0 on success, AC_ERR_* mask otherwise. |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4091 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4092 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
| 4093 | u16 heads, u16 sectors) |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4094 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4095 | struct ata_taskfile tf; |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4096 | unsigned int err_mask; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4097 | |
| 4098 | /* Number of sectors per track 1-255. Number of heads 1-16 */ |
| 4099 | if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) |
Albert Lee | 00b6f5e | 2006-03-27 16:39:18 +0800 | [diff] [blame] | 4100 | return AC_ERR_INVALID; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4101 | |
| 4102 | /* set up init dev params taskfile */ |
| 4103 | DPRINTK("init dev params \n"); |
| 4104 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4105 | ata_tf_init(dev, &tf); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4106 | tf.command = ATA_CMD_INIT_DEV_PARAMS; |
| 4107 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 4108 | tf.protocol = ATA_PROT_NODATA; |
| 4109 | tf.nsect = sectors; |
| 4110 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4111 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4112 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0); |
Alan Cox | 18b2466 | 2007-08-08 14:28:49 +0100 | [diff] [blame] | 4113 | /* A clean abort indicates an original or just out of spec drive |
| 4114 | and we should continue as we issue the setup based on the |
| 4115 | drive reported working geometry */ |
| 4116 | if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) |
| 4117 | err_mask = 0; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4118 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4119 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4120 | return err_mask; |
Albert Lee | 8bf62ec | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4124 | * ata_sg_clean - Unmap DMA memory associated with command |
| 4125 | * @qc: Command containing DMA memory to be released |
| 4126 | * |
| 4127 | * Unmap all mapped DMA memory associated with this command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | * |
| 4129 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4130 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | */ |
Tejun Heo | 70e6ad0 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 4132 | void ata_sg_clean(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | { |
| 4134 | struct ata_port *ap = qc->ap; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4135 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | int dir = qc->dma_dir; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4137 | void *pad_buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4139 | WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP)); |
| 4140 | WARN_ON(sg == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | |
| 4142 | if (qc->flags & ATA_QCFLAG_SINGLE) |
Jeff Garzik | f131883 | 2006-02-20 16:55:56 -0500 | [diff] [blame] | 4143 | WARN_ON(qc->n_elem > 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 4145 | VPRINTK("unmapping %u sg elements\n", qc->n_elem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4147 | /* if we padded the buffer out to 32-bit bound, and data |
| 4148 | * xfer direction is from-device, we must copy from the |
| 4149 | * pad buffer back into the supplied buffer |
| 4150 | */ |
| 4151 | if (qc->pad_len && !(qc->tf.flags & ATA_TFLAG_WRITE)) |
| 4152 | pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); |
| 4153 | |
| 4154 | if (qc->flags & ATA_QCFLAG_SG) { |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4155 | if (qc->n_elem) |
Brian King | 2f1f610 | 2006-03-23 17:30:15 -0600 | [diff] [blame] | 4156 | dma_unmap_sg(ap->dev, sg, qc->n_elem, dir); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4157 | /* restore last sg */ |
| 4158 | sg[qc->orig_n_elem - 1].length += qc->pad_len; |
| 4159 | if (pad_buf) { |
| 4160 | struct scatterlist *psg = &qc->pad_sgent; |
| 4161 | void *addr = kmap_atomic(psg->page, KM_IRQ0); |
| 4162 | memcpy(addr + psg->offset, pad_buf, qc->pad_len); |
Mark Lord | dfa1598 | 2005-12-12 23:19:28 -0500 | [diff] [blame] | 4163 | kunmap_atomic(addr, KM_IRQ0); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4164 | } |
| 4165 | } else { |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 4166 | if (qc->n_elem) |
Brian King | 2f1f610 | 2006-03-23 17:30:15 -0600 | [diff] [blame] | 4167 | dma_unmap_single(ap->dev, |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4168 | sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), |
| 4169 | dir); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4170 | /* restore sg */ |
| 4171 | sg->length += qc->pad_len; |
| 4172 | if (pad_buf) |
| 4173 | memcpy(qc->buf_virt + sg->length - qc->pad_len, |
| 4174 | pad_buf, qc->pad_len); |
| 4175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4176 | |
| 4177 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4178 | qc->__sg = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | /** |
| 4182 | * ata_fill_sg - Fill PCI IDE PRD table |
| 4183 | * @qc: Metadata associated with taskfile to be transferred |
| 4184 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4185 | * Fill PCI IDE PRD (scatter-gather) table with segments |
| 4186 | * associated with the current disk command. |
| 4187 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4189 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4190 | * |
| 4191 | */ |
| 4192 | static void ata_fill_sg(struct ata_queued_cmd *qc) |
| 4193 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | struct ata_port *ap = qc->ap; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4195 | struct scatterlist *sg; |
| 4196 | unsigned int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4198 | WARN_ON(qc->__sg == NULL); |
Jeff Garzik | f131883 | 2006-02-20 16:55:56 -0500 | [diff] [blame] | 4199 | WARN_ON(qc->n_elem == 0 && qc->pad_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | |
| 4201 | idx = 0; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4202 | ata_for_each_sg(sg, qc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | u32 addr, offset; |
| 4204 | u32 sg_len, len; |
| 4205 | |
| 4206 | /* determine if physical DMA addr spans 64K boundary. |
| 4207 | * Note h/w doesn't support 64-bit, so we unconditionally |
| 4208 | * truncate dma_addr_t to u32. |
| 4209 | */ |
| 4210 | addr = (u32) sg_dma_address(sg); |
| 4211 | sg_len = sg_dma_len(sg); |
| 4212 | |
| 4213 | while (sg_len) { |
| 4214 | offset = addr & 0xffff; |
| 4215 | len = sg_len; |
| 4216 | if ((offset + sg_len) > 0x10000) |
| 4217 | len = 0x10000 - offset; |
| 4218 | |
| 4219 | ap->prd[idx].addr = cpu_to_le32(addr); |
| 4220 | ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff); |
| 4221 | VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len); |
| 4222 | |
| 4223 | idx++; |
| 4224 | sg_len -= len; |
| 4225 | addr += len; |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | if (idx) |
| 4230 | ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); |
| 4231 | } |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | /** |
Alan Cox | d26fc95 | 2007-07-06 19:13:52 -0400 | [diff] [blame] | 4234 | * ata_fill_sg_dumb - Fill PCI IDE PRD table |
| 4235 | * @qc: Metadata associated with taskfile to be transferred |
| 4236 | * |
| 4237 | * Fill PCI IDE PRD (scatter-gather) table with segments |
| 4238 | * associated with the current disk command. Perform the fill |
| 4239 | * so that we avoid writing any length 64K records for |
| 4240 | * controllers that don't follow the spec. |
| 4241 | * |
| 4242 | * LOCKING: |
| 4243 | * spin_lock_irqsave(host lock) |
| 4244 | * |
| 4245 | */ |
| 4246 | static void ata_fill_sg_dumb(struct ata_queued_cmd *qc) |
| 4247 | { |
| 4248 | struct ata_port *ap = qc->ap; |
| 4249 | struct scatterlist *sg; |
| 4250 | unsigned int idx; |
| 4251 | |
| 4252 | WARN_ON(qc->__sg == NULL); |
| 4253 | WARN_ON(qc->n_elem == 0 && qc->pad_len == 0); |
| 4254 | |
| 4255 | idx = 0; |
| 4256 | ata_for_each_sg(sg, qc) { |
| 4257 | u32 addr, offset; |
| 4258 | u32 sg_len, len, blen; |
| 4259 | |
| 4260 | /* determine if physical DMA addr spans 64K boundary. |
| 4261 | * Note h/w doesn't support 64-bit, so we unconditionally |
| 4262 | * truncate dma_addr_t to u32. |
| 4263 | */ |
| 4264 | addr = (u32) sg_dma_address(sg); |
| 4265 | sg_len = sg_dma_len(sg); |
| 4266 | |
| 4267 | while (sg_len) { |
| 4268 | offset = addr & 0xffff; |
| 4269 | len = sg_len; |
| 4270 | if ((offset + sg_len) > 0x10000) |
| 4271 | len = 0x10000 - offset; |
| 4272 | |
| 4273 | blen = len & 0xffff; |
| 4274 | ap->prd[idx].addr = cpu_to_le32(addr); |
| 4275 | if (blen == 0) { |
| 4276 | /* Some PATA chipsets like the CS5530 can't |
| 4277 | cope with 0x0000 meaning 64K as the spec says */ |
| 4278 | ap->prd[idx].flags_len = cpu_to_le32(0x8000); |
| 4279 | blen = 0x8000; |
| 4280 | ap->prd[++idx].addr = cpu_to_le32(addr + 0x8000); |
| 4281 | } |
| 4282 | ap->prd[idx].flags_len = cpu_to_le32(blen); |
| 4283 | VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len); |
| 4284 | |
| 4285 | idx++; |
| 4286 | sg_len -= len; |
| 4287 | addr += len; |
| 4288 | } |
| 4289 | } |
| 4290 | |
| 4291 | if (idx) |
| 4292 | ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); |
| 4293 | } |
| 4294 | |
| 4295 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | * ata_check_atapi_dma - Check whether ATAPI DMA can be supported |
| 4297 | * @qc: Metadata associated with taskfile to check |
| 4298 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4299 | * Allow low-level driver to filter ATA PACKET commands, returning |
| 4300 | * a status indicating whether or not it is OK to use DMA for the |
| 4301 | * supplied PACKET command. |
| 4302 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4304 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4305 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | * RETURNS: 0 when ATAPI DMA can be used |
| 4307 | * nonzero otherwise |
| 4308 | */ |
| 4309 | int ata_check_atapi_dma(struct ata_queued_cmd *qc) |
| 4310 | { |
| 4311 | struct ata_port *ap = qc->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4313 | /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a |
| 4314 | * few ATAPI devices choke on such DMA requests. |
| 4315 | */ |
| 4316 | if (unlikely(qc->nbytes & 15)) |
| 4317 | return 1; |
Albert Lee | 6f23a31 | 2007-04-02 11:39:25 +0800 | [diff] [blame] | 4318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4319 | if (ap->ops->check_atapi_dma) |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4320 | return ap->ops->check_atapi_dma(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4321 | |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4322 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | } |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4325 | /** |
| 4326 | * ata_qc_prep - Prepare taskfile for submission |
| 4327 | * @qc: Metadata associated with taskfile to be prepared |
| 4328 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4329 | * Prepare ATA taskfile for submission. |
| 4330 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4332 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4333 | */ |
| 4334 | void ata_qc_prep(struct ata_queued_cmd *qc) |
| 4335 | { |
| 4336 | if (!(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 4337 | return; |
| 4338 | |
| 4339 | ata_fill_sg(qc); |
| 4340 | } |
| 4341 | |
Alan Cox | d26fc95 | 2007-07-06 19:13:52 -0400 | [diff] [blame] | 4342 | /** |
| 4343 | * ata_dumb_qc_prep - Prepare taskfile for submission |
| 4344 | * @qc: Metadata associated with taskfile to be prepared |
| 4345 | * |
| 4346 | * Prepare ATA taskfile for submission. |
| 4347 | * |
| 4348 | * LOCKING: |
| 4349 | * spin_lock_irqsave(host lock) |
| 4350 | */ |
| 4351 | void ata_dumb_qc_prep(struct ata_queued_cmd *qc) |
| 4352 | { |
| 4353 | if (!(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 4354 | return; |
| 4355 | |
| 4356 | ata_fill_sg_dumb(qc); |
| 4357 | } |
| 4358 | |
Brian King | e46834c | 2006-03-17 17:04:03 -0600 | [diff] [blame] | 4359 | void ata_noop_qc_prep(struct ata_queued_cmd *qc) { } |
| 4360 | |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4361 | /** |
| 4362 | * ata_sg_init_one - Associate command with memory buffer |
| 4363 | * @qc: Command to be associated |
| 4364 | * @buf: Memory buffer |
| 4365 | * @buflen: Length of memory buffer, in bytes. |
| 4366 | * |
| 4367 | * Initialize the data-related elements of queued_cmd @qc |
| 4368 | * to point to a single memory buffer, @buf of byte length @buflen. |
| 4369 | * |
| 4370 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4371 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4372 | */ |
| 4373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) |
| 4375 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | qc->flags |= ATA_QCFLAG_SINGLE; |
| 4377 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4378 | qc->__sg = &qc->sgent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | qc->n_elem = 1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4380 | qc->orig_n_elem = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | qc->buf_virt = buf; |
Brian King | 233277c | 2006-06-07 11:25:31 -0500 | [diff] [blame] | 4382 | qc->nbytes = buflen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | |
Tejun Heo | 61c0596 | 2006-11-14 22:35:43 +0900 | [diff] [blame] | 4384 | sg_init_one(&qc->sgent, buf, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4385 | } |
| 4386 | |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4387 | /** |
| 4388 | * ata_sg_init - Associate command with scatter-gather table. |
| 4389 | * @qc: Command to be associated |
| 4390 | * @sg: Scatter-gather table. |
| 4391 | * @n_elem: Number of elements in s/g table. |
| 4392 | * |
| 4393 | * Initialize the data-related elements of queued_cmd @qc |
| 4394 | * to point to a scatter-gather table @sg, containing @n_elem |
| 4395 | * elements. |
| 4396 | * |
| 4397 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4398 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4399 | */ |
| 4400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4401 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
| 4402 | unsigned int n_elem) |
| 4403 | { |
| 4404 | qc->flags |= ATA_QCFLAG_SG; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4405 | qc->__sg = sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4406 | qc->n_elem = n_elem; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4407 | qc->orig_n_elem = n_elem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4411 | * ata_sg_setup_one - DMA-map the memory buffer associated with a command. |
| 4412 | * @qc: Command with memory buffer to be mapped. |
| 4413 | * |
| 4414 | * DMA-map the memory buffer associated with queued_cmd @qc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | * |
| 4416 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4417 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | * |
| 4419 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4420 | * Zero on success, negative on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | */ |
| 4422 | |
| 4423 | static int ata_sg_setup_one(struct ata_queued_cmd *qc) |
| 4424 | { |
| 4425 | struct ata_port *ap = qc->ap; |
| 4426 | int dir = qc->dma_dir; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4427 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | dma_addr_t dma_address; |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 4429 | int trim_sg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4431 | /* we must lengthen transfers to end on a 32-bit boundary */ |
| 4432 | qc->pad_len = sg->length & 3; |
| 4433 | if (qc->pad_len) { |
| 4434 | void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); |
| 4435 | struct scatterlist *psg = &qc->pad_sgent; |
| 4436 | |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4437 | WARN_ON(qc->dev->class != ATA_DEV_ATAPI); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4438 | |
| 4439 | memset(pad_buf, 0, ATA_DMA_PAD_SZ); |
| 4440 | |
| 4441 | if (qc->tf.flags & ATA_TFLAG_WRITE) |
| 4442 | memcpy(pad_buf, qc->buf_virt + sg->length - qc->pad_len, |
| 4443 | qc->pad_len); |
| 4444 | |
| 4445 | sg_dma_address(psg) = ap->pad_dma + (qc->tag * ATA_DMA_PAD_SZ); |
| 4446 | sg_dma_len(psg) = ATA_DMA_PAD_SZ; |
| 4447 | /* trim sg */ |
| 4448 | sg->length -= qc->pad_len; |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 4449 | if (sg->length == 0) |
| 4450 | trim_sg = 1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4451 | |
| 4452 | DPRINTK("padding done, sg->length=%u pad_len=%u\n", |
| 4453 | sg->length, qc->pad_len); |
| 4454 | } |
| 4455 | |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 4456 | if (trim_sg) { |
| 4457 | qc->n_elem--; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4458 | goto skip_map; |
| 4459 | } |
| 4460 | |
Brian King | 2f1f610 | 2006-03-23 17:30:15 -0600 | [diff] [blame] | 4461 | dma_address = dma_map_single(ap->dev, qc->buf_virt, |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 4462 | sg->length, dir); |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 4463 | if (dma_mapping_error(dma_address)) { |
| 4464 | /* restore sg */ |
| 4465 | sg->length += qc->pad_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | return -1; |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 4467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | |
| 4469 | sg_dma_address(sg) = dma_address; |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 4470 | sg_dma_len(sg) = sg->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4471 | |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 4472 | skip_map: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), |
| 4474 | qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 4475 | |
| 4476 | return 0; |
| 4477 | } |
| 4478 | |
| 4479 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4480 | * ata_sg_setup - DMA-map the scatter-gather table associated with a command. |
| 4481 | * @qc: Command with scatter-gather table to be mapped. |
| 4482 | * |
| 4483 | * DMA-map the scatter-gather table associated with queued_cmd @qc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | * |
| 4485 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4486 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | * |
| 4488 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4489 | * Zero on success, negative on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | * |
| 4491 | */ |
| 4492 | |
| 4493 | static int ata_sg_setup(struct ata_queued_cmd *qc) |
| 4494 | { |
| 4495 | struct ata_port *ap = qc->ap; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4496 | struct scatterlist *sg = qc->__sg; |
| 4497 | struct scatterlist *lsg = &sg[qc->n_elem - 1]; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4498 | int n_elem, pre_n_elem, dir, trim_sg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 4500 | VPRINTK("ENTER, ata%u\n", ap->print_id); |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4501 | WARN_ON(!(qc->flags & ATA_QCFLAG_SG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4503 | /* we must lengthen transfers to end on a 32-bit boundary */ |
| 4504 | qc->pad_len = lsg->length & 3; |
| 4505 | if (qc->pad_len) { |
| 4506 | void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); |
| 4507 | struct scatterlist *psg = &qc->pad_sgent; |
| 4508 | unsigned int offset; |
| 4509 | |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4510 | WARN_ON(qc->dev->class != ATA_DEV_ATAPI); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4511 | |
| 4512 | memset(pad_buf, 0, ATA_DMA_PAD_SZ); |
| 4513 | |
| 4514 | /* |
| 4515 | * psg->page/offset are used to copy to-be-written |
| 4516 | * data in this function or read data in ata_sg_clean. |
| 4517 | */ |
| 4518 | offset = lsg->offset + lsg->length - qc->pad_len; |
| 4519 | psg->page = nth_page(lsg->page, offset >> PAGE_SHIFT); |
| 4520 | psg->offset = offset_in_page(offset); |
| 4521 | |
| 4522 | if (qc->tf.flags & ATA_TFLAG_WRITE) { |
| 4523 | void *addr = kmap_atomic(psg->page, KM_IRQ0); |
| 4524 | memcpy(pad_buf, addr + psg->offset, qc->pad_len); |
Mark Lord | dfa1598 | 2005-12-12 23:19:28 -0500 | [diff] [blame] | 4525 | kunmap_atomic(addr, KM_IRQ0); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | sg_dma_address(psg) = ap->pad_dma + (qc->tag * ATA_DMA_PAD_SZ); |
| 4529 | sg_dma_len(psg) = ATA_DMA_PAD_SZ; |
| 4530 | /* trim last sg */ |
| 4531 | lsg->length -= qc->pad_len; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4532 | if (lsg->length == 0) |
| 4533 | trim_sg = 1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4534 | |
| 4535 | DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n", |
| 4536 | qc->n_elem - 1, lsg->length, qc->pad_len); |
| 4537 | } |
| 4538 | |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4539 | pre_n_elem = qc->n_elem; |
| 4540 | if (trim_sg && pre_n_elem) |
| 4541 | pre_n_elem--; |
| 4542 | |
| 4543 | if (!pre_n_elem) { |
| 4544 | n_elem = 0; |
| 4545 | goto skip_map; |
| 4546 | } |
| 4547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | dir = qc->dma_dir; |
Brian King | 2f1f610 | 2006-03-23 17:30:15 -0600 | [diff] [blame] | 4549 | n_elem = dma_map_sg(ap->dev, sg, pre_n_elem, dir); |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 4550 | if (n_elem < 1) { |
| 4551 | /* restore last sg */ |
| 4552 | lsg->length += qc->pad_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | return -1; |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 4554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4555 | |
| 4556 | DPRINTK("%d sg elements mapped\n", n_elem); |
| 4557 | |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 4558 | skip_map: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4559 | qc->n_elem = n_elem; |
| 4560 | |
| 4561 | return 0; |
| 4562 | } |
| 4563 | |
| 4564 | /** |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4565 | * swap_buf_le16 - swap halves of 16-bit words in place |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4566 | * @buf: Buffer to swap |
| 4567 | * @buf_words: Number of 16-bit words in buffer. |
| 4568 | * |
| 4569 | * Swap halves of 16-bit words if needed to convert from |
| 4570 | * little-endian byte order to native cpu byte order, or |
| 4571 | * vice-versa. |
| 4572 | * |
| 4573 | * LOCKING: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 4574 | * Inherited from caller. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4575 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4576 | void swap_buf_le16(u16 *buf, unsigned int buf_words) |
| 4577 | { |
| 4578 | #ifdef __BIG_ENDIAN |
| 4579 | unsigned int i; |
| 4580 | |
| 4581 | for (i = 0; i < buf_words; i++) |
| 4582 | buf[i] = le16_to_cpu(buf[i]); |
| 4583 | #endif /* __BIG_ENDIAN */ |
| 4584 | } |
| 4585 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4586 | /** |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4587 | * ata_data_xfer - Transfer data by PIO |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4588 | * @adev: device to target |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4589 | * @buf: data buffer |
| 4590 | * @buflen: buffer length |
Jeff Garzik | 344baba | 2005-09-07 01:15:17 -0400 | [diff] [blame] | 4591 | * @write_data: read/write |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4592 | * |
| 4593 | * Transfer data from/to the device data register by PIO. |
| 4594 | * |
| 4595 | * LOCKING: |
| 4596 | * Inherited from caller. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4597 | */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4598 | void ata_data_xfer(struct ata_device *adev, unsigned char *buf, |
| 4599 | unsigned int buflen, int write_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4601 | struct ata_port *ap = adev->link->ap; |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4602 | unsigned int words = buflen >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4604 | /* Transfer multiple of 2 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | if (write_data) |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4606 | iowrite16_rep(ap->ioaddr.data_addr, buf, words); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | else |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4608 | ioread16_rep(ap->ioaddr.data_addr, buf, words); |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4609 | |
| 4610 | /* Transfer trailing 1 byte, if any. */ |
| 4611 | if (unlikely(buflen & 0x01)) { |
| 4612 | u16 align_buf[1] = { 0 }; |
| 4613 | unsigned char *trailing_buf = buf + buflen - 1; |
| 4614 | |
| 4615 | if (write_data) { |
| 4616 | memcpy(align_buf, trailing_buf, 1); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4617 | iowrite16(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr); |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4618 | } else { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4619 | align_buf[0] = cpu_to_le16(ioread16(ap->ioaddr.data_addr)); |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4620 | memcpy(trailing_buf, align_buf, 1); |
| 4621 | } |
| 4622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4625 | /** |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4626 | * ata_data_xfer_noirq - Transfer data by PIO |
Alan Cox | 75e9958 | 2006-05-24 14:14:41 +0100 | [diff] [blame] | 4627 | * @adev: device to target |
| 4628 | * @buf: data buffer |
| 4629 | * @buflen: buffer length |
| 4630 | * @write_data: read/write |
| 4631 | * |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 4632 | * Transfer data from/to the device data register by PIO. Do the |
Alan Cox | 75e9958 | 2006-05-24 14:14:41 +0100 | [diff] [blame] | 4633 | * transfer with interrupts disabled. |
| 4634 | * |
| 4635 | * LOCKING: |
| 4636 | * Inherited from caller. |
| 4637 | */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4638 | void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf, |
| 4639 | unsigned int buflen, int write_data) |
Alan Cox | 75e9958 | 2006-05-24 14:14:41 +0100 | [diff] [blame] | 4640 | { |
| 4641 | unsigned long flags; |
| 4642 | local_irq_save(flags); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 4643 | ata_data_xfer(adev, buf, buflen, write_data); |
Alan Cox | 75e9958 | 2006-05-24 14:14:41 +0100 | [diff] [blame] | 4644 | local_irq_restore(flags); |
| 4645 | } |
| 4646 | |
| 4647 | |
| 4648 | /** |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4649 | * ata_pio_sector - Transfer a sector of data. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4650 | * @qc: Command on going |
| 4651 | * |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4652 | * Transfer qc->sect_size bytes of data from/to the ATA device. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4653 | * |
| 4654 | * LOCKING: |
| 4655 | * Inherited from caller. |
| 4656 | */ |
| 4657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | static void ata_pio_sector(struct ata_queued_cmd *qc) |
| 4659 | { |
| 4660 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4661 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4662 | struct ata_port *ap = qc->ap; |
| 4663 | struct page *page; |
| 4664 | unsigned int offset; |
| 4665 | unsigned char *buf; |
| 4666 | |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4667 | if (qc->curbytes == qc->nbytes - qc->sect_size) |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 4668 | ap->hsm_task_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4669 | |
| 4670 | page = sg[qc->cursg].page; |
Tejun Heo | 726f078 | 2007-01-03 17:30:39 +0900 | [diff] [blame] | 4671 | offset = sg[qc->cursg].offset + qc->cursg_ofs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4672 | |
| 4673 | /* get the current page and offset */ |
| 4674 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 4675 | offset %= PAGE_SIZE; |
| 4676 | |
Albert Lee | 7282aa4 | 2005-10-09 09:46:07 -0400 | [diff] [blame] | 4677 | DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 4678 | |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4679 | if (PageHighMem(page)) { |
| 4680 | unsigned long flags; |
Albert Lee | 7282aa4 | 2005-10-09 09:46:07 -0400 | [diff] [blame] | 4681 | |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4682 | /* FIXME: use a bounce buffer */ |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4683 | local_irq_save(flags); |
| 4684 | buf = kmap_atomic(page, KM_IRQ0); |
Albert Lee | 083958d | 2005-10-09 09:47:31 -0400 | [diff] [blame] | 4685 | |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4686 | /* do the actual data transfer */ |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4687 | ap->ops->data_xfer(qc->dev, buf + offset, qc->sect_size, do_write); |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4688 | |
| 4689 | kunmap_atomic(buf, KM_IRQ0); |
| 4690 | local_irq_restore(flags); |
| 4691 | } else { |
| 4692 | buf = page_address(page); |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4693 | ap->ops->data_xfer(qc->dev, buf + offset, qc->sect_size, do_write); |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4696 | qc->curbytes += qc->sect_size; |
| 4697 | qc->cursg_ofs += qc->sect_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | |
Tejun Heo | 726f078 | 2007-01-03 17:30:39 +0900 | [diff] [blame] | 4699 | if (qc->cursg_ofs == (&sg[qc->cursg])->length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | qc->cursg++; |
| 4701 | qc->cursg_ofs = 0; |
| 4702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4703 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4705 | /** |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4706 | * ata_pio_sectors - Transfer one or many sectors. |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 4707 | * @qc: Command on going |
| 4708 | * |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4709 | * Transfer one or many sectors of data from/to the |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 4710 | * ATA device for the DRQ request. |
| 4711 | * |
| 4712 | * LOCKING: |
| 4713 | * Inherited from caller. |
| 4714 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 4716 | static void ata_pio_sectors(struct ata_queued_cmd *qc) |
| 4717 | { |
| 4718 | if (is_multi_taskfile(&qc->tf)) { |
| 4719 | /* READ/WRITE MULTIPLE */ |
| 4720 | unsigned int nsect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4721 | |
Jeff Garzik | 587005d | 2006-02-11 18:17:32 -0500 | [diff] [blame] | 4722 | WARN_ON(qc->dev->multi_count == 0); |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 4723 | |
Mark Lord | 5a5dbd1 | 2007-03-16 10:22:26 -0400 | [diff] [blame] | 4724 | nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, |
Tejun Heo | 726f078 | 2007-01-03 17:30:39 +0900 | [diff] [blame] | 4725 | qc->dev->multi_count); |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 4726 | while (nsect--) |
| 4727 | ata_pio_sector(qc); |
| 4728 | } else |
| 4729 | ata_pio_sector(qc); |
Albert Lee | 4cc980b | 2007-08-15 03:19:45 -0400 | [diff] [blame] | 4730 | |
| 4731 | ata_altstatus(qc->ap); /* flush */ |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | /** |
Albert Lee | c71c185 | 2005-10-04 06:03:45 -0400 | [diff] [blame] | 4735 | * atapi_send_cdb - Write CDB bytes to hardware |
| 4736 | * @ap: Port to which ATAPI device is attached. |
| 4737 | * @qc: Taskfile currently active |
| 4738 | * |
| 4739 | * When device has indicated its readiness to accept |
| 4740 | * a CDB, this function is called. Send the CDB. |
| 4741 | * |
| 4742 | * LOCKING: |
| 4743 | * caller. |
| 4744 | */ |
| 4745 | |
| 4746 | static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc) |
| 4747 | { |
| 4748 | /* send SCSI cdb */ |
| 4749 | DPRINTK("send cdb\n"); |
Jeff Garzik | db024d5 | 2006-02-13 00:23:57 -0500 | [diff] [blame] | 4750 | WARN_ON(qc->dev->cdb_len < 12); |
Albert Lee | c71c185 | 2005-10-04 06:03:45 -0400 | [diff] [blame] | 4751 | |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4752 | ap->ops->data_xfer(qc->dev, qc->cdb, qc->dev->cdb_len, 1); |
Albert Lee | c71c185 | 2005-10-04 06:03:45 -0400 | [diff] [blame] | 4753 | ata_altstatus(ap); /* flush */ |
| 4754 | |
| 4755 | switch (qc->tf.protocol) { |
| 4756 | case ATA_PROT_ATAPI: |
| 4757 | ap->hsm_task_state = HSM_ST; |
| 4758 | break; |
| 4759 | case ATA_PROT_ATAPI_NODATA: |
| 4760 | ap->hsm_task_state = HSM_ST_LAST; |
| 4761 | break; |
| 4762 | case ATA_PROT_ATAPI_DMA: |
| 4763 | ap->hsm_task_state = HSM_ST_LAST; |
| 4764 | /* initiate bmdma */ |
| 4765 | ap->ops->bmdma_start(qc); |
| 4766 | break; |
| 4767 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | } |
| 4769 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4770 | /** |
| 4771 | * __atapi_pio_bytes - Transfer data from/to the ATAPI device. |
| 4772 | * @qc: Command on going |
| 4773 | * @bytes: number of bytes |
| 4774 | * |
| 4775 | * Transfer Transfer data from/to the ATAPI device. |
| 4776 | * |
| 4777 | * LOCKING: |
| 4778 | * Inherited from caller. |
| 4779 | * |
| 4780 | */ |
| 4781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4782 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) |
| 4783 | { |
| 4784 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4785 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | struct ata_port *ap = qc->ap; |
| 4787 | struct page *page; |
| 4788 | unsigned char *buf; |
| 4789 | unsigned int offset, count; |
| 4790 | |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4791 | if (qc->curbytes + bytes >= qc->nbytes) |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 4792 | ap->hsm_task_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | |
| 4794 | next_sg: |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4795 | if (unlikely(qc->cursg >= qc->n_elem)) { |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 4796 | /* |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4797 | * The end of qc->sg is reached and the device expects |
| 4798 | * more data to transfer. In order not to overrun qc->sg |
| 4799 | * and fulfill length specified in the byte count register, |
| 4800 | * - for read case, discard trailing data from the device |
| 4801 | * - for write case, padding zero data to the device |
| 4802 | */ |
| 4803 | u16 pad_buf[1] = { 0 }; |
| 4804 | unsigned int words = bytes >> 1; |
| 4805 | unsigned int i; |
| 4806 | |
| 4807 | if (words) /* warning if bytes > 1 */ |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 4808 | ata_dev_printk(qc->dev, KERN_WARNING, |
| 4809 | "%u bytes trailing data\n", bytes); |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4810 | |
| 4811 | for (i = 0; i < words; i++) |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4812 | ap->ops->data_xfer(qc->dev, (unsigned char*)pad_buf, 2, do_write); |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4813 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 4814 | ap->hsm_task_state = HSM_ST_LAST; |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4815 | return; |
| 4816 | } |
| 4817 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4818 | sg = &qc->__sg[qc->cursg]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4820 | page = sg->page; |
| 4821 | offset = sg->offset + qc->cursg_ofs; |
| 4822 | |
| 4823 | /* get the current page and offset */ |
| 4824 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 4825 | offset %= PAGE_SIZE; |
| 4826 | |
Albert Lee | 6952df0 | 2005-06-06 15:56:03 +0800 | [diff] [blame] | 4827 | /* don't overrun current sg */ |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 4828 | count = min(sg->length - qc->cursg_ofs, bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4829 | |
| 4830 | /* don't cross page boundaries */ |
| 4831 | count = min(count, (unsigned int)PAGE_SIZE - offset); |
| 4832 | |
Albert Lee | 7282aa4 | 2005-10-09 09:46:07 -0400 | [diff] [blame] | 4833 | DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 4834 | |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4835 | if (PageHighMem(page)) { |
| 4836 | unsigned long flags; |
Albert Lee | 7282aa4 | 2005-10-09 09:46:07 -0400 | [diff] [blame] | 4837 | |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4838 | /* FIXME: use bounce buffer */ |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4839 | local_irq_save(flags); |
| 4840 | buf = kmap_atomic(page, KM_IRQ0); |
Albert Lee | 083958d | 2005-10-09 09:47:31 -0400 | [diff] [blame] | 4841 | |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4842 | /* do the actual data transfer */ |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4843 | ap->ops->data_xfer(qc->dev, buf + offset, count, do_write); |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4844 | |
| 4845 | kunmap_atomic(buf, KM_IRQ0); |
| 4846 | local_irq_restore(flags); |
| 4847 | } else { |
| 4848 | buf = page_address(page); |
Alan Cox | a6b2c5d | 2006-05-22 16:59:59 +0100 | [diff] [blame] | 4849 | ap->ops->data_xfer(qc->dev, buf + offset, count, do_write); |
Albert Lee | 91b8b31 | 2005-10-09 09:48:44 -0400 | [diff] [blame] | 4850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | |
| 4852 | bytes -= count; |
| 4853 | qc->curbytes += count; |
| 4854 | qc->cursg_ofs += count; |
| 4855 | |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 4856 | if (qc->cursg_ofs == sg->length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | qc->cursg++; |
| 4858 | qc->cursg_ofs = 0; |
| 4859 | } |
| 4860 | |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 4861 | if (bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | goto next_sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4863 | } |
| 4864 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4865 | /** |
| 4866 | * atapi_pio_bytes - Transfer data from/to the ATAPI device. |
| 4867 | * @qc: Command on going |
| 4868 | * |
| 4869 | * Transfer Transfer data from/to the ATAPI device. |
| 4870 | * |
| 4871 | * LOCKING: |
| 4872 | * Inherited from caller. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4873 | */ |
| 4874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4875 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) |
| 4876 | { |
| 4877 | struct ata_port *ap = qc->ap; |
| 4878 | struct ata_device *dev = qc->dev; |
| 4879 | unsigned int ireason, bc_lo, bc_hi, bytes; |
| 4880 | int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; |
| 4881 | |
Albert Lee | eec4c3f | 2006-05-18 17:51:10 +0800 | [diff] [blame] | 4882 | /* Abuse qc->result_tf for temp storage of intermediate TF |
| 4883 | * here to save some kernel stack usage. |
| 4884 | * For normal completion, qc->result_tf is not relevant. For |
| 4885 | * error, qc->result_tf is later overwritten by ata_qc_complete(). |
| 4886 | * So, the correctness of qc->result_tf is not affected. |
| 4887 | */ |
| 4888 | ap->ops->tf_read(ap, &qc->result_tf); |
| 4889 | ireason = qc->result_tf.nsect; |
| 4890 | bc_lo = qc->result_tf.lbam; |
| 4891 | bc_hi = qc->result_tf.lbah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | bytes = (bc_hi << 8) | bc_lo; |
| 4893 | |
| 4894 | /* shall be cleared to zero, indicating xfer of data */ |
| 4895 | if (ireason & (1 << 0)) |
| 4896 | goto err_out; |
| 4897 | |
| 4898 | /* make sure transfer direction matches expected */ |
| 4899 | i_write = ((ireason & (1 << 1)) == 0) ? 1 : 0; |
| 4900 | if (do_write != i_write) |
| 4901 | goto err_out; |
| 4902 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 4903 | VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 4904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4905 | __atapi_pio_bytes(qc, bytes); |
Albert Lee | 4cc980b | 2007-08-15 03:19:45 -0400 | [diff] [blame] | 4906 | ata_altstatus(ap); /* flush */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | |
| 4908 | return; |
| 4909 | |
| 4910 | err_out: |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 4911 | ata_dev_printk(dev, KERN_INFO, "ATAPI check failed\n"); |
Tejun Heo | 11a56d2 | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4912 | qc->err_mask |= AC_ERR_HSM; |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 4913 | ap->hsm_task_state = HSM_ST_ERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | /** |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4917 | * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue. |
| 4918 | * @ap: the target ata_port |
| 4919 | * @qc: qc on going |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4920 | * |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4921 | * RETURNS: |
| 4922 | * 1 if ok in workqueue, 0 otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4923 | */ |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4924 | |
| 4925 | static inline int ata_hsm_ok_in_wq(struct ata_port *ap, struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | { |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4927 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 4928 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4930 | if (ap->hsm_task_state == HSM_ST_FIRST) { |
| 4931 | if (qc->tf.protocol == ATA_PROT_PIO && |
| 4932 | (qc->tf.flags & ATA_TFLAG_WRITE)) |
| 4933 | return 1; |
| 4934 | |
| 4935 | if (is_atapi_taskfile(&qc->tf) && |
| 4936 | !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) |
| 4937 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4940 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 4943 | /** |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4944 | * ata_hsm_qc_complete - finish a qc running on standard HSM |
| 4945 | * @qc: Command to complete |
| 4946 | * @in_wq: 1 if called from workqueue, 0 otherwise |
| 4947 | * |
| 4948 | * Finish @qc which is running on standard HSM. |
| 4949 | * |
| 4950 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4951 | * If @in_wq is zero, spin_lock_irqsave(host lock). |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4952 | * Otherwise, none on entry and grabs host lock. |
| 4953 | */ |
| 4954 | static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq) |
| 4955 | { |
| 4956 | struct ata_port *ap = qc->ap; |
| 4957 | unsigned long flags; |
| 4958 | |
| 4959 | if (ap->ops->error_handler) { |
| 4960 | if (in_wq) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 4961 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4962 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4963 | /* EH might have kicked in while host lock is |
| 4964 | * released. |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4965 | */ |
| 4966 | qc = ata_qc_from_tag(ap, qc->tag); |
| 4967 | if (qc) { |
| 4968 | if (likely(!(qc->err_mask & AC_ERR_HSM))) { |
Akira Iguchi | 8362500 | 2007-01-26 16:27:32 +0900 | [diff] [blame] | 4969 | ap->ops->irq_on(ap); |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4970 | ata_qc_complete(qc); |
| 4971 | } else |
| 4972 | ata_port_freeze(ap); |
| 4973 | } |
| 4974 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 4975 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4976 | } else { |
| 4977 | if (likely(!(qc->err_mask & AC_ERR_HSM))) |
| 4978 | ata_qc_complete(qc); |
| 4979 | else |
| 4980 | ata_port_freeze(ap); |
| 4981 | } |
| 4982 | } else { |
| 4983 | if (in_wq) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 4984 | spin_lock_irqsave(ap->lock, flags); |
Akira Iguchi | 8362500 | 2007-01-26 16:27:32 +0900 | [diff] [blame] | 4985 | ap->ops->irq_on(ap); |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4986 | ata_qc_complete(qc); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 4987 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 4988 | } else |
| 4989 | ata_qc_complete(qc); |
| 4990 | } |
| 4991 | } |
| 4992 | |
| 4993 | /** |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 4994 | * ata_hsm_move - move the HSM to the next state. |
| 4995 | * @ap: the target ata_port |
| 4996 | * @qc: qc on going |
| 4997 | * @status: current device status |
| 4998 | * @in_wq: 1 if called from workqueue, 0 otherwise |
| 4999 | * |
| 5000 | * RETURNS: |
| 5001 | * 1 when poll next status needed, 0 otherwise. |
| 5002 | */ |
Tejun Heo | 9a1004d | 2006-05-31 18:27:52 +0900 | [diff] [blame] | 5003 | int ata_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc, |
| 5004 | u8 status, int in_wq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5005 | { |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5006 | unsigned long flags = 0; |
| 5007 | int poll_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5008 | |
Albert Lee | 6912ccd | 2006-03-25 17:45:49 +0800 | [diff] [blame] | 5009 | WARN_ON((qc->flags & ATA_QCFLAG_ACTIVE) == 0); |
Albert Lee | 0565c26 | 2006-02-13 18:55:25 +0800 | [diff] [blame] | 5010 | |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5011 | /* Make sure ata_qc_issue_prot() does not throw things |
| 5012 | * like DMA polling into the workqueue. Notice that |
| 5013 | * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). |
Albert Lee | 1c84898 | 2005-12-05 15:40:15 +0800 | [diff] [blame] | 5014 | */ |
Albert Lee | c234fb0 | 2006-03-25 17:58:38 +0800 | [diff] [blame] | 5015 | WARN_ON(in_wq != ata_hsm_ok_in_wq(ap, qc)); |
Albert Lee | 1c84898 | 2005-12-05 15:40:15 +0800 | [diff] [blame] | 5016 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5017 | fsm_start: |
Albert Lee | 999bb6f | 2006-03-25 18:07:48 +0800 | [diff] [blame] | 5018 | DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n", |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5019 | ap->print_id, qc->tf.protocol, ap->hsm_task_state, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5021 | switch (ap->hsm_task_state) { |
| 5022 | case HSM_ST_FIRST: |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5023 | /* Send first data block or PACKET CDB */ |
| 5024 | |
| 5025 | /* If polling, we will stay in the work queue after |
| 5026 | * sending the data. Otherwise, interrupt handler |
| 5027 | * takes over after sending the data. |
| 5028 | */ |
| 5029 | poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); |
| 5030 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5031 | /* check device status */ |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5032 | if (unlikely((status & ATA_DRQ) == 0)) { |
| 5033 | /* handle BSY=0, DRQ=0 as error */ |
| 5034 | if (likely(status & (ATA_ERR | ATA_DF))) |
| 5035 | /* device stops HSM for abort/error */ |
| 5036 | qc->err_mask |= AC_ERR_DEV; |
| 5037 | else |
| 5038 | /* HSM violation. Let EH handle this */ |
| 5039 | qc->err_mask |= AC_ERR_HSM; |
| 5040 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5041 | ap->hsm_task_state = HSM_ST_ERR; |
| 5042 | goto fsm_start; |
| 5043 | } |
| 5044 | |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5045 | /* Device should not ask for data transfer (DRQ=1) |
| 5046 | * when it finds something wrong. |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5047 | * We ignore DRQ here and stop the HSM by |
| 5048 | * changing hsm_task_state to HSM_ST_ERR and |
| 5049 | * let the EH abort the command or reset the device. |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5050 | */ |
| 5051 | if (unlikely(status & (ATA_ERR | ATA_DF))) { |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5052 | ata_port_printk(ap, KERN_WARNING, "DRQ=1 with device " |
| 5053 | "error, dev_stat 0x%X\n", status); |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5054 | qc->err_mask |= AC_ERR_HSM; |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5055 | ap->hsm_task_state = HSM_ST_ERR; |
| 5056 | goto fsm_start; |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5057 | } |
| 5058 | |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5059 | /* Send the CDB (atapi) or the first data block (ata pio out). |
| 5060 | * During the state transition, interrupt handler shouldn't |
| 5061 | * be invoked before the data transfer is complete and |
| 5062 | * hsm_task_state is changed. Hence, the following locking. |
| 5063 | */ |
| 5064 | if (in_wq) |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5065 | spin_lock_irqsave(ap->lock, flags); |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5066 | |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5067 | if (qc->tf.protocol == ATA_PROT_PIO) { |
| 5068 | /* PIO data out protocol. |
| 5069 | * send first data block. |
| 5070 | */ |
| 5071 | |
| 5072 | /* ata_pio_sectors() might change the state |
| 5073 | * to HSM_ST_LAST. so, the state is changed here |
| 5074 | * before ata_pio_sectors(). |
| 5075 | */ |
| 5076 | ap->hsm_task_state = HSM_ST; |
| 5077 | ata_pio_sectors(qc); |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5078 | } else |
| 5079 | /* send CDB */ |
| 5080 | atapi_send_cdb(ap, qc); |
| 5081 | |
| 5082 | if (in_wq) |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5083 | spin_unlock_irqrestore(ap->lock, flags); |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5084 | |
| 5085 | /* if polling, ata_pio_task() handles the rest. |
| 5086 | * otherwise, interrupt handler takes over from here. |
| 5087 | */ |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5088 | break; |
| 5089 | |
| 5090 | case HSM_ST: |
| 5091 | /* complete command or read/write the data register */ |
| 5092 | if (qc->tf.protocol == ATA_PROT_ATAPI) { |
| 5093 | /* ATAPI PIO protocol */ |
| 5094 | if ((status & ATA_DRQ) == 0) { |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5095 | /* No more data to transfer or device error. |
| 5096 | * Device error will be tagged in HSM_ST_LAST. |
| 5097 | */ |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5098 | ap->hsm_task_state = HSM_ST_LAST; |
| 5099 | goto fsm_start; |
| 5100 | } |
| 5101 | |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5102 | /* Device should not ask for data transfer (DRQ=1) |
| 5103 | * when it finds something wrong. |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5104 | * We ignore DRQ here and stop the HSM by |
| 5105 | * changing hsm_task_state to HSM_ST_ERR and |
| 5106 | * let the EH abort the command or reset the device. |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5107 | */ |
| 5108 | if (unlikely(status & (ATA_ERR | ATA_DF))) { |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5109 | ata_port_printk(ap, KERN_WARNING, "DRQ=1 with " |
| 5110 | "device error, dev_stat 0x%X\n", |
| 5111 | status); |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5112 | qc->err_mask |= AC_ERR_HSM; |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5113 | ap->hsm_task_state = HSM_ST_ERR; |
| 5114 | goto fsm_start; |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5115 | } |
| 5116 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5117 | atapi_pio_bytes(qc); |
| 5118 | |
| 5119 | if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) |
| 5120 | /* bad ireason reported by device */ |
| 5121 | goto fsm_start; |
| 5122 | |
| 5123 | } else { |
| 5124 | /* ATA PIO protocol */ |
| 5125 | if (unlikely((status & ATA_DRQ) == 0)) { |
| 5126 | /* handle BSY=0, DRQ=0 as error */ |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5127 | if (likely(status & (ATA_ERR | ATA_DF))) |
| 5128 | /* device stops HSM for abort/error */ |
| 5129 | qc->err_mask |= AC_ERR_DEV; |
| 5130 | else |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 5131 | /* HSM violation. Let EH handle this. |
| 5132 | * Phantom devices also trigger this |
| 5133 | * condition. Mark hint. |
| 5134 | */ |
| 5135 | qc->err_mask |= AC_ERR_HSM | |
| 5136 | AC_ERR_NODEV_HINT; |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5137 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5138 | ap->hsm_task_state = HSM_ST_ERR; |
| 5139 | goto fsm_start; |
| 5140 | } |
| 5141 | |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5142 | /* For PIO reads, some devices may ask for |
| 5143 | * data transfer (DRQ=1) alone with ERR=1. |
| 5144 | * We respect DRQ here and transfer one |
| 5145 | * block of junk data before changing the |
| 5146 | * hsm_task_state to HSM_ST_ERR. |
| 5147 | * |
| 5148 | * For PIO writes, ERR=1 DRQ=1 doesn't make |
| 5149 | * sense since the data block has been |
| 5150 | * transferred to the device. |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5151 | */ |
| 5152 | if (unlikely(status & (ATA_ERR | ATA_DF))) { |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5153 | /* data might be corrputed */ |
| 5154 | qc->err_mask |= AC_ERR_DEV; |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5155 | |
| 5156 | if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { |
| 5157 | ata_pio_sectors(qc); |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5158 | status = ata_wait_idle(ap); |
| 5159 | } |
| 5160 | |
Albert Lee | 3655d1d | 2006-05-19 11:43:04 +0800 | [diff] [blame] | 5161 | if (status & (ATA_BUSY | ATA_DRQ)) |
| 5162 | qc->err_mask |= AC_ERR_HSM; |
| 5163 | |
Albert Lee | eee6c32 | 2006-04-01 17:38:43 +0800 | [diff] [blame] | 5164 | /* ata_pio_sectors() might change the |
| 5165 | * state to HSM_ST_LAST. so, the state |
| 5166 | * is changed after ata_pio_sectors(). |
| 5167 | */ |
| 5168 | ap->hsm_task_state = HSM_ST_ERR; |
| 5169 | goto fsm_start; |
Albert Lee | 7160195 | 2006-03-25 18:11:12 +0800 | [diff] [blame] | 5170 | } |
| 5171 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5172 | ata_pio_sectors(qc); |
| 5173 | |
| 5174 | if (ap->hsm_task_state == HSM_ST_LAST && |
| 5175 | (!(qc->tf.flags & ATA_TFLAG_WRITE))) { |
| 5176 | /* all data read */ |
Albert Lee | 52a3220 | 2006-03-25 18:18:15 +0800 | [diff] [blame] | 5177 | status = ata_wait_idle(ap); |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5178 | goto fsm_start; |
| 5179 | } |
| 5180 | } |
| 5181 | |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5182 | poll_next = 1; |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5183 | break; |
| 5184 | |
| 5185 | case HSM_ST_LAST: |
Albert Lee | 6912ccd | 2006-03-25 17:45:49 +0800 | [diff] [blame] | 5186 | if (unlikely(!ata_ok(status))) { |
| 5187 | qc->err_mask |= __ac_err_mask(status); |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5188 | ap->hsm_task_state = HSM_ST_ERR; |
| 5189 | goto fsm_start; |
| 5190 | } |
| 5191 | |
| 5192 | /* no more data to transfer */ |
Albert Lee | 4332a77 | 2006-04-03 17:43:24 +0800 | [diff] [blame] | 5193 | DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n", |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5194 | ap->print_id, qc->dev->devno, status); |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5195 | |
Albert Lee | 6912ccd | 2006-03-25 17:45:49 +0800 | [diff] [blame] | 5196 | WARN_ON(qc->err_mask); |
| 5197 | |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5198 | ap->hsm_task_state = HSM_ST_IDLE; |
| 5199 | |
| 5200 | /* complete taskfile transaction */ |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 5201 | ata_hsm_qc_complete(qc, in_wq); |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5202 | |
| 5203 | poll_next = 0; |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5204 | break; |
| 5205 | |
| 5206 | case HSM_ST_ERR: |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5207 | /* make sure qc->err_mask is available to |
| 5208 | * know what's wrong and recover |
| 5209 | */ |
| 5210 | WARN_ON(qc->err_mask == 0); |
| 5211 | |
| 5212 | ap->hsm_task_state = HSM_ST_IDLE; |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5213 | |
Albert Lee | 999bb6f | 2006-03-25 18:07:48 +0800 | [diff] [blame] | 5214 | /* complete taskfile transaction */ |
Tejun Heo | c17ea20 | 2006-05-15 20:59:29 +0900 | [diff] [blame] | 5215 | ata_hsm_qc_complete(qc, in_wq); |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5216 | |
| 5217 | poll_next = 0; |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5218 | break; |
| 5219 | default: |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5220 | poll_next = 0; |
Albert Lee | 6912ccd | 2006-03-25 17:45:49 +0800 | [diff] [blame] | 5221 | BUG(); |
Albert Lee | e2cec77 | 2006-03-25 17:43:49 +0800 | [diff] [blame] | 5222 | } |
| 5223 | |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5224 | return poll_next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 5227 | static void ata_pio_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 5229 | struct ata_port *ap = |
| 5230 | container_of(work, struct ata_port, port_task.work); |
| 5231 | struct ata_queued_cmd *qc = ap->port_task_data; |
Albert Lee | a1af373 | 2006-03-25 17:50:15 +0800 | [diff] [blame] | 5232 | u8 status; |
| 5233 | int poll_next; |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 5234 | |
| 5235 | fsm_start: |
Albert Lee | a1af373 | 2006-03-25 17:50:15 +0800 | [diff] [blame] | 5236 | WARN_ON(ap->hsm_task_state == HSM_ST_IDLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | |
Albert Lee | a1af373 | 2006-03-25 17:50:15 +0800 | [diff] [blame] | 5238 | /* |
| 5239 | * This is purely heuristic. This is a fast path. |
| 5240 | * Sometimes when we enter, BSY will be cleared in |
| 5241 | * a chk-status or two. If not, the drive is probably seeking |
| 5242 | * or something. Snooze for a couple msecs, then |
| 5243 | * chk-status again. If still busy, queue delayed work. |
| 5244 | */ |
| 5245 | status = ata_busy_wait(ap, ATA_BUSY, 5); |
| 5246 | if (status & ATA_BUSY) { |
| 5247 | msleep(2); |
| 5248 | status = ata_busy_wait(ap, ATA_BUSY, 10); |
| 5249 | if (status & ATA_BUSY) { |
Albert Lee | 31ce6da | 2006-04-03 18:31:44 +0800 | [diff] [blame] | 5250 | ata_port_queue_task(ap, ata_pio_task, qc, ATA_SHORT_PAUSE); |
Albert Lee | a1af373 | 2006-03-25 17:50:15 +0800 | [diff] [blame] | 5251 | return; |
| 5252 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5253 | } |
| 5254 | |
Albert Lee | a1af373 | 2006-03-25 17:50:15 +0800 | [diff] [blame] | 5255 | /* move the HSM */ |
| 5256 | poll_next = ata_hsm_move(ap, qc, status, 1); |
| 5257 | |
| 5258 | /* another command or interrupt handler |
| 5259 | * may be running at this point. |
| 5260 | */ |
| 5261 | if (poll_next) |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 5262 | goto fsm_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5263 | } |
| 5264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5265 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5266 | * ata_qc_new - Request an available ATA command, for queueing |
| 5267 | * @ap: Port associated with device @dev |
| 5268 | * @dev: Device from whom we request an available command structure |
| 5269 | * |
| 5270 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5271 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5272 | */ |
| 5273 | |
| 5274 | static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) |
| 5275 | { |
| 5276 | struct ata_queued_cmd *qc = NULL; |
| 5277 | unsigned int i; |
| 5278 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 5279 | /* no command while frozen */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 5280 | if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 5281 | return NULL; |
| 5282 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 5283 | /* the last tag is reserved for internal command. */ |
| 5284 | for (i = 0; i < ATA_MAX_QUEUE - 1; i++) |
Tejun Heo | 6cec4a3 | 2006-05-15 21:03:41 +0900 | [diff] [blame] | 5285 | if (!test_and_set_bit(i, &ap->qc_allocated)) { |
Tejun Heo | f69499f | 2006-05-15 20:58:03 +0900 | [diff] [blame] | 5286 | qc = __ata_qc_from_tag(ap, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5287 | break; |
| 5288 | } |
| 5289 | |
| 5290 | if (qc) |
| 5291 | qc->tag = i; |
| 5292 | |
| 5293 | return qc; |
| 5294 | } |
| 5295 | |
| 5296 | /** |
| 5297 | * ata_qc_new_init - Request an available ATA command, and initialize it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | * @dev: Device from whom we request an available command structure |
| 5299 | * |
| 5300 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5301 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | */ |
| 5303 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 5304 | struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5305 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5306 | struct ata_port *ap = dev->link->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | struct ata_queued_cmd *qc; |
| 5308 | |
| 5309 | qc = ata_qc_new(ap); |
| 5310 | if (qc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5311 | qc->scsicmd = NULL; |
| 5312 | qc->ap = ap; |
| 5313 | qc->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 5315 | ata_qc_reinit(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | return qc; |
| 5319 | } |
| 5320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | /** |
| 5322 | * ata_qc_free - free unused ata_queued_cmd |
| 5323 | * @qc: Command to complete |
| 5324 | * |
| 5325 | * Designed to free unused ata_queued_cmd object |
| 5326 | * in case something prevents using it. |
| 5327 | * |
| 5328 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5329 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5330 | */ |
| 5331 | void ata_qc_free(struct ata_queued_cmd *qc) |
| 5332 | { |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5333 | struct ata_port *ap = qc->ap; |
| 5334 | unsigned int tag; |
| 5335 | |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 5336 | WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5338 | qc->flags = 0; |
| 5339 | tag = qc->tag; |
| 5340 | if (likely(ata_tag_valid(tag))) { |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5341 | qc->tag = ATA_TAG_POISON; |
Tejun Heo | 6cec4a3 | 2006-05-15 21:03:41 +0900 | [diff] [blame] | 5342 | clear_bit(tag, &ap->qc_allocated); |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5343 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5344 | } |
| 5345 | |
Tejun Heo | 7601442 | 2006-02-11 15:13:49 +0900 | [diff] [blame] | 5346 | void __ata_qc_complete(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | { |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5348 | struct ata_port *ap = qc->ap; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5349 | struct ata_link *link = qc->dev->link; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5350 | |
Tejun Heo | a463147 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 5351 | WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
| 5352 | WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5353 | |
| 5354 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 5355 | ata_sg_clean(qc); |
| 5356 | |
Tejun Heo | 7401abf | 2006-05-15 20:57:32 +0900 | [diff] [blame] | 5357 | /* command should be marked inactive atomically with qc completion */ |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5358 | if (qc->tf.protocol == ATA_PROT_NCQ) |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5359 | link->sactive &= ~(1 << qc->tag); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5360 | else |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5361 | link->active_tag = ATA_TAG_POISON; |
Tejun Heo | 7401abf | 2006-05-15 20:57:32 +0900 | [diff] [blame] | 5362 | |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 5363 | /* atapi: mark qc as inactive to prevent the interrupt handler |
| 5364 | * from completing the command twice later, before the error handler |
| 5365 | * is called. (when rc != 0 and atapi request sense is needed) |
| 5366 | */ |
| 5367 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5368 | ap->qc_active &= ~(1 << qc->tag); |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 5369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | /* call completion callback */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5371 | qc->complete_fn(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | } |
| 5373 | |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5374 | static void fill_result_tf(struct ata_queued_cmd *qc) |
| 5375 | { |
| 5376 | struct ata_port *ap = qc->ap; |
| 5377 | |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5378 | qc->result_tf.flags = qc->tf.flags; |
Mark Lord | 4742d54 | 2007-04-02 16:20:35 -0400 | [diff] [blame] | 5379 | ap->ops->tf_read(ap, &qc->result_tf); |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5380 | } |
| 5381 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5382 | /** |
| 5383 | * ata_qc_complete - Complete an active ATA command |
| 5384 | * @qc: Command to complete |
| 5385 | * @err_mask: ATA Status register contents |
| 5386 | * |
| 5387 | * Indicate to the mid and upper layers that an ATA |
| 5388 | * command has completed, with either an ok or not-ok status. |
| 5389 | * |
| 5390 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5391 | * spin_lock_irqsave(host lock) |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5392 | */ |
| 5393 | void ata_qc_complete(struct ata_queued_cmd *qc) |
| 5394 | { |
| 5395 | struct ata_port *ap = qc->ap; |
| 5396 | |
| 5397 | /* XXX: New EH and old EH use different mechanisms to |
| 5398 | * synchronize EH with regular execution path. |
| 5399 | * |
| 5400 | * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED. |
| 5401 | * Normal execution path is responsible for not accessing a |
| 5402 | * failed qc. libata core enforces the rule by returning NULL |
| 5403 | * from ata_qc_from_tag() for failed qcs. |
| 5404 | * |
| 5405 | * Old EH depends on ata_qc_complete() nullifying completion |
| 5406 | * requests if ATA_QCFLAG_EH_SCHEDULED is set. Old EH does |
| 5407 | * not synchronize with interrupt handler. Only PIO task is |
| 5408 | * taken care of. |
| 5409 | */ |
| 5410 | if (ap->ops->error_handler) { |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 5411 | WARN_ON(ap->pflags & ATA_PFLAG_FROZEN); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5412 | |
| 5413 | if (unlikely(qc->err_mask)) |
| 5414 | qc->flags |= ATA_QCFLAG_FAILED; |
| 5415 | |
| 5416 | if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) { |
| 5417 | if (!ata_tag_internal(qc->tag)) { |
| 5418 | /* always fill result TF for failed qc */ |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5419 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5420 | ata_qc_schedule_eh(qc); |
| 5421 | return; |
| 5422 | } |
| 5423 | } |
| 5424 | |
| 5425 | /* read result TF if requested */ |
| 5426 | if (qc->flags & ATA_QCFLAG_RESULT_TF) |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5427 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5428 | |
| 5429 | __ata_qc_complete(qc); |
| 5430 | } else { |
| 5431 | if (qc->flags & ATA_QCFLAG_EH_SCHEDULED) |
| 5432 | return; |
| 5433 | |
| 5434 | /* read result TF if failed or requested */ |
| 5435 | if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF) |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5436 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5437 | |
| 5438 | __ata_qc_complete(qc); |
| 5439 | } |
| 5440 | } |
| 5441 | |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5442 | /** |
| 5443 | * ata_qc_complete_multiple - Complete multiple qcs successfully |
| 5444 | * @ap: port in question |
| 5445 | * @qc_active: new qc_active mask |
| 5446 | * @finish_qc: LLDD callback invoked before completing a qc |
| 5447 | * |
| 5448 | * Complete in-flight commands. This functions is meant to be |
| 5449 | * called from low-level driver's interrupt routine to complete |
| 5450 | * requests normally. ap->qc_active and @qc_active is compared |
| 5451 | * and commands are completed accordingly. |
| 5452 | * |
| 5453 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5454 | * spin_lock_irqsave(host lock) |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5455 | * |
| 5456 | * RETURNS: |
| 5457 | * Number of completed commands on success, -errno otherwise. |
| 5458 | */ |
| 5459 | int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active, |
| 5460 | void (*finish_qc)(struct ata_queued_cmd *)) |
| 5461 | { |
| 5462 | int nr_done = 0; |
| 5463 | u32 done_mask; |
| 5464 | int i; |
| 5465 | |
| 5466 | done_mask = ap->qc_active ^ qc_active; |
| 5467 | |
| 5468 | if (unlikely(done_mask & qc_active)) { |
| 5469 | ata_port_printk(ap, KERN_ERR, "illegal qc_active transition " |
| 5470 | "(%08x->%08x)\n", ap->qc_active, qc_active); |
| 5471 | return -EINVAL; |
| 5472 | } |
| 5473 | |
| 5474 | for (i = 0; i < ATA_MAX_QUEUE; i++) { |
| 5475 | struct ata_queued_cmd *qc; |
| 5476 | |
| 5477 | if (!(done_mask & (1 << i))) |
| 5478 | continue; |
| 5479 | |
| 5480 | if ((qc = ata_qc_from_tag(ap, i))) { |
| 5481 | if (finish_qc) |
| 5482 | finish_qc(qc); |
| 5483 | ata_qc_complete(qc); |
| 5484 | nr_done++; |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | return nr_done; |
| 5489 | } |
| 5490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | static inline int ata_should_dma_map(struct ata_queued_cmd *qc) |
| 5492 | { |
| 5493 | struct ata_port *ap = qc->ap; |
| 5494 | |
| 5495 | switch (qc->tf.protocol) { |
Tejun Heo | 3dc1d88 | 2006-05-15 21:03:45 +0900 | [diff] [blame] | 5496 | case ATA_PROT_NCQ: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | case ATA_PROT_DMA: |
| 5498 | case ATA_PROT_ATAPI_DMA: |
| 5499 | return 1; |
| 5500 | |
| 5501 | case ATA_PROT_ATAPI: |
| 5502 | case ATA_PROT_PIO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | if (ap->flags & ATA_FLAG_PIO_DMA) |
| 5504 | return 1; |
| 5505 | |
| 5506 | /* fall through */ |
| 5507 | |
| 5508 | default: |
| 5509 | return 0; |
| 5510 | } |
| 5511 | |
| 5512 | /* never reached */ |
| 5513 | } |
| 5514 | |
| 5515 | /** |
| 5516 | * ata_qc_issue - issue taskfile to device |
| 5517 | * @qc: command to issue to device |
| 5518 | * |
| 5519 | * Prepare an ATA command to submission to device. |
| 5520 | * This includes mapping the data into a DMA-able |
| 5521 | * area, filling in the S/G table, and finally |
| 5522 | * writing the taskfile to hardware, starting the command. |
| 5523 | * |
| 5524 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5525 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | */ |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 5527 | void ata_qc_issue(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5528 | { |
| 5529 | struct ata_port *ap = qc->ap; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5530 | struct ata_link *link = qc->dev->link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5532 | /* Make sure only one non-NCQ command is outstanding. The |
| 5533 | * check is skipped for old EH because it reuses active qc to |
| 5534 | * request ATAPI sense. |
| 5535 | */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5536 | WARN_ON(ap->ops->error_handler && ata_tag_valid(link->active_tag)); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5537 | |
| 5538 | if (qc->tf.protocol == ATA_PROT_NCQ) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5539 | WARN_ON(link->sactive & (1 << qc->tag)); |
| 5540 | link->sactive |= 1 << qc->tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5541 | } else { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5542 | WARN_ON(link->sactive); |
| 5543 | link->active_tag = qc->tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5544 | } |
| 5545 | |
Tejun Heo | e4a70e7 | 2006-03-31 20:36:47 +0900 | [diff] [blame] | 5546 | qc->flags |= ATA_QCFLAG_ACTIVE; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5547 | ap->qc_active |= 1 << qc->tag; |
Tejun Heo | e4a70e7 | 2006-03-31 20:36:47 +0900 | [diff] [blame] | 5548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | if (ata_should_dma_map(qc)) { |
| 5550 | if (qc->flags & ATA_QCFLAG_SG) { |
| 5551 | if (ata_sg_setup(qc)) |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5552 | goto sg_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5553 | } else if (qc->flags & ATA_QCFLAG_SINGLE) { |
| 5554 | if (ata_sg_setup_one(qc)) |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5555 | goto sg_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | } |
| 5557 | } else { |
| 5558 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
| 5559 | } |
| 5560 | |
| 5561 | ap->ops->qc_prep(qc); |
| 5562 | |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 5563 | qc->err_mask |= ap->ops->qc_issue(qc); |
| 5564 | if (unlikely(qc->err_mask)) |
| 5565 | goto err; |
| 5566 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5567 | |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5568 | sg_err: |
| 5569 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 5570 | qc->err_mask |= AC_ERR_SYSTEM; |
| 5571 | err: |
| 5572 | ata_qc_complete(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5573 | } |
| 5574 | |
| 5575 | /** |
| 5576 | * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner |
| 5577 | * @qc: command to issue to device |
| 5578 | * |
| 5579 | * Using various libata functions and hooks, this function |
| 5580 | * starts an ATA command. ATA commands are grouped into |
| 5581 | * classes called "protocols", and issuing each type of protocol |
| 5582 | * is slightly different. |
| 5583 | * |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 5584 | * May be used as the qc_issue() entry in ata_port_operations. |
| 5585 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5586 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5587 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5588 | * |
| 5589 | * RETURNS: |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5590 | * Zero on success, AC_ERR_* mask on failure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | */ |
| 5592 | |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5593 | unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5594 | { |
| 5595 | struct ata_port *ap = qc->ap; |
| 5596 | |
Albert Lee | e50362e | 2005-09-27 17:39:50 +0800 | [diff] [blame] | 5597 | /* Use polling pio if the LLD doesn't handle |
| 5598 | * interrupt driven pio and atapi CDB interrupt. |
| 5599 | */ |
| 5600 | if (ap->flags & ATA_FLAG_PIO_POLLING) { |
| 5601 | switch (qc->tf.protocol) { |
| 5602 | case ATA_PROT_PIO: |
Albert Lee | e3472cb | 2006-12-07 11:37:58 +0800 | [diff] [blame] | 5603 | case ATA_PROT_NODATA: |
Albert Lee | e50362e | 2005-09-27 17:39:50 +0800 | [diff] [blame] | 5604 | case ATA_PROT_ATAPI: |
| 5605 | case ATA_PROT_ATAPI_NODATA: |
| 5606 | qc->tf.flags |= ATA_TFLAG_POLLING; |
| 5607 | break; |
| 5608 | case ATA_PROT_ATAPI_DMA: |
| 5609 | if (qc->dev->flags & ATA_DFLAG_CDB_INTR) |
Albert Lee | 3a77827 | 2006-06-22 13:00:25 +0800 | [diff] [blame] | 5610 | /* see ata_dma_blacklisted() */ |
Albert Lee | e50362e | 2005-09-27 17:39:50 +0800 | [diff] [blame] | 5611 | BUG(); |
| 5612 | break; |
| 5613 | default: |
| 5614 | break; |
| 5615 | } |
| 5616 | } |
| 5617 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5618 | /* select the device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5619 | ata_dev_select(ap, qc->dev->devno, 1, 0); |
| 5620 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5621 | /* start the command */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | switch (qc->tf.protocol) { |
| 5623 | case ATA_PROT_NODATA: |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5624 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 5625 | ata_qc_set_polling(qc); |
| 5626 | |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 5627 | ata_tf_to_host(ap, &qc->tf); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5628 | ap->hsm_task_state = HSM_ST_LAST; |
| 5629 | |
| 5630 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
Albert Lee | 31ce6da | 2006-04-03 18:31:44 +0800 | [diff] [blame] | 5631 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | break; |
| 5634 | |
| 5635 | case ATA_PROT_DMA: |
Jeff Garzik | 587005d | 2006-02-11 18:17:32 -0500 | [diff] [blame] | 5636 | WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5638 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
| 5639 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
| 5640 | ap->ops->bmdma_start(qc); /* initiate bmdma */ |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5641 | ap->hsm_task_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5642 | break; |
| 5643 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5644 | case ATA_PROT_PIO: |
| 5645 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 5646 | ata_qc_set_polling(qc); |
| 5647 | |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 5648 | ata_tf_to_host(ap, &qc->tf); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5649 | |
Albert Lee | 54f0038 | 2005-09-30 19:14:19 +0800 | [diff] [blame] | 5650 | if (qc->tf.flags & ATA_TFLAG_WRITE) { |
| 5651 | /* PIO data out protocol */ |
| 5652 | ap->hsm_task_state = HSM_ST_FIRST; |
Albert Lee | 31ce6da | 2006-04-03 18:31:44 +0800 | [diff] [blame] | 5653 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
Albert Lee | 54f0038 | 2005-09-30 19:14:19 +0800 | [diff] [blame] | 5654 | |
| 5655 | /* always send first data block using |
Albert Lee | e27486d | 2005-11-01 19:24:49 +0800 | [diff] [blame] | 5656 | * the ata_pio_task() codepath. |
Albert Lee | 54f0038 | 2005-09-30 19:14:19 +0800 | [diff] [blame] | 5657 | */ |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5658 | } else { |
Albert Lee | 54f0038 | 2005-09-30 19:14:19 +0800 | [diff] [blame] | 5659 | /* PIO data in protocol */ |
| 5660 | ap->hsm_task_state = HSM_ST; |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5661 | |
Albert Lee | 54f0038 | 2005-09-30 19:14:19 +0800 | [diff] [blame] | 5662 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
Albert Lee | 31ce6da | 2006-04-03 18:31:44 +0800 | [diff] [blame] | 5663 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5664 | |
Albert Lee | 54f0038 | 2005-09-30 19:14:19 +0800 | [diff] [blame] | 5665 | /* if polling, ata_pio_task() handles the rest. |
| 5666 | * otherwise, interrupt handler takes over from here. |
| 5667 | */ |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5668 | } |
| 5669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | break; |
| 5671 | |
| 5672 | case ATA_PROT_ATAPI: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5673 | case ATA_PROT_ATAPI_NODATA: |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5674 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 5675 | ata_qc_set_polling(qc); |
| 5676 | |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 5677 | ata_tf_to_host(ap, &qc->tf); |
Jeff Garzik | f6ef65e | 2006-01-27 02:45:00 -0500 | [diff] [blame] | 5678 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5679 | ap->hsm_task_state = HSM_ST_FIRST; |
| 5680 | |
| 5681 | /* send cdb by polling if no cdb interrupt */ |
| 5682 | if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || |
| 5683 | (qc->tf.flags & ATA_TFLAG_POLLING)) |
Albert Lee | 31ce6da | 2006-04-03 18:31:44 +0800 | [diff] [blame] | 5684 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5685 | break; |
| 5686 | |
| 5687 | case ATA_PROT_ATAPI_DMA: |
Jeff Garzik | 587005d | 2006-02-11 18:17:32 -0500 | [diff] [blame] | 5688 | WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5690 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
| 5691 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5692 | ap->hsm_task_state = HSM_ST_FIRST; |
| 5693 | |
| 5694 | /* send cdb by polling if no cdb interrupt */ |
| 5695 | if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) |
Albert Lee | 31ce6da | 2006-04-03 18:31:44 +0800 | [diff] [blame] | 5696 | ata_port_queue_task(ap, ata_pio_task, qc, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | break; |
| 5698 | |
| 5699 | default: |
| 5700 | WARN_ON(1); |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 5701 | return AC_ERR_SYSTEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | } |
| 5703 | |
| 5704 | return 0; |
| 5705 | } |
| 5706 | |
| 5707 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5708 | * ata_host_intr - Handle host interrupt for given (port, task) |
| 5709 | * @ap: Port on which interrupt arrived (possibly...) |
| 5710 | * @qc: Taskfile currently active in engine |
| 5711 | * |
| 5712 | * Handle host interrupt for given queued command. Currently, |
| 5713 | * only DMA interrupts are handled. All other commands are |
| 5714 | * handled via polling with interrupts disabled (nIEN bit). |
| 5715 | * |
| 5716 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5717 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5718 | * |
| 5719 | * RETURNS: |
| 5720 | * One if interrupt was handled, zero if not (shared irq). |
| 5721 | */ |
| 5722 | |
| 5723 | inline unsigned int ata_host_intr (struct ata_port *ap, |
| 5724 | struct ata_queued_cmd *qc) |
| 5725 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5726 | struct ata_eh_info *ehi = &ap->link.eh_info; |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5727 | u8 status, host_stat = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5728 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5729 | VPRINTK("ata%u: protocol %d task_state %d\n", |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5730 | ap->print_id, qc->tf.protocol, ap->hsm_task_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5731 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5732 | /* Check whether we are expecting interrupt in this state */ |
| 5733 | switch (ap->hsm_task_state) { |
| 5734 | case HSM_ST_FIRST: |
Albert Lee | 6912ccd | 2006-03-25 17:45:49 +0800 | [diff] [blame] | 5735 | /* Some pre-ATAPI-4 devices assert INTRQ |
| 5736 | * at this state when ready to receive CDB. |
| 5737 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5738 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5739 | /* Check the ATA_DFLAG_CDB_INTR flag is enough here. |
| 5740 | * The flag was turned on only for atapi devices. |
| 5741 | * No need to check is_atapi_taskfile(&qc->tf) again. |
| 5742 | */ |
| 5743 | if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5744 | goto idle_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5745 | break; |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5746 | case HSM_ST_LAST: |
| 5747 | if (qc->tf.protocol == ATA_PROT_DMA || |
| 5748 | qc->tf.protocol == ATA_PROT_ATAPI_DMA) { |
| 5749 | /* check status of DMA engine */ |
| 5750 | host_stat = ap->ops->bmdma_status(ap); |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5751 | VPRINTK("ata%u: host_stat 0x%X\n", |
| 5752 | ap->print_id, host_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5753 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5754 | /* if it's not our irq... */ |
| 5755 | if (!(host_stat & ATA_DMA_INTR)) |
| 5756 | goto idle_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5758 | /* before we do anything else, clear DMA-Start bit */ |
| 5759 | ap->ops->bmdma_stop(qc); |
Albert Lee | a4f1661 | 2005-12-26 16:40:53 +0800 | [diff] [blame] | 5760 | |
| 5761 | if (unlikely(host_stat & ATA_DMA_ERR)) { |
| 5762 | /* error when transfering data to/from memory */ |
| 5763 | qc->err_mask |= AC_ERR_HOST_BUS; |
| 5764 | ap->hsm_task_state = HSM_ST_ERR; |
| 5765 | } |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5766 | } |
| 5767 | break; |
| 5768 | case HSM_ST: |
| 5769 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5770 | default: |
| 5771 | goto idle_irq; |
| 5772 | } |
| 5773 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5774 | /* check altstatus */ |
| 5775 | status = ata_altstatus(ap); |
| 5776 | if (status & ATA_BUSY) |
| 5777 | goto idle_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5778 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5779 | /* check main status, clearing INTRQ */ |
| 5780 | status = ata_chk_status(ap); |
| 5781 | if (unlikely(status & ATA_BUSY)) |
| 5782 | goto idle_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5783 | |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5784 | /* ack bmdma irq events */ |
| 5785 | ap->ops->irq_clear(ap); |
| 5786 | |
Albert Lee | bb5cb29 | 2006-03-25 17:48:02 +0800 | [diff] [blame] | 5787 | ata_hsm_move(ap, qc, status, 0); |
Tejun Heo | ea54763 | 2006-11-17 12:06:21 +0900 | [diff] [blame] | 5788 | |
| 5789 | if (unlikely(qc->err_mask) && (qc->tf.protocol == ATA_PROT_DMA || |
| 5790 | qc->tf.protocol == ATA_PROT_ATAPI_DMA)) |
| 5791 | ata_ehi_push_desc(ehi, "BMDMA stat 0x%x", host_stat); |
| 5792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5793 | return 1; /* irq handled */ |
| 5794 | |
| 5795 | idle_irq: |
| 5796 | ap->stats.idle_irq++; |
| 5797 | |
| 5798 | #ifdef ATA_IRQ_TRAP |
| 5799 | if ((ap->stats.idle_irq % 1000) == 0) { |
Jeff Garzik | 6d32d30 | 2007-08-15 05:38:46 -0400 | [diff] [blame] | 5800 | ata_chk_status(ap); |
| 5801 | ap->ops->irq_clear(ap); |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 5802 | ata_port_printk(ap, KERN_WARNING, "irq trap\n"); |
Alan Cox | 23cfce8 | 2006-03-21 16:06:53 +0000 | [diff] [blame] | 5803 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5804 | } |
| 5805 | #endif |
| 5806 | return 0; /* irq not handled */ |
| 5807 | } |
| 5808 | |
| 5809 | /** |
| 5810 | * ata_interrupt - Default ATA host interrupt handler |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5811 | * @irq: irq line (unused) |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5812 | * @dev_instance: pointer to our ata_host information structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5814 | * Default interrupt handler for PCI IDE devices. Calls |
| 5815 | * ata_host_intr() for each port that is not disabled. |
| 5816 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5818 | * Obtains host lock during operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5819 | * |
| 5820 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5821 | * IRQ_NONE or IRQ_HANDLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5822 | */ |
| 5823 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5824 | irqreturn_t ata_interrupt (int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5826 | struct ata_host *host = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | unsigned int i; |
| 5828 | unsigned int handled = 0; |
| 5829 | unsigned long flags; |
| 5830 | |
| 5831 | /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5832 | spin_lock_irqsave(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5834 | for (i = 0; i < host->n_ports; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5835 | struct ata_port *ap; |
| 5836 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5837 | ap = host->ports[i]; |
Tejun Heo | c138950 | 2005-08-22 14:59:24 +0900 | [diff] [blame] | 5838 | if (ap && |
Jeff Garzik | 029f546 | 2006-04-02 10:30:40 -0400 | [diff] [blame] | 5839 | !(ap->flags & ATA_FLAG_DISABLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5840 | struct ata_queued_cmd *qc; |
| 5841 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5842 | qc = ata_qc_from_tag(ap, ap->link.active_tag); |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 5843 | if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) && |
Albert Lee | 21b1ed7 | 2005-04-29 17:34:59 +0800 | [diff] [blame] | 5844 | (qc->flags & ATA_QCFLAG_ACTIVE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5845 | handled |= ata_host_intr(ap, qc); |
| 5846 | } |
| 5847 | } |
| 5848 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5849 | spin_unlock_irqrestore(&host->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | |
| 5851 | return IRQ_RETVAL(handled); |
| 5852 | } |
| 5853 | |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5854 | /** |
| 5855 | * sata_scr_valid - test whether SCRs are accessible |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5856 | * @link: ATA link to test SCR accessibility for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5857 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5858 | * Test whether SCRs are accessible for @link. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5859 | * |
| 5860 | * LOCKING: |
| 5861 | * None. |
| 5862 | * |
| 5863 | * RETURNS: |
| 5864 | * 1 if SCRs are accessible, 0 otherwise. |
| 5865 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5866 | int sata_scr_valid(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5867 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5868 | struct ata_port *ap = link->ap; |
| 5869 | |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 5870 | return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | /** |
| 5874 | * sata_scr_read - read SCR register of the specified port |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5875 | * @link: ATA link to read SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5876 | * @reg: SCR to read |
| 5877 | * @val: Place to store read value |
| 5878 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5879 | * Read SCR register @reg of @link into *@val. This function is |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5880 | * guaranteed to succeed if the cable type of the port is SATA |
| 5881 | * and the port implements ->scr_read. |
| 5882 | * |
| 5883 | * LOCKING: |
| 5884 | * None. |
| 5885 | * |
| 5886 | * RETURNS: |
| 5887 | * 0 on success, negative errno on failure. |
| 5888 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5889 | int sata_scr_read(struct ata_link *link, int reg, u32 *val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5890 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5891 | struct ata_port *ap = link->ap; |
| 5892 | |
| 5893 | if (sata_scr_valid(link)) |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 5894 | return ap->ops->scr_read(ap, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5895 | return -EOPNOTSUPP; |
| 5896 | } |
| 5897 | |
| 5898 | /** |
| 5899 | * sata_scr_write - write SCR register of the specified port |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5900 | * @link: ATA link to write SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5901 | * @reg: SCR to write |
| 5902 | * @val: value to write |
| 5903 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5904 | * Write @val to SCR register @reg of @link. This function is |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5905 | * guaranteed to succeed if the cable type of the port is SATA |
| 5906 | * and the port implements ->scr_read. |
| 5907 | * |
| 5908 | * LOCKING: |
| 5909 | * None. |
| 5910 | * |
| 5911 | * RETURNS: |
| 5912 | * 0 on success, negative errno on failure. |
| 5913 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5914 | int sata_scr_write(struct ata_link *link, int reg, u32 val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5915 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5916 | struct ata_port *ap = link->ap; |
| 5917 | |
| 5918 | if (sata_scr_valid(link)) |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 5919 | return ap->ops->scr_write(ap, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5920 | return -EOPNOTSUPP; |
| 5921 | } |
| 5922 | |
| 5923 | /** |
| 5924 | * sata_scr_write_flush - write SCR register of the specified port and flush |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5925 | * @link: ATA link to write SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5926 | * @reg: SCR to write |
| 5927 | * @val: value to write |
| 5928 | * |
| 5929 | * This function is identical to sata_scr_write() except that this |
| 5930 | * function performs flush after writing to the register. |
| 5931 | * |
| 5932 | * LOCKING: |
| 5933 | * None. |
| 5934 | * |
| 5935 | * RETURNS: |
| 5936 | * 0 on success, negative errno on failure. |
| 5937 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5938 | int sata_scr_write_flush(struct ata_link *link, int reg, u32 val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5939 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5940 | struct ata_port *ap = link->ap; |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 5941 | int rc; |
| 5942 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5943 | if (sata_scr_valid(link)) { |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 5944 | rc = ap->ops->scr_write(ap, reg, val); |
| 5945 | if (rc == 0) |
| 5946 | rc = ap->ops->scr_read(ap, reg, &val); |
| 5947 | return rc; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5948 | } |
| 5949 | return -EOPNOTSUPP; |
| 5950 | } |
| 5951 | |
| 5952 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5953 | * ata_link_online - test whether the given link is online |
| 5954 | * @link: ATA link to test |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5955 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5956 | * Test whether @link is online. Note that this function returns |
| 5957 | * 0 if online status of @link cannot be obtained, so |
| 5958 | * ata_link_online(link) != !ata_link_offline(link). |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5959 | * |
| 5960 | * LOCKING: |
| 5961 | * None. |
| 5962 | * |
| 5963 | * RETURNS: |
| 5964 | * 1 if the port online status is available and online. |
| 5965 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5966 | int ata_link_online(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5967 | { |
| 5968 | u32 sstatus; |
| 5969 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5970 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
| 5971 | (sstatus & 0xf) == 0x3) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5972 | return 1; |
| 5973 | return 0; |
| 5974 | } |
| 5975 | |
| 5976 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5977 | * ata_link_offline - test whether the given link is offline |
| 5978 | * @link: ATA link to test |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5979 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5980 | * Test whether @link is offline. Note that this function |
| 5981 | * returns 0 if offline status of @link cannot be obtained, so |
| 5982 | * ata_link_online(link) != !ata_link_offline(link). |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5983 | * |
| 5984 | * LOCKING: |
| 5985 | * None. |
| 5986 | * |
| 5987 | * RETURNS: |
| 5988 | * 1 if the port offline status is available and offline. |
| 5989 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5990 | int ata_link_offline(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5991 | { |
| 5992 | u32 sstatus; |
| 5993 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5994 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
| 5995 | (sstatus & 0xf) != 0x3) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5996 | return 1; |
| 5997 | return 0; |
| 5998 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 5999 | |
Tejun Heo | 77b08fb | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 6000 | int ata_flush_cache(struct ata_device *dev) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6001 | { |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 6002 | unsigned int err_mask; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6003 | u8 cmd; |
| 6004 | |
| 6005 | if (!ata_try_flush_cache(dev)) |
| 6006 | return 0; |
| 6007 | |
Tejun Heo | 6fc49ad | 2006-11-11 20:10:45 +0900 | [diff] [blame] | 6008 | if (dev->flags & ATA_DFLAG_FLUSH_EXT) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6009 | cmd = ATA_CMD_FLUSH_EXT; |
| 6010 | else |
| 6011 | cmd = ATA_CMD_FLUSH; |
| 6012 | |
Alan Cox | 4f34337 | 2007-08-08 14:30:31 +0100 | [diff] [blame] | 6013 | /* This is wrong. On a failed flush we get back the LBA of the lost |
| 6014 | sector and we should (assuming it wasn't aborted as unknown) issue |
| 6015 | a further flush command to continue the writeback until it |
| 6016 | does not error */ |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 6017 | err_mask = ata_do_simple_cmd(dev, cmd); |
| 6018 | if (err_mask) { |
| 6019 | ata_dev_printk(dev, KERN_ERR, "failed to flush cache\n"); |
| 6020 | return -EIO; |
| 6021 | } |
| 6022 | |
| 6023 | return 0; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6024 | } |
| 6025 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6026 | #ifdef CONFIG_PM |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6027 | static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg, |
| 6028 | unsigned int action, unsigned int ehi_flags, |
| 6029 | int wait) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6030 | { |
| 6031 | unsigned long flags; |
| 6032 | int i, rc; |
| 6033 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6034 | for (i = 0; i < host->n_ports; i++) { |
| 6035 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | e3667eb | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 6036 | struct ata_link *link; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6037 | |
| 6038 | /* Previous resume operation might still be in |
| 6039 | * progress. Wait for PM_PENDING to clear. |
| 6040 | */ |
| 6041 | if (ap->pflags & ATA_PFLAG_PM_PENDING) { |
| 6042 | ata_port_wait_eh(ap); |
| 6043 | WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); |
| 6044 | } |
| 6045 | |
| 6046 | /* request PM ops to EH */ |
| 6047 | spin_lock_irqsave(ap->lock, flags); |
| 6048 | |
| 6049 | ap->pm_mesg = mesg; |
| 6050 | if (wait) { |
| 6051 | rc = 0; |
| 6052 | ap->pm_result = &rc; |
| 6053 | } |
| 6054 | |
| 6055 | ap->pflags |= ATA_PFLAG_PM_PENDING; |
Tejun Heo | e3667eb | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 6056 | __ata_port_for_each_link(link, ap) { |
| 6057 | link->eh_info.action |= action; |
| 6058 | link->eh_info.flags |= ehi_flags; |
| 6059 | } |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6060 | |
| 6061 | ata_port_schedule_eh(ap); |
| 6062 | |
| 6063 | spin_unlock_irqrestore(ap->lock, flags); |
| 6064 | |
| 6065 | /* wait and check result */ |
| 6066 | if (wait) { |
| 6067 | ata_port_wait_eh(ap); |
| 6068 | WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); |
| 6069 | if (rc) |
| 6070 | return rc; |
| 6071 | } |
| 6072 | } |
| 6073 | |
| 6074 | return 0; |
| 6075 | } |
| 6076 | |
| 6077 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6078 | * ata_host_suspend - suspend host |
| 6079 | * @host: host to suspend |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6080 | * @mesg: PM message |
| 6081 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6082 | * Suspend @host. Actual operation is performed by EH. This |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6083 | * function requests EH to perform PM operations and waits for EH |
| 6084 | * to finish. |
| 6085 | * |
| 6086 | * LOCKING: |
| 6087 | * Kernel thread context (may sleep). |
| 6088 | * |
| 6089 | * RETURNS: |
| 6090 | * 0 on success, -errno on failure. |
| 6091 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6092 | int ata_host_suspend(struct ata_host *host, pm_message_t mesg) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6093 | { |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 6094 | int rc; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6095 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6096 | rc = ata_host_request_pm(host, mesg, 0, ATA_EHI_QUIET, 1); |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 6097 | if (rc == 0) |
| 6098 | host->dev->power.power_state = mesg; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6099 | return rc; |
| 6100 | } |
| 6101 | |
| 6102 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6103 | * ata_host_resume - resume host |
| 6104 | * @host: host to resume |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6105 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6106 | * Resume @host. Actual operation is performed by EH. This |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6107 | * function requests EH to perform PM operations and returns. |
| 6108 | * Note that all resume operations are performed parallely. |
| 6109 | * |
| 6110 | * LOCKING: |
| 6111 | * Kernel thread context (may sleep). |
| 6112 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6113 | void ata_host_resume(struct ata_host *host) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6114 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6115 | ata_host_request_pm(host, PMSG_ON, ATA_EH_SOFTRESET, |
| 6116 | ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); |
| 6117 | host->dev->power.power_state = PMSG_ON; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6118 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6119 | #endif |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6120 | |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 6121 | /** |
| 6122 | * ata_port_start - Set port up for dma. |
| 6123 | * @ap: Port to initialize |
| 6124 | * |
| 6125 | * Called just after data structures for each port are |
| 6126 | * initialized. Allocates space for PRD table. |
| 6127 | * |
| 6128 | * May be used as the port_start() entry in ata_port_operations. |
| 6129 | * |
| 6130 | * LOCKING: |
| 6131 | * Inherited from caller. |
| 6132 | */ |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6133 | int ata_port_start(struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6134 | { |
Brian King | 2f1f610 | 2006-03-23 17:30:15 -0600 | [diff] [blame] | 6135 | struct device *dev = ap->dev; |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 6136 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6138 | ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, |
| 6139 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6140 | if (!ap->prd) |
| 6141 | return -ENOMEM; |
| 6142 | |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 6143 | rc = ata_pad_alloc(ap, dev); |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6144 | if (rc) |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 6145 | return rc; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 6146 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6147 | DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd, |
| 6148 | (unsigned long long)ap->prd_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6149 | return 0; |
| 6150 | } |
| 6151 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 6152 | /** |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 6153 | * ata_dev_init - Initialize an ata_device structure |
| 6154 | * @dev: Device structure to initialize |
| 6155 | * |
| 6156 | * Initialize @dev in preparation for probing. |
| 6157 | * |
| 6158 | * LOCKING: |
| 6159 | * Inherited from caller. |
| 6160 | */ |
| 6161 | void ata_dev_init(struct ata_device *dev) |
| 6162 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 6163 | struct ata_link *link = dev->link; |
| 6164 | struct ata_port *ap = link->ap; |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 6165 | unsigned long flags; |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 6166 | |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 6167 | /* SATA spd limit is bound to the first device */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 6168 | link->sata_spd_limit = link->hw_sata_spd_limit; |
| 6169 | link->sata_spd = 0; |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 6170 | |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 6171 | /* High bits of dev->flags are used to record warm plug |
| 6172 | * requests which occur asynchronously. Synchronize using |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6173 | * host lock. |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 6174 | */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6175 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 6176 | dev->flags &= ~ATA_DFLAG_INIT_MASK; |
Tejun Heo | 3dcc323 | 2007-09-03 12:20:11 +0900 | [diff] [blame] | 6177 | dev->horkage = 0; |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6178 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 6179 | |
| 6180 | memset((void *)dev + ATA_DEVICE_CLEAR_OFFSET, 0, |
| 6181 | sizeof(*dev) - ATA_DEVICE_CLEAR_OFFSET); |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 6182 | dev->pio_mask = UINT_MAX; |
| 6183 | dev->mwdma_mask = UINT_MAX; |
| 6184 | dev->udma_mask = UINT_MAX; |
| 6185 | } |
| 6186 | |
| 6187 | /** |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6188 | * ata_link_init - Initialize an ata_link structure |
| 6189 | * @ap: ATA port link is attached to |
| 6190 | * @link: Link structure to initialize |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6191 | * @pmp: Port multiplier port number |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6192 | * |
| 6193 | * Initialize @link. |
| 6194 | * |
| 6195 | * LOCKING: |
| 6196 | * Kernel thread context (may sleep) |
| 6197 | */ |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6198 | static void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp) |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6199 | { |
| 6200 | int i; |
| 6201 | |
| 6202 | /* clear everything except for devices */ |
| 6203 | memset(link, 0, offsetof(struct ata_link, device[0])); |
| 6204 | |
| 6205 | link->ap = ap; |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6206 | link->pmp = pmp; |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6207 | link->active_tag = ATA_TAG_POISON; |
| 6208 | link->hw_sata_spd_limit = UINT_MAX; |
| 6209 | |
| 6210 | /* can't use iterator, ap isn't initialized yet */ |
| 6211 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 6212 | struct ata_device *dev = &link->device[i]; |
| 6213 | |
| 6214 | dev->link = link; |
| 6215 | dev->devno = dev - link->device; |
| 6216 | ata_dev_init(dev); |
| 6217 | } |
| 6218 | } |
| 6219 | |
| 6220 | /** |
| 6221 | * sata_link_init_spd - Initialize link->sata_spd_limit |
| 6222 | * @link: Link to configure sata_spd_limit for |
| 6223 | * |
| 6224 | * Initialize @link->[hw_]sata_spd_limit to the currently |
| 6225 | * configured value. |
| 6226 | * |
| 6227 | * LOCKING: |
| 6228 | * Kernel thread context (may sleep). |
| 6229 | * |
| 6230 | * RETURNS: |
| 6231 | * 0 on success, -errno on failure. |
| 6232 | */ |
| 6233 | static int sata_link_init_spd(struct ata_link *link) |
| 6234 | { |
| 6235 | u32 scontrol, spd; |
| 6236 | int rc; |
| 6237 | |
| 6238 | rc = sata_scr_read(link, SCR_CONTROL, &scontrol); |
| 6239 | if (rc) |
| 6240 | return rc; |
| 6241 | |
| 6242 | spd = (scontrol >> 4) & 0xf; |
| 6243 | if (spd) |
| 6244 | link->hw_sata_spd_limit &= (1 << spd) - 1; |
| 6245 | |
| 6246 | link->sata_spd_limit = link->hw_sata_spd_limit; |
| 6247 | |
| 6248 | return 0; |
| 6249 | } |
| 6250 | |
| 6251 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6252 | * ata_port_alloc - allocate and initialize basic ATA port resources |
| 6253 | * @host: ATA host this allocated port belongs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | * |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6255 | * Allocate and initialize basic ATA port resources. |
| 6256 | * |
| 6257 | * RETURNS: |
| 6258 | * Allocate ATA port on success, NULL on failure. |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 6259 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6260 | * LOCKING: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6261 | * Inherited from calling layer (may sleep). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6262 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6263 | struct ata_port *ata_port_alloc(struct ata_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6264 | { |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6265 | struct ata_port *ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6266 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6267 | DPRINTK("ENTER\n"); |
| 6268 | |
| 6269 | ap = kzalloc(sizeof(*ap), GFP_KERNEL); |
| 6270 | if (!ap) |
| 6271 | return NULL; |
| 6272 | |
Tejun Heo | f4d6d00 | 2007-05-01 11:50:15 +0200 | [diff] [blame] | 6273 | ap->pflags |= ATA_PFLAG_INITIALIZING; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6274 | ap->lock = &host->lock; |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 6275 | ap->flags = ATA_FLAG_DISABLED; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6276 | ap->print_id = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6277 | ap->ctl = ATA_DEVCTL_OBS; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6278 | ap->host = host; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6279 | ap->dev = host->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | ap->last_ctl = 0xFF; |
Borislav Petkov | bd5d825 | 2006-06-11 23:17:01 -0400 | [diff] [blame] | 6281 | |
| 6282 | #if defined(ATA_VERBOSE_DEBUG) |
| 6283 | /* turn on all debugging levels */ |
| 6284 | ap->msg_enable = 0x00FF; |
| 6285 | #elif defined(ATA_DEBUG) |
| 6286 | ap->msg_enable = ATA_MSG_DRV | ATA_MSG_INFO | ATA_MSG_CTL | ATA_MSG_WARN | ATA_MSG_ERR; |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 6287 | #else |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 6288 | ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; |
Borislav Petkov | bd5d825 | 2006-06-11 23:17:01 -0400 | [diff] [blame] | 6289 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 6291 | INIT_DELAYED_WORK(&ap->port_task, NULL); |
| 6292 | INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); |
| 6293 | INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); |
Tejun Heo | a72ec4c | 2006-01-23 13:09:37 +0900 | [diff] [blame] | 6294 | INIT_LIST_HEAD(&ap->eh_done_q); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 6295 | init_waitqueue_head(&ap->eh_wait_q); |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 6296 | init_timer_deferrable(&ap->fastdrain_timer); |
| 6297 | ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; |
| 6298 | ap->fastdrain_timer.data = (unsigned long)ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6299 | |
Tejun Heo | 838df62 | 2006-05-15 20:57:44 +0900 | [diff] [blame] | 6300 | ap->cbl = ATA_CBL_NONE; |
Tejun Heo | 838df62 | 2006-05-15 20:57:44 +0900 | [diff] [blame] | 6301 | |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6302 | ata_link_init(ap, &ap->link, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6303 | |
| 6304 | #ifdef ATA_IRQ_TRAP |
| 6305 | ap->stats.unhandled_irq = 1; |
| 6306 | ap->stats.idle_irq = 1; |
| 6307 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6308 | return ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | } |
| 6310 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6311 | static void ata_host_release(struct device *gendev, void *res) |
| 6312 | { |
| 6313 | struct ata_host *host = dev_get_drvdata(gendev); |
| 6314 | int i; |
| 6315 | |
| 6316 | for (i = 0; i < host->n_ports; i++) { |
| 6317 | struct ata_port *ap = host->ports[i]; |
| 6318 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6319 | if (!ap) |
| 6320 | continue; |
| 6321 | |
| 6322 | if ((host->flags & ATA_HOST_STARTED) && ap->ops->port_stop) |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6323 | ap->ops->port_stop(ap); |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6324 | } |
| 6325 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6326 | if ((host->flags & ATA_HOST_STARTED) && host->ops->host_stop) |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6327 | host->ops->host_stop(host); |
Tejun Heo | 1aa56cc | 2007-02-27 22:33:21 +0900 | [diff] [blame] | 6328 | |
Tejun Heo | 1aa506e | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 6329 | for (i = 0; i < host->n_ports; i++) { |
| 6330 | struct ata_port *ap = host->ports[i]; |
| 6331 | |
Tejun Heo | 4911487 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6332 | if (!ap) |
| 6333 | continue; |
| 6334 | |
| 6335 | if (ap->scsi_host) |
Tejun Heo | 1aa506e | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 6336 | scsi_host_put(ap->scsi_host); |
| 6337 | |
Tejun Heo | 4911487 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6338 | kfree(ap); |
Tejun Heo | 1aa506e | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 6339 | host->ports[i] = NULL; |
| 6340 | } |
| 6341 | |
Tejun Heo | 1aa56cc | 2007-02-27 22:33:21 +0900 | [diff] [blame] | 6342 | dev_set_drvdata(gendev, NULL); |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6343 | } |
| 6344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6345 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6346 | * ata_host_alloc - allocate and init basic ATA host resources |
| 6347 | * @dev: generic device this host is associated with |
| 6348 | * @max_ports: maximum number of ATA ports associated with this host |
| 6349 | * |
| 6350 | * Allocate and initialize basic ATA host resources. LLD calls |
| 6351 | * this function to allocate a host, initializes it fully and |
| 6352 | * attaches it using ata_host_register(). |
| 6353 | * |
| 6354 | * @max_ports ports are allocated and host->n_ports is |
| 6355 | * initialized to @max_ports. The caller is allowed to decrease |
| 6356 | * host->n_ports before calling ata_host_register(). The unused |
| 6357 | * ports will be automatically freed on registration. |
| 6358 | * |
| 6359 | * RETURNS: |
| 6360 | * Allocate ATA host on success, NULL on failure. |
| 6361 | * |
| 6362 | * LOCKING: |
| 6363 | * Inherited from calling layer (may sleep). |
| 6364 | */ |
| 6365 | struct ata_host *ata_host_alloc(struct device *dev, int max_ports) |
| 6366 | { |
| 6367 | struct ata_host *host; |
| 6368 | size_t sz; |
| 6369 | int i; |
| 6370 | |
| 6371 | DPRINTK("ENTER\n"); |
| 6372 | |
| 6373 | if (!devres_open_group(dev, NULL, GFP_KERNEL)) |
| 6374 | return NULL; |
| 6375 | |
| 6376 | /* alloc a container for our list of ATA ports (buses) */ |
| 6377 | sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *); |
| 6378 | /* alloc a container for our list of ATA ports (buses) */ |
| 6379 | host = devres_alloc(ata_host_release, sz, GFP_KERNEL); |
| 6380 | if (!host) |
| 6381 | goto err_out; |
| 6382 | |
| 6383 | devres_add(dev, host); |
| 6384 | dev_set_drvdata(dev, host); |
| 6385 | |
| 6386 | spin_lock_init(&host->lock); |
| 6387 | host->dev = dev; |
| 6388 | host->n_ports = max_ports; |
| 6389 | |
| 6390 | /* allocate ports bound to this host */ |
| 6391 | for (i = 0; i < max_ports; i++) { |
| 6392 | struct ata_port *ap; |
| 6393 | |
| 6394 | ap = ata_port_alloc(host); |
| 6395 | if (!ap) |
| 6396 | goto err_out; |
| 6397 | |
| 6398 | ap->port_no = i; |
| 6399 | host->ports[i] = ap; |
| 6400 | } |
| 6401 | |
| 6402 | devres_remove_group(dev, NULL); |
| 6403 | return host; |
| 6404 | |
| 6405 | err_out: |
| 6406 | devres_release_group(dev, NULL); |
| 6407 | return NULL; |
| 6408 | } |
| 6409 | |
| 6410 | /** |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6411 | * ata_host_alloc_pinfo - alloc host and init with port_info array |
| 6412 | * @dev: generic device this host is associated with |
| 6413 | * @ppi: array of ATA port_info to initialize host with |
| 6414 | * @n_ports: number of ATA ports attached to this host |
| 6415 | * |
| 6416 | * Allocate ATA host and initialize with info from @ppi. If NULL |
| 6417 | * terminated, @ppi may contain fewer entries than @n_ports. The |
| 6418 | * last entry will be used for the remaining ports. |
| 6419 | * |
| 6420 | * RETURNS: |
| 6421 | * Allocate ATA host on success, NULL on failure. |
| 6422 | * |
| 6423 | * LOCKING: |
| 6424 | * Inherited from calling layer (may sleep). |
| 6425 | */ |
| 6426 | struct ata_host *ata_host_alloc_pinfo(struct device *dev, |
| 6427 | const struct ata_port_info * const * ppi, |
| 6428 | int n_ports) |
| 6429 | { |
| 6430 | const struct ata_port_info *pi; |
| 6431 | struct ata_host *host; |
| 6432 | int i, j; |
| 6433 | |
| 6434 | host = ata_host_alloc(dev, n_ports); |
| 6435 | if (!host) |
| 6436 | return NULL; |
| 6437 | |
| 6438 | for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { |
| 6439 | struct ata_port *ap = host->ports[i]; |
| 6440 | |
| 6441 | if (ppi[j]) |
| 6442 | pi = ppi[j++]; |
| 6443 | |
| 6444 | ap->pio_mask = pi->pio_mask; |
| 6445 | ap->mwdma_mask = pi->mwdma_mask; |
| 6446 | ap->udma_mask = pi->udma_mask; |
| 6447 | ap->flags |= pi->flags; |
Tejun Heo | 0c88758 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6448 | ap->link.flags |= pi->link_flags; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6449 | ap->ops = pi->port_ops; |
| 6450 | |
| 6451 | if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) |
| 6452 | host->ops = pi->port_ops; |
| 6453 | if (!host->private_data && pi->private_data) |
| 6454 | host->private_data = pi->private_data; |
| 6455 | } |
| 6456 | |
| 6457 | return host; |
| 6458 | } |
| 6459 | |
| 6460 | /** |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6461 | * ata_host_start - start and freeze ports of an ATA host |
| 6462 | * @host: ATA host to start ports for |
| 6463 | * |
| 6464 | * Start and then freeze ports of @host. Started status is |
| 6465 | * recorded in host->flags, so this function can be called |
| 6466 | * multiple times. Ports are guaranteed to get started only |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6467 | * once. If host->ops isn't initialized yet, its set to the |
| 6468 | * first non-dummy port ops. |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6469 | * |
| 6470 | * LOCKING: |
| 6471 | * Inherited from calling layer (may sleep). |
| 6472 | * |
| 6473 | * RETURNS: |
| 6474 | * 0 if all ports are started successfully, -errno otherwise. |
| 6475 | */ |
| 6476 | int ata_host_start(struct ata_host *host) |
| 6477 | { |
| 6478 | int i, rc; |
| 6479 | |
| 6480 | if (host->flags & ATA_HOST_STARTED) |
| 6481 | return 0; |
| 6482 | |
| 6483 | for (i = 0; i < host->n_ports; i++) { |
| 6484 | struct ata_port *ap = host->ports[i]; |
| 6485 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6486 | if (!host->ops && !ata_port_is_dummy(ap)) |
| 6487 | host->ops = ap->ops; |
| 6488 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6489 | if (ap->ops->port_start) { |
| 6490 | rc = ap->ops->port_start(ap); |
| 6491 | if (rc) { |
| 6492 | ata_port_printk(ap, KERN_ERR, "failed to " |
| 6493 | "start port (errno=%d)\n", rc); |
| 6494 | goto err_out; |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | ata_eh_freeze_port(ap); |
| 6499 | } |
| 6500 | |
| 6501 | host->flags |= ATA_HOST_STARTED; |
| 6502 | return 0; |
| 6503 | |
| 6504 | err_out: |
| 6505 | while (--i >= 0) { |
| 6506 | struct ata_port *ap = host->ports[i]; |
| 6507 | |
| 6508 | if (ap->ops->port_stop) |
| 6509 | ap->ops->port_stop(ap); |
| 6510 | } |
| 6511 | return rc; |
| 6512 | } |
| 6513 | |
| 6514 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6515 | * ata_sas_host_init - Initialize a host struct |
| 6516 | * @host: host to initialize |
| 6517 | * @dev: device host is attached to |
| 6518 | * @flags: host flags |
| 6519 | * @ops: port_ops |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6520 | * |
| 6521 | * LOCKING: |
| 6522 | * PCI/etc. bus probe sem. |
| 6523 | * |
| 6524 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6525 | /* KILLME - the only user left is ipr */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6526 | void ata_host_init(struct ata_host *host, struct device *dev, |
| 6527 | unsigned long flags, const struct ata_port_operations *ops) |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6528 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6529 | spin_lock_init(&host->lock); |
| 6530 | host->dev = dev; |
| 6531 | host->flags = flags; |
| 6532 | host->ops = ops; |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6536 | * ata_host_register - register initialized ATA host |
| 6537 | * @host: ATA host to register |
| 6538 | * @sht: template for SCSI host |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 6539 | * |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6540 | * Register initialized ATA host. @host is allocated using |
| 6541 | * ata_host_alloc() and fully initialized by LLD. This function |
| 6542 | * starts ports, registers @host with ATA and SCSI layers and |
| 6543 | * probe registered devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6544 | * |
| 6545 | * LOCKING: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6546 | * Inherited from calling layer (may sleep). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6547 | * |
| 6548 | * RETURNS: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6549 | * 0 on success, -errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6550 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6551 | int ata_host_register(struct ata_host *host, struct scsi_host_template *sht) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6552 | { |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6553 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6554 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6555 | /* host must have been started */ |
| 6556 | if (!(host->flags & ATA_HOST_STARTED)) { |
| 6557 | dev_printk(KERN_ERR, host->dev, |
| 6558 | "BUG: trying to register unstarted host\n"); |
| 6559 | WARN_ON(1); |
| 6560 | return -EINVAL; |
Alan Cox | 02f076a | 2006-09-26 17:35:32 +0100 | [diff] [blame] | 6561 | } |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6562 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6563 | /* Blow away unused ports. This happens when LLD can't |
| 6564 | * determine the exact number of ports to allocate at |
| 6565 | * allocation time. |
| 6566 | */ |
| 6567 | for (i = host->n_ports; host->ports[i]; i++) |
| 6568 | kfree(host->ports[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6570 | /* give ports names and add SCSI hosts */ |
| 6571 | for (i = 0; i < host->n_ports; i++) |
| 6572 | host->ports[i]->print_id = ata_print_id++; |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6573 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6574 | rc = ata_scsi_add_hosts(host, sht); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6575 | if (rc) |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6576 | return rc; |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6577 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 6578 | /* associate with ACPI nodes */ |
| 6579 | ata_acpi_associate(host); |
| 6580 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6581 | /* set cable, sata_spd_limit and report */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6582 | for (i = 0; i < host->n_ports; i++) { |
| 6583 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6584 | unsigned long xfer_mask; |
| 6585 | |
| 6586 | /* set SATA cable type if still unset */ |
| 6587 | if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) |
| 6588 | ap->cbl = ATA_CBL_SATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6589 | |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 6590 | /* init sata_spd_limit to the current value */ |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6591 | sata_link_init_spd(&ap->link); |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 6592 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6593 | /* print per-port info to dmesg */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6594 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, |
| 6595 | ap->udma_mask); |
| 6596 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6597 | if (!ata_port_is_dummy(ap)) |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6598 | ata_port_printk(ap, KERN_INFO, |
| 6599 | "%cATA max %s %s\n", |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 6600 | (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6601 | ata_mode_string(xfer_mask), |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6602 | ap->link.eh_info.desc); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6603 | else |
| 6604 | ata_port_printk(ap, KERN_INFO, "DUMMY\n"); |
| 6605 | } |
| 6606 | |
| 6607 | /* perform each probe synchronously */ |
| 6608 | DPRINTK("probe begin\n"); |
| 6609 | for (i = 0; i < host->n_ports; i++) { |
| 6610 | struct ata_port *ap = host->ports[i]; |
| 6611 | int rc; |
| 6612 | |
| 6613 | /* probe */ |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 6614 | if (ap->ops->error_handler) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 6615 | struct ata_eh_info *ehi = &ap->link.eh_info; |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6616 | unsigned long flags; |
| 6617 | |
| 6618 | ata_port_probe(ap); |
| 6619 | |
| 6620 | /* kick EH for boot probing */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6621 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6622 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6623 | ehi->probe_mask = |
| 6624 | (1 << ata_link_max_devices(&ap->link)) - 1; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 6625 | ehi->action |= ATA_EH_SOFTRESET; |
| 6626 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6627 | |
Tejun Heo | f4d6d00 | 2007-05-01 11:50:15 +0200 | [diff] [blame] | 6628 | ap->pflags &= ~ATA_PFLAG_INITIALIZING; |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 6629 | ap->pflags |= ATA_PFLAG_LOADING; |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6630 | ata_port_schedule_eh(ap); |
| 6631 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6632 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6633 | |
| 6634 | /* wait for EH to finish */ |
| 6635 | ata_port_wait_eh(ap); |
| 6636 | } else { |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 6637 | DPRINTK("ata%u: bus probe begin\n", ap->print_id); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6638 | rc = ata_bus_probe(ap); |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 6639 | DPRINTK("ata%u: bus probe end\n", ap->print_id); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 6640 | |
| 6641 | if (rc) { |
| 6642 | /* FIXME: do something useful here? |
| 6643 | * Current libata behavior will |
| 6644 | * tear down everything when |
| 6645 | * the module is removed |
| 6646 | * or the h/w is unplugged. |
| 6647 | */ |
| 6648 | } |
| 6649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | /* probes are done, now scan each port's disk(s) */ |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 6653 | DPRINTK("host probe begin\n"); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6654 | for (i = 0; i < host->n_ports; i++) { |
| 6655 | struct ata_port *ap = host->ports[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6656 | |
Tejun Heo | 1ae4631 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 6657 | ata_scsi_scan_host(ap, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6658 | } |
| 6659 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6660 | return 0; |
| 6661 | } |
| 6662 | |
| 6663 | /** |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6664 | * ata_host_activate - start host, request IRQ and register it |
| 6665 | * @host: target ATA host |
| 6666 | * @irq: IRQ to request |
| 6667 | * @irq_handler: irq_handler used when requesting IRQ |
| 6668 | * @irq_flags: irq_flags used when requesting IRQ |
| 6669 | * @sht: scsi_host_template to use when registering the host |
| 6670 | * |
| 6671 | * After allocating an ATA host and initializing it, most libata |
| 6672 | * LLDs perform three steps to activate the host - start host, |
| 6673 | * request IRQ and register it. This helper takes necessasry |
| 6674 | * arguments and performs the three steps in one go. |
| 6675 | * |
| 6676 | * LOCKING: |
| 6677 | * Inherited from calling layer (may sleep). |
| 6678 | * |
| 6679 | * RETURNS: |
| 6680 | * 0 on success, -errno otherwise. |
| 6681 | */ |
| 6682 | int ata_host_activate(struct ata_host *host, int irq, |
| 6683 | irq_handler_t irq_handler, unsigned long irq_flags, |
| 6684 | struct scsi_host_template *sht) |
| 6685 | { |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6686 | int i, rc; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6687 | |
| 6688 | rc = ata_host_start(host); |
| 6689 | if (rc) |
| 6690 | return rc; |
| 6691 | |
| 6692 | rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, |
| 6693 | dev_driver_string(host->dev), host); |
| 6694 | if (rc) |
| 6695 | return rc; |
| 6696 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6697 | for (i = 0; i < host->n_ports; i++) |
| 6698 | ata_port_desc(host->ports[i], "irq %d", irq); |
Tejun Heo | 4031826 | 2007-07-03 01:38:47 +0900 | [diff] [blame] | 6699 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6700 | rc = ata_host_register(host, sht); |
| 6701 | /* if failed, just free the IRQ and leave ports alone */ |
| 6702 | if (rc) |
| 6703 | devm_free_irq(host->dev, irq, host); |
| 6704 | |
| 6705 | return rc; |
| 6706 | } |
| 6707 | |
| 6708 | /** |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6709 | * ata_port_detach - Detach ATA port in prepration of device removal |
| 6710 | * @ap: ATA port to be detached |
| 6711 | * |
| 6712 | * Detach all ATA devices and the associated SCSI devices of @ap; |
| 6713 | * then, remove the associated SCSI host. @ap is guaranteed to |
| 6714 | * be quiescent on return from this function. |
| 6715 | * |
| 6716 | * LOCKING: |
| 6717 | * Kernel thread context (may sleep). |
| 6718 | */ |
| 6719 | void ata_port_detach(struct ata_port *ap) |
| 6720 | { |
| 6721 | unsigned long flags; |
Tejun Heo | 41bda9c | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 6722 | struct ata_link *link; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6723 | struct ata_device *dev; |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6724 | |
| 6725 | if (!ap->ops->error_handler) |
Tejun Heo | c3cf30a | 2006-08-05 03:59:11 +0900 | [diff] [blame] | 6726 | goto skip_eh; |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6727 | |
| 6728 | /* tell EH we're leaving & flush EH */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6729 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 6730 | ap->pflags |= ATA_PFLAG_UNLOADING; |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6731 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6732 | |
| 6733 | ata_port_wait_eh(ap); |
| 6734 | |
| 6735 | /* EH is now guaranteed to see UNLOADING, so no new device |
| 6736 | * will be attached. Disable all existing devices. |
| 6737 | */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6738 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6739 | |
Tejun Heo | 41bda9c | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 6740 | ata_port_for_each_link(link, ap) { |
| 6741 | ata_link_for_each_dev(dev, link) |
| 6742 | ata_dev_disable(dev); |
| 6743 | } |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6744 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6745 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6746 | |
| 6747 | /* Final freeze & EH. All in-flight commands are aborted. EH |
| 6748 | * will be skipped and retrials will be terminated with bad |
| 6749 | * target. |
| 6750 | */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6751 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6752 | ata_port_freeze(ap); /* won't be thawed */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6753 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6754 | |
| 6755 | ata_port_wait_eh(ap); |
Oleg Nesterov | 45a66c1 | 2007-07-09 11:46:13 -0700 | [diff] [blame] | 6756 | cancel_rearming_delayed_work(&ap->hotplug_task); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6757 | |
Tejun Heo | c3cf30a | 2006-08-05 03:59:11 +0900 | [diff] [blame] | 6758 | skip_eh: |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6759 | /* remove the associated SCSI host */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6760 | scsi_remove_host(ap->scsi_host); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | /** |
Tejun Heo | 0529c15 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 6764 | * ata_host_detach - Detach all ports of an ATA host |
| 6765 | * @host: Host to detach |
| 6766 | * |
| 6767 | * Detach all ports of @host. |
| 6768 | * |
| 6769 | * LOCKING: |
| 6770 | * Kernel thread context (may sleep). |
| 6771 | */ |
| 6772 | void ata_host_detach(struct ata_host *host) |
| 6773 | { |
| 6774 | int i; |
| 6775 | |
| 6776 | for (i = 0; i < host->n_ports; i++) |
| 6777 | ata_port_detach(host->ports[i]); |
| 6778 | } |
| 6779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6780 | /** |
| 6781 | * ata_std_ports - initialize ioaddr with standard port offsets. |
| 6782 | * @ioaddr: IO address structure to be initialized |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 6783 | * |
| 6784 | * Utility function which initializes data_addr, error_addr, |
| 6785 | * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr, |
| 6786 | * device_addr, status_addr, and command_addr to standard offsets |
| 6787 | * relative to cmd_addr. |
| 6788 | * |
| 6789 | * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | */ |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 6791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6792 | void ata_std_ports(struct ata_ioports *ioaddr) |
| 6793 | { |
| 6794 | ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; |
| 6795 | ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; |
| 6796 | ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; |
| 6797 | ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; |
| 6798 | ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; |
| 6799 | ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; |
| 6800 | ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; |
| 6801 | ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; |
| 6802 | ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; |
| 6803 | ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; |
| 6804 | } |
| 6805 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 6806 | |
Jeff Garzik | 374b187 | 2005-08-30 05:42:52 -0400 | [diff] [blame] | 6807 | #ifdef CONFIG_PCI |
| 6808 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 6809 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6810 | * ata_pci_remove_one - PCI layer callback for device removal |
| 6811 | * @pdev: PCI device that was removed |
| 6812 | * |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6813 | * PCI layer indicates to libata via this hook that hot-unplug or |
| 6814 | * module unload event has occurred. Detach all ports. Resource |
| 6815 | * release is handled via devres. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | * |
| 6817 | * LOCKING: |
| 6818 | * Inherited from PCI layer (may sleep). |
| 6819 | */ |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6820 | void ata_pci_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6821 | { |
| 6822 | struct device *dev = pci_dev_to_dev(pdev); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6823 | struct ata_host *host = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6824 | |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6825 | ata_host_detach(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | /* move to PCI subsystem */ |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 6829 | int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6830 | { |
| 6831 | unsigned long tmp = 0; |
| 6832 | |
| 6833 | switch (bits->width) { |
| 6834 | case 1: { |
| 6835 | u8 tmp8 = 0; |
| 6836 | pci_read_config_byte(pdev, bits->reg, &tmp8); |
| 6837 | tmp = tmp8; |
| 6838 | break; |
| 6839 | } |
| 6840 | case 2: { |
| 6841 | u16 tmp16 = 0; |
| 6842 | pci_read_config_word(pdev, bits->reg, &tmp16); |
| 6843 | tmp = tmp16; |
| 6844 | break; |
| 6845 | } |
| 6846 | case 4: { |
| 6847 | u32 tmp32 = 0; |
| 6848 | pci_read_config_dword(pdev, bits->reg, &tmp32); |
| 6849 | tmp = tmp32; |
| 6850 | break; |
| 6851 | } |
| 6852 | |
| 6853 | default: |
| 6854 | return -EINVAL; |
| 6855 | } |
| 6856 | |
| 6857 | tmp &= bits->mask; |
| 6858 | |
| 6859 | return (tmp == bits->val) ? 1 : 0; |
| 6860 | } |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6861 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6862 | #ifdef CONFIG_PM |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 6863 | void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6864 | { |
| 6865 | pci_save_state(pdev); |
Tejun Heo | 4c90d97 | 2007-02-20 18:14:48 +0900 | [diff] [blame] | 6866 | pci_disable_device(pdev); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6867 | |
Tejun Heo | 4c90d97 | 2007-02-20 18:14:48 +0900 | [diff] [blame] | 6868 | if (mesg.event == PM_EVENT_SUSPEND) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6869 | pci_set_power_state(pdev, PCI_D3hot); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6870 | } |
| 6871 | |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6872 | int ata_pci_device_do_resume(struct pci_dev *pdev) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6873 | { |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6874 | int rc; |
| 6875 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6876 | pci_set_power_state(pdev, PCI_D0); |
| 6877 | pci_restore_state(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6878 | |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6879 | rc = pcim_enable_device(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6880 | if (rc) { |
| 6881 | dev_printk(KERN_ERR, &pdev->dev, |
| 6882 | "failed to enable device after resume (%d)\n", rc); |
| 6883 | return rc; |
| 6884 | } |
| 6885 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6886 | pci_set_master(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6887 | return 0; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6888 | } |
| 6889 | |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 6890 | int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6891 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6892 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6893 | int rc = 0; |
| 6894 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6895 | rc = ata_host_suspend(host, mesg); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6896 | if (rc) |
| 6897 | return rc; |
| 6898 | |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 6899 | ata_pci_device_do_suspend(pdev, mesg); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6900 | |
| 6901 | return 0; |
| 6902 | } |
| 6903 | |
| 6904 | int ata_pci_device_resume(struct pci_dev *pdev) |
| 6905 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6906 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6907 | int rc; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6908 | |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6909 | rc = ata_pci_device_do_resume(pdev); |
| 6910 | if (rc == 0) |
| 6911 | ata_host_resume(host); |
| 6912 | return rc; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6913 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6914 | #endif /* CONFIG_PM */ |
| 6915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6916 | #endif /* CONFIG_PCI */ |
| 6917 | |
| 6918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6919 | static int __init ata_init(void) |
| 6920 | { |
Andrew Morton | a8601e5 | 2006-06-25 01:36:52 -0700 | [diff] [blame] | 6921 | ata_probe_timeout *= HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6922 | ata_wq = create_workqueue("ata"); |
| 6923 | if (!ata_wq) |
| 6924 | return -ENOMEM; |
| 6925 | |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 6926 | ata_aux_wq = create_singlethread_workqueue("ata_aux"); |
| 6927 | if (!ata_aux_wq) { |
| 6928 | destroy_workqueue(ata_wq); |
| 6929 | return -ENOMEM; |
| 6930 | } |
| 6931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6932 | printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); |
| 6933 | return 0; |
| 6934 | } |
| 6935 | |
| 6936 | static void __exit ata_exit(void) |
| 6937 | { |
| 6938 | destroy_workqueue(ata_wq); |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 6939 | destroy_workqueue(ata_aux_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6940 | } |
| 6941 | |
Brian King | a462508 | 2006-11-13 16:32:36 -0600 | [diff] [blame] | 6942 | subsys_initcall(ata_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6943 | module_exit(ata_exit); |
| 6944 | |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 6945 | static unsigned long ratelimit_time; |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 6946 | static DEFINE_SPINLOCK(ata_ratelimit_lock); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 6947 | |
| 6948 | int ata_ratelimit(void) |
| 6949 | { |
| 6950 | int rc; |
| 6951 | unsigned long flags; |
| 6952 | |
| 6953 | spin_lock_irqsave(&ata_ratelimit_lock, flags); |
| 6954 | |
| 6955 | if (time_after(jiffies, ratelimit_time)) { |
| 6956 | rc = 1; |
| 6957 | ratelimit_time = jiffies + (HZ/5); |
| 6958 | } else |
| 6959 | rc = 0; |
| 6960 | |
| 6961 | spin_unlock_irqrestore(&ata_ratelimit_lock, flags); |
| 6962 | |
| 6963 | return rc; |
| 6964 | } |
| 6965 | |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6966 | /** |
| 6967 | * ata_wait_register - wait until register value changes |
| 6968 | * @reg: IO-mapped register |
| 6969 | * @mask: Mask to apply to read register value |
| 6970 | * @val: Wait condition |
| 6971 | * @interval_msec: polling interval in milliseconds |
| 6972 | * @timeout_msec: timeout in milliseconds |
| 6973 | * |
| 6974 | * Waiting for some bits of register to change is a common |
| 6975 | * operation for ATA controllers. This function reads 32bit LE |
| 6976 | * IO-mapped register @reg and tests for the following condition. |
| 6977 | * |
| 6978 | * (*@reg & mask) != val |
| 6979 | * |
| 6980 | * If the condition is met, it returns; otherwise, the process is |
| 6981 | * repeated after @interval_msec until timeout. |
| 6982 | * |
| 6983 | * LOCKING: |
| 6984 | * Kernel thread context (may sleep) |
| 6985 | * |
| 6986 | * RETURNS: |
| 6987 | * The final register value. |
| 6988 | */ |
| 6989 | u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, |
| 6990 | unsigned long interval_msec, |
| 6991 | unsigned long timeout_msec) |
| 6992 | { |
| 6993 | unsigned long timeout; |
| 6994 | u32 tmp; |
| 6995 | |
| 6996 | tmp = ioread32(reg); |
| 6997 | |
| 6998 | /* Calculate timeout _after_ the first read to make sure |
| 6999 | * preceding writes reach the controller before starting to |
| 7000 | * eat away the timeout. |
| 7001 | */ |
| 7002 | timeout = jiffies + (timeout_msec * HZ) / 1000; |
| 7003 | |
| 7004 | while ((tmp & mask) == val && time_before(jiffies, timeout)) { |
| 7005 | msleep(interval_msec); |
| 7006 | tmp = ioread32(reg); |
| 7007 | } |
| 7008 | |
| 7009 | return tmp; |
| 7010 | } |
| 7011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7012 | /* |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 7013 | * Dummy port_ops |
| 7014 | */ |
| 7015 | static void ata_dummy_noret(struct ata_port *ap) { } |
| 7016 | static int ata_dummy_ret0(struct ata_port *ap) { return 0; } |
| 7017 | static void ata_dummy_qc_noret(struct ata_queued_cmd *qc) { } |
| 7018 | |
| 7019 | static u8 ata_dummy_check_status(struct ata_port *ap) |
| 7020 | { |
| 7021 | return ATA_DRDY; |
| 7022 | } |
| 7023 | |
| 7024 | static unsigned int ata_dummy_qc_issue(struct ata_queued_cmd *qc) |
| 7025 | { |
| 7026 | return AC_ERR_SYSTEM; |
| 7027 | } |
| 7028 | |
| 7029 | const struct ata_port_operations ata_dummy_port_ops = { |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 7030 | .check_status = ata_dummy_check_status, |
| 7031 | .check_altstatus = ata_dummy_check_status, |
| 7032 | .dev_select = ata_noop_dev_select, |
| 7033 | .qc_prep = ata_noop_qc_prep, |
| 7034 | .qc_issue = ata_dummy_qc_issue, |
| 7035 | .freeze = ata_dummy_noret, |
| 7036 | .thaw = ata_dummy_noret, |
| 7037 | .error_handler = ata_dummy_noret, |
| 7038 | .post_internal_cmd = ata_dummy_qc_noret, |
| 7039 | .irq_clear = ata_dummy_noret, |
| 7040 | .port_start = ata_dummy_ret0, |
| 7041 | .port_stop = ata_dummy_noret, |
| 7042 | }; |
| 7043 | |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 7044 | const struct ata_port_info ata_dummy_port_info = { |
| 7045 | .port_ops = &ata_dummy_port_ops, |
| 7046 | }; |
| 7047 | |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 7048 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7049 | * libata is essentially a library of internal helper functions for |
| 7050 | * low-level ATA host controller drivers. As such, the API/ABI is |
| 7051 | * likely to change as new drivers are added and updated. |
| 7052 | * Do not depend on ABI/API stability. |
| 7053 | */ |
| 7054 | |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 7055 | EXPORT_SYMBOL_GPL(sata_deb_timing_normal); |
| 7056 | EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug); |
| 7057 | EXPORT_SYMBOL_GPL(sata_deb_timing_long); |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 7058 | EXPORT_SYMBOL_GPL(ata_dummy_port_ops); |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 7059 | EXPORT_SYMBOL_GPL(ata_dummy_port_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7060 | EXPORT_SYMBOL_GPL(ata_std_bios_param); |
| 7061 | EXPORT_SYMBOL_GPL(ata_std_ports); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 7062 | EXPORT_SYMBOL_GPL(ata_host_init); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 7063 | EXPORT_SYMBOL_GPL(ata_host_alloc); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 7064 | EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 7065 | EXPORT_SYMBOL_GPL(ata_host_start); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 7066 | EXPORT_SYMBOL_GPL(ata_host_register); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 7067 | EXPORT_SYMBOL_GPL(ata_host_activate); |
Tejun Heo | 0529c15 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 7068 | EXPORT_SYMBOL_GPL(ata_host_detach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7069 | EXPORT_SYMBOL_GPL(ata_sg_init); |
| 7070 | EXPORT_SYMBOL_GPL(ata_sg_init_one); |
Tejun Heo | 9a1004d | 2006-05-31 18:27:52 +0900 | [diff] [blame] | 7071 | EXPORT_SYMBOL_GPL(ata_hsm_move); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 7072 | EXPORT_SYMBOL_GPL(ata_qc_complete); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 7073 | EXPORT_SYMBOL_GPL(ata_qc_complete_multiple); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7074 | EXPORT_SYMBOL_GPL(ata_qc_issue_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | EXPORT_SYMBOL_GPL(ata_tf_load); |
| 7076 | EXPORT_SYMBOL_GPL(ata_tf_read); |
| 7077 | EXPORT_SYMBOL_GPL(ata_noop_dev_select); |
| 7078 | EXPORT_SYMBOL_GPL(ata_std_dev_select); |
Jeff Garzik | 43727fb | 2007-02-25 16:50:52 -0500 | [diff] [blame] | 7079 | EXPORT_SYMBOL_GPL(sata_print_link_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7080 | EXPORT_SYMBOL_GPL(ata_tf_to_fis); |
| 7081 | EXPORT_SYMBOL_GPL(ata_tf_from_fis); |
| 7082 | EXPORT_SYMBOL_GPL(ata_check_status); |
| 7083 | EXPORT_SYMBOL_GPL(ata_altstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7084 | EXPORT_SYMBOL_GPL(ata_exec_command); |
| 7085 | EXPORT_SYMBOL_GPL(ata_port_start); |
Alan Cox | d92e74d | 2007-06-07 16:19:15 +0100 | [diff] [blame] | 7086 | EXPORT_SYMBOL_GPL(ata_sff_port_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7087 | EXPORT_SYMBOL_GPL(ata_interrupt); |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 7088 | EXPORT_SYMBOL_GPL(ata_do_set_mode); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 7089 | EXPORT_SYMBOL_GPL(ata_data_xfer); |
| 7090 | EXPORT_SYMBOL_GPL(ata_data_xfer_noirq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7091 | EXPORT_SYMBOL_GPL(ata_qc_prep); |
Alan Cox | d26fc95 | 2007-07-06 19:13:52 -0400 | [diff] [blame] | 7092 | EXPORT_SYMBOL_GPL(ata_dumb_qc_prep); |
Brian King | e46834c | 2006-03-17 17:04:03 -0600 | [diff] [blame] | 7093 | EXPORT_SYMBOL_GPL(ata_noop_qc_prep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7094 | EXPORT_SYMBOL_GPL(ata_bmdma_setup); |
| 7095 | EXPORT_SYMBOL_GPL(ata_bmdma_start); |
| 7096 | EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear); |
| 7097 | EXPORT_SYMBOL_GPL(ata_bmdma_status); |
| 7098 | EXPORT_SYMBOL_GPL(ata_bmdma_stop); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 7099 | EXPORT_SYMBOL_GPL(ata_bmdma_freeze); |
| 7100 | EXPORT_SYMBOL_GPL(ata_bmdma_thaw); |
| 7101 | EXPORT_SYMBOL_GPL(ata_bmdma_drive_eh); |
| 7102 | EXPORT_SYMBOL_GPL(ata_bmdma_error_handler); |
| 7103 | EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7104 | EXPORT_SYMBOL_GPL(ata_port_probe); |
Alan | 10305f0 | 2007-02-20 18:01:59 +0000 | [diff] [blame] | 7105 | EXPORT_SYMBOL_GPL(ata_dev_disable); |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 7106 | EXPORT_SYMBOL_GPL(sata_set_spd); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7107 | EXPORT_SYMBOL_GPL(sata_link_debounce); |
| 7108 | EXPORT_SYMBOL_GPL(sata_link_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7109 | EXPORT_SYMBOL_GPL(sata_phy_reset); |
| 7110 | EXPORT_SYMBOL_GPL(__sata_phy_reset); |
| 7111 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 7112 | EXPORT_SYMBOL_GPL(ata_std_prereset); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 7113 | EXPORT_SYMBOL_GPL(ata_std_softreset); |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7114 | EXPORT_SYMBOL_GPL(sata_link_hardreset); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 7115 | EXPORT_SYMBOL_GPL(sata_std_hardreset); |
| 7116 | EXPORT_SYMBOL_GPL(ata_std_postreset); |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 7117 | EXPORT_SYMBOL_GPL(ata_dev_classify); |
| 7118 | EXPORT_SYMBOL_GPL(ata_dev_pair); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7119 | EXPORT_SYMBOL_GPL(ata_port_disable); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 7120 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 7121 | EXPORT_SYMBOL_GPL(ata_wait_register); |
Tejun Heo | 6f8b995 | 2006-01-24 17:05:21 +0900 | [diff] [blame] | 7122 | EXPORT_SYMBOL_GPL(ata_busy_sleep); |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 7123 | EXPORT_SYMBOL_GPL(ata_wait_ready); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 7124 | EXPORT_SYMBOL_GPL(ata_port_queue_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7125 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |
| 7126 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7127 | EXPORT_SYMBOL_GPL(ata_scsi_slave_config); |
Tejun Heo | 83c47bc | 2006-05-31 18:28:07 +0900 | [diff] [blame] | 7128 | EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 7129 | EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7130 | EXPORT_SYMBOL_GPL(ata_host_intr); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 7131 | EXPORT_SYMBOL_GPL(sata_scr_valid); |
| 7132 | EXPORT_SYMBOL_GPL(sata_scr_read); |
| 7133 | EXPORT_SYMBOL_GPL(sata_scr_write); |
| 7134 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7135 | EXPORT_SYMBOL_GPL(ata_link_online); |
| 7136 | EXPORT_SYMBOL_GPL(ata_link_offline); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7137 | #ifdef CONFIG_PM |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 7138 | EXPORT_SYMBOL_GPL(ata_host_suspend); |
| 7139 | EXPORT_SYMBOL_GPL(ata_host_resume); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7140 | #endif /* CONFIG_PM */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 7141 | EXPORT_SYMBOL_GPL(ata_id_string); |
| 7142 | EXPORT_SYMBOL_GPL(ata_id_c_string); |
Alan | 10305f0 | 2007-02-20 18:01:59 +0000 | [diff] [blame] | 7143 | EXPORT_SYMBOL_GPL(ata_id_to_dma_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7144 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
| 7145 | |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 7146 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 7147 | EXPORT_SYMBOL_GPL(ata_timing_compute); |
| 7148 | EXPORT_SYMBOL_GPL(ata_timing_merge); |
| 7149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7150 | #ifdef CONFIG_PCI |
| 7151 | EXPORT_SYMBOL_GPL(pci_test_config_bits); |
Tejun Heo | d583bc1 | 2007-07-04 18:02:07 +0900 | [diff] [blame] | 7152 | EXPORT_SYMBOL_GPL(ata_pci_init_sff_host); |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 7153 | EXPORT_SYMBOL_GPL(ata_pci_init_bmdma); |
Tejun Heo | d583bc1 | 2007-07-04 18:02:07 +0900 | [diff] [blame] | 7154 | EXPORT_SYMBOL_GPL(ata_pci_prepare_sff_host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7155 | EXPORT_SYMBOL_GPL(ata_pci_init_one); |
| 7156 | EXPORT_SYMBOL_GPL(ata_pci_remove_one); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7157 | #ifdef CONFIG_PM |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 7158 | EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend); |
| 7159 | EXPORT_SYMBOL_GPL(ata_pci_device_do_resume); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 7160 | EXPORT_SYMBOL_GPL(ata_pci_device_suspend); |
| 7161 | EXPORT_SYMBOL_GPL(ata_pci_device_resume); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7162 | #endif /* CONFIG_PM */ |
Alan Cox | 67951ad | 2006-03-22 15:55:54 +0000 | [diff] [blame] | 7163 | EXPORT_SYMBOL_GPL(ata_pci_default_filter); |
| 7164 | EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7165 | #endif /* CONFIG_PCI */ |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 7166 | |
Tejun Heo | b64bbc3 | 2007-07-16 14:29:39 +0900 | [diff] [blame] | 7167 | EXPORT_SYMBOL_GPL(__ata_ehi_push_desc); |
| 7168 | EXPORT_SYMBOL_GPL(ata_ehi_push_desc); |
| 7169 | EXPORT_SYMBOL_GPL(ata_ehi_clear_desc); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 7170 | EXPORT_SYMBOL_GPL(ata_port_desc); |
| 7171 | #ifdef CONFIG_PCI |
| 7172 | EXPORT_SYMBOL_GPL(ata_port_pbar_desc); |
| 7173 | #endif /* CONFIG_PCI */ |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 7174 | EXPORT_SYMBOL_GPL(ata_eng_timeout); |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 7175 | EXPORT_SYMBOL_GPL(ata_port_schedule_eh); |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7176 | EXPORT_SYMBOL_GPL(ata_link_abort); |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 7177 | EXPORT_SYMBOL_GPL(ata_port_abort); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 7178 | EXPORT_SYMBOL_GPL(ata_port_freeze); |
| 7179 | EXPORT_SYMBOL_GPL(ata_eh_freeze_port); |
| 7180 | EXPORT_SYMBOL_GPL(ata_eh_thaw_port); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 7181 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); |
| 7182 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 7183 | EXPORT_SYMBOL_GPL(ata_do_eh); |
Akira Iguchi | 8362500 | 2007-01-26 16:27:32 +0900 | [diff] [blame] | 7184 | EXPORT_SYMBOL_GPL(ata_irq_on); |
Akira Iguchi | a619f981b | 2007-01-26 16:28:18 +0900 | [diff] [blame] | 7185 | EXPORT_SYMBOL_GPL(ata_dev_try_classify); |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 7186 | |
| 7187 | EXPORT_SYMBOL_GPL(ata_cable_40wire); |
| 7188 | EXPORT_SYMBOL_GPL(ata_cable_80wire); |
| 7189 | EXPORT_SYMBOL_GPL(ata_cable_unknown); |
| 7190 | EXPORT_SYMBOL_GPL(ata_cable_sata); |