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 | * |
Alan Cox | 92c52c5 | 2007-11-19 14:30:16 +0000 | [diff] [blame] | 33 | * Standards documents from: |
| 34 | * http://www.t13.org (ATA standards, PCI DMA IDE spec) |
| 35 | * http://www.t10.org (SCSI MMC - for ATAPI MMC) |
| 36 | * http://www.sata-io.org (SATA) |
| 37 | * http://www.compactflash.org (CF) |
| 38 | * http://www.qic.org (QIC157 - Tape and DSC) |
| 39 | * http://www.ce-ata.org (CE-ATA: not supported) |
| 40 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | */ |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/kernel.h> |
| 44 | #include <linux/module.h> |
| 45 | #include <linux/pci.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/list.h> |
| 48 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/spinlock.h> |
| 50 | #include <linux/blkdev.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/timer.h> |
| 53 | #include <linux/interrupt.h> |
| 54 | #include <linux/completion.h> |
| 55 | #include <linux/suspend.h> |
| 56 | #include <linux/workqueue.h> |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 57 | #include <linux/jiffies.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 58 | #include <linux/scatterlist.h> |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 59 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <scsi/scsi.h> |
Jeff Garzik | 193515d | 2005-11-07 00:59:37 -0500 | [diff] [blame] | 61 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <scsi/scsi_host.h> |
| 63 | #include <linux/libata.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <asm/semaphore.h> |
| 65 | #include <asm/byteorder.h> |
Tejun Heo | 140b5e5 | 2007-12-12 12:21:52 +0900 | [diff] [blame] | 66 | #include <linux/cdrom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #include "libata.h" |
| 69 | |
Jeff Garzik | fda0efc | 2007-01-31 07:43:15 -0500 | [diff] [blame] | 70 | |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 71 | /* debounce timing parameters in msecs { interval, duration, timeout } */ |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 72 | const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; |
| 73 | const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 }; |
| 74 | const unsigned long sata_deb_timing_long[] = { 100, 2000, 5000 }; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 75 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 76 | const struct ata_port_operations ata_base_port_ops = { |
| 77 | .irq_clear = ata_noop_irq_clear, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 78 | .prereset = ata_std_prereset, |
| 79 | .hardreset = sata_std_hardreset, |
| 80 | .postreset = ata_std_postreset, |
| 81 | .error_handler = ata_std_error_handler, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | const struct ata_port_operations sata_port_ops = { |
| 85 | .inherits = &ata_base_port_ops, |
| 86 | |
| 87 | .qc_defer = ata_std_qc_defer, |
| 88 | .dev_select = ata_noop_dev_select, |
| 89 | }; |
| 90 | |
| 91 | const struct ata_port_operations sata_pmp_port_ops = { |
| 92 | .inherits = &sata_port_ops, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 93 | |
| 94 | .pmp_prereset = sata_pmp_std_prereset, |
| 95 | .pmp_hardreset = sata_pmp_std_hardreset, |
| 96 | .pmp_postreset = sata_pmp_std_postreset, |
| 97 | .error_handler = sata_pmp_error_handler, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 98 | }; |
| 99 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 100 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
| 101 | u16 heads, u16 sectors); |
| 102 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev); |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 103 | static unsigned int ata_dev_set_feature(struct ata_device *dev, |
| 104 | u8 enable, u8 feature); |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 105 | static void ata_dev_xfermask(struct ata_device *dev); |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 106 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 108 | unsigned int ata_print_id = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static struct workqueue_struct *ata_wq; |
| 110 | |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 111 | struct workqueue_struct *ata_aux_wq; |
| 112 | |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 113 | struct ata_force_param { |
| 114 | const char *name; |
| 115 | unsigned int cbl; |
| 116 | int spd_limit; |
| 117 | unsigned long xfer_mask; |
| 118 | unsigned int horkage_on; |
| 119 | unsigned int horkage_off; |
| 120 | }; |
| 121 | |
| 122 | struct ata_force_ent { |
| 123 | int port; |
| 124 | int device; |
| 125 | struct ata_force_param param; |
| 126 | }; |
| 127 | |
| 128 | static struct ata_force_ent *ata_force_tbl; |
| 129 | static int ata_force_tbl_size; |
| 130 | |
| 131 | static char ata_force_param_buf[PAGE_SIZE] __initdata; |
Tejun Heo | 7afb422 | 2008-03-09 20:21:53 +0900 | [diff] [blame] | 132 | /* param_buf is thrown away after initialization, disallow read */ |
| 133 | module_param_string(force, ata_force_param_buf, sizeof(ata_force_param_buf), 0); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 134 | MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/kernel-parameters.txt for details)"); |
| 135 | |
Jeff Garzik | 418dc1f | 2006-03-11 20:50:08 -0500 | [diff] [blame] | 136 | int atapi_enabled = 1; |
Jeff Garzik | 1623c81 | 2005-08-30 03:37:42 -0400 | [diff] [blame] | 137 | module_param(atapi_enabled, int, 0444); |
| 138 | MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); |
| 139 | |
Adrian Bunk | c5c61bd | 2008-02-25 02:07:25 +0200 | [diff] [blame] | 140 | static int atapi_dmadir = 0; |
Albert Lee | 95de719 | 2006-04-04 10:57:18 +0800 | [diff] [blame] | 141 | module_param(atapi_dmadir, int, 0444); |
| 142 | MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)"); |
| 143 | |
Mark Lord | baf4fdf | 2007-08-08 01:08:45 +0900 | [diff] [blame] | 144 | int atapi_passthru16 = 1; |
| 145 | module_param(atapi_passthru16, int, 0444); |
| 146 | MODULE_PARM_DESC(atapi_passthru16, "Enable ATA_16 passthru for ATAPI devices; on by default (0=off, 1=on)"); |
| 147 | |
Jeff Garzik | c3c013a | 2006-02-27 22:31:19 -0500 | [diff] [blame] | 148 | int libata_fua = 0; |
| 149 | module_param_named(fua, libata_fua, int, 0444); |
| 150 | MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); |
| 151 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 152 | static int ata_ignore_hpa; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 153 | module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644); |
| 154 | MODULE_PARM_DESC(ignore_hpa, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)"); |
| 155 | |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 156 | static int libata_dma_mask = ATA_DMA_MASK_ATA|ATA_DMA_MASK_ATAPI|ATA_DMA_MASK_CFA; |
| 157 | module_param_named(dma, libata_dma_mask, int, 0444); |
| 158 | MODULE_PARM_DESC(dma, "DMA enable/disable (0x1==ATA, 0x2==ATAPI, 0x4==CF)"); |
| 159 | |
Andrew Morton | a8601e5 | 2006-06-25 01:36:52 -0700 | [diff] [blame] | 160 | static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ; |
| 161 | module_param(ata_probe_timeout, int, 0444); |
| 162 | MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)"); |
| 163 | |
Jeff Garzik | 6ebe9d8 | 2007-10-05 16:28:36 -0400 | [diff] [blame] | 164 | int libata_noacpi = 0; |
Jeff Garzik | d7d0dad | 2007-03-28 01:57:37 -0400 | [diff] [blame] | 165 | module_param_named(noacpi, libata_noacpi, int, 0444); |
Jeff Garzik | 6ebe9d8 | 2007-10-05 16:28:36 -0400 | [diff] [blame] | 166 | MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in probe/suspend/resume when set"); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 167 | |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 168 | int libata_allow_tpm = 0; |
| 169 | module_param_named(allow_tpm, libata_allow_tpm, int, 0444); |
| 170 | MODULE_PARM_DESC(allow_tpm, "Permit the use of TPM commands"); |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | MODULE_AUTHOR("Jeff Garzik"); |
| 173 | MODULE_DESCRIPTION("Library module for ATA devices"); |
| 174 | MODULE_LICENSE("GPL"); |
| 175 | MODULE_VERSION(DRV_VERSION); |
| 176 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 177 | |
| 178 | /** |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 179 | * ata_force_cbl - force cable type according to libata.force |
Randy Dunlap | 4cdfa1b | 2008-02-22 12:21:37 -0800 | [diff] [blame] | 180 | * @ap: ATA port of interest |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 181 | * |
| 182 | * Force cable type according to libata.force and whine about it. |
| 183 | * The last entry which has matching port number is used, so it |
| 184 | * can be specified as part of device force parameters. For |
| 185 | * example, both "a:40c,1.00:udma4" and "1.00:40c,udma4" have the |
| 186 | * same effect. |
| 187 | * |
| 188 | * LOCKING: |
| 189 | * EH context. |
| 190 | */ |
| 191 | void ata_force_cbl(struct ata_port *ap) |
| 192 | { |
| 193 | int i; |
| 194 | |
| 195 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
| 196 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 197 | |
| 198 | if (fe->port != -1 && fe->port != ap->print_id) |
| 199 | continue; |
| 200 | |
| 201 | if (fe->param.cbl == ATA_CBL_NONE) |
| 202 | continue; |
| 203 | |
| 204 | ap->cbl = fe->param.cbl; |
| 205 | ata_port_printk(ap, KERN_NOTICE, |
| 206 | "FORCE: cable set to %s\n", fe->param.name); |
| 207 | return; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * ata_force_spd_limit - force SATA spd limit according to libata.force |
| 213 | * @link: ATA link of interest |
| 214 | * |
| 215 | * Force SATA spd limit according to libata.force and whine about |
| 216 | * it. When only the port part is specified (e.g. 1:), the limit |
| 217 | * applies to all links connected to both the host link and all |
| 218 | * fan-out ports connected via PMP. If the device part is |
| 219 | * specified as 0 (e.g. 1.00:), it specifies the first fan-out |
| 220 | * link not the host link. Device number 15 always points to the |
| 221 | * host link whether PMP is attached or not. |
| 222 | * |
| 223 | * LOCKING: |
| 224 | * EH context. |
| 225 | */ |
| 226 | static void ata_force_spd_limit(struct ata_link *link) |
| 227 | { |
| 228 | int linkno, i; |
| 229 | |
| 230 | if (ata_is_host_link(link)) |
| 231 | linkno = 15; |
| 232 | else |
| 233 | linkno = link->pmp; |
| 234 | |
| 235 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
| 236 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 237 | |
| 238 | if (fe->port != -1 && fe->port != link->ap->print_id) |
| 239 | continue; |
| 240 | |
| 241 | if (fe->device != -1 && fe->device != linkno) |
| 242 | continue; |
| 243 | |
| 244 | if (!fe->param.spd_limit) |
| 245 | continue; |
| 246 | |
| 247 | link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; |
| 248 | ata_link_printk(link, KERN_NOTICE, |
| 249 | "FORCE: PHY spd limit set to %s\n", fe->param.name); |
| 250 | return; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * ata_force_xfermask - force xfermask according to libata.force |
| 256 | * @dev: ATA device of interest |
| 257 | * |
| 258 | * Force xfer_mask according to libata.force and whine about it. |
| 259 | * For consistency with link selection, device number 15 selects |
| 260 | * the first device connected to the host link. |
| 261 | * |
| 262 | * LOCKING: |
| 263 | * EH context. |
| 264 | */ |
| 265 | static void ata_force_xfermask(struct ata_device *dev) |
| 266 | { |
| 267 | int devno = dev->link->pmp + dev->devno; |
| 268 | int alt_devno = devno; |
| 269 | int i; |
| 270 | |
| 271 | /* allow n.15 for the first device attached to host port */ |
| 272 | if (ata_is_host_link(dev->link) && devno == 0) |
| 273 | alt_devno = 15; |
| 274 | |
| 275 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
| 276 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 277 | unsigned long pio_mask, mwdma_mask, udma_mask; |
| 278 | |
| 279 | if (fe->port != -1 && fe->port != dev->link->ap->print_id) |
| 280 | continue; |
| 281 | |
| 282 | if (fe->device != -1 && fe->device != devno && |
| 283 | fe->device != alt_devno) |
| 284 | continue; |
| 285 | |
| 286 | if (!fe->param.xfer_mask) |
| 287 | continue; |
| 288 | |
| 289 | ata_unpack_xfermask(fe->param.xfer_mask, |
| 290 | &pio_mask, &mwdma_mask, &udma_mask); |
| 291 | if (udma_mask) |
| 292 | dev->udma_mask = udma_mask; |
| 293 | else if (mwdma_mask) { |
| 294 | dev->udma_mask = 0; |
| 295 | dev->mwdma_mask = mwdma_mask; |
| 296 | } else { |
| 297 | dev->udma_mask = 0; |
| 298 | dev->mwdma_mask = 0; |
| 299 | dev->pio_mask = pio_mask; |
| 300 | } |
| 301 | |
| 302 | ata_dev_printk(dev, KERN_NOTICE, |
| 303 | "FORCE: xfer_mask set to %s\n", fe->param.name); |
| 304 | return; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * ata_force_horkage - force horkage according to libata.force |
| 310 | * @dev: ATA device of interest |
| 311 | * |
| 312 | * Force horkage according to libata.force and whine about it. |
| 313 | * For consistency with link selection, device number 15 selects |
| 314 | * the first device connected to the host link. |
| 315 | * |
| 316 | * LOCKING: |
| 317 | * EH context. |
| 318 | */ |
| 319 | static void ata_force_horkage(struct ata_device *dev) |
| 320 | { |
| 321 | int devno = dev->link->pmp + dev->devno; |
| 322 | int alt_devno = devno; |
| 323 | int i; |
| 324 | |
| 325 | /* allow n.15 for the first device attached to host port */ |
| 326 | if (ata_is_host_link(dev->link) && devno == 0) |
| 327 | alt_devno = 15; |
| 328 | |
| 329 | for (i = 0; i < ata_force_tbl_size; i++) { |
| 330 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 331 | |
| 332 | if (fe->port != -1 && fe->port != dev->link->ap->print_id) |
| 333 | continue; |
| 334 | |
| 335 | if (fe->device != -1 && fe->device != devno && |
| 336 | fe->device != alt_devno) |
| 337 | continue; |
| 338 | |
| 339 | if (!(~dev->horkage & fe->param.horkage_on) && |
| 340 | !(dev->horkage & fe->param.horkage_off)) |
| 341 | continue; |
| 342 | |
| 343 | dev->horkage |= fe->param.horkage_on; |
| 344 | dev->horkage &= ~fe->param.horkage_off; |
| 345 | |
| 346 | ata_dev_printk(dev, KERN_NOTICE, |
| 347 | "FORCE: horkage modified (%s)\n", fe->param.name); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /** |
Tejun Heo | 436d34b | 2008-04-02 17:28:46 +0900 | [diff] [blame] | 352 | * atapi_cmd_type - Determine ATAPI command type from SCSI opcode |
| 353 | * @opcode: SCSI opcode |
| 354 | * |
| 355 | * Determine ATAPI command type from @opcode. |
| 356 | * |
| 357 | * LOCKING: |
| 358 | * None. |
| 359 | * |
| 360 | * RETURNS: |
| 361 | * ATAPI_{READ|WRITE|READ_CD|PASS_THRU|MISC} |
| 362 | */ |
| 363 | int atapi_cmd_type(u8 opcode) |
| 364 | { |
| 365 | switch (opcode) { |
| 366 | case GPCMD_READ_10: |
| 367 | case GPCMD_READ_12: |
| 368 | return ATAPI_READ; |
| 369 | |
| 370 | case GPCMD_WRITE_10: |
| 371 | case GPCMD_WRITE_12: |
| 372 | case GPCMD_WRITE_AND_VERIFY_10: |
| 373 | return ATAPI_WRITE; |
| 374 | |
| 375 | case GPCMD_READ_CD: |
| 376 | case GPCMD_READ_CD_MSF: |
| 377 | return ATAPI_READ_CD; |
| 378 | |
Tejun Heo | e52dcc4 | 2008-04-02 17:35:19 +0900 | [diff] [blame] | 379 | case ATA_16: |
| 380 | case ATA_12: |
| 381 | if (atapi_passthru16) |
| 382 | return ATAPI_PASS_THRU; |
| 383 | /* fall thru */ |
Tejun Heo | 436d34b | 2008-04-02 17:28:46 +0900 | [diff] [blame] | 384 | default: |
| 385 | return ATAPI_MISC; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /** |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame^] | 390 | * ata_noop_irq_clear - Noop placeholder for irq_clear |
| 391 | * @ap: Port associated with this ATA transaction. |
| 392 | */ |
| 393 | void ata_noop_irq_clear(struct ata_port *ap) |
| 394 | { |
| 395 | } |
| 396 | |
| 397 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure |
| 399 | * @tf: Taskfile to convert |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | * @pmp: Port multiplier port |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 401 | * @is_cmd: This FIS is for command |
| 402 | * @fis: Buffer into which data will output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | * |
| 404 | * Converts a standard ATA taskfile to a Serial ATA |
| 405 | * FIS structure (Register - Host to Device). |
| 406 | * |
| 407 | * LOCKING: |
| 408 | * Inherited from caller. |
| 409 | */ |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 410 | 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] | 411 | { |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 412 | fis[0] = 0x27; /* Register - Host to Device FIS */ |
| 413 | fis[1] = pmp & 0xf; /* Port multiplier number*/ |
| 414 | if (is_cmd) |
| 415 | fis[1] |= (1 << 7); /* bit 7 indicates Command FIS */ |
| 416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | fis[2] = tf->command; |
| 418 | fis[3] = tf->feature; |
| 419 | |
| 420 | fis[4] = tf->lbal; |
| 421 | fis[5] = tf->lbam; |
| 422 | fis[6] = tf->lbah; |
| 423 | fis[7] = tf->device; |
| 424 | |
| 425 | fis[8] = tf->hob_lbal; |
| 426 | fis[9] = tf->hob_lbam; |
| 427 | fis[10] = tf->hob_lbah; |
| 428 | fis[11] = tf->hob_feature; |
| 429 | |
| 430 | fis[12] = tf->nsect; |
| 431 | fis[13] = tf->hob_nsect; |
| 432 | fis[14] = 0; |
| 433 | fis[15] = tf->ctl; |
| 434 | |
| 435 | fis[16] = 0; |
| 436 | fis[17] = 0; |
| 437 | fis[18] = 0; |
| 438 | fis[19] = 0; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * ata_tf_from_fis - Convert SATA FIS to ATA taskfile |
| 443 | * @fis: Buffer from which data will be input |
| 444 | * @tf: Taskfile to output |
| 445 | * |
Mark Lord | e12a1be | 2005-11-12 18:55:45 -0500 | [diff] [blame] | 446 | * Converts a serial ATA FIS structure to a standard ATA taskfile. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | * |
| 448 | * LOCKING: |
| 449 | * Inherited from caller. |
| 450 | */ |
| 451 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 452 | void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
| 454 | tf->command = fis[2]; /* status */ |
| 455 | tf->feature = fis[3]; /* error */ |
| 456 | |
| 457 | tf->lbal = fis[4]; |
| 458 | tf->lbam = fis[5]; |
| 459 | tf->lbah = fis[6]; |
| 460 | tf->device = fis[7]; |
| 461 | |
| 462 | tf->hob_lbal = fis[8]; |
| 463 | tf->hob_lbam = fis[9]; |
| 464 | tf->hob_lbah = fis[10]; |
| 465 | |
| 466 | tf->nsect = fis[12]; |
| 467 | tf->hob_nsect = fis[13]; |
| 468 | } |
| 469 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 470 | static const u8 ata_rw_cmds[] = { |
| 471 | /* pio multi */ |
| 472 | ATA_CMD_READ_MULTI, |
| 473 | ATA_CMD_WRITE_MULTI, |
| 474 | ATA_CMD_READ_MULTI_EXT, |
| 475 | ATA_CMD_WRITE_MULTI_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 476 | 0, |
| 477 | 0, |
| 478 | 0, |
| 479 | ATA_CMD_WRITE_MULTI_FUA_EXT, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 480 | /* pio */ |
| 481 | ATA_CMD_PIO_READ, |
| 482 | ATA_CMD_PIO_WRITE, |
| 483 | ATA_CMD_PIO_READ_EXT, |
| 484 | ATA_CMD_PIO_WRITE_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 485 | 0, |
| 486 | 0, |
| 487 | 0, |
| 488 | 0, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 489 | /* dma */ |
| 490 | ATA_CMD_READ, |
| 491 | ATA_CMD_WRITE, |
| 492 | ATA_CMD_READ_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 493 | ATA_CMD_WRITE_EXT, |
| 494 | 0, |
| 495 | 0, |
| 496 | 0, |
| 497 | ATA_CMD_WRITE_FUA_EXT |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 498 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | /** |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 501 | * ata_rwcmd_protocol - set taskfile r/w commands and protocol |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 502 | * @tf: command to examine and configure |
| 503 | * @dev: device tf belongs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | * |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 505 | * Examine the device configuration and tf->flags to calculate |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 506 | * the proper read/write commands and protocol to use. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | * |
| 508 | * LOCKING: |
| 509 | * caller. |
| 510 | */ |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 511 | 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] | 512 | { |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 513 | u8 cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 515 | int index, fua, lba48, write; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 516 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 517 | fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 518 | lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; |
| 519 | write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 521 | if (dev->flags & ATA_DFLAG_PIO) { |
| 522 | tf->protocol = ATA_PROT_PIO; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 523 | index = dev->multi_count ? 0 : 8; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 524 | } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { |
Alan Cox | 8d238e0 | 2006-01-17 20:50:31 +0000 | [diff] [blame] | 525 | /* Unable to use DMA due to host limitation */ |
| 526 | tf->protocol = ATA_PROT_PIO; |
Albert Lee | 0565c26 | 2006-02-13 18:55:25 +0800 | [diff] [blame] | 527 | index = dev->multi_count ? 0 : 8; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 528 | } else { |
| 529 | tf->protocol = ATA_PROT_DMA; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 530 | index = 16; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 533 | cmd = ata_rw_cmds[index + fua + lba48 + write]; |
| 534 | if (cmd) { |
| 535 | tf->command = cmd; |
| 536 | return 0; |
| 537 | } |
| 538 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 541 | /** |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 542 | * ata_tf_read_block - Read block address from ATA taskfile |
| 543 | * @tf: ATA taskfile of interest |
| 544 | * @dev: ATA device @tf belongs to |
| 545 | * |
| 546 | * LOCKING: |
| 547 | * None. |
| 548 | * |
| 549 | * Read block address from @tf. This function can handle all |
| 550 | * three address formats - LBA, LBA48 and CHS. tf->protocol and |
| 551 | * flags select the address format to use. |
| 552 | * |
| 553 | * RETURNS: |
| 554 | * Block address read from @tf. |
| 555 | */ |
| 556 | u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev) |
| 557 | { |
| 558 | u64 block = 0; |
| 559 | |
| 560 | if (tf->flags & ATA_TFLAG_LBA) { |
| 561 | if (tf->flags & ATA_TFLAG_LBA48) { |
| 562 | block |= (u64)tf->hob_lbah << 40; |
| 563 | block |= (u64)tf->hob_lbam << 32; |
| 564 | block |= tf->hob_lbal << 24; |
| 565 | } else |
| 566 | block |= (tf->device & 0xf) << 24; |
| 567 | |
| 568 | block |= tf->lbah << 16; |
| 569 | block |= tf->lbam << 8; |
| 570 | block |= tf->lbal; |
| 571 | } else { |
| 572 | u32 cyl, head, sect; |
| 573 | |
| 574 | cyl = tf->lbam | (tf->lbah << 8); |
| 575 | head = tf->device & 0xf; |
| 576 | sect = tf->lbal; |
| 577 | |
| 578 | block = (cyl * dev->heads + head) * dev->sectors + sect; |
| 579 | } |
| 580 | |
| 581 | return block; |
| 582 | } |
| 583 | |
| 584 | /** |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 585 | * ata_build_rw_tf - Build ATA taskfile for given read/write request |
| 586 | * @tf: Target ATA taskfile |
| 587 | * @dev: ATA device @tf belongs to |
| 588 | * @block: Block address |
| 589 | * @n_block: Number of blocks |
| 590 | * @tf_flags: RW/FUA etc... |
| 591 | * @tag: tag |
| 592 | * |
| 593 | * LOCKING: |
| 594 | * None. |
| 595 | * |
| 596 | * Build ATA taskfile @tf for read/write request described by |
| 597 | * @block, @n_block, @tf_flags and @tag on @dev. |
| 598 | * |
| 599 | * RETURNS: |
| 600 | * |
| 601 | * 0 on success, -ERANGE if the request is too large for @dev, |
| 602 | * -EINVAL if the request is invalid. |
| 603 | */ |
| 604 | int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, |
| 605 | u64 block, u32 n_block, unsigned int tf_flags, |
| 606 | unsigned int tag) |
| 607 | { |
| 608 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 609 | tf->flags |= tf_flags; |
| 610 | |
Tejun Heo | 6d1245b | 2007-02-20 23:20:27 +0900 | [diff] [blame] | 611 | if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) { |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 612 | /* yay, NCQ */ |
| 613 | if (!lba_48_ok(block, n_block)) |
| 614 | return -ERANGE; |
| 615 | |
| 616 | tf->protocol = ATA_PROT_NCQ; |
| 617 | tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; |
| 618 | |
| 619 | if (tf->flags & ATA_TFLAG_WRITE) |
| 620 | tf->command = ATA_CMD_FPDMA_WRITE; |
| 621 | else |
| 622 | tf->command = ATA_CMD_FPDMA_READ; |
| 623 | |
| 624 | tf->nsect = tag << 3; |
| 625 | tf->hob_feature = (n_block >> 8) & 0xff; |
| 626 | tf->feature = n_block & 0xff; |
| 627 | |
| 628 | tf->hob_lbah = (block >> 40) & 0xff; |
| 629 | tf->hob_lbam = (block >> 32) & 0xff; |
| 630 | tf->hob_lbal = (block >> 24) & 0xff; |
| 631 | tf->lbah = (block >> 16) & 0xff; |
| 632 | tf->lbam = (block >> 8) & 0xff; |
| 633 | tf->lbal = block & 0xff; |
| 634 | |
| 635 | tf->device = 1 << 6; |
| 636 | if (tf->flags & ATA_TFLAG_FUA) |
| 637 | tf->device |= 1 << 7; |
| 638 | } else if (dev->flags & ATA_DFLAG_LBA) { |
| 639 | tf->flags |= ATA_TFLAG_LBA; |
| 640 | |
| 641 | if (lba_28_ok(block, n_block)) { |
| 642 | /* use LBA28 */ |
| 643 | tf->device |= (block >> 24) & 0xf; |
| 644 | } else if (lba_48_ok(block, n_block)) { |
| 645 | if (!(dev->flags & ATA_DFLAG_LBA48)) |
| 646 | return -ERANGE; |
| 647 | |
| 648 | /* use LBA48 */ |
| 649 | tf->flags |= ATA_TFLAG_LBA48; |
| 650 | |
| 651 | tf->hob_nsect = (n_block >> 8) & 0xff; |
| 652 | |
| 653 | tf->hob_lbah = (block >> 40) & 0xff; |
| 654 | tf->hob_lbam = (block >> 32) & 0xff; |
| 655 | tf->hob_lbal = (block >> 24) & 0xff; |
| 656 | } else |
| 657 | /* request too large even for LBA48 */ |
| 658 | return -ERANGE; |
| 659 | |
| 660 | if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) |
| 661 | return -EINVAL; |
| 662 | |
| 663 | tf->nsect = n_block & 0xff; |
| 664 | |
| 665 | tf->lbah = (block >> 16) & 0xff; |
| 666 | tf->lbam = (block >> 8) & 0xff; |
| 667 | tf->lbal = block & 0xff; |
| 668 | |
| 669 | tf->device |= ATA_LBA; |
| 670 | } else { |
| 671 | /* CHS */ |
| 672 | u32 sect, head, cyl, track; |
| 673 | |
| 674 | /* The request -may- be too large for CHS addressing. */ |
| 675 | if (!lba_28_ok(block, n_block)) |
| 676 | return -ERANGE; |
| 677 | |
| 678 | if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) |
| 679 | return -EINVAL; |
| 680 | |
| 681 | /* Convert LBA to CHS */ |
| 682 | track = (u32)block / dev->sectors; |
| 683 | cyl = track / dev->heads; |
| 684 | head = track % dev->heads; |
| 685 | sect = (u32)block % dev->sectors + 1; |
| 686 | |
| 687 | DPRINTK("block %u track %u cyl %u head %u sect %u\n", |
| 688 | (u32)block, track, cyl, head, sect); |
| 689 | |
| 690 | /* Check whether the converted CHS can fit. |
| 691 | Cylinder: 0-65535 |
| 692 | Head: 0-15 |
| 693 | Sector: 1-255*/ |
| 694 | if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) |
| 695 | return -ERANGE; |
| 696 | |
| 697 | tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ |
| 698 | tf->lbal = sect; |
| 699 | tf->lbam = cyl; |
| 700 | tf->lbah = cyl >> 8; |
| 701 | tf->device |= head; |
| 702 | } |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | /** |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 708 | * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask |
| 709 | * @pio_mask: pio_mask |
| 710 | * @mwdma_mask: mwdma_mask |
| 711 | * @udma_mask: udma_mask |
| 712 | * |
| 713 | * Pack @pio_mask, @mwdma_mask and @udma_mask into a single |
| 714 | * unsigned int xfer_mask. |
| 715 | * |
| 716 | * LOCKING: |
| 717 | * None. |
| 718 | * |
| 719 | * RETURNS: |
| 720 | * Packed xfer_mask. |
| 721 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 722 | unsigned long ata_pack_xfermask(unsigned long pio_mask, |
| 723 | unsigned long mwdma_mask, |
| 724 | unsigned long udma_mask) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 725 | { |
| 726 | return ((pio_mask << ATA_SHIFT_PIO) & ATA_MASK_PIO) | |
| 727 | ((mwdma_mask << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA) | |
| 728 | ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA); |
| 729 | } |
| 730 | |
Tejun Heo | c0489e4 | 2006-03-24 14:07:49 +0900 | [diff] [blame] | 731 | /** |
| 732 | * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks |
| 733 | * @xfer_mask: xfer_mask to unpack |
| 734 | * @pio_mask: resulting pio_mask |
| 735 | * @mwdma_mask: resulting mwdma_mask |
| 736 | * @udma_mask: resulting udma_mask |
| 737 | * |
| 738 | * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask. |
| 739 | * Any NULL distination masks will be ignored. |
| 740 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 741 | void ata_unpack_xfermask(unsigned long xfer_mask, unsigned long *pio_mask, |
| 742 | unsigned long *mwdma_mask, unsigned long *udma_mask) |
Tejun Heo | c0489e4 | 2006-03-24 14:07:49 +0900 | [diff] [blame] | 743 | { |
| 744 | if (pio_mask) |
| 745 | *pio_mask = (xfer_mask & ATA_MASK_PIO) >> ATA_SHIFT_PIO; |
| 746 | if (mwdma_mask) |
| 747 | *mwdma_mask = (xfer_mask & ATA_MASK_MWDMA) >> ATA_SHIFT_MWDMA; |
| 748 | if (udma_mask) |
| 749 | *udma_mask = (xfer_mask & ATA_MASK_UDMA) >> ATA_SHIFT_UDMA; |
| 750 | } |
| 751 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 752 | static const struct ata_xfer_ent { |
Tejun Heo | be9a50c | 2006-03-31 22:48:52 +0900 | [diff] [blame] | 753 | int shift, bits; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 754 | u8 base; |
| 755 | } ata_xfer_tbl[] = { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 756 | { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 }, |
| 757 | { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 }, |
| 758 | { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 }, |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 759 | { -1, }, |
| 760 | }; |
| 761 | |
| 762 | /** |
| 763 | * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask |
| 764 | * @xfer_mask: xfer_mask of interest |
| 765 | * |
| 766 | * Return matching XFER_* value for @xfer_mask. Only the highest |
| 767 | * bit of @xfer_mask is considered. |
| 768 | * |
| 769 | * LOCKING: |
| 770 | * None. |
| 771 | * |
| 772 | * RETURNS: |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 773 | * Matching XFER_* value, 0xff if no match found. |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 774 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 775 | u8 ata_xfer_mask2mode(unsigned long xfer_mask) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 776 | { |
| 777 | int highbit = fls(xfer_mask) - 1; |
| 778 | const struct ata_xfer_ent *ent; |
| 779 | |
| 780 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 781 | if (highbit >= ent->shift && highbit < ent->shift + ent->bits) |
| 782 | return ent->base + highbit - ent->shift; |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 783 | return 0xff; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /** |
| 787 | * ata_xfer_mode2mask - Find matching xfer_mask for XFER_* |
| 788 | * @xfer_mode: XFER_* of interest |
| 789 | * |
| 790 | * Return matching xfer_mask for @xfer_mode. |
| 791 | * |
| 792 | * LOCKING: |
| 793 | * None. |
| 794 | * |
| 795 | * RETURNS: |
| 796 | * Matching xfer_mask, 0 if no match found. |
| 797 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 798 | unsigned long ata_xfer_mode2mask(u8 xfer_mode) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 799 | { |
| 800 | const struct ata_xfer_ent *ent; |
| 801 | |
| 802 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 803 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 804 | return ((2 << (ent->shift + xfer_mode - ent->base)) - 1) |
| 805 | & ~((1 << ent->shift) - 1); |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * ata_xfer_mode2shift - Find matching xfer_shift for XFER_* |
| 811 | * @xfer_mode: XFER_* of interest |
| 812 | * |
| 813 | * Return matching xfer_shift for @xfer_mode. |
| 814 | * |
| 815 | * LOCKING: |
| 816 | * None. |
| 817 | * |
| 818 | * RETURNS: |
| 819 | * Matching xfer_shift, -1 if no match found. |
| 820 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 821 | int ata_xfer_mode2shift(unsigned long xfer_mode) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 822 | { |
| 823 | const struct ata_xfer_ent *ent; |
| 824 | |
| 825 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 826 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
| 827 | return ent->shift; |
| 828 | return -1; |
| 829 | } |
| 830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | /** |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 832 | * ata_mode_string - convert xfer_mask to string |
| 833 | * @xfer_mask: mask of bits supported; only highest bit counts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | * |
| 835 | * Determine string which represents the highest speed |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 836 | * (highest bit in @modemask). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | * |
| 838 | * LOCKING: |
| 839 | * None. |
| 840 | * |
| 841 | * RETURNS: |
| 842 | * Constant C string representing highest speed listed in |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 843 | * @mode_mask, or the constant C string "<n/a>". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 845 | const char *ata_mode_string(unsigned long xfer_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | { |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 847 | static const char * const xfer_mode_str[] = { |
| 848 | "PIO0", |
| 849 | "PIO1", |
| 850 | "PIO2", |
| 851 | "PIO3", |
| 852 | "PIO4", |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 853 | "PIO5", |
| 854 | "PIO6", |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 855 | "MWDMA0", |
| 856 | "MWDMA1", |
| 857 | "MWDMA2", |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 858 | "MWDMA3", |
| 859 | "MWDMA4", |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 860 | "UDMA/16", |
| 861 | "UDMA/25", |
| 862 | "UDMA/33", |
| 863 | "UDMA/44", |
| 864 | "UDMA/66", |
| 865 | "UDMA/100", |
| 866 | "UDMA/133", |
| 867 | "UDMA7", |
| 868 | }; |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 869 | int highbit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 871 | highbit = fls(xfer_mask) - 1; |
| 872 | if (highbit >= 0 && highbit < ARRAY_SIZE(xfer_mode_str)) |
| 873 | return xfer_mode_str[highbit]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | return "<n/a>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Tejun Heo | 4c360c8 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 877 | static const char *sata_spd_string(unsigned int spd) |
| 878 | { |
| 879 | static const char * const spd_str[] = { |
| 880 | "1.5 Gbps", |
| 881 | "3.0 Gbps", |
| 882 | }; |
| 883 | |
| 884 | if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) |
| 885 | return "<unknown>"; |
| 886 | return spd_str[spd - 1]; |
| 887 | } |
| 888 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 889 | void ata_dev_disable(struct ata_device *dev) |
Tejun Heo | 0b8efb0 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 890 | { |
Tejun Heo | 09d7f9b | 2007-06-25 23:34:02 +0900 | [diff] [blame] | 891 | if (ata_dev_enabled(dev)) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 892 | if (ata_msg_drv(dev->link->ap)) |
Tejun Heo | 09d7f9b | 2007-06-25 23:34:02 +0900 | [diff] [blame] | 893 | ata_dev_printk(dev, KERN_WARNING, "disabled\n"); |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 894 | ata_acpi_on_disable(dev); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 895 | ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | |
| 896 | ATA_DNXFER_QUIET); |
Tejun Heo | 0b8efb0 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 897 | dev->class++; |
| 898 | } |
| 899 | } |
| 900 | |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 901 | static int ata_dev_set_dipm(struct ata_device *dev, enum link_pm policy) |
| 902 | { |
| 903 | struct ata_link *link = dev->link; |
| 904 | struct ata_port *ap = link->ap; |
| 905 | u32 scontrol; |
| 906 | unsigned int err_mask; |
| 907 | int rc; |
| 908 | |
| 909 | /* |
| 910 | * disallow DIPM for drivers which haven't set |
| 911 | * ATA_FLAG_IPM. This is because when DIPM is enabled, |
| 912 | * phy ready will be set in the interrupt status on |
| 913 | * state changes, which will cause some drivers to |
| 914 | * think there are errors - additionally drivers will |
| 915 | * need to disable hot plug. |
| 916 | */ |
| 917 | if (!(ap->flags & ATA_FLAG_IPM) || !ata_dev_enabled(dev)) { |
| 918 | ap->pm_policy = NOT_AVAILABLE; |
| 919 | return -EINVAL; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * For DIPM, we will only enable it for the |
| 924 | * min_power setting. |
| 925 | * |
| 926 | * Why? Because Disks are too stupid to know that |
| 927 | * If the host rejects a request to go to SLUMBER |
| 928 | * they should retry at PARTIAL, and instead it |
| 929 | * just would give up. So, for medium_power to |
| 930 | * work at all, we need to only allow HIPM. |
| 931 | */ |
| 932 | rc = sata_scr_read(link, SCR_CONTROL, &scontrol); |
| 933 | if (rc) |
| 934 | return rc; |
| 935 | |
| 936 | switch (policy) { |
| 937 | case MIN_POWER: |
| 938 | /* no restrictions on IPM transitions */ |
| 939 | scontrol &= ~(0x3 << 8); |
| 940 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); |
| 941 | if (rc) |
| 942 | return rc; |
| 943 | |
| 944 | /* enable DIPM */ |
| 945 | if (dev->flags & ATA_DFLAG_DIPM) |
| 946 | err_mask = ata_dev_set_feature(dev, |
| 947 | SETFEATURES_SATA_ENABLE, SATA_DIPM); |
| 948 | break; |
| 949 | case MEDIUM_POWER: |
| 950 | /* allow IPM to PARTIAL */ |
| 951 | scontrol &= ~(0x1 << 8); |
| 952 | scontrol |= (0x2 << 8); |
| 953 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); |
| 954 | if (rc) |
| 955 | return rc; |
| 956 | |
Kristen Carlson Accardi | f5456b6 | 2007-11-02 16:37:08 -0700 | [diff] [blame] | 957 | /* |
| 958 | * we don't have to disable DIPM since IPM flags |
| 959 | * disallow transitions to SLUMBER, which effectively |
| 960 | * disable DIPM if it does not support PARTIAL |
| 961 | */ |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 962 | break; |
| 963 | case NOT_AVAILABLE: |
| 964 | case MAX_PERFORMANCE: |
| 965 | /* disable all IPM transitions */ |
| 966 | scontrol |= (0x3 << 8); |
| 967 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); |
| 968 | if (rc) |
| 969 | return rc; |
| 970 | |
Kristen Carlson Accardi | f5456b6 | 2007-11-02 16:37:08 -0700 | [diff] [blame] | 971 | /* |
| 972 | * we don't have to disable DIPM since IPM flags |
| 973 | * disallow all transitions which effectively |
| 974 | * disable DIPM anyway. |
| 975 | */ |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 976 | break; |
| 977 | } |
| 978 | |
| 979 | /* FIXME: handle SET FEATURES failure */ |
| 980 | (void) err_mask; |
| 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | /** |
| 986 | * ata_dev_enable_pm - enable SATA interface power management |
Stephen Hemminger | 48166fd | 2007-10-31 10:00:27 -0700 | [diff] [blame] | 987 | * @dev: device to enable power management |
| 988 | * @policy: the link power management policy |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 989 | * |
| 990 | * Enable SATA Interface power management. This will enable |
| 991 | * Device Interface Power Management (DIPM) for min_power |
| 992 | * policy, and then call driver specific callbacks for |
| 993 | * enabling Host Initiated Power management. |
| 994 | * |
| 995 | * Locking: Caller. |
| 996 | * Returns: -EINVAL if IPM is not supported, 0 otherwise. |
| 997 | */ |
| 998 | void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy) |
| 999 | { |
| 1000 | int rc = 0; |
| 1001 | struct ata_port *ap = dev->link->ap; |
| 1002 | |
| 1003 | /* set HIPM first, then DIPM */ |
| 1004 | if (ap->ops->enable_pm) |
| 1005 | rc = ap->ops->enable_pm(ap, policy); |
| 1006 | if (rc) |
| 1007 | goto enable_pm_out; |
| 1008 | rc = ata_dev_set_dipm(dev, policy); |
| 1009 | |
| 1010 | enable_pm_out: |
| 1011 | if (rc) |
| 1012 | ap->pm_policy = MAX_PERFORMANCE; |
| 1013 | else |
| 1014 | ap->pm_policy = policy; |
| 1015 | return /* rc */; /* hopefully we can use 'rc' eventually */ |
| 1016 | } |
| 1017 | |
Stephen Rothwell | 1992a5e | 2007-10-31 14:53:32 +1100 | [diff] [blame] | 1018 | #ifdef CONFIG_PM |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 1019 | /** |
| 1020 | * ata_dev_disable_pm - disable SATA interface power management |
Stephen Hemminger | 48166fd | 2007-10-31 10:00:27 -0700 | [diff] [blame] | 1021 | * @dev: device to disable power management |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 1022 | * |
| 1023 | * Disable SATA Interface power management. This will disable |
| 1024 | * Device Interface Power Management (DIPM) without changing |
| 1025 | * policy, call driver specific callbacks for disabling Host |
| 1026 | * Initiated Power management. |
| 1027 | * |
| 1028 | * Locking: Caller. |
| 1029 | * Returns: void |
| 1030 | */ |
| 1031 | static void ata_dev_disable_pm(struct ata_device *dev) |
| 1032 | { |
| 1033 | struct ata_port *ap = dev->link->ap; |
| 1034 | |
| 1035 | ata_dev_set_dipm(dev, MAX_PERFORMANCE); |
| 1036 | if (ap->ops->disable_pm) |
| 1037 | ap->ops->disable_pm(ap); |
| 1038 | } |
Stephen Rothwell | 1992a5e | 2007-10-31 14:53:32 +1100 | [diff] [blame] | 1039 | #endif /* CONFIG_PM */ |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 1040 | |
| 1041 | void ata_lpm_schedule(struct ata_port *ap, enum link_pm policy) |
| 1042 | { |
| 1043 | ap->pm_policy = policy; |
Tejun Heo | 3ec25eb | 2008-03-27 18:37:14 +0900 | [diff] [blame] | 1044 | ap->link.eh_info.action |= ATA_EH_LPM; |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 1045 | ap->link.eh_info.flags |= ATA_EHI_NO_AUTOPSY; |
| 1046 | ata_port_schedule_eh(ap); |
| 1047 | } |
| 1048 | |
Stephen Rothwell | 1992a5e | 2007-10-31 14:53:32 +1100 | [diff] [blame] | 1049 | #ifdef CONFIG_PM |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 1050 | static void ata_lpm_enable(struct ata_host *host) |
| 1051 | { |
| 1052 | struct ata_link *link; |
| 1053 | struct ata_port *ap; |
| 1054 | struct ata_device *dev; |
| 1055 | int i; |
| 1056 | |
| 1057 | for (i = 0; i < host->n_ports; i++) { |
| 1058 | ap = host->ports[i]; |
| 1059 | ata_port_for_each_link(link, ap) { |
| 1060 | ata_link_for_each_dev(dev, link) |
| 1061 | ata_dev_disable_pm(dev); |
| 1062 | } |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | static void ata_lpm_disable(struct ata_host *host) |
| 1067 | { |
| 1068 | int i; |
| 1069 | |
| 1070 | for (i = 0; i < host->n_ports; i++) { |
| 1071 | struct ata_port *ap = host->ports[i]; |
| 1072 | ata_lpm_schedule(ap, ap->pm_policy); |
| 1073 | } |
| 1074 | } |
Stephen Rothwell | 1992a5e | 2007-10-31 14:53:32 +1100 | [diff] [blame] | 1075 | #endif /* CONFIG_PM */ |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 1076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | /** |
| 1078 | * ata_dev_classify - determine device type based on ATA-spec signature |
| 1079 | * @tf: ATA taskfile register set for device to be identified |
| 1080 | * |
| 1081 | * Determine from taskfile register contents whether a device is |
| 1082 | * ATA or ATAPI, as per "Signature and persistence" section |
| 1083 | * of ATA/PI spec (volume 1, sect 5.14). |
| 1084 | * |
| 1085 | * LOCKING: |
| 1086 | * None. |
| 1087 | * |
| 1088 | * RETURNS: |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1089 | * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP or |
| 1090 | * %ATA_DEV_UNKNOWN the event of failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | */ |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 1092 | unsigned int ata_dev_classify(const struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | { |
| 1094 | /* Apple's open source Darwin code hints that some devices only |
| 1095 | * put a proper signature into the LBA mid/high registers, |
| 1096 | * So, we only check those. It's sufficient for uniqueness. |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1097 | * |
| 1098 | * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate |
| 1099 | * signatures for ATA and ATAPI devices attached on SerialATA, |
| 1100 | * 0x3c/0xc3 and 0x69/0x96 respectively. However, SerialATA |
| 1101 | * spec has never mentioned about using different signatures |
| 1102 | * for ATA/ATAPI devices. Then, Serial ATA II: Port |
| 1103 | * Multiplier specification began to use 0x69/0x96 to identify |
| 1104 | * port multpliers and 0x3c/0xc3 to identify SEMB device. |
| 1105 | * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and |
| 1106 | * 0x69/0x96 shortly and described them as reserved for |
| 1107 | * SerialATA. |
| 1108 | * |
| 1109 | * We follow the current spec and consider that 0x69/0x96 |
| 1110 | * identifies a port multiplier and 0x3c/0xc3 a SEMB device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | */ |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1112 | if ((tf->lbam == 0) && (tf->lbah == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | DPRINTK("found ATA device by sig\n"); |
| 1114 | return ATA_DEV_ATA; |
| 1115 | } |
| 1116 | |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1117 | if ((tf->lbam == 0x14) && (tf->lbah == 0xeb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | DPRINTK("found ATAPI device by sig\n"); |
| 1119 | return ATA_DEV_ATAPI; |
| 1120 | } |
| 1121 | |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1122 | if ((tf->lbam == 0x69) && (tf->lbah == 0x96)) { |
| 1123 | DPRINTK("found PMP device by sig\n"); |
| 1124 | return ATA_DEV_PMP; |
| 1125 | } |
| 1126 | |
| 1127 | if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) { |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1128 | printk(KERN_INFO "ata: SEMB device ignored\n"); |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1129 | return ATA_DEV_SEMB_UNSUP; /* not yet */ |
| 1130 | } |
| 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | DPRINTK("unknown device\n"); |
| 1133 | return ATA_DEV_UNKNOWN; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1137 | * ata_id_string - Convert IDENTIFY DEVICE page into string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | * @id: IDENTIFY DEVICE results we will examine |
| 1139 | * @s: string into which data is output |
| 1140 | * @ofs: offset into identify device page |
| 1141 | * @len: length of string to return. must be an even number. |
| 1142 | * |
| 1143 | * The strings in the IDENTIFY DEVICE page are broken up into |
| 1144 | * 16-bit chunks. Run through the string, and output each |
| 1145 | * 8-bit chunk linearly, regardless of platform. |
| 1146 | * |
| 1147 | * LOCKING: |
| 1148 | * caller. |
| 1149 | */ |
| 1150 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1151 | void ata_id_string(const u16 *id, unsigned char *s, |
| 1152 | unsigned int ofs, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | { |
| 1154 | unsigned int c; |
| 1155 | |
| 1156 | while (len > 0) { |
| 1157 | c = id[ofs] >> 8; |
| 1158 | *s = c; |
| 1159 | s++; |
| 1160 | |
| 1161 | c = id[ofs] & 0xff; |
| 1162 | *s = c; |
| 1163 | s++; |
| 1164 | |
| 1165 | ofs++; |
| 1166 | len -= 2; |
| 1167 | } |
| 1168 | } |
| 1169 | |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1170 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1171 | * ata_id_c_string - Convert IDENTIFY DEVICE page into C string |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1172 | * @id: IDENTIFY DEVICE results we will examine |
| 1173 | * @s: string into which data is output |
| 1174 | * @ofs: offset into identify device page |
| 1175 | * @len: length of string to return. must be an odd number. |
| 1176 | * |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1177 | * This function is identical to ata_id_string except that it |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1178 | * trims trailing spaces and terminates the resulting string with |
| 1179 | * null. @len must be actual maximum length (even number) + 1. |
| 1180 | * |
| 1181 | * LOCKING: |
| 1182 | * caller. |
| 1183 | */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1184 | void ata_id_c_string(const u16 *id, unsigned char *s, |
| 1185 | unsigned int ofs, unsigned int len) |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1186 | { |
| 1187 | unsigned char *p; |
| 1188 | |
| 1189 | WARN_ON(!(len & 1)); |
| 1190 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1191 | ata_id_string(id, s, ofs, len - 1); |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1192 | |
| 1193 | p = s + strnlen(s, len - 1); |
| 1194 | while (p > s && p[-1] == ' ') |
| 1195 | p--; |
| 1196 | *p = '\0'; |
| 1197 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1198 | |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 1199 | static u64 ata_id_n_sectors(const u16 *id) |
| 1200 | { |
| 1201 | if (ata_id_has_lba(id)) { |
| 1202 | if (ata_id_has_lba48(id)) |
| 1203 | return ata_id_u64(id, 100); |
| 1204 | else |
| 1205 | return ata_id_u32(id, 60); |
| 1206 | } else { |
| 1207 | if (ata_id_current_chs_valid(id)) |
| 1208 | return ata_id_u32(id, 57); |
| 1209 | else |
| 1210 | return id[1] * id[3] * id[6]; |
| 1211 | } |
| 1212 | } |
| 1213 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1214 | static u64 ata_tf_to_lba48(struct ata_taskfile *tf) |
| 1215 | { |
| 1216 | u64 sectors = 0; |
| 1217 | |
| 1218 | sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; |
| 1219 | sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; |
| 1220 | sectors |= (tf->hob_lbal & 0xff) << 24; |
| 1221 | sectors |= (tf->lbah & 0xff) << 16; |
| 1222 | sectors |= (tf->lbam & 0xff) << 8; |
| 1223 | sectors |= (tf->lbal & 0xff); |
| 1224 | |
| 1225 | return ++sectors; |
| 1226 | } |
| 1227 | |
| 1228 | static u64 ata_tf_to_lba(struct ata_taskfile *tf) |
| 1229 | { |
| 1230 | u64 sectors = 0; |
| 1231 | |
| 1232 | sectors |= (tf->device & 0x0f) << 24; |
| 1233 | sectors |= (tf->lbah & 0xff) << 16; |
| 1234 | sectors |= (tf->lbam & 0xff) << 8; |
| 1235 | sectors |= (tf->lbal & 0xff); |
| 1236 | |
| 1237 | return ++sectors; |
| 1238 | } |
| 1239 | |
| 1240 | /** |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1241 | * ata_read_native_max_address - Read native max address |
| 1242 | * @dev: target device |
| 1243 | * @max_sectors: out parameter for the result native max address |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1244 | * |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1245 | * Perform an LBA48 or LBA28 native size query upon the device in |
| 1246 | * question. |
| 1247 | * |
| 1248 | * RETURNS: |
| 1249 | * 0 on success, -EACCES if command is aborted by the drive. |
| 1250 | * -EIO on other errors. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1251 | */ |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1252 | 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] | 1253 | { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1254 | unsigned int err_mask; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1255 | struct ata_taskfile tf; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1256 | int lba48 = ata_id_has_lba48(dev->id); |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1257 | |
| 1258 | ata_tf_init(dev, &tf); |
| 1259 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1260 | /* always clear all address registers */ |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1261 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1262 | |
| 1263 | if (lba48) { |
| 1264 | tf.command = ATA_CMD_READ_NATIVE_MAX_EXT; |
| 1265 | tf.flags |= ATA_TFLAG_LBA48; |
| 1266 | } else |
| 1267 | tf.command = ATA_CMD_READ_NATIVE_MAX; |
| 1268 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1269 | tf.protocol |= ATA_PROT_NODATA; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1270 | tf.device |= ATA_LBA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1271 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1272 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1273 | if (err_mask) { |
| 1274 | ata_dev_printk(dev, KERN_WARNING, "failed to read native " |
| 1275 | "max address (err_mask=0x%x)\n", err_mask); |
| 1276 | if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) |
| 1277 | return -EACCES; |
| 1278 | return -EIO; |
| 1279 | } |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1280 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1281 | if (lba48) |
| 1282 | *max_sectors = ata_tf_to_lba48(&tf); |
| 1283 | else |
| 1284 | *max_sectors = ata_tf_to_lba(&tf); |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1285 | if (dev->horkage & ATA_HORKAGE_HPA_SIZE) |
Alan Cox | 93328e1 | 2007-09-29 04:06:48 -0400 | [diff] [blame] | 1286 | (*max_sectors)--; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1287 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /** |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1291 | * ata_set_max_sectors - Set max sectors |
| 1292 | * @dev: target device |
Randy Dunlap | 6b38d1d | 2007-05-01 17:35:55 -0700 | [diff] [blame] | 1293 | * @new_sectors: new max sectors value to set for the device |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1294 | * |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1295 | * Set max sectors of @dev to @new_sectors. |
| 1296 | * |
| 1297 | * RETURNS: |
| 1298 | * 0 on success, -EACCES if command is aborted or denied (due to |
| 1299 | * previous non-volatile SET_MAX) by the drive. -EIO on other |
| 1300 | * errors. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1301 | */ |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1302 | 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] | 1303 | { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1304 | unsigned int err_mask; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1305 | struct ata_taskfile tf; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1306 | int lba48 = ata_id_has_lba48(dev->id); |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1307 | |
| 1308 | new_sectors--; |
| 1309 | |
| 1310 | ata_tf_init(dev, &tf); |
| 1311 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1312 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1313 | |
| 1314 | if (lba48) { |
| 1315 | tf.command = ATA_CMD_SET_MAX_EXT; |
| 1316 | tf.flags |= ATA_TFLAG_LBA48; |
| 1317 | |
| 1318 | tf.hob_lbal = (new_sectors >> 24) & 0xff; |
| 1319 | tf.hob_lbam = (new_sectors >> 32) & 0xff; |
| 1320 | tf.hob_lbah = (new_sectors >> 40) & 0xff; |
Tejun Heo | 1e582ba | 2007-09-21 20:07:14 +0900 | [diff] [blame] | 1321 | } else { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1322 | tf.command = ATA_CMD_SET_MAX; |
| 1323 | |
Tejun Heo | 1e582ba | 2007-09-21 20:07:14 +0900 | [diff] [blame] | 1324 | tf.device |= (new_sectors >> 24) & 0xf; |
| 1325 | } |
| 1326 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1327 | tf.protocol |= ATA_PROT_NODATA; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1328 | tf.device |= ATA_LBA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1329 | |
| 1330 | tf.lbal = (new_sectors >> 0) & 0xff; |
| 1331 | tf.lbam = (new_sectors >> 8) & 0xff; |
| 1332 | tf.lbah = (new_sectors >> 16) & 0xff; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1333 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1334 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1335 | if (err_mask) { |
| 1336 | ata_dev_printk(dev, KERN_WARNING, "failed to set " |
| 1337 | "max address (err_mask=0x%x)\n", err_mask); |
| 1338 | if (err_mask == AC_ERR_DEV && |
| 1339 | (tf.feature & (ATA_ABORTED | ATA_IDNF))) |
| 1340 | return -EACCES; |
| 1341 | return -EIO; |
| 1342 | } |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1343 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1344 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * ata_hpa_resize - Resize a device with an HPA set |
| 1349 | * @dev: Device to resize |
| 1350 | * |
| 1351 | * Read the size of an LBA28 or LBA48 disk with HPA features and resize |
| 1352 | * it if required to the full size of the media. The caller must check |
| 1353 | * the drive has the HPA feature set enabled. |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1354 | * |
| 1355 | * RETURNS: |
| 1356 | * 0 on success, -errno on failure. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1357 | */ |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1358 | static int ata_hpa_resize(struct ata_device *dev) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1359 | { |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1360 | struct ata_eh_context *ehc = &dev->link->eh_context; |
| 1361 | int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; |
| 1362 | u64 sectors = ata_id_n_sectors(dev->id); |
| 1363 | u64 native_sectors; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1364 | int rc; |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1365 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1366 | /* do we need to do it? */ |
| 1367 | if (dev->class != ATA_DEV_ATA || |
| 1368 | !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || |
| 1369 | (dev->horkage & ATA_HORKAGE_BROKEN_HPA)) |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1370 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1371 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1372 | /* read native max address */ |
| 1373 | rc = ata_read_native_max_address(dev, &native_sectors); |
| 1374 | if (rc) { |
Tejun Heo | dda7aba | 2008-03-23 21:05:15 +0900 | [diff] [blame] | 1375 | /* If device aborted the command or HPA isn't going to |
| 1376 | * be unlocked, skip HPA resizing. |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1377 | */ |
Tejun Heo | dda7aba | 2008-03-23 21:05:15 +0900 | [diff] [blame] | 1378 | if (rc == -EACCES || !ata_ignore_hpa) { |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1379 | ata_dev_printk(dev, KERN_WARNING, "HPA support seems " |
Tejun Heo | dda7aba | 2008-03-23 21:05:15 +0900 | [diff] [blame] | 1380 | "broken, skipping HPA handling\n"); |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1381 | dev->horkage |= ATA_HORKAGE_BROKEN_HPA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1382 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1383 | /* we can continue if device aborted the command */ |
| 1384 | if (rc == -EACCES) |
| 1385 | rc = 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1386 | } |
Tejun Heo | 37301a5 | 2007-06-25 20:45:54 +0900 | [diff] [blame] | 1387 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1388 | return rc; |
| 1389 | } |
| 1390 | |
| 1391 | /* nothing to do? */ |
| 1392 | if (native_sectors <= sectors || !ata_ignore_hpa) { |
| 1393 | if (!print_info || native_sectors == sectors) |
| 1394 | return 0; |
| 1395 | |
| 1396 | if (native_sectors > sectors) |
| 1397 | ata_dev_printk(dev, KERN_INFO, |
| 1398 | "HPA detected: current %llu, native %llu\n", |
| 1399 | (unsigned long long)sectors, |
| 1400 | (unsigned long long)native_sectors); |
| 1401 | else if (native_sectors < sectors) |
| 1402 | ata_dev_printk(dev, KERN_WARNING, |
| 1403 | "native sectors (%llu) is smaller than " |
| 1404 | "sectors (%llu)\n", |
| 1405 | (unsigned long long)native_sectors, |
| 1406 | (unsigned long long)sectors); |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
| 1410 | /* let's unlock HPA */ |
| 1411 | rc = ata_set_max_sectors(dev, native_sectors); |
| 1412 | if (rc == -EACCES) { |
| 1413 | /* if device aborted the command, skip HPA resizing */ |
| 1414 | ata_dev_printk(dev, KERN_WARNING, "device aborted resize " |
| 1415 | "(%llu -> %llu), skipping HPA handling\n", |
| 1416 | (unsigned long long)sectors, |
| 1417 | (unsigned long long)native_sectors); |
| 1418 | dev->horkage |= ATA_HORKAGE_BROKEN_HPA; |
| 1419 | return 0; |
| 1420 | } else if (rc) |
| 1421 | return rc; |
| 1422 | |
| 1423 | /* re-read IDENTIFY data */ |
| 1424 | rc = ata_dev_reread_id(dev, 0); |
| 1425 | if (rc) { |
| 1426 | ata_dev_printk(dev, KERN_ERR, "failed to re-read IDENTIFY " |
| 1427 | "data after HPA resizing\n"); |
| 1428 | return rc; |
| 1429 | } |
| 1430 | |
| 1431 | if (print_info) { |
| 1432 | u64 new_sectors = ata_id_n_sectors(dev->id); |
| 1433 | ata_dev_printk(dev, KERN_INFO, |
| 1434 | "HPA unlocked: %llu -> %llu, native %llu\n", |
| 1435 | (unsigned long long)sectors, |
| 1436 | (unsigned long long)new_sectors, |
| 1437 | (unsigned long long)native_sectors); |
| 1438 | } |
| 1439 | |
| 1440 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1443 | /** |
| 1444 | * ata_noop_dev_select - Select device 0/1 on ATA bus |
| 1445 | * @ap: ATA channel to manipulate |
| 1446 | * @device: ATA device (numbered from zero) to select |
| 1447 | * |
| 1448 | * This function performs no actual function. |
| 1449 | * |
| 1450 | * May be used as the dev_select() entry in ata_port_operations. |
| 1451 | * |
| 1452 | * LOCKING: |
| 1453 | * caller. |
| 1454 | */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1455 | void ata_noop_dev_select(struct ata_port *ap, unsigned int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
| 1457 | } |
| 1458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | /** |
| 1460 | * ata_dump_id - IDENTIFY DEVICE info debugging output |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1461 | * @id: IDENTIFY DEVICE page to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | * |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1463 | * Dump selected 16-bit words from the given IDENTIFY DEVICE |
| 1464 | * page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | * |
| 1466 | * LOCKING: |
| 1467 | * caller. |
| 1468 | */ |
| 1469 | |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1470 | static inline void ata_dump_id(const u16 *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | { |
| 1472 | DPRINTK("49==0x%04x " |
| 1473 | "53==0x%04x " |
| 1474 | "63==0x%04x " |
| 1475 | "64==0x%04x " |
| 1476 | "75==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1477 | id[49], |
| 1478 | id[53], |
| 1479 | id[63], |
| 1480 | id[64], |
| 1481 | id[75]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | DPRINTK("80==0x%04x " |
| 1483 | "81==0x%04x " |
| 1484 | "82==0x%04x " |
| 1485 | "83==0x%04x " |
| 1486 | "84==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1487 | id[80], |
| 1488 | id[81], |
| 1489 | id[82], |
| 1490 | id[83], |
| 1491 | id[84]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | DPRINTK("88==0x%04x " |
| 1493 | "93==0x%04x\n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1494 | id[88], |
| 1495 | id[93]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1498 | /** |
| 1499 | * ata_id_xfermask - Compute xfermask from the given IDENTIFY data |
| 1500 | * @id: IDENTIFY data to compute xfer mask from |
| 1501 | * |
| 1502 | * Compute the xfermask for this device. This is not as trivial |
| 1503 | * as it seems if we must consider early devices correctly. |
| 1504 | * |
| 1505 | * FIXME: pre IDE drive timing (do we care ?). |
| 1506 | * |
| 1507 | * LOCKING: |
| 1508 | * None. |
| 1509 | * |
| 1510 | * RETURNS: |
| 1511 | * Computed xfermask |
| 1512 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 1513 | unsigned long ata_id_xfermask(const u16 *id) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1514 | { |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 1515 | unsigned long pio_mask, mwdma_mask, udma_mask; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1516 | |
| 1517 | /* Usual case. Word 53 indicates word 64 is valid */ |
| 1518 | if (id[ATA_ID_FIELD_VALID] & (1 << 1)) { |
| 1519 | pio_mask = id[ATA_ID_PIO_MODES] & 0x03; |
| 1520 | pio_mask <<= 3; |
| 1521 | pio_mask |= 0x7; |
| 1522 | } else { |
| 1523 | /* If word 64 isn't valid then Word 51 high byte holds |
| 1524 | * the PIO timing number for the maximum. Turn it into |
| 1525 | * a mask. |
| 1526 | */ |
Lennert Buytenhek | 7a0f1c8 | 2007-01-29 13:28:47 +0100 | [diff] [blame] | 1527 | u8 mode = (id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF; |
Alan Cox | 46767aeb | 2006-09-29 18:26:47 +0100 | [diff] [blame] | 1528 | if (mode < 5) /* Valid PIO range */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1529 | pio_mask = (2 << mode) - 1; |
Alan Cox | 46767aeb | 2006-09-29 18:26:47 +0100 | [diff] [blame] | 1530 | else |
| 1531 | pio_mask = 1; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1532 | |
| 1533 | /* But wait.. there's more. Design your standards by |
| 1534 | * committee and you too can get a free iordy field to |
| 1535 | * process. However its the speeds not the modes that |
| 1536 | * are supported... Note drivers using the timing API |
| 1537 | * will get this right anyway |
| 1538 | */ |
| 1539 | } |
| 1540 | |
| 1541 | mwdma_mask = id[ATA_ID_MWDMA_MODES] & 0x07; |
Tejun Heo | fb21f0d | 2006-03-12 12:34:35 +0900 | [diff] [blame] | 1542 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1543 | if (ata_id_is_cfa(id)) { |
| 1544 | /* |
| 1545 | * Process compact flash extended modes |
| 1546 | */ |
| 1547 | int pio = id[163] & 0x7; |
| 1548 | int dma = (id[163] >> 3) & 7; |
| 1549 | |
| 1550 | if (pio) |
| 1551 | pio_mask |= (1 << 5); |
| 1552 | if (pio > 1) |
| 1553 | pio_mask |= (1 << 6); |
| 1554 | if (dma) |
| 1555 | mwdma_mask |= (1 << 3); |
| 1556 | if (dma > 1) |
| 1557 | mwdma_mask |= (1 << 4); |
| 1558 | } |
| 1559 | |
Tejun Heo | fb21f0d | 2006-03-12 12:34:35 +0900 | [diff] [blame] | 1560 | udma_mask = 0; |
| 1561 | if (id[ATA_ID_FIELD_VALID] & (1 << 2)) |
| 1562 | udma_mask = id[ATA_ID_UDMA_MODES] & 0xff; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1563 | |
| 1564 | return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 1565 | } |
| 1566 | |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1567 | /** |
Jeff Garzik | 442eacc | 2007-12-19 04:25:10 -0500 | [diff] [blame] | 1568 | * ata_pio_queue_task - Queue port_task |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1569 | * @ap: The ata_port to queue port_task for |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 1570 | * @fn: workqueue function to be scheduled |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1571 | * @data: data for @fn to use |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 1572 | * @delay: delay time for workqueue function |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1573 | * |
| 1574 | * Schedule @fn(@data) for execution after @delay jiffies using |
| 1575 | * port_task. There is one port_task per port and it's the |
| 1576 | * user(low level driver)'s responsibility to make sure that only |
| 1577 | * one task is active at any given time. |
| 1578 | * |
| 1579 | * libata core layer takes care of synchronization between |
Jeff Garzik | 442eacc | 2007-12-19 04:25:10 -0500 | [diff] [blame] | 1580 | * port_task and EH. ata_pio_queue_task() may be ignored for EH |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1581 | * synchronization. |
| 1582 | * |
| 1583 | * LOCKING: |
| 1584 | * Inherited from caller. |
| 1585 | */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame^] | 1586 | void ata_pio_queue_task(struct ata_port *ap, void *data, unsigned long delay) |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1587 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 1588 | ap->port_task_data = data; |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1589 | |
Oleg Nesterov | 45a66c1 | 2007-07-09 11:46:13 -0700 | [diff] [blame] | 1590 | /* may fail if ata_port_flush_task() in progress */ |
| 1591 | queue_delayed_work(ata_wq, &ap->port_task, delay); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * ata_port_flush_task - Flush port_task |
| 1596 | * @ap: The ata_port to flush port_task for |
| 1597 | * |
| 1598 | * After this function completes, port_task is guranteed not to |
| 1599 | * be running or scheduled. |
| 1600 | * |
| 1601 | * LOCKING: |
| 1602 | * Kernel thread context (may sleep) |
| 1603 | */ |
| 1604 | void ata_port_flush_task(struct ata_port *ap) |
| 1605 | { |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1606 | DPRINTK("ENTER\n"); |
| 1607 | |
Oleg Nesterov | 45a66c1 | 2007-07-09 11:46:13 -0700 | [diff] [blame] | 1608 | cancel_rearming_delayed_work(&ap->port_task); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1609 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1610 | if (ata_msg_ctl(ap)) |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 1611 | ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __func__); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 1612 | } |
| 1613 | |
Adrian Bunk | 7102d23 | 2007-01-04 00:09:36 +0100 | [diff] [blame] | 1614 | static void ata_qc_complete_internal(struct ata_queued_cmd *qc) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1615 | { |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1616 | struct completion *waiting = qc->private_data; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1617 | |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1618 | complete(waiting); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /** |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1622 | * ata_exec_internal_sg - execute libata internal command |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1623 | * @dev: Device to which the command is sent |
| 1624 | * @tf: Taskfile registers for the command and the result |
Tejun Heo | d69cf37 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1625 | * @cdb: CDB for packet command |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1626 | * @dma_dir: Data tranfer direction of the command |
Randy Dunlap | 5c1ad8b | 2007-10-18 14:12:26 -0700 | [diff] [blame] | 1627 | * @sgl: sg list for the data buffer of the command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1628 | * @n_elem: Number of sg entries |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1629 | * @timeout: Timeout in msecs (0 for default) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1630 | * |
| 1631 | * Executes libata internal command with timeout. @tf contains |
| 1632 | * command on entry and result on return. Timeout and error |
| 1633 | * conditions are reported via return value. No recovery action |
| 1634 | * is taken after a command times out. It's caller's duty to |
| 1635 | * clean up after timeout. |
| 1636 | * |
| 1637 | * LOCKING: |
| 1638 | * None. Should be called with kernel context, might sleep. |
Tejun Heo | 551e888 | 2006-06-12 14:09:49 +0900 | [diff] [blame] | 1639 | * |
| 1640 | * RETURNS: |
| 1641 | * Zero on success, AC_ERR_* mask on failure |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1642 | */ |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1643 | unsigned ata_exec_internal_sg(struct ata_device *dev, |
| 1644 | struct ata_taskfile *tf, const u8 *cdb, |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1645 | int dma_dir, struct scatterlist *sgl, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1646 | unsigned int n_elem, unsigned long timeout) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1647 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1648 | struct ata_link *link = dev->link; |
| 1649 | struct ata_port *ap = link->ap; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1650 | u8 command = tf->command; |
| 1651 | struct ata_queued_cmd *qc; |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1652 | unsigned int tag, preempted_tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1653 | u32 preempted_sactive, preempted_qc_active; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1654 | int preempted_nr_active_links; |
Ingo Molnar | 60be6b9 | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 1655 | DECLARE_COMPLETION_ONSTACK(wait); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1656 | unsigned long flags; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1657 | unsigned int err_mask; |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1658 | int rc; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1659 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1660 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1661 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 1662 | /* no internal command while frozen */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1663 | if (ap->pflags & ATA_PFLAG_FROZEN) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1664 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 1665 | return AC_ERR_SYSTEM; |
| 1666 | } |
| 1667 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1668 | /* initialize internal qc */ |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1669 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1670 | /* XXX: Tag 0 is used for drivers with legacy EH as some |
| 1671 | * drivers choke if any other tag is given. This breaks |
| 1672 | * ata_tag_internal() test for those drivers. Don't use new |
| 1673 | * EH stuff without converting to it. |
| 1674 | */ |
| 1675 | if (ap->ops->error_handler) |
| 1676 | tag = ATA_TAG_INTERNAL; |
| 1677 | else |
| 1678 | tag = 0; |
| 1679 | |
Tejun Heo | 6cec4a3 | 2006-05-15 21:03:41 +0900 | [diff] [blame] | 1680 | if (test_and_set_bit(tag, &ap->qc_allocated)) |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1681 | BUG(); |
Tejun Heo | f69499f | 2006-05-15 20:58:03 +0900 | [diff] [blame] | 1682 | qc = __ata_qc_from_tag(ap, tag); |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1683 | |
| 1684 | qc->tag = tag; |
| 1685 | qc->scsicmd = NULL; |
| 1686 | qc->ap = ap; |
| 1687 | qc->dev = dev; |
| 1688 | ata_qc_reinit(qc); |
| 1689 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1690 | preempted_tag = link->active_tag; |
| 1691 | preempted_sactive = link->sactive; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1692 | preempted_qc_active = ap->qc_active; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1693 | preempted_nr_active_links = ap->nr_active_links; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1694 | link->active_tag = ATA_TAG_POISON; |
| 1695 | link->sactive = 0; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1696 | ap->qc_active = 0; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1697 | ap->nr_active_links = 0; |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1698 | |
| 1699 | /* prepare & issue qc */ |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1700 | qc->tf = *tf; |
Tejun Heo | d69cf37 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1701 | if (cdb) |
| 1702 | memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); |
Tejun Heo | e61e067 | 2006-05-15 20:57:40 +0900 | [diff] [blame] | 1703 | qc->flags |= ATA_QCFLAG_RESULT_TF; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1704 | qc->dma_dir = dma_dir; |
| 1705 | if (dma_dir != DMA_NONE) { |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1706 | unsigned int i, buflen = 0; |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1707 | struct scatterlist *sg; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1708 | |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1709 | for_each_sg(sgl, sg, n_elem, i) |
| 1710 | buflen += sg->length; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1711 | |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1712 | ata_sg_init(qc, sgl, n_elem); |
Brian King | 49c8042 | 2007-01-30 11:32:26 -0600 | [diff] [blame] | 1713 | qc->nbytes = buflen; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1714 | } |
| 1715 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1716 | qc->private_data = &wait; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1717 | qc->complete_fn = ata_qc_complete_internal; |
| 1718 | |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 1719 | ata_qc_issue(qc); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1720 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1721 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1722 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1723 | if (!timeout) |
| 1724 | timeout = ata_probe_timeout * 1000 / HZ; |
| 1725 | |
| 1726 | rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); |
Albert Lee | 41ade50 | 2006-03-14 11:19:04 +0800 | [diff] [blame] | 1727 | |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1728 | ata_port_flush_task(ap); |
| 1729 | |
| 1730 | if (!rc) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1731 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1732 | |
| 1733 | /* We're racing with irq here. If we lose, the |
| 1734 | * following test prevents us from completing the qc |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1735 | * twice. If we win, the port is frozen and will be |
| 1736 | * cleaned up by ->post_internal_cmd(). |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1737 | */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1738 | if (qc->flags & ATA_QCFLAG_ACTIVE) { |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1739 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 1740 | |
| 1741 | if (ap->ops->error_handler) |
| 1742 | ata_port_freeze(ap); |
| 1743 | else |
| 1744 | ata_qc_complete(qc); |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 1745 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1746 | if (ata_msg_warn(ap)) |
| 1747 | ata_dev_printk(dev, KERN_WARNING, |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 1748 | "qc timeout (cmd 0x%x)\n", command); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1749 | } |
| 1750 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1751 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1752 | } |
| 1753 | |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1754 | /* do post_internal_cmd */ |
| 1755 | if (ap->ops->post_internal_cmd) |
| 1756 | ap->ops->post_internal_cmd(qc); |
| 1757 | |
Tejun Heo | a51d644 | 2007-03-20 15:24:11 +0900 | [diff] [blame] | 1758 | /* perform minimal error analysis */ |
| 1759 | if (qc->flags & ATA_QCFLAG_FAILED) { |
| 1760 | if (qc->result_tf.command & (ATA_ERR | ATA_DF)) |
| 1761 | qc->err_mask |= AC_ERR_DEV; |
| 1762 | |
| 1763 | if (!qc->err_mask) |
| 1764 | qc->err_mask |= AC_ERR_OTHER; |
| 1765 | |
| 1766 | if (qc->err_mask & ~AC_ERR_OTHER) |
| 1767 | qc->err_mask &= ~AC_ERR_OTHER; |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1768 | } |
| 1769 | |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1770 | /* finish up */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1771 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1772 | |
Tejun Heo | e61e067 | 2006-05-15 20:57:40 +0900 | [diff] [blame] | 1773 | *tf = qc->result_tf; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1774 | err_mask = qc->err_mask; |
| 1775 | |
| 1776 | ata_qc_free(qc); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1777 | link->active_tag = preempted_tag; |
| 1778 | link->sactive = preempted_sactive; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1779 | ap->qc_active = preempted_qc_active; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1780 | ap->nr_active_links = preempted_nr_active_links; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1781 | |
Tejun Heo | 1f7dd3e9 | 2006-03-24 15:25:30 +0900 | [diff] [blame] | 1782 | /* XXX - Some LLDDs (sata_mv) disable port on command failure. |
| 1783 | * Until those drivers are fixed, we detect the condition |
| 1784 | * here, fail the command with AC_ERR_SYSTEM and reenable the |
| 1785 | * port. |
| 1786 | * |
| 1787 | * Note that this doesn't change any behavior as internal |
| 1788 | * command failure results in disabling the device in the |
| 1789 | * higher layer for LLDDs without new reset/EH callbacks. |
| 1790 | * |
| 1791 | * Kill the following code as soon as those drivers are fixed. |
| 1792 | */ |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 1793 | if (ap->flags & ATA_FLAG_DISABLED) { |
Tejun Heo | 1f7dd3e9 | 2006-03-24 15:25:30 +0900 | [diff] [blame] | 1794 | err_mask |= AC_ERR_SYSTEM; |
| 1795 | ata_port_probe(ap); |
| 1796 | } |
| 1797 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1798 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1799 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1800 | return err_mask; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1801 | } |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | /** |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1804 | * ata_exec_internal - execute libata internal command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1805 | * @dev: Device to which the command is sent |
| 1806 | * @tf: Taskfile registers for the command and the result |
| 1807 | * @cdb: CDB for packet command |
| 1808 | * @dma_dir: Data tranfer direction of the command |
| 1809 | * @buf: Data buffer of the command |
| 1810 | * @buflen: Length of data buffer |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1811 | * @timeout: Timeout in msecs (0 for default) |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1812 | * |
| 1813 | * Wrapper around ata_exec_internal_sg() which takes simple |
| 1814 | * buffer instead of sg list. |
| 1815 | * |
| 1816 | * LOCKING: |
| 1817 | * None. Should be called with kernel context, might sleep. |
| 1818 | * |
| 1819 | * RETURNS: |
| 1820 | * Zero on success, AC_ERR_* mask on failure |
| 1821 | */ |
| 1822 | unsigned ata_exec_internal(struct ata_device *dev, |
| 1823 | struct ata_taskfile *tf, const u8 *cdb, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1824 | int dma_dir, void *buf, unsigned int buflen, |
| 1825 | unsigned long timeout) |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1826 | { |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1827 | struct scatterlist *psg = NULL, sg; |
| 1828 | unsigned int n_elem = 0; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1829 | |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1830 | if (dma_dir != DMA_NONE) { |
| 1831 | WARN_ON(!buf); |
| 1832 | sg_init_one(&sg, buf, buflen); |
| 1833 | psg = &sg; |
| 1834 | n_elem++; |
| 1835 | } |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1836 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1837 | return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem, |
| 1838 | timeout); |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | /** |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1842 | * ata_do_simple_cmd - execute simple internal command |
| 1843 | * @dev: Device to which the command is sent |
| 1844 | * @cmd: Opcode to execute |
| 1845 | * |
| 1846 | * Execute a 'simple' command, that only consists of the opcode |
| 1847 | * 'cmd' itself, without filling any other registers |
| 1848 | * |
| 1849 | * LOCKING: |
| 1850 | * Kernel thread context (may sleep). |
| 1851 | * |
| 1852 | * RETURNS: |
| 1853 | * Zero on success, AC_ERR_* mask on failure |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1854 | */ |
Tejun Heo | 77b08fb | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1855 | unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd) |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1856 | { |
| 1857 | struct ata_taskfile tf; |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1858 | |
| 1859 | ata_tf_init(dev, &tf); |
| 1860 | |
| 1861 | tf.command = cmd; |
| 1862 | tf.flags |= ATA_TFLAG_DEVICE; |
| 1863 | tf.protocol = ATA_PROT_NODATA; |
| 1864 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1865 | return ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); |
Tejun Heo | e58eb58 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 1866 | } |
| 1867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | /** |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1869 | * ata_pio_need_iordy - check if iordy needed |
| 1870 | * @adev: ATA device |
| 1871 | * |
| 1872 | * Check if the current speed of the device requires IORDY. Used |
| 1873 | * by various controllers for chip configuration. |
| 1874 | */ |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1875 | |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1876 | unsigned int ata_pio_need_iordy(const struct ata_device *adev) |
| 1877 | { |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1878 | /* Controller doesn't support IORDY. Probably a pointless check |
| 1879 | as the caller should know this */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1880 | if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1881 | return 0; |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1882 | /* PIO3 and higher it is mandatory */ |
| 1883 | if (adev->pio_mode > XFER_PIO_2) |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1884 | return 1; |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1885 | /* We turn it on when possible */ |
| 1886 | if (ata_id_has_iordy(adev->id)) |
| 1887 | return 1; |
| 1888 | return 0; |
| 1889 | } |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 1890 | |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1891 | /** |
| 1892 | * ata_pio_mask_no_iordy - Return the non IORDY mask |
| 1893 | * @adev: ATA device |
| 1894 | * |
| 1895 | * Compute the highest mode possible if we are not using iordy. Return |
| 1896 | * -1 if no iordy mode is available. |
| 1897 | */ |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1898 | |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1899 | static u32 ata_pio_mask_no_iordy(const struct ata_device *adev) |
| 1900 | { |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1901 | /* 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] | 1902 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1903 | u16 pio = adev->id[ATA_ID_EIDE_PIO]; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1904 | /* Is the speed faster than the drive allows non IORDY ? */ |
| 1905 | if (pio) { |
| 1906 | /* This is cycle times not frequency - watch the logic! */ |
| 1907 | if (pio > 240) /* PIO2 is 240nS per cycle */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1908 | return 3 << ATA_SHIFT_PIO; |
| 1909 | return 7 << ATA_SHIFT_PIO; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1910 | } |
| 1911 | } |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1912 | return 3 << ATA_SHIFT_PIO; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | /** |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1916 | * ata_dev_read_id - Read ID data from the specified device |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1917 | * @dev: target device |
| 1918 | * @p_class: pointer to class of the target device (may be changed) |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1919 | * @flags: ATA_READID_* flags |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 1920 | * @id: buffer to read IDENTIFY data into |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1921 | * |
| 1922 | * Read ID data from the specified device. ATA_CMD_ID_ATA is |
| 1923 | * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI |
Tejun Heo | aec5c3c | 2006-03-25 01:33:34 +0900 | [diff] [blame] | 1924 | * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS |
| 1925 | * for pre-ATA4 drives. |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1926 | * |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1927 | * FIXME: ATA_CMD_ID_ATA is optional for early drives and right |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1928 | * now we abort if we hit that case. |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1929 | * |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1930 | * LOCKING: |
| 1931 | * Kernel thread context (may sleep) |
| 1932 | * |
| 1933 | * RETURNS: |
| 1934 | * 0 on success, -errno otherwise. |
| 1935 | */ |
Tejun Heo | a9beec9 | 2006-05-31 18:27:44 +0900 | [diff] [blame] | 1936 | 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] | 1937 | unsigned int flags, u16 *id) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1938 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1939 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1940 | unsigned int class = *p_class; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1941 | struct ata_taskfile tf; |
| 1942 | unsigned int err_mask = 0; |
| 1943 | const char *reason; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1944 | int may_fallback = 1, tried_spinup = 0; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1945 | int rc; |
| 1946 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1947 | if (ata_msg_ctl(ap)) |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 1948 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __func__); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1949 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1950 | retry: |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1951 | ata_tf_init(dev, &tf); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1952 | |
| 1953 | switch (class) { |
| 1954 | case ATA_DEV_ATA: |
| 1955 | tf.command = ATA_CMD_ID_ATA; |
| 1956 | break; |
| 1957 | case ATA_DEV_ATAPI: |
| 1958 | tf.command = ATA_CMD_ID_ATAPI; |
| 1959 | break; |
| 1960 | default: |
| 1961 | rc = -ENODEV; |
| 1962 | reason = "unsupported class"; |
| 1963 | goto err_out; |
| 1964 | } |
| 1965 | |
| 1966 | tf.protocol = ATA_PROT_PIO; |
Tejun Heo | 81afe89 | 2007-02-07 12:37:41 -0800 | [diff] [blame] | 1967 | |
| 1968 | /* Some devices choke if TF registers contain garbage. Make |
| 1969 | * sure those are properly initialized. |
| 1970 | */ |
| 1971 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 1972 | |
| 1973 | /* Device presence detection is unreliable on some |
| 1974 | * controllers. Always poll IDENTIFY if available. |
| 1975 | */ |
| 1976 | tf.flags |= ATA_TFLAG_POLLING; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1977 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1978 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1979 | id, sizeof(id[0]) * ATA_ID_WORDS, 0); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1980 | if (err_mask) { |
Tejun Heo | 800b399 | 2006-12-03 21:34:13 +0900 | [diff] [blame] | 1981 | if (err_mask & AC_ERR_NODEV_HINT) { |
Tejun Heo | 1ffc151 | 2008-03-23 15:16:53 +0900 | [diff] [blame] | 1982 | ata_dev_printk(dev, KERN_DEBUG, |
| 1983 | "NODEV after polling detection\n"); |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1984 | return -ENOENT; |
| 1985 | } |
| 1986 | |
Tejun Heo | 1ffc151 | 2008-03-23 15:16:53 +0900 | [diff] [blame] | 1987 | if ((err_mask == AC_ERR_DEV) && (tf.feature & ATA_ABORTED)) { |
| 1988 | /* Device or controller might have reported |
| 1989 | * the wrong device class. Give a shot at the |
| 1990 | * other IDENTIFY if the current one is |
| 1991 | * aborted by the device. |
| 1992 | */ |
| 1993 | if (may_fallback) { |
| 1994 | may_fallback = 0; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1995 | |
Tejun Heo | 1ffc151 | 2008-03-23 15:16:53 +0900 | [diff] [blame] | 1996 | if (class == ATA_DEV_ATA) |
| 1997 | class = ATA_DEV_ATAPI; |
| 1998 | else |
| 1999 | class = ATA_DEV_ATA; |
| 2000 | goto retry; |
| 2001 | } |
| 2002 | |
| 2003 | /* Control reaches here iff the device aborted |
| 2004 | * both flavors of IDENTIFYs which happens |
| 2005 | * sometimes with phantom devices. |
| 2006 | */ |
| 2007 | ata_dev_printk(dev, KERN_DEBUG, |
| 2008 | "both IDENTIFYs aborted, assuming NODEV\n"); |
| 2009 | return -ENOENT; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 2010 | } |
| 2011 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2012 | rc = -EIO; |
| 2013 | reason = "I/O error"; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2014 | goto err_out; |
| 2015 | } |
| 2016 | |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 2017 | /* Falling back doesn't make sense if ID data was read |
| 2018 | * successfully at least once. |
| 2019 | */ |
| 2020 | may_fallback = 0; |
| 2021 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2022 | swap_buf_le16(id, ATA_ID_WORDS); |
| 2023 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2024 | /* sanity check */ |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 2025 | rc = -EINVAL; |
Alan Cox | 6070068 | 2007-06-07 16:13:55 +0100 | [diff] [blame] | 2026 | reason = "device reports invalid type"; |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 2027 | |
| 2028 | if (class == ATA_DEV_ATA) { |
| 2029 | if (!ata_id_is_ata(id) && !ata_id_is_cfa(id)) |
| 2030 | goto err_out; |
| 2031 | } else { |
| 2032 | if (ata_id_is_ata(id)) |
| 2033 | goto err_out; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2034 | } |
| 2035 | |
Mark Lord | 169439c | 2007-04-17 18:26:07 -0400 | [diff] [blame] | 2036 | if (!tried_spinup && (id[2] == 0x37c8 || id[2] == 0x738c)) { |
| 2037 | tried_spinup = 1; |
| 2038 | /* |
| 2039 | * Drive powered-up in standby mode, and requires a specific |
| 2040 | * SET_FEATURES spin-up subcommand before it will accept |
| 2041 | * anything other than the original IDENTIFY command. |
| 2042 | */ |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 2043 | err_mask = ata_dev_set_feature(dev, SETFEATURES_SPINUP, 0); |
Ryan Power | fb0582f9 | 2007-08-10 13:59:35 -0700 | [diff] [blame] | 2044 | if (err_mask && id[2] != 0x738c) { |
Mark Lord | 169439c | 2007-04-17 18:26:07 -0400 | [diff] [blame] | 2045 | rc = -EIO; |
| 2046 | reason = "SPINUP failed"; |
| 2047 | goto err_out; |
| 2048 | } |
| 2049 | /* |
| 2050 | * If the drive initially returned incomplete IDENTIFY info, |
| 2051 | * we now must reissue the IDENTIFY command. |
| 2052 | */ |
| 2053 | if (id[2] == 0x37c8) |
| 2054 | goto retry; |
| 2055 | } |
| 2056 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2057 | if ((flags & ATA_READID_POSTRESET) && class == ATA_DEV_ATA) { |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2058 | /* |
| 2059 | * The exact sequence expected by certain pre-ATA4 drives is: |
| 2060 | * SRST RESET |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 2061 | * IDENTIFY (optional in early ATA) |
| 2062 | * INITIALIZE DEVICE PARAMETERS (later IDE and ATA) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2063 | * anything else.. |
| 2064 | * Some drives were very specific about that exact sequence. |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 2065 | * |
| 2066 | * Note that ATA4 says lba is mandatory so the second check |
| 2067 | * shoud never trigger. |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2068 | */ |
| 2069 | if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) { |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2070 | err_mask = ata_dev_init_params(dev, id[3], id[6]); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2071 | if (err_mask) { |
| 2072 | rc = -EIO; |
| 2073 | reason = "INIT_DEV_PARAMS failed"; |
| 2074 | goto err_out; |
| 2075 | } |
| 2076 | |
| 2077 | /* current CHS translation info (id[53-58]) might be |
| 2078 | * changed. reread the identify device info. |
| 2079 | */ |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2080 | flags &= ~ATA_READID_POSTRESET; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2081 | goto retry; |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | *p_class = class; |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 2086 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2087 | return 0; |
| 2088 | |
| 2089 | err_out: |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2090 | if (ata_msg_warn(ap)) |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2091 | ata_dev_printk(dev, KERN_WARNING, "failed to IDENTIFY " |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2092 | "(%s, err_mask=0x%x)\n", reason, err_mask); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2093 | return rc; |
| 2094 | } |
| 2095 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2096 | static inline u8 ata_dev_knobble(struct ata_device *dev) |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2097 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2098 | struct ata_port *ap = dev->link->ap; |
| 2099 | return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2100 | } |
| 2101 | |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2102 | static void ata_dev_config_ncq(struct ata_device *dev, |
| 2103 | char *desc, size_t desc_sz) |
| 2104 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2105 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2106 | int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); |
| 2107 | |
| 2108 | if (!ata_id_has_ncq(dev->id)) { |
| 2109 | desc[0] = '\0'; |
| 2110 | return; |
| 2111 | } |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2112 | if (dev->horkage & ATA_HORKAGE_NONCQ) { |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 2113 | snprintf(desc, desc_sz, "NCQ (not used)"); |
| 2114 | return; |
| 2115 | } |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2116 | if (ap->flags & ATA_FLAG_NCQ) { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2117 | hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2118 | dev->flags |= ATA_DFLAG_NCQ; |
| 2119 | } |
| 2120 | |
| 2121 | if (hdepth >= ddepth) |
| 2122 | snprintf(desc, desc_sz, "NCQ (depth %d)", ddepth); |
| 2123 | else |
| 2124 | snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth); |
| 2125 | } |
| 2126 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2127 | /** |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2128 | * ata_dev_configure - Configure the specified ATA/ATAPI device |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2129 | * @dev: Target device to configure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | * |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2131 | * Configure @dev according to @dev->id. Generic and low-level |
| 2132 | * driver specific fixups are also applied. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | * |
| 2134 | * LOCKING: |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2135 | * Kernel thread context (may sleep) |
| 2136 | * |
| 2137 | * RETURNS: |
| 2138 | * 0 on success, -errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | */ |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 2140 | int ata_dev_configure(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2142 | struct ata_port *ap = dev->link->ap; |
| 2143 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2144 | int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2145 | const u16 *id = dev->id; |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 2146 | unsigned long xfer_mask; |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2147 | char revbuf[7]; /* XYZ-99\0 */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2148 | char fwrevbuf[ATA_ID_FW_REV_LEN+1]; |
| 2149 | char modelbuf[ATA_ID_PROD_LEN+1]; |
Brian King | e6d902a | 2006-06-28 08:30:31 -0500 | [diff] [blame] | 2150 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2152 | if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 2153 | ata_dev_printk(dev, KERN_INFO, "%s: ENTER/EXIT -- nodev\n", |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 2154 | __func__); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2155 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2158 | if (ata_msg_probe(ap)) |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 2159 | ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2161 | /* set horkage */ |
| 2162 | dev->horkage |= ata_dev_blacklisted(dev); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 2163 | ata_force_horkage(dev); |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2164 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2165 | /* let ACPI work its magic */ |
| 2166 | rc = ata_acpi_on_devcfg(dev); |
| 2167 | if (rc) |
| 2168 | return rc; |
Kristen Carlson Accardi | 08573a8 | 2006-11-10 16:14:47 -0800 | [diff] [blame] | 2169 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 2170 | /* massage HPA, do it early as it might change IDENTIFY data */ |
| 2171 | rc = ata_hpa_resize(dev); |
| 2172 | if (rc) |
| 2173 | return rc; |
| 2174 | |
Tejun Heo | c39f5eb | 2006-03-13 19:51:19 +0900 | [diff] [blame] | 2175 | /* print device capabilities */ |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2176 | if (ata_msg_probe(ap)) |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2177 | ata_dev_printk(dev, KERN_DEBUG, |
| 2178 | "%s: cfg 49:%04x 82:%04x 83:%04x 84:%04x " |
| 2179 | "85:%04x 86:%04x 87:%04x 88:%04x\n", |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 2180 | __func__, |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2181 | id[49], id[82], id[83], id[84], |
| 2182 | id[85], id[86], id[87], id[88]); |
Tejun Heo | c39f5eb | 2006-03-13 19:51:19 +0900 | [diff] [blame] | 2183 | |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2184 | /* initialize to-be-configured parameters */ |
Tejun Heo | ea1dd4e | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 2185 | dev->flags &= ~ATA_DFLAG_CFG_MASK; |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2186 | dev->max_sectors = 0; |
| 2187 | dev->cdb_len = 0; |
| 2188 | dev->n_sectors = 0; |
| 2189 | dev->cylinders = 0; |
| 2190 | dev->heads = 0; |
| 2191 | dev->sectors = 0; |
| 2192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | /* |
| 2194 | * common ATA, ATAPI feature tests |
| 2195 | */ |
| 2196 | |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 2197 | /* find max transfer mode; for printk only */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2198 | xfer_mask = ata_id_xfermask(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2200 | if (ata_msg_probe(ap)) |
| 2201 | ata_dump_id(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
Albert Lee | ef143d5 | 2007-06-05 13:01:33 +0800 | [diff] [blame] | 2203 | /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ |
| 2204 | ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, |
| 2205 | sizeof(fwrevbuf)); |
| 2206 | |
| 2207 | ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, |
| 2208 | sizeof(modelbuf)); |
| 2209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | /* ATA-specific feature tests */ |
| 2211 | if (dev->class == ATA_DEV_ATA) { |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2212 | if (ata_id_is_cfa(id)) { |
| 2213 | if (id[162] & 1) /* CPRM may make this media unusable */ |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 2214 | ata_dev_printk(dev, KERN_WARNING, |
| 2215 | "supports DRM functions and may " |
| 2216 | "not be fully accessable.\n"); |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2217 | snprintf(revbuf, 7, "CFA"); |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 2218 | } else { |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 2219 | snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 2220 | /* Warn the user if the device has TPM extensions */ |
| 2221 | if (ata_id_has_tpm(id)) |
| 2222 | ata_dev_printk(dev, KERN_WARNING, |
| 2223 | "supports DRM functions and may " |
| 2224 | "not be fully accessable.\n"); |
| 2225 | } |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2226 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2227 | dev->n_sectors = ata_id_n_sectors(id); |
Tejun Heo | 2940740 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 2228 | |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2229 | if (dev->id[59] & 0x100) |
| 2230 | dev->multi_count = dev->id[59] & 0xff; |
| 2231 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2232 | if (ata_id_has_lba(id)) { |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2233 | const char *lba_desc; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2234 | char ncq_desc[20]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2235 | |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2236 | lba_desc = "LBA"; |
| 2237 | dev->flags |= ATA_DFLAG_LBA; |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2238 | if (ata_id_has_lba48(id)) { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2239 | dev->flags |= ATA_DFLAG_LBA48; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2240 | lba_desc = "LBA48"; |
Tejun Heo | 6fc49ad | 2006-11-11 20:10:45 +0900 | [diff] [blame] | 2241 | |
| 2242 | if (dev->n_sectors >= (1UL << 28) && |
| 2243 | ata_id_has_flush_ext(id)) |
| 2244 | dev->flags |= ATA_DFLAG_FLUSH_EXT; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2245 | } |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2246 | |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2247 | /* config NCQ */ |
| 2248 | ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); |
| 2249 | |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2250 | /* print device info to dmesg */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2251 | if (ata_msg_drv(ap) && print_info) { |
| 2252 | ata_dev_printk(dev, KERN_INFO, |
| 2253 | "%s: %s, %s, max %s\n", |
| 2254 | revbuf, modelbuf, fwrevbuf, |
| 2255 | ata_mode_string(xfer_mask)); |
| 2256 | ata_dev_printk(dev, KERN_INFO, |
| 2257 | "%Lu sectors, multi %u: %s %s\n", |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2258 | (unsigned long long)dev->n_sectors, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2259 | dev->multi_count, lba_desc, ncq_desc); |
| 2260 | } |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2261 | } else { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2262 | /* CHS */ |
| 2263 | |
| 2264 | /* Default translation */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2265 | dev->cylinders = id[1]; |
| 2266 | dev->heads = id[3]; |
| 2267 | dev->sectors = id[6]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2268 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2269 | if (ata_id_current_chs_valid(id)) { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2270 | /* Current CHS translation is valid. */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2271 | dev->cylinders = id[54]; |
| 2272 | dev->heads = id[55]; |
| 2273 | dev->sectors = id[56]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | /* print device info to dmesg */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2277 | if (ata_msg_drv(ap) && print_info) { |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2278 | ata_dev_printk(dev, KERN_INFO, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2279 | "%s: %s, %s, max %s\n", |
| 2280 | revbuf, modelbuf, fwrevbuf, |
| 2281 | ata_mode_string(xfer_mask)); |
Jeff Garzik | a84471f | 2007-02-26 05:51:33 -0500 | [diff] [blame] | 2282 | ata_dev_printk(dev, KERN_INFO, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2283 | "%Lu sectors, multi %u, CHS %u/%u/%u\n", |
| 2284 | (unsigned long long)dev->n_sectors, |
| 2285 | dev->multi_count, dev->cylinders, |
| 2286 | dev->heads, dev->sectors); |
| 2287 | } |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 2288 | } |
| 2289 | |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 2290 | dev->cdb_len = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | /* ATAPI-specific feature tests */ |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 2294 | else if (dev->class == ATA_DEV_ATAPI) { |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2295 | const char *cdb_intr_string = ""; |
| 2296 | const char *atapi_an_string = ""; |
Tejun Heo | 9116300 | 2008-02-21 13:25:50 +0900 | [diff] [blame] | 2297 | const char *dma_dir_string = ""; |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2298 | u32 sntf; |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2299 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2300 | rc = atapi_cdb_len(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | if ((rc < 12) || (rc > ATAPI_CDB_LEN)) { |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2302 | if (ata_msg_warn(ap)) |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2303 | ata_dev_printk(dev, KERN_WARNING, |
| 2304 | "unsupported CDB len\n"); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2305 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | goto err_out_nosup; |
| 2307 | } |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 2308 | dev->cdb_len = (unsigned int) rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2310 | /* Enable ATAPI AN if both the host and device have |
| 2311 | * the support. If PMP is attached, SNTF is required |
| 2312 | * to enable ATAPI AN to discern between PHY status |
| 2313 | * changed notifications and ATAPI ANs. |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2314 | */ |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2315 | if ((ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && |
| 2316 | (!ap->nr_pmp_links || |
| 2317 | sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2318 | unsigned int err_mask; |
| 2319 | |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2320 | /* issue SET feature command to turn this on */ |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 2321 | err_mask = ata_dev_set_feature(dev, |
| 2322 | SETFEATURES_SATA_ENABLE, SATA_AN); |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2323 | if (err_mask) |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2324 | ata_dev_printk(dev, KERN_ERR, |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2325 | "failed to enable ATAPI AN " |
| 2326 | "(err_mask=0x%x)\n", err_mask); |
| 2327 | else { |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2328 | dev->flags |= ATA_DFLAG_AN; |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2329 | atapi_an_string = ", ATAPI AN"; |
| 2330 | } |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2331 | } |
| 2332 | |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2333 | if (ata_id_cdb_intr(dev->id)) { |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 2334 | dev->flags |= ATA_DFLAG_CDB_INTR; |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2335 | cdb_intr_string = ", CDB intr"; |
| 2336 | } |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 2337 | |
Tejun Heo | 9116300 | 2008-02-21 13:25:50 +0900 | [diff] [blame] | 2338 | if (atapi_dmadir || atapi_id_dmadir(dev->id)) { |
| 2339 | dev->flags |= ATA_DFLAG_DMADIR; |
| 2340 | dma_dir_string = ", DMADIR"; |
| 2341 | } |
| 2342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | /* print device info to dmesg */ |
Borislav Petkov | 5afc814 | 2006-06-27 14:51:25 +0200 | [diff] [blame] | 2344 | if (ata_msg_drv(ap) && print_info) |
Albert Lee | ef143d5 | 2007-06-05 13:01:33 +0800 | [diff] [blame] | 2345 | ata_dev_printk(dev, KERN_INFO, |
Tejun Heo | 9116300 | 2008-02-21 13:25:50 +0900 | [diff] [blame] | 2346 | "ATAPI: %s, %s, max %s%s%s%s\n", |
Albert Lee | ef143d5 | 2007-06-05 13:01:33 +0800 | [diff] [blame] | 2347 | modelbuf, fwrevbuf, |
Tejun Heo | 12436c3 | 2006-05-15 20:59:15 +0900 | [diff] [blame] | 2348 | ata_mode_string(xfer_mask), |
Tejun Heo | 9116300 | 2008-02-21 13:25:50 +0900 | [diff] [blame] | 2349 | cdb_intr_string, atapi_an_string, |
| 2350 | dma_dir_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Tejun Heo | 914ed35 | 2006-11-01 18:39:55 +0900 | [diff] [blame] | 2353 | /* determine max_sectors */ |
| 2354 | dev->max_sectors = ATA_MAX_SECTORS; |
| 2355 | if (dev->flags & ATA_DFLAG_LBA48) |
| 2356 | dev->max_sectors = ATA_MAX_SECTORS_LBA48; |
| 2357 | |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 2358 | if (!(dev->horkage & ATA_HORKAGE_IPM)) { |
| 2359 | if (ata_id_has_hipm(dev->id)) |
| 2360 | dev->flags |= ATA_DFLAG_HIPM; |
| 2361 | if (ata_id_has_dipm(dev->id)) |
| 2362 | dev->flags |= ATA_DFLAG_DIPM; |
| 2363 | } |
| 2364 | |
Alan Cox | c5038fc | 2007-10-25 14:21:16 +0100 | [diff] [blame] | 2365 | /* Limit PATA drive on SATA cable bridge transfers to udma5, |
| 2366 | 200 sectors */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2367 | if (ata_dev_knobble(dev)) { |
Borislav Petkov | 5afc814 | 2006-06-27 14:51:25 +0200 | [diff] [blame] | 2368 | if (ata_msg_drv(ap) && print_info) |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2369 | ata_dev_printk(dev, KERN_INFO, |
| 2370 | "applying bridge limits\n"); |
Tejun Heo | 5a52913 | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 2371 | dev->udma_mask &= ATA_UDMA5; |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2372 | dev->max_sectors = ATA_MAX_SECTORS; |
| 2373 | } |
| 2374 | |
Tony Battersby | f8d8e57 | 2007-10-30 11:44:35 -0400 | [diff] [blame] | 2375 | if ((dev->class == ATA_DEV_ATAPI) && |
Albert Lee | f442cd8 | 2007-11-15 10:35:47 +0900 | [diff] [blame] | 2376 | (atapi_command_packet_set(id) == TYPE_TAPE)) { |
Tony Battersby | f8d8e57 | 2007-10-30 11:44:35 -0400 | [diff] [blame] | 2377 | dev->max_sectors = ATA_MAX_SECTORS_TAPE; |
Albert Lee | f442cd8 | 2007-11-15 10:35:47 +0900 | [diff] [blame] | 2378 | dev->horkage |= ATA_HORKAGE_STUCK_ERR; |
| 2379 | } |
Tony Battersby | f8d8e57 | 2007-10-30 11:44:35 -0400 | [diff] [blame] | 2380 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2381 | if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) |
Tejun Heo | 03ec52d | 2007-04-12 13:38:11 +0900 | [diff] [blame] | 2382 | dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, |
| 2383 | dev->max_sectors); |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 2384 | |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 2385 | if (ata_dev_blacklisted(dev) & ATA_HORKAGE_IPM) { |
| 2386 | dev->horkage |= ATA_HORKAGE_IPM; |
| 2387 | |
| 2388 | /* reset link pm_policy for this port to no pm */ |
| 2389 | ap->pm_policy = MAX_PERFORMANCE; |
| 2390 | } |
| 2391 | |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2392 | if (ap->ops->dev_config) |
Alan | cd0d3bb | 2007-03-02 00:56:15 +0000 | [diff] [blame] | 2393 | ap->ops->dev_config(dev); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2394 | |
Alan Cox | c5038fc | 2007-10-25 14:21:16 +0100 | [diff] [blame] | 2395 | if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { |
| 2396 | /* Let the user know. We don't want to disallow opens for |
| 2397 | rescue purposes, or in case the vendor is just a blithering |
| 2398 | idiot. Do this after the dev_config call as some controllers |
| 2399 | with buggy firmware may want to avoid reporting false device |
| 2400 | bugs */ |
| 2401 | |
| 2402 | if (print_info) { |
| 2403 | ata_dev_printk(dev, KERN_WARNING, |
| 2404 | "Drive reports diagnostics failure. This may indicate a drive\n"); |
| 2405 | ata_dev_printk(dev, KERN_WARNING, |
| 2406 | "fault or invalid emulation. Contact drive vendor for information.\n"); |
| 2407 | } |
| 2408 | } |
| 2409 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2410 | if (ata_msg_probe(ap)) |
| 2411 | ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n", |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 2412 | __func__, ata_chk_status(ap)); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2413 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | |
| 2415 | err_out_nosup: |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2416 | if (ata_msg_probe(ap)) |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2417 | ata_dev_printk(dev, KERN_DEBUG, |
Harvey Harrison | 7f5e4e8 | 2008-03-05 18:24:52 -0800 | [diff] [blame] | 2418 | "%s: EXIT, err\n", __func__); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2419 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | /** |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2423 | * ata_cable_40wire - return 40 wire cable type |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2424 | * @ap: port |
| 2425 | * |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2426 | * Helper method for drivers which want to hardwire 40 wire cable |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2427 | * detection. |
| 2428 | */ |
| 2429 | |
| 2430 | int ata_cable_40wire(struct ata_port *ap) |
| 2431 | { |
| 2432 | return ATA_CBL_PATA40; |
| 2433 | } |
| 2434 | |
| 2435 | /** |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2436 | * ata_cable_80wire - return 80 wire cable type |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2437 | * @ap: port |
| 2438 | * |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2439 | * Helper method for drivers which want to hardwire 80 wire cable |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2440 | * detection. |
| 2441 | */ |
| 2442 | |
| 2443 | int ata_cable_80wire(struct ata_port *ap) |
| 2444 | { |
| 2445 | return ATA_CBL_PATA80; |
| 2446 | } |
| 2447 | |
| 2448 | /** |
| 2449 | * ata_cable_unknown - return unknown PATA cable. |
| 2450 | * @ap: port |
| 2451 | * |
| 2452 | * Helper method for drivers which have no PATA cable detection. |
| 2453 | */ |
| 2454 | |
| 2455 | int ata_cable_unknown(struct ata_port *ap) |
| 2456 | { |
| 2457 | return ATA_CBL_PATA_UNK; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
Tejun Heo | c88f90c | 2007-11-27 19:43:48 +0900 | [diff] [blame] | 2461 | * ata_cable_ignore - return ignored PATA cable. |
| 2462 | * @ap: port |
| 2463 | * |
| 2464 | * Helper method for drivers which don't use cable type to limit |
| 2465 | * transfer mode. |
| 2466 | */ |
| 2467 | int ata_cable_ignore(struct ata_port *ap) |
| 2468 | { |
| 2469 | return ATA_CBL_PATA_IGN; |
| 2470 | } |
| 2471 | |
| 2472 | /** |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2473 | * ata_cable_sata - return SATA cable type |
| 2474 | * @ap: port |
| 2475 | * |
| 2476 | * Helper method for drivers which have SATA cables |
| 2477 | */ |
| 2478 | |
| 2479 | int ata_cable_sata(struct ata_port *ap) |
| 2480 | { |
| 2481 | return ATA_CBL_SATA; |
| 2482 | } |
| 2483 | |
| 2484 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | * ata_bus_probe - Reset and probe ATA bus |
| 2486 | * @ap: Bus to probe |
| 2487 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2488 | * Master ATA bus probing function. Initiates a hardware-dependent |
| 2489 | * bus reset, then attempts to identify any devices found on |
| 2490 | * the bus. |
| 2491 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2493 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | * |
| 2495 | * RETURNS: |
Tejun Heo | 96072e6 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2496 | * Zero on success, negative errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | */ |
| 2498 | |
Brian King | 8028916 | 2006-08-07 14:27:31 -0500 | [diff] [blame] | 2499 | int ata_bus_probe(struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | { |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2501 | unsigned int classes[ATA_MAX_DEVICES]; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2502 | int tries[ATA_MAX_DEVICES]; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2503 | int rc; |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2504 | struct ata_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2506 | ata_port_probe(ap); |
| 2507 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2508 | ata_link_for_each_dev(dev, &ap->link) |
| 2509 | tries[dev->devno] = ATA_PROBE_MAX_TRIES; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2510 | |
| 2511 | retry: |
Tejun Heo | cdeab11 | 2007-10-29 16:41:09 +0900 | [diff] [blame] | 2512 | ata_link_for_each_dev(dev, &ap->link) { |
| 2513 | /* If we issue an SRST then an ATA drive (not ATAPI) |
| 2514 | * may change configuration and be in PIO0 timing. If |
| 2515 | * we do a hard reset (or are coming from power on) |
| 2516 | * this is true for ATA or ATAPI. Until we've set a |
| 2517 | * suitable controller mode we should not touch the |
| 2518 | * bus as we may be talking too fast. |
| 2519 | */ |
| 2520 | dev->pio_mode = XFER_PIO_0; |
| 2521 | |
| 2522 | /* If the controller has a pio mode setup function |
| 2523 | * then use it to set the chipset to rights. Don't |
| 2524 | * touch the DMA setup as that will be dealt with when |
| 2525 | * configuring devices. |
| 2526 | */ |
| 2527 | if (ap->ops->set_piomode) |
| 2528 | ap->ops->set_piomode(ap, dev); |
| 2529 | } |
| 2530 | |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2531 | /* reset and determine device classes */ |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2532 | ap->ops->phy_reset(ap); |
Tejun Heo | 2061a47 | 2006-03-12 00:57:39 +0900 | [diff] [blame] | 2533 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2534 | ata_link_for_each_dev(dev, &ap->link) { |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2535 | if (!(ap->flags & ATA_FLAG_DISABLED) && |
| 2536 | dev->class != ATA_DEV_UNKNOWN) |
| 2537 | classes[dev->devno] = dev->class; |
| 2538 | else |
| 2539 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2540 | |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2541 | dev->class = ATA_DEV_UNKNOWN; |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2542 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2544 | ata_port_probe(ap); |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2545 | |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2546 | /* read IDENTIFY page and configure devices. We have to do the identify |
| 2547 | specific sequence bass-ackwards so that PDIAG- is released by |
| 2548 | the slave device */ |
| 2549 | |
Bartlomiej Zolnierkiewicz | a4ba7fe | 2008-04-02 10:35:15 +0900 | [diff] [blame] | 2550 | ata_link_for_each_dev_reverse(dev, &ap->link) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2551 | if (tries[dev->devno]) |
| 2552 | dev->class = classes[dev->devno]; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2553 | |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2554 | if (!ata_dev_enabled(dev)) |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2555 | continue; |
| 2556 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2557 | rc = ata_dev_read_id(dev, &dev->class, ATA_READID_POSTRESET, |
| 2558 | dev->id); |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2559 | if (rc) |
| 2560 | goto fail; |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2561 | } |
| 2562 | |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2563 | /* Now ask for the cable type as PDIAG- should have been released */ |
| 2564 | if (ap->ops->cable_detect) |
| 2565 | ap->cbl = ap->ops->cable_detect(ap); |
| 2566 | |
Alan Cox | 614fe29 | 2007-08-22 23:22:45 +0100 | [diff] [blame] | 2567 | /* We may have SATA bridge glue hiding here irrespective of the |
| 2568 | reported cable types and sensed types */ |
| 2569 | ata_link_for_each_dev(dev, &ap->link) { |
| 2570 | if (!ata_dev_enabled(dev)) |
| 2571 | continue; |
| 2572 | /* SATA drives indicate we have a bridge. We don't know which |
| 2573 | end of the link the bridge is which is a problem */ |
| 2574 | if (ata_id_is_sata(dev->id)) |
| 2575 | ap->cbl = ATA_CBL_SATA; |
| 2576 | } |
| 2577 | |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2578 | /* After the identify sequence we can now set up the devices. We do |
| 2579 | this in the normal order so that the user doesn't get confused */ |
| 2580 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2581 | ata_link_for_each_dev(dev, &ap->link) { |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2582 | if (!ata_dev_enabled(dev)) |
| 2583 | continue; |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2584 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2585 | ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO; |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 2586 | rc = ata_dev_configure(dev); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2587 | ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2588 | if (rc) |
| 2589 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | } |
| 2591 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2592 | /* configure transfer mode */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2593 | rc = ata_set_mode(&ap->link, &dev); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2594 | if (rc) |
Tejun Heo | 51713d3 | 2006-04-11 22:26:29 +0900 | [diff] [blame] | 2595 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2597 | ata_link_for_each_dev(dev, &ap->link) |
| 2598 | if (ata_dev_enabled(dev)) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2599 | return 0; |
Alan Cox | e35a9e0 | 2006-03-27 18:46:37 +0100 | [diff] [blame] | 2600 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2601 | /* no device present, disable port */ |
| 2602 | ata_port_disable(ap); |
Tejun Heo | 96072e6 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2603 | return -ENODEV; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2604 | |
| 2605 | fail: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2606 | tries[dev->devno]--; |
| 2607 | |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2608 | switch (rc) { |
| 2609 | case -EINVAL: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2610 | /* eeek, something went very wrong, give up */ |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2611 | tries[dev->devno] = 0; |
| 2612 | break; |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2613 | |
| 2614 | case -ENODEV: |
| 2615 | /* give it just one more chance */ |
| 2616 | tries[dev->devno] = min(tries[dev->devno], 1); |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2617 | case -EIO: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2618 | if (tries[dev->devno] == 1) { |
| 2619 | /* This is the last chance, better to slow |
| 2620 | * down than lose it. |
| 2621 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2622 | sata_down_spd_limit(&ap->link); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2623 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); |
| 2624 | } |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2625 | } |
| 2626 | |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2627 | if (!tries[dev->devno]) |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2628 | ata_dev_disable(dev); |
Tejun Heo | ec57375 | 2006-04-11 22:26:29 +0900 | [diff] [blame] | 2629 | |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2630 | goto retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2634 | * ata_port_probe - Mark port as enabled |
| 2635 | * @ap: Port for which we indicate enablement |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2637 | * Modify @ap data structure such that the system |
| 2638 | * thinks that the entire port is enabled. |
| 2639 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2640 | * LOCKING: host lock, or some other form of |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2641 | * serialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | */ |
| 2643 | |
| 2644 | void ata_port_probe(struct ata_port *ap) |
| 2645 | { |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2646 | ap->flags &= ~ATA_FLAG_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | /** |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2650 | * sata_print_link_status - Print SATA link status |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2651 | * @link: SATA link to printk link status about |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2652 | * |
| 2653 | * This function prints link speed and status of a SATA link. |
| 2654 | * |
| 2655 | * LOCKING: |
| 2656 | * None. |
| 2657 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2658 | void sata_print_link_status(struct ata_link *link) |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2659 | { |
Tejun Heo | 6d5f973 | 2006-04-03 00:09:41 +0900 | [diff] [blame] | 2660 | u32 sstatus, scontrol, tmp; |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2661 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2662 | if (sata_scr_read(link, SCR_STATUS, &sstatus)) |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2663 | return; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2664 | sata_scr_read(link, SCR_CONTROL, &scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2665 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2666 | if (ata_link_online(link)) { |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2667 | tmp = (sstatus >> 4) & 0xf; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2668 | ata_link_printk(link, KERN_INFO, |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2669 | "SATA link up %s (SStatus %X SControl %X)\n", |
| 2670 | sata_spd_string(tmp), sstatus, scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2671 | } else { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2672 | ata_link_printk(link, KERN_INFO, |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2673 | "SATA link down (SStatus %X SControl %X)\n", |
| 2674 | sstatus, scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | /** |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2679 | * ata_dev_pair - return other device on cable |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2680 | * @adev: device |
| 2681 | * |
| 2682 | * Obtain the other device on the same cable, or if none is |
| 2683 | * present NULL is returned |
| 2684 | */ |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2685 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2686 | struct ata_device *ata_dev_pair(struct ata_device *adev) |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2687 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2688 | struct ata_link *link = adev->link; |
| 2689 | struct ata_device *pair = &link->device[1 - adev->devno]; |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2690 | if (!ata_dev_enabled(pair)) |
Alan Cox | ebdfca6 | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2691 | return NULL; |
| 2692 | return pair; |
| 2693 | } |
| 2694 | |
| 2695 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2696 | * ata_port_disable - Disable port. |
| 2697 | * @ap: Port to be disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2699 | * Modify @ap data structure such that the system |
| 2700 | * thinks that the entire port is disabled, and should |
| 2701 | * never attempt to probe or communicate with devices |
| 2702 | * on this port. |
| 2703 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2704 | * LOCKING: host lock, or some other form of |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2705 | * serialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | */ |
| 2707 | |
| 2708 | void ata_port_disable(struct ata_port *ap) |
| 2709 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2710 | ap->link.device[0].class = ATA_DEV_NONE; |
| 2711 | ap->link.device[1].class = ATA_DEV_NONE; |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 2712 | ap->flags |= ATA_FLAG_DISABLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2715 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2716 | * sata_down_spd_limit - adjust SATA spd limit downward |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2717 | * @link: Link to adjust SATA spd limit for |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2718 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2719 | * Adjust SATA spd limit of @link downward. Note that this |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2720 | * function only adjusts the limit. The change must be applied |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2721 | * using sata_set_spd(). |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2722 | * |
| 2723 | * LOCKING: |
| 2724 | * Inherited from caller. |
| 2725 | * |
| 2726 | * RETURNS: |
| 2727 | * 0 on success, negative errno on failure |
| 2728 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2729 | int sata_down_spd_limit(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2730 | { |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2731 | u32 sstatus, spd, mask; |
| 2732 | int rc, highbit; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2733 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2734 | if (!sata_scr_valid(link)) |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2735 | return -EOPNOTSUPP; |
| 2736 | |
| 2737 | /* If SCR can be read, use it to determine the current SPD. |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2738 | * If not, use cached value in link->sata_spd. |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2739 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2740 | rc = sata_scr_read(link, SCR_STATUS, &sstatus); |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2741 | if (rc == 0) |
| 2742 | spd = (sstatus >> 4) & 0xf; |
| 2743 | else |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2744 | spd = link->sata_spd; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2745 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2746 | mask = link->sata_spd_limit; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2747 | if (mask <= 1) |
| 2748 | return -EINVAL; |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2749 | |
| 2750 | /* unconditionally mask off the highest bit */ |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2751 | highbit = fls(mask) - 1; |
| 2752 | mask &= ~(1 << highbit); |
| 2753 | |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2754 | /* Mask off all speeds higher than or equal to the current |
| 2755 | * one. Force 1.5Gbps if current SPD is not available. |
| 2756 | */ |
| 2757 | if (spd > 1) |
| 2758 | mask &= (1 << (spd - 1)) - 1; |
| 2759 | else |
| 2760 | mask &= 1; |
| 2761 | |
| 2762 | /* were we already at the bottom? */ |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2763 | if (!mask) |
| 2764 | return -EINVAL; |
| 2765 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2766 | link->sata_spd_limit = mask; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2767 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2768 | 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] | 2769 | sata_spd_string(fls(mask))); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2770 | |
| 2771 | return 0; |
| 2772 | } |
| 2773 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2774 | static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2775 | { |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2776 | struct ata_link *host_link = &link->ap->link; |
| 2777 | u32 limit, target, spd; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2778 | |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2779 | limit = link->sata_spd_limit; |
| 2780 | |
| 2781 | /* Don't configure downstream link faster than upstream link. |
| 2782 | * It doesn't speed up anything and some PMPs choke on such |
| 2783 | * configuration. |
| 2784 | */ |
| 2785 | if (!ata_is_host_link(link) && host_link->sata_spd) |
| 2786 | limit &= (1 << host_link->sata_spd) - 1; |
| 2787 | |
| 2788 | if (limit == UINT_MAX) |
| 2789 | target = 0; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2790 | else |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2791 | target = fls(limit); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2792 | |
| 2793 | spd = (*scontrol >> 4) & 0xf; |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2794 | *scontrol = (*scontrol & ~0xf0) | ((target & 0xf) << 4); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2795 | |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2796 | return spd != target; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2800 | * sata_set_spd_needed - is SATA spd configuration needed |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2801 | * @link: Link in question |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2802 | * |
| 2803 | * Test whether the spd limit in SControl matches |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2804 | * @link->sata_spd_limit. This function is used to determine |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2805 | * whether hardreset is necessary to apply SATA spd |
| 2806 | * configuration. |
| 2807 | * |
| 2808 | * LOCKING: |
| 2809 | * Inherited from caller. |
| 2810 | * |
| 2811 | * RETURNS: |
| 2812 | * 1 if SATA spd configuration is needed, 0 otherwise. |
| 2813 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2814 | int sata_set_spd_needed(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2815 | { |
| 2816 | u32 scontrol; |
| 2817 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2818 | if (sata_scr_read(link, SCR_CONTROL, &scontrol)) |
Tejun Heo | db64bcf | 2007-10-31 10:17:06 +0900 | [diff] [blame] | 2819 | return 1; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2820 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2821 | return __sata_set_spd_needed(link, &scontrol); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2825 | * sata_set_spd - set SATA spd according to spd limit |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2826 | * @link: Link to set SATA spd for |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2827 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2828 | * Set SATA spd of @link according to sata_spd_limit. |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2829 | * |
| 2830 | * LOCKING: |
| 2831 | * Inherited from caller. |
| 2832 | * |
| 2833 | * RETURNS: |
| 2834 | * 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] | 2835 | * changed. Negative errno if SCR registers are inaccessible. |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2836 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2837 | int sata_set_spd(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2838 | { |
| 2839 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2840 | int rc; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2841 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2842 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2843 | return rc; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2844 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2845 | if (!__sata_set_spd_needed(link, &scontrol)) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2846 | return 0; |
| 2847 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2848 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2849 | return rc; |
| 2850 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2851 | return 1; |
| 2852 | } |
| 2853 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2854 | /* |
| 2855 | * This mode timing computation functionality is ported over from |
| 2856 | * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik |
| 2857 | */ |
| 2858 | /* |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2859 | * 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] | 2860 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2861 | * for UDMA6, which is currently supported only by Maxtor drives. |
| 2862 | * |
| 2863 | * 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] | 2864 | */ |
| 2865 | |
| 2866 | static const struct ata_timing ata_timing[] = { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2867 | /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */ |
| 2868 | { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 }, |
| 2869 | { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 }, |
| 2870 | { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 }, |
| 2871 | { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 }, |
| 2872 | { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 }, |
| 2873 | { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 100, 0 }, |
| 2874 | { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 80, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2875 | |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2876 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, |
| 2877 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, |
| 2878 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2879 | |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2880 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, |
| 2881 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, |
| 2882 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2883 | { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 100, 0 }, |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2884 | { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 80, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2885 | |
| 2886 | /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2887 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, |
| 2888 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, |
| 2889 | { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 }, |
| 2890 | { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 }, |
| 2891 | { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 }, |
| 2892 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 }, |
| 2893 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2894 | |
| 2895 | { 0xFF } |
| 2896 | }; |
| 2897 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 2898 | #define ENOUGH(v, unit) (((v)-1)/(unit)+1) |
| 2899 | #define EZ(v, unit) ((v)?ENOUGH(v, unit):0) |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2900 | |
| 2901 | static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT) |
| 2902 | { |
| 2903 | q->setup = EZ(t->setup * 1000, T); |
| 2904 | q->act8b = EZ(t->act8b * 1000, T); |
| 2905 | q->rec8b = EZ(t->rec8b * 1000, T); |
| 2906 | q->cyc8b = EZ(t->cyc8b * 1000, T); |
| 2907 | q->active = EZ(t->active * 1000, T); |
| 2908 | q->recover = EZ(t->recover * 1000, T); |
| 2909 | q->cycle = EZ(t->cycle * 1000, T); |
| 2910 | q->udma = EZ(t->udma * 1000, UT); |
| 2911 | } |
| 2912 | |
| 2913 | void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, |
| 2914 | struct ata_timing *m, unsigned int what) |
| 2915 | { |
| 2916 | if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup); |
| 2917 | if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b); |
| 2918 | if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b); |
| 2919 | if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b); |
| 2920 | if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active); |
| 2921 | if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover); |
| 2922 | if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle); |
| 2923 | if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma); |
| 2924 | } |
| 2925 | |
Tejun Heo | 6357357 | 2007-11-27 19:43:39 +0900 | [diff] [blame] | 2926 | const struct ata_timing *ata_timing_find_mode(u8 xfer_mode) |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2927 | { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2928 | const struct ata_timing *t = ata_timing; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2929 | |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 2930 | while (xfer_mode > t->mode) |
| 2931 | t++; |
| 2932 | |
| 2933 | if (xfer_mode == t->mode) |
| 2934 | return t; |
| 2935 | return NULL; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | int ata_timing_compute(struct ata_device *adev, unsigned short speed, |
| 2939 | struct ata_timing *t, int T, int UT) |
| 2940 | { |
| 2941 | const struct ata_timing *s; |
| 2942 | struct ata_timing p; |
| 2943 | |
| 2944 | /* |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2945 | * Find the mode. |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 2946 | */ |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2947 | |
| 2948 | if (!(s = ata_timing_find_mode(speed))) |
| 2949 | return -EINVAL; |
| 2950 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 2951 | memcpy(t, s, sizeof(*s)); |
| 2952 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2953 | /* |
| 2954 | * If the drive is an EIDE drive, it can tell us it needs extended |
| 2955 | * PIO/MW_DMA cycle timing. |
| 2956 | */ |
| 2957 | |
| 2958 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ |
| 2959 | memset(&p, 0, sizeof(p)); |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 2960 | if (speed >= XFER_PIO_0 && speed <= XFER_SW_DMA_0) { |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2961 | if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO]; |
| 2962 | else p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO_IORDY]; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 2963 | } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) { |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2964 | p.cycle = adev->id[ATA_ID_EIDE_DMA_MIN]; |
| 2965 | } |
| 2966 | ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); |
| 2967 | } |
| 2968 | |
| 2969 | /* |
| 2970 | * Convert the timing to bus clock counts. |
| 2971 | */ |
| 2972 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 2973 | ata_timing_quantize(t, t, T, UT); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2974 | |
| 2975 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 2976 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, |
| 2977 | * S.M.A.R.T * and some other commands. We have to ensure that the |
| 2978 | * DMA cycle timing is slower/equal than the fastest PIO timing. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2979 | */ |
| 2980 | |
Alan | fd3367af | 2006-12-07 12:41:18 +0000 | [diff] [blame] | 2981 | if (speed > XFER_PIO_6) { |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2982 | ata_timing_compute(adev, adev->pio_mode, &p, T, UT); |
| 2983 | ata_timing_merge(&p, t, t, ATA_TIMING_ALL); |
| 2984 | } |
| 2985 | |
| 2986 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 2987 | * Lengthen active & recovery time so that cycle time is correct. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2988 | */ |
| 2989 | |
| 2990 | if (t->act8b + t->rec8b < t->cyc8b) { |
| 2991 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; |
| 2992 | t->rec8b = t->cyc8b - t->act8b; |
| 2993 | } |
| 2994 | |
| 2995 | if (t->active + t->recover < t->cycle) { |
| 2996 | t->active += (t->cycle - (t->active + t->recover)) / 2; |
| 2997 | t->recover = t->cycle - t->active; |
| 2998 | } |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 2999 | |
Alan Cox | 4f701d1 | 2007-04-23 11:55:36 +0100 | [diff] [blame] | 3000 | /* In a few cases quantisation may produce enough errors to |
| 3001 | leave t->cycle too low for the sum of active and recovery |
| 3002 | if so we must correct this */ |
| 3003 | if (t->active + t->recover > t->cycle) |
| 3004 | t->cycle = t->active + t->recover; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3005 | |
| 3006 | return 0; |
| 3007 | } |
| 3008 | |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3009 | /** |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 3010 | * ata_timing_cycle2mode - find xfer mode for the specified cycle duration |
| 3011 | * @xfer_shift: ATA_SHIFT_* value for transfer type to examine. |
| 3012 | * @cycle: cycle duration in ns |
| 3013 | * |
| 3014 | * Return matching xfer mode for @cycle. The returned mode is of |
| 3015 | * the transfer type specified by @xfer_shift. If @cycle is too |
| 3016 | * slow for @xfer_shift, 0xff is returned. If @cycle is faster |
| 3017 | * than the fastest known mode, the fasted mode is returned. |
| 3018 | * |
| 3019 | * LOCKING: |
| 3020 | * None. |
| 3021 | * |
| 3022 | * RETURNS: |
| 3023 | * Matching xfer_mode, 0xff if no match found. |
| 3024 | */ |
| 3025 | u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle) |
| 3026 | { |
| 3027 | u8 base_mode = 0xff, last_mode = 0xff; |
| 3028 | const struct ata_xfer_ent *ent; |
| 3029 | const struct ata_timing *t; |
| 3030 | |
| 3031 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 3032 | if (ent->shift == xfer_shift) |
| 3033 | base_mode = ent->base; |
| 3034 | |
| 3035 | for (t = ata_timing_find_mode(base_mode); |
| 3036 | t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { |
| 3037 | unsigned short this_cycle; |
| 3038 | |
| 3039 | switch (xfer_shift) { |
| 3040 | case ATA_SHIFT_PIO: |
| 3041 | case ATA_SHIFT_MWDMA: |
| 3042 | this_cycle = t->cycle; |
| 3043 | break; |
| 3044 | case ATA_SHIFT_UDMA: |
| 3045 | this_cycle = t->udma; |
| 3046 | break; |
| 3047 | default: |
| 3048 | return 0xff; |
| 3049 | } |
| 3050 | |
| 3051 | if (cycle > this_cycle) |
| 3052 | break; |
| 3053 | |
| 3054 | last_mode = t->mode; |
| 3055 | } |
| 3056 | |
| 3057 | return last_mode; |
| 3058 | } |
| 3059 | |
| 3060 | /** |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3061 | * ata_down_xfermask_limit - adjust dev xfer masks downward |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3062 | * @dev: Device to adjust xfer masks |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3063 | * @sel: ATA_DNXFER_* selector |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3064 | * |
| 3065 | * Adjust xfer masks of @dev downward. Note that this function |
| 3066 | * does not apply the change. Invoking ata_set_mode() afterwards |
| 3067 | * will apply the limit. |
| 3068 | * |
| 3069 | * LOCKING: |
| 3070 | * Inherited from caller. |
| 3071 | * |
| 3072 | * RETURNS: |
| 3073 | * 0 on success, negative errno on failure |
| 3074 | */ |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3075 | int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel) |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3076 | { |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3077 | char buf[32]; |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 3078 | unsigned long orig_mask, xfer_mask; |
| 3079 | unsigned long pio_mask, mwdma_mask, udma_mask; |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3080 | int quiet, highbit; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3081 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3082 | quiet = !!(sel & ATA_DNXFER_QUIET); |
| 3083 | sel &= ~ATA_DNXFER_QUIET; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3084 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3085 | xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, |
| 3086 | dev->mwdma_mask, |
| 3087 | dev->udma_mask); |
| 3088 | ata_unpack_xfermask(xfer_mask, &pio_mask, &mwdma_mask, &udma_mask); |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3089 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3090 | switch (sel) { |
| 3091 | case ATA_DNXFER_PIO: |
| 3092 | highbit = fls(pio_mask) - 1; |
| 3093 | pio_mask &= ~(1 << highbit); |
| 3094 | break; |
| 3095 | |
| 3096 | case ATA_DNXFER_DMA: |
| 3097 | if (udma_mask) { |
| 3098 | highbit = fls(udma_mask) - 1; |
| 3099 | udma_mask &= ~(1 << highbit); |
| 3100 | if (!udma_mask) |
| 3101 | return -ENOENT; |
| 3102 | } else if (mwdma_mask) { |
| 3103 | highbit = fls(mwdma_mask) - 1; |
| 3104 | mwdma_mask &= ~(1 << highbit); |
| 3105 | if (!mwdma_mask) |
| 3106 | return -ENOENT; |
| 3107 | } |
| 3108 | break; |
| 3109 | |
| 3110 | case ATA_DNXFER_40C: |
| 3111 | udma_mask &= ATA_UDMA_MASK_40C; |
| 3112 | break; |
| 3113 | |
| 3114 | case ATA_DNXFER_FORCE_PIO0: |
| 3115 | pio_mask &= 1; |
| 3116 | case ATA_DNXFER_FORCE_PIO: |
| 3117 | mwdma_mask = 0; |
| 3118 | udma_mask = 0; |
| 3119 | break; |
| 3120 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3121 | default: |
| 3122 | BUG(); |
| 3123 | } |
| 3124 | |
| 3125 | xfer_mask &= ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 3126 | |
| 3127 | if (!(xfer_mask & ATA_MASK_PIO) || xfer_mask == orig_mask) |
| 3128 | return -ENOENT; |
| 3129 | |
| 3130 | if (!quiet) { |
| 3131 | if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA)) |
| 3132 | snprintf(buf, sizeof(buf), "%s:%s", |
| 3133 | ata_mode_string(xfer_mask), |
| 3134 | ata_mode_string(xfer_mask & ATA_MASK_PIO)); |
| 3135 | else |
| 3136 | snprintf(buf, sizeof(buf), "%s", |
| 3137 | ata_mode_string(xfer_mask)); |
| 3138 | |
| 3139 | ata_dev_printk(dev, KERN_WARNING, |
| 3140 | "limiting speed to %s\n", buf); |
| 3141 | } |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3142 | |
| 3143 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, |
| 3144 | &dev->udma_mask); |
| 3145 | |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3146 | return 0; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3147 | } |
| 3148 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3149 | static int ata_dev_set_mode(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3151 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3152 | const char *dev_err_whine = ""; |
| 3153 | int ign_dev_err = 0; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3154 | unsigned int err_mask; |
| 3155 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | |
Tejun Heo | e838460 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 3157 | dev->flags &= ~ATA_DFLAG_PIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | if (dev->xfer_shift == ATA_SHIFT_PIO) |
| 3159 | dev->flags |= ATA_DFLAG_PIO; |
| 3160 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3161 | err_mask = ata_dev_set_xfermode(dev); |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3162 | |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3163 | if (err_mask & ~AC_ERR_DEV) |
| 3164 | goto fail; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3165 | |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3166 | /* revalidate */ |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 3167 | ehc->i.flags |= ATA_EHI_POST_SETMODE; |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 3168 | rc = ata_dev_revalidate(dev, ATA_DEV_UNKNOWN, 0); |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 3169 | ehc->i.flags &= ~ATA_EHI_POST_SETMODE; |
Tejun Heo | 5eb45c0 | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 3170 | if (rc) |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3171 | return rc; |
Tejun Heo | 48a8a14 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3172 | |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3173 | /* Old CFA may refuse this command, which is just fine */ |
| 3174 | if (dev->xfer_shift == ATA_SHIFT_PIO && ata_id_is_cfa(dev->id)) |
| 3175 | ign_dev_err = 1; |
| 3176 | |
| 3177 | /* Some very old devices and some bad newer ones fail any kind of |
| 3178 | SET_XFERMODE request but support PIO0-2 timings and no IORDY */ |
| 3179 | if (dev->xfer_shift == ATA_SHIFT_PIO && !ata_id_has_iordy(dev->id) && |
| 3180 | dev->pio_mode <= XFER_PIO_2) |
| 3181 | ign_dev_err = 1; |
| 3182 | |
| 3183 | /* Early MWDMA devices do DMA but don't allow DMA mode setting. |
| 3184 | Don't fail an MWDMA0 set IFF the device indicates it is in MWDMA0 */ |
| 3185 | if (dev->xfer_shift == ATA_SHIFT_MWDMA && |
| 3186 | dev->dma_mode == XFER_MW_DMA_0 && |
| 3187 | (dev->id[63] >> 8) & 1) |
| 3188 | ign_dev_err = 1; |
| 3189 | |
| 3190 | /* if the device is actually configured correctly, ignore dev err */ |
| 3191 | if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) |
| 3192 | ign_dev_err = 1; |
| 3193 | |
| 3194 | if (err_mask & AC_ERR_DEV) { |
| 3195 | if (!ign_dev_err) |
| 3196 | goto fail; |
| 3197 | else |
| 3198 | dev_err_whine = " (device error ignored)"; |
| 3199 | } |
| 3200 | |
Tejun Heo | 23e71c3 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3201 | DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", |
| 3202 | dev->xfer_shift, (int)dev->xfer_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3204 | ata_dev_printk(dev, KERN_INFO, "configured for %s%s\n", |
| 3205 | ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), |
| 3206 | dev_err_whine); |
| 3207 | |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3208 | return 0; |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3209 | |
| 3210 | fail: |
| 3211 | ata_dev_printk(dev, KERN_ERR, "failed to set xfermode " |
| 3212 | "(err_mask=0x%x)\n", err_mask); |
| 3213 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | /** |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 3217 | * ata_do_set_mode - Program timings and issue SET FEATURES - XFER |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3218 | * @link: link on which timings will be programmed |
Joe Perches | 1967b7f | 2008-02-03 17:08:11 +0200 | [diff] [blame] | 3219 | * @r_failed_dev: out parameter for failed device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | * |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 3221 | * Standard implementation of the function used to tune and set |
| 3222 | * ATA device disk transfer mode (PIO3, UDMA6, etc.). If |
| 3223 | * ata_dev_set_mode() fails, pointer to the failing device is |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3224 | * returned in @r_failed_dev. |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 3225 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3227 | * PCI/etc. bus probe sem. |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3228 | * |
| 3229 | * RETURNS: |
| 3230 | * 0 on success, negative errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | */ |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 3232 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3233 | 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] | 3234 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3235 | struct ata_port *ap = link->ap; |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3236 | struct ata_device *dev; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3237 | int rc = 0, used_dma = 0, found = 0; |
Tejun Heo | 3adcebb | 2006-05-15 20:57:37 +0900 | [diff] [blame] | 3238 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3239 | /* step 1: calculate xfer_mask */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3240 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 3241 | unsigned long pio_mask, dma_mask; |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3242 | unsigned int mode_mask; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3243 | |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3244 | if (!ata_dev_enabled(dev)) |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3245 | continue; |
| 3246 | |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3247 | mode_mask = ATA_DMA_MASK_ATA; |
| 3248 | if (dev->class == ATA_DEV_ATAPI) |
| 3249 | mode_mask = ATA_DMA_MASK_ATAPI; |
| 3250 | else if (ata_id_is_cfa(dev->id)) |
| 3251 | mode_mask = ATA_DMA_MASK_CFA; |
| 3252 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3253 | ata_dev_xfermask(dev); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 3254 | ata_force_xfermask(dev); |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3255 | |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 3256 | pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); |
| 3257 | dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3258 | |
| 3259 | if (libata_dma_mask & mode_mask) |
| 3260 | dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); |
| 3261 | else |
| 3262 | dma_mask = 0; |
| 3263 | |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 3264 | dev->pio_mode = ata_xfer_mask2mode(pio_mask); |
| 3265 | dev->dma_mode = ata_xfer_mask2mode(dma_mask); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3266 | |
Tejun Heo | 4f65977 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3267 | found = 1; |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3268 | if (dev->dma_mode != 0xff) |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3269 | used_dma = 1; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3270 | } |
Tejun Heo | 4f65977 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3271 | if (!found) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3272 | goto out; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3273 | |
| 3274 | /* step 2: always set host PIO timings */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3275 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3276 | if (!ata_dev_enabled(dev)) |
| 3277 | continue; |
| 3278 | |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3279 | if (dev->pio_mode == 0xff) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3280 | ata_dev_printk(dev, KERN_WARNING, "no PIO support\n"); |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3281 | rc = -EINVAL; |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3282 | goto out; |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | dev->xfer_mode = dev->pio_mode; |
| 3286 | dev->xfer_shift = ATA_SHIFT_PIO; |
| 3287 | if (ap->ops->set_piomode) |
| 3288 | ap->ops->set_piomode(ap, dev); |
| 3289 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3290 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3291 | /* step 3: set host DMA timings */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3292 | ata_link_for_each_dev(dev, link) { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3293 | if (!ata_dev_enabled(dev) || dev->dma_mode == 0xff) |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3294 | continue; |
| 3295 | |
| 3296 | dev->xfer_mode = dev->dma_mode; |
| 3297 | dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); |
| 3298 | if (ap->ops->set_dmamode) |
| 3299 | ap->ops->set_dmamode(ap, dev); |
| 3300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | |
| 3302 | /* step 4: update devices' xfer mode */ |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3303 | ata_link_for_each_dev(dev, link) { |
Alan | 18d90de | 2007-01-24 11:42:38 +0000 | [diff] [blame] | 3304 | /* don't update suspended devices' xfer mode */ |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 3305 | if (!ata_dev_enabled(dev)) |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3306 | continue; |
| 3307 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3308 | rc = ata_dev_set_mode(dev); |
Tejun Heo | 5bbc53f | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 3309 | if (rc) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3310 | goto out; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3313 | /* Record simplex status. If we selected DMA then the other |
| 3314 | * host channels are not permitted to do so. |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3315 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 3316 | if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) |
Alan | 032af1c | 2007-03-01 17:36:46 +0000 | [diff] [blame] | 3317 | ap->host->simplex_claimed = ap; |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3318 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3319 | out: |
| 3320 | if (rc) |
| 3321 | *r_failed_dev = dev; |
| 3322 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | } |
| 3324 | |
| 3325 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3326 | * sata_link_debounce - debounce SATA phy status |
| 3327 | * @link: ATA link to debounce SATA phy status for |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3328 | * @params: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3329 | * @deadline: deadline jiffies for the operation |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3330 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3331 | * Make sure SStatus of @link reaches stable state, determined by |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3332 | * holding the same value where DET is not 1 for @duration polled |
| 3333 | * every @interval, before @timeout. Timeout constraints the |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3334 | * beginning of the stable state. Because DET gets stuck at 1 on |
| 3335 | * some controllers after hot unplugging, this functions waits |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3336 | * until timeout then returns 0 if DET is stable at 1. |
| 3337 | * |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3338 | * @timeout is further limited by @deadline. The sooner of the |
| 3339 | * two is used. |
| 3340 | * |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3341 | * LOCKING: |
| 3342 | * Kernel thread context (may sleep) |
| 3343 | * |
| 3344 | * RETURNS: |
| 3345 | * 0 on success, -errno on failure. |
| 3346 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3347 | int sata_link_debounce(struct ata_link *link, const unsigned long *params, |
| 3348 | unsigned long deadline) |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3349 | { |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3350 | unsigned long interval_msec = params[0]; |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3351 | unsigned long duration = msecs_to_jiffies(params[1]); |
| 3352 | unsigned long last_jiffies, t; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3353 | u32 last, cur; |
| 3354 | int rc; |
| 3355 | |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3356 | t = jiffies + msecs_to_jiffies(params[2]); |
| 3357 | if (time_before(t, deadline)) |
| 3358 | deadline = t; |
| 3359 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3360 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3361 | return rc; |
| 3362 | cur &= 0xf; |
| 3363 | |
| 3364 | last = cur; |
| 3365 | last_jiffies = jiffies; |
| 3366 | |
| 3367 | while (1) { |
| 3368 | msleep(interval_msec); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3369 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3370 | return rc; |
| 3371 | cur &= 0xf; |
| 3372 | |
| 3373 | /* DET stable? */ |
| 3374 | if (cur == last) { |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3375 | if (cur == 1 && time_before(jiffies, deadline)) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3376 | continue; |
| 3377 | if (time_after(jiffies, last_jiffies + duration)) |
| 3378 | return 0; |
| 3379 | continue; |
| 3380 | } |
| 3381 | |
| 3382 | /* unstable, start over */ |
| 3383 | last = cur; |
| 3384 | last_jiffies = jiffies; |
| 3385 | |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 3386 | /* Check deadline. If debouncing failed, return |
| 3387 | * -EPIPE to tell upper layer to lower link speed. |
| 3388 | */ |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3389 | if (time_after(jiffies, deadline)) |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 3390 | return -EPIPE; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3395 | * sata_link_resume - resume SATA link |
| 3396 | * @link: ATA link to resume SATA |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3397 | * @params: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3398 | * @deadline: deadline jiffies for the operation |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3399 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3400 | * Resume SATA phy @link and debounce it. |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3401 | * |
| 3402 | * LOCKING: |
| 3403 | * Kernel thread context (may sleep) |
| 3404 | * |
| 3405 | * RETURNS: |
| 3406 | * 0 on success, -errno on failure. |
| 3407 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3408 | int sata_link_resume(struct ata_link *link, const unsigned long *params, |
| 3409 | unsigned long deadline) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3410 | { |
| 3411 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3412 | int rc; |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3413 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3414 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3415 | return rc; |
| 3416 | |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3417 | scontrol = (scontrol & 0x0f0) | 0x300; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3418 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3419 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3420 | return rc; |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3421 | |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3422 | /* Some PHYs react badly if SStatus is pounded immediately |
| 3423 | * after resuming. Delay 200ms before debouncing. |
| 3424 | */ |
| 3425 | msleep(200); |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3426 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3427 | return sata_link_debounce(link, params, deadline); |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3428 | } |
| 3429 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3430 | /** |
| 3431 | * ata_std_prereset - prepare for reset |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3432 | * @link: ATA link to be reset |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3433 | * @deadline: deadline jiffies for the operation |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3434 | * |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3435 | * @link is about to be reset. Initialize it. Failure from |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3436 | * prereset makes libata abort whole reset sequence and give up |
| 3437 | * that port, so prereset should be best-effort. It does its |
| 3438 | * best to prepare for reset sequence but if things go wrong, it |
| 3439 | * should just whine, not fail. |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +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_prereset(struct ata_link *link, unsigned long deadline) |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3448 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3449 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3450 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 3451 | const unsigned long *timing = sata_ehc_deb_timing(ehc); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3452 | int rc; |
| 3453 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3454 | /* if we're about to do hardreset, nothing more to do */ |
| 3455 | if (ehc->i.action & ATA_EH_HARDRESET) |
| 3456 | return 0; |
| 3457 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3458 | /* if SATA, resume link */ |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 3459 | if (ap->flags & ATA_FLAG_SATA) { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3460 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3461 | /* whine about phy resume failure but proceed */ |
| 3462 | if (rc && rc != -EOPNOTSUPP) |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3463 | ata_link_printk(link, KERN_WARNING, "failed to resume " |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3464 | "link for reset (errno=%d)\n", rc); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3465 | } |
| 3466 | |
Tejun Heo | 8cebf27 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 3467 | /* wait for !BSY if we don't know that no device is attached */ |
| 3468 | if (!ata_link_offline(link)) { |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3469 | rc = ata_wait_ready(ap, deadline); |
Tejun Heo | 6dffaf6 | 2007-05-23 11:58:52 +0200 | [diff] [blame] | 3470 | if (rc && rc != -ENODEV) { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3471 | ata_link_printk(link, KERN_WARNING, "device not ready " |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3472 | "(errno=%d), forcing hardreset\n", rc); |
| 3473 | ehc->i.action |= ATA_EH_HARDRESET; |
| 3474 | } |
| 3475 | } |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3476 | |
| 3477 | return 0; |
| 3478 | } |
| 3479 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3480 | /** |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3481 | * sata_link_hardreset - reset link via SATA phy reset |
| 3482 | * @link: link to reset |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3483 | * @timing: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3484 | * @deadline: deadline jiffies for the operation |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3485 | * |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3486 | * SATA phy-reset @link using DET bits of SControl register. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3487 | * |
| 3488 | * LOCKING: |
| 3489 | * Kernel thread context (may sleep) |
| 3490 | * |
| 3491 | * RETURNS: |
| 3492 | * 0 on success, -errno otherwise. |
| 3493 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3494 | int sata_link_hardreset(struct ata_link *link, const unsigned long *timing, |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3495 | unsigned long deadline) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3496 | { |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3497 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3498 | int rc; |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3499 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3500 | DPRINTK("ENTER\n"); |
| 3501 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3502 | if (sata_set_spd_needed(link)) { |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3503 | /* SATA spec says nothing about how to reconfigure |
| 3504 | * spd. To be on the safe side, turn off phy during |
| 3505 | * reconfiguration. This works for at least ICH7 AHCI |
| 3506 | * and Sil3124. |
| 3507 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3508 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3509 | goto out; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3510 | |
Martin Hicks | a34b6fc | 2006-07-05 15:06:13 -0400 | [diff] [blame] | 3511 | scontrol = (scontrol & 0x0f0) | 0x304; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3512 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3513 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3514 | goto out; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3515 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3516 | sata_set_spd(link); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | /* issue phy wake/reset */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3520 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3521 | goto out; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3522 | |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3523 | scontrol = (scontrol & 0x0f0) | 0x301; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3524 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3525 | if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3526 | goto out; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3527 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3528 | /* 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] | 3529 | * 10.4.2 says at least 1 ms. |
| 3530 | */ |
| 3531 | msleep(1); |
| 3532 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3533 | /* bring link back */ |
| 3534 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3535 | out: |
| 3536 | DPRINTK("EXIT, rc=%d\n", rc); |
| 3537 | return rc; |
| 3538 | } |
| 3539 | |
| 3540 | /** |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3541 | * ata_std_postreset - standard postreset callback |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3542 | * @link: the target ata_link |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3543 | * @classes: classes of attached devices |
| 3544 | * |
| 3545 | * This function is invoked after a successful reset. Note that |
| 3546 | * the device might have been reset more than once using |
| 3547 | * different reset methods before postreset is invoked. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3548 | * |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3549 | * LOCKING: |
| 3550 | * Kernel thread context (may sleep) |
| 3551 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3552 | void ata_std_postreset(struct ata_link *link, unsigned int *classes) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3553 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3554 | struct ata_port *ap = link->ap; |
Tejun Heo | dc2b351 | 2006-05-15 20:58:00 +0900 | [diff] [blame] | 3555 | u32 serror; |
| 3556 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3557 | DPRINTK("ENTER\n"); |
| 3558 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3559 | /* print link status */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3560 | sata_print_link_status(link); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3561 | |
Tejun Heo | dc2b351 | 2006-05-15 20:58:00 +0900 | [diff] [blame] | 3562 | /* clear SError */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3563 | if (sata_scr_read(link, SCR_ERROR, &serror) == 0) |
| 3564 | sata_scr_write(link, SCR_ERROR, serror); |
Tejun Heo | f7fe7ad4 | 2007-12-08 08:47:01 +0900 | [diff] [blame] | 3565 | link->eh_info.serror = 0; |
Tejun Heo | dc2b351 | 2006-05-15 20:58:00 +0900 | [diff] [blame] | 3566 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3567 | /* is double-select really necessary? */ |
| 3568 | if (classes[0] != ATA_DEV_NONE) |
| 3569 | ap->ops->dev_select(ap, 1); |
| 3570 | if (classes[1] != ATA_DEV_NONE) |
| 3571 | ap->ops->dev_select(ap, 0); |
| 3572 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 3573 | /* bail out if no device is present */ |
| 3574 | if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { |
| 3575 | DPRINTK("EXIT, no device\n"); |
| 3576 | return; |
| 3577 | } |
| 3578 | |
| 3579 | /* set up device control */ |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 3580 | if (ap->ioaddr.ctl_addr) |
| 3581 | iowrite8(ap->ctl, ap->ioaddr.ctl_addr); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3582 | |
| 3583 | DPRINTK("EXIT\n"); |
| 3584 | } |
| 3585 | |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3586 | /** |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3587 | * ata_dev_same_device - Determine whether new ID matches configured device |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3588 | * @dev: device to compare against |
| 3589 | * @new_class: class of the new device |
| 3590 | * @new_id: IDENTIFY page of the new device |
| 3591 | * |
| 3592 | * Compare @new_class and @new_id against @dev and determine |
| 3593 | * whether @dev is the device indicated by @new_class and |
| 3594 | * @new_id. |
| 3595 | * |
| 3596 | * LOCKING: |
| 3597 | * None. |
| 3598 | * |
| 3599 | * RETURNS: |
| 3600 | * 1 if @dev matches @new_class and @new_id, 0 otherwise. |
| 3601 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3602 | static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class, |
| 3603 | const u16 *new_id) |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3604 | { |
| 3605 | const u16 *old_id = dev->id; |
Tejun Heo | a0cf733 | 2007-01-02 20:18:49 +0900 | [diff] [blame] | 3606 | unsigned char model[2][ATA_ID_PROD_LEN + 1]; |
| 3607 | unsigned char serial[2][ATA_ID_SERNO_LEN + 1]; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3608 | |
| 3609 | if (dev->class != new_class) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3610 | ata_dev_printk(dev, KERN_INFO, "class mismatch %d != %d\n", |
| 3611 | dev->class, new_class); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3612 | return 0; |
| 3613 | } |
| 3614 | |
Tejun Heo | a0cf733 | 2007-01-02 20:18:49 +0900 | [diff] [blame] | 3615 | ata_id_c_string(old_id, model[0], ATA_ID_PROD, sizeof(model[0])); |
| 3616 | ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1])); |
| 3617 | ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0])); |
| 3618 | 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] | 3619 | |
| 3620 | if (strcmp(model[0], model[1])) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3621 | ata_dev_printk(dev, KERN_INFO, "model number mismatch " |
| 3622 | "'%s' != '%s'\n", model[0], model[1]); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3623 | return 0; |
| 3624 | } |
| 3625 | |
| 3626 | if (strcmp(serial[0], serial[1])) { |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3627 | ata_dev_printk(dev, KERN_INFO, "serial number mismatch " |
| 3628 | "'%s' != '%s'\n", serial[0], serial[1]); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3629 | return 0; |
| 3630 | } |
| 3631 | |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3632 | return 1; |
| 3633 | } |
| 3634 | |
| 3635 | /** |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3636 | * ata_dev_reread_id - Re-read IDENTIFY data |
Henrik Kretzschmar | 3fae450 | 2007-06-19 10:10:50 +0200 | [diff] [blame] | 3637 | * @dev: target ATA device |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 3638 | * @readid_flags: read ID flags |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3639 | * |
| 3640 | * Re-read IDENTIFY page and make sure @dev is still attached to |
| 3641 | * the port. |
| 3642 | * |
| 3643 | * LOCKING: |
| 3644 | * Kernel thread context (may sleep) |
| 3645 | * |
| 3646 | * RETURNS: |
| 3647 | * 0 on success, negative errno otherwise |
| 3648 | */ |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3649 | 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] | 3650 | { |
Tejun Heo | 5eb45c0 | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 3651 | unsigned int class = dev->class; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3652 | u16 *id = (void *)dev->link->ap->sector_buf; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3653 | int rc; |
| 3654 | |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 3655 | /* read ID data */ |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 3656 | rc = ata_dev_read_id(dev, &class, readid_flags, id); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3657 | if (rc) |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3658 | return rc; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3659 | |
| 3660 | /* is the device still there? */ |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3661 | if (!ata_dev_same_device(dev, class, id)) |
| 3662 | return -ENODEV; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3663 | |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 3664 | memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3665 | return 0; |
| 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * ata_dev_revalidate - Revalidate ATA device |
| 3670 | * @dev: device to revalidate |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 3671 | * @new_class: new class code |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3672 | * @readid_flags: read ID flags |
| 3673 | * |
| 3674 | * Re-read IDENTIFY page, make sure @dev is still attached to the |
| 3675 | * port and reconfigure it according to the new IDENTIFY page. |
| 3676 | * |
| 3677 | * LOCKING: |
| 3678 | * Kernel thread context (may sleep) |
| 3679 | * |
| 3680 | * RETURNS: |
| 3681 | * 0 on success, negative errno otherwise |
| 3682 | */ |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 3683 | int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, |
| 3684 | unsigned int readid_flags) |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3685 | { |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3686 | u64 n_sectors = dev->n_sectors; |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3687 | int rc; |
| 3688 | |
| 3689 | if (!ata_dev_enabled(dev)) |
| 3690 | return -ENODEV; |
| 3691 | |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 3692 | /* fail early if !ATA && !ATAPI to avoid issuing [P]IDENTIFY to PMP */ |
| 3693 | if (ata_class_enabled(new_class) && |
| 3694 | new_class != ATA_DEV_ATA && new_class != ATA_DEV_ATAPI) { |
| 3695 | ata_dev_printk(dev, KERN_INFO, "class mismatch %u != %u\n", |
| 3696 | dev->class, new_class); |
| 3697 | rc = -ENODEV; |
| 3698 | goto fail; |
| 3699 | } |
| 3700 | |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3701 | /* re-read ID */ |
| 3702 | rc = ata_dev_reread_id(dev, readid_flags); |
| 3703 | if (rc) |
| 3704 | goto fail; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3705 | |
| 3706 | /* configure device according to the new ID */ |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 3707 | rc = ata_dev_configure(dev); |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3708 | if (rc) |
| 3709 | goto fail; |
| 3710 | |
| 3711 | /* verify n_sectors hasn't changed */ |
Tejun Heo | b54eebd | 2007-08-17 18:46:51 +0900 | [diff] [blame] | 3712 | if (dev->class == ATA_DEV_ATA && n_sectors && |
| 3713 | dev->n_sectors != n_sectors) { |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3714 | ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch " |
| 3715 | "%llu != %llu\n", |
| 3716 | (unsigned long long)n_sectors, |
| 3717 | (unsigned long long)dev->n_sectors); |
Tejun Heo | 8270bec | 2007-08-16 03:02:22 +0900 | [diff] [blame] | 3718 | |
| 3719 | /* restore original n_sectors */ |
| 3720 | dev->n_sectors = n_sectors; |
| 3721 | |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 3722 | rc = -ENODEV; |
| 3723 | goto fail; |
| 3724 | } |
| 3725 | |
| 3726 | return 0; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3727 | |
| 3728 | fail: |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3729 | ata_dev_printk(dev, KERN_ERR, "revalidation failed (errno=%d)\n", rc); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3730 | return rc; |
| 3731 | } |
| 3732 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3733 | struct ata_blacklist_entry { |
| 3734 | const char *model_num; |
| 3735 | const char *model_rev; |
| 3736 | unsigned long horkage; |
| 3737 | }; |
| 3738 | |
| 3739 | static const struct ata_blacklist_entry ata_device_blacklist [] = { |
| 3740 | /* Devices with DMA related problems under Linux */ |
| 3741 | { "WDC AC11000H", NULL, ATA_HORKAGE_NODMA }, |
| 3742 | { "WDC AC22100H", NULL, ATA_HORKAGE_NODMA }, |
| 3743 | { "WDC AC32500H", NULL, ATA_HORKAGE_NODMA }, |
| 3744 | { "WDC AC33100H", NULL, ATA_HORKAGE_NODMA }, |
| 3745 | { "WDC AC31600H", NULL, ATA_HORKAGE_NODMA }, |
| 3746 | { "WDC AC32100H", "24.09P07", ATA_HORKAGE_NODMA }, |
| 3747 | { "WDC AC23200L", "21.10N21", ATA_HORKAGE_NODMA }, |
| 3748 | { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA }, |
| 3749 | { "CRD-8400B", NULL, ATA_HORKAGE_NODMA }, |
| 3750 | { "CRD-8480B", NULL, ATA_HORKAGE_NODMA }, |
| 3751 | { "CRD-8482B", NULL, ATA_HORKAGE_NODMA }, |
| 3752 | { "CRD-84", NULL, ATA_HORKAGE_NODMA }, |
| 3753 | { "SanDisk SDP3B", NULL, ATA_HORKAGE_NODMA }, |
| 3754 | { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA }, |
| 3755 | { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA }, |
| 3756 | { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA }, |
| 3757 | { "HITACHI CDR-8335", NULL, ATA_HORKAGE_NODMA }, |
| 3758 | { "HITACHI CDR-8435", NULL, ATA_HORKAGE_NODMA }, |
| 3759 | { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA }, |
| 3760 | { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA }, |
| 3761 | { "CD-532E-A", NULL, ATA_HORKAGE_NODMA }, |
| 3762 | { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA }, |
| 3763 | { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA }, |
| 3764 | { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA }, |
| 3765 | { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA }, |
| 3766 | { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3767 | { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA }, |
| 3768 | { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA }, |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3769 | { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA }, |
Dave Jones | 39f1988 | 2007-05-21 14:31:03 -0400 | [diff] [blame] | 3770 | { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA }, |
Tejun Heo | 3af9a77 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 3771 | /* Odd clown on sil3726/4726 PMPs */ |
| 3772 | { "Config Disk", NULL, ATA_HORKAGE_NODMA | |
| 3773 | ATA_HORKAGE_SKIP_PM }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3774 | |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 3775 | /* Weird ATAPI devices */ |
Tejun Heo | 40a1d53 | 2007-06-27 02:49:38 +0900 | [diff] [blame] | 3776 | { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 }, |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 3777 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3778 | /* Devices we expect to fail diagnostics */ |
| 3779 | |
| 3780 | /* Devices where NCQ should be avoided */ |
| 3781 | /* NCQ is slow */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3782 | { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ }, |
Tejun Heo | 459ad68 | 2007-12-07 12:46:23 +0900 | [diff] [blame] | 3783 | { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, |
Tejun Heo | 09125ea | 2007-02-28 15:21:23 +0900 | [diff] [blame] | 3784 | /* http://thread.gmane.org/gmane.linux.ide/14907 */ |
| 3785 | { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ }, |
Paul Rolland | 7acfaf3 | 2007-03-26 21:43:44 -0800 | [diff] [blame] | 3786 | /* NCQ is broken */ |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3787 | { "Maxtor *", "BANC*", ATA_HORKAGE_NONCQ }, |
Alan Cox | 0e3dbc0 | 2007-09-20 15:22:47 +0100 | [diff] [blame] | 3788 | { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ }, |
Paolo Ornati | da6f0ec | 2007-10-04 11:06:56 +0900 | [diff] [blame] | 3789 | { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ }, |
Tejun Heo | e41bd3e | 2007-12-09 19:45:39 +0900 | [diff] [blame] | 3790 | { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ }, |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3791 | |
Robert Hancock | 36e337d | 2007-04-02 22:05:29 -0600 | [diff] [blame] | 3792 | /* Blacklist entries taken from Silicon Image 3124/3132 |
| 3793 | Windows driver .inf file - also several Linux problem reports */ |
| 3794 | { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ, }, |
| 3795 | { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ, }, |
| 3796 | { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ, }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3797 | |
Tejun Heo | 16c55b0 | 2007-08-29 11:58:33 +0900 | [diff] [blame] | 3798 | /* devices which puke on READ_NATIVE_MAX */ |
| 3799 | { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, }, |
| 3800 | { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA }, |
| 3801 | { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA }, |
| 3802 | { "MAXTOR 6L080L4", "A93.0500", ATA_HORKAGE_BROKEN_HPA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3803 | |
Alan Cox | 93328e1 | 2007-09-29 04:06:48 -0400 | [diff] [blame] | 3804 | /* Devices which report 1 sector over size HPA */ |
| 3805 | { "ST340823A", NULL, ATA_HORKAGE_HPA_SIZE, }, |
| 3806 | { "ST320413A", NULL, ATA_HORKAGE_HPA_SIZE, }, |
Mikko Rapeli | b152fcd | 2008-02-19 01:41:25 +0100 | [diff] [blame] | 3807 | { "ST310211A", NULL, ATA_HORKAGE_HPA_SIZE, }, |
Alan Cox | 93328e1 | 2007-09-29 04:06:48 -0400 | [diff] [blame] | 3808 | |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 3809 | /* Devices which get the IVB wrong */ |
| 3810 | { "QUANTUM FIREBALLlct10 05", "A03.0900", ATA_HORKAGE_IVB, }, |
| 3811 | { "TSSTcorp CDDVDW SH-S202J", "SB00", ATA_HORKAGE_IVB, }, |
Peter Missel | e9f3340 | 2007-11-27 18:04:42 +0100 | [diff] [blame] | 3812 | { "TSSTcorp CDDVDW SH-S202J", "SB01", ATA_HORKAGE_IVB, }, |
| 3813 | { "TSSTcorp CDDVDW SH-S202N", "SB00", ATA_HORKAGE_IVB, }, |
| 3814 | { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, }, |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 3815 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3816 | /* End Marker */ |
| 3817 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | }; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 3819 | |
Adrian Bunk | 741b776 | 2007-10-24 18:23:06 +0200 | [diff] [blame] | 3820 | static int strn_pattern_cmp(const char *patt, const char *name, int wildchar) |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3821 | { |
| 3822 | const char *p; |
| 3823 | int len; |
| 3824 | |
| 3825 | /* |
| 3826 | * check for trailing wildcard: *\0 |
| 3827 | */ |
| 3828 | p = strchr(patt, wildchar); |
| 3829 | if (p && ((*(p + 1)) == 0)) |
| 3830 | len = p - patt; |
Andrew Paprocki | 317b50b | 2007-10-15 15:43:12 -0400 | [diff] [blame] | 3831 | else { |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3832 | len = strlen(name); |
Andrew Paprocki | 317b50b | 2007-10-15 15:43:12 -0400 | [diff] [blame] | 3833 | if (!len) { |
| 3834 | if (!*patt) |
| 3835 | return 0; |
| 3836 | return -1; |
| 3837 | } |
| 3838 | } |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3839 | |
| 3840 | return strncmp(patt, name, len); |
| 3841 | } |
| 3842 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 3843 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | { |
Tejun Heo | 8bfa79f | 2007-01-02 20:19:40 +0900 | [diff] [blame] | 3845 | unsigned char model_num[ATA_ID_PROD_LEN + 1]; |
| 3846 | unsigned char model_rev[ATA_ID_FW_REV_LEN + 1]; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3847 | const struct ata_blacklist_entry *ad = ata_device_blacklist; |
Albert Lee | 3a77827 | 2006-06-22 13:00:25 +0800 | [diff] [blame] | 3848 | |
Tejun Heo | 8bfa79f | 2007-01-02 20:19:40 +0900 | [diff] [blame] | 3849 | ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); |
| 3850 | 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] | 3851 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3852 | while (ad->model_num) { |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3853 | if (!strn_pattern_cmp(ad->model_num, model_num, '*')) { |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3854 | if (ad->model_rev == NULL) |
| 3855 | return ad->horkage; |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 3856 | if (!strn_pattern_cmp(ad->model_rev, model_rev, '*')) |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3857 | return ad->horkage; |
Alan Cox | f4b15fe | 2006-03-22 15:54:04 +0000 | [diff] [blame] | 3858 | } |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3859 | ad++; |
Alan Cox | f4b15fe | 2006-03-22 15:54:04 +0000 | [diff] [blame] | 3860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | return 0; |
| 3862 | } |
| 3863 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3864 | static int ata_dma_blacklisted(const struct ata_device *dev) |
| 3865 | { |
| 3866 | /* We don't support polling DMA. |
| 3867 | * DMA blacklist those ATAPI devices with CDB-intr (and use PIO) |
| 3868 | * if the LLDD handles only interrupts in the HSM_ST_LAST state. |
| 3869 | */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3870 | if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3871 | (dev->flags & ATA_DFLAG_CDB_INTR)) |
| 3872 | return 1; |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 3873 | return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3876 | /** |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 3877 | * ata_is_40wire - check drive side detection |
| 3878 | * @dev: device |
| 3879 | * |
| 3880 | * Perform drive side detection decoding, allowing for device vendors |
| 3881 | * who can't follow the documentation. |
| 3882 | */ |
| 3883 | |
| 3884 | static int ata_is_40wire(struct ata_device *dev) |
| 3885 | { |
| 3886 | if (dev->horkage & ATA_HORKAGE_IVB) |
| 3887 | return ata_drive_40wire_relaxed(dev->id); |
| 3888 | return ata_drive_40wire(dev->id); |
| 3889 | } |
| 3890 | |
| 3891 | /** |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3892 | * ata_dev_xfermask - Compute supported xfermask of the given device |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3893 | * @dev: Device to compute xfermask for |
| 3894 | * |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 3895 | * Compute supported xfermask of @dev and store it in |
| 3896 | * dev->*_mask. This function is responsible for applying all |
| 3897 | * known limits including host controller limits, device |
| 3898 | * blacklist, etc... |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3899 | * |
| 3900 | * LOCKING: |
| 3901 | * None. |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3902 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3903 | static void ata_dev_xfermask(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3905 | struct ata_link *link = dev->link; |
| 3906 | struct ata_port *ap = link->ap; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 3907 | struct ata_host *host = ap->host; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3908 | unsigned long xfer_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3910 | /* controller modes available */ |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3911 | xfer_mask = ata_pack_xfermask(ap->pio_mask, |
| 3912 | ap->mwdma_mask, ap->udma_mask); |
| 3913 | |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 3914 | /* drive modes available */ |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3915 | xfer_mask &= ata_pack_xfermask(dev->pio_mask, |
| 3916 | dev->mwdma_mask, dev->udma_mask); |
| 3917 | xfer_mask &= ata_id_xfermask(dev->id); |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3918 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 3919 | /* |
| 3920 | * CFA Advanced TrueIDE timings are not allowed on a shared |
| 3921 | * cable |
| 3922 | */ |
| 3923 | if (ata_dev_pair(dev)) { |
| 3924 | /* No PIO5 or PIO6 */ |
| 3925 | xfer_mask &= ~(0x03 << (ATA_SHIFT_PIO + 5)); |
| 3926 | /* No MWDMA3 or MWDMA 4 */ |
| 3927 | xfer_mask &= ~(0x03 << (ATA_SHIFT_MWDMA + 3)); |
| 3928 | } |
| 3929 | |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3930 | if (ata_dma_blacklisted(dev)) { |
| 3931 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 3932 | ata_dev_printk(dev, KERN_WARNING, |
| 3933 | "device is on DMA blacklist, disabling DMA\n"); |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3934 | } |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3935 | |
Petr Vandrovec | 14d66ab | 2007-03-08 10:12:12 +0100 | [diff] [blame] | 3936 | if ((host->flags & ATA_HOST_SIMPLEX) && |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3937 | host->simplex_claimed && host->simplex_claimed != ap) { |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 3938 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
| 3939 | ata_dev_printk(dev, KERN_WARNING, "simplex DMA is claimed by " |
| 3940 | "other device, disabling DMA\n"); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3941 | } |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3942 | |
Jeff Garzik | e424675 | 2007-03-09 09:56:46 -0500 | [diff] [blame] | 3943 | if (ap->flags & ATA_FLAG_NO_IORDY) |
| 3944 | xfer_mask &= ata_pio_mask_no_iordy(dev); |
| 3945 | |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3946 | if (ap->ops->mode_filter) |
Alan Cox | a76b62c | 2007-03-09 09:34:07 -0500 | [diff] [blame] | 3947 | xfer_mask = ap->ops->mode_filter(dev, xfer_mask); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3948 | |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 3949 | /* Apply cable rule here. Don't apply it early because when |
| 3950 | * we handle hot plug the cable type can itself change. |
| 3951 | * Check this last so that we know if the transfer rate was |
| 3952 | * solely limited by the cable. |
| 3953 | * Unknown or 80 wire cables reported host side are checked |
| 3954 | * drive side as well. Cases where we know a 40wire cable |
| 3955 | * is used safely for 80 are not checked here. |
| 3956 | */ |
| 3957 | if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA)) |
| 3958 | /* UDMA/44 or higher would be available */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3959 | if ((ap->cbl == ATA_CBL_PATA40) || |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 3960 | (ata_is_40wire(dev) && |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3961 | (ap->cbl == ATA_CBL_PATA_UNK || |
| 3962 | ap->cbl == ATA_CBL_PATA80))) { |
| 3963 | ata_dev_printk(dev, KERN_WARNING, |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 3964 | "limited to UDMA/33 due to 40-wire cable\n"); |
| 3965 | xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); |
| 3966 | } |
| 3967 | |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 3968 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, |
| 3969 | &dev->mwdma_mask, &dev->udma_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | * @dev: Device to which command will be sent |
| 3975 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 3976 | * Issue SET FEATURES - XFER MODE command to device @dev |
| 3977 | * on port @ap. |
| 3978 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3980 | * PCI/etc. bus probe sem. |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3981 | * |
| 3982 | * RETURNS: |
| 3983 | * 0 on success, AC_ERR_* mask otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | */ |
| 3985 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3986 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 3988 | struct ata_taskfile tf; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3989 | unsigned int err_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | |
| 3991 | /* set up set-features taskfile */ |
| 3992 | DPRINTK("set features - xfer mode\n"); |
| 3993 | |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 3994 | /* Some controllers and ATAPI devices show flaky interrupt |
| 3995 | * behavior after setting xfer mode. Use polling instead. |
| 3996 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3997 | ata_tf_init(dev, &tf); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 3998 | tf.command = ATA_CMD_SET_FEATURES; |
| 3999 | tf.feature = SETFEATURES_XFER; |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 4000 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_POLLING; |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4001 | tf.protocol = ATA_PROT_NODATA; |
Alan Cox | b9f8ab2 | 2007-11-19 14:33:11 +0000 | [diff] [blame] | 4002 | /* If we are using IORDY we must send the mode setting command */ |
Jeff Garzik | 11b7bec | 2007-11-23 21:12:14 -0500 | [diff] [blame] | 4003 | if (ata_pio_need_iordy(dev)) |
| 4004 | tf.nsect = dev->xfer_mode; |
Alan Cox | b9f8ab2 | 2007-11-19 14:33:11 +0000 | [diff] [blame] | 4005 | /* If the device has IORDY and the controller does not - turn it off */ |
| 4006 | else if (ata_id_has_iordy(dev->id)) |
Jeff Garzik | 11b7bec | 2007-11-23 21:12:14 -0500 | [diff] [blame] | 4007 | tf.nsect = 0x01; |
Alan Cox | b9f8ab2 | 2007-11-19 14:33:11 +0000 | [diff] [blame] | 4008 | else /* In the ancient relic department - skip all of this */ |
| 4009 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4010 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 4011 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4013 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4014 | return err_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | /** |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4017 | * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4018 | * @dev: Device to which command will be sent |
| 4019 | * @enable: Whether to enable or disable the feature |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4020 | * @feature: The sector count represents the feature to set |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4021 | * |
| 4022 | * Issue SET FEATURES - SATA FEATURES command to device @dev |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4023 | * on port @ap with sector count |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4024 | * |
| 4025 | * LOCKING: |
| 4026 | * PCI/etc. bus probe sem. |
| 4027 | * |
| 4028 | * RETURNS: |
| 4029 | * 0 on success, AC_ERR_* mask otherwise. |
| 4030 | */ |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4031 | static unsigned int ata_dev_set_feature(struct ata_device *dev, u8 enable, |
| 4032 | u8 feature) |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4033 | { |
| 4034 | struct ata_taskfile tf; |
| 4035 | unsigned int err_mask; |
| 4036 | |
| 4037 | /* set up set-features taskfile */ |
| 4038 | DPRINTK("set features - SATA features\n"); |
| 4039 | |
| 4040 | ata_tf_init(dev, &tf); |
| 4041 | tf.command = ATA_CMD_SET_FEATURES; |
| 4042 | tf.feature = enable; |
| 4043 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 4044 | tf.protocol = ATA_PROT_NODATA; |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4045 | tf.nsect = feature; |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4046 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 4047 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4048 | |
| 4049 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4050 | return err_mask; |
| 4051 | } |
| 4052 | |
| 4053 | /** |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4054 | * ata_dev_init_params - Issue INIT DEV PARAMS command |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4055 | * @dev: Device to which command will be sent |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 4056 | * @heads: Number of heads (taskfile parameter) |
| 4057 | * @sectors: Number of sectors (taskfile parameter) |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4058 | * |
| 4059 | * LOCKING: |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4060 | * Kernel thread context (may sleep) |
| 4061 | * |
| 4062 | * RETURNS: |
| 4063 | * 0 on success, AC_ERR_* mask otherwise. |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4064 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4065 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
| 4066 | u16 heads, u16 sectors) |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4067 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4068 | struct ata_taskfile tf; |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4069 | unsigned int err_mask; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4070 | |
| 4071 | /* Number of sectors per track 1-255. Number of heads 1-16 */ |
| 4072 | if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) |
Albert Lee | 00b6f5e | 2006-03-27 16:39:18 +0800 | [diff] [blame] | 4073 | return AC_ERR_INVALID; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4074 | |
| 4075 | /* set up init dev params taskfile */ |
| 4076 | DPRINTK("init dev params \n"); |
| 4077 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4078 | ata_tf_init(dev, &tf); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4079 | tf.command = ATA_CMD_INIT_DEV_PARAMS; |
| 4080 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 4081 | tf.protocol = ATA_PROT_NODATA; |
| 4082 | tf.nsect = sectors; |
| 4083 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4084 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 4085 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); |
Alan Cox | 18b2466 | 2007-08-08 14:28:49 +0100 | [diff] [blame] | 4086 | /* A clean abort indicates an original or just out of spec drive |
| 4087 | and we should continue as we issue the setup based on the |
| 4088 | drive reported working geometry */ |
| 4089 | if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) |
| 4090 | err_mask = 0; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4091 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4092 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4093 | return err_mask; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4097 | * ata_sg_clean - Unmap DMA memory associated with command |
| 4098 | * @qc: Command containing DMA memory to be released |
| 4099 | * |
| 4100 | * Unmap all mapped DMA memory associated with this command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | * |
| 4102 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4103 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | */ |
Tejun Heo | 70e6ad0 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 4105 | void ata_sg_clean(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | { |
| 4107 | struct ata_port *ap = qc->ap; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4108 | struct scatterlist *sg = qc->sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | int dir = qc->dma_dir; |
| 4110 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4111 | WARN_ON(sg == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4112 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4113 | VPRINTK("unmapping %u sg elements\n", qc->n_elem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4115 | if (qc->n_elem) |
| 4116 | dma_unmap_sg(ap->dev, sg, qc->n_elem, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | |
| 4118 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4119 | qc->sg = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
| 4122 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | * ata_check_atapi_dma - Check whether ATAPI DMA can be supported |
| 4124 | * @qc: Metadata associated with taskfile to check |
| 4125 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4126 | * Allow low-level driver to filter ATA PACKET commands, returning |
| 4127 | * a status indicating whether or not it is OK to use DMA for the |
| 4128 | * supplied PACKET command. |
| 4129 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4131 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4132 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | * RETURNS: 0 when ATAPI DMA can be used |
| 4134 | * nonzero otherwise |
| 4135 | */ |
| 4136 | int ata_check_atapi_dma(struct ata_queued_cmd *qc) |
| 4137 | { |
| 4138 | struct ata_port *ap = qc->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4140 | /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a |
| 4141 | * few ATAPI devices choke on such DMA requests. |
| 4142 | */ |
| 4143 | if (unlikely(qc->nbytes & 15)) |
| 4144 | return 1; |
Albert Lee | 6f23a31 | 2007-04-02 11:39:25 +0800 | [diff] [blame] | 4145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | if (ap->ops->check_atapi_dma) |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4147 | return ap->ops->check_atapi_dma(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4148 | |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4149 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | } |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | /** |
Tejun Heo | 31cc23b | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4153 | * ata_std_qc_defer - Check whether a qc needs to be deferred |
| 4154 | * @qc: ATA command in question |
| 4155 | * |
| 4156 | * Non-NCQ commands cannot run with any other command, NCQ or |
| 4157 | * not. As upper layer only knows the queue depth, we are |
| 4158 | * responsible for maintaining exclusion. This function checks |
| 4159 | * whether a new command @qc can be issued. |
| 4160 | * |
| 4161 | * LOCKING: |
| 4162 | * spin_lock_irqsave(host lock) |
| 4163 | * |
| 4164 | * RETURNS: |
| 4165 | * ATA_DEFER_* if deferring is needed, 0 otherwise. |
| 4166 | */ |
| 4167 | int ata_std_qc_defer(struct ata_queued_cmd *qc) |
| 4168 | { |
| 4169 | struct ata_link *link = qc->dev->link; |
| 4170 | |
| 4171 | if (qc->tf.protocol == ATA_PROT_NCQ) { |
| 4172 | if (!ata_tag_valid(link->active_tag)) |
| 4173 | return 0; |
| 4174 | } else { |
| 4175 | if (!ata_tag_valid(link->active_tag) && !link->sactive) |
| 4176 | return 0; |
| 4177 | } |
| 4178 | |
| 4179 | return ATA_DEFER_LINK; |
| 4180 | } |
| 4181 | |
Brian King | e46834c | 2006-03-17 17:04:03 -0600 | [diff] [blame] | 4182 | void ata_noop_qc_prep(struct ata_queued_cmd *qc) { } |
| 4183 | |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4184 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4185 | * ata_sg_init - Associate command with scatter-gather table. |
| 4186 | * @qc: Command to be associated |
| 4187 | * @sg: Scatter-gather table. |
| 4188 | * @n_elem: Number of elements in s/g table. |
| 4189 | * |
| 4190 | * Initialize the data-related elements of queued_cmd @qc |
| 4191 | * to point to a scatter-gather table @sg, containing @n_elem |
| 4192 | * elements. |
| 4193 | * |
| 4194 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4195 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4196 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
| 4198 | unsigned int n_elem) |
| 4199 | { |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4200 | qc->sg = sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | qc->n_elem = n_elem; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4202 | qc->cursg = qc->sg; |
| 4203 | } |
| 4204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4206 | * ata_sg_setup - DMA-map the scatter-gather table associated with a command. |
| 4207 | * @qc: Command with scatter-gather table to be mapped. |
| 4208 | * |
| 4209 | * DMA-map the scatter-gather table associated with queued_cmd @qc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | * |
| 4211 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4212 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4213 | * |
| 4214 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4215 | * Zero on success, negative on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | * |
| 4217 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | static int ata_sg_setup(struct ata_queued_cmd *qc) |
| 4219 | { |
| 4220 | struct ata_port *ap = qc->ap; |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4221 | unsigned int n_elem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 4223 | VPRINTK("ENTER, ata%u\n", ap->print_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4224 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4225 | n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); |
| 4226 | if (n_elem < 1) |
| 4227 | return -1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4228 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4229 | DPRINTK("%d sg elements mapped\n", n_elem); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4230 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4231 | qc->n_elem = n_elem; |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 4232 | qc->flags |= ATA_QCFLAG_DMAMAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | |
| 4234 | return 0; |
| 4235 | } |
| 4236 | |
| 4237 | /** |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4238 | * swap_buf_le16 - swap halves of 16-bit words in place |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4239 | * @buf: Buffer to swap |
| 4240 | * @buf_words: Number of 16-bit words in buffer. |
| 4241 | * |
| 4242 | * Swap halves of 16-bit words if needed to convert from |
| 4243 | * little-endian byte order to native cpu byte order, or |
| 4244 | * vice-versa. |
| 4245 | * |
| 4246 | * LOCKING: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 4247 | * Inherited from caller. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4248 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | void swap_buf_le16(u16 *buf, unsigned int buf_words) |
| 4250 | { |
| 4251 | #ifdef __BIG_ENDIAN |
| 4252 | unsigned int i; |
| 4253 | |
| 4254 | for (i = 0; i < buf_words; i++) |
| 4255 | buf[i] = le16_to_cpu(buf[i]); |
| 4256 | #endif /* __BIG_ENDIAN */ |
| 4257 | } |
| 4258 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4259 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | * ata_qc_new - Request an available ATA command, for queueing |
| 4261 | * @ap: Port associated with device @dev |
| 4262 | * @dev: Device from whom we request an available command structure |
| 4263 | * |
| 4264 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4265 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | */ |
| 4267 | |
| 4268 | static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) |
| 4269 | { |
| 4270 | struct ata_queued_cmd *qc = NULL; |
| 4271 | unsigned int i; |
| 4272 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 4273 | /* no command while frozen */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 4274 | if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 4275 | return NULL; |
| 4276 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 4277 | /* the last tag is reserved for internal command. */ |
| 4278 | for (i = 0; i < ATA_MAX_QUEUE - 1; i++) |
Tejun Heo | 6cec4a3 | 2006-05-15 21:03:41 +0900 | [diff] [blame] | 4279 | if (!test_and_set_bit(i, &ap->qc_allocated)) { |
Tejun Heo | f69499f | 2006-05-15 20:58:03 +0900 | [diff] [blame] | 4280 | qc = __ata_qc_from_tag(ap, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | break; |
| 4282 | } |
| 4283 | |
| 4284 | if (qc) |
| 4285 | qc->tag = i; |
| 4286 | |
| 4287 | return qc; |
| 4288 | } |
| 4289 | |
| 4290 | /** |
| 4291 | * ata_qc_new_init - Request an available ATA command, and initialize it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | * @dev: Device from whom we request an available command structure |
| 4293 | * |
| 4294 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4295 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | */ |
| 4297 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4298 | struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4300 | struct ata_port *ap = dev->link->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | struct ata_queued_cmd *qc; |
| 4302 | |
| 4303 | qc = ata_qc_new(ap); |
| 4304 | if (qc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4305 | qc->scsicmd = NULL; |
| 4306 | qc->ap = ap; |
| 4307 | qc->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 4309 | ata_qc_reinit(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | return qc; |
| 4313 | } |
| 4314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | /** |
| 4316 | * ata_qc_free - free unused ata_queued_cmd |
| 4317 | * @qc: Command to complete |
| 4318 | * |
| 4319 | * Designed to free unused ata_queued_cmd object |
| 4320 | * in case something prevents using it. |
| 4321 | * |
| 4322 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4323 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | */ |
| 4325 | void ata_qc_free(struct ata_queued_cmd *qc) |
| 4326 | { |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4327 | struct ata_port *ap = qc->ap; |
| 4328 | unsigned int tag; |
| 4329 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4330 | WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4332 | qc->flags = 0; |
| 4333 | tag = qc->tag; |
| 4334 | if (likely(ata_tag_valid(tag))) { |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4335 | qc->tag = ATA_TAG_POISON; |
Tejun Heo | 6cec4a3 | 2006-05-15 21:03:41 +0900 | [diff] [blame] | 4336 | clear_bit(tag, &ap->qc_allocated); |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4337 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | } |
| 4339 | |
Tejun Heo | 7601442 | 2006-02-11 15:13:49 +0900 | [diff] [blame] | 4340 | void __ata_qc_complete(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4341 | { |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4342 | struct ata_port *ap = qc->ap; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4343 | struct ata_link *link = qc->dev->link; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4344 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 4345 | WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
| 4346 | WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | |
| 4348 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 4349 | ata_sg_clean(qc); |
| 4350 | |
Tejun Heo | 7401abf | 2006-05-15 20:57:32 +0900 | [diff] [blame] | 4351 | /* command should be marked inactive atomically with qc completion */ |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4352 | if (qc->tf.protocol == ATA_PROT_NCQ) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4353 | link->sactive &= ~(1 << qc->tag); |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4354 | if (!link->sactive) |
| 4355 | ap->nr_active_links--; |
| 4356 | } else { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4357 | link->active_tag = ATA_TAG_POISON; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4358 | ap->nr_active_links--; |
| 4359 | } |
| 4360 | |
| 4361 | /* clear exclusive status */ |
| 4362 | if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && |
| 4363 | ap->excl_link == link)) |
| 4364 | ap->excl_link = NULL; |
Tejun Heo | 7401abf | 2006-05-15 20:57:32 +0900 | [diff] [blame] | 4365 | |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 4366 | /* atapi: mark qc as inactive to prevent the interrupt handler |
| 4367 | * from completing the command twice later, before the error handler |
| 4368 | * is called. (when rc != 0 and atapi request sense is needed) |
| 4369 | */ |
| 4370 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4371 | ap->qc_active &= ~(1 << qc->tag); |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 4372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | /* call completion callback */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4374 | qc->complete_fn(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | } |
| 4376 | |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4377 | static void fill_result_tf(struct ata_queued_cmd *qc) |
| 4378 | { |
| 4379 | struct ata_port *ap = qc->ap; |
| 4380 | |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4381 | qc->result_tf.flags = qc->tf.flags; |
Mark Lord | 4742d54 | 2007-04-02 16:20:35 -0400 | [diff] [blame] | 4382 | ap->ops->tf_read(ap, &qc->result_tf); |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4383 | } |
| 4384 | |
Tejun Heo | 00115e0 | 2007-11-27 19:28:58 +0900 | [diff] [blame] | 4385 | static void ata_verify_xfer(struct ata_queued_cmd *qc) |
| 4386 | { |
| 4387 | struct ata_device *dev = qc->dev; |
| 4388 | |
| 4389 | if (ata_tag_internal(qc->tag)) |
| 4390 | return; |
| 4391 | |
| 4392 | if (ata_is_nodata(qc->tf.protocol)) |
| 4393 | return; |
| 4394 | |
| 4395 | if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) |
| 4396 | return; |
| 4397 | |
| 4398 | dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; |
| 4399 | } |
| 4400 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4401 | /** |
| 4402 | * ata_qc_complete - Complete an active ATA command |
| 4403 | * @qc: Command to complete |
| 4404 | * @err_mask: ATA Status register contents |
| 4405 | * |
| 4406 | * Indicate to the mid and upper layers that an ATA |
| 4407 | * command has completed, with either an ok or not-ok status. |
| 4408 | * |
| 4409 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4410 | * spin_lock_irqsave(host lock) |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4411 | */ |
| 4412 | void ata_qc_complete(struct ata_queued_cmd *qc) |
| 4413 | { |
| 4414 | struct ata_port *ap = qc->ap; |
| 4415 | |
| 4416 | /* XXX: New EH and old EH use different mechanisms to |
| 4417 | * synchronize EH with regular execution path. |
| 4418 | * |
| 4419 | * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED. |
| 4420 | * Normal execution path is responsible for not accessing a |
| 4421 | * failed qc. libata core enforces the rule by returning NULL |
| 4422 | * from ata_qc_from_tag() for failed qcs. |
| 4423 | * |
| 4424 | * Old EH depends on ata_qc_complete() nullifying completion |
| 4425 | * requests if ATA_QCFLAG_EH_SCHEDULED is set. Old EH does |
| 4426 | * not synchronize with interrupt handler. Only PIO task is |
| 4427 | * taken care of. |
| 4428 | */ |
| 4429 | if (ap->ops->error_handler) { |
Tejun Heo | 4dbfa39 | 2007-10-25 18:22:44 +0900 | [diff] [blame] | 4430 | struct ata_device *dev = qc->dev; |
| 4431 | struct ata_eh_info *ehi = &dev->link->eh_info; |
| 4432 | |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 4433 | WARN_ON(ap->pflags & ATA_PFLAG_FROZEN); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4434 | |
| 4435 | if (unlikely(qc->err_mask)) |
| 4436 | qc->flags |= ATA_QCFLAG_FAILED; |
| 4437 | |
| 4438 | if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) { |
| 4439 | if (!ata_tag_internal(qc->tag)) { |
| 4440 | /* always fill result TF for failed qc */ |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4441 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4442 | ata_qc_schedule_eh(qc); |
| 4443 | return; |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | /* read result TF if requested */ |
| 4448 | if (qc->flags & ATA_QCFLAG_RESULT_TF) |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4449 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4450 | |
Tejun Heo | 4dbfa39 | 2007-10-25 18:22:44 +0900 | [diff] [blame] | 4451 | /* Some commands need post-processing after successful |
| 4452 | * completion. |
| 4453 | */ |
| 4454 | switch (qc->tf.command) { |
| 4455 | case ATA_CMD_SET_FEATURES: |
| 4456 | if (qc->tf.feature != SETFEATURES_WC_ON && |
| 4457 | qc->tf.feature != SETFEATURES_WC_OFF) |
| 4458 | break; |
| 4459 | /* fall through */ |
| 4460 | case ATA_CMD_INIT_DEV_PARAMS: /* CHS translation changed */ |
| 4461 | case ATA_CMD_SET_MULTI: /* multi_count changed */ |
| 4462 | /* revalidate device */ |
| 4463 | ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; |
| 4464 | ata_port_schedule_eh(ap); |
| 4465 | break; |
Tejun Heo | 054a5fb | 2007-10-25 18:30:36 +0900 | [diff] [blame] | 4466 | |
| 4467 | case ATA_CMD_SLEEP: |
| 4468 | dev->flags |= ATA_DFLAG_SLEEPING; |
| 4469 | break; |
Tejun Heo | 4dbfa39 | 2007-10-25 18:22:44 +0900 | [diff] [blame] | 4470 | } |
| 4471 | |
Tejun Heo | 00115e0 | 2007-11-27 19:28:58 +0900 | [diff] [blame] | 4472 | if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) |
| 4473 | ata_verify_xfer(qc); |
| 4474 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4475 | __ata_qc_complete(qc); |
| 4476 | } else { |
| 4477 | if (qc->flags & ATA_QCFLAG_EH_SCHEDULED) |
| 4478 | return; |
| 4479 | |
| 4480 | /* read result TF if failed or requested */ |
| 4481 | if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF) |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4482 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4483 | |
| 4484 | __ata_qc_complete(qc); |
| 4485 | } |
| 4486 | } |
| 4487 | |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4488 | /** |
| 4489 | * ata_qc_complete_multiple - Complete multiple qcs successfully |
| 4490 | * @ap: port in question |
| 4491 | * @qc_active: new qc_active mask |
| 4492 | * @finish_qc: LLDD callback invoked before completing a qc |
| 4493 | * |
| 4494 | * Complete in-flight commands. This functions is meant to be |
| 4495 | * called from low-level driver's interrupt routine to complete |
| 4496 | * requests normally. ap->qc_active and @qc_active is compared |
| 4497 | * and commands are completed accordingly. |
| 4498 | * |
| 4499 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4500 | * spin_lock_irqsave(host lock) |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4501 | * |
| 4502 | * RETURNS: |
| 4503 | * Number of completed commands on success, -errno otherwise. |
| 4504 | */ |
| 4505 | int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active, |
| 4506 | void (*finish_qc)(struct ata_queued_cmd *)) |
| 4507 | { |
| 4508 | int nr_done = 0; |
| 4509 | u32 done_mask; |
| 4510 | int i; |
| 4511 | |
| 4512 | done_mask = ap->qc_active ^ qc_active; |
| 4513 | |
| 4514 | if (unlikely(done_mask & qc_active)) { |
| 4515 | ata_port_printk(ap, KERN_ERR, "illegal qc_active transition " |
| 4516 | "(%08x->%08x)\n", ap->qc_active, qc_active); |
| 4517 | return -EINVAL; |
| 4518 | } |
| 4519 | |
| 4520 | for (i = 0; i < ATA_MAX_QUEUE; i++) { |
| 4521 | struct ata_queued_cmd *qc; |
| 4522 | |
| 4523 | if (!(done_mask & (1 << i))) |
| 4524 | continue; |
| 4525 | |
| 4526 | if ((qc = ata_qc_from_tag(ap, i))) { |
| 4527 | if (finish_qc) |
| 4528 | finish_qc(qc); |
| 4529 | ata_qc_complete(qc); |
| 4530 | nr_done++; |
| 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | return nr_done; |
| 4535 | } |
| 4536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4537 | /** |
| 4538 | * ata_qc_issue - issue taskfile to device |
| 4539 | * @qc: command to issue to device |
| 4540 | * |
| 4541 | * Prepare an ATA command to submission to device. |
| 4542 | * This includes mapping the data into a DMA-able |
| 4543 | * area, filling in the S/G table, and finally |
| 4544 | * writing the taskfile to hardware, starting the command. |
| 4545 | * |
| 4546 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4547 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | */ |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 4549 | void ata_qc_issue(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4550 | { |
| 4551 | struct ata_port *ap = qc->ap; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4552 | struct ata_link *link = qc->dev->link; |
Tejun Heo | 405e66b | 2007-11-27 19:28:53 +0900 | [diff] [blame] | 4553 | u8 prot = qc->tf.protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4555 | /* Make sure only one non-NCQ command is outstanding. The |
| 4556 | * check is skipped for old EH because it reuses active qc to |
| 4557 | * request ATAPI sense. |
| 4558 | */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4559 | WARN_ON(ap->ops->error_handler && ata_tag_valid(link->active_tag)); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4560 | |
Tejun Heo | 1973a02 | 2007-12-05 10:36:13 +0900 | [diff] [blame] | 4561 | if (ata_is_ncq(prot)) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4562 | WARN_ON(link->sactive & (1 << qc->tag)); |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4563 | |
| 4564 | if (!link->sactive) |
| 4565 | ap->nr_active_links++; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4566 | link->sactive |= 1 << qc->tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4567 | } else { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4568 | WARN_ON(link->sactive); |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4569 | |
| 4570 | ap->nr_active_links++; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4571 | link->active_tag = qc->tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4572 | } |
| 4573 | |
Tejun Heo | e4a70e7 | 2006-03-31 20:36:47 +0900 | [diff] [blame] | 4574 | qc->flags |= ATA_QCFLAG_ACTIVE; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4575 | ap->qc_active |= 1 << qc->tag; |
Tejun Heo | e4a70e7 | 2006-03-31 20:36:47 +0900 | [diff] [blame] | 4576 | |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 4577 | /* We guarantee to LLDs that they will have at least one |
| 4578 | * non-zero sg if the command is a data command. |
| 4579 | */ |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4580 | BUG_ON(ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)); |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 4581 | |
Tejun Heo | 405e66b | 2007-11-27 19:28:53 +0900 | [diff] [blame] | 4582 | if (ata_is_dma(prot) || (ata_is_pio(prot) && |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 4583 | (ap->flags & ATA_FLAG_PIO_DMA))) |
Tejun Heo | 001102d | 2007-12-05 16:43:09 +0900 | [diff] [blame] | 4584 | if (ata_sg_setup(qc)) |
| 4585 | goto sg_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | |
Tejun Heo | cf48062 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 4587 | /* if device is sleeping, schedule reset and abort the link */ |
Tejun Heo | 054a5fb | 2007-10-25 18:30:36 +0900 | [diff] [blame] | 4588 | if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { |
Tejun Heo | cf48062 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 4589 | link->eh_info.action |= ATA_EH_RESET; |
Tejun Heo | 054a5fb | 2007-10-25 18:30:36 +0900 | [diff] [blame] | 4590 | ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); |
| 4591 | ata_link_abort(link); |
| 4592 | return; |
| 4593 | } |
| 4594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | ap->ops->qc_prep(qc); |
| 4596 | |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 4597 | qc->err_mask |= ap->ops->qc_issue(qc); |
| 4598 | if (unlikely(qc->err_mask)) |
| 4599 | goto err; |
| 4600 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4601 | |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4602 | sg_err: |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 4603 | qc->err_mask |= AC_ERR_SYSTEM; |
| 4604 | err: |
| 4605 | ata_qc_complete(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | /** |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4609 | * sata_scr_valid - test whether SCRs are accessible |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4610 | * @link: ATA link to test SCR accessibility for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4611 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4612 | * Test whether SCRs are accessible for @link. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4613 | * |
| 4614 | * LOCKING: |
| 4615 | * None. |
| 4616 | * |
| 4617 | * RETURNS: |
| 4618 | * 1 if SCRs are accessible, 0 otherwise. |
| 4619 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4620 | int sata_scr_valid(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4621 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4622 | struct ata_port *ap = link->ap; |
| 4623 | |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 4624 | return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
| 4628 | * sata_scr_read - read SCR register of the specified port |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4629 | * @link: ATA link to read SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4630 | * @reg: SCR to read |
| 4631 | * @val: Place to store read value |
| 4632 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4633 | * Read SCR register @reg of @link into *@val. This function is |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4634 | * guaranteed to succeed if @link is ap->link, the cable type of |
| 4635 | * the port is SATA and the port implements ->scr_read. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4636 | * |
| 4637 | * LOCKING: |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4638 | * None if @link is ap->link. Kernel thread context otherwise. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4639 | * |
| 4640 | * RETURNS: |
| 4641 | * 0 on success, negative errno on failure. |
| 4642 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4643 | int sata_scr_read(struct ata_link *link, int reg, u32 *val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4644 | { |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4645 | if (ata_is_host_link(link)) { |
| 4646 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4647 | |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4648 | if (sata_scr_valid(link)) |
| 4649 | return ap->ops->scr_read(ap, reg, val); |
| 4650 | return -EOPNOTSUPP; |
| 4651 | } |
| 4652 | |
| 4653 | return sata_pmp_scr_read(link, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4654 | } |
| 4655 | |
| 4656 | /** |
| 4657 | * sata_scr_write - write SCR register of the specified port |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4658 | * @link: ATA link to write SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4659 | * @reg: SCR to write |
| 4660 | * @val: value to write |
| 4661 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4662 | * Write @val to SCR register @reg of @link. This function is |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4663 | * guaranteed to succeed if @link is ap->link, the cable type of |
| 4664 | * the port is SATA and the port implements ->scr_read. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4665 | * |
| 4666 | * LOCKING: |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4667 | * None if @link is ap->link. Kernel thread context otherwise. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4668 | * |
| 4669 | * RETURNS: |
| 4670 | * 0 on success, negative errno on failure. |
| 4671 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4672 | int sata_scr_write(struct ata_link *link, int reg, u32 val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4673 | { |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4674 | if (ata_is_host_link(link)) { |
| 4675 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4676 | |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4677 | if (sata_scr_valid(link)) |
| 4678 | return ap->ops->scr_write(ap, reg, val); |
| 4679 | return -EOPNOTSUPP; |
| 4680 | } |
| 4681 | |
| 4682 | return sata_pmp_scr_write(link, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | /** |
| 4686 | * 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] | 4687 | * @link: ATA link to write SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4688 | * @reg: SCR to write |
| 4689 | * @val: value to write |
| 4690 | * |
| 4691 | * This function is identical to sata_scr_write() except that this |
| 4692 | * function performs flush after writing to the register. |
| 4693 | * |
| 4694 | * LOCKING: |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4695 | * None if @link is ap->link. Kernel thread context otherwise. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4696 | * |
| 4697 | * RETURNS: |
| 4698 | * 0 on success, negative errno on failure. |
| 4699 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4700 | 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] | 4701 | { |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4702 | if (ata_is_host_link(link)) { |
| 4703 | struct ata_port *ap = link->ap; |
| 4704 | int rc; |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 4705 | |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4706 | if (sata_scr_valid(link)) { |
| 4707 | rc = ap->ops->scr_write(ap, reg, val); |
| 4708 | if (rc == 0) |
| 4709 | rc = ap->ops->scr_read(ap, reg, &val); |
| 4710 | return rc; |
| 4711 | } |
| 4712 | return -EOPNOTSUPP; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4713 | } |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4714 | |
| 4715 | return sata_pmp_scr_write(link, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4719 | * ata_link_online - test whether the given link is online |
| 4720 | * @link: ATA link to test |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4721 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4722 | * Test whether @link is online. Note that this function returns |
| 4723 | * 0 if online status of @link cannot be obtained, so |
| 4724 | * ata_link_online(link) != !ata_link_offline(link). |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4725 | * |
| 4726 | * LOCKING: |
| 4727 | * None. |
| 4728 | * |
| 4729 | * RETURNS: |
| 4730 | * 1 if the port online status is available and online. |
| 4731 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4732 | int ata_link_online(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4733 | { |
| 4734 | u32 sstatus; |
| 4735 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4736 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
| 4737 | (sstatus & 0xf) == 0x3) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4738 | return 1; |
| 4739 | return 0; |
| 4740 | } |
| 4741 | |
| 4742 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4743 | * ata_link_offline - test whether the given link is offline |
| 4744 | * @link: ATA link to test |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4745 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4746 | * Test whether @link is offline. Note that this function |
| 4747 | * returns 0 if offline status of @link cannot be obtained, so |
| 4748 | * ata_link_online(link) != !ata_link_offline(link). |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4749 | * |
| 4750 | * LOCKING: |
| 4751 | * None. |
| 4752 | * |
| 4753 | * RETURNS: |
| 4754 | * 1 if the port offline status is available and offline. |
| 4755 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4756 | int ata_link_offline(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4757 | { |
| 4758 | u32 sstatus; |
| 4759 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4760 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
| 4761 | (sstatus & 0xf) != 0x3) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 4762 | return 1; |
| 4763 | return 0; |
| 4764 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4765 | |
Tejun Heo | 77b08fb | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 4766 | int ata_flush_cache(struct ata_device *dev) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4767 | { |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 4768 | unsigned int err_mask; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4769 | u8 cmd; |
| 4770 | |
| 4771 | if (!ata_try_flush_cache(dev)) |
| 4772 | return 0; |
| 4773 | |
Tejun Heo | 6fc49ad | 2006-11-11 20:10:45 +0900 | [diff] [blame] | 4774 | if (dev->flags & ATA_DFLAG_FLUSH_EXT) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4775 | cmd = ATA_CMD_FLUSH_EXT; |
| 4776 | else |
| 4777 | cmd = ATA_CMD_FLUSH; |
| 4778 | |
Alan Cox | 4f34337 | 2007-08-08 14:30:31 +0100 | [diff] [blame] | 4779 | /* This is wrong. On a failed flush we get back the LBA of the lost |
| 4780 | sector and we should (assuming it wasn't aborted as unknown) issue |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 4781 | a further flush command to continue the writeback until it |
Alan Cox | 4f34337 | 2007-08-08 14:30:31 +0100 | [diff] [blame] | 4782 | does not error */ |
Tejun Heo | 977e6b9 | 2006-06-24 20:30:19 +0900 | [diff] [blame] | 4783 | err_mask = ata_do_simple_cmd(dev, cmd); |
| 4784 | if (err_mask) { |
| 4785 | ata_dev_printk(dev, KERN_ERR, "failed to flush cache\n"); |
| 4786 | return -EIO; |
| 4787 | } |
| 4788 | |
| 4789 | return 0; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4790 | } |
| 4791 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 4792 | #ifdef CONFIG_PM |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4793 | static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg, |
| 4794 | unsigned int action, unsigned int ehi_flags, |
| 4795 | int wait) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4796 | { |
| 4797 | unsigned long flags; |
| 4798 | int i, rc; |
| 4799 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4800 | for (i = 0; i < host->n_ports; i++) { |
| 4801 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | e3667eb | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 4802 | struct ata_link *link; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4803 | |
| 4804 | /* Previous resume operation might still be in |
| 4805 | * progress. Wait for PM_PENDING to clear. |
| 4806 | */ |
| 4807 | if (ap->pflags & ATA_PFLAG_PM_PENDING) { |
| 4808 | ata_port_wait_eh(ap); |
| 4809 | WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); |
| 4810 | } |
| 4811 | |
| 4812 | /* request PM ops to EH */ |
| 4813 | spin_lock_irqsave(ap->lock, flags); |
| 4814 | |
| 4815 | ap->pm_mesg = mesg; |
| 4816 | if (wait) { |
| 4817 | rc = 0; |
| 4818 | ap->pm_result = &rc; |
| 4819 | } |
| 4820 | |
| 4821 | ap->pflags |= ATA_PFLAG_PM_PENDING; |
Tejun Heo | e3667eb | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 4822 | __ata_port_for_each_link(link, ap) { |
| 4823 | link->eh_info.action |= action; |
| 4824 | link->eh_info.flags |= ehi_flags; |
| 4825 | } |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4826 | |
| 4827 | ata_port_schedule_eh(ap); |
| 4828 | |
| 4829 | spin_unlock_irqrestore(ap->lock, flags); |
| 4830 | |
| 4831 | /* wait and check result */ |
| 4832 | if (wait) { |
| 4833 | ata_port_wait_eh(ap); |
| 4834 | WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); |
| 4835 | if (rc) |
| 4836 | return rc; |
| 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | return 0; |
| 4841 | } |
| 4842 | |
| 4843 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4844 | * ata_host_suspend - suspend host |
| 4845 | * @host: host to suspend |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4846 | * @mesg: PM message |
| 4847 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4848 | * Suspend @host. Actual operation is performed by EH. This |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4849 | * function requests EH to perform PM operations and waits for EH |
| 4850 | * to finish. |
| 4851 | * |
| 4852 | * LOCKING: |
| 4853 | * Kernel thread context (may sleep). |
| 4854 | * |
| 4855 | * RETURNS: |
| 4856 | * 0 on success, -errno on failure. |
| 4857 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4858 | int ata_host_suspend(struct ata_host *host, pm_message_t mesg) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4859 | { |
Tejun Heo | 9666f40 | 2007-05-04 21:27:47 +0200 | [diff] [blame] | 4860 | int rc; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4861 | |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 4862 | /* |
| 4863 | * disable link pm on all ports before requesting |
| 4864 | * any pm activity |
| 4865 | */ |
| 4866 | ata_lpm_enable(host); |
| 4867 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4868 | rc = ata_host_request_pm(host, mesg, 0, ATA_EHI_QUIET, 1); |
Jeff Garzik | 72ad6ec | 2008-02-25 17:31:10 -0500 | [diff] [blame] | 4869 | if (rc == 0) |
| 4870 | host->dev->power.power_state = mesg; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4871 | return rc; |
| 4872 | } |
| 4873 | |
| 4874 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4875 | * ata_host_resume - resume host |
| 4876 | * @host: host to resume |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4877 | * |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4878 | * Resume @host. Actual operation is performed by EH. This |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4879 | * function requests EH to perform PM operations and returns. |
| 4880 | * Note that all resume operations are performed parallely. |
| 4881 | * |
| 4882 | * LOCKING: |
| 4883 | * Kernel thread context (may sleep). |
| 4884 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4885 | void ata_host_resume(struct ata_host *host) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4886 | { |
Tejun Heo | cf48062 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 4887 | ata_host_request_pm(host, PMSG_ON, ATA_EH_RESET, |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4888 | ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); |
Jeff Garzik | 72ad6ec | 2008-02-25 17:31:10 -0500 | [diff] [blame] | 4889 | host->dev->power.power_state = PMSG_ON; |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 4890 | |
| 4891 | /* reenable link pm */ |
| 4892 | ata_lpm_disable(host); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4893 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 4894 | #endif |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 4895 | |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4896 | /** |
| 4897 | * ata_port_start - Set port up for dma. |
| 4898 | * @ap: Port to initialize |
| 4899 | * |
| 4900 | * Called just after data structures for each port are |
| 4901 | * initialized. Allocates space for PRD table. |
| 4902 | * |
| 4903 | * May be used as the port_start() entry in ata_port_operations. |
| 4904 | * |
| 4905 | * LOCKING: |
| 4906 | * Inherited from caller. |
| 4907 | */ |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 4908 | int ata_port_start(struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4909 | { |
Brian King | 2f1f610 | 2006-03-23 17:30:15 -0600 | [diff] [blame] | 4910 | struct device *dev = ap->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4911 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 4912 | ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, |
| 4913 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | if (!ap->prd) |
| 4915 | return -ENOMEM; |
| 4916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4917 | return 0; |
| 4918 | } |
| 4919 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4920 | /** |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 4921 | * ata_dev_init - Initialize an ata_device structure |
| 4922 | * @dev: Device structure to initialize |
| 4923 | * |
| 4924 | * Initialize @dev in preparation for probing. |
| 4925 | * |
| 4926 | * LOCKING: |
| 4927 | * Inherited from caller. |
| 4928 | */ |
| 4929 | void ata_dev_init(struct ata_device *dev) |
| 4930 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4931 | struct ata_link *link = dev->link; |
| 4932 | struct ata_port *ap = link->ap; |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 4933 | unsigned long flags; |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 4934 | |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 4935 | /* SATA spd limit is bound to the first device */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4936 | link->sata_spd_limit = link->hw_sata_spd_limit; |
| 4937 | link->sata_spd = 0; |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 4938 | |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 4939 | /* High bits of dev->flags are used to record warm plug |
| 4940 | * requests which occur asynchronously. Synchronize using |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4941 | * host lock. |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 4942 | */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 4943 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 4944 | dev->flags &= ~ATA_DFLAG_INIT_MASK; |
Tejun Heo | 3dcc323 | 2007-09-03 12:20:11 +0900 | [diff] [blame] | 4945 | dev->horkage = 0; |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 4946 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 4947 | |
| 4948 | memset((void *)dev + ATA_DEVICE_CLEAR_OFFSET, 0, |
| 4949 | sizeof(*dev) - ATA_DEVICE_CLEAR_OFFSET); |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 4950 | dev->pio_mask = UINT_MAX; |
| 4951 | dev->mwdma_mask = UINT_MAX; |
| 4952 | dev->udma_mask = UINT_MAX; |
| 4953 | } |
| 4954 | |
| 4955 | /** |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4956 | * ata_link_init - Initialize an ata_link structure |
| 4957 | * @ap: ATA port link is attached to |
| 4958 | * @link: Link structure to initialize |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4959 | * @pmp: Port multiplier port number |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4960 | * |
| 4961 | * Initialize @link. |
| 4962 | * |
| 4963 | * LOCKING: |
| 4964 | * Kernel thread context (may sleep) |
| 4965 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4966 | 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] | 4967 | { |
| 4968 | int i; |
| 4969 | |
| 4970 | /* clear everything except for devices */ |
| 4971 | memset(link, 0, offsetof(struct ata_link, device[0])); |
| 4972 | |
| 4973 | link->ap = ap; |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4974 | link->pmp = pmp; |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 4975 | link->active_tag = ATA_TAG_POISON; |
| 4976 | link->hw_sata_spd_limit = UINT_MAX; |
| 4977 | |
| 4978 | /* can't use iterator, ap isn't initialized yet */ |
| 4979 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 4980 | struct ata_device *dev = &link->device[i]; |
| 4981 | |
| 4982 | dev->link = link; |
| 4983 | dev->devno = dev - link->device; |
| 4984 | ata_dev_init(dev); |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | /** |
| 4989 | * sata_link_init_spd - Initialize link->sata_spd_limit |
| 4990 | * @link: Link to configure sata_spd_limit for |
| 4991 | * |
| 4992 | * Initialize @link->[hw_]sata_spd_limit to the currently |
| 4993 | * configured value. |
| 4994 | * |
| 4995 | * LOCKING: |
| 4996 | * Kernel thread context (may sleep). |
| 4997 | * |
| 4998 | * RETURNS: |
| 4999 | * 0 on success, -errno on failure. |
| 5000 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 5001 | int sata_link_init_spd(struct ata_link *link) |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5002 | { |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5003 | u32 scontrol; |
| 5004 | u8 spd; |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5005 | int rc; |
| 5006 | |
| 5007 | rc = sata_scr_read(link, SCR_CONTROL, &scontrol); |
| 5008 | if (rc) |
| 5009 | return rc; |
| 5010 | |
| 5011 | spd = (scontrol >> 4) & 0xf; |
| 5012 | if (spd) |
| 5013 | link->hw_sata_spd_limit &= (1 << spd) - 1; |
| 5014 | |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5015 | ata_force_spd_limit(link); |
| 5016 | |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5017 | link->sata_spd_limit = link->hw_sata_spd_limit; |
| 5018 | |
| 5019 | return 0; |
| 5020 | } |
| 5021 | |
| 5022 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5023 | * ata_port_alloc - allocate and initialize basic ATA port resources |
| 5024 | * @host: ATA host this allocated port belongs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5025 | * |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5026 | * Allocate and initialize basic ATA port resources. |
| 5027 | * |
| 5028 | * RETURNS: |
| 5029 | * Allocate ATA port on success, NULL on failure. |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5030 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | * LOCKING: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5032 | * Inherited from calling layer (may sleep). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5033 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5034 | struct ata_port *ata_port_alloc(struct ata_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | { |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5036 | struct ata_port *ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5038 | DPRINTK("ENTER\n"); |
| 5039 | |
| 5040 | ap = kzalloc(sizeof(*ap), GFP_KERNEL); |
| 5041 | if (!ap) |
| 5042 | return NULL; |
| 5043 | |
Tejun Heo | f4d6d00 | 2007-05-01 11:50:15 +0200 | [diff] [blame] | 5044 | ap->pflags |= ATA_PFLAG_INITIALIZING; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5045 | ap->lock = &host->lock; |
Tejun Heo | 198e0fe | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 5046 | ap->flags = ATA_FLAG_DISABLED; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5047 | ap->print_id = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | ap->ctl = ATA_DEVCTL_OBS; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5049 | ap->host = host; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5050 | ap->dev = host->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5051 | ap->last_ctl = 0xFF; |
Borislav Petkov | bd5d825 | 2006-06-11 23:17:01 -0400 | [diff] [blame] | 5052 | |
| 5053 | #if defined(ATA_VERBOSE_DEBUG) |
| 5054 | /* turn on all debugging levels */ |
| 5055 | ap->msg_enable = 0x00FF; |
| 5056 | #elif defined(ATA_DEBUG) |
| 5057 | 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] | 5058 | #else |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 5059 | ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; |
Borislav Petkov | bd5d825 | 2006-06-11 23:17:01 -0400 | [diff] [blame] | 5060 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5061 | |
Jeff Garzik | 442eacc | 2007-12-19 04:25:10 -0500 | [diff] [blame] | 5062 | INIT_DELAYED_WORK(&ap->port_task, ata_pio_task); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 5063 | INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); |
| 5064 | INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); |
Tejun Heo | a72ec4c | 2006-01-23 13:09:37 +0900 | [diff] [blame] | 5065 | INIT_LIST_HEAD(&ap->eh_done_q); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 5066 | init_waitqueue_head(&ap->eh_wait_q); |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 5067 | init_timer_deferrable(&ap->fastdrain_timer); |
| 5068 | ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; |
| 5069 | ap->fastdrain_timer.data = (unsigned long)ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | |
Tejun Heo | 838df62 | 2006-05-15 20:57:44 +0900 | [diff] [blame] | 5071 | ap->cbl = ATA_CBL_NONE; |
Tejun Heo | 838df62 | 2006-05-15 20:57:44 +0900 | [diff] [blame] | 5072 | |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5073 | ata_link_init(ap, &ap->link, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5074 | |
| 5075 | #ifdef ATA_IRQ_TRAP |
| 5076 | ap->stats.unhandled_irq = 1; |
| 5077 | ap->stats.idle_irq = 1; |
| 5078 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5079 | return ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5080 | } |
| 5081 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5082 | static void ata_host_release(struct device *gendev, void *res) |
| 5083 | { |
| 5084 | struct ata_host *host = dev_get_drvdata(gendev); |
| 5085 | int i; |
| 5086 | |
| 5087 | for (i = 0; i < host->n_ports; i++) { |
| 5088 | struct ata_port *ap = host->ports[i]; |
| 5089 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5090 | if (!ap) |
| 5091 | continue; |
| 5092 | |
Tejun Heo | 4911487 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5093 | if (ap->scsi_host) |
Tejun Heo | 1aa506e | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 5094 | scsi_host_put(ap->scsi_host); |
| 5095 | |
Tejun Heo | 633273a3 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5096 | kfree(ap->pmp_link); |
Tejun Heo | 4911487 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5097 | kfree(ap); |
Tejun Heo | 1aa506e | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 5098 | host->ports[i] = NULL; |
| 5099 | } |
| 5100 | |
Tejun Heo | 1aa56cc | 2007-02-27 22:33:21 +0900 | [diff] [blame] | 5101 | dev_set_drvdata(gendev, NULL); |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5102 | } |
| 5103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5105 | * ata_host_alloc - allocate and init basic ATA host resources |
| 5106 | * @dev: generic device this host is associated with |
| 5107 | * @max_ports: maximum number of ATA ports associated with this host |
| 5108 | * |
| 5109 | * Allocate and initialize basic ATA host resources. LLD calls |
| 5110 | * this function to allocate a host, initializes it fully and |
| 5111 | * attaches it using ata_host_register(). |
| 5112 | * |
| 5113 | * @max_ports ports are allocated and host->n_ports is |
| 5114 | * initialized to @max_ports. The caller is allowed to decrease |
| 5115 | * host->n_ports before calling ata_host_register(). The unused |
| 5116 | * ports will be automatically freed on registration. |
| 5117 | * |
| 5118 | * RETURNS: |
| 5119 | * Allocate ATA host on success, NULL on failure. |
| 5120 | * |
| 5121 | * LOCKING: |
| 5122 | * Inherited from calling layer (may sleep). |
| 5123 | */ |
| 5124 | struct ata_host *ata_host_alloc(struct device *dev, int max_ports) |
| 5125 | { |
| 5126 | struct ata_host *host; |
| 5127 | size_t sz; |
| 5128 | int i; |
| 5129 | |
| 5130 | DPRINTK("ENTER\n"); |
| 5131 | |
| 5132 | if (!devres_open_group(dev, NULL, GFP_KERNEL)) |
| 5133 | return NULL; |
| 5134 | |
| 5135 | /* alloc a container for our list of ATA ports (buses) */ |
| 5136 | sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *); |
| 5137 | /* alloc a container for our list of ATA ports (buses) */ |
| 5138 | host = devres_alloc(ata_host_release, sz, GFP_KERNEL); |
| 5139 | if (!host) |
| 5140 | goto err_out; |
| 5141 | |
| 5142 | devres_add(dev, host); |
| 5143 | dev_set_drvdata(dev, host); |
| 5144 | |
| 5145 | spin_lock_init(&host->lock); |
| 5146 | host->dev = dev; |
| 5147 | host->n_ports = max_ports; |
| 5148 | |
| 5149 | /* allocate ports bound to this host */ |
| 5150 | for (i = 0; i < max_ports; i++) { |
| 5151 | struct ata_port *ap; |
| 5152 | |
| 5153 | ap = ata_port_alloc(host); |
| 5154 | if (!ap) |
| 5155 | goto err_out; |
| 5156 | |
| 5157 | ap->port_no = i; |
| 5158 | host->ports[i] = ap; |
| 5159 | } |
| 5160 | |
| 5161 | devres_remove_group(dev, NULL); |
| 5162 | return host; |
| 5163 | |
| 5164 | err_out: |
| 5165 | devres_release_group(dev, NULL); |
| 5166 | return NULL; |
| 5167 | } |
| 5168 | |
| 5169 | /** |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5170 | * ata_host_alloc_pinfo - alloc host and init with port_info array |
| 5171 | * @dev: generic device this host is associated with |
| 5172 | * @ppi: array of ATA port_info to initialize host with |
| 5173 | * @n_ports: number of ATA ports attached to this host |
| 5174 | * |
| 5175 | * Allocate ATA host and initialize with info from @ppi. If NULL |
| 5176 | * terminated, @ppi may contain fewer entries than @n_ports. The |
| 5177 | * last entry will be used for the remaining ports. |
| 5178 | * |
| 5179 | * RETURNS: |
| 5180 | * Allocate ATA host on success, NULL on failure. |
| 5181 | * |
| 5182 | * LOCKING: |
| 5183 | * Inherited from calling layer (may sleep). |
| 5184 | */ |
| 5185 | struct ata_host *ata_host_alloc_pinfo(struct device *dev, |
| 5186 | const struct ata_port_info * const * ppi, |
| 5187 | int n_ports) |
| 5188 | { |
| 5189 | const struct ata_port_info *pi; |
| 5190 | struct ata_host *host; |
| 5191 | int i, j; |
| 5192 | |
| 5193 | host = ata_host_alloc(dev, n_ports); |
| 5194 | if (!host) |
| 5195 | return NULL; |
| 5196 | |
| 5197 | for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { |
| 5198 | struct ata_port *ap = host->ports[i]; |
| 5199 | |
| 5200 | if (ppi[j]) |
| 5201 | pi = ppi[j++]; |
| 5202 | |
| 5203 | ap->pio_mask = pi->pio_mask; |
| 5204 | ap->mwdma_mask = pi->mwdma_mask; |
| 5205 | ap->udma_mask = pi->udma_mask; |
| 5206 | ap->flags |= pi->flags; |
Tejun Heo | 0c88758 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5207 | ap->link.flags |= pi->link_flags; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5208 | ap->ops = pi->port_ops; |
| 5209 | |
| 5210 | if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) |
| 5211 | host->ops = pi->port_ops; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5212 | } |
| 5213 | |
| 5214 | return host; |
| 5215 | } |
| 5216 | |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 5217 | static void ata_host_stop(struct device *gendev, void *res) |
| 5218 | { |
| 5219 | struct ata_host *host = dev_get_drvdata(gendev); |
| 5220 | int i; |
| 5221 | |
| 5222 | WARN_ON(!(host->flags & ATA_HOST_STARTED)); |
| 5223 | |
| 5224 | for (i = 0; i < host->n_ports; i++) { |
| 5225 | struct ata_port *ap = host->ports[i]; |
| 5226 | |
| 5227 | if (ap->ops->port_stop) |
| 5228 | ap->ops->port_stop(ap); |
| 5229 | } |
| 5230 | |
| 5231 | if (host->ops->host_stop) |
| 5232 | host->ops->host_stop(host); |
| 5233 | } |
| 5234 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5235 | /** |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 5236 | * ata_finalize_port_ops - finalize ata_port_operations |
| 5237 | * @ops: ata_port_operations to finalize |
| 5238 | * |
| 5239 | * An ata_port_operations can inherit from another ops and that |
| 5240 | * ops can again inherit from another. This can go on as many |
| 5241 | * times as necessary as long as there is no loop in the |
| 5242 | * inheritance chain. |
| 5243 | * |
| 5244 | * Ops tables are finalized when the host is started. NULL or |
| 5245 | * unspecified entries are inherited from the closet ancestor |
| 5246 | * which has the method and the entry is populated with it. |
| 5247 | * After finalization, the ops table directly points to all the |
| 5248 | * methods and ->inherits is no longer necessary and cleared. |
| 5249 | * |
| 5250 | * Using ATA_OP_NULL, inheriting ops can force a method to NULL. |
| 5251 | * |
| 5252 | * LOCKING: |
| 5253 | * None. |
| 5254 | */ |
| 5255 | static void ata_finalize_port_ops(struct ata_port_operations *ops) |
| 5256 | { |
| 5257 | static spinlock_t lock = SPIN_LOCK_UNLOCKED; |
| 5258 | const struct ata_port_operations *cur; |
| 5259 | void **begin = (void **)ops; |
| 5260 | void **end = (void **)&ops->inherits; |
| 5261 | void **pp; |
| 5262 | |
| 5263 | if (!ops || !ops->inherits) |
| 5264 | return; |
| 5265 | |
| 5266 | spin_lock(&lock); |
| 5267 | |
| 5268 | for (cur = ops->inherits; cur; cur = cur->inherits) { |
| 5269 | void **inherit = (void **)cur; |
| 5270 | |
| 5271 | for (pp = begin; pp < end; pp++, inherit++) |
| 5272 | if (!*pp) |
| 5273 | *pp = *inherit; |
| 5274 | } |
| 5275 | |
| 5276 | for (pp = begin; pp < end; pp++) |
| 5277 | if (IS_ERR(*pp)) |
| 5278 | *pp = NULL; |
| 5279 | |
| 5280 | ops->inherits = NULL; |
| 5281 | |
| 5282 | spin_unlock(&lock); |
| 5283 | } |
| 5284 | |
| 5285 | /** |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5286 | * ata_host_start - start and freeze ports of an ATA host |
| 5287 | * @host: ATA host to start ports for |
| 5288 | * |
| 5289 | * Start and then freeze ports of @host. Started status is |
| 5290 | * recorded in host->flags, so this function can be called |
| 5291 | * multiple times. Ports are guaranteed to get started only |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5292 | * once. If host->ops isn't initialized yet, its set to the |
| 5293 | * first non-dummy port ops. |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5294 | * |
| 5295 | * LOCKING: |
| 5296 | * Inherited from calling layer (may sleep). |
| 5297 | * |
| 5298 | * RETURNS: |
| 5299 | * 0 if all ports are started successfully, -errno otherwise. |
| 5300 | */ |
| 5301 | int ata_host_start(struct ata_host *host) |
| 5302 | { |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 5303 | int have_stop = 0; |
| 5304 | void *start_dr = NULL; |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5305 | int i, rc; |
| 5306 | |
| 5307 | if (host->flags & ATA_HOST_STARTED) |
| 5308 | return 0; |
| 5309 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 5310 | ata_finalize_port_ops(host->ops); |
| 5311 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5312 | for (i = 0; i < host->n_ports; i++) { |
| 5313 | struct ata_port *ap = host->ports[i]; |
| 5314 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 5315 | ata_finalize_port_ops(ap->ops); |
| 5316 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5317 | if (!host->ops && !ata_port_is_dummy(ap)) |
| 5318 | host->ops = ap->ops; |
| 5319 | |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 5320 | if (ap->ops->port_stop) |
| 5321 | have_stop = 1; |
| 5322 | } |
| 5323 | |
| 5324 | if (host->ops->host_stop) |
| 5325 | have_stop = 1; |
| 5326 | |
| 5327 | if (have_stop) { |
| 5328 | start_dr = devres_alloc(ata_host_stop, 0, GFP_KERNEL); |
| 5329 | if (!start_dr) |
| 5330 | return -ENOMEM; |
| 5331 | } |
| 5332 | |
| 5333 | for (i = 0; i < host->n_ports; i++) { |
| 5334 | struct ata_port *ap = host->ports[i]; |
| 5335 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5336 | if (ap->ops->port_start) { |
| 5337 | rc = ap->ops->port_start(ap); |
| 5338 | if (rc) { |
Alan Cox | 0f9fe9b | 2007-11-30 15:23:16 +0000 | [diff] [blame] | 5339 | if (rc != -ENODEV) |
Andrew Morton | 0f75774 | 2008-01-10 14:33:09 -0800 | [diff] [blame] | 5340 | dev_printk(KERN_ERR, host->dev, |
| 5341 | "failed to start port %d " |
| 5342 | "(errno=%d)\n", i, rc); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5343 | goto err_out; |
| 5344 | } |
| 5345 | } |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5346 | ata_eh_freeze_port(ap); |
| 5347 | } |
| 5348 | |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 5349 | if (start_dr) |
| 5350 | devres_add(host->dev, start_dr); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5351 | host->flags |= ATA_HOST_STARTED; |
| 5352 | return 0; |
| 5353 | |
| 5354 | err_out: |
| 5355 | while (--i >= 0) { |
| 5356 | struct ata_port *ap = host->ports[i]; |
| 5357 | |
| 5358 | if (ap->ops->port_stop) |
| 5359 | ap->ops->port_stop(ap); |
| 5360 | } |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 5361 | devres_free(start_dr); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5362 | return rc; |
| 5363 | } |
| 5364 | |
| 5365 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5366 | * ata_sas_host_init - Initialize a host struct |
| 5367 | * @host: host to initialize |
| 5368 | * @dev: device host is attached to |
| 5369 | * @flags: host flags |
| 5370 | * @ops: port_ops |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 5371 | * |
| 5372 | * LOCKING: |
| 5373 | * PCI/etc. bus probe sem. |
| 5374 | * |
| 5375 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5376 | /* KILLME - the only user left is ipr */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5377 | void ata_host_init(struct ata_host *host, struct device *dev, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 5378 | unsigned long flags, struct ata_port_operations *ops) |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 5379 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5380 | spin_lock_init(&host->lock); |
| 5381 | host->dev = dev; |
| 5382 | host->flags = flags; |
| 5383 | host->ops = ops; |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5387 | * ata_host_register - register initialized ATA host |
| 5388 | * @host: ATA host to register |
| 5389 | * @sht: template for SCSI host |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5390 | * |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5391 | * Register initialized ATA host. @host is allocated using |
| 5392 | * ata_host_alloc() and fully initialized by LLD. This function |
| 5393 | * starts ports, registers @host with ATA and SCSI layers and |
| 5394 | * probe registered devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5395 | * |
| 5396 | * LOCKING: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5397 | * Inherited from calling layer (may sleep). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5398 | * |
| 5399 | * RETURNS: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5400 | * 0 on success, -errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5401 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5402 | 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] | 5403 | { |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5404 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5406 | /* host must have been started */ |
| 5407 | if (!(host->flags & ATA_HOST_STARTED)) { |
| 5408 | dev_printk(KERN_ERR, host->dev, |
| 5409 | "BUG: trying to register unstarted host\n"); |
| 5410 | WARN_ON(1); |
| 5411 | return -EINVAL; |
Alan Cox | 02f076a | 2006-09-26 17:35:32 +0100 | [diff] [blame] | 5412 | } |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5413 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5414 | /* Blow away unused ports. This happens when LLD can't |
| 5415 | * determine the exact number of ports to allocate at |
| 5416 | * allocation time. |
| 5417 | */ |
| 5418 | for (i = host->n_ports; host->ports[i]; i++) |
| 5419 | kfree(host->ports[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5420 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5421 | /* give ports names and add SCSI hosts */ |
| 5422 | for (i = 0; i < host->n_ports; i++) |
| 5423 | host->ports[i]->print_id = ata_print_id++; |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5424 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5425 | rc = ata_scsi_add_hosts(host, sht); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5426 | if (rc) |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5427 | return rc; |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5428 | |
Tejun Heo | fafbae8 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 5429 | /* associate with ACPI nodes */ |
| 5430 | ata_acpi_associate(host); |
| 5431 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5432 | /* set cable, sata_spd_limit and report */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5433 | for (i = 0; i < host->n_ports; i++) { |
| 5434 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5435 | unsigned long xfer_mask; |
| 5436 | |
| 5437 | /* set SATA cable type if still unset */ |
| 5438 | if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) |
| 5439 | ap->cbl = ATA_CBL_SATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5440 | |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 5441 | /* init sata_spd_limit to the current value */ |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5442 | sata_link_init_spd(&ap->link); |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 5443 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 5444 | /* print per-port info to dmesg */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5445 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, |
| 5446 | ap->udma_mask); |
| 5447 | |
Tejun Heo | abf6e8e | 2007-10-09 14:57:25 +0900 | [diff] [blame] | 5448 | if (!ata_port_is_dummy(ap)) { |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 5449 | ata_port_printk(ap, KERN_INFO, |
| 5450 | "%cATA max %s %s\n", |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 5451 | (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5452 | ata_mode_string(xfer_mask), |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 5453 | ap->link.eh_info.desc); |
Tejun Heo | abf6e8e | 2007-10-09 14:57:25 +0900 | [diff] [blame] | 5454 | ata_ehi_clear_desc(&ap->link.eh_info); |
| 5455 | } else |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5456 | ata_port_printk(ap, KERN_INFO, "DUMMY\n"); |
| 5457 | } |
| 5458 | |
| 5459 | /* perform each probe synchronously */ |
| 5460 | DPRINTK("probe begin\n"); |
| 5461 | for (i = 0; i < host->n_ports; i++) { |
| 5462 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5463 | |
| 5464 | /* probe */ |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 5465 | if (ap->ops->error_handler) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5466 | struct ata_eh_info *ehi = &ap->link.eh_info; |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5467 | unsigned long flags; |
| 5468 | |
| 5469 | ata_port_probe(ap); |
| 5470 | |
| 5471 | /* kick EH for boot probing */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5472 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5473 | |
Tejun Heo | b558edd | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 5474 | ehi->probe_mask |= ATA_ALL_DEVICES; |
Tejun Heo | cf48062 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 5475 | ehi->action |= ATA_EH_RESET; |
Tejun Heo | 1cdaf53 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 5476 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5477 | |
Tejun Heo | f4d6d00 | 2007-05-01 11:50:15 +0200 | [diff] [blame] | 5478 | ap->pflags &= ~ATA_PFLAG_INITIALIZING; |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 5479 | ap->pflags |= ATA_PFLAG_LOADING; |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5480 | ata_port_schedule_eh(ap); |
| 5481 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5482 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5483 | |
| 5484 | /* wait for EH to finish */ |
| 5485 | ata_port_wait_eh(ap); |
| 5486 | } else { |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5487 | DPRINTK("ata%u: bus probe begin\n", ap->print_id); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5488 | rc = ata_bus_probe(ap); |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 5489 | DPRINTK("ata%u: bus probe end\n", ap->print_id); |
Tejun Heo | 3e70639 | 2006-05-31 18:28:11 +0900 | [diff] [blame] | 5490 | |
| 5491 | if (rc) { |
| 5492 | /* FIXME: do something useful here? |
| 5493 | * Current libata behavior will |
| 5494 | * tear down everything when |
| 5495 | * the module is removed |
| 5496 | * or the h/w is unplugged. |
| 5497 | */ |
| 5498 | } |
| 5499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | /* probes are done, now scan each port's disk(s) */ |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 5503 | DPRINTK("host probe begin\n"); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5504 | for (i = 0; i < host->n_ports; i++) { |
| 5505 | struct ata_port *ap = host->ports[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | |
Tejun Heo | 1ae4631 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 5507 | ata_scsi_scan_host(ap, 1); |
Kristen Carlson Accardi | ca77329 | 2007-10-25 00:58:59 -0400 | [diff] [blame] | 5508 | ata_lpm_schedule(ap, ap->pm_policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | } |
| 5510 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5511 | return 0; |
| 5512 | } |
| 5513 | |
| 5514 | /** |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5515 | * ata_host_activate - start host, request IRQ and register it |
| 5516 | * @host: target ATA host |
| 5517 | * @irq: IRQ to request |
| 5518 | * @irq_handler: irq_handler used when requesting IRQ |
| 5519 | * @irq_flags: irq_flags used when requesting IRQ |
| 5520 | * @sht: scsi_host_template to use when registering the host |
| 5521 | * |
| 5522 | * After allocating an ATA host and initializing it, most libata |
| 5523 | * LLDs perform three steps to activate the host - start host, |
| 5524 | * request IRQ and register it. This helper takes necessasry |
| 5525 | * arguments and performs the three steps in one go. |
| 5526 | * |
Paul Mundt | 3d46b2e | 2007-11-08 11:14:56 +0900 | [diff] [blame] | 5527 | * An invalid IRQ skips the IRQ registration and expects the host to |
| 5528 | * have set polling mode on the port. In this case, @irq_handler |
| 5529 | * should be NULL. |
| 5530 | * |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5531 | * LOCKING: |
| 5532 | * Inherited from calling layer (may sleep). |
| 5533 | * |
| 5534 | * RETURNS: |
| 5535 | * 0 on success, -errno otherwise. |
| 5536 | */ |
| 5537 | int ata_host_activate(struct ata_host *host, int irq, |
| 5538 | irq_handler_t irq_handler, unsigned long irq_flags, |
| 5539 | struct scsi_host_template *sht) |
| 5540 | { |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 5541 | int i, rc; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5542 | |
| 5543 | rc = ata_host_start(host); |
| 5544 | if (rc) |
| 5545 | return rc; |
| 5546 | |
Paul Mundt | 3d46b2e | 2007-11-08 11:14:56 +0900 | [diff] [blame] | 5547 | /* Special case for polling mode */ |
| 5548 | if (!irq) { |
| 5549 | WARN_ON(irq_handler); |
| 5550 | return ata_host_register(host, sht); |
| 5551 | } |
| 5552 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5553 | rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, |
| 5554 | dev_driver_string(host->dev), host); |
| 5555 | if (rc) |
| 5556 | return rc; |
| 5557 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 5558 | for (i = 0; i < host->n_ports; i++) |
| 5559 | ata_port_desc(host->ports[i], "irq %d", irq); |
Tejun Heo | 4031826 | 2007-07-03 01:38:47 +0900 | [diff] [blame] | 5560 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5561 | rc = ata_host_register(host, sht); |
| 5562 | /* if failed, just free the IRQ and leave ports alone */ |
| 5563 | if (rc) |
| 5564 | devm_free_irq(host->dev, irq, host); |
| 5565 | |
| 5566 | return rc; |
| 5567 | } |
| 5568 | |
| 5569 | /** |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5570 | * ata_port_detach - Detach ATA port in prepration of device removal |
| 5571 | * @ap: ATA port to be detached |
| 5572 | * |
| 5573 | * Detach all ATA devices and the associated SCSI devices of @ap; |
| 5574 | * then, remove the associated SCSI host. @ap is guaranteed to |
| 5575 | * be quiescent on return from this function. |
| 5576 | * |
| 5577 | * LOCKING: |
| 5578 | * Kernel thread context (may sleep). |
| 5579 | */ |
Adrian Bunk | 741b776 | 2007-10-24 18:23:06 +0200 | [diff] [blame] | 5580 | static void ata_port_detach(struct ata_port *ap) |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5581 | { |
| 5582 | unsigned long flags; |
Tejun Heo | 41bda9c | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 5583 | struct ata_link *link; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5584 | struct ata_device *dev; |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5585 | |
| 5586 | if (!ap->ops->error_handler) |
Tejun Heo | c3cf30a | 2006-08-05 03:59:11 +0900 | [diff] [blame] | 5587 | goto skip_eh; |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5588 | |
| 5589 | /* tell EH we're leaving & flush EH */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5590 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 5591 | ap->pflags |= ATA_PFLAG_UNLOADING; |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5592 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5593 | |
| 5594 | ata_port_wait_eh(ap); |
| 5595 | |
Tejun Heo | 7f9ad9b | 2007-12-15 15:05:00 +0900 | [diff] [blame] | 5596 | /* EH is now guaranteed to see UNLOADING - EH context belongs |
| 5597 | * to us. Disable all existing devices. |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5598 | */ |
Tejun Heo | 41bda9c | 2007-08-06 18:36:24 +0900 | [diff] [blame] | 5599 | ata_port_for_each_link(link, ap) { |
| 5600 | ata_link_for_each_dev(dev, link) |
| 5601 | ata_dev_disable(dev); |
| 5602 | } |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5603 | |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5604 | /* Final freeze & EH. All in-flight commands are aborted. EH |
| 5605 | * will be skipped and retrials will be terminated with bad |
| 5606 | * target. |
| 5607 | */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5608 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5609 | ata_port_freeze(ap); /* won't be thawed */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5610 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5611 | |
| 5612 | ata_port_wait_eh(ap); |
Oleg Nesterov | 45a66c1 | 2007-07-09 11:46:13 -0700 | [diff] [blame] | 5613 | cancel_rearming_delayed_work(&ap->hotplug_task); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5614 | |
Tejun Heo | c3cf30a | 2006-08-05 03:59:11 +0900 | [diff] [blame] | 5615 | skip_eh: |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5616 | /* remove the associated SCSI host */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5617 | scsi_remove_host(ap->scsi_host); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | /** |
Tejun Heo | 0529c15 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 5621 | * ata_host_detach - Detach all ports of an ATA host |
| 5622 | * @host: Host to detach |
| 5623 | * |
| 5624 | * Detach all ports of @host. |
| 5625 | * |
| 5626 | * LOCKING: |
| 5627 | * Kernel thread context (may sleep). |
| 5628 | */ |
| 5629 | void ata_host_detach(struct ata_host *host) |
| 5630 | { |
| 5631 | int i; |
| 5632 | |
| 5633 | for (i = 0; i < host->n_ports; i++) |
| 5634 | ata_port_detach(host->ports[i]); |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 5635 | |
| 5636 | /* the host is dead now, dissociate ACPI */ |
| 5637 | ata_acpi_dissociate(host); |
Tejun Heo | 0529c15 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 5638 | } |
| 5639 | |
Jeff Garzik | 374b187 | 2005-08-30 05:42:52 -0400 | [diff] [blame] | 5640 | #ifdef CONFIG_PCI |
| 5641 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 5642 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | * ata_pci_remove_one - PCI layer callback for device removal |
| 5644 | * @pdev: PCI device that was removed |
| 5645 | * |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5646 | * PCI layer indicates to libata via this hook that hot-unplug or |
| 5647 | * module unload event has occurred. Detach all ports. Resource |
| 5648 | * release is handled via devres. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5649 | * |
| 5650 | * LOCKING: |
| 5651 | * Inherited from PCI layer (may sleep). |
| 5652 | */ |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5653 | void ata_pci_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | { |
Jeff Garzik | 2855568 | 2007-10-11 17:12:35 -0400 | [diff] [blame] | 5655 | struct device *dev = &pdev->dev; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5656 | struct ata_host *host = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5657 | |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5658 | ata_host_detach(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | /* move to PCI subsystem */ |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 5662 | 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] | 5663 | { |
| 5664 | unsigned long tmp = 0; |
| 5665 | |
| 5666 | switch (bits->width) { |
| 5667 | case 1: { |
| 5668 | u8 tmp8 = 0; |
| 5669 | pci_read_config_byte(pdev, bits->reg, &tmp8); |
| 5670 | tmp = tmp8; |
| 5671 | break; |
| 5672 | } |
| 5673 | case 2: { |
| 5674 | u16 tmp16 = 0; |
| 5675 | pci_read_config_word(pdev, bits->reg, &tmp16); |
| 5676 | tmp = tmp16; |
| 5677 | break; |
| 5678 | } |
| 5679 | case 4: { |
| 5680 | u32 tmp32 = 0; |
| 5681 | pci_read_config_dword(pdev, bits->reg, &tmp32); |
| 5682 | tmp = tmp32; |
| 5683 | break; |
| 5684 | } |
| 5685 | |
| 5686 | default: |
| 5687 | return -EINVAL; |
| 5688 | } |
| 5689 | |
| 5690 | tmp &= bits->mask; |
| 5691 | |
| 5692 | return (tmp == bits->val) ? 1 : 0; |
| 5693 | } |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5694 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 5695 | #ifdef CONFIG_PM |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 5696 | 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] | 5697 | { |
| 5698 | pci_save_state(pdev); |
Tejun Heo | 4c90d97 | 2007-02-20 18:14:48 +0900 | [diff] [blame] | 5699 | pci_disable_device(pdev); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5700 | |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 5701 | if (mesg.event & PM_EVENT_SLEEP) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5702 | pci_set_power_state(pdev, PCI_D3hot); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5703 | } |
| 5704 | |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5705 | int ata_pci_device_do_resume(struct pci_dev *pdev) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5706 | { |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5707 | int rc; |
| 5708 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5709 | pci_set_power_state(pdev, PCI_D0); |
| 5710 | pci_restore_state(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5711 | |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5712 | rc = pcim_enable_device(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5713 | if (rc) { |
| 5714 | dev_printk(KERN_ERR, &pdev->dev, |
| 5715 | "failed to enable device after resume (%d)\n", rc); |
| 5716 | return rc; |
| 5717 | } |
| 5718 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5719 | pci_set_master(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5720 | return 0; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5721 | } |
| 5722 | |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 5723 | 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] | 5724 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5725 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5726 | int rc = 0; |
| 5727 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5728 | rc = ata_host_suspend(host, mesg); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5729 | if (rc) |
| 5730 | return rc; |
| 5731 | |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 5732 | ata_pci_device_do_suspend(pdev, mesg); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5733 | |
| 5734 | return 0; |
| 5735 | } |
| 5736 | |
| 5737 | int ata_pci_device_resume(struct pci_dev *pdev) |
| 5738 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5739 | struct ata_host *host = dev_get_drvdata(&pdev->dev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5740 | int rc; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5741 | |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 5742 | rc = ata_pci_device_do_resume(pdev); |
| 5743 | if (rc == 0) |
| 5744 | ata_host_resume(host); |
| 5745 | return rc; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5746 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 5747 | #endif /* CONFIG_PM */ |
| 5748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5749 | #endif /* CONFIG_PCI */ |
| 5750 | |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5751 | static int __init ata_parse_force_one(char **cur, |
| 5752 | struct ata_force_ent *force_ent, |
| 5753 | const char **reason) |
| 5754 | { |
| 5755 | /* FIXME: Currently, there's no way to tag init const data and |
| 5756 | * using __initdata causes build failure on some versions of |
| 5757 | * gcc. Once __initdataconst is implemented, add const to the |
| 5758 | * following structure. |
| 5759 | */ |
| 5760 | static struct ata_force_param force_tbl[] __initdata = { |
| 5761 | { "40c", .cbl = ATA_CBL_PATA40 }, |
| 5762 | { "80c", .cbl = ATA_CBL_PATA80 }, |
| 5763 | { "short40c", .cbl = ATA_CBL_PATA40_SHORT }, |
| 5764 | { "unk", .cbl = ATA_CBL_PATA_UNK }, |
| 5765 | { "ign", .cbl = ATA_CBL_PATA_IGN }, |
| 5766 | { "sata", .cbl = ATA_CBL_SATA }, |
| 5767 | { "1.5Gbps", .spd_limit = 1 }, |
| 5768 | { "3.0Gbps", .spd_limit = 2 }, |
| 5769 | { "noncq", .horkage_on = ATA_HORKAGE_NONCQ }, |
| 5770 | { "ncq", .horkage_off = ATA_HORKAGE_NONCQ }, |
| 5771 | { "pio0", .xfer_mask = 1 << (ATA_SHIFT_PIO + 0) }, |
| 5772 | { "pio1", .xfer_mask = 1 << (ATA_SHIFT_PIO + 1) }, |
| 5773 | { "pio2", .xfer_mask = 1 << (ATA_SHIFT_PIO + 2) }, |
| 5774 | { "pio3", .xfer_mask = 1 << (ATA_SHIFT_PIO + 3) }, |
| 5775 | { "pio4", .xfer_mask = 1 << (ATA_SHIFT_PIO + 4) }, |
| 5776 | { "pio5", .xfer_mask = 1 << (ATA_SHIFT_PIO + 5) }, |
| 5777 | { "pio6", .xfer_mask = 1 << (ATA_SHIFT_PIO + 6) }, |
| 5778 | { "mwdma0", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 0) }, |
| 5779 | { "mwdma1", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 1) }, |
| 5780 | { "mwdma2", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 2) }, |
| 5781 | { "mwdma3", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 3) }, |
| 5782 | { "mwdma4", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 4) }, |
| 5783 | { "udma0", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 0) }, |
| 5784 | { "udma16", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 0) }, |
| 5785 | { "udma/16", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 0) }, |
| 5786 | { "udma1", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 1) }, |
| 5787 | { "udma25", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 1) }, |
| 5788 | { "udma/25", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 1) }, |
| 5789 | { "udma2", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 2) }, |
| 5790 | { "udma33", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 2) }, |
| 5791 | { "udma/33", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 2) }, |
| 5792 | { "udma3", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 3) }, |
| 5793 | { "udma44", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 3) }, |
| 5794 | { "udma/44", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 3) }, |
| 5795 | { "udma4", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 4) }, |
| 5796 | { "udma66", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 4) }, |
| 5797 | { "udma/66", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 4) }, |
| 5798 | { "udma5", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 5) }, |
| 5799 | { "udma100", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 5) }, |
| 5800 | { "udma/100", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 5) }, |
| 5801 | { "udma6", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, |
| 5802 | { "udma133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, |
| 5803 | { "udma/133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, |
| 5804 | { "udma7", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 7) }, |
| 5805 | }; |
| 5806 | char *start = *cur, *p = *cur; |
| 5807 | char *id, *val, *endp; |
| 5808 | const struct ata_force_param *match_fp = NULL; |
| 5809 | int nr_matches = 0, i; |
| 5810 | |
| 5811 | /* find where this param ends and update *cur */ |
| 5812 | while (*p != '\0' && *p != ',') |
| 5813 | p++; |
| 5814 | |
| 5815 | if (*p == '\0') |
| 5816 | *cur = p; |
| 5817 | else |
| 5818 | *cur = p + 1; |
| 5819 | |
| 5820 | *p = '\0'; |
| 5821 | |
| 5822 | /* parse */ |
| 5823 | p = strchr(start, ':'); |
| 5824 | if (!p) { |
| 5825 | val = strstrip(start); |
| 5826 | goto parse_val; |
| 5827 | } |
| 5828 | *p = '\0'; |
| 5829 | |
| 5830 | id = strstrip(start); |
| 5831 | val = strstrip(p + 1); |
| 5832 | |
| 5833 | /* parse id */ |
| 5834 | p = strchr(id, '.'); |
| 5835 | if (p) { |
| 5836 | *p++ = '\0'; |
| 5837 | force_ent->device = simple_strtoul(p, &endp, 10); |
| 5838 | if (p == endp || *endp != '\0') { |
| 5839 | *reason = "invalid device"; |
| 5840 | return -EINVAL; |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | force_ent->port = simple_strtoul(id, &endp, 10); |
| 5845 | if (p == endp || *endp != '\0') { |
| 5846 | *reason = "invalid port/link"; |
| 5847 | return -EINVAL; |
| 5848 | } |
| 5849 | |
| 5850 | parse_val: |
| 5851 | /* parse val, allow shortcuts so that both 1.5 and 1.5Gbps work */ |
| 5852 | for (i = 0; i < ARRAY_SIZE(force_tbl); i++) { |
| 5853 | const struct ata_force_param *fp = &force_tbl[i]; |
| 5854 | |
| 5855 | if (strncasecmp(val, fp->name, strlen(val))) |
| 5856 | continue; |
| 5857 | |
| 5858 | nr_matches++; |
| 5859 | match_fp = fp; |
| 5860 | |
| 5861 | if (strcasecmp(val, fp->name) == 0) { |
| 5862 | nr_matches = 1; |
| 5863 | break; |
| 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | if (!nr_matches) { |
| 5868 | *reason = "unknown value"; |
| 5869 | return -EINVAL; |
| 5870 | } |
| 5871 | if (nr_matches > 1) { |
| 5872 | *reason = "ambigious value"; |
| 5873 | return -EINVAL; |
| 5874 | } |
| 5875 | |
| 5876 | force_ent->param = *match_fp; |
| 5877 | |
| 5878 | return 0; |
| 5879 | } |
| 5880 | |
| 5881 | static void __init ata_parse_force_param(void) |
| 5882 | { |
| 5883 | int idx = 0, size = 1; |
| 5884 | int last_port = -1, last_device = -1; |
| 5885 | char *p, *cur, *next; |
| 5886 | |
| 5887 | /* calculate maximum number of params and allocate force_tbl */ |
| 5888 | for (p = ata_force_param_buf; *p; p++) |
| 5889 | if (*p == ',') |
| 5890 | size++; |
| 5891 | |
| 5892 | ata_force_tbl = kzalloc(sizeof(ata_force_tbl[0]) * size, GFP_KERNEL); |
| 5893 | if (!ata_force_tbl) { |
| 5894 | printk(KERN_WARNING "ata: failed to extend force table, " |
| 5895 | "libata.force ignored\n"); |
| 5896 | return; |
| 5897 | } |
| 5898 | |
| 5899 | /* parse and populate the table */ |
| 5900 | for (cur = ata_force_param_buf; *cur != '\0'; cur = next) { |
| 5901 | const char *reason = ""; |
| 5902 | struct ata_force_ent te = { .port = -1, .device = -1 }; |
| 5903 | |
| 5904 | next = cur; |
| 5905 | if (ata_parse_force_one(&next, &te, &reason)) { |
| 5906 | printk(KERN_WARNING "ata: failed to parse force " |
| 5907 | "parameter \"%s\" (%s)\n", |
| 5908 | cur, reason); |
| 5909 | continue; |
| 5910 | } |
| 5911 | |
| 5912 | if (te.port == -1) { |
| 5913 | te.port = last_port; |
| 5914 | te.device = last_device; |
| 5915 | } |
| 5916 | |
| 5917 | ata_force_tbl[idx++] = te; |
| 5918 | |
| 5919 | last_port = te.port; |
| 5920 | last_device = te.device; |
| 5921 | } |
| 5922 | |
| 5923 | ata_force_tbl_size = idx; |
| 5924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | static int __init ata_init(void) |
| 5927 | { |
Andrew Morton | a8601e5 | 2006-06-25 01:36:52 -0700 | [diff] [blame] | 5928 | ata_probe_timeout *= HZ; |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5929 | |
| 5930 | ata_parse_force_param(); |
| 5931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | ata_wq = create_workqueue("ata"); |
| 5933 | if (!ata_wq) |
| 5934 | return -ENOMEM; |
| 5935 | |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 5936 | ata_aux_wq = create_singlethread_workqueue("ata_aux"); |
| 5937 | if (!ata_aux_wq) { |
| 5938 | destroy_workqueue(ata_wq); |
| 5939 | return -ENOMEM; |
| 5940 | } |
| 5941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5942 | printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); |
| 5943 | return 0; |
| 5944 | } |
| 5945 | |
| 5946 | static void __exit ata_exit(void) |
| 5947 | { |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5948 | kfree(ata_force_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5949 | destroy_workqueue(ata_wq); |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 5950 | destroy_workqueue(ata_aux_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5951 | } |
| 5952 | |
Brian King | a462508 | 2006-11-13 16:32:36 -0600 | [diff] [blame] | 5953 | subsys_initcall(ata_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5954 | module_exit(ata_exit); |
| 5955 | |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 5956 | static unsigned long ratelimit_time; |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 5957 | static DEFINE_SPINLOCK(ata_ratelimit_lock); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 5958 | |
| 5959 | int ata_ratelimit(void) |
| 5960 | { |
| 5961 | int rc; |
| 5962 | unsigned long flags; |
| 5963 | |
| 5964 | spin_lock_irqsave(&ata_ratelimit_lock, flags); |
| 5965 | |
| 5966 | if (time_after(jiffies, ratelimit_time)) { |
| 5967 | rc = 1; |
| 5968 | ratelimit_time = jiffies + (HZ/5); |
| 5969 | } else |
| 5970 | rc = 0; |
| 5971 | |
| 5972 | spin_unlock_irqrestore(&ata_ratelimit_lock, flags); |
| 5973 | |
| 5974 | return rc; |
| 5975 | } |
| 5976 | |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 5977 | /** |
| 5978 | * ata_wait_register - wait until register value changes |
| 5979 | * @reg: IO-mapped register |
| 5980 | * @mask: Mask to apply to read register value |
| 5981 | * @val: Wait condition |
| 5982 | * @interval_msec: polling interval in milliseconds |
| 5983 | * @timeout_msec: timeout in milliseconds |
| 5984 | * |
| 5985 | * Waiting for some bits of register to change is a common |
| 5986 | * operation for ATA controllers. This function reads 32bit LE |
| 5987 | * IO-mapped register @reg and tests for the following condition. |
| 5988 | * |
| 5989 | * (*@reg & mask) != val |
| 5990 | * |
| 5991 | * If the condition is met, it returns; otherwise, the process is |
| 5992 | * repeated after @interval_msec until timeout. |
| 5993 | * |
| 5994 | * LOCKING: |
| 5995 | * Kernel thread context (may sleep) |
| 5996 | * |
| 5997 | * RETURNS: |
| 5998 | * The final register value. |
| 5999 | */ |
| 6000 | u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, |
| 6001 | unsigned long interval_msec, |
| 6002 | unsigned long timeout_msec) |
| 6003 | { |
| 6004 | unsigned long timeout; |
| 6005 | u32 tmp; |
| 6006 | |
| 6007 | tmp = ioread32(reg); |
| 6008 | |
| 6009 | /* Calculate timeout _after_ the first read to make sure |
| 6010 | * preceding writes reach the controller before starting to |
| 6011 | * eat away the timeout. |
| 6012 | */ |
| 6013 | timeout = jiffies + (timeout_msec * HZ) / 1000; |
| 6014 | |
| 6015 | while ((tmp & mask) == val && time_before(jiffies, timeout)) { |
| 6016 | msleep(interval_msec); |
| 6017 | tmp = ioread32(reg); |
| 6018 | } |
| 6019 | |
| 6020 | return tmp; |
| 6021 | } |
| 6022 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | /* |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6024 | * Dummy port_ops |
| 6025 | */ |
| 6026 | static void ata_dummy_noret(struct ata_port *ap) { } |
| 6027 | static int ata_dummy_ret0(struct ata_port *ap) { return 0; } |
| 6028 | static void ata_dummy_qc_noret(struct ata_queued_cmd *qc) { } |
| 6029 | |
| 6030 | static u8 ata_dummy_check_status(struct ata_port *ap) |
| 6031 | { |
| 6032 | return ATA_DRDY; |
| 6033 | } |
| 6034 | |
| 6035 | static unsigned int ata_dummy_qc_issue(struct ata_queued_cmd *qc) |
| 6036 | { |
| 6037 | return AC_ERR_SYSTEM; |
| 6038 | } |
| 6039 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6040 | struct ata_port_operations ata_dummy_port_ops = { |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6041 | .check_status = ata_dummy_check_status, |
| 6042 | .check_altstatus = ata_dummy_check_status, |
| 6043 | .dev_select = ata_noop_dev_select, |
| 6044 | .qc_prep = ata_noop_qc_prep, |
| 6045 | .qc_issue = ata_dummy_qc_issue, |
| 6046 | .freeze = ata_dummy_noret, |
| 6047 | .thaw = ata_dummy_noret, |
| 6048 | .error_handler = ata_dummy_noret, |
| 6049 | .post_internal_cmd = ata_dummy_qc_noret, |
| 6050 | .irq_clear = ata_dummy_noret, |
| 6051 | .port_start = ata_dummy_ret0, |
| 6052 | .port_stop = ata_dummy_noret, |
| 6053 | }; |
| 6054 | |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6055 | const struct ata_port_info ata_dummy_port_info = { |
| 6056 | .port_ops = &ata_dummy_port_ops, |
| 6057 | }; |
| 6058 | |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6059 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6060 | * libata is essentially a library of internal helper functions for |
| 6061 | * low-level ATA host controller drivers. As such, the API/ABI is |
| 6062 | * likely to change as new drivers are added and updated. |
| 6063 | * Do not depend on ABI/API stability. |
| 6064 | */ |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 6065 | EXPORT_SYMBOL_GPL(sata_deb_timing_normal); |
| 6066 | EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug); |
| 6067 | EXPORT_SYMBOL_GPL(sata_deb_timing_long); |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6068 | EXPORT_SYMBOL_GPL(ata_base_port_ops); |
| 6069 | EXPORT_SYMBOL_GPL(sata_port_ops); |
| 6070 | EXPORT_SYMBOL_GPL(sata_pmp_port_ops); |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6071 | EXPORT_SYMBOL_GPL(ata_dummy_port_ops); |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6072 | EXPORT_SYMBOL_GPL(ata_dummy_port_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6073 | EXPORT_SYMBOL_GPL(ata_std_bios_param); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6074 | EXPORT_SYMBOL_GPL(ata_host_init); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6075 | EXPORT_SYMBOL_GPL(ata_host_alloc); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6076 | EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6077 | EXPORT_SYMBOL_GPL(ata_host_start); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6078 | EXPORT_SYMBOL_GPL(ata_host_register); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6079 | EXPORT_SYMBOL_GPL(ata_host_activate); |
Tejun Heo | 0529c15 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 6080 | EXPORT_SYMBOL_GPL(ata_host_detach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6081 | EXPORT_SYMBOL_GPL(ata_sg_init); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 6082 | EXPORT_SYMBOL_GPL(ata_qc_complete); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 6083 | EXPORT_SYMBOL_GPL(ata_qc_complete_multiple); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6084 | EXPORT_SYMBOL_GPL(ata_noop_dev_select); |
Jeff Garzik | 43727fb | 2007-02-25 16:50:52 -0500 | [diff] [blame] | 6085 | EXPORT_SYMBOL_GPL(sata_print_link_status); |
Tejun Heo | 436d34b | 2008-04-02 17:28:46 +0900 | [diff] [blame] | 6086 | EXPORT_SYMBOL_GPL(atapi_cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | EXPORT_SYMBOL_GPL(ata_tf_to_fis); |
| 6088 | EXPORT_SYMBOL_GPL(ata_tf_from_fis); |
Tejun Heo | 6357357 | 2007-11-27 19:43:39 +0900 | [diff] [blame] | 6089 | EXPORT_SYMBOL_GPL(ata_pack_xfermask); |
| 6090 | EXPORT_SYMBOL_GPL(ata_unpack_xfermask); |
| 6091 | EXPORT_SYMBOL_GPL(ata_xfer_mask2mode); |
| 6092 | EXPORT_SYMBOL_GPL(ata_xfer_mode2mask); |
| 6093 | EXPORT_SYMBOL_GPL(ata_xfer_mode2shift); |
| 6094 | EXPORT_SYMBOL_GPL(ata_mode_string); |
| 6095 | EXPORT_SYMBOL_GPL(ata_id_xfermask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6096 | EXPORT_SYMBOL_GPL(ata_port_start); |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 6097 | EXPORT_SYMBOL_GPL(ata_do_set_mode); |
Tejun Heo | 31cc23b | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 6098 | EXPORT_SYMBOL_GPL(ata_std_qc_defer); |
Brian King | e46834c | 2006-03-17 17:04:03 -0600 | [diff] [blame] | 6099 | EXPORT_SYMBOL_GPL(ata_noop_qc_prep); |
Tejun Heo | 358f9a7 | 2008-03-25 12:22:47 +0900 | [diff] [blame] | 6100 | EXPORT_SYMBOL_GPL(ata_noop_irq_clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | EXPORT_SYMBOL_GPL(ata_port_probe); |
Alan | 10305f0 | 2007-02-20 18:01:59 +0000 | [diff] [blame] | 6102 | EXPORT_SYMBOL_GPL(ata_dev_disable); |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 6103 | EXPORT_SYMBOL_GPL(sata_set_spd); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6104 | EXPORT_SYMBOL_GPL(sata_link_debounce); |
| 6105 | EXPORT_SYMBOL_GPL(sata_link_resume); |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6106 | EXPORT_SYMBOL_GPL(sata_link_hardreset); |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 6107 | EXPORT_SYMBOL_GPL(ata_dev_classify); |
| 6108 | EXPORT_SYMBOL_GPL(ata_dev_pair); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | EXPORT_SYMBOL_GPL(ata_port_disable); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 6110 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6111 | EXPORT_SYMBOL_GPL(ata_wait_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6112 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |
| 6113 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6114 | EXPORT_SYMBOL_GPL(ata_scsi_slave_config); |
Tejun Heo | 83c47bc | 2006-05-31 18:28:07 +0900 | [diff] [blame] | 6115 | EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 6116 | EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 6117 | EXPORT_SYMBOL_GPL(sata_scr_valid); |
| 6118 | EXPORT_SYMBOL_GPL(sata_scr_read); |
| 6119 | EXPORT_SYMBOL_GPL(sata_scr_write); |
| 6120 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6121 | EXPORT_SYMBOL_GPL(ata_link_online); |
| 6122 | EXPORT_SYMBOL_GPL(ata_link_offline); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6123 | #ifdef CONFIG_PM |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6124 | EXPORT_SYMBOL_GPL(ata_host_suspend); |
| 6125 | EXPORT_SYMBOL_GPL(ata_host_resume); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6126 | #endif /* CONFIG_PM */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 6127 | EXPORT_SYMBOL_GPL(ata_id_string); |
| 6128 | EXPORT_SYMBOL_GPL(ata_id_c_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6129 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
| 6130 | |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 6131 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); |
Tejun Heo | 6357357 | 2007-11-27 19:43:39 +0900 | [diff] [blame] | 6132 | EXPORT_SYMBOL_GPL(ata_timing_find_mode); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 6133 | EXPORT_SYMBOL_GPL(ata_timing_compute); |
| 6134 | EXPORT_SYMBOL_GPL(ata_timing_merge); |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 6135 | EXPORT_SYMBOL_GPL(ata_timing_cycle2mode); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 6136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6137 | #ifdef CONFIG_PCI |
| 6138 | EXPORT_SYMBOL_GPL(pci_test_config_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6139 | EXPORT_SYMBOL_GPL(ata_pci_remove_one); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6140 | #ifdef CONFIG_PM |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6141 | EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend); |
| 6142 | EXPORT_SYMBOL_GPL(ata_pci_device_do_resume); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6143 | EXPORT_SYMBOL_GPL(ata_pci_device_suspend); |
| 6144 | EXPORT_SYMBOL_GPL(ata_pci_device_resume); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6145 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6146 | #endif /* CONFIG_PCI */ |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6147 | |
Tejun Heo | 31f8838 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 6148 | EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch); |
Tejun Heo | 3af9a77 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 6149 | EXPORT_SYMBOL_GPL(sata_pmp_std_prereset); |
| 6150 | EXPORT_SYMBOL_GPL(sata_pmp_std_hardreset); |
| 6151 | EXPORT_SYMBOL_GPL(sata_pmp_std_postreset); |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 6152 | EXPORT_SYMBOL_GPL(sata_pmp_error_handler); |
Tejun Heo | 3af9a77 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 6153 | |
Tejun Heo | b64bbc3 | 2007-07-16 14:29:39 +0900 | [diff] [blame] | 6154 | EXPORT_SYMBOL_GPL(__ata_ehi_push_desc); |
| 6155 | EXPORT_SYMBOL_GPL(ata_ehi_push_desc); |
| 6156 | EXPORT_SYMBOL_GPL(ata_ehi_clear_desc); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6157 | EXPORT_SYMBOL_GPL(ata_port_desc); |
| 6158 | #ifdef CONFIG_PCI |
| 6159 | EXPORT_SYMBOL_GPL(ata_port_pbar_desc); |
| 6160 | #endif /* CONFIG_PCI */ |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 6161 | EXPORT_SYMBOL_GPL(ata_port_schedule_eh); |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6162 | EXPORT_SYMBOL_GPL(ata_link_abort); |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 6163 | EXPORT_SYMBOL_GPL(ata_port_abort); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 6164 | EXPORT_SYMBOL_GPL(ata_port_freeze); |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 6165 | EXPORT_SYMBOL_GPL(sata_async_notification); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 6166 | EXPORT_SYMBOL_GPL(ata_eh_freeze_port); |
| 6167 | EXPORT_SYMBOL_GPL(ata_eh_thaw_port); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 6168 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); |
| 6169 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 6170 | EXPORT_SYMBOL_GPL(ata_do_eh); |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 6171 | EXPORT_SYMBOL_GPL(ata_std_error_handler); |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 6172 | |
| 6173 | EXPORT_SYMBOL_GPL(ata_cable_40wire); |
| 6174 | EXPORT_SYMBOL_GPL(ata_cable_80wire); |
| 6175 | EXPORT_SYMBOL_GPL(ata_cable_unknown); |
Tejun Heo | c88f90c | 2007-11-27 19:43:48 +0900 | [diff] [blame] | 6176 | EXPORT_SYMBOL_GPL(ata_cable_ignore); |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 6177 | EXPORT_SYMBOL_GPL(ata_cable_sata); |