Lines Matching +full:tf +full:- +full:a
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-sff.c - helper library for PCI IDE BMDMA
5 * Copyright 2003-2006 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2006 Jeff Garzik
9 * as Documentation/driver-api/libata.rst
12 * http://www.sata-io.org/
53 * ata_sff_check_status - Read device status reg & clear interrupt
56 * Reads ATA taskfile status register for currently-selected device
65 return ioread8(ap->ioaddr.status_addr); in ata_sff_check_status()
70 * ata_sff_altstatus - Read device alternate status reg
72 * @status: pointer to a status value
74 * Reads ATA alternate status register for currently-selected device
87 if (ap->ops->sff_check_altstatus) { in ata_sff_altstatus()
88 tmp = ap->ops->sff_check_altstatus(ap); in ata_sff_altstatus()
91 if (ap->ioaddr.altstatus_addr) { in ata_sff_altstatus()
92 tmp = ioread8(ap->ioaddr.altstatus_addr); in ata_sff_altstatus()
104 * ata_sff_irq_status - Check if the device is busy
123 status = ap->ops->sff_check_status(ap); in ata_sff_irq_status()
128 * ata_sff_sync - Flush writes
145 * ata_sff_pause - Flush writes and wait 400nS
164 * ata_sff_dma_pause - Pause before commencing DMA
188 u8 status = link->ap->ops->sff_check_status(link->ap); in ata_sff_check_ready()
194 * ata_sff_wait_ready - sleep until BSY clears, or timeout
205 * 0 on success, -errno otherwise.
214 * ata_sff_set_devctl - Write device control reg
228 if (ap->ops->sff_set_devctl) { in ata_sff_set_devctl()
229 ap->ops->sff_set_devctl(ap, ctl); in ata_sff_set_devctl()
232 if (ap->ioaddr.ctl_addr) { in ata_sff_set_devctl()
233 iowrite8(ctl, ap->ioaddr.ctl_addr); in ata_sff_set_devctl()
241 * ata_sff_dev_select - Select device 0/1 on ATA bus
263 iowrite8(tmp, ap->ioaddr.device_addr); in ata_sff_dev_select()
269 * ata_dev_select - Select device 0/1 on ATA bus
272 * @wait: non-zero to wait for Status register BSY bit to clear
273 * @can_sleep: non-zero if context allows sleeping
279 * This is a high-level version of ata_sff_dev_select(), which
292 ap->ops->sff_dev_select(ap, device); in ata_dev_select()
295 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) in ata_dev_select()
302 * ata_sff_irq_on - Enable interrupts on a port.
305 * Enable interrupts on a legacy IDE device using MMIO or PIO,
316 if (ap->ops->sff_irq_on) { in ata_sff_irq_on()
317 ap->ops->sff_irq_on(ap); in ata_sff_irq_on()
321 ap->ctl &= ~ATA_NIEN; in ata_sff_irq_on()
322 ap->last_ctl = ap->ctl; in ata_sff_irq_on()
324 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_irq_on()
327 if (ap->ops->sff_irq_clear) in ata_sff_irq_on()
328 ap->ops->sff_irq_clear(ap); in ata_sff_irq_on()
333 * ata_sff_tf_load - send taskfile registers to host controller
335 * @tf: ATA taskfile register set
342 void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_tf_load() argument
344 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_load()
345 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ata_sff_tf_load()
347 if (tf->ctl != ap->last_ctl) { in ata_sff_tf_load()
348 if (ioaddr->ctl_addr) in ata_sff_tf_load()
349 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_load()
350 ap->last_ctl = tf->ctl; in ata_sff_tf_load()
354 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ata_sff_tf_load()
355 WARN_ON_ONCE(!ioaddr->ctl_addr); in ata_sff_tf_load()
356 iowrite8(tf->hob_feature, ioaddr->feature_addr); in ata_sff_tf_load()
357 iowrite8(tf->hob_nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
358 iowrite8(tf->hob_lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
359 iowrite8(tf->hob_lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
360 iowrite8(tf->hob_lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
364 iowrite8(tf->feature, ioaddr->feature_addr); in ata_sff_tf_load()
365 iowrite8(tf->nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
366 iowrite8(tf->lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
367 iowrite8(tf->lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
368 iowrite8(tf->lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
371 if (tf->flags & ATA_TFLAG_DEVICE) in ata_sff_tf_load()
372 iowrite8(tf->device, ioaddr->device_addr); in ata_sff_tf_load()
379 * ata_sff_tf_read - input device's ATA taskfile shadow registers
381 * @tf: ATA taskfile register set for storing input
383 * Reads ATA taskfile registers for currently-selected device
384 * into @tf. Assumes the device has a fully SFF compliant task file
385 * layout and behaviour. If you device does not (eg has a different
386 * status method) then you will need to provide a replacement tf_read
391 void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf) in ata_sff_tf_read() argument
393 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_read()
395 tf->status = ata_sff_check_status(ap); in ata_sff_tf_read()
396 tf->error = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
397 tf->nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
398 tf->lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
399 tf->lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
400 tf->lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
401 tf->device = ioread8(ioaddr->device_addr); in ata_sff_tf_read()
403 if (tf->flags & ATA_TFLAG_LBA48) { in ata_sff_tf_read()
404 if (likely(ioaddr->ctl_addr)) { in ata_sff_tf_read()
405 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in ata_sff_tf_read()
406 tf->hob_feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
407 tf->hob_nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
408 tf->hob_lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
409 tf->hob_lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
410 tf->hob_lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
411 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_read()
412 ap->last_ctl = tf->ctl; in ata_sff_tf_read()
420 * ata_sff_exec_command - issue ATA command to host controller
422 * @tf: ATA taskfile register set
430 void ata_sff_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_exec_command() argument
432 iowrite8(tf->command, ap->ioaddr.command_addr); in ata_sff_exec_command()
438 * ata_tf_to_host - issue ATA taskfile to host controller
440 * @tf: ATA taskfile register set
451 const struct ata_taskfile *tf, in ata_tf_to_host() argument
454 trace_ata_tf_load(ap, tf); in ata_tf_to_host()
455 ap->ops->sff_tf_load(ap, tf); in ata_tf_to_host()
456 trace_ata_exec_command(ap, tf, tag); in ata_tf_to_host()
457 ap->ops->sff_exec_command(ap, tf); in ata_tf_to_host()
461 * ata_sff_data_xfer - Transfer data by PIO
478 struct ata_port *ap = qc->dev->link->ap; in ata_sff_data_xfer()
479 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer()
493 buf += buflen - 1; in ata_sff_data_xfer()
514 * ata_sff_data_xfer32 - Transfer data by PIO
533 struct ata_device *dev = qc->dev; in ata_sff_data_xfer32()
534 struct ata_port *ap = dev->link->ap; in ata_sff_data_xfer32()
535 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer32()
539 if (!(ap->pflags & ATA_PFLAG_PIO32)) in ata_sff_data_xfer32()
553 buf += buflen - slop; in ata_sff_data_xfer32()
580 bool do_write = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_pio_xfer()
584 qc->ap->ops->sff_data_xfer(qc, buf + offset, xfer_size, do_write); in ata_pio_xfer()
592 * ata_pio_sector - Transfer a sector of data.
595 * Transfer qc->sect_size bytes of data from/to the ATA device.
602 struct ata_port *ap = qc->ap; in ata_pio_sector()
606 if (!qc->cursg) { in ata_pio_sector()
607 qc->curbytes = qc->nbytes; in ata_pio_sector()
610 if (qc->curbytes == qc->nbytes - qc->sect_size) in ata_pio_sector()
611 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
613 page = sg_page(qc->cursg); in ata_pio_sector()
614 offset = qc->cursg->offset + qc->cursg_ofs; in ata_pio_sector()
620 trace_ata_sff_pio_transfer_data(qc, offset, qc->sect_size); in ata_pio_sector()
623 * Split the transfer when it splits a page boundary. Note that the in ata_pio_sector()
627 if (offset + qc->sect_size > PAGE_SIZE) { in ata_pio_sector()
628 unsigned int split_len = PAGE_SIZE - offset; in ata_pio_sector()
632 qc->sect_size - split_len); in ata_pio_sector()
634 ata_pio_xfer(qc, page, offset, qc->sect_size); in ata_pio_sector()
637 qc->curbytes += qc->sect_size; in ata_pio_sector()
638 qc->cursg_ofs += qc->sect_size; in ata_pio_sector()
640 if (qc->cursg_ofs == qc->cursg->length) { in ata_pio_sector()
641 qc->cursg = sg_next(qc->cursg); in ata_pio_sector()
642 if (!qc->cursg) in ata_pio_sector()
643 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
644 qc->cursg_ofs = 0; in ata_pio_sector()
649 * ata_pio_sectors - Transfer one or many sectors.
660 if (is_multi_taskfile(&qc->tf)) { in ata_pio_sectors()
664 WARN_ON_ONCE(qc->dev->multi_count == 0); in ata_pio_sectors()
666 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, in ata_pio_sectors()
667 qc->dev->multi_count); in ata_pio_sectors()
668 while (nsect--) in ata_pio_sectors()
673 ata_sff_sync(qc->ap); /* flush */ in ata_pio_sectors()
677 * atapi_send_cdb - Write CDB bytes to hardware
682 * a CDB, this function is called. Send the CDB.
690 trace_atapi_send_cdb(qc, 0, qc->dev->cdb_len); in atapi_send_cdb()
691 WARN_ON_ONCE(qc->dev->cdb_len < 12); in atapi_send_cdb()
693 ap->ops->sff_data_xfer(qc, qc->cdb, qc->dev->cdb_len, 1); in atapi_send_cdb()
697 switch (qc->tf.protocol) { in atapi_send_cdb()
699 ap->hsm_task_state = HSM_ST; in atapi_send_cdb()
702 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
706 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
708 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in atapi_send_cdb()
709 ap->ops->bmdma_start(qc); in atapi_send_cdb()
718 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
730 int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; in __atapi_pio_bytes()
731 struct ata_port *ap = qc->ap; in __atapi_pio_bytes()
732 struct ata_device *dev = qc->dev; in __atapi_pio_bytes()
733 struct ata_eh_info *ehi = &dev->link->eh_info; in __atapi_pio_bytes()
740 sg = qc->cursg; in __atapi_pio_bytes()
744 qc->nbytes, qc->curbytes, bytes); in __atapi_pio_bytes()
745 return -1; in __atapi_pio_bytes()
749 offset = sg->offset + qc->cursg_ofs; in __atapi_pio_bytes()
756 count = min(sg->length - qc->cursg_ofs, bytes); in __atapi_pio_bytes()
759 count = min(count, (unsigned int)PAGE_SIZE - offset); in __atapi_pio_bytes()
765 consumed = ap->ops->sff_data_xfer(qc, buf + offset, count, rw); in __atapi_pio_bytes()
768 bytes -= min(bytes, consumed); in __atapi_pio_bytes()
769 qc->curbytes += count; in __atapi_pio_bytes()
770 qc->cursg_ofs += count; in __atapi_pio_bytes()
772 if (qc->cursg_ofs == sg->length) { in __atapi_pio_bytes()
773 qc->cursg = sg_next(qc->cursg); in __atapi_pio_bytes()
774 qc->cursg_ofs = 0; in __atapi_pio_bytes()
778 * There used to be a WARN_ON_ONCE(qc->cursg && count != consumed); in __atapi_pio_bytes()
781 * made. Somebody should implement a proper sanity check. in __atapi_pio_bytes()
789 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
799 struct ata_port *ap = qc->ap; in atapi_pio_bytes()
800 struct ata_device *dev = qc->dev; in atapi_pio_bytes()
801 struct ata_eh_info *ehi = &dev->link->eh_info; in atapi_pio_bytes()
803 int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; in atapi_pio_bytes()
805 /* Abuse qc->result_tf for temp storage of intermediate TF in atapi_pio_bytes()
807 * For normal completion, qc->result_tf is not relevant. For in atapi_pio_bytes()
808 * error, qc->result_tf is later overwritten by ata_qc_complete(). in atapi_pio_bytes()
809 * So, the correctness of qc->result_tf is not affected. in atapi_pio_bytes()
811 ap->ops->sff_tf_read(ap, &qc->result_tf); in atapi_pio_bytes()
812 ireason = qc->result_tf.nsect; in atapi_pio_bytes()
813 bc_lo = qc->result_tf.lbam; in atapi_pio_bytes()
814 bc_hi = qc->result_tf.lbah; in atapi_pio_bytes()
839 qc->err_mask |= AC_ERR_HSM; in atapi_pio_bytes()
840 ap->hsm_task_state = HSM_ST_ERR; in atapi_pio_bytes()
844 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
854 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_hsm_ok_in_wq()
857 if (ap->hsm_task_state == HSM_ST_FIRST) { in ata_hsm_ok_in_wq()
858 if (qc->tf.protocol == ATA_PROT_PIO && in ata_hsm_ok_in_wq()
859 (qc->tf.flags & ATA_TFLAG_WRITE)) in ata_hsm_ok_in_wq()
862 if (ata_is_atapi(qc->tf.protocol) && in ata_hsm_ok_in_wq()
863 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_hsm_ok_in_wq()
871 * ata_hsm_qc_complete - finish a qc running on standard HSM
883 struct ata_port *ap = qc->ap; in ata_hsm_qc_complete()
887 qc = ata_qc_from_tag(ap, qc->tag); in ata_hsm_qc_complete()
889 if (likely(!(qc->err_mask & AC_ERR_HSM))) { in ata_hsm_qc_complete()
896 if (likely(!(qc->err_mask & AC_ERR_HSM))) in ata_hsm_qc_complete()
904 * ata_sff_hsm_move - move the HSM to the next state.
916 struct ata_link *link = qc->dev->link; in ata_sff_hsm_move()
917 struct ata_eh_info *ehi = &link->eh_info; in ata_sff_hsm_move()
920 lockdep_assert_held(ap->lock); in ata_sff_hsm_move()
922 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); in ata_sff_hsm_move()
926 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). in ata_sff_hsm_move()
933 switch (ap->hsm_task_state) { in ata_sff_hsm_move()
941 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); in ata_sff_hsm_move()
948 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
953 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
956 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
972 if (!(qc->dev->quirks & ATA_QUIRK_STUCK_ERR)) { in ata_sff_hsm_move()
976 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
977 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
982 if (qc->tf.protocol == ATA_PROT_PIO) { in ata_sff_hsm_move()
991 ap->hsm_task_state = HSM_ST; in ata_sff_hsm_move()
1004 if (qc->tf.protocol == ATAPI_PROT_PIO) { in ata_sff_hsm_move()
1010 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_hsm_move()
1021 ata_ehi_push_desc(ehi, "ST-ATAPI: " in ata_sff_hsm_move()
1024 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1025 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1031 if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) in ata_sff_hsm_move()
1041 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1044 * IDENTIFY, it's likely a phantom in ata_sff_hsm_move()
1047 if (qc->dev->quirks & in ata_sff_hsm_move()
1049 qc->err_mask |= in ata_sff_hsm_move()
1056 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1059 qc->err_mask |= AC_ERR_HSM | in ata_sff_hsm_move()
1063 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1079 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1081 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { in ata_sff_hsm_move()
1087 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1090 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1101 qc->err_mask |= AC_ERR_NODEV_HINT; in ata_sff_hsm_move()
1107 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1113 if (ap->hsm_task_state == HSM_ST_LAST && in ata_sff_hsm_move()
1114 (!(qc->tf.flags & ATA_TFLAG_WRITE))) { in ata_sff_hsm_move()
1126 qc->err_mask |= __ac_err_mask(status); in ata_sff_hsm_move()
1127 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1134 WARN_ON_ONCE(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)); in ata_sff_hsm_move()
1136 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1145 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1155 ap->print_id, ap->hsm_task_state); in ata_sff_hsm_move()
1176 struct ata_port *ap = link->ap; in ata_sff_queue_pio_task()
1178 WARN_ON((ap->sff_pio_task_link != NULL) && in ata_sff_queue_pio_task()
1179 (ap->sff_pio_task_link != link)); in ata_sff_queue_pio_task()
1180 ap->sff_pio_task_link = link; in ata_sff_queue_pio_task()
1183 ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay)); in ata_sff_queue_pio_task()
1191 cancel_delayed_work_sync(&ap->sff_pio_task); in ata_sff_flush_pio_task()
1201 spin_lock_irq(ap->lock); in ata_sff_flush_pio_task()
1202 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_flush_pio_task()
1203 spin_unlock_irq(ap->lock); in ata_sff_flush_pio_task()
1205 ap->sff_pio_task_link = NULL; in ata_sff_flush_pio_task()
1212 struct ata_link *link = ap->sff_pio_task_link; in ata_sff_pio_task()
1217 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1219 BUG_ON(ap->sff_pio_task_link == NULL); in ata_sff_pio_task()
1221 qc = ata_qc_from_tag(ap, link->active_tag); in ata_sff_pio_task()
1223 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1228 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); in ata_sff_pio_task()
1231 * This is purely heuristic. This is a fast path. in ata_sff_pio_task()
1233 * a chk-status or two. If not, the drive is probably seeking in ata_sff_pio_task()
1234 * or something. Snooze for a couple msecs, then in ata_sff_pio_task()
1235 * chk-status again. If still busy, queue delayed work. in ata_sff_pio_task()
1239 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1241 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1254 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1264 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1268 * ata_sff_qc_issue - issue taskfile to a SFF controller
1271 * This function issues a PIO or NODATA command to a SFF
1282 struct ata_port *ap = qc->ap; in ata_sff_qc_issue()
1283 struct ata_link *link = qc->dev->link; in ata_sff_qc_issue()
1288 if (ap->flags & ATA_FLAG_PIO_POLLING) in ata_sff_qc_issue()
1289 qc->tf.flags |= ATA_TFLAG_POLLING; in ata_sff_qc_issue()
1292 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_sff_qc_issue()
1295 switch (qc->tf.protocol) { in ata_sff_qc_issue()
1297 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1300 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1301 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_qc_issue()
1303 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1309 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1312 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1314 if (qc->tf.flags & ATA_TFLAG_WRITE) { in ata_sff_qc_issue()
1316 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1324 ap->hsm_task_state = HSM_ST; in ata_sff_qc_issue()
1326 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1339 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1342 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1344 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1347 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || in ata_sff_qc_issue()
1348 (qc->tf.flags & ATA_TFLAG_POLLING)) in ata_sff_qc_issue()
1361 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
1362 * @qc: qc to fill result TF for
1364 * @qc is finished and result TF needs to be filled. Fill it
1365 * using ->sff_tf_read.
1372 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); in ata_sff_qc_fill_rtf()
1378 ap->stats.idle_irq++; in ata_sff_idle_irq()
1381 if ((ap->stats.idle_irq % 1000) == 0) { in ata_sff_idle_irq()
1382 ap->ops->sff_check_status(ap); in ata_sff_idle_irq()
1383 if (ap->ops->sff_irq_clear) in ata_sff_idle_irq()
1384 ap->ops->sff_irq_clear(ap); in ata_sff_idle_irq()
1401 switch (ap->hsm_task_state) { in __ata_sff_port_intr()
1403 /* Some pre-ATAPI-4 devices assert INTRQ in __ata_sff_port_intr()
1409 * need to check ata_is_atapi(qc->tf.protocol) again. in __ata_sff_port_intr()
1411 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in __ata_sff_port_intr()
1425 qc->err_mask |= AC_ERR_HSM; in __ata_sff_port_intr()
1426 ap->hsm_task_state = HSM_ST_ERR; in __ata_sff_port_intr()
1432 if (ap->ops->sff_irq_clear) in __ata_sff_port_intr()
1433 ap->ops->sff_irq_clear(ap); in __ata_sff_port_intr()
1441 * ata_sff_port_intr - Handle SFF port interrupt
1469 spin_lock_irqsave(&host->lock, flags); in __ata_sff_interrupt()
1473 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1474 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1477 qc = ata_qc_from_tag(ap, ap->link.active_tag); in __ata_sff_interrupt()
1479 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) in __ata_sff_interrupt()
1495 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1496 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1501 if (!ap->ops->sff_irq_check || in __ata_sff_interrupt()
1502 !ap->ops->sff_irq_check(ap)) in __ata_sff_interrupt()
1506 ap->ops->sff_check_status(ap); in __ata_sff_interrupt()
1507 if (ap->ops->sff_irq_clear) in __ata_sff_interrupt()
1508 ap->ops->sff_irq_clear(ap); in __ata_sff_interrupt()
1511 if (!(ap->ops->sff_check_status(ap) & ATA_BUSY)) in __ata_sff_interrupt()
1526 spin_unlock_irqrestore(&host->lock, flags); in __ata_sff_interrupt()
1532 * ata_sff_interrupt - Default SFF ATA host interrupt handler
1552 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1570 qc = ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_lost_interrupt()
1571 /* We cannot lose an interrupt on a non-existent or polled command */ in ata_sff_lost_interrupt()
1572 if (!qc || qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_lost_interrupt()
1574 /* See if the controller thinks it is still busy - if so the command in ata_sff_lost_interrupt()
1575 isn't a lost IRQ but is still in progress */ in ata_sff_lost_interrupt()
1581 /* There was a command running, we are no longer busy and we have in ata_sff_lost_interrupt()
1591 * ata_sff_freeze - Freeze SFF controller port
1601 ap->ctl |= ATA_NIEN; in ata_sff_freeze()
1602 ap->last_ctl = ap->ctl; in ata_sff_freeze()
1604 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_freeze()
1610 ap->ops->sff_check_status(ap); in ata_sff_freeze()
1612 if (ap->ops->sff_irq_clear) in ata_sff_freeze()
1613 ap->ops->sff_irq_clear(ap); in ata_sff_freeze()
1618 * ata_sff_thaw - Thaw SFF controller port
1628 /* clear & re-enable interrupts */ in ata_sff_thaw()
1629 ap->ops->sff_check_status(ap); in ata_sff_thaw()
1630 if (ap->ops->sff_irq_clear) in ata_sff_thaw()
1631 ap->ops->sff_irq_clear(ap); in ata_sff_thaw()
1637 * ata_sff_prereset - prepare SFF link for reset
1653 struct ata_eh_context *ehc = &link->eh_context; in ata_sff_prereset()
1656 /* The standard prereset is best-effort and always returns 0 */ in ata_sff_prereset()
1660 if (ehc->i.action & ATA_EH_HARDRESET) in ata_sff_prereset()
1666 if (rc && rc != -ENODEV) { in ata_sff_prereset()
1670 ehc->i.action |= ATA_EH_HARDRESET; in ata_sff_prereset()
1679 * ata_devchk - PATA device presence detection
1684 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1687 * Write a pattern to the ATA shadow registers,
1688 * and if a device is present, it will respond by
1700 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_devchk()
1703 ap->ops->sff_dev_select(ap, device); in ata_devchk()
1705 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1706 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1708 iowrite8(0xaa, ioaddr->nsect_addr); in ata_devchk()
1709 iowrite8(0x55, ioaddr->lbal_addr); in ata_devchk()
1711 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1712 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1714 nsect = ioread8(ioaddr->nsect_addr); in ata_devchk()
1715 lbal = ioread8(ioaddr->lbal_addr); in ata_devchk()
1718 return true; /* we found a device */ in ata_devchk()
1724 * ata_sff_dev_classify - Parse returned ATA device signature
1729 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1730 * an ATA/ATAPI-defined set of values is placed in the ATA
1736 * and the spec-defined values examined by ata_dev_classify().
1742 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1747 struct ata_port *ap = dev->link->ap; in ata_sff_dev_classify()
1748 struct ata_taskfile tf; in ata_sff_dev_classify() local
1752 ap->ops->sff_dev_select(ap, dev->devno); in ata_sff_dev_classify()
1754 memset(&tf, 0, sizeof(tf)); in ata_sff_dev_classify()
1756 ap->ops->sff_tf_read(ap, &tf); in ata_sff_dev_classify()
1757 err = tf.error; in ata_sff_dev_classify()
1764 dev->quirks |= ATA_QUIRK_DIAGNOSTIC; in ata_sff_dev_classify()
1767 else if ((dev->devno == 0) && (err == 0x81)) in ata_sff_dev_classify()
1773 class = ata_port_classify(ap, &tf); in ata_sff_dev_classify()
1783 if (present && (dev->quirks & ATA_QUIRK_DIAGNOSTIC)) in ata_sff_dev_classify()
1789 if (ap->ops->sff_check_status(ap) == 0) in ata_sff_dev_classify()
1798 * ata_sff_wait_after_reset - wait for devices to become ready after reset
1804 * reset. It contains preceding 150ms wait to avoid accessing TF
1811 * 0 on success, -ENODEV if some or all of devices in @devmask
1812 * don't seem to exist. -errno on other errors.
1817 struct ata_port *ap = link->ap; in ata_sff_wait_after_reset()
1818 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_wait_after_reset()
1827 /* -ENODEV means the odd clown forgot the D7 pulldown resistor in ata_sff_wait_after_reset()
1828 * and TF status is 0xff, bail out on it too. in ata_sff_wait_after_reset()
1839 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1848 nsect = ioread8(ioaddr->nsect_addr); in ata_sff_wait_after_reset()
1849 lbal = ioread8(ioaddr->lbal_addr); in ata_sff_wait_after_reset()
1852 ata_msleep(ap, 50); /* give drive a breather */ in ata_sff_wait_after_reset()
1857 if (rc != -ENODEV) in ata_sff_wait_after_reset()
1864 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1866 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1868 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1877 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_bus_softreset()
1879 if (ap->ioaddr.ctl_addr) { in ata_bus_softreset()
1881 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1883 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in ata_bus_softreset()
1885 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1886 ap->last_ctl = ap->ctl; in ata_bus_softreset()
1890 return ata_sff_wait_after_reset(&ap->link, devmask, deadline); in ata_bus_softreset()
1894 * ata_sff_softreset - reset host port via ATA SRST
1905 * 0 on success, -errno otherwise.
1910 struct ata_port *ap = link->ap; in ata_sff_softreset()
1911 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ata_sff_softreset()
1923 ap->ops->sff_dev_select(ap, 0); in ata_sff_softreset()
1927 /* if link is occupied, -ENODEV too is an error */ in ata_sff_softreset()
1928 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in ata_sff_softreset()
1934 classes[0] = ata_sff_dev_classify(&link->device[0], in ata_sff_softreset()
1937 classes[1] = ata_sff_dev_classify(&link->device[1], in ata_sff_softreset()
1945 * sata_sff_hardreset - reset host port via SATA phy reset
1950 * SATA phy-reset host port using DET bits of SControl register,
1957 * 0 on success, -errno otherwise.
1962 struct ata_eh_context *ehc = &link->eh_context; in sata_sff_hardreset()
1970 *class = ata_sff_dev_classify(link->device, 1, NULL); in sata_sff_hardreset()
1977 * ata_sff_postreset - SFF postreset callback
1981 * This function is invoked after a successful reset. It first
1990 struct ata_port *ap = link->ap; in ata_sff_postreset()
1994 /* is double-select really necessary? */ in ata_sff_postreset()
1996 ap->ops->sff_dev_select(ap, 1); in ata_sff_postreset()
1998 ap->ops->sff_dev_select(ap, 0); in ata_sff_postreset()
2005 if (ata_sff_set_devctl(ap, ap->ctl)) in ata_sff_postreset()
2006 ap->last_ctl = ap->ctl; in ata_sff_postreset()
2011 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2014 * Drain the FIFO and device of any stuck data following a command
2015 * failing to complete. In some cases this is necessary before a
2025 /* We only need to flush incoming data when a command was running */ in ata_sff_drain_fifo()
2026 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ata_sff_drain_fifo()
2029 ap = qc->ap; in ata_sff_drain_fifo()
2031 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ata_sff_drain_fifo()
2033 ioread16(ap->ioaddr.data_addr); in ata_sff_drain_fifo()
2042 * ata_sff_error_handler - Stock error handler for SFF controller
2047 * use this EH as-is or with some added handling before and
2055 ata_reset_fn_t softreset = ap->ops->softreset; in ata_sff_error_handler()
2056 ata_reset_fn_t hardreset = ap->ops->hardreset; in ata_sff_error_handler()
2060 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_error_handler()
2061 if (qc && !(qc->flags & ATA_QCFLAG_EH)) in ata_sff_error_handler()
2064 spin_lock_irqsave(ap->lock, flags); in ata_sff_error_handler()
2067 * We *MUST* do FIFO draining before we issue a reset as in ata_sff_error_handler()
2073 if (ap->ops->sff_drain_fifo) in ata_sff_error_handler()
2074 ap->ops->sff_drain_fifo(qc); in ata_sff_error_handler()
2076 spin_unlock_irqrestore(ap->lock, flags); in ata_sff_error_handler()
2078 /* ignore built-in hardresets if SCR access is not available */ in ata_sff_error_handler()
2080 hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link)) in ata_sff_error_handler()
2083 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, in ata_sff_error_handler()
2084 ap->ops->postreset); in ata_sff_error_handler()
2089 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
2101 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; in ata_sff_std_ports()
2102 ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; in ata_sff_std_ports()
2103 ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; in ata_sff_std_ports()
2104 ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; in ata_sff_std_ports()
2105 ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; in ata_sff_std_ports()
2106 ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; in ata_sff_std_ports()
2107 ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; in ata_sff_std_ports()
2108 ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; in ata_sff_std_ports()
2109 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; in ata_sff_std_ports()
2110 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; in ata_sff_std_ports()
2131 * ata_pci_sff_init_host - acquire native PCI ATA resources and init host
2146 * 0 if at least one port is initialized, -ENODEV if no port is
2151 struct device *gdev = host->dev; in ata_pci_sff_init_host()
2158 struct ata_port *ap = host->ports[i]; in ata_pci_sff_init_host()
2170 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2180 if (rc == -EBUSY) in ata_pci_sff_init_host()
2182 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2185 host->iomap = iomap = pcim_iomap_table(pdev); in ata_pci_sff_init_host()
2187 ap->ioaddr.cmd_addr = iomap[base]; in ata_pci_sff_init_host()
2188 ap->ioaddr.altstatus_addr = in ata_pci_sff_init_host()
2189 ap->ioaddr.ctl_addr = (void __iomem *) in ata_pci_sff_init_host()
2191 ata_sff_std_ports(&ap->ioaddr); in ata_pci_sff_init_host()
2202 return -ENODEV; in ata_pci_sff_init_host()
2210 * ata_pci_sff_prepare_host - helper to prepare PCI PIO-only SFF ATA host
2215 * Helper to allocate PIO-only SFF ATA host for @pdev, acquire
2222 * 0 on success, -errno otherwise.
2231 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) in ata_pci_sff_prepare_host()
2232 return -ENOMEM; in ata_pci_sff_prepare_host()
2234 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); in ata_pci_sff_prepare_host()
2236 dev_err(&pdev->dev, "failed to allocate ATA host\n"); in ata_pci_sff_prepare_host()
2237 rc = -ENOMEM; in ata_pci_sff_prepare_host()
2245 devres_remove_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2250 devres_release_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2256 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
2269 * 0 on success, -errno otherwise.
2275 struct device *dev = host->dev; in ata_pci_sff_activate_host()
2277 const char *drv_name = dev_driver_string(host->dev); in ata_pci_sff_activate_host()
2284 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { in ata_pci_sff_activate_host()
2296 if (!ata_port_is_dummy(host->ports[0])) in ata_pci_sff_activate_host()
2298 if (!ata_port_is_dummy(host->ports[1])) in ata_pci_sff_activate_host()
2305 return -ENOMEM; in ata_pci_sff_activate_host()
2307 if (!legacy_mode && pdev->irq) { in ata_pci_sff_activate_host()
2310 rc = devm_request_irq(dev, pdev->irq, irq_handler, in ata_pci_sff_activate_host()
2316 if (ata_port_is_dummy(host->ports[i])) in ata_pci_sff_activate_host()
2318 ata_port_desc_misc(host->ports[i], pdev->irq); in ata_pci_sff_activate_host()
2321 if (!ata_port_is_dummy(host->ports[0])) { in ata_pci_sff_activate_host()
2328 ata_port_desc_misc(host->ports[0], in ata_pci_sff_activate_host()
2332 if (!ata_port_is_dummy(host->ports[1])) { in ata_pci_sff_activate_host()
2339 ata_port_desc_misc(host->ports[1], in ata_pci_sff_activate_host()
2362 if (ppi[i]->port_ops != &ata_dummy_port_ops) in ata_sff_find_valid_pi()
2373 struct device *dev = &pdev->dev; in ata_pci_init_one()
2380 dev_err(&pdev->dev, "no valid port_info specified\n"); in ata_pci_init_one()
2381 return -EINVAL; in ata_pci_init_one()
2385 return -ENOMEM; in ata_pci_init_one()
2401 host->private_data = host_priv; in ata_pci_init_one()
2402 host->flags |= hflags; in ata_pci_init_one()
2413 devres_remove_group(&pdev->dev, NULL); in ata_pci_init_one()
2415 devres_release_group(&pdev->dev, NULL); in ata_pci_init_one()
2421 * ata_pci_sff_init_one - Initialize/register PIO-only PCI IDE controller
2428 * This is a helper function which can be called from a driver's
2433 * Nobody makes a single channel controller that appears solely as
2440 * Zero on success, negative on errno-based value on error.
2486 * ata_bmdma_fill_sg - Fill PCI IDE PRD table
2489 * Fill PCI IDE PRD (scatter-gather) table with segments
2498 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg()
2499 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg()
2504 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg()
2509 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg()
2519 len = 0x10000 - offset; in ata_bmdma_fill_sg()
2525 sg_len -= len; in ata_bmdma_fill_sg()
2530 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg()
2534 * ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
2537 * Fill PCI IDE PRD (scatter-gather) table with segments
2548 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg_dumb()
2549 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg_dumb()
2554 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg_dumb()
2559 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg_dumb()
2569 len = 0x10000 - offset; in ata_bmdma_fill_sg_dumb()
2584 sg_len -= len; in ata_bmdma_fill_sg_dumb()
2589 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg_dumb()
2593 * ata_bmdma_qc_prep - Prepare taskfile for submission
2603 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_qc_prep()
2613 * ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
2623 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_dumb_qc_prep()
2633 * ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
2636 * This function issues a PIO, NODATA or DMA command to a
2648 struct ata_port *ap = qc->ap; in ata_bmdma_qc_issue()
2649 struct ata_link *link = qc->dev->link; in ata_bmdma_qc_issue()
2652 if (!ata_is_dma(qc->tf.protocol)) in ata_bmdma_qc_issue()
2656 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_bmdma_qc_issue()
2659 switch (qc->tf.protocol) { in ata_bmdma_qc_issue()
2661 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2663 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2664 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2665 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2666 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2667 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2668 ap->ops->bmdma_start(qc); /* initiate bmdma */ in ata_bmdma_qc_issue()
2669 ap->hsm_task_state = HSM_ST_LAST; in ata_bmdma_qc_issue()
2673 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2675 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2676 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2677 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2678 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2679 ap->hsm_task_state = HSM_ST_FIRST; in ata_bmdma_qc_issue()
2682 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_bmdma_qc_issue()
2696 * ata_bmdma_port_intr - Handle BMDMA port interrupt
2710 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_bmdma_port_intr()
2715 if (ap->hsm_task_state == HSM_ST_LAST && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_port_intr()
2717 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_port_intr()
2724 /* before we do anything else, clear DMA-Start bit */ in ata_bmdma_port_intr()
2725 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_port_intr()
2726 ap->ops->bmdma_stop(qc); in ata_bmdma_port_intr()
2731 qc->err_mask |= AC_ERR_HOST_BUS; in ata_bmdma_port_intr()
2732 ap->hsm_task_state = HSM_ST_ERR; in ata_bmdma_port_intr()
2738 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) in ata_bmdma_port_intr()
2746 * ata_bmdma_interrupt - Default BMDMA ATA host interrupt handler
2766 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
2771 * able to use this EH as-is or with some added handling before
2783 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_bmdma_error_handler()
2784 if (qc && !(qc->flags & ATA_QCFLAG_EH)) in ata_bmdma_error_handler()
2788 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_error_handler()
2790 if (qc && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_error_handler()
2793 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_error_handler()
2798 * really a timeout event, adjust error mask and in ata_bmdma_error_handler()
2801 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { in ata_bmdma_error_handler()
2802 qc->err_mask = AC_ERR_HOST_BUS; in ata_bmdma_error_handler()
2806 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_error_handler()
2807 ap->ops->bmdma_stop(qc); in ata_bmdma_error_handler()
2811 ap->ops->sff_check_status(ap); in ata_bmdma_error_handler()
2812 if (ap->ops->sff_irq_clear) in ata_bmdma_error_handler()
2813 ap->ops->sff_irq_clear(ap); in ata_bmdma_error_handler()
2817 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_error_handler()
2827 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
2835 struct ata_port *ap = qc->ap; in ata_bmdma_post_internal_cmd()
2838 if (ata_is_dma(qc->tf.protocol)) { in ata_bmdma_post_internal_cmd()
2839 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2840 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_post_internal_cmd()
2841 ap->ops->bmdma_stop(qc); in ata_bmdma_post_internal_cmd()
2842 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2848 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
2860 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_irq_clear()
2870 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
2878 struct ata_port *ap = qc->ap; in ata_bmdma_setup()
2879 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_bmdma_setup()
2884 iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); in ata_bmdma_setup()
2886 /* specify data direction, triple-check start bit is clear */ in ata_bmdma_setup()
2887 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2891 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2894 ap->ops->sff_exec_command(ap, &qc->tf); in ata_bmdma_setup()
2899 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
2907 struct ata_port *ap = qc->ap; in ata_bmdma_start()
2911 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2912 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2919 * Further, a read of the DMA status register _immediately_ in ata_bmdma_start()
2921 * is expected, so I think it is best to not add a readb() in ata_bmdma_start()
2932 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
2944 struct ata_port *ap = qc->ap; in ata_bmdma_stop()
2945 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_stop()
2951 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in ata_bmdma_stop()
2957 * ata_bmdma_status - Read PCI IDE BMDMA status
2969 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); in ata_bmdma_status()
2975 * ata_bmdma_port_start - Set port up for bmdma.
2988 if (ap->mwdma_mask || ap->udma_mask) { in ata_bmdma_port_start()
2989 ap->bmdma_prd = in ata_bmdma_port_start()
2990 dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ, in ata_bmdma_port_start()
2991 &ap->bmdma_prd_dma, GFP_KERNEL); in ata_bmdma_port_start()
2992 if (!ap->bmdma_prd) in ata_bmdma_port_start()
2993 return -ENOMEM; in ata_bmdma_port_start()
3001 * ata_bmdma_port_start32 - Set port up for dma.
3016 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; in ata_bmdma_port_start32()
3024 * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex
3030 * have -undefined- behaviour.
3039 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3045 return -EOPNOTSUPP; in ata_pci_bmdma_clear_simplex()
3048 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3057 dev_err(host->dev, "BMDMA: %s, falling back to PIO\n", reason); in ata_bmdma_nodma()
3060 host->ports[i]->mwdma_mask = 0; in ata_bmdma_nodma()
3061 host->ports[i]->udma_mask = 0; in ata_bmdma_nodma()
3066 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
3076 struct device *gdev = host->dev; in ata_pci_bmdma_init()
3089 * ->sff_irq_clear method. Try to initialize bmdma_addr in ata_pci_bmdma_init()
3092 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3102 host->iomap = pcim_iomap_table(pdev); in ata_pci_bmdma_init()
3105 struct ata_port *ap = host->ports[i]; in ata_pci_bmdma_init()
3106 void __iomem *bmdma = host->iomap[4] + 8 * i; in ata_pci_bmdma_init()
3111 ap->ioaddr.bmdma_addr = bmdma; in ata_pci_bmdma_init()
3112 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && in ata_pci_bmdma_init()
3114 host->flags |= ATA_HOST_SIMPLEX; in ata_pci_bmdma_init()
3123 * ata_pci_bmdma_prepare_host - helper to prepare PCI BMDMA ATA host
3135 * 0 on success, -errno otherwise.
3153 * ata_pci_bmdma_init_one - Initialize/register BMDMA PCI IDE controller
3167 * Zero on success, negative on errno-based value on error.
3182 * ata_sff_port_init - Initialize SFF/BMDMA ATA port
3193 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task); in ata_sff_port_init()
3194 ap->ctl = ATA_DEVCTL_OBS; in ata_sff_port_init()
3195 ap->last_ctl = 0xFF; in ata_sff_port_init()
3202 return -ENOMEM; in ata_sff_init()