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