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
189 u8 status = link->ap->ops->sff_check_status(link->ap); in ata_sff_check_ready()
195 * ata_sff_wait_ready - sleep until BSY clears, or timeout
206 * 0 on success, -errno otherwise.
215 * ata_sff_set_devctl - Write device control reg
229 if (ap->ops->sff_set_devctl) { in ata_sff_set_devctl()
230 ap->ops->sff_set_devctl(ap, ctl); in ata_sff_set_devctl()
233 if (ap->ioaddr.ctl_addr) { in ata_sff_set_devctl()
234 iowrite8(ctl, ap->ioaddr.ctl_addr); in ata_sff_set_devctl()
242 * ata_sff_dev_select - Select device 0/1 on ATA bus
248 * ATA channel. Works with both PIO and MMIO.
264 iowrite8(tmp, ap->ioaddr.device_addr); in ata_sff_dev_select()
270 * ata_dev_select - Select device 0/1 on ATA bus
273 * @wait: non-zero to wait for Status register BSY bit to clear
274 * @can_sleep: non-zero if context allows sleeping
280 * This is a high-level version of ata_sff_dev_select(), which
293 ap->ops->sff_dev_select(ap, device); in ata_dev_select()
296 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) in ata_dev_select()
303 * ata_sff_irq_on - Enable interrupts on a port.
306 * Enable interrupts on a legacy IDE device using MMIO or PIO,
317 if (ap->ops->sff_irq_on) { in ata_sff_irq_on()
318 ap->ops->sff_irq_on(ap); in ata_sff_irq_on()
322 ap->ctl &= ~ATA_NIEN; in ata_sff_irq_on()
323 ap->last_ctl = ap->ctl; in ata_sff_irq_on()
325 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_irq_on()
328 if (ap->ops->sff_irq_clear) in ata_sff_irq_on()
329 ap->ops->sff_irq_clear(ap); in ata_sff_irq_on()
334 * ata_sff_tf_load - send taskfile registers to host controller
345 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_load()
346 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ata_sff_tf_load()
348 if (tf->ctl != ap->last_ctl) { in ata_sff_tf_load()
349 if (ioaddr->ctl_addr) in ata_sff_tf_load()
350 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_load()
351 ap->last_ctl = tf->ctl; in ata_sff_tf_load()
355 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ata_sff_tf_load()
356 WARN_ON_ONCE(!ioaddr->ctl_addr); in ata_sff_tf_load()
357 iowrite8(tf->hob_feature, ioaddr->feature_addr); in ata_sff_tf_load()
358 iowrite8(tf->hob_nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
359 iowrite8(tf->hob_lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
360 iowrite8(tf->hob_lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
361 iowrite8(tf->hob_lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
365 iowrite8(tf->feature, ioaddr->feature_addr); in ata_sff_tf_load()
366 iowrite8(tf->nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
367 iowrite8(tf->lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
368 iowrite8(tf->lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
369 iowrite8(tf->lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
372 if (tf->flags & ATA_TFLAG_DEVICE) in ata_sff_tf_load()
373 iowrite8(tf->device, ioaddr->device_addr); in ata_sff_tf_load()
380 * ata_sff_tf_read - input device's ATA taskfile shadow registers
384 * Reads ATA taskfile registers for currently-selected device
394 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_read()
396 tf->status = ata_sff_check_status(ap); in ata_sff_tf_read()
397 tf->error = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
398 tf->nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
399 tf->lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
400 tf->lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
401 tf->lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
402 tf->device = ioread8(ioaddr->device_addr); in ata_sff_tf_read()
404 if (tf->flags & ATA_TFLAG_LBA48) { in ata_sff_tf_read()
405 if (likely(ioaddr->ctl_addr)) { in ata_sff_tf_read()
406 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in ata_sff_tf_read()
407 tf->hob_feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
408 tf->hob_nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
409 tf->hob_lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
410 tf->hob_lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
411 tf->hob_lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
412 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_read()
413 ap->last_ctl = tf->ctl; in ata_sff_tf_read()
421 * ata_sff_exec_command - issue ATA command to host controller
433 iowrite8(tf->command, ap->ioaddr.command_addr); in ata_sff_exec_command()
439 * ata_tf_to_host - issue ATA taskfile to host controller
456 ap->ops->sff_tf_load(ap, tf); in ata_tf_to_host()
458 ap->ops->sff_exec_command(ap, tf); in ata_tf_to_host()
462 * ata_sff_data_xfer - Transfer data by PIO
468 * Transfer data from/to the device data register by PIO.
479 struct ata_port *ap = qc->dev->link->ap; in ata_sff_data_xfer()
480 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer()
483 /* Transfer multiple of 2 bytes */ in ata_sff_data_xfer()
489 /* Transfer trailing byte, if any. */ in ata_sff_data_xfer()
494 buf += buflen - 1; in ata_sff_data_xfer()
515 * ata_sff_data_xfer32 - Transfer data by PIO
521 * Transfer data from/to the device data register by PIO using 32bit
534 struct ata_device *dev = qc->dev; in ata_sff_data_xfer32()
535 struct ata_port *ap = dev->link->ap; in ata_sff_data_xfer32()
536 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer32()
540 if (!(ap->pflags & ATA_PFLAG_PIO32)) in ata_sff_data_xfer32()
543 /* Transfer multiple of 4 bytes */ in ata_sff_data_xfer32()
549 /* Transfer trailing bytes, if any */ in ata_sff_data_xfer32()
554 buf += buflen - slop; in ata_sff_data_xfer32()
581 bool do_write = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_pio_xfer()
585 qc->ap->ops->sff_data_xfer(qc, buf + offset, xfer_size, do_write); in ata_pio_xfer()
593 * ata_pio_sector - Transfer a sector of data.
596 * Transfer qc->sect_size bytes of data from/to the ATA device.
603 struct ata_port *ap = qc->ap; in ata_pio_sector()
607 if (!qc->cursg) { in ata_pio_sector()
608 qc->curbytes = qc->nbytes; in ata_pio_sector()
611 if (qc->curbytes == qc->nbytes - qc->sect_size) in ata_pio_sector()
612 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
614 page = sg_page(qc->cursg); in ata_pio_sector()
615 offset = qc->cursg->offset + qc->cursg_ofs; in ata_pio_sector()
622 count = min(qc->cursg->length - qc->cursg_ofs, qc->sect_size); in ata_pio_sector()
627 * Split the transfer when it splits a page boundary. Note that the in ata_pio_sector()
632 unsigned int split_len = PAGE_SIZE - offset; in ata_pio_sector()
635 ata_pio_xfer(qc, nth_page(page, 1), 0, count - split_len); in ata_pio_sector()
640 qc->curbytes += count; in ata_pio_sector()
641 qc->cursg_ofs += count; in ata_pio_sector()
643 if (qc->cursg_ofs == qc->cursg->length) { in ata_pio_sector()
644 qc->cursg = sg_next(qc->cursg); in ata_pio_sector()
645 if (!qc->cursg) in ata_pio_sector()
646 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
647 qc->cursg_ofs = 0; in ata_pio_sector()
652 * ata_pio_sectors - Transfer one or many sectors.
655 * Transfer one or many sectors of data from/to the
663 if (is_multi_taskfile(&qc->tf)) { in ata_pio_sectors()
667 WARN_ON_ONCE(qc->dev->multi_count == 0); in ata_pio_sectors()
669 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, in ata_pio_sectors()
670 qc->dev->multi_count); in ata_pio_sectors()
671 while (nsect--) in ata_pio_sectors()
676 ata_sff_sync(qc->ap); /* flush */ in ata_pio_sectors()
680 * atapi_send_cdb - Write CDB bytes to hardware
693 trace_atapi_send_cdb(qc, 0, qc->dev->cdb_len); in atapi_send_cdb()
694 WARN_ON_ONCE(qc->dev->cdb_len < 12); in atapi_send_cdb()
696 ap->ops->sff_data_xfer(qc, qc->cdb, qc->dev->cdb_len, 1); in atapi_send_cdb()
700 switch (qc->tf.protocol) { in atapi_send_cdb()
702 ap->hsm_task_state = HSM_ST; in atapi_send_cdb()
705 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
709 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
711 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in atapi_send_cdb()
712 ap->ops->bmdma_start(qc); in atapi_send_cdb()
721 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
725 * Transfer data from/to the ATAPI device.
733 int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; in __atapi_pio_bytes()
734 struct ata_port *ap = qc->ap; in __atapi_pio_bytes()
735 struct ata_device *dev = qc->dev; in __atapi_pio_bytes()
736 struct ata_eh_info *ehi = &dev->link->eh_info; in __atapi_pio_bytes()
743 sg = qc->cursg; in __atapi_pio_bytes()
747 qc->nbytes, qc->curbytes, bytes); in __atapi_pio_bytes()
748 return -1; in __atapi_pio_bytes()
752 offset = sg->offset + qc->cursg_ofs; in __atapi_pio_bytes()
759 count = min(sg->length - qc->cursg_ofs, bytes); in __atapi_pio_bytes()
762 count = min(count, (unsigned int)PAGE_SIZE - offset); in __atapi_pio_bytes()
766 /* do the actual data transfer */ in __atapi_pio_bytes()
768 consumed = ap->ops->sff_data_xfer(qc, buf + offset, count, rw); in __atapi_pio_bytes()
771 bytes -= min(bytes, consumed); in __atapi_pio_bytes()
772 qc->curbytes += count; in __atapi_pio_bytes()
773 qc->cursg_ofs += count; in __atapi_pio_bytes()
775 if (qc->cursg_ofs == sg->length) { in __atapi_pio_bytes()
776 qc->cursg = sg_next(qc->cursg); in __atapi_pio_bytes()
777 qc->cursg_ofs = 0; in __atapi_pio_bytes()
781 * There used to be a WARN_ON_ONCE(qc->cursg && count != consumed); in __atapi_pio_bytes()
792 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
795 * Transfer Transfer data from/to the ATAPI device.
802 struct ata_port *ap = qc->ap; in atapi_pio_bytes()
803 struct ata_device *dev = qc->dev; in atapi_pio_bytes()
804 struct ata_eh_info *ehi = &dev->link->eh_info; in atapi_pio_bytes()
806 int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; in atapi_pio_bytes()
808 /* Abuse qc->result_tf for temp storage of intermediate TF in atapi_pio_bytes()
810 * For normal completion, qc->result_tf is not relevant. For in atapi_pio_bytes()
811 * error, qc->result_tf is later overwritten by ata_qc_complete(). in atapi_pio_bytes()
812 * So, the correctness of qc->result_tf is not affected. in atapi_pio_bytes()
814 ap->ops->sff_tf_read(ap, &qc->result_tf); in atapi_pio_bytes()
815 ireason = qc->result_tf.nsect; in atapi_pio_bytes()
816 bc_lo = qc->result_tf.lbam; in atapi_pio_bytes()
817 bc_hi = qc->result_tf.lbah; in atapi_pio_bytes()
824 /* make sure transfer direction matches expected */ in atapi_pio_bytes()
842 qc->err_mask |= AC_ERR_HSM; in atapi_pio_bytes()
843 ap->hsm_task_state = HSM_ST_ERR; in atapi_pio_bytes()
847 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
857 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_hsm_ok_in_wq()
860 if (ap->hsm_task_state == HSM_ST_FIRST) { in ata_hsm_ok_in_wq()
861 if (qc->tf.protocol == ATA_PROT_PIO && in ata_hsm_ok_in_wq()
862 (qc->tf.flags & ATA_TFLAG_WRITE)) in ata_hsm_ok_in_wq()
865 if (ata_is_atapi(qc->tf.protocol) && in ata_hsm_ok_in_wq()
866 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_hsm_ok_in_wq()
874 * ata_hsm_qc_complete - finish a qc running on standard HSM
886 struct ata_port *ap = qc->ap; in ata_hsm_qc_complete()
890 qc = ata_qc_from_tag(ap, qc->tag); in ata_hsm_qc_complete()
892 if (likely(!(qc->err_mask & AC_ERR_HSM))) { in ata_hsm_qc_complete()
899 if (likely(!(qc->err_mask & AC_ERR_HSM))) in ata_hsm_qc_complete()
907 * ata_sff_hsm_move - move the HSM to the next state.
919 struct ata_link *link = qc->dev->link; in ata_sff_hsm_move()
920 struct ata_eh_info *ehi = &link->eh_info; in ata_sff_hsm_move()
923 lockdep_assert_held(ap->lock); in ata_sff_hsm_move()
925 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); in ata_sff_hsm_move()
929 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). in ata_sff_hsm_move()
936 switch (ap->hsm_task_state) { in ata_sff_hsm_move()
944 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); in ata_sff_hsm_move()
951 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
956 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
959 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
963 /* Device should not ask for data transfer (DRQ=1) in ata_sff_hsm_move()
975 if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) { in ata_sff_hsm_move()
979 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
980 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
985 if (qc->tf.protocol == ATA_PROT_PIO) { in ata_sff_hsm_move()
986 /* PIO data out protocol. in ata_sff_hsm_move()
994 ap->hsm_task_state = HSM_ST; in ata_sff_hsm_move()
1007 if (qc->tf.protocol == ATAPI_PROT_PIO) { in ata_sff_hsm_move()
1008 /* ATAPI PIO protocol */ in ata_sff_hsm_move()
1010 /* No more data to transfer or device error. in ata_sff_hsm_move()
1013 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_hsm_move()
1017 /* Device should not ask for data transfer (DRQ=1) in ata_sff_hsm_move()
1024 ata_ehi_push_desc(ehi, "ST-ATAPI: " in ata_sff_hsm_move()
1027 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1028 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1034 if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) in ata_sff_hsm_move()
1039 /* ATA PIO protocol */ in ata_sff_hsm_move()
1044 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1050 if (qc->dev->horkage & in ata_sff_hsm_move()
1052 qc->err_mask |= in ata_sff_hsm_move()
1059 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1062 qc->err_mask |= AC_ERR_HSM | in ata_sff_hsm_move()
1066 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1070 /* For PIO reads, some devices may ask for in ata_sff_hsm_move()
1071 * data transfer (DRQ=1) alone with ERR=1. in ata_sff_hsm_move()
1072 * We respect DRQ here and transfer one in ata_sff_hsm_move()
1076 * For PIO writes, ERR=1 DRQ=1 doesn't make in ata_sff_hsm_move()
1082 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1084 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { in ata_sff_hsm_move()
1090 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1093 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1104 qc->err_mask |= AC_ERR_NODEV_HINT; in ata_sff_hsm_move()
1110 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1116 if (ap->hsm_task_state == HSM_ST_LAST && in ata_sff_hsm_move()
1117 (!(qc->tf.flags & ATA_TFLAG_WRITE))) { in ata_sff_hsm_move()
1129 qc->err_mask |= __ac_err_mask(status); in ata_sff_hsm_move()
1130 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1134 /* no more data to transfer */ in ata_sff_hsm_move()
1137 WARN_ON_ONCE(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)); in ata_sff_hsm_move()
1139 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1148 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1158 ap->print_id, ap->hsm_task_state); in ata_sff_hsm_move()
1179 struct ata_port *ap = link->ap; in ata_sff_queue_pio_task()
1181 WARN_ON((ap->sff_pio_task_link != NULL) && in ata_sff_queue_pio_task()
1182 (ap->sff_pio_task_link != link)); in ata_sff_queue_pio_task()
1183 ap->sff_pio_task_link = link; in ata_sff_queue_pio_task()
1186 ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay)); in ata_sff_queue_pio_task()
1194 cancel_delayed_work_sync(&ap->sff_pio_task); in ata_sff_flush_pio_task()
1204 spin_lock_irq(ap->lock); in ata_sff_flush_pio_task()
1205 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_flush_pio_task()
1206 spin_unlock_irq(ap->lock); in ata_sff_flush_pio_task()
1208 ap->sff_pio_task_link = NULL; in ata_sff_flush_pio_task()
1215 struct ata_link *link = ap->sff_pio_task_link; in ata_sff_pio_task()
1220 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1222 BUG_ON(ap->sff_pio_task_link == NULL); in ata_sff_pio_task()
1224 qc = ata_qc_from_tag(ap, link->active_tag); in ata_sff_pio_task()
1226 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1231 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); in ata_sff_pio_task()
1236 * a chk-status or two. If not, the drive is probably seeking in ata_sff_pio_task()
1238 * chk-status again. If still busy, queue delayed work. in ata_sff_pio_task()
1242 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1244 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1257 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1267 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1271 * ata_sff_qc_issue - issue taskfile to a SFF controller
1274 * This function issues a PIO or NODATA command to a SFF
1285 struct ata_port *ap = qc->ap; in ata_sff_qc_issue()
1286 struct ata_link *link = qc->dev->link; in ata_sff_qc_issue()
1288 /* Use polling pio if the LLD doesn't handle in ata_sff_qc_issue()
1289 * interrupt driven pio and atapi CDB interrupt. in ata_sff_qc_issue()
1291 if (ap->flags & ATA_FLAG_PIO_POLLING) in ata_sff_qc_issue()
1292 qc->tf.flags |= ATA_TFLAG_POLLING; in ata_sff_qc_issue()
1295 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_sff_qc_issue()
1298 switch (qc->tf.protocol) { in ata_sff_qc_issue()
1300 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1303 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1304 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_qc_issue()
1306 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1312 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1315 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1317 if (qc->tf.flags & ATA_TFLAG_WRITE) { in ata_sff_qc_issue()
1318 /* PIO data out protocol */ in ata_sff_qc_issue()
1319 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1326 /* PIO data in protocol */ in ata_sff_qc_issue()
1327 ap->hsm_task_state = HSM_ST; in ata_sff_qc_issue()
1329 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1342 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1345 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1347 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1350 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || in ata_sff_qc_issue()
1351 (qc->tf.flags & ATA_TFLAG_POLLING)) in ata_sff_qc_issue()
1364 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
1368 * using ->sff_tf_read.
1375 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); in ata_sff_qc_fill_rtf()
1381 ap->stats.idle_irq++; in ata_sff_idle_irq()
1384 if ((ap->stats.idle_irq % 1000) == 0) { in ata_sff_idle_irq()
1385 ap->ops->sff_check_status(ap); in ata_sff_idle_irq()
1386 if (ap->ops->sff_irq_clear) in ata_sff_idle_irq()
1387 ap->ops->sff_irq_clear(ap); in ata_sff_idle_irq()
1404 switch (ap->hsm_task_state) { in __ata_sff_port_intr()
1406 /* Some pre-ATAPI-4 devices assert INTRQ in __ata_sff_port_intr()
1412 * need to check ata_is_atapi(qc->tf.protocol) again. in __ata_sff_port_intr()
1414 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in __ata_sff_port_intr()
1428 qc->err_mask |= AC_ERR_HSM; in __ata_sff_port_intr()
1429 ap->hsm_task_state = HSM_ST_ERR; in __ata_sff_port_intr()
1435 if (ap->ops->sff_irq_clear) in __ata_sff_port_intr()
1436 ap->ops->sff_irq_clear(ap); in __ata_sff_port_intr()
1444 * ata_sff_port_intr - Handle SFF port interrupt
1472 spin_lock_irqsave(&host->lock, flags); in __ata_sff_interrupt()
1476 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1477 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1480 qc = ata_qc_from_tag(ap, ap->link.active_tag); in __ata_sff_interrupt()
1482 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) in __ata_sff_interrupt()
1498 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1499 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1504 if (!ap->ops->sff_irq_check || in __ata_sff_interrupt()
1505 !ap->ops->sff_irq_check(ap)) in __ata_sff_interrupt()
1509 ap->ops->sff_check_status(ap); in __ata_sff_interrupt()
1510 if (ap->ops->sff_irq_clear) in __ata_sff_interrupt()
1511 ap->ops->sff_irq_clear(ap); in __ata_sff_interrupt()
1514 if (!(ap->ops->sff_check_status(ap) & ATA_BUSY)) in __ata_sff_interrupt()
1529 spin_unlock_irqrestore(&host->lock, flags); in __ata_sff_interrupt()
1535 * ata_sff_interrupt - Default SFF ATA host interrupt handler
1555 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1573 qc = ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_lost_interrupt()
1574 /* We cannot lose an interrupt on a non-existent or polled command */ in ata_sff_lost_interrupt()
1575 if (!qc || qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_lost_interrupt()
1577 /* See if the controller thinks it is still busy - if so the command in ata_sff_lost_interrupt()
1594 * ata_sff_freeze - Freeze SFF controller port
1604 ap->ctl |= ATA_NIEN; in ata_sff_freeze()
1605 ap->last_ctl = ap->ctl; in ata_sff_freeze()
1607 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_freeze()
1613 ap->ops->sff_check_status(ap); in ata_sff_freeze()
1615 if (ap->ops->sff_irq_clear) in ata_sff_freeze()
1616 ap->ops->sff_irq_clear(ap); in ata_sff_freeze()
1621 * ata_sff_thaw - Thaw SFF controller port
1631 /* clear & re-enable interrupts */ in ata_sff_thaw()
1632 ap->ops->sff_check_status(ap); in ata_sff_thaw()
1633 if (ap->ops->sff_irq_clear) in ata_sff_thaw()
1634 ap->ops->sff_irq_clear(ap); in ata_sff_thaw()
1640 * ata_sff_prereset - prepare SFF link for reset
1656 struct ata_eh_context *ehc = &link->eh_context; in ata_sff_prereset()
1659 /* The standard prereset is best-effort and always returns 0 */ in ata_sff_prereset()
1663 if (ehc->i.action & ATA_EH_HARDRESET) in ata_sff_prereset()
1669 if (rc && rc != -ENODEV) { in ata_sff_prereset()
1673 ehc->i.action |= ATA_EH_HARDRESET; in ata_sff_prereset()
1682 * ata_devchk - PATA device presence detection
1687 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1703 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_devchk()
1706 ap->ops->sff_dev_select(ap, device); in ata_devchk()
1708 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1709 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1711 iowrite8(0xaa, ioaddr->nsect_addr); in ata_devchk()
1712 iowrite8(0x55, ioaddr->lbal_addr); in ata_devchk()
1714 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1715 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1717 nsect = ioread8(ioaddr->nsect_addr); in ata_devchk()
1718 lbal = ioread8(ioaddr->lbal_addr); in ata_devchk()
1727 * ata_sff_dev_classify - Parse returned ATA device signature
1732 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1733 * an ATA/ATAPI-defined set of values is placed in the ATA
1739 * and the spec-defined values examined by ata_dev_classify().
1745 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1750 struct ata_port *ap = dev->link->ap; in ata_sff_dev_classify()
1755 ap->ops->sff_dev_select(ap, dev->devno); in ata_sff_dev_classify()
1759 ap->ops->sff_tf_read(ap, &tf); in ata_sff_dev_classify()
1767 dev->horkage |= ATA_HORKAGE_DIAGNOSTIC; in ata_sff_dev_classify()
1770 else if ((dev->devno == 0) && (err == 0x81)) in ata_sff_dev_classify()
1786 if (present && (dev->horkage & ATA_HORKAGE_DIAGNOSTIC)) in ata_sff_dev_classify()
1792 if (ap->ops->sff_check_status(ap) == 0) in ata_sff_dev_classify()
1801 * ata_sff_wait_after_reset - wait for devices to become ready after reset
1814 * 0 on success, -ENODEV if some or all of devices in @devmask
1815 * don't seem to exist. -errno on other errors.
1820 struct ata_port *ap = link->ap; in ata_sff_wait_after_reset()
1821 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_wait_after_reset()
1830 /* -ENODEV means the odd clown forgot the D7 pulldown resistor in ata_sff_wait_after_reset()
1842 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1851 nsect = ioread8(ioaddr->nsect_addr); in ata_sff_wait_after_reset()
1852 lbal = ioread8(ioaddr->lbal_addr); in ata_sff_wait_after_reset()
1860 if (rc != -ENODEV) in ata_sff_wait_after_reset()
1867 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1869 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1871 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1880 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_bus_softreset()
1882 if (ap->ioaddr.ctl_addr) { in ata_bus_softreset()
1884 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1886 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in ata_bus_softreset()
1888 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1889 ap->last_ctl = ap->ctl; in ata_bus_softreset()
1893 return ata_sff_wait_after_reset(&ap->link, devmask, deadline); in ata_bus_softreset()
1897 * ata_sff_softreset - reset host port via ATA SRST
1908 * 0 on success, -errno otherwise.
1913 struct ata_port *ap = link->ap; in ata_sff_softreset()
1914 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ata_sff_softreset()
1926 ap->ops->sff_dev_select(ap, 0); in ata_sff_softreset()
1930 /* if link is occupied, -ENODEV too is an error */ in ata_sff_softreset()
1931 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in ata_sff_softreset()
1937 classes[0] = ata_sff_dev_classify(&link->device[0], in ata_sff_softreset()
1940 classes[1] = ata_sff_dev_classify(&link->device[1], in ata_sff_softreset()
1948 * sata_sff_hardreset - reset host port via SATA phy reset
1953 * SATA phy-reset host port using DET bits of SControl register,
1960 * 0 on success, -errno otherwise.
1965 struct ata_eh_context *ehc = &link->eh_context; in sata_sff_hardreset()
1973 *class = ata_sff_dev_classify(link->device, 1, NULL); in sata_sff_hardreset()
1980 * ata_sff_postreset - SFF postreset callback
1993 struct ata_port *ap = link->ap; in ata_sff_postreset()
1997 /* is double-select really necessary? */ in ata_sff_postreset()
1999 ap->ops->sff_dev_select(ap, 1); in ata_sff_postreset()
2001 ap->ops->sff_dev_select(ap, 0); in ata_sff_postreset()
2008 if (ata_sff_set_devctl(ap, ap->ctl)) in ata_sff_postreset()
2009 ap->last_ctl = ap->ctl; in ata_sff_postreset()
2014 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2029 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ata_sff_drain_fifo()
2032 ap = qc->ap; in ata_sff_drain_fifo()
2034 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ata_sff_drain_fifo()
2036 ioread16(ap->ioaddr.data_addr); in ata_sff_drain_fifo()
2045 * ata_sff_error_handler - Stock error handler for SFF controller
2050 * use this EH as-is or with some added handling before and
2058 ata_reset_fn_t softreset = ap->ops->softreset; in ata_sff_error_handler()
2059 ata_reset_fn_t hardreset = ap->ops->hardreset; in ata_sff_error_handler()
2063 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_error_handler()
2064 if (qc && !(qc->flags & ATA_QCFLAG_EH)) in ata_sff_error_handler()
2067 spin_lock_irqsave(ap->lock, flags); in ata_sff_error_handler()
2073 * qc in case anyone wants to do different PIO/DMA recovery or in ata_sff_error_handler()
2076 if (ap->ops->sff_drain_fifo) in ata_sff_error_handler()
2077 ap->ops->sff_drain_fifo(qc); in ata_sff_error_handler()
2079 spin_unlock_irqrestore(ap->lock, flags); in ata_sff_error_handler()
2081 /* ignore built-in hardresets if SCR access is not available */ in ata_sff_error_handler()
2083 hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link)) in ata_sff_error_handler()
2086 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, in ata_sff_error_handler()
2087 ap->ops->postreset); in ata_sff_error_handler()
2092 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
2104 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; in ata_sff_std_ports()
2105 ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; in ata_sff_std_ports()
2106 ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; in ata_sff_std_ports()
2107 ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; in ata_sff_std_ports()
2108 ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; in ata_sff_std_ports()
2109 ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; in ata_sff_std_ports()
2110 ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; in ata_sff_std_ports()
2111 ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; in ata_sff_std_ports()
2112 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; in ata_sff_std_ports()
2113 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; in ata_sff_std_ports()
2134 * ata_pci_sff_init_host - acquire native PCI ATA resources and init host
2149 * 0 if at least one port is initialized, -ENODEV if no port is
2154 struct device *gdev = host->dev; in ata_pci_sff_init_host()
2161 struct ata_port *ap = host->ports[i]; in ata_pci_sff_init_host()
2173 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2183 if (rc == -EBUSY) in ata_pci_sff_init_host()
2185 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2188 host->iomap = iomap = pcim_iomap_table(pdev); in ata_pci_sff_init_host()
2190 ap->ioaddr.cmd_addr = iomap[base]; in ata_pci_sff_init_host()
2191 ap->ioaddr.altstatus_addr = in ata_pci_sff_init_host()
2192 ap->ioaddr.ctl_addr = (void __iomem *) in ata_pci_sff_init_host()
2194 ata_sff_std_ports(&ap->ioaddr); in ata_pci_sff_init_host()
2205 return -ENODEV; in ata_pci_sff_init_host()
2213 * ata_pci_sff_prepare_host - helper to prepare PCI PIO-only SFF ATA host
2218 * Helper to allocate PIO-only SFF ATA host for @pdev, acquire
2225 * 0 on success, -errno otherwise.
2234 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) in ata_pci_sff_prepare_host()
2235 return -ENOMEM; in ata_pci_sff_prepare_host()
2237 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); in ata_pci_sff_prepare_host()
2239 dev_err(&pdev->dev, "failed to allocate ATA host\n"); in ata_pci_sff_prepare_host()
2240 rc = -ENOMEM; in ata_pci_sff_prepare_host()
2248 devres_remove_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2253 devres_release_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2259 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
2272 * 0 on success, -errno otherwise.
2278 struct device *dev = host->dev; in ata_pci_sff_activate_host()
2280 const char *drv_name = dev_driver_string(host->dev); in ata_pci_sff_activate_host()
2287 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { in ata_pci_sff_activate_host()
2299 if (!ata_port_is_dummy(host->ports[0])) in ata_pci_sff_activate_host()
2301 if (!ata_port_is_dummy(host->ports[1])) in ata_pci_sff_activate_host()
2308 return -ENOMEM; in ata_pci_sff_activate_host()
2310 if (!legacy_mode && pdev->irq) { in ata_pci_sff_activate_host()
2313 rc = devm_request_irq(dev, pdev->irq, irq_handler, in ata_pci_sff_activate_host()
2319 if (ata_port_is_dummy(host->ports[i])) in ata_pci_sff_activate_host()
2321 ata_port_desc(host->ports[i], "irq %d", pdev->irq); in ata_pci_sff_activate_host()
2324 if (!ata_port_is_dummy(host->ports[0])) { in ata_pci_sff_activate_host()
2331 ata_port_desc(host->ports[0], "irq %d", in ata_pci_sff_activate_host()
2335 if (!ata_port_is_dummy(host->ports[1])) { in ata_pci_sff_activate_host()
2342 ata_port_desc(host->ports[1], "irq %d", in ata_pci_sff_activate_host()
2365 if (ppi[i]->port_ops != &ata_dummy_port_ops) in ata_sff_find_valid_pi()
2376 struct device *dev = &pdev->dev; in ata_pci_init_one()
2383 dev_err(&pdev->dev, "no valid port_info specified\n"); in ata_pci_init_one()
2384 return -EINVAL; in ata_pci_init_one()
2388 return -ENOMEM; in ata_pci_init_one()
2404 host->private_data = host_priv; in ata_pci_init_one()
2405 host->flags |= hflags; in ata_pci_init_one()
2416 devres_remove_group(&pdev->dev, NULL); in ata_pci_init_one()
2418 devres_release_group(&pdev->dev, NULL); in ata_pci_init_one()
2424 * ata_pci_sff_init_one - Initialize/register PIO-only PCI IDE controller
2433 * IDE taskfile registers and is PIO only.
2443 * Zero on success, negative on errno-based value on error.
2489 * ata_bmdma_fill_sg - Fill PCI IDE PRD table
2492 * Fill PCI IDE PRD (scatter-gather) table with segments
2501 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg()
2502 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg()
2507 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg()
2512 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg()
2522 len = 0x10000 - offset; in ata_bmdma_fill_sg()
2528 sg_len -= len; in ata_bmdma_fill_sg()
2533 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg()
2537 * ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
2540 * Fill PCI IDE PRD (scatter-gather) table with segments
2551 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg_dumb()
2552 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg_dumb()
2557 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg_dumb()
2562 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg_dumb()
2572 len = 0x10000 - offset; in ata_bmdma_fill_sg_dumb()
2587 sg_len -= len; in ata_bmdma_fill_sg_dumb()
2592 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg_dumb()
2596 * ata_bmdma_qc_prep - Prepare taskfile for submission
2606 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_qc_prep()
2616 * ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
2626 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_dumb_qc_prep()
2636 * ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
2639 * This function issues a PIO, NODATA or DMA command to a
2640 * SFF/BMDMA controller. PIO and NODATA are handled by
2651 struct ata_port *ap = qc->ap; in ata_bmdma_qc_issue()
2652 struct ata_link *link = qc->dev->link; in ata_bmdma_qc_issue()
2654 /* defer PIO handling to sff_qc_issue */ in ata_bmdma_qc_issue()
2655 if (!ata_is_dma(qc->tf.protocol)) in ata_bmdma_qc_issue()
2659 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_bmdma_qc_issue()
2662 switch (qc->tf.protocol) { in ata_bmdma_qc_issue()
2664 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2666 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2667 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2668 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2669 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2670 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2671 ap->ops->bmdma_start(qc); /* initiate bmdma */ in ata_bmdma_qc_issue()
2672 ap->hsm_task_state = HSM_ST_LAST; in ata_bmdma_qc_issue()
2676 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2678 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2679 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2680 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2681 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2682 ap->hsm_task_state = HSM_ST_FIRST; in ata_bmdma_qc_issue()
2685 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_bmdma_qc_issue()
2699 * ata_bmdma_port_intr - Handle BMDMA port interrupt
2713 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_bmdma_port_intr()
2718 if (ap->hsm_task_state == HSM_ST_LAST && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_port_intr()
2720 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_port_intr()
2727 /* before we do anything else, clear DMA-Start bit */ in ata_bmdma_port_intr()
2728 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_port_intr()
2729 ap->ops->bmdma_stop(qc); in ata_bmdma_port_intr()
2734 qc->err_mask |= AC_ERR_HOST_BUS; in ata_bmdma_port_intr()
2735 ap->hsm_task_state = HSM_ST_ERR; in ata_bmdma_port_intr()
2741 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) in ata_bmdma_port_intr()
2749 * ata_bmdma_interrupt - Default BMDMA ATA host interrupt handler
2769 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
2774 * able to use this EH as-is or with some added handling before
2786 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_bmdma_error_handler()
2787 if (qc && !(qc->flags & ATA_QCFLAG_EH)) in ata_bmdma_error_handler()
2790 /* reset PIO HSM and stop DMA engine */ in ata_bmdma_error_handler()
2791 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_error_handler()
2793 if (qc && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_error_handler()
2796 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_error_handler()
2804 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { in ata_bmdma_error_handler()
2805 qc->err_mask = AC_ERR_HOST_BUS; in ata_bmdma_error_handler()
2809 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_error_handler()
2810 ap->ops->bmdma_stop(qc); in ata_bmdma_error_handler()
2814 ap->ops->sff_check_status(ap); in ata_bmdma_error_handler()
2815 if (ap->ops->sff_irq_clear) in ata_bmdma_error_handler()
2816 ap->ops->sff_irq_clear(ap); in ata_bmdma_error_handler()
2820 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_error_handler()
2830 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
2838 struct ata_port *ap = qc->ap; in ata_bmdma_post_internal_cmd()
2841 if (ata_is_dma(qc->tf.protocol)) { in ata_bmdma_post_internal_cmd()
2842 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2843 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_post_internal_cmd()
2844 ap->ops->bmdma_stop(qc); in ata_bmdma_post_internal_cmd()
2845 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2851 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
2863 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_irq_clear()
2873 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
2881 struct ata_port *ap = qc->ap; in ata_bmdma_setup()
2882 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_bmdma_setup()
2887 iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); in ata_bmdma_setup()
2889 /* specify data direction, triple-check start bit is clear */ in ata_bmdma_setup()
2890 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2894 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2897 ap->ops->sff_exec_command(ap, &qc->tf); in ata_bmdma_setup()
2902 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
2910 struct ata_port *ap = qc->ap; in ata_bmdma_start()
2914 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2915 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2935 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
2947 struct ata_port *ap = qc->ap; in ata_bmdma_stop()
2948 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_stop()
2954 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in ata_bmdma_stop()
2960 * ata_bmdma_status - Read PCI IDE BMDMA status
2972 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); in ata_bmdma_status()
2978 * ata_bmdma_port_start - Set port up for bmdma.
2991 if (ap->mwdma_mask || ap->udma_mask) { in ata_bmdma_port_start()
2992 ap->bmdma_prd = in ata_bmdma_port_start()
2993 dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ, in ata_bmdma_port_start()
2994 &ap->bmdma_prd_dma, GFP_KERNEL); in ata_bmdma_port_start()
2995 if (!ap->bmdma_prd) in ata_bmdma_port_start()
2996 return -ENOMEM; in ata_bmdma_port_start()
3004 * ata_bmdma_port_start32 - Set port up for dma.
3008 * initialized. Enables 32bit PIO and allocates space for PRD
3012 * devices that are capable of 32bit PIO.
3019 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; in ata_bmdma_port_start32()
3027 * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex
3033 * have -undefined- behaviour.
3041 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3047 return -EOPNOTSUPP; in ata_pci_bmdma_clear_simplex()
3056 dev_err(host->dev, "BMDMA: %s, falling back to PIO\n", reason); in ata_bmdma_nodma()
3059 host->ports[i]->mwdma_mask = 0; in ata_bmdma_nodma()
3060 host->ports[i]->udma_mask = 0; in ata_bmdma_nodma()
3065 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
3075 struct device *gdev = host->dev; in ata_pci_bmdma_init()
3088 * ->sff_irq_clear method. Try to initialize bmdma_addr in ata_pci_bmdma_init()
3091 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3101 host->iomap = pcim_iomap_table(pdev); in ata_pci_bmdma_init()
3104 struct ata_port *ap = host->ports[i]; in ata_pci_bmdma_init()
3105 void __iomem *bmdma = host->iomap[4] + 8 * i; in ata_pci_bmdma_init()
3110 ap->ioaddr.bmdma_addr = bmdma; in ata_pci_bmdma_init()
3111 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && in ata_pci_bmdma_init()
3113 host->flags |= ATA_HOST_SIMPLEX; in ata_pci_bmdma_init()
3122 * ata_pci_bmdma_prepare_host - helper to prepare PCI BMDMA ATA host
3134 * 0 on success, -errno otherwise.
3152 * ata_pci_bmdma_init_one - Initialize/register BMDMA PCI IDE controller
3166 * Zero on success, negative on errno-based value on error.
3181 * ata_sff_port_init - Initialize SFF/BMDMA ATA port
3192 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task); in ata_sff_port_init()
3193 ap->ctl = ATA_DEVCTL_OBS; in ata_sff_port_init()
3194 ap->last_ctl = 0xFF; in ata_sff_port_init()
3201 return -ENOMEM; in ata_sff_init()