Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Garzik | af36d7f | 2005-08-28 20:18:39 -0400 | [diff] [blame] | 2 | * libata-core.c - helper library for ATA |
| 3 | * |
| 4 | * Maintained by: Jeff Garzik <jgarzik@pobox.com> |
| 5 | * Please ALWAYS copy linux-ide@vger.kernel.org |
| 6 | * on emails. |
| 7 | * |
| 8 | * Copyright 2003-2004 Red Hat, Inc. All rights reserved. |
| 9 | * Copyright 2003-2004 Jeff Garzik |
| 10 | * |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; see the file COPYING. If not, write to |
| 24 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
| 26 | * |
| 27 | * libata documentation is available via 'make {ps|pdf}docs', |
| 28 | * as Documentation/DocBook/libata.* |
| 29 | * |
| 30 | * Hardware documentation available from http://www.t13.org/ and |
| 31 | * http://www.sata-io.org/ |
| 32 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | #include <linux/config.h> |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/init.h> |
| 40 | #include <linux/list.h> |
| 41 | #include <linux/mm.h> |
| 42 | #include <linux/highmem.h> |
| 43 | #include <linux/spinlock.h> |
| 44 | #include <linux/blkdev.h> |
| 45 | #include <linux/delay.h> |
| 46 | #include <linux/timer.h> |
| 47 | #include <linux/interrupt.h> |
| 48 | #include <linux/completion.h> |
| 49 | #include <linux/suspend.h> |
| 50 | #include <linux/workqueue.h> |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 51 | #include <linux/jiffies.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 52 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <scsi/scsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include "scsi_priv.h" |
Jeff Garzik | 193515d | 2005-11-07 00:59:37 -0500 | [diff] [blame] | 55 | #include <scsi/scsi_cmnd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <scsi/scsi_host.h> |
| 57 | #include <linux/libata.h> |
| 58 | #include <asm/io.h> |
| 59 | #include <asm/semaphore.h> |
| 60 | #include <asm/byteorder.h> |
| 61 | |
| 62 | #include "libata.h" |
| 63 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 64 | static unsigned int ata_dev_init_params(struct ata_port *ap, |
| 65 | struct ata_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static void ata_set_mode(struct ata_port *ap); |
| 67 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 68 | static unsigned int ata_dev_xfermask(struct ata_port *ap, |
| 69 | struct ata_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static int fgb(u32 bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | static unsigned int ata_unique_id = 1; |
| 73 | static struct workqueue_struct *ata_wq; |
| 74 | |
Jeff Garzik | 1623c81 | 2005-08-30 03:37:42 -0400 | [diff] [blame] | 75 | int atapi_enabled = 0; |
| 76 | module_param(atapi_enabled, int, 0444); |
| 77 | MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)"); |
| 78 | |
Jeff Garzik | c3c013a | 2006-02-27 22:31:19 -0500 | [diff] [blame] | 79 | int libata_fua = 0; |
| 80 | module_param_named(fua, libata_fua, int, 0444); |
| 81 | MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)"); |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | MODULE_AUTHOR("Jeff Garzik"); |
| 84 | MODULE_DESCRIPTION("Library module for ATA devices"); |
| 85 | MODULE_LICENSE("GPL"); |
| 86 | MODULE_VERSION(DRV_VERSION); |
| 87 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 88 | |
| 89 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure |
| 91 | * @tf: Taskfile to convert |
| 92 | * @fis: Buffer into which data will output |
| 93 | * @pmp: Port multiplier port |
| 94 | * |
| 95 | * Converts a standard ATA taskfile to a Serial ATA |
| 96 | * FIS structure (Register - Host to Device). |
| 97 | * |
| 98 | * LOCKING: |
| 99 | * Inherited from caller. |
| 100 | */ |
| 101 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 102 | void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
| 104 | fis[0] = 0x27; /* Register - Host to Device FIS */ |
| 105 | fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number, |
| 106 | bit 7 indicates Command FIS */ |
| 107 | fis[2] = tf->command; |
| 108 | fis[3] = tf->feature; |
| 109 | |
| 110 | fis[4] = tf->lbal; |
| 111 | fis[5] = tf->lbam; |
| 112 | fis[6] = tf->lbah; |
| 113 | fis[7] = tf->device; |
| 114 | |
| 115 | fis[8] = tf->hob_lbal; |
| 116 | fis[9] = tf->hob_lbam; |
| 117 | fis[10] = tf->hob_lbah; |
| 118 | fis[11] = tf->hob_feature; |
| 119 | |
| 120 | fis[12] = tf->nsect; |
| 121 | fis[13] = tf->hob_nsect; |
| 122 | fis[14] = 0; |
| 123 | fis[15] = tf->ctl; |
| 124 | |
| 125 | fis[16] = 0; |
| 126 | fis[17] = 0; |
| 127 | fis[18] = 0; |
| 128 | fis[19] = 0; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * ata_tf_from_fis - Convert SATA FIS to ATA taskfile |
| 133 | * @fis: Buffer from which data will be input |
| 134 | * @tf: Taskfile to output |
| 135 | * |
Mark Lord | e12a1be | 2005-11-12 18:55:45 -0500 | [diff] [blame] | 136 | * Converts a serial ATA FIS structure to a standard ATA taskfile. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | * |
| 138 | * LOCKING: |
| 139 | * Inherited from caller. |
| 140 | */ |
| 141 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 142 | void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | tf->command = fis[2]; /* status */ |
| 145 | tf->feature = fis[3]; /* error */ |
| 146 | |
| 147 | tf->lbal = fis[4]; |
| 148 | tf->lbam = fis[5]; |
| 149 | tf->lbah = fis[6]; |
| 150 | tf->device = fis[7]; |
| 151 | |
| 152 | tf->hob_lbal = fis[8]; |
| 153 | tf->hob_lbam = fis[9]; |
| 154 | tf->hob_lbah = fis[10]; |
| 155 | |
| 156 | tf->nsect = fis[12]; |
| 157 | tf->hob_nsect = fis[13]; |
| 158 | } |
| 159 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 160 | static const u8 ata_rw_cmds[] = { |
| 161 | /* pio multi */ |
| 162 | ATA_CMD_READ_MULTI, |
| 163 | ATA_CMD_WRITE_MULTI, |
| 164 | ATA_CMD_READ_MULTI_EXT, |
| 165 | ATA_CMD_WRITE_MULTI_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 166 | 0, |
| 167 | 0, |
| 168 | 0, |
| 169 | ATA_CMD_WRITE_MULTI_FUA_EXT, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 170 | /* pio */ |
| 171 | ATA_CMD_PIO_READ, |
| 172 | ATA_CMD_PIO_WRITE, |
| 173 | ATA_CMD_PIO_READ_EXT, |
| 174 | ATA_CMD_PIO_WRITE_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 175 | 0, |
| 176 | 0, |
| 177 | 0, |
| 178 | 0, |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 179 | /* dma */ |
| 180 | ATA_CMD_READ, |
| 181 | ATA_CMD_WRITE, |
| 182 | ATA_CMD_READ_EXT, |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 183 | ATA_CMD_WRITE_EXT, |
| 184 | 0, |
| 185 | 0, |
| 186 | 0, |
| 187 | ATA_CMD_WRITE_FUA_EXT |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 188 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 191 | * ata_rwcmd_protocol - set taskfile r/w commands and protocol |
| 192 | * @qc: command to examine and configure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | * |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 194 | * Examine the device configuration and tf->flags to calculate |
| 195 | * the proper read/write commands and protocol to use. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * |
| 197 | * LOCKING: |
| 198 | * caller. |
| 199 | */ |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 200 | int ata_rwcmd_protocol(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 202 | struct ata_taskfile *tf = &qc->tf; |
| 203 | struct ata_device *dev = qc->dev; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 204 | u8 cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 206 | int index, fua, lba48, write; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 207 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 208 | fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 209 | lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; |
| 210 | write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 212 | if (dev->flags & ATA_DFLAG_PIO) { |
| 213 | tf->protocol = ATA_PROT_PIO; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 214 | index = dev->multi_count ? 0 : 8; |
Alan Cox | 8d238e0 | 2006-01-17 20:50:31 +0000 | [diff] [blame] | 215 | } else if (lba48 && (qc->ap->flags & ATA_FLAG_PIO_LBA48)) { |
| 216 | /* Unable to use DMA due to host limitation */ |
| 217 | tf->protocol = ATA_PROT_PIO; |
Albert Lee | 0565c26 | 2006-02-13 18:55:25 +0800 | [diff] [blame] | 218 | index = dev->multi_count ? 0 : 8; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 219 | } else { |
| 220 | tf->protocol = ATA_PROT_DMA; |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 221 | index = 16; |
Albert Lee | 8cbd6df | 2005-10-12 15:06:27 +0800 | [diff] [blame] | 222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Tejun Heo | 9a3dccc | 2006-01-06 09:56:18 +0100 | [diff] [blame] | 224 | cmd = ata_rw_cmds[index + fua + lba48 + write]; |
| 225 | if (cmd) { |
| 226 | tf->command = cmd; |
| 227 | return 0; |
| 228 | } |
| 229 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 232 | /** |
| 233 | * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask |
| 234 | * @pio_mask: pio_mask |
| 235 | * @mwdma_mask: mwdma_mask |
| 236 | * @udma_mask: udma_mask |
| 237 | * |
| 238 | * Pack @pio_mask, @mwdma_mask and @udma_mask into a single |
| 239 | * unsigned int xfer_mask. |
| 240 | * |
| 241 | * LOCKING: |
| 242 | * None. |
| 243 | * |
| 244 | * RETURNS: |
| 245 | * Packed xfer_mask. |
| 246 | */ |
| 247 | static unsigned int ata_pack_xfermask(unsigned int pio_mask, |
| 248 | unsigned int mwdma_mask, |
| 249 | unsigned int udma_mask) |
| 250 | { |
| 251 | return ((pio_mask << ATA_SHIFT_PIO) & ATA_MASK_PIO) | |
| 252 | ((mwdma_mask << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA) | |
| 253 | ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA); |
| 254 | } |
| 255 | |
| 256 | static const struct ata_xfer_ent { |
| 257 | unsigned int shift, bits; |
| 258 | u8 base; |
| 259 | } ata_xfer_tbl[] = { |
| 260 | { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 }, |
| 261 | { ATA_SHIFT_MWDMA, ATA_BITS_MWDMA, XFER_MW_DMA_0 }, |
| 262 | { ATA_SHIFT_UDMA, ATA_BITS_UDMA, XFER_UDMA_0 }, |
| 263 | { -1, }, |
| 264 | }; |
| 265 | |
| 266 | /** |
| 267 | * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask |
| 268 | * @xfer_mask: xfer_mask of interest |
| 269 | * |
| 270 | * Return matching XFER_* value for @xfer_mask. Only the highest |
| 271 | * bit of @xfer_mask is considered. |
| 272 | * |
| 273 | * LOCKING: |
| 274 | * None. |
| 275 | * |
| 276 | * RETURNS: |
| 277 | * Matching XFER_* value, 0 if no match found. |
| 278 | */ |
| 279 | static u8 ata_xfer_mask2mode(unsigned int xfer_mask) |
| 280 | { |
| 281 | int highbit = fls(xfer_mask) - 1; |
| 282 | const struct ata_xfer_ent *ent; |
| 283 | |
| 284 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 285 | if (highbit >= ent->shift && highbit < ent->shift + ent->bits) |
| 286 | return ent->base + highbit - ent->shift; |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * ata_xfer_mode2mask - Find matching xfer_mask for XFER_* |
| 292 | * @xfer_mode: XFER_* of interest |
| 293 | * |
| 294 | * Return matching xfer_mask for @xfer_mode. |
| 295 | * |
| 296 | * LOCKING: |
| 297 | * None. |
| 298 | * |
| 299 | * RETURNS: |
| 300 | * Matching xfer_mask, 0 if no match found. |
| 301 | */ |
| 302 | static unsigned int ata_xfer_mode2mask(u8 xfer_mode) |
| 303 | { |
| 304 | const struct ata_xfer_ent *ent; |
| 305 | |
| 306 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 307 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
| 308 | return 1 << (ent->shift + xfer_mode - ent->base); |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * ata_xfer_mode2shift - Find matching xfer_shift for XFER_* |
| 314 | * @xfer_mode: XFER_* of interest |
| 315 | * |
| 316 | * Return matching xfer_shift for @xfer_mode. |
| 317 | * |
| 318 | * LOCKING: |
| 319 | * None. |
| 320 | * |
| 321 | * RETURNS: |
| 322 | * Matching xfer_shift, -1 if no match found. |
| 323 | */ |
| 324 | static int ata_xfer_mode2shift(unsigned int xfer_mode) |
| 325 | { |
| 326 | const struct ata_xfer_ent *ent; |
| 327 | |
| 328 | for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) |
| 329 | if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) |
| 330 | return ent->shift; |
| 331 | return -1; |
| 332 | } |
| 333 | |
Arjan van de Ven | 98ac62d | 2005-11-28 10:06:23 +0100 | [diff] [blame] | 334 | static const char * const xfer_mode_str[] = { |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 335 | "PIO0", |
| 336 | "PIO1", |
| 337 | "PIO2", |
| 338 | "PIO3", |
| 339 | "PIO4", |
| 340 | "MWDMA0", |
| 341 | "MWDMA1", |
| 342 | "MWDMA2", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | "UDMA/16", |
| 344 | "UDMA/25", |
| 345 | "UDMA/33", |
| 346 | "UDMA/44", |
| 347 | "UDMA/66", |
| 348 | "UDMA/100", |
| 349 | "UDMA/133", |
| 350 | "UDMA7", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | /** |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 354 | * ata_mode_string - convert xfer_mask to string |
| 355 | * @xfer_mask: mask of bits supported; only highest bit counts. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | * |
| 357 | * Determine string which represents the highest speed |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 358 | * (highest bit in @modemask). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | * |
| 360 | * LOCKING: |
| 361 | * None. |
| 362 | * |
| 363 | * RETURNS: |
| 364 | * Constant C string representing highest speed listed in |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 365 | * @mode_mask, or the constant C string "<n/a>". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | */ |
| 367 | |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 368 | static const char *ata_mode_string(unsigned int xfer_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 370 | int highbit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Tejun Heo | 1da7b0d | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 372 | highbit = fls(xfer_mask) - 1; |
| 373 | if (highbit >= 0 && highbit < ARRAY_SIZE(xfer_mode_str)) |
| 374 | return xfer_mode_str[highbit]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return "<n/a>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
| 379 | * ata_pio_devchk - PATA device presence detection |
| 380 | * @ap: ATA channel to examine |
| 381 | * @device: Device to examine (starting at zero) |
| 382 | * |
| 383 | * This technique was originally described in |
| 384 | * Hale Landis's ATADRVR (www.ata-atapi.com), and |
| 385 | * later found its way into the ATA/ATAPI spec. |
| 386 | * |
| 387 | * Write a pattern to the ATA shadow registers, |
| 388 | * and if a device is present, it will respond by |
| 389 | * correctly storing and echoing back the |
| 390 | * ATA shadow register contents. |
| 391 | * |
| 392 | * LOCKING: |
| 393 | * caller. |
| 394 | */ |
| 395 | |
| 396 | static unsigned int ata_pio_devchk(struct ata_port *ap, |
| 397 | unsigned int device) |
| 398 | { |
| 399 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 400 | u8 nsect, lbal; |
| 401 | |
| 402 | ap->ops->dev_select(ap, device); |
| 403 | |
| 404 | outb(0x55, ioaddr->nsect_addr); |
| 405 | outb(0xaa, ioaddr->lbal_addr); |
| 406 | |
| 407 | outb(0xaa, ioaddr->nsect_addr); |
| 408 | outb(0x55, ioaddr->lbal_addr); |
| 409 | |
| 410 | outb(0x55, ioaddr->nsect_addr); |
| 411 | outb(0xaa, ioaddr->lbal_addr); |
| 412 | |
| 413 | nsect = inb(ioaddr->nsect_addr); |
| 414 | lbal = inb(ioaddr->lbal_addr); |
| 415 | |
| 416 | if ((nsect == 0x55) && (lbal == 0xaa)) |
| 417 | return 1; /* we found a device */ |
| 418 | |
| 419 | return 0; /* nothing found */ |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * ata_mmio_devchk - PATA device presence detection |
| 424 | * @ap: ATA channel to examine |
| 425 | * @device: Device to examine (starting at zero) |
| 426 | * |
| 427 | * This technique was originally described in |
| 428 | * Hale Landis's ATADRVR (www.ata-atapi.com), and |
| 429 | * later found its way into the ATA/ATAPI spec. |
| 430 | * |
| 431 | * Write a pattern to the ATA shadow registers, |
| 432 | * and if a device is present, it will respond by |
| 433 | * correctly storing and echoing back the |
| 434 | * ATA shadow register contents. |
| 435 | * |
| 436 | * LOCKING: |
| 437 | * caller. |
| 438 | */ |
| 439 | |
| 440 | static unsigned int ata_mmio_devchk(struct ata_port *ap, |
| 441 | unsigned int device) |
| 442 | { |
| 443 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 444 | u8 nsect, lbal; |
| 445 | |
| 446 | ap->ops->dev_select(ap, device); |
| 447 | |
| 448 | writeb(0x55, (void __iomem *) ioaddr->nsect_addr); |
| 449 | writeb(0xaa, (void __iomem *) ioaddr->lbal_addr); |
| 450 | |
| 451 | writeb(0xaa, (void __iomem *) ioaddr->nsect_addr); |
| 452 | writeb(0x55, (void __iomem *) ioaddr->lbal_addr); |
| 453 | |
| 454 | writeb(0x55, (void __iomem *) ioaddr->nsect_addr); |
| 455 | writeb(0xaa, (void __iomem *) ioaddr->lbal_addr); |
| 456 | |
| 457 | nsect = readb((void __iomem *) ioaddr->nsect_addr); |
| 458 | lbal = readb((void __iomem *) ioaddr->lbal_addr); |
| 459 | |
| 460 | if ((nsect == 0x55) && (lbal == 0xaa)) |
| 461 | return 1; /* we found a device */ |
| 462 | |
| 463 | return 0; /* nothing found */ |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * ata_devchk - PATA device presence detection |
| 468 | * @ap: ATA channel to examine |
| 469 | * @device: Device to examine (starting at zero) |
| 470 | * |
| 471 | * Dispatch ATA device presence detection, depending |
| 472 | * on whether we are using PIO or MMIO to talk to the |
| 473 | * ATA shadow registers. |
| 474 | * |
| 475 | * LOCKING: |
| 476 | * caller. |
| 477 | */ |
| 478 | |
| 479 | static unsigned int ata_devchk(struct ata_port *ap, |
| 480 | unsigned int device) |
| 481 | { |
| 482 | if (ap->flags & ATA_FLAG_MMIO) |
| 483 | return ata_mmio_devchk(ap, device); |
| 484 | return ata_pio_devchk(ap, device); |
| 485 | } |
| 486 | |
| 487 | /** |
| 488 | * ata_dev_classify - determine device type based on ATA-spec signature |
| 489 | * @tf: ATA taskfile register set for device to be identified |
| 490 | * |
| 491 | * Determine from taskfile register contents whether a device is |
| 492 | * ATA or ATAPI, as per "Signature and persistence" section |
| 493 | * of ATA/PI spec (volume 1, sect 5.14). |
| 494 | * |
| 495 | * LOCKING: |
| 496 | * None. |
| 497 | * |
| 498 | * RETURNS: |
| 499 | * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, or %ATA_DEV_UNKNOWN |
| 500 | * the event of failure. |
| 501 | */ |
| 502 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 503 | unsigned int ata_dev_classify(const struct ata_taskfile *tf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
| 505 | /* Apple's open source Darwin code hints that some devices only |
| 506 | * put a proper signature into the LBA mid/high registers, |
| 507 | * So, we only check those. It's sufficient for uniqueness. |
| 508 | */ |
| 509 | |
| 510 | if (((tf->lbam == 0) && (tf->lbah == 0)) || |
| 511 | ((tf->lbam == 0x3c) && (tf->lbah == 0xc3))) { |
| 512 | DPRINTK("found ATA device by sig\n"); |
| 513 | return ATA_DEV_ATA; |
| 514 | } |
| 515 | |
| 516 | if (((tf->lbam == 0x14) && (tf->lbah == 0xeb)) || |
| 517 | ((tf->lbam == 0x69) && (tf->lbah == 0x96))) { |
| 518 | DPRINTK("found ATAPI device by sig\n"); |
| 519 | return ATA_DEV_ATAPI; |
| 520 | } |
| 521 | |
| 522 | DPRINTK("unknown device\n"); |
| 523 | return ATA_DEV_UNKNOWN; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * ata_dev_try_classify - Parse returned ATA device signature |
| 528 | * @ap: ATA channel to examine |
| 529 | * @device: Device to examine (starting at zero) |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 530 | * @r_err: Value of error register on completion |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | * |
| 532 | * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs, |
| 533 | * an ATA/ATAPI-defined set of values is placed in the ATA |
| 534 | * shadow registers, indicating the results of device detection |
| 535 | * and diagnostics. |
| 536 | * |
| 537 | * Select the ATA device, and read the values from the ATA shadow |
| 538 | * registers. Then parse according to the Error register value, |
| 539 | * and the spec-defined values examined by ata_dev_classify(). |
| 540 | * |
| 541 | * LOCKING: |
| 542 | * caller. |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 543 | * |
| 544 | * RETURNS: |
| 545 | * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | */ |
| 547 | |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 548 | static unsigned int |
| 549 | ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | struct ata_taskfile tf; |
| 552 | unsigned int class; |
| 553 | u8 err; |
| 554 | |
| 555 | ap->ops->dev_select(ap, device); |
| 556 | |
| 557 | memset(&tf, 0, sizeof(tf)); |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | ap->ops->tf_read(ap, &tf); |
Jeff Garzik | 0169e28 | 2005-10-29 21:25:10 -0400 | [diff] [blame] | 560 | err = tf.feature; |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 561 | if (r_err) |
| 562 | *r_err = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
| 564 | /* see if device passed diags */ |
| 565 | if (err == 1) |
| 566 | /* do nothing */ ; |
| 567 | else if ((device == 0) && (err == 0x81)) |
| 568 | /* do nothing */ ; |
| 569 | else |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 570 | return ATA_DEV_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 572 | /* determine if device is ATA or ATAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | class = ata_dev_classify(&tf); |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | if (class == ATA_DEV_UNKNOWN) |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 576 | return ATA_DEV_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0)) |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 578 | return ATA_DEV_NONE; |
| 579 | return class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 583 | * ata_id_string - Convert IDENTIFY DEVICE page into string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | * @id: IDENTIFY DEVICE results we will examine |
| 585 | * @s: string into which data is output |
| 586 | * @ofs: offset into identify device page |
| 587 | * @len: length of string to return. must be an even number. |
| 588 | * |
| 589 | * The strings in the IDENTIFY DEVICE page are broken up into |
| 590 | * 16-bit chunks. Run through the string, and output each |
| 591 | * 8-bit chunk linearly, regardless of platform. |
| 592 | * |
| 593 | * LOCKING: |
| 594 | * caller. |
| 595 | */ |
| 596 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 597 | void ata_id_string(const u16 *id, unsigned char *s, |
| 598 | unsigned int ofs, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
| 600 | unsigned int c; |
| 601 | |
| 602 | while (len > 0) { |
| 603 | c = id[ofs] >> 8; |
| 604 | *s = c; |
| 605 | s++; |
| 606 | |
| 607 | c = id[ofs] & 0xff; |
| 608 | *s = c; |
| 609 | s++; |
| 610 | |
| 611 | ofs++; |
| 612 | len -= 2; |
| 613 | } |
| 614 | } |
| 615 | |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 616 | /** |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 617 | * ata_id_c_string - Convert IDENTIFY DEVICE page into C string |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 618 | * @id: IDENTIFY DEVICE results we will examine |
| 619 | * @s: string into which data is output |
| 620 | * @ofs: offset into identify device page |
| 621 | * @len: length of string to return. must be an odd number. |
| 622 | * |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 623 | * This function is identical to ata_id_string except that it |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 624 | * trims trailing spaces and terminates the resulting string with |
| 625 | * null. @len must be actual maximum length (even number) + 1. |
| 626 | * |
| 627 | * LOCKING: |
| 628 | * caller. |
| 629 | */ |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 630 | void ata_id_c_string(const u16 *id, unsigned char *s, |
| 631 | unsigned int ofs, unsigned int len) |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 632 | { |
| 633 | unsigned char *p; |
| 634 | |
| 635 | WARN_ON(!(len & 1)); |
| 636 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 637 | ata_id_string(id, s, ofs, len - 1); |
Tejun Heo | 0e949ff | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 638 | |
| 639 | p = s + strnlen(s, len - 1); |
| 640 | while (p > s && p[-1] == ' ') |
| 641 | p--; |
| 642 | *p = '\0'; |
| 643 | } |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 644 | |
Tejun Heo | 2940740 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 645 | static u64 ata_id_n_sectors(const u16 *id) |
| 646 | { |
| 647 | if (ata_id_has_lba(id)) { |
| 648 | if (ata_id_has_lba48(id)) |
| 649 | return ata_id_u64(id, 100); |
| 650 | else |
| 651 | return ata_id_u32(id, 60); |
| 652 | } else { |
| 653 | if (ata_id_current_chs_valid(id)) |
| 654 | return ata_id_u32(id, 57); |
| 655 | else |
| 656 | return id[1] * id[3] * id[6]; |
| 657 | } |
| 658 | } |
| 659 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 660 | /** |
| 661 | * ata_noop_dev_select - Select device 0/1 on ATA bus |
| 662 | * @ap: ATA channel to manipulate |
| 663 | * @device: ATA device (numbered from zero) to select |
| 664 | * |
| 665 | * This function performs no actual function. |
| 666 | * |
| 667 | * May be used as the dev_select() entry in ata_port_operations. |
| 668 | * |
| 669 | * LOCKING: |
| 670 | * caller. |
| 671 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | void ata_noop_dev_select (struct ata_port *ap, unsigned int device) |
| 673 | { |
| 674 | } |
| 675 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | /** |
| 678 | * ata_std_dev_select - Select device 0/1 on ATA bus |
| 679 | * @ap: ATA channel to manipulate |
| 680 | * @device: ATA device (numbered from zero) to select |
| 681 | * |
| 682 | * Use the method defined in the ATA specification to |
| 683 | * make either device 0, or device 1, active on the |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 684 | * ATA channel. Works with both PIO and MMIO. |
| 685 | * |
| 686 | * May be used as the dev_select() entry in ata_port_operations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | * |
| 688 | * LOCKING: |
| 689 | * caller. |
| 690 | */ |
| 691 | |
| 692 | void ata_std_dev_select (struct ata_port *ap, unsigned int device) |
| 693 | { |
| 694 | u8 tmp; |
| 695 | |
| 696 | if (device == 0) |
| 697 | tmp = ATA_DEVICE_OBS; |
| 698 | else |
| 699 | tmp = ATA_DEVICE_OBS | ATA_DEV1; |
| 700 | |
| 701 | if (ap->flags & ATA_FLAG_MMIO) { |
| 702 | writeb(tmp, (void __iomem *) ap->ioaddr.device_addr); |
| 703 | } else { |
| 704 | outb(tmp, ap->ioaddr.device_addr); |
| 705 | } |
| 706 | ata_pause(ap); /* needed; also flushes, for mmio */ |
| 707 | } |
| 708 | |
| 709 | /** |
| 710 | * ata_dev_select - Select device 0/1 on ATA bus |
| 711 | * @ap: ATA channel to manipulate |
| 712 | * @device: ATA device (numbered from zero) to select |
| 713 | * @wait: non-zero to wait for Status register BSY bit to clear |
| 714 | * @can_sleep: non-zero if context allows sleeping |
| 715 | * |
| 716 | * Use the method defined in the ATA specification to |
| 717 | * make either device 0, or device 1, active on the |
| 718 | * ATA channel. |
| 719 | * |
| 720 | * This is a high-level version of ata_std_dev_select(), |
| 721 | * which additionally provides the services of inserting |
| 722 | * the proper pauses and status polling, where needed. |
| 723 | * |
| 724 | * LOCKING: |
| 725 | * caller. |
| 726 | */ |
| 727 | |
| 728 | void ata_dev_select(struct ata_port *ap, unsigned int device, |
| 729 | unsigned int wait, unsigned int can_sleep) |
| 730 | { |
| 731 | VPRINTK("ENTER, ata%u: device %u, wait %u\n", |
| 732 | ap->id, device, wait); |
| 733 | |
| 734 | if (wait) |
| 735 | ata_wait_idle(ap); |
| 736 | |
| 737 | ap->ops->dev_select(ap, device); |
| 738 | |
| 739 | if (wait) { |
| 740 | if (can_sleep && ap->device[device].class == ATA_DEV_ATAPI) |
| 741 | msleep(150); |
| 742 | ata_wait_idle(ap); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * ata_dump_id - IDENTIFY DEVICE info debugging output |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 748 | * @id: IDENTIFY DEVICE page to dump |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | * |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 750 | * Dump selected 16-bit words from the given IDENTIFY DEVICE |
| 751 | * page. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | * |
| 753 | * LOCKING: |
| 754 | * caller. |
| 755 | */ |
| 756 | |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 757 | static inline void ata_dump_id(const u16 *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
| 759 | DPRINTK("49==0x%04x " |
| 760 | "53==0x%04x " |
| 761 | "63==0x%04x " |
| 762 | "64==0x%04x " |
| 763 | "75==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 764 | id[49], |
| 765 | id[53], |
| 766 | id[63], |
| 767 | id[64], |
| 768 | id[75]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | DPRINTK("80==0x%04x " |
| 770 | "81==0x%04x " |
| 771 | "82==0x%04x " |
| 772 | "83==0x%04x " |
| 773 | "84==0x%04x \n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 774 | id[80], |
| 775 | id[81], |
| 776 | id[82], |
| 777 | id[83], |
| 778 | id[84]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | DPRINTK("88==0x%04x " |
| 780 | "93==0x%04x\n", |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 781 | id[88], |
| 782 | id[93]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Tejun Heo | cb95d56 | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 785 | /** |
| 786 | * ata_id_xfermask - Compute xfermask from the given IDENTIFY data |
| 787 | * @id: IDENTIFY data to compute xfer mask from |
| 788 | * |
| 789 | * Compute the xfermask for this device. This is not as trivial |
| 790 | * as it seems if we must consider early devices correctly. |
| 791 | * |
| 792 | * FIXME: pre IDE drive timing (do we care ?). |
| 793 | * |
| 794 | * LOCKING: |
| 795 | * None. |
| 796 | * |
| 797 | * RETURNS: |
| 798 | * Computed xfermask |
| 799 | */ |
| 800 | static unsigned int ata_id_xfermask(const u16 *id) |
| 801 | { |
| 802 | unsigned int pio_mask, mwdma_mask, udma_mask; |
| 803 | |
| 804 | /* Usual case. Word 53 indicates word 64 is valid */ |
| 805 | if (id[ATA_ID_FIELD_VALID] & (1 << 1)) { |
| 806 | pio_mask = id[ATA_ID_PIO_MODES] & 0x03; |
| 807 | pio_mask <<= 3; |
| 808 | pio_mask |= 0x7; |
| 809 | } else { |
| 810 | /* If word 64 isn't valid then Word 51 high byte holds |
| 811 | * the PIO timing number for the maximum. Turn it into |
| 812 | * a mask. |
| 813 | */ |
| 814 | pio_mask = (2 << (id[ATA_ID_OLD_PIO_MODES] & 0xFF)) - 1 ; |
| 815 | |
| 816 | /* But wait.. there's more. Design your standards by |
| 817 | * committee and you too can get a free iordy field to |
| 818 | * process. However its the speeds not the modes that |
| 819 | * are supported... Note drivers using the timing API |
| 820 | * will get this right anyway |
| 821 | */ |
| 822 | } |
| 823 | |
| 824 | mwdma_mask = id[ATA_ID_MWDMA_MODES] & 0x07; |
| 825 | udma_mask = id[ATA_ID_UDMA_MODES] & 0xff; |
| 826 | |
| 827 | return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask); |
| 828 | } |
| 829 | |
Alan Cox | 11e29e2 | 2005-10-21 18:46:32 -0400 | [diff] [blame] | 830 | /* |
| 831 | * Compute the PIO modes available for this device. This is not as |
| 832 | * trivial as it seems if we must consider early devices correctly. |
| 833 | * |
| 834 | * FIXME: pre IDE drive timing (do we care ?). |
| 835 | */ |
| 836 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 837 | static unsigned int ata_pio_modes(const struct ata_device *adev) |
Alan Cox | 11e29e2 | 2005-10-21 18:46:32 -0400 | [diff] [blame] | 838 | { |
| 839 | u16 modes; |
| 840 | |
Alan Cox | ffa2945 | 2006-01-09 17:14:40 +0000 | [diff] [blame] | 841 | /* Usual case. Word 53 indicates word 64 is valid */ |
| 842 | if (adev->id[ATA_ID_FIELD_VALID] & (1 << 1)) { |
Alan Cox | 11e29e2 | 2005-10-21 18:46:32 -0400 | [diff] [blame] | 843 | modes = adev->id[ATA_ID_PIO_MODES] & 0x03; |
| 844 | modes <<= 3; |
| 845 | modes |= 0x7; |
| 846 | return modes; |
| 847 | } |
| 848 | |
Alan Cox | ffa2945 | 2006-01-09 17:14:40 +0000 | [diff] [blame] | 849 | /* If word 64 isn't valid then Word 51 high byte holds the PIO timing |
| 850 | number for the maximum. Turn it into a mask and return it */ |
| 851 | modes = (2 << ((adev->id[ATA_ID_OLD_PIO_MODES] >> 8) & 0xFF)) - 1 ; |
Alan Cox | 11e29e2 | 2005-10-21 18:46:32 -0400 | [diff] [blame] | 852 | return modes; |
Alan Cox | ffa2945 | 2006-01-09 17:14:40 +0000 | [diff] [blame] | 853 | /* But wait.. there's more. Design your standards by committee and |
| 854 | you too can get a free iordy field to process. However its the |
| 855 | speeds not the modes that are supported... Note drivers using the |
| 856 | timing API will get this right anyway */ |
Alan Cox | 11e29e2 | 2005-10-21 18:46:32 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 859 | /** |
| 860 | * ata_port_queue_task - Queue port_task |
| 861 | * @ap: The ata_port to queue port_task for |
| 862 | * |
| 863 | * Schedule @fn(@data) for execution after @delay jiffies using |
| 864 | * port_task. There is one port_task per port and it's the |
| 865 | * user(low level driver)'s responsibility to make sure that only |
| 866 | * one task is active at any given time. |
| 867 | * |
| 868 | * libata core layer takes care of synchronization between |
| 869 | * port_task and EH. ata_port_queue_task() may be ignored for EH |
| 870 | * synchronization. |
| 871 | * |
| 872 | * LOCKING: |
| 873 | * Inherited from caller. |
| 874 | */ |
| 875 | void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), void *data, |
| 876 | unsigned long delay) |
| 877 | { |
| 878 | int rc; |
| 879 | |
Tejun Heo | 2e755f6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 880 | if (ap->flags & ATA_FLAG_FLUSH_PORT_TASK) |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 881 | return; |
| 882 | |
| 883 | PREPARE_WORK(&ap->port_task, fn, data); |
| 884 | |
| 885 | if (!delay) |
| 886 | rc = queue_work(ata_wq, &ap->port_task); |
| 887 | else |
| 888 | rc = queue_delayed_work(ata_wq, &ap->port_task, delay); |
| 889 | |
| 890 | /* rc == 0 means that another user is using port task */ |
| 891 | WARN_ON(rc == 0); |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * ata_port_flush_task - Flush port_task |
| 896 | * @ap: The ata_port to flush port_task for |
| 897 | * |
| 898 | * After this function completes, port_task is guranteed not to |
| 899 | * be running or scheduled. |
| 900 | * |
| 901 | * LOCKING: |
| 902 | * Kernel thread context (may sleep) |
| 903 | */ |
| 904 | void ata_port_flush_task(struct ata_port *ap) |
| 905 | { |
| 906 | unsigned long flags; |
| 907 | |
| 908 | DPRINTK("ENTER\n"); |
| 909 | |
| 910 | spin_lock_irqsave(&ap->host_set->lock, flags); |
Tejun Heo | 2e755f6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 911 | ap->flags |= ATA_FLAG_FLUSH_PORT_TASK; |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 912 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
| 913 | |
| 914 | DPRINTK("flush #1\n"); |
| 915 | flush_workqueue(ata_wq); |
| 916 | |
| 917 | /* |
| 918 | * At this point, if a task is running, it's guaranteed to see |
| 919 | * the FLUSH flag; thus, it will never queue pio tasks again. |
| 920 | * Cancel and flush. |
| 921 | */ |
| 922 | if (!cancel_delayed_work(&ap->port_task)) { |
| 923 | DPRINTK("flush #2\n"); |
| 924 | flush_workqueue(ata_wq); |
| 925 | } |
| 926 | |
| 927 | spin_lock_irqsave(&ap->host_set->lock, flags); |
Tejun Heo | 2e755f6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 928 | ap->flags &= ~ATA_FLAG_FLUSH_PORT_TASK; |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 929 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
| 930 | |
| 931 | DPRINTK("EXIT\n"); |
| 932 | } |
| 933 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 934 | void ata_qc_complete_internal(struct ata_queued_cmd *qc) |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 935 | { |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 936 | struct completion *waiting = qc->private_data; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 937 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 938 | qc->ap->ops->tf_read(qc->ap, &qc->tf); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 939 | complete(waiting); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /** |
| 943 | * ata_exec_internal - execute libata internal command |
| 944 | * @ap: Port to which the command is sent |
| 945 | * @dev: Device to which the command is sent |
| 946 | * @tf: Taskfile registers for the command and the result |
| 947 | * @dma_dir: Data tranfer direction of the command |
| 948 | * @buf: Data buffer of the command |
| 949 | * @buflen: Length of data buffer |
| 950 | * |
| 951 | * Executes libata internal command with timeout. @tf contains |
| 952 | * command on entry and result on return. Timeout and error |
| 953 | * conditions are reported via return value. No recovery action |
| 954 | * is taken after a command times out. It's caller's duty to |
| 955 | * clean up after timeout. |
| 956 | * |
| 957 | * LOCKING: |
| 958 | * None. Should be called with kernel context, might sleep. |
| 959 | */ |
| 960 | |
| 961 | static unsigned |
| 962 | ata_exec_internal(struct ata_port *ap, struct ata_device *dev, |
| 963 | struct ata_taskfile *tf, |
| 964 | int dma_dir, void *buf, unsigned int buflen) |
| 965 | { |
| 966 | u8 command = tf->command; |
| 967 | struct ata_queued_cmd *qc; |
| 968 | DECLARE_COMPLETION(wait); |
| 969 | unsigned long flags; |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 970 | unsigned int err_mask; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 971 | |
| 972 | spin_lock_irqsave(&ap->host_set->lock, flags); |
| 973 | |
| 974 | qc = ata_qc_new_init(ap, dev); |
| 975 | BUG_ON(qc == NULL); |
| 976 | |
| 977 | qc->tf = *tf; |
| 978 | qc->dma_dir = dma_dir; |
| 979 | if (dma_dir != DMA_NONE) { |
| 980 | ata_sg_init_one(qc, buf, buflen); |
| 981 | qc->nsect = buflen / ATA_SECT_SIZE; |
| 982 | } |
| 983 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 984 | qc->private_data = &wait; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 985 | qc->complete_fn = ata_qc_complete_internal; |
| 986 | |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 987 | qc->err_mask = ata_qc_issue(qc); |
| 988 | if (qc->err_mask) |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 989 | ata_qc_complete(qc); |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 990 | |
| 991 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
| 992 | |
| 993 | if (!wait_for_completion_timeout(&wait, ATA_TMOUT_INTERNAL)) { |
| 994 | spin_lock_irqsave(&ap->host_set->lock, flags); |
| 995 | |
| 996 | /* We're racing with irq here. If we lose, the |
| 997 | * following test prevents us from completing the qc |
| 998 | * again. If completion irq occurs after here but |
| 999 | * before the caller cleans up, it will result in a |
| 1000 | * spurious interrupt. We can live with that. |
| 1001 | */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1002 | if (qc->flags & ATA_QCFLAG_ACTIVE) { |
Tejun Heo | 11a56d2 | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1003 | qc->err_mask = AC_ERR_TIMEOUT; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1004 | ata_qc_complete(qc); |
| 1005 | printk(KERN_WARNING "ata%u: qc timeout (cmd 0x%x)\n", |
| 1006 | ap->id, command); |
| 1007 | } |
| 1008 | |
| 1009 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
| 1010 | } |
| 1011 | |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 1012 | *tf = qc->tf; |
| 1013 | err_mask = qc->err_mask; |
| 1014 | |
| 1015 | ata_qc_free(qc); |
| 1016 | |
| 1017 | return err_mask; |
Tejun Heo | a2a7a66 | 2005-12-13 14:48:31 +0900 | [diff] [blame] | 1018 | } |
| 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | /** |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 1021 | * ata_pio_need_iordy - check if iordy needed |
| 1022 | * @adev: ATA device |
| 1023 | * |
| 1024 | * Check if the current speed of the device requires IORDY. Used |
| 1025 | * by various controllers for chip configuration. |
| 1026 | */ |
| 1027 | |
| 1028 | unsigned int ata_pio_need_iordy(const struct ata_device *adev) |
| 1029 | { |
| 1030 | int pio; |
| 1031 | int speed = adev->pio_mode - XFER_PIO_0; |
| 1032 | |
| 1033 | if (speed < 2) |
| 1034 | return 0; |
| 1035 | if (speed > 2) |
| 1036 | return 1; |
| 1037 | |
| 1038 | /* If we have no drive specific rule, then PIO 2 is non IORDY */ |
| 1039 | |
| 1040 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ |
| 1041 | pio = adev->id[ATA_ID_EIDE_PIO]; |
| 1042 | /* Is the speed faster than the drive allows non IORDY ? */ |
| 1043 | if (pio) { |
| 1044 | /* This is cycle times not frequency - watch the logic! */ |
| 1045 | if (pio > 240) /* PIO2 is 240nS per cycle */ |
| 1046 | return 1; |
| 1047 | return 0; |
| 1048 | } |
| 1049 | } |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
| 1053 | /** |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1054 | * ata_dev_read_id - Read ID data from the specified device |
| 1055 | * @ap: port on which target device resides |
| 1056 | * @dev: target device |
| 1057 | * @p_class: pointer to class of the target device (may be changed) |
| 1058 | * @post_reset: is this read ID post-reset? |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1059 | * @p_id: read IDENTIFY page (newly allocated) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1060 | * |
| 1061 | * Read ID data from the specified device. ATA_CMD_ID_ATA is |
| 1062 | * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI |
| 1063 | * devices. This function also takes care of EDD signature |
| 1064 | * misreporting (to be removed once EDD support is gone) and |
| 1065 | * issues ATA_CMD_INIT_DEV_PARAMS for pre-ATA4 drives. |
| 1066 | * |
| 1067 | * LOCKING: |
| 1068 | * Kernel thread context (may sleep) |
| 1069 | * |
| 1070 | * RETURNS: |
| 1071 | * 0 on success, -errno otherwise. |
| 1072 | */ |
| 1073 | static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev, |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1074 | unsigned int *p_class, int post_reset, u16 **p_id) |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1075 | { |
| 1076 | unsigned int class = *p_class; |
| 1077 | unsigned int using_edd; |
| 1078 | struct ata_taskfile tf; |
| 1079 | unsigned int err_mask = 0; |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1080 | u16 *id; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1081 | const char *reason; |
| 1082 | int rc; |
| 1083 | |
| 1084 | DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno); |
| 1085 | |
| 1086 | if (ap->ops->probe_reset || |
| 1087 | ap->flags & (ATA_FLAG_SRST | ATA_FLAG_SATA_RESET)) |
| 1088 | using_edd = 0; |
| 1089 | else |
| 1090 | using_edd = 1; |
| 1091 | |
| 1092 | ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */ |
| 1093 | |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1094 | id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL); |
| 1095 | if (id == NULL) { |
| 1096 | rc = -ENOMEM; |
| 1097 | reason = "out of memory"; |
| 1098 | goto err_out; |
| 1099 | } |
| 1100 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1101 | retry: |
| 1102 | ata_tf_init(ap, &tf, dev->devno); |
| 1103 | |
| 1104 | switch (class) { |
| 1105 | case ATA_DEV_ATA: |
| 1106 | tf.command = ATA_CMD_ID_ATA; |
| 1107 | break; |
| 1108 | case ATA_DEV_ATAPI: |
| 1109 | tf.command = ATA_CMD_ID_ATAPI; |
| 1110 | break; |
| 1111 | default: |
| 1112 | rc = -ENODEV; |
| 1113 | reason = "unsupported class"; |
| 1114 | goto err_out; |
| 1115 | } |
| 1116 | |
| 1117 | tf.protocol = ATA_PROT_PIO; |
| 1118 | |
| 1119 | err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, |
| 1120 | id, sizeof(id[0]) * ATA_ID_WORDS); |
| 1121 | |
| 1122 | if (err_mask) { |
| 1123 | rc = -EIO; |
| 1124 | reason = "I/O error"; |
| 1125 | |
| 1126 | if (err_mask & ~AC_ERR_DEV) |
| 1127 | goto err_out; |
| 1128 | |
| 1129 | /* |
| 1130 | * arg! EDD works for all test cases, but seems to return |
| 1131 | * the ATA signature for some ATAPI devices. Until the |
| 1132 | * reason for this is found and fixed, we fix up the mess |
| 1133 | * here. If IDENTIFY DEVICE returns command aborted |
| 1134 | * (as ATAPI devices do), then we issue an |
| 1135 | * IDENTIFY PACKET DEVICE. |
| 1136 | * |
| 1137 | * ATA software reset (SRST, the default) does not appear |
| 1138 | * to have this problem. |
| 1139 | */ |
| 1140 | if ((using_edd) && (class == ATA_DEV_ATA)) { |
| 1141 | u8 err = tf.feature; |
| 1142 | if (err & ATA_ABORTED) { |
| 1143 | class = ATA_DEV_ATAPI; |
| 1144 | goto retry; |
| 1145 | } |
| 1146 | } |
| 1147 | goto err_out; |
| 1148 | } |
| 1149 | |
| 1150 | swap_buf_le16(id, ATA_ID_WORDS); |
| 1151 | |
| 1152 | /* print device capabilities */ |
| 1153 | printk(KERN_DEBUG "ata%u: dev %u cfg " |
| 1154 | "49:%04x 82:%04x 83:%04x 84:%04x 85:%04x 86:%04x 87:%04x 88:%04x\n", |
| 1155 | ap->id, dev->devno, |
| 1156 | id[49], id[82], id[83], id[84], id[85], id[86], id[87], id[88]); |
| 1157 | |
| 1158 | /* sanity check */ |
| 1159 | if ((class == ATA_DEV_ATA) != ata_id_is_ata(id)) { |
| 1160 | rc = -EINVAL; |
| 1161 | reason = "device reports illegal type"; |
| 1162 | goto err_out; |
| 1163 | } |
| 1164 | |
| 1165 | if (post_reset && class == ATA_DEV_ATA) { |
| 1166 | /* |
| 1167 | * The exact sequence expected by certain pre-ATA4 drives is: |
| 1168 | * SRST RESET |
| 1169 | * IDENTIFY |
| 1170 | * INITIALIZE DEVICE PARAMETERS |
| 1171 | * anything else.. |
| 1172 | * Some drives were very specific about that exact sequence. |
| 1173 | */ |
| 1174 | if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) { |
| 1175 | err_mask = ata_dev_init_params(ap, dev); |
| 1176 | if (err_mask) { |
| 1177 | rc = -EIO; |
| 1178 | reason = "INIT_DEV_PARAMS failed"; |
| 1179 | goto err_out; |
| 1180 | } |
| 1181 | |
| 1182 | /* current CHS translation info (id[53-58]) might be |
| 1183 | * changed. reread the identify device info. |
| 1184 | */ |
| 1185 | post_reset = 0; |
| 1186 | goto retry; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | *p_class = class; |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1191 | *p_id = id; |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1192 | return 0; |
| 1193 | |
| 1194 | err_out: |
| 1195 | printk(KERN_WARNING "ata%u: dev %u failed to IDENTIFY (%s)\n", |
| 1196 | ap->id, dev->devno, reason); |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1197 | kfree(id); |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1198 | return rc; |
| 1199 | } |
| 1200 | |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1201 | static inline u8 ata_dev_knobble(const struct ata_port *ap, |
| 1202 | struct ata_device *dev) |
| 1203 | { |
| 1204 | return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); |
| 1205 | } |
| 1206 | |
Tejun Heo | 49016ac | 2006-02-21 02:12:11 +0900 | [diff] [blame] | 1207 | /** |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1208 | * ata_dev_configure - Configure the specified ATA/ATAPI device |
| 1209 | * @ap: Port on which target device resides |
| 1210 | * @dev: Target device to configure |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1211 | * @print_info: Enable device info printout |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | * |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1213 | * Configure @dev according to @dev->id. Generic and low-level |
| 1214 | * driver specific fixups are also applied. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | * |
| 1216 | * LOCKING: |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1217 | * Kernel thread context (may sleep) |
| 1218 | * |
| 1219 | * RETURNS: |
| 1220 | * 0 on success, -errno otherwise |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | */ |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1222 | static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev, |
| 1223 | int print_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | { |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1225 | unsigned int xfer_mask; |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 1226 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | if (!ata_dev_present(dev)) { |
| 1229 | DPRINTK("ENTER/EXIT (host %u, dev %u) -- nodev\n", |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1230 | ap->id, dev->devno); |
| 1231 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1234 | DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Tejun Heo | 208a993 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1236 | /* initialize to-be-configured parameters */ |
| 1237 | dev->flags = 0; |
| 1238 | dev->max_sectors = 0; |
| 1239 | dev->cdb_len = 0; |
| 1240 | dev->n_sectors = 0; |
| 1241 | dev->cylinders = 0; |
| 1242 | dev->heads = 0; |
| 1243 | dev->sectors = 0; |
| 1244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | /* |
| 1246 | * common ATA, ATAPI feature tests |
| 1247 | */ |
| 1248 | |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1249 | /* we require DMA support (bits 8 of word 49) */ |
| 1250 | if (!ata_id_has_dma(dev->id)) { |
| 1251 | printk(KERN_DEBUG "ata%u: no dma\n", ap->id); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1252 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | goto err_out_nosup; |
| 1254 | } |
| 1255 | |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1256 | /* find max transfer mode; for printk only */ |
| 1257 | xfer_mask = ata_id_xfermask(dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Tejun Heo | 0bd3300 | 2006-02-12 22:47:05 +0900 | [diff] [blame] | 1259 | ata_dump_id(dev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | /* ATA-specific feature tests */ |
| 1262 | if (dev->class == ATA_DEV_ATA) { |
Tejun Heo | 2940740 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 1263 | dev->n_sectors = ata_id_n_sectors(dev->id); |
| 1264 | |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1265 | if (ata_id_has_lba(dev->id)) { |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1266 | const char *lba_desc; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1267 | |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1268 | lba_desc = "LBA"; |
| 1269 | dev->flags |= ATA_DFLAG_LBA; |
| 1270 | if (ata_id_has_lba48(dev->id)) { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1271 | dev->flags |= ATA_DFLAG_LBA48; |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1272 | lba_desc = "LBA48"; |
| 1273 | } |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1274 | |
| 1275 | /* print device info to dmesg */ |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1276 | if (print_info) |
| 1277 | printk(KERN_INFO "ata%u: dev %u ATA-%d, " |
| 1278 | "max %s, %Lu sectors: %s\n", |
| 1279 | ap->id, dev->devno, |
| 1280 | ata_id_major_version(dev->id), |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1281 | ata_mode_string(xfer_mask), |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1282 | (unsigned long long)dev->n_sectors, |
| 1283 | lba_desc); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1284 | } else { |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1285 | /* CHS */ |
| 1286 | |
| 1287 | /* Default translation */ |
| 1288 | dev->cylinders = dev->id[1]; |
| 1289 | dev->heads = dev->id[3]; |
| 1290 | dev->sectors = dev->id[6]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1291 | |
| 1292 | if (ata_id_current_chs_valid(dev->id)) { |
| 1293 | /* Current CHS translation is valid. */ |
| 1294 | dev->cylinders = dev->id[54]; |
| 1295 | dev->heads = dev->id[55]; |
| 1296 | dev->sectors = dev->id[56]; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /* print device info to dmesg */ |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1300 | if (print_info) |
| 1301 | printk(KERN_INFO "ata%u: dev %u ATA-%d, " |
| 1302 | "max %s, %Lu sectors: CHS %u/%u/%u\n", |
| 1303 | ap->id, dev->devno, |
| 1304 | ata_id_major_version(dev->id), |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1305 | ata_mode_string(xfer_mask), |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1306 | (unsigned long long)dev->n_sectors, |
| 1307 | dev->cylinders, dev->heads, dev->sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 1310 | dev->cdb_len = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | /* ATAPI-specific feature tests */ |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 1314 | else if (dev->class == ATA_DEV_ATAPI) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | rc = atapi_cdb_len(dev->id); |
| 1316 | if ((rc < 12) || (rc > ATAPI_CDB_LEN)) { |
| 1317 | printk(KERN_WARNING "ata%u: unsupported CDB len\n", ap->id); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1318 | rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | goto err_out_nosup; |
| 1320 | } |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 1321 | dev->cdb_len = (unsigned int) rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
| 1323 | /* print device info to dmesg */ |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1324 | if (print_info) |
| 1325 | printk(KERN_INFO "ata%u: dev %u ATAPI, max %s\n", |
Tejun Heo | ff8854b | 2006-03-06 04:31:56 +0900 | [diff] [blame] | 1326 | ap->id, dev->devno, ata_mode_string(xfer_mask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Tejun Heo | 6e7846e | 2006-02-12 23:32:58 +0900 | [diff] [blame] | 1329 | ap->host->max_cmd_len = 0; |
| 1330 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 1331 | ap->host->max_cmd_len = max_t(unsigned int, |
| 1332 | ap->host->max_cmd_len, |
| 1333 | ap->device[i].cdb_len); |
| 1334 | |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1335 | /* limit bridge transfers to udma5, 200 sectors */ |
| 1336 | if (ata_dev_knobble(ap, dev)) { |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1337 | if (print_info) |
| 1338 | printk(KERN_INFO "ata%u(%u): applying bridge limits\n", |
| 1339 | ap->id, dev->devno); |
Tejun Heo | 4b2f3ed | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1340 | ap->udma_mask &= ATA_UDMA5; |
| 1341 | dev->max_sectors = ATA_MAX_SECTORS; |
| 1342 | } |
| 1343 | |
| 1344 | if (ap->ops->dev_config) |
| 1345 | ap->ops->dev_config(ap, dev); |
| 1346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | DPRINTK("EXIT, drv_stat = 0x%x\n", ata_chk_status(ap)); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
| 1350 | err_out_nosup: |
| 1351 | printk(KERN_WARNING "ata%u: dev %u not supported, ignoring\n", |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1352 | ap->id, dev->devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | DPRINTK("EXIT, err\n"); |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1354 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * ata_bus_probe - Reset and probe ATA bus |
| 1359 | * @ap: Bus to probe |
| 1360 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1361 | * Master ATA bus probing function. Initiates a hardware-dependent |
| 1362 | * bus reset, then attempts to identify any devices found on |
| 1363 | * the bus. |
| 1364 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1366 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | * |
| 1368 | * RETURNS: |
| 1369 | * Zero on success, non-zero on error. |
| 1370 | */ |
| 1371 | |
| 1372 | static int ata_bus_probe(struct ata_port *ap) |
| 1373 | { |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1374 | unsigned int classes[ATA_MAX_DEVICES]; |
| 1375 | unsigned int i, rc, found = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1377 | ata_port_probe(ap); |
| 1378 | |
| 1379 | /* reset */ |
Tejun Heo | c19ba8a | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 1380 | if (ap->ops->probe_reset) { |
Tejun Heo | c19ba8a | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 1381 | rc = ap->ops->probe_reset(ap, classes); |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1382 | if (rc) { |
| 1383 | printk("ata%u: reset failed (errno=%d)\n", ap->id, rc); |
| 1384 | return rc; |
Tejun Heo | c19ba8a | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 1385 | } |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1386 | |
| 1387 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 1388 | if (classes[i] == ATA_DEV_UNKNOWN) |
| 1389 | classes[i] = ATA_DEV_NONE; |
| 1390 | } else { |
Tejun Heo | c19ba8a | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 1391 | ap->ops->phy_reset(ap); |
| 1392 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1393 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 1394 | if (!(ap->flags & ATA_FLAG_PORT_DISABLED)) |
| 1395 | classes[i] = ap->device[i].class; |
| 1396 | else |
| 1397 | ap->device[i].class = ATA_DEV_UNKNOWN; |
| 1398 | } |
| 1399 | ata_port_probe(ap); |
| 1400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1402 | /* read IDENTIFY page and configure devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1404 | struct ata_device *dev = &ap->device[i]; |
| 1405 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1406 | dev->class = classes[i]; |
| 1407 | |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1408 | if (!ata_dev_present(dev)) |
| 1409 | continue; |
| 1410 | |
| 1411 | WARN_ON(dev->id != NULL); |
| 1412 | if (ata_dev_read_id(ap, dev, &dev->class, 1, &dev->id)) { |
| 1413 | dev->class = ATA_DEV_NONE; |
| 1414 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | } |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1416 | |
Tejun Heo | 4c2d721 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1417 | if (ata_dev_configure(ap, dev, 1)) { |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1418 | dev->class++; /* disable device */ |
| 1419 | continue; |
| 1420 | } |
| 1421 | |
Tejun Heo | ffeae41 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 1422 | found = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Tejun Heo | 28ca5c5 | 2006-03-01 16:09:36 +0900 | [diff] [blame] | 1425 | if (!found) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | goto err_out_disable; |
| 1427 | |
| 1428 | ata_set_mode(ap); |
| 1429 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
| 1430 | goto err_out_disable; |
| 1431 | |
| 1432 | return 0; |
| 1433 | |
| 1434 | err_out_disable: |
| 1435 | ap->ops->port_disable(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | return -1; |
| 1437 | } |
| 1438 | |
| 1439 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1440 | * ata_port_probe - Mark port as enabled |
| 1441 | * @ap: Port for which we indicate enablement |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1443 | * Modify @ap data structure such that the system |
| 1444 | * thinks that the entire port is enabled. |
| 1445 | * |
| 1446 | * LOCKING: host_set lock, or some other form of |
| 1447 | * serialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | */ |
| 1449 | |
| 1450 | void ata_port_probe(struct ata_port *ap) |
| 1451 | { |
| 1452 | ap->flags &= ~ATA_FLAG_PORT_DISABLED; |
| 1453 | } |
| 1454 | |
| 1455 | /** |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 1456 | * sata_print_link_status - Print SATA link status |
| 1457 | * @ap: SATA port to printk link status about |
| 1458 | * |
| 1459 | * This function prints link speed and status of a SATA link. |
| 1460 | * |
| 1461 | * LOCKING: |
| 1462 | * None. |
| 1463 | */ |
| 1464 | static void sata_print_link_status(struct ata_port *ap) |
| 1465 | { |
| 1466 | u32 sstatus, tmp; |
| 1467 | const char *speed; |
| 1468 | |
| 1469 | if (!ap->ops->scr_read) |
| 1470 | return; |
| 1471 | |
| 1472 | sstatus = scr_read(ap, SCR_STATUS); |
| 1473 | |
| 1474 | if (sata_dev_present(ap)) { |
| 1475 | tmp = (sstatus >> 4) & 0xf; |
| 1476 | if (tmp & (1 << 0)) |
| 1477 | speed = "1.5"; |
| 1478 | else if (tmp & (1 << 1)) |
| 1479 | speed = "3.0"; |
| 1480 | else |
| 1481 | speed = "<unknown>"; |
| 1482 | printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n", |
| 1483 | ap->id, speed, sstatus); |
| 1484 | } else { |
| 1485 | printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n", |
| 1486 | ap->id, sstatus); |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1491 | * __sata_phy_reset - Wake/reset a low-level SATA PHY |
| 1492 | * @ap: SATA port associated with target SATA PHY. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1494 | * This function issues commands to standard SATA Sxxx |
| 1495 | * PHY registers, to wake up the phy (and device), and |
| 1496 | * clear any reset condition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | * |
| 1498 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1499 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | * |
| 1501 | */ |
| 1502 | void __sata_phy_reset(struct ata_port *ap) |
| 1503 | { |
| 1504 | u32 sstatus; |
| 1505 | unsigned long timeout = jiffies + (HZ * 5); |
| 1506 | |
| 1507 | if (ap->flags & ATA_FLAG_SATA_RESET) { |
Brett Russ | cdcca89e | 2005-03-28 15:10:27 -0500 | [diff] [blame] | 1508 | /* issue phy wake/reset */ |
| 1509 | scr_write_flush(ap, SCR_CONTROL, 0x301); |
Tejun Heo | 62ba284 | 2005-06-26 23:27:19 +0900 | [diff] [blame] | 1510 | /* Couldn't find anything in SATA I/II specs, but |
| 1511 | * AHCI-1.1 10.4.2 says at least 1 ms. */ |
| 1512 | mdelay(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | } |
Brett Russ | cdcca89e | 2005-03-28 15:10:27 -0500 | [diff] [blame] | 1514 | scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | |
| 1516 | /* wait for phy to become ready, if necessary */ |
| 1517 | do { |
| 1518 | msleep(200); |
| 1519 | sstatus = scr_read(ap, SCR_STATUS); |
| 1520 | if ((sstatus & 0xf) != 1) |
| 1521 | break; |
| 1522 | } while (time_before(jiffies, timeout)); |
| 1523 | |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 1524 | /* print link status */ |
| 1525 | sata_print_link_status(ap); |
Jeff Garzik | 656563e | 2005-11-20 03:36:45 -0500 | [diff] [blame] | 1526 | |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 1527 | /* TODO: phy layer with polling, timeouts, etc. */ |
| 1528 | if (sata_dev_present(ap)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | ata_port_probe(ap); |
Tejun Heo | 3be680b | 2005-12-19 22:35:02 +0900 | [diff] [blame] | 1530 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | ata_port_disable(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
| 1533 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
| 1534 | return; |
| 1535 | |
| 1536 | if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { |
| 1537 | ata_port_disable(ap); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
| 1541 | ap->cbl = ATA_CBL_SATA; |
| 1542 | } |
| 1543 | |
| 1544 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1545 | * sata_phy_reset - Reset SATA bus. |
| 1546 | * @ap: SATA port associated with target SATA PHY. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1548 | * This function resets the SATA bus, and then probes |
| 1549 | * the bus for devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | * |
| 1551 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1552 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | * |
| 1554 | */ |
| 1555 | void sata_phy_reset(struct ata_port *ap) |
| 1556 | { |
| 1557 | __sata_phy_reset(ap); |
| 1558 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
| 1559 | return; |
| 1560 | ata_bus_reset(ap); |
| 1561 | } |
| 1562 | |
| 1563 | /** |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1564 | * ata_port_disable - Disable port. |
| 1565 | * @ap: Port to be disabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1567 | * Modify @ap data structure such that the system |
| 1568 | * thinks that the entire port is disabled, and should |
| 1569 | * never attempt to probe or communicate with devices |
| 1570 | * on this port. |
| 1571 | * |
| 1572 | * LOCKING: host_set lock, or some other form of |
| 1573 | * serialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | */ |
| 1575 | |
| 1576 | void ata_port_disable(struct ata_port *ap) |
| 1577 | { |
| 1578 | ap->device[0].class = ATA_DEV_NONE; |
| 1579 | ap->device[1].class = ATA_DEV_NONE; |
| 1580 | ap->flags |= ATA_FLAG_PORT_DISABLED; |
| 1581 | } |
| 1582 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1583 | /* |
| 1584 | * This mode timing computation functionality is ported over from |
| 1585 | * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik |
| 1586 | */ |
| 1587 | /* |
| 1588 | * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). |
| 1589 | * These were taken from ATA/ATAPI-6 standard, rev 0a, except |
| 1590 | * for PIO 5, which is a nonstandard extension and UDMA6, which |
| 1591 | * is currently supported only by Maxtor drives. |
| 1592 | */ |
| 1593 | |
| 1594 | static const struct ata_timing ata_timing[] = { |
| 1595 | |
| 1596 | { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 }, |
| 1597 | { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 }, |
| 1598 | { XFER_UDMA_4, 0, 0, 0, 0, 0, 0, 0, 30 }, |
| 1599 | { XFER_UDMA_3, 0, 0, 0, 0, 0, 0, 0, 45 }, |
| 1600 | |
| 1601 | { XFER_UDMA_2, 0, 0, 0, 0, 0, 0, 0, 60 }, |
| 1602 | { XFER_UDMA_1, 0, 0, 0, 0, 0, 0, 0, 80 }, |
| 1603 | { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, |
| 1604 | |
| 1605 | /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ |
| 1606 | |
| 1607 | { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, |
| 1608 | { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, |
| 1609 | { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, |
| 1610 | |
| 1611 | { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, |
| 1612 | { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, |
| 1613 | { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, |
| 1614 | |
| 1615 | /* { XFER_PIO_5, 20, 50, 30, 100, 50, 30, 100, 0 }, */ |
| 1616 | { XFER_PIO_4, 25, 70, 25, 120, 70, 25, 120, 0 }, |
| 1617 | { XFER_PIO_3, 30, 80, 70, 180, 80, 70, 180, 0 }, |
| 1618 | |
| 1619 | { XFER_PIO_2, 30, 290, 40, 330, 100, 90, 240, 0 }, |
| 1620 | { XFER_PIO_1, 50, 290, 93, 383, 125, 100, 383, 0 }, |
| 1621 | { XFER_PIO_0, 70, 290, 240, 600, 165, 150, 600, 0 }, |
| 1622 | |
| 1623 | /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */ |
| 1624 | |
| 1625 | { 0xFF } |
| 1626 | }; |
| 1627 | |
| 1628 | #define ENOUGH(v,unit) (((v)-1)/(unit)+1) |
| 1629 | #define EZ(v,unit) ((v)?ENOUGH(v,unit):0) |
| 1630 | |
| 1631 | static void ata_timing_quantize(const struct ata_timing *t, struct ata_timing *q, int T, int UT) |
| 1632 | { |
| 1633 | q->setup = EZ(t->setup * 1000, T); |
| 1634 | q->act8b = EZ(t->act8b * 1000, T); |
| 1635 | q->rec8b = EZ(t->rec8b * 1000, T); |
| 1636 | q->cyc8b = EZ(t->cyc8b * 1000, T); |
| 1637 | q->active = EZ(t->active * 1000, T); |
| 1638 | q->recover = EZ(t->recover * 1000, T); |
| 1639 | q->cycle = EZ(t->cycle * 1000, T); |
| 1640 | q->udma = EZ(t->udma * 1000, UT); |
| 1641 | } |
| 1642 | |
| 1643 | void ata_timing_merge(const struct ata_timing *a, const struct ata_timing *b, |
| 1644 | struct ata_timing *m, unsigned int what) |
| 1645 | { |
| 1646 | if (what & ATA_TIMING_SETUP ) m->setup = max(a->setup, b->setup); |
| 1647 | if (what & ATA_TIMING_ACT8B ) m->act8b = max(a->act8b, b->act8b); |
| 1648 | if (what & ATA_TIMING_REC8B ) m->rec8b = max(a->rec8b, b->rec8b); |
| 1649 | if (what & ATA_TIMING_CYC8B ) m->cyc8b = max(a->cyc8b, b->cyc8b); |
| 1650 | if (what & ATA_TIMING_ACTIVE ) m->active = max(a->active, b->active); |
| 1651 | if (what & ATA_TIMING_RECOVER) m->recover = max(a->recover, b->recover); |
| 1652 | if (what & ATA_TIMING_CYCLE ) m->cycle = max(a->cycle, b->cycle); |
| 1653 | if (what & ATA_TIMING_UDMA ) m->udma = max(a->udma, b->udma); |
| 1654 | } |
| 1655 | |
| 1656 | static const struct ata_timing* ata_timing_find_mode(unsigned short speed) |
| 1657 | { |
| 1658 | const struct ata_timing *t; |
| 1659 | |
| 1660 | for (t = ata_timing; t->mode != speed; t++) |
Alan Cox | 9119075 | 2005-10-26 12:17:46 -0400 | [diff] [blame] | 1661 | if (t->mode == 0xFF) |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1662 | return NULL; |
| 1663 | return t; |
| 1664 | } |
| 1665 | |
| 1666 | int ata_timing_compute(struct ata_device *adev, unsigned short speed, |
| 1667 | struct ata_timing *t, int T, int UT) |
| 1668 | { |
| 1669 | const struct ata_timing *s; |
| 1670 | struct ata_timing p; |
| 1671 | |
| 1672 | /* |
| 1673 | * Find the mode. |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 1674 | */ |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1675 | |
| 1676 | if (!(s = ata_timing_find_mode(speed))) |
| 1677 | return -EINVAL; |
| 1678 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 1679 | memcpy(t, s, sizeof(*s)); |
| 1680 | |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1681 | /* |
| 1682 | * If the drive is an EIDE drive, it can tell us it needs extended |
| 1683 | * PIO/MW_DMA cycle timing. |
| 1684 | */ |
| 1685 | |
| 1686 | if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */ |
| 1687 | memset(&p, 0, sizeof(p)); |
| 1688 | if(speed >= XFER_PIO_0 && speed <= XFER_SW_DMA_0) { |
| 1689 | if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO]; |
| 1690 | else p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO_IORDY]; |
| 1691 | } else if(speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) { |
| 1692 | p.cycle = adev->id[ATA_ID_EIDE_DMA_MIN]; |
| 1693 | } |
| 1694 | ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B); |
| 1695 | } |
| 1696 | |
| 1697 | /* |
| 1698 | * Convert the timing to bus clock counts. |
| 1699 | */ |
| 1700 | |
Albert Lee | 75b1f2f | 2005-11-16 17:06:18 +0800 | [diff] [blame] | 1701 | ata_timing_quantize(t, t, T, UT); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1702 | |
| 1703 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 1704 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, |
| 1705 | * S.M.A.R.T * and some other commands. We have to ensure that the |
| 1706 | * DMA cycle timing is slower/equal than the fastest PIO timing. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1707 | */ |
| 1708 | |
| 1709 | if (speed > XFER_PIO_4) { |
| 1710 | ata_timing_compute(adev, adev->pio_mode, &p, T, UT); |
| 1711 | ata_timing_merge(&p, t, t, ATA_TIMING_ALL); |
| 1712 | } |
| 1713 | |
| 1714 | /* |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 1715 | * Lengthen active & recovery time so that cycle time is correct. |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 1716 | */ |
| 1717 | |
| 1718 | if (t->act8b + t->rec8b < t->cyc8b) { |
| 1719 | t->act8b += (t->cyc8b - (t->act8b + t->rec8b)) / 2; |
| 1720 | t->rec8b = t->cyc8b - t->act8b; |
| 1721 | } |
| 1722 | |
| 1723 | if (t->active + t->recover < t->cycle) { |
| 1724 | t->active += (t->cycle - (t->active + t->recover)) / 2; |
| 1725 | t->recover = t->cycle - t->active; |
| 1726 | } |
| 1727 | |
| 1728 | return 0; |
| 1729 | } |
| 1730 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 1731 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | unsigned int shift; |
| 1733 | u8 base; |
| 1734 | } xfer_mode_classes[] = { |
| 1735 | { ATA_SHIFT_UDMA, XFER_UDMA_0 }, |
| 1736 | { ATA_SHIFT_MWDMA, XFER_MW_DMA_0 }, |
| 1737 | { ATA_SHIFT_PIO, XFER_PIO_0 }, |
| 1738 | }; |
| 1739 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1740 | static u8 base_from_shift(unsigned int shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | { |
| 1742 | int i; |
| 1743 | |
| 1744 | for (i = 0; i < ARRAY_SIZE(xfer_mode_classes); i++) |
| 1745 | if (xfer_mode_classes[i].shift == shift) |
| 1746 | return xfer_mode_classes[i].base; |
| 1747 | |
| 1748 | return 0xff; |
| 1749 | } |
| 1750 | |
| 1751 | static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) |
| 1752 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | if (!ata_dev_present(dev) || (ap->flags & ATA_FLAG_PORT_DISABLED)) |
| 1754 | return; |
| 1755 | |
| 1756 | if (dev->xfer_shift == ATA_SHIFT_PIO) |
| 1757 | dev->flags |= ATA_DFLAG_PIO; |
| 1758 | |
| 1759 | ata_dev_set_xfermode(ap, dev); |
| 1760 | |
Tejun Heo | 48a8a14 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 1761 | if (ata_dev_revalidate(ap, dev, 0)) { |
| 1762 | printk(KERN_ERR "ata%u: failed to revalidate after set " |
| 1763 | "xfermode, disabled\n", ap->id); |
| 1764 | ata_port_disable(ap); |
| 1765 | } |
| 1766 | |
Tejun Heo | 23e71c3 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 1767 | DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", |
| 1768 | dev->xfer_shift, (int)dev->xfer_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | |
| 1770 | printk(KERN_INFO "ata%u: dev %u configured for %s\n", |
Tejun Heo | 23e71c3 | 2006-03-06 04:31:57 +0900 | [diff] [blame] | 1771 | ap->id, dev->devno, |
| 1772 | ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | static int ata_host_set_pio(struct ata_port *ap) |
| 1776 | { |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1777 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | |
| 1779 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 1780 | struct ata_device *dev = &ap->device[i]; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1781 | |
| 1782 | if (!ata_dev_present(dev)) |
| 1783 | continue; |
| 1784 | |
| 1785 | if (!dev->pio_mode) { |
| 1786 | printk(KERN_WARNING "ata%u: no PIO support\n", ap->id); |
| 1787 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | } |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1789 | |
| 1790 | dev->xfer_mode = dev->pio_mode; |
| 1791 | dev->xfer_shift = ATA_SHIFT_PIO; |
| 1792 | if (ap->ops->set_piomode) |
| 1793 | ap->ops->set_piomode(ap, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | return 0; |
| 1797 | } |
| 1798 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1799 | static void ata_host_set_dma(struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | { |
| 1801 | int i; |
| 1802 | |
| 1803 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 1804 | struct ata_device *dev = &ap->device[i]; |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1805 | |
| 1806 | if (!ata_dev_present(dev) || !dev->dma_mode) |
| 1807 | continue; |
| 1808 | |
| 1809 | dev->xfer_mode = dev->dma_mode; |
| 1810 | dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); |
| 1811 | if (ap->ops->set_dmamode) |
| 1812 | ap->ops->set_dmamode(ap, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | /** |
| 1817 | * ata_set_mode - Program timings and issue SET FEATURES - XFER |
| 1818 | * @ap: port on which timings will be programmed |
| 1819 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1820 | * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). |
| 1821 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1823 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | */ |
| 1825 | static void ata_set_mode(struct ata_port *ap) |
| 1826 | { |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1827 | int i, rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1829 | /* step 1: calculate xfer_mask */ |
| 1830 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 1831 | struct ata_device *dev = &ap->device[i]; |
| 1832 | unsigned int xfer_mask; |
| 1833 | |
| 1834 | if (!ata_dev_present(dev)) |
| 1835 | continue; |
| 1836 | |
| 1837 | xfer_mask = ata_dev_xfermask(ap, dev); |
| 1838 | |
| 1839 | dev->pio_mode = ata_xfer_mask2mode(xfer_mask & ATA_MASK_PIO); |
| 1840 | dev->dma_mode = ata_xfer_mask2mode(xfer_mask & (ATA_MASK_MWDMA | |
| 1841 | ATA_MASK_UDMA)); |
| 1842 | } |
| 1843 | |
| 1844 | /* step 2: always set host PIO timings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | rc = ata_host_set_pio(ap); |
| 1846 | if (rc) |
| 1847 | goto err_out; |
| 1848 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1849 | /* step 3: set host DMA timings */ |
| 1850 | ata_host_set_dma(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | |
| 1852 | /* step 4: update devices' xfer mode */ |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 1853 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 1854 | ata_dev_set_mode(ap, &ap->device[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | |
| 1856 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
| 1857 | return; |
| 1858 | |
| 1859 | if (ap->ops->post_set_mode) |
| 1860 | ap->ops->post_set_mode(ap); |
| 1861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | return; |
| 1863 | |
| 1864 | err_out: |
| 1865 | ata_port_disable(ap); |
| 1866 | } |
| 1867 | |
| 1868 | /** |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 1869 | * ata_tf_to_host - issue ATA taskfile to host controller |
| 1870 | * @ap: port to which command is being issued |
| 1871 | * @tf: ATA taskfile register set |
| 1872 | * |
| 1873 | * Issues ATA taskfile register set to ATA host controller, |
| 1874 | * with proper synchronization with interrupt handler and |
| 1875 | * other threads. |
| 1876 | * |
| 1877 | * LOCKING: |
| 1878 | * spin_lock_irqsave(host_set lock) |
| 1879 | */ |
| 1880 | |
| 1881 | static inline void ata_tf_to_host(struct ata_port *ap, |
| 1882 | const struct ata_taskfile *tf) |
| 1883 | { |
| 1884 | ap->ops->tf_load(ap, tf); |
| 1885 | ap->ops->exec_command(ap, tf); |
| 1886 | } |
| 1887 | |
| 1888 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | * ata_busy_sleep - sleep until BSY clears, or timeout |
| 1890 | * @ap: port containing status register to be polled |
| 1891 | * @tmout_pat: impatience timeout |
| 1892 | * @tmout: overall timeout |
| 1893 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 1894 | * Sleep until ATA Status register bit BSY clears, |
| 1895 | * or a timeout occurs. |
| 1896 | * |
| 1897 | * LOCKING: None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | */ |
| 1899 | |
Tejun Heo | 6f8b995 | 2006-01-24 17:05:21 +0900 | [diff] [blame] | 1900 | unsigned int ata_busy_sleep (struct ata_port *ap, |
| 1901 | unsigned long tmout_pat, unsigned long tmout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | { |
| 1903 | unsigned long timer_start, timeout; |
| 1904 | u8 status; |
| 1905 | |
| 1906 | status = ata_busy_wait(ap, ATA_BUSY, 300); |
| 1907 | timer_start = jiffies; |
| 1908 | timeout = timer_start + tmout_pat; |
| 1909 | while ((status & ATA_BUSY) && (time_before(jiffies, timeout))) { |
| 1910 | msleep(50); |
| 1911 | status = ata_busy_wait(ap, ATA_BUSY, 3); |
| 1912 | } |
| 1913 | |
| 1914 | if (status & ATA_BUSY) |
| 1915 | printk(KERN_WARNING "ata%u is slow to respond, " |
| 1916 | "please be patient\n", ap->id); |
| 1917 | |
| 1918 | timeout = timer_start + tmout; |
| 1919 | while ((status & ATA_BUSY) && (time_before(jiffies, timeout))) { |
| 1920 | msleep(50); |
| 1921 | status = ata_chk_status(ap); |
| 1922 | } |
| 1923 | |
| 1924 | if (status & ATA_BUSY) { |
| 1925 | printk(KERN_ERR "ata%u failed to respond (%lu secs)\n", |
| 1926 | ap->id, tmout / HZ); |
| 1927 | return 1; |
| 1928 | } |
| 1929 | |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask) |
| 1934 | { |
| 1935 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 1936 | unsigned int dev0 = devmask & (1 << 0); |
| 1937 | unsigned int dev1 = devmask & (1 << 1); |
| 1938 | unsigned long timeout; |
| 1939 | |
| 1940 | /* if device 0 was found in ata_devchk, wait for its |
| 1941 | * BSY bit to clear |
| 1942 | */ |
| 1943 | if (dev0) |
| 1944 | ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); |
| 1945 | |
| 1946 | /* if device 1 was found in ata_devchk, wait for |
| 1947 | * register access, then wait for BSY to clear |
| 1948 | */ |
| 1949 | timeout = jiffies + ATA_TMOUT_BOOT; |
| 1950 | while (dev1) { |
| 1951 | u8 nsect, lbal; |
| 1952 | |
| 1953 | ap->ops->dev_select(ap, 1); |
| 1954 | if (ap->flags & ATA_FLAG_MMIO) { |
| 1955 | nsect = readb((void __iomem *) ioaddr->nsect_addr); |
| 1956 | lbal = readb((void __iomem *) ioaddr->lbal_addr); |
| 1957 | } else { |
| 1958 | nsect = inb(ioaddr->nsect_addr); |
| 1959 | lbal = inb(ioaddr->lbal_addr); |
| 1960 | } |
| 1961 | if ((nsect == 1) && (lbal == 1)) |
| 1962 | break; |
| 1963 | if (time_after(jiffies, timeout)) { |
| 1964 | dev1 = 0; |
| 1965 | break; |
| 1966 | } |
| 1967 | msleep(50); /* give drive a breather */ |
| 1968 | } |
| 1969 | if (dev1) |
| 1970 | ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); |
| 1971 | |
| 1972 | /* is all this really necessary? */ |
| 1973 | ap->ops->dev_select(ap, 0); |
| 1974 | if (dev1) |
| 1975 | ap->ops->dev_select(ap, 1); |
| 1976 | if (dev0) |
| 1977 | ap->ops->dev_select(ap, 0); |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1981 | * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command. |
| 1982 | * @ap: Port to reset and probe |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1984 | * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and |
| 1985 | * probe the bus. Not often used these days. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | * |
| 1987 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 1988 | * PCI/etc. bus probe sem. |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 1989 | * Obtains host_set lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | * |
| 1991 | */ |
| 1992 | |
| 1993 | static unsigned int ata_bus_edd(struct ata_port *ap) |
| 1994 | { |
| 1995 | struct ata_taskfile tf; |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 1996 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | |
| 1998 | /* set up execute-device-diag (bus reset) taskfile */ |
| 1999 | /* also, take interrupts to a known state (disabled) */ |
| 2000 | DPRINTK("execute-device-diag\n"); |
| 2001 | ata_tf_init(ap, &tf, 0); |
| 2002 | tf.ctl |= ATA_NIEN; |
| 2003 | tf.command = ATA_CMD_EDD; |
| 2004 | tf.protocol = ATA_PROT_NODATA; |
| 2005 | |
| 2006 | /* do bus reset */ |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 2007 | spin_lock_irqsave(&ap->host_set->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | ata_tf_to_host(ap, &tf); |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 2009 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
| 2011 | /* spec says at least 2ms. but who knows with those |
| 2012 | * crazy ATAPI devices... |
| 2013 | */ |
| 2014 | msleep(150); |
| 2015 | |
| 2016 | return ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); |
| 2017 | } |
| 2018 | |
| 2019 | static unsigned int ata_bus_softreset(struct ata_port *ap, |
| 2020 | unsigned int devmask) |
| 2021 | { |
| 2022 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 2023 | |
| 2024 | DPRINTK("ata%u: bus reset via SRST\n", ap->id); |
| 2025 | |
| 2026 | /* software reset. causes dev0 to be selected */ |
| 2027 | if (ap->flags & ATA_FLAG_MMIO) { |
| 2028 | writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr); |
| 2029 | udelay(20); /* FIXME: flush */ |
| 2030 | writeb(ap->ctl | ATA_SRST, (void __iomem *) ioaddr->ctl_addr); |
| 2031 | udelay(20); /* FIXME: flush */ |
| 2032 | writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr); |
| 2033 | } else { |
| 2034 | outb(ap->ctl, ioaddr->ctl_addr); |
| 2035 | udelay(10); |
| 2036 | outb(ap->ctl | ATA_SRST, ioaddr->ctl_addr); |
| 2037 | udelay(10); |
| 2038 | outb(ap->ctl, ioaddr->ctl_addr); |
| 2039 | } |
| 2040 | |
| 2041 | /* spec mandates ">= 2ms" before checking status. |
| 2042 | * We wait 150ms, because that was the magic delay used for |
| 2043 | * ATAPI devices in Hale Landis's ATADRVR, for the period of time |
| 2044 | * between when the ATA command register is written, and then |
| 2045 | * status is checked. Because waiting for "a while" before |
| 2046 | * checking status is fine, post SRST, we perform this magic |
| 2047 | * delay here as well. |
| 2048 | */ |
| 2049 | msleep(150); |
| 2050 | |
| 2051 | ata_bus_post_reset(ap, devmask); |
| 2052 | |
| 2053 | return 0; |
| 2054 | } |
| 2055 | |
| 2056 | /** |
| 2057 | * ata_bus_reset - reset host port and associated ATA channel |
| 2058 | * @ap: port to reset |
| 2059 | * |
| 2060 | * This is typically the first time we actually start issuing |
| 2061 | * commands to the ATA channel. We wait for BSY to clear, then |
| 2062 | * issue EXECUTE DEVICE DIAGNOSTIC command, polling for its |
| 2063 | * result. Determine what devices, if any, are on the channel |
| 2064 | * by looking at the device 0/1 error register. Look at the signature |
| 2065 | * stored in each device's taskfile registers, to determine if |
| 2066 | * the device is ATA or ATAPI. |
| 2067 | * |
| 2068 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2069 | * PCI/etc. bus probe sem. |
| 2070 | * Obtains host_set lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | * |
| 2072 | * SIDE EFFECTS: |
| 2073 | * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. |
| 2074 | */ |
| 2075 | |
| 2076 | void ata_bus_reset(struct ata_port *ap) |
| 2077 | { |
| 2078 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 2079 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; |
| 2080 | u8 err; |
| 2081 | unsigned int dev0, dev1 = 0, rc = 0, devmask = 0; |
| 2082 | |
| 2083 | DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no); |
| 2084 | |
| 2085 | /* determine if device 0/1 are present */ |
| 2086 | if (ap->flags & ATA_FLAG_SATA_RESET) |
| 2087 | dev0 = 1; |
| 2088 | else { |
| 2089 | dev0 = ata_devchk(ap, 0); |
| 2090 | if (slave_possible) |
| 2091 | dev1 = ata_devchk(ap, 1); |
| 2092 | } |
| 2093 | |
| 2094 | if (dev0) |
| 2095 | devmask |= (1 << 0); |
| 2096 | if (dev1) |
| 2097 | devmask |= (1 << 1); |
| 2098 | |
| 2099 | /* select device 0 again */ |
| 2100 | ap->ops->dev_select(ap, 0); |
| 2101 | |
| 2102 | /* issue bus reset */ |
| 2103 | if (ap->flags & ATA_FLAG_SRST) |
| 2104 | rc = ata_bus_softreset(ap, devmask); |
| 2105 | else if ((ap->flags & ATA_FLAG_SATA_RESET) == 0) { |
| 2106 | /* set up device control */ |
| 2107 | if (ap->flags & ATA_FLAG_MMIO) |
| 2108 | writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr); |
| 2109 | else |
| 2110 | outb(ap->ctl, ioaddr->ctl_addr); |
| 2111 | rc = ata_bus_edd(ap); |
| 2112 | } |
| 2113 | |
| 2114 | if (rc) |
| 2115 | goto err_out; |
| 2116 | |
| 2117 | /* |
| 2118 | * determine by signature whether we have ATA or ATAPI devices |
| 2119 | */ |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2120 | ap->device[0].class = ata_dev_try_classify(ap, 0, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | if ((slave_possible) && (err != 0x81)) |
Tejun Heo | b4dc762 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2122 | ap->device[1].class = ata_dev_try_classify(ap, 1, &err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | |
| 2124 | /* re-enable interrupts */ |
| 2125 | if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ |
| 2126 | ata_irq_on(ap); |
| 2127 | |
| 2128 | /* is double-select really necessary? */ |
| 2129 | if (ap->device[1].class != ATA_DEV_NONE) |
| 2130 | ap->ops->dev_select(ap, 1); |
| 2131 | if (ap->device[0].class != ATA_DEV_NONE) |
| 2132 | ap->ops->dev_select(ap, 0); |
| 2133 | |
| 2134 | /* if no devices were detected, disable this port */ |
| 2135 | if ((ap->device[0].class == ATA_DEV_NONE) && |
| 2136 | (ap->device[1].class == ATA_DEV_NONE)) |
| 2137 | goto err_out; |
| 2138 | |
| 2139 | if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) { |
| 2140 | /* set up device control for ATA_FLAG_SATA_RESET */ |
| 2141 | if (ap->flags & ATA_FLAG_MMIO) |
| 2142 | writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr); |
| 2143 | else |
| 2144 | outb(ap->ctl, ioaddr->ctl_addr); |
| 2145 | } |
| 2146 | |
| 2147 | DPRINTK("EXIT\n"); |
| 2148 | return; |
| 2149 | |
| 2150 | err_out: |
| 2151 | printk(KERN_ERR "ata%u: disabling port\n", ap->id); |
| 2152 | ap->ops->port_disable(ap); |
| 2153 | |
| 2154 | DPRINTK("EXIT\n"); |
| 2155 | } |
| 2156 | |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2157 | static int sata_phy_resume(struct ata_port *ap) |
| 2158 | { |
| 2159 | unsigned long timeout = jiffies + (HZ * 5); |
| 2160 | u32 sstatus; |
| 2161 | |
| 2162 | scr_write_flush(ap, SCR_CONTROL, 0x300); |
| 2163 | |
| 2164 | /* Wait for phy to become ready, if necessary. */ |
| 2165 | do { |
| 2166 | msleep(200); |
| 2167 | sstatus = scr_read(ap, SCR_STATUS); |
| 2168 | if ((sstatus & 0xf) != 1) |
| 2169 | return 0; |
| 2170 | } while (time_before(jiffies, timeout)); |
| 2171 | |
| 2172 | return -1; |
| 2173 | } |
| 2174 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2175 | /** |
Tejun Heo | 8a19ac8 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2176 | * ata_std_probeinit - initialize probing |
| 2177 | * @ap: port to be probed |
| 2178 | * |
| 2179 | * @ap is about to be probed. Initialize it. This function is |
| 2180 | * to be used as standard callback for ata_drive_probe_reset(). |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2181 | * |
| 2182 | * NOTE!!! Do not use this function as probeinit if a low level |
| 2183 | * driver implements only hardreset. Just pass NULL as probeinit |
| 2184 | * in that case. Using this function is probably okay but doing |
| 2185 | * so makes reset sequence different from the original |
| 2186 | * ->phy_reset implementation and Jeff nervous. :-P |
Tejun Heo | 8a19ac8 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2187 | */ |
| 2188 | extern void ata_std_probeinit(struct ata_port *ap) |
| 2189 | { |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2190 | if (ap->flags & ATA_FLAG_SATA && ap->ops->scr_read) { |
Tejun Heo | 8a19ac8 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2191 | sata_phy_resume(ap); |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2192 | if (sata_dev_present(ap)) |
| 2193 | ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); |
| 2194 | } |
Tejun Heo | 8a19ac8 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /** |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2198 | * ata_std_softreset - reset host port via ATA SRST |
| 2199 | * @ap: port to reset |
| 2200 | * @verbose: fail verbosely |
| 2201 | * @classes: resulting classes of attached devices |
| 2202 | * |
| 2203 | * Reset host port using ATA SRST. This function is to be used |
| 2204 | * as standard callback for ata_drive_*_reset() functions. |
| 2205 | * |
| 2206 | * LOCKING: |
| 2207 | * Kernel thread context (may sleep) |
| 2208 | * |
| 2209 | * RETURNS: |
| 2210 | * 0 on success, -errno otherwise. |
| 2211 | */ |
| 2212 | int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes) |
| 2213 | { |
| 2214 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; |
| 2215 | unsigned int devmask = 0, err_mask; |
| 2216 | u8 err; |
| 2217 | |
| 2218 | DPRINTK("ENTER\n"); |
| 2219 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2220 | if (ap->ops->scr_read && !sata_dev_present(ap)) { |
| 2221 | classes[0] = ATA_DEV_NONE; |
| 2222 | goto out; |
| 2223 | } |
| 2224 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2225 | /* determine if device 0/1 are present */ |
| 2226 | if (ata_devchk(ap, 0)) |
| 2227 | devmask |= (1 << 0); |
| 2228 | if (slave_possible && ata_devchk(ap, 1)) |
| 2229 | devmask |= (1 << 1); |
| 2230 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2231 | /* select device 0 again */ |
| 2232 | ap->ops->dev_select(ap, 0); |
| 2233 | |
| 2234 | /* issue bus reset */ |
| 2235 | DPRINTK("about to softreset, devmask=%x\n", devmask); |
| 2236 | err_mask = ata_bus_softreset(ap, devmask); |
| 2237 | if (err_mask) { |
| 2238 | if (verbose) |
| 2239 | printk(KERN_ERR "ata%u: SRST failed (err_mask=0x%x)\n", |
| 2240 | ap->id, err_mask); |
| 2241 | else |
| 2242 | DPRINTK("EXIT, softreset failed (err_mask=0x%x)\n", |
| 2243 | err_mask); |
| 2244 | return -EIO; |
| 2245 | } |
| 2246 | |
| 2247 | /* determine by signature whether we have ATA or ATAPI devices */ |
| 2248 | classes[0] = ata_dev_try_classify(ap, 0, &err); |
| 2249 | if (slave_possible && err != 0x81) |
| 2250 | classes[1] = ata_dev_try_classify(ap, 1, &err); |
| 2251 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2252 | out: |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2253 | DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]); |
| 2254 | return 0; |
| 2255 | } |
| 2256 | |
| 2257 | /** |
| 2258 | * sata_std_hardreset - reset host port via SATA phy reset |
| 2259 | * @ap: port to reset |
| 2260 | * @verbose: fail verbosely |
| 2261 | * @class: resulting class of attached device |
| 2262 | * |
| 2263 | * SATA phy-reset host port using DET bits of SControl register. |
| 2264 | * This function is to be used as standard callback for |
| 2265 | * ata_drive_*_reset(). |
| 2266 | * |
| 2267 | * LOCKING: |
| 2268 | * Kernel thread context (may sleep) |
| 2269 | * |
| 2270 | * RETURNS: |
| 2271 | * 0 on success, -errno otherwise. |
| 2272 | */ |
| 2273 | int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class) |
| 2274 | { |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2275 | DPRINTK("ENTER\n"); |
| 2276 | |
| 2277 | /* Issue phy wake/reset */ |
| 2278 | scr_write_flush(ap, SCR_CONTROL, 0x301); |
| 2279 | |
| 2280 | /* |
| 2281 | * Couldn't find anything in SATA I/II specs, but AHCI-1.1 |
| 2282 | * 10.4.2 says at least 1 ms. |
| 2283 | */ |
| 2284 | msleep(1); |
| 2285 | |
Tejun Heo | 7a7921e | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2286 | /* Bring phy back */ |
| 2287 | sata_phy_resume(ap); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2288 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2289 | /* TODO: phy layer with polling, timeouts, etc. */ |
| 2290 | if (!sata_dev_present(ap)) { |
| 2291 | *class = ATA_DEV_NONE; |
| 2292 | DPRINTK("EXIT, link offline\n"); |
| 2293 | return 0; |
| 2294 | } |
| 2295 | |
| 2296 | if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { |
| 2297 | if (verbose) |
| 2298 | printk(KERN_ERR "ata%u: COMRESET failed " |
| 2299 | "(device not ready)\n", ap->id); |
| 2300 | else |
| 2301 | DPRINTK("EXIT, device not ready\n"); |
| 2302 | return -EIO; |
| 2303 | } |
| 2304 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2305 | ap->ops->dev_select(ap, 0); /* probably unnecessary */ |
| 2306 | |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2307 | *class = ata_dev_try_classify(ap, 0, NULL); |
| 2308 | |
| 2309 | DPRINTK("EXIT, class=%u\n", *class); |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
| 2313 | /** |
| 2314 | * ata_std_postreset - standard postreset callback |
| 2315 | * @ap: the target ata_port |
| 2316 | * @classes: classes of attached devices |
| 2317 | * |
| 2318 | * This function is invoked after a successful reset. Note that |
| 2319 | * the device might have been reset more than once using |
| 2320 | * different reset methods before postreset is invoked. |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2321 | * |
| 2322 | * This function is to be used as standard callback for |
| 2323 | * ata_drive_*_reset(). |
| 2324 | * |
| 2325 | * LOCKING: |
| 2326 | * Kernel thread context (may sleep) |
| 2327 | */ |
| 2328 | void ata_std_postreset(struct ata_port *ap, unsigned int *classes) |
| 2329 | { |
| 2330 | DPRINTK("ENTER\n"); |
| 2331 | |
Tejun Heo | 56497bd | 2006-02-15 15:01:42 +0900 | [diff] [blame] | 2332 | /* set cable type if it isn't already set */ |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2333 | if (ap->cbl == ATA_CBL_NONE && ap->flags & ATA_FLAG_SATA) |
| 2334 | ap->cbl = ATA_CBL_SATA; |
| 2335 | |
| 2336 | /* print link status */ |
| 2337 | if (ap->cbl == ATA_CBL_SATA) |
| 2338 | sata_print_link_status(ap); |
| 2339 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2340 | /* re-enable interrupts */ |
| 2341 | if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ |
| 2342 | ata_irq_on(ap); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2343 | |
| 2344 | /* is double-select really necessary? */ |
| 2345 | if (classes[0] != ATA_DEV_NONE) |
| 2346 | ap->ops->dev_select(ap, 1); |
| 2347 | if (classes[1] != ATA_DEV_NONE) |
| 2348 | ap->ops->dev_select(ap, 0); |
| 2349 | |
Tejun Heo | 3a39746 | 2006-02-10 23:58:48 +0900 | [diff] [blame] | 2350 | /* bail out if no device is present */ |
| 2351 | if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { |
| 2352 | DPRINTK("EXIT, no device\n"); |
| 2353 | return; |
| 2354 | } |
| 2355 | |
| 2356 | /* set up device control */ |
| 2357 | if (ap->ioaddr.ctl_addr) { |
| 2358 | if (ap->flags & ATA_FLAG_MMIO) |
| 2359 | writeb(ap->ctl, (void __iomem *) ap->ioaddr.ctl_addr); |
| 2360 | else |
| 2361 | outb(ap->ctl, ap->ioaddr.ctl_addr); |
| 2362 | } |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2363 | |
| 2364 | DPRINTK("EXIT\n"); |
| 2365 | } |
| 2366 | |
| 2367 | /** |
| 2368 | * ata_std_probe_reset - standard probe reset method |
| 2369 | * @ap: prot to perform probe-reset |
| 2370 | * @classes: resulting classes of attached devices |
| 2371 | * |
| 2372 | * The stock off-the-shelf ->probe_reset method. |
| 2373 | * |
| 2374 | * LOCKING: |
| 2375 | * Kernel thread context (may sleep) |
| 2376 | * |
| 2377 | * RETURNS: |
| 2378 | * 0 on success, -errno otherwise. |
| 2379 | */ |
| 2380 | int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes) |
| 2381 | { |
| 2382 | ata_reset_fn_t hardreset; |
| 2383 | |
| 2384 | hardreset = NULL; |
Tejun Heo | b911fc3 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2385 | if (ap->flags & ATA_FLAG_SATA && ap->ops->scr_read) |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2386 | hardreset = sata_std_hardreset; |
| 2387 | |
Tejun Heo | 8a19ac8 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2388 | return ata_drive_probe_reset(ap, ata_std_probeinit, |
Tejun Heo | 7944ea9 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2389 | ata_std_softreset, hardreset, |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2390 | ata_std_postreset, classes); |
| 2391 | } |
| 2392 | |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2393 | static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset, |
| 2394 | ata_postreset_fn_t postreset, |
| 2395 | unsigned int *classes) |
| 2396 | { |
| 2397 | int i, rc; |
| 2398 | |
| 2399 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 2400 | classes[i] = ATA_DEV_UNKNOWN; |
| 2401 | |
| 2402 | rc = reset(ap, 0, classes); |
| 2403 | if (rc) |
| 2404 | return rc; |
| 2405 | |
| 2406 | /* If any class isn't ATA_DEV_UNKNOWN, consider classification |
| 2407 | * is complete and convert all ATA_DEV_UNKNOWN to |
| 2408 | * ATA_DEV_NONE. |
| 2409 | */ |
| 2410 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 2411 | if (classes[i] != ATA_DEV_UNKNOWN) |
| 2412 | break; |
| 2413 | |
| 2414 | if (i < ATA_MAX_DEVICES) |
| 2415 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 2416 | if (classes[i] == ATA_DEV_UNKNOWN) |
| 2417 | classes[i] = ATA_DEV_NONE; |
| 2418 | |
| 2419 | if (postreset) |
| 2420 | postreset(ap, classes); |
| 2421 | |
| 2422 | return classes[0] != ATA_DEV_UNKNOWN ? 0 : -ENODEV; |
| 2423 | } |
| 2424 | |
| 2425 | /** |
| 2426 | * ata_drive_probe_reset - Perform probe reset with given methods |
| 2427 | * @ap: port to reset |
Tejun Heo | 7944ea9 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2428 | * @probeinit: probeinit method (can be NULL) |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2429 | * @softreset: softreset method (can be NULL) |
| 2430 | * @hardreset: hardreset method (can be NULL) |
| 2431 | * @postreset: postreset method (can be NULL) |
| 2432 | * @classes: resulting classes of attached devices |
| 2433 | * |
| 2434 | * Reset the specified port and classify attached devices using |
| 2435 | * given methods. This function prefers softreset but tries all |
| 2436 | * possible reset sequences to reset and classify devices. This |
| 2437 | * function is intended to be used for constructing ->probe_reset |
| 2438 | * callback by low level drivers. |
| 2439 | * |
| 2440 | * Reset methods should follow the following rules. |
| 2441 | * |
| 2442 | * - Return 0 on sucess, -errno on failure. |
| 2443 | * - If classification is supported, fill classes[] with |
| 2444 | * recognized class codes. |
| 2445 | * - If classification is not supported, leave classes[] alone. |
| 2446 | * - If verbose is non-zero, print error message on failure; |
| 2447 | * otherwise, shut up. |
| 2448 | * |
| 2449 | * LOCKING: |
| 2450 | * Kernel thread context (may sleep) |
| 2451 | * |
| 2452 | * RETURNS: |
| 2453 | * 0 on success, -EINVAL if no reset method is avaliable, -ENODEV |
| 2454 | * if classification fails, and any error code from reset |
| 2455 | * methods. |
| 2456 | */ |
Tejun Heo | 7944ea9 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2457 | int ata_drive_probe_reset(struct ata_port *ap, ata_probeinit_fn_t probeinit, |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2458 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, |
| 2459 | ata_postreset_fn_t postreset, unsigned int *classes) |
| 2460 | { |
| 2461 | int rc = -EINVAL; |
| 2462 | |
Tejun Heo | 7944ea9 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 2463 | if (probeinit) |
| 2464 | probeinit(ap); |
| 2465 | |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 2466 | if (softreset) { |
| 2467 | rc = do_probe_reset(ap, softreset, postreset, classes); |
| 2468 | if (rc == 0) |
| 2469 | return 0; |
| 2470 | } |
| 2471 | |
| 2472 | if (!hardreset) |
| 2473 | return rc; |
| 2474 | |
| 2475 | rc = do_probe_reset(ap, hardreset, postreset, classes); |
| 2476 | if (rc == 0 || rc != -ENODEV) |
| 2477 | return rc; |
| 2478 | |
| 2479 | if (softreset) |
| 2480 | rc = do_probe_reset(ap, softreset, postreset, classes); |
| 2481 | |
| 2482 | return rc; |
| 2483 | } |
| 2484 | |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 2485 | /** |
| 2486 | * ata_dev_same_device - Determine whether new ID matches configured device |
| 2487 | * @ap: port on which the device to compare against resides |
| 2488 | * @dev: device to compare against |
| 2489 | * @new_class: class of the new device |
| 2490 | * @new_id: IDENTIFY page of the new device |
| 2491 | * |
| 2492 | * Compare @new_class and @new_id against @dev and determine |
| 2493 | * whether @dev is the device indicated by @new_class and |
| 2494 | * @new_id. |
| 2495 | * |
| 2496 | * LOCKING: |
| 2497 | * None. |
| 2498 | * |
| 2499 | * RETURNS: |
| 2500 | * 1 if @dev matches @new_class and @new_id, 0 otherwise. |
| 2501 | */ |
| 2502 | static int ata_dev_same_device(struct ata_port *ap, struct ata_device *dev, |
| 2503 | unsigned int new_class, const u16 *new_id) |
| 2504 | { |
| 2505 | const u16 *old_id = dev->id; |
| 2506 | unsigned char model[2][41], serial[2][21]; |
| 2507 | u64 new_n_sectors; |
| 2508 | |
| 2509 | if (dev->class != new_class) { |
| 2510 | printk(KERN_INFO |
| 2511 | "ata%u: dev %u class mismatch %d != %d\n", |
| 2512 | ap->id, dev->devno, dev->class, new_class); |
| 2513 | return 0; |
| 2514 | } |
| 2515 | |
| 2516 | ata_id_c_string(old_id, model[0], ATA_ID_PROD_OFS, sizeof(model[0])); |
| 2517 | ata_id_c_string(new_id, model[1], ATA_ID_PROD_OFS, sizeof(model[1])); |
| 2518 | ata_id_c_string(old_id, serial[0], ATA_ID_SERNO_OFS, sizeof(serial[0])); |
| 2519 | ata_id_c_string(new_id, serial[1], ATA_ID_SERNO_OFS, sizeof(serial[1])); |
| 2520 | new_n_sectors = ata_id_n_sectors(new_id); |
| 2521 | |
| 2522 | if (strcmp(model[0], model[1])) { |
| 2523 | printk(KERN_INFO |
| 2524 | "ata%u: dev %u model number mismatch '%s' != '%s'\n", |
| 2525 | ap->id, dev->devno, model[0], model[1]); |
| 2526 | return 0; |
| 2527 | } |
| 2528 | |
| 2529 | if (strcmp(serial[0], serial[1])) { |
| 2530 | printk(KERN_INFO |
| 2531 | "ata%u: dev %u serial number mismatch '%s' != '%s'\n", |
| 2532 | ap->id, dev->devno, serial[0], serial[1]); |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
| 2536 | if (dev->class == ATA_DEV_ATA && dev->n_sectors != new_n_sectors) { |
| 2537 | printk(KERN_INFO |
| 2538 | "ata%u: dev %u n_sectors mismatch %llu != %llu\n", |
| 2539 | ap->id, dev->devno, (unsigned long long)dev->n_sectors, |
| 2540 | (unsigned long long)new_n_sectors); |
| 2541 | return 0; |
| 2542 | } |
| 2543 | |
| 2544 | return 1; |
| 2545 | } |
| 2546 | |
| 2547 | /** |
| 2548 | * ata_dev_revalidate - Revalidate ATA device |
| 2549 | * @ap: port on which the device to revalidate resides |
| 2550 | * @dev: device to revalidate |
| 2551 | * @post_reset: is this revalidation after reset? |
| 2552 | * |
| 2553 | * Re-read IDENTIFY page and make sure @dev is still attached to |
| 2554 | * the port. |
| 2555 | * |
| 2556 | * LOCKING: |
| 2557 | * Kernel thread context (may sleep) |
| 2558 | * |
| 2559 | * RETURNS: |
| 2560 | * 0 on success, negative errno otherwise |
| 2561 | */ |
| 2562 | int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, |
| 2563 | int post_reset) |
| 2564 | { |
| 2565 | unsigned int class; |
| 2566 | u16 *id; |
| 2567 | int rc; |
| 2568 | |
| 2569 | if (!ata_dev_present(dev)) |
| 2570 | return -ENODEV; |
| 2571 | |
| 2572 | class = dev->class; |
| 2573 | id = NULL; |
| 2574 | |
| 2575 | /* allocate & read ID data */ |
| 2576 | rc = ata_dev_read_id(ap, dev, &class, post_reset, &id); |
| 2577 | if (rc) |
| 2578 | goto fail; |
| 2579 | |
| 2580 | /* is the device still there? */ |
| 2581 | if (!ata_dev_same_device(ap, dev, class, id)) { |
| 2582 | rc = -ENODEV; |
| 2583 | goto fail; |
| 2584 | } |
| 2585 | |
| 2586 | kfree(dev->id); |
| 2587 | dev->id = id; |
| 2588 | |
| 2589 | /* configure device according to the new ID */ |
| 2590 | return ata_dev_configure(ap, dev, 0); |
| 2591 | |
| 2592 | fail: |
| 2593 | printk(KERN_ERR "ata%u: dev %u revalidation failed (errno=%d)\n", |
| 2594 | ap->id, dev->devno, rc); |
| 2595 | kfree(id); |
| 2596 | return rc; |
| 2597 | } |
| 2598 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 2599 | static void ata_pr_blacklisted(const struct ata_port *ap, |
| 2600 | const struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | { |
| 2602 | printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, disabling DMA\n", |
| 2603 | ap->id, dev->devno); |
| 2604 | } |
| 2605 | |
Arjan van de Ven | 98ac62d | 2005-11-28 10:06:23 +0100 | [diff] [blame] | 2606 | static const char * const ata_dma_blacklist [] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | "WDC AC11000H", |
| 2608 | "WDC AC22100H", |
| 2609 | "WDC AC32500H", |
| 2610 | "WDC AC33100H", |
| 2611 | "WDC AC31600H", |
| 2612 | "WDC AC32100H", |
| 2613 | "WDC AC23200L", |
| 2614 | "Compaq CRD-8241B", |
| 2615 | "CRD-8400B", |
| 2616 | "CRD-8480B", |
| 2617 | "CRD-8482B", |
| 2618 | "CRD-84", |
| 2619 | "SanDisk SDP3B", |
| 2620 | "SanDisk SDP3B-64", |
| 2621 | "SANYO CD-ROM CRD", |
| 2622 | "HITACHI CDR-8", |
| 2623 | "HITACHI CDR-8335", |
| 2624 | "HITACHI CDR-8435", |
| 2625 | "Toshiba CD-ROM XM-6202B", |
Jeff Garzik | e922256 | 2005-06-28 00:03:37 -0400 | [diff] [blame] | 2626 | "TOSHIBA CD-ROM XM-1702BC", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | "CD-532E-A", |
| 2628 | "E-IDE CD-ROM CR-840", |
| 2629 | "CD-ROM Drive/F5A", |
| 2630 | "WPI CDD-820", |
| 2631 | "SAMSUNG CD-ROM SC-148C", |
| 2632 | "SAMSUNG CD-ROM SC", |
| 2633 | "SanDisk SDP3B-64", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | "ATAPI CD-ROM DRIVE 40X MAXIMUM", |
| 2635 | "_NEC DV5800A", |
| 2636 | }; |
| 2637 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 2638 | static int ata_dma_blacklisted(const struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | { |
Tejun Heo | 2e02671 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 2640 | unsigned char model_num[41]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | int i; |
| 2642 | |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 2643 | ata_id_c_string(dev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | |
| 2645 | for (i = 0; i < ARRAY_SIZE(ata_dma_blacklist); i++) |
Tejun Heo | 2e02671 | 2006-02-12 22:47:04 +0900 | [diff] [blame] | 2646 | if (!strcmp(ata_dma_blacklist[i], model_num)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | return 1; |
| 2648 | |
| 2649 | return 0; |
| 2650 | } |
| 2651 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 2652 | /** |
| 2653 | * ata_dev_xfermask - Compute supported xfermask of the given device |
| 2654 | * @ap: Port on which the device to compute xfermask for resides |
| 2655 | * @dev: Device to compute xfermask for |
| 2656 | * |
| 2657 | * Compute supported xfermask of @dev. This function is |
| 2658 | * responsible for applying all known limits including host |
| 2659 | * controller limits, device blacklist, etc... |
| 2660 | * |
| 2661 | * LOCKING: |
| 2662 | * None. |
| 2663 | * |
| 2664 | * RETURNS: |
| 2665 | * Computed xfermask. |
| 2666 | */ |
| 2667 | static unsigned int ata_dev_xfermask(struct ata_port *ap, |
| 2668 | struct ata_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | { |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 2670 | unsigned long xfer_mask; |
| 2671 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 2673 | xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, |
| 2674 | ap->udma_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 2676 | /* use port-wide xfermask for now */ |
| 2677 | for (i = 0; i < ATA_MAX_DEVICES; i++) { |
| 2678 | struct ata_device *d = &ap->device[i]; |
| 2679 | if (!ata_dev_present(d)) |
| 2680 | continue; |
| 2681 | xfer_mask &= ata_id_xfermask(d->id); |
| 2682 | if (ata_dma_blacklisted(d)) |
| 2683 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | } |
| 2685 | |
Tejun Heo | a6d5a51 | 2006-03-06 04:31:57 +0900 | [diff] [blame^] | 2686 | if (ata_dma_blacklisted(dev)) |
| 2687 | printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, " |
| 2688 | "disabling DMA\n", ap->id, dev->devno); |
| 2689 | |
| 2690 | return xfer_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | /* find greatest bit */ |
| 2694 | static int fgb(u32 bitmap) |
| 2695 | { |
| 2696 | unsigned int i; |
| 2697 | int x = -1; |
| 2698 | |
| 2699 | for (i = 0; i < 32; i++) |
| 2700 | if (bitmap & (1 << i)) |
| 2701 | x = i; |
| 2702 | |
| 2703 | return x; |
| 2704 | } |
| 2705 | |
| 2706 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command |
| 2708 | * @ap: Port associated with device @dev |
| 2709 | * @dev: Device to which command will be sent |
| 2710 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2711 | * Issue SET FEATURES - XFER MODE command to device @dev |
| 2712 | * on port @ap. |
| 2713 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2715 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | */ |
| 2717 | |
| 2718 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) |
| 2719 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 2720 | struct ata_taskfile tf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2721 | |
| 2722 | /* set up set-features taskfile */ |
| 2723 | DPRINTK("set features - xfer mode\n"); |
| 2724 | |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 2725 | ata_tf_init(ap, &tf, dev->devno); |
| 2726 | tf.command = ATA_CMD_SET_FEATURES; |
| 2727 | tf.feature = SETFEATURES_XFER; |
| 2728 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 2729 | tf.protocol = ATA_PROT_NODATA; |
| 2730 | tf.nsect = dev->xfer_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 2732 | if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) { |
| 2733 | printk(KERN_ERR "ata%u: failed to set xfermode, disabled\n", |
| 2734 | ap->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | ata_port_disable(ap); |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 2736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | |
| 2738 | DPRINTK("EXIT\n"); |
| 2739 | } |
| 2740 | |
| 2741 | /** |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2742 | * ata_dev_init_params - Issue INIT DEV PARAMS command |
| 2743 | * @ap: Port associated with device @dev |
| 2744 | * @dev: Device to which command will be sent |
| 2745 | * |
| 2746 | * LOCKING: |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 2747 | * Kernel thread context (may sleep) |
| 2748 | * |
| 2749 | * RETURNS: |
| 2750 | * 0 on success, AC_ERR_* mask otherwise. |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2751 | */ |
| 2752 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 2753 | static unsigned int ata_dev_init_params(struct ata_port *ap, |
| 2754 | struct ata_device *dev) |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2755 | { |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 2756 | struct ata_taskfile tf; |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 2757 | unsigned int err_mask; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2758 | u16 sectors = dev->id[6]; |
| 2759 | u16 heads = dev->id[3]; |
| 2760 | |
| 2761 | /* Number of sectors per track 1-255. Number of heads 1-16 */ |
| 2762 | if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 2763 | return 0; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2764 | |
| 2765 | /* set up init dev params taskfile */ |
| 2766 | DPRINTK("init dev params \n"); |
| 2767 | |
Tejun Heo | a012370 | 2005-12-13 14:49:31 +0900 | [diff] [blame] | 2768 | ata_tf_init(ap, &tf, dev->devno); |
| 2769 | tf.command = ATA_CMD_INIT_DEV_PARAMS; |
| 2770 | tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; |
| 2771 | tf.protocol = ATA_PROT_NODATA; |
| 2772 | tf.nsect = sectors; |
| 2773 | tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2774 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 2775 | err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2776 | |
Tejun Heo | 6aff8f1 | 2006-02-15 18:24:09 +0900 | [diff] [blame] | 2777 | DPRINTK("EXIT, err_mask=%x\n", err_mask); |
| 2778 | return err_mask; |
Albert Lee | 8bf62ece | 2005-05-12 15:29:42 -0400 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2782 | * ata_sg_clean - Unmap DMA memory associated with command |
| 2783 | * @qc: Command containing DMA memory to be released |
| 2784 | * |
| 2785 | * Unmap all mapped DMA memory associated with this command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | * |
| 2787 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2788 | * spin_lock_irqsave(host_set lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | */ |
| 2790 | |
| 2791 | static void ata_sg_clean(struct ata_queued_cmd *qc) |
| 2792 | { |
| 2793 | struct ata_port *ap = qc->ap; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2794 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2795 | int dir = qc->dma_dir; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2796 | void *pad_buf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 2798 | WARN_ON(!(qc->flags & ATA_QCFLAG_DMAMAP)); |
| 2799 | WARN_ON(sg == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | |
| 2801 | if (qc->flags & ATA_QCFLAG_SINGLE) |
Jeff Garzik | f131883 | 2006-02-20 16:55:56 -0500 | [diff] [blame] | 2802 | WARN_ON(qc->n_elem > 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 2804 | VPRINTK("unmapping %u sg elements\n", qc->n_elem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2806 | /* if we padded the buffer out to 32-bit bound, and data |
| 2807 | * xfer direction is from-device, we must copy from the |
| 2808 | * pad buffer back into the supplied buffer |
| 2809 | */ |
| 2810 | if (qc->pad_len && !(qc->tf.flags & ATA_TFLAG_WRITE)) |
| 2811 | pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); |
| 2812 | |
| 2813 | if (qc->flags & ATA_QCFLAG_SG) { |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 2814 | if (qc->n_elem) |
| 2815 | dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2816 | /* restore last sg */ |
| 2817 | sg[qc->orig_n_elem - 1].length += qc->pad_len; |
| 2818 | if (pad_buf) { |
| 2819 | struct scatterlist *psg = &qc->pad_sgent; |
| 2820 | void *addr = kmap_atomic(psg->page, KM_IRQ0); |
| 2821 | memcpy(addr + psg->offset, pad_buf, qc->pad_len); |
Mark Lord | dfa1598 | 2005-12-12 23:19:28 -0500 | [diff] [blame] | 2822 | kunmap_atomic(addr, KM_IRQ0); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2823 | } |
| 2824 | } else { |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 2825 | if (qc->n_elem) |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 2826 | dma_unmap_single(ap->host_set->dev, |
| 2827 | sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), |
| 2828 | dir); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2829 | /* restore sg */ |
| 2830 | sg->length += qc->pad_len; |
| 2831 | if (pad_buf) |
| 2832 | memcpy(qc->buf_virt + sg->length - qc->pad_len, |
| 2833 | pad_buf, qc->pad_len); |
| 2834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | |
| 2836 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2837 | qc->__sg = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | /** |
| 2841 | * ata_fill_sg - Fill PCI IDE PRD table |
| 2842 | * @qc: Metadata associated with taskfile to be transferred |
| 2843 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2844 | * Fill PCI IDE PRD (scatter-gather) table with segments |
| 2845 | * associated with the current disk command. |
| 2846 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | * LOCKING: |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2848 | * spin_lock_irqsave(host_set lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | * |
| 2850 | */ |
| 2851 | static void ata_fill_sg(struct ata_queued_cmd *qc) |
| 2852 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | struct ata_port *ap = qc->ap; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2854 | struct scatterlist *sg; |
| 2855 | unsigned int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 2857 | WARN_ON(qc->__sg == NULL); |
Jeff Garzik | f131883 | 2006-02-20 16:55:56 -0500 | [diff] [blame] | 2858 | WARN_ON(qc->n_elem == 0 && qc->pad_len == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | |
| 2860 | idx = 0; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2861 | ata_for_each_sg(sg, qc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | u32 addr, offset; |
| 2863 | u32 sg_len, len; |
| 2864 | |
| 2865 | /* determine if physical DMA addr spans 64K boundary. |
| 2866 | * Note h/w doesn't support 64-bit, so we unconditionally |
| 2867 | * truncate dma_addr_t to u32. |
| 2868 | */ |
| 2869 | addr = (u32) sg_dma_address(sg); |
| 2870 | sg_len = sg_dma_len(sg); |
| 2871 | |
| 2872 | while (sg_len) { |
| 2873 | offset = addr & 0xffff; |
| 2874 | len = sg_len; |
| 2875 | if ((offset + sg_len) > 0x10000) |
| 2876 | len = 0x10000 - offset; |
| 2877 | |
| 2878 | ap->prd[idx].addr = cpu_to_le32(addr); |
| 2879 | ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff); |
| 2880 | VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len); |
| 2881 | |
| 2882 | idx++; |
| 2883 | sg_len -= len; |
| 2884 | addr += len; |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | if (idx) |
| 2889 | ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); |
| 2890 | } |
| 2891 | /** |
| 2892 | * ata_check_atapi_dma - Check whether ATAPI DMA can be supported |
| 2893 | * @qc: Metadata associated with taskfile to check |
| 2894 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2895 | * Allow low-level driver to filter ATA PACKET commands, returning |
| 2896 | * a status indicating whether or not it is OK to use DMA for the |
| 2897 | * supplied PACKET command. |
| 2898 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2900 | * spin_lock_irqsave(host_set lock) |
| 2901 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | * RETURNS: 0 when ATAPI DMA can be used |
| 2903 | * nonzero otherwise |
| 2904 | */ |
| 2905 | int ata_check_atapi_dma(struct ata_queued_cmd *qc) |
| 2906 | { |
| 2907 | struct ata_port *ap = qc->ap; |
| 2908 | int rc = 0; /* Assume ATAPI DMA is OK by default */ |
| 2909 | |
| 2910 | if (ap->ops->check_atapi_dma) |
| 2911 | rc = ap->ops->check_atapi_dma(qc); |
| 2912 | |
| 2913 | return rc; |
| 2914 | } |
| 2915 | /** |
| 2916 | * ata_qc_prep - Prepare taskfile for submission |
| 2917 | * @qc: Metadata associated with taskfile to be prepared |
| 2918 | * |
Jeff Garzik | 780a87f | 2005-05-30 15:41:05 -0400 | [diff] [blame] | 2919 | * Prepare ATA taskfile for submission. |
| 2920 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | * LOCKING: |
| 2922 | * spin_lock_irqsave(host_set lock) |
| 2923 | */ |
| 2924 | void ata_qc_prep(struct ata_queued_cmd *qc) |
| 2925 | { |
| 2926 | if (!(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 2927 | return; |
| 2928 | |
| 2929 | ata_fill_sg(qc); |
| 2930 | } |
| 2931 | |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2932 | /** |
| 2933 | * ata_sg_init_one - Associate command with memory buffer |
| 2934 | * @qc: Command to be associated |
| 2935 | * @buf: Memory buffer |
| 2936 | * @buflen: Length of memory buffer, in bytes. |
| 2937 | * |
| 2938 | * Initialize the data-related elements of queued_cmd @qc |
| 2939 | * to point to a single memory buffer, @buf of byte length @buflen. |
| 2940 | * |
| 2941 | * LOCKING: |
| 2942 | * spin_lock_irqsave(host_set lock) |
| 2943 | */ |
| 2944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) |
| 2946 | { |
| 2947 | struct scatterlist *sg; |
| 2948 | |
| 2949 | qc->flags |= ATA_QCFLAG_SINGLE; |
| 2950 | |
| 2951 | memset(&qc->sgent, 0, sizeof(qc->sgent)); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2952 | qc->__sg = &qc->sgent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | qc->n_elem = 1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2954 | qc->orig_n_elem = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | qc->buf_virt = buf; |
| 2956 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2957 | sg = qc->__sg; |
Jeff Garzik | f0612bb | 2005-10-30 01:58:18 -0500 | [diff] [blame] | 2958 | sg_init_one(sg, buf, buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | } |
| 2960 | |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2961 | /** |
| 2962 | * ata_sg_init - Associate command with scatter-gather table. |
| 2963 | * @qc: Command to be associated |
| 2964 | * @sg: Scatter-gather table. |
| 2965 | * @n_elem: Number of elements in s/g table. |
| 2966 | * |
| 2967 | * Initialize the data-related elements of queued_cmd @qc |
| 2968 | * to point to a scatter-gather table @sg, containing @n_elem |
| 2969 | * elements. |
| 2970 | * |
| 2971 | * LOCKING: |
| 2972 | * spin_lock_irqsave(host_set lock) |
| 2973 | */ |
| 2974 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
| 2976 | unsigned int n_elem) |
| 2977 | { |
| 2978 | qc->flags |= ATA_QCFLAG_SG; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2979 | qc->__sg = sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | qc->n_elem = n_elem; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 2981 | qc->orig_n_elem = n_elem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2985 | * ata_sg_setup_one - DMA-map the memory buffer associated with a command. |
| 2986 | * @qc: Command with memory buffer to be mapped. |
| 2987 | * |
| 2988 | * DMA-map the memory buffer associated with queued_cmd @qc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | * |
| 2990 | * LOCKING: |
| 2991 | * spin_lock_irqsave(host_set lock) |
| 2992 | * |
| 2993 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 2994 | * Zero on success, negative on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | */ |
| 2996 | |
| 2997 | static int ata_sg_setup_one(struct ata_queued_cmd *qc) |
| 2998 | { |
| 2999 | struct ata_port *ap = qc->ap; |
| 3000 | int dir = qc->dma_dir; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3001 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | dma_addr_t dma_address; |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 3003 | int trim_sg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3005 | /* we must lengthen transfers to end on a 32-bit boundary */ |
| 3006 | qc->pad_len = sg->length & 3; |
| 3007 | if (qc->pad_len) { |
| 3008 | void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); |
| 3009 | struct scatterlist *psg = &qc->pad_sgent; |
| 3010 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3011 | WARN_ON(qc->dev->class != ATA_DEV_ATAPI); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3012 | |
| 3013 | memset(pad_buf, 0, ATA_DMA_PAD_SZ); |
| 3014 | |
| 3015 | if (qc->tf.flags & ATA_TFLAG_WRITE) |
| 3016 | memcpy(pad_buf, qc->buf_virt + sg->length - qc->pad_len, |
| 3017 | qc->pad_len); |
| 3018 | |
| 3019 | sg_dma_address(psg) = ap->pad_dma + (qc->tag * ATA_DMA_PAD_SZ); |
| 3020 | sg_dma_len(psg) = ATA_DMA_PAD_SZ; |
| 3021 | /* trim sg */ |
| 3022 | sg->length -= qc->pad_len; |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 3023 | if (sg->length == 0) |
| 3024 | trim_sg = 1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3025 | |
| 3026 | DPRINTK("padding done, sg->length=%u pad_len=%u\n", |
| 3027 | sg->length, qc->pad_len); |
| 3028 | } |
| 3029 | |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 3030 | if (trim_sg) { |
| 3031 | qc->n_elem--; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 3032 | goto skip_map; |
| 3033 | } |
| 3034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 3036 | sg->length, dir); |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 3037 | if (dma_mapping_error(dma_address)) { |
| 3038 | /* restore sg */ |
| 3039 | sg->length += qc->pad_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | return -1; |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 3041 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | |
| 3043 | sg_dma_address(sg) = dma_address; |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 3044 | sg_dma_len(sg) = sg->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
Tejun Heo | 2e242fa | 2006-02-20 23:48:38 +0900 | [diff] [blame] | 3046 | skip_map: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), |
| 3048 | qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 3049 | |
| 3050 | return 0; |
| 3051 | } |
| 3052 | |
| 3053 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3054 | * ata_sg_setup - DMA-map the scatter-gather table associated with a command. |
| 3055 | * @qc: Command with scatter-gather table to be mapped. |
| 3056 | * |
| 3057 | * DMA-map the scatter-gather table associated with queued_cmd @qc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | * |
| 3059 | * LOCKING: |
| 3060 | * spin_lock_irqsave(host_set lock) |
| 3061 | * |
| 3062 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3063 | * Zero on success, negative on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | * |
| 3065 | */ |
| 3066 | |
| 3067 | static int ata_sg_setup(struct ata_queued_cmd *qc) |
| 3068 | { |
| 3069 | struct ata_port *ap = qc->ap; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3070 | struct scatterlist *sg = qc->__sg; |
| 3071 | struct scatterlist *lsg = &sg[qc->n_elem - 1]; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 3072 | int n_elem, pre_n_elem, dir, trim_sg = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | |
| 3074 | VPRINTK("ENTER, ata%u\n", ap->id); |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3075 | WARN_ON(!(qc->flags & ATA_QCFLAG_SG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3077 | /* we must lengthen transfers to end on a 32-bit boundary */ |
| 3078 | qc->pad_len = lsg->length & 3; |
| 3079 | if (qc->pad_len) { |
| 3080 | void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ); |
| 3081 | struct scatterlist *psg = &qc->pad_sgent; |
| 3082 | unsigned int offset; |
| 3083 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3084 | WARN_ON(qc->dev->class != ATA_DEV_ATAPI); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3085 | |
| 3086 | memset(pad_buf, 0, ATA_DMA_PAD_SZ); |
| 3087 | |
| 3088 | /* |
| 3089 | * psg->page/offset are used to copy to-be-written |
| 3090 | * data in this function or read data in ata_sg_clean. |
| 3091 | */ |
| 3092 | offset = lsg->offset + lsg->length - qc->pad_len; |
| 3093 | psg->page = nth_page(lsg->page, offset >> PAGE_SHIFT); |
| 3094 | psg->offset = offset_in_page(offset); |
| 3095 | |
| 3096 | if (qc->tf.flags & ATA_TFLAG_WRITE) { |
| 3097 | void *addr = kmap_atomic(psg->page, KM_IRQ0); |
| 3098 | memcpy(pad_buf, addr + psg->offset, qc->pad_len); |
Mark Lord | dfa1598 | 2005-12-12 23:19:28 -0500 | [diff] [blame] | 3099 | kunmap_atomic(addr, KM_IRQ0); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | sg_dma_address(psg) = ap->pad_dma + (qc->tag * ATA_DMA_PAD_SZ); |
| 3103 | sg_dma_len(psg) = ATA_DMA_PAD_SZ; |
| 3104 | /* trim last sg */ |
| 3105 | lsg->length -= qc->pad_len; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 3106 | if (lsg->length == 0) |
| 3107 | trim_sg = 1; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3108 | |
| 3109 | DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n", |
| 3110 | qc->n_elem - 1, lsg->length, qc->pad_len); |
| 3111 | } |
| 3112 | |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 3113 | pre_n_elem = qc->n_elem; |
| 3114 | if (trim_sg && pre_n_elem) |
| 3115 | pre_n_elem--; |
| 3116 | |
| 3117 | if (!pre_n_elem) { |
| 3118 | n_elem = 0; |
| 3119 | goto skip_map; |
| 3120 | } |
| 3121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | dir = qc->dma_dir; |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 3123 | n_elem = dma_map_sg(ap->host_set->dev, sg, pre_n_elem, dir); |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 3124 | if (n_elem < 1) { |
| 3125 | /* restore last sg */ |
| 3126 | lsg->length += qc->pad_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | return -1; |
Tejun Heo | 537a95d | 2005-11-05 14:29:01 -0500 | [diff] [blame] | 3128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3129 | |
| 3130 | DPRINTK("%d sg elements mapped\n", n_elem); |
| 3131 | |
Jeff Garzik | e1410f2 | 2005-11-14 14:06:26 -0500 | [diff] [blame] | 3132 | skip_map: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | qc->n_elem = n_elem; |
| 3134 | |
| 3135 | return 0; |
| 3136 | } |
| 3137 | |
| 3138 | /** |
Tejun Heo | 40e8c82 | 2005-08-22 17:12:45 +0900 | [diff] [blame] | 3139 | * ata_poll_qc_complete - turn irq back on and finish qc |
| 3140 | * @qc: Command to complete |
Randy Dunlap | 8e8b77d | 2005-11-01 21:29:27 -0800 | [diff] [blame] | 3141 | * @err_mask: ATA status register content |
Tejun Heo | 40e8c82 | 2005-08-22 17:12:45 +0900 | [diff] [blame] | 3142 | * |
| 3143 | * LOCKING: |
| 3144 | * None. (grabs host lock) |
| 3145 | */ |
| 3146 | |
Albert Lee | a22e2eb | 2005-12-05 15:38:02 +0800 | [diff] [blame] | 3147 | void ata_poll_qc_complete(struct ata_queued_cmd *qc) |
Tejun Heo | 40e8c82 | 2005-08-22 17:12:45 +0900 | [diff] [blame] | 3148 | { |
| 3149 | struct ata_port *ap = qc->ap; |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3150 | unsigned long flags; |
Tejun Heo | 40e8c82 | 2005-08-22 17:12:45 +0900 | [diff] [blame] | 3151 | |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3152 | spin_lock_irqsave(&ap->host_set->lock, flags); |
Tejun Heo | 40e8c82 | 2005-08-22 17:12:45 +0900 | [diff] [blame] | 3153 | ap->flags &= ~ATA_FLAG_NOINTR; |
| 3154 | ata_irq_on(ap); |
Albert Lee | a22e2eb | 2005-12-05 15:38:02 +0800 | [diff] [blame] | 3155 | ata_qc_complete(qc); |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3156 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
Tejun Heo | 40e8c82 | 2005-08-22 17:12:45 +0900 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | /** |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 3160 | * ata_pio_poll - poll using PIO, depending on current state |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 3161 | * @ap: the target ata_port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | * |
| 3163 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3164 | * None. (executing in kernel thread context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3165 | * |
| 3166 | * RETURNS: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 3167 | * timeout value to use |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | */ |
| 3169 | |
| 3170 | static unsigned long ata_pio_poll(struct ata_port *ap) |
| 3171 | { |
Albert Lee | c14b833 | 2005-12-05 15:36:08 +0800 | [diff] [blame] | 3172 | struct ata_queued_cmd *qc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | u8 status; |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3174 | unsigned int poll_state = HSM_ST_UNKNOWN; |
| 3175 | unsigned int reg_state = HSM_ST_UNKNOWN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | |
Albert Lee | c14b833 | 2005-12-05 15:36:08 +0800 | [diff] [blame] | 3177 | qc = ata_qc_from_tag(ap, ap->active_tag); |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3178 | WARN_ON(qc == NULL); |
Albert Lee | c14b833 | 2005-12-05 15:36:08 +0800 | [diff] [blame] | 3179 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3180 | switch (ap->hsm_task_state) { |
| 3181 | case HSM_ST: |
| 3182 | case HSM_ST_POLL: |
| 3183 | poll_state = HSM_ST_POLL; |
| 3184 | reg_state = HSM_ST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | break; |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3186 | case HSM_ST_LAST: |
| 3187 | case HSM_ST_LAST_POLL: |
| 3188 | poll_state = HSM_ST_LAST_POLL; |
| 3189 | reg_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | break; |
| 3191 | default: |
| 3192 | BUG(); |
| 3193 | break; |
| 3194 | } |
| 3195 | |
| 3196 | status = ata_chk_status(ap); |
| 3197 | if (status & ATA_BUSY) { |
| 3198 | if (time_after(jiffies, ap->pio_task_timeout)) { |
Tejun Heo | 11a56d2 | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 3199 | qc->err_mask |= AC_ERR_TIMEOUT; |
Albert Lee | 7c39833 | 2005-11-09 13:03:30 +0800 | [diff] [blame] | 3200 | ap->hsm_task_state = HSM_ST_TMOUT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | return 0; |
| 3202 | } |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3203 | ap->hsm_task_state = poll_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | return ATA_SHORT_PAUSE; |
| 3205 | } |
| 3206 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3207 | ap->hsm_task_state = reg_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | return 0; |
| 3209 | } |
| 3210 | |
| 3211 | /** |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 3212 | * ata_pio_complete - check if drive is busy or idle |
| 3213 | * @ap: the target ata_port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | * |
| 3215 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3216 | * None. (executing in kernel thread context) |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3217 | * |
| 3218 | * RETURNS: |
| 3219 | * Non-zero if qc completed, zero otherwise. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | */ |
| 3221 | |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3222 | static int ata_pio_complete (struct ata_port *ap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | { |
| 3224 | struct ata_queued_cmd *qc; |
| 3225 | u8 drv_stat; |
| 3226 | |
| 3227 | /* |
Alan Cox | 31433ea | 2005-08-26 15:56:47 +0100 | [diff] [blame] | 3228 | * This is purely heuristic. This is a fast path. Sometimes when |
| 3229 | * we enter, BSY will be cleared in a chk-status or two. If not, |
| 3230 | * the drive is probably seeking or something. Snooze for a couple |
| 3231 | * msecs, then chk-status again. If still busy, fall back to |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3232 | * HSM_ST_POLL state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | */ |
Albert Lee | fe79e68 | 2005-12-06 11:34:59 +0800 | [diff] [blame] | 3234 | drv_stat = ata_busy_wait(ap, ATA_BUSY, 10); |
| 3235 | if (drv_stat & ATA_BUSY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | msleep(2); |
Albert Lee | fe79e68 | 2005-12-06 11:34:59 +0800 | [diff] [blame] | 3237 | drv_stat = ata_busy_wait(ap, ATA_BUSY, 10); |
| 3238 | if (drv_stat & ATA_BUSY) { |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3239 | ap->hsm_task_state = HSM_ST_LAST_POLL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3241 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | } |
| 3243 | } |
| 3244 | |
Albert Lee | c14b833 | 2005-12-05 15:36:08 +0800 | [diff] [blame] | 3245 | qc = ata_qc_from_tag(ap, ap->active_tag); |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3246 | WARN_ON(qc == NULL); |
Albert Lee | c14b833 | 2005-12-05 15:36:08 +0800 | [diff] [blame] | 3247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | drv_stat = ata_wait_idle(ap); |
| 3249 | if (!ata_ok(drv_stat)) { |
Albert Lee | 1c84898 | 2005-12-05 15:40:15 +0800 | [diff] [blame] | 3250 | qc->err_mask |= __ac_err_mask(drv_stat); |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3251 | ap->hsm_task_state = HSM_ST_ERR; |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3252 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3255 | ap->hsm_task_state = HSM_ST_IDLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3257 | WARN_ON(qc->err_mask); |
Albert Lee | a22e2eb | 2005-12-05 15:38:02 +0800 | [diff] [blame] | 3258 | ata_poll_qc_complete(qc); |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3259 | |
| 3260 | /* another command may start at this point */ |
| 3261 | |
| 3262 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 3265 | |
| 3266 | /** |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 3267 | * swap_buf_le16 - swap halves of 16-bit words in place |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 3268 | * @buf: Buffer to swap |
| 3269 | * @buf_words: Number of 16-bit words in buffer. |
| 3270 | * |
| 3271 | * Swap halves of 16-bit words if needed to convert from |
| 3272 | * little-endian byte order to native cpu byte order, or |
| 3273 | * vice-versa. |
| 3274 | * |
| 3275 | * LOCKING: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 3276 | * Inherited from caller. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 3277 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | void swap_buf_le16(u16 *buf, unsigned int buf_words) |
| 3279 | { |
| 3280 | #ifdef __BIG_ENDIAN |
| 3281 | unsigned int i; |
| 3282 | |
| 3283 | for (i = 0; i < buf_words; i++) |
| 3284 | buf[i] = le16_to_cpu(buf[i]); |
| 3285 | #endif /* __BIG_ENDIAN */ |
| 3286 | } |
| 3287 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3288 | /** |
| 3289 | * ata_mmio_data_xfer - Transfer data by MMIO |
| 3290 | * @ap: port to read/write |
| 3291 | * @buf: data buffer |
| 3292 | * @buflen: buffer length |
Jeff Garzik | 344baba | 2005-09-07 01:15:17 -0400 | [diff] [blame] | 3293 | * @write_data: read/write |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3294 | * |
| 3295 | * Transfer data from/to the device data register by MMIO. |
| 3296 | * |
| 3297 | * LOCKING: |
| 3298 | * Inherited from caller. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3299 | */ |
| 3300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | static void ata_mmio_data_xfer(struct ata_port *ap, unsigned char *buf, |
| 3302 | unsigned int buflen, int write_data) |
| 3303 | { |
| 3304 | unsigned int i; |
| 3305 | unsigned int words = buflen >> 1; |
| 3306 | u16 *buf16 = (u16 *) buf; |
| 3307 | void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr; |
| 3308 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3309 | /* Transfer multiple of 2 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | if (write_data) { |
| 3311 | for (i = 0; i < words; i++) |
| 3312 | writew(le16_to_cpu(buf16[i]), mmio); |
| 3313 | } else { |
| 3314 | for (i = 0; i < words; i++) |
| 3315 | buf16[i] = cpu_to_le16(readw(mmio)); |
| 3316 | } |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3317 | |
| 3318 | /* Transfer trailing 1 byte, if any. */ |
| 3319 | if (unlikely(buflen & 0x01)) { |
| 3320 | u16 align_buf[1] = { 0 }; |
| 3321 | unsigned char *trailing_buf = buf + buflen - 1; |
| 3322 | |
| 3323 | if (write_data) { |
| 3324 | memcpy(align_buf, trailing_buf, 1); |
| 3325 | writew(le16_to_cpu(align_buf[0]), mmio); |
| 3326 | } else { |
| 3327 | align_buf[0] = cpu_to_le16(readw(mmio)); |
| 3328 | memcpy(trailing_buf, align_buf, 1); |
| 3329 | } |
| 3330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3331 | } |
| 3332 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3333 | /** |
| 3334 | * ata_pio_data_xfer - Transfer data by PIO |
| 3335 | * @ap: port to read/write |
| 3336 | * @buf: data buffer |
| 3337 | * @buflen: buffer length |
Jeff Garzik | 344baba | 2005-09-07 01:15:17 -0400 | [diff] [blame] | 3338 | * @write_data: read/write |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3339 | * |
| 3340 | * Transfer data from/to the device data register by PIO. |
| 3341 | * |
| 3342 | * LOCKING: |
| 3343 | * Inherited from caller. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3344 | */ |
| 3345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3346 | static void ata_pio_data_xfer(struct ata_port *ap, unsigned char *buf, |
| 3347 | unsigned int buflen, int write_data) |
| 3348 | { |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3349 | unsigned int words = buflen >> 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3351 | /* Transfer multiple of 2 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | if (write_data) |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3353 | outsw(ap->ioaddr.data_addr, buf, words); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | else |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3355 | insw(ap->ioaddr.data_addr, buf, words); |
| 3356 | |
| 3357 | /* Transfer trailing 1 byte, if any. */ |
| 3358 | if (unlikely(buflen & 0x01)) { |
| 3359 | u16 align_buf[1] = { 0 }; |
| 3360 | unsigned char *trailing_buf = buf + buflen - 1; |
| 3361 | |
| 3362 | if (write_data) { |
| 3363 | memcpy(align_buf, trailing_buf, 1); |
| 3364 | outw(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr); |
| 3365 | } else { |
| 3366 | align_buf[0] = cpu_to_le16(inw(ap->ioaddr.data_addr)); |
| 3367 | memcpy(trailing_buf, align_buf, 1); |
| 3368 | } |
| 3369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3372 | /** |
| 3373 | * ata_data_xfer - Transfer data from/to the data register. |
| 3374 | * @ap: port to read/write |
| 3375 | * @buf: data buffer |
| 3376 | * @buflen: buffer length |
| 3377 | * @do_write: read/write |
| 3378 | * |
| 3379 | * Transfer data from/to the device data register. |
| 3380 | * |
| 3381 | * LOCKING: |
| 3382 | * Inherited from caller. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3383 | */ |
| 3384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | static void ata_data_xfer(struct ata_port *ap, unsigned char *buf, |
| 3386 | unsigned int buflen, int do_write) |
| 3387 | { |
Alan Cox | a1bd9e6 | 2006-01-17 20:53:50 +0000 | [diff] [blame] | 3388 | /* Make the crap hardware pay the costs not the good stuff */ |
| 3389 | if (unlikely(ap->flags & ATA_FLAG_IRQ_MASK)) { |
| 3390 | unsigned long flags; |
| 3391 | local_irq_save(flags); |
| 3392 | if (ap->flags & ATA_FLAG_MMIO) |
| 3393 | ata_mmio_data_xfer(ap, buf, buflen, do_write); |
| 3394 | else |
| 3395 | ata_pio_data_xfer(ap, buf, buflen, do_write); |
| 3396 | local_irq_restore(flags); |
| 3397 | } else { |
| 3398 | if (ap->flags & ATA_FLAG_MMIO) |
| 3399 | ata_mmio_data_xfer(ap, buf, buflen, do_write); |
| 3400 | else |
| 3401 | ata_pio_data_xfer(ap, buf, buflen, do_write); |
| 3402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3405 | /** |
| 3406 | * ata_pio_sector - Transfer ATA_SECT_SIZE (512 bytes) of data. |
| 3407 | * @qc: Command on going |
| 3408 | * |
| 3409 | * Transfer ATA_SECT_SIZE of data from/to the ATA device. |
| 3410 | * |
| 3411 | * LOCKING: |
| 3412 | * Inherited from caller. |
| 3413 | */ |
| 3414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | static void ata_pio_sector(struct ata_queued_cmd *qc) |
| 3416 | { |
| 3417 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3418 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | struct ata_port *ap = qc->ap; |
| 3420 | struct page *page; |
| 3421 | unsigned int offset; |
| 3422 | unsigned char *buf; |
| 3423 | |
| 3424 | if (qc->cursect == (qc->nsect - 1)) |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3425 | ap->hsm_task_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | |
| 3427 | page = sg[qc->cursg].page; |
| 3428 | offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; |
| 3429 | |
| 3430 | /* get the current page and offset */ |
| 3431 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 3432 | offset %= PAGE_SIZE; |
| 3433 | |
| 3434 | buf = kmap(page) + offset; |
| 3435 | |
| 3436 | qc->cursect++; |
| 3437 | qc->cursg_ofs++; |
| 3438 | |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 3439 | if ((qc->cursg_ofs * ATA_SECT_SIZE) == (&sg[qc->cursg])->length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | qc->cursg++; |
| 3441 | qc->cursg_ofs = 0; |
| 3442 | } |
| 3443 | |
| 3444 | DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 3445 | |
| 3446 | /* do the actual data transfer */ |
| 3447 | do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
| 3448 | ata_data_xfer(ap, buf, ATA_SECT_SIZE, do_write); |
| 3449 | |
| 3450 | kunmap(page); |
| 3451 | } |
| 3452 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3453 | /** |
| 3454 | * __atapi_pio_bytes - Transfer data from/to the ATAPI device. |
| 3455 | * @qc: Command on going |
| 3456 | * @bytes: number of bytes |
| 3457 | * |
| 3458 | * Transfer Transfer data from/to the ATAPI device. |
| 3459 | * |
| 3460 | * LOCKING: |
| 3461 | * Inherited from caller. |
| 3462 | * |
| 3463 | */ |
| 3464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3465 | static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) |
| 3466 | { |
| 3467 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3468 | struct scatterlist *sg = qc->__sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3469 | struct ata_port *ap = qc->ap; |
| 3470 | struct page *page; |
| 3471 | unsigned char *buf; |
| 3472 | unsigned int offset, count; |
| 3473 | |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 3474 | if (qc->curbytes + bytes >= qc->nbytes) |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3475 | ap->hsm_task_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
| 3477 | next_sg: |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 3478 | if (unlikely(qc->cursg >= qc->n_elem)) { |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3479 | /* |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 3480 | * The end of qc->sg is reached and the device expects |
| 3481 | * more data to transfer. In order not to overrun qc->sg |
| 3482 | * and fulfill length specified in the byte count register, |
| 3483 | * - for read case, discard trailing data from the device |
| 3484 | * - for write case, padding zero data to the device |
| 3485 | */ |
| 3486 | u16 pad_buf[1] = { 0 }; |
| 3487 | unsigned int words = bytes >> 1; |
| 3488 | unsigned int i; |
| 3489 | |
| 3490 | if (words) /* warning if bytes > 1 */ |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3491 | printk(KERN_WARNING "ata%u: %u bytes trailing data\n", |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 3492 | ap->id, bytes); |
| 3493 | |
| 3494 | for (i = 0; i < words; i++) |
| 3495 | ata_data_xfer(ap, (unsigned char*)pad_buf, 2, do_write); |
| 3496 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3497 | ap->hsm_task_state = HSM_ST_LAST; |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 3498 | return; |
| 3499 | } |
| 3500 | |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 3501 | sg = &qc->__sg[qc->cursg]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | page = sg->page; |
| 3504 | offset = sg->offset + qc->cursg_ofs; |
| 3505 | |
| 3506 | /* get the current page and offset */ |
| 3507 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 3508 | offset %= PAGE_SIZE; |
| 3509 | |
Albert Lee | 6952df0 | 2005-06-06 15:56:03 +0800 | [diff] [blame] | 3510 | /* don't overrun current sg */ |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 3511 | count = min(sg->length - qc->cursg_ofs, bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | |
| 3513 | /* don't cross page boundaries */ |
| 3514 | count = min(count, (unsigned int)PAGE_SIZE - offset); |
| 3515 | |
| 3516 | buf = kmap(page) + offset; |
| 3517 | |
| 3518 | bytes -= count; |
| 3519 | qc->curbytes += count; |
| 3520 | qc->cursg_ofs += count; |
| 3521 | |
Albert Lee | 32529e0 | 2005-05-26 03:49:42 -0400 | [diff] [blame] | 3522 | if (qc->cursg_ofs == sg->length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | qc->cursg++; |
| 3524 | qc->cursg_ofs = 0; |
| 3525 | } |
| 3526 | |
| 3527 | DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 3528 | |
| 3529 | /* do the actual data transfer */ |
| 3530 | ata_data_xfer(ap, buf, count, do_write); |
| 3531 | |
| 3532 | kunmap(page); |
| 3533 | |
Albert Lee | 563a6e1 | 2005-08-12 14:17:50 +0800 | [diff] [blame] | 3534 | if (bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | goto next_sg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3538 | /** |
| 3539 | * atapi_pio_bytes - Transfer data from/to the ATAPI device. |
| 3540 | * @qc: Command on going |
| 3541 | * |
| 3542 | * Transfer Transfer data from/to the ATAPI device. |
| 3543 | * |
| 3544 | * LOCKING: |
| 3545 | * Inherited from caller. |
Albert Lee | 6ae4cfb | 2005-08-12 14:15:34 +0800 | [diff] [blame] | 3546 | */ |
| 3547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) |
| 3549 | { |
| 3550 | struct ata_port *ap = qc->ap; |
| 3551 | struct ata_device *dev = qc->dev; |
| 3552 | unsigned int ireason, bc_lo, bc_hi, bytes; |
| 3553 | int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; |
| 3554 | |
| 3555 | ap->ops->tf_read(ap, &qc->tf); |
| 3556 | ireason = qc->tf.nsect; |
| 3557 | bc_lo = qc->tf.lbam; |
| 3558 | bc_hi = qc->tf.lbah; |
| 3559 | bytes = (bc_hi << 8) | bc_lo; |
| 3560 | |
| 3561 | /* shall be cleared to zero, indicating xfer of data */ |
| 3562 | if (ireason & (1 << 0)) |
| 3563 | goto err_out; |
| 3564 | |
| 3565 | /* make sure transfer direction matches expected */ |
| 3566 | i_write = ((ireason & (1 << 1)) == 0) ? 1 : 0; |
| 3567 | if (do_write != i_write) |
| 3568 | goto err_out; |
| 3569 | |
| 3570 | __atapi_pio_bytes(qc, bytes); |
| 3571 | |
| 3572 | return; |
| 3573 | |
| 3574 | err_out: |
| 3575 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", |
| 3576 | ap->id, dev->devno); |
Tejun Heo | 11a56d2 | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 3577 | qc->err_mask |= AC_ERR_HSM; |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3578 | ap->hsm_task_state = HSM_ST_ERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | /** |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 3582 | * ata_pio_block - start PIO on a block |
| 3583 | * @ap: the target ata_port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | * |
| 3585 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3586 | * None. (executing in kernel thread context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | */ |
| 3588 | |
| 3589 | static void ata_pio_block(struct ata_port *ap) |
| 3590 | { |
| 3591 | struct ata_queued_cmd *qc; |
| 3592 | u8 status; |
| 3593 | |
| 3594 | /* |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 3595 | * This is purely heuristic. This is a fast path. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | * Sometimes when we enter, BSY will be cleared in |
| 3597 | * a chk-status or two. If not, the drive is probably seeking |
| 3598 | * or something. Snooze for a couple msecs, then |
| 3599 | * chk-status again. If still busy, fall back to |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3600 | * HSM_ST_POLL state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | */ |
| 3602 | status = ata_busy_wait(ap, ATA_BUSY, 5); |
| 3603 | if (status & ATA_BUSY) { |
| 3604 | msleep(2); |
| 3605 | status = ata_busy_wait(ap, ATA_BUSY, 10); |
| 3606 | if (status & ATA_BUSY) { |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3607 | ap->hsm_task_state = HSM_ST_POLL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | ap->pio_task_timeout = jiffies + ATA_TMOUT_PIO; |
| 3609 | return; |
| 3610 | } |
| 3611 | } |
| 3612 | |
| 3613 | qc = ata_qc_from_tag(ap, ap->active_tag); |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3614 | WARN_ON(qc == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | |
Albert Lee | fe79e68 | 2005-12-06 11:34:59 +0800 | [diff] [blame] | 3616 | /* check error */ |
| 3617 | if (status & (ATA_ERR | ATA_DF)) { |
| 3618 | qc->err_mask |= AC_ERR_DEV; |
| 3619 | ap->hsm_task_state = HSM_ST_ERR; |
| 3620 | return; |
| 3621 | } |
| 3622 | |
| 3623 | /* transfer data if any */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | if (is_atapi_taskfile(&qc->tf)) { |
Albert Lee | fe79e68 | 2005-12-06 11:34:59 +0800 | [diff] [blame] | 3625 | /* DRQ=0 means no more data to transfer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | if ((status & ATA_DRQ) == 0) { |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3627 | ap->hsm_task_state = HSM_ST_LAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | return; |
| 3629 | } |
| 3630 | |
| 3631 | atapi_pio_bytes(qc); |
| 3632 | } else { |
| 3633 | /* handle BSY=0, DRQ=0 as error */ |
| 3634 | if ((status & ATA_DRQ) == 0) { |
Tejun Heo | 11a56d2 | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 3635 | qc->err_mask |= AC_ERR_HSM; |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3636 | ap->hsm_task_state = HSM_ST_ERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3637 | return; |
| 3638 | } |
| 3639 | |
| 3640 | ata_pio_sector(qc); |
| 3641 | } |
| 3642 | } |
| 3643 | |
| 3644 | static void ata_pio_error(struct ata_port *ap) |
| 3645 | { |
| 3646 | struct ata_queued_cmd *qc; |
Jeff Garzik | a7dac44 | 2005-10-30 04:44:42 -0500 | [diff] [blame] | 3647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | qc = ata_qc_from_tag(ap, ap->active_tag); |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3649 | WARN_ON(qc == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | |
Albert Lee | 0565c26 | 2006-02-13 18:55:25 +0800 | [diff] [blame] | 3651 | if (qc->tf.command != ATA_CMD_PACKET) |
| 3652 | printk(KERN_WARNING "ata%u: PIO error\n", ap->id); |
| 3653 | |
Albert Lee | 1c84898 | 2005-12-05 15:40:15 +0800 | [diff] [blame] | 3654 | /* make sure qc->err_mask is available to |
| 3655 | * know what's wrong and recover |
| 3656 | */ |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3657 | WARN_ON(qc->err_mask == 0); |
Albert Lee | 1c84898 | 2005-12-05 15:40:15 +0800 | [diff] [blame] | 3658 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3659 | ap->hsm_task_state = HSM_ST_IDLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | |
Albert Lee | a22e2eb | 2005-12-05 15:38:02 +0800 | [diff] [blame] | 3661 | ata_poll_qc_complete(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | static void ata_pio_task(void *_data) |
| 3665 | { |
| 3666 | struct ata_port *ap = _data; |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3667 | unsigned long timeout; |
| 3668 | int qc_completed; |
| 3669 | |
| 3670 | fsm_start: |
| 3671 | timeout = 0; |
| 3672 | qc_completed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3673 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3674 | switch (ap->hsm_task_state) { |
| 3675 | case HSM_ST_IDLE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | return; |
| 3677 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3678 | case HSM_ST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | ata_pio_block(ap); |
| 3680 | break; |
| 3681 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3682 | case HSM_ST_LAST: |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3683 | qc_completed = ata_pio_complete(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | break; |
| 3685 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3686 | case HSM_ST_POLL: |
| 3687 | case HSM_ST_LAST_POLL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | timeout = ata_pio_poll(ap); |
| 3689 | break; |
| 3690 | |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 3691 | case HSM_ST_TMOUT: |
| 3692 | case HSM_ST_ERR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | ata_pio_error(ap); |
| 3694 | return; |
| 3695 | } |
| 3696 | |
| 3697 | if (timeout) |
Tejun Heo | 8061f5f | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 3698 | ata_port_queue_task(ap, ata_pio_task, ap, timeout); |
Jeff Garzik | 7fb6ec2 | 2005-09-16 06:01:48 -0400 | [diff] [blame] | 3699 | else if (!qc_completed) |
| 3700 | goto fsm_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | /** |
Tejun Heo | 8061f5f | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 3704 | * atapi_packet_task - Write CDB bytes to hardware |
| 3705 | * @_data: Port to which ATAPI device is attached. |
| 3706 | * |
| 3707 | * When device has indicated its readiness to accept |
| 3708 | * a CDB, this function is called. Send the CDB. |
| 3709 | * If DMA is to be performed, exit immediately. |
| 3710 | * Otherwise, we are in polling mode, so poll |
| 3711 | * status under operation succeeds or fails. |
| 3712 | * |
| 3713 | * LOCKING: |
| 3714 | * Kernel thread context (may sleep) |
| 3715 | */ |
| 3716 | |
| 3717 | static void atapi_packet_task(void *_data) |
| 3718 | { |
| 3719 | struct ata_port *ap = _data; |
| 3720 | struct ata_queued_cmd *qc; |
| 3721 | u8 status; |
| 3722 | |
| 3723 | qc = ata_qc_from_tag(ap, ap->active_tag); |
| 3724 | WARN_ON(qc == NULL); |
| 3725 | WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); |
| 3726 | |
| 3727 | /* sleep-wait for BSY to clear */ |
| 3728 | DPRINTK("busy wait\n"); |
| 3729 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { |
| 3730 | qc->err_mask |= AC_ERR_TIMEOUT; |
| 3731 | goto err_out; |
| 3732 | } |
| 3733 | |
| 3734 | /* make sure DRQ is set */ |
| 3735 | status = ata_chk_status(ap); |
| 3736 | if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) { |
| 3737 | qc->err_mask |= AC_ERR_HSM; |
| 3738 | goto err_out; |
| 3739 | } |
| 3740 | |
| 3741 | /* send SCSI cdb */ |
| 3742 | DPRINTK("send cdb\n"); |
| 3743 | WARN_ON(qc->dev->cdb_len < 12); |
| 3744 | |
| 3745 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA || |
| 3746 | qc->tf.protocol == ATA_PROT_ATAPI_NODATA) { |
| 3747 | unsigned long flags; |
| 3748 | |
| 3749 | /* Once we're done issuing command and kicking bmdma, |
| 3750 | * irq handler takes over. To not lose irq, we need |
| 3751 | * to clear NOINTR flag before sending cdb, but |
| 3752 | * interrupt handler shouldn't be invoked before we're |
| 3753 | * finished. Hence, the following locking. |
| 3754 | */ |
| 3755 | spin_lock_irqsave(&ap->host_set->lock, flags); |
| 3756 | ap->flags &= ~ATA_FLAG_NOINTR; |
| 3757 | ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1); |
| 3758 | if (qc->tf.protocol == ATA_PROT_ATAPI_DMA) |
| 3759 | ap->ops->bmdma_start(qc); /* initiate bmdma */ |
| 3760 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
| 3761 | } else { |
| 3762 | ata_data_xfer(ap, qc->cdb, qc->dev->cdb_len, 1); |
| 3763 | |
| 3764 | /* PIO commands are handled by polling */ |
| 3765 | ap->hsm_task_state = HSM_ST; |
| 3766 | ata_port_queue_task(ap, ata_pio_task, ap, 0); |
| 3767 | } |
| 3768 | |
| 3769 | return; |
| 3770 | |
| 3771 | err_out: |
| 3772 | ata_poll_qc_complete(qc); |
| 3773 | } |
| 3774 | |
| 3775 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | * ata_qc_timeout - Handle timeout of queued command |
| 3777 | * @qc: Command that timed out |
| 3778 | * |
| 3779 | * Some part of the kernel (currently, only the SCSI layer) |
| 3780 | * has noticed that the active command on port @ap has not |
| 3781 | * completed after a specified length of time. Handle this |
| 3782 | * condition by disabling DMA (if necessary) and completing |
| 3783 | * transactions, with error if necessary. |
| 3784 | * |
| 3785 | * This also handles the case of the "lost interrupt", where |
| 3786 | * for some reason (possibly hardware bug, possibly driver bug) |
| 3787 | * an interrupt was not delivered to the driver, even though the |
| 3788 | * transaction completed successfully. |
| 3789 | * |
| 3790 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3791 | * Inherited from SCSI layer (none, can sleep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | */ |
| 3793 | |
| 3794 | static void ata_qc_timeout(struct ata_queued_cmd *qc) |
| 3795 | { |
| 3796 | struct ata_port *ap = qc->ap; |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3797 | struct ata_host_set *host_set = ap->host_set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | u8 host_stat = 0, drv_stat; |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3799 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | |
| 3801 | DPRINTK("ENTER\n"); |
| 3802 | |
Tejun Heo | c18d06f | 2006-02-02 00:56:10 +0900 | [diff] [blame] | 3803 | ap->hsm_task_state = HSM_ST_IDLE; |
| 3804 | |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3805 | spin_lock_irqsave(&host_set->lock, flags); |
| 3806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | switch (qc->tf.protocol) { |
| 3808 | |
| 3809 | case ATA_PROT_DMA: |
| 3810 | case ATA_PROT_ATAPI_DMA: |
| 3811 | host_stat = ap->ops->bmdma_status(ap); |
| 3812 | |
| 3813 | /* before we do anything else, clear DMA-Start bit */ |
Alan Cox | b73fc89 | 2005-08-26 16:03:19 +0100 | [diff] [blame] | 3814 | ap->ops->bmdma_stop(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | |
| 3816 | /* fall through */ |
| 3817 | |
| 3818 | default: |
| 3819 | ata_altstatus(ap); |
| 3820 | drv_stat = ata_chk_status(ap); |
| 3821 | |
| 3822 | /* ack bmdma irq events */ |
| 3823 | ap->ops->irq_clear(ap); |
| 3824 | |
| 3825 | printk(KERN_ERR "ata%u: command 0x%x timeout, stat 0x%x host_stat 0x%x\n", |
| 3826 | ap->id, qc->tf.command, drv_stat, host_stat); |
| 3827 | |
| 3828 | /* complete taskfile transaction */ |
Albert Lee | a22e2eb | 2005-12-05 15:38:02 +0800 | [diff] [blame] | 3829 | qc->err_mask |= ac_err_mask(drv_stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | break; |
| 3831 | } |
Jeff Garzik | b8f6153 | 2005-08-25 22:01:20 -0400 | [diff] [blame] | 3832 | |
| 3833 | spin_unlock_irqrestore(&host_set->lock, flags); |
| 3834 | |
Tejun Heo | a72ec4c | 2006-01-23 13:09:37 +0900 | [diff] [blame] | 3835 | ata_eh_qc_complete(qc); |
| 3836 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | DPRINTK("EXIT\n"); |
| 3838 | } |
| 3839 | |
| 3840 | /** |
| 3841 | * ata_eng_timeout - Handle timeout of queued command |
| 3842 | * @ap: Port on which timed-out command is active |
| 3843 | * |
| 3844 | * Some part of the kernel (currently, only the SCSI layer) |
| 3845 | * has noticed that the active command on port @ap has not |
| 3846 | * completed after a specified length of time. Handle this |
| 3847 | * condition by disabling DMA (if necessary) and completing |
| 3848 | * transactions, with error if necessary. |
| 3849 | * |
| 3850 | * This also handles the case of the "lost interrupt", where |
| 3851 | * for some reason (possibly hardware bug, possibly driver bug) |
| 3852 | * an interrupt was not delivered to the driver, even though the |
| 3853 | * transaction completed successfully. |
| 3854 | * |
| 3855 | * LOCKING: |
| 3856 | * Inherited from SCSI layer (none, can sleep) |
| 3857 | */ |
| 3858 | |
| 3859 | void ata_eng_timeout(struct ata_port *ap) |
| 3860 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3861 | DPRINTK("ENTER\n"); |
| 3862 | |
Tejun Heo | f637902 | 2006-02-10 15:10:48 +0900 | [diff] [blame] | 3863 | ata_qc_timeout(ata_qc_from_tag(ap, ap->active_tag)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3865 | DPRINTK("EXIT\n"); |
| 3866 | } |
| 3867 | |
| 3868 | /** |
| 3869 | * ata_qc_new - Request an available ATA command, for queueing |
| 3870 | * @ap: Port associated with device @dev |
| 3871 | * @dev: Device from whom we request an available command structure |
| 3872 | * |
| 3873 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3874 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3875 | */ |
| 3876 | |
| 3877 | static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) |
| 3878 | { |
| 3879 | struct ata_queued_cmd *qc = NULL; |
| 3880 | unsigned int i; |
| 3881 | |
| 3882 | for (i = 0; i < ATA_MAX_QUEUE; i++) |
| 3883 | if (!test_and_set_bit(i, &ap->qactive)) { |
| 3884 | qc = ata_qc_from_tag(ap, i); |
| 3885 | break; |
| 3886 | } |
| 3887 | |
| 3888 | if (qc) |
| 3889 | qc->tag = i; |
| 3890 | |
| 3891 | return qc; |
| 3892 | } |
| 3893 | |
| 3894 | /** |
| 3895 | * ata_qc_new_init - Request an available ATA command, and initialize it |
| 3896 | * @ap: Port associated with device @dev |
| 3897 | * @dev: Device from whom we request an available command structure |
| 3898 | * |
| 3899 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3900 | * None. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3901 | */ |
| 3902 | |
| 3903 | struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, |
| 3904 | struct ata_device *dev) |
| 3905 | { |
| 3906 | struct ata_queued_cmd *qc; |
| 3907 | |
| 3908 | qc = ata_qc_new(ap); |
| 3909 | if (qc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | qc->scsicmd = NULL; |
| 3911 | qc->ap = ap; |
| 3912 | qc->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | |
Jeff Garzik | 2c13b7c | 2005-11-14 14:14:16 -0500 | [diff] [blame] | 3914 | ata_qc_reinit(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | } |
| 3916 | |
| 3917 | return qc; |
| 3918 | } |
| 3919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | /** |
| 3921 | * ata_qc_free - free unused ata_queued_cmd |
| 3922 | * @qc: Command to complete |
| 3923 | * |
| 3924 | * Designed to free unused ata_queued_cmd object |
| 3925 | * in case something prevents using it. |
| 3926 | * |
| 3927 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 3928 | * spin_lock_irqsave(host_set lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | */ |
| 3930 | void ata_qc_free(struct ata_queued_cmd *qc) |
| 3931 | { |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 3932 | struct ata_port *ap = qc->ap; |
| 3933 | unsigned int tag; |
| 3934 | |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3935 | WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | |
Tejun Heo | 4ba946e | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 3937 | qc->flags = 0; |
| 3938 | tag = qc->tag; |
| 3939 | if (likely(ata_tag_valid(tag))) { |
| 3940 | if (tag == ap->active_tag) |
| 3941 | ap->active_tag = ATA_TAG_POISON; |
| 3942 | qc->tag = ATA_TAG_POISON; |
| 3943 | clear_bit(tag, &ap->qactive); |
| 3944 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
Tejun Heo | 7601442 | 2006-02-11 15:13:49 +0900 | [diff] [blame] | 3947 | void __ata_qc_complete(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | { |
Tejun Heo | a4631474 | 2006-02-11 19:11:13 +0900 | [diff] [blame] | 3949 | WARN_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */ |
| 3950 | WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | |
| 3952 | if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 3953 | ata_sg_clean(qc); |
| 3954 | |
Albert Lee | 3f3791d | 2005-08-16 14:25:38 +0800 | [diff] [blame] | 3955 | /* atapi: mark qc as inactive to prevent the interrupt handler |
| 3956 | * from completing the command twice later, before the error handler |
| 3957 | * is called. (when rc != 0 and atapi request sense is needed) |
| 3958 | */ |
| 3959 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
| 3960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | /* call completion callback */ |
Tejun Heo | 77853bf | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 3962 | qc->complete_fn(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | static inline int ata_should_dma_map(struct ata_queued_cmd *qc) |
| 3966 | { |
| 3967 | struct ata_port *ap = qc->ap; |
| 3968 | |
| 3969 | switch (qc->tf.protocol) { |
| 3970 | case ATA_PROT_DMA: |
| 3971 | case ATA_PROT_ATAPI_DMA: |
| 3972 | return 1; |
| 3973 | |
| 3974 | case ATA_PROT_ATAPI: |
| 3975 | case ATA_PROT_PIO: |
| 3976 | case ATA_PROT_PIO_MULT: |
| 3977 | if (ap->flags & ATA_FLAG_PIO_DMA) |
| 3978 | return 1; |
| 3979 | |
| 3980 | /* fall through */ |
| 3981 | |
| 3982 | default: |
| 3983 | return 0; |
| 3984 | } |
| 3985 | |
| 3986 | /* never reached */ |
| 3987 | } |
| 3988 | |
| 3989 | /** |
| 3990 | * ata_qc_issue - issue taskfile to device |
| 3991 | * @qc: command to issue to device |
| 3992 | * |
| 3993 | * Prepare an ATA command to submission to device. |
| 3994 | * This includes mapping the data into a DMA-able |
| 3995 | * area, filling in the S/G table, and finally |
| 3996 | * writing the taskfile to hardware, starting the command. |
| 3997 | * |
| 3998 | * LOCKING: |
| 3999 | * spin_lock_irqsave(host_set lock) |
| 4000 | * |
| 4001 | * RETURNS: |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4002 | * Zero on success, AC_ERR_* mask on failure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | */ |
| 4004 | |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4005 | unsigned int ata_qc_issue(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | { |
| 4007 | struct ata_port *ap = qc->ap; |
| 4008 | |
| 4009 | if (ata_should_dma_map(qc)) { |
| 4010 | if (qc->flags & ATA_QCFLAG_SG) { |
| 4011 | if (ata_sg_setup(qc)) |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4012 | goto sg_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | } else if (qc->flags & ATA_QCFLAG_SINGLE) { |
| 4014 | if (ata_sg_setup_one(qc)) |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4015 | goto sg_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4016 | } |
| 4017 | } else { |
| 4018 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
| 4019 | } |
| 4020 | |
| 4021 | ap->ops->qc_prep(qc); |
| 4022 | |
| 4023 | qc->ap->active_tag = qc->tag; |
| 4024 | qc->flags |= ATA_QCFLAG_ACTIVE; |
| 4025 | |
| 4026 | return ap->ops->qc_issue(qc); |
| 4027 | |
Tejun Heo | 8e436af | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4028 | sg_err: |
| 4029 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4030 | return AC_ERR_SYSTEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4034 | /** |
| 4035 | * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner |
| 4036 | * @qc: command to issue to device |
| 4037 | * |
| 4038 | * Using various libata functions and hooks, this function |
| 4039 | * starts an ATA command. ATA commands are grouped into |
| 4040 | * classes called "protocols", and issuing each type of protocol |
| 4041 | * is slightly different. |
| 4042 | * |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4043 | * May be used as the qc_issue() entry in ata_port_operations. |
| 4044 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | * LOCKING: |
| 4046 | * spin_lock_irqsave(host_set lock) |
| 4047 | * |
| 4048 | * RETURNS: |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4049 | * Zero on success, AC_ERR_* mask on failure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | */ |
| 4051 | |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4052 | unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | { |
| 4054 | struct ata_port *ap = qc->ap; |
| 4055 | |
| 4056 | ata_dev_select(ap, qc->dev->devno, 1, 0); |
| 4057 | |
| 4058 | switch (qc->tf.protocol) { |
| 4059 | case ATA_PROT_NODATA: |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 4060 | ata_tf_to_host(ap, &qc->tf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | break; |
| 4062 | |
| 4063 | case ATA_PROT_DMA: |
| 4064 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
| 4065 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
| 4066 | ap->ops->bmdma_start(qc); /* initiate bmdma */ |
| 4067 | break; |
| 4068 | |
| 4069 | case ATA_PROT_PIO: /* load tf registers, initiate polling pio */ |
| 4070 | ata_qc_set_polling(qc); |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 4071 | ata_tf_to_host(ap, &qc->tf); |
Albert Lee | 14be71f | 2005-09-27 17:36:35 +0800 | [diff] [blame] | 4072 | ap->hsm_task_state = HSM_ST; |
Tejun Heo | 8061f5f | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 4073 | ata_port_queue_task(ap, ata_pio_task, ap, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | break; |
| 4075 | |
| 4076 | case ATA_PROT_ATAPI: |
| 4077 | ata_qc_set_polling(qc); |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 4078 | ata_tf_to_host(ap, &qc->tf); |
Tejun Heo | 8061f5f | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 4079 | ata_port_queue_task(ap, atapi_packet_task, ap, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4080 | break; |
| 4081 | |
| 4082 | case ATA_PROT_ATAPI_NODATA: |
Tejun Heo | c138950 | 2005-08-22 14:59:24 +0900 | [diff] [blame] | 4083 | ap->flags |= ATA_FLAG_NOINTR; |
Jeff Garzik | e533825 | 2005-10-30 21:37:17 -0500 | [diff] [blame] | 4084 | ata_tf_to_host(ap, &qc->tf); |
Tejun Heo | 8061f5f | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 4085 | ata_port_queue_task(ap, atapi_packet_task, ap, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4086 | break; |
| 4087 | |
| 4088 | case ATA_PROT_ATAPI_DMA: |
Tejun Heo | c138950 | 2005-08-22 14:59:24 +0900 | [diff] [blame] | 4089 | ap->flags |= ATA_FLAG_NOINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4090 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
| 4091 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
Tejun Heo | 8061f5f | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 4092 | ata_port_queue_task(ap, atapi_packet_task, ap, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | break; |
| 4094 | |
| 4095 | default: |
| 4096 | WARN_ON(1); |
Tejun Heo | 9a3d9eb | 2006-01-23 13:09:36 +0900 | [diff] [blame] | 4097 | return AC_ERR_SYSTEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | return 0; |
| 4101 | } |
| 4102 | |
| 4103 | /** |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4104 | * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | * @qc: Info associated with this ATA transaction. |
| 4106 | * |
| 4107 | * LOCKING: |
| 4108 | * spin_lock_irqsave(host_set lock) |
| 4109 | */ |
| 4110 | |
| 4111 | static void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc) |
| 4112 | { |
| 4113 | struct ata_port *ap = qc->ap; |
| 4114 | unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); |
| 4115 | u8 dmactl; |
| 4116 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
| 4117 | |
| 4118 | /* load PRD table addr. */ |
| 4119 | mb(); /* make sure PRD table writes are visible to controller */ |
| 4120 | writel(ap->prd_dma, mmio + ATA_DMA_TABLE_OFS); |
| 4121 | |
| 4122 | /* specify data direction, triple-check start bit is clear */ |
| 4123 | dmactl = readb(mmio + ATA_DMA_CMD); |
| 4124 | dmactl &= ~(ATA_DMA_WR | ATA_DMA_START); |
| 4125 | if (!rw) |
| 4126 | dmactl |= ATA_DMA_WR; |
| 4127 | writeb(dmactl, mmio + ATA_DMA_CMD); |
| 4128 | |
| 4129 | /* issue r/w command */ |
| 4130 | ap->ops->exec_command(ap, &qc->tf); |
| 4131 | } |
| 4132 | |
| 4133 | /** |
Alan Cox | b73fc89 | 2005-08-26 16:03:19 +0100 | [diff] [blame] | 4134 | * ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4135 | * @qc: Info associated with this ATA transaction. |
| 4136 | * |
| 4137 | * LOCKING: |
| 4138 | * spin_lock_irqsave(host_set lock) |
| 4139 | */ |
| 4140 | |
| 4141 | static void ata_bmdma_start_mmio (struct ata_queued_cmd *qc) |
| 4142 | { |
| 4143 | struct ata_port *ap = qc->ap; |
| 4144 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
| 4145 | u8 dmactl; |
| 4146 | |
| 4147 | /* start host DMA transaction */ |
| 4148 | dmactl = readb(mmio + ATA_DMA_CMD); |
| 4149 | writeb(dmactl | ATA_DMA_START, mmio + ATA_DMA_CMD); |
| 4150 | |
| 4151 | /* Strictly, one may wish to issue a readb() here, to |
| 4152 | * flush the mmio write. However, control also passes |
| 4153 | * to the hardware at this point, and it will interrupt |
| 4154 | * us when we are to resume control. So, in effect, |
| 4155 | * we don't care when the mmio write flushes. |
| 4156 | * Further, a read of the DMA status register _immediately_ |
| 4157 | * following the write may not be what certain flaky hardware |
| 4158 | * is expected, so I think it is best to not add a readb() |
| 4159 | * without first all the MMIO ATA cards/mobos. |
| 4160 | * Or maybe I'm just being paranoid. |
| 4161 | */ |
| 4162 | } |
| 4163 | |
| 4164 | /** |
| 4165 | * ata_bmdma_setup_pio - Set up PCI IDE BMDMA transaction (PIO) |
| 4166 | * @qc: Info associated with this ATA transaction. |
| 4167 | * |
| 4168 | * LOCKING: |
| 4169 | * spin_lock_irqsave(host_set lock) |
| 4170 | */ |
| 4171 | |
| 4172 | static void ata_bmdma_setup_pio (struct ata_queued_cmd *qc) |
| 4173 | { |
| 4174 | struct ata_port *ap = qc->ap; |
| 4175 | unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); |
| 4176 | u8 dmactl; |
| 4177 | |
| 4178 | /* load PRD table addr. */ |
| 4179 | outl(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); |
| 4180 | |
| 4181 | /* specify data direction, triple-check start bit is clear */ |
| 4182 | dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 4183 | dmactl &= ~(ATA_DMA_WR | ATA_DMA_START); |
| 4184 | if (!rw) |
| 4185 | dmactl |= ATA_DMA_WR; |
| 4186 | outb(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 4187 | |
| 4188 | /* issue r/w command */ |
| 4189 | ap->ops->exec_command(ap, &qc->tf); |
| 4190 | } |
| 4191 | |
| 4192 | /** |
| 4193 | * ata_bmdma_start_pio - Start a PCI IDE BMDMA transaction (PIO) |
| 4194 | * @qc: Info associated with this ATA transaction. |
| 4195 | * |
| 4196 | * LOCKING: |
| 4197 | * spin_lock_irqsave(host_set lock) |
| 4198 | */ |
| 4199 | |
| 4200 | static void ata_bmdma_start_pio (struct ata_queued_cmd *qc) |
| 4201 | { |
| 4202 | struct ata_port *ap = qc->ap; |
| 4203 | u8 dmactl; |
| 4204 | |
| 4205 | /* start host DMA transaction */ |
| 4206 | dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 4207 | outb(dmactl | ATA_DMA_START, |
| 4208 | ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 4209 | } |
| 4210 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4211 | |
| 4212 | /** |
| 4213 | * ata_bmdma_start - Start a PCI IDE BMDMA transaction |
| 4214 | * @qc: Info associated with this ATA transaction. |
| 4215 | * |
| 4216 | * Writes the ATA_DMA_START flag to the DMA command register. |
| 4217 | * |
| 4218 | * May be used as the bmdma_start() entry in ata_port_operations. |
| 4219 | * |
| 4220 | * LOCKING: |
| 4221 | * spin_lock_irqsave(host_set lock) |
| 4222 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | void ata_bmdma_start(struct ata_queued_cmd *qc) |
| 4224 | { |
| 4225 | if (qc->ap->flags & ATA_FLAG_MMIO) |
| 4226 | ata_bmdma_start_mmio(qc); |
| 4227 | else |
| 4228 | ata_bmdma_start_pio(qc); |
| 4229 | } |
| 4230 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4231 | |
| 4232 | /** |
| 4233 | * ata_bmdma_setup - Set up PCI IDE BMDMA transaction |
| 4234 | * @qc: Info associated with this ATA transaction. |
| 4235 | * |
| 4236 | * Writes address of PRD table to device's PRD Table Address |
| 4237 | * register, sets the DMA control register, and calls |
| 4238 | * ops->exec_command() to start the transfer. |
| 4239 | * |
| 4240 | * May be used as the bmdma_setup() entry in ata_port_operations. |
| 4241 | * |
| 4242 | * LOCKING: |
| 4243 | * spin_lock_irqsave(host_set lock) |
| 4244 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | void ata_bmdma_setup(struct ata_queued_cmd *qc) |
| 4246 | { |
| 4247 | if (qc->ap->flags & ATA_FLAG_MMIO) |
| 4248 | ata_bmdma_setup_mmio(qc); |
| 4249 | else |
| 4250 | ata_bmdma_setup_pio(qc); |
| 4251 | } |
| 4252 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4253 | |
| 4254 | /** |
| 4255 | * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt. |
Jeff Garzik | decc6d0 | 2005-06-02 18:42:33 -0400 | [diff] [blame] | 4256 | * @ap: Port associated with this ATA transaction. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4257 | * |
| 4258 | * Clear interrupt and error flags in DMA status register. |
| 4259 | * |
| 4260 | * May be used as the irq_clear() entry in ata_port_operations. |
| 4261 | * |
| 4262 | * LOCKING: |
| 4263 | * spin_lock_irqsave(host_set lock) |
| 4264 | */ |
| 4265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | void ata_bmdma_irq_clear(struct ata_port *ap) |
| 4267 | { |
| 4268 | if (ap->flags & ATA_FLAG_MMIO) { |
| 4269 | void __iomem *mmio = ((void __iomem *) ap->ioaddr.bmdma_addr) + ATA_DMA_STATUS; |
| 4270 | writeb(readb(mmio), mmio); |
| 4271 | } else { |
| 4272 | unsigned long addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS; |
| 4273 | outb(inb(addr), addr); |
| 4274 | } |
| 4275 | |
| 4276 | } |
| 4277 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4278 | |
| 4279 | /** |
| 4280 | * ata_bmdma_status - Read PCI IDE BMDMA status |
Jeff Garzik | decc6d0 | 2005-06-02 18:42:33 -0400 | [diff] [blame] | 4281 | * @ap: Port associated with this ATA transaction. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4282 | * |
| 4283 | * Read and return BMDMA status register. |
| 4284 | * |
| 4285 | * May be used as the bmdma_status() entry in ata_port_operations. |
| 4286 | * |
| 4287 | * LOCKING: |
| 4288 | * spin_lock_irqsave(host_set lock) |
| 4289 | */ |
| 4290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | u8 ata_bmdma_status(struct ata_port *ap) |
| 4292 | { |
| 4293 | u8 host_stat; |
| 4294 | if (ap->flags & ATA_FLAG_MMIO) { |
| 4295 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
| 4296 | host_stat = readb(mmio + ATA_DMA_STATUS); |
| 4297 | } else |
Albert Lee | ee500aa | 2005-09-27 17:34:38 +0800 | [diff] [blame] | 4298 | host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | return host_stat; |
| 4300 | } |
| 4301 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4302 | |
| 4303 | /** |
| 4304 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer |
Alan Cox | b73fc89 | 2005-08-26 16:03:19 +0100 | [diff] [blame] | 4305 | * @qc: Command we are ending DMA for |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4306 | * |
| 4307 | * Clears the ATA_DMA_START flag in the dma control register |
| 4308 | * |
| 4309 | * May be used as the bmdma_stop() entry in ata_port_operations. |
| 4310 | * |
| 4311 | * LOCKING: |
| 4312 | * spin_lock_irqsave(host_set lock) |
| 4313 | */ |
| 4314 | |
Alan Cox | b73fc89 | 2005-08-26 16:03:19 +0100 | [diff] [blame] | 4315 | void ata_bmdma_stop(struct ata_queued_cmd *qc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | { |
Alan Cox | b73fc89 | 2005-08-26 16:03:19 +0100 | [diff] [blame] | 4317 | struct ata_port *ap = qc->ap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | if (ap->flags & ATA_FLAG_MMIO) { |
| 4319 | void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr; |
| 4320 | |
| 4321 | /* clear start/stop bit */ |
| 4322 | writeb(readb(mmio + ATA_DMA_CMD) & ~ATA_DMA_START, |
| 4323 | mmio + ATA_DMA_CMD); |
| 4324 | } else { |
| 4325 | /* clear start/stop bit */ |
| 4326 | outb(inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START, |
| 4327 | ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 4328 | } |
| 4329 | |
| 4330 | /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ |
| 4331 | ata_altstatus(ap); /* dummy read */ |
| 4332 | } |
| 4333 | |
| 4334 | /** |
| 4335 | * ata_host_intr - Handle host interrupt for given (port, task) |
| 4336 | * @ap: Port on which interrupt arrived (possibly...) |
| 4337 | * @qc: Taskfile currently active in engine |
| 4338 | * |
| 4339 | * Handle host interrupt for given queued command. Currently, |
| 4340 | * only DMA interrupts are handled. All other commands are |
| 4341 | * handled via polling with interrupts disabled (nIEN bit). |
| 4342 | * |
| 4343 | * LOCKING: |
| 4344 | * spin_lock_irqsave(host_set lock) |
| 4345 | * |
| 4346 | * RETURNS: |
| 4347 | * One if interrupt was handled, zero if not (shared irq). |
| 4348 | */ |
| 4349 | |
| 4350 | inline unsigned int ata_host_intr (struct ata_port *ap, |
| 4351 | struct ata_queued_cmd *qc) |
| 4352 | { |
| 4353 | u8 status, host_stat; |
| 4354 | |
| 4355 | switch (qc->tf.protocol) { |
| 4356 | |
| 4357 | case ATA_PROT_DMA: |
| 4358 | case ATA_PROT_ATAPI_DMA: |
| 4359 | case ATA_PROT_ATAPI: |
| 4360 | /* check status of DMA engine */ |
| 4361 | host_stat = ap->ops->bmdma_status(ap); |
| 4362 | VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat); |
| 4363 | |
| 4364 | /* if it's not our irq... */ |
| 4365 | if (!(host_stat & ATA_DMA_INTR)) |
| 4366 | goto idle_irq; |
| 4367 | |
| 4368 | /* before we do anything else, clear DMA-Start bit */ |
Alan Cox | b73fc89 | 2005-08-26 16:03:19 +0100 | [diff] [blame] | 4369 | ap->ops->bmdma_stop(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4370 | |
| 4371 | /* fall through */ |
| 4372 | |
| 4373 | case ATA_PROT_ATAPI_NODATA: |
| 4374 | case ATA_PROT_NODATA: |
| 4375 | /* check altstatus */ |
| 4376 | status = ata_altstatus(ap); |
| 4377 | if (status & ATA_BUSY) |
| 4378 | goto idle_irq; |
| 4379 | |
| 4380 | /* check main status, clearing INTRQ */ |
| 4381 | status = ata_chk_status(ap); |
| 4382 | if (unlikely(status & ATA_BUSY)) |
| 4383 | goto idle_irq; |
| 4384 | DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n", |
| 4385 | ap->id, qc->tf.protocol, status); |
| 4386 | |
| 4387 | /* ack bmdma irq events */ |
| 4388 | ap->ops->irq_clear(ap); |
| 4389 | |
| 4390 | /* complete taskfile transaction */ |
Albert Lee | a22e2eb | 2005-12-05 15:38:02 +0800 | [diff] [blame] | 4391 | qc->err_mask |= ac_err_mask(status); |
| 4392 | ata_qc_complete(qc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | break; |
| 4394 | |
| 4395 | default: |
| 4396 | goto idle_irq; |
| 4397 | } |
| 4398 | |
| 4399 | return 1; /* irq handled */ |
| 4400 | |
| 4401 | idle_irq: |
| 4402 | ap->stats.idle_irq++; |
| 4403 | |
| 4404 | #ifdef ATA_IRQ_TRAP |
| 4405 | if ((ap->stats.idle_irq % 1000) == 0) { |
| 4406 | handled = 1; |
| 4407 | ata_irq_ack(ap, 0); /* debug trap */ |
| 4408 | printk(KERN_WARNING "ata%d: irq trap\n", ap->id); |
| 4409 | } |
| 4410 | #endif |
| 4411 | return 0; /* irq not handled */ |
| 4412 | } |
| 4413 | |
| 4414 | /** |
| 4415 | * ata_interrupt - Default ATA host interrupt handler |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4416 | * @irq: irq line (unused) |
| 4417 | * @dev_instance: pointer to our ata_host_set information structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | * @regs: unused |
| 4419 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4420 | * Default interrupt handler for PCI IDE devices. Calls |
| 4421 | * ata_host_intr() for each port that is not disabled. |
| 4422 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4424 | * Obtains host_set lock during operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | * |
| 4426 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4427 | * IRQ_NONE or IRQ_HANDLED. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | */ |
| 4429 | |
| 4430 | irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) |
| 4431 | { |
| 4432 | struct ata_host_set *host_set = dev_instance; |
| 4433 | unsigned int i; |
| 4434 | unsigned int handled = 0; |
| 4435 | unsigned long flags; |
| 4436 | |
| 4437 | /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */ |
| 4438 | spin_lock_irqsave(&host_set->lock, flags); |
| 4439 | |
| 4440 | for (i = 0; i < host_set->n_ports; i++) { |
| 4441 | struct ata_port *ap; |
| 4442 | |
| 4443 | ap = host_set->ports[i]; |
Tejun Heo | c138950 | 2005-08-22 14:59:24 +0900 | [diff] [blame] | 4444 | if (ap && |
| 4445 | !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4446 | struct ata_queued_cmd *qc; |
| 4447 | |
| 4448 | qc = ata_qc_from_tag(ap, ap->active_tag); |
Albert Lee | 21b1ed7 | 2005-04-29 17:34:59 +0800 | [diff] [blame] | 4449 | if (qc && (!(qc->tf.ctl & ATA_NIEN)) && |
| 4450 | (qc->flags & ATA_QCFLAG_ACTIVE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4451 | handled |= ata_host_intr(ap, qc); |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | spin_unlock_irqrestore(&host_set->lock, flags); |
| 4456 | |
| 4457 | return IRQ_RETVAL(handled); |
| 4458 | } |
| 4459 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4460 | |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4461 | /* |
| 4462 | * Execute a 'simple' command, that only consists of the opcode 'cmd' itself, |
| 4463 | * without filling any other registers |
| 4464 | */ |
| 4465 | static int ata_do_simple_cmd(struct ata_port *ap, struct ata_device *dev, |
| 4466 | u8 cmd) |
| 4467 | { |
| 4468 | struct ata_taskfile tf; |
| 4469 | int err; |
| 4470 | |
| 4471 | ata_tf_init(ap, &tf, dev->devno); |
| 4472 | |
| 4473 | tf.command = cmd; |
| 4474 | tf.flags |= ATA_TFLAG_DEVICE; |
| 4475 | tf.protocol = ATA_PROT_NODATA; |
| 4476 | |
| 4477 | err = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0); |
| 4478 | if (err) |
| 4479 | printk(KERN_ERR "%s: ata command failed: %d\n", |
| 4480 | __FUNCTION__, err); |
| 4481 | |
| 4482 | return err; |
| 4483 | } |
| 4484 | |
| 4485 | static int ata_flush_cache(struct ata_port *ap, struct ata_device *dev) |
| 4486 | { |
| 4487 | u8 cmd; |
| 4488 | |
| 4489 | if (!ata_try_flush_cache(dev)) |
| 4490 | return 0; |
| 4491 | |
| 4492 | if (ata_id_has_flush_ext(dev->id)) |
| 4493 | cmd = ATA_CMD_FLUSH_EXT; |
| 4494 | else |
| 4495 | cmd = ATA_CMD_FLUSH; |
| 4496 | |
| 4497 | return ata_do_simple_cmd(ap, dev, cmd); |
| 4498 | } |
| 4499 | |
| 4500 | static int ata_standby_drive(struct ata_port *ap, struct ata_device *dev) |
| 4501 | { |
| 4502 | return ata_do_simple_cmd(ap, dev, ATA_CMD_STANDBYNOW1); |
| 4503 | } |
| 4504 | |
| 4505 | static int ata_start_drive(struct ata_port *ap, struct ata_device *dev) |
| 4506 | { |
| 4507 | return ata_do_simple_cmd(ap, dev, ATA_CMD_IDLEIMMEDIATE); |
| 4508 | } |
| 4509 | |
| 4510 | /** |
| 4511 | * ata_device_resume - wakeup a previously suspended devices |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4512 | * @ap: port the device is connected to |
| 4513 | * @dev: the device to resume |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4514 | * |
| 4515 | * Kick the drive back into action, by sending it an idle immediate |
| 4516 | * command and making sure its transfer mode matches between drive |
| 4517 | * and host. |
| 4518 | * |
| 4519 | */ |
| 4520 | int ata_device_resume(struct ata_port *ap, struct ata_device *dev) |
| 4521 | { |
| 4522 | if (ap->flags & ATA_FLAG_SUSPENDED) { |
| 4523 | ap->flags &= ~ATA_FLAG_SUSPENDED; |
| 4524 | ata_set_mode(ap); |
| 4525 | } |
| 4526 | if (!ata_dev_present(dev)) |
| 4527 | return 0; |
| 4528 | if (dev->class == ATA_DEV_ATA) |
| 4529 | ata_start_drive(ap, dev); |
| 4530 | |
| 4531 | return 0; |
| 4532 | } |
| 4533 | |
| 4534 | /** |
| 4535 | * ata_device_suspend - prepare a device for suspend |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4536 | * @ap: port the device is connected to |
| 4537 | * @dev: the device to suspend |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4538 | * |
| 4539 | * Flush the cache on the drive, if appropriate, then issue a |
| 4540 | * standbynow command. |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 4541 | */ |
| 4542 | int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) |
| 4543 | { |
| 4544 | if (!ata_dev_present(dev)) |
| 4545 | return 0; |
| 4546 | if (dev->class == ATA_DEV_ATA) |
| 4547 | ata_flush_cache(ap, dev); |
| 4548 | |
| 4549 | ata_standby_drive(ap, dev); |
| 4550 | ap->flags |= ATA_FLAG_SUSPENDED; |
| 4551 | return 0; |
| 4552 | } |
| 4553 | |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4554 | /** |
| 4555 | * ata_port_start - Set port up for dma. |
| 4556 | * @ap: Port to initialize |
| 4557 | * |
| 4558 | * Called just after data structures for each port are |
| 4559 | * initialized. Allocates space for PRD table. |
| 4560 | * |
| 4561 | * May be used as the port_start() entry in ata_port_operations. |
| 4562 | * |
| 4563 | * LOCKING: |
| 4564 | * Inherited from caller. |
| 4565 | */ |
| 4566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4567 | int ata_port_start (struct ata_port *ap) |
| 4568 | { |
| 4569 | struct device *dev = ap->host_set->dev; |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 4570 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | |
| 4572 | ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL); |
| 4573 | if (!ap->prd) |
| 4574 | return -ENOMEM; |
| 4575 | |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 4576 | rc = ata_pad_alloc(ap, dev); |
| 4577 | if (rc) { |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4578 | dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 4579 | return rc; |
Jeff Garzik | cedc9a4 | 2005-10-05 07:13:30 -0400 | [diff] [blame] | 4580 | } |
| 4581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd, (unsigned long long) ap->prd_dma); |
| 4583 | |
| 4584 | return 0; |
| 4585 | } |
| 4586 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4587 | |
| 4588 | /** |
| 4589 | * ata_port_stop - Undo ata_port_start() |
| 4590 | * @ap: Port to shut down |
| 4591 | * |
| 4592 | * Frees the PRD table. |
| 4593 | * |
| 4594 | * May be used as the port_stop() entry in ata_port_operations. |
| 4595 | * |
| 4596 | * LOCKING: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 4597 | * Inherited from caller. |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4598 | */ |
| 4599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4600 | void ata_port_stop (struct ata_port *ap) |
| 4601 | { |
| 4602 | struct device *dev = ap->host_set->dev; |
| 4603 | |
| 4604 | dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); |
Jeff Garzik | 6037d6b | 2005-11-04 22:08:00 -0500 | [diff] [blame] | 4605 | ata_pad_free(ap, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | } |
| 4607 | |
Jeff Garzik | aa8f0dc | 2005-05-26 21:54:27 -0400 | [diff] [blame] | 4608 | void ata_host_stop (struct ata_host_set *host_set) |
| 4609 | { |
| 4610 | if (host_set->mmio_base) |
| 4611 | iounmap(host_set->mmio_base); |
| 4612 | } |
| 4613 | |
| 4614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4615 | /** |
| 4616 | * ata_host_remove - Unregister SCSI host structure with upper layers |
| 4617 | * @ap: Port to unregister |
| 4618 | * @do_unregister: 1 if we fully unregister, 0 to just stop the port |
| 4619 | * |
| 4620 | * LOCKING: |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 4621 | * Inherited from caller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | */ |
| 4623 | |
| 4624 | static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister) |
| 4625 | { |
| 4626 | struct Scsi_Host *sh = ap->host; |
| 4627 | |
| 4628 | DPRINTK("ENTER\n"); |
| 4629 | |
| 4630 | if (do_unregister) |
| 4631 | scsi_remove_host(sh); |
| 4632 | |
| 4633 | ap->ops->port_stop(ap); |
| 4634 | } |
| 4635 | |
| 4636 | /** |
| 4637 | * ata_host_init - Initialize an ata_port structure |
| 4638 | * @ap: Structure to initialize |
| 4639 | * @host: associated SCSI mid-layer structure |
| 4640 | * @host_set: Collection of hosts to which @ap belongs |
| 4641 | * @ent: Probe information provided by low-level driver |
| 4642 | * @port_no: Port number associated with this ata_port |
| 4643 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4644 | * Initialize a new ata_port structure, and its associated |
| 4645 | * scsi_host. |
| 4646 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4648 | * Inherited from caller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | */ |
| 4650 | |
| 4651 | static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, |
| 4652 | struct ata_host_set *host_set, |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 4653 | const struct ata_probe_ent *ent, unsigned int port_no) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4654 | { |
| 4655 | unsigned int i; |
| 4656 | |
| 4657 | host->max_id = 16; |
| 4658 | host->max_lun = 1; |
| 4659 | host->max_channel = 1; |
| 4660 | host->unique_id = ata_unique_id++; |
| 4661 | host->max_cmd_len = 12; |
Christoph Hellwig | 1241319 | 2005-06-11 01:05:01 +0200 | [diff] [blame] | 4662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | ap->flags = ATA_FLAG_PORT_DISABLED; |
| 4664 | ap->id = host->unique_id; |
| 4665 | ap->host = host; |
| 4666 | ap->ctl = ATA_DEVCTL_OBS; |
| 4667 | ap->host_set = host_set; |
| 4668 | ap->port_no = port_no; |
| 4669 | ap->hard_port_no = |
| 4670 | ent->legacy_mode ? ent->hard_port_no : port_no; |
| 4671 | ap->pio_mask = ent->pio_mask; |
| 4672 | ap->mwdma_mask = ent->mwdma_mask; |
| 4673 | ap->udma_mask = ent->udma_mask; |
| 4674 | ap->flags |= ent->host_flags; |
| 4675 | ap->ops = ent->port_ops; |
| 4676 | ap->cbl = ATA_CBL_NONE; |
| 4677 | ap->active_tag = ATA_TAG_POISON; |
| 4678 | ap->last_ctl = 0xFF; |
| 4679 | |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 4680 | INIT_WORK(&ap->port_task, NULL, NULL); |
Tejun Heo | a72ec4c | 2006-01-23 13:09:37 +0900 | [diff] [blame] | 4681 | INIT_LIST_HEAD(&ap->eh_done_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | |
| 4683 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 4684 | ap->device[i].devno = i; |
| 4685 | |
| 4686 | #ifdef ATA_IRQ_TRAP |
| 4687 | ap->stats.unhandled_irq = 1; |
| 4688 | ap->stats.idle_irq = 1; |
| 4689 | #endif |
| 4690 | |
| 4691 | memcpy(&ap->ioaddr, &ent->port[port_no], sizeof(struct ata_ioports)); |
| 4692 | } |
| 4693 | |
| 4694 | /** |
| 4695 | * ata_host_add - Attach low-level ATA driver to system |
| 4696 | * @ent: Information provided by low-level driver |
| 4697 | * @host_set: Collections of ports to which we add |
| 4698 | * @port_no: Port number associated with this host |
| 4699 | * |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4700 | * Attach low-level ATA driver to system. |
| 4701 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4702 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4703 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | * |
| 4705 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4706 | * New ata_port on success, for NULL on error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | */ |
| 4708 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 4709 | static struct ata_port * ata_host_add(const struct ata_probe_ent *ent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | struct ata_host_set *host_set, |
| 4711 | unsigned int port_no) |
| 4712 | { |
| 4713 | struct Scsi_Host *host; |
| 4714 | struct ata_port *ap; |
| 4715 | int rc; |
| 4716 | |
| 4717 | DPRINTK("ENTER\n"); |
| 4718 | host = scsi_host_alloc(ent->sht, sizeof(struct ata_port)); |
| 4719 | if (!host) |
| 4720 | return NULL; |
| 4721 | |
| 4722 | ap = (struct ata_port *) &host->hostdata[0]; |
| 4723 | |
| 4724 | ata_host_init(ap, host, host_set, ent, port_no); |
| 4725 | |
| 4726 | rc = ap->ops->port_start(ap); |
| 4727 | if (rc) |
| 4728 | goto err_out; |
| 4729 | |
| 4730 | return ap; |
| 4731 | |
| 4732 | err_out: |
| 4733 | scsi_host_put(host); |
| 4734 | return NULL; |
| 4735 | } |
| 4736 | |
| 4737 | /** |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4738 | * ata_device_add - Register hardware device with ATA and SCSI layers |
| 4739 | * @ent: Probe information describing hardware device to be registered |
| 4740 | * |
| 4741 | * This function processes the information provided in the probe |
| 4742 | * information struct @ent, allocates the necessary ATA and SCSI |
| 4743 | * host information structures, initializes them, and registers |
| 4744 | * everything with requisite kernel subsystems. |
| 4745 | * |
| 4746 | * This function requests irqs, probes the ATA bus, and probes |
| 4747 | * the SCSI bus. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | * |
| 4749 | * LOCKING: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4750 | * PCI/etc. bus probe sem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | * |
| 4752 | * RETURNS: |
Jeff Garzik | 0cba632 | 2005-05-30 19:49:12 -0400 | [diff] [blame] | 4753 | * Number of ports registered. Zero on error (no ports registered). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4754 | */ |
| 4755 | |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 4756 | int ata_device_add(const struct ata_probe_ent *ent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | { |
| 4758 | unsigned int count = 0, i; |
| 4759 | struct device *dev = ent->dev; |
| 4760 | struct ata_host_set *host_set; |
| 4761 | |
| 4762 | DPRINTK("ENTER\n"); |
| 4763 | /* alloc a container for our list of ATA ports (buses) */ |
Randy Dunlap | 57f3bda | 2005-10-28 20:37:23 -0700 | [diff] [blame] | 4764 | host_set = kzalloc(sizeof(struct ata_host_set) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | (ent->n_ports * sizeof(void *)), GFP_KERNEL); |
| 4766 | if (!host_set) |
| 4767 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4768 | spin_lock_init(&host_set->lock); |
| 4769 | |
| 4770 | host_set->dev = dev; |
| 4771 | host_set->n_ports = ent->n_ports; |
| 4772 | host_set->irq = ent->irq; |
| 4773 | host_set->mmio_base = ent->mmio_base; |
| 4774 | host_set->private_data = ent->private_data; |
| 4775 | host_set->ops = ent->port_ops; |
| 4776 | |
| 4777 | /* register each port bound to this device */ |
| 4778 | for (i = 0; i < ent->n_ports; i++) { |
| 4779 | struct ata_port *ap; |
| 4780 | unsigned long xfer_mode_mask; |
| 4781 | |
| 4782 | ap = ata_host_add(ent, host_set, i); |
| 4783 | if (!ap) |
| 4784 | goto err_out; |
| 4785 | |
| 4786 | host_set->ports[i] = ap; |
| 4787 | xfer_mode_mask =(ap->udma_mask << ATA_SHIFT_UDMA) | |
| 4788 | (ap->mwdma_mask << ATA_SHIFT_MWDMA) | |
| 4789 | (ap->pio_mask << ATA_SHIFT_PIO); |
| 4790 | |
| 4791 | /* print per-port info to dmesg */ |
| 4792 | printk(KERN_INFO "ata%u: %cATA max %s cmd 0x%lX ctl 0x%lX " |
| 4793 | "bmdma 0x%lX irq %lu\n", |
| 4794 | ap->id, |
| 4795 | ap->flags & ATA_FLAG_SATA ? 'S' : 'P', |
| 4796 | ata_mode_string(xfer_mode_mask), |
| 4797 | ap->ioaddr.cmd_addr, |
| 4798 | ap->ioaddr.ctl_addr, |
| 4799 | ap->ioaddr.bmdma_addr, |
| 4800 | ent->irq); |
| 4801 | |
| 4802 | ata_chk_status(ap); |
| 4803 | host_set->ops->irq_clear(ap); |
| 4804 | count++; |
| 4805 | } |
| 4806 | |
Randy Dunlap | 57f3bda | 2005-10-28 20:37:23 -0700 | [diff] [blame] | 4807 | if (!count) |
| 4808 | goto err_free_ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4809 | |
| 4810 | /* obtain irq, that is shared between channels */ |
| 4811 | if (request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags, |
| 4812 | DRV_NAME, host_set)) |
| 4813 | goto err_out; |
| 4814 | |
| 4815 | /* perform each probe synchronously */ |
| 4816 | DPRINTK("probe begin\n"); |
| 4817 | for (i = 0; i < count; i++) { |
| 4818 | struct ata_port *ap; |
| 4819 | int rc; |
| 4820 | |
| 4821 | ap = host_set->ports[i]; |
| 4822 | |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4823 | DPRINTK("ata%u: bus probe begin\n", ap->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | rc = ata_bus_probe(ap); |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4825 | DPRINTK("ata%u: bus probe end\n", ap->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4826 | |
| 4827 | if (rc) { |
| 4828 | /* FIXME: do something useful here? |
| 4829 | * Current libata behavior will |
| 4830 | * tear down everything when |
| 4831 | * the module is removed |
| 4832 | * or the h/w is unplugged. |
| 4833 | */ |
| 4834 | } |
| 4835 | |
| 4836 | rc = scsi_add_host(ap->host, dev); |
| 4837 | if (rc) { |
| 4838 | printk(KERN_ERR "ata%u: scsi_add_host failed\n", |
| 4839 | ap->id); |
| 4840 | /* FIXME: do something useful here */ |
| 4841 | /* FIXME: handle unconditional calls to |
| 4842 | * scsi_scan_host and ata_host_remove, below, |
| 4843 | * at the very least |
| 4844 | */ |
| 4845 | } |
| 4846 | } |
| 4847 | |
| 4848 | /* probes are done, now scan each port's disk(s) */ |
Randy Dunlap | c893a3a | 2006-01-28 13:15:32 -0500 | [diff] [blame] | 4849 | DPRINTK("host probe begin\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | for (i = 0; i < count; i++) { |
| 4851 | struct ata_port *ap = host_set->ports[i]; |
| 4852 | |
Jeff Garzik | 644dd0c | 2005-10-03 15:55:19 -0400 | [diff] [blame] | 4853 | ata_scsi_scan_host(ap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | dev_set_drvdata(dev, host_set); |
| 4857 | |
| 4858 | VPRINTK("EXIT, returning %u\n", ent->n_ports); |
| 4859 | return ent->n_ports; /* success */ |
| 4860 | |
| 4861 | err_out: |
| 4862 | for (i = 0; i < count; i++) { |
| 4863 | ata_host_remove(host_set->ports[i], 1); |
| 4864 | scsi_host_put(host_set->ports[i]->host); |
| 4865 | } |
Randy Dunlap | 57f3bda | 2005-10-28 20:37:23 -0700 | [diff] [blame] | 4866 | err_free_ret: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4867 | kfree(host_set); |
| 4868 | VPRINTK("EXIT, returning 0\n"); |
| 4869 | return 0; |
| 4870 | } |
| 4871 | |
| 4872 | /** |
Alan Cox | 17b1445 | 2005-09-15 15:44:00 +0100 | [diff] [blame] | 4873 | * ata_host_set_remove - PCI layer callback for device removal |
| 4874 | * @host_set: ATA host set that was removed |
| 4875 | * |
| 4876 | * Unregister all objects associated with this host set. Free those |
| 4877 | * objects. |
| 4878 | * |
| 4879 | * LOCKING: |
| 4880 | * Inherited from calling layer (may sleep). |
| 4881 | */ |
| 4882 | |
Alan Cox | 17b1445 | 2005-09-15 15:44:00 +0100 | [diff] [blame] | 4883 | void ata_host_set_remove(struct ata_host_set *host_set) |
| 4884 | { |
| 4885 | struct ata_port *ap; |
| 4886 | unsigned int i; |
| 4887 | |
| 4888 | for (i = 0; i < host_set->n_ports; i++) { |
| 4889 | ap = host_set->ports[i]; |
| 4890 | scsi_remove_host(ap->host); |
| 4891 | } |
| 4892 | |
| 4893 | free_irq(host_set->irq, host_set); |
| 4894 | |
| 4895 | for (i = 0; i < host_set->n_ports; i++) { |
| 4896 | ap = host_set->ports[i]; |
| 4897 | |
| 4898 | ata_scsi_release(ap->host); |
| 4899 | |
| 4900 | if ((ap->flags & ATA_FLAG_NO_LEGACY) == 0) { |
| 4901 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 4902 | |
| 4903 | if (ioaddr->cmd_addr == 0x1f0) |
| 4904 | release_region(0x1f0, 8); |
| 4905 | else if (ioaddr->cmd_addr == 0x170) |
| 4906 | release_region(0x170, 8); |
| 4907 | } |
| 4908 | |
| 4909 | scsi_host_put(ap->host); |
| 4910 | } |
| 4911 | |
| 4912 | if (host_set->ops->host_stop) |
| 4913 | host_set->ops->host_stop(host_set); |
| 4914 | |
| 4915 | kfree(host_set); |
| 4916 | } |
| 4917 | |
| 4918 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | * ata_scsi_release - SCSI layer callback hook for host unload |
| 4920 | * @host: libata host to be unloaded |
| 4921 | * |
| 4922 | * Performs all duties necessary to shut down a libata port... |
| 4923 | * Kill port kthread, disable port, and release resources. |
| 4924 | * |
| 4925 | * LOCKING: |
| 4926 | * Inherited from SCSI layer. |
| 4927 | * |
| 4928 | * RETURNS: |
| 4929 | * One. |
| 4930 | */ |
| 4931 | |
| 4932 | int ata_scsi_release(struct Scsi_Host *host) |
| 4933 | { |
| 4934 | struct ata_port *ap = (struct ata_port *) &host->hostdata[0]; |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 4935 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | |
| 4937 | DPRINTK("ENTER\n"); |
| 4938 | |
| 4939 | ap->ops->port_disable(ap); |
| 4940 | ata_host_remove(ap, 0); |
Tejun Heo | d9572b1 | 2006-03-01 16:09:35 +0900 | [diff] [blame] | 4941 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
| 4942 | kfree(ap->device[i].id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | |
| 4944 | DPRINTK("EXIT\n"); |
| 4945 | return 1; |
| 4946 | } |
| 4947 | |
| 4948 | /** |
| 4949 | * ata_std_ports - initialize ioaddr with standard port offsets. |
| 4950 | * @ioaddr: IO address structure to be initialized |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4951 | * |
| 4952 | * Utility function which initializes data_addr, error_addr, |
| 4953 | * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr, |
| 4954 | * device_addr, status_addr, and command_addr to standard offsets |
| 4955 | * relative to cmd_addr. |
| 4956 | * |
| 4957 | * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4958 | */ |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | void ata_std_ports(struct ata_ioports *ioaddr) |
| 4961 | { |
| 4962 | ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; |
| 4963 | ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; |
| 4964 | ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; |
| 4965 | ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; |
| 4966 | ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; |
| 4967 | ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; |
| 4968 | ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; |
| 4969 | ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; |
| 4970 | ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; |
| 4971 | ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; |
| 4972 | } |
| 4973 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4974 | |
Jeff Garzik | 374b187 | 2005-08-30 05:42:52 -0400 | [diff] [blame] | 4975 | #ifdef CONFIG_PCI |
| 4976 | |
| 4977 | void ata_pci_host_stop (struct ata_host_set *host_set) |
| 4978 | { |
| 4979 | struct pci_dev *pdev = to_pci_dev(host_set->dev); |
| 4980 | |
| 4981 | pci_iounmap(pdev, host_set->mmio_base); |
| 4982 | } |
| 4983 | |
Edward Falk | 0baab86 | 2005-06-02 18:17:13 -0400 | [diff] [blame] | 4984 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | * ata_pci_remove_one - PCI layer callback for device removal |
| 4986 | * @pdev: PCI device that was removed |
| 4987 | * |
| 4988 | * PCI layer indicates to libata via this hook that |
Randy Dunlap | 6f0ef4f | 2005-10-25 01:44:30 -0400 | [diff] [blame] | 4989 | * hot-unplug or module unload event has occurred. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4990 | * Handle this by unregistering all objects associated |
| 4991 | * with this PCI device. Free those objects. Then finally |
| 4992 | * release PCI resources and disable device. |
| 4993 | * |
| 4994 | * LOCKING: |
| 4995 | * Inherited from PCI layer (may sleep). |
| 4996 | */ |
| 4997 | |
| 4998 | void ata_pci_remove_one (struct pci_dev *pdev) |
| 4999 | { |
| 5000 | struct device *dev = pci_dev_to_dev(pdev); |
| 5001 | struct ata_host_set *host_set = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | |
Alan Cox | 17b1445 | 2005-09-15 15:44:00 +0100 | [diff] [blame] | 5003 | ata_host_set_remove(host_set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5004 | pci_release_regions(pdev); |
| 5005 | pci_disable_device(pdev); |
| 5006 | dev_set_drvdata(dev, NULL); |
| 5007 | } |
| 5008 | |
| 5009 | /* move to PCI subsystem */ |
Jeff Garzik | 057ace5 | 2005-10-22 14:27:05 -0400 | [diff] [blame] | 5010 | 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] | 5011 | { |
| 5012 | unsigned long tmp = 0; |
| 5013 | |
| 5014 | switch (bits->width) { |
| 5015 | case 1: { |
| 5016 | u8 tmp8 = 0; |
| 5017 | pci_read_config_byte(pdev, bits->reg, &tmp8); |
| 5018 | tmp = tmp8; |
| 5019 | break; |
| 5020 | } |
| 5021 | case 2: { |
| 5022 | u16 tmp16 = 0; |
| 5023 | pci_read_config_word(pdev, bits->reg, &tmp16); |
| 5024 | tmp = tmp16; |
| 5025 | break; |
| 5026 | } |
| 5027 | case 4: { |
| 5028 | u32 tmp32 = 0; |
| 5029 | pci_read_config_dword(pdev, bits->reg, &tmp32); |
| 5030 | tmp = tmp32; |
| 5031 | break; |
| 5032 | } |
| 5033 | |
| 5034 | default: |
| 5035 | return -EINVAL; |
| 5036 | } |
| 5037 | |
| 5038 | tmp &= bits->mask; |
| 5039 | |
| 5040 | return (tmp == bits->val) ? 1 : 0; |
| 5041 | } |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5042 | |
| 5043 | int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5044 | { |
| 5045 | pci_save_state(pdev); |
| 5046 | pci_disable_device(pdev); |
| 5047 | pci_set_power_state(pdev, PCI_D3hot); |
| 5048 | return 0; |
| 5049 | } |
| 5050 | |
| 5051 | int ata_pci_device_resume(struct pci_dev *pdev) |
| 5052 | { |
| 5053 | pci_set_power_state(pdev, PCI_D0); |
| 5054 | pci_restore_state(pdev); |
| 5055 | pci_enable_device(pdev); |
| 5056 | pci_set_master(pdev); |
| 5057 | return 0; |
| 5058 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | #endif /* CONFIG_PCI */ |
| 5060 | |
| 5061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5062 | static int __init ata_init(void) |
| 5063 | { |
| 5064 | ata_wq = create_workqueue("ata"); |
| 5065 | if (!ata_wq) |
| 5066 | return -ENOMEM; |
| 5067 | |
| 5068 | printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); |
| 5069 | return 0; |
| 5070 | } |
| 5071 | |
| 5072 | static void __exit ata_exit(void) |
| 5073 | { |
| 5074 | destroy_workqueue(ata_wq); |
| 5075 | } |
| 5076 | |
| 5077 | module_init(ata_init); |
| 5078 | module_exit(ata_exit); |
| 5079 | |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 5080 | static unsigned long ratelimit_time; |
| 5081 | static spinlock_t ata_ratelimit_lock = SPIN_LOCK_UNLOCKED; |
| 5082 | |
| 5083 | int ata_ratelimit(void) |
| 5084 | { |
| 5085 | int rc; |
| 5086 | unsigned long flags; |
| 5087 | |
| 5088 | spin_lock_irqsave(&ata_ratelimit_lock, flags); |
| 5089 | |
| 5090 | if (time_after(jiffies, ratelimit_time)) { |
| 5091 | rc = 1; |
| 5092 | ratelimit_time = jiffies + (HZ/5); |
| 5093 | } else |
| 5094 | rc = 0; |
| 5095 | |
| 5096 | spin_unlock_irqrestore(&ata_ratelimit_lock, flags); |
| 5097 | |
| 5098 | return rc; |
| 5099 | } |
| 5100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | /* |
| 5102 | * libata is essentially a library of internal helper functions for |
| 5103 | * low-level ATA host controller drivers. As such, the API/ABI is |
| 5104 | * likely to change as new drivers are added and updated. |
| 5105 | * Do not depend on ABI/API stability. |
| 5106 | */ |
| 5107 | |
| 5108 | EXPORT_SYMBOL_GPL(ata_std_bios_param); |
| 5109 | EXPORT_SYMBOL_GPL(ata_std_ports); |
| 5110 | EXPORT_SYMBOL_GPL(ata_device_add); |
Alan Cox | 17b1445 | 2005-09-15 15:44:00 +0100 | [diff] [blame] | 5111 | EXPORT_SYMBOL_GPL(ata_host_set_remove); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 | EXPORT_SYMBOL_GPL(ata_sg_init); |
| 5113 | EXPORT_SYMBOL_GPL(ata_sg_init_one); |
Tejun Heo | 7601442 | 2006-02-11 15:13:49 +0900 | [diff] [blame] | 5114 | EXPORT_SYMBOL_GPL(__ata_qc_complete); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5115 | EXPORT_SYMBOL_GPL(ata_qc_issue_prot); |
| 5116 | EXPORT_SYMBOL_GPL(ata_eng_timeout); |
| 5117 | EXPORT_SYMBOL_GPL(ata_tf_load); |
| 5118 | EXPORT_SYMBOL_GPL(ata_tf_read); |
| 5119 | EXPORT_SYMBOL_GPL(ata_noop_dev_select); |
| 5120 | EXPORT_SYMBOL_GPL(ata_std_dev_select); |
| 5121 | EXPORT_SYMBOL_GPL(ata_tf_to_fis); |
| 5122 | EXPORT_SYMBOL_GPL(ata_tf_from_fis); |
| 5123 | EXPORT_SYMBOL_GPL(ata_check_status); |
| 5124 | EXPORT_SYMBOL_GPL(ata_altstatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | EXPORT_SYMBOL_GPL(ata_exec_command); |
| 5126 | EXPORT_SYMBOL_GPL(ata_port_start); |
| 5127 | EXPORT_SYMBOL_GPL(ata_port_stop); |
Jeff Garzik | aa8f0dc | 2005-05-26 21:54:27 -0400 | [diff] [blame] | 5128 | EXPORT_SYMBOL_GPL(ata_host_stop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | EXPORT_SYMBOL_GPL(ata_interrupt); |
| 5130 | EXPORT_SYMBOL_GPL(ata_qc_prep); |
| 5131 | EXPORT_SYMBOL_GPL(ata_bmdma_setup); |
| 5132 | EXPORT_SYMBOL_GPL(ata_bmdma_start); |
| 5133 | EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear); |
| 5134 | EXPORT_SYMBOL_GPL(ata_bmdma_status); |
| 5135 | EXPORT_SYMBOL_GPL(ata_bmdma_stop); |
| 5136 | EXPORT_SYMBOL_GPL(ata_port_probe); |
| 5137 | EXPORT_SYMBOL_GPL(sata_phy_reset); |
| 5138 | EXPORT_SYMBOL_GPL(__sata_phy_reset); |
| 5139 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
Tejun Heo | 8a19ac8 | 2006-02-02 18:20:00 +0900 | [diff] [blame] | 5140 | EXPORT_SYMBOL_GPL(ata_std_probeinit); |
Tejun Heo | c2bd580 | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 5141 | EXPORT_SYMBOL_GPL(ata_std_softreset); |
| 5142 | EXPORT_SYMBOL_GPL(sata_std_hardreset); |
| 5143 | EXPORT_SYMBOL_GPL(ata_std_postreset); |
| 5144 | EXPORT_SYMBOL_GPL(ata_std_probe_reset); |
Tejun Heo | a62c0fc | 2006-01-24 17:05:22 +0900 | [diff] [blame] | 5145 | EXPORT_SYMBOL_GPL(ata_drive_probe_reset); |
Tejun Heo | 623a312 | 2006-03-05 17:55:58 +0900 | [diff] [blame] | 5146 | EXPORT_SYMBOL_GPL(ata_dev_revalidate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | EXPORT_SYMBOL_GPL(ata_port_disable); |
Jeff Garzik | 67846b3 | 2005-10-05 02:58:32 -0400 | [diff] [blame] | 5148 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
Tejun Heo | 6f8b995 | 2006-01-24 17:05:21 +0900 | [diff] [blame] | 5149 | EXPORT_SYMBOL_GPL(ata_busy_sleep); |
Tejun Heo | 86e45b6 | 2006-03-05 15:29:09 +0900 | [diff] [blame] | 5150 | EXPORT_SYMBOL_GPL(ata_port_queue_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |
| 5152 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
Tejun Heo | f29841e | 2006-02-10 15:10:48 +0900 | [diff] [blame] | 5153 | EXPORT_SYMBOL_GPL(ata_scsi_timed_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | EXPORT_SYMBOL_GPL(ata_scsi_error); |
| 5155 | EXPORT_SYMBOL_GPL(ata_scsi_slave_config); |
| 5156 | EXPORT_SYMBOL_GPL(ata_scsi_release); |
| 5157 | EXPORT_SYMBOL_GPL(ata_host_intr); |
| 5158 | EXPORT_SYMBOL_GPL(ata_dev_classify); |
Tejun Heo | 6a62a04 | 2006-02-13 10:02:46 +0900 | [diff] [blame] | 5159 | EXPORT_SYMBOL_GPL(ata_id_string); |
| 5160 | EXPORT_SYMBOL_GPL(ata_id_c_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
Tejun Heo | a72ec4c | 2006-01-23 13:09:37 +0900 | [diff] [blame] | 5162 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); |
| 5163 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | |
Alan Cox | 1bc4ccf | 2006-01-09 17:18:14 +0000 | [diff] [blame] | 5165 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); |
Alan Cox | 452503f | 2005-10-21 19:01:32 -0400 | [diff] [blame] | 5166 | EXPORT_SYMBOL_GPL(ata_timing_compute); |
| 5167 | EXPORT_SYMBOL_GPL(ata_timing_merge); |
| 5168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | #ifdef CONFIG_PCI |
| 5170 | EXPORT_SYMBOL_GPL(pci_test_config_bits); |
Jeff Garzik | 374b187 | 2005-08-30 05:42:52 -0400 | [diff] [blame] | 5171 | EXPORT_SYMBOL_GPL(ata_pci_host_stop); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); |
| 5173 | EXPORT_SYMBOL_GPL(ata_pci_init_one); |
| 5174 | EXPORT_SYMBOL_GPL(ata_pci_remove_one); |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5175 | EXPORT_SYMBOL_GPL(ata_pci_device_suspend); |
| 5176 | EXPORT_SYMBOL_GPL(ata_pci_device_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5177 | #endif /* CONFIG_PCI */ |
Jens Axboe | 9b84754 | 2006-01-06 09:28:07 +0100 | [diff] [blame] | 5178 | |
| 5179 | EXPORT_SYMBOL_GPL(ata_device_suspend); |
| 5180 | EXPORT_SYMBOL_GPL(ata_device_resume); |
| 5181 | EXPORT_SYMBOL_GPL(ata_scsi_device_suspend); |
| 5182 | EXPORT_SYMBOL_GPL(ata_scsi_device_resume); |