Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 1 | /* |
Dave Jones | f3a03b0 | 2007-07-16 11:23:03 -0400 | [diff] [blame] | 2 | * libata-sff.c - helper library for PCI IDE BMDMA |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 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-2006 Red Hat, Inc. All rights reserved. |
| 9 | * Copyright 2003-2006 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 | * |
| 33 | */ |
| 34 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 35 | #include <linux/kernel.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/libata.h> |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 38 | #include <linux/highmem.h> |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 39 | |
| 40 | #include "libata.h" |
| 41 | |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 42 | const struct ata_port_operations ata_sff_port_ops = { |
| 43 | .inherits = &ata_base_port_ops, |
| 44 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 45 | .qc_prep = ata_sff_qc_prep, |
| 46 | .qc_issue = ata_sff_qc_issue, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 47 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 48 | .freeze = ata_sff_freeze, |
| 49 | .thaw = ata_sff_thaw, |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 50 | .prereset = ata_sff_prereset, |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 51 | .softreset = ata_sff_softreset, |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame^] | 52 | .hardreset = sata_sff_hardreset, |
Tejun Heo | 203c75b | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 53 | .postreset = ata_sff_postreset, |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 54 | .error_handler = ata_sff_error_handler, |
| 55 | .post_internal_cmd = ata_sff_post_internal_cmd, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 56 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 57 | .sff_dev_select = ata_sff_dev_select, |
| 58 | .sff_check_status = ata_sff_check_status, |
| 59 | .sff_tf_load = ata_sff_tf_load, |
| 60 | .sff_tf_read = ata_sff_tf_read, |
| 61 | .sff_exec_command = ata_sff_exec_command, |
| 62 | .sff_data_xfer = ata_sff_data_xfer, |
| 63 | .sff_irq_on = ata_sff_irq_on, |
Tejun Heo | 288623a | 2008-04-07 22:47:17 +0900 | [diff] [blame] | 64 | .sff_irq_clear = ata_sff_irq_clear, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 65 | |
| 66 | .port_start = ata_sff_port_start, |
| 67 | }; |
| 68 | |
| 69 | const struct ata_port_operations ata_bmdma_port_ops = { |
| 70 | .inherits = &ata_sff_port_ops, |
| 71 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 72 | .mode_filter = ata_bmdma_mode_filter, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 73 | |
| 74 | .bmdma_setup = ata_bmdma_setup, |
| 75 | .bmdma_start = ata_bmdma_start, |
| 76 | .bmdma_stop = ata_bmdma_stop, |
| 77 | .bmdma_status = ata_bmdma_status, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * ata_fill_sg - Fill PCI IDE PRD table |
| 82 | * @qc: Metadata associated with taskfile to be transferred |
| 83 | * |
| 84 | * Fill PCI IDE PRD (scatter-gather) table with segments |
| 85 | * associated with the current disk command. |
| 86 | * |
| 87 | * LOCKING: |
| 88 | * spin_lock_irqsave(host lock) |
| 89 | * |
| 90 | */ |
| 91 | static void ata_fill_sg(struct ata_queued_cmd *qc) |
| 92 | { |
| 93 | struct ata_port *ap = qc->ap; |
| 94 | struct scatterlist *sg; |
| 95 | unsigned int si, pi; |
| 96 | |
| 97 | pi = 0; |
| 98 | for_each_sg(qc->sg, sg, qc->n_elem, si) { |
| 99 | u32 addr, offset; |
| 100 | u32 sg_len, len; |
| 101 | |
| 102 | /* determine if physical DMA addr spans 64K boundary. |
| 103 | * Note h/w doesn't support 64-bit, so we unconditionally |
| 104 | * truncate dma_addr_t to u32. |
| 105 | */ |
| 106 | addr = (u32) sg_dma_address(sg); |
| 107 | sg_len = sg_dma_len(sg); |
| 108 | |
| 109 | while (sg_len) { |
| 110 | offset = addr & 0xffff; |
| 111 | len = sg_len; |
| 112 | if ((offset + sg_len) > 0x10000) |
| 113 | len = 0x10000 - offset; |
| 114 | |
| 115 | ap->prd[pi].addr = cpu_to_le32(addr); |
| 116 | ap->prd[pi].flags_len = cpu_to_le32(len & 0xffff); |
| 117 | VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len); |
| 118 | |
| 119 | pi++; |
| 120 | sg_len -= len; |
| 121 | addr += len; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | ap->prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * ata_fill_sg_dumb - Fill PCI IDE PRD table |
| 130 | * @qc: Metadata associated with taskfile to be transferred |
| 131 | * |
| 132 | * Fill PCI IDE PRD (scatter-gather) table with segments |
| 133 | * associated with the current disk command. Perform the fill |
| 134 | * so that we avoid writing any length 64K records for |
| 135 | * controllers that don't follow the spec. |
| 136 | * |
| 137 | * LOCKING: |
| 138 | * spin_lock_irqsave(host lock) |
| 139 | * |
| 140 | */ |
| 141 | static void ata_fill_sg_dumb(struct ata_queued_cmd *qc) |
| 142 | { |
| 143 | struct ata_port *ap = qc->ap; |
| 144 | struct scatterlist *sg; |
| 145 | unsigned int si, pi; |
| 146 | |
| 147 | pi = 0; |
| 148 | for_each_sg(qc->sg, sg, qc->n_elem, si) { |
| 149 | u32 addr, offset; |
| 150 | u32 sg_len, len, blen; |
| 151 | |
| 152 | /* determine if physical DMA addr spans 64K boundary. |
| 153 | * Note h/w doesn't support 64-bit, so we unconditionally |
| 154 | * truncate dma_addr_t to u32. |
| 155 | */ |
| 156 | addr = (u32) sg_dma_address(sg); |
| 157 | sg_len = sg_dma_len(sg); |
| 158 | |
| 159 | while (sg_len) { |
| 160 | offset = addr & 0xffff; |
| 161 | len = sg_len; |
| 162 | if ((offset + sg_len) > 0x10000) |
| 163 | len = 0x10000 - offset; |
| 164 | |
| 165 | blen = len & 0xffff; |
| 166 | ap->prd[pi].addr = cpu_to_le32(addr); |
| 167 | if (blen == 0) { |
| 168 | /* Some PATA chipsets like the CS5530 can't |
| 169 | cope with 0x0000 meaning 64K as the spec says */ |
| 170 | ap->prd[pi].flags_len = cpu_to_le32(0x8000); |
| 171 | blen = 0x8000; |
| 172 | ap->prd[++pi].addr = cpu_to_le32(addr + 0x8000); |
| 173 | } |
| 174 | ap->prd[pi].flags_len = cpu_to_le32(blen); |
| 175 | VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len); |
| 176 | |
| 177 | pi++; |
| 178 | sg_len -= len; |
| 179 | addr += len; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | ap->prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); |
| 184 | } |
| 185 | |
| 186 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 187 | * ata_sff_qc_prep - Prepare taskfile for submission |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 188 | * @qc: Metadata associated with taskfile to be prepared |
| 189 | * |
| 190 | * Prepare ATA taskfile for submission. |
| 191 | * |
| 192 | * LOCKING: |
| 193 | * spin_lock_irqsave(host lock) |
| 194 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 195 | void ata_sff_qc_prep(struct ata_queued_cmd *qc) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 196 | { |
| 197 | if (!(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 198 | return; |
| 199 | |
| 200 | ata_fill_sg(qc); |
| 201 | } |
| 202 | |
| 203 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 204 | * ata_sff_dumb_qc_prep - Prepare taskfile for submission |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 205 | * @qc: Metadata associated with taskfile to be prepared |
| 206 | * |
| 207 | * Prepare ATA taskfile for submission. |
| 208 | * |
| 209 | * LOCKING: |
| 210 | * spin_lock_irqsave(host lock) |
| 211 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 212 | void ata_sff_dumb_qc_prep(struct ata_queued_cmd *qc) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 213 | { |
| 214 | if (!(qc->flags & ATA_QCFLAG_DMAMAP)) |
| 215 | return; |
| 216 | |
| 217 | ata_fill_sg_dumb(qc); |
| 218 | } |
| 219 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 220 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 221 | * ata_sff_check_status - Read device status reg & clear interrupt |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 222 | * @ap: port where the device is |
| 223 | * |
| 224 | * Reads ATA taskfile status register for currently-selected device |
| 225 | * and return its value. This also clears pending interrupts |
| 226 | * from this device |
| 227 | * |
| 228 | * LOCKING: |
| 229 | * Inherited from caller. |
| 230 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 231 | u8 ata_sff_check_status(struct ata_port *ap) |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 232 | { |
| 233 | return ioread8(ap->ioaddr.status_addr); |
| 234 | } |
| 235 | |
| 236 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 237 | * ata_sff_altstatus - Read device alternate status reg |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 238 | * @ap: port where the device is |
| 239 | * |
| 240 | * Reads ATA taskfile alternate status register for |
| 241 | * currently-selected device and return its value. |
| 242 | * |
| 243 | * Note: may NOT be used as the check_altstatus() entry in |
| 244 | * ata_port_operations. |
| 245 | * |
| 246 | * LOCKING: |
| 247 | * Inherited from caller. |
| 248 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 249 | u8 ata_sff_altstatus(struct ata_port *ap) |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 250 | { |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 251 | if (ap->ops->sff_check_altstatus) |
| 252 | return ap->ops->sff_check_altstatus(ap); |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 253 | |
| 254 | return ioread8(ap->ioaddr.altstatus_addr); |
| 255 | } |
| 256 | |
| 257 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 258 | * ata_sff_busy_sleep - sleep until BSY clears, or timeout |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 259 | * @ap: port containing status register to be polled |
| 260 | * @tmout_pat: impatience timeout |
| 261 | * @tmout: overall timeout |
| 262 | * |
| 263 | * Sleep until ATA Status register bit BSY clears, |
| 264 | * or a timeout occurs. |
| 265 | * |
| 266 | * LOCKING: |
| 267 | * Kernel thread context (may sleep). |
| 268 | * |
| 269 | * RETURNS: |
| 270 | * 0 on success, -errno otherwise. |
| 271 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 272 | int ata_sff_busy_sleep(struct ata_port *ap, |
| 273 | unsigned long tmout_pat, unsigned long tmout) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 274 | { |
| 275 | unsigned long timer_start, timeout; |
| 276 | u8 status; |
| 277 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 278 | status = ata_sff_busy_wait(ap, ATA_BUSY, 300); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 279 | timer_start = jiffies; |
| 280 | timeout = timer_start + tmout_pat; |
| 281 | while (status != 0xff && (status & ATA_BUSY) && |
| 282 | time_before(jiffies, timeout)) { |
| 283 | msleep(50); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 284 | status = ata_sff_busy_wait(ap, ATA_BUSY, 3); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | if (status != 0xff && (status & ATA_BUSY)) |
| 288 | ata_port_printk(ap, KERN_WARNING, |
| 289 | "port is slow to respond, please be patient " |
| 290 | "(Status 0x%x)\n", status); |
| 291 | |
| 292 | timeout = timer_start + tmout; |
| 293 | while (status != 0xff && (status & ATA_BUSY) && |
| 294 | time_before(jiffies, timeout)) { |
| 295 | msleep(50); |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 296 | status = ap->ops->sff_check_status(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | if (status == 0xff) |
| 300 | return -ENODEV; |
| 301 | |
| 302 | if (status & ATA_BUSY) { |
| 303 | ata_port_printk(ap, KERN_ERR, "port failed to respond " |
| 304 | "(%lu secs, Status 0x%x)\n", |
| 305 | tmout / HZ, status); |
| 306 | return -EBUSY; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 312 | static int ata_sff_check_ready(struct ata_link *link) |
| 313 | { |
| 314 | u8 status = link->ap->ops->sff_check_status(link->ap); |
| 315 | |
| 316 | if (!(status & ATA_BUSY)) |
| 317 | return 1; |
| 318 | if (status == 0xff) |
| 319 | return -ENODEV; |
| 320 | return 0; |
| 321 | } |
| 322 | |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 323 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 324 | * ata_sff_wait_ready - sleep until BSY clears, or timeout |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 325 | * @link: SFF link to wait ready status for |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 326 | * @deadline: deadline jiffies for the operation |
| 327 | * |
| 328 | * Sleep until ATA Status register bit BSY clears, or timeout |
| 329 | * occurs. |
| 330 | * |
| 331 | * LOCKING: |
| 332 | * Kernel thread context (may sleep). |
| 333 | * |
| 334 | * RETURNS: |
| 335 | * 0 on success, -errno otherwise. |
| 336 | */ |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 337 | int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 338 | { |
Tejun Heo | aa2731a | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 339 | return ata_wait_ready(link, deadline, ata_sff_check_ready); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 343 | * ata_sff_dev_select - Select device 0/1 on ATA bus |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 344 | * @ap: ATA channel to manipulate |
| 345 | * @device: ATA device (numbered from zero) to select |
| 346 | * |
| 347 | * Use the method defined in the ATA specification to |
| 348 | * make either device 0, or device 1, active on the |
| 349 | * ATA channel. Works with both PIO and MMIO. |
| 350 | * |
| 351 | * May be used as the dev_select() entry in ata_port_operations. |
| 352 | * |
| 353 | * LOCKING: |
| 354 | * caller. |
| 355 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 356 | void ata_sff_dev_select(struct ata_port *ap, unsigned int device) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 357 | { |
| 358 | u8 tmp; |
| 359 | |
| 360 | if (device == 0) |
| 361 | tmp = ATA_DEVICE_OBS; |
| 362 | else |
| 363 | tmp = ATA_DEVICE_OBS | ATA_DEV1; |
| 364 | |
| 365 | iowrite8(tmp, ap->ioaddr.device_addr); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 366 | ata_sff_pause(ap); /* needed; also flushes, for mmio */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /** |
| 370 | * ata_dev_select - Select device 0/1 on ATA bus |
| 371 | * @ap: ATA channel to manipulate |
| 372 | * @device: ATA device (numbered from zero) to select |
| 373 | * @wait: non-zero to wait for Status register BSY bit to clear |
| 374 | * @can_sleep: non-zero if context allows sleeping |
| 375 | * |
| 376 | * Use the method defined in the ATA specification to |
| 377 | * make either device 0, or device 1, active on the |
| 378 | * ATA channel. |
| 379 | * |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 380 | * This is a high-level version of ata_sff_dev_select(), which |
| 381 | * additionally provides the services of inserting the proper |
| 382 | * pauses and status polling, where needed. |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 383 | * |
| 384 | * LOCKING: |
| 385 | * caller. |
| 386 | */ |
| 387 | void ata_dev_select(struct ata_port *ap, unsigned int device, |
| 388 | unsigned int wait, unsigned int can_sleep) |
| 389 | { |
| 390 | if (ata_msg_probe(ap)) |
| 391 | ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, " |
| 392 | "device %u, wait %u\n", device, wait); |
| 393 | |
| 394 | if (wait) |
| 395 | ata_wait_idle(ap); |
| 396 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 397 | ap->ops->sff_dev_select(ap, device); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 398 | |
| 399 | if (wait) { |
| 400 | if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) |
| 401 | msleep(150); |
| 402 | ata_wait_idle(ap); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 407 | * ata_sff_irq_on - Enable interrupts on a port. |
Tejun Heo | 90088bb | 2006-10-09 11:10:26 +0900 | [diff] [blame] | 408 | * @ap: Port on which interrupts are enabled. |
| 409 | * |
| 410 | * Enable interrupts on a legacy IDE device using MMIO or PIO, |
| 411 | * wait for idle, clear any pending interrupts. |
| 412 | * |
| 413 | * LOCKING: |
| 414 | * Inherited from caller. |
| 415 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 416 | u8 ata_sff_irq_on(struct ata_port *ap) |
Tejun Heo | 90088bb | 2006-10-09 11:10:26 +0900 | [diff] [blame] | 417 | { |
| 418 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 419 | u8 tmp; |
| 420 | |
| 421 | ap->ctl &= ~ATA_NIEN; |
| 422 | ap->last_ctl = ap->ctl; |
| 423 | |
Tejun Heo | f659f0e4 | 2008-03-06 13:12:54 +0900 | [diff] [blame] | 424 | if (ioaddr->ctl_addr) |
| 425 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
Tejun Heo | 90088bb | 2006-10-09 11:10:26 +0900 | [diff] [blame] | 426 | tmp = ata_wait_idle(ap); |
| 427 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 428 | ap->ops->sff_irq_clear(ap); |
Tejun Heo | 90088bb | 2006-10-09 11:10:26 +0900 | [diff] [blame] | 429 | |
| 430 | return tmp; |
| 431 | } |
| 432 | |
| 433 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 434 | * ata_sff_irq_clear - Clear PCI IDE BMDMA interrupt. |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 435 | * @ap: Port associated with this ATA transaction. |
| 436 | * |
| 437 | * Clear interrupt and error flags in DMA status register. |
| 438 | * |
| 439 | * May be used as the irq_clear() entry in ata_port_operations. |
| 440 | * |
| 441 | * LOCKING: |
| 442 | * spin_lock_irqsave(host lock) |
| 443 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 444 | void ata_sff_irq_clear(struct ata_port *ap) |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 445 | { |
| 446 | void __iomem *mmio = ap->ioaddr.bmdma_addr; |
| 447 | |
| 448 | if (!mmio) |
| 449 | return; |
| 450 | |
| 451 | iowrite8(ioread8(mmio + ATA_DMA_STATUS), mmio + ATA_DMA_STATUS); |
| 452 | } |
| 453 | |
| 454 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 455 | * ata_sff_tf_load - send taskfile registers to host controller |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 456 | * @ap: Port to which output is sent |
| 457 | * @tf: ATA taskfile register set |
| 458 | * |
| 459 | * Outputs ATA taskfile to standard ATA host controller. |
| 460 | * |
| 461 | * LOCKING: |
| 462 | * Inherited from caller. |
| 463 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 464 | void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 465 | { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 466 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 467 | unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; |
| 468 | |
| 469 | if (tf->ctl != ap->last_ctl) { |
Tejun Heo | f659f0e4 | 2008-03-06 13:12:54 +0900 | [diff] [blame] | 470 | if (ioaddr->ctl_addr) |
| 471 | iowrite8(tf->ctl, ioaddr->ctl_addr); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 472 | ap->last_ctl = tf->ctl; |
| 473 | ata_wait_idle(ap); |
| 474 | } |
| 475 | |
| 476 | if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { |
Tejun Heo | f659f0e4 | 2008-03-06 13:12:54 +0900 | [diff] [blame] | 477 | WARN_ON(!ioaddr->ctl_addr); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 478 | iowrite8(tf->hob_feature, ioaddr->feature_addr); |
| 479 | iowrite8(tf->hob_nsect, ioaddr->nsect_addr); |
| 480 | iowrite8(tf->hob_lbal, ioaddr->lbal_addr); |
| 481 | iowrite8(tf->hob_lbam, ioaddr->lbam_addr); |
| 482 | iowrite8(tf->hob_lbah, ioaddr->lbah_addr); |
| 483 | VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n", |
| 484 | tf->hob_feature, |
| 485 | tf->hob_nsect, |
| 486 | tf->hob_lbal, |
| 487 | tf->hob_lbam, |
| 488 | tf->hob_lbah); |
| 489 | } |
| 490 | |
| 491 | if (is_addr) { |
| 492 | iowrite8(tf->feature, ioaddr->feature_addr); |
| 493 | iowrite8(tf->nsect, ioaddr->nsect_addr); |
| 494 | iowrite8(tf->lbal, ioaddr->lbal_addr); |
| 495 | iowrite8(tf->lbam, ioaddr->lbam_addr); |
| 496 | iowrite8(tf->lbah, ioaddr->lbah_addr); |
| 497 | VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n", |
| 498 | tf->feature, |
| 499 | tf->nsect, |
| 500 | tf->lbal, |
| 501 | tf->lbam, |
| 502 | tf->lbah); |
| 503 | } |
| 504 | |
| 505 | if (tf->flags & ATA_TFLAG_DEVICE) { |
| 506 | iowrite8(tf->device, ioaddr->device_addr); |
| 507 | VPRINTK("device 0x%X\n", tf->device); |
| 508 | } |
| 509 | |
| 510 | ata_wait_idle(ap); |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 514 | * ata_sff_tf_read - input device's ATA taskfile shadow registers |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 515 | * @ap: Port from which input is read |
| 516 | * @tf: ATA taskfile register set for storing input |
| 517 | * |
| 518 | * Reads ATA taskfile registers for currently-selected device |
Alan Cox | 76548ed | 2007-11-19 14:34:56 +0000 | [diff] [blame] | 519 | * into @tf. Assumes the device has a fully SFF compliant task file |
| 520 | * layout and behaviour. If you device does not (eg has a different |
| 521 | * status method) then you will need to provide a replacement tf_read |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 522 | * |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 523 | * LOCKING: |
| 524 | * Inherited from caller. |
| 525 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 526 | void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf) |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 527 | { |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 528 | struct ata_ioports *ioaddr = &ap->ioaddr; |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 529 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 530 | tf->command = ata_sff_check_status(ap); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 531 | tf->feature = ioread8(ioaddr->error_addr); |
| 532 | tf->nsect = ioread8(ioaddr->nsect_addr); |
| 533 | tf->lbal = ioread8(ioaddr->lbal_addr); |
| 534 | tf->lbam = ioread8(ioaddr->lbam_addr); |
| 535 | tf->lbah = ioread8(ioaddr->lbah_addr); |
| 536 | tf->device = ioread8(ioaddr->device_addr); |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 537 | |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 538 | if (tf->flags & ATA_TFLAG_LBA48) { |
Tejun Heo | f659f0e4 | 2008-03-06 13:12:54 +0900 | [diff] [blame] | 539 | if (likely(ioaddr->ctl_addr)) { |
| 540 | iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); |
| 541 | tf->hob_feature = ioread8(ioaddr->error_addr); |
| 542 | tf->hob_nsect = ioread8(ioaddr->nsect_addr); |
| 543 | tf->hob_lbal = ioread8(ioaddr->lbal_addr); |
| 544 | tf->hob_lbam = ioread8(ioaddr->lbam_addr); |
| 545 | tf->hob_lbah = ioread8(ioaddr->lbah_addr); |
| 546 | iowrite8(tf->ctl, ioaddr->ctl_addr); |
| 547 | ap->last_ctl = tf->ctl; |
| 548 | } else |
| 549 | WARN_ON(1); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 550 | } |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 553 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 554 | * ata_sff_exec_command - issue ATA command to host controller |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 555 | * @ap: port to which command is being issued |
| 556 | * @tf: ATA taskfile register set |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 557 | * |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 558 | * Issues ATA command, with proper synchronization with interrupt |
| 559 | * handler / other threads. |
Jeff Garzik | 2cc432e | 2006-03-23 00:32:03 -0500 | [diff] [blame] | 560 | * |
| 561 | * LOCKING: |
Jeff Garzik | cca3974 | 2006-08-24 03:19:22 -0400 | [diff] [blame] | 562 | * spin_lock_irqsave(host lock) |
Jeff Garzik | 2cc432e | 2006-03-23 00:32:03 -0500 | [diff] [blame] | 563 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 564 | void ata_sff_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) |
Jeff Garzik | 2cc432e | 2006-03-23 00:32:03 -0500 | [diff] [blame] | 565 | { |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 566 | DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command); |
Jeff Garzik | 2cc432e | 2006-03-23 00:32:03 -0500 | [diff] [blame] | 567 | |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 568 | iowrite8(tf->command, ap->ioaddr.command_addr); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 569 | ata_sff_pause(ap); |
Jeff Garzik | 2cc432e | 2006-03-23 00:32:03 -0500 | [diff] [blame] | 570 | } |
| 571 | |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 572 | /** |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 573 | * ata_tf_to_host - issue ATA taskfile to host controller |
| 574 | * @ap: port to which command is being issued |
| 575 | * @tf: ATA taskfile register set |
| 576 | * |
| 577 | * Issues ATA taskfile register set to ATA host controller, |
| 578 | * with proper synchronization with interrupt handler and |
| 579 | * other threads. |
| 580 | * |
| 581 | * LOCKING: |
| 582 | * spin_lock_irqsave(host lock) |
| 583 | */ |
| 584 | static inline void ata_tf_to_host(struct ata_port *ap, |
| 585 | const struct ata_taskfile *tf) |
| 586 | { |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 587 | ap->ops->sff_tf_load(ap, tf); |
| 588 | ap->ops->sff_exec_command(ap, tf); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 592 | * ata_sff_data_xfer - Transfer data by PIO |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 593 | * @dev: device to target |
| 594 | * @buf: data buffer |
| 595 | * @buflen: buffer length |
| 596 | * @rw: read/write |
| 597 | * |
| 598 | * Transfer data from/to the device data register by PIO. |
| 599 | * |
| 600 | * LOCKING: |
| 601 | * Inherited from caller. |
| 602 | * |
| 603 | * RETURNS: |
| 604 | * Bytes consumed. |
| 605 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 606 | unsigned int ata_sff_data_xfer(struct ata_device *dev, unsigned char *buf, |
| 607 | unsigned int buflen, int rw) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 608 | { |
| 609 | struct ata_port *ap = dev->link->ap; |
| 610 | void __iomem *data_addr = ap->ioaddr.data_addr; |
| 611 | unsigned int words = buflen >> 1; |
| 612 | |
| 613 | /* Transfer multiple of 2 bytes */ |
| 614 | if (rw == READ) |
| 615 | ioread16_rep(data_addr, buf, words); |
| 616 | else |
| 617 | iowrite16_rep(data_addr, buf, words); |
| 618 | |
| 619 | /* Transfer trailing 1 byte, if any. */ |
| 620 | if (unlikely(buflen & 0x01)) { |
| 621 | __le16 align_buf[1] = { 0 }; |
| 622 | unsigned char *trailing_buf = buf + buflen - 1; |
| 623 | |
| 624 | if (rw == READ) { |
| 625 | align_buf[0] = cpu_to_le16(ioread16(data_addr)); |
| 626 | memcpy(trailing_buf, align_buf, 1); |
| 627 | } else { |
| 628 | memcpy(align_buf, trailing_buf, 1); |
| 629 | iowrite16(le16_to_cpu(align_buf[0]), data_addr); |
| 630 | } |
| 631 | words++; |
| 632 | } |
| 633 | |
| 634 | return words << 1; |
| 635 | } |
| 636 | |
| 637 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 638 | * ata_sff_data_xfer_noirq - Transfer data by PIO |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 639 | * @dev: device to target |
| 640 | * @buf: data buffer |
| 641 | * @buflen: buffer length |
| 642 | * @rw: read/write |
| 643 | * |
| 644 | * Transfer data from/to the device data register by PIO. Do the |
| 645 | * transfer with interrupts disabled. |
| 646 | * |
| 647 | * LOCKING: |
| 648 | * Inherited from caller. |
| 649 | * |
| 650 | * RETURNS: |
| 651 | * Bytes consumed. |
| 652 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 653 | unsigned int ata_sff_data_xfer_noirq(struct ata_device *dev, unsigned char *buf, |
| 654 | unsigned int buflen, int rw) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 655 | { |
| 656 | unsigned long flags; |
| 657 | unsigned int consumed; |
| 658 | |
| 659 | local_irq_save(flags); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 660 | consumed = ata_sff_data_xfer(dev, buf, buflen, rw); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 661 | local_irq_restore(flags); |
| 662 | |
| 663 | return consumed; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * ata_pio_sector - Transfer a sector of data. |
| 668 | * @qc: Command on going |
| 669 | * |
| 670 | * Transfer qc->sect_size bytes of data from/to the ATA device. |
| 671 | * |
| 672 | * LOCKING: |
| 673 | * Inherited from caller. |
| 674 | */ |
| 675 | static void ata_pio_sector(struct ata_queued_cmd *qc) |
| 676 | { |
| 677 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
| 678 | struct ata_port *ap = qc->ap; |
| 679 | struct page *page; |
| 680 | unsigned int offset; |
| 681 | unsigned char *buf; |
| 682 | |
| 683 | if (qc->curbytes == qc->nbytes - qc->sect_size) |
| 684 | ap->hsm_task_state = HSM_ST_LAST; |
| 685 | |
| 686 | page = sg_page(qc->cursg); |
| 687 | offset = qc->cursg->offset + qc->cursg_ofs; |
| 688 | |
| 689 | /* get the current page and offset */ |
| 690 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 691 | offset %= PAGE_SIZE; |
| 692 | |
| 693 | DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 694 | |
| 695 | if (PageHighMem(page)) { |
| 696 | unsigned long flags; |
| 697 | |
| 698 | /* FIXME: use a bounce buffer */ |
| 699 | local_irq_save(flags); |
| 700 | buf = kmap_atomic(page, KM_IRQ0); |
| 701 | |
| 702 | /* do the actual data transfer */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 703 | ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size, |
| 704 | do_write); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 705 | |
| 706 | kunmap_atomic(buf, KM_IRQ0); |
| 707 | local_irq_restore(flags); |
| 708 | } else { |
| 709 | buf = page_address(page); |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 710 | ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size, |
| 711 | do_write); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | qc->curbytes += qc->sect_size; |
| 715 | qc->cursg_ofs += qc->sect_size; |
| 716 | |
| 717 | if (qc->cursg_ofs == qc->cursg->length) { |
| 718 | qc->cursg = sg_next(qc->cursg); |
| 719 | qc->cursg_ofs = 0; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * ata_pio_sectors - Transfer one or many sectors. |
| 725 | * @qc: Command on going |
| 726 | * |
| 727 | * Transfer one or many sectors of data from/to the |
| 728 | * ATA device for the DRQ request. |
| 729 | * |
| 730 | * LOCKING: |
| 731 | * Inherited from caller. |
| 732 | */ |
| 733 | static void ata_pio_sectors(struct ata_queued_cmd *qc) |
| 734 | { |
| 735 | if (is_multi_taskfile(&qc->tf)) { |
| 736 | /* READ/WRITE MULTIPLE */ |
| 737 | unsigned int nsect; |
| 738 | |
| 739 | WARN_ON(qc->dev->multi_count == 0); |
| 740 | |
| 741 | nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, |
| 742 | qc->dev->multi_count); |
| 743 | while (nsect--) |
| 744 | ata_pio_sector(qc); |
| 745 | } else |
| 746 | ata_pio_sector(qc); |
| 747 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 748 | ata_sff_altstatus(qc->ap); /* flush */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | /** |
| 752 | * atapi_send_cdb - Write CDB bytes to hardware |
| 753 | * @ap: Port to which ATAPI device is attached. |
| 754 | * @qc: Taskfile currently active |
| 755 | * |
| 756 | * When device has indicated its readiness to accept |
| 757 | * a CDB, this function is called. Send the CDB. |
| 758 | * |
| 759 | * LOCKING: |
| 760 | * caller. |
| 761 | */ |
| 762 | static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc) |
| 763 | { |
| 764 | /* send SCSI cdb */ |
| 765 | DPRINTK("send cdb\n"); |
| 766 | WARN_ON(qc->dev->cdb_len < 12); |
| 767 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 768 | ap->ops->sff_data_xfer(qc->dev, qc->cdb, qc->dev->cdb_len, 1); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 769 | ata_sff_altstatus(ap); /* flush */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 770 | |
| 771 | switch (qc->tf.protocol) { |
| 772 | case ATAPI_PROT_PIO: |
| 773 | ap->hsm_task_state = HSM_ST; |
| 774 | break; |
| 775 | case ATAPI_PROT_NODATA: |
| 776 | ap->hsm_task_state = HSM_ST_LAST; |
| 777 | break; |
| 778 | case ATAPI_PROT_DMA: |
| 779 | ap->hsm_task_state = HSM_ST_LAST; |
| 780 | /* initiate bmdma */ |
| 781 | ap->ops->bmdma_start(qc); |
| 782 | break; |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * __atapi_pio_bytes - Transfer data from/to the ATAPI device. |
| 788 | * @qc: Command on going |
| 789 | * @bytes: number of bytes |
| 790 | * |
| 791 | * Transfer Transfer data from/to the ATAPI device. |
| 792 | * |
| 793 | * LOCKING: |
| 794 | * Inherited from caller. |
| 795 | * |
| 796 | */ |
| 797 | static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) |
| 798 | { |
| 799 | int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; |
| 800 | struct ata_port *ap = qc->ap; |
| 801 | struct ata_device *dev = qc->dev; |
| 802 | struct ata_eh_info *ehi = &dev->link->eh_info; |
| 803 | struct scatterlist *sg; |
| 804 | struct page *page; |
| 805 | unsigned char *buf; |
| 806 | unsigned int offset, count, consumed; |
| 807 | |
| 808 | next_sg: |
| 809 | sg = qc->cursg; |
| 810 | if (unlikely(!sg)) { |
| 811 | ata_ehi_push_desc(ehi, "unexpected or too much trailing data " |
| 812 | "buf=%u cur=%u bytes=%u", |
| 813 | qc->nbytes, qc->curbytes, bytes); |
| 814 | return -1; |
| 815 | } |
| 816 | |
| 817 | page = sg_page(sg); |
| 818 | offset = sg->offset + qc->cursg_ofs; |
| 819 | |
| 820 | /* get the current page and offset */ |
| 821 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
| 822 | offset %= PAGE_SIZE; |
| 823 | |
| 824 | /* don't overrun current sg */ |
| 825 | count = min(sg->length - qc->cursg_ofs, bytes); |
| 826 | |
| 827 | /* don't cross page boundaries */ |
| 828 | count = min(count, (unsigned int)PAGE_SIZE - offset); |
| 829 | |
| 830 | DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
| 831 | |
| 832 | if (PageHighMem(page)) { |
| 833 | unsigned long flags; |
| 834 | |
| 835 | /* FIXME: use bounce buffer */ |
| 836 | local_irq_save(flags); |
| 837 | buf = kmap_atomic(page, KM_IRQ0); |
| 838 | |
| 839 | /* do the actual data transfer */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 840 | consumed = ap->ops->sff_data_xfer(dev, buf + offset, count, rw); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 841 | |
| 842 | kunmap_atomic(buf, KM_IRQ0); |
| 843 | local_irq_restore(flags); |
| 844 | } else { |
| 845 | buf = page_address(page); |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 846 | consumed = ap->ops->sff_data_xfer(dev, buf + offset, count, rw); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | bytes -= min(bytes, consumed); |
| 850 | qc->curbytes += count; |
| 851 | qc->cursg_ofs += count; |
| 852 | |
| 853 | if (qc->cursg_ofs == sg->length) { |
| 854 | qc->cursg = sg_next(qc->cursg); |
| 855 | qc->cursg_ofs = 0; |
| 856 | } |
| 857 | |
| 858 | /* consumed can be larger than count only for the last transfer */ |
| 859 | WARN_ON(qc->cursg && count != consumed); |
| 860 | |
| 861 | if (bytes) |
| 862 | goto next_sg; |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * atapi_pio_bytes - Transfer data from/to the ATAPI device. |
| 868 | * @qc: Command on going |
| 869 | * |
| 870 | * Transfer Transfer data from/to the ATAPI device. |
| 871 | * |
| 872 | * LOCKING: |
| 873 | * Inherited from caller. |
| 874 | */ |
| 875 | static void atapi_pio_bytes(struct ata_queued_cmd *qc) |
| 876 | { |
| 877 | struct ata_port *ap = qc->ap; |
| 878 | struct ata_device *dev = qc->dev; |
| 879 | struct ata_eh_info *ehi = &dev->link->eh_info; |
| 880 | unsigned int ireason, bc_lo, bc_hi, bytes; |
| 881 | int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; |
| 882 | |
| 883 | /* Abuse qc->result_tf for temp storage of intermediate TF |
| 884 | * here to save some kernel stack usage. |
| 885 | * For normal completion, qc->result_tf is not relevant. For |
| 886 | * error, qc->result_tf is later overwritten by ata_qc_complete(). |
| 887 | * So, the correctness of qc->result_tf is not affected. |
| 888 | */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 889 | ap->ops->sff_tf_read(ap, &qc->result_tf); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 890 | ireason = qc->result_tf.nsect; |
| 891 | bc_lo = qc->result_tf.lbam; |
| 892 | bc_hi = qc->result_tf.lbah; |
| 893 | bytes = (bc_hi << 8) | bc_lo; |
| 894 | |
| 895 | /* shall be cleared to zero, indicating xfer of data */ |
| 896 | if (unlikely(ireason & (1 << 0))) |
| 897 | goto atapi_check; |
| 898 | |
| 899 | /* make sure transfer direction matches expected */ |
| 900 | i_write = ((ireason & (1 << 1)) == 0) ? 1 : 0; |
| 901 | if (unlikely(do_write != i_write)) |
| 902 | goto atapi_check; |
| 903 | |
| 904 | if (unlikely(!bytes)) |
| 905 | goto atapi_check; |
| 906 | |
| 907 | VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); |
| 908 | |
| 909 | if (unlikely(__atapi_pio_bytes(qc, bytes))) |
| 910 | goto err_out; |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 911 | ata_sff_altstatus(ap); /* flush */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 912 | |
| 913 | return; |
| 914 | |
| 915 | atapi_check: |
| 916 | ata_ehi_push_desc(ehi, "ATAPI check failed (ireason=0x%x bytes=%u)", |
| 917 | ireason, bytes); |
| 918 | err_out: |
| 919 | qc->err_mask |= AC_ERR_HSM; |
| 920 | ap->hsm_task_state = HSM_ST_ERR; |
| 921 | } |
| 922 | |
| 923 | /** |
| 924 | * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue. |
| 925 | * @ap: the target ata_port |
| 926 | * @qc: qc on going |
| 927 | * |
| 928 | * RETURNS: |
| 929 | * 1 if ok in workqueue, 0 otherwise. |
| 930 | */ |
| 931 | static inline int ata_hsm_ok_in_wq(struct ata_port *ap, struct ata_queued_cmd *qc) |
| 932 | { |
| 933 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 934 | return 1; |
| 935 | |
| 936 | if (ap->hsm_task_state == HSM_ST_FIRST) { |
| 937 | if (qc->tf.protocol == ATA_PROT_PIO && |
| 938 | (qc->tf.flags & ATA_TFLAG_WRITE)) |
| 939 | return 1; |
| 940 | |
| 941 | if (ata_is_atapi(qc->tf.protocol) && |
| 942 | !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) |
| 943 | return 1; |
| 944 | } |
| 945 | |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * ata_hsm_qc_complete - finish a qc running on standard HSM |
| 951 | * @qc: Command to complete |
| 952 | * @in_wq: 1 if called from workqueue, 0 otherwise |
| 953 | * |
| 954 | * Finish @qc which is running on standard HSM. |
| 955 | * |
| 956 | * LOCKING: |
| 957 | * If @in_wq is zero, spin_lock_irqsave(host lock). |
| 958 | * Otherwise, none on entry and grabs host lock. |
| 959 | */ |
| 960 | static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq) |
| 961 | { |
| 962 | struct ata_port *ap = qc->ap; |
| 963 | unsigned long flags; |
| 964 | |
| 965 | if (ap->ops->error_handler) { |
| 966 | if (in_wq) { |
| 967 | spin_lock_irqsave(ap->lock, flags); |
| 968 | |
| 969 | /* EH might have kicked in while host lock is |
| 970 | * released. |
| 971 | */ |
| 972 | qc = ata_qc_from_tag(ap, qc->tag); |
| 973 | if (qc) { |
| 974 | if (likely(!(qc->err_mask & AC_ERR_HSM))) { |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 975 | ap->ops->sff_irq_on(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 976 | ata_qc_complete(qc); |
| 977 | } else |
| 978 | ata_port_freeze(ap); |
| 979 | } |
| 980 | |
| 981 | spin_unlock_irqrestore(ap->lock, flags); |
| 982 | } else { |
| 983 | if (likely(!(qc->err_mask & AC_ERR_HSM))) |
| 984 | ata_qc_complete(qc); |
| 985 | else |
| 986 | ata_port_freeze(ap); |
| 987 | } |
| 988 | } else { |
| 989 | if (in_wq) { |
| 990 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 991 | ap->ops->sff_irq_on(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 992 | ata_qc_complete(qc); |
| 993 | spin_unlock_irqrestore(ap->lock, flags); |
| 994 | } else |
| 995 | ata_qc_complete(qc); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1000 | * ata_sff_hsm_move - move the HSM to the next state. |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1001 | * @ap: the target ata_port |
| 1002 | * @qc: qc on going |
| 1003 | * @status: current device status |
| 1004 | * @in_wq: 1 if called from workqueue, 0 otherwise |
| 1005 | * |
| 1006 | * RETURNS: |
| 1007 | * 1 when poll next status needed, 0 otherwise. |
| 1008 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1009 | int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc, |
| 1010 | u8 status, int in_wq) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1011 | { |
| 1012 | unsigned long flags = 0; |
| 1013 | int poll_next; |
| 1014 | |
| 1015 | WARN_ON((qc->flags & ATA_QCFLAG_ACTIVE) == 0); |
| 1016 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1017 | /* Make sure ata_sff_qc_issue() does not throw things |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1018 | * like DMA polling into the workqueue. Notice that |
| 1019 | * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). |
| 1020 | */ |
| 1021 | WARN_ON(in_wq != ata_hsm_ok_in_wq(ap, qc)); |
| 1022 | |
| 1023 | fsm_start: |
| 1024 | DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n", |
| 1025 | ap->print_id, qc->tf.protocol, ap->hsm_task_state, status); |
| 1026 | |
| 1027 | switch (ap->hsm_task_state) { |
| 1028 | case HSM_ST_FIRST: |
| 1029 | /* Send first data block or PACKET CDB */ |
| 1030 | |
| 1031 | /* If polling, we will stay in the work queue after |
| 1032 | * sending the data. Otherwise, interrupt handler |
| 1033 | * takes over after sending the data. |
| 1034 | */ |
| 1035 | poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); |
| 1036 | |
| 1037 | /* check device status */ |
| 1038 | if (unlikely((status & ATA_DRQ) == 0)) { |
| 1039 | /* handle BSY=0, DRQ=0 as error */ |
| 1040 | if (likely(status & (ATA_ERR | ATA_DF))) |
| 1041 | /* device stops HSM for abort/error */ |
| 1042 | qc->err_mask |= AC_ERR_DEV; |
| 1043 | else |
| 1044 | /* HSM violation. Let EH handle this */ |
| 1045 | qc->err_mask |= AC_ERR_HSM; |
| 1046 | |
| 1047 | ap->hsm_task_state = HSM_ST_ERR; |
| 1048 | goto fsm_start; |
| 1049 | } |
| 1050 | |
| 1051 | /* Device should not ask for data transfer (DRQ=1) |
| 1052 | * when it finds something wrong. |
| 1053 | * We ignore DRQ here and stop the HSM by |
| 1054 | * changing hsm_task_state to HSM_ST_ERR and |
| 1055 | * let the EH abort the command or reset the device. |
| 1056 | */ |
| 1057 | if (unlikely(status & (ATA_ERR | ATA_DF))) { |
| 1058 | /* Some ATAPI tape drives forget to clear the ERR bit |
| 1059 | * when doing the next command (mostly request sense). |
| 1060 | * We ignore ERR here to workaround and proceed sending |
| 1061 | * the CDB. |
| 1062 | */ |
| 1063 | if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) { |
| 1064 | ata_port_printk(ap, KERN_WARNING, |
| 1065 | "DRQ=1 with device error, " |
| 1066 | "dev_stat 0x%X\n", status); |
| 1067 | qc->err_mask |= AC_ERR_HSM; |
| 1068 | ap->hsm_task_state = HSM_ST_ERR; |
| 1069 | goto fsm_start; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | /* Send the CDB (atapi) or the first data block (ata pio out). |
| 1074 | * During the state transition, interrupt handler shouldn't |
| 1075 | * be invoked before the data transfer is complete and |
| 1076 | * hsm_task_state is changed. Hence, the following locking. |
| 1077 | */ |
| 1078 | if (in_wq) |
| 1079 | spin_lock_irqsave(ap->lock, flags); |
| 1080 | |
| 1081 | if (qc->tf.protocol == ATA_PROT_PIO) { |
| 1082 | /* PIO data out protocol. |
| 1083 | * send first data block. |
| 1084 | */ |
| 1085 | |
| 1086 | /* ata_pio_sectors() might change the state |
| 1087 | * to HSM_ST_LAST. so, the state is changed here |
| 1088 | * before ata_pio_sectors(). |
| 1089 | */ |
| 1090 | ap->hsm_task_state = HSM_ST; |
| 1091 | ata_pio_sectors(qc); |
| 1092 | } else |
| 1093 | /* send CDB */ |
| 1094 | atapi_send_cdb(ap, qc); |
| 1095 | |
| 1096 | if (in_wq) |
| 1097 | spin_unlock_irqrestore(ap->lock, flags); |
| 1098 | |
| 1099 | /* if polling, ata_pio_task() handles the rest. |
| 1100 | * otherwise, interrupt handler takes over from here. |
| 1101 | */ |
| 1102 | break; |
| 1103 | |
| 1104 | case HSM_ST: |
| 1105 | /* complete command or read/write the data register */ |
| 1106 | if (qc->tf.protocol == ATAPI_PROT_PIO) { |
| 1107 | /* ATAPI PIO protocol */ |
| 1108 | if ((status & ATA_DRQ) == 0) { |
| 1109 | /* No more data to transfer or device error. |
| 1110 | * Device error will be tagged in HSM_ST_LAST. |
| 1111 | */ |
| 1112 | ap->hsm_task_state = HSM_ST_LAST; |
| 1113 | goto fsm_start; |
| 1114 | } |
| 1115 | |
| 1116 | /* Device should not ask for data transfer (DRQ=1) |
| 1117 | * when it finds something wrong. |
| 1118 | * We ignore DRQ here and stop the HSM by |
| 1119 | * changing hsm_task_state to HSM_ST_ERR and |
| 1120 | * let the EH abort the command or reset the device. |
| 1121 | */ |
| 1122 | if (unlikely(status & (ATA_ERR | ATA_DF))) { |
| 1123 | ata_port_printk(ap, KERN_WARNING, "DRQ=1 with " |
| 1124 | "device error, dev_stat 0x%X\n", |
| 1125 | status); |
| 1126 | qc->err_mask |= AC_ERR_HSM; |
| 1127 | ap->hsm_task_state = HSM_ST_ERR; |
| 1128 | goto fsm_start; |
| 1129 | } |
| 1130 | |
| 1131 | atapi_pio_bytes(qc); |
| 1132 | |
| 1133 | if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) |
| 1134 | /* bad ireason reported by device */ |
| 1135 | goto fsm_start; |
| 1136 | |
| 1137 | } else { |
| 1138 | /* ATA PIO protocol */ |
| 1139 | if (unlikely((status & ATA_DRQ) == 0)) { |
| 1140 | /* handle BSY=0, DRQ=0 as error */ |
| 1141 | if (likely(status & (ATA_ERR | ATA_DF))) |
| 1142 | /* device stops HSM for abort/error */ |
| 1143 | qc->err_mask |= AC_ERR_DEV; |
| 1144 | else |
| 1145 | /* HSM violation. Let EH handle this. |
| 1146 | * Phantom devices also trigger this |
| 1147 | * condition. Mark hint. |
| 1148 | */ |
| 1149 | qc->err_mask |= AC_ERR_HSM | |
| 1150 | AC_ERR_NODEV_HINT; |
| 1151 | |
| 1152 | ap->hsm_task_state = HSM_ST_ERR; |
| 1153 | goto fsm_start; |
| 1154 | } |
| 1155 | |
| 1156 | /* For PIO reads, some devices may ask for |
| 1157 | * data transfer (DRQ=1) alone with ERR=1. |
| 1158 | * We respect DRQ here and transfer one |
| 1159 | * block of junk data before changing the |
| 1160 | * hsm_task_state to HSM_ST_ERR. |
| 1161 | * |
| 1162 | * For PIO writes, ERR=1 DRQ=1 doesn't make |
| 1163 | * sense since the data block has been |
| 1164 | * transferred to the device. |
| 1165 | */ |
| 1166 | if (unlikely(status & (ATA_ERR | ATA_DF))) { |
| 1167 | /* data might be corrputed */ |
| 1168 | qc->err_mask |= AC_ERR_DEV; |
| 1169 | |
| 1170 | if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { |
| 1171 | ata_pio_sectors(qc); |
| 1172 | status = ata_wait_idle(ap); |
| 1173 | } |
| 1174 | |
| 1175 | if (status & (ATA_BUSY | ATA_DRQ)) |
| 1176 | qc->err_mask |= AC_ERR_HSM; |
| 1177 | |
| 1178 | /* ata_pio_sectors() might change the |
| 1179 | * state to HSM_ST_LAST. so, the state |
| 1180 | * is changed after ata_pio_sectors(). |
| 1181 | */ |
| 1182 | ap->hsm_task_state = HSM_ST_ERR; |
| 1183 | goto fsm_start; |
| 1184 | } |
| 1185 | |
| 1186 | ata_pio_sectors(qc); |
| 1187 | |
| 1188 | if (ap->hsm_task_state == HSM_ST_LAST && |
| 1189 | (!(qc->tf.flags & ATA_TFLAG_WRITE))) { |
| 1190 | /* all data read */ |
| 1191 | status = ata_wait_idle(ap); |
| 1192 | goto fsm_start; |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | poll_next = 1; |
| 1197 | break; |
| 1198 | |
| 1199 | case HSM_ST_LAST: |
| 1200 | if (unlikely(!ata_ok(status))) { |
| 1201 | qc->err_mask |= __ac_err_mask(status); |
| 1202 | ap->hsm_task_state = HSM_ST_ERR; |
| 1203 | goto fsm_start; |
| 1204 | } |
| 1205 | |
| 1206 | /* no more data to transfer */ |
| 1207 | DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n", |
| 1208 | ap->print_id, qc->dev->devno, status); |
| 1209 | |
| 1210 | WARN_ON(qc->err_mask); |
| 1211 | |
| 1212 | ap->hsm_task_state = HSM_ST_IDLE; |
| 1213 | |
| 1214 | /* complete taskfile transaction */ |
| 1215 | ata_hsm_qc_complete(qc, in_wq); |
| 1216 | |
| 1217 | poll_next = 0; |
| 1218 | break; |
| 1219 | |
| 1220 | case HSM_ST_ERR: |
| 1221 | /* make sure qc->err_mask is available to |
| 1222 | * know what's wrong and recover |
| 1223 | */ |
| 1224 | WARN_ON(qc->err_mask == 0); |
| 1225 | |
| 1226 | ap->hsm_task_state = HSM_ST_IDLE; |
| 1227 | |
| 1228 | /* complete taskfile transaction */ |
| 1229 | ata_hsm_qc_complete(qc, in_wq); |
| 1230 | |
| 1231 | poll_next = 0; |
| 1232 | break; |
| 1233 | default: |
| 1234 | poll_next = 0; |
| 1235 | BUG(); |
| 1236 | } |
| 1237 | |
| 1238 | return poll_next; |
| 1239 | } |
| 1240 | |
| 1241 | void ata_pio_task(struct work_struct *work) |
| 1242 | { |
| 1243 | struct ata_port *ap = |
| 1244 | container_of(work, struct ata_port, port_task.work); |
| 1245 | struct ata_queued_cmd *qc = ap->port_task_data; |
| 1246 | u8 status; |
| 1247 | int poll_next; |
| 1248 | |
| 1249 | fsm_start: |
| 1250 | WARN_ON(ap->hsm_task_state == HSM_ST_IDLE); |
| 1251 | |
| 1252 | /* |
| 1253 | * This is purely heuristic. This is a fast path. |
| 1254 | * Sometimes when we enter, BSY will be cleared in |
| 1255 | * a chk-status or two. If not, the drive is probably seeking |
| 1256 | * or something. Snooze for a couple msecs, then |
| 1257 | * chk-status again. If still busy, queue delayed work. |
| 1258 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1259 | status = ata_sff_busy_wait(ap, ATA_BUSY, 5); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1260 | if (status & ATA_BUSY) { |
| 1261 | msleep(2); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1262 | status = ata_sff_busy_wait(ap, ATA_BUSY, 10); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1263 | if (status & ATA_BUSY) { |
| 1264 | ata_pio_queue_task(ap, qc, ATA_SHORT_PAUSE); |
| 1265 | return; |
| 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | /* move the HSM */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1270 | poll_next = ata_sff_hsm_move(ap, qc, status, 1); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1271 | |
| 1272 | /* another command or interrupt handler |
| 1273 | * may be running at this point. |
| 1274 | */ |
| 1275 | if (poll_next) |
| 1276 | goto fsm_start; |
| 1277 | } |
| 1278 | |
| 1279 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1280 | * ata_sff_qc_issue - issue taskfile to device in proto-dependent manner |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1281 | * @qc: command to issue to device |
| 1282 | * |
| 1283 | * Using various libata functions and hooks, this function |
| 1284 | * starts an ATA command. ATA commands are grouped into |
| 1285 | * classes called "protocols", and issuing each type of protocol |
| 1286 | * is slightly different. |
| 1287 | * |
| 1288 | * May be used as the qc_issue() entry in ata_port_operations. |
| 1289 | * |
| 1290 | * LOCKING: |
| 1291 | * spin_lock_irqsave(host lock) |
| 1292 | * |
| 1293 | * RETURNS: |
| 1294 | * Zero on success, AC_ERR_* mask on failure |
| 1295 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1296 | unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1297 | { |
| 1298 | struct ata_port *ap = qc->ap; |
| 1299 | |
| 1300 | /* Use polling pio if the LLD doesn't handle |
| 1301 | * interrupt driven pio and atapi CDB interrupt. |
| 1302 | */ |
| 1303 | if (ap->flags & ATA_FLAG_PIO_POLLING) { |
| 1304 | switch (qc->tf.protocol) { |
| 1305 | case ATA_PROT_PIO: |
| 1306 | case ATA_PROT_NODATA: |
| 1307 | case ATAPI_PROT_PIO: |
| 1308 | case ATAPI_PROT_NODATA: |
| 1309 | qc->tf.flags |= ATA_TFLAG_POLLING; |
| 1310 | break; |
| 1311 | case ATAPI_PROT_DMA: |
| 1312 | if (qc->dev->flags & ATA_DFLAG_CDB_INTR) |
| 1313 | /* see ata_dma_blacklisted() */ |
| 1314 | BUG(); |
| 1315 | break; |
| 1316 | default: |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | /* select the device */ |
| 1322 | ata_dev_select(ap, qc->dev->devno, 1, 0); |
| 1323 | |
| 1324 | /* start the command */ |
| 1325 | switch (qc->tf.protocol) { |
| 1326 | case ATA_PROT_NODATA: |
| 1327 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 1328 | ata_qc_set_polling(qc); |
| 1329 | |
| 1330 | ata_tf_to_host(ap, &qc->tf); |
| 1331 | ap->hsm_task_state = HSM_ST_LAST; |
| 1332 | |
| 1333 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 1334 | ata_pio_queue_task(ap, qc, 0); |
| 1335 | |
| 1336 | break; |
| 1337 | |
| 1338 | case ATA_PROT_DMA: |
| 1339 | WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING); |
| 1340 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1341 | ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1342 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
| 1343 | ap->ops->bmdma_start(qc); /* initiate bmdma */ |
| 1344 | ap->hsm_task_state = HSM_ST_LAST; |
| 1345 | break; |
| 1346 | |
| 1347 | case ATA_PROT_PIO: |
| 1348 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 1349 | ata_qc_set_polling(qc); |
| 1350 | |
| 1351 | ata_tf_to_host(ap, &qc->tf); |
| 1352 | |
| 1353 | if (qc->tf.flags & ATA_TFLAG_WRITE) { |
| 1354 | /* PIO data out protocol */ |
| 1355 | ap->hsm_task_state = HSM_ST_FIRST; |
| 1356 | ata_pio_queue_task(ap, qc, 0); |
| 1357 | |
| 1358 | /* always send first data block using |
| 1359 | * the ata_pio_task() codepath. |
| 1360 | */ |
| 1361 | } else { |
| 1362 | /* PIO data in protocol */ |
| 1363 | ap->hsm_task_state = HSM_ST; |
| 1364 | |
| 1365 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 1366 | ata_pio_queue_task(ap, qc, 0); |
| 1367 | |
| 1368 | /* if polling, ata_pio_task() handles the rest. |
| 1369 | * otherwise, interrupt handler takes over from here. |
| 1370 | */ |
| 1371 | } |
| 1372 | |
| 1373 | break; |
| 1374 | |
| 1375 | case ATAPI_PROT_PIO: |
| 1376 | case ATAPI_PROT_NODATA: |
| 1377 | if (qc->tf.flags & ATA_TFLAG_POLLING) |
| 1378 | ata_qc_set_polling(qc); |
| 1379 | |
| 1380 | ata_tf_to_host(ap, &qc->tf); |
| 1381 | |
| 1382 | ap->hsm_task_state = HSM_ST_FIRST; |
| 1383 | |
| 1384 | /* send cdb by polling if no cdb interrupt */ |
| 1385 | if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || |
| 1386 | (qc->tf.flags & ATA_TFLAG_POLLING)) |
| 1387 | ata_pio_queue_task(ap, qc, 0); |
| 1388 | break; |
| 1389 | |
| 1390 | case ATAPI_PROT_DMA: |
| 1391 | WARN_ON(qc->tf.flags & ATA_TFLAG_POLLING); |
| 1392 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1393 | ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1394 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
| 1395 | ap->hsm_task_state = HSM_ST_FIRST; |
| 1396 | |
| 1397 | /* send cdb by polling if no cdb interrupt */ |
| 1398 | if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) |
| 1399 | ata_pio_queue_task(ap, qc, 0); |
| 1400 | break; |
| 1401 | |
| 1402 | default: |
| 1403 | WARN_ON(1); |
| 1404 | return AC_ERR_SYSTEM; |
| 1405 | } |
| 1406 | |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
| 1410 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1411 | * ata_sff_host_intr - Handle host interrupt for given (port, task) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1412 | * @ap: Port on which interrupt arrived (possibly...) |
| 1413 | * @qc: Taskfile currently active in engine |
| 1414 | * |
| 1415 | * Handle host interrupt for given queued command. Currently, |
| 1416 | * only DMA interrupts are handled. All other commands are |
| 1417 | * handled via polling with interrupts disabled (nIEN bit). |
| 1418 | * |
| 1419 | * LOCKING: |
| 1420 | * spin_lock_irqsave(host lock) |
| 1421 | * |
| 1422 | * RETURNS: |
| 1423 | * One if interrupt was handled, zero if not (shared irq). |
| 1424 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1425 | inline unsigned int ata_sff_host_intr(struct ata_port *ap, |
| 1426 | struct ata_queued_cmd *qc) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1427 | { |
| 1428 | struct ata_eh_info *ehi = &ap->link.eh_info; |
| 1429 | u8 status, host_stat = 0; |
| 1430 | |
| 1431 | VPRINTK("ata%u: protocol %d task_state %d\n", |
| 1432 | ap->print_id, qc->tf.protocol, ap->hsm_task_state); |
| 1433 | |
| 1434 | /* Check whether we are expecting interrupt in this state */ |
| 1435 | switch (ap->hsm_task_state) { |
| 1436 | case HSM_ST_FIRST: |
| 1437 | /* Some pre-ATAPI-4 devices assert INTRQ |
| 1438 | * at this state when ready to receive CDB. |
| 1439 | */ |
| 1440 | |
| 1441 | /* Check the ATA_DFLAG_CDB_INTR flag is enough here. |
| 1442 | * The flag was turned on only for atapi devices. No |
| 1443 | * need to check ata_is_atapi(qc->tf.protocol) again. |
| 1444 | */ |
| 1445 | if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) |
| 1446 | goto idle_irq; |
| 1447 | break; |
| 1448 | case HSM_ST_LAST: |
| 1449 | if (qc->tf.protocol == ATA_PROT_DMA || |
| 1450 | qc->tf.protocol == ATAPI_PROT_DMA) { |
| 1451 | /* check status of DMA engine */ |
| 1452 | host_stat = ap->ops->bmdma_status(ap); |
| 1453 | VPRINTK("ata%u: host_stat 0x%X\n", |
| 1454 | ap->print_id, host_stat); |
| 1455 | |
| 1456 | /* if it's not our irq... */ |
| 1457 | if (!(host_stat & ATA_DMA_INTR)) |
| 1458 | goto idle_irq; |
| 1459 | |
| 1460 | /* before we do anything else, clear DMA-Start bit */ |
| 1461 | ap->ops->bmdma_stop(qc); |
| 1462 | |
| 1463 | if (unlikely(host_stat & ATA_DMA_ERR)) { |
| 1464 | /* error when transfering data to/from memory */ |
| 1465 | qc->err_mask |= AC_ERR_HOST_BUS; |
| 1466 | ap->hsm_task_state = HSM_ST_ERR; |
| 1467 | } |
| 1468 | } |
| 1469 | break; |
| 1470 | case HSM_ST: |
| 1471 | break; |
| 1472 | default: |
| 1473 | goto idle_irq; |
| 1474 | } |
| 1475 | |
| 1476 | /* check altstatus */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1477 | status = ata_sff_altstatus(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1478 | if (status & ATA_BUSY) |
| 1479 | goto idle_irq; |
| 1480 | |
| 1481 | /* check main status, clearing INTRQ */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1482 | status = ap->ops->sff_check_status(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1483 | if (unlikely(status & ATA_BUSY)) |
| 1484 | goto idle_irq; |
| 1485 | |
| 1486 | /* ack bmdma irq events */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1487 | ap->ops->sff_irq_clear(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1488 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1489 | ata_sff_hsm_move(ap, qc, status, 0); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1490 | |
| 1491 | if (unlikely(qc->err_mask) && (qc->tf.protocol == ATA_PROT_DMA || |
| 1492 | qc->tf.protocol == ATAPI_PROT_DMA)) |
| 1493 | ata_ehi_push_desc(ehi, "BMDMA stat 0x%x", host_stat); |
| 1494 | |
| 1495 | return 1; /* irq handled */ |
| 1496 | |
| 1497 | idle_irq: |
| 1498 | ap->stats.idle_irq++; |
| 1499 | |
| 1500 | #ifdef ATA_IRQ_TRAP |
| 1501 | if ((ap->stats.idle_irq % 1000) == 0) { |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1502 | ap->ops->sff_check_status(ap); |
| 1503 | ap->ops->sff_irq_clear(ap); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1504 | ata_port_printk(ap, KERN_WARNING, "irq trap\n"); |
| 1505 | return 1; |
| 1506 | } |
| 1507 | #endif |
| 1508 | return 0; /* irq not handled */ |
| 1509 | } |
| 1510 | |
| 1511 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1512 | * ata_sff_interrupt - Default ATA host interrupt handler |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1513 | * @irq: irq line (unused) |
| 1514 | * @dev_instance: pointer to our ata_host information structure |
| 1515 | * |
| 1516 | * Default interrupt handler for PCI IDE devices. Calls |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1517 | * ata_sff_host_intr() for each port that is not disabled. |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1518 | * |
| 1519 | * LOCKING: |
| 1520 | * Obtains host lock during operation. |
| 1521 | * |
| 1522 | * RETURNS: |
| 1523 | * IRQ_NONE or IRQ_HANDLED. |
| 1524 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1525 | irqreturn_t ata_sff_interrupt(int irq, void *dev_instance) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1526 | { |
| 1527 | struct ata_host *host = dev_instance; |
| 1528 | unsigned int i; |
| 1529 | unsigned int handled = 0; |
| 1530 | unsigned long flags; |
| 1531 | |
| 1532 | /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */ |
| 1533 | spin_lock_irqsave(&host->lock, flags); |
| 1534 | |
| 1535 | for (i = 0; i < host->n_ports; i++) { |
| 1536 | struct ata_port *ap; |
| 1537 | |
| 1538 | ap = host->ports[i]; |
| 1539 | if (ap && |
| 1540 | !(ap->flags & ATA_FLAG_DISABLED)) { |
| 1541 | struct ata_queued_cmd *qc; |
| 1542 | |
| 1543 | qc = ata_qc_from_tag(ap, ap->link.active_tag); |
| 1544 | if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) && |
| 1545 | (qc->flags & ATA_QCFLAG_ACTIVE)) |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1546 | handled |= ata_sff_host_intr(ap, qc); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
| 1550 | spin_unlock_irqrestore(&host->lock, flags); |
| 1551 | |
| 1552 | return IRQ_RETVAL(handled); |
| 1553 | } |
| 1554 | |
| 1555 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1556 | * ata_sff_freeze - Freeze SFF controller port |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1557 | * @ap: port to freeze |
| 1558 | * |
| 1559 | * Freeze BMDMA controller port. |
| 1560 | * |
| 1561 | * LOCKING: |
| 1562 | * Inherited from caller. |
| 1563 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1564 | void ata_sff_freeze(struct ata_port *ap) |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1565 | { |
| 1566 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 1567 | |
| 1568 | ap->ctl |= ATA_NIEN; |
| 1569 | ap->last_ctl = ap->ctl; |
| 1570 | |
Tejun Heo | f659f0e4 | 2008-03-06 13:12:54 +0900 | [diff] [blame] | 1571 | if (ioaddr->ctl_addr) |
| 1572 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
Tejun Heo | 0f0a3ad | 2006-11-17 12:24:22 +0900 | [diff] [blame] | 1573 | |
| 1574 | /* Under certain circumstances, some controllers raise IRQ on |
| 1575 | * ATA_NIEN manipulation. Also, many controllers fail to mask |
| 1576 | * previously pending IRQ on ATA_NIEN assertion. Clear it. |
| 1577 | */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1578 | ap->ops->sff_check_status(ap); |
Tejun Heo | 0f0a3ad | 2006-11-17 12:24:22 +0900 | [diff] [blame] | 1579 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1580 | ap->ops->sff_irq_clear(ap); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1584 | * ata_sff_thaw - Thaw SFF controller port |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1585 | * @ap: port to thaw |
| 1586 | * |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1587 | * Thaw SFF controller port. |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1588 | * |
| 1589 | * LOCKING: |
| 1590 | * Inherited from caller. |
| 1591 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1592 | void ata_sff_thaw(struct ata_port *ap) |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1593 | { |
| 1594 | /* clear & re-enable interrupts */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1595 | ap->ops->sff_check_status(ap); |
| 1596 | ap->ops->sff_irq_clear(ap); |
| 1597 | ap->ops->sff_irq_on(ap); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | /** |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 1601 | * ata_sff_prereset - prepare SFF link for reset |
| 1602 | * @link: SFF link to be reset |
| 1603 | * @deadline: deadline jiffies for the operation |
| 1604 | * |
| 1605 | * SFF link @link is about to be reset. Initialize it. It first |
| 1606 | * calls ata_std_prereset() and wait for !BSY if the port is |
| 1607 | * being softreset. |
| 1608 | * |
| 1609 | * LOCKING: |
| 1610 | * Kernel thread context (may sleep) |
| 1611 | * |
| 1612 | * RETURNS: |
| 1613 | * 0 on success, -errno otherwise. |
| 1614 | */ |
| 1615 | int ata_sff_prereset(struct ata_link *link, unsigned long deadline) |
| 1616 | { |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 1617 | struct ata_eh_context *ehc = &link->eh_context; |
| 1618 | int rc; |
| 1619 | |
| 1620 | rc = ata_std_prereset(link, deadline); |
| 1621 | if (rc) |
| 1622 | return rc; |
| 1623 | |
| 1624 | /* if we're about to do hardreset, nothing more to do */ |
| 1625 | if (ehc->i.action & ATA_EH_HARDRESET) |
| 1626 | return 0; |
| 1627 | |
| 1628 | /* wait for !BSY if we don't know that no device is attached */ |
| 1629 | if (!ata_link_offline(link)) { |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1630 | rc = ata_sff_wait_ready(link, deadline); |
Tejun Heo | 0aa1113 | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 1631 | if (rc && rc != -ENODEV) { |
| 1632 | ata_link_printk(link, KERN_WARNING, "device not ready " |
| 1633 | "(errno=%d), forcing hardreset\n", rc); |
| 1634 | ehc->i.action |= ATA_EH_HARDRESET; |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
| 1641 | /** |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1642 | * ata_devchk - PATA device presence detection |
| 1643 | * @ap: ATA channel to examine |
| 1644 | * @device: Device to examine (starting at zero) |
| 1645 | * |
| 1646 | * This technique was originally described in |
| 1647 | * Hale Landis's ATADRVR (www.ata-atapi.com), and |
| 1648 | * later found its way into the ATA/ATAPI spec. |
| 1649 | * |
| 1650 | * Write a pattern to the ATA shadow registers, |
| 1651 | * and if a device is present, it will respond by |
| 1652 | * correctly storing and echoing back the |
| 1653 | * ATA shadow register contents. |
| 1654 | * |
| 1655 | * LOCKING: |
| 1656 | * caller. |
| 1657 | */ |
| 1658 | static unsigned int ata_devchk(struct ata_port *ap, unsigned int device) |
| 1659 | { |
| 1660 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 1661 | u8 nsect, lbal; |
| 1662 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1663 | ap->ops->sff_dev_select(ap, device); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1664 | |
| 1665 | iowrite8(0x55, ioaddr->nsect_addr); |
| 1666 | iowrite8(0xaa, ioaddr->lbal_addr); |
| 1667 | |
| 1668 | iowrite8(0xaa, ioaddr->nsect_addr); |
| 1669 | iowrite8(0x55, ioaddr->lbal_addr); |
| 1670 | |
| 1671 | iowrite8(0x55, ioaddr->nsect_addr); |
| 1672 | iowrite8(0xaa, ioaddr->lbal_addr); |
| 1673 | |
| 1674 | nsect = ioread8(ioaddr->nsect_addr); |
| 1675 | lbal = ioread8(ioaddr->lbal_addr); |
| 1676 | |
| 1677 | if ((nsect == 0x55) && (lbal == 0xaa)) |
| 1678 | return 1; /* we found a device */ |
| 1679 | |
| 1680 | return 0; /* nothing found */ |
| 1681 | } |
| 1682 | |
| 1683 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1684 | * ata_sff_dev_classify - Parse returned ATA device signature |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1685 | * @dev: ATA device to classify (starting at zero) |
| 1686 | * @present: device seems present |
| 1687 | * @r_err: Value of error register on completion |
| 1688 | * |
| 1689 | * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs, |
| 1690 | * an ATA/ATAPI-defined set of values is placed in the ATA |
| 1691 | * shadow registers, indicating the results of device detection |
| 1692 | * and diagnostics. |
| 1693 | * |
| 1694 | * Select the ATA device, and read the values from the ATA shadow |
| 1695 | * registers. Then parse according to the Error register value, |
| 1696 | * and the spec-defined values examined by ata_dev_classify(). |
| 1697 | * |
| 1698 | * LOCKING: |
| 1699 | * caller. |
| 1700 | * |
| 1701 | * RETURNS: |
| 1702 | * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE. |
| 1703 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1704 | unsigned int ata_sff_dev_classify(struct ata_device *dev, int present, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1705 | u8 *r_err) |
| 1706 | { |
| 1707 | struct ata_port *ap = dev->link->ap; |
| 1708 | struct ata_taskfile tf; |
| 1709 | unsigned int class; |
| 1710 | u8 err; |
| 1711 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1712 | ap->ops->sff_dev_select(ap, dev->devno); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1713 | |
| 1714 | memset(&tf, 0, sizeof(tf)); |
| 1715 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1716 | ap->ops->sff_tf_read(ap, &tf); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1717 | err = tf.feature; |
| 1718 | if (r_err) |
| 1719 | *r_err = err; |
| 1720 | |
| 1721 | /* see if device passed diags: continue and warn later */ |
| 1722 | if (err == 0) |
| 1723 | /* diagnostic fail : do nothing _YET_ */ |
| 1724 | dev->horkage |= ATA_HORKAGE_DIAGNOSTIC; |
| 1725 | else if (err == 1) |
| 1726 | /* do nothing */ ; |
| 1727 | else if ((dev->devno == 0) && (err == 0x81)) |
| 1728 | /* do nothing */ ; |
| 1729 | else |
| 1730 | return ATA_DEV_NONE; |
| 1731 | |
| 1732 | /* determine if device is ATA or ATAPI */ |
| 1733 | class = ata_dev_classify(&tf); |
| 1734 | |
| 1735 | if (class == ATA_DEV_UNKNOWN) { |
| 1736 | /* If the device failed diagnostic, it's likely to |
| 1737 | * have reported incorrect device signature too. |
| 1738 | * Assume ATA device if the device seems present but |
| 1739 | * device signature is invalid with diagnostic |
| 1740 | * failure. |
| 1741 | */ |
| 1742 | if (present && (dev->horkage & ATA_HORKAGE_DIAGNOSTIC)) |
| 1743 | class = ATA_DEV_ATA; |
| 1744 | else |
| 1745 | class = ATA_DEV_NONE; |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1746 | } else if ((class == ATA_DEV_ATA) && |
| 1747 | (ap->ops->sff_check_status(ap) == 0)) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1748 | class = ATA_DEV_NONE; |
| 1749 | |
| 1750 | return class; |
| 1751 | } |
| 1752 | |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1753 | /** |
| 1754 | * ata_sff_wait_after_reset - wait for devices to become ready after reset |
| 1755 | * @link: SFF link which is just reset |
| 1756 | * @devmask: mask of present devices |
| 1757 | * @deadline: deadline jiffies for the operation |
| 1758 | * |
| 1759 | * Wait devices attached to SFF @link to become ready after |
| 1760 | * reset. It contains preceding 150ms wait to avoid accessing TF |
| 1761 | * status register too early. |
| 1762 | * |
| 1763 | * LOCKING: |
| 1764 | * Kernel thread context (may sleep). |
| 1765 | * |
| 1766 | * RETURNS: |
| 1767 | * 0 on success, -ENODEV if some or all of devices in @devmask |
| 1768 | * don't seem to exist. -errno on other errors. |
| 1769 | */ |
| 1770 | int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask, |
| 1771 | unsigned long deadline) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1772 | { |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1773 | struct ata_port *ap = link->ap; |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1774 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 1775 | unsigned int dev0 = devmask & (1 << 0); |
| 1776 | unsigned int dev1 = devmask & (1 << 1); |
| 1777 | int rc, ret = 0; |
| 1778 | |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1779 | msleep(ATA_WAIT_AFTER_RESET_MSECS); |
| 1780 | |
| 1781 | /* always check readiness of the master device */ |
| 1782 | rc = ata_sff_wait_ready(link, deadline); |
| 1783 | /* -ENODEV means the odd clown forgot the D7 pulldown resistor |
| 1784 | * and TF status is 0xff, bail out on it too. |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1785 | */ |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1786 | if (rc) |
| 1787 | return rc; |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1788 | |
| 1789 | /* if device 1 was found in ata_devchk, wait for register |
| 1790 | * access briefly, then wait for BSY to clear. |
| 1791 | */ |
| 1792 | if (dev1) { |
| 1793 | int i; |
| 1794 | |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1795 | ap->ops->sff_dev_select(ap, 1); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1796 | |
| 1797 | /* Wait for register access. Some ATAPI devices fail |
| 1798 | * to set nsect/lbal after reset, so don't waste too |
| 1799 | * much time on it. We're gonna wait for !BSY anyway. |
| 1800 | */ |
| 1801 | for (i = 0; i < 2; i++) { |
| 1802 | u8 nsect, lbal; |
| 1803 | |
| 1804 | nsect = ioread8(ioaddr->nsect_addr); |
| 1805 | lbal = ioread8(ioaddr->lbal_addr); |
| 1806 | if ((nsect == 1) && (lbal == 1)) |
| 1807 | break; |
| 1808 | msleep(50); /* give drive a breather */ |
| 1809 | } |
| 1810 | |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1811 | rc = ata_sff_wait_ready(link, deadline); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1812 | if (rc) { |
| 1813 | if (rc != -ENODEV) |
| 1814 | return rc; |
| 1815 | ret = rc; |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | /* is all this really necessary? */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1820 | ap->ops->sff_dev_select(ap, 0); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1821 | if (dev1) |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1822 | ap->ops->sff_dev_select(ap, 1); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1823 | if (dev0) |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1824 | ap->ops->sff_dev_select(ap, 0); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1825 | |
| 1826 | return ret; |
| 1827 | } |
| 1828 | |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1829 | static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask, |
| 1830 | unsigned long deadline) |
| 1831 | { |
| 1832 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 1833 | |
| 1834 | DPRINTK("ata%u: bus reset via SRST\n", ap->print_id); |
| 1835 | |
| 1836 | /* software reset. causes dev0 to be selected */ |
| 1837 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
| 1838 | udelay(20); /* FIXME: flush */ |
| 1839 | iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); |
| 1840 | udelay(20); /* FIXME: flush */ |
| 1841 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
| 1842 | |
Tejun Heo | 705e76b | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1843 | /* wait the port to become ready */ |
| 1844 | return ata_sff_wait_after_reset(&ap->link, devmask, deadline); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1848 | * ata_sff_softreset - reset host port via ATA SRST |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1849 | * @link: ATA link to reset |
| 1850 | * @classes: resulting classes of attached devices |
| 1851 | * @deadline: deadline jiffies for the operation |
| 1852 | * |
| 1853 | * Reset host port using ATA SRST. |
| 1854 | * |
| 1855 | * LOCKING: |
| 1856 | * Kernel thread context (may sleep) |
| 1857 | * |
| 1858 | * RETURNS: |
| 1859 | * 0 on success, -errno otherwise. |
| 1860 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1861 | int ata_sff_softreset(struct ata_link *link, unsigned int *classes, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1862 | unsigned long deadline) |
| 1863 | { |
| 1864 | struct ata_port *ap = link->ap; |
| 1865 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; |
| 1866 | unsigned int devmask = 0; |
| 1867 | int rc; |
| 1868 | u8 err; |
| 1869 | |
| 1870 | DPRINTK("ENTER\n"); |
| 1871 | |
| 1872 | if (ata_link_offline(link)) { |
| 1873 | classes[0] = ATA_DEV_NONE; |
| 1874 | goto out; |
| 1875 | } |
| 1876 | |
| 1877 | /* determine if device 0/1 are present */ |
| 1878 | if (ata_devchk(ap, 0)) |
| 1879 | devmask |= (1 << 0); |
| 1880 | if (slave_possible && ata_devchk(ap, 1)) |
| 1881 | devmask |= (1 << 1); |
| 1882 | |
| 1883 | /* select device 0 again */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1884 | ap->ops->sff_dev_select(ap, 0); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1885 | |
| 1886 | /* issue bus reset */ |
| 1887 | DPRINTK("about to softreset, devmask=%x\n", devmask); |
| 1888 | rc = ata_bus_softreset(ap, devmask, deadline); |
| 1889 | /* if link is occupied, -ENODEV too is an error */ |
| 1890 | if (rc && (rc != -ENODEV || sata_scr_valid(link))) { |
| 1891 | ata_link_printk(link, KERN_ERR, "SRST failed (errno=%d)\n", rc); |
| 1892 | return rc; |
| 1893 | } |
| 1894 | |
| 1895 | /* determine by signature whether we have ATA or ATAPI devices */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1896 | classes[0] = ata_sff_dev_classify(&link->device[0], |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1897 | devmask & (1 << 0), &err); |
| 1898 | if (slave_possible && err != 0x81) |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1899 | classes[1] = ata_sff_dev_classify(&link->device[1], |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1900 | devmask & (1 << 1), &err); |
| 1901 | |
| 1902 | out: |
| 1903 | DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]); |
| 1904 | return 0; |
| 1905 | } |
| 1906 | |
| 1907 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1908 | * sata_sff_hardreset - reset host port via SATA phy reset |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1909 | * @link: link to reset |
| 1910 | * @class: resulting class of attached device |
| 1911 | * @deadline: deadline jiffies for the operation |
| 1912 | * |
| 1913 | * SATA phy-reset host port using DET bits of SControl register, |
| 1914 | * wait for !BSY and classify the attached device. |
| 1915 | * |
| 1916 | * LOCKING: |
| 1917 | * Kernel thread context (may sleep) |
| 1918 | * |
| 1919 | * RETURNS: |
| 1920 | * 0 on success, -errno otherwise. |
| 1921 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1922 | int sata_sff_hardreset(struct ata_link *link, unsigned int *class, |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1923 | unsigned long deadline) |
| 1924 | { |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1925 | struct ata_eh_context *ehc = &link->eh_context; |
| 1926 | const unsigned long *timing = sata_ehc_deb_timing(ehc); |
| 1927 | bool online; |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1928 | int rc; |
| 1929 | |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1930 | rc = sata_link_hardreset(link, timing, deadline, &online, |
| 1931 | ata_sff_check_ready); |
| 1932 | *class = ATA_DEV_NONE; |
| 1933 | if (online) |
| 1934 | *class = ata_sff_dev_classify(link->device, 1, NULL); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1935 | |
| 1936 | DPRINTK("EXIT, class=%u\n", *class); |
Tejun Heo | 9dadd45 | 2008-04-07 22:47:19 +0900 | [diff] [blame] | 1937 | return rc; |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | /** |
Tejun Heo | 203c75b | 2008-04-07 22:47:18 +0900 | [diff] [blame] | 1941 | * ata_sff_postreset - SFF postreset callback |
| 1942 | * @link: the target SFF ata_link |
| 1943 | * @classes: classes of attached devices |
| 1944 | * |
| 1945 | * This function is invoked after a successful reset. It first |
| 1946 | * calls ata_std_postreset() and performs SFF specific postreset |
| 1947 | * processing. |
| 1948 | * |
| 1949 | * LOCKING: |
| 1950 | * Kernel thread context (may sleep) |
| 1951 | */ |
| 1952 | void ata_sff_postreset(struct ata_link *link, unsigned int *classes) |
| 1953 | { |
| 1954 | struct ata_port *ap = link->ap; |
| 1955 | |
| 1956 | ata_std_postreset(link, classes); |
| 1957 | |
| 1958 | /* is double-select really necessary? */ |
| 1959 | if (classes[0] != ATA_DEV_NONE) |
| 1960 | ap->ops->sff_dev_select(ap, 1); |
| 1961 | if (classes[1] != ATA_DEV_NONE) |
| 1962 | ap->ops->sff_dev_select(ap, 0); |
| 1963 | |
| 1964 | /* bail out if no device is present */ |
| 1965 | if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { |
| 1966 | DPRINTK("EXIT, no device\n"); |
| 1967 | return; |
| 1968 | } |
| 1969 | |
| 1970 | /* set up device control */ |
| 1971 | if (ap->ioaddr.ctl_addr) |
| 1972 | iowrite8(ap->ctl, ap->ioaddr.ctl_addr); |
| 1973 | } |
| 1974 | |
| 1975 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1976 | * ata_sff_error_handler - Stock error handler for BMDMA controller |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1977 | * @ap: port to handle error for |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1978 | * |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1979 | * Stock error handler for SFF controller. It can handle both |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1980 | * PATA and SATA controllers. Many controllers should be able to |
| 1981 | * use this EH as-is or with some added handling before and |
| 1982 | * after. |
| 1983 | * |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1984 | * LOCKING: |
| 1985 | * Kernel thread context (may sleep) |
| 1986 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 1987 | void ata_sff_error_handler(struct ata_port *ap) |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1988 | { |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 1989 | ata_reset_fn_t softreset = ap->ops->softreset; |
| 1990 | ata_reset_fn_t hardreset = ap->ops->hardreset; |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1991 | struct ata_queued_cmd *qc; |
| 1992 | unsigned long flags; |
| 1993 | int thaw = 0; |
| 1994 | |
Tejun Heo | 9af5c9c | 2007-08-06 18:36:22 +0900 | [diff] [blame] | 1995 | qc = __ata_qc_from_tag(ap, ap->link.active_tag); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 1996 | if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) |
| 1997 | qc = NULL; |
| 1998 | |
| 1999 | /* reset PIO HSM and stop DMA engine */ |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 2000 | spin_lock_irqsave(ap->lock, flags); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2001 | |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2002 | ap->hsm_task_state = HSM_ST_IDLE; |
| 2003 | |
Tejun Heo | ed82f96 | 2008-03-25 21:34:39 +0900 | [diff] [blame] | 2004 | if (ap->ioaddr.bmdma_addr && |
| 2005 | qc && (qc->tf.protocol == ATA_PROT_DMA || |
Tejun Heo | 0dc3688 | 2007-12-18 16:34:43 -0500 | [diff] [blame] | 2006 | qc->tf.protocol == ATAPI_PROT_DMA)) { |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2007 | u8 host_stat; |
| 2008 | |
Robert Hancock | fbbb262 | 2006-10-27 19:08:41 -0700 | [diff] [blame] | 2009 | host_stat = ap->ops->bmdma_status(ap); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2010 | |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2011 | /* BMDMA controllers indicate host bus error by |
| 2012 | * setting DMA_ERR bit and timing out. As it wasn't |
| 2013 | * really a timeout event, adjust error mask and |
| 2014 | * cancel frozen state. |
| 2015 | */ |
Alan | 18d90de | 2007-01-24 11:42:38 +0000 | [diff] [blame] | 2016 | if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2017 | qc->err_mask = AC_ERR_HOST_BUS; |
| 2018 | thaw = 1; |
| 2019 | } |
| 2020 | |
| 2021 | ap->ops->bmdma_stop(qc); |
| 2022 | } |
| 2023 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2024 | ata_sff_altstatus(ap); |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2025 | ap->ops->sff_check_status(ap); |
| 2026 | ap->ops->sff_irq_clear(ap); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2027 | |
Jeff Garzik | ba6a130 | 2006-06-22 23:46:10 -0400 | [diff] [blame] | 2028 | spin_unlock_irqrestore(ap->lock, flags); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2029 | |
| 2030 | if (thaw) |
| 2031 | ata_eh_thaw_port(ap); |
| 2032 | |
| 2033 | /* PIO and DMA engines have been stopped, perform recovery */ |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2034 | |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame^] | 2035 | /* Ignore ata_sff_softreset if ctl isn't accessible and |
| 2036 | * built-in hardresets if SCR access isn't available. |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 2037 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2038 | if (softreset == ata_sff_softreset && !ap->ioaddr.ctl_addr) |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 2039 | softreset = NULL; |
Tejun Heo | 57c9efd | 2008-04-07 22:47:19 +0900 | [diff] [blame^] | 2040 | if (ata_is_builtin_hardreset(hardreset) && !sata_scr_valid(&ap->link)) |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 2041 | hardreset = NULL; |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2042 | |
Tejun Heo | a1efdab | 2008-03-25 12:22:50 +0900 | [diff] [blame] | 2043 | ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, |
| 2044 | ap->ops->postreset); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2048 | * ata_sff_post_internal_cmd - Stock post_internal_cmd for SFF controller |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2049 | * @qc: internal command to clean up |
| 2050 | * |
| 2051 | * LOCKING: |
| 2052 | * Kernel thread context (may sleep) |
| 2053 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2054 | void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc) |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2055 | { |
Alan | 61dd08c | 2007-01-25 15:09:05 +0000 | [diff] [blame] | 2056 | if (qc->ap->ioaddr.bmdma_addr) |
| 2057 | ata_bmdma_stop(qc); |
Tejun Heo | 6d97dbd | 2006-05-15 20:58:24 +0900 | [diff] [blame] | 2058 | } |
| 2059 | |
Alan Cox | d92e74d | 2007-06-07 16:19:15 +0100 | [diff] [blame] | 2060 | /** |
| 2061 | * ata_sff_port_start - Set port up for dma. |
| 2062 | * @ap: Port to initialize |
| 2063 | * |
| 2064 | * Called just after data structures for each port are |
| 2065 | * initialized. Allocates space for PRD table if the device |
| 2066 | * is DMA capable SFF. |
| 2067 | * |
| 2068 | * May be used as the port_start() entry in ata_port_operations. |
| 2069 | * |
| 2070 | * LOCKING: |
| 2071 | * Inherited from caller. |
| 2072 | */ |
Alan Cox | d92e74d | 2007-06-07 16:19:15 +0100 | [diff] [blame] | 2073 | int ata_sff_port_start(struct ata_port *ap) |
| 2074 | { |
| 2075 | if (ap->ioaddr.bmdma_addr) |
| 2076 | return ata_port_start(ap); |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2080 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2081 | * ata_sff_std_ports - initialize ioaddr with standard port offsets. |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2082 | * @ioaddr: IO address structure to be initialized |
| 2083 | * |
| 2084 | * Utility function which initializes data_addr, error_addr, |
| 2085 | * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr, |
| 2086 | * device_addr, status_addr, and command_addr to standard offsets |
| 2087 | * relative to cmd_addr. |
| 2088 | * |
| 2089 | * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr. |
| 2090 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2091 | void ata_sff_std_ports(struct ata_ioports *ioaddr) |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2092 | { |
| 2093 | ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; |
| 2094 | ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; |
| 2095 | ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; |
| 2096 | ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; |
| 2097 | ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; |
| 2098 | ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; |
| 2099 | ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; |
| 2100 | ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; |
| 2101 | ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; |
| 2102 | ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; |
| 2103 | } |
| 2104 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2105 | unsigned long ata_bmdma_mode_filter(struct ata_device *adev, |
| 2106 | unsigned long xfer_mask) |
Tejun Heo | 071ce34 | 2008-03-25 22:16:42 +0900 | [diff] [blame] | 2107 | { |
| 2108 | /* Filter out DMA modes if the device has been configured by |
| 2109 | the BIOS as PIO only */ |
| 2110 | |
| 2111 | if (adev->link->ap->ioaddr.bmdma_addr == NULL) |
| 2112 | xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); |
| 2113 | return xfer_mask; |
| 2114 | } |
| 2115 | |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2116 | /** |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2117 | * ata_bmdma_setup - Set up PCI IDE BMDMA transaction |
| 2118 | * @qc: Info associated with this ATA transaction. |
| 2119 | * |
| 2120 | * LOCKING: |
| 2121 | * spin_lock_irqsave(host lock) |
| 2122 | */ |
| 2123 | void ata_bmdma_setup(struct ata_queued_cmd *qc) |
| 2124 | { |
| 2125 | struct ata_port *ap = qc->ap; |
| 2126 | unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); |
| 2127 | u8 dmactl; |
| 2128 | |
| 2129 | /* load PRD table addr. */ |
| 2130 | mb(); /* make sure PRD table writes are visible to controller */ |
| 2131 | iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); |
| 2132 | |
| 2133 | /* specify data direction, triple-check start bit is clear */ |
| 2134 | dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 2135 | dmactl &= ~(ATA_DMA_WR | ATA_DMA_START); |
| 2136 | if (!rw) |
| 2137 | dmactl |= ATA_DMA_WR; |
| 2138 | iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 2139 | |
| 2140 | /* issue r/w command */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2141 | ap->ops->sff_exec_command(ap, &qc->tf); |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | /** |
| 2145 | * ata_bmdma_start - Start a PCI IDE BMDMA transaction |
| 2146 | * @qc: Info associated with this ATA transaction. |
| 2147 | * |
| 2148 | * LOCKING: |
| 2149 | * spin_lock_irqsave(host lock) |
| 2150 | */ |
| 2151 | void ata_bmdma_start(struct ata_queued_cmd *qc) |
| 2152 | { |
| 2153 | struct ata_port *ap = qc->ap; |
| 2154 | u8 dmactl; |
| 2155 | |
| 2156 | /* start host DMA transaction */ |
| 2157 | dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 2158 | iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
| 2159 | |
| 2160 | /* Strictly, one may wish to issue an ioread8() here, to |
| 2161 | * flush the mmio write. However, control also passes |
| 2162 | * to the hardware at this point, and it will interrupt |
| 2163 | * us when we are to resume control. So, in effect, |
| 2164 | * we don't care when the mmio write flushes. |
| 2165 | * Further, a read of the DMA status register _immediately_ |
| 2166 | * following the write may not be what certain flaky hardware |
| 2167 | * is expected, so I think it is best to not add a readb() |
| 2168 | * without first all the MMIO ATA cards/mobos. |
| 2169 | * Or maybe I'm just being paranoid. |
| 2170 | * |
| 2171 | * FIXME: The posting of this write means I/O starts are |
| 2172 | * unneccessarily delayed for MMIO |
| 2173 | */ |
| 2174 | } |
| 2175 | |
| 2176 | /** |
| 2177 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer |
| 2178 | * @qc: Command we are ending DMA for |
| 2179 | * |
| 2180 | * Clears the ATA_DMA_START flag in the dma control register |
| 2181 | * |
| 2182 | * May be used as the bmdma_stop() entry in ata_port_operations. |
| 2183 | * |
| 2184 | * LOCKING: |
| 2185 | * spin_lock_irqsave(host lock) |
| 2186 | */ |
| 2187 | void ata_bmdma_stop(struct ata_queued_cmd *qc) |
| 2188 | { |
| 2189 | struct ata_port *ap = qc->ap; |
| 2190 | void __iomem *mmio = ap->ioaddr.bmdma_addr; |
| 2191 | |
| 2192 | /* clear start/stop bit */ |
| 2193 | iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ATA_DMA_START, |
| 2194 | mmio + ATA_DMA_CMD); |
| 2195 | |
| 2196 | /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2197 | ata_sff_altstatus(ap); /* dummy read */ |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * ata_bmdma_status - Read PCI IDE BMDMA status |
| 2202 | * @ap: Port associated with this ATA transaction. |
| 2203 | * |
| 2204 | * Read and return BMDMA status register. |
| 2205 | * |
| 2206 | * May be used as the bmdma_status() entry in ata_port_operations. |
| 2207 | * |
| 2208 | * LOCKING: |
| 2209 | * spin_lock_irqsave(host lock) |
| 2210 | */ |
| 2211 | u8 ata_bmdma_status(struct ata_port *ap) |
| 2212 | { |
| 2213 | return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); |
| 2214 | } |
| 2215 | |
| 2216 | /** |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2217 | * ata_bus_reset - reset host port and associated ATA channel |
| 2218 | * @ap: port to reset |
| 2219 | * |
| 2220 | * This is typically the first time we actually start issuing |
| 2221 | * commands to the ATA channel. We wait for BSY to clear, then |
| 2222 | * issue EXECUTE DEVICE DIAGNOSTIC command, polling for its |
| 2223 | * result. Determine what devices, if any, are on the channel |
| 2224 | * by looking at the device 0/1 error register. Look at the signature |
| 2225 | * stored in each device's taskfile registers, to determine if |
| 2226 | * the device is ATA or ATAPI. |
| 2227 | * |
| 2228 | * LOCKING: |
| 2229 | * PCI/etc. bus probe sem. |
| 2230 | * Obtains host lock. |
| 2231 | * |
| 2232 | * SIDE EFFECTS: |
| 2233 | * Sets ATA_FLAG_DISABLED if bus reset fails. |
| 2234 | * |
| 2235 | * DEPRECATED: |
| 2236 | * This function is only for drivers which still use old EH and |
| 2237 | * will be removed soon. |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2238 | */ |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2239 | void ata_bus_reset(struct ata_port *ap) |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2240 | { |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2241 | struct ata_device *device = ap->link.device; |
| 2242 | struct ata_ioports *ioaddr = &ap->ioaddr; |
| 2243 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; |
| 2244 | u8 err; |
| 2245 | unsigned int dev0, dev1 = 0, devmask = 0; |
| 2246 | int rc; |
| 2247 | |
| 2248 | DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no); |
| 2249 | |
| 2250 | /* determine if device 0/1 are present */ |
| 2251 | if (ap->flags & ATA_FLAG_SATA_RESET) |
| 2252 | dev0 = 1; |
| 2253 | else { |
| 2254 | dev0 = ata_devchk(ap, 0); |
| 2255 | if (slave_possible) |
| 2256 | dev1 = ata_devchk(ap, 1); |
| 2257 | } |
| 2258 | |
| 2259 | if (dev0) |
| 2260 | devmask |= (1 << 0); |
| 2261 | if (dev1) |
| 2262 | devmask |= (1 << 1); |
| 2263 | |
| 2264 | /* select device 0 again */ |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2265 | ap->ops->sff_dev_select(ap, 0); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2266 | |
| 2267 | /* issue bus reset */ |
| 2268 | if (ap->flags & ATA_FLAG_SRST) { |
| 2269 | rc = ata_bus_softreset(ap, devmask, jiffies + 40 * HZ); |
| 2270 | if (rc && rc != -ENODEV) |
| 2271 | goto err_out; |
| 2272 | } |
| 2273 | |
| 2274 | /* |
| 2275 | * determine by signature whether we have ATA or ATAPI devices |
| 2276 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2277 | device[0].class = ata_sff_dev_classify(&device[0], dev0, &err); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2278 | if ((slave_possible) && (err != 0x81)) |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2279 | device[1].class = ata_sff_dev_classify(&device[1], dev1, &err); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2280 | |
| 2281 | /* is double-select really necessary? */ |
| 2282 | if (device[1].class != ATA_DEV_NONE) |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2283 | ap->ops->sff_dev_select(ap, 1); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2284 | if (device[0].class != ATA_DEV_NONE) |
Tejun Heo | 5682ed3 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2285 | ap->ops->sff_dev_select(ap, 0); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2286 | |
| 2287 | /* if no devices were detected, disable this port */ |
| 2288 | if ((device[0].class == ATA_DEV_NONE) && |
| 2289 | (device[1].class == ATA_DEV_NONE)) |
| 2290 | goto err_out; |
| 2291 | |
| 2292 | if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) { |
| 2293 | /* set up device control for ATA_FLAG_SATA_RESET */ |
| 2294 | iowrite8(ap->ctl, ioaddr->ctl_addr); |
| 2295 | } |
| 2296 | |
| 2297 | DPRINTK("EXIT\n"); |
| 2298 | return; |
| 2299 | |
| 2300 | err_out: |
| 2301 | ata_port_printk(ap, KERN_ERR, "disabling port\n"); |
| 2302 | ata_port_disable(ap); |
| 2303 | |
| 2304 | DPRINTK("EXIT\n"); |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2305 | } |
| 2306 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2307 | #ifdef CONFIG_PCI |
Alan | 4112e16 | 2007-01-08 12:10:05 +0000 | [diff] [blame] | 2308 | |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2309 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2310 | * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2311 | * @pdev: PCI device |
| 2312 | * |
| 2313 | * Some PCI ATA devices report simplex mode but in fact can be told to |
| 2314 | * enter non simplex mode. This implements the necessary logic to |
| 2315 | * perform the task on such devices. Calling it on other devices will |
| 2316 | * have -undefined- behaviour. |
| 2317 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2318 | int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev) |
Alan | 4112e16 | 2007-01-08 12:10:05 +0000 | [diff] [blame] | 2319 | { |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2320 | unsigned long bmdma = pci_resource_start(pdev, 4); |
| 2321 | u8 simplex; |
Jeff Garzik | a84471f | 2007-02-26 05:51:33 -0500 | [diff] [blame] | 2322 | |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2323 | if (bmdma == 0) |
| 2324 | return -ENOENT; |
| 2325 | |
| 2326 | simplex = inb(bmdma + 0x02); |
| 2327 | outb(simplex & 0x60, bmdma + 0x02); |
| 2328 | simplex = inb(bmdma + 0x02); |
| 2329 | if (simplex & 0x80) |
| 2330 | return -EOPNOTSUPP; |
| 2331 | return 0; |
| 2332 | } |
| 2333 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2334 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2335 | * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2336 | * @host: target ATA host |
| 2337 | * |
| 2338 | * Acquire PCI BMDMA resources and initialize @host accordingly. |
| 2339 | * |
| 2340 | * LOCKING: |
| 2341 | * Inherited from calling layer (may sleep). |
| 2342 | * |
| 2343 | * RETURNS: |
| 2344 | * 0 on success, -errno otherwise. |
| 2345 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2346 | int ata_pci_bmdma_init(struct ata_host *host) |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2347 | { |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2348 | struct device *gdev = host->dev; |
| 2349 | struct pci_dev *pdev = to_pci_dev(gdev); |
| 2350 | int i, rc; |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2351 | |
Alan Cox | 6fdc99a | 2007-07-26 18:41:30 +0100 | [diff] [blame] | 2352 | /* No BAR4 allocation: No DMA */ |
| 2353 | if (pci_resource_start(pdev, 4) == 0) |
| 2354 | return 0; |
| 2355 | |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2356 | /* TODO: If we get no DMA mask we should fall back to PIO */ |
| 2357 | rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); |
| 2358 | if (rc) |
| 2359 | return rc; |
| 2360 | rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); |
| 2361 | if (rc) |
| 2362 | return rc; |
| 2363 | |
| 2364 | /* request and iomap DMA region */ |
Tejun Heo | 35a10a8 | 2008-01-04 18:42:21 +0900 | [diff] [blame] | 2365 | rc = pcim_iomap_regions(pdev, 1 << 4, dev_driver_string(gdev)); |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2366 | if (rc) { |
| 2367 | dev_printk(KERN_ERR, gdev, "failed to request/iomap BAR4\n"); |
| 2368 | return -ENOMEM; |
| 2369 | } |
| 2370 | host->iomap = pcim_iomap_table(pdev); |
| 2371 | |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2372 | for (i = 0; i < 2; i++) { |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2373 | struct ata_port *ap = host->ports[i]; |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2374 | void __iomem *bmdma = host->iomap[4] + 8 * i; |
| 2375 | |
| 2376 | if (ata_port_is_dummy(ap)) |
| 2377 | continue; |
| 2378 | |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2379 | ap->ioaddr.bmdma_addr = bmdma; |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2380 | if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && |
| 2381 | (ioread8(bmdma + 2) & 0x80)) |
| 2382 | host->flags |= ATA_HOST_SIMPLEX; |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 2383 | |
| 2384 | ata_port_desc(ap, "bmdma 0x%llx", |
| 2385 | (unsigned long long)pci_resource_start(pdev, 4) + 8 * i); |
Tejun Heo | 0d5ff56 | 2007-02-01 15:06:36 +0900 | [diff] [blame] | 2386 | } |
| 2387 | |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2388 | return 0; |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2389 | } |
| 2390 | |
Tejun Heo | 272f788 | 2008-03-25 22:16:40 +0900 | [diff] [blame] | 2391 | static int ata_resources_present(struct pci_dev *pdev, int port) |
| 2392 | { |
| 2393 | int i; |
| 2394 | |
| 2395 | /* Check the PCI resources for this channel are enabled */ |
| 2396 | port = port * 2; |
| 2397 | for (i = 0; i < 2; i ++) { |
| 2398 | if (pci_resource_start(pdev, port + i) == 0 || |
| 2399 | pci_resource_len(pdev, port + i) == 0) |
| 2400 | return 0; |
| 2401 | } |
| 2402 | return 1; |
| 2403 | } |
| 2404 | |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2405 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2406 | * ata_pci_sff_init_host - acquire native PCI ATA resources and init host |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2407 | * @host: target ATA host |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2408 | * |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2409 | * Acquire native PCI ATA resources for @host and initialize the |
| 2410 | * first two ports of @host accordingly. Ports marked dummy are |
| 2411 | * skipped and allocation failure makes the port dummy. |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2412 | * |
Tejun Heo | d583bc1 | 2007-07-04 18:02:07 +0900 | [diff] [blame] | 2413 | * Note that native PCI resources are valid even for legacy hosts |
| 2414 | * as we fix up pdev resources array early in boot, so this |
| 2415 | * function can be used for both native and legacy SFF hosts. |
| 2416 | * |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2417 | * LOCKING: |
| 2418 | * Inherited from calling layer (may sleep). |
| 2419 | * |
| 2420 | * RETURNS: |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2421 | * 0 if at least one port is initialized, -ENODEV if no port is |
| 2422 | * available. |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2423 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2424 | int ata_pci_sff_init_host(struct ata_host *host) |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2425 | { |
| 2426 | struct device *gdev = host->dev; |
| 2427 | struct pci_dev *pdev = to_pci_dev(gdev); |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2428 | unsigned int mask = 0; |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2429 | int i, rc; |
| 2430 | |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2431 | /* request, iomap BARs and init port addresses accordingly */ |
| 2432 | for (i = 0; i < 2; i++) { |
| 2433 | struct ata_port *ap = host->ports[i]; |
| 2434 | int base = i * 2; |
| 2435 | void __iomem * const *iomap; |
| 2436 | |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2437 | if (ata_port_is_dummy(ap)) |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2438 | continue; |
| 2439 | |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2440 | /* Discard disabled ports. Some controllers show |
| 2441 | * their unused channels this way. Disabled ports are |
| 2442 | * made dummy. |
| 2443 | */ |
| 2444 | if (!ata_resources_present(pdev, i)) { |
| 2445 | ap->ops = &ata_dummy_port_ops; |
| 2446 | continue; |
| 2447 | } |
| 2448 | |
Tejun Heo | 35a10a8 | 2008-01-04 18:42:21 +0900 | [diff] [blame] | 2449 | rc = pcim_iomap_regions(pdev, 0x3 << base, |
| 2450 | dev_driver_string(gdev)); |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2451 | if (rc) { |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2452 | dev_printk(KERN_WARNING, gdev, |
| 2453 | "failed to request/iomap BARs for port %d " |
| 2454 | "(errno=%d)\n", i, rc); |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2455 | if (rc == -EBUSY) |
| 2456 | pcim_pin_device(pdev); |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2457 | ap->ops = &ata_dummy_port_ops; |
| 2458 | continue; |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2459 | } |
| 2460 | host->iomap = iomap = pcim_iomap_table(pdev); |
| 2461 | |
| 2462 | ap->ioaddr.cmd_addr = iomap[base]; |
| 2463 | ap->ioaddr.altstatus_addr = |
| 2464 | ap->ioaddr.ctl_addr = (void __iomem *) |
| 2465 | ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2466 | ata_sff_std_ports(&ap->ioaddr); |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2467 | |
Tejun Heo | cbcdd87 | 2007-08-18 13:14:55 +0900 | [diff] [blame] | 2468 | ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx", |
| 2469 | (unsigned long long)pci_resource_start(pdev, base), |
| 2470 | (unsigned long long)pci_resource_start(pdev, base + 1)); |
| 2471 | |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2472 | mask |= 1 << i; |
| 2473 | } |
| 2474 | |
| 2475 | if (!mask) { |
| 2476 | dev_printk(KERN_ERR, gdev, "no available native port\n"); |
| 2477 | return -ENODEV; |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | return 0; |
| 2481 | } |
| 2482 | |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2483 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2484 | * ata_pci_sff_prepare_host - helper to prepare native PCI ATA host |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2485 | * @pdev: target PCI device |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2486 | * @ppi: array of port_info, must be enough for two ports |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2487 | * @r_host: out argument for the initialized ATA host |
| 2488 | * |
| 2489 | * Helper to allocate ATA host for @pdev, acquire all native PCI |
| 2490 | * resources and initialize it accordingly in one go. |
| 2491 | * |
| 2492 | * LOCKING: |
| 2493 | * Inherited from calling layer (may sleep). |
| 2494 | * |
| 2495 | * RETURNS: |
| 2496 | * 0 on success, -errno otherwise. |
| 2497 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2498 | int ata_pci_sff_prepare_host(struct pci_dev *pdev, |
Tejun Heo | d583bc1 | 2007-07-04 18:02:07 +0900 | [diff] [blame] | 2499 | const struct ata_port_info * const * ppi, |
| 2500 | struct ata_host **r_host) |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2501 | { |
| 2502 | struct ata_host *host; |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2503 | int rc; |
| 2504 | |
| 2505 | if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) |
| 2506 | return -ENOMEM; |
| 2507 | |
| 2508 | host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); |
| 2509 | if (!host) { |
| 2510 | dev_printk(KERN_ERR, &pdev->dev, |
| 2511 | "failed to allocate ATA host\n"); |
| 2512 | rc = -ENOMEM; |
| 2513 | goto err_out; |
| 2514 | } |
| 2515 | |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2516 | rc = ata_pci_sff_init_host(host); |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2517 | if (rc) |
| 2518 | goto err_out; |
| 2519 | |
| 2520 | /* init DMA related stuff */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2521 | rc = ata_pci_bmdma_init(host); |
Tejun Heo | 21b0ad4 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2522 | if (rc) |
| 2523 | goto err_bmdma; |
| 2524 | |
| 2525 | devres_remove_group(&pdev->dev, NULL); |
| 2526 | *r_host = host; |
| 2527 | return 0; |
| 2528 | |
| 2529 | err_bmdma: |
| 2530 | /* This is necessary because PCI and iomap resources are |
| 2531 | * merged and releasing the top group won't release the |
| 2532 | * acquired resources if some of those have been acquired |
| 2533 | * before entering this function. |
| 2534 | */ |
| 2535 | pcim_iounmap_regions(pdev, 0xf); |
| 2536 | err_out: |
| 2537 | devres_release_group(&pdev->dev, NULL); |
| 2538 | return rc; |
| 2539 | } |
| 2540 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2541 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2542 | * ata_pci_sff_activate_host - start SFF host, request IRQ and register it |
Tejun Heo | 4e6b79f | 2008-01-18 18:36:28 +0900 | [diff] [blame] | 2543 | * @host: target SFF ATA host |
| 2544 | * @irq_handler: irq_handler used when requesting IRQ(s) |
| 2545 | * @sht: scsi_host_template to use when registering the host |
| 2546 | * |
| 2547 | * This is the counterpart of ata_host_activate() for SFF ATA |
| 2548 | * hosts. This separate helper is necessary because SFF hosts |
| 2549 | * use two separate interrupts in legacy mode. |
| 2550 | * |
| 2551 | * LOCKING: |
| 2552 | * Inherited from calling layer (may sleep). |
| 2553 | * |
| 2554 | * RETURNS: |
| 2555 | * 0 on success, -errno otherwise. |
| 2556 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2557 | int ata_pci_sff_activate_host(struct ata_host *host, |
Tejun Heo | 4e6b79f | 2008-01-18 18:36:28 +0900 | [diff] [blame] | 2558 | irq_handler_t irq_handler, |
| 2559 | struct scsi_host_template *sht) |
| 2560 | { |
| 2561 | struct device *dev = host->dev; |
| 2562 | struct pci_dev *pdev = to_pci_dev(dev); |
| 2563 | const char *drv_name = dev_driver_string(host->dev); |
| 2564 | int legacy_mode = 0, rc; |
| 2565 | |
| 2566 | rc = ata_host_start(host); |
| 2567 | if (rc) |
| 2568 | return rc; |
| 2569 | |
| 2570 | if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { |
| 2571 | u8 tmp8, mask; |
| 2572 | |
| 2573 | /* TODO: What if one channel is in native mode ... */ |
| 2574 | pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); |
| 2575 | mask = (1 << 2) | (1 << 0); |
| 2576 | if ((tmp8 & mask) != mask) |
| 2577 | legacy_mode = 1; |
| 2578 | #if defined(CONFIG_NO_ATA_LEGACY) |
| 2579 | /* Some platforms with PCI limits cannot address compat |
| 2580 | port space. In that case we punt if their firmware has |
| 2581 | left a device in compatibility mode */ |
| 2582 | if (legacy_mode) { |
| 2583 | printk(KERN_ERR "ata: Compatibility mode ATA is not supported on this platform, skipping.\n"); |
| 2584 | return -EOPNOTSUPP; |
| 2585 | } |
| 2586 | #endif |
| 2587 | } |
| 2588 | |
| 2589 | if (!devres_open_group(dev, NULL, GFP_KERNEL)) |
| 2590 | return -ENOMEM; |
| 2591 | |
| 2592 | if (!legacy_mode && pdev->irq) { |
| 2593 | rc = devm_request_irq(dev, pdev->irq, irq_handler, |
| 2594 | IRQF_SHARED, drv_name, host); |
| 2595 | if (rc) |
| 2596 | goto out; |
| 2597 | |
| 2598 | ata_port_desc(host->ports[0], "irq %d", pdev->irq); |
| 2599 | ata_port_desc(host->ports[1], "irq %d", pdev->irq); |
| 2600 | } else if (legacy_mode) { |
| 2601 | if (!ata_port_is_dummy(host->ports[0])) { |
| 2602 | rc = devm_request_irq(dev, ATA_PRIMARY_IRQ(pdev), |
| 2603 | irq_handler, IRQF_SHARED, |
| 2604 | drv_name, host); |
| 2605 | if (rc) |
| 2606 | goto out; |
| 2607 | |
| 2608 | ata_port_desc(host->ports[0], "irq %d", |
| 2609 | ATA_PRIMARY_IRQ(pdev)); |
| 2610 | } |
| 2611 | |
| 2612 | if (!ata_port_is_dummy(host->ports[1])) { |
| 2613 | rc = devm_request_irq(dev, ATA_SECONDARY_IRQ(pdev), |
| 2614 | irq_handler, IRQF_SHARED, |
| 2615 | drv_name, host); |
| 2616 | if (rc) |
| 2617 | goto out; |
| 2618 | |
| 2619 | ata_port_desc(host->ports[1], "irq %d", |
| 2620 | ATA_SECONDARY_IRQ(pdev)); |
| 2621 | } |
| 2622 | } |
| 2623 | |
| 2624 | rc = ata_host_register(host, sht); |
| 2625 | out: |
| 2626 | if (rc == 0) |
| 2627 | devres_remove_group(dev, NULL); |
| 2628 | else |
| 2629 | devres_release_group(dev, NULL); |
| 2630 | |
| 2631 | return rc; |
| 2632 | } |
| 2633 | |
| 2634 | /** |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2635 | * ata_pci_sff_init_one - Initialize/register PCI IDE host controller |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2636 | * @pdev: Controller to be initialized |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2637 | * @ppi: array of port_info, must be enough for two ports |
Tejun Heo | 1bd5b71 | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 2638 | * @sht: scsi_host_template to use when registering the host |
Tejun Heo | 887125e | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 2639 | * @host_priv: host private_data |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2640 | * |
| 2641 | * This is a helper function which can be called from a driver's |
| 2642 | * xxx_init_one() probe function if the hardware uses traditional |
| 2643 | * IDE taskfile registers. |
| 2644 | * |
| 2645 | * This function calls pci_enable_device(), reserves its register |
| 2646 | * regions, sets the dma mask, enables bus master mode, and calls |
| 2647 | * ata_device_add() |
| 2648 | * |
Alan Cox | 2ec7df0 | 2006-08-10 16:59:10 +0900 | [diff] [blame] | 2649 | * ASSUMPTION: |
| 2650 | * Nobody makes a single channel controller that appears solely as |
| 2651 | * the secondary legacy port on PCI. |
| 2652 | * |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2653 | * LOCKING: |
| 2654 | * Inherited from PCI layer (may sleep). |
| 2655 | * |
| 2656 | * RETURNS: |
| 2657 | * Zero on success, negative on errno-based value on error. |
| 2658 | */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2659 | int ata_pci_sff_init_one(struct pci_dev *pdev, |
| 2660 | const struct ata_port_info * const * ppi, |
| 2661 | struct scsi_host_template *sht, void *host_priv) |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2662 | { |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 2663 | struct device *dev = &pdev->dev; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2664 | const struct ata_port_info *pi = NULL; |
Tejun Heo | 0f834de | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2665 | struct ata_host *host = NULL; |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2666 | int i, rc; |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2667 | |
| 2668 | DPRINTK("ENTER\n"); |
| 2669 | |
Tejun Heo | 1626aeb | 2007-05-04 12:43:58 +0200 | [diff] [blame] | 2670 | /* look up the first valid port_info */ |
| 2671 | for (i = 0; i < 2 && ppi[i]; i++) { |
| 2672 | if (ppi[i]->port_ops != &ata_dummy_port_ops) { |
| 2673 | pi = ppi[i]; |
| 2674 | break; |
| 2675 | } |
| 2676 | } |
| 2677 | |
| 2678 | if (!pi) { |
| 2679 | dev_printk(KERN_ERR, &pdev->dev, |
| 2680 | "no valid port_info specified\n"); |
| 2681 | return -EINVAL; |
| 2682 | } |
| 2683 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 2684 | if (!devres_open_group(dev, NULL, GFP_KERNEL)) |
| 2685 | return -ENOMEM; |
| 2686 | |
Tejun Heo | f0d36ef | 2007-01-20 16:00:28 +0900 | [diff] [blame] | 2687 | rc = pcim_enable_device(pdev); |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2688 | if (rc) |
Tejun Heo | 4e6b79f | 2008-01-18 18:36:28 +0900 | [diff] [blame] | 2689 | goto out; |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2690 | |
Tejun Heo | 4e6b79f | 2008-01-18 18:36:28 +0900 | [diff] [blame] | 2691 | /* prepare and activate SFF host */ |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2692 | rc = ata_pci_sff_prepare_host(pdev, ppi, &host); |
Tejun Heo | d583bc1 | 2007-07-04 18:02:07 +0900 | [diff] [blame] | 2693 | if (rc) |
Tejun Heo | 4e6b79f | 2008-01-18 18:36:28 +0900 | [diff] [blame] | 2694 | goto out; |
Tejun Heo | 887125e | 2008-03-25 12:22:49 +0900 | [diff] [blame] | 2695 | host->private_data = host_priv; |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2696 | |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2697 | pci_set_master(pdev); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2698 | rc = ata_pci_sff_activate_host(host, ata_sff_interrupt, sht); |
Tejun Heo | 4e6b79f | 2008-01-18 18:36:28 +0900 | [diff] [blame] | 2699 | out: |
| 2700 | if (rc == 0) |
| 2701 | devres_remove_group(&pdev->dev, NULL); |
| 2702 | else |
| 2703 | devres_release_group(&pdev->dev, NULL); |
Tejun Heo | d491b27 | 2007-04-17 23:44:07 +0900 | [diff] [blame] | 2704 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2705 | return rc; |
| 2706 | } |
| 2707 | |
Jeff Garzik | 1fdffbc | 2006-02-09 05:15:27 -0500 | [diff] [blame] | 2708 | #endif /* CONFIG_PCI */ |
| 2709 | |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2710 | EXPORT_SYMBOL_GPL(ata_sff_port_ops); |
| 2711 | EXPORT_SYMBOL_GPL(ata_bmdma_port_ops); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2712 | EXPORT_SYMBOL_GPL(ata_sff_qc_prep); |
| 2713 | EXPORT_SYMBOL_GPL(ata_sff_dumb_qc_prep); |
| 2714 | EXPORT_SYMBOL_GPL(ata_sff_dev_select); |
| 2715 | EXPORT_SYMBOL_GPL(ata_sff_check_status); |
| 2716 | EXPORT_SYMBOL_GPL(ata_sff_altstatus); |
| 2717 | EXPORT_SYMBOL_GPL(ata_sff_busy_sleep); |
| 2718 | EXPORT_SYMBOL_GPL(ata_sff_wait_ready); |
| 2719 | EXPORT_SYMBOL_GPL(ata_sff_tf_load); |
| 2720 | EXPORT_SYMBOL_GPL(ata_sff_tf_read); |
| 2721 | EXPORT_SYMBOL_GPL(ata_sff_exec_command); |
| 2722 | EXPORT_SYMBOL_GPL(ata_sff_data_xfer); |
| 2723 | EXPORT_SYMBOL_GPL(ata_sff_data_xfer_noirq); |
| 2724 | EXPORT_SYMBOL_GPL(ata_sff_irq_on); |
| 2725 | EXPORT_SYMBOL_GPL(ata_sff_irq_clear); |
| 2726 | EXPORT_SYMBOL_GPL(ata_sff_hsm_move); |
| 2727 | EXPORT_SYMBOL_GPL(ata_sff_qc_issue); |
| 2728 | EXPORT_SYMBOL_GPL(ata_sff_host_intr); |
| 2729 | EXPORT_SYMBOL_GPL(ata_sff_interrupt); |
| 2730 | EXPORT_SYMBOL_GPL(ata_sff_freeze); |
| 2731 | EXPORT_SYMBOL_GPL(ata_sff_thaw); |
| 2732 | EXPORT_SYMBOL_GPL(ata_sff_prereset); |
| 2733 | EXPORT_SYMBOL_GPL(ata_sff_dev_classify); |
| 2734 | EXPORT_SYMBOL_GPL(ata_sff_wait_after_reset); |
| 2735 | EXPORT_SYMBOL_GPL(ata_sff_softreset); |
| 2736 | EXPORT_SYMBOL_GPL(sata_sff_hardreset); |
| 2737 | EXPORT_SYMBOL_GPL(ata_sff_postreset); |
| 2738 | EXPORT_SYMBOL_GPL(ata_sff_error_handler); |
| 2739 | EXPORT_SYMBOL_GPL(ata_sff_post_internal_cmd); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2740 | EXPORT_SYMBOL_GPL(ata_sff_port_start); |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2741 | EXPORT_SYMBOL_GPL(ata_sff_std_ports); |
| 2742 | EXPORT_SYMBOL_GPL(ata_bmdma_mode_filter); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2743 | EXPORT_SYMBOL_GPL(ata_bmdma_setup); |
| 2744 | EXPORT_SYMBOL_GPL(ata_bmdma_start); |
| 2745 | EXPORT_SYMBOL_GPL(ata_bmdma_stop); |
| 2746 | EXPORT_SYMBOL_GPL(ata_bmdma_status); |
| 2747 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
| 2748 | #ifdef CONFIG_PCI |
Tejun Heo | 9363c38 | 2008-04-07 22:47:16 +0900 | [diff] [blame] | 2749 | EXPORT_SYMBOL_GPL(ata_pci_bmdma_clear_simplex); |
| 2750 | EXPORT_SYMBOL_GPL(ata_pci_bmdma_init); |
| 2751 | EXPORT_SYMBOL_GPL(ata_pci_sff_init_host); |
| 2752 | EXPORT_SYMBOL_GPL(ata_pci_sff_prepare_host); |
| 2753 | EXPORT_SYMBOL_GPL(ata_pci_sff_activate_host); |
| 2754 | EXPORT_SYMBOL_GPL(ata_pci_sff_init_one); |
Tejun Heo | 624d5c5 | 2008-03-25 22:16:41 +0900 | [diff] [blame] | 2755 | #endif /* CONFIG_PCI */ |