Lines Matching +full:pio +full:- +full:transfer
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/
54 * ata_sff_check_status - Read device status reg & clear interrupt
57 * Reads ATA taskfile status register for currently-selected device
66 return ioread8(ap->ioaddr.status_addr); in ata_sff_check_status()
71 * ata_sff_altstatus - Read device alternate status reg
75 * Reads ATA alternate status register for currently-selected device
88 if (ap->ops->sff_check_altstatus) { in ata_sff_altstatus()
89 tmp = ap->ops->sff_check_altstatus(ap); in ata_sff_altstatus()
92 if (ap->ioaddr.altstatus_addr) { in ata_sff_altstatus()
93 tmp = ioread8(ap->ioaddr.altstatus_addr); in ata_sff_altstatus()
105 * ata_sff_irq_status - Check if the device is busy
124 status = ap->ops->sff_check_status(ap); in ata_sff_irq_status()
129 * ata_sff_sync - Flush writes
146 * ata_sff_pause - Flush writes and wait 400nS
165 * ata_sff_dma_pause - Pause before commencing DMA
188 * ata_sff_busy_sleep - sleep until BSY clears, or timeout
200 * 0 on success, -errno otherwise.
226 status = ap->ops->sff_check_status(ap); in ata_sff_busy_sleep()
230 return -ENODEV; in ata_sff_busy_sleep()
236 return -EBUSY; in ata_sff_busy_sleep()
245 u8 status = link->ap->ops->sff_check_status(link->ap); in ata_sff_check_ready()
251 * ata_sff_wait_ready - sleep until BSY clears, or timeout
262 * 0 on success, -errno otherwise.
271 * ata_sff_set_devctl - Write device control reg
285 if (ap->ops->sff_set_devctl) { in ata_sff_set_devctl()
286 ap->ops->sff_set_devctl(ap, ctl); in ata_sff_set_devctl()
289 if (ap->ioaddr.ctl_addr) { in ata_sff_set_devctl()
290 iowrite8(ctl, ap->ioaddr.ctl_addr); in ata_sff_set_devctl()
298 * ata_sff_dev_select - Select device 0/1 on ATA bus
304 * ATA channel. Works with both PIO and MMIO.
320 iowrite8(tmp, ap->ioaddr.device_addr); in ata_sff_dev_select()
326 * ata_dev_select - Select device 0/1 on ATA bus
329 * @wait: non-zero to wait for Status register BSY bit to clear
330 * @can_sleep: non-zero if context allows sleeping
336 * This is a high-level version of ata_sff_dev_select(), which
349 ap->ops->sff_dev_select(ap, device); in ata_dev_select()
352 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) in ata_dev_select()
359 * ata_sff_irq_on - Enable interrupts on a port.
362 * Enable interrupts on a legacy IDE device using MMIO or PIO,
373 if (ap->ops->sff_irq_on) { in ata_sff_irq_on()
374 ap->ops->sff_irq_on(ap); in ata_sff_irq_on()
378 ap->ctl &= ~ATA_NIEN; in ata_sff_irq_on()
379 ap->last_ctl = ap->ctl; in ata_sff_irq_on()
381 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_irq_on()
384 if (ap->ops->sff_irq_clear) in ata_sff_irq_on()
385 ap->ops->sff_irq_clear(ap); in ata_sff_irq_on()
390 * ata_sff_tf_load - send taskfile registers to host controller
401 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_load()
402 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ata_sff_tf_load()
404 if (tf->ctl != ap->last_ctl) { in ata_sff_tf_load()
405 if (ioaddr->ctl_addr) in ata_sff_tf_load()
406 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_load()
407 ap->last_ctl = tf->ctl; in ata_sff_tf_load()
411 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ata_sff_tf_load()
412 WARN_ON_ONCE(!ioaddr->ctl_addr); in ata_sff_tf_load()
413 iowrite8(tf->hob_feature, ioaddr->feature_addr); in ata_sff_tf_load()
414 iowrite8(tf->hob_nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
415 iowrite8(tf->hob_lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
416 iowrite8(tf->hob_lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
417 iowrite8(tf->hob_lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
421 iowrite8(tf->feature, ioaddr->feature_addr); in ata_sff_tf_load()
422 iowrite8(tf->nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
423 iowrite8(tf->lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
424 iowrite8(tf->lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
425 iowrite8(tf->lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
428 if (tf->flags & ATA_TFLAG_DEVICE) in ata_sff_tf_load()
429 iowrite8(tf->device, ioaddr->device_addr); in ata_sff_tf_load()
436 * ata_sff_tf_read - input device's ATA taskfile shadow registers
440 * Reads ATA taskfile registers for currently-selected device
450 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_read()
452 tf->status = ata_sff_check_status(ap); in ata_sff_tf_read()
453 tf->error = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
454 tf->nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
455 tf->lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
456 tf->lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
457 tf->lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
458 tf->device = ioread8(ioaddr->device_addr); in ata_sff_tf_read()
460 if (tf->flags & ATA_TFLAG_LBA48) { in ata_sff_tf_read()
461 if (likely(ioaddr->ctl_addr)) { in ata_sff_tf_read()
462 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in ata_sff_tf_read()
463 tf->hob_feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
464 tf->hob_nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
465 tf->hob_lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
466 tf->hob_lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
467 tf->hob_lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
468 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_read()
469 ap->last_ctl = tf->ctl; in ata_sff_tf_read()
477 * ata_sff_exec_command - issue ATA command to host controller
489 iowrite8(tf->command, ap->ioaddr.command_addr); in ata_sff_exec_command()
495 * ata_tf_to_host - issue ATA taskfile to host controller
512 ap->ops->sff_tf_load(ap, tf); in ata_tf_to_host()
514 ap->ops->sff_exec_command(ap, tf); in ata_tf_to_host()
518 * ata_sff_data_xfer - Transfer data by PIO
524 * Transfer data from/to the device data register by PIO.
535 struct ata_port *ap = qc->dev->link->ap; in ata_sff_data_xfer()
536 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer()
539 /* Transfer multiple of 2 bytes */ in ata_sff_data_xfer()
545 /* Transfer trailing byte, if any. */ in ata_sff_data_xfer()
550 buf += buflen - 1; in ata_sff_data_xfer()
571 * ata_sff_data_xfer32 - Transfer data by PIO
577 * Transfer data from/to the device data register by PIO using 32bit
590 struct ata_device *dev = qc->dev; in ata_sff_data_xfer32()
591 struct ata_port *ap = dev->link->ap; in ata_sff_data_xfer32()
592 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer32()
596 if (!(ap->pflags & ATA_PFLAG_PIO32)) in ata_sff_data_xfer32()
599 /* Transfer multiple of 4 bytes */ in ata_sff_data_xfer32()
605 /* Transfer trailing bytes, if any */ in ata_sff_data_xfer32()
610 buf += buflen - slop; in ata_sff_data_xfer32()
637 bool do_write = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_pio_xfer()
641 qc->ap->ops->sff_data_xfer(qc, buf + offset, xfer_size, do_write); in ata_pio_xfer()
649 * ata_pio_sector - Transfer a sector of data.
652 * Transfer qc->sect_size bytes of data from/to the ATA device.
659 struct ata_port *ap = qc->ap; in ata_pio_sector()
663 if (!qc->cursg) { in ata_pio_sector()
664 qc->curbytes = qc->nbytes; in ata_pio_sector()
667 if (qc->curbytes == qc->nbytes - qc->sect_size) in ata_pio_sector()
668 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
670 page = sg_page(qc->cursg); in ata_pio_sector()
671 offset = qc->cursg->offset + qc->cursg_ofs; in ata_pio_sector()
677 trace_ata_sff_pio_transfer_data(qc, offset, qc->sect_size); in ata_pio_sector()
680 * Split the transfer when it splits a page boundary. Note that the in ata_pio_sector()
684 if (offset + qc->sect_size > PAGE_SIZE) { in ata_pio_sector()
685 unsigned int split_len = PAGE_SIZE - offset; in ata_pio_sector()
689 qc->sect_size - split_len); in ata_pio_sector()
691 ata_pio_xfer(qc, page, offset, qc->sect_size); in ata_pio_sector()
694 qc->curbytes += qc->sect_size; in ata_pio_sector()
695 qc->cursg_ofs += qc->sect_size; in ata_pio_sector()
697 if (qc->cursg_ofs == qc->cursg->length) { in ata_pio_sector()
698 qc->cursg = sg_next(qc->cursg); in ata_pio_sector()
699 if (!qc->cursg) in ata_pio_sector()
700 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
701 qc->cursg_ofs = 0; in ata_pio_sector()
706 * ata_pio_sectors - Transfer one or many sectors.
709 * Transfer one or many sectors of data from/to the
717 if (is_multi_taskfile(&qc->tf)) { in ata_pio_sectors()
721 WARN_ON_ONCE(qc->dev->multi_count == 0); in ata_pio_sectors()
723 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, in ata_pio_sectors()
724 qc->dev->multi_count); in ata_pio_sectors()
725 while (nsect--) in ata_pio_sectors()
730 ata_sff_sync(qc->ap); /* flush */ in ata_pio_sectors()
734 * atapi_send_cdb - Write CDB bytes to hardware
747 trace_atapi_send_cdb(qc, 0, qc->dev->cdb_len); in atapi_send_cdb()
748 WARN_ON_ONCE(qc->dev->cdb_len < 12); in atapi_send_cdb()
750 ap->ops->sff_data_xfer(qc, qc->cdb, qc->dev->cdb_len, 1); in atapi_send_cdb()
754 switch (qc->tf.protocol) { in atapi_send_cdb()
756 ap->hsm_task_state = HSM_ST; in atapi_send_cdb()
759 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
763 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
765 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in atapi_send_cdb()
766 ap->ops->bmdma_start(qc); in atapi_send_cdb()
775 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
779 * Transfer data from/to the ATAPI device.
787 int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; in __atapi_pio_bytes()
788 struct ata_port *ap = qc->ap; in __atapi_pio_bytes()
789 struct ata_device *dev = qc->dev; in __atapi_pio_bytes()
790 struct ata_eh_info *ehi = &dev->link->eh_info; in __atapi_pio_bytes()
797 sg = qc->cursg; in __atapi_pio_bytes()
801 qc->nbytes, qc->curbytes, bytes); in __atapi_pio_bytes()
802 return -1; in __atapi_pio_bytes()
806 offset = sg->offset + qc->cursg_ofs; in __atapi_pio_bytes()
813 count = min(sg->length - qc->cursg_ofs, bytes); in __atapi_pio_bytes()
816 count = min(count, (unsigned int)PAGE_SIZE - offset); in __atapi_pio_bytes()
820 /* do the actual data transfer */ in __atapi_pio_bytes()
822 consumed = ap->ops->sff_data_xfer(qc, buf + offset, count, rw); in __atapi_pio_bytes()
825 bytes -= min(bytes, consumed); in __atapi_pio_bytes()
826 qc->curbytes += count; in __atapi_pio_bytes()
827 qc->cursg_ofs += count; in __atapi_pio_bytes()
829 if (qc->cursg_ofs == sg->length) { in __atapi_pio_bytes()
830 qc->cursg = sg_next(qc->cursg); in __atapi_pio_bytes()
831 qc->cursg_ofs = 0; in __atapi_pio_bytes()
835 * There used to be a WARN_ON_ONCE(qc->cursg && count != consumed); in __atapi_pio_bytes()
846 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
849 * Transfer Transfer data from/to the ATAPI device.
856 struct ata_port *ap = qc->ap; in atapi_pio_bytes()
857 struct ata_device *dev = qc->dev; in atapi_pio_bytes()
858 struct ata_eh_info *ehi = &dev->link->eh_info; in atapi_pio_bytes()
860 int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; in atapi_pio_bytes()
862 /* Abuse qc->result_tf for temp storage of intermediate TF in atapi_pio_bytes()
864 * For normal completion, qc->result_tf is not relevant. For in atapi_pio_bytes()
865 * error, qc->result_tf is later overwritten by ata_qc_complete(). in atapi_pio_bytes()
866 * So, the correctness of qc->result_tf is not affected. in atapi_pio_bytes()
868 ap->ops->sff_tf_read(ap, &qc->result_tf); in atapi_pio_bytes()
869 ireason = qc->result_tf.nsect; in atapi_pio_bytes()
870 bc_lo = qc->result_tf.lbam; in atapi_pio_bytes()
871 bc_hi = qc->result_tf.lbah; in atapi_pio_bytes()
878 /* make sure transfer direction matches expected */ in atapi_pio_bytes()
896 qc->err_mask |= AC_ERR_HSM; in atapi_pio_bytes()
897 ap->hsm_task_state = HSM_ST_ERR; in atapi_pio_bytes()
901 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
911 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_hsm_ok_in_wq()
914 if (ap->hsm_task_state == HSM_ST_FIRST) { in ata_hsm_ok_in_wq()
915 if (qc->tf.protocol == ATA_PROT_PIO && in ata_hsm_ok_in_wq()
916 (qc->tf.flags & ATA_TFLAG_WRITE)) in ata_hsm_ok_in_wq()
919 if (ata_is_atapi(qc->tf.protocol) && in ata_hsm_ok_in_wq()
920 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_hsm_ok_in_wq()
928 * ata_hsm_qc_complete - finish a qc running on standard HSM
940 struct ata_port *ap = qc->ap; in ata_hsm_qc_complete()
942 if (ap->ops->error_handler) { in ata_hsm_qc_complete()
947 qc = ata_qc_from_tag(ap, qc->tag); in ata_hsm_qc_complete()
949 if (likely(!(qc->err_mask & AC_ERR_HSM))) { in ata_hsm_qc_complete()
956 if (likely(!(qc->err_mask & AC_ERR_HSM))) in ata_hsm_qc_complete()
971 * ata_sff_hsm_move - move the HSM to the next state.
983 struct ata_link *link = qc->dev->link; in ata_sff_hsm_move()
984 struct ata_eh_info *ehi = &link->eh_info; in ata_sff_hsm_move()
987 lockdep_assert_held(ap->lock); in ata_sff_hsm_move()
989 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); in ata_sff_hsm_move()
993 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). in ata_sff_hsm_move()
1000 switch (ap->hsm_task_state) { in ata_sff_hsm_move()
1008 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); in ata_sff_hsm_move()
1015 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1020 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1023 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1027 /* Device should not ask for data transfer (DRQ=1) in ata_sff_hsm_move()
1039 if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) { in ata_sff_hsm_move()
1043 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1044 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1049 if (qc->tf.protocol == ATA_PROT_PIO) { in ata_sff_hsm_move()
1050 /* PIO data out protocol. in ata_sff_hsm_move()
1058 ap->hsm_task_state = HSM_ST; in ata_sff_hsm_move()
1071 if (qc->tf.protocol == ATAPI_PROT_PIO) { in ata_sff_hsm_move()
1072 /* ATAPI PIO protocol */ in ata_sff_hsm_move()
1074 /* No more data to transfer or device error. in ata_sff_hsm_move()
1077 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_hsm_move()
1081 /* Device should not ask for data transfer (DRQ=1) in ata_sff_hsm_move()
1088 ata_ehi_push_desc(ehi, "ST-ATAPI: " in ata_sff_hsm_move()
1091 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1092 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1098 if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) in ata_sff_hsm_move()
1103 /* ATA PIO protocol */ in ata_sff_hsm_move()
1108 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1114 if (qc->dev->horkage & in ata_sff_hsm_move()
1116 qc->err_mask |= in ata_sff_hsm_move()
1123 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1126 qc->err_mask |= AC_ERR_HSM | in ata_sff_hsm_move()
1130 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1134 /* For PIO reads, some devices may ask for in ata_sff_hsm_move()
1135 * data transfer (DRQ=1) alone with ERR=1. in ata_sff_hsm_move()
1136 * We respect DRQ here and transfer one in ata_sff_hsm_move()
1140 * For PIO writes, ERR=1 DRQ=1 doesn't make in ata_sff_hsm_move()
1146 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1148 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { in ata_sff_hsm_move()
1154 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1157 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1168 qc->err_mask |= AC_ERR_NODEV_HINT; in ata_sff_hsm_move()
1174 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1180 if (ap->hsm_task_state == HSM_ST_LAST && in ata_sff_hsm_move()
1181 (!(qc->tf.flags & ATA_TFLAG_WRITE))) { in ata_sff_hsm_move()
1193 qc->err_mask |= __ac_err_mask(status); in ata_sff_hsm_move()
1194 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1198 /* no more data to transfer */ in ata_sff_hsm_move()
1201 WARN_ON_ONCE(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)); in ata_sff_hsm_move()
1203 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1212 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1222 ap->print_id, ap->hsm_task_state); in ata_sff_hsm_move()
1243 struct ata_port *ap = link->ap; in ata_sff_queue_pio_task()
1245 WARN_ON((ap->sff_pio_task_link != NULL) && in ata_sff_queue_pio_task()
1246 (ap->sff_pio_task_link != link)); in ata_sff_queue_pio_task()
1247 ap->sff_pio_task_link = link; in ata_sff_queue_pio_task()
1250 ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay)); in ata_sff_queue_pio_task()
1258 cancel_delayed_work_sync(&ap->sff_pio_task); in ata_sff_flush_pio_task()
1268 spin_lock_irq(ap->lock); in ata_sff_flush_pio_task()
1269 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_flush_pio_task()
1270 spin_unlock_irq(ap->lock); in ata_sff_flush_pio_task()
1272 ap->sff_pio_task_link = NULL; in ata_sff_flush_pio_task()
1279 struct ata_link *link = ap->sff_pio_task_link; in ata_sff_pio_task()
1284 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1286 BUG_ON(ap->sff_pio_task_link == NULL); in ata_sff_pio_task()
1288 qc = ata_qc_from_tag(ap, link->active_tag); in ata_sff_pio_task()
1290 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1295 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); in ata_sff_pio_task()
1300 * a chk-status or two. If not, the drive is probably seeking in ata_sff_pio_task()
1302 * chk-status again. If still busy, queue delayed work. in ata_sff_pio_task()
1306 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1308 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1321 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1331 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1335 * ata_sff_qc_issue - issue taskfile to a SFF controller
1338 * This function issues a PIO or NODATA command to a SFF
1349 struct ata_port *ap = qc->ap; in ata_sff_qc_issue()
1350 struct ata_link *link = qc->dev->link; in ata_sff_qc_issue()
1352 /* Use polling pio if the LLD doesn't handle in ata_sff_qc_issue()
1353 * interrupt driven pio and atapi CDB interrupt. in ata_sff_qc_issue()
1355 if (ap->flags & ATA_FLAG_PIO_POLLING) in ata_sff_qc_issue()
1356 qc->tf.flags |= ATA_TFLAG_POLLING; in ata_sff_qc_issue()
1359 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_sff_qc_issue()
1362 switch (qc->tf.protocol) { in ata_sff_qc_issue()
1364 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1367 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1368 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_qc_issue()
1370 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1376 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1379 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1381 if (qc->tf.flags & ATA_TFLAG_WRITE) { in ata_sff_qc_issue()
1382 /* PIO data out protocol */ in ata_sff_qc_issue()
1383 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1390 /* PIO data in protocol */ in ata_sff_qc_issue()
1391 ap->hsm_task_state = HSM_ST; in ata_sff_qc_issue()
1393 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1406 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1409 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1411 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1414 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || in ata_sff_qc_issue()
1415 (qc->tf.flags & ATA_TFLAG_POLLING)) in ata_sff_qc_issue()
1428 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
1432 * using ->sff_tf_read.
1442 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); in ata_sff_qc_fill_rtf()
1449 ap->stats.idle_irq++; in ata_sff_idle_irq()
1452 if ((ap->stats.idle_irq % 1000) == 0) { in ata_sff_idle_irq()
1453 ap->ops->sff_check_status(ap); in ata_sff_idle_irq()
1454 if (ap->ops->sff_irq_clear) in ata_sff_idle_irq()
1455 ap->ops->sff_irq_clear(ap); in ata_sff_idle_irq()
1472 switch (ap->hsm_task_state) { in __ata_sff_port_intr()
1474 /* Some pre-ATAPI-4 devices assert INTRQ in __ata_sff_port_intr()
1480 * need to check ata_is_atapi(qc->tf.protocol) again. in __ata_sff_port_intr()
1482 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in __ata_sff_port_intr()
1496 qc->err_mask |= AC_ERR_HSM; in __ata_sff_port_intr()
1497 ap->hsm_task_state = HSM_ST_ERR; in __ata_sff_port_intr()
1503 if (ap->ops->sff_irq_clear) in __ata_sff_port_intr()
1504 ap->ops->sff_irq_clear(ap); in __ata_sff_port_intr()
1512 * ata_sff_port_intr - Handle SFF port interrupt
1540 spin_lock_irqsave(&host->lock, flags); in __ata_sff_interrupt()
1544 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1545 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1548 qc = ata_qc_from_tag(ap, ap->link.active_tag); in __ata_sff_interrupt()
1550 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) in __ata_sff_interrupt()
1566 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1567 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1572 if (!ap->ops->sff_irq_check || in __ata_sff_interrupt()
1573 !ap->ops->sff_irq_check(ap)) in __ata_sff_interrupt()
1577 ap->ops->sff_check_status(ap); in __ata_sff_interrupt()
1578 if (ap->ops->sff_irq_clear) in __ata_sff_interrupt()
1579 ap->ops->sff_irq_clear(ap); in __ata_sff_interrupt()
1582 if (!(ap->ops->sff_check_status(ap) & ATA_BUSY)) in __ata_sff_interrupt()
1597 spin_unlock_irqrestore(&host->lock, flags); in __ata_sff_interrupt()
1603 * ata_sff_interrupt - Default SFF ATA host interrupt handler
1623 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1641 qc = ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_lost_interrupt()
1642 /* We cannot lose an interrupt on a non-existent or polled command */ in ata_sff_lost_interrupt()
1643 if (!qc || qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_lost_interrupt()
1645 /* See if the controller thinks it is still busy - if so the command in ata_sff_lost_interrupt()
1662 * ata_sff_freeze - Freeze SFF controller port
1672 ap->ctl |= ATA_NIEN; in ata_sff_freeze()
1673 ap->last_ctl = ap->ctl; in ata_sff_freeze()
1675 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_freeze()
1681 ap->ops->sff_check_status(ap); in ata_sff_freeze()
1683 if (ap->ops->sff_irq_clear) in ata_sff_freeze()
1684 ap->ops->sff_irq_clear(ap); in ata_sff_freeze()
1689 * ata_sff_thaw - Thaw SFF controller port
1699 /* clear & re-enable interrupts */ in ata_sff_thaw()
1700 ap->ops->sff_check_status(ap); in ata_sff_thaw()
1701 if (ap->ops->sff_irq_clear) in ata_sff_thaw()
1702 ap->ops->sff_irq_clear(ap); in ata_sff_thaw()
1708 * ata_sff_prereset - prepare SFF link for reset
1724 struct ata_eh_context *ehc = &link->eh_context; in ata_sff_prereset()
1727 /* The standard prereset is best-effort and always returns 0 */ in ata_sff_prereset()
1731 if (ehc->i.action & ATA_EH_HARDRESET) in ata_sff_prereset()
1737 if (rc && rc != -ENODEV) { in ata_sff_prereset()
1741 ehc->i.action |= ATA_EH_HARDRESET; in ata_sff_prereset()
1750 * ata_devchk - PATA device presence detection
1755 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1771 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_devchk()
1774 ap->ops->sff_dev_select(ap, device); in ata_devchk()
1776 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1777 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1779 iowrite8(0xaa, ioaddr->nsect_addr); in ata_devchk()
1780 iowrite8(0x55, ioaddr->lbal_addr); in ata_devchk()
1782 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1783 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1785 nsect = ioread8(ioaddr->nsect_addr); in ata_devchk()
1786 lbal = ioread8(ioaddr->lbal_addr); in ata_devchk()
1795 * ata_sff_dev_classify - Parse returned ATA device signature
1800 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1801 * an ATA/ATAPI-defined set of values is placed in the ATA
1807 * and the spec-defined values examined by ata_dev_classify().
1813 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1818 struct ata_port *ap = dev->link->ap; in ata_sff_dev_classify()
1823 ap->ops->sff_dev_select(ap, dev->devno); in ata_sff_dev_classify()
1827 ap->ops->sff_tf_read(ap, &tf); in ata_sff_dev_classify()
1835 dev->horkage |= ATA_HORKAGE_DIAGNOSTIC; in ata_sff_dev_classify()
1838 else if ((dev->devno == 0) && (err == 0x81)) in ata_sff_dev_classify()
1854 if (present && (dev->horkage & ATA_HORKAGE_DIAGNOSTIC)) in ata_sff_dev_classify()
1860 if (ap->ops->sff_check_status(ap) == 0) in ata_sff_dev_classify()
1869 * ata_sff_wait_after_reset - wait for devices to become ready after reset
1882 * 0 on success, -ENODEV if some or all of devices in @devmask
1883 * don't seem to exist. -errno on other errors.
1888 struct ata_port *ap = link->ap; in ata_sff_wait_after_reset()
1889 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_wait_after_reset()
1898 /* -ENODEV means the odd clown forgot the D7 pulldown resistor in ata_sff_wait_after_reset()
1910 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1919 nsect = ioread8(ioaddr->nsect_addr); in ata_sff_wait_after_reset()
1920 lbal = ioread8(ioaddr->lbal_addr); in ata_sff_wait_after_reset()
1928 if (rc != -ENODEV) in ata_sff_wait_after_reset()
1935 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1937 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1939 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1948 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_bus_softreset()
1950 if (ap->ioaddr.ctl_addr) { in ata_bus_softreset()
1952 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1954 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in ata_bus_softreset()
1956 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1957 ap->last_ctl = ap->ctl; in ata_bus_softreset()
1961 return ata_sff_wait_after_reset(&ap->link, devmask, deadline); in ata_bus_softreset()
1965 * ata_sff_softreset - reset host port via ATA SRST
1976 * 0 on success, -errno otherwise.
1981 struct ata_port *ap = link->ap; in ata_sff_softreset()
1982 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ata_sff_softreset()
1994 ap->ops->sff_dev_select(ap, 0); in ata_sff_softreset()
1998 /* if link is occupied, -ENODEV too is an error */ in ata_sff_softreset()
1999 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in ata_sff_softreset()
2005 classes[0] = ata_sff_dev_classify(&link->device[0], in ata_sff_softreset()
2008 classes[1] = ata_sff_dev_classify(&link->device[1], in ata_sff_softreset()
2016 * sata_sff_hardreset - reset host port via SATA phy reset
2021 * SATA phy-reset host port using DET bits of SControl register,
2028 * 0 on success, -errno otherwise.
2033 struct ata_eh_context *ehc = &link->eh_context; in sata_sff_hardreset()
2041 *class = ata_sff_dev_classify(link->device, 1, NULL); in sata_sff_hardreset()
2048 * ata_sff_postreset - SFF postreset callback
2061 struct ata_port *ap = link->ap; in ata_sff_postreset()
2065 /* is double-select really necessary? */ in ata_sff_postreset()
2067 ap->ops->sff_dev_select(ap, 1); in ata_sff_postreset()
2069 ap->ops->sff_dev_select(ap, 0); in ata_sff_postreset()
2076 if (ata_sff_set_devctl(ap, ap->ctl)) in ata_sff_postreset()
2077 ap->last_ctl = ap->ctl; in ata_sff_postreset()
2082 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2097 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ata_sff_drain_fifo()
2100 ap = qc->ap; in ata_sff_drain_fifo()
2102 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ata_sff_drain_fifo()
2104 ioread16(ap->ioaddr.data_addr); in ata_sff_drain_fifo()
2113 * ata_sff_error_handler - Stock error handler for SFF controller
2118 * use this EH as-is or with some added handling before and
2126 ata_reset_fn_t softreset = ap->ops->softreset; in ata_sff_error_handler()
2127 ata_reset_fn_t hardreset = ap->ops->hardreset; in ata_sff_error_handler()
2131 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_error_handler()
2132 if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) in ata_sff_error_handler()
2135 spin_lock_irqsave(ap->lock, flags); in ata_sff_error_handler()
2141 * qc in case anyone wants to do different PIO/DMA recovery or in ata_sff_error_handler()
2144 if (ap->ops->sff_drain_fifo) in ata_sff_error_handler()
2145 ap->ops->sff_drain_fifo(qc); in ata_sff_error_handler()
2147 spin_unlock_irqrestore(ap->lock, flags); in ata_sff_error_handler()
2149 /* ignore built-in hardresets if SCR access is not available */ in ata_sff_error_handler()
2151 hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link)) in ata_sff_error_handler()
2154 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, in ata_sff_error_handler()
2155 ap->ops->postreset); in ata_sff_error_handler()
2160 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
2172 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; in ata_sff_std_ports()
2173 ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; in ata_sff_std_ports()
2174 ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; in ata_sff_std_ports()
2175 ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; in ata_sff_std_ports()
2176 ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; in ata_sff_std_ports()
2177 ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; in ata_sff_std_ports()
2178 ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; in ata_sff_std_ports()
2179 ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; in ata_sff_std_ports()
2180 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; in ata_sff_std_ports()
2181 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; in ata_sff_std_ports()
2202 * ata_pci_sff_init_host - acquire native PCI ATA resources and init host
2217 * 0 if at least one port is initialized, -ENODEV if no port is
2222 struct device *gdev = host->dev; in ata_pci_sff_init_host()
2229 struct ata_port *ap = host->ports[i]; in ata_pci_sff_init_host()
2241 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2251 if (rc == -EBUSY) in ata_pci_sff_init_host()
2253 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2256 host->iomap = iomap = pcim_iomap_table(pdev); in ata_pci_sff_init_host()
2258 ap->ioaddr.cmd_addr = iomap[base]; in ata_pci_sff_init_host()
2259 ap->ioaddr.altstatus_addr = in ata_pci_sff_init_host()
2260 ap->ioaddr.ctl_addr = (void __iomem *) in ata_pci_sff_init_host()
2262 ata_sff_std_ports(&ap->ioaddr); in ata_pci_sff_init_host()
2273 return -ENODEV; in ata_pci_sff_init_host()
2281 * ata_pci_sff_prepare_host - helper to prepare PCI PIO-only SFF ATA host
2286 * Helper to allocate PIO-only SFF ATA host for @pdev, acquire
2293 * 0 on success, -errno otherwise.
2302 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) in ata_pci_sff_prepare_host()
2303 return -ENOMEM; in ata_pci_sff_prepare_host()
2305 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); in ata_pci_sff_prepare_host()
2307 dev_err(&pdev->dev, "failed to allocate ATA host\n"); in ata_pci_sff_prepare_host()
2308 rc = -ENOMEM; in ata_pci_sff_prepare_host()
2316 devres_remove_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2321 devres_release_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2327 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
2340 * 0 on success, -errno otherwise.
2346 struct device *dev = host->dev; in ata_pci_sff_activate_host()
2348 const char *drv_name = dev_driver_string(host->dev); in ata_pci_sff_activate_host()
2355 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { in ata_pci_sff_activate_host()
2367 if (!ata_port_is_dummy(host->ports[0])) in ata_pci_sff_activate_host()
2369 if (!ata_port_is_dummy(host->ports[1])) in ata_pci_sff_activate_host()
2376 return -ENOMEM; in ata_pci_sff_activate_host()
2378 if (!legacy_mode && pdev->irq) { in ata_pci_sff_activate_host()
2381 rc = devm_request_irq(dev, pdev->irq, irq_handler, in ata_pci_sff_activate_host()
2387 if (ata_port_is_dummy(host->ports[i])) in ata_pci_sff_activate_host()
2389 ata_port_desc(host->ports[i], "irq %d", pdev->irq); in ata_pci_sff_activate_host()
2392 if (!ata_port_is_dummy(host->ports[0])) { in ata_pci_sff_activate_host()
2399 ata_port_desc(host->ports[0], "irq %d", in ata_pci_sff_activate_host()
2403 if (!ata_port_is_dummy(host->ports[1])) { in ata_pci_sff_activate_host()
2410 ata_port_desc(host->ports[1], "irq %d", in ata_pci_sff_activate_host()
2433 if (ppi[i]->port_ops != &ata_dummy_port_ops) in ata_sff_find_valid_pi()
2444 struct device *dev = &pdev->dev; in ata_pci_init_one()
2451 dev_err(&pdev->dev, "no valid port_info specified\n"); in ata_pci_init_one()
2452 return -EINVAL; in ata_pci_init_one()
2456 return -ENOMEM; in ata_pci_init_one()
2472 host->private_data = host_priv; in ata_pci_init_one()
2473 host->flags |= hflags; in ata_pci_init_one()
2484 devres_remove_group(&pdev->dev, NULL); in ata_pci_init_one()
2486 devres_release_group(&pdev->dev, NULL); in ata_pci_init_one()
2492 * ata_pci_sff_init_one - Initialize/register PIO-only PCI IDE controller
2501 * IDE taskfile registers and is PIO only.
2511 * Zero on success, negative on errno-based value on error.
2557 * ata_bmdma_fill_sg - Fill PCI IDE PRD table
2560 * Fill PCI IDE PRD (scatter-gather) table with segments
2569 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg()
2570 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg()
2575 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg()
2580 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg()
2590 len = 0x10000 - offset; in ata_bmdma_fill_sg()
2596 sg_len -= len; in ata_bmdma_fill_sg()
2601 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg()
2605 * ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
2608 * Fill PCI IDE PRD (scatter-gather) table with segments
2619 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg_dumb()
2620 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg_dumb()
2625 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg_dumb()
2630 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg_dumb()
2640 len = 0x10000 - offset; in ata_bmdma_fill_sg_dumb()
2655 sg_len -= len; in ata_bmdma_fill_sg_dumb()
2660 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg_dumb()
2664 * ata_bmdma_qc_prep - Prepare taskfile for submission
2674 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_qc_prep()
2684 * ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
2694 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_dumb_qc_prep()
2704 * ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
2707 * This function issues a PIO, NODATA or DMA command to a
2708 * SFF/BMDMA controller. PIO and NODATA are handled by
2719 struct ata_port *ap = qc->ap; in ata_bmdma_qc_issue()
2720 struct ata_link *link = qc->dev->link; in ata_bmdma_qc_issue()
2722 /* defer PIO handling to sff_qc_issue */ in ata_bmdma_qc_issue()
2723 if (!ata_is_dma(qc->tf.protocol)) in ata_bmdma_qc_issue()
2727 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_bmdma_qc_issue()
2730 switch (qc->tf.protocol) { in ata_bmdma_qc_issue()
2732 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2734 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2735 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2736 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2737 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2738 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2739 ap->ops->bmdma_start(qc); /* initiate bmdma */ in ata_bmdma_qc_issue()
2740 ap->hsm_task_state = HSM_ST_LAST; in ata_bmdma_qc_issue()
2744 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2746 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2747 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2748 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2749 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2750 ap->hsm_task_state = HSM_ST_FIRST; in ata_bmdma_qc_issue()
2753 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_bmdma_qc_issue()
2767 * ata_bmdma_port_intr - Handle BMDMA port interrupt
2781 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_bmdma_port_intr()
2786 if (ap->hsm_task_state == HSM_ST_LAST && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_port_intr()
2788 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_port_intr()
2795 /* before we do anything else, clear DMA-Start bit */ in ata_bmdma_port_intr()
2796 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_port_intr()
2797 ap->ops->bmdma_stop(qc); in ata_bmdma_port_intr()
2802 qc->err_mask |= AC_ERR_HOST_BUS; in ata_bmdma_port_intr()
2803 ap->hsm_task_state = HSM_ST_ERR; in ata_bmdma_port_intr()
2809 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) in ata_bmdma_port_intr()
2817 * ata_bmdma_interrupt - Default BMDMA ATA host interrupt handler
2837 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
2842 * able to use this EH as-is or with some added handling before
2854 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_bmdma_error_handler()
2855 if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) in ata_bmdma_error_handler()
2858 /* reset PIO HSM and stop DMA engine */ in ata_bmdma_error_handler()
2859 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_error_handler()
2861 if (qc && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_error_handler()
2864 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_error_handler()
2872 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { in ata_bmdma_error_handler()
2873 qc->err_mask = AC_ERR_HOST_BUS; in ata_bmdma_error_handler()
2877 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_error_handler()
2878 ap->ops->bmdma_stop(qc); in ata_bmdma_error_handler()
2882 ap->ops->sff_check_status(ap); in ata_bmdma_error_handler()
2883 if (ap->ops->sff_irq_clear) in ata_bmdma_error_handler()
2884 ap->ops->sff_irq_clear(ap); in ata_bmdma_error_handler()
2888 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_error_handler()
2898 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
2906 struct ata_port *ap = qc->ap; in ata_bmdma_post_internal_cmd()
2909 if (ata_is_dma(qc->tf.protocol)) { in ata_bmdma_post_internal_cmd()
2910 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2911 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_post_internal_cmd()
2912 ap->ops->bmdma_stop(qc); in ata_bmdma_post_internal_cmd()
2913 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2919 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
2931 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_irq_clear()
2941 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
2949 struct ata_port *ap = qc->ap; in ata_bmdma_setup()
2950 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_bmdma_setup()
2955 iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); in ata_bmdma_setup()
2957 /* specify data direction, triple-check start bit is clear */ in ata_bmdma_setup()
2958 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2962 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2965 ap->ops->sff_exec_command(ap, &qc->tf); in ata_bmdma_setup()
2970 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
2978 struct ata_port *ap = qc->ap; in ata_bmdma_start()
2982 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2983 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
3003 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
3015 struct ata_port *ap = qc->ap; in ata_bmdma_stop()
3016 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_stop()
3022 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in ata_bmdma_stop()
3028 * ata_bmdma_status - Read PCI IDE BMDMA status
3040 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); in ata_bmdma_status()
3046 * ata_bmdma_port_start - Set port up for bmdma.
3059 if (ap->mwdma_mask || ap->udma_mask) { in ata_bmdma_port_start()
3060 ap->bmdma_prd = in ata_bmdma_port_start()
3061 dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ, in ata_bmdma_port_start()
3062 &ap->bmdma_prd_dma, GFP_KERNEL); in ata_bmdma_port_start()
3063 if (!ap->bmdma_prd) in ata_bmdma_port_start()
3064 return -ENOMEM; in ata_bmdma_port_start()
3072 * ata_bmdma_port_start32 - Set port up for dma.
3076 * initialized. Enables 32bit PIO and allocates space for PRD
3080 * devices that are capable of 32bit PIO.
3087 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; in ata_bmdma_port_start32()
3095 * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex
3101 * have -undefined- behaviour.
3109 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3115 return -EOPNOTSUPP; in ata_pci_bmdma_clear_simplex()
3124 dev_err(host->dev, "BMDMA: %s, falling back to PIO\n", reason); in ata_bmdma_nodma()
3127 host->ports[i]->mwdma_mask = 0; in ata_bmdma_nodma()
3128 host->ports[i]->udma_mask = 0; in ata_bmdma_nodma()
3133 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
3143 struct device *gdev = host->dev; in ata_pci_bmdma_init()
3156 * ->sff_irq_clear method. Try to initialize bmdma_addr in ata_pci_bmdma_init()
3159 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3169 host->iomap = pcim_iomap_table(pdev); in ata_pci_bmdma_init()
3172 struct ata_port *ap = host->ports[i]; in ata_pci_bmdma_init()
3173 void __iomem *bmdma = host->iomap[4] + 8 * i; in ata_pci_bmdma_init()
3178 ap->ioaddr.bmdma_addr = bmdma; in ata_pci_bmdma_init()
3179 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && in ata_pci_bmdma_init()
3181 host->flags |= ATA_HOST_SIMPLEX; in ata_pci_bmdma_init()
3190 * ata_pci_bmdma_prepare_host - helper to prepare PCI BMDMA ATA host
3202 * 0 on success, -errno otherwise.
3220 * ata_pci_bmdma_init_one - Initialize/register BMDMA PCI IDE controller
3234 * Zero on success, negative on errno-based value on error.
3249 * ata_sff_port_init - Initialize SFF/BMDMA ATA port
3260 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task); in ata_sff_port_init()
3261 ap->ctl = ATA_DEVCTL_OBS; in ata_sff_port_init()
3262 ap->last_ctl = 0xFF; in ata_sff_port_init()
3269 return -ENOMEM; in ata_sff_init()