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 | * |
Tejun Heo | 8c3d3d4 | 2013-05-14 11:09:50 -0700 | [diff] [blame] | 4 | * Maintained by: Tejun Heo <tj@kernel.org> |
Jeff Garzik | af36d7f | 2005-08-28 20:18:39 -0400 | [diff] [blame] | 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> |
Anil Veliyankara Madam | 848c392 | 2016-01-07 21:18:52 -0800 | [diff] [blame] | 53 | #include <linux/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <linux/interrupt.h> |
| 55 | #include <linux/completion.h> |
| 56 | #include <linux/suspend.h> |
| 57 | #include <linux/workqueue.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> |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 60 | #include <linux/async.h> |
Mark Lord | e18086d | 2009-03-19 13:32:21 -0400 | [diff] [blame] | 61 | #include <linux/log2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 62 | #include <linux/slab.h> |
George Spelvin | 428ac5f | 2014-08-06 16:09:27 -0700 | [diff] [blame] | 63 | #include <linux/glob.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <scsi/scsi.h> |
Jeff Garzik | 193515d | 2005-11-07 00:59:37 -0500 | [diff] [blame] | 65 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include <scsi/scsi_host.h> |
| 67 | #include <linux/libata.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <asm/byteorder.h> |
Hannes Reinecke | fe5af0c | 2016-04-25 12:45:48 +0200 | [diff] [blame] | 69 | #include <asm/unaligned.h> |
Tejun Heo | 140b5e59 | 2007-12-12 12:21:52 +0900 | [diff] [blame] | 70 | #include <linux/cdrom.h> |
Akinobu Mita | 9990b6f | 2010-04-12 21:11:41 +0900 | [diff] [blame] | 71 | #include <linux/ratelimit.h> |
Lin Ming | 9ee4f39 | 2011-12-05 09:20:28 +0800 | [diff] [blame] | 72 | #include <linux/pm_runtime.h> |
Brian Norris | b7db04d | 2012-11-02 12:29:32 -0700 | [diff] [blame] | 73 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Hannes Reinecke | 255c03d | 2015-03-27 16:46:38 +0100 | [diff] [blame] | 75 | #define CREATE_TRACE_POINTS |
| 76 | #include <trace/events/libata.h> |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include "libata.h" |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 79 | #include "libata-transport.h" |
Jeff Garzik | fda0efc | 2007-01-31 07:43:15 -0500 | [diff] [blame] | 80 | |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 81 | /* debounce timing parameters in msecs { interval, duration, timeout } */ |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 82 | const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; |
| 83 | const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 }; |
| 84 | const unsigned long sata_deb_timing_long[] = { 100, 2000, 5000 }; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 85 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 86 | const struct ata_port_operations ata_base_port_ops = { |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 87 | .prereset = ata_std_prereset, |
Tejun Heo | 203c75b | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 88 | .postreset = ata_std_postreset, |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 89 | .error_handler = ata_std_error_handler, |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 90 | .sched_eh = ata_std_sched_eh, |
| 91 | .end_eh = ata_std_end_eh, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | const struct ata_port_operations sata_port_ops = { |
| 95 | .inherits = &ata_base_port_ops, |
| 96 | |
| 97 | .qc_defer = ata_std_qc_defer, |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 98 | .hardreset = sata_std_hardreset, |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 99 | }; |
| 100 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 101 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
| 102 | u16 heads, u16 sectors); |
| 103 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev); |
| 104 | static void ata_dev_xfermask(struct ata_device *dev); |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 105 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Tero Roponen | a78f57a | 2012-04-22 11:38:00 +0300 | [diff] [blame] | 107 | atomic_t ata_print_id = ATOMIC_INIT(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 109 | struct ata_force_param { |
| 110 | const char *name; |
| 111 | unsigned int cbl; |
| 112 | int spd_limit; |
| 113 | unsigned long xfer_mask; |
| 114 | unsigned int horkage_on; |
| 115 | unsigned int horkage_off; |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 116 | unsigned int lflags; |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | struct ata_force_ent { |
| 120 | int port; |
| 121 | int device; |
| 122 | struct ata_force_param param; |
| 123 | }; |
| 124 | |
| 125 | static struct ata_force_ent *ata_force_tbl; |
| 126 | static int ata_force_tbl_size; |
| 127 | |
| 128 | static char ata_force_param_buf[PAGE_SIZE] __initdata; |
Tejun Heo | 7afb422 | 2008-03-09 20:21:53 +0900 | [diff] [blame] | 129 | /* param_buf is thrown away after initialization, disallow read */ |
| 130 | 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] | 131 | MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/kernel-parameters.txt for details)"); |
| 132 | |
Tejun Heo | 2486fa5 | 2008-07-31 07:52:40 +0900 | [diff] [blame] | 133 | static int atapi_enabled = 1; |
Jeff Garzik | 1623c81 | 2005-08-30 03:37:42 -0400 | [diff] [blame] | 134 | module_param(atapi_enabled, int, 0444); |
Evgeni Golov | ad5d8ea | 2009-06-22 09:46:20 +0200 | [diff] [blame] | 135 | MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on [default])"); |
Jeff Garzik | 1623c81 | 2005-08-30 03:37:42 -0400 | [diff] [blame] | 136 | |
Adrian Bunk | c5c61bd | 2008-02-25 02:07:25 +0200 | [diff] [blame] | 137 | static int atapi_dmadir = 0; |
Albert Lee | 95de719 | 2006-04-04 10:57:18 +0800 | [diff] [blame] | 138 | module_param(atapi_dmadir, int, 0444); |
Evgeni Golov | ad5d8ea | 2009-06-22 09:46:20 +0200 | [diff] [blame] | 139 | MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off [default], 1=on)"); |
Albert Lee | 95de719 | 2006-04-04 10:57:18 +0800 | [diff] [blame] | 140 | |
Mark Lord | baf4fdf | 2007-08-08 01:08:45 +0900 | [diff] [blame] | 141 | int atapi_passthru16 = 1; |
| 142 | module_param(atapi_passthru16, int, 0444); |
Evgeni Golov | ad5d8ea | 2009-06-22 09:46:20 +0200 | [diff] [blame] | 143 | MODULE_PARM_DESC(atapi_passthru16, "Enable ATA_16 passthru for ATAPI devices (0=off, 1=on [default])"); |
Mark Lord | baf4fdf | 2007-08-08 01:08:45 +0900 | [diff] [blame] | 144 | |
Jeff Garzik | c3c013a | 2006-02-27 22:31:19 -0500 | [diff] [blame] | 145 | int libata_fua = 0; |
| 146 | module_param_named(fua, libata_fua, int, 0444); |
Evgeni Golov | ad5d8ea | 2009-06-22 09:46:20 +0200 | [diff] [blame] | 147 | MODULE_PARM_DESC(fua, "FUA support (0=off [default], 1=on)"); |
Jeff Garzik | c3c013a | 2006-02-27 22:31:19 -0500 | [diff] [blame] | 148 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 149 | static int ata_ignore_hpa; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 150 | module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644); |
| 151 | MODULE_PARM_DESC(ignore_hpa, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)"); |
| 152 | |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 153 | static int libata_dma_mask = ATA_DMA_MASK_ATA|ATA_DMA_MASK_ATAPI|ATA_DMA_MASK_CFA; |
| 154 | module_param_named(dma, libata_dma_mask, int, 0444); |
| 155 | MODULE_PARM_DESC(dma, "DMA enable/disable (0x1==ATA, 0x2==ATAPI, 0x4==CF)"); |
| 156 | |
Tejun Heo | 87fbc5a | 2008-05-20 02:17:54 +0900 | [diff] [blame] | 157 | static int ata_probe_timeout; |
Andrew Morton | a8601e5 | 2006-06-25 01:36:52 -0700 | [diff] [blame] | 158 | module_param(ata_probe_timeout, int, 0444); |
| 159 | MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)"); |
| 160 | |
Jeff Garzik | 6ebe9d8 | 2007-10-05 16:28:36 -0400 | [diff] [blame] | 161 | int libata_noacpi = 0; |
Jeff Garzik | d7d0dad | 2007-03-28 01:57:37 -0400 | [diff] [blame] | 162 | module_param_named(noacpi, libata_noacpi, int, 0444); |
Evgeni Golov | ad5d8ea | 2009-06-22 09:46:20 +0200 | [diff] [blame] | 163 | MODULE_PARM_DESC(noacpi, "Disable the use of ACPI in probe/suspend/resume (0=off [default], 1=on)"); |
Kristen Carlson Accardi | 11ef697 | 2006-09-28 11:29:01 -0700 | [diff] [blame] | 164 | |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 165 | int libata_allow_tpm = 0; |
| 166 | module_param_named(allow_tpm, libata_allow_tpm, int, 0444); |
Evgeni Golov | ad5d8ea | 2009-06-22 09:46:20 +0200 | [diff] [blame] | 167 | MODULE_PARM_DESC(allow_tpm, "Permit the use of TPM commands (0=off [default], 1=on)"); |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 168 | |
Tejun Heo | e7ecd43 | 2010-05-19 15:38:58 +0200 | [diff] [blame] | 169 | static int atapi_an; |
| 170 | module_param(atapi_an, int, 0444); |
| 171 | MODULE_PARM_DESC(atapi_an, "Enable ATAPI AN media presence notification (0=0ff [default], 1=on)"); |
| 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | MODULE_AUTHOR("Jeff Garzik"); |
| 174 | MODULE_DESCRIPTION("Library module for ATA devices"); |
| 175 | MODULE_LICENSE("GPL"); |
| 176 | MODULE_VERSION(DRV_VERSION); |
| 177 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 178 | |
Tejun Heo | 9913ff8a | 2009-01-29 20:31:31 +0900 | [diff] [blame] | 179 | static bool ata_sstatus_online(u32 sstatus) |
| 180 | { |
| 181 | return (sstatus & 0xf) == 0x3; |
| 182 | } |
| 183 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 184 | /** |
| 185 | * ata_link_next - link iteration helper |
| 186 | * @link: the previous link, NULL to start |
| 187 | * @ap: ATA port containing links to iterate |
| 188 | * @mode: iteration mode, one of ATA_LITER_* |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 189 | * |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 190 | * LOCKING: |
| 191 | * Host lock or EH context. |
| 192 | * |
| 193 | * RETURNS: |
| 194 | * Pointer to the next link. |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 195 | */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 196 | struct ata_link *ata_link_next(struct ata_link *link, struct ata_port *ap, |
| 197 | enum ata_link_iter_mode mode) |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 198 | { |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 199 | BUG_ON(mode != ATA_LITER_EDGE && |
| 200 | mode != ATA_LITER_PMP_FIRST && mode != ATA_LITER_HOST_FIRST); |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 201 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 202 | /* NULL link indicates start of iteration */ |
| 203 | if (!link) |
| 204 | switch (mode) { |
| 205 | case ATA_LITER_EDGE: |
| 206 | case ATA_LITER_PMP_FIRST: |
| 207 | if (sata_pmp_attached(ap)) |
| 208 | return ap->pmp_link; |
| 209 | /* fall through */ |
| 210 | case ATA_LITER_HOST_FIRST: |
| 211 | return &ap->link; |
| 212 | } |
| 213 | |
| 214 | /* we just iterated over the host link, what's next? */ |
| 215 | if (link == &ap->link) |
| 216 | switch (mode) { |
| 217 | case ATA_LITER_HOST_FIRST: |
| 218 | if (sata_pmp_attached(ap)) |
| 219 | return ap->pmp_link; |
| 220 | /* fall through */ |
| 221 | case ATA_LITER_PMP_FIRST: |
| 222 | if (unlikely(ap->slave_link)) |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 223 | return ap->slave_link; |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 224 | /* fall through */ |
| 225 | case ATA_LITER_EDGE: |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 226 | return NULL; |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 227 | } |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 228 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 229 | /* slave_link excludes PMP */ |
| 230 | if (unlikely(link == ap->slave_link)) |
| 231 | return NULL; |
| 232 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 233 | /* we were over a PMP link */ |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 234 | if (++link < ap->pmp_link + ap->nr_pmp_links) |
| 235 | return link; |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 236 | |
| 237 | if (mode == ATA_LITER_PMP_FIRST) |
| 238 | return &ap->link; |
| 239 | |
Tejun Heo | aadffb6 | 2008-07-31 17:02:41 +0900 | [diff] [blame] | 240 | return NULL; |
| 241 | } |
| 242 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 243 | /** |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 244 | * ata_dev_next - device iteration helper |
| 245 | * @dev: the previous device, NULL to start |
| 246 | * @link: ATA link containing devices to iterate |
| 247 | * @mode: iteration mode, one of ATA_DITER_* |
| 248 | * |
| 249 | * LOCKING: |
| 250 | * Host lock or EH context. |
| 251 | * |
| 252 | * RETURNS: |
| 253 | * Pointer to the next device. |
| 254 | */ |
| 255 | struct ata_device *ata_dev_next(struct ata_device *dev, struct ata_link *link, |
| 256 | enum ata_dev_iter_mode mode) |
| 257 | { |
| 258 | BUG_ON(mode != ATA_DITER_ENABLED && mode != ATA_DITER_ENABLED_REVERSE && |
| 259 | mode != ATA_DITER_ALL && mode != ATA_DITER_ALL_REVERSE); |
| 260 | |
| 261 | /* NULL dev indicates start of iteration */ |
| 262 | if (!dev) |
| 263 | switch (mode) { |
| 264 | case ATA_DITER_ENABLED: |
| 265 | case ATA_DITER_ALL: |
| 266 | dev = link->device; |
| 267 | goto check; |
| 268 | case ATA_DITER_ENABLED_REVERSE: |
| 269 | case ATA_DITER_ALL_REVERSE: |
| 270 | dev = link->device + ata_link_max_devices(link) - 1; |
| 271 | goto check; |
| 272 | } |
| 273 | |
| 274 | next: |
| 275 | /* move to the next one */ |
| 276 | switch (mode) { |
| 277 | case ATA_DITER_ENABLED: |
| 278 | case ATA_DITER_ALL: |
| 279 | if (++dev < link->device + ata_link_max_devices(link)) |
| 280 | goto check; |
| 281 | return NULL; |
| 282 | case ATA_DITER_ENABLED_REVERSE: |
| 283 | case ATA_DITER_ALL_REVERSE: |
| 284 | if (--dev >= link->device) |
| 285 | goto check; |
| 286 | return NULL; |
| 287 | } |
| 288 | |
| 289 | check: |
| 290 | if ((mode == ATA_DITER_ENABLED || mode == ATA_DITER_ENABLED_REVERSE) && |
| 291 | !ata_dev_enabled(dev)) |
| 292 | goto next; |
| 293 | return dev; |
| 294 | } |
| 295 | |
| 296 | /** |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 297 | * ata_dev_phys_link - find physical link for a device |
| 298 | * @dev: ATA device to look up physical link for |
| 299 | * |
| 300 | * Look up physical link which @dev is attached to. Note that |
| 301 | * this is different from @dev->link only when @dev is on slave |
| 302 | * link. For all other cases, it's the same as @dev->link. |
| 303 | * |
| 304 | * LOCKING: |
| 305 | * Don't care. |
| 306 | * |
| 307 | * RETURNS: |
| 308 | * Pointer to the found physical link. |
| 309 | */ |
| 310 | struct ata_link *ata_dev_phys_link(struct ata_device *dev) |
| 311 | { |
| 312 | struct ata_port *ap = dev->link->ap; |
| 313 | |
| 314 | if (!ap->slave_link) |
| 315 | return dev->link; |
| 316 | if (!dev->devno) |
| 317 | return &ap->link; |
| 318 | return ap->slave_link; |
| 319 | } |
| 320 | |
| 321 | /** |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 322 | * ata_force_cbl - force cable type according to libata.force |
Randy Dunlap | 4cdfa1b | 2008-02-22 12:21:37 -0800 | [diff] [blame] | 323 | * @ap: ATA port of interest |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 324 | * |
| 325 | * Force cable type according to libata.force and whine about it. |
| 326 | * The last entry which has matching port number is used, so it |
| 327 | * can be specified as part of device force parameters. For |
| 328 | * example, both "a:40c,1.00:udma4" and "1.00:40c,udma4" have the |
| 329 | * same effect. |
| 330 | * |
| 331 | * LOCKING: |
| 332 | * EH context. |
| 333 | */ |
| 334 | void ata_force_cbl(struct ata_port *ap) |
| 335 | { |
| 336 | int i; |
| 337 | |
| 338 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
| 339 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 340 | |
| 341 | if (fe->port != -1 && fe->port != ap->print_id) |
| 342 | continue; |
| 343 | |
| 344 | if (fe->param.cbl == ATA_CBL_NONE) |
| 345 | continue; |
| 346 | |
| 347 | ap->cbl = fe->param.cbl; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 348 | ata_port_notice(ap, "FORCE: cable set to %s\n", fe->param.name); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 349 | return; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | /** |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 354 | * ata_force_link_limits - force link limits according to libata.force |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 355 | * @link: ATA link of interest |
| 356 | * |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 357 | * Force link flags and SATA spd limit according to libata.force |
| 358 | * and whine about it. When only the port part is specified |
| 359 | * (e.g. 1:), the limit applies to all links connected to both |
| 360 | * the host link and all fan-out ports connected via PMP. If the |
| 361 | * device part is specified as 0 (e.g. 1.00:), it specifies the |
| 362 | * first fan-out link not the host link. Device number 15 always |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 363 | * points to the host link whether PMP is attached or not. If the |
| 364 | * controller has slave link, device number 16 points to it. |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 365 | * |
| 366 | * LOCKING: |
| 367 | * EH context. |
| 368 | */ |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 369 | static void ata_force_link_limits(struct ata_link *link) |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 370 | { |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 371 | bool did_spd = false; |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 372 | int linkno = link->pmp; |
| 373 | int i; |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 374 | |
| 375 | if (ata_is_host_link(link)) |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 376 | linkno += 15; |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 377 | |
| 378 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
| 379 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 380 | |
| 381 | if (fe->port != -1 && fe->port != link->ap->print_id) |
| 382 | continue; |
| 383 | |
| 384 | if (fe->device != -1 && fe->device != linkno) |
| 385 | continue; |
| 386 | |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 387 | /* only honor the first spd limit */ |
| 388 | if (!did_spd && fe->param.spd_limit) { |
| 389 | link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 390 | ata_link_notice(link, "FORCE: PHY spd limit set to %s\n", |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 391 | fe->param.name); |
| 392 | did_spd = true; |
| 393 | } |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 394 | |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 395 | /* let lflags stack */ |
| 396 | if (fe->param.lflags) { |
| 397 | link->flags |= fe->param.lflags; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 398 | ata_link_notice(link, |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 399 | "FORCE: link flag 0x%x forced -> 0x%x\n", |
| 400 | fe->param.lflags, link->flags); |
| 401 | } |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * ata_force_xfermask - force xfermask according to libata.force |
| 407 | * @dev: ATA device of interest |
| 408 | * |
| 409 | * Force xfer_mask according to libata.force and whine about it. |
| 410 | * For consistency with link selection, device number 15 selects |
| 411 | * the first device connected to the host link. |
| 412 | * |
| 413 | * LOCKING: |
| 414 | * EH context. |
| 415 | */ |
| 416 | static void ata_force_xfermask(struct ata_device *dev) |
| 417 | { |
| 418 | int devno = dev->link->pmp + dev->devno; |
| 419 | int alt_devno = devno; |
| 420 | int i; |
| 421 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 422 | /* allow n.15/16 for devices attached to host port */ |
| 423 | if (ata_is_host_link(dev->link)) |
| 424 | alt_devno += 15; |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 425 | |
| 426 | for (i = ata_force_tbl_size - 1; i >= 0; i--) { |
| 427 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 428 | unsigned long pio_mask, mwdma_mask, udma_mask; |
| 429 | |
| 430 | if (fe->port != -1 && fe->port != dev->link->ap->print_id) |
| 431 | continue; |
| 432 | |
| 433 | if (fe->device != -1 && fe->device != devno && |
| 434 | fe->device != alt_devno) |
| 435 | continue; |
| 436 | |
| 437 | if (!fe->param.xfer_mask) |
| 438 | continue; |
| 439 | |
| 440 | ata_unpack_xfermask(fe->param.xfer_mask, |
| 441 | &pio_mask, &mwdma_mask, &udma_mask); |
| 442 | if (udma_mask) |
| 443 | dev->udma_mask = udma_mask; |
| 444 | else if (mwdma_mask) { |
| 445 | dev->udma_mask = 0; |
| 446 | dev->mwdma_mask = mwdma_mask; |
| 447 | } else { |
| 448 | dev->udma_mask = 0; |
| 449 | dev->mwdma_mask = 0; |
| 450 | dev->pio_mask = pio_mask; |
| 451 | } |
| 452 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 453 | ata_dev_notice(dev, "FORCE: xfer_mask set to %s\n", |
| 454 | fe->param.name); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * ata_force_horkage - force horkage according to libata.force |
| 461 | * @dev: ATA device of interest |
| 462 | * |
| 463 | * Force horkage according to libata.force and whine about it. |
| 464 | * For consistency with link selection, device number 15 selects |
| 465 | * the first device connected to the host link. |
| 466 | * |
| 467 | * LOCKING: |
| 468 | * EH context. |
| 469 | */ |
| 470 | static void ata_force_horkage(struct ata_device *dev) |
| 471 | { |
| 472 | int devno = dev->link->pmp + dev->devno; |
| 473 | int alt_devno = devno; |
| 474 | int i; |
| 475 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 476 | /* allow n.15/16 for devices attached to host port */ |
| 477 | if (ata_is_host_link(dev->link)) |
| 478 | alt_devno += 15; |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 479 | |
| 480 | for (i = 0; i < ata_force_tbl_size; i++) { |
| 481 | const struct ata_force_ent *fe = &ata_force_tbl[i]; |
| 482 | |
| 483 | if (fe->port != -1 && fe->port != dev->link->ap->print_id) |
| 484 | continue; |
| 485 | |
| 486 | if (fe->device != -1 && fe->device != devno && |
| 487 | fe->device != alt_devno) |
| 488 | continue; |
| 489 | |
| 490 | if (!(~dev->horkage & fe->param.horkage_on) && |
| 491 | !(dev->horkage & fe->param.horkage_off)) |
| 492 | continue; |
| 493 | |
| 494 | dev->horkage |= fe->param.horkage_on; |
| 495 | dev->horkage &= ~fe->param.horkage_off; |
| 496 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 497 | ata_dev_notice(dev, "FORCE: horkage modified (%s)\n", |
| 498 | fe->param.name); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | /** |
Tejun Heo | 436d34b | 2008-04-02 17:28:46 +0900 | [diff] [blame] | 503 | * atapi_cmd_type - Determine ATAPI command type from SCSI opcode |
| 504 | * @opcode: SCSI opcode |
| 505 | * |
| 506 | * Determine ATAPI command type from @opcode. |
| 507 | * |
| 508 | * LOCKING: |
| 509 | * None. |
| 510 | * |
| 511 | * RETURNS: |
| 512 | * ATAPI_{READ|WRITE|READ_CD|PASS_THRU|MISC} |
| 513 | */ |
| 514 | int atapi_cmd_type(u8 opcode) |
| 515 | { |
| 516 | switch (opcode) { |
| 517 | case GPCMD_READ_10: |
| 518 | case GPCMD_READ_12: |
| 519 | return ATAPI_READ; |
| 520 | |
| 521 | case GPCMD_WRITE_10: |
| 522 | case GPCMD_WRITE_12: |
| 523 | case GPCMD_WRITE_AND_VERIFY_10: |
| 524 | return ATAPI_WRITE; |
| 525 | |
| 526 | case GPCMD_READ_CD: |
| 527 | case GPCMD_READ_CD_MSF: |
| 528 | return ATAPI_READ_CD; |
| 529 | |
Tejun Heo | e52dcc4 | 2008-04-02 17:35:19 +0900 | [diff] [blame] | 530 | case ATA_16: |
| 531 | case ATA_12: |
| 532 | if (atapi_passthru16) |
| 533 | return ATAPI_PASS_THRU; |
| 534 | /* fall thru */ |
Tejun Heo | 436d34b | 2008-04-02 17:28:46 +0900 | [diff] [blame] | 535 | default: |
| 536 | return ATAPI_MISC; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure |
| 542 | * @tf: Taskfile to convert |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | * @pmp: Port multiplier port |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 544 | * @is_cmd: This FIS is for command |
| 545 | * @fis: Buffer into which data will output |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | * |
| 547 | * Converts a standard ATA taskfile to a Serial ATA |
| 548 | * FIS structure (Register - Host to Device). |
| 549 | * |
| 550 | * LOCKING: |
| 551 | * Inherited from caller. |
| 552 | */ |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 553 | 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] | 554 | { |
Tejun Heo | 9977126 | 2007-07-16 14:29:38 +0900 | [diff] [blame] | 555 | fis[0] = 0x27; /* Register - Host to Device FIS */ |
| 556 | fis[1] = pmp & 0xf; /* Port multiplier number*/ |
| 557 | if (is_cmd) |
| 558 | fis[1] |= (1 << 7); /* bit 7 indicates Command FIS */ |
| 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | fis[2] = tf->command; |
| 561 | fis[3] = tf->feature; |
| 562 | |
| 563 | fis[4] = tf->lbal; |
| 564 | fis[5] = tf->lbam; |
| 565 | fis[6] = tf->lbah; |
| 566 | fis[7] = tf->device; |
| 567 | |
| 568 | fis[8] = tf->hob_lbal; |
| 569 | fis[9] = tf->hob_lbam; |
| 570 | fis[10] = tf->hob_lbah; |
| 571 | fis[11] = tf->hob_feature; |
| 572 | |
| 573 | fis[12] = tf->nsect; |
| 574 | fis[13] = tf->hob_nsect; |
| 575 | fis[14] = 0; |
| 576 | fis[15] = tf->ctl; |
| 577 | |
Marc Carino | 86a565e | 2013-09-01 08:59:01 -0700 | [diff] [blame] | 578 | fis[16] = tf->auxiliary & 0xff; |
| 579 | fis[17] = (tf->auxiliary >> 8) & 0xff; |
| 580 | fis[18] = (tf->auxiliary >> 16) & 0xff; |
| 581 | fis[19] = (tf->auxiliary >> 24) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /** |
| 585 | * ata_tf_from_fis - Convert SATA FIS to ATA taskfile |
| 586 | * @fis: Buffer from which data will be input |
| 587 | * @tf: Taskfile to output |
| 588 | * |
Mark Lord | e12a1be | 2005-11-12 18:55:45 -0500 | [diff] [blame] | 589 | * Converts a serial ATA FIS structure to a standard ATA taskfile. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | * |
| 591 | * LOCKING: |
| 592 | * Inherited from caller. |
| 593 | */ |
| 594 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 595 | void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
| 597 | tf->command = fis[2]; /* status */ |
| 598 | tf->feature = fis[3]; /* error */ |
| 599 | |
| 600 | tf->lbal = fis[4]; |
| 601 | tf->lbam = fis[5]; |
| 602 | tf->lbah = fis[6]; |
| 603 | tf->device = fis[7]; |
| 604 | |
| 605 | tf->hob_lbal = fis[8]; |
| 606 | tf->hob_lbam = fis[9]; |
| 607 | tf->hob_lbah = fis[10]; |
| 608 | |
| 609 | tf->nsect = fis[12]; |
| 610 | tf->hob_nsect = fis[13]; |
| 611 | } |
| 612 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 613 | static const u8 ata_rw_cmds[] = { |
| 614 | /* pio multi */ |
| 615 | ATA_CMD_READ_MULTI, |
| 616 | ATA_CMD_WRITE_MULTI, |
| 617 | ATA_CMD_READ_MULTI_EXT, |
| 618 | ATA_CMD_WRITE_MULTI_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 619 | 0, |
| 620 | 0, |
| 621 | 0, |
| 622 | ATA_CMD_WRITE_MULTI_FUA_EXT, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 623 | /* pio */ |
| 624 | ATA_CMD_PIO_READ, |
| 625 | ATA_CMD_PIO_WRITE, |
| 626 | ATA_CMD_PIO_READ_EXT, |
| 627 | ATA_CMD_PIO_WRITE_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 628 | 0, |
| 629 | 0, |
| 630 | 0, |
| 631 | 0, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 632 | /* dma */ |
| 633 | ATA_CMD_READ, |
| 634 | ATA_CMD_WRITE, |
| 635 | ATA_CMD_READ_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 636 | ATA_CMD_WRITE_EXT, |
| 637 | 0, |
| 638 | 0, |
| 639 | 0, |
| 640 | ATA_CMD_WRITE_FUA_EXT |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 641 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | /** |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 644 | * ata_rwcmd_protocol - set taskfile r/w commands and protocol |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 645 | * @tf: command to examine and configure |
| 646 | * @dev: device tf belongs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | * |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 648 | * Examine the device configuration and tf->flags to calculate |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 649 | * the proper read/write commands and protocol to use. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | * |
| 651 | * LOCKING: |
| 652 | * caller. |
| 653 | */ |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 654 | 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] | 655 | { |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 656 | u8 cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 658 | int index, fua, lba48, write; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 659 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 660 | fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 661 | lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; |
| 662 | write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 664 | if (dev->flags & ATA_DFLAG_PIO) { |
| 665 | tf->protocol = ATA_PROT_PIO; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 666 | index = dev->multi_count ? 0 : 8; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 667 | } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { |
Alan Cox | 8d238e0 | 2006-01-17 20:50:31 +0000 | [diff] [blame] | 668 | /* Unable to use DMA due to host limitation */ |
| 669 | tf->protocol = ATA_PROT_PIO; |
Albert Lee | 0565c26 | 2006-02-13 18:55:25 +0800 | [diff] [blame] | 670 | index = dev->multi_count ? 0 : 8; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 671 | } else { |
| 672 | tf->protocol = ATA_PROT_DMA; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 673 | index = 16; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 676 | cmd = ata_rw_cmds[index + fua + lba48 + write]; |
| 677 | if (cmd) { |
| 678 | tf->command = cmd; |
| 679 | return 0; |
| 680 | } |
| 681 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 684 | /** |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 685 | * ata_tf_read_block - Read block address from ATA taskfile |
| 686 | * @tf: ATA taskfile of interest |
| 687 | * @dev: ATA device @tf belongs to |
| 688 | * |
| 689 | * LOCKING: |
| 690 | * None. |
| 691 | * |
| 692 | * Read block address from @tf. This function can handle all |
| 693 | * three address formats - LBA, LBA48 and CHS. tf->protocol and |
| 694 | * flags select the address format to use. |
| 695 | * |
| 696 | * RETURNS: |
| 697 | * Block address read from @tf. |
| 698 | */ |
Hannes Reinecke | cffd1ee | 2016-04-04 11:43:57 +0200 | [diff] [blame] | 699 | u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 700 | { |
| 701 | u64 block = 0; |
| 702 | |
Tejun Heo | fe16d4f | 2015-08-03 11:41:33 -0400 | [diff] [blame] | 703 | if (tf->flags & ATA_TFLAG_LBA) { |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 704 | if (tf->flags & ATA_TFLAG_LBA48) { |
| 705 | block |= (u64)tf->hob_lbah << 40; |
| 706 | block |= (u64)tf->hob_lbam << 32; |
Roland Dreier | 44901a9 | 2008-11-04 10:34:48 -0800 | [diff] [blame] | 707 | block |= (u64)tf->hob_lbal << 24; |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 708 | } else |
| 709 | block |= (tf->device & 0xf) << 24; |
| 710 | |
| 711 | block |= tf->lbah << 16; |
| 712 | block |= tf->lbam << 8; |
| 713 | block |= tf->lbal; |
| 714 | } else { |
| 715 | u32 cyl, head, sect; |
| 716 | |
| 717 | cyl = tf->lbam | (tf->lbah << 8); |
| 718 | head = tf->device & 0xf; |
| 719 | sect = tf->lbal; |
| 720 | |
Tejun Heo | ac8672e | 2009-08-16 21:21:21 +0900 | [diff] [blame] | 721 | if (!sect) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 722 | ata_dev_warn(dev, |
| 723 | "device reported invalid CHS sector 0\n"); |
Hannes Reinecke | cffd1ee | 2016-04-04 11:43:57 +0200 | [diff] [blame] | 724 | return U64_MAX; |
Tejun Heo | ac8672e | 2009-08-16 21:21:21 +0900 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | block = (cyl * dev->heads + head) * dev->sectors + sect - 1; |
Tejun Heo | 35b649f | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | return block; |
| 731 | } |
| 732 | |
| 733 | /** |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 734 | * ata_build_rw_tf - Build ATA taskfile for given read/write request |
| 735 | * @tf: Target ATA taskfile |
| 736 | * @dev: ATA device @tf belongs to |
| 737 | * @block: Block address |
| 738 | * @n_block: Number of blocks |
| 739 | * @tf_flags: RW/FUA etc... |
| 740 | * @tag: tag |
| 741 | * |
| 742 | * LOCKING: |
| 743 | * None. |
| 744 | * |
| 745 | * Build ATA taskfile @tf for read/write request described by |
| 746 | * @block, @n_block, @tf_flags and @tag on @dev. |
| 747 | * |
| 748 | * RETURNS: |
| 749 | * |
| 750 | * 0 on success, -ERANGE if the request is too large for @dev, |
| 751 | * -EINVAL if the request is invalid. |
| 752 | */ |
| 753 | int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, |
| 754 | u64 block, u32 n_block, unsigned int tf_flags, |
| 755 | unsigned int tag) |
| 756 | { |
| 757 | tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 758 | tf->flags |= tf_flags; |
| 759 | |
Tejun Heo | 6d1245b | 2007-02-20 23:20:27 +0900 | [diff] [blame] | 760 | if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) { |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 761 | /* yay, NCQ */ |
| 762 | if (!lba_48_ok(block, n_block)) |
| 763 | return -ERANGE; |
| 764 | |
| 765 | tf->protocol = ATA_PROT_NCQ; |
| 766 | tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; |
| 767 | |
| 768 | if (tf->flags & ATA_TFLAG_WRITE) |
| 769 | tf->command = ATA_CMD_FPDMA_WRITE; |
| 770 | else |
| 771 | tf->command = ATA_CMD_FPDMA_READ; |
| 772 | |
| 773 | tf->nsect = tag << 3; |
| 774 | tf->hob_feature = (n_block >> 8) & 0xff; |
| 775 | tf->feature = n_block & 0xff; |
| 776 | |
| 777 | tf->hob_lbah = (block >> 40) & 0xff; |
| 778 | tf->hob_lbam = (block >> 32) & 0xff; |
| 779 | tf->hob_lbal = (block >> 24) & 0xff; |
| 780 | tf->lbah = (block >> 16) & 0xff; |
| 781 | tf->lbam = (block >> 8) & 0xff; |
| 782 | tf->lbal = block & 0xff; |
| 783 | |
Sergei Shtylyov | 9ca7cfa | 2012-08-21 22:18:50 +0400 | [diff] [blame] | 784 | tf->device = ATA_LBA; |
Tejun Heo | bd056d7 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 785 | if (tf->flags & ATA_TFLAG_FUA) |
| 786 | tf->device |= 1 << 7; |
| 787 | } else if (dev->flags & ATA_DFLAG_LBA) { |
| 788 | tf->flags |= ATA_TFLAG_LBA; |
| 789 | |
| 790 | if (lba_28_ok(block, n_block)) { |
| 791 | /* use LBA28 */ |
| 792 | tf->device |= (block >> 24) & 0xf; |
| 793 | } else if (lba_48_ok(block, n_block)) { |
| 794 | if (!(dev->flags & ATA_DFLAG_LBA48)) |
| 795 | return -ERANGE; |
| 796 | |
| 797 | /* use LBA48 */ |
| 798 | tf->flags |= ATA_TFLAG_LBA48; |
| 799 | |
| 800 | tf->hob_nsect = (n_block >> 8) & 0xff; |
| 801 | |
| 802 | tf->hob_lbah = (block >> 40) & 0xff; |
| 803 | tf->hob_lbam = (block >> 32) & 0xff; |
| 804 | tf->hob_lbal = (block >> 24) & 0xff; |
| 805 | } else |
| 806 | /* request too large even for LBA48 */ |
| 807 | return -ERANGE; |
| 808 | |
| 809 | if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | tf->nsect = n_block & 0xff; |
| 813 | |
| 814 | tf->lbah = (block >> 16) & 0xff; |
| 815 | tf->lbam = (block >> 8) & 0xff; |
| 816 | tf->lbal = block & 0xff; |
| 817 | |
| 818 | tf->device |= ATA_LBA; |
| 819 | } else { |
| 820 | /* CHS */ |
| 821 | u32 sect, head, cyl, track; |
| 822 | |
| 823 | /* The request -may- be too large for CHS addressing. */ |
| 824 | if (!lba_28_ok(block, n_block)) |
| 825 | return -ERANGE; |
| 826 | |
| 827 | if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) |
| 828 | return -EINVAL; |
| 829 | |
| 830 | /* Convert LBA to CHS */ |
| 831 | track = (u32)block / dev->sectors; |
| 832 | cyl = track / dev->heads; |
| 833 | head = track % dev->heads; |
| 834 | sect = (u32)block % dev->sectors + 1; |
| 835 | |
| 836 | DPRINTK("block %u track %u cyl %u head %u sect %u\n", |
| 837 | (u32)block, track, cyl, head, sect); |
| 838 | |
| 839 | /* Check whether the converted CHS can fit. |
| 840 | Cylinder: 0-65535 |
| 841 | Head: 0-15 |
| 842 | Sector: 1-255*/ |
| 843 | if ((cyl >> 16) || (head >> 4) || (sect >> 8) || (!sect)) |
| 844 | return -ERANGE; |
| 845 | |
| 846 | tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ |
| 847 | tf->lbal = sect; |
| 848 | tf->lbam = cyl; |
| 849 | tf->lbah = cyl >> 8; |
| 850 | tf->device |= head; |
| 851 | } |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | /** |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 857 | * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask |
| 858 | * @pio_mask: pio_mask |
| 859 | * @mwdma_mask: mwdma_mask |
| 860 | * @udma_mask: udma_mask |
| 861 | * |
| 862 | * Pack @pio_mask, @mwdma_mask and @udma_mask into a single |
| 863 | * unsigned int xfer_mask. |
| 864 | * |
| 865 | * LOCKING: |
| 866 | * None. |
| 867 | * |
| 868 | * RETURNS: |
| 869 | * Packed xfer_mask. |
| 870 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 871 | unsigned long ata_pack_xfermask(unsigned long pio_mask, |
| 872 | unsigned long mwdma_mask, |
| 873 | unsigned long udma_mask) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 874 | { |
| 875 | return ((pio_mask << ATA_SHIFT_PIO) & ATA_MASK_PIO) | |
| 876 | ((mwdma_mask << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA) | |
| 877 | ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA); |
| 878 | } |
| 879 | |
Tejun Heo | c0489e4 | 2006-03-24 14:07:49 +0900 | [diff] [blame] | 880 | /** |
| 881 | * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks |
| 882 | * @xfer_mask: xfer_mask to unpack |
| 883 | * @pio_mask: resulting pio_mask |
| 884 | * @mwdma_mask: resulting mwdma_mask |
| 885 | * @udma_mask: resulting udma_mask |
| 886 | * |
| 887 | * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask. |
| 888 | * Any NULL distination masks will be ignored. |
| 889 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 890 | void ata_unpack_xfermask(unsigned long xfer_mask, unsigned long *pio_mask, |
| 891 | unsigned long *mwdma_mask, unsigned long *udma_mask) |
Tejun Heo | c0489e4 | 2006-03-24 14:07:49 +0900 | [diff] [blame] | 892 | { |
| 893 | if (pio_mask) |
| 894 | *pio_mask = (xfer_mask & ATA_MASK_PIO) >> ATA_SHIFT_PIO; |
| 895 | if (mwdma_mask) |
| 896 | *mwdma_mask = (xfer_mask & ATA_MASK_MWDMA) >> ATA_SHIFT_MWDMA; |
| 897 | if (udma_mask) |
| 898 | *udma_mask = (xfer_mask & ATA_MASK_UDMA) >> ATA_SHIFT_UDMA; |
| 899 | } |
| 900 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 901 | static const struct ata_xfer_ent { |
Tejun Heo | be9a50c | 2006-03-31 22:48:52 +0900 | [diff] [blame] | 902 | int shift, bits; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 903 | u8 base; |
| 904 | } ata_xfer_tbl[] = { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 905 | { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 }, |
| 906 | { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 }, |
| 907 | { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 }, |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 908 | { -1, }, |
| 909 | }; |
| 910 | |
| 911 | /** |
| 912 | * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask |
| 913 | * @xfer_mask: xfer_mask of interest |
| 914 | * |
| 915 | * Return matching XFER_* value for @xfer_mask. Only the highest |
| 916 | * bit of @xfer_mask is considered. |
| 917 | * |
| 918 | * LOCKING: |
| 919 | * None. |
| 920 | * |
| 921 | * RETURNS: |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 922 | * Matching XFER_* value, 0xff if no match found. |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 923 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 924 | u8 ata_xfer_mask2mode(unsigned long xfer_mask) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 925 | { |
| 926 | int highbit = fls(xfer_mask) - 1; |
| 927 | const struct ata_xfer_ent *ent; |
| 928 | |
| 929 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 930 | if (highbit >= ent->shift && highbit < ent->shift + ent->bits) |
| 931 | return ent->base + highbit - ent->shift; |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 932 | return 0xff; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /** |
| 936 | * ata_xfer_mode2mask - Find matching xfer_mask for XFER_* |
| 937 | * @xfer_mode: XFER_* of interest |
| 938 | * |
| 939 | * Return matching xfer_mask for @xfer_mode. |
| 940 | * |
| 941 | * LOCKING: |
| 942 | * None. |
| 943 | * |
| 944 | * RETURNS: |
| 945 | * Matching xfer_mask, 0 if no match found. |
| 946 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 947 | unsigned long ata_xfer_mode2mask(u8 xfer_mode) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 948 | { |
| 949 | const struct ata_xfer_ent *ent; |
| 950 | |
| 951 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 952 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 953 | return ((2 << (ent->shift + xfer_mode - ent->base)) - 1) |
| 954 | & ~((1 << ent->shift) - 1); |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * ata_xfer_mode2shift - Find matching xfer_shift for XFER_* |
| 960 | * @xfer_mode: XFER_* of interest |
| 961 | * |
| 962 | * Return matching xfer_shift for @xfer_mode. |
| 963 | * |
| 964 | * LOCKING: |
| 965 | * None. |
| 966 | * |
| 967 | * RETURNS: |
| 968 | * Matching xfer_shift, -1 if no match found. |
| 969 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 970 | int ata_xfer_mode2shift(unsigned long xfer_mode) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 971 | { |
| 972 | const struct ata_xfer_ent *ent; |
| 973 | |
| 974 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 975 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
| 976 | return ent->shift; |
| 977 | return -1; |
| 978 | } |
| 979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | /** |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 981 | * ata_mode_string - convert xfer_mask to string |
| 982 | * @xfer_mask: mask of bits supported; only highest bit counts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | * |
| 984 | * Determine string which represents the highest speed |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 985 | * (highest bit in @modemask). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | * |
| 987 | * LOCKING: |
| 988 | * None. |
| 989 | * |
| 990 | * RETURNS: |
| 991 | * Constant C string representing highest speed listed in |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 992 | * @mode_mask, or the constant C string "<n/a>". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 994 | const char *ata_mode_string(unsigned long xfer_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | { |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 996 | static const char * const xfer_mode_str[] = { |
| 997 | "PIO0", |
| 998 | "PIO1", |
| 999 | "PIO2", |
| 1000 | "PIO3", |
| 1001 | "PIO4", |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1002 | "PIO5", |
| 1003 | "PIO6", |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 1004 | "MWDMA0", |
| 1005 | "MWDMA1", |
| 1006 | "MWDMA2", |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1007 | "MWDMA3", |
| 1008 | "MWDMA4", |
Tejun Heo | 75f554b | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 1009 | "UDMA/16", |
| 1010 | "UDMA/25", |
| 1011 | "UDMA/33", |
| 1012 | "UDMA/44", |
| 1013 | "UDMA/66", |
| 1014 | "UDMA/100", |
| 1015 | "UDMA/133", |
| 1016 | "UDMA7", |
| 1017 | }; |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1018 | int highbit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1020 | highbit = fls(xfer_mask) - 1; |
| 1021 | if (highbit >= 0 && highbit < ARRAY_SIZE(xfer_mode_str)) |
| 1022 | return xfer_mode_str[highbit]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | return "<n/a>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 1026 | const char *sata_spd_string(unsigned int spd) |
Tejun Heo | 4c360c8 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 1027 | { |
| 1028 | static const char * const spd_str[] = { |
| 1029 | "1.5 Gbps", |
| 1030 | "3.0 Gbps", |
Shane Huang | 8522ee2 | 2008-12-30 11:00:37 +0800 | [diff] [blame] | 1031 | "6.0 Gbps", |
Tejun Heo | 4c360c8 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 1032 | }; |
| 1033 | |
| 1034 | if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) |
| 1035 | return "<unknown>"; |
| 1036 | return spd_str[spd - 1]; |
| 1037 | } |
| 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | /** |
| 1040 | * ata_dev_classify - determine device type based on ATA-spec signature |
| 1041 | * @tf: ATA taskfile register set for device to be identified |
| 1042 | * |
| 1043 | * Determine from taskfile register contents whether a device is |
| 1044 | * ATA or ATAPI, as per "Signature and persistence" section |
| 1045 | * of ATA/PI spec (volume 1, sect 5.14). |
| 1046 | * |
| 1047 | * LOCKING: |
| 1048 | * None. |
| 1049 | * |
| 1050 | * RETURNS: |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 1051 | * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP, |
| 1052 | * %ATA_DEV_ZAC, or %ATA_DEV_UNKNOWN the event of failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | */ |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 1054 | unsigned int ata_dev_classify(const struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | { |
| 1056 | /* Apple's open source Darwin code hints that some devices only |
| 1057 | * put a proper signature into the LBA mid/high registers, |
| 1058 | * So, we only check those. It's sufficient for uniqueness. |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1059 | * |
| 1060 | * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate |
| 1061 | * signatures for ATA and ATAPI devices attached on SerialATA, |
| 1062 | * 0x3c/0xc3 and 0x69/0x96 respectively. However, SerialATA |
| 1063 | * spec has never mentioned about using different signatures |
| 1064 | * for ATA/ATAPI devices. Then, Serial ATA II: Port |
| 1065 | * Multiplier specification began to use 0x69/0x96 to identify |
| 1066 | * port multpliers and 0x3c/0xc3 to identify SEMB device. |
| 1067 | * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and |
| 1068 | * 0x69/0x96 shortly and described them as reserved for |
| 1069 | * SerialATA. |
| 1070 | * |
| 1071 | * We follow the current spec and consider that 0x69/0x96 |
| 1072 | * identifies a port multiplier and 0x3c/0xc3 a SEMB device. |
Tejun Heo | 79b42ba | 2009-04-15 06:21:10 +0900 | [diff] [blame] | 1073 | * Unfortunately, WDC WD1600JS-62MHB5 (a hard drive) reports |
| 1074 | * SEMB signature. This is worked around in |
| 1075 | * ata_dev_read_id(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | */ |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1077 | if ((tf->lbam == 0) && (tf->lbah == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | DPRINTK("found ATA device by sig\n"); |
| 1079 | return ATA_DEV_ATA; |
| 1080 | } |
| 1081 | |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1082 | if ((tf->lbam == 0x14) && (tf->lbah == 0xeb)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | DPRINTK("found ATAPI device by sig\n"); |
| 1084 | return ATA_DEV_ATAPI; |
| 1085 | } |
| 1086 | |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1087 | if ((tf->lbam == 0x69) && (tf->lbah == 0x96)) { |
| 1088 | DPRINTK("found PMP device by sig\n"); |
| 1089 | return ATA_DEV_PMP; |
| 1090 | } |
| 1091 | |
| 1092 | if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) { |
Tejun Heo | 79b42ba | 2009-04-15 06:21:10 +0900 | [diff] [blame] | 1093 | DPRINTK("found SEMB device by sig (could be ATA device)\n"); |
| 1094 | return ATA_DEV_SEMB; |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 1095 | } |
| 1096 | |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 1097 | if ((tf->lbam == 0xcd) && (tf->lbah == 0xab)) { |
| 1098 | DPRINTK("found ZAC device by sig\n"); |
| 1099 | return ATA_DEV_ZAC; |
| 1100 | } |
| 1101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | DPRINTK("unknown device\n"); |
| 1103 | return ATA_DEV_UNKNOWN; |
| 1104 | } |
| 1105 | |
| 1106 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1107 | * ata_id_string - Convert IDENTIFY DEVICE page into string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | * @id: IDENTIFY DEVICE results we will examine |
| 1109 | * @s: string into which data is output |
| 1110 | * @ofs: offset into identify device page |
| 1111 | * @len: length of string to return. must be an even number. |
| 1112 | * |
| 1113 | * The strings in the IDENTIFY DEVICE page are broken up into |
| 1114 | * 16-bit chunks. Run through the string, and output each |
| 1115 | * 8-bit chunk linearly, regardless of platform. |
| 1116 | * |
| 1117 | * LOCKING: |
| 1118 | * caller. |
| 1119 | */ |
| 1120 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1121 | void ata_id_string(const u16 *id, unsigned char *s, |
| 1122 | unsigned int ofs, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
| 1124 | unsigned int c; |
| 1125 | |
Alan Cox | 963e497 | 2008-07-24 17:16:06 +0100 | [diff] [blame] | 1126 | BUG_ON(len & 1); |
| 1127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | while (len > 0) { |
| 1129 | c = id[ofs] >> 8; |
| 1130 | *s = c; |
| 1131 | s++; |
| 1132 | |
| 1133 | c = id[ofs] & 0xff; |
| 1134 | *s = c; |
| 1135 | s++; |
| 1136 | |
| 1137 | ofs++; |
| 1138 | len -= 2; |
| 1139 | } |
| 1140 | } |
| 1141 | |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1142 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1143 | * ata_id_c_string - Convert IDENTIFY DEVICE page into C string |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1144 | * @id: IDENTIFY DEVICE results we will examine |
| 1145 | * @s: string into which data is output |
| 1146 | * @ofs: offset into identify device page |
| 1147 | * @len: length of string to return. must be an odd number. |
| 1148 | * |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1149 | * This function is identical to ata_id_string except that it |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1150 | * trims trailing spaces and terminates the resulting string with |
| 1151 | * null. @len must be actual maximum length (even number) + 1. |
| 1152 | * |
| 1153 | * LOCKING: |
| 1154 | * caller. |
| 1155 | */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1156 | void ata_id_c_string(const u16 *id, unsigned char *s, |
| 1157 | unsigned int ofs, unsigned int len) |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1158 | { |
| 1159 | unsigned char *p; |
| 1160 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 1161 | ata_id_string(id, s, ofs, len - 1); |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1162 | |
| 1163 | p = s + strnlen(s, len - 1); |
| 1164 | while (p > s && p[-1] == ' ') |
| 1165 | p--; |
| 1166 | *p = '\0'; |
| 1167 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1168 | |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 1169 | static u64 ata_id_n_sectors(const u16 *id) |
| 1170 | { |
| 1171 | if (ata_id_has_lba(id)) { |
| 1172 | if (ata_id_has_lba48(id)) |
Robert Hancock | 968e594 | 2009-02-16 20:15:08 -0600 | [diff] [blame] | 1173 | return ata_id_u64(id, ATA_ID_LBA_CAPACITY_2); |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 1174 | else |
Robert Hancock | 968e594 | 2009-02-16 20:15:08 -0600 | [diff] [blame] | 1175 | return ata_id_u32(id, ATA_ID_LBA_CAPACITY); |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 1176 | } else { |
| 1177 | if (ata_id_current_chs_valid(id)) |
Robert Hancock | 968e594 | 2009-02-16 20:15:08 -0600 | [diff] [blame] | 1178 | return id[ATA_ID_CUR_CYLS] * id[ATA_ID_CUR_HEADS] * |
| 1179 | id[ATA_ID_CUR_SECTORS]; |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 1180 | else |
Robert Hancock | 968e594 | 2009-02-16 20:15:08 -0600 | [diff] [blame] | 1181 | return id[ATA_ID_CYLS] * id[ATA_ID_HEADS] * |
| 1182 | id[ATA_ID_SECTORS]; |
Tejun Heo | db6f875 | 2007-09-03 12:31:58 +0900 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
Tejun Heo | a5987e0 | 2008-03-27 19:14:23 +0900 | [diff] [blame] | 1186 | u64 ata_tf_to_lba48(const struct ata_taskfile *tf) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1187 | { |
| 1188 | u64 sectors = 0; |
| 1189 | |
| 1190 | sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; |
| 1191 | sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; |
Roland Dreier | ba14a9c | 2008-10-28 16:52:20 -0700 | [diff] [blame] | 1192 | sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1193 | sectors |= (tf->lbah & 0xff) << 16; |
| 1194 | sectors |= (tf->lbam & 0xff) << 8; |
| 1195 | sectors |= (tf->lbal & 0xff); |
| 1196 | |
Tejun Heo | a5987e0 | 2008-03-27 19:14:23 +0900 | [diff] [blame] | 1197 | return sectors; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1198 | } |
| 1199 | |
Tejun Heo | a5987e0 | 2008-03-27 19:14:23 +0900 | [diff] [blame] | 1200 | u64 ata_tf_to_lba(const struct ata_taskfile *tf) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1201 | { |
| 1202 | u64 sectors = 0; |
| 1203 | |
| 1204 | sectors |= (tf->device & 0x0f) << 24; |
| 1205 | sectors |= (tf->lbah & 0xff) << 16; |
| 1206 | sectors |= (tf->lbam & 0xff) << 8; |
| 1207 | sectors |= (tf->lbal & 0xff); |
| 1208 | |
Tejun Heo | a5987e0 | 2008-03-27 19:14:23 +0900 | [diff] [blame] | 1209 | return sectors; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | /** |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1213 | * ata_read_native_max_address - Read native max address |
| 1214 | * @dev: target device |
| 1215 | * @max_sectors: out parameter for the result native max address |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1216 | * |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1217 | * Perform an LBA48 or LBA28 native size query upon the device in |
| 1218 | * question. |
| 1219 | * |
| 1220 | * RETURNS: |
| 1221 | * 0 on success, -EACCES if command is aborted by the drive. |
| 1222 | * -EIO on other errors. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1223 | */ |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1224 | 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] | 1225 | { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1226 | unsigned int err_mask; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1227 | struct ata_taskfile tf; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1228 | int lba48 = ata_id_has_lba48(dev->id); |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1229 | |
| 1230 | ata_tf_init(dev, &tf); |
| 1231 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1232 | /* always clear all address registers */ |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1233 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1234 | |
| 1235 | if (lba48) { |
| 1236 | tf.command = ATA_CMD_READ_NATIVE_MAX_EXT; |
| 1237 | tf.flags |= ATA_TFLAG_LBA48; |
| 1238 | } else |
| 1239 | tf.command = ATA_CMD_READ_NATIVE_MAX; |
| 1240 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1241 | tf.protocol |= ATA_PROT_NODATA; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1242 | tf.device |= ATA_LBA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1243 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1244 | 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] | 1245 | if (err_mask) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1246 | ata_dev_warn(dev, |
| 1247 | "failed to read native max address (err_mask=0x%x)\n", |
| 1248 | err_mask); |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1249 | if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) |
| 1250 | return -EACCES; |
| 1251 | return -EIO; |
| 1252 | } |
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 | if (lba48) |
Tejun Heo | a5987e0 | 2008-03-27 19:14:23 +0900 | [diff] [blame] | 1255 | *max_sectors = ata_tf_to_lba48(&tf) + 1; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1256 | else |
Tejun Heo | a5987e0 | 2008-03-27 19:14:23 +0900 | [diff] [blame] | 1257 | *max_sectors = ata_tf_to_lba(&tf) + 1; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1258 | if (dev->horkage & ATA_HORKAGE_HPA_SIZE) |
Alan Cox | 93328e11 | 2007-09-29 04:06:48 -0400 | [diff] [blame] | 1259 | (*max_sectors)--; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1260 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /** |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1264 | * ata_set_max_sectors - Set max sectors |
| 1265 | * @dev: target device |
Randy Dunlap | 6b38d1d | 2007-05-01 17:35:55 -0700 | [diff] [blame] | 1266 | * @new_sectors: new max sectors value to set for the device |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1267 | * |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1268 | * Set max sectors of @dev to @new_sectors. |
| 1269 | * |
| 1270 | * RETURNS: |
| 1271 | * 0 on success, -EACCES if command is aborted or denied (due to |
| 1272 | * previous non-volatile SET_MAX) by the drive. -EIO on other |
| 1273 | * errors. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1274 | */ |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1275 | 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] | 1276 | { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1277 | unsigned int err_mask; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1278 | struct ata_taskfile tf; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1279 | int lba48 = ata_id_has_lba48(dev->id); |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1280 | |
| 1281 | new_sectors--; |
| 1282 | |
| 1283 | ata_tf_init(dev, &tf); |
| 1284 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1285 | tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1286 | |
| 1287 | if (lba48) { |
| 1288 | tf.command = ATA_CMD_SET_MAX_EXT; |
| 1289 | tf.flags |= ATA_TFLAG_LBA48; |
| 1290 | |
| 1291 | tf.hob_lbal = (new_sectors >> 24) & 0xff; |
| 1292 | tf.hob_lbam = (new_sectors >> 32) & 0xff; |
| 1293 | tf.hob_lbah = (new_sectors >> 40) & 0xff; |
Tejun Heo | 1e582ba | 2007-09-21 20:07:14 +0900 | [diff] [blame] | 1294 | } else { |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1295 | tf.command = ATA_CMD_SET_MAX; |
| 1296 | |
Tejun Heo | 1e582ba | 2007-09-21 20:07:14 +0900 | [diff] [blame] | 1297 | tf.device |= (new_sectors >> 24) & 0xf; |
| 1298 | } |
| 1299 | |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1300 | tf.protocol |= ATA_PROT_NODATA; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1301 | tf.device |= ATA_LBA; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1302 | |
| 1303 | tf.lbal = (new_sectors >> 0) & 0xff; |
| 1304 | tf.lbam = (new_sectors >> 8) & 0xff; |
| 1305 | tf.lbah = (new_sectors >> 16) & 0xff; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1306 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1307 | 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] | 1308 | if (err_mask) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1309 | ata_dev_warn(dev, |
| 1310 | "failed to set max address (err_mask=0x%x)\n", |
| 1311 | err_mask); |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1312 | if (err_mask == AC_ERR_DEV && |
| 1313 | (tf.feature & (ATA_ABORTED | ATA_IDNF))) |
| 1314 | return -EACCES; |
| 1315 | return -EIO; |
| 1316 | } |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1317 | |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1318 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * ata_hpa_resize - Resize a device with an HPA set |
| 1323 | * @dev: Device to resize |
| 1324 | * |
| 1325 | * Read the size of an LBA28 or LBA48 disk with HPA features and resize |
| 1326 | * it if required to the full size of the media. The caller must check |
| 1327 | * the drive has the HPA feature set enabled. |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1328 | * |
| 1329 | * RETURNS: |
| 1330 | * 0 on success, -errno on failure. |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1331 | */ |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1332 | static int ata_hpa_resize(struct ata_device *dev) |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1333 | { |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1334 | struct ata_eh_context *ehc = &dev->link->eh_context; |
| 1335 | int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 1336 | bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA; |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1337 | u64 sectors = ata_id_n_sectors(dev->id); |
| 1338 | u64 native_sectors; |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1339 | int rc; |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 1340 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1341 | /* do we need to do it? */ |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 1342 | if ((dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) || |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1343 | !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || |
| 1344 | (dev->horkage & ATA_HORKAGE_BROKEN_HPA)) |
Tejun Heo | c728a91 | 2007-09-03 12:32:30 +0900 | [diff] [blame] | 1345 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1346 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1347 | /* read native max address */ |
| 1348 | rc = ata_read_native_max_address(dev, &native_sectors); |
| 1349 | if (rc) { |
Tejun Heo | dda7aba | 2008-03-23 21:05:15 +0900 | [diff] [blame] | 1350 | /* If device aborted the command or HPA isn't going to |
| 1351 | * be unlocked, skip HPA resizing. |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1352 | */ |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 1353 | if (rc == -EACCES || !unlock_hpa) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1354 | ata_dev_warn(dev, |
| 1355 | "HPA support seems broken, skipping HPA handling\n"); |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1356 | dev->horkage |= ATA_HORKAGE_BROKEN_HPA; |
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 | /* we can continue if device aborted the command */ |
| 1359 | if (rc == -EACCES) |
| 1360 | rc = 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1361 | } |
Tejun Heo | 37301a5 | 2007-06-25 20:45:54 +0900 | [diff] [blame] | 1362 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1363 | return rc; |
| 1364 | } |
Tejun Heo | 5920dad | 2009-07-15 17:11:41 +0900 | [diff] [blame] | 1365 | dev->n_native_sectors = native_sectors; |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1366 | |
| 1367 | /* nothing to do? */ |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 1368 | if (native_sectors <= sectors || !unlock_hpa) { |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1369 | if (!print_info || native_sectors == sectors) |
| 1370 | return 0; |
| 1371 | |
| 1372 | if (native_sectors > sectors) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1373 | ata_dev_info(dev, |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1374 | "HPA detected: current %llu, native %llu\n", |
| 1375 | (unsigned long long)sectors, |
| 1376 | (unsigned long long)native_sectors); |
| 1377 | else if (native_sectors < sectors) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1378 | ata_dev_warn(dev, |
| 1379 | "native sectors (%llu) is smaller than sectors (%llu)\n", |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1380 | (unsigned long long)native_sectors, |
| 1381 | (unsigned long long)sectors); |
| 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | /* let's unlock HPA */ |
| 1386 | rc = ata_set_max_sectors(dev, native_sectors); |
| 1387 | if (rc == -EACCES) { |
| 1388 | /* if device aborted the command, skip HPA resizing */ |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1389 | ata_dev_warn(dev, |
| 1390 | "device aborted resize (%llu -> %llu), skipping HPA handling\n", |
| 1391 | (unsigned long long)sectors, |
| 1392 | (unsigned long long)native_sectors); |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1393 | dev->horkage |= ATA_HORKAGE_BROKEN_HPA; |
| 1394 | return 0; |
| 1395 | } else if (rc) |
| 1396 | return rc; |
| 1397 | |
| 1398 | /* re-read IDENTIFY data */ |
| 1399 | rc = ata_dev_reread_id(dev, 0); |
| 1400 | if (rc) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1401 | ata_dev_err(dev, |
| 1402 | "failed to re-read IDENTIFY data after HPA resizing\n"); |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1403 | return rc; |
| 1404 | } |
| 1405 | |
| 1406 | if (print_info) { |
| 1407 | u64 new_sectors = ata_id_n_sectors(dev->id); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1408 | ata_dev_info(dev, |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 1409 | "HPA unlocked: %llu -> %llu, native %llu\n", |
| 1410 | (unsigned long long)sectors, |
| 1411 | (unsigned long long)new_sectors, |
| 1412 | (unsigned long long)native_sectors); |
| 1413 | } |
| 1414 | |
| 1415 | return 0; |
Alan Cox | 1e99973 | 2007-04-11 00:23:13 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 1418 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | * ata_dump_id - IDENTIFY DEVICE info debugging output |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1420 | * @id: IDENTIFY DEVICE page to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | * |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1422 | * Dump selected 16-bit words from the given IDENTIFY DEVICE |
| 1423 | * page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | * |
| 1425 | * LOCKING: |
| 1426 | * caller. |
| 1427 | */ |
| 1428 | |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1429 | static inline void ata_dump_id(const u16 *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | { |
| 1431 | DPRINTK("49==0x%04x " |
| 1432 | "53==0x%04x " |
| 1433 | "63==0x%04x " |
| 1434 | "64==0x%04x " |
| 1435 | "75==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1436 | id[49], |
| 1437 | id[53], |
| 1438 | id[63], |
| 1439 | id[64], |
| 1440 | id[75]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | DPRINTK("80==0x%04x " |
| 1442 | "81==0x%04x " |
| 1443 | "82==0x%04x " |
| 1444 | "83==0x%04x " |
| 1445 | "84==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1446 | id[80], |
| 1447 | id[81], |
| 1448 | id[82], |
| 1449 | id[83], |
| 1450 | id[84]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | DPRINTK("88==0x%04x " |
| 1452 | "93==0x%04x\n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1453 | id[88], |
| 1454 | id[93]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1457 | /** |
| 1458 | * ata_id_xfermask - Compute xfermask from the given IDENTIFY data |
| 1459 | * @id: IDENTIFY data to compute xfer mask from |
| 1460 | * |
| 1461 | * Compute the xfermask for this device. This is not as trivial |
| 1462 | * as it seems if we must consider early devices correctly. |
| 1463 | * |
| 1464 | * FIXME: pre IDE drive timing (do we care ?). |
| 1465 | * |
| 1466 | * LOCKING: |
| 1467 | * None. |
| 1468 | * |
| 1469 | * RETURNS: |
| 1470 | * Computed xfermask |
| 1471 | */ |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 1472 | unsigned long ata_id_xfermask(const u16 *id) |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1473 | { |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 1474 | unsigned long pio_mask, mwdma_mask, udma_mask; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1475 | |
| 1476 | /* Usual case. Word 53 indicates word 64 is valid */ |
| 1477 | if (id[ATA_ID_FIELD_VALID] & (1 << 1)) { |
| 1478 | pio_mask = id[ATA_ID_PIO_MODES] & 0x03; |
| 1479 | pio_mask <<= 3; |
| 1480 | pio_mask |= 0x7; |
| 1481 | } else { |
| 1482 | /* If word 64 isn't valid then Word 51 high byte holds |
| 1483 | * the PIO timing number for the maximum. Turn it into |
| 1484 | * a mask. |
| 1485 | */ |
Lennert Buytenhek | 7a0f1c8 | 2007-01-29 13:28:47 +0100 | [diff] [blame] | 1486 | u8 mode = (id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF; |
Alan Cox | 46767aeb | 2006-09-29 18:26:47 +0100 | [diff] [blame] | 1487 | if (mode < 5) /* Valid PIO range */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1488 | pio_mask = (2 << mode) - 1; |
Alan Cox | 46767aeb | 2006-09-29 18:26:47 +0100 | [diff] [blame] | 1489 | else |
| 1490 | pio_mask = 1; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1491 | |
| 1492 | /* But wait.. there's more. Design your standards by |
| 1493 | * committee and you too can get a free iordy field to |
| 1494 | * process. However its the speeds not the modes that |
| 1495 | * are supported... Note drivers using the timing API |
| 1496 | * will get this right anyway |
| 1497 | */ |
| 1498 | } |
| 1499 | |
| 1500 | mwdma_mask = id[ATA_ID_MWDMA_MODES] & 0x07; |
Tejun Heo | fb21f0d | 2006-03-12 12:34:35 +0900 | [diff] [blame] | 1501 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1502 | if (ata_id_is_cfa(id)) { |
| 1503 | /* |
| 1504 | * Process compact flash extended modes |
| 1505 | */ |
Sergei Shtylyov | 62afe5d | 2009-04-13 20:50:00 +0400 | [diff] [blame] | 1506 | int pio = (id[ATA_ID_CFA_MODES] >> 0) & 0x7; |
| 1507 | int dma = (id[ATA_ID_CFA_MODES] >> 3) & 0x7; |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 1508 | |
| 1509 | if (pio) |
| 1510 | pio_mask |= (1 << 5); |
| 1511 | if (pio > 1) |
| 1512 | pio_mask |= (1 << 6); |
| 1513 | if (dma) |
| 1514 | mwdma_mask |= (1 << 3); |
| 1515 | if (dma > 1) |
| 1516 | mwdma_mask |= (1 << 4); |
| 1517 | } |
| 1518 | |
Tejun Heo | fb21f0d | 2006-03-12 12:34:35 +0900 | [diff] [blame] | 1519 | udma_mask = 0; |
| 1520 | if (id[ATA_ID_FIELD_VALID] & (1 << 2)) |
| 1521 | udma_mask = id[ATA_ID_UDMA_MODES] & 0xff; |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1522 | |
| 1523 | return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 1524 | } |
| 1525 | |
Adrian Bunk | 7102d23 | 2007-01-04 00:09:36 +0100 | [diff] [blame] | 1526 | static void ata_qc_complete_internal(struct ata_queued_cmd *qc) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1527 | { |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1528 | struct completion *waiting = qc->private_data; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1529 | |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1530 | complete(waiting); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /** |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1534 | * ata_exec_internal_sg - execute libata internal command |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1535 | * @dev: Device to which the command is sent |
| 1536 | * @tf: Taskfile registers for the command and the result |
Tejun Heo | d69cf37 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1537 | * @cdb: CDB for packet command |
Masanari Iida | e227867 | 2014-02-18 22:54:36 +0900 | [diff] [blame] | 1538 | * @dma_dir: Data transfer direction of the command |
Randy Dunlap | 5c1ad8b | 2007-10-18 14:12:26 -0700 | [diff] [blame] | 1539 | * @sgl: sg list for the data buffer of the command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1540 | * @n_elem: Number of sg entries |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1541 | * @timeout: Timeout in msecs (0 for default) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1542 | * |
| 1543 | * Executes libata internal command with timeout. @tf contains |
| 1544 | * command on entry and result on return. Timeout and error |
| 1545 | * conditions are reported via return value. No recovery action |
| 1546 | * is taken after a command times out. It's caller's duty to |
| 1547 | * clean up after timeout. |
| 1548 | * |
| 1549 | * LOCKING: |
| 1550 | * None. Should be called with kernel context, might sleep. |
Tejun Heo | 551e888 | 2006-06-12 14:09:49 +0900 | [diff] [blame] | 1551 | * |
| 1552 | * RETURNS: |
| 1553 | * Zero on success, AC_ERR_* mask on failure |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1554 | */ |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1555 | unsigned ata_exec_internal_sg(struct ata_device *dev, |
| 1556 | struct ata_taskfile *tf, const u8 *cdb, |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1557 | int dma_dir, struct scatterlist *sgl, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1558 | unsigned int n_elem, unsigned long timeout) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1559 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1560 | struct ata_link *link = dev->link; |
| 1561 | struct ata_port *ap = link->ap; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1562 | u8 command = tf->command; |
Tejun Heo | 87fbc5a | 2008-05-20 02:17:54 +0900 | [diff] [blame] | 1563 | int auto_timeout = 0; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1564 | struct ata_queued_cmd *qc; |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1565 | unsigned int tag, preempted_tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1566 | u32 preempted_sactive, preempted_qc_active; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1567 | int preempted_nr_active_links; |
Ingo Molnar | 60be6b9 | 2006-07-03 00:25:26 -0700 | [diff] [blame] | 1568 | DECLARE_COMPLETION_ONSTACK(wait); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1569 | unsigned long flags; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1570 | unsigned int err_mask; |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1571 | int rc; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1572 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1573 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1574 | |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 1575 | /* no internal command while frozen */ |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 1576 | if (ap->pflags & ATA_PFLAG_FROZEN) { |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1577 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 1578 | return AC_ERR_SYSTEM; |
| 1579 | } |
| 1580 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1581 | /* initialize internal qc */ |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1582 | |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1583 | /* XXX: Tag 0 is used for drivers with legacy EH as some |
| 1584 | * drivers choke if any other tag is given. This breaks |
| 1585 | * ata_tag_internal() test for those drivers. Don't use new |
| 1586 | * EH stuff without converting to it. |
| 1587 | */ |
| 1588 | if (ap->ops->error_handler) |
| 1589 | tag = ATA_TAG_INTERNAL; |
| 1590 | else |
| 1591 | tag = 0; |
| 1592 | |
Tejun Heo | f69499f | 2006-05-15 20:58:03 +0900 | [diff] [blame] | 1593 | qc = __ata_qc_from_tag(ap, tag); |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1594 | |
| 1595 | qc->tag = tag; |
| 1596 | qc->scsicmd = NULL; |
| 1597 | qc->ap = ap; |
| 1598 | qc->dev = dev; |
| 1599 | ata_qc_reinit(qc); |
| 1600 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1601 | preempted_tag = link->active_tag; |
| 1602 | preempted_sactive = link->sactive; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1603 | preempted_qc_active = ap->qc_active; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1604 | preempted_nr_active_links = ap->nr_active_links; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1605 | link->active_tag = ATA_TAG_POISON; |
| 1606 | link->sactive = 0; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1607 | ap->qc_active = 0; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1608 | ap->nr_active_links = 0; |
Tejun Heo | 2ab7db1 | 2006-05-15 20:58:02 +0900 | [diff] [blame] | 1609 | |
| 1610 | /* prepare & issue qc */ |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1611 | qc->tf = *tf; |
Tejun Heo | d69cf37 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 1612 | if (cdb) |
| 1613 | memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); |
Vincent Pelletier | e771451 | 2013-05-18 18:44:04 +0200 | [diff] [blame] | 1614 | |
| 1615 | /* some SATA bridges need us to indicate data xfer direction */ |
| 1616 | if (tf->protocol == ATAPI_PROT_DMA && (dev->flags & ATA_DFLAG_DMADIR) && |
| 1617 | dma_dir == DMA_FROM_DEVICE) |
| 1618 | qc->tf.feature |= ATAPI_DMADIR; |
| 1619 | |
Tejun Heo | e61e067 | 2006-05-15 20:57:40 +0900 | [diff] [blame] | 1620 | qc->flags |= ATA_QCFLAG_RESULT_TF; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1621 | qc->dma_dir = dma_dir; |
| 1622 | if (dma_dir != DMA_NONE) { |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1623 | unsigned int i, buflen = 0; |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1624 | struct scatterlist *sg; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1625 | |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1626 | for_each_sg(sgl, sg, n_elem, i) |
| 1627 | buflen += sg->length; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1628 | |
Jens Axboe | 8726021 | 2007-10-16 11:14:12 +0200 | [diff] [blame] | 1629 | ata_sg_init(qc, sgl, n_elem); |
Brian King | 49c8042 | 2007-01-30 11:32:26 -0600 | [diff] [blame] | 1630 | qc->nbytes = buflen; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1631 | } |
| 1632 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1633 | qc->private_data = &wait; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1634 | qc->complete_fn = ata_qc_complete_internal; |
| 1635 | |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 1636 | ata_qc_issue(qc); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1637 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1638 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1639 | |
Tejun Heo | 87fbc5a | 2008-05-20 02:17:54 +0900 | [diff] [blame] | 1640 | if (!timeout) { |
| 1641 | if (ata_probe_timeout) |
| 1642 | timeout = ata_probe_timeout * 1000; |
| 1643 | else { |
| 1644 | timeout = ata_internal_cmd_timeout(dev, command); |
| 1645 | auto_timeout = 1; |
| 1646 | } |
| 1647 | } |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1648 | |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 1649 | if (ap->ops->error_handler) |
| 1650 | ata_eh_release(ap); |
| 1651 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1652 | rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); |
Albert Lee | 41ade50 | 2006-03-14 11:19:04 +0800 | [diff] [blame] | 1653 | |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 1654 | if (ap->ops->error_handler) |
| 1655 | ata_eh_acquire(ap); |
| 1656 | |
Tejun Heo | c429137 | 2010-05-10 21:41:38 +0200 | [diff] [blame] | 1657 | ata_sff_flush_pio_task(ap); |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1658 | |
| 1659 | if (!rc) { |
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 | |
| 1662 | /* We're racing with irq here. If we lose, the |
| 1663 | * following test prevents us from completing the qc |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1664 | * twice. If we win, the port is frozen and will be |
| 1665 | * cleaned up by ->post_internal_cmd(). |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1666 | */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1667 | if (qc->flags & ATA_QCFLAG_ACTIVE) { |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1668 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 1669 | |
| 1670 | if (ap->ops->error_handler) |
| 1671 | ata_port_freeze(ap); |
| 1672 | else |
| 1673 | ata_qc_complete(qc); |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 1674 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1675 | if (ata_msg_warn(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1676 | ata_dev_warn(dev, "qc timeout (cmd 0x%x)\n", |
| 1677 | command); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1678 | } |
| 1679 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1680 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1681 | } |
| 1682 | |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1683 | /* do post_internal_cmd */ |
| 1684 | if (ap->ops->post_internal_cmd) |
| 1685 | ap->ops->post_internal_cmd(qc); |
| 1686 | |
Tejun Heo | a51d644 | 2007-03-20 15:24:11 +0900 | [diff] [blame] | 1687 | /* perform minimal error analysis */ |
| 1688 | if (qc->flags & ATA_QCFLAG_FAILED) { |
| 1689 | if (qc->result_tf.command & (ATA_ERR | ATA_DF)) |
| 1690 | qc->err_mask |= AC_ERR_DEV; |
| 1691 | |
| 1692 | if (!qc->err_mask) |
| 1693 | qc->err_mask |= AC_ERR_OTHER; |
| 1694 | |
| 1695 | if (qc->err_mask & ~AC_ERR_OTHER) |
| 1696 | qc->err_mask &= ~AC_ERR_OTHER; |
Tejun Heo | d95a717 | 2006-05-15 20:58:14 +0900 | [diff] [blame] | 1697 | } |
| 1698 | |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1699 | /* finish up */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1700 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1701 | |
Tejun Heo | e61e067 | 2006-05-15 20:57:40 +0900 | [diff] [blame] | 1702 | *tf = qc->result_tf; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1703 | err_mask = qc->err_mask; |
| 1704 | |
| 1705 | ata_qc_free(qc); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1706 | link->active_tag = preempted_tag; |
| 1707 | link->sactive = preempted_sactive; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 1708 | ap->qc_active = preempted_qc_active; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 1709 | ap->nr_active_links = preempted_nr_active_links; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1710 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 1711 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 1586930 | 2006-05-15 20:57:33 +0900 | [diff] [blame] | 1712 | |
Tejun Heo | 87fbc5a | 2008-05-20 02:17:54 +0900 | [diff] [blame] | 1713 | if ((err_mask & AC_ERR_TIMEOUT) && auto_timeout) |
| 1714 | ata_internal_cmd_timed_out(dev, command); |
| 1715 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1716 | return err_mask; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1717 | } |
| 1718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | /** |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1720 | * ata_exec_internal - execute libata internal command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1721 | * @dev: Device to which the command is sent |
| 1722 | * @tf: Taskfile registers for the command and the result |
| 1723 | * @cdb: CDB for packet command |
Masanari Iida | e227867 | 2014-02-18 22:54:36 +0900 | [diff] [blame] | 1724 | * @dma_dir: Data transfer direction of the command |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1725 | * @buf: Data buffer of the command |
| 1726 | * @buflen: Length of data buffer |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1727 | * @timeout: Timeout in msecs (0 for default) |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1728 | * |
| 1729 | * Wrapper around ata_exec_internal_sg() which takes simple |
| 1730 | * buffer instead of sg list. |
| 1731 | * |
| 1732 | * LOCKING: |
| 1733 | * None. Should be called with kernel context, might sleep. |
| 1734 | * |
| 1735 | * RETURNS: |
| 1736 | * Zero on success, AC_ERR_* mask on failure |
| 1737 | */ |
| 1738 | unsigned ata_exec_internal(struct ata_device *dev, |
| 1739 | struct ata_taskfile *tf, const u8 *cdb, |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1740 | int dma_dir, void *buf, unsigned int buflen, |
| 1741 | unsigned long timeout) |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1742 | { |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1743 | struct scatterlist *psg = NULL, sg; |
| 1744 | unsigned int n_elem = 0; |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1745 | |
Tejun Heo | 33480a0 | 2006-12-12 02:15:31 +0900 | [diff] [blame] | 1746 | if (dma_dir != DMA_NONE) { |
| 1747 | WARN_ON(!buf); |
| 1748 | sg_init_one(&sg, buf, buflen); |
| 1749 | psg = &sg; |
| 1750 | n_elem++; |
| 1751 | } |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1752 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 1753 | return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem, |
| 1754 | timeout); |
Tejun Heo | 2432697 | 2006-11-14 22:47:09 +0900 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | /** |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1758 | * ata_pio_need_iordy - check if iordy needed |
| 1759 | * @adev: ATA device |
| 1760 | * |
| 1761 | * Check if the current speed of the device requires IORDY. Used |
| 1762 | * by various controllers for chip configuration. |
| 1763 | */ |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1764 | unsigned int ata_pio_need_iordy(const struct ata_device *adev) |
| 1765 | { |
Tejun Heo | 0d9e665 | 2009-06-11 11:04:45 +0900 | [diff] [blame] | 1766 | /* Don't set IORDY if we're preparing for reset. IORDY may |
| 1767 | * lead to controller lock up on certain controllers if the |
| 1768 | * port is not occupied. See bko#11703 for details. |
| 1769 | */ |
| 1770 | if (adev->link->ap->pflags & ATA_PFLAG_RESETTING) |
| 1771 | return 0; |
| 1772 | /* Controller doesn't support IORDY. Probably a pointless |
| 1773 | * check as the caller should know this. |
| 1774 | */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1775 | if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1776 | return 0; |
David Daney | 5c18c4d | 2008-12-10 15:39:12 -0800 | [diff] [blame] | 1777 | /* CF spec. r4.1 Table 22 says no iordy on PIO5 and PIO6. */ |
| 1778 | if (ata_id_is_cfa(adev->id) |
| 1779 | && (adev->pio_mode == XFER_PIO_5 || adev->pio_mode == XFER_PIO_6)) |
| 1780 | return 0; |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1781 | /* PIO3 and higher it is mandatory */ |
| 1782 | if (adev->pio_mode > XFER_PIO_2) |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1783 | return 1; |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1784 | /* We turn it on when possible */ |
| 1785 | if (ata_id_has_iordy(adev->id)) |
| 1786 | return 1; |
| 1787 | return 0; |
| 1788 | } |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 1789 | |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1790 | /** |
| 1791 | * ata_pio_mask_no_iordy - Return the non IORDY mask |
| 1792 | * @adev: ATA device |
| 1793 | * |
| 1794 | * Compute the highest mode possible if we are not using iordy. Return |
| 1795 | * -1 if no iordy mode is available. |
| 1796 | */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1797 | static u32 ata_pio_mask_no_iordy(const struct ata_device *adev) |
| 1798 | { |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1799 | /* 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] | 1800 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1801 | u16 pio = adev->id[ATA_ID_EIDE_PIO]; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1802 | /* Is the speed faster than the drive allows non IORDY ? */ |
| 1803 | if (pio) { |
| 1804 | /* This is cycle times not frequency - watch the logic! */ |
| 1805 | if (pio > 240) /* PIO2 is 240nS per cycle */ |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1806 | return 3 << ATA_SHIFT_PIO; |
| 1807 | return 7 << ATA_SHIFT_PIO; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1808 | } |
| 1809 | } |
Alan Cox | 432729f | 2007-03-08 23:22:59 +0000 | [diff] [blame] | 1810 | return 3 << ATA_SHIFT_PIO; |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | /** |
Alan Cox | 963e497 | 2008-07-24 17:16:06 +0100 | [diff] [blame] | 1814 | * ata_do_dev_read_id - default ID read method |
| 1815 | * @dev: device |
| 1816 | * @tf: proposed taskfile |
| 1817 | * @id: data buffer |
| 1818 | * |
| 1819 | * Issue the identify taskfile and hand back the buffer containing |
| 1820 | * identify data. For some RAID controllers and for pre ATA devices |
| 1821 | * this function is wrapped or replaced by the driver |
| 1822 | */ |
| 1823 | unsigned int ata_do_dev_read_id(struct ata_device *dev, |
| 1824 | struct ata_taskfile *tf, u16 *id) |
| 1825 | { |
| 1826 | return ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE, |
| 1827 | id, sizeof(id[0]) * ATA_ID_WORDS, 0); |
| 1828 | } |
| 1829 | |
| 1830 | /** |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1831 | * ata_dev_read_id - Read ID data from the specified device |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1832 | * @dev: target device |
| 1833 | * @p_class: pointer to class of the target device (may be changed) |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1834 | * @flags: ATA_READID_* flags |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 1835 | * @id: buffer to read IDENTIFY data into |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1836 | * |
| 1837 | * Read ID data from the specified device. ATA_CMD_ID_ATA is |
| 1838 | * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI |
Tejun Heo | aec5c3c | 2006-03-25 01:33:34 +0900 | [diff] [blame] | 1839 | * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS |
| 1840 | * for pre-ATA4 drives. |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1841 | * |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1842 | * FIXME: ATA_CMD_ID_ATA is optional for early drives and right |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 1843 | * now we abort if we hit that case. |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 1844 | * |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1845 | * LOCKING: |
| 1846 | * Kernel thread context (may sleep) |
| 1847 | * |
| 1848 | * RETURNS: |
| 1849 | * 0 on success, -errno otherwise. |
| 1850 | */ |
Tejun Heo | a9beec9 | 2006-05-31 18:27:44 +0900 | [diff] [blame] | 1851 | 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] | 1852 | unsigned int flags, u16 *id) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1853 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1854 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1855 | unsigned int class = *p_class; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1856 | struct ata_taskfile tf; |
| 1857 | unsigned int err_mask = 0; |
| 1858 | const char *reason; |
Tejun Heo | 79b42ba | 2009-04-15 06:21:10 +0900 | [diff] [blame] | 1859 | bool is_semb = class == ATA_DEV_SEMB; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1860 | int may_fallback = 1, tried_spinup = 0; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1861 | int rc; |
| 1862 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 1863 | if (ata_msg_ctl(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1864 | ata_dev_dbg(dev, "%s: ENTER\n", __func__); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1865 | |
Alan Cox | 963e497 | 2008-07-24 17:16:06 +0100 | [diff] [blame] | 1866 | retry: |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 1867 | ata_tf_init(dev, &tf); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1868 | |
| 1869 | switch (class) { |
Tejun Heo | 79b42ba | 2009-04-15 06:21:10 +0900 | [diff] [blame] | 1870 | case ATA_DEV_SEMB: |
| 1871 | class = ATA_DEV_ATA; /* some hard drives report SEMB sig */ |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1872 | case ATA_DEV_ATA: |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 1873 | case ATA_DEV_ZAC: |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1874 | tf.command = ATA_CMD_ID_ATA; |
| 1875 | break; |
| 1876 | case ATA_DEV_ATAPI: |
| 1877 | tf.command = ATA_CMD_ID_ATAPI; |
| 1878 | break; |
| 1879 | default: |
| 1880 | rc = -ENODEV; |
| 1881 | reason = "unsupported class"; |
| 1882 | goto err_out; |
| 1883 | } |
| 1884 | |
| 1885 | tf.protocol = ATA_PROT_PIO; |
Tejun Heo | 81afe89 | 2007-02-07 12:37:41 -0800 | [diff] [blame] | 1886 | |
| 1887 | /* Some devices choke if TF registers contain garbage. Make |
| 1888 | * sure those are properly initialized. |
| 1889 | */ |
| 1890 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 1891 | |
| 1892 | /* Device presence detection is unreliable on some |
| 1893 | * controllers. Always poll IDENTIFY if available. |
| 1894 | */ |
| 1895 | tf.flags |= ATA_TFLAG_POLLING; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1896 | |
Alan Cox | 963e497 | 2008-07-24 17:16:06 +0100 | [diff] [blame] | 1897 | if (ap->ops->read_id) |
| 1898 | err_mask = ap->ops->read_id(dev, &tf, id); |
| 1899 | else |
| 1900 | err_mask = ata_do_dev_read_id(dev, &tf, id); |
| 1901 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1902 | if (err_mask) { |
Tejun Heo | 800b399 | 2006-12-03 21:34:13 +0900 | [diff] [blame] | 1903 | if (err_mask & AC_ERR_NODEV_HINT) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1904 | ata_dev_dbg(dev, "NODEV after polling detection\n"); |
Tejun Heo | 55a8e2c | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 1905 | return -ENOENT; |
| 1906 | } |
| 1907 | |
Tejun Heo | 79b42ba | 2009-04-15 06:21:10 +0900 | [diff] [blame] | 1908 | if (is_semb) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1909 | ata_dev_info(dev, |
| 1910 | "IDENTIFY failed on device w/ SEMB sig, disabled\n"); |
Tejun Heo | 79b42ba | 2009-04-15 06:21:10 +0900 | [diff] [blame] | 1911 | /* SEMB is not supported yet */ |
| 1912 | *p_class = ATA_DEV_SEMB_UNSUP; |
| 1913 | return 0; |
| 1914 | } |
| 1915 | |
Tejun Heo | 1ffc151 | 2008-03-23 15:16:53 +0900 | [diff] [blame] | 1916 | if ((err_mask == AC_ERR_DEV) && (tf.feature & ATA_ABORTED)) { |
| 1917 | /* Device or controller might have reported |
| 1918 | * the wrong device class. Give a shot at the |
| 1919 | * other IDENTIFY if the current one is |
| 1920 | * aborted by the device. |
| 1921 | */ |
| 1922 | if (may_fallback) { |
| 1923 | may_fallback = 0; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1924 | |
Tejun Heo | 1ffc151 | 2008-03-23 15:16:53 +0900 | [diff] [blame] | 1925 | if (class == ATA_DEV_ATA) |
| 1926 | class = ATA_DEV_ATAPI; |
| 1927 | else |
| 1928 | class = ATA_DEV_ATA; |
| 1929 | goto retry; |
| 1930 | } |
| 1931 | |
| 1932 | /* Control reaches here iff the device aborted |
| 1933 | * both flavors of IDENTIFYs which happens |
| 1934 | * sometimes with phantom devices. |
| 1935 | */ |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1936 | ata_dev_dbg(dev, |
| 1937 | "both IDENTIFYs aborted, assuming NODEV\n"); |
Tejun Heo | 1ffc151 | 2008-03-23 15:16:53 +0900 | [diff] [blame] | 1938 | return -ENOENT; |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1939 | } |
| 1940 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1941 | rc = -EIO; |
| 1942 | reason = "I/O error"; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1943 | goto err_out; |
| 1944 | } |
| 1945 | |
Tejun Heo | 43c9c59 | 2010-05-23 12:59:11 +0200 | [diff] [blame] | 1946 | if (dev->horkage & ATA_HORKAGE_DUMP_ID) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 1947 | ata_dev_dbg(dev, "dumping IDENTIFY data, " |
| 1948 | "class=%d may_fallback=%d tried_spinup=%d\n", |
| 1949 | class, may_fallback, tried_spinup); |
Tejun Heo | 43c9c59 | 2010-05-23 12:59:11 +0200 | [diff] [blame] | 1950 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, |
| 1951 | 16, 2, id, ATA_ID_WORDS * sizeof(*id), true); |
| 1952 | } |
| 1953 | |
Tejun Heo | 54936f8 | 2007-05-11 14:35:29 +0200 | [diff] [blame] | 1954 | /* Falling back doesn't make sense if ID data was read |
| 1955 | * successfully at least once. |
| 1956 | */ |
| 1957 | may_fallback = 0; |
| 1958 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1959 | swap_buf_le16(id, ATA_ID_WORDS); |
| 1960 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1961 | /* sanity check */ |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 1962 | rc = -EINVAL; |
Alan Cox | 6070068 | 2007-06-07 16:13:55 +0100 | [diff] [blame] | 1963 | reason = "device reports invalid type"; |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 1964 | |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 1965 | if (class == ATA_DEV_ATA || class == ATA_DEV_ZAC) { |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 1966 | if (!ata_id_is_ata(id) && !ata_id_is_cfa(id)) |
| 1967 | goto err_out; |
Andy Whitcroft | db63a4c | 2012-05-04 22:15:10 +0100 | [diff] [blame] | 1968 | if (ap->host->flags & ATA_HOST_IGNORE_ATA && |
| 1969 | ata_id_is_ata(id)) { |
| 1970 | ata_dev_dbg(dev, |
| 1971 | "host indicates ignore ATA devices, ignored\n"); |
| 1972 | return -ENOENT; |
| 1973 | } |
Tejun Heo | a4f5749 | 2006-09-12 20:35:49 -0700 | [diff] [blame] | 1974 | } else { |
| 1975 | if (ata_id_is_ata(id)) |
| 1976 | goto err_out; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1977 | } |
| 1978 | |
Mark Lord | 169439c | 2007-04-17 18:26:07 -0400 | [diff] [blame] | 1979 | if (!tried_spinup && (id[2] == 0x37c8 || id[2] == 0x738c)) { |
| 1980 | tried_spinup = 1; |
| 1981 | /* |
| 1982 | * Drive powered-up in standby mode, and requires a specific |
| 1983 | * SET_FEATURES spin-up subcommand before it will accept |
| 1984 | * anything other than the original IDENTIFY command. |
| 1985 | */ |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 1986 | err_mask = ata_dev_set_feature(dev, SETFEATURES_SPINUP, 0); |
Ryan Power | fb0582f9 | 2007-08-10 13:59:35 -0700 | [diff] [blame] | 1987 | if (err_mask && id[2] != 0x738c) { |
Mark Lord | 169439c | 2007-04-17 18:26:07 -0400 | [diff] [blame] | 1988 | rc = -EIO; |
| 1989 | reason = "SPINUP failed"; |
| 1990 | goto err_out; |
| 1991 | } |
| 1992 | /* |
| 1993 | * If the drive initially returned incomplete IDENTIFY info, |
| 1994 | * we now must reissue the IDENTIFY command. |
| 1995 | */ |
| 1996 | if (id[2] == 0x37c8) |
| 1997 | goto retry; |
| 1998 | } |
| 1999 | |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 2000 | if ((flags & ATA_READID_POSTRESET) && |
| 2001 | (class == ATA_DEV_ATA || class == ATA_DEV_ZAC)) { |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2002 | /* |
| 2003 | * The exact sequence expected by certain pre-ATA4 drives is: |
| 2004 | * SRST RESET |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 2005 | * IDENTIFY (optional in early ATA) |
| 2006 | * INITIALIZE DEVICE PARAMETERS (later IDE and ATA) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2007 | * anything else.. |
| 2008 | * Some drives were very specific about that exact sequence. |
Alan Cox | 50a9901 | 2007-08-08 14:27:00 +0100 | [diff] [blame] | 2009 | * |
| 2010 | * Note that ATA4 says lba is mandatory so the second check |
Adam Buchbinder | c9404c9 | 2009-12-18 15:40:42 -0500 | [diff] [blame] | 2011 | * should never trigger. |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2012 | */ |
| 2013 | if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) { |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2014 | err_mask = ata_dev_init_params(dev, id[3], id[6]); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2015 | if (err_mask) { |
| 2016 | rc = -EIO; |
| 2017 | reason = "INIT_DEV_PARAMS failed"; |
| 2018 | goto err_out; |
| 2019 | } |
| 2020 | |
| 2021 | /* current CHS translation info (id[53-58]) might be |
| 2022 | * changed. reread the identify device info. |
| 2023 | */ |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2024 | flags &= ~ATA_READID_POSTRESET; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2025 | goto retry; |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | *p_class = class; |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 2030 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2031 | return 0; |
| 2032 | |
| 2033 | err_out: |
Tejun Heo | 8857455 | 2006-06-25 20:00:35 +0900 | [diff] [blame] | 2034 | if (ata_msg_warn(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2035 | ata_dev_warn(dev, "failed to IDENTIFY (%s, err_mask=0x%x)\n", |
| 2036 | reason, err_mask); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2037 | return rc; |
| 2038 | } |
| 2039 | |
Tejun Heo | 9062712 | 2009-01-29 20:31:36 +0900 | [diff] [blame] | 2040 | static int ata_do_link_spd_horkage(struct ata_device *dev) |
| 2041 | { |
| 2042 | struct ata_link *plink = ata_dev_phys_link(dev); |
| 2043 | u32 target, target_limit; |
| 2044 | |
| 2045 | if (!sata_scr_valid(plink)) |
| 2046 | return 0; |
| 2047 | |
| 2048 | if (dev->horkage & ATA_HORKAGE_1_5_GBPS) |
| 2049 | target = 1; |
| 2050 | else |
| 2051 | return 0; |
| 2052 | |
| 2053 | target_limit = (1 << target) - 1; |
| 2054 | |
| 2055 | /* if already on stricter limit, no need to push further */ |
| 2056 | if (plink->sata_spd_limit <= target_limit) |
| 2057 | return 0; |
| 2058 | |
| 2059 | plink->sata_spd_limit = target_limit; |
| 2060 | |
| 2061 | /* Request another EH round by returning -EAGAIN if link is |
| 2062 | * going faster than the target speed. Forward progress is |
| 2063 | * guaranteed by setting sata_spd_limit to target_limit above. |
| 2064 | */ |
| 2065 | if (plink->sata_spd > target) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2066 | ata_dev_info(dev, "applying link speed limit horkage to %s\n", |
| 2067 | sata_spd_string(target)); |
Tejun Heo | 9062712 | 2009-01-29 20:31:36 +0900 | [diff] [blame] | 2068 | return -EAGAIN; |
| 2069 | } |
| 2070 | return 0; |
| 2071 | } |
| 2072 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2073 | static inline u8 ata_dev_knobble(struct ata_device *dev) |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2074 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2075 | struct ata_port *ap = dev->link->ap; |
Jens Axboe | 9ce8e30 | 2008-08-27 15:23:18 +0200 | [diff] [blame] | 2076 | |
| 2077 | if (ata_dev_blacklisted(dev) & ATA_HORKAGE_BRIDGE_OK) |
| 2078 | return 0; |
| 2079 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2080 | return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2081 | } |
| 2082 | |
Hannes Reinecke | 5a23355 | 2016-04-25 12:45:46 +0200 | [diff] [blame] | 2083 | static void ata_dev_config_ncq_send_recv(struct ata_device *dev) |
| 2084 | { |
| 2085 | struct ata_port *ap = dev->link->ap; |
| 2086 | unsigned int err_mask; |
Hannes Reinecke | fe5af0c | 2016-04-25 12:45:48 +0200 | [diff] [blame] | 2087 | int log_index = ATA_LOG_NCQ_SEND_RECV * 2; |
| 2088 | u16 log_pages; |
Hannes Reinecke | 5a23355 | 2016-04-25 12:45:46 +0200 | [diff] [blame] | 2089 | |
Hannes Reinecke | fe5af0c | 2016-04-25 12:45:48 +0200 | [diff] [blame] | 2090 | err_mask = ata_read_log_page(dev, ATA_LOG_DIRECTORY, |
| 2091 | 0, ap->sector_buf, 1); |
| 2092 | if (err_mask) { |
| 2093 | ata_dev_dbg(dev, |
| 2094 | "failed to get Log Directory Emask 0x%x\n", |
| 2095 | err_mask); |
| 2096 | return; |
| 2097 | } |
| 2098 | log_pages = get_unaligned_le16(&ap->sector_buf[log_index]); |
| 2099 | if (!log_pages) { |
| 2100 | ata_dev_warn(dev, |
| 2101 | "NCQ Send/Recv Log not supported\n"); |
| 2102 | return; |
| 2103 | } |
Hannes Reinecke | 5a23355 | 2016-04-25 12:45:46 +0200 | [diff] [blame] | 2104 | err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_SEND_RECV, |
| 2105 | 0, ap->sector_buf, 1); |
| 2106 | if (err_mask) { |
| 2107 | ata_dev_dbg(dev, |
| 2108 | "failed to get NCQ Send/Recv Log Emask 0x%x\n", |
| 2109 | err_mask); |
| 2110 | } else { |
| 2111 | u8 *cmds = dev->ncq_send_recv_cmds; |
| 2112 | |
| 2113 | dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; |
| 2114 | memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE); |
| 2115 | |
| 2116 | if (dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) { |
| 2117 | ata_dev_dbg(dev, "disabling queued TRIM support\n"); |
| 2118 | cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &= |
| 2119 | ~ATA_LOG_NCQ_SEND_RECV_DSM_TRIM; |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | |
Hannes Reinecke | 284b3b7 | 2016-04-25 12:45:54 +0200 | [diff] [blame^] | 2124 | static void ata_dev_config_ncq_non_data(struct ata_device *dev) |
| 2125 | { |
| 2126 | struct ata_port *ap = dev->link->ap; |
| 2127 | unsigned int err_mask; |
| 2128 | int log_index = ATA_LOG_NCQ_NON_DATA * 2; |
| 2129 | u16 log_pages; |
| 2130 | |
| 2131 | err_mask = ata_read_log_page(dev, ATA_LOG_DIRECTORY, |
| 2132 | 0, ap->sector_buf, 1); |
| 2133 | if (err_mask) { |
| 2134 | ata_dev_dbg(dev, |
| 2135 | "failed to get Log Directory Emask 0x%x\n", |
| 2136 | err_mask); |
| 2137 | return; |
| 2138 | } |
| 2139 | log_pages = get_unaligned_le16(&ap->sector_buf[log_index]); |
| 2140 | if (!log_pages) { |
| 2141 | ata_dev_warn(dev, |
| 2142 | "NCQ Send/Recv Log not supported\n"); |
| 2143 | return; |
| 2144 | } |
| 2145 | err_mask = ata_read_log_page(dev, ATA_LOG_NCQ_NON_DATA, |
| 2146 | 0, ap->sector_buf, 1); |
| 2147 | if (err_mask) { |
| 2148 | ata_dev_dbg(dev, |
| 2149 | "failed to get NCQ Non-Data Log Emask 0x%x\n", |
| 2150 | err_mask); |
| 2151 | } else { |
| 2152 | u8 *cmds = dev->ncq_non_data_cmds; |
| 2153 | |
| 2154 | memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE); |
| 2155 | } |
| 2156 | } |
| 2157 | |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2158 | static int ata_dev_config_ncq(struct ata_device *dev, |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2159 | char *desc, size_t desc_sz) |
| 2160 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2161 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2162 | int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2163 | unsigned int err_mask; |
| 2164 | char *aa_desc = ""; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2165 | |
| 2166 | if (!ata_id_has_ncq(dev->id)) { |
| 2167 | desc[0] = '\0'; |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2168 | return 0; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2169 | } |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2170 | if (dev->horkage & ATA_HORKAGE_NONCQ) { |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 2171 | snprintf(desc, desc_sz, "NCQ (not used)"); |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2172 | return 0; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 2173 | } |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2174 | if (ap->flags & ATA_FLAG_NCQ) { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 2175 | hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2176 | dev->flags |= ATA_DFLAG_NCQ; |
| 2177 | } |
| 2178 | |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2179 | if (!(dev->horkage & ATA_HORKAGE_BROKEN_FPDMA_AA) && |
| 2180 | (ap->flags & ATA_FLAG_FPDMA_AA) && |
| 2181 | ata_id_has_fpdma_aa(dev->id)) { |
| 2182 | err_mask = ata_dev_set_feature(dev, SETFEATURES_SATA_ENABLE, |
| 2183 | SATA_FPDMA_AA); |
| 2184 | if (err_mask) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2185 | ata_dev_err(dev, |
| 2186 | "failed to enable AA (error_mask=0x%x)\n", |
| 2187 | err_mask); |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2188 | if (err_mask != AC_ERR_DEV) { |
| 2189 | dev->horkage |= ATA_HORKAGE_BROKEN_FPDMA_AA; |
| 2190 | return -EIO; |
| 2191 | } |
| 2192 | } else |
| 2193 | aa_desc = ", AA"; |
| 2194 | } |
| 2195 | |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2196 | if (hdepth >= ddepth) |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2197 | snprintf(desc, desc_sz, "NCQ (depth %d)%s", ddepth, aa_desc); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2198 | else |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2199 | snprintf(desc, desc_sz, "NCQ (depth %d/%d)%s", hdepth, |
| 2200 | ddepth, aa_desc); |
Marc Carino | ed36911 | 2013-08-24 23:22:50 -0700 | [diff] [blame] | 2201 | |
Hannes Reinecke | 284b3b7 | 2016-04-25 12:45:54 +0200 | [diff] [blame^] | 2202 | if ((ap->flags & ATA_FLAG_FPDMA_AUX)) { |
| 2203 | if (ata_id_has_ncq_send_and_recv(dev->id)) |
| 2204 | ata_dev_config_ncq_send_recv(dev); |
| 2205 | if (ata_id_has_ncq_non_data(dev->id)) |
| 2206 | ata_dev_config_ncq_non_data(dev); |
| 2207 | } |
Marc Carino | ed36911 | 2013-08-24 23:22:50 -0700 | [diff] [blame] | 2208 | |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2209 | return 0; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2210 | } |
| 2211 | |
Hannes Reinecke | e87fd28 | 2016-04-04 11:43:55 +0200 | [diff] [blame] | 2212 | static void ata_dev_config_sense_reporting(struct ata_device *dev) |
| 2213 | { |
| 2214 | unsigned int err_mask; |
| 2215 | |
| 2216 | if (!ata_id_has_sense_reporting(dev->id)) |
| 2217 | return; |
| 2218 | |
| 2219 | if (ata_id_sense_reporting_enabled(dev->id)) |
| 2220 | return; |
| 2221 | |
| 2222 | err_mask = ata_dev_set_feature(dev, SETFEATURE_SENSE_DATA, 0x1); |
| 2223 | if (err_mask) { |
| 2224 | ata_dev_dbg(dev, |
| 2225 | "failed to enable Sense Data Reporting, Emask 0x%x\n", |
| 2226 | err_mask); |
| 2227 | } |
| 2228 | } |
| 2229 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 2230 | /** |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2231 | * ata_dev_configure - Configure the specified ATA/ATAPI device |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2232 | * @dev: Target device to configure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | * |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2234 | * Configure @dev according to @dev->id. Generic and low-level |
| 2235 | * driver specific fixups are also applied. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | * |
| 2237 | * LOCKING: |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2238 | * Kernel thread context (may sleep) |
| 2239 | * |
| 2240 | * RETURNS: |
| 2241 | * 0 on success, -errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | */ |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 2243 | int ata_dev_configure(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2245 | struct ata_port *ap = dev->link->ap; |
| 2246 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2247 | int print_info = ehc->i.flags & ATA_EHI_PRINTINFO; |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2248 | const u16 *id = dev->id; |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 2249 | unsigned long xfer_mask; |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 2250 | unsigned int err_mask; |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2251 | char revbuf[7]; /* XYZ-99\0 */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2252 | char fwrevbuf[ATA_ID_FW_REV_LEN+1]; |
| 2253 | char modelbuf[ATA_ID_PROD_LEN+1]; |
Brian King | e6d902a | 2006-06-28 08:30:31 -0500 | [diff] [blame] | 2254 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2256 | if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2257 | ata_dev_info(dev, "%s: ENTER/EXIT -- nodev\n", __func__); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2258 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2261 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2262 | ata_dev_dbg(dev, "%s: ENTER\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2264 | /* set horkage */ |
| 2265 | dev->horkage |= ata_dev_blacklisted(dev); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 2266 | ata_force_horkage(dev); |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2267 | |
Tejun Heo | 50af2fa | 2008-05-19 01:15:14 +0900 | [diff] [blame] | 2268 | if (dev->horkage & ATA_HORKAGE_DISABLE) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2269 | ata_dev_info(dev, "unsupported device, disabling\n"); |
Tejun Heo | 50af2fa | 2008-05-19 01:15:14 +0900 | [diff] [blame] | 2270 | ata_dev_disable(dev); |
| 2271 | return 0; |
| 2272 | } |
| 2273 | |
Tejun Heo | 2486fa5 | 2008-07-31 07:52:40 +0900 | [diff] [blame] | 2274 | if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) && |
| 2275 | dev->class == ATA_DEV_ATAPI) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2276 | ata_dev_warn(dev, "WARNING: ATAPI is %s, device ignored\n", |
| 2277 | atapi_enabled ? "not supported with this driver" |
| 2278 | : "disabled"); |
Tejun Heo | 2486fa5 | 2008-07-31 07:52:40 +0900 | [diff] [blame] | 2279 | ata_dev_disable(dev); |
| 2280 | return 0; |
| 2281 | } |
| 2282 | |
Tejun Heo | 9062712 | 2009-01-29 20:31:36 +0900 | [diff] [blame] | 2283 | rc = ata_do_link_spd_horkage(dev); |
| 2284 | if (rc) |
| 2285 | return rc; |
| 2286 | |
Tejun Heo | ecd75ad | 2014-01-16 09:47:17 -0500 | [diff] [blame] | 2287 | /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */ |
| 2288 | if ((dev->horkage & ATA_HORKAGE_WD_BROKEN_LPM) && |
| 2289 | (id[ATA_ID_SATA_CAPABILITY] & 0xe) == 0x2) |
| 2290 | dev->horkage |= ATA_HORKAGE_NOLPM; |
| 2291 | |
| 2292 | if (dev->horkage & ATA_HORKAGE_NOLPM) { |
| 2293 | ata_dev_warn(dev, "LPM support broken, forcing max_power\n"); |
| 2294 | dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER; |
| 2295 | } |
| 2296 | |
Tejun Heo | 6746544 | 2007-05-15 03:28:16 +0900 | [diff] [blame] | 2297 | /* let ACPI work its magic */ |
| 2298 | rc = ata_acpi_on_devcfg(dev); |
| 2299 | if (rc) |
| 2300 | return rc; |
Kristen Carlson Accardi | 08573a8 | 2006-11-10 16:14:47 -0800 | [diff] [blame] | 2301 | |
Tejun Heo | 05027ad | 2007-09-03 12:32:57 +0900 | [diff] [blame] | 2302 | /* massage HPA, do it early as it might change IDENTIFY data */ |
| 2303 | rc = ata_hpa_resize(dev); |
| 2304 | if (rc) |
| 2305 | return rc; |
| 2306 | |
Tejun Heo | c39f5eb | 2006-03-13 19:51:19 +0900 | [diff] [blame] | 2307 | /* print device capabilities */ |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2308 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2309 | ata_dev_dbg(dev, |
| 2310 | "%s: cfg 49:%04x 82:%04x 83:%04x 84:%04x " |
| 2311 | "85:%04x 86:%04x 87:%04x 88:%04x\n", |
| 2312 | __func__, |
| 2313 | id[49], id[82], id[83], id[84], |
| 2314 | id[85], id[86], id[87], id[88]); |
Tejun Heo | c39f5eb | 2006-03-13 19:51:19 +0900 | [diff] [blame] | 2315 | |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2316 | /* initialize to-be-configured parameters */ |
Tejun Heo | ea1dd4e | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 2317 | dev->flags &= ~ATA_DFLAG_CFG_MASK; |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2318 | dev->max_sectors = 0; |
| 2319 | dev->cdb_len = 0; |
| 2320 | dev->n_sectors = 0; |
| 2321 | dev->cylinders = 0; |
| 2322 | dev->heads = 0; |
| 2323 | dev->sectors = 0; |
Mark Lord | e18086d | 2009-03-19 13:32:21 -0400 | [diff] [blame] | 2324 | dev->multi_count = 0; |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | /* |
| 2327 | * common ATA, ATAPI feature tests |
| 2328 | */ |
| 2329 | |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 2330 | /* find max transfer mode; for printk only */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2331 | xfer_mask = ata_id_xfermask(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2333 | if (ata_msg_probe(ap)) |
| 2334 | ata_dump_id(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | |
Albert Lee | ef143d5 | 2007-06-05 13:01:33 +0800 | [diff] [blame] | 2336 | /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ |
| 2337 | ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, |
| 2338 | sizeof(fwrevbuf)); |
| 2339 | |
| 2340 | ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, |
| 2341 | sizeof(modelbuf)); |
| 2342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | /* ATA-specific feature tests */ |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 2344 | if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2345 | if (ata_id_is_cfa(id)) { |
Sergei Shtylyov | 62afe5d | 2009-04-13 20:50:00 +0400 | [diff] [blame] | 2346 | /* CPRM may make this media unusable */ |
| 2347 | if (id[ATA_ID_CFA_KEY_MGMT] & 1) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2348 | ata_dev_warn(dev, |
| 2349 | "supports DRM functions and may not be fully accessible\n"); |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2350 | snprintf(revbuf, 7, "CFA"); |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 2351 | } else { |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 2352 | snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 2353 | /* Warn the user if the device has TPM extensions */ |
| 2354 | if (ata_id_has_tpm(id)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2355 | ata_dev_warn(dev, |
| 2356 | "supports DRM functions and may not be fully accessible\n"); |
Alan Cox | ae8d4ee | 2007-11-04 22:05:49 -0500 | [diff] [blame] | 2357 | } |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2358 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2359 | dev->n_sectors = ata_id_n_sectors(id); |
Tejun Heo | 2940740 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 2360 | |
Mark Lord | e18086d | 2009-03-19 13:32:21 -0400 | [diff] [blame] | 2361 | /* get current R/W Multiple count setting */ |
| 2362 | if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) { |
| 2363 | unsigned int max = dev->id[47] & 0xff; |
| 2364 | unsigned int cnt = dev->id[59] & 0xff; |
| 2365 | /* only recognize/allow powers of two here */ |
| 2366 | if (is_power_of_2(max) && is_power_of_2(cnt)) |
| 2367 | if (cnt <= max) |
| 2368 | dev->multi_count = cnt; |
| 2369 | } |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2370 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2371 | if (ata_id_has_lba(id)) { |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2372 | const char *lba_desc; |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2373 | char ncq_desc[24]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2374 | |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2375 | lba_desc = "LBA"; |
| 2376 | dev->flags |= ATA_DFLAG_LBA; |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2377 | if (ata_id_has_lba48(id)) { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2378 | dev->flags |= ATA_DFLAG_LBA48; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2379 | lba_desc = "LBA48"; |
Tejun Heo | 6fc49ad | 2006-11-11 20:10:45 +0900 | [diff] [blame] | 2380 | |
| 2381 | if (dev->n_sectors >= (1UL << 28) && |
| 2382 | ata_id_has_flush_ext(id)) |
| 2383 | dev->flags |= ATA_DFLAG_FLUSH_EXT; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2384 | } |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2385 | |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2386 | /* config NCQ */ |
Shaohua Li | 388539f | 2009-07-27 09:24:35 +0800 | [diff] [blame] | 2387 | rc = ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); |
| 2388 | if (rc) |
| 2389 | return rc; |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 2390 | |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2391 | /* print device info to dmesg */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2392 | if (ata_msg_drv(ap) && print_info) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2393 | ata_dev_info(dev, "%s: %s, %s, max %s\n", |
| 2394 | revbuf, modelbuf, fwrevbuf, |
| 2395 | ata_mode_string(xfer_mask)); |
| 2396 | ata_dev_info(dev, |
| 2397 | "%llu sectors, multi %u: %s %s\n", |
Tejun Heo | f15a1da | 2006-05-15 20:57:56 +0900 | [diff] [blame] | 2398 | (unsigned long long)dev->n_sectors, |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2399 | dev->multi_count, lba_desc, ncq_desc); |
| 2400 | } |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2401 | } else { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2402 | /* CHS */ |
| 2403 | |
| 2404 | /* Default translation */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2405 | dev->cylinders = id[1]; |
| 2406 | dev->heads = id[3]; |
| 2407 | dev->sectors = id[6]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2408 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2409 | if (ata_id_current_chs_valid(id)) { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2410 | /* Current CHS translation is valid. */ |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2411 | dev->cylinders = id[54]; |
| 2412 | dev->heads = id[55]; |
| 2413 | dev->sectors = id[56]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | /* print device info to dmesg */ |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2417 | if (ata_msg_drv(ap) && print_info) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2418 | ata_dev_info(dev, "%s: %s, %s, max %s\n", |
| 2419 | revbuf, modelbuf, fwrevbuf, |
| 2420 | ata_mode_string(xfer_mask)); |
| 2421 | ata_dev_info(dev, |
| 2422 | "%llu sectors, multi %u, CHS %u/%u/%u\n", |
| 2423 | (unsigned long long)dev->n_sectors, |
| 2424 | dev->multi_count, dev->cylinders, |
| 2425 | dev->heads, dev->sectors); |
Eric D. Mudama | 3f64f56 | 2007-01-30 23:00:40 -0700 | [diff] [blame] | 2426 | } |
Albert Lee | 07f6f7d | 2005-11-01 19:33:20 +0800 | [diff] [blame] | 2427 | } |
| 2428 | |
Shane Huang | 803739d | 2012-12-17 23:18:59 +0800 | [diff] [blame] | 2429 | /* Check and mark DevSlp capability. Get DevSlp timing variables |
| 2430 | * from SATA Settings page of Identify Device Data Log. |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 2431 | */ |
Shane Huang | 803739d | 2012-12-17 23:18:59 +0800 | [diff] [blame] | 2432 | if (ata_id_has_devslp(dev->id)) { |
David Woodhouse | 8e725c7 | 2013-03-29 11:54:55 +0000 | [diff] [blame] | 2433 | u8 *sata_setting = ap->sector_buf; |
Shane Huang | 803739d | 2012-12-17 23:18:59 +0800 | [diff] [blame] | 2434 | int i, j; |
| 2435 | |
| 2436 | dev->flags |= ATA_DFLAG_DEVSLP; |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 2437 | err_mask = ata_read_log_page(dev, |
| 2438 | ATA_LOG_SATA_ID_DEV_DATA, |
| 2439 | ATA_LOG_SATA_SETTINGS, |
Shane Huang | 803739d | 2012-12-17 23:18:59 +0800 | [diff] [blame] | 2440 | sata_setting, |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 2441 | 1); |
| 2442 | if (err_mask) |
| 2443 | ata_dev_dbg(dev, |
| 2444 | "failed to get Identify Device Data, Emask 0x%x\n", |
| 2445 | err_mask); |
Shane Huang | 803739d | 2012-12-17 23:18:59 +0800 | [diff] [blame] | 2446 | else |
| 2447 | for (i = 0; i < ATA_LOG_DEVSLP_SIZE; i++) { |
| 2448 | j = ATA_LOG_DEVSLP_OFFSET + i; |
| 2449 | dev->devslp_timing[i] = sata_setting[j]; |
| 2450 | } |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 2451 | } |
Hannes Reinecke | e87fd28 | 2016-04-04 11:43:55 +0200 | [diff] [blame] | 2452 | ata_dev_config_sense_reporting(dev); |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 2453 | dev->cdb_len = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | /* ATAPI-specific feature tests */ |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 2457 | else if (dev->class == ATA_DEV_ATAPI) { |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2458 | const char *cdb_intr_string = ""; |
| 2459 | const char *atapi_an_string = ""; |
Tejun Heo | 9116300 | 2008-02-21 13:25:50 +0900 | [diff] [blame] | 2460 | const char *dma_dir_string = ""; |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2461 | u32 sntf; |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2462 | |
Tejun Heo | 1148c3a | 2006-03-13 19:48:04 +0900 | [diff] [blame] | 2463 | rc = atapi_cdb_len(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | if ((rc < 12) || (rc > ATAPI_CDB_LEN)) { |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2465 | if (ata_msg_warn(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2466 | ata_dev_warn(dev, "unsupported CDB len\n"); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2467 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | goto err_out_nosup; |
| 2469 | } |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 2470 | dev->cdb_len = (unsigned int) rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2472 | /* Enable ATAPI AN if both the host and device have |
| 2473 | * the support. If PMP is attached, SNTF is required |
| 2474 | * to enable ATAPI AN to discern between PHY status |
| 2475 | * changed notifications and ATAPI ANs. |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2476 | */ |
Tejun Heo | e7ecd43 | 2010-05-19 15:38:58 +0200 | [diff] [blame] | 2477 | if (atapi_an && |
| 2478 | (ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && |
Tejun Heo | 071f44b | 2008-04-07 22:47:22 +0900 | [diff] [blame] | 2479 | (!sata_pmp_attached(ap) || |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 2480 | sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2481 | /* issue SET feature command to turn this on */ |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 2482 | err_mask = ata_dev_set_feature(dev, |
| 2483 | SETFEATURES_SATA_ENABLE, SATA_AN); |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2484 | if (err_mask) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2485 | ata_dev_err(dev, |
| 2486 | "failed to enable ATAPI AN (err_mask=0x%x)\n", |
| 2487 | err_mask); |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2488 | else { |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2489 | dev->flags |= ATA_DFLAG_AN; |
Tejun Heo | 854c73a | 2007-09-23 13:14:11 +0900 | [diff] [blame] | 2490 | atapi_an_string = ", ATAPI AN"; |
| 2491 | } |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 2492 | } |
| 2493 | |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2494 | if (ata_id_cdb_intr(dev->id)) { |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 2495 | dev->flags |= ATA_DFLAG_CDB_INTR; |
Albert Lee | 08a556d | 2006-03-31 13:29:04 +0800 | [diff] [blame] | 2496 | cdb_intr_string = ", CDB intr"; |
| 2497 | } |
Albert Lee | 312f7da | 2005-09-27 17:38:03 +0800 | [diff] [blame] | 2498 | |
Vincent Pelletier | 966fbe1 | 2013-05-21 22:30:58 +0200 | [diff] [blame] | 2499 | if (atapi_dmadir || (dev->horkage & ATA_HORKAGE_ATAPI_DMADIR) || atapi_id_dmadir(dev->id)) { |
Tejun Heo | 9116300 | 2008-02-21 13:25:50 +0900 | [diff] [blame] | 2500 | dev->flags |= ATA_DFLAG_DMADIR; |
| 2501 | dma_dir_string = ", DMADIR"; |
| 2502 | } |
| 2503 | |
Aaron Lu | afe7595 | 2013-01-15 17:20:58 +0800 | [diff] [blame] | 2504 | if (ata_id_has_da(dev->id)) { |
Lin Ming | b1354cb | 2012-06-25 16:13:08 +0800 | [diff] [blame] | 2505 | dev->flags |= ATA_DFLAG_DA; |
Aaron Lu | afe7595 | 2013-01-15 17:20:58 +0800 | [diff] [blame] | 2506 | zpodd_init(dev); |
| 2507 | } |
Lin Ming | b1354cb | 2012-06-25 16:13:08 +0800 | [diff] [blame] | 2508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | /* print device info to dmesg */ |
Borislav Petkov | 5afc814 | 2006-06-27 14:51:25 +0200 | [diff] [blame] | 2510 | if (ata_msg_drv(ap) && print_info) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2511 | ata_dev_info(dev, |
| 2512 | "ATAPI: %s, %s, max %s%s%s%s\n", |
| 2513 | modelbuf, fwrevbuf, |
| 2514 | ata_mode_string(xfer_mask), |
| 2515 | cdb_intr_string, atapi_an_string, |
| 2516 | dma_dir_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Tejun Heo | 914ed35 | 2006-11-01 18:39:55 +0900 | [diff] [blame] | 2519 | /* determine max_sectors */ |
| 2520 | dev->max_sectors = ATA_MAX_SECTORS; |
| 2521 | if (dev->flags & ATA_DFLAG_LBA48) |
| 2522 | dev->max_sectors = ATA_MAX_SECTORS_LBA48; |
| 2523 | |
Alan Cox | c5038fc | 2007-10-25 14:21:16 +0100 | [diff] [blame] | 2524 | /* Limit PATA drive on SATA cable bridge transfers to udma5, |
| 2525 | 200 sectors */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2526 | if (ata_dev_knobble(dev)) { |
Borislav Petkov | 5afc814 | 2006-06-27 14:51:25 +0200 | [diff] [blame] | 2527 | if (ata_msg_drv(ap) && print_info) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2528 | ata_dev_info(dev, "applying bridge limits\n"); |
Tejun Heo | 5a52913 | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 2529 | dev->udma_mask &= ATA_UDMA5; |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2530 | dev->max_sectors = ATA_MAX_SECTORS; |
| 2531 | } |
| 2532 | |
Tony Battersby | f8d8e57 | 2007-10-30 11:44:35 -0400 | [diff] [blame] | 2533 | if ((dev->class == ATA_DEV_ATAPI) && |
Albert Lee | f442cd8 | 2007-11-15 10:35:47 +0900 | [diff] [blame] | 2534 | (atapi_command_packet_set(id) == TYPE_TAPE)) { |
Tony Battersby | f8d8e57 | 2007-10-30 11:44:35 -0400 | [diff] [blame] | 2535 | dev->max_sectors = ATA_MAX_SECTORS_TAPE; |
Albert Lee | f442cd8 | 2007-11-15 10:35:47 +0900 | [diff] [blame] | 2536 | dev->horkage |= ATA_HORKAGE_STUCK_ERR; |
| 2537 | } |
Tony Battersby | f8d8e57 | 2007-10-30 11:44:35 -0400 | [diff] [blame] | 2538 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 2539 | if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) |
Tejun Heo | 03ec52d | 2007-04-12 13:38:11 +0900 | [diff] [blame] | 2540 | dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, |
| 2541 | dev->max_sectors); |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 2542 | |
David Milburn | af34d63 | 2015-07-13 11:48:23 -0500 | [diff] [blame] | 2543 | if (dev->horkage & ATA_HORKAGE_MAX_SEC_1024) |
| 2544 | dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_1024, |
| 2545 | dev->max_sectors); |
| 2546 | |
Shan Hai | a32450e | 2013-03-18 10:30:44 +0800 | [diff] [blame] | 2547 | if (dev->horkage & ATA_HORKAGE_MAX_SEC_LBA48) |
| 2548 | dev->max_sectors = ATA_MAX_SECTORS_LBA48; |
| 2549 | |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2550 | if (ap->ops->dev_config) |
Alan | cd0d3bb | 2007-03-02 00:56:15 +0000 | [diff] [blame] | 2551 | ap->ops->dev_config(dev); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2552 | |
Alan Cox | c5038fc | 2007-10-25 14:21:16 +0100 | [diff] [blame] | 2553 | if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { |
| 2554 | /* Let the user know. We don't want to disallow opens for |
| 2555 | rescue purposes, or in case the vendor is just a blithering |
| 2556 | idiot. Do this after the dev_config call as some controllers |
| 2557 | with buggy firmware may want to avoid reporting false device |
| 2558 | bugs */ |
| 2559 | |
| 2560 | if (print_info) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2561 | ata_dev_warn(dev, |
Alan Cox | c5038fc | 2007-10-25 14:21:16 +0100 | [diff] [blame] | 2562 | "Drive reports diagnostics failure. This may indicate a drive\n"); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2563 | ata_dev_warn(dev, |
Alan Cox | c5038fc | 2007-10-25 14:21:16 +0100 | [diff] [blame] | 2564 | "fault or invalid emulation. Contact drive vendor for information.\n"); |
| 2565 | } |
| 2566 | } |
| 2567 | |
Tejun Heo | ac70a96 | 2008-11-27 13:36:48 +0900 | [diff] [blame] | 2568 | if ((dev->horkage & ATA_HORKAGE_FIRMWARE_WARN) && print_info) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2569 | ata_dev_warn(dev, "WARNING: device requires firmware update to be fully functional\n"); |
| 2570 | ata_dev_warn(dev, " contact the vendor or visit http://ata.wiki.kernel.org\n"); |
Tejun Heo | ac70a96 | 2008-11-27 13:36:48 +0900 | [diff] [blame] | 2571 | } |
| 2572 | |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2573 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | |
| 2575 | err_out_nosup: |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 2576 | if (ata_msg_probe(ap)) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2577 | ata_dev_dbg(dev, "%s: EXIT, err\n", __func__); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2578 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | /** |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2582 | * ata_cable_40wire - return 40 wire cable type |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2583 | * @ap: port |
| 2584 | * |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2585 | * Helper method for drivers which want to hardwire 40 wire cable |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2586 | * detection. |
| 2587 | */ |
| 2588 | |
| 2589 | int ata_cable_40wire(struct ata_port *ap) |
| 2590 | { |
| 2591 | return ATA_CBL_PATA40; |
| 2592 | } |
| 2593 | |
| 2594 | /** |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2595 | * ata_cable_80wire - return 80 wire cable type |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2596 | * @ap: port |
| 2597 | * |
Alan Cox | 2e41e8e | 2007-03-08 23:19:19 +0000 | [diff] [blame] | 2598 | * Helper method for drivers which want to hardwire 80 wire cable |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2599 | * detection. |
| 2600 | */ |
| 2601 | |
| 2602 | int ata_cable_80wire(struct ata_port *ap) |
| 2603 | { |
| 2604 | return ATA_CBL_PATA80; |
| 2605 | } |
| 2606 | |
| 2607 | /** |
| 2608 | * ata_cable_unknown - return unknown PATA cable. |
| 2609 | * @ap: port |
| 2610 | * |
| 2611 | * Helper method for drivers which have no PATA cable detection. |
| 2612 | */ |
| 2613 | |
| 2614 | int ata_cable_unknown(struct ata_port *ap) |
| 2615 | { |
| 2616 | return ATA_CBL_PATA_UNK; |
| 2617 | } |
| 2618 | |
| 2619 | /** |
Tejun Heo | c88f90c | 2007-11-27 19:43:48 +0900 | [diff] [blame] | 2620 | * ata_cable_ignore - return ignored PATA cable. |
| 2621 | * @ap: port |
| 2622 | * |
| 2623 | * Helper method for drivers which don't use cable type to limit |
| 2624 | * transfer mode. |
| 2625 | */ |
| 2626 | int ata_cable_ignore(struct ata_port *ap) |
| 2627 | { |
| 2628 | return ATA_CBL_PATA_IGN; |
| 2629 | } |
| 2630 | |
| 2631 | /** |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2632 | * ata_cable_sata - return SATA cable type |
| 2633 | * @ap: port |
| 2634 | * |
| 2635 | * Helper method for drivers which have SATA cables |
| 2636 | */ |
| 2637 | |
| 2638 | int ata_cable_sata(struct ata_port *ap) |
| 2639 | { |
| 2640 | return ATA_CBL_SATA; |
| 2641 | } |
| 2642 | |
| 2643 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | * ata_bus_probe - Reset and probe ATA bus |
| 2645 | * @ap: Bus to probe |
| 2646 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2647 | * Master ATA bus probing function. Initiates a hardware-dependent |
| 2648 | * bus reset, then attempts to identify any devices found on |
| 2649 | * the bus. |
| 2650 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2652 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | * |
| 2654 | * RETURNS: |
Tejun Heo | 96072e6 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2655 | * Zero on success, negative errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | */ |
| 2657 | |
Brian King | 8028916 | 2006-08-07 14:27:31 -0500 | [diff] [blame] | 2658 | int ata_bus_probe(struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | { |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2660 | unsigned int classes[ATA_MAX_DEVICES]; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2661 | int tries[ATA_MAX_DEVICES]; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2662 | int rc; |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2663 | struct ata_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2665 | ata_for_each_dev(dev, &ap->link, ALL) |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2666 | tries[dev->devno] = ATA_PROBE_MAX_TRIES; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2667 | |
| 2668 | retry: |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2669 | ata_for_each_dev(dev, &ap->link, ALL) { |
Tejun Heo | cdeab11 | 2007-10-29 16:41:09 +0900 | [diff] [blame] | 2670 | /* If we issue an SRST then an ATA drive (not ATAPI) |
| 2671 | * may change configuration and be in PIO0 timing. If |
| 2672 | * we do a hard reset (or are coming from power on) |
| 2673 | * this is true for ATA or ATAPI. Until we've set a |
| 2674 | * suitable controller mode we should not touch the |
| 2675 | * bus as we may be talking too fast. |
| 2676 | */ |
| 2677 | dev->pio_mode = XFER_PIO_0; |
Aaron Lu | 5416912 | 2012-12-03 11:35:02 +0800 | [diff] [blame] | 2678 | dev->dma_mode = 0xff; |
Tejun Heo | cdeab11 | 2007-10-29 16:41:09 +0900 | [diff] [blame] | 2679 | |
| 2680 | /* If the controller has a pio mode setup function |
| 2681 | * then use it to set the chipset to rights. Don't |
| 2682 | * touch the DMA setup as that will be dealt with when |
| 2683 | * configuring devices. |
| 2684 | */ |
| 2685 | if (ap->ops->set_piomode) |
| 2686 | ap->ops->set_piomode(ap, dev); |
| 2687 | } |
| 2688 | |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2689 | /* reset and determine device classes */ |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2690 | ap->ops->phy_reset(ap); |
Tejun Heo | 2061a47 | 2006-03-12 00:57:39 +0900 | [diff] [blame] | 2691 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2692 | ata_for_each_dev(dev, &ap->link, ALL) { |
Tejun Heo | 3e4ec34 | 2010-05-10 21:41:30 +0200 | [diff] [blame] | 2693 | if (dev->class != ATA_DEV_UNKNOWN) |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2694 | classes[dev->devno] = dev->class; |
| 2695 | else |
| 2696 | classes[dev->devno] = ATA_DEV_NONE; |
Tejun Heo | 2044470 | 2006-03-13 01:57:01 +0900 | [diff] [blame] | 2697 | |
Tejun Heo | 52783c5 | 2006-05-31 18:28:22 +0900 | [diff] [blame] | 2698 | dev->class = ATA_DEV_UNKNOWN; |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 2699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2701 | /* read IDENTIFY page and configure devices. We have to do the identify |
| 2702 | specific sequence bass-ackwards so that PDIAG- is released by |
| 2703 | the slave device */ |
| 2704 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2705 | ata_for_each_dev(dev, &ap->link, ALL_REVERSE) { |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2706 | if (tries[dev->devno]) |
| 2707 | dev->class = classes[dev->devno]; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2708 | |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2709 | if (!ata_dev_enabled(dev)) |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 2710 | continue; |
| 2711 | |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 2712 | rc = ata_dev_read_id(dev, &dev->class, ATA_READID_POSTRESET, |
| 2713 | dev->id); |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2714 | if (rc) |
| 2715 | goto fail; |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2716 | } |
| 2717 | |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 2718 | /* Now ask for the cable type as PDIAG- should have been released */ |
| 2719 | if (ap->ops->cable_detect) |
| 2720 | ap->cbl = ap->ops->cable_detect(ap); |
| 2721 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2722 | /* We may have SATA bridge glue hiding here irrespective of |
| 2723 | * the reported cable types and sensed types. When SATA |
| 2724 | * drives indicate we have a bridge, we don't know which end |
| 2725 | * of the link the bridge is which is a problem. |
| 2726 | */ |
| 2727 | ata_for_each_dev(dev, &ap->link, ENABLED) |
Alan Cox | 614fe29 | 2007-08-22 23:22:45 +0100 | [diff] [blame] | 2728 | if (ata_id_is_sata(dev->id)) |
| 2729 | ap->cbl = ATA_CBL_SATA; |
Alan Cox | 614fe29 | 2007-08-22 23:22:45 +0100 | [diff] [blame] | 2730 | |
Jeff Garzik | f31f0cc | 2007-03-02 17:47:28 -0500 | [diff] [blame] | 2731 | /* After the identify sequence we can now set up the devices. We do |
| 2732 | this in the normal order so that the user doesn't get confused */ |
| 2733 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2734 | ata_for_each_dev(dev, &ap->link, ENABLED) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2735 | ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO; |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 2736 | rc = ata_dev_configure(dev); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2737 | ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2738 | if (rc) |
| 2739 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2742 | /* configure transfer mode */ |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2743 | rc = ata_set_mode(&ap->link, &dev); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2744 | if (rc) |
Tejun Heo | 51713d3 | 2006-04-11 22:26:29 +0900 | [diff] [blame] | 2745 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 2747 | ata_for_each_dev(dev, &ap->link, ENABLED) |
| 2748 | return 0; |
Alan Cox | e35a9e0 | 2006-03-27 18:46:37 +0100 | [diff] [blame] | 2749 | |
Tejun Heo | 96072e6 | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 2750 | return -ENODEV; |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2751 | |
| 2752 | fail: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2753 | tries[dev->devno]--; |
| 2754 | |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2755 | switch (rc) { |
| 2756 | case -EINVAL: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2757 | /* eeek, something went very wrong, give up */ |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2758 | tries[dev->devno] = 0; |
| 2759 | break; |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2760 | |
| 2761 | case -ENODEV: |
| 2762 | /* give it just one more chance */ |
| 2763 | tries[dev->devno] = min(tries[dev->devno], 1); |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2764 | case -EIO: |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2765 | if (tries[dev->devno] == 1) { |
| 2766 | /* This is the last chance, better to slow |
| 2767 | * down than lose it. |
| 2768 | */ |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2769 | sata_down_spd_limit(&ap->link, 0); |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2770 | ata_down_xfermask_limit(dev, ATA_DNXFER_PIO); |
| 2771 | } |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2772 | } |
| 2773 | |
Tejun Heo | 4ae72a1 | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 2774 | if (!tries[dev->devno]) |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2775 | ata_dev_disable(dev); |
Tejun Heo | ec57375 | 2006-04-11 22:26:29 +0900 | [diff] [blame] | 2776 | |
Tejun Heo | 14d2bac | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 2777 | goto retry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | /** |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2781 | * sata_print_link_status - Print SATA link status |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2782 | * @link: SATA link to printk link status about |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2783 | * |
| 2784 | * This function prints link speed and status of a SATA link. |
| 2785 | * |
| 2786 | * LOCKING: |
| 2787 | * None. |
| 2788 | */ |
Adrian Bunk | 6bdb4fc | 2008-04-21 11:51:11 +0300 | [diff] [blame] | 2789 | static void sata_print_link_status(struct ata_link *link) |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2790 | { |
Tejun Heo | 6d5f973 | 2006-04-03 00:09:41 +0900 | [diff] [blame] | 2791 | u32 sstatus, scontrol, tmp; |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2792 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2793 | if (sata_scr_read(link, SCR_STATUS, &sstatus)) |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2794 | return; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2795 | sata_scr_read(link, SCR_CONTROL, &scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2796 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 2797 | if (ata_phys_link_online(link)) { |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2798 | tmp = (sstatus >> 4) & 0xf; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2799 | ata_link_info(link, "SATA link up %s (SStatus %X SControl %X)\n", |
| 2800 | sata_spd_string(tmp), sstatus, scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2801 | } else { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2802 | ata_link_info(link, "SATA link down (SStatus %X SControl %X)\n", |
| 2803 | sstatus, scontrol); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | |
| 2807 | /** |
Alan Cox | ebdfca6e | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2808 | * ata_dev_pair - return other device on cable |
Alan Cox | ebdfca6e | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2809 | * @adev: device |
| 2810 | * |
| 2811 | * Obtain the other device on the same cable, or if none is |
| 2812 | * present NULL is returned |
| 2813 | */ |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 2814 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 2815 | struct ata_device *ata_dev_pair(struct ata_device *adev) |
Alan Cox | ebdfca6e | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2816 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 2817 | struct ata_link *link = adev->link; |
| 2818 | struct ata_device *pair = &link->device[1 - adev->devno]; |
Tejun Heo | e1211e3 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 2819 | if (!ata_dev_enabled(pair)) |
Alan Cox | ebdfca6e | 2006-03-23 15:38:34 +0000 | [diff] [blame] | 2820 | return NULL; |
| 2821 | return pair; |
| 2822 | } |
| 2823 | |
| 2824 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2825 | * sata_down_spd_limit - adjust SATA spd limit downward |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2826 | * @link: Link to adjust SATA spd limit for |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2827 | * @spd_limit: Additional limit |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2828 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2829 | * Adjust SATA spd limit of @link downward. Note that this |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2830 | * function only adjusts the limit. The change must be applied |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2831 | * using sata_set_spd(). |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2832 | * |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2833 | * If @spd_limit is non-zero, the speed is limited to equal to or |
| 2834 | * lower than @spd_limit if such speed is supported. If |
| 2835 | * @spd_limit is slower than any supported speed, only the lowest |
| 2836 | * supported speed is allowed. |
| 2837 | * |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2838 | * LOCKING: |
| 2839 | * Inherited from caller. |
| 2840 | * |
| 2841 | * RETURNS: |
| 2842 | * 0 on success, negative errno on failure |
| 2843 | */ |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2844 | int sata_down_spd_limit(struct ata_link *link, u32 spd_limit) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2845 | { |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2846 | u32 sstatus, spd, mask; |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2847 | int rc, bit; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2848 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2849 | if (!sata_scr_valid(link)) |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2850 | return -EOPNOTSUPP; |
| 2851 | |
| 2852 | /* If SCR can be read, use it to determine the current SPD. |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2853 | * If not, use cached value in link->sata_spd. |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2854 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2855 | rc = sata_scr_read(link, SCR_STATUS, &sstatus); |
Tejun Heo | 9913ff8a | 2009-01-29 20:31:31 +0900 | [diff] [blame] | 2856 | if (rc == 0 && ata_sstatus_online(sstatus)) |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2857 | spd = (sstatus >> 4) & 0xf; |
| 2858 | else |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2859 | spd = link->sata_spd; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2860 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2861 | mask = link->sata_spd_limit; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2862 | if (mask <= 1) |
| 2863 | return -EINVAL; |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2864 | |
| 2865 | /* unconditionally mask off the highest bit */ |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2866 | bit = fls(mask) - 1; |
| 2867 | mask &= ~(1 << bit); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2868 | |
Tejun Heo | 008a789 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 2869 | /* Mask off all speeds higher than or equal to the current |
| 2870 | * one. Force 1.5Gbps if current SPD is not available. |
| 2871 | */ |
| 2872 | if (spd > 1) |
| 2873 | mask &= (1 << (spd - 1)) - 1; |
| 2874 | else |
| 2875 | mask &= 1; |
| 2876 | |
| 2877 | /* were we already at the bottom? */ |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2878 | if (!mask) |
| 2879 | return -EINVAL; |
| 2880 | |
Tejun Heo | a07d499 | 2009-01-29 20:31:33 +0900 | [diff] [blame] | 2881 | if (spd_limit) { |
| 2882 | if (mask & ((1 << spd_limit) - 1)) |
| 2883 | mask &= (1 << spd_limit) - 1; |
| 2884 | else { |
| 2885 | bit = ffs(mask) - 1; |
| 2886 | mask = 1 << bit; |
| 2887 | } |
| 2888 | } |
| 2889 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2890 | link->sata_spd_limit = mask; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2891 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 2892 | ata_link_warn(link, "limiting SATA link speed to %s\n", |
| 2893 | sata_spd_string(fls(mask))); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2894 | |
| 2895 | return 0; |
| 2896 | } |
| 2897 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2898 | static int __sata_set_spd_needed(struct ata_link *link, u32 *scontrol) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2899 | { |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2900 | struct ata_link *host_link = &link->ap->link; |
| 2901 | u32 limit, target, spd; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2902 | |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2903 | limit = link->sata_spd_limit; |
| 2904 | |
| 2905 | /* Don't configure downstream link faster than upstream link. |
| 2906 | * It doesn't speed up anything and some PMPs choke on such |
| 2907 | * configuration. |
| 2908 | */ |
| 2909 | if (!ata_is_host_link(link) && host_link->sata_spd) |
| 2910 | limit &= (1 << host_link->sata_spd) - 1; |
| 2911 | |
| 2912 | if (limit == UINT_MAX) |
| 2913 | target = 0; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2914 | else |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2915 | target = fls(limit); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2916 | |
| 2917 | spd = (*scontrol >> 4) & 0xf; |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2918 | *scontrol = (*scontrol & ~0xf0) | ((target & 0xf) << 4); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2919 | |
Tejun Heo | 5270222 | 2007-10-31 10:17:07 +0900 | [diff] [blame] | 2920 | return spd != target; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2924 | * sata_set_spd_needed - is SATA spd configuration needed |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2925 | * @link: Link in question |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2926 | * |
| 2927 | * Test whether the spd limit in SControl matches |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2928 | * @link->sata_spd_limit. This function is used to determine |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2929 | * whether hardreset is necessary to apply SATA spd |
| 2930 | * configuration. |
| 2931 | * |
| 2932 | * LOCKING: |
| 2933 | * Inherited from caller. |
| 2934 | * |
| 2935 | * RETURNS: |
| 2936 | * 1 if SATA spd configuration is needed, 0 otherwise. |
| 2937 | */ |
Adrian Bunk | 1dc55e8 | 2008-04-21 11:51:17 +0300 | [diff] [blame] | 2938 | static int sata_set_spd_needed(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2939 | { |
| 2940 | u32 scontrol; |
| 2941 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2942 | if (sata_scr_read(link, SCR_CONTROL, &scontrol)) |
Tejun Heo | db64bcf | 2007-10-31 10:17:06 +0900 | [diff] [blame] | 2943 | return 1; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2944 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2945 | return __sata_set_spd_needed(link, &scontrol); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | /** |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 2949 | * sata_set_spd - set SATA spd according to spd limit |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2950 | * @link: Link to set SATA spd for |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2951 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2952 | * Set SATA spd of @link according to sata_spd_limit. |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2953 | * |
| 2954 | * LOCKING: |
| 2955 | * Inherited from caller. |
| 2956 | * |
| 2957 | * RETURNS: |
| 2958 | * 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] | 2959 | * changed. Negative errno if SCR registers are inaccessible. |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2960 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2961 | int sata_set_spd(struct ata_link *link) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2962 | { |
| 2963 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2964 | int rc; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2965 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2966 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2967 | return rc; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2968 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2969 | if (!__sata_set_spd_needed(link, &scontrol)) |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2970 | return 0; |
| 2971 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 2972 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 2973 | return rc; |
| 2974 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 2975 | return 1; |
| 2976 | } |
| 2977 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2978 | /* |
| 2979 | * This mode timing computation functionality is ported over from |
| 2980 | * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik |
| 2981 | */ |
| 2982 | /* |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2983 | * 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] | 2984 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 2985 | * for UDMA6, which is currently supported only by Maxtor drives. |
| 2986 | * |
| 2987 | * 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] | 2988 | */ |
| 2989 | |
| 2990 | static const struct ata_timing ata_timing[] = { |
David Daney | 3ada9c1 | 2009-01-15 17:45:31 -0800 | [diff] [blame] | 2991 | /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 0, 960, 0 }, */ |
| 2992 | { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 0, 600, 0 }, |
| 2993 | { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 0, 383, 0 }, |
| 2994 | { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 0, 240, 0 }, |
| 2995 | { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 0, 180, 0 }, |
| 2996 | { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 0, 120, 0 }, |
| 2997 | { XFER_PIO_5, 15, 65, 25, 100, 65, 25, 0, 100, 0 }, |
| 2998 | { XFER_PIO_6, 10, 55, 20, 80, 55, 20, 0, 80, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 2999 | |
David Daney | 3ada9c1 | 2009-01-15 17:45:31 -0800 | [diff] [blame] | 3000 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 50, 960, 0 }, |
| 3001 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 30, 480, 0 }, |
| 3002 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 20, 240, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3003 | |
David Daney | 3ada9c1 | 2009-01-15 17:45:31 -0800 | [diff] [blame] | 3004 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 20, 480, 0 }, |
| 3005 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 5, 150, 0 }, |
| 3006 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 5, 120, 0 }, |
| 3007 | { XFER_MW_DMA_3, 25, 0, 0, 0, 65, 25, 5, 100, 0 }, |
| 3008 | { XFER_MW_DMA_4, 25, 0, 0, 0, 55, 20, 5, 80, 0 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3009 | |
David Daney | 3ada9c1 | 2009-01-15 17:45:31 -0800 | [diff] [blame] | 3010 | /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 0, 150 }, */ |
| 3011 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 0, 120 }, |
| 3012 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 0, 80 }, |
| 3013 | { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 0, 60 }, |
| 3014 | { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 0, 45 }, |
| 3015 | { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 0, 30 }, |
| 3016 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 0, 20 }, |
| 3017 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 0, 15 }, |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3018 | |
| 3019 | { 0xFF } |
| 3020 | }; |
| 3021 | |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3022 | #define ENOUGH(v, unit) (((v)-1)/(unit)+1) |
| 3023 | #define EZ(v, unit) ((v)?ENOUGH(v, unit):0) |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3024 | |
| 3025 | static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT) |
| 3026 | { |
David Daney | 3ada9c1 | 2009-01-15 17:45:31 -0800 | [diff] [blame] | 3027 | q->setup = EZ(t->setup * 1000, T); |
| 3028 | q->act8b = EZ(t->act8b * 1000, T); |
| 3029 | q->rec8b = EZ(t->rec8b * 1000, T); |
| 3030 | q->cyc8b = EZ(t->cyc8b * 1000, T); |
| 3031 | q->active = EZ(t->active * 1000, T); |
| 3032 | q->recover = EZ(t->recover * 1000, T); |
| 3033 | q->dmack_hold = EZ(t->dmack_hold * 1000, T); |
| 3034 | q->cycle = EZ(t->cycle * 1000, T); |
| 3035 | q->udma = EZ(t->udma * 1000, UT); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, |
| 3039 | struct ata_timing *m, unsigned int what) |
| 3040 | { |
| 3041 | if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup); |
| 3042 | if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b); |
| 3043 | if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b); |
| 3044 | if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b); |
| 3045 | if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active); |
| 3046 | if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover); |
David Daney | 3ada9c1 | 2009-01-15 17:45:31 -0800 | [diff] [blame] | 3047 | if (what & ATA_TIMING_DMACK_HOLD) m->dmack_hold = max(a->dmack_hold, b->dmack_hold); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3048 | if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle); |
| 3049 | if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma); |
| 3050 | } |
| 3051 | |
Tejun Heo | 6357357 | 2007-11-27 19:43:39 +0900 | [diff] [blame] | 3052 | const struct ata_timing *ata_timing_find_mode(u8 xfer_mode) |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3053 | { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3054 | const struct ata_timing *t = ata_timing; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3055 | |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3056 | while (xfer_mode > t->mode) |
| 3057 | t++; |
| 3058 | |
| 3059 | if (xfer_mode == t->mode) |
| 3060 | return t; |
Borislav Petkov | cd705d5 | 2012-10-21 18:57:56 +0200 | [diff] [blame] | 3061 | |
| 3062 | WARN_ONCE(true, "%s: unable to find timing for xfer_mode 0x%x\n", |
| 3063 | __func__, xfer_mode); |
| 3064 | |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3065 | return NULL; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | int ata_timing_compute(struct ata_device *adev, unsigned short speed, |
| 3069 | struct ata_timing *t, int T, int UT) |
| 3070 | { |
Bartlomiej Zolnierkiewicz | 9e8808a | 2010-01-18 18:13:57 +0100 | [diff] [blame] | 3071 | const u16 *id = adev->id; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3072 | const struct ata_timing *s; |
| 3073 | struct ata_timing p; |
| 3074 | |
| 3075 | /* |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 3076 | * Find the mode. |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 3077 | */ |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3078 | |
| 3079 | if (!(s = ata_timing_find_mode(speed))) |
| 3080 | return -EINVAL; |
| 3081 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 3082 | memcpy(t, s, sizeof(*s)); |
| 3083 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3084 | /* |
| 3085 | * If the drive is an EIDE drive, it can tell us it needs extended |
| 3086 | * PIO/MW_DMA cycle timing. |
| 3087 | */ |
| 3088 | |
Bartlomiej Zolnierkiewicz | 9e8808a | 2010-01-18 18:13:57 +0100 | [diff] [blame] | 3089 | if (id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3090 | memset(&p, 0, sizeof(p)); |
Bartlomiej Zolnierkiewicz | 9e8808a | 2010-01-18 18:13:57 +0100 | [diff] [blame] | 3091 | |
Bartlomiej Zolnierkiewicz | bff0025 | 2011-10-13 15:17:32 +0200 | [diff] [blame] | 3092 | if (speed >= XFER_PIO_0 && speed < XFER_SW_DMA_0) { |
Bartlomiej Zolnierkiewicz | 9e8808a | 2010-01-18 18:13:57 +0100 | [diff] [blame] | 3093 | if (speed <= XFER_PIO_2) |
| 3094 | p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO]; |
| 3095 | else if ((speed <= XFER_PIO_4) || |
| 3096 | (speed == XFER_PIO_5 && !ata_id_is_cfa(id))) |
| 3097 | p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY]; |
| 3098 | } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) |
| 3099 | p.cycle = id[ATA_ID_EIDE_DMA_MIN]; |
| 3100 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3101 | ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); |
| 3102 | } |
| 3103 | |
| 3104 | /* |
| 3105 | * Convert the timing to bus clock counts. |
| 3106 | */ |
| 3107 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 3108 | ata_timing_quantize(t, t, T, UT); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3109 | |
| 3110 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 3111 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, |
| 3112 | * S.M.A.R.T * and some other commands. We have to ensure that the |
| 3113 | * DMA cycle timing is slower/equal than the fastest PIO timing. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3114 | */ |
| 3115 | |
Alan | fd3367af | 2006-12-07 12:41:18 +0000 | [diff] [blame] | 3116 | if (speed > XFER_PIO_6) { |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3117 | ata_timing_compute(adev, adev->pio_mode, &p, T, UT); |
| 3118 | ata_timing_merge(&p, t, t, ATA_TIMING_ALL); |
| 3119 | } |
| 3120 | |
| 3121 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 3122 | * Lengthen active & recovery time so that cycle time is correct. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3123 | */ |
| 3124 | |
| 3125 | if (t->act8b + t->rec8b < t->cyc8b) { |
| 3126 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; |
| 3127 | t->rec8b = t->cyc8b - t->act8b; |
| 3128 | } |
| 3129 | |
| 3130 | if (t->active + t->recover < t->cycle) { |
| 3131 | t->active += (t->cycle - (t->active + t->recover)) / 2; |
| 3132 | t->recover = t->cycle - t->active; |
| 3133 | } |
Jeff Garzik | a617c09 | 2007-05-21 20:14:23 -0400 | [diff] [blame] | 3134 | |
Alan Cox | 4f701d1 | 2007-04-23 11:55:36 +0100 | [diff] [blame] | 3135 | /* In a few cases quantisation may produce enough errors to |
| 3136 | leave t->cycle too low for the sum of active and recovery |
| 3137 | if so we must correct this */ |
| 3138 | if (t->active + t->recover > t->cycle) |
| 3139 | t->cycle = t->active + t->recover; |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 3140 | |
| 3141 | return 0; |
| 3142 | } |
| 3143 | |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3144 | /** |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 3145 | * ata_timing_cycle2mode - find xfer mode for the specified cycle duration |
| 3146 | * @xfer_shift: ATA_SHIFT_* value for transfer type to examine. |
| 3147 | * @cycle: cycle duration in ns |
| 3148 | * |
| 3149 | * Return matching xfer mode for @cycle. The returned mode is of |
| 3150 | * the transfer type specified by @xfer_shift. If @cycle is too |
| 3151 | * slow for @xfer_shift, 0xff is returned. If @cycle is faster |
| 3152 | * than the fastest known mode, the fasted mode is returned. |
| 3153 | * |
| 3154 | * LOCKING: |
| 3155 | * None. |
| 3156 | * |
| 3157 | * RETURNS: |
| 3158 | * Matching xfer_mode, 0xff if no match found. |
| 3159 | */ |
| 3160 | u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle) |
| 3161 | { |
| 3162 | u8 base_mode = 0xff, last_mode = 0xff; |
| 3163 | const struct ata_xfer_ent *ent; |
| 3164 | const struct ata_timing *t; |
| 3165 | |
| 3166 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 3167 | if (ent->shift == xfer_shift) |
| 3168 | base_mode = ent->base; |
| 3169 | |
| 3170 | for (t = ata_timing_find_mode(base_mode); |
| 3171 | t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { |
| 3172 | unsigned short this_cycle; |
| 3173 | |
| 3174 | switch (xfer_shift) { |
| 3175 | case ATA_SHIFT_PIO: |
| 3176 | case ATA_SHIFT_MWDMA: |
| 3177 | this_cycle = t->cycle; |
| 3178 | break; |
| 3179 | case ATA_SHIFT_UDMA: |
| 3180 | this_cycle = t->udma; |
| 3181 | break; |
| 3182 | default: |
| 3183 | return 0xff; |
| 3184 | } |
| 3185 | |
| 3186 | if (cycle > this_cycle) |
| 3187 | break; |
| 3188 | |
| 3189 | last_mode = t->mode; |
| 3190 | } |
| 3191 | |
| 3192 | return last_mode; |
| 3193 | } |
| 3194 | |
| 3195 | /** |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3196 | * ata_down_xfermask_limit - adjust dev xfer masks downward |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3197 | * @dev: Device to adjust xfer masks |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3198 | * @sel: ATA_DNXFER_* selector |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3199 | * |
| 3200 | * Adjust xfer masks of @dev downward. Note that this function |
| 3201 | * does not apply the change. Invoking ata_set_mode() afterwards |
| 3202 | * will apply the limit. |
| 3203 | * |
| 3204 | * LOCKING: |
| 3205 | * Inherited from caller. |
| 3206 | * |
| 3207 | * RETURNS: |
| 3208 | * 0 on success, negative errno on failure |
| 3209 | */ |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3210 | int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel) |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3211 | { |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3212 | char buf[32]; |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 3213 | unsigned long orig_mask, xfer_mask; |
| 3214 | unsigned long pio_mask, mwdma_mask, udma_mask; |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3215 | int quiet, highbit; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3216 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3217 | quiet = !!(sel & ATA_DNXFER_QUIET); |
| 3218 | sel &= ~ATA_DNXFER_QUIET; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3219 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3220 | xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, |
| 3221 | dev->mwdma_mask, |
| 3222 | dev->udma_mask); |
| 3223 | ata_unpack_xfermask(xfer_mask, &pio_mask, &mwdma_mask, &udma_mask); |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3224 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3225 | switch (sel) { |
| 3226 | case ATA_DNXFER_PIO: |
| 3227 | highbit = fls(pio_mask) - 1; |
| 3228 | pio_mask &= ~(1 << highbit); |
| 3229 | break; |
| 3230 | |
| 3231 | case ATA_DNXFER_DMA: |
| 3232 | if (udma_mask) { |
| 3233 | highbit = fls(udma_mask) - 1; |
| 3234 | udma_mask &= ~(1 << highbit); |
| 3235 | if (!udma_mask) |
| 3236 | return -ENOENT; |
| 3237 | } else if (mwdma_mask) { |
| 3238 | highbit = fls(mwdma_mask) - 1; |
| 3239 | mwdma_mask &= ~(1 << highbit); |
| 3240 | if (!mwdma_mask) |
| 3241 | return -ENOENT; |
| 3242 | } |
| 3243 | break; |
| 3244 | |
| 3245 | case ATA_DNXFER_40C: |
| 3246 | udma_mask &= ATA_UDMA_MASK_40C; |
| 3247 | break; |
| 3248 | |
| 3249 | case ATA_DNXFER_FORCE_PIO0: |
| 3250 | pio_mask &= 1; |
| 3251 | case ATA_DNXFER_FORCE_PIO: |
| 3252 | mwdma_mask = 0; |
| 3253 | udma_mask = 0; |
| 3254 | break; |
| 3255 | |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3256 | default: |
| 3257 | BUG(); |
| 3258 | } |
| 3259 | |
| 3260 | xfer_mask &= ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 3261 | |
| 3262 | if (!(xfer_mask & ATA_MASK_PIO) || xfer_mask == orig_mask) |
| 3263 | return -ENOENT; |
| 3264 | |
| 3265 | if (!quiet) { |
| 3266 | if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA)) |
| 3267 | snprintf(buf, sizeof(buf), "%s:%s", |
| 3268 | ata_mode_string(xfer_mask), |
| 3269 | ata_mode_string(xfer_mask & ATA_MASK_PIO)); |
| 3270 | else |
| 3271 | snprintf(buf, sizeof(buf), "%s", |
| 3272 | ata_mode_string(xfer_mask)); |
| 3273 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3274 | ata_dev_warn(dev, "limiting speed to %s\n", buf); |
Tejun Heo | 458337d | 2007-02-02 16:22:30 +0900 | [diff] [blame] | 3275 | } |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3276 | |
| 3277 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, |
| 3278 | &dev->udma_mask); |
| 3279 | |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3280 | return 0; |
Tejun Heo | cf176e1 | 2006-04-02 17:54:46 +0900 | [diff] [blame] | 3281 | } |
| 3282 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3283 | static int ata_dev_set_mode(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | { |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 3285 | struct ata_port *ap = dev->link->ap; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 3286 | struct ata_eh_context *ehc = &dev->link->eh_context; |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 3287 | const bool nosetxfer = dev->horkage & ATA_HORKAGE_NOSETXFER; |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3288 | const char *dev_err_whine = ""; |
| 3289 | int ign_dev_err = 0; |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 3290 | unsigned int err_mask = 0; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3291 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | |
Tejun Heo | e838460 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 3293 | dev->flags &= ~ATA_DFLAG_PIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | if (dev->xfer_shift == ATA_SHIFT_PIO) |
| 3295 | dev->flags |= ATA_DFLAG_PIO; |
| 3296 | |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 3297 | if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id)) |
| 3298 | dev_err_whine = " (SET_XFERMODE skipped)"; |
| 3299 | else { |
| 3300 | if (nosetxfer) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3301 | ata_dev_warn(dev, |
| 3302 | "NOSETXFER but PATA detected - can't " |
| 3303 | "skip SETXFER, might malfunction\n"); |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 3304 | err_mask = ata_dev_set_xfermode(dev); |
| 3305 | } |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3306 | |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3307 | if (err_mask & ~AC_ERR_DEV) |
| 3308 | goto fail; |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 3309 | |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3310 | /* revalidate */ |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 3311 | ehc->i.flags |= ATA_EHI_POST_SETMODE; |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 3312 | rc = ata_dev_revalidate(dev, ATA_DEV_UNKNOWN, 0); |
Tejun Heo | baa1e78 | 2006-11-01 18:39:27 +0900 | [diff] [blame] | 3313 | ehc->i.flags &= ~ATA_EHI_POST_SETMODE; |
Tejun Heo | 5eb45c0 | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 3314 | if (rc) |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3315 | return rc; |
Tejun Heo | 48a8a14 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3316 | |
Alan Cox | b93fda1 | 2008-04-08 16:36:44 +0100 | [diff] [blame] | 3317 | if (dev->xfer_shift == ATA_SHIFT_PIO) { |
| 3318 | /* Old CFA may refuse this command, which is just fine */ |
| 3319 | if (ata_id_is_cfa(dev->id)) |
| 3320 | ign_dev_err = 1; |
| 3321 | /* Catch several broken garbage emulations plus some pre |
| 3322 | ATA devices */ |
| 3323 | if (ata_id_major_version(dev->id) == 0 && |
| 3324 | dev->pio_mode <= XFER_PIO_2) |
| 3325 | ign_dev_err = 1; |
| 3326 | /* Some very old devices and some bad newer ones fail |
| 3327 | any kind of SET_XFERMODE request but support PIO0-2 |
| 3328 | timings and no IORDY */ |
| 3329 | if (!ata_id_has_iordy(dev->id) && dev->pio_mode <= XFER_PIO_2) |
| 3330 | ign_dev_err = 1; |
| 3331 | } |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3332 | /* Early MWDMA devices do DMA but don't allow DMA mode setting. |
| 3333 | Don't fail an MWDMA0 set IFF the device indicates it is in MWDMA0 */ |
| 3334 | if (dev->xfer_shift == ATA_SHIFT_MWDMA && |
| 3335 | dev->dma_mode == XFER_MW_DMA_0 && |
| 3336 | (dev->id[63] >> 8) & 1) |
| 3337 | ign_dev_err = 1; |
| 3338 | |
| 3339 | /* if the device is actually configured correctly, ignore dev err */ |
| 3340 | if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) |
| 3341 | ign_dev_err = 1; |
| 3342 | |
| 3343 | if (err_mask & AC_ERR_DEV) { |
| 3344 | if (!ign_dev_err) |
| 3345 | goto fail; |
| 3346 | else |
| 3347 | dev_err_whine = " (device error ignored)"; |
| 3348 | } |
| 3349 | |
Tejun Heo | 23e71c3 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3350 | DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", |
| 3351 | dev->xfer_shift, (int)dev->xfer_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3353 | ata_dev_info(dev, "configured for %s%s\n", |
| 3354 | ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), |
| 3355 | dev_err_whine); |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3356 | |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3357 | return 0; |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3358 | |
| 3359 | fail: |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3360 | ata_dev_err(dev, "failed to set xfermode (err_mask=0x%x)\n", err_mask); |
Tejun Heo | 4055dee | 2008-02-07 10:34:08 +0900 | [diff] [blame] | 3361 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | /** |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 3365 | * ata_do_set_mode - Program timings and issue SET FEATURES - XFER |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3366 | * @link: link on which timings will be programmed |
Joe Perches | 1967b7f | 2008-02-03 17:08:11 +0200 | [diff] [blame] | 3367 | * @r_failed_dev: out parameter for failed device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | * |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 3369 | * Standard implementation of the function used to tune and set |
| 3370 | * ATA device disk transfer mode (PIO3, UDMA6, etc.). If |
| 3371 | * ata_dev_set_mode() fails, pointer to the failing device is |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3372 | * returned in @r_failed_dev. |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 3373 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3375 | * PCI/etc. bus probe sem. |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3376 | * |
| 3377 | * RETURNS: |
| 3378 | * 0 on success, negative errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3379 | */ |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 3380 | |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3381 | 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] | 3382 | { |
Tejun Heo | 0260731 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3383 | struct ata_port *ap = link->ap; |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3384 | struct ata_device *dev; |
Tejun Heo | f58229f | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3385 | int rc = 0, used_dma = 0, found = 0; |
Tejun Heo | 3adcebb | 2006-05-15 20:57:37 +0900 | [diff] [blame] | 3386 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3387 | /* step 1: calculate xfer_mask */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 3388 | ata_for_each_dev(dev, link, ENABLED) { |
Tejun Heo | 7dc951a | 2007-11-27 19:43:42 +0900 | [diff] [blame] | 3389 | unsigned long pio_mask, dma_mask; |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3390 | unsigned int mode_mask; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3391 | |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3392 | mode_mask = ATA_DMA_MASK_ATA; |
| 3393 | if (dev->class == ATA_DEV_ATAPI) |
| 3394 | mode_mask = ATA_DMA_MASK_ATAPI; |
| 3395 | else if (ata_id_is_cfa(dev->id)) |
| 3396 | mode_mask = ATA_DMA_MASK_CFA; |
| 3397 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3398 | ata_dev_xfermask(dev); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 3399 | ata_force_xfermask(dev); |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3400 | |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 3401 | pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3402 | |
| 3403 | if (libata_dma_mask & mode_mask) |
Sergei Shtylyov | 80a9c43 | 2011-12-22 22:41:32 +0300 | [diff] [blame] | 3404 | dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, |
| 3405 | dev->udma_mask); |
Alan Cox | b3a7060 | 2007-10-02 12:38:26 -0400 | [diff] [blame] | 3406 | else |
| 3407 | dma_mask = 0; |
| 3408 | |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 3409 | dev->pio_mode = ata_xfer_mask2mode(pio_mask); |
| 3410 | dev->dma_mode = ata_xfer_mask2mode(dma_mask); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3411 | |
Tejun Heo | 4f65977 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3412 | found = 1; |
Alan Cox | b15b3eb | 2008-08-01 09:18:34 +0100 | [diff] [blame] | 3413 | if (ata_dma_enabled(dev)) |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3414 | used_dma = 1; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3415 | } |
Tejun Heo | 4f65977 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3416 | if (!found) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3417 | goto out; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3418 | |
| 3419 | /* step 2: always set host PIO timings */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 3420 | ata_for_each_dev(dev, link, ENABLED) { |
Tejun Heo | 70cd071 | 2007-11-27 19:43:40 +0900 | [diff] [blame] | 3421 | if (dev->pio_mode == 0xff) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3422 | ata_dev_warn(dev, "no PIO support\n"); |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3423 | rc = -EINVAL; |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3424 | goto out; |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | dev->xfer_mode = dev->pio_mode; |
| 3428 | dev->xfer_shift = ATA_SHIFT_PIO; |
| 3429 | if (ap->ops->set_piomode) |
| 3430 | ap->ops->set_piomode(ap, dev); |
| 3431 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 3433 | /* step 3: set host DMA timings */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 3434 | ata_for_each_dev(dev, link, ENABLED) { |
| 3435 | if (!ata_dma_enabled(dev)) |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3436 | continue; |
| 3437 | |
| 3438 | dev->xfer_mode = dev->dma_mode; |
| 3439 | dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); |
| 3440 | if (ap->ops->set_dmamode) |
| 3441 | ap->ops->set_dmamode(ap, dev); |
| 3442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | |
| 3444 | /* step 4: update devices' xfer mode */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 3445 | ata_for_each_dev(dev, link, ENABLED) { |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 3446 | rc = ata_dev_set_mode(dev); |
Tejun Heo | 5bbc53f | 2006-04-01 01:38:17 +0900 | [diff] [blame] | 3447 | if (rc) |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3448 | goto out; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 3449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | |
Tejun Heo | e8e0619 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3451 | /* Record simplex status. If we selected DMA then the other |
| 3452 | * host channels are not permitted to do so. |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3453 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 3454 | if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) |
Alan | 032af1c | 2007-03-01 17:36:46 +0000 | [diff] [blame] | 3455 | ap->host->simplex_claimed = ap; |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 3456 | |
Tejun Heo | e82cbdb | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3457 | out: |
| 3458 | if (rc) |
| 3459 | *r_failed_dev = dev; |
| 3460 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | /** |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3464 | * ata_wait_ready - wait for link to become ready |
| 3465 | * @link: link to be waited on |
| 3466 | * @deadline: deadline jiffies for the operation |
| 3467 | * @check_ready: callback to check link readiness |
| 3468 | * |
| 3469 | * Wait for @link to become ready. @check_ready should return |
| 3470 | * positive number if @link is ready, 0 if it isn't, -ENODEV if |
| 3471 | * link doesn't seem to be occupied, other errno for other error |
| 3472 | * conditions. |
| 3473 | * |
| 3474 | * Transient -ENODEV conditions are allowed for |
| 3475 | * ATA_TMOUT_FF_WAIT. |
| 3476 | * |
| 3477 | * LOCKING: |
| 3478 | * EH context. |
| 3479 | * |
| 3480 | * RETURNS: |
| 3481 | * 0 if @linke is ready before @deadline; otherwise, -errno. |
| 3482 | */ |
| 3483 | int ata_wait_ready(struct ata_link *link, unsigned long deadline, |
| 3484 | int (*check_ready)(struct ata_link *link)) |
| 3485 | { |
| 3486 | unsigned long start = jiffies; |
Tejun Heo | b48d58f | 2010-04-09 19:46:38 +0900 | [diff] [blame] | 3487 | unsigned long nodev_deadline; |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3488 | int warned = 0; |
| 3489 | |
Tejun Heo | b48d58f | 2010-04-09 19:46:38 +0900 | [diff] [blame] | 3490 | /* choose which 0xff timeout to use, read comment in libata.h */ |
| 3491 | if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN) |
| 3492 | nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT_LONG); |
| 3493 | else |
| 3494 | nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT); |
| 3495 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 3496 | /* Slave readiness can't be tested separately from master. On |
| 3497 | * M/S emulation configuration, this function should be called |
| 3498 | * only on the master and it will handle both master and slave. |
| 3499 | */ |
| 3500 | WARN_ON(link == link->ap->slave_link); |
| 3501 | |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3502 | if (time_after(nodev_deadline, deadline)) |
| 3503 | nodev_deadline = deadline; |
| 3504 | |
| 3505 | while (1) { |
| 3506 | unsigned long now = jiffies; |
| 3507 | int ready, tmp; |
| 3508 | |
| 3509 | ready = tmp = check_ready(link); |
| 3510 | if (ready > 0) |
| 3511 | return 0; |
| 3512 | |
Tejun Heo | b48d58f | 2010-04-09 19:46:38 +0900 | [diff] [blame] | 3513 | /* |
| 3514 | * -ENODEV could be transient. Ignore -ENODEV if link |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3515 | * is online. Also, some SATA devices take a long |
Tejun Heo | b48d58f | 2010-04-09 19:46:38 +0900 | [diff] [blame] | 3516 | * time to clear 0xff after reset. Wait for |
| 3517 | * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't |
| 3518 | * offline. |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3519 | * |
| 3520 | * Note that some PATA controllers (pata_ali) explode |
| 3521 | * if status register is read more than once when |
| 3522 | * there's no device attached. |
| 3523 | */ |
| 3524 | if (ready == -ENODEV) { |
| 3525 | if (ata_link_online(link)) |
| 3526 | ready = 0; |
| 3527 | else if ((link->ap->flags & ATA_FLAG_SATA) && |
| 3528 | !ata_link_offline(link) && |
| 3529 | time_before(now, nodev_deadline)) |
| 3530 | ready = 0; |
| 3531 | } |
| 3532 | |
| 3533 | if (ready) |
| 3534 | return ready; |
| 3535 | if (time_after(now, deadline)) |
| 3536 | return -EBUSY; |
| 3537 | |
| 3538 | if (!warned && time_after(now, start + 5 * HZ) && |
| 3539 | (deadline - now > 3 * HZ)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3540 | ata_link_warn(link, |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3541 | "link is slow to respond, please be patient " |
| 3542 | "(ready=%d)\n", tmp); |
| 3543 | warned = 1; |
| 3544 | } |
| 3545 | |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 3546 | ata_msleep(link->ap, 50); |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * ata_wait_after_reset - wait for link to become ready after reset |
| 3552 | * @link: link to be waited on |
| 3553 | * @deadline: deadline jiffies for the operation |
| 3554 | * @check_ready: callback to check link readiness |
| 3555 | * |
| 3556 | * Wait for @link to become ready after reset. |
| 3557 | * |
| 3558 | * LOCKING: |
| 3559 | * EH context. |
| 3560 | * |
| 3561 | * RETURNS: |
| 3562 | * 0 if @linke is ready before @deadline; otherwise, -errno. |
| 3563 | */ |
Harvey Harrison | 2b4221b | 2008-04-24 18:37:34 -0700 | [diff] [blame] | 3564 | int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3565 | int (*check_ready)(struct ata_link *link)) |
| 3566 | { |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 3567 | ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3568 | |
| 3569 | return ata_wait_ready(link, deadline, check_ready); |
| 3570 | } |
| 3571 | |
| 3572 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3573 | * sata_link_debounce - debounce SATA phy status |
| 3574 | * @link: ATA link to debounce SATA phy status for |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3575 | * @params: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3576 | * @deadline: deadline jiffies for the operation |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3577 | * |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 3578 | * Make sure SStatus of @link reaches stable state, determined by |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3579 | * holding the same value where DET is not 1 for @duration polled |
| 3580 | * every @interval, before @timeout. Timeout constraints the |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3581 | * beginning of the stable state. Because DET gets stuck at 1 on |
| 3582 | * some controllers after hot unplugging, this functions waits |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3583 | * until timeout then returns 0 if DET is stable at 1. |
| 3584 | * |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3585 | * @timeout is further limited by @deadline. The sooner of the |
| 3586 | * two is used. |
| 3587 | * |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3588 | * LOCKING: |
| 3589 | * Kernel thread context (may sleep) |
| 3590 | * |
| 3591 | * RETURNS: |
| 3592 | * 0 on success, -errno on failure. |
| 3593 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3594 | int sata_link_debounce(struct ata_link *link, const unsigned long *params, |
| 3595 | unsigned long deadline) |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3596 | { |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 3597 | unsigned long interval = params[0]; |
| 3598 | unsigned long duration = params[1]; |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3599 | unsigned long last_jiffies, t; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3600 | u32 last, cur; |
| 3601 | int rc; |
| 3602 | |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 3603 | t = ata_deadline(jiffies, params[2]); |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3604 | if (time_before(t, deadline)) |
| 3605 | deadline = t; |
| 3606 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3607 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3608 | return rc; |
| 3609 | cur &= 0xf; |
| 3610 | |
| 3611 | last = cur; |
| 3612 | last_jiffies = jiffies; |
| 3613 | |
| 3614 | while (1) { |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 3615 | ata_msleep(link->ap, interval); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3616 | if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3617 | return rc; |
| 3618 | cur &= 0xf; |
| 3619 | |
| 3620 | /* DET stable? */ |
| 3621 | if (cur == last) { |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3622 | if (cur == 1 && time_before(jiffies, deadline)) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3623 | continue; |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 3624 | if (time_after(jiffies, |
| 3625 | ata_deadline(last_jiffies, duration))) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3626 | return 0; |
| 3627 | continue; |
| 3628 | } |
| 3629 | |
| 3630 | /* unstable, start over */ |
| 3631 | last = cur; |
| 3632 | last_jiffies = jiffies; |
| 3633 | |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 3634 | /* Check deadline. If debouncing failed, return |
| 3635 | * -EPIPE to tell upper layer to lower link speed. |
| 3636 | */ |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3637 | if (time_after(jiffies, deadline)) |
Tejun Heo | f154515 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 3638 | return -EPIPE; |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | /** |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3643 | * sata_link_resume - resume SATA link |
| 3644 | * @link: ATA link to resume SATA |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3645 | * @params: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3646 | * @deadline: deadline jiffies for the operation |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3647 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3648 | * Resume SATA phy @link and debounce it. |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3649 | * |
| 3650 | * LOCKING: |
| 3651 | * Kernel thread context (may sleep) |
| 3652 | * |
| 3653 | * RETURNS: |
| 3654 | * 0 on success, -errno on failure. |
| 3655 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3656 | int sata_link_resume(struct ata_link *link, const unsigned long *params, |
| 3657 | unsigned long deadline) |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3658 | { |
Tejun Heo | 5040ab6 | 2010-01-11 11:14:44 +0900 | [diff] [blame] | 3659 | int tries = ATA_LINK_RESUME_TRIES; |
Tejun Heo | ac37198 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3660 | u32 scontrol, serror; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3661 | int rc; |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3662 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3663 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3664 | return rc; |
| 3665 | |
Tejun Heo | 5040ab6 | 2010-01-11 11:14:44 +0900 | [diff] [blame] | 3666 | /* |
| 3667 | * Writes to SControl sometimes get ignored under certain |
| 3668 | * controllers (ata_piix SIDPR). Make sure DET actually is |
| 3669 | * cleared. |
Tejun Heo | d7bb4cc | 2006-05-31 18:27:46 +0900 | [diff] [blame] | 3670 | */ |
Tejun Heo | 5040ab6 | 2010-01-11 11:14:44 +0900 | [diff] [blame] | 3671 | do { |
| 3672 | scontrol = (scontrol & 0x0f0) | 0x300; |
| 3673 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
| 3674 | return rc; |
| 3675 | /* |
| 3676 | * Some PHYs react badly if SStatus is pounded |
| 3677 | * immediately after resuming. Delay 200ms before |
| 3678 | * debouncing. |
| 3679 | */ |
Danesh Petigara | e39b2bb | 2016-01-07 16:03:33 -0800 | [diff] [blame] | 3680 | if (!(link->flags & ATA_LFLAG_NO_DB_DELAY)) |
| 3681 | ata_msleep(link->ap, 200); |
Tejun Heo | 5040ab6 | 2010-01-11 11:14:44 +0900 | [diff] [blame] | 3682 | |
| 3683 | /* is SControl restored correctly? */ |
| 3684 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
| 3685 | return rc; |
| 3686 | } while ((scontrol & 0xf0f) != 0x300 && --tries); |
| 3687 | |
| 3688 | if ((scontrol & 0xf0f) != 0x300) { |
Tejun Heo | 38941c9 | 2011-07-01 15:12:09 +0200 | [diff] [blame] | 3689 | ata_link_warn(link, "failed to resume link (SControl %X)\n", |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3690 | scontrol); |
Tejun Heo | 5040ab6 | 2010-01-11 11:14:44 +0900 | [diff] [blame] | 3691 | return 0; |
| 3692 | } |
| 3693 | |
| 3694 | if (tries < ATA_LINK_RESUME_TRIES) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3695 | ata_link_warn(link, "link resume succeeded after %d retries\n", |
| 3696 | ATA_LINK_RESUME_TRIES - tries); |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3697 | |
Tejun Heo | ac37198 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3698 | if ((rc = sata_link_debounce(link, params, deadline))) |
| 3699 | return rc; |
| 3700 | |
Tejun Heo | f046519 | 2008-05-19 01:15:08 +0900 | [diff] [blame] | 3701 | /* clear SError, some PHYs require this even for SRST to work */ |
Tejun Heo | ac37198 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3702 | if (!(rc = sata_scr_read(link, SCR_ERROR, &serror))) |
| 3703 | rc = sata_scr_write(link, SCR_ERROR, serror); |
Tejun Heo | ac37198 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3704 | |
Tejun Heo | f046519 | 2008-05-19 01:15:08 +0900 | [diff] [blame] | 3705 | return rc != -EINVAL ? rc : 0; |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 3706 | } |
| 3707 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3708 | /** |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 3709 | * sata_link_scr_lpm - manipulate SControl IPM and SPM fields |
| 3710 | * @link: ATA link to manipulate SControl for |
| 3711 | * @policy: LPM policy to configure |
| 3712 | * @spm_wakeup: initiate LPM transition to active state |
| 3713 | * |
| 3714 | * Manipulate the IPM field of the SControl register of @link |
| 3715 | * according to @policy. If @policy is ATA_LPM_MAX_POWER and |
| 3716 | * @spm_wakeup is %true, the SPM field is manipulated to wake up |
| 3717 | * the link. This function also clears PHYRDY_CHG before |
| 3718 | * returning. |
| 3719 | * |
| 3720 | * LOCKING: |
| 3721 | * EH context. |
| 3722 | * |
| 3723 | * RETURNS: |
Masanari Iida | 8485187 | 2015-05-29 23:11:51 +0900 | [diff] [blame] | 3724 | * 0 on success, -errno otherwise. |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 3725 | */ |
| 3726 | int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy, |
| 3727 | bool spm_wakeup) |
| 3728 | { |
| 3729 | struct ata_eh_context *ehc = &link->eh_context; |
| 3730 | bool woken_up = false; |
| 3731 | u32 scontrol; |
| 3732 | int rc; |
| 3733 | |
| 3734 | rc = sata_scr_read(link, SCR_CONTROL, &scontrol); |
| 3735 | if (rc) |
| 3736 | return rc; |
| 3737 | |
| 3738 | switch (policy) { |
| 3739 | case ATA_LPM_MAX_POWER: |
| 3740 | /* disable all LPM transitions */ |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 3741 | scontrol |= (0x7 << 8); |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 3742 | /* initiate transition to active state */ |
| 3743 | if (spm_wakeup) { |
| 3744 | scontrol |= (0x4 << 12); |
| 3745 | woken_up = true; |
| 3746 | } |
| 3747 | break; |
| 3748 | case ATA_LPM_MED_POWER: |
| 3749 | /* allow LPM to PARTIAL */ |
| 3750 | scontrol &= ~(0x1 << 8); |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 3751 | scontrol |= (0x6 << 8); |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 3752 | break; |
| 3753 | case ATA_LPM_MIN_POWER: |
Kristen Carlson Accardi | 8a745f1 | 2011-03-04 10:24:11 -0800 | [diff] [blame] | 3754 | if (ata_link_nr_enabled(link) > 0) |
| 3755 | /* no restrictions on LPM transitions */ |
Shane Huang | 65fe1f0 | 2012-09-07 22:40:01 +0800 | [diff] [blame] | 3756 | scontrol &= ~(0x7 << 8); |
Kristen Carlson Accardi | 8a745f1 | 2011-03-04 10:24:11 -0800 | [diff] [blame] | 3757 | else { |
| 3758 | /* empty port, power off */ |
| 3759 | scontrol &= ~0xf; |
| 3760 | scontrol |= (0x1 << 2); |
| 3761 | } |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 3762 | break; |
| 3763 | default: |
| 3764 | WARN_ON(1); |
| 3765 | } |
| 3766 | |
| 3767 | rc = sata_scr_write(link, SCR_CONTROL, scontrol); |
| 3768 | if (rc) |
| 3769 | return rc; |
| 3770 | |
| 3771 | /* give the link time to transit out of LPM state */ |
| 3772 | if (woken_up) |
| 3773 | msleep(10); |
| 3774 | |
| 3775 | /* clear PHYRDY_CHG from SError */ |
| 3776 | ehc->i.serror &= ~SERR_PHYRDY_CHG; |
| 3777 | return sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG); |
| 3778 | } |
| 3779 | |
| 3780 | /** |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 3781 | * ata_std_prereset - prepare for reset |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3782 | * @link: ATA link to be reset |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3783 | * @deadline: deadline jiffies for the operation |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3784 | * |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3785 | * @link is about to be reset. Initialize it. Failure from |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3786 | * prereset makes libata abort whole reset sequence and give up |
| 3787 | * that port, so prereset should be best-effort. It does its |
| 3788 | * best to prepare for reset sequence but if things go wrong, it |
| 3789 | * should just whine, not fail. |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3790 | * |
| 3791 | * LOCKING: |
| 3792 | * Kernel thread context (may sleep) |
| 3793 | * |
| 3794 | * RETURNS: |
| 3795 | * 0 on success, -errno otherwise. |
| 3796 | */ |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 3797 | int ata_std_prereset(struct ata_link *link, unsigned long deadline) |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3798 | { |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3799 | struct ata_port *ap = link->ap; |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3800 | struct ata_eh_context *ehc = &link->eh_context; |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 3801 | const unsigned long *timing = sata_ehc_deb_timing(ehc); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3802 | int rc; |
| 3803 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3804 | /* if we're about to do hardreset, nothing more to do */ |
| 3805 | if (ehc->i.action & ATA_EH_HARDRESET) |
| 3806 | return 0; |
| 3807 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3808 | /* if SATA, resume link */ |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 3809 | if (ap->flags & ATA_FLAG_SATA) { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3810 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | b8cffc6 | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3811 | /* whine about phy resume failure but proceed */ |
| 3812 | if (rc && rc != -EOPNOTSUPP) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3813 | ata_link_warn(link, |
| 3814 | "failed to resume link for reset (errno=%d)\n", |
| 3815 | rc); |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3816 | } |
| 3817 | |
Tejun Heo | 45db2f6 | 2008-04-08 01:46:56 +0900 | [diff] [blame] | 3818 | /* no point in trying softreset on offline link */ |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 3819 | if (ata_phys_link_offline(link)) |
Tejun Heo | 45db2f6 | 2008-04-08 01:46:56 +0900 | [diff] [blame] | 3820 | ehc->i.action &= ~ATA_EH_SOFTRESET; |
| 3821 | |
Tejun Heo | f5914a4 | 2006-05-31 18:27:48 +0900 | [diff] [blame] | 3822 | return 0; |
| 3823 | } |
| 3824 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3825 | /** |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3826 | * sata_link_hardreset - reset link via SATA phy reset |
| 3827 | * @link: link to reset |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3828 | * @timing: timing parameters { interval, duratinon, timeout } in msec |
Tejun Heo | d4b2bab | 2007-02-02 16:50:52 +0900 | [diff] [blame] | 3829 | * @deadline: deadline jiffies for the operation |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3830 | * @online: optional out parameter indicating link onlineness |
| 3831 | * @check_ready: optional callback to check link readiness |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3832 | * |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3833 | * SATA phy-reset @link using DET bits of SControl register. |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3834 | * After hardreset, link readiness is waited upon using |
| 3835 | * ata_wait_ready() if @check_ready is specified. LLDs are |
| 3836 | * allowed to not specify @check_ready and wait itself after this |
| 3837 | * function returns. Device classification is LLD's |
| 3838 | * responsibility. |
| 3839 | * |
| 3840 | * *@online is set to one iff reset succeeded and @link is online |
| 3841 | * after reset. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3842 | * |
| 3843 | * LOCKING: |
| 3844 | * Kernel thread context (may sleep) |
| 3845 | * |
| 3846 | * RETURNS: |
| 3847 | * 0 on success, -errno otherwise. |
| 3848 | */ |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3849 | int sata_link_hardreset(struct ata_link *link, const unsigned long *timing, |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3850 | unsigned long deadline, |
| 3851 | bool *online, int (*check_ready)(struct ata_link *)) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3852 | { |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3853 | u32 scontrol; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3854 | int rc; |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3855 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3856 | DPRINTK("ENTER\n"); |
| 3857 | |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3858 | if (online) |
| 3859 | *online = false; |
| 3860 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3861 | if (sata_set_spd_needed(link)) { |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3862 | /* SATA spec says nothing about how to reconfigure |
| 3863 | * spd. To be on the safe side, turn off phy during |
| 3864 | * reconfiguration. This works for at least ICH7 AHCI |
| 3865 | * and Sil3124. |
| 3866 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3867 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3868 | goto out; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3869 | |
Martin Hicks | a34b6fc | 2006-07-05 15:06:13 -0400 | [diff] [blame] | 3870 | scontrol = (scontrol & 0x0f0) | 0x304; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3871 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3872 | if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3873 | goto out; |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3874 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3875 | sata_set_spd(link); |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | /* issue phy wake/reset */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3879 | if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3880 | goto out; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3881 | |
Tejun Heo | 852ee16 | 2006-04-01 01:38:18 +0900 | [diff] [blame] | 3882 | scontrol = (scontrol & 0x0f0) | 0x301; |
Tejun Heo | 81952c5 | 2006-05-15 20:57:47 +0900 | [diff] [blame] | 3883 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3884 | if ((rc = sata_scr_write_flush(link, SCR_CONTROL, scontrol))) |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3885 | goto out; |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3886 | |
Tejun Heo | 1c3fae4 | 2006-04-02 20:53:28 +0900 | [diff] [blame] | 3887 | /* 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] | 3888 | * 10.4.2 says at least 1 ms. |
| 3889 | */ |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 3890 | ata_msleep(link->ap, 1); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3891 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3892 | /* bring link back */ |
| 3893 | rc = sata_link_resume(link, timing, deadline); |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3894 | if (rc) |
| 3895 | goto out; |
| 3896 | /* if link is offline nothing more to do */ |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 3897 | if (ata_phys_link_offline(link)) |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3898 | goto out; |
| 3899 | |
| 3900 | /* Link is online. From this point, -ENODEV too is an error. */ |
| 3901 | if (online) |
| 3902 | *online = true; |
| 3903 | |
Tejun Heo | 071f44b | 2008-04-07 22:47:22 +0900 | [diff] [blame] | 3904 | if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) { |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3905 | /* If PMP is supported, we have to do follow-up SRST. |
| 3906 | * Some PMPs don't send D2H Reg FIS after hardreset if |
| 3907 | * the first port is empty. Wait only for |
| 3908 | * ATA_TMOUT_PMP_SRST_WAIT. |
| 3909 | */ |
| 3910 | if (check_ready) { |
| 3911 | unsigned long pmp_deadline; |
| 3912 | |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 3913 | pmp_deadline = ata_deadline(jiffies, |
| 3914 | ATA_TMOUT_PMP_SRST_WAIT); |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3915 | if (time_after(pmp_deadline, deadline)) |
| 3916 | pmp_deadline = deadline; |
| 3917 | ata_wait_ready(link, pmp_deadline, check_ready); |
| 3918 | } |
| 3919 | rc = -EAGAIN; |
| 3920 | goto out; |
| 3921 | } |
| 3922 | |
| 3923 | rc = 0; |
| 3924 | if (check_ready) |
| 3925 | rc = ata_wait_ready(link, deadline, check_ready); |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3926 | out: |
Tejun Heo | 0cbf071 | 2008-05-19 01:15:05 +0900 | [diff] [blame] | 3927 | if (rc && rc != -EAGAIN) { |
| 3928 | /* online is set iff link is online && reset succeeded */ |
| 3929 | if (online) |
| 3930 | *online = false; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 3931 | ata_link_err(link, "COMRESET failed (errno=%d)\n", rc); |
Tejun Heo | 0cbf071 | 2008-05-19 01:15:05 +0900 | [diff] [blame] | 3932 | } |
Tejun Heo | b6103f6 | 2006-11-01 17:59:53 +0900 | [diff] [blame] | 3933 | DPRINTK("EXIT, rc=%d\n", rc); |
| 3934 | return rc; |
| 3935 | } |
| 3936 | |
| 3937 | /** |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3938 | * sata_std_hardreset - COMRESET w/o waiting or classification |
| 3939 | * @link: link to reset |
| 3940 | * @class: resulting class of attached device |
| 3941 | * @deadline: deadline jiffies for the operation |
| 3942 | * |
| 3943 | * Standard SATA COMRESET w/o waiting or classification. |
| 3944 | * |
| 3945 | * LOCKING: |
| 3946 | * Kernel thread context (may sleep) |
| 3947 | * |
| 3948 | * RETURNS: |
| 3949 | * 0 if link offline, -EAGAIN if link online, -errno on errors. |
| 3950 | */ |
| 3951 | int sata_std_hardreset(struct ata_link *link, unsigned int *class, |
| 3952 | unsigned long deadline) |
| 3953 | { |
| 3954 | const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); |
| 3955 | bool online; |
| 3956 | int rc; |
| 3957 | |
| 3958 | /* do hardreset */ |
| 3959 | rc = sata_link_hardreset(link, timing, deadline, &online, NULL); |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 3960 | return online ? -EAGAIN : rc; |
| 3961 | } |
| 3962 | |
| 3963 | /** |
Tejun Heo | 203c75b | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 3964 | * ata_std_postreset - standard postreset callback |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3965 | * @link: the target ata_link |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3966 | * @classes: classes of attached devices |
| 3967 | * |
| 3968 | * This function is invoked after a successful reset. Note that |
| 3969 | * the device might have been reset more than once using |
| 3970 | * different reset methods before postreset is invoked. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3971 | * |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3972 | * LOCKING: |
| 3973 | * Kernel thread context (may sleep) |
| 3974 | */ |
Tejun Heo | 203c75b | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 3975 | void ata_std_postreset(struct ata_link *link, unsigned int *classes) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3976 | { |
Tejun Heo | f046519 | 2008-05-19 01:15:08 +0900 | [diff] [blame] | 3977 | u32 serror; |
| 3978 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3979 | DPRINTK("ENTER\n"); |
| 3980 | |
Tejun Heo | f046519 | 2008-05-19 01:15:08 +0900 | [diff] [blame] | 3981 | /* reset complete, clear SError */ |
| 3982 | if (!sata_scr_read(link, SCR_ERROR, &serror)) |
| 3983 | sata_scr_write(link, SCR_ERROR, serror); |
| 3984 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3985 | /* print link status */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 3986 | sata_print_link_status(link); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3987 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3988 | DPRINTK("EXIT\n"); |
| 3989 | } |
| 3990 | |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 3991 | /** |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3992 | * ata_dev_same_device - Determine whether new ID matches configured device |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 3993 | * @dev: device to compare against |
| 3994 | * @new_class: class of the new device |
| 3995 | * @new_id: IDENTIFY page of the new device |
| 3996 | * |
| 3997 | * Compare @new_class and @new_id against @dev and determine |
| 3998 | * whether @dev is the device indicated by @new_class and |
| 3999 | * @new_id. |
| 4000 | * |
| 4001 | * LOCKING: |
| 4002 | * None. |
| 4003 | * |
| 4004 | * RETURNS: |
| 4005 | * 1 if @dev matches @new_class and @new_id, 0 otherwise. |
| 4006 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4007 | static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class, |
| 4008 | const u16 *new_id) |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4009 | { |
| 4010 | const u16 *old_id = dev->id; |
Tejun Heo | a0cf733 | 2007-01-02 20:18:49 +0900 | [diff] [blame] | 4011 | unsigned char model[2][ATA_ID_PROD_LEN + 1]; |
| 4012 | unsigned char serial[2][ATA_ID_SERNO_LEN + 1]; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4013 | |
| 4014 | if (dev->class != new_class) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4015 | ata_dev_info(dev, "class mismatch %d != %d\n", |
| 4016 | dev->class, new_class); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4017 | return 0; |
| 4018 | } |
| 4019 | |
Tejun Heo | a0cf733 | 2007-01-02 20:18:49 +0900 | [diff] [blame] | 4020 | ata_id_c_string(old_id, model[0], ATA_ID_PROD, sizeof(model[0])); |
| 4021 | ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1])); |
| 4022 | ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0])); |
| 4023 | 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] | 4024 | |
| 4025 | if (strcmp(model[0], model[1])) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4026 | ata_dev_info(dev, "model number mismatch '%s' != '%s'\n", |
| 4027 | model[0], model[1]); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4028 | return 0; |
| 4029 | } |
| 4030 | |
| 4031 | if (strcmp(serial[0], serial[1])) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4032 | ata_dev_info(dev, "serial number mismatch '%s' != '%s'\n", |
| 4033 | serial[0], serial[1]); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4034 | return 0; |
| 4035 | } |
| 4036 | |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4037 | return 1; |
| 4038 | } |
| 4039 | |
| 4040 | /** |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4041 | * ata_dev_reread_id - Re-read IDENTIFY data |
Henrik Kretzschmar | 3fae450 | 2007-06-19 10:10:50 +0200 | [diff] [blame] | 4042 | * @dev: target ATA device |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 4043 | * @readid_flags: read ID flags |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4044 | * |
| 4045 | * Re-read IDENTIFY page and make sure @dev is still attached to |
| 4046 | * the port. |
| 4047 | * |
| 4048 | * LOCKING: |
| 4049 | * Kernel thread context (may sleep) |
| 4050 | * |
| 4051 | * RETURNS: |
| 4052 | * 0 on success, negative errno otherwise |
| 4053 | */ |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4054 | 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] | 4055 | { |
Tejun Heo | 5eb45c0 | 2006-04-02 18:51:52 +0900 | [diff] [blame] | 4056 | unsigned int class = dev->class; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4057 | u16 *id = (void *)dev->link->ap->sector_buf; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4058 | int rc; |
| 4059 | |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 4060 | /* read ID data */ |
Tejun Heo | bff0464 | 2006-11-10 18:08:10 +0900 | [diff] [blame] | 4061 | rc = ata_dev_read_id(dev, &class, readid_flags, id); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4062 | if (rc) |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4063 | return rc; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4064 | |
| 4065 | /* is the device still there? */ |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4066 | if (!ata_dev_same_device(dev, class, id)) |
| 4067 | return -ENODEV; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4068 | |
Tejun Heo | fe635c7 | 2006-05-15 20:57:35 +0900 | [diff] [blame] | 4069 | memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4070 | return 0; |
| 4071 | } |
| 4072 | |
| 4073 | /** |
| 4074 | * ata_dev_revalidate - Revalidate ATA device |
| 4075 | * @dev: device to revalidate |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4076 | * @new_class: new class code |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4077 | * @readid_flags: read ID flags |
| 4078 | * |
| 4079 | * Re-read IDENTIFY page, make sure @dev is still attached to the |
| 4080 | * port and reconfigure it according to the new IDENTIFY page. |
| 4081 | * |
| 4082 | * LOCKING: |
| 4083 | * Kernel thread context (may sleep) |
| 4084 | * |
| 4085 | * RETURNS: |
| 4086 | * 0 on success, negative errno otherwise |
| 4087 | */ |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4088 | int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class, |
| 4089 | unsigned int readid_flags) |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4090 | { |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4091 | u64 n_sectors = dev->n_sectors; |
Tejun Heo | 5920dad | 2009-07-15 17:11:41 +0900 | [diff] [blame] | 4092 | u64 n_native_sectors = dev->n_native_sectors; |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4093 | int rc; |
| 4094 | |
| 4095 | if (!ata_dev_enabled(dev)) |
| 4096 | return -ENODEV; |
| 4097 | |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4098 | /* fail early if !ATA && !ATAPI to avoid issuing [P]IDENTIFY to PMP */ |
| 4099 | if (ata_class_enabled(new_class) && |
Borislav Petkov | f0d0613 | 2009-04-26 16:33:34 +0200 | [diff] [blame] | 4100 | new_class != ATA_DEV_ATA && |
| 4101 | new_class != ATA_DEV_ATAPI && |
Hannes Reinecke | 9162c65 | 2014-11-05 13:08:21 +0100 | [diff] [blame] | 4102 | new_class != ATA_DEV_ZAC && |
Borislav Petkov | f0d0613 | 2009-04-26 16:33:34 +0200 | [diff] [blame] | 4103 | new_class != ATA_DEV_SEMB) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4104 | ata_dev_info(dev, "class mismatch %u != %u\n", |
| 4105 | dev->class, new_class); |
Tejun Heo | 422c9da | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4106 | rc = -ENODEV; |
| 4107 | goto fail; |
| 4108 | } |
| 4109 | |
Tejun Heo | fe30911 | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4110 | /* re-read ID */ |
| 4111 | rc = ata_dev_reread_id(dev, readid_flags); |
| 4112 | if (rc) |
| 4113 | goto fail; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4114 | |
| 4115 | /* configure device according to the new ID */ |
Tejun Heo | efdaedc | 2006-11-01 18:38:52 +0900 | [diff] [blame] | 4116 | rc = ata_dev_configure(dev); |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4117 | if (rc) |
| 4118 | goto fail; |
| 4119 | |
| 4120 | /* verify n_sectors hasn't changed */ |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 4121 | if (dev->class != ATA_DEV_ATA || !n_sectors || |
| 4122 | dev->n_sectors == n_sectors) |
| 4123 | return 0; |
| 4124 | |
| 4125 | /* n_sectors has changed */ |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4126 | ata_dev_warn(dev, "n_sectors mismatch %llu != %llu\n", |
| 4127 | (unsigned long long)n_sectors, |
| 4128 | (unsigned long long)dev->n_sectors); |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 4129 | |
| 4130 | /* |
| 4131 | * Something could have caused HPA to be unlocked |
| 4132 | * involuntarily. If n_native_sectors hasn't changed and the |
| 4133 | * new size matches it, keep the device. |
| 4134 | */ |
| 4135 | if (dev->n_native_sectors == n_native_sectors && |
| 4136 | dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4137 | ata_dev_warn(dev, |
| 4138 | "new n_sectors matches native, probably " |
| 4139 | "late HPA unlock, n_sectors updated\n"); |
Tejun Heo | 68939ce | 2010-05-15 20:09:33 +0200 | [diff] [blame] | 4140 | /* use the larger n_sectors */ |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 4141 | return 0; |
Tejun Heo | 6ddcd3b | 2007-05-15 03:28:15 +0900 | [diff] [blame] | 4142 | } |
| 4143 | |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 4144 | /* |
| 4145 | * Some BIOSes boot w/o HPA but resume w/ HPA locked. Try |
| 4146 | * unlocking HPA in those cases. |
| 4147 | * |
| 4148 | * https://bugzilla.kernel.org/show_bug.cgi?id=15396 |
| 4149 | */ |
| 4150 | if (dev->n_native_sectors == n_native_sectors && |
| 4151 | dev->n_sectors < n_sectors && n_sectors == n_native_sectors && |
| 4152 | !(dev->horkage & ATA_HORKAGE_BROKEN_HPA)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4153 | ata_dev_warn(dev, |
| 4154 | "old n_sectors matches native, probably " |
| 4155 | "late HPA lock, will try to unlock HPA\n"); |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 4156 | /* try unlocking HPA */ |
| 4157 | dev->flags |= ATA_DFLAG_UNLOCK_HPA; |
| 4158 | rc = -EIO; |
| 4159 | } else |
| 4160 | rc = -ENODEV; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4161 | |
Tejun Heo | 445d211 | 2010-04-05 10:33:13 +0900 | [diff] [blame] | 4162 | /* restore original n_[native_]sectors and fail */ |
| 4163 | dev->n_native_sectors = n_native_sectors; |
| 4164 | dev->n_sectors = n_sectors; |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4165 | fail: |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4166 | ata_dev_err(dev, "revalidation failed (errno=%d)\n", rc); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 4167 | return rc; |
| 4168 | } |
| 4169 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4170 | struct ata_blacklist_entry { |
| 4171 | const char *model_num; |
| 4172 | const char *model_rev; |
| 4173 | unsigned long horkage; |
| 4174 | }; |
| 4175 | |
| 4176 | static const struct ata_blacklist_entry ata_device_blacklist [] = { |
| 4177 | /* Devices with DMA related problems under Linux */ |
| 4178 | { "WDC AC11000H", NULL, ATA_HORKAGE_NODMA }, |
| 4179 | { "WDC AC22100H", NULL, ATA_HORKAGE_NODMA }, |
| 4180 | { "WDC AC32500H", NULL, ATA_HORKAGE_NODMA }, |
| 4181 | { "WDC AC33100H", NULL, ATA_HORKAGE_NODMA }, |
| 4182 | { "WDC AC31600H", NULL, ATA_HORKAGE_NODMA }, |
| 4183 | { "WDC AC32100H", "24.09P07", ATA_HORKAGE_NODMA }, |
| 4184 | { "WDC AC23200L", "21.10N21", ATA_HORKAGE_NODMA }, |
| 4185 | { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA }, |
| 4186 | { "CRD-8400B", NULL, ATA_HORKAGE_NODMA }, |
Mark Lord | 7da4c93 | 2010-07-01 18:18:12 -0400 | [diff] [blame] | 4187 | { "CRD-848[02]B", NULL, ATA_HORKAGE_NODMA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4188 | { "CRD-84", NULL, ATA_HORKAGE_NODMA }, |
| 4189 | { "SanDisk SDP3B", NULL, ATA_HORKAGE_NODMA }, |
| 4190 | { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA }, |
| 4191 | { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA }, |
| 4192 | { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA }, |
Mark Lord | 7da4c93 | 2010-07-01 18:18:12 -0400 | [diff] [blame] | 4193 | { "HITACHI CDR-8[34]35",NULL, ATA_HORKAGE_NODMA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4194 | { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA }, |
| 4195 | { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA }, |
| 4196 | { "CD-532E-A", NULL, ATA_HORKAGE_NODMA }, |
| 4197 | { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA }, |
| 4198 | { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA }, |
| 4199 | { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA }, |
| 4200 | { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA }, |
| 4201 | { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4202 | { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA }, |
| 4203 | { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA }, |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 4204 | { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA }, |
Dave Jones | 39f1988 | 2007-05-21 14:31:03 -0400 | [diff] [blame] | 4205 | { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA }, |
Prarit Bhargava | d17d794 | 2012-08-23 15:11:52 -0400 | [diff] [blame] | 4206 | { " 2GB ATA Flash Disk", "ADMA428M", ATA_HORKAGE_NODMA }, |
Shikha Jain | b00622f | 2016-01-11 14:55:45 -0800 | [diff] [blame] | 4207 | { "VRFDFC22048UCHC-TE*", NULL, ATA_HORKAGE_NODMA }, |
Tejun Heo | 3af9a77 | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 4208 | /* Odd clown on sil3726/4726 PMPs */ |
Tejun Heo | 50af2fa | 2008-05-19 01:15:14 +0900 | [diff] [blame] | 4209 | { "Config Disk", NULL, ATA_HORKAGE_DISABLE }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4210 | |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 4211 | /* Weird ATAPI devices */ |
Tejun Heo | 40a1d53 | 2007-06-27 02:49:38 +0900 | [diff] [blame] | 4212 | { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 }, |
Tejun Heo | 6a87e42 | 2008-11-03 19:01:09 +0900 | [diff] [blame] | 4213 | { "QUANTUM DAT DAT72-000", NULL, ATA_HORKAGE_ATAPI_MOD16_DMA }, |
Shan Hai | a32450e | 2013-03-18 10:30:44 +0800 | [diff] [blame] | 4214 | { "Slimtype DVD A DS8A8SH", NULL, ATA_HORKAGE_MAX_SEC_LBA48 }, |
Shan Hai | 0523f03 | 2013-10-28 16:08:01 +0800 | [diff] [blame] | 4215 | { "Slimtype DVD A DS8A9SH", NULL, ATA_HORKAGE_MAX_SEC_LBA48 }, |
Albert Lee | 18d6e9d | 2007-04-02 11:34:15 +0800 | [diff] [blame] | 4216 | |
David Milburn | af34d63 | 2015-07-13 11:48:23 -0500 | [diff] [blame] | 4217 | /* |
| 4218 | * Causes silent data corruption with higher max sects. |
| 4219 | * http://lkml.kernel.org/g/x49wpy40ysk.fsf@segfault.boston.devel.redhat.com |
| 4220 | */ |
| 4221 | { "ST380013AS", "3.20", ATA_HORKAGE_MAX_SEC_1024 }, |
| 4222 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4223 | /* Devices we expect to fail diagnostics */ |
| 4224 | |
| 4225 | /* Devices where NCQ should be avoided */ |
| 4226 | /* NCQ is slow */ |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 4227 | { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ }, |
Tejun Heo | 459ad68 | 2007-12-07 12:46:23 +0900 | [diff] [blame] | 4228 | { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, |
Tejun Heo | 09125ea | 2007-02-28 15:21:23 +0900 | [diff] [blame] | 4229 | /* http://thread.gmane.org/gmane.linux.ide/14907 */ |
| 4230 | { "FUJITSU MHT2060BH", NULL, ATA_HORKAGE_NONCQ }, |
Paul Rolland | 7acfaf3 | 2007-03-26 21:43:44 -0800 | [diff] [blame] | 4231 | /* NCQ is broken */ |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 4232 | { "Maxtor *", "BANC*", ATA_HORKAGE_NONCQ }, |
Alan Cox | 0e3dbc0 | 2007-09-20 15:22:47 +0100 | [diff] [blame] | 4233 | { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ }, |
Paolo Ornati | da6f0ec | 2007-10-04 11:06:56 +0900 | [diff] [blame] | 4234 | { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ }, |
Tejun Heo | e41bd3e | 2007-12-09 19:45:39 +0900 | [diff] [blame] | 4235 | { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ }, |
Lubomir Bulej | 5ccfca9 | 2008-12-22 11:35:22 +0100 | [diff] [blame] | 4236 | { "OCZ CORE_SSD", "02.10104", ATA_HORKAGE_NONCQ }, |
Jeff Garzik | 539cc7c | 2007-09-20 16:31:47 -0400 | [diff] [blame] | 4237 | |
Tejun Heo | ac70a96 | 2008-11-27 13:36:48 +0900 | [diff] [blame] | 4238 | /* Seagate NCQ + FLUSH CACHE firmware bug */ |
Mark Lord | 4d1f908 | 2010-07-05 18:53:37 -0400 | [diff] [blame] | 4239 | { "ST31500341AS", "SD1[5-9]", ATA_HORKAGE_NONCQ | |
Tejun Heo | ac70a96 | 2008-11-27 13:36:48 +0900 | [diff] [blame] | 4240 | ATA_HORKAGE_FIRMWARE_WARN }, |
Tejun Heo | d10d491 | 2008-12-11 13:42:42 +0900 | [diff] [blame] | 4241 | |
Mark Lord | 4d1f908 | 2010-07-05 18:53:37 -0400 | [diff] [blame] | 4242 | { "ST31000333AS", "SD1[5-9]", ATA_HORKAGE_NONCQ | |
Tejun Heo | d10d491 | 2008-12-11 13:42:42 +0900 | [diff] [blame] | 4243 | ATA_HORKAGE_FIRMWARE_WARN }, |
| 4244 | |
Mark Lord | 4d1f908 | 2010-07-05 18:53:37 -0400 | [diff] [blame] | 4245 | { "ST3640[36]23AS", "SD1[5-9]", ATA_HORKAGE_NONCQ | |
Tejun Heo | d10d491 | 2008-12-11 13:42:42 +0900 | [diff] [blame] | 4246 | ATA_HORKAGE_FIRMWARE_WARN }, |
| 4247 | |
Mark Lord | 4d1f908 | 2010-07-05 18:53:37 -0400 | [diff] [blame] | 4248 | { "ST3320[68]13AS", "SD1[5-9]", ATA_HORKAGE_NONCQ | |
Tejun Heo | ac70a96 | 2008-11-27 13:36:48 +0900 | [diff] [blame] | 4249 | ATA_HORKAGE_FIRMWARE_WARN }, |
| 4250 | |
Aleksei Mamlin | 08c85d2 | 2015-07-01 13:48:30 +0300 | [diff] [blame] | 4251 | /* drives which fail FPDMA_AA activation (some may freeze afterwards) */ |
Michele Baldessari | 8780994 | 2013-11-25 19:00:14 +0000 | [diff] [blame] | 4252 | { "ST1000LM024 HN-M101MBB", "2AR10001", ATA_HORKAGE_BROKEN_FPDMA_AA }, |
Michele Baldessari | b28a613 | 2014-03-07 16:34:29 +0000 | [diff] [blame] | 4253 | { "ST1000LM024 HN-M101MBB", "2BA30001", ATA_HORKAGE_BROKEN_FPDMA_AA }, |
Aleksei Mamlin | 08c85d2 | 2015-07-01 13:48:30 +0300 | [diff] [blame] | 4254 | { "VB0250EAVER", "HPG7", ATA_HORKAGE_BROKEN_FPDMA_AA }, |
Michele Baldessari | 8780994 | 2013-11-25 19:00:14 +0000 | [diff] [blame] | 4255 | |
Robert Hancock | 36e337d | 2007-04-02 22:05:29 -0600 | [diff] [blame] | 4256 | /* Blacklist entries taken from Silicon Image 3124/3132 |
| 4257 | Windows driver .inf file - also several Linux problem reports */ |
| 4258 | { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ, }, |
| 4259 | { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ, }, |
| 4260 | { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ, }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4261 | |
Tejun Heo | 68b0ddb | 2010-04-05 10:51:26 +0900 | [diff] [blame] | 4262 | /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */ |
| 4263 | { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, }, |
| 4264 | |
Tejun Heo | 16c55b0 | 2007-08-29 11:58:33 +0900 | [diff] [blame] | 4265 | /* devices which puke on READ_NATIVE_MAX */ |
| 4266 | { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, }, |
| 4267 | { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA }, |
| 4268 | { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA }, |
| 4269 | { "MAXTOR 6L080L4", "A93.0500", ATA_HORKAGE_BROKEN_HPA }, |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4270 | |
Tejun Heo | 7831387b | 2009-08-07 01:59:15 +0900 | [diff] [blame] | 4271 | /* this one allows HPA unlocking but fails IOs on the area */ |
| 4272 | { "OCZ-VERTEX", "1.30", ATA_HORKAGE_BROKEN_HPA }, |
| 4273 | |
Alan Cox | 93328e11 | 2007-09-29 04:06:48 -0400 | [diff] [blame] | 4274 | /* Devices which report 1 sector over size HPA */ |
| 4275 | { "ST340823A", NULL, ATA_HORKAGE_HPA_SIZE, }, |
| 4276 | { "ST320413A", NULL, ATA_HORKAGE_HPA_SIZE, }, |
Mikko Rapeli | b152fcd | 2008-02-19 01:41:25 +0100 | [diff] [blame] | 4277 | { "ST310211A", NULL, ATA_HORKAGE_HPA_SIZE, }, |
Alan Cox | 93328e11 | 2007-09-29 04:06:48 -0400 | [diff] [blame] | 4278 | |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 4279 | /* Devices which get the IVB wrong */ |
| 4280 | { "QUANTUM FIREBALLlct10 05", "A03.0900", ATA_HORKAGE_IVB, }, |
Alan Cox | a79067e | 2008-04-29 14:08:36 +0100 | [diff] [blame] | 4281 | /* Maybe we should just blacklist TSSTcorp... */ |
Mark Lord | 7da4c93 | 2010-07-01 18:18:12 -0400 | [diff] [blame] | 4282 | { "TSSTcorp CDDVDW SH-S202[HJN]", "SB0[01]", ATA_HORKAGE_IVB, }, |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 4283 | |
Jens Axboe | 9ce8e30 | 2008-08-27 15:23:18 +0200 | [diff] [blame] | 4284 | /* Devices that do not need bridging limits applied */ |
| 4285 | { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK, }, |
Jeff Garzik | 04d0f1b8 | 2012-08-17 13:36:59 -0400 | [diff] [blame] | 4286 | { "BUFFALO HD-QSU2/R5", NULL, ATA_HORKAGE_BRIDGE_OK, }, |
Jens Axboe | 9ce8e30 | 2008-08-27 15:23:18 +0200 | [diff] [blame] | 4287 | |
Tejun Heo | 9062712 | 2009-01-29 20:31:36 +0900 | [diff] [blame] | 4288 | /* Devices which aren't very happy with higher link speeds */ |
| 4289 | { "WD My Book", NULL, ATA_HORKAGE_1_5_GBPS, }, |
Daniel J Blueman | c531077 | 2012-07-23 12:22:37 +0800 | [diff] [blame] | 4290 | { "Seagate FreeAgent GoFlex", NULL, ATA_HORKAGE_1_5_GBPS, }, |
Tejun Heo | 9062712 | 2009-01-29 20:31:36 +0900 | [diff] [blame] | 4291 | |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 4292 | /* |
| 4293 | * Devices which choke on SETXFER. Applies only if both the |
| 4294 | * device and controller are SATA. |
| 4295 | */ |
Tejun Heo | cd69187 | 2011-06-22 12:13:10 +0200 | [diff] [blame] | 4296 | { "PIONEER DVD-RW DVRTD08", NULL, ATA_HORKAGE_NOSETXFER }, |
Vladimir LAVALLADE | 3a25179 | 2012-01-08 13:50:13 +0100 | [diff] [blame] | 4297 | { "PIONEER DVD-RW DVRTD08A", NULL, ATA_HORKAGE_NOSETXFER }, |
| 4298 | { "PIONEER DVD-RW DVR-215", NULL, ATA_HORKAGE_NOSETXFER }, |
Tejun Heo | cd69187 | 2011-06-22 12:13:10 +0200 | [diff] [blame] | 4299 | { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER }, |
| 4300 | { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER }, |
Tejun Heo | d0cb43b | 2009-07-09 09:27:50 +0900 | [diff] [blame] | 4301 | |
Marc Carino | f78dea0 | 2013-12-16 18:15:53 -0800 | [diff] [blame] | 4302 | /* devices that don't properly handle queued TRIM commands */ |
Martin K. Petersen | 243918b | 2015-06-18 14:50:18 -0400 | [diff] [blame] | 4303 | { "Micron_M500_*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | |
Martin K. Petersen | e61f7d1 | 2015-01-08 10:34:27 -0500 | [diff] [blame] | 4304 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Martin K. Petersen | ff7f53f | 2015-03-27 15:17:20 -0400 | [diff] [blame] | 4305 | { "Crucial_CT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | |
| 4306 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Martin K. Petersen | 9051bd3 | 2015-07-15 21:03:23 -0400 | [diff] [blame] | 4307 | { "Micron_M5[15]0_*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM | |
Martin K. Petersen | ff7f53f | 2015-03-27 15:17:20 -0400 | [diff] [blame] | 4308 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4309 | { "Crucial_CT*M550*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM | |
| 4310 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4311 | { "Crucial_CT*MX100*", "MU01", ATA_HORKAGE_NO_NCQ_TRIM | |
| 4312 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Martin K. Petersen | 9a9324d | 2015-05-04 12:20:29 -0400 | [diff] [blame] | 4313 | { "Samsung SSD 8*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | |
Martin K. Petersen | 6fc4d97 | 2015-03-27 15:17:21 -0400 | [diff] [blame] | 4314 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Guillermo A. Amaral | 7a7184b | 2015-08-25 23:29:13 -0700 | [diff] [blame] | 4315 | { "FCCT*M500*", NULL, ATA_HORKAGE_NO_NCQ_TRIM | |
| 4316 | ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Martin K. Petersen | e61f7d1 | 2015-01-08 10:34:27 -0500 | [diff] [blame] | 4317 | |
Arne Fitzenreiter | cda57b1 | 2015-07-15 13:54:37 +0200 | [diff] [blame] | 4318 | /* devices that don't properly handle TRIM commands */ |
| 4319 | { "SuperSSpeed S238*", NULL, ATA_HORKAGE_NOTRIM, }, |
| 4320 | |
Martin K. Petersen | e61f7d1 | 2015-01-08 10:34:27 -0500 | [diff] [blame] | 4321 | /* |
| 4322 | * As defined, the DRAT (Deterministic Read After Trim) and RZAT |
| 4323 | * (Return Zero After Trim) flags in the ATA Command Set are |
| 4324 | * unreliable in the sense that they only define what happens if |
| 4325 | * the device successfully executed the DSM TRIM command. TRIM |
| 4326 | * is only advisory, however, and the device is free to silently |
| 4327 | * ignore all or parts of the request. |
| 4328 | * |
| 4329 | * Whitelist drives that are known to reliably return zeroes |
| 4330 | * after TRIM. |
| 4331 | */ |
| 4332 | |
| 4333 | /* |
| 4334 | * The intel 510 drive has buggy DRAT/RZAT. Explicitly exclude |
| 4335 | * that model before whitelisting all other intel SSDs. |
| 4336 | */ |
| 4337 | { "INTEL*SSDSC2MH*", NULL, 0, }, |
| 4338 | |
Martin K. Petersen | ff7f53f | 2015-03-27 15:17:20 -0400 | [diff] [blame] | 4339 | { "Micron*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4340 | { "Crucial*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Martin K. Petersen | e61f7d1 | 2015-01-08 10:34:27 -0500 | [diff] [blame] | 4341 | { "INTEL*SSD*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4342 | { "SSD*INTEL*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4343 | { "Samsung*SSD*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4344 | { "SAMSUNG*SSD*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
| 4345 | { "ST[1248][0248]0[FH]*", NULL, ATA_HORKAGE_ZERO_AFTER_TRIM, }, |
Marc Carino | f78dea0 | 2013-12-16 18:15:53 -0800 | [diff] [blame] | 4346 | |
Tejun Heo | ecd75ad | 2014-01-16 09:47:17 -0500 | [diff] [blame] | 4347 | /* |
| 4348 | * Some WD SATA-I drives spin up and down erratically when the link |
| 4349 | * is put into the slumber mode. We don't have full list of the |
| 4350 | * affected devices. Disable LPM if the device matches one of the |
| 4351 | * known prefixes and is SATA-1. As a side effect LPM partial is |
| 4352 | * lost too. |
| 4353 | * |
| 4354 | * https://bugzilla.kernel.org/show_bug.cgi?id=57211 |
| 4355 | */ |
| 4356 | { "WDC WD800JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4357 | { "WDC WD1200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4358 | { "WDC WD1600JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4359 | { "WDC WD2000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4360 | { "WDC WD2500JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4361 | { "WDC WD3000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4362 | { "WDC WD3200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM }, |
| 4363 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4364 | /* End Marker */ |
| 4365 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | }; |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 4367 | |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 4368 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4369 | { |
Tejun Heo | 8bfa79f | 2007-01-02 20:19:40 +0900 | [diff] [blame] | 4370 | unsigned char model_num[ATA_ID_PROD_LEN + 1]; |
| 4371 | unsigned char model_rev[ATA_ID_FW_REV_LEN + 1]; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4372 | const struct ata_blacklist_entry *ad = ata_device_blacklist; |
Albert Lee | 3a77827 | 2006-06-22 13:00:25 +0800 | [diff] [blame] | 4373 | |
Tejun Heo | 8bfa79f | 2007-01-02 20:19:40 +0900 | [diff] [blame] | 4374 | ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); |
| 4375 | 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] | 4376 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4377 | while (ad->model_num) { |
George Spelvin | 1c40279 | 2014-10-07 07:26:38 -0400 | [diff] [blame] | 4378 | if (glob_match(ad->model_num, model_num)) { |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4379 | if (ad->model_rev == NULL) |
| 4380 | return ad->horkage; |
George Spelvin | 1c40279 | 2014-10-07 07:26:38 -0400 | [diff] [blame] | 4381 | if (glob_match(ad->model_rev, model_rev)) |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4382 | return ad->horkage; |
Alan Cox | f4b15fe | 2006-03-22 15:54:04 +0000 | [diff] [blame] | 4383 | } |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4384 | ad++; |
Alan Cox | f4b15fe | 2006-03-22 15:54:04 +0000 | [diff] [blame] | 4385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | return 0; |
| 4387 | } |
| 4388 | |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4389 | static int ata_dma_blacklisted(const struct ata_device *dev) |
| 4390 | { |
| 4391 | /* We don't support polling DMA. |
| 4392 | * DMA blacklist those ATAPI devices with CDB-intr (and use PIO) |
| 4393 | * if the LLDD handles only interrupts in the HSM_ST_LAST state. |
| 4394 | */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4395 | if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4396 | (dev->flags & ATA_DFLAG_CDB_INTR)) |
| 4397 | return 1; |
Tejun Heo | 75683fe | 2007-07-05 13:31:27 +0900 | [diff] [blame] | 4398 | return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0; |
Alan Cox | 6919a0a | 2006-10-27 19:08:46 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4401 | /** |
Alan Cox | 6bbfd53 | 2007-11-05 22:58:58 +0000 | [diff] [blame] | 4402 | * ata_is_40wire - check drive side detection |
| 4403 | * @dev: device |
| 4404 | * |
| 4405 | * Perform drive side detection decoding, allowing for device vendors |
| 4406 | * who can't follow the documentation. |
| 4407 | */ |
| 4408 | |
| 4409 | static int ata_is_40wire(struct ata_device *dev) |
| 4410 | { |
| 4411 | if (dev->horkage & ATA_HORKAGE_IVB) |
| 4412 | return ata_drive_40wire_relaxed(dev->id); |
| 4413 | return ata_drive_40wire(dev->id); |
| 4414 | } |
| 4415 | |
| 4416 | /** |
Alan Cox | 15a5551 | 2008-03-28 14:33:46 -0700 | [diff] [blame] | 4417 | * cable_is_40wire - 40/80/SATA decider |
| 4418 | * @ap: port to consider |
| 4419 | * |
| 4420 | * This function encapsulates the policy for speed management |
| 4421 | * in one place. At the moment we don't cache the result but |
| 4422 | * there is a good case for setting ap->cbl to the result when |
| 4423 | * we are called with unknown cables (and figuring out if it |
| 4424 | * impacts hotplug at all). |
| 4425 | * |
| 4426 | * Return 1 if the cable appears to be 40 wire. |
| 4427 | */ |
| 4428 | |
| 4429 | static int cable_is_40wire(struct ata_port *ap) |
| 4430 | { |
| 4431 | struct ata_link *link; |
| 4432 | struct ata_device *dev; |
| 4433 | |
Tejun Heo | 4a9c7b3 | 2008-10-27 19:59:23 +0900 | [diff] [blame] | 4434 | /* If the controller thinks we are 40 wire, we are. */ |
Alan Cox | 15a5551 | 2008-03-28 14:33:46 -0700 | [diff] [blame] | 4435 | if (ap->cbl == ATA_CBL_PATA40) |
| 4436 | return 1; |
Tejun Heo | 4a9c7b3 | 2008-10-27 19:59:23 +0900 | [diff] [blame] | 4437 | |
| 4438 | /* If the controller thinks we are 80 wire, we are. */ |
Alan Cox | 15a5551 | 2008-03-28 14:33:46 -0700 | [diff] [blame] | 4439 | if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) |
| 4440 | return 0; |
Tejun Heo | 4a9c7b3 | 2008-10-27 19:59:23 +0900 | [diff] [blame] | 4441 | |
| 4442 | /* If the system is known to be 40 wire short cable (eg |
| 4443 | * laptop), then we allow 80 wire modes even if the drive |
| 4444 | * isn't sure. |
| 4445 | */ |
Alan Cox | f792068 | 2008-04-08 16:37:50 +0100 | [diff] [blame] | 4446 | if (ap->cbl == ATA_CBL_PATA40_SHORT) |
| 4447 | return 0; |
Alan Cox | 15a5551 | 2008-03-28 14:33:46 -0700 | [diff] [blame] | 4448 | |
Tejun Heo | 4a9c7b3 | 2008-10-27 19:59:23 +0900 | [diff] [blame] | 4449 | /* If the controller doesn't know, we scan. |
| 4450 | * |
| 4451 | * Note: We look for all 40 wire detects at this point. Any |
| 4452 | * 80 wire detect is taken to be 80 wire cable because |
| 4453 | * - in many setups only the one drive (slave if present) will |
| 4454 | * give a valid detect |
| 4455 | * - if you have a non detect capable drive you don't want it |
| 4456 | * to colour the choice |
| 4457 | */ |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 4458 | ata_for_each_link(link, ap, EDGE) { |
| 4459 | ata_for_each_dev(dev, link, ENABLED) { |
| 4460 | if (!ata_is_40wire(dev)) |
Alan Cox | 15a5551 | 2008-03-28 14:33:46 -0700 | [diff] [blame] | 4461 | return 0; |
| 4462 | } |
| 4463 | } |
| 4464 | return 1; |
| 4465 | } |
| 4466 | |
| 4467 | /** |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4468 | * ata_dev_xfermask - Compute supported xfermask of the given device |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4469 | * @dev: Device to compute xfermask for |
| 4470 | * |
Tejun Heo | acf356b | 2006-03-24 14:07:50 +0900 | [diff] [blame] | 4471 | * Compute supported xfermask of @dev and store it in |
| 4472 | * dev->*_mask. This function is responsible for applying all |
| 4473 | * known limits including host controller limits, device |
| 4474 | * blacklist, etc... |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4475 | * |
| 4476 | * LOCKING: |
| 4477 | * None. |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4478 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4479 | static void ata_dev_xfermask(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4481 | struct ata_link *link = dev->link; |
| 4482 | struct ata_port *ap = link->ap; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4483 | struct ata_host *host = ap->host; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4484 | unsigned long xfer_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4485 | |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 4486 | /* controller modes available */ |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 4487 | xfer_mask = ata_pack_xfermask(ap->pio_mask, |
| 4488 | ap->mwdma_mask, ap->udma_mask); |
| 4489 | |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 4490 | /* drive modes available */ |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 4491 | xfer_mask &= ata_pack_xfermask(dev->pio_mask, |
| 4492 | dev->mwdma_mask, dev->udma_mask); |
| 4493 | xfer_mask &= ata_id_xfermask(dev->id); |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 4494 | |
Alan Cox | b352e57 | 2006-08-10 18:52:12 +0100 | [diff] [blame] | 4495 | /* |
| 4496 | * CFA Advanced TrueIDE timings are not allowed on a shared |
| 4497 | * cable |
| 4498 | */ |
| 4499 | if (ata_dev_pair(dev)) { |
| 4500 | /* No PIO5 or PIO6 */ |
| 4501 | xfer_mask &= ~(0x03 << (ATA_SHIFT_PIO + 5)); |
| 4502 | /* No MWDMA3 or MWDMA 4 */ |
| 4503 | xfer_mask &= ~(0x03 << (ATA_SHIFT_MWDMA + 3)); |
| 4504 | } |
| 4505 | |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 4506 | if (ata_dma_blacklisted(dev)) { |
| 4507 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4508 | ata_dev_warn(dev, |
| 4509 | "device is on DMA blacklist, disabling DMA\n"); |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 4510 | } |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 4511 | |
Petr Vandrovec | 14d66ab | 2007-03-08 10:12:12 +0100 | [diff] [blame] | 4512 | if ((host->flags & ATA_HOST_SIMPLEX) && |
Jeff Garzik | 2dcb407 | 2007-10-19 06:42:56 -0400 | [diff] [blame] | 4513 | host->simplex_claimed && host->simplex_claimed != ap) { |
Tejun Heo | 37deecb | 2006-08-10 16:59:07 +0900 | [diff] [blame] | 4514 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4515 | ata_dev_warn(dev, |
| 4516 | "simplex DMA is claimed by other device, disabling DMA\n"); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 4517 | } |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 4518 | |
Jeff Garzik | e424675 | 2007-03-09 09:56:46 -0500 | [diff] [blame] | 4519 | if (ap->flags & ATA_FLAG_NO_IORDY) |
| 4520 | xfer_mask &= ata_pio_mask_no_iordy(dev); |
| 4521 | |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 4522 | if (ap->ops->mode_filter) |
Alan Cox | a76b62ca | 2007-03-09 09:34:07 -0500 | [diff] [blame] | 4523 | xfer_mask = ap->ops->mode_filter(dev, xfer_mask); |
Alan Cox | 5444a6f | 2006-03-27 18:58:20 +0100 | [diff] [blame] | 4524 | |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 4525 | /* Apply cable rule here. Don't apply it early because when |
| 4526 | * we handle hot plug the cable type can itself change. |
| 4527 | * Check this last so that we know if the transfer rate was |
| 4528 | * solely limited by the cable. |
| 4529 | * Unknown or 80 wire cables reported host side are checked |
| 4530 | * drive side as well. Cases where we know a 40wire cable |
| 4531 | * is used safely for 80 are not checked here. |
| 4532 | */ |
| 4533 | if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA)) |
| 4534 | /* UDMA/44 or higher would be available */ |
Alan Cox | 15a5551 | 2008-03-28 14:33:46 -0700 | [diff] [blame] | 4535 | if (cable_is_40wire(ap)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 4536 | ata_dev_warn(dev, |
| 4537 | "limited to UDMA/33 due to 40-wire cable\n"); |
Robert Hancock | 8343f88 | 2007-03-06 02:37:51 -0800 | [diff] [blame] | 4538 | xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA); |
| 4539 | } |
| 4540 | |
Tejun Heo | 565083e | 2006-04-02 17:54:47 +0900 | [diff] [blame] | 4541 | ata_unpack_xfermask(xfer_mask, &dev->pio_mask, |
| 4542 | &dev->mwdma_mask, &dev->udma_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4543 | } |
| 4544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4547 | * @dev: Device to which command will be sent |
| 4548 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4549 | * Issue SET FEATURES - XFER MODE command to device @dev |
| 4550 | * on port @ap. |
| 4551 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4553 | * PCI/etc. bus probe sem. |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4554 | * |
| 4555 | * RETURNS: |
| 4556 | * 0 on success, AC_ERR_* mask otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4557 | */ |
| 4558 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4559 | static unsigned int ata_dev_set_xfermode(struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4561 | struct ata_taskfile tf; |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4562 | unsigned int err_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | |
| 4564 | /* set up set-features taskfile */ |
| 4565 | DPRINTK("set features - xfer mode\n"); |
| 4566 | |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 4567 | /* Some controllers and ATAPI devices show flaky interrupt |
| 4568 | * behavior after setting xfer mode. Use polling instead. |
| 4569 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4570 | ata_tf_init(dev, &tf); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4571 | tf.command = ATA_CMD_SET_FEATURES; |
| 4572 | tf.feature = SETFEATURES_XFER; |
Tejun Heo | 464cf17 | 2007-05-27 15:10:40 +0200 | [diff] [blame] | 4573 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_POLLING; |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4574 | tf.protocol = ATA_PROT_NODATA; |
Alan Cox | b9f8ab2 | 2007-11-19 14:33:11 +0000 | [diff] [blame] | 4575 | /* If we are using IORDY we must send the mode setting command */ |
Jeff Garzik | 11b7bec | 2007-11-23 21:12:14 -0500 | [diff] [blame] | 4576 | if (ata_pio_need_iordy(dev)) |
| 4577 | tf.nsect = dev->xfer_mode; |
Alan Cox | b9f8ab2 | 2007-11-19 14:33:11 +0000 | [diff] [blame] | 4578 | /* If the device has IORDY and the controller does not - turn it off */ |
| 4579 | else if (ata_id_has_iordy(dev->id)) |
Jeff Garzik | 11b7bec | 2007-11-23 21:12:14 -0500 | [diff] [blame] | 4580 | tf.nsect = 0x01; |
Alan Cox | b9f8ab2 | 2007-11-19 14:33:11 +0000 | [diff] [blame] | 4581 | else /* In the ancient relic department - skip all of this */ |
| 4582 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4583 | |
Mikulas Patocka | d531be2 | 2015-07-08 13:06:12 -0400 | [diff] [blame] | 4584 | /* On some disks, this command causes spin-up, so we need longer timeout */ |
| 4585 | err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 15000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | |
Tejun Heo | 83206a2 | 2006-03-24 15:25:31 +0900 | [diff] [blame] | 4587 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4588 | return err_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | } |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 4590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | /** |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4592 | * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4593 | * @dev: Device to which command will be sent |
| 4594 | * @enable: Whether to enable or disable the feature |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4595 | * @feature: The sector count represents the feature to set |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4596 | * |
| 4597 | * Issue SET FEATURES - SATA FEATURES command to device @dev |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4598 | * on port @ap with sector count |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4599 | * |
| 4600 | * LOCKING: |
| 4601 | * PCI/etc. bus probe sem. |
| 4602 | * |
| 4603 | * RETURNS: |
| 4604 | * 0 on success, AC_ERR_* mask otherwise. |
| 4605 | */ |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 4606 | unsigned int ata_dev_set_feature(struct ata_device *dev, u8 enable, u8 feature) |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4607 | { |
| 4608 | struct ata_taskfile tf; |
| 4609 | unsigned int err_mask; |
| 4610 | |
| 4611 | /* set up set-features taskfile */ |
| 4612 | DPRINTK("set features - SATA features\n"); |
| 4613 | |
| 4614 | ata_tf_init(dev, &tf); |
| 4615 | tf.command = ATA_CMD_SET_FEATURES; |
| 4616 | tf.feature = enable; |
| 4617 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 4618 | tf.protocol = ATA_PROT_NODATA; |
Jeff Garzik | 218f3d3 | 2007-10-25 00:33:27 -0400 | [diff] [blame] | 4619 | tf.nsect = feature; |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4620 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 4621 | 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] | 4622 | |
| 4623 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4624 | return err_mask; |
| 4625 | } |
Jeff Garzik | 633de4c | 2012-09-13 01:12:29 -0400 | [diff] [blame] | 4626 | EXPORT_SYMBOL_GPL(ata_dev_set_feature); |
Kristen Carlson Accardi | 9f45cbd | 2007-08-15 03:57:11 -0400 | [diff] [blame] | 4627 | |
| 4628 | /** |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4629 | * ata_dev_init_params - Issue INIT DEV PARAMS command |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4630 | * @dev: Device to which command will be sent |
Randy Dunlap | e2a7f77 | 2006-05-18 10:50:18 -0700 | [diff] [blame] | 4631 | * @heads: Number of heads (taskfile parameter) |
| 4632 | * @sectors: Number of sectors (taskfile parameter) |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4633 | * |
| 4634 | * LOCKING: |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4635 | * Kernel thread context (may sleep) |
| 4636 | * |
| 4637 | * RETURNS: |
| 4638 | * 0 on success, AC_ERR_* mask otherwise. |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4639 | */ |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4640 | static unsigned int ata_dev_init_params(struct ata_device *dev, |
| 4641 | u16 heads, u16 sectors) |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4642 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4643 | struct ata_taskfile tf; |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4644 | unsigned int err_mask; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4645 | |
| 4646 | /* Number of sectors per track 1-255. Number of heads 1-16 */ |
| 4647 | if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) |
Albert Lee | 00b6f5e | 2006-03-27 16:39:18 +0800 | [diff] [blame] | 4648 | return AC_ERR_INVALID; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4649 | |
| 4650 | /* set up init dev params taskfile */ |
| 4651 | DPRINTK("init dev params \n"); |
| 4652 | |
Tejun Heo | 3373efd | 2006-05-15 20:57:53 +0900 | [diff] [blame] | 4653 | ata_tf_init(dev, &tf); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 4654 | tf.command = ATA_CMD_INIT_DEV_PARAMS; |
| 4655 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 4656 | tf.protocol = ATA_PROT_NODATA; |
| 4657 | tf.nsect = sectors; |
| 4658 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4659 | |
Tejun Heo | 2b78910 | 2007-10-09 15:05:44 +0900 | [diff] [blame] | 4660 | 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] | 4661 | /* A clean abort indicates an original or just out of spec drive |
| 4662 | and we should continue as we issue the setup based on the |
| 4663 | drive reported working geometry */ |
| 4664 | if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) |
| 4665 | err_mask = 0; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4666 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 4667 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 4668 | return err_mask; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4672 | * ata_sg_clean - Unmap DMA memory associated with command |
| 4673 | * @qc: Command containing DMA memory to be released |
| 4674 | * |
| 4675 | * Unmap all mapped DMA memory associated with this command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4676 | * |
| 4677 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4678 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4679 | */ |
Tejun Heo | 70e6ad0 | 2006-11-14 22:47:10 +0900 | [diff] [blame] | 4680 | void ata_sg_clean(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4681 | { |
| 4682 | struct ata_port *ap = qc->ap; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4683 | struct scatterlist *sg = qc->sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | int dir = qc->dma_dir; |
| 4685 | |
Tejun Heo | efcb3cf | 2009-01-09 19:19:14 +0900 | [diff] [blame] | 4686 | WARN_ON_ONCE(sg == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4687 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4688 | VPRINTK("unmapping %u sg elements\n", qc->n_elem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4689 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4690 | if (qc->n_elem) |
FUJITA Tomonori | 5825627 | 2009-02-27 17:35:43 +0900 | [diff] [blame] | 4691 | dma_unmap_sg(ap->dev, sg, qc->orig_n_elem, dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | |
| 4693 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4694 | qc->sg = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
| 4697 | /** |
Tejun Heo | 5895ef9 | 2008-06-17 12:36:26 +0900 | [diff] [blame] | 4698 | * atapi_check_dma - Check whether ATAPI DMA can be supported |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | * @qc: Metadata associated with taskfile to check |
| 4700 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 4701 | * Allow low-level driver to filter ATA PACKET commands, returning |
| 4702 | * a status indicating whether or not it is OK to use DMA for the |
| 4703 | * supplied PACKET command. |
| 4704 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4705 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4706 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4707 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | * RETURNS: 0 when ATAPI DMA can be used |
| 4709 | * nonzero otherwise |
| 4710 | */ |
Tejun Heo | 5895ef9 | 2008-06-17 12:36:26 +0900 | [diff] [blame] | 4711 | int atapi_check_dma(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | { |
| 4713 | struct ata_port *ap = qc->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4715 | /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a |
| 4716 | * few ATAPI devices choke on such DMA requests. |
| 4717 | */ |
Tejun Heo | 6a87e42 | 2008-11-03 19:01:09 +0900 | [diff] [blame] | 4718 | if (!(qc->dev->horkage & ATA_HORKAGE_ATAPI_MOD16_DMA) && |
| 4719 | unlikely(qc->nbytes & 15)) |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4720 | return 1; |
Albert Lee | 6f23a31 | 2007-04-02 11:39:25 +0800 | [diff] [blame] | 4721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | if (ap->ops->check_atapi_dma) |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4723 | return ap->ops->check_atapi_dma(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4725 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | } |
Tejun Heo | b9a4197 | 2007-06-27 02:48:43 +0900 | [diff] [blame] | 4727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4728 | /** |
Tejun Heo | 31cc23b | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4729 | * ata_std_qc_defer - Check whether a qc needs to be deferred |
| 4730 | * @qc: ATA command in question |
| 4731 | * |
| 4732 | * Non-NCQ commands cannot run with any other command, NCQ or |
| 4733 | * not. As upper layer only knows the queue depth, we are |
| 4734 | * responsible for maintaining exclusion. This function checks |
| 4735 | * whether a new command @qc can be issued. |
| 4736 | * |
| 4737 | * LOCKING: |
| 4738 | * spin_lock_irqsave(host lock) |
| 4739 | * |
| 4740 | * RETURNS: |
| 4741 | * ATA_DEFER_* if deferring is needed, 0 otherwise. |
| 4742 | */ |
| 4743 | int ata_std_qc_defer(struct ata_queued_cmd *qc) |
| 4744 | { |
| 4745 | struct ata_link *link = qc->dev->link; |
| 4746 | |
| 4747 | if (qc->tf.protocol == ATA_PROT_NCQ) { |
| 4748 | if (!ata_tag_valid(link->active_tag)) |
| 4749 | return 0; |
| 4750 | } else { |
| 4751 | if (!ata_tag_valid(link->active_tag) && !link->sactive) |
| 4752 | return 0; |
| 4753 | } |
| 4754 | |
| 4755 | return ATA_DEFER_LINK; |
| 4756 | } |
| 4757 | |
Brian King | e46834c | 2006-03-17 17:04:03 -0600 | [diff] [blame] | 4758 | void ata_noop_qc_prep(struct ata_queued_cmd *qc) { } |
| 4759 | |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4760 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4761 | * ata_sg_init - Associate command with scatter-gather table. |
| 4762 | * @qc: Command to be associated |
| 4763 | * @sg: Scatter-gather table. |
| 4764 | * @n_elem: Number of elements in s/g table. |
| 4765 | * |
| 4766 | * Initialize the data-related elements of queued_cmd @qc |
| 4767 | * to point to a scatter-gather table @sg, containing @n_elem |
| 4768 | * elements. |
| 4769 | * |
| 4770 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4771 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4772 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4773 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
| 4774 | unsigned int n_elem) |
| 4775 | { |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4776 | qc->sg = sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4777 | qc->n_elem = n_elem; |
Tejun Heo | ff2aeb1 | 2007-12-05 16:43:11 +0900 | [diff] [blame] | 4778 | qc->cursg = qc->sg; |
| 4779 | } |
| 4780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4782 | * ata_sg_setup - DMA-map the scatter-gather table associated with a command. |
| 4783 | * @qc: Command with scatter-gather table to be mapped. |
| 4784 | * |
| 4785 | * DMA-map the scatter-gather table associated with queued_cmd @qc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | * |
| 4787 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4788 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | * |
| 4790 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4791 | * Zero on success, negative on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | * |
| 4793 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4794 | static int ata_sg_setup(struct ata_queued_cmd *qc) |
| 4795 | { |
| 4796 | struct ata_port *ap = qc->ap; |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4797 | unsigned int n_elem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | |
Tejun Heo | 44877b4 | 2007-02-21 01:06:51 +0900 | [diff] [blame] | 4799 | VPRINTK("ENTER, ata%u\n", ap->print_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4801 | n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); |
| 4802 | if (n_elem < 1) |
| 4803 | return -1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4804 | |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4805 | DPRINTK("%d sg elements mapped\n", n_elem); |
FUJITA Tomonori | 5825627 | 2009-02-27 17:35:43 +0900 | [diff] [blame] | 4806 | qc->orig_n_elem = qc->n_elem; |
James Bottomley | dde2020 | 2008-02-19 11:36:56 +0100 | [diff] [blame] | 4807 | qc->n_elem = n_elem; |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 4808 | qc->flags |= ATA_QCFLAG_DMAMAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | |
| 4810 | return 0; |
| 4811 | } |
| 4812 | |
| 4813 | /** |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4814 | * swap_buf_le16 - swap halves of 16-bit words in place |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4815 | * @buf: Buffer to swap |
| 4816 | * @buf_words: Number of 16-bit words in buffer. |
| 4817 | * |
| 4818 | * Swap halves of 16-bit words if needed to convert from |
| 4819 | * little-endian byte order to native cpu byte order, or |
| 4820 | * vice-versa. |
| 4821 | * |
| 4822 | * LOCKING: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 4823 | * Inherited from caller. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4824 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | void swap_buf_le16(u16 *buf, unsigned int buf_words) |
| 4826 | { |
| 4827 | #ifdef __BIG_ENDIAN |
| 4828 | unsigned int i; |
| 4829 | |
| 4830 | for (i = 0; i < buf_words; i++) |
| 4831 | buf[i] = le16_to_cpu(buf[i]); |
| 4832 | #endif /* __BIG_ENDIAN */ |
| 4833 | } |
| 4834 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 4835 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4836 | * ata_qc_new_init - Request an available ATA command, and initialize it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | * @dev: Device from whom we request an available command structure |
Randy Dunlap | 38755e8 | 2015-08-09 18:37:36 -0700 | [diff] [blame] | 4838 | * @tag: tag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4839 | * |
| 4840 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4841 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | */ |
| 4843 | |
Shaohua Li | 98bd4be | 2015-01-23 19:52:07 -0800 | [diff] [blame] | 4844 | struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4846 | struct ata_port *ap = dev->link->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | struct ata_queued_cmd *qc; |
| 4848 | |
Shaohua Li | 98bd4be | 2015-01-23 19:52:07 -0800 | [diff] [blame] | 4849 | /* no command while frozen */ |
| 4850 | if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) |
| 4851 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | |
Shaohua Li | 98bd4be | 2015-01-23 19:52:07 -0800 | [diff] [blame] | 4853 | /* libsas case */ |
Shaohua Li | 5067c04 | 2015-03-12 10:32:18 -0700 | [diff] [blame] | 4854 | if (ap->flags & ATA_FLAG_SAS_HOST) { |
Shaohua Li | 98bd4be | 2015-01-23 19:52:07 -0800 | [diff] [blame] | 4855 | tag = ata_sas_allocate_tag(ap); |
| 4856 | if (tag < 0) |
| 4857 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | } |
| 4859 | |
Shaohua Li | 98bd4be | 2015-01-23 19:52:07 -0800 | [diff] [blame] | 4860 | qc = __ata_qc_from_tag(ap, tag); |
| 4861 | qc->tag = tag; |
| 4862 | qc->scsicmd = NULL; |
| 4863 | qc->ap = ap; |
| 4864 | qc->dev = dev; |
| 4865 | |
| 4866 | ata_qc_reinit(qc); |
| 4867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4868 | return qc; |
| 4869 | } |
| 4870 | |
Tejun Heo | 8a8bc22 | 2008-11-10 14:48:21 +0900 | [diff] [blame] | 4871 | /** |
| 4872 | * ata_qc_free - free unused ata_queued_cmd |
| 4873 | * @qc: Command to complete |
| 4874 | * |
| 4875 | * Designed to free unused ata_queued_cmd object |
| 4876 | * in case something prevents using it. |
| 4877 | * |
| 4878 | * LOCKING: |
| 4879 | * spin_lock_irqsave(host lock) |
| 4880 | */ |
| 4881 | void ata_qc_free(struct ata_queued_cmd *qc) |
| 4882 | { |
Julia Lawall | a110401 | 2009-10-17 08:41:47 +0200 | [diff] [blame] | 4883 | struct ata_port *ap; |
Tejun Heo | 8a8bc22 | 2008-11-10 14:48:21 +0900 | [diff] [blame] | 4884 | unsigned int tag; |
| 4885 | |
Tejun Heo | efcb3cf | 2009-01-09 19:19:14 +0900 | [diff] [blame] | 4886 | WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
Julia Lawall | a110401 | 2009-10-17 08:41:47 +0200 | [diff] [blame] | 4887 | ap = qc->ap; |
Tejun Heo | 8a8bc22 | 2008-11-10 14:48:21 +0900 | [diff] [blame] | 4888 | |
| 4889 | qc->flags = 0; |
| 4890 | tag = qc->tag; |
| 4891 | if (likely(ata_tag_valid(tag))) { |
| 4892 | qc->tag = ATA_TAG_POISON; |
Shaohua Li | 5067c04 | 2015-03-12 10:32:18 -0700 | [diff] [blame] | 4893 | if (ap->flags & ATA_FLAG_SAS_HOST) |
Shaohua Li | 98bd4be | 2015-01-23 19:52:07 -0800 | [diff] [blame] | 4894 | ata_sas_free_tag(tag, ap); |
Tejun Heo | 8a8bc22 | 2008-11-10 14:48:21 +0900 | [diff] [blame] | 4895 | } |
| 4896 | } |
| 4897 | |
Tejun Heo | 7601442 | 2006-02-11 15:13:49 +0900 | [diff] [blame] | 4898 | void __ata_qc_complete(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | { |
Julia Lawall | a110401 | 2009-10-17 08:41:47 +0200 | [diff] [blame] | 4900 | struct ata_port *ap; |
| 4901 | struct ata_link *link; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4902 | |
Tejun Heo | efcb3cf | 2009-01-09 19:19:14 +0900 | [diff] [blame] | 4903 | WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
| 4904 | WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)); |
Julia Lawall | a110401 | 2009-10-17 08:41:47 +0200 | [diff] [blame] | 4905 | ap = qc->ap; |
| 4906 | link = qc->dev->link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4907 | |
| 4908 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 4909 | ata_sg_clean(qc); |
| 4910 | |
Tejun Heo | 7401abf | 2006-05-15 20:57:32 +0900 | [diff] [blame] | 4911 | /* command should be marked inactive atomically with qc completion */ |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4912 | if (qc->tf.protocol == ATA_PROT_NCQ) { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4913 | link->sactive &= ~(1 << qc->tag); |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4914 | if (!link->sactive) |
| 4915 | ap->nr_active_links--; |
| 4916 | } else { |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 4917 | link->active_tag = ATA_TAG_POISON; |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 4918 | ap->nr_active_links--; |
| 4919 | } |
| 4920 | |
| 4921 | /* clear exclusive status */ |
| 4922 | if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && |
| 4923 | ap->excl_link == link)) |
| 4924 | ap->excl_link = NULL; |
Tejun Heo | 7401abf | 2006-05-15 20:57:32 +0900 | [diff] [blame] | 4925 | |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 4926 | /* atapi: mark qc as inactive to prevent the interrupt handler |
| 4927 | * from completing the command twice later, before the error handler |
| 4928 | * is called. (when rc != 0 and atapi request sense is needed) |
| 4929 | */ |
| 4930 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 4931 | ap->qc_active &= ~(1 << qc->tag); |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 4932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | /* call completion callback */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4934 | qc->complete_fn(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4935 | } |
| 4936 | |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4937 | static void fill_result_tf(struct ata_queued_cmd *qc) |
| 4938 | { |
| 4939 | struct ata_port *ap = qc->ap; |
| 4940 | |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4941 | qc->result_tf.flags = qc->tf.flags; |
Tejun Heo | 22183bf | 2008-04-07 22:47:20 +0900 | [diff] [blame] | 4942 | ap->ops->qc_fill_rtf(qc); |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 4943 | } |
| 4944 | |
Tejun Heo | 00115e0 | 2007-11-27 19:28:58 +0900 | [diff] [blame] | 4945 | static void ata_verify_xfer(struct ata_queued_cmd *qc) |
| 4946 | { |
| 4947 | struct ata_device *dev = qc->dev; |
| 4948 | |
Tejun Heo | 00115e0 | 2007-11-27 19:28:58 +0900 | [diff] [blame] | 4949 | if (ata_is_nodata(qc->tf.protocol)) |
| 4950 | return; |
| 4951 | |
| 4952 | if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) |
| 4953 | return; |
| 4954 | |
| 4955 | dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; |
| 4956 | } |
| 4957 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4958 | /** |
| 4959 | * ata_qc_complete - Complete an active ATA command |
| 4960 | * @qc: Command to complete |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4961 | * |
Tejun Heo | 1aadf5c | 2010-06-25 15:03:34 +0200 | [diff] [blame] | 4962 | * Indicate to the mid and upper layers that an ATA command has |
| 4963 | * completed, with either an ok or not-ok status. |
| 4964 | * |
| 4965 | * Refrain from calling this function multiple times when |
| 4966 | * successfully completing multiple NCQ commands. |
| 4967 | * ata_qc_complete_multiple() should be used instead, which will |
| 4968 | * properly update IRQ expect state. |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4969 | * |
| 4970 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 4971 | * spin_lock_irqsave(host lock) |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4972 | */ |
| 4973 | void ata_qc_complete(struct ata_queued_cmd *qc) |
| 4974 | { |
| 4975 | struct ata_port *ap = qc->ap; |
| 4976 | |
| 4977 | /* XXX: New EH and old EH use different mechanisms to |
| 4978 | * synchronize EH with regular execution path. |
| 4979 | * |
| 4980 | * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED. |
| 4981 | * Normal execution path is responsible for not accessing a |
| 4982 | * failed qc. libata core enforces the rule by returning NULL |
| 4983 | * from ata_qc_from_tag() for failed qcs. |
| 4984 | * |
| 4985 | * Old EH depends on ata_qc_complete() nullifying completion |
| 4986 | * requests if ATA_QCFLAG_EH_SCHEDULED is set. Old EH does |
| 4987 | * not synchronize with interrupt handler. Only PIO task is |
| 4988 | * taken care of. |
| 4989 | */ |
| 4990 | if (ap->ops->error_handler) { |
Tejun Heo | 4dbfa39 | 2007-10-25 18:22:44 +0900 | [diff] [blame] | 4991 | struct ata_device *dev = qc->dev; |
| 4992 | struct ata_eh_info *ehi = &dev->link->eh_info; |
| 4993 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 4994 | if (unlikely(qc->err_mask)) |
| 4995 | qc->flags |= ATA_QCFLAG_FAILED; |
| 4996 | |
Tejun Heo | f08dc1a | 2010-12-09 15:59:32 +0100 | [diff] [blame] | 4997 | /* |
| 4998 | * Finish internal commands without any further processing |
| 4999 | * and always with the result TF filled. |
| 5000 | */ |
| 5001 | if (unlikely(ata_tag_internal(qc->tag))) { |
Tejun Heo | f4b31db9 | 2009-10-16 13:00:51 +0900 | [diff] [blame] | 5002 | fill_result_tf(qc); |
Hannes Reinecke | 255c03d | 2015-03-27 16:46:38 +0100 | [diff] [blame] | 5003 | trace_ata_qc_complete_internal(qc); |
Tejun Heo | f08dc1a | 2010-12-09 15:59:32 +0100 | [diff] [blame] | 5004 | __ata_qc_complete(qc); |
| 5005 | return; |
| 5006 | } |
Tejun Heo | f4b31db9 | 2009-10-16 13:00:51 +0900 | [diff] [blame] | 5007 | |
Tejun Heo | f08dc1a | 2010-12-09 15:59:32 +0100 | [diff] [blame] | 5008 | /* |
| 5009 | * Non-internal qc has failed. Fill the result TF and |
| 5010 | * summon EH. |
| 5011 | */ |
| 5012 | if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) { |
| 5013 | fill_result_tf(qc); |
Hannes Reinecke | 255c03d | 2015-03-27 16:46:38 +0100 | [diff] [blame] | 5014 | trace_ata_qc_complete_failed(qc); |
Tejun Heo | f08dc1a | 2010-12-09 15:59:32 +0100 | [diff] [blame] | 5015 | ata_qc_schedule_eh(qc); |
Tejun Heo | f4b31db9 | 2009-10-16 13:00:51 +0900 | [diff] [blame] | 5016 | return; |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5017 | } |
| 5018 | |
Tejun Heo | 4dc738e | 2009-09-17 18:45:27 +0900 | [diff] [blame] | 5019 | WARN_ON_ONCE(ap->pflags & ATA_PFLAG_FROZEN); |
| 5020 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5021 | /* read result TF if requested */ |
| 5022 | if (qc->flags & ATA_QCFLAG_RESULT_TF) |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5023 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5024 | |
Hannes Reinecke | 255c03d | 2015-03-27 16:46:38 +0100 | [diff] [blame] | 5025 | trace_ata_qc_complete_done(qc); |
Tejun Heo | 4dbfa39 | 2007-10-25 18:22:44 +0900 | [diff] [blame] | 5026 | /* Some commands need post-processing after successful |
| 5027 | * completion. |
| 5028 | */ |
| 5029 | switch (qc->tf.command) { |
| 5030 | case ATA_CMD_SET_FEATURES: |
| 5031 | if (qc->tf.feature != SETFEATURES_WC_ON && |
| 5032 | qc->tf.feature != SETFEATURES_WC_OFF) |
| 5033 | break; |
| 5034 | /* fall through */ |
| 5035 | case ATA_CMD_INIT_DEV_PARAMS: /* CHS translation changed */ |
| 5036 | case ATA_CMD_SET_MULTI: /* multi_count changed */ |
| 5037 | /* revalidate device */ |
| 5038 | ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; |
| 5039 | ata_port_schedule_eh(ap); |
| 5040 | break; |
Tejun Heo | 054a5fb | 2007-10-25 18:30:36 +0900 | [diff] [blame] | 5041 | |
| 5042 | case ATA_CMD_SLEEP: |
| 5043 | dev->flags |= ATA_DFLAG_SLEEPING; |
| 5044 | break; |
Tejun Heo | 4dbfa39 | 2007-10-25 18:22:44 +0900 | [diff] [blame] | 5045 | } |
| 5046 | |
Tejun Heo | 00115e0 | 2007-11-27 19:28:58 +0900 | [diff] [blame] | 5047 | if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) |
| 5048 | ata_verify_xfer(qc); |
| 5049 | |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5050 | __ata_qc_complete(qc); |
| 5051 | } else { |
| 5052 | if (qc->flags & ATA_QCFLAG_EH_SCHEDULED) |
| 5053 | return; |
| 5054 | |
| 5055 | /* read result TF if failed or requested */ |
| 5056 | if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF) |
Tejun Heo | 39599a5 | 2006-11-14 22:37:35 +0900 | [diff] [blame] | 5057 | fill_result_tf(qc); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 5058 | |
| 5059 | __ata_qc_complete(qc); |
| 5060 | } |
| 5061 | } |
| 5062 | |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5063 | /** |
| 5064 | * ata_qc_complete_multiple - Complete multiple qcs successfully |
| 5065 | * @ap: port in question |
| 5066 | * @qc_active: new qc_active mask |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5067 | * |
| 5068 | * Complete in-flight commands. This functions is meant to be |
| 5069 | * called from low-level driver's interrupt routine to complete |
| 5070 | * requests normally. ap->qc_active and @qc_active is compared |
| 5071 | * and commands are completed accordingly. |
| 5072 | * |
Tejun Heo | 1aadf5c | 2010-06-25 15:03:34 +0200 | [diff] [blame] | 5073 | * Always use this function when completing multiple NCQ commands |
| 5074 | * from IRQ handlers instead of calling ata_qc_complete() |
| 5075 | * multiple times to keep IRQ expect status properly in sync. |
| 5076 | * |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5077 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5078 | * spin_lock_irqsave(host lock) |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5079 | * |
| 5080 | * RETURNS: |
| 5081 | * Number of completed commands on success, -errno otherwise. |
| 5082 | */ |
Tejun Heo | 79f97da | 2008-04-07 22:47:20 +0900 | [diff] [blame] | 5083 | int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active) |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5084 | { |
| 5085 | int nr_done = 0; |
| 5086 | u32 done_mask; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5087 | |
| 5088 | done_mask = ap->qc_active ^ qc_active; |
| 5089 | |
| 5090 | if (unlikely(done_mask & qc_active)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 5091 | ata_port_err(ap, "illegal qc_active transition (%08x->%08x)\n", |
| 5092 | ap->qc_active, qc_active); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5093 | return -EINVAL; |
| 5094 | } |
| 5095 | |
Jens Axboe | 4376818 | 2009-05-20 09:44:39 +0200 | [diff] [blame] | 5096 | while (done_mask) { |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5097 | struct ata_queued_cmd *qc; |
Jens Axboe | 4376818 | 2009-05-20 09:44:39 +0200 | [diff] [blame] | 5098 | unsigned int tag = __ffs(done_mask); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5099 | |
Jens Axboe | 4376818 | 2009-05-20 09:44:39 +0200 | [diff] [blame] | 5100 | qc = ata_qc_from_tag(ap, tag); |
| 5101 | if (qc) { |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5102 | ata_qc_complete(qc); |
| 5103 | nr_done++; |
| 5104 | } |
Jens Axboe | 4376818 | 2009-05-20 09:44:39 +0200 | [diff] [blame] | 5105 | done_mask &= ~(1 << tag); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | return nr_done; |
| 5109 | } |
| 5110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | /** |
| 5112 | * ata_qc_issue - issue taskfile to device |
| 5113 | * @qc: command to issue to device |
| 5114 | * |
| 5115 | * Prepare an ATA command to submission to device. |
| 5116 | * This includes mapping the data into a DMA-able |
| 5117 | * area, filling in the S/G table, and finally |
| 5118 | * writing the taskfile to hardware, starting the command. |
| 5119 | * |
| 5120 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5121 | * spin_lock_irqsave(host lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | */ |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 5123 | void ata_qc_issue(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5124 | { |
| 5125 | struct ata_port *ap = qc->ap; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5126 | struct ata_link *link = qc->dev->link; |
Tejun Heo | 405e66b | 2007-11-27 19:28:53 +0900 | [diff] [blame] | 5127 | u8 prot = qc->tf.protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5128 | |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5129 | /* Make sure only one non-NCQ command is outstanding. The |
| 5130 | * check is skipped for old EH because it reuses active qc to |
| 5131 | * request ATAPI sense. |
| 5132 | */ |
Tejun Heo | efcb3cf | 2009-01-09 19:19:14 +0900 | [diff] [blame] | 5133 | WARN_ON_ONCE(ap->ops->error_handler && ata_tag_valid(link->active_tag)); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5134 | |
Tejun Heo | 1973a02 | 2007-12-05 10:36:13 +0900 | [diff] [blame] | 5135 | if (ata_is_ncq(prot)) { |
Tejun Heo | efcb3cf | 2009-01-09 19:19:14 +0900 | [diff] [blame] | 5136 | WARN_ON_ONCE(link->sactive & (1 << qc->tag)); |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 5137 | |
| 5138 | if (!link->sactive) |
| 5139 | ap->nr_active_links++; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5140 | link->sactive |= 1 << qc->tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5141 | } else { |
Tejun Heo | efcb3cf | 2009-01-09 19:19:14 +0900 | [diff] [blame] | 5142 | WARN_ON_ONCE(link->sactive); |
Tejun Heo | da917d6 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 5143 | |
| 5144 | ap->nr_active_links++; |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5145 | link->active_tag = qc->tag; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5146 | } |
| 5147 | |
Tejun Heo | e4a70e7 | 2006-03-31 20:36:47 +0900 | [diff] [blame] | 5148 | qc->flags |= ATA_QCFLAG_ACTIVE; |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 5149 | ap->qc_active |= 1 << qc->tag; |
Tejun Heo | e4a70e7 | 2006-03-31 20:36:47 +0900 | [diff] [blame] | 5150 | |
Tejun Heo | 60f5d6e | 2010-08-23 11:27:27 +0200 | [diff] [blame] | 5151 | /* |
| 5152 | * We guarantee to LLDs that they will have at least one |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 5153 | * non-zero sg if the command is a data command. |
| 5154 | */ |
Tejun Heo | 60f5d6e | 2010-08-23 11:27:27 +0200 | [diff] [blame] | 5155 | if (WARN_ON_ONCE(ata_is_data(prot) && |
| 5156 | (!qc->sg || !qc->n_elem || !qc->nbytes))) |
| 5157 | goto sys_err; |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 5158 | |
Tejun Heo | 405e66b | 2007-11-27 19:28:53 +0900 | [diff] [blame] | 5159 | if (ata_is_dma(prot) || (ata_is_pio(prot) && |
Tejun Heo | f92a263 | 2007-12-05 16:43:10 +0900 | [diff] [blame] | 5160 | (ap->flags & ATA_FLAG_PIO_DMA))) |
Tejun Heo | 001102d | 2007-12-05 16:43:09 +0900 | [diff] [blame] | 5161 | if (ata_sg_setup(qc)) |
Tejun Heo | 60f5d6e | 2010-08-23 11:27:27 +0200 | [diff] [blame] | 5162 | goto sys_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5163 | |
Tejun Heo | cf48062 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 5164 | /* if device is sleeping, schedule reset and abort the link */ |
Tejun Heo | 054a5fb | 2007-10-25 18:30:36 +0900 | [diff] [blame] | 5165 | if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { |
Tejun Heo | cf48062 | 2008-01-24 00:05:14 +0900 | [diff] [blame] | 5166 | link->eh_info.action |= ATA_EH_RESET; |
Tejun Heo | 054a5fb | 2007-10-25 18:30:36 +0900 | [diff] [blame] | 5167 | ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); |
| 5168 | ata_link_abort(link); |
| 5169 | return; |
| 5170 | } |
| 5171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | ap->ops->qc_prep(qc); |
Hannes Reinecke | 255c03d | 2015-03-27 16:46:38 +0100 | [diff] [blame] | 5173 | trace_ata_qc_issue(qc); |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 5174 | qc->err_mask |= ap->ops->qc_issue(qc); |
| 5175 | if (unlikely(qc->err_mask)) |
| 5176 | goto err; |
| 5177 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | |
Tejun Heo | 60f5d6e | 2010-08-23 11:27:27 +0200 | [diff] [blame] | 5179 | sys_err: |
Tejun Heo | 8e0e694 | 2006-03-31 20:41:11 +0900 | [diff] [blame] | 5180 | qc->err_mask |= AC_ERR_SYSTEM; |
| 5181 | err: |
| 5182 | ata_qc_complete(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | /** |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5186 | * sata_scr_valid - test whether SCRs are accessible |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5187 | * @link: ATA link to test SCR accessibility for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5188 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5189 | * Test whether SCRs are accessible for @link. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5190 | * |
| 5191 | * LOCKING: |
| 5192 | * None. |
| 5193 | * |
| 5194 | * RETURNS: |
| 5195 | * 1 if SCRs are accessible, 0 otherwise. |
| 5196 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5197 | int sata_scr_valid(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5198 | { |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5199 | struct ata_port *ap = link->ap; |
| 5200 | |
Tejun Heo | a16abc0 | 2007-05-21 18:33:47 +0200 | [diff] [blame] | 5201 | return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | /** |
| 5205 | * sata_scr_read - read SCR register of the specified port |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5206 | * @link: ATA link to read SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5207 | * @reg: SCR to read |
| 5208 | * @val: Place to store read value |
| 5209 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5210 | * Read SCR register @reg of @link into *@val. This function is |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5211 | * guaranteed to succeed if @link is ap->link, the cable type of |
| 5212 | * the port is SATA and the port implements ->scr_read. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5213 | * |
| 5214 | * LOCKING: |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5215 | * None if @link is ap->link. Kernel thread context otherwise. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5216 | * |
| 5217 | * RETURNS: |
| 5218 | * 0 on success, negative errno on failure. |
| 5219 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5220 | int sata_scr_read(struct ata_link *link, int reg, u32 *val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5221 | { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5222 | if (ata_is_host_link(link)) { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5223 | if (sata_scr_valid(link)) |
Tejun Heo | 82ef04f | 2008-07-31 17:02:40 +0900 | [diff] [blame] | 5224 | return link->ap->ops->scr_read(link, reg, val); |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5225 | return -EOPNOTSUPP; |
| 5226 | } |
| 5227 | |
| 5228 | return sata_pmp_scr_read(link, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5229 | } |
| 5230 | |
| 5231 | /** |
| 5232 | * sata_scr_write - write SCR register of the specified port |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5233 | * @link: ATA link to write SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5234 | * @reg: SCR to write |
| 5235 | * @val: value to write |
| 5236 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5237 | * Write @val to SCR register @reg of @link. This function is |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5238 | * guaranteed to succeed if @link is ap->link, the cable type of |
| 5239 | * the port is SATA and the port implements ->scr_read. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5240 | * |
| 5241 | * LOCKING: |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5242 | * None if @link is ap->link. Kernel thread context otherwise. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5243 | * |
| 5244 | * RETURNS: |
| 5245 | * 0 on success, negative errno on failure. |
| 5246 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5247 | int sata_scr_write(struct ata_link *link, int reg, u32 val) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5248 | { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5249 | if (ata_is_host_link(link)) { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5250 | if (sata_scr_valid(link)) |
Tejun Heo | 82ef04f | 2008-07-31 17:02:40 +0900 | [diff] [blame] | 5251 | return link->ap->ops->scr_write(link, reg, val); |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5252 | return -EOPNOTSUPP; |
| 5253 | } |
| 5254 | |
| 5255 | return sata_pmp_scr_write(link, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | /** |
| 5259 | * 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] | 5260 | * @link: ATA link to write SCR for |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5261 | * @reg: SCR to write |
| 5262 | * @val: value to write |
| 5263 | * |
| 5264 | * This function is identical to sata_scr_write() except that this |
| 5265 | * function performs flush after writing to the register. |
| 5266 | * |
| 5267 | * LOCKING: |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5268 | * None if @link is ap->link. Kernel thread context otherwise. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5269 | * |
| 5270 | * RETURNS: |
| 5271 | * 0 on success, negative errno on failure. |
| 5272 | */ |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5273 | 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] | 5274 | { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5275 | if (ata_is_host_link(link)) { |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5276 | int rc; |
Tejun Heo | da3dbb1 | 2007-07-16 14:29:40 +0900 | [diff] [blame] | 5277 | |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5278 | if (sata_scr_valid(link)) { |
Tejun Heo | 82ef04f | 2008-07-31 17:02:40 +0900 | [diff] [blame] | 5279 | rc = link->ap->ops->scr_write(link, reg, val); |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5280 | if (rc == 0) |
Tejun Heo | 82ef04f | 2008-07-31 17:02:40 +0900 | [diff] [blame] | 5281 | rc = link->ap->ops->scr_read(link, reg, &val); |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5282 | return rc; |
| 5283 | } |
| 5284 | return -EOPNOTSUPP; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5285 | } |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5286 | |
| 5287 | return sata_pmp_scr_write(link, reg, val); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | /** |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5291 | * ata_phys_link_online - test whether the given link is online |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5292 | * @link: ATA link to test |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5293 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5294 | * Test whether @link is online. Note that this function returns |
| 5295 | * 0 if online status of @link cannot be obtained, so |
| 5296 | * ata_link_online(link) != !ata_link_offline(link). |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5297 | * |
| 5298 | * LOCKING: |
| 5299 | * None. |
| 5300 | * |
| 5301 | * RETURNS: |
Tejun Heo | b5b3fa3 | 2008-07-31 17:02:42 +0900 | [diff] [blame] | 5302 | * True if the port online status is available and online. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5303 | */ |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5304 | bool ata_phys_link_online(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5305 | { |
| 5306 | u32 sstatus; |
| 5307 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5308 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
Tejun Heo | 9913ff8a | 2009-01-29 20:31:31 +0900 | [diff] [blame] | 5309 | ata_sstatus_online(sstatus)) |
Tejun Heo | b5b3fa3 | 2008-07-31 17:02:42 +0900 | [diff] [blame] | 5310 | return true; |
| 5311 | return false; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | /** |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5315 | * ata_phys_link_offline - test whether the given link is offline |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5316 | * @link: ATA link to test |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5317 | * |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5318 | * Test whether @link is offline. Note that this function |
| 5319 | * returns 0 if offline status of @link cannot be obtained, so |
| 5320 | * ata_link_online(link) != !ata_link_offline(link). |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5321 | * |
| 5322 | * LOCKING: |
| 5323 | * None. |
| 5324 | * |
| 5325 | * RETURNS: |
Tejun Heo | b5b3fa3 | 2008-07-31 17:02:42 +0900 | [diff] [blame] | 5326 | * True if the port offline status is available and offline. |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5327 | */ |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5328 | bool ata_phys_link_offline(struct ata_link *link) |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5329 | { |
| 5330 | u32 sstatus; |
| 5331 | |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5332 | if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0 && |
Tejun Heo | 9913ff8a | 2009-01-29 20:31:31 +0900 | [diff] [blame] | 5333 | !ata_sstatus_online(sstatus)) |
Tejun Heo | b5b3fa3 | 2008-07-31 17:02:42 +0900 | [diff] [blame] | 5334 | return true; |
| 5335 | return false; |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 5336 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 5337 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5338 | /** |
| 5339 | * ata_link_online - test whether the given link is online |
| 5340 | * @link: ATA link to test |
| 5341 | * |
| 5342 | * Test whether @link is online. This is identical to |
| 5343 | * ata_phys_link_online() when there's no slave link. When |
| 5344 | * there's a slave link, this function should only be called on |
| 5345 | * the master link and will return true if any of M/S links is |
| 5346 | * online. |
| 5347 | * |
| 5348 | * LOCKING: |
| 5349 | * None. |
| 5350 | * |
| 5351 | * RETURNS: |
| 5352 | * True if the port online status is available and online. |
| 5353 | */ |
| 5354 | bool ata_link_online(struct ata_link *link) |
| 5355 | { |
| 5356 | struct ata_link *slave = link->ap->slave_link; |
| 5357 | |
| 5358 | WARN_ON(link == slave); /* shouldn't be called on slave link */ |
| 5359 | |
| 5360 | return ata_phys_link_online(link) || |
| 5361 | (slave && ata_phys_link_online(slave)); |
| 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * ata_link_offline - test whether the given link is offline |
| 5366 | * @link: ATA link to test |
| 5367 | * |
| 5368 | * Test whether @link is offline. This is identical to |
| 5369 | * ata_phys_link_offline() when there's no slave link. When |
| 5370 | * there's a slave link, this function should only be called on |
| 5371 | * the master link and will return true if both M/S links are |
| 5372 | * offline. |
| 5373 | * |
| 5374 | * LOCKING: |
| 5375 | * None. |
| 5376 | * |
| 5377 | * RETURNS: |
| 5378 | * True if the port offline status is available and offline. |
| 5379 | */ |
| 5380 | bool ata_link_offline(struct ata_link *link) |
| 5381 | { |
| 5382 | struct ata_link *slave = link->ap->slave_link; |
| 5383 | |
| 5384 | WARN_ON(link == slave); /* shouldn't be called on slave link */ |
| 5385 | |
| 5386 | return ata_phys_link_offline(link) && |
| 5387 | (!slave || ata_phys_link_offline(slave)); |
| 5388 | } |
| 5389 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 5390 | #ifdef CONFIG_PM |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5391 | static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, |
| 5392 | unsigned int action, unsigned int ehi_flags, |
| 5393 | bool async) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5394 | { |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5395 | struct ata_link *link; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5396 | unsigned long flags; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5397 | |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5398 | /* Previous resume operation might still be in |
| 5399 | * progress. Wait for PM_PENDING to clear. |
| 5400 | */ |
| 5401 | if (ap->pflags & ATA_PFLAG_PM_PENDING) { |
| 5402 | ata_port_wait_eh(ap); |
| 5403 | WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5404 | } |
| 5405 | |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5406 | /* request PM ops to EH */ |
| 5407 | spin_lock_irqsave(ap->lock, flags); |
| 5408 | |
| 5409 | ap->pm_mesg = mesg; |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5410 | ap->pflags |= ATA_PFLAG_PM_PENDING; |
| 5411 | ata_for_each_link(link, ap, HOST_FIRST) { |
| 5412 | link->eh_info.action |= action; |
| 5413 | link->eh_info.flags |= ehi_flags; |
| 5414 | } |
| 5415 | |
| 5416 | ata_port_schedule_eh(ap); |
| 5417 | |
| 5418 | spin_unlock_irqrestore(ap->lock, flags); |
| 5419 | |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5420 | if (!async) { |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5421 | ata_port_wait_eh(ap); |
| 5422 | WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); |
| 5423 | } |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5424 | } |
| 5425 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5426 | /* |
| 5427 | * On some hardware, device fails to respond after spun down for suspend. As |
| 5428 | * the device won't be used before being resumed, we don't need to touch the |
| 5429 | * device. Ask EH to skip the usual stuff and proceed directly to suspend. |
| 5430 | * |
| 5431 | * http://thread.gmane.org/gmane.linux.ide/46764 |
| 5432 | */ |
| 5433 | static const unsigned int ata_port_suspend_ehi = ATA_EHI_QUIET |
| 5434 | | ATA_EHI_NO_AUTOPSY |
| 5435 | | ATA_EHI_NO_RECOVERY; |
| 5436 | |
| 5437 | static void ata_port_suspend(struct ata_port *ap, pm_message_t mesg) |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5438 | { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5439 | ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, false); |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5440 | } |
| 5441 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5442 | static void ata_port_suspend_async(struct ata_port *ap, pm_message_t mesg) |
| 5443 | { |
| 5444 | ata_port_request_pm(ap, mesg, 0, ata_port_suspend_ehi, true); |
| 5445 | } |
| 5446 | |
| 5447 | static int ata_port_pm_suspend(struct device *dev) |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5448 | { |
| 5449 | struct ata_port *ap = to_ata_port(dev); |
| 5450 | |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5451 | if (pm_runtime_suspended(dev)) |
| 5452 | return 0; |
| 5453 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5454 | ata_port_suspend(ap, PMSG_SUSPEND); |
| 5455 | return 0; |
Lin Ming | 33574d6 | 2011-12-22 14:50:49 +0800 | [diff] [blame] | 5456 | } |
| 5457 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5458 | static int ata_port_pm_freeze(struct device *dev) |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5459 | { |
| 5460 | struct ata_port *ap = to_ata_port(dev); |
| 5461 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5462 | if (pm_runtime_suspended(dev)) |
| 5463 | return 0; |
| 5464 | |
| 5465 | ata_port_suspend(ap, PMSG_FREEZE); |
| 5466 | return 0; |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5467 | } |
| 5468 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5469 | static int ata_port_pm_poweroff(struct device *dev) |
Lin Ming | e90b1e5 | 2011-12-22 14:50:48 +0800 | [diff] [blame] | 5470 | { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5471 | ata_port_suspend(to_ata_port(dev), PMSG_HIBERNATE); |
| 5472 | return 0; |
| 5473 | } |
Lin Ming | e90b1e5 | 2011-12-22 14:50:48 +0800 | [diff] [blame] | 5474 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5475 | static const unsigned int ata_port_resume_ehi = ATA_EHI_NO_AUTOPSY |
| 5476 | | ATA_EHI_QUIET; |
Lin Ming | e90b1e5 | 2011-12-22 14:50:48 +0800 | [diff] [blame] | 5477 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5478 | static void ata_port_resume(struct ata_port *ap, pm_message_t mesg) |
| 5479 | { |
| 5480 | ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, false); |
| 5481 | } |
| 5482 | |
| 5483 | static void ata_port_resume_async(struct ata_port *ap, pm_message_t mesg) |
| 5484 | { |
| 5485 | ata_port_request_pm(ap, mesg, ATA_EH_RESET, ata_port_resume_ehi, true); |
| 5486 | } |
| 5487 | |
| 5488 | static int ata_port_pm_resume(struct device *dev) |
| 5489 | { |
Todd Brandt | 200421a | 2014-03-14 13:52:54 -0700 | [diff] [blame] | 5490 | ata_port_resume_async(to_ata_port(dev), PMSG_RESUME); |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5491 | pm_runtime_disable(dev); |
| 5492 | pm_runtime_set_active(dev); |
| 5493 | pm_runtime_enable(dev); |
| 5494 | return 0; |
Lin Ming | e90b1e5 | 2011-12-22 14:50:48 +0800 | [diff] [blame] | 5495 | } |
| 5496 | |
Aaron Lu | 7e15e9b | 2013-01-15 17:21:04 +0800 | [diff] [blame] | 5497 | /* |
| 5498 | * For ODDs, the upper layer will poll for media change every few seconds, |
| 5499 | * which will make it enter and leave suspend state every few seconds. And |
| 5500 | * as each suspend will cause a hard/soft reset, the gain of runtime suspend |
| 5501 | * is very little and the ODD may malfunction after constantly being reset. |
| 5502 | * So the idle callback here will not proceed to suspend if a non-ZPODD capable |
| 5503 | * ODD is attached to the port. |
| 5504 | */ |
Lin Ming | 9ee4f39 | 2011-12-05 09:20:28 +0800 | [diff] [blame] | 5505 | static int ata_port_runtime_idle(struct device *dev) |
| 5506 | { |
Aaron Lu | 7e15e9b | 2013-01-15 17:21:04 +0800 | [diff] [blame] | 5507 | struct ata_port *ap = to_ata_port(dev); |
| 5508 | struct ata_link *link; |
| 5509 | struct ata_device *adev; |
| 5510 | |
| 5511 | ata_for_each_link(link, ap, HOST_FIRST) { |
| 5512 | ata_for_each_dev(adev, link, ENABLED) |
| 5513 | if (adev->class == ATA_DEV_ATAPI && |
| 5514 | !zpodd_dev_enabled(adev)) |
| 5515 | return -EBUSY; |
| 5516 | } |
| 5517 | |
Rafael J. Wysocki | 45f0a85 | 2013-06-03 21:49:52 +0200 | [diff] [blame] | 5518 | return 0; |
Lin Ming | 9ee4f39 | 2011-12-05 09:20:28 +0800 | [diff] [blame] | 5519 | } |
| 5520 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 5521 | static int ata_port_runtime_suspend(struct device *dev) |
| 5522 | { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5523 | ata_port_suspend(to_ata_port(dev), PMSG_AUTO_SUSPEND); |
| 5524 | return 0; |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | static int ata_port_runtime_resume(struct device *dev) |
| 5528 | { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5529 | ata_port_resume(to_ata_port(dev), PMSG_AUTO_RESUME); |
| 5530 | return 0; |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 5531 | } |
| 5532 | |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5533 | static const struct dev_pm_ops ata_port_pm_ops = { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5534 | .suspend = ata_port_pm_suspend, |
| 5535 | .resume = ata_port_pm_resume, |
| 5536 | .freeze = ata_port_pm_freeze, |
| 5537 | .thaw = ata_port_pm_resume, |
| 5538 | .poweroff = ata_port_pm_poweroff, |
| 5539 | .restore = ata_port_pm_resume, |
Lin Ming | 9ee4f39 | 2011-12-05 09:20:28 +0800 | [diff] [blame] | 5540 | |
Aaron Lu | a7ff60d | 2013-01-25 14:29:35 +0800 | [diff] [blame] | 5541 | .runtime_suspend = ata_port_runtime_suspend, |
| 5542 | .runtime_resume = ata_port_runtime_resume, |
Lin Ming | 9ee4f39 | 2011-12-05 09:20:28 +0800 | [diff] [blame] | 5543 | .runtime_idle = ata_port_runtime_idle, |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5544 | }; |
| 5545 | |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5546 | /* sas ports don't participate in pm runtime management of ata_ports, |
| 5547 | * and need to resume ata devices at the domain level, not the per-port |
| 5548 | * level. sas suspend/resume is async to allow parallel port recovery |
| 5549 | * since sas has multiple ata_port instances per Scsi_Host. |
| 5550 | */ |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5551 | void ata_sas_port_suspend(struct ata_port *ap) |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5552 | { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5553 | ata_port_suspend_async(ap, PMSG_SUSPEND); |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5554 | } |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5555 | EXPORT_SYMBOL_GPL(ata_sas_port_suspend); |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5556 | |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5557 | void ata_sas_port_resume(struct ata_port *ap) |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5558 | { |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5559 | ata_port_resume_async(ap, PMSG_RESUME); |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5560 | } |
Dan Williams | bc6e7c4 | 2014-03-14 13:52:48 -0700 | [diff] [blame] | 5561 | EXPORT_SYMBOL_GPL(ata_sas_port_resume); |
Dan Williams | 2fcbdcb | 2012-06-21 23:41:46 -0700 | [diff] [blame] | 5562 | |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5563 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5564 | * ata_host_suspend - suspend host |
| 5565 | * @host: host to suspend |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5566 | * @mesg: PM message |
| 5567 | * |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5568 | * Suspend @host. Actual operation is performed by port suspend. |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5569 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5570 | int ata_host_suspend(struct ata_host *host, pm_message_t mesg) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5571 | { |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5572 | host->dev->power.power_state = mesg; |
| 5573 | return 0; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | /** |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5577 | * ata_host_resume - resume host |
| 5578 | * @host: host to resume |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5579 | * |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5580 | * Resume @host. Actual operation is performed by port resume. |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5581 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5582 | void ata_host_resume(struct ata_host *host) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5583 | { |
Jeff Garzik | 72ad6ec | 2008-02-25 17:31:10 -0500 | [diff] [blame] | 5584 | host->dev->power.power_state = PMSG_ON; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5585 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 5586 | #endif |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 5587 | |
Lin Ming | 5ef4108 | 2011-12-05 09:20:27 +0800 | [diff] [blame] | 5588 | struct device_type ata_port_type = { |
| 5589 | .name = "ata_port", |
| 5590 | #ifdef CONFIG_PM |
| 5591 | .pm = &ata_port_pm_ops, |
| 5592 | #endif |
| 5593 | }; |
| 5594 | |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 5595 | /** |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 5596 | * ata_dev_init - Initialize an ata_device structure |
| 5597 | * @dev: Device structure to initialize |
| 5598 | * |
| 5599 | * Initialize @dev in preparation for probing. |
| 5600 | * |
| 5601 | * LOCKING: |
| 5602 | * Inherited from caller. |
| 5603 | */ |
| 5604 | void ata_dev_init(struct ata_device *dev) |
| 5605 | { |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5606 | struct ata_link *link = ata_dev_phys_link(dev); |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5607 | struct ata_port *ap = link->ap; |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 5608 | unsigned long flags; |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 5609 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5610 | /* SATA spd limit is bound to the attached device, reset together */ |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 5611 | link->sata_spd_limit = link->hw_sata_spd_limit; |
| 5612 | link->sata_spd = 0; |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 5613 | |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 5614 | /* High bits of dev->flags are used to record warm plug |
| 5615 | * requests which occur asynchronously. Synchronize using |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5616 | * host lock. |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 5617 | */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5618 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 5619 | dev->flags &= ~ATA_DFLAG_INIT_MASK; |
Tejun Heo | 3dcc323 | 2007-09-03 12:20:11 +0900 | [diff] [blame] | 5620 | dev->horkage = 0; |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 5621 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 72fa4b7 | 2006-05-31 18:27:32 +0900 | [diff] [blame] | 5622 | |
Tejun Heo | 99cf610 | 2009-01-29 20:31:32 +0900 | [diff] [blame] | 5623 | memset((void *)dev + ATA_DEVICE_CLEAR_BEGIN, 0, |
| 5624 | ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); |
Tejun Heo | 3ef3b43 | 2006-05-31 18:27:30 +0900 | [diff] [blame] | 5625 | dev->pio_mask = UINT_MAX; |
| 5626 | dev->mwdma_mask = UINT_MAX; |
| 5627 | dev->udma_mask = UINT_MAX; |
| 5628 | } |
| 5629 | |
| 5630 | /** |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5631 | * ata_link_init - Initialize an ata_link structure |
| 5632 | * @ap: ATA port link is attached to |
| 5633 | * @link: Link structure to initialize |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5634 | * @pmp: Port multiplier port number |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5635 | * |
| 5636 | * Initialize @link. |
| 5637 | * |
| 5638 | * LOCKING: |
| 5639 | * Kernel thread context (may sleep) |
| 5640 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 5641 | 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] | 5642 | { |
| 5643 | int i; |
| 5644 | |
| 5645 | /* clear everything except for devices */ |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 5646 | memset((void *)link + ATA_LINK_CLEAR_BEGIN, 0, |
| 5647 | ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5648 | |
| 5649 | link->ap = ap; |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5650 | link->pmp = pmp; |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5651 | link->active_tag = ATA_TAG_POISON; |
| 5652 | link->hw_sata_spd_limit = UINT_MAX; |
| 5653 | |
| 5654 | /* can't use iterator, ap isn't initialized yet */ |
| 5655 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 5656 | struct ata_device *dev = &link->device[i]; |
| 5657 | |
| 5658 | dev->link = link; |
| 5659 | dev->devno = dev - link->device; |
Tejun Heo | 110f66d | 2009-09-16 04:17:28 +0900 | [diff] [blame] | 5660 | #ifdef CONFIG_ATA_ACPI |
| 5661 | dev->gtf_filter = ata_acpi_gtf_filter; |
| 5662 | #endif |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5663 | ata_dev_init(dev); |
| 5664 | } |
| 5665 | } |
| 5666 | |
| 5667 | /** |
| 5668 | * sata_link_init_spd - Initialize link->sata_spd_limit |
| 5669 | * @link: Link to configure sata_spd_limit for |
| 5670 | * |
| 5671 | * Initialize @link->[hw_]sata_spd_limit to the currently |
| 5672 | * configured value. |
| 5673 | * |
| 5674 | * LOCKING: |
| 5675 | * Kernel thread context (may sleep). |
| 5676 | * |
| 5677 | * RETURNS: |
| 5678 | * 0 on success, -errno on failure. |
| 5679 | */ |
Tejun Heo | fb7fd61 | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 5680 | int sata_link_init_spd(struct ata_link *link) |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5681 | { |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5682 | u8 spd; |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5683 | int rc; |
| 5684 | |
Tejun Heo | d127ea7 | 2008-07-31 16:09:34 +0900 | [diff] [blame] | 5685 | rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5686 | if (rc) |
| 5687 | return rc; |
| 5688 | |
Tejun Heo | d127ea7 | 2008-07-31 16:09:34 +0900 | [diff] [blame] | 5689 | spd = (link->saved_scontrol >> 4) & 0xf; |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5690 | if (spd) |
| 5691 | link->hw_sata_spd_limit &= (1 << spd) - 1; |
| 5692 | |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 5693 | ata_force_link_limits(link); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 5694 | |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5695 | link->sata_spd_limit = link->hw_sata_spd_limit; |
| 5696 | |
| 5697 | return 0; |
| 5698 | } |
| 5699 | |
| 5700 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5701 | * ata_port_alloc - allocate and initialize basic ATA port resources |
| 5702 | * @host: ATA host this allocated port belongs to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5703 | * |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5704 | * Allocate and initialize basic ATA port resources. |
| 5705 | * |
| 5706 | * RETURNS: |
| 5707 | * Allocate ATA port on success, NULL on failure. |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 5708 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | * LOCKING: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5710 | * Inherited from calling layer (may sleep). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5711 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5712 | struct ata_port *ata_port_alloc(struct ata_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | { |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5714 | struct ata_port *ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5715 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5716 | DPRINTK("ENTER\n"); |
| 5717 | |
| 5718 | ap = kzalloc(sizeof(*ap), GFP_KERNEL); |
| 5719 | if (!ap) |
| 5720 | return NULL; |
Jeff Garzik | 4fca377 | 2011-02-15 01:13:24 -0500 | [diff] [blame] | 5721 | |
Maxime Bizon | 7b3a24c5 | 2011-03-16 14:58:32 +0100 | [diff] [blame] | 5722 | ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5723 | ap->lock = &host->lock; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5724 | ap->print_id = -1; |
David Milburn | e628dc9 | 2013-05-14 13:48:40 -0500 | [diff] [blame] | 5725 | ap->local_port_no = -1; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 5726 | ap->host = host; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5727 | ap->dev = host->dev; |
Borislav Petkov | bd5d825 | 2006-06-11 23:17:01 -0400 | [diff] [blame] | 5728 | |
| 5729 | #if defined(ATA_VERBOSE_DEBUG) |
| 5730 | /* turn on all debugging levels */ |
| 5731 | ap->msg_enable = 0x00FF; |
| 5732 | #elif defined(ATA_DEBUG) |
| 5733 | 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] | 5734 | #else |
Borislav Petkov | 0dd4b21 | 2006-06-23 02:29:08 -0400 | [diff] [blame] | 5735 | ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; |
Borislav Petkov | bd5d825 | 2006-06-11 23:17:01 -0400 | [diff] [blame] | 5736 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | |
Tejun Heo | ad72cf9 | 2010-07-02 10:03:52 +0200 | [diff] [blame] | 5738 | mutex_init(&ap->scsi_scan_mutex); |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 5739 | INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); |
| 5740 | INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); |
Tejun Heo | a72ec4c | 2006-01-23 13:09:37 +0900 | [diff] [blame] | 5741 | INIT_LIST_HEAD(&ap->eh_done_q); |
Tejun Heo | c6cf9e9 | 2006-05-31 18:27:27 +0900 | [diff] [blame] | 5742 | init_waitqueue_head(&ap->eh_wait_q); |
Elias Oltmanns | 45fabbb | 2008-09-21 11:54:08 +0200 | [diff] [blame] | 5743 | init_completion(&ap->park_req_pending); |
Tejun Heo | 5ddf24c | 2007-07-16 14:29:41 +0900 | [diff] [blame] | 5744 | init_timer_deferrable(&ap->fastdrain_timer); |
| 5745 | ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn; |
| 5746 | ap->fastdrain_timer.data = (unsigned long)ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5747 | |
Tejun Heo | 838df62 | 2006-05-15 20:57:44 +0900 | [diff] [blame] | 5748 | ap->cbl = ATA_CBL_NONE; |
Tejun Heo | 838df62 | 2006-05-15 20:57:44 +0900 | [diff] [blame] | 5749 | |
Tejun Heo | 8989805 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5750 | ata_link_init(ap, &ap->link, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5751 | |
| 5752 | #ifdef ATA_IRQ_TRAP |
| 5753 | ap->stats.unhandled_irq = 1; |
| 5754 | ap->stats.idle_irq = 1; |
| 5755 | #endif |
Tejun Heo | 270390e | 2010-05-10 21:41:35 +0200 | [diff] [blame] | 5756 | ata_sff_port_init(ap); |
| 5757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5758 | return ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | } |
| 5760 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5761 | static void ata_host_release(struct device *gendev, void *res) |
| 5762 | { |
| 5763 | struct ata_host *host = dev_get_drvdata(gendev); |
| 5764 | int i; |
| 5765 | |
| 5766 | for (i = 0; i < host->n_ports; i++) { |
| 5767 | struct ata_port *ap = host->ports[i]; |
| 5768 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5769 | if (!ap) |
| 5770 | continue; |
| 5771 | |
Tejun Heo | 4911487 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5772 | if (ap->scsi_host) |
Tejun Heo | 1aa506e4 | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 5773 | scsi_host_put(ap->scsi_host); |
| 5774 | |
Tejun Heo | 633273a | 2007-09-23 13:19:54 +0900 | [diff] [blame] | 5775 | kfree(ap->pmp_link); |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5776 | kfree(ap->slave_link); |
Tejun Heo | 4911487 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 5777 | kfree(ap); |
Tejun Heo | 1aa506e4 | 2007-03-09 19:36:12 +0900 | [diff] [blame] | 5778 | host->ports[i] = NULL; |
| 5779 | } |
| 5780 | |
Tejun Heo | 1aa56cc | 2007-02-27 22:33:21 +0900 | [diff] [blame] | 5781 | dev_set_drvdata(gendev, NULL); |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 5782 | } |
| 5783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5784 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5785 | * ata_host_alloc - allocate and init basic ATA host resources |
| 5786 | * @dev: generic device this host is associated with |
| 5787 | * @max_ports: maximum number of ATA ports associated with this host |
| 5788 | * |
| 5789 | * Allocate and initialize basic ATA host resources. LLD calls |
| 5790 | * this function to allocate a host, initializes it fully and |
| 5791 | * attaches it using ata_host_register(). |
| 5792 | * |
| 5793 | * @max_ports ports are allocated and host->n_ports is |
| 5794 | * initialized to @max_ports. The caller is allowed to decrease |
| 5795 | * host->n_ports before calling ata_host_register(). The unused |
| 5796 | * ports will be automatically freed on registration. |
| 5797 | * |
| 5798 | * RETURNS: |
| 5799 | * Allocate ATA host on success, NULL on failure. |
| 5800 | * |
| 5801 | * LOCKING: |
| 5802 | * Inherited from calling layer (may sleep). |
| 5803 | */ |
| 5804 | struct ata_host *ata_host_alloc(struct device *dev, int max_ports) |
| 5805 | { |
| 5806 | struct ata_host *host; |
| 5807 | size_t sz; |
| 5808 | int i; |
| 5809 | |
| 5810 | DPRINTK("ENTER\n"); |
| 5811 | |
| 5812 | if (!devres_open_group(dev, NULL, GFP_KERNEL)) |
| 5813 | return NULL; |
| 5814 | |
| 5815 | /* alloc a container for our list of ATA ports (buses) */ |
| 5816 | sz = sizeof(struct ata_host) + (max_ports + 1) * sizeof(void *); |
| 5817 | /* alloc a container for our list of ATA ports (buses) */ |
| 5818 | host = devres_alloc(ata_host_release, sz, GFP_KERNEL); |
| 5819 | if (!host) |
| 5820 | goto err_out; |
| 5821 | |
| 5822 | devres_add(dev, host); |
| 5823 | dev_set_drvdata(dev, host); |
| 5824 | |
| 5825 | spin_lock_init(&host->lock); |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 5826 | mutex_init(&host->eh_mutex); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5827 | host->dev = dev; |
| 5828 | host->n_ports = max_ports; |
| 5829 | |
| 5830 | /* allocate ports bound to this host */ |
| 5831 | for (i = 0; i < max_ports; i++) { |
| 5832 | struct ata_port *ap; |
| 5833 | |
| 5834 | ap = ata_port_alloc(host); |
| 5835 | if (!ap) |
| 5836 | goto err_out; |
| 5837 | |
| 5838 | ap->port_no = i; |
| 5839 | host->ports[i] = ap; |
| 5840 | } |
| 5841 | |
| 5842 | devres_remove_group(dev, NULL); |
| 5843 | return host; |
| 5844 | |
| 5845 | err_out: |
| 5846 | devres_release_group(dev, NULL); |
| 5847 | return NULL; |
| 5848 | } |
| 5849 | |
| 5850 | /** |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5851 | * ata_host_alloc_pinfo - alloc host and init with port_info array |
| 5852 | * @dev: generic device this host is associated with |
| 5853 | * @ppi: array of ATA port_info to initialize host with |
| 5854 | * @n_ports: number of ATA ports attached to this host |
| 5855 | * |
| 5856 | * Allocate ATA host and initialize with info from @ppi. If NULL |
| 5857 | * terminated, @ppi may contain fewer entries than @n_ports. The |
| 5858 | * last entry will be used for the remaining ports. |
| 5859 | * |
| 5860 | * RETURNS: |
| 5861 | * Allocate ATA host on success, NULL on failure. |
| 5862 | * |
| 5863 | * LOCKING: |
| 5864 | * Inherited from calling layer (may sleep). |
| 5865 | */ |
| 5866 | struct ata_host *ata_host_alloc_pinfo(struct device *dev, |
| 5867 | const struct ata_port_info * const * ppi, |
| 5868 | int n_ports) |
| 5869 | { |
| 5870 | const struct ata_port_info *pi; |
| 5871 | struct ata_host *host; |
| 5872 | int i, j; |
| 5873 | |
| 5874 | host = ata_host_alloc(dev, n_ports); |
| 5875 | if (!host) |
| 5876 | return NULL; |
| 5877 | |
| 5878 | for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { |
| 5879 | struct ata_port *ap = host->ports[i]; |
| 5880 | |
| 5881 | if (ppi[j]) |
| 5882 | pi = ppi[j++]; |
| 5883 | |
| 5884 | ap->pio_mask = pi->pio_mask; |
| 5885 | ap->mwdma_mask = pi->mwdma_mask; |
| 5886 | ap->udma_mask = pi->udma_mask; |
| 5887 | ap->flags |= pi->flags; |
Tejun Heo | 0c88758 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 5888 | ap->link.flags |= pi->link_flags; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5889 | ap->ops = pi->port_ops; |
| 5890 | |
| 5891 | if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) |
| 5892 | host->ops = pi->port_ops; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5893 | } |
| 5894 | |
| 5895 | return host; |
| 5896 | } |
| 5897 | |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 5898 | /** |
| 5899 | * ata_slave_link_init - initialize slave link |
| 5900 | * @ap: port to initialize slave link for |
| 5901 | * |
| 5902 | * Create and initialize slave link for @ap. This enables slave |
| 5903 | * link handling on the port. |
| 5904 | * |
| 5905 | * In libata, a port contains links and a link contains devices. |
| 5906 | * There is single host link but if a PMP is attached to it, |
| 5907 | * there can be multiple fan-out links. On SATA, there's usually |
| 5908 | * a single device connected to a link but PATA and SATA |
| 5909 | * controllers emulating TF based interface can have two - master |
| 5910 | * and slave. |
| 5911 | * |
| 5912 | * However, there are a few controllers which don't fit into this |
| 5913 | * abstraction too well - SATA controllers which emulate TF |
| 5914 | * interface with both master and slave devices but also have |
| 5915 | * separate SCR register sets for each device. These controllers |
| 5916 | * need separate links for physical link handling |
| 5917 | * (e.g. onlineness, link speed) but should be treated like a |
| 5918 | * traditional M/S controller for everything else (e.g. command |
| 5919 | * issue, softreset). |
| 5920 | * |
| 5921 | * slave_link is libata's way of handling this class of |
| 5922 | * controllers without impacting core layer too much. For |
| 5923 | * anything other than physical link handling, the default host |
| 5924 | * link is used for both master and slave. For physical link |
| 5925 | * handling, separate @ap->slave_link is used. All dirty details |
| 5926 | * are implemented inside libata core layer. From LLD's POV, the |
| 5927 | * only difference is that prereset, hardreset and postreset are |
| 5928 | * called once more for the slave link, so the reset sequence |
| 5929 | * looks like the following. |
| 5930 | * |
| 5931 | * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) -> |
| 5932 | * softreset(M) -> postreset(M) -> postreset(S) |
| 5933 | * |
| 5934 | * Note that softreset is called only for the master. Softreset |
| 5935 | * resets both M/S by definition, so SRST on master should handle |
| 5936 | * both (the standard method will work just fine). |
| 5937 | * |
| 5938 | * LOCKING: |
| 5939 | * Should be called before host is registered. |
| 5940 | * |
| 5941 | * RETURNS: |
| 5942 | * 0 on success, -errno on failure. |
| 5943 | */ |
| 5944 | int ata_slave_link_init(struct ata_port *ap) |
| 5945 | { |
| 5946 | struct ata_link *link; |
| 5947 | |
| 5948 | WARN_ON(ap->slave_link); |
| 5949 | WARN_ON(ap->flags & ATA_FLAG_PMP); |
| 5950 | |
| 5951 | link = kzalloc(sizeof(*link), GFP_KERNEL); |
| 5952 | if (!link) |
| 5953 | return -ENOMEM; |
| 5954 | |
| 5955 | ata_link_init(ap, link, 1); |
| 5956 | ap->slave_link = link; |
| 5957 | return 0; |
| 5958 | } |
| 5959 | |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 5960 | static void ata_host_stop(struct device *gendev, void *res) |
| 5961 | { |
| 5962 | struct ata_host *host = dev_get_drvdata(gendev); |
| 5963 | int i; |
| 5964 | |
| 5965 | WARN_ON(!(host->flags & ATA_HOST_STARTED)); |
| 5966 | |
| 5967 | for (i = 0; i < host->n_ports; i++) { |
| 5968 | struct ata_port *ap = host->ports[i]; |
| 5969 | |
| 5970 | if (ap->ops->port_stop) |
| 5971 | ap->ops->port_stop(ap); |
| 5972 | } |
| 5973 | |
| 5974 | if (host->ops->host_stop) |
| 5975 | host->ops->host_stop(host); |
| 5976 | } |
| 5977 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 5978 | /** |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 5979 | * ata_finalize_port_ops - finalize ata_port_operations |
| 5980 | * @ops: ata_port_operations to finalize |
| 5981 | * |
| 5982 | * An ata_port_operations can inherit from another ops and that |
| 5983 | * ops can again inherit from another. This can go on as many |
| 5984 | * times as necessary as long as there is no loop in the |
| 5985 | * inheritance chain. |
| 5986 | * |
| 5987 | * Ops tables are finalized when the host is started. NULL or |
| 5988 | * unspecified entries are inherited from the closet ancestor |
| 5989 | * which has the method and the entry is populated with it. |
| 5990 | * After finalization, the ops table directly points to all the |
| 5991 | * methods and ->inherits is no longer necessary and cleared. |
| 5992 | * |
| 5993 | * Using ATA_OP_NULL, inheriting ops can force a method to NULL. |
| 5994 | * |
| 5995 | * LOCKING: |
| 5996 | * None. |
| 5997 | */ |
| 5998 | static void ata_finalize_port_ops(struct ata_port_operations *ops) |
| 5999 | { |
Pradeep Singh Rautela | 2da6765 | 2008-05-29 23:28:14 +0530 | [diff] [blame] | 6000 | static DEFINE_SPINLOCK(lock); |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6001 | const struct ata_port_operations *cur; |
| 6002 | void **begin = (void **)ops; |
| 6003 | void **end = (void **)&ops->inherits; |
| 6004 | void **pp; |
| 6005 | |
| 6006 | if (!ops || !ops->inherits) |
| 6007 | return; |
| 6008 | |
| 6009 | spin_lock(&lock); |
| 6010 | |
| 6011 | for (cur = ops->inherits; cur; cur = cur->inherits) { |
| 6012 | void **inherit = (void **)cur; |
| 6013 | |
| 6014 | for (pp = begin; pp < end; pp++, inherit++) |
| 6015 | if (!*pp) |
| 6016 | *pp = *inherit; |
| 6017 | } |
| 6018 | |
| 6019 | for (pp = begin; pp < end; pp++) |
| 6020 | if (IS_ERR(*pp)) |
| 6021 | *pp = NULL; |
| 6022 | |
| 6023 | ops->inherits = NULL; |
| 6024 | |
| 6025 | spin_unlock(&lock); |
| 6026 | } |
| 6027 | |
| 6028 | /** |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6029 | * ata_host_start - start and freeze ports of an ATA host |
| 6030 | * @host: ATA host to start ports for |
| 6031 | * |
| 6032 | * Start and then freeze ports of @host. Started status is |
| 6033 | * recorded in host->flags, so this function can be called |
| 6034 | * multiple times. Ports are guaranteed to get started only |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6035 | * once. If host->ops isn't initialized yet, its set to the |
| 6036 | * first non-dummy port ops. |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6037 | * |
| 6038 | * LOCKING: |
| 6039 | * Inherited from calling layer (may sleep). |
| 6040 | * |
| 6041 | * RETURNS: |
| 6042 | * 0 if all ports are started successfully, -errno otherwise. |
| 6043 | */ |
| 6044 | int ata_host_start(struct ata_host *host) |
| 6045 | { |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 6046 | int have_stop = 0; |
| 6047 | void *start_dr = NULL; |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6048 | int i, rc; |
| 6049 | |
| 6050 | if (host->flags & ATA_HOST_STARTED) |
| 6051 | return 0; |
| 6052 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6053 | ata_finalize_port_ops(host->ops); |
| 6054 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6055 | for (i = 0; i < host->n_ports; i++) { |
| 6056 | struct ata_port *ap = host->ports[i]; |
| 6057 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6058 | ata_finalize_port_ops(ap->ops); |
| 6059 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6060 | if (!host->ops && !ata_port_is_dummy(ap)) |
| 6061 | host->ops = ap->ops; |
| 6062 | |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 6063 | if (ap->ops->port_stop) |
| 6064 | have_stop = 1; |
| 6065 | } |
| 6066 | |
| 6067 | if (host->ops->host_stop) |
| 6068 | have_stop = 1; |
| 6069 | |
| 6070 | if (have_stop) { |
| 6071 | start_dr = devres_alloc(ata_host_stop, 0, GFP_KERNEL); |
| 6072 | if (!start_dr) |
| 6073 | return -ENOMEM; |
| 6074 | } |
| 6075 | |
| 6076 | for (i = 0; i < host->n_ports; i++) { |
| 6077 | struct ata_port *ap = host->ports[i]; |
| 6078 | |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6079 | if (ap->ops->port_start) { |
| 6080 | rc = ap->ops->port_start(ap); |
| 6081 | if (rc) { |
Alan Cox | 0f9fe9b | 2007-11-30 15:23:16 +0000 | [diff] [blame] | 6082 | if (rc != -ENODEV) |
Joe Perches | a44fec1 | 2011-04-15 15:51:58 -0700 | [diff] [blame] | 6083 | dev_err(host->dev, |
| 6084 | "failed to start port %d (errno=%d)\n", |
| 6085 | i, rc); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6086 | goto err_out; |
| 6087 | } |
| 6088 | } |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6089 | ata_eh_freeze_port(ap); |
| 6090 | } |
| 6091 | |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 6092 | if (start_dr) |
| 6093 | devres_add(host->dev, start_dr); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6094 | host->flags |= ATA_HOST_STARTED; |
| 6095 | return 0; |
| 6096 | |
| 6097 | err_out: |
| 6098 | while (--i >= 0) { |
| 6099 | struct ata_port *ap = host->ports[i]; |
| 6100 | |
| 6101 | if (ap->ops->port_stop) |
| 6102 | ap->ops->port_stop(ap); |
| 6103 | } |
Tejun Heo | 32ebbc0 | 2007-11-08 13:09:00 +0900 | [diff] [blame] | 6104 | devres_free(start_dr); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6105 | return rc; |
| 6106 | } |
| 6107 | |
| 6108 | /** |
Dan Williams | 8d8e7d1 | 2012-07-09 21:06:08 -0700 | [diff] [blame] | 6109 | * ata_sas_host_init - Initialize a host struct for sas (ipr, libsas) |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6110 | * @host: host to initialize |
| 6111 | * @dev: device host is attached to |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6112 | * @ops: port_ops |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6113 | * |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6114 | */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6115 | void ata_host_init(struct ata_host *host, struct device *dev, |
Dan Williams | 8d8e7d1 | 2012-07-09 21:06:08 -0700 | [diff] [blame] | 6116 | struct ata_port_operations *ops) |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6117 | { |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6118 | spin_lock_init(&host->lock); |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 6119 | mutex_init(&host->eh_mutex); |
Tejun Heo | 1a112d1 | 2014-07-23 09:05:27 -0400 | [diff] [blame] | 6120 | host->n_tags = ATA_MAX_QUEUE - 1; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6121 | host->dev = dev; |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6122 | host->ops = ops; |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6123 | } |
| 6124 | |
Dan Williams | 9508a66 | 2012-01-18 20:47:01 -0800 | [diff] [blame] | 6125 | void __ata_port_probe(struct ata_port *ap) |
| 6126 | { |
| 6127 | struct ata_eh_info *ehi = &ap->link.eh_info; |
| 6128 | unsigned long flags; |
| 6129 | |
| 6130 | /* kick EH for boot probing */ |
| 6131 | spin_lock_irqsave(ap->lock, flags); |
| 6132 | |
| 6133 | ehi->probe_mask |= ATA_ALL_DEVICES; |
| 6134 | ehi->action |= ATA_EH_RESET; |
| 6135 | ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; |
| 6136 | |
| 6137 | ap->pflags &= ~ATA_PFLAG_INITIALIZING; |
| 6138 | ap->pflags |= ATA_PFLAG_LOADING; |
| 6139 | ata_port_schedule_eh(ap); |
| 6140 | |
| 6141 | spin_unlock_irqrestore(ap->lock, flags); |
| 6142 | } |
| 6143 | |
James Bottomley | 238c9cf | 2011-01-23 08:28:33 -0600 | [diff] [blame] | 6144 | int ata_port_probe(struct ata_port *ap) |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 6145 | { |
James Bottomley | 238c9cf | 2011-01-23 08:28:33 -0600 | [diff] [blame] | 6146 | int rc = 0; |
Arjan van de Ven | 886ad09 | 2009-01-09 15:54:07 -0800 | [diff] [blame] | 6147 | |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 6148 | if (ap->ops->error_handler) { |
Dan Williams | 9508a66 | 2012-01-18 20:47:01 -0800 | [diff] [blame] | 6149 | __ata_port_probe(ap); |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 6150 | ata_port_wait_eh(ap); |
| 6151 | } else { |
| 6152 | DPRINTK("ata%u: bus probe begin\n", ap->print_id); |
| 6153 | rc = ata_bus_probe(ap); |
| 6154 | DPRINTK("ata%u: bus probe end\n", ap->print_id); |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 6155 | } |
James Bottomley | 238c9cf | 2011-01-23 08:28:33 -0600 | [diff] [blame] | 6156 | return rc; |
| 6157 | } |
| 6158 | |
| 6159 | |
| 6160 | static void async_port_probe(void *data, async_cookie_t cookie) |
| 6161 | { |
| 6162 | struct ata_port *ap = data; |
Jeff Garzik | 4fca377 | 2011-02-15 01:13:24 -0500 | [diff] [blame] | 6163 | |
James Bottomley | 238c9cf | 2011-01-23 08:28:33 -0600 | [diff] [blame] | 6164 | /* |
| 6165 | * If we're not allowed to scan this host in parallel, |
| 6166 | * we need to wait until all previous scans have completed |
| 6167 | * before going further. |
| 6168 | * Jeff Garzik says this is only within a controller, so we |
| 6169 | * don't need to wait for port 0, only for later ports. |
| 6170 | */ |
| 6171 | if (!(ap->host->flags & ATA_HOST_PARALLEL_SCAN) && ap->port_no != 0) |
| 6172 | async_synchronize_cookie(cookie); |
| 6173 | |
| 6174 | (void)ata_port_probe(ap); |
Arjan van de Ven | f29d3b2 | 2009-01-05 15:07:07 -0800 | [diff] [blame] | 6175 | |
| 6176 | /* in order to keep device order, we need to synchronize at this point */ |
| 6177 | async_synchronize_cookie(cookie); |
| 6178 | |
| 6179 | ata_scsi_scan_host(ap, 1); |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 6180 | } |
James Bottomley | 238c9cf | 2011-01-23 08:28:33 -0600 | [diff] [blame] | 6181 | |
Brian King | b03732f | 2006-08-07 14:27:10 -0500 | [diff] [blame] | 6182 | /** |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6183 | * ata_host_register - register initialized ATA host |
| 6184 | * @host: ATA host to register |
| 6185 | * @sht: template for SCSI host |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 6186 | * |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6187 | * Register initialized ATA host. @host is allocated using |
| 6188 | * ata_host_alloc() and fully initialized by LLD. This function |
| 6189 | * starts ports, registers @host with ATA and SCSI layers and |
| 6190 | * probe registered devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6191 | * |
| 6192 | * LOCKING: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6193 | * Inherited from calling layer (may sleep). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | * |
| 6195 | * RETURNS: |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6196 | * 0 on success, -errno otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6197 | */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6198 | 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] | 6199 | { |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6200 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6201 | |
Tejun Heo | 1a112d1 | 2014-07-23 09:05:27 -0400 | [diff] [blame] | 6202 | host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE - 1); |
Kevin Hao | 1871ee1 | 2014-07-12 12:08:24 +0800 | [diff] [blame] | 6203 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6204 | /* host must have been started */ |
| 6205 | if (!(host->flags & ATA_HOST_STARTED)) { |
Joe Perches | a44fec1 | 2011-04-15 15:51:58 -0700 | [diff] [blame] | 6206 | dev_err(host->dev, "BUG: trying to register unstarted host\n"); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6207 | WARN_ON(1); |
| 6208 | return -EINVAL; |
Alan Cox | 02f076a | 2006-09-26 17:35:32 +0100 | [diff] [blame] | 6209 | } |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6210 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6211 | /* Blow away unused ports. This happens when LLD can't |
| 6212 | * determine the exact number of ports to allocate at |
| 6213 | * allocation time. |
| 6214 | */ |
| 6215 | for (i = host->n_ports; host->ports[i]; i++) |
| 6216 | kfree(host->ports[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6217 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6218 | /* give ports names and add SCSI hosts */ |
David Milburn | e628dc9 | 2013-05-14 13:48:40 -0500 | [diff] [blame] | 6219 | for (i = 0; i < host->n_ports; i++) { |
Dan Williams | 85d6725 | 2012-03-10 23:28:46 -0800 | [diff] [blame] | 6220 | host->ports[i]->print_id = atomic_inc_return(&ata_print_id); |
David Milburn | e628dc9 | 2013-05-14 13:48:40 -0500 | [diff] [blame] | 6221 | host->ports[i]->local_port_no = i + 1; |
| 6222 | } |
Jeff Garzik | 4fca377 | 2011-02-15 01:13:24 -0500 | [diff] [blame] | 6223 | |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6224 | /* Create associated sysfs transport objects */ |
| 6225 | for (i = 0; i < host->n_ports; i++) { |
| 6226 | rc = ata_tport_add(host->dev,host->ports[i]); |
| 6227 | if (rc) { |
| 6228 | goto err_tadd; |
| 6229 | } |
| 6230 | } |
| 6231 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6232 | rc = ata_scsi_add_hosts(host, sht); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6233 | if (rc) |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6234 | goto err_tadd; |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6235 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6236 | /* set cable, sata_spd_limit and report */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6237 | for (i = 0; i < host->n_ports; i++) { |
| 6238 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6239 | unsigned long xfer_mask; |
| 6240 | |
| 6241 | /* set SATA cable type if still unset */ |
| 6242 | if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) |
| 6243 | ap->cbl = ATA_CBL_SATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 6245 | /* init sata_spd_limit to the current value */ |
Tejun Heo | 4fb37a2 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 6246 | sata_link_init_spd(&ap->link); |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 6247 | if (ap->slave_link) |
| 6248 | sata_link_init_spd(ap->slave_link); |
Tejun Heo | 5a04bf4 | 2006-05-31 18:27:38 +0900 | [diff] [blame] | 6249 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6250 | /* print per-port info to dmesg */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6251 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, |
| 6252 | ap->udma_mask); |
| 6253 | |
Tejun Heo | abf6e8e | 2007-10-09 14:57:25 +0900 | [diff] [blame] | 6254 | if (!ata_port_is_dummy(ap)) { |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6255 | ata_port_info(ap, "%cATA max %s %s\n", |
| 6256 | (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', |
| 6257 | ata_mode_string(xfer_mask), |
| 6258 | ap->link.eh_info.desc); |
Tejun Heo | abf6e8e | 2007-10-09 14:57:25 +0900 | [diff] [blame] | 6259 | ata_ehi_clear_desc(&ap->link.eh_info); |
| 6260 | } else |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6261 | ata_port_info(ap, "DUMMY\n"); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6262 | } |
| 6263 | |
Vegard Nossum | f600535 | 2009-04-08 18:19:39 +0200 | [diff] [blame] | 6264 | /* perform each probe asynchronously */ |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6265 | for (i = 0; i < host->n_ports; i++) { |
| 6266 | struct ata_port *ap = host->ports[i]; |
Arjan van de Ven | 7931805 | 2009-01-04 05:32:28 -0800 | [diff] [blame] | 6267 | async_schedule(async_port_probe, ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6269 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6270 | return 0; |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6271 | |
| 6272 | err_tadd: |
| 6273 | while (--i >= 0) { |
| 6274 | ata_tport_delete(host->ports[i]); |
| 6275 | } |
| 6276 | return rc; |
| 6277 | |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6278 | } |
| 6279 | |
| 6280 | /** |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6281 | * ata_host_activate - start host, request IRQ and register it |
| 6282 | * @host: target ATA host |
| 6283 | * @irq: IRQ to request |
| 6284 | * @irq_handler: irq_handler used when requesting IRQ |
| 6285 | * @irq_flags: irq_flags used when requesting IRQ |
| 6286 | * @sht: scsi_host_template to use when registering the host |
| 6287 | * |
| 6288 | * After allocating an ATA host and initializing it, most libata |
| 6289 | * LLDs perform three steps to activate the host - start host, |
| 6290 | * request IRQ and register it. This helper takes necessasry |
| 6291 | * arguments and performs the three steps in one go. |
| 6292 | * |
Paul Mundt | 3d46b2e | 2007-11-08 11:14:56 +0900 | [diff] [blame] | 6293 | * An invalid IRQ skips the IRQ registration and expects the host to |
| 6294 | * have set polling mode on the port. In this case, @irq_handler |
| 6295 | * should be NULL. |
| 6296 | * |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6297 | * LOCKING: |
| 6298 | * Inherited from calling layer (may sleep). |
| 6299 | * |
| 6300 | * RETURNS: |
| 6301 | * 0 on success, -errno otherwise. |
| 6302 | */ |
| 6303 | int ata_host_activate(struct ata_host *host, int irq, |
| 6304 | irq_handler_t irq_handler, unsigned long irq_flags, |
| 6305 | struct scsi_host_template *sht) |
| 6306 | { |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6307 | int i, rc; |
Heiner Kallweit | 7e22c00 | 2015-12-06 21:56:33 +0100 | [diff] [blame] | 6308 | char *irq_desc; |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6309 | |
| 6310 | rc = ata_host_start(host); |
| 6311 | if (rc) |
| 6312 | return rc; |
| 6313 | |
Paul Mundt | 3d46b2e | 2007-11-08 11:14:56 +0900 | [diff] [blame] | 6314 | /* Special case for polling mode */ |
| 6315 | if (!irq) { |
| 6316 | WARN_ON(irq_handler); |
| 6317 | return ata_host_register(host, sht); |
| 6318 | } |
| 6319 | |
Heiner Kallweit | 7e22c00 | 2015-12-06 21:56:33 +0100 | [diff] [blame] | 6320 | irq_desc = devm_kasprintf(host->dev, GFP_KERNEL, "%s[%s]", |
| 6321 | dev_driver_string(host->dev), |
| 6322 | dev_name(host->dev)); |
| 6323 | if (!irq_desc) |
| 6324 | return -ENOMEM; |
| 6325 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6326 | rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, |
Heiner Kallweit | 7e22c00 | 2015-12-06 21:56:33 +0100 | [diff] [blame] | 6327 | irq_desc, host); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6328 | if (rc) |
| 6329 | return rc; |
| 6330 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 6331 | for (i = 0; i < host->n_ports; i++) |
| 6332 | ata_port_desc(host->ports[i], "irq %d", irq); |
Tejun Heo | 4031826 | 2007-07-03 01:38:47 +0900 | [diff] [blame] | 6333 | |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6334 | rc = ata_host_register(host, sht); |
| 6335 | /* if failed, just free the IRQ and leave ports alone */ |
| 6336 | if (rc) |
| 6337 | devm_free_irq(host->dev, irq, host); |
| 6338 | |
| 6339 | return rc; |
| 6340 | } |
| 6341 | |
| 6342 | /** |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6343 | * ata_port_detach - Detach ATA port in prepration of device removal |
| 6344 | * @ap: ATA port to be detached |
| 6345 | * |
| 6346 | * Detach all ATA devices and the associated SCSI devices of @ap; |
| 6347 | * then, remove the associated SCSI host. @ap is guaranteed to |
| 6348 | * be quiescent on return from this function. |
| 6349 | * |
| 6350 | * LOCKING: |
| 6351 | * Kernel thread context (may sleep). |
| 6352 | */ |
Adrian Bunk | 741b776 | 2007-10-24 18:23:06 +0200 | [diff] [blame] | 6353 | static void ata_port_detach(struct ata_port *ap) |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6354 | { |
| 6355 | unsigned long flags; |
Levente Kurusa | a6f9bf4 | 2014-05-06 15:57:48 +0200 | [diff] [blame] | 6356 | struct ata_link *link; |
| 6357 | struct ata_device *dev; |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6358 | |
| 6359 | if (!ap->ops->error_handler) |
Tejun Heo | c3cf30a | 2006-08-05 03:59:11 +0900 | [diff] [blame] | 6360 | goto skip_eh; |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6361 | |
| 6362 | /* tell EH we're leaving & flush EH */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6363 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | b51e9e5 | 2006-06-29 01:29:30 +0900 | [diff] [blame] | 6364 | ap->pflags |= ATA_PFLAG_UNLOADING; |
Tejun Heo | ece180d | 2008-11-03 20:04:37 +0900 | [diff] [blame] | 6365 | ata_port_schedule_eh(ap); |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 6366 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6367 | |
Tejun Heo | ece180d | 2008-11-03 20:04:37 +0900 | [diff] [blame] | 6368 | /* wait till EH commits suicide */ |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6369 | ata_port_wait_eh(ap); |
| 6370 | |
Tejun Heo | ece180d | 2008-11-03 20:04:37 +0900 | [diff] [blame] | 6371 | /* it better be dead now */ |
| 6372 | WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED)); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6373 | |
Tejun Heo | afe2c51 | 2010-12-14 16:21:17 +0100 | [diff] [blame] | 6374 | cancel_delayed_work_sync(&ap->hotplug_task); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6375 | |
Tejun Heo | c3cf30a | 2006-08-05 03:59:11 +0900 | [diff] [blame] | 6376 | skip_eh: |
Levente Kurusa | a6f9bf4 | 2014-05-06 15:57:48 +0200 | [diff] [blame] | 6377 | /* clean up zpodd on port removal */ |
| 6378 | ata_for_each_link(link, ap, HOST_FIRST) { |
| 6379 | ata_for_each_dev(dev, link, ALL) { |
| 6380 | if (zpodd_dev_enabled(dev)) |
| 6381 | zpodd_exit(dev); |
| 6382 | } |
| 6383 | } |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6384 | if (ap->pmp_link) { |
| 6385 | int i; |
| 6386 | for (i = 0; i < SATA_PMP_MAX_PORTS; i++) |
| 6387 | ata_tlink_delete(&ap->pmp_link[i]); |
| 6388 | } |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6389 | /* remove the associated SCSI host */ |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6390 | scsi_remove_host(ap->scsi_host); |
Rafael J. Wysocki | c570076 | 2013-11-25 13:19:01 +0100 | [diff] [blame] | 6391 | ata_tport_delete(ap); |
Tejun Heo | 720ba12 | 2006-05-31 18:28:13 +0900 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | /** |
Tejun Heo | 0529c159 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 6395 | * ata_host_detach - Detach all ports of an ATA host |
| 6396 | * @host: Host to detach |
| 6397 | * |
| 6398 | * Detach all ports of @host. |
| 6399 | * |
| 6400 | * LOCKING: |
| 6401 | * Kernel thread context (may sleep). |
| 6402 | */ |
| 6403 | void ata_host_detach(struct ata_host *host) |
| 6404 | { |
| 6405 | int i; |
| 6406 | |
| 6407 | for (i = 0; i < host->n_ports; i++) |
| 6408 | ata_port_detach(host->ports[i]); |
Tejun Heo | 562f0c2 | 2007-12-15 15:05:01 +0900 | [diff] [blame] | 6409 | |
| 6410 | /* the host is dead now, dissociate ACPI */ |
| 6411 | ata_acpi_dissociate(host); |
Tejun Heo | 0529c159 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 6412 | } |
| 6413 | |
Jeff Garzik | 374b187 | 2005-08-30 05:42:52 -0400 | [diff] [blame] | 6414 | #ifdef CONFIG_PCI |
| 6415 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 6416 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6417 | * ata_pci_remove_one - PCI layer callback for device removal |
| 6418 | * @pdev: PCI device that was removed |
| 6419 | * |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6420 | * PCI layer indicates to libata via this hook that hot-unplug or |
| 6421 | * module unload event has occurred. Detach all ports. Resource |
| 6422 | * release is handled via devres. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6423 | * |
| 6424 | * LOCKING: |
| 6425 | * Inherited from PCI layer (may sleep). |
| 6426 | */ |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6427 | void ata_pci_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6428 | { |
Brian Norris | 04a3f5b | 2012-12-03 10:34:41 -0800 | [diff] [blame] | 6429 | struct ata_host *host = pci_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6430 | |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6431 | ata_host_detach(host); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
| 6434 | /* move to PCI subsystem */ |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 6435 | 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] | 6436 | { |
| 6437 | unsigned long tmp = 0; |
| 6438 | |
| 6439 | switch (bits->width) { |
| 6440 | case 1: { |
| 6441 | u8 tmp8 = 0; |
| 6442 | pci_read_config_byte(pdev, bits->reg, &tmp8); |
| 6443 | tmp = tmp8; |
| 6444 | break; |
| 6445 | } |
| 6446 | case 2: { |
| 6447 | u16 tmp16 = 0; |
| 6448 | pci_read_config_word(pdev, bits->reg, &tmp16); |
| 6449 | tmp = tmp16; |
| 6450 | break; |
| 6451 | } |
| 6452 | case 4: { |
| 6453 | u32 tmp32 = 0; |
| 6454 | pci_read_config_dword(pdev, bits->reg, &tmp32); |
| 6455 | tmp = tmp32; |
| 6456 | break; |
| 6457 | } |
| 6458 | |
| 6459 | default: |
| 6460 | return -EINVAL; |
| 6461 | } |
| 6462 | |
| 6463 | tmp &= bits->mask; |
| 6464 | |
| 6465 | return (tmp == bits->val) ? 1 : 0; |
| 6466 | } |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6467 | |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6468 | #ifdef CONFIG_PM |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 6469 | 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] | 6470 | { |
| 6471 | pci_save_state(pdev); |
Tejun Heo | 4c90d97 | 2007-02-20 18:14:48 +0900 | [diff] [blame] | 6472 | pci_disable_device(pdev); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6473 | |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 6474 | if (mesg.event & PM_EVENT_SLEEP) |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6475 | pci_set_power_state(pdev, PCI_D3hot); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6476 | } |
| 6477 | |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6478 | int ata_pci_device_do_resume(struct pci_dev *pdev) |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6479 | { |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6480 | int rc; |
| 6481 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6482 | pci_set_power_state(pdev, PCI_D0); |
| 6483 | pci_restore_state(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6484 | |
Tejun Heo | b878ca5 | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 6485 | rc = pcim_enable_device(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6486 | if (rc) { |
Joe Perches | a44fec1 | 2011-04-15 15:51:58 -0700 | [diff] [blame] | 6487 | dev_err(&pdev->dev, |
| 6488 | "failed to enable device after resume (%d)\n", rc); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6489 | return rc; |
| 6490 | } |
| 6491 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6492 | pci_set_master(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6493 | return 0; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6494 | } |
| 6495 | |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 6496 | 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] | 6497 | { |
Brian Norris | 04a3f5b | 2012-12-03 10:34:41 -0800 | [diff] [blame] | 6498 | struct ata_host *host = pci_get_drvdata(pdev); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6499 | int rc = 0; |
| 6500 | |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6501 | rc = ata_host_suspend(host, mesg); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6502 | if (rc) |
| 6503 | return rc; |
| 6504 | |
Tejun Heo | 3c5100c | 2006-07-26 16:58:33 +0900 | [diff] [blame] | 6505 | ata_pci_device_do_suspend(pdev, mesg); |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6506 | |
| 6507 | return 0; |
| 6508 | } |
| 6509 | |
| 6510 | int ata_pci_device_resume(struct pci_dev *pdev) |
| 6511 | { |
Brian Norris | 04a3f5b | 2012-12-03 10:34:41 -0800 | [diff] [blame] | 6512 | struct ata_host *host = pci_get_drvdata(pdev); |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6513 | int rc; |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 6514 | |
Tejun Heo | 553c4aa | 2006-12-26 19:39:50 +0900 | [diff] [blame] | 6515 | rc = ata_pci_device_do_resume(pdev); |
| 6516 | if (rc == 0) |
| 6517 | ata_host_resume(host); |
| 6518 | return rc; |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 6519 | } |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 6520 | #endif /* CONFIG_PM */ |
| 6521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6522 | #endif /* CONFIG_PCI */ |
| 6523 | |
Brian Norris | b7db04d | 2012-11-02 12:29:32 -0700 | [diff] [blame] | 6524 | /** |
| 6525 | * ata_platform_remove_one - Platform layer callback for device removal |
| 6526 | * @pdev: Platform device that was removed |
| 6527 | * |
| 6528 | * Platform layer indicates to libata via this hook that hot-unplug or |
| 6529 | * module unload event has occurred. Detach all ports. Resource |
| 6530 | * release is handled via devres. |
| 6531 | * |
| 6532 | * LOCKING: |
| 6533 | * Inherited from platform layer (may sleep). |
| 6534 | */ |
| 6535 | int ata_platform_remove_one(struct platform_device *pdev) |
| 6536 | { |
| 6537 | struct ata_host *host = platform_get_drvdata(pdev); |
| 6538 | |
| 6539 | ata_host_detach(host); |
| 6540 | |
| 6541 | return 0; |
| 6542 | } |
| 6543 | |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 6544 | static int __init ata_parse_force_one(char **cur, |
| 6545 | struct ata_force_ent *force_ent, |
| 6546 | const char **reason) |
| 6547 | { |
Rasmus Villemoes | 0f5f264 | 2015-06-09 15:33:19 +0200 | [diff] [blame] | 6548 | static const struct ata_force_param force_tbl[] __initconst = { |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 6549 | { "40c", .cbl = ATA_CBL_PATA40 }, |
| 6550 | { "80c", .cbl = ATA_CBL_PATA80 }, |
| 6551 | { "short40c", .cbl = ATA_CBL_PATA40_SHORT }, |
| 6552 | { "unk", .cbl = ATA_CBL_PATA_UNK }, |
| 6553 | { "ign", .cbl = ATA_CBL_PATA_IGN }, |
| 6554 | { "sata", .cbl = ATA_CBL_SATA }, |
| 6555 | { "1.5Gbps", .spd_limit = 1 }, |
| 6556 | { "3.0Gbps", .spd_limit = 2 }, |
| 6557 | { "noncq", .horkage_on = ATA_HORKAGE_NONCQ }, |
| 6558 | { "ncq", .horkage_off = ATA_HORKAGE_NONCQ }, |
Martin K. Petersen | d7b16e4 | 2015-05-04 21:54:18 -0400 | [diff] [blame] | 6559 | { "noncqtrim", .horkage_on = ATA_HORKAGE_NO_NCQ_TRIM }, |
| 6560 | { "ncqtrim", .horkage_off = ATA_HORKAGE_NO_NCQ_TRIM }, |
Tejun Heo | 43c9c59 | 2010-05-23 12:59:11 +0200 | [diff] [blame] | 6561 | { "dump_id", .horkage_on = ATA_HORKAGE_DUMP_ID }, |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 6562 | { "pio0", .xfer_mask = 1 << (ATA_SHIFT_PIO + 0) }, |
| 6563 | { "pio1", .xfer_mask = 1 << (ATA_SHIFT_PIO + 1) }, |
| 6564 | { "pio2", .xfer_mask = 1 << (ATA_SHIFT_PIO + 2) }, |
| 6565 | { "pio3", .xfer_mask = 1 << (ATA_SHIFT_PIO + 3) }, |
| 6566 | { "pio4", .xfer_mask = 1 << (ATA_SHIFT_PIO + 4) }, |
| 6567 | { "pio5", .xfer_mask = 1 << (ATA_SHIFT_PIO + 5) }, |
| 6568 | { "pio6", .xfer_mask = 1 << (ATA_SHIFT_PIO + 6) }, |
| 6569 | { "mwdma0", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 0) }, |
| 6570 | { "mwdma1", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 1) }, |
| 6571 | { "mwdma2", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 2) }, |
| 6572 | { "mwdma3", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 3) }, |
| 6573 | { "mwdma4", .xfer_mask = 1 << (ATA_SHIFT_MWDMA + 4) }, |
| 6574 | { "udma0", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 0) }, |
| 6575 | { "udma16", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 0) }, |
| 6576 | { "udma/16", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 0) }, |
| 6577 | { "udma1", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 1) }, |
| 6578 | { "udma25", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 1) }, |
| 6579 | { "udma/25", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 1) }, |
| 6580 | { "udma2", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 2) }, |
| 6581 | { "udma33", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 2) }, |
| 6582 | { "udma/33", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 2) }, |
| 6583 | { "udma3", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 3) }, |
| 6584 | { "udma44", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 3) }, |
| 6585 | { "udma/44", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 3) }, |
| 6586 | { "udma4", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 4) }, |
| 6587 | { "udma66", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 4) }, |
| 6588 | { "udma/66", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 4) }, |
| 6589 | { "udma5", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 5) }, |
| 6590 | { "udma100", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 5) }, |
| 6591 | { "udma/100", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 5) }, |
| 6592 | { "udma6", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, |
| 6593 | { "udma133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, |
| 6594 | { "udma/133", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 6) }, |
| 6595 | { "udma7", .xfer_mask = 1 << (ATA_SHIFT_UDMA + 7) }, |
Tejun Heo | 05944bd | 2008-08-13 20:19:09 +0900 | [diff] [blame] | 6596 | { "nohrst", .lflags = ATA_LFLAG_NO_HRST }, |
| 6597 | { "nosrst", .lflags = ATA_LFLAG_NO_SRST }, |
| 6598 | { "norst", .lflags = ATA_LFLAG_NO_HRST | ATA_LFLAG_NO_SRST }, |
Dan Williams | ca6d43b | 2012-06-21 23:41:41 -0700 | [diff] [blame] | 6599 | { "rstonce", .lflags = ATA_LFLAG_RST_ONCE }, |
Vincent Pelletier | 966fbe1 | 2013-05-21 22:30:58 +0200 | [diff] [blame] | 6600 | { "atapi_dmadir", .horkage_on = ATA_HORKAGE_ATAPI_DMADIR }, |
Robin H. Johnson | b8bd6dc | 2013-12-16 09:31:19 -0800 | [diff] [blame] | 6601 | { "disable", .horkage_on = ATA_HORKAGE_DISABLE }, |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 6602 | }; |
| 6603 | char *start = *cur, *p = *cur; |
| 6604 | char *id, *val, *endp; |
| 6605 | const struct ata_force_param *match_fp = NULL; |
| 6606 | int nr_matches = 0, i; |
| 6607 | |
| 6608 | /* find where this param ends and update *cur */ |
| 6609 | while (*p != '\0' && *p != ',') |
| 6610 | p++; |
| 6611 | |
| 6612 | if (*p == '\0') |
| 6613 | *cur = p; |
| 6614 | else |
| 6615 | *cur = p + 1; |
| 6616 | |
| 6617 | *p = '\0'; |
| 6618 | |
| 6619 | /* parse */ |
| 6620 | p = strchr(start, ':'); |
| 6621 | if (!p) { |
| 6622 | val = strstrip(start); |
| 6623 | goto parse_val; |
| 6624 | } |
| 6625 | *p = '\0'; |
| 6626 | |
| 6627 | id = strstrip(start); |
| 6628 | val = strstrip(p + 1); |
| 6629 | |
| 6630 | /* parse id */ |
| 6631 | p = strchr(id, '.'); |
| 6632 | if (p) { |
| 6633 | *p++ = '\0'; |
| 6634 | force_ent->device = simple_strtoul(p, &endp, 10); |
| 6635 | if (p == endp || *endp != '\0') { |
| 6636 | *reason = "invalid device"; |
| 6637 | return -EINVAL; |
| 6638 | } |
| 6639 | } |
| 6640 | |
| 6641 | force_ent->port = simple_strtoul(id, &endp, 10); |
| 6642 | if (p == endp || *endp != '\0') { |
| 6643 | *reason = "invalid port/link"; |
| 6644 | return -EINVAL; |
| 6645 | } |
| 6646 | |
| 6647 | parse_val: |
| 6648 | /* parse val, allow shortcuts so that both 1.5 and 1.5Gbps work */ |
| 6649 | for (i = 0; i < ARRAY_SIZE(force_tbl); i++) { |
| 6650 | const struct ata_force_param *fp = &force_tbl[i]; |
| 6651 | |
| 6652 | if (strncasecmp(val, fp->name, strlen(val))) |
| 6653 | continue; |
| 6654 | |
| 6655 | nr_matches++; |
| 6656 | match_fp = fp; |
| 6657 | |
| 6658 | if (strcasecmp(val, fp->name) == 0) { |
| 6659 | nr_matches = 1; |
| 6660 | break; |
| 6661 | } |
| 6662 | } |
| 6663 | |
| 6664 | if (!nr_matches) { |
| 6665 | *reason = "unknown value"; |
| 6666 | return -EINVAL; |
| 6667 | } |
| 6668 | if (nr_matches > 1) { |
| 6669 | *reason = "ambigious value"; |
| 6670 | return -EINVAL; |
| 6671 | } |
| 6672 | |
| 6673 | force_ent->param = *match_fp; |
| 6674 | |
| 6675 | return 0; |
| 6676 | } |
| 6677 | |
| 6678 | static void __init ata_parse_force_param(void) |
| 6679 | { |
| 6680 | int idx = 0, size = 1; |
| 6681 | int last_port = -1, last_device = -1; |
| 6682 | char *p, *cur, *next; |
| 6683 | |
| 6684 | /* calculate maximum number of params and allocate force_tbl */ |
| 6685 | for (p = ata_force_param_buf; *p; p++) |
| 6686 | if (*p == ',') |
| 6687 | size++; |
| 6688 | |
| 6689 | ata_force_tbl = kzalloc(sizeof(ata_force_tbl[0]) * size, GFP_KERNEL); |
| 6690 | if (!ata_force_tbl) { |
| 6691 | printk(KERN_WARNING "ata: failed to extend force table, " |
| 6692 | "libata.force ignored\n"); |
| 6693 | return; |
| 6694 | } |
| 6695 | |
| 6696 | /* parse and populate the table */ |
| 6697 | for (cur = ata_force_param_buf; *cur != '\0'; cur = next) { |
| 6698 | const char *reason = ""; |
| 6699 | struct ata_force_ent te = { .port = -1, .device = -1 }; |
| 6700 | |
| 6701 | next = cur; |
| 6702 | if (ata_parse_force_one(&next, &te, &reason)) { |
| 6703 | printk(KERN_WARNING "ata: failed to parse force " |
| 6704 | "parameter \"%s\" (%s)\n", |
| 6705 | cur, reason); |
| 6706 | continue; |
| 6707 | } |
| 6708 | |
| 6709 | if (te.port == -1) { |
| 6710 | te.port = last_port; |
| 6711 | te.device = last_device; |
| 6712 | } |
| 6713 | |
| 6714 | ata_force_tbl[idx++] = te; |
| 6715 | |
| 6716 | last_port = te.port; |
| 6717 | last_device = te.device; |
| 6718 | } |
| 6719 | |
| 6720 | ata_force_tbl_size = idx; |
| 6721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6723 | static int __init ata_init(void) |
| 6724 | { |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6725 | int rc; |
Tejun Heo | 270390e | 2010-05-10 21:41:35 +0200 | [diff] [blame] | 6726 | |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 6727 | ata_parse_force_param(); |
| 6728 | |
Tejun Heo | 270390e | 2010-05-10 21:41:35 +0200 | [diff] [blame] | 6729 | rc = ata_sff_init(); |
Tejun Heo | ad72cf9 | 2010-07-02 10:03:52 +0200 | [diff] [blame] | 6730 | if (rc) { |
| 6731 | kfree(ata_force_tbl); |
| 6732 | return rc; |
| 6733 | } |
Tejun Heo | 453b07a | 2006-05-31 18:27:42 +0900 | [diff] [blame] | 6734 | |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6735 | libata_transport_init(); |
| 6736 | ata_scsi_transport_template = ata_attach_transport(); |
| 6737 | if (!ata_scsi_transport_template) { |
| 6738 | ata_sff_exit(); |
| 6739 | rc = -ENOMEM; |
| 6740 | goto err_out; |
Jeff Garzik | 4fca377 | 2011-02-15 01:13:24 -0500 | [diff] [blame] | 6741 | } |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6743 | printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); |
| 6744 | return 0; |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6745 | |
| 6746 | err_out: |
| 6747 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6748 | } |
| 6749 | |
| 6750 | static void __exit ata_exit(void) |
| 6751 | { |
Gwendal Grignou | d902747 | 2010-05-25 12:31:38 -0700 | [diff] [blame] | 6752 | ata_release_transport(ata_scsi_transport_template); |
| 6753 | libata_transport_exit(); |
Tejun Heo | 270390e | 2010-05-10 21:41:35 +0200 | [diff] [blame] | 6754 | ata_sff_exit(); |
Tejun Heo | 3326732 | 2008-02-13 09:15:09 +0900 | [diff] [blame] | 6755 | kfree(ata_force_tbl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
Brian King | a462508 | 2006-11-13 16:32:36 -0600 | [diff] [blame] | 6758 | subsys_initcall(ata_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6759 | module_exit(ata_exit); |
| 6760 | |
Akinobu Mita | 9990b6f | 2010-04-12 21:11:41 +0900 | [diff] [blame] | 6761 | static DEFINE_RATELIMIT_STATE(ratelimit, HZ / 5, 1); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 6762 | |
| 6763 | int ata_ratelimit(void) |
| 6764 | { |
Akinobu Mita | 9990b6f | 2010-04-12 21:11:41 +0900 | [diff] [blame] | 6765 | return __ratelimit(&ratelimit); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 6766 | } |
| 6767 | |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 6768 | /** |
| 6769 | * ata_msleep - ATA EH owner aware msleep |
| 6770 | * @ap: ATA port to attribute the sleep to |
| 6771 | * @msecs: duration to sleep in milliseconds |
| 6772 | * |
| 6773 | * Sleeps @msecs. If the current task is owner of @ap's EH, the |
| 6774 | * ownership is released before going to sleep and reacquired |
| 6775 | * after the sleep is complete. IOW, other ports sharing the |
| 6776 | * @ap->host will be allowed to own the EH while this task is |
| 6777 | * sleeping. |
| 6778 | * |
| 6779 | * LOCKING: |
| 6780 | * Might sleep. |
| 6781 | */ |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 6782 | void ata_msleep(struct ata_port *ap, unsigned int msecs) |
| 6783 | { |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 6784 | bool owns_eh = ap && ap->host->eh_owner == current; |
| 6785 | |
| 6786 | if (owns_eh) |
| 6787 | ata_eh_release(ap); |
| 6788 | |
Anil Veliyankara Madam | 848c392 | 2016-01-07 21:18:52 -0800 | [diff] [blame] | 6789 | if (msecs < 20) { |
| 6790 | unsigned long usecs = msecs * USEC_PER_MSEC; |
| 6791 | usleep_range(usecs, usecs + 50); |
| 6792 | } else { |
| 6793 | msleep(msecs); |
| 6794 | } |
Tejun Heo | c0c362b | 2010-09-06 17:57:14 +0200 | [diff] [blame] | 6795 | |
| 6796 | if (owns_eh) |
| 6797 | ata_eh_acquire(ap); |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 6798 | } |
| 6799 | |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6800 | /** |
| 6801 | * ata_wait_register - wait until register value changes |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 6802 | * @ap: ATA port to wait register for, can be NULL |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6803 | * @reg: IO-mapped register |
| 6804 | * @mask: Mask to apply to read register value |
| 6805 | * @val: Wait condition |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 6806 | * @interval: polling interval in milliseconds |
| 6807 | * @timeout: timeout in milliseconds |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6808 | * |
| 6809 | * Waiting for some bits of register to change is a common |
| 6810 | * operation for ATA controllers. This function reads 32bit LE |
| 6811 | * IO-mapped register @reg and tests for the following condition. |
| 6812 | * |
| 6813 | * (*@reg & mask) != val |
| 6814 | * |
| 6815 | * If the condition is met, it returns; otherwise, the process is |
| 6816 | * repeated after @interval_msec until timeout. |
| 6817 | * |
| 6818 | * LOCKING: |
| 6819 | * Kernel thread context (may sleep) |
| 6820 | * |
| 6821 | * RETURNS: |
| 6822 | * The final register value. |
| 6823 | */ |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 6824 | u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val, |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 6825 | unsigned long interval, unsigned long timeout) |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6826 | { |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 6827 | unsigned long deadline; |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6828 | u32 tmp; |
| 6829 | |
| 6830 | tmp = ioread32(reg); |
| 6831 | |
| 6832 | /* Calculate timeout _after_ the first read to make sure |
| 6833 | * preceding writes reach the controller before starting to |
| 6834 | * eat away the timeout. |
| 6835 | */ |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 6836 | deadline = ata_deadline(jiffies, timeout); |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6837 | |
Tejun Heo | 341c2c9 | 2008-05-20 02:17:51 +0900 | [diff] [blame] | 6838 | while ((tmp & mask) == val && time_before(jiffies, deadline)) { |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 6839 | ata_msleep(ap, interval); |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 6840 | tmp = ioread32(reg); |
| 6841 | } |
| 6842 | |
| 6843 | return tmp; |
| 6844 | } |
| 6845 | |
Gabriele Mazzotta | 8393b81 | 2015-04-25 19:52:36 +0200 | [diff] [blame] | 6846 | /** |
| 6847 | * sata_lpm_ignore_phy_events - test if PHY event should be ignored |
| 6848 | * @link: Link receiving the event |
| 6849 | * |
| 6850 | * Test whether the received PHY event has to be ignored or not. |
| 6851 | * |
| 6852 | * LOCKING: |
| 6853 | * None: |
| 6854 | * |
| 6855 | * RETURNS: |
| 6856 | * True if the event has to be ignored. |
| 6857 | */ |
| 6858 | bool sata_lpm_ignore_phy_events(struct ata_link *link) |
| 6859 | { |
Gabriele Mazzotta | 09c5b48 | 2015-04-25 19:52:37 +0200 | [diff] [blame] | 6860 | unsigned long lpm_timeout = link->last_lpm_change + |
| 6861 | msecs_to_jiffies(ATA_TMOUT_SPURIOUS_PHY); |
| 6862 | |
Gabriele Mazzotta | 8393b81 | 2015-04-25 19:52:36 +0200 | [diff] [blame] | 6863 | /* if LPM is enabled, PHYRDY doesn't mean anything */ |
Gabriele Mazzotta | 09c5b48 | 2015-04-25 19:52:37 +0200 | [diff] [blame] | 6864 | if (link->lpm_policy > ATA_LPM_MAX_POWER) |
| 6865 | return true; |
| 6866 | |
| 6867 | /* ignore the first PHY event after the LPM policy changed |
| 6868 | * as it is might be spurious |
| 6869 | */ |
| 6870 | if ((link->flags & ATA_LFLAG_CHANGED) && |
| 6871 | time_before(jiffies, lpm_timeout)) |
| 6872 | return true; |
| 6873 | |
| 6874 | return false; |
Gabriele Mazzotta | 8393b81 | 2015-04-25 19:52:36 +0200 | [diff] [blame] | 6875 | } |
| 6876 | EXPORT_SYMBOL_GPL(sata_lpm_ignore_phy_events); |
| 6877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6878 | /* |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6879 | * Dummy port_ops |
| 6880 | */ |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6881 | static unsigned int ata_dummy_qc_issue(struct ata_queued_cmd *qc) |
| 6882 | { |
| 6883 | return AC_ERR_SYSTEM; |
| 6884 | } |
| 6885 | |
Tejun Heo | 182d7bb | 2008-04-07 22:47:21 +0900 | [diff] [blame] | 6886 | static void ata_dummy_error_handler(struct ata_port *ap) |
| 6887 | { |
| 6888 | /* truly dummy */ |
| 6889 | } |
| 6890 | |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6891 | struct ata_port_operations ata_dummy_port_ops = { |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6892 | .qc_prep = ata_noop_qc_prep, |
| 6893 | .qc_issue = ata_dummy_qc_issue, |
Tejun Heo | 182d7bb | 2008-04-07 22:47:21 +0900 | [diff] [blame] | 6894 | .error_handler = ata_dummy_error_handler, |
Dan Williams | e4a9c37 | 2012-06-21 23:25:27 -0700 | [diff] [blame] | 6895 | .sched_eh = ata_std_sched_eh, |
| 6896 | .end_eh = ata_std_end_eh, |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6897 | }; |
| 6898 | |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6899 | const struct ata_port_info ata_dummy_port_info = { |
| 6900 | .port_ops = &ata_dummy_port_ops, |
| 6901 | }; |
| 6902 | |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6903 | /* |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6904 | * Utility print functions |
| 6905 | */ |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6906 | void ata_port_printk(const struct ata_port *ap, const char *level, |
| 6907 | const char *fmt, ...) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6908 | { |
| 6909 | struct va_format vaf; |
| 6910 | va_list args; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6911 | |
| 6912 | va_start(args, fmt); |
| 6913 | |
| 6914 | vaf.fmt = fmt; |
| 6915 | vaf.va = &args; |
| 6916 | |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6917 | printk("%sata%u: %pV", level, ap->print_id, &vaf); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6918 | |
| 6919 | va_end(args); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6920 | } |
| 6921 | EXPORT_SYMBOL(ata_port_printk); |
| 6922 | |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6923 | void ata_link_printk(const struct ata_link *link, const char *level, |
| 6924 | const char *fmt, ...) |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6925 | { |
| 6926 | struct va_format vaf; |
| 6927 | va_list args; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6928 | |
| 6929 | va_start(args, fmt); |
| 6930 | |
| 6931 | vaf.fmt = fmt; |
| 6932 | vaf.va = &args; |
| 6933 | |
| 6934 | if (sata_pmp_attached(link->ap) || link->ap->slave_link) |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6935 | printk("%sata%u.%02u: %pV", |
| 6936 | level, link->ap->print_id, link->pmp, &vaf); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6937 | else |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6938 | printk("%sata%u: %pV", |
| 6939 | level, link->ap->print_id, &vaf); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6940 | |
| 6941 | va_end(args); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6942 | } |
| 6943 | EXPORT_SYMBOL(ata_link_printk); |
| 6944 | |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6945 | void ata_dev_printk(const struct ata_device *dev, const char *level, |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6946 | const char *fmt, ...) |
| 6947 | { |
| 6948 | struct va_format vaf; |
| 6949 | va_list args; |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6950 | |
| 6951 | va_start(args, fmt); |
| 6952 | |
| 6953 | vaf.fmt = fmt; |
| 6954 | vaf.va = &args; |
| 6955 | |
Joe Perches | d7bead1 | 2014-09-22 09:52:18 -0700 | [diff] [blame] | 6956 | printk("%sata%u.%02u: %pV", |
| 6957 | level, dev->link->ap->print_id, dev->link->pmp + dev->devno, |
| 6958 | &vaf); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6959 | |
| 6960 | va_end(args); |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6961 | } |
| 6962 | EXPORT_SYMBOL(ata_dev_printk); |
| 6963 | |
Joe Perches | 06296a1 | 2011-04-15 15:52:00 -0700 | [diff] [blame] | 6964 | void ata_print_version(const struct device *dev, const char *version) |
| 6965 | { |
| 6966 | dev_printk(KERN_DEBUG, dev, "version %s\n", version); |
| 6967 | } |
| 6968 | EXPORT_SYMBOL(ata_print_version); |
| 6969 | |
Joe Perches | a9a79df | 2011-04-15 15:51:59 -0700 | [diff] [blame] | 6970 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6971 | * libata is essentially a library of internal helper functions for |
| 6972 | * low-level ATA host controller drivers. As such, the API/ABI is |
| 6973 | * likely to change as new drivers are added and updated. |
| 6974 | * Do not depend on ABI/API stability. |
| 6975 | */ |
Tejun Heo | e9c8391 | 2006-07-03 16:07:26 +0900 | [diff] [blame] | 6976 | EXPORT_SYMBOL_GPL(sata_deb_timing_normal); |
| 6977 | EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug); |
| 6978 | EXPORT_SYMBOL_GPL(sata_deb_timing_long); |
Tejun Heo | 029cfd6 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 6979 | EXPORT_SYMBOL_GPL(ata_base_port_ops); |
| 6980 | EXPORT_SYMBOL_GPL(sata_port_ops); |
Tejun Heo | dd5b06c | 2006-08-10 16:59:12 +0900 | [diff] [blame] | 6981 | EXPORT_SYMBOL_GPL(ata_dummy_port_ops); |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6982 | EXPORT_SYMBOL_GPL(ata_dummy_port_info); |
Tejun Heo | 1eca436 | 2008-11-03 20:03:17 +0900 | [diff] [blame] | 6983 | EXPORT_SYMBOL_GPL(ata_link_next); |
| 6984 | EXPORT_SYMBOL_GPL(ata_dev_next); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6985 | EXPORT_SYMBOL_GPL(ata_std_bios_param); |
Tejun Heo | d8d9129 | 2010-05-15 20:09:34 +0200 | [diff] [blame] | 6986 | EXPORT_SYMBOL_GPL(ata_scsi_unlock_native_capacity); |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 6987 | EXPORT_SYMBOL_GPL(ata_host_init); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6988 | EXPORT_SYMBOL_GPL(ata_host_alloc); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6989 | EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo); |
Tejun Heo | b1c7291 | 2008-07-31 17:02:43 +0900 | [diff] [blame] | 6990 | EXPORT_SYMBOL_GPL(ata_slave_link_init); |
Tejun Heo | ecef725 | 2007-04-17 23:44:06 +0900 | [diff] [blame] | 6991 | EXPORT_SYMBOL_GPL(ata_host_start); |
Tejun Heo | f318719 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6992 | EXPORT_SYMBOL_GPL(ata_host_register); |
Tejun Heo | f5cda25 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 6993 | EXPORT_SYMBOL_GPL(ata_host_activate); |
Tejun Heo | 0529c159 | 2007-01-20 16:00:26 +0900 | [diff] [blame] | 6994 | EXPORT_SYMBOL_GPL(ata_host_detach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6995 | EXPORT_SYMBOL_GPL(ata_sg_init); |
Tejun Heo | f686bcb | 2006-05-15 20:58:05 +0900 | [diff] [blame] | 6996 | EXPORT_SYMBOL_GPL(ata_qc_complete); |
Tejun Heo | dedaf2b | 2006-05-15 21:03:43 +0900 | [diff] [blame] | 6997 | EXPORT_SYMBOL_GPL(ata_qc_complete_multiple); |
Tejun Heo | 436d34b | 2008-04-02 17:28:46 +0900 | [diff] [blame] | 6998 | EXPORT_SYMBOL_GPL(atapi_cmd_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6999 | EXPORT_SYMBOL_GPL(ata_tf_to_fis); |
| 7000 | EXPORT_SYMBOL_GPL(ata_tf_from_fis); |
Tejun Heo | 6357357 | 2007-11-27 19:43:39 +0900 | [diff] [blame] | 7001 | EXPORT_SYMBOL_GPL(ata_pack_xfermask); |
| 7002 | EXPORT_SYMBOL_GPL(ata_unpack_xfermask); |
| 7003 | EXPORT_SYMBOL_GPL(ata_xfer_mask2mode); |
| 7004 | EXPORT_SYMBOL_GPL(ata_xfer_mode2mask); |
| 7005 | EXPORT_SYMBOL_GPL(ata_xfer_mode2shift); |
| 7006 | EXPORT_SYMBOL_GPL(ata_mode_string); |
| 7007 | EXPORT_SYMBOL_GPL(ata_id_xfermask); |
Alan | 0435182 | 2007-03-06 02:37:52 -0800 | [diff] [blame] | 7008 | EXPORT_SYMBOL_GPL(ata_do_set_mode); |
Tejun Heo | 31cc23b | 2007-09-23 13:14:12 +0900 | [diff] [blame] | 7009 | EXPORT_SYMBOL_GPL(ata_std_qc_defer); |
Brian King | e46834c | 2006-03-17 17:04:03 -0600 | [diff] [blame] | 7010 | EXPORT_SYMBOL_GPL(ata_noop_qc_prep); |
Alan | 10305f0 | 2007-02-20 18:01:59 +0000 | [diff] [blame] | 7011 | EXPORT_SYMBOL_GPL(ata_dev_disable); |
Tejun Heo | 3c567b7 | 2006-05-15 20:57:23 +0900 | [diff] [blame] | 7012 | EXPORT_SYMBOL_GPL(sata_set_spd); |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 7013 | EXPORT_SYMBOL_GPL(ata_wait_after_reset); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7014 | EXPORT_SYMBOL_GPL(sata_link_debounce); |
| 7015 | EXPORT_SYMBOL_GPL(sata_link_resume); |
Tejun Heo | 1152b26 | 2010-09-01 17:50:05 +0200 | [diff] [blame] | 7016 | EXPORT_SYMBOL_GPL(sata_link_scr_lpm); |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 7017 | EXPORT_SYMBOL_GPL(ata_std_prereset); |
Tejun Heo | cc0680a | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7018 | EXPORT_SYMBOL_GPL(sata_link_hardreset); |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 7019 | EXPORT_SYMBOL_GPL(sata_std_hardreset); |
Tejun Heo | 203c75b | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 7020 | EXPORT_SYMBOL_GPL(ata_std_postreset); |
Jeff Garzik | 2e9edbf | 2006-03-24 09:56:57 -0500 | [diff] [blame] | 7021 | EXPORT_SYMBOL_GPL(ata_dev_classify); |
| 7022 | EXPORT_SYMBOL_GPL(ata_dev_pair); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 7023 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
Tejun Heo | 97750ce | 2010-09-06 17:56:29 +0200 | [diff] [blame] | 7024 | EXPORT_SYMBOL_GPL(ata_msleep); |
Tejun Heo | c22daff | 2006-04-11 22:22:29 +0900 | [diff] [blame] | 7025 | EXPORT_SYMBOL_GPL(ata_wait_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7026 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7027 | EXPORT_SYMBOL_GPL(ata_scsi_slave_config); |
Tejun Heo | 83c47bc | 2006-05-31 18:28:07 +0900 | [diff] [blame] | 7028 | EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); |
Tejun Heo | a6e6ce8 | 2006-05-15 21:03:48 +0900 | [diff] [blame] | 7029 | EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); |
Dan Williams | f6e6703 | 2011-09-20 15:10:33 -0700 | [diff] [blame] | 7030 | EXPORT_SYMBOL_GPL(__ata_change_queue_depth); |
Tejun Heo | 34bf217 | 2006-05-15 20:57:46 +0900 | [diff] [blame] | 7031 | EXPORT_SYMBOL_GPL(sata_scr_valid); |
| 7032 | EXPORT_SYMBOL_GPL(sata_scr_read); |
| 7033 | EXPORT_SYMBOL_GPL(sata_scr_write); |
| 7034 | EXPORT_SYMBOL_GPL(sata_scr_write_flush); |
Tejun Heo | 936fd73 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7035 | EXPORT_SYMBOL_GPL(ata_link_online); |
| 7036 | EXPORT_SYMBOL_GPL(ata_link_offline); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7037 | #ifdef CONFIG_PM |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 7038 | EXPORT_SYMBOL_GPL(ata_host_suspend); |
| 7039 | EXPORT_SYMBOL_GPL(ata_host_resume); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7040 | #endif /* CONFIG_PM */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 7041 | EXPORT_SYMBOL_GPL(ata_id_string); |
| 7042 | EXPORT_SYMBOL_GPL(ata_id_c_string); |
Alan Cox | 963e497 | 2008-07-24 17:16:06 +0100 | [diff] [blame] | 7043 | EXPORT_SYMBOL_GPL(ata_do_dev_read_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7044 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
| 7045 | |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 7046 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); |
Tejun Heo | 6357357 | 2007-11-27 19:43:39 +0900 | [diff] [blame] | 7047 | EXPORT_SYMBOL_GPL(ata_timing_find_mode); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 7048 | EXPORT_SYMBOL_GPL(ata_timing_compute); |
| 7049 | EXPORT_SYMBOL_GPL(ata_timing_merge); |
Tejun Heo | a0f79b9 | 2007-12-18 16:33:05 +0900 | [diff] [blame] | 7050 | EXPORT_SYMBOL_GPL(ata_timing_cycle2mode); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 7051 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | #ifdef CONFIG_PCI |
| 7053 | EXPORT_SYMBOL_GPL(pci_test_config_bits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7054 | EXPORT_SYMBOL_GPL(ata_pci_remove_one); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7055 | #ifdef CONFIG_PM |
Tejun Heo | 500530f | 2006-07-03 16:07:27 +0900 | [diff] [blame] | 7056 | EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend); |
| 7057 | EXPORT_SYMBOL_GPL(ata_pci_device_do_resume); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 7058 | EXPORT_SYMBOL_GPL(ata_pci_device_suspend); |
| 7059 | EXPORT_SYMBOL_GPL(ata_pci_device_resume); |
Tejun Heo | 6ffa01d | 2007-03-02 17:32:47 +0900 | [diff] [blame] | 7060 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7061 | #endif /* CONFIG_PCI */ |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 7062 | |
Brian Norris | b7db04d | 2012-11-02 12:29:32 -0700 | [diff] [blame] | 7063 | EXPORT_SYMBOL_GPL(ata_platform_remove_one); |
| 7064 | |
Tejun Heo | b64bbc3 | 2007-07-16 14:29:39 +0900 | [diff] [blame] | 7065 | EXPORT_SYMBOL_GPL(__ata_ehi_push_desc); |
| 7066 | EXPORT_SYMBOL_GPL(ata_ehi_push_desc); |
| 7067 | EXPORT_SYMBOL_GPL(ata_ehi_clear_desc); |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 7068 | EXPORT_SYMBOL_GPL(ata_port_desc); |
| 7069 | #ifdef CONFIG_PCI |
| 7070 | EXPORT_SYMBOL_GPL(ata_port_pbar_desc); |
| 7071 | #endif /* CONFIG_PCI */ |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 7072 | EXPORT_SYMBOL_GPL(ata_port_schedule_eh); |
Tejun Heo | dbd8261 | 2007-08-06 18:36:23 +0900 | [diff] [blame] | 7073 | EXPORT_SYMBOL_GPL(ata_link_abort); |
Tejun Heo | 7b70fc0 | 2006-05-15 20:58:07 +0900 | [diff] [blame] | 7074 | EXPORT_SYMBOL_GPL(ata_port_abort); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 7075 | EXPORT_SYMBOL_GPL(ata_port_freeze); |
Tejun Heo | 7d77b24 | 2007-09-23 13:14:13 +0900 | [diff] [blame] | 7076 | EXPORT_SYMBOL_GPL(sata_async_notification); |
Tejun Heo | e318049 | 2006-05-15 20:58:09 +0900 | [diff] [blame] | 7077 | EXPORT_SYMBOL_GPL(ata_eh_freeze_port); |
| 7078 | EXPORT_SYMBOL_GPL(ata_eh_thaw_port); |
Tejun Heo | ece1d63 | 2006-04-02 18:51:53 +0900 | [diff] [blame] | 7079 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); |
| 7080 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); |
Mark Lord | 10acf3b | 2008-05-02 02:14:53 -0400 | [diff] [blame] | 7081 | EXPORT_SYMBOL_GPL(ata_eh_analyze_ncq_error); |
Tejun Heo | 022bdb0 | 2006-05-15 20:58:22 +0900 | [diff] [blame] | 7082 | EXPORT_SYMBOL_GPL(ata_do_eh); |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 7083 | EXPORT_SYMBOL_GPL(ata_std_error_handler); |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 7084 | |
| 7085 | EXPORT_SYMBOL_GPL(ata_cable_40wire); |
| 7086 | EXPORT_SYMBOL_GPL(ata_cable_80wire); |
| 7087 | EXPORT_SYMBOL_GPL(ata_cable_unknown); |
Tejun Heo | c88f90c | 2007-11-27 19:43:48 +0900 | [diff] [blame] | 7088 | EXPORT_SYMBOL_GPL(ata_cable_ignore); |
Alan Cox | be0d18d | 2007-03-06 02:37:56 -0800 | [diff] [blame] | 7089 | EXPORT_SYMBOL_GPL(ata_cable_sata); |