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/
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 * currently-selected device and return its value.
85 if (ap->ops->sff_check_altstatus) in ata_sff_altstatus()
86 return ap->ops->sff_check_altstatus(ap); in ata_sff_altstatus()
88 return ioread8(ap->ioaddr.altstatus_addr); in ata_sff_altstatus()
92 * ata_sff_irq_status - Check if the device is busy
107 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) { in ata_sff_irq_status()
114 status = ap->ops->sff_check_status(ap); in ata_sff_irq_status()
119 * ata_sff_sync - Flush writes
132 if (ap->ops->sff_check_altstatus) in ata_sff_sync()
133 ap->ops->sff_check_altstatus(ap); in ata_sff_sync()
134 else if (ap->ioaddr.altstatus_addr) in ata_sff_sync()
135 ioread8(ap->ioaddr.altstatus_addr); in ata_sff_sync()
139 * ata_sff_pause - Flush writes and wait 400nS
158 * ata_sff_dma_pause - Pause before commencing DMA
167 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) { in ata_sff_dma_pause()
181 * ata_sff_busy_sleep - sleep until BSY clears, or timeout
187 * or a timeout occurs.
193 * 0 on success, -errno otherwise.
219 status = ap->ops->sff_check_status(ap); in ata_sff_busy_sleep()
223 return -ENODEV; in ata_sff_busy_sleep()
229 return -EBUSY; in ata_sff_busy_sleep()
238 u8 status = link->ap->ops->sff_check_status(link->ap); in ata_sff_check_ready()
244 * ata_sff_wait_ready - sleep until BSY clears, or timeout
255 * 0 on success, -errno otherwise.
264 * ata_sff_set_devctl - Write device control reg
278 if (ap->ops->sff_set_devctl) in ata_sff_set_devctl()
279 ap->ops->sff_set_devctl(ap, ctl); in ata_sff_set_devctl()
281 iowrite8(ctl, ap->ioaddr.ctl_addr); in ata_sff_set_devctl()
285 * ata_sff_dev_select - Select device 0/1 on ATA bus
307 iowrite8(tmp, ap->ioaddr.device_addr); in ata_sff_dev_select()
313 * ata_dev_select - Select device 0/1 on ATA bus
316 * @wait: non-zero to wait for Status register BSY bit to clear
317 * @can_sleep: non-zero if context allows sleeping
323 * This is a high-level version of ata_sff_dev_select(), which
340 ap->ops->sff_dev_select(ap, device); in ata_dev_select()
343 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) in ata_dev_select()
350 * ata_sff_irq_on - Enable interrupts on a port.
353 * Enable interrupts on a legacy IDE device using MMIO or PIO,
364 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_irq_on()
366 if (ap->ops->sff_irq_on) { in ata_sff_irq_on()
367 ap->ops->sff_irq_on(ap); in ata_sff_irq_on()
371 ap->ctl &= ~ATA_NIEN; in ata_sff_irq_on()
372 ap->last_ctl = ap->ctl; in ata_sff_irq_on()
374 if (ap->ops->sff_set_devctl || ioaddr->ctl_addr) in ata_sff_irq_on()
375 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_irq_on()
378 if (ap->ops->sff_irq_clear) in ata_sff_irq_on()
379 ap->ops->sff_irq_clear(ap); in ata_sff_irq_on()
384 * ata_sff_tf_load - send taskfile registers to host controller
386 * @tf: ATA taskfile register set
393 void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_tf_load() argument
395 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_load()
396 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ata_sff_tf_load()
398 if (tf->ctl != ap->last_ctl) { in ata_sff_tf_load()
399 if (ioaddr->ctl_addr) in ata_sff_tf_load()
400 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_load()
401 ap->last_ctl = tf->ctl; in ata_sff_tf_load()
405 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ata_sff_tf_load()
406 WARN_ON_ONCE(!ioaddr->ctl_addr); in ata_sff_tf_load()
407 iowrite8(tf->hob_feature, ioaddr->feature_addr); in ata_sff_tf_load()
408 iowrite8(tf->hob_nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
409 iowrite8(tf->hob_lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
410 iowrite8(tf->hob_lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
411 iowrite8(tf->hob_lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
413 tf->hob_feature, in ata_sff_tf_load()
414 tf->hob_nsect, in ata_sff_tf_load()
415 tf->hob_lbal, in ata_sff_tf_load()
416 tf->hob_lbam, in ata_sff_tf_load()
417 tf->hob_lbah); 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()
427 tf->feature, in ata_sff_tf_load()
428 tf->nsect, in ata_sff_tf_load()
429 tf->lbal, in ata_sff_tf_load()
430 tf->lbam, in ata_sff_tf_load()
431 tf->lbah); in ata_sff_tf_load()
434 if (tf->flags & ATA_TFLAG_DEVICE) { in ata_sff_tf_load()
435 iowrite8(tf->device, ioaddr->device_addr); in ata_sff_tf_load()
436 VPRINTK("device 0x%X\n", tf->device); in ata_sff_tf_load()
444 * ata_sff_tf_read - input device's ATA taskfile shadow registers
446 * @tf: ATA taskfile register set for storing input
448 * Reads ATA taskfile registers for currently-selected device
449 * into @tf. Assumes the device has a fully SFF compliant task file
450 * layout and behaviour. If you device does not (eg has a different
451 * status method) then you will need to provide a replacement tf_read
456 void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf) in ata_sff_tf_read() argument
458 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_read()
460 tf->command = ata_sff_check_status(ap); in ata_sff_tf_read()
461 tf->feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
462 tf->nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
463 tf->lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
464 tf->lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
465 tf->lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
466 tf->device = ioread8(ioaddr->device_addr); in ata_sff_tf_read()
468 if (tf->flags & ATA_TFLAG_LBA48) { in ata_sff_tf_read()
469 if (likely(ioaddr->ctl_addr)) { in ata_sff_tf_read()
470 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in ata_sff_tf_read()
471 tf->hob_feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
472 tf->hob_nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
473 tf->hob_lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
474 tf->hob_lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
475 tf->hob_lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
476 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_read()
477 ap->last_ctl = tf->ctl; in ata_sff_tf_read()
485 * ata_sff_exec_command - issue ATA command to host controller
487 * @tf: ATA taskfile register set
495 void ata_sff_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_exec_command() argument
497 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command); in ata_sff_exec_command()
499 iowrite8(tf->command, ap->ioaddr.command_addr); in ata_sff_exec_command()
505 * ata_tf_to_host - issue ATA taskfile to host controller
507 * @tf: ATA taskfile register set
517 const struct ata_taskfile *tf) in ata_tf_to_host() argument
519 ap->ops->sff_tf_load(ap, tf); in ata_tf_to_host()
520 ap->ops->sff_exec_command(ap, tf); in ata_tf_to_host()
524 * ata_sff_data_xfer - Transfer data by PIO
541 struct ata_port *ap = qc->dev->link->ap; in ata_sff_data_xfer()
542 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer()
556 buf += buflen - 1; in ata_sff_data_xfer()
577 * ata_sff_data_xfer32 - Transfer data by PIO
596 struct ata_device *dev = qc->dev; in ata_sff_data_xfer32()
597 struct ata_port *ap = dev->link->ap; in ata_sff_data_xfer32()
598 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer32()
602 if (!(ap->pflags & ATA_PFLAG_PIO32)) in ata_sff_data_xfer32()
616 buf += buflen - slop; in ata_sff_data_xfer32()
643 bool do_write = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_pio_xfer()
647 qc->ap->ops->sff_data_xfer(qc, buf + offset, xfer_size, do_write); in ata_pio_xfer()
655 * ata_pio_sector - Transfer a sector of data.
658 * Transfer qc->sect_size bytes of data from/to the ATA device.
665 struct ata_port *ap = qc->ap; in ata_pio_sector()
669 if (!qc->cursg) { in ata_pio_sector()
670 qc->curbytes = qc->nbytes; in ata_pio_sector()
673 if (qc->curbytes == qc->nbytes - qc->sect_size) in ata_pio_sector()
674 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
676 page = sg_page(qc->cursg); in ata_pio_sector()
677 offset = qc->cursg->offset + qc->cursg_ofs; in ata_pio_sector()
683 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); in ata_pio_sector()
686 * Split the transfer when it splits a page boundary. Note that the in ata_pio_sector()
690 if (offset + qc->sect_size > PAGE_SIZE) { in ata_pio_sector()
691 unsigned int split_len = PAGE_SIZE - offset; in ata_pio_sector()
695 qc->sect_size - split_len); in ata_pio_sector()
697 ata_pio_xfer(qc, page, offset, qc->sect_size); in ata_pio_sector()
700 qc->curbytes += qc->sect_size; in ata_pio_sector()
701 qc->cursg_ofs += qc->sect_size; in ata_pio_sector()
703 if (qc->cursg_ofs == qc->cursg->length) { in ata_pio_sector()
704 qc->cursg = sg_next(qc->cursg); in ata_pio_sector()
705 if (!qc->cursg) in ata_pio_sector()
706 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
707 qc->cursg_ofs = 0; in ata_pio_sector()
712 * ata_pio_sectors - Transfer one or many sectors.
723 if (is_multi_taskfile(&qc->tf)) { in ata_pio_sectors()
727 WARN_ON_ONCE(qc->dev->multi_count == 0); in ata_pio_sectors()
729 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, in ata_pio_sectors()
730 qc->dev->multi_count); in ata_pio_sectors()
731 while (nsect--) in ata_pio_sectors()
736 ata_sff_sync(qc->ap); /* flush */ in ata_pio_sectors()
740 * atapi_send_cdb - Write CDB bytes to hardware
745 * a CDB, this function is called. Send the CDB.
754 WARN_ON_ONCE(qc->dev->cdb_len < 12); in atapi_send_cdb()
756 ap->ops->sff_data_xfer(qc, qc->cdb, qc->dev->cdb_len, 1); in atapi_send_cdb()
760 switch (qc->tf.protocol) { in atapi_send_cdb()
762 ap->hsm_task_state = HSM_ST; in atapi_send_cdb()
765 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
769 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
771 ap->ops->bmdma_start(qc); in atapi_send_cdb()
780 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
792 int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; in __atapi_pio_bytes()
793 struct ata_port *ap = qc->ap; in __atapi_pio_bytes()
794 struct ata_device *dev = qc->dev; in __atapi_pio_bytes()
795 struct ata_eh_info *ehi = &dev->link->eh_info; in __atapi_pio_bytes()
802 sg = qc->cursg; in __atapi_pio_bytes()
806 qc->nbytes, qc->curbytes, bytes); in __atapi_pio_bytes()
807 return -1; in __atapi_pio_bytes()
811 offset = sg->offset + qc->cursg_ofs; in __atapi_pio_bytes()
818 count = min(sg->length - qc->cursg_ofs, bytes); in __atapi_pio_bytes()
821 count = min(count, (unsigned int)PAGE_SIZE - offset); in __atapi_pio_bytes()
823 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); in __atapi_pio_bytes()
827 consumed = ap->ops->sff_data_xfer(qc, buf + offset, count, rw); in __atapi_pio_bytes()
830 bytes -= min(bytes, consumed); in __atapi_pio_bytes()
831 qc->curbytes += count; in __atapi_pio_bytes()
832 qc->cursg_ofs += count; in __atapi_pio_bytes()
834 if (qc->cursg_ofs == sg->length) { in __atapi_pio_bytes()
835 qc->cursg = sg_next(qc->cursg); in __atapi_pio_bytes()
836 qc->cursg_ofs = 0; in __atapi_pio_bytes()
840 * There used to be a WARN_ON_ONCE(qc->cursg && count != consumed); in __atapi_pio_bytes()
843 * made. Somebody should implement a proper sanity check. in __atapi_pio_bytes()
851 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
861 struct ata_port *ap = qc->ap; in atapi_pio_bytes()
862 struct ata_device *dev = qc->dev; in atapi_pio_bytes()
863 struct ata_eh_info *ehi = &dev->link->eh_info; in atapi_pio_bytes()
865 int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; in atapi_pio_bytes()
867 /* Abuse qc->result_tf for temp storage of intermediate TF in atapi_pio_bytes()
869 * For normal completion, qc->result_tf is not relevant. For in atapi_pio_bytes()
870 * error, qc->result_tf is later overwritten by ata_qc_complete(). in atapi_pio_bytes()
871 * So, the correctness of qc->result_tf is not affected. in atapi_pio_bytes()
873 ap->ops->sff_tf_read(ap, &qc->result_tf); in atapi_pio_bytes()
874 ireason = qc->result_tf.nsect; in atapi_pio_bytes()
875 bc_lo = qc->result_tf.lbam; in atapi_pio_bytes()
876 bc_hi = qc->result_tf.lbah; in atapi_pio_bytes()
891 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); in atapi_pio_bytes()
903 qc->err_mask |= AC_ERR_HSM; in atapi_pio_bytes()
904 ap->hsm_task_state = HSM_ST_ERR; in atapi_pio_bytes()
908 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
918 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_hsm_ok_in_wq()
921 if (ap->hsm_task_state == HSM_ST_FIRST) { in ata_hsm_ok_in_wq()
922 if (qc->tf.protocol == ATA_PROT_PIO && in ata_hsm_ok_in_wq()
923 (qc->tf.flags & ATA_TFLAG_WRITE)) in ata_hsm_ok_in_wq()
926 if (ata_is_atapi(qc->tf.protocol) && in ata_hsm_ok_in_wq()
927 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_hsm_ok_in_wq()
935 * ata_hsm_qc_complete - finish a qc running on standard HSM
947 struct ata_port *ap = qc->ap; in ata_hsm_qc_complete()
949 if (ap->ops->error_handler) { in ata_hsm_qc_complete()
954 qc = ata_qc_from_tag(ap, qc->tag); in ata_hsm_qc_complete()
956 if (likely(!(qc->err_mask & AC_ERR_HSM))) { in ata_hsm_qc_complete()
963 if (likely(!(qc->err_mask & AC_ERR_HSM))) in ata_hsm_qc_complete()
978 * ata_sff_hsm_move - move the HSM to the next state.
990 struct ata_link *link = qc->dev->link; in ata_sff_hsm_move()
991 struct ata_eh_info *ehi = &link->eh_info; in ata_sff_hsm_move()
994 lockdep_assert_held(ap->lock); in ata_sff_hsm_move()
996 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); in ata_sff_hsm_move()
1000 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). in ata_sff_hsm_move()
1006 ap->print_id, qc->tf.protocol, ap->hsm_task_state, status); in ata_sff_hsm_move()
1008 switch (ap->hsm_task_state) { in ata_sff_hsm_move()
1016 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); in ata_sff_hsm_move()
1023 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1028 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1031 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1047 if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) { in ata_sff_hsm_move()
1051 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1052 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1057 if (qc->tf.protocol == ATA_PROT_PIO) { in ata_sff_hsm_move()
1066 ap->hsm_task_state = HSM_ST; in ata_sff_hsm_move()
1079 if (qc->tf.protocol == ATAPI_PROT_PIO) { in ata_sff_hsm_move()
1085 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_hsm_move()
1096 ata_ehi_push_desc(ehi, "ST-ATAPI: " in ata_sff_hsm_move()
1099 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1100 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1106 if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) in ata_sff_hsm_move()
1116 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1119 * IDENTIFY, it's likely a phantom in ata_sff_hsm_move()
1122 if (qc->dev->horkage & in ata_sff_hsm_move()
1124 qc->err_mask |= in ata_sff_hsm_move()
1131 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1134 qc->err_mask |= AC_ERR_HSM | in ata_sff_hsm_move()
1138 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1154 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1156 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { in ata_sff_hsm_move()
1162 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1165 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1176 qc->err_mask |= AC_ERR_NODEV_HINT; in ata_sff_hsm_move()
1182 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1188 if (ap->hsm_task_state == HSM_ST_LAST && in ata_sff_hsm_move()
1189 (!(qc->tf.flags & ATA_TFLAG_WRITE))) { in ata_sff_hsm_move()
1201 qc->err_mask |= __ac_err_mask(status); in ata_sff_hsm_move()
1202 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1208 ap->print_id, qc->dev->devno, status); in ata_sff_hsm_move()
1210 WARN_ON_ONCE(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)); in ata_sff_hsm_move()
1212 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1221 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1231 ap->print_id, ap->hsm_task_state); in ata_sff_hsm_move()
1252 struct ata_port *ap = link->ap; in ata_sff_queue_pio_task()
1254 WARN_ON((ap->sff_pio_task_link != NULL) && in ata_sff_queue_pio_task()
1255 (ap->sff_pio_task_link != link)); in ata_sff_queue_pio_task()
1256 ap->sff_pio_task_link = link; in ata_sff_queue_pio_task()
1259 ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay)); in ata_sff_queue_pio_task()
1267 cancel_delayed_work_sync(&ap->sff_pio_task); in ata_sff_flush_pio_task()
1277 spin_lock_irq(ap->lock); in ata_sff_flush_pio_task()
1278 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_flush_pio_task()
1279 spin_unlock_irq(ap->lock); in ata_sff_flush_pio_task()
1281 ap->sff_pio_task_link = NULL; in ata_sff_flush_pio_task()
1291 struct ata_link *link = ap->sff_pio_task_link; in ata_sff_pio_task()
1296 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1298 BUG_ON(ap->sff_pio_task_link == NULL); in ata_sff_pio_task()
1300 qc = ata_qc_from_tag(ap, link->active_tag); in ata_sff_pio_task()
1302 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1307 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); in ata_sff_pio_task()
1310 * This is purely heuristic. This is a fast path. in ata_sff_pio_task()
1312 * a chk-status or two. If not, the drive is probably seeking in ata_sff_pio_task()
1313 * or something. Snooze for a couple msecs, then in ata_sff_pio_task()
1314 * chk-status again. If still busy, queue delayed work. in ata_sff_pio_task()
1318 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1320 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1333 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1343 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1347 * ata_sff_qc_issue - issue taskfile to a SFF controller
1350 * This function issues a PIO or NODATA command to a SFF
1361 struct ata_port *ap = qc->ap; in ata_sff_qc_issue()
1362 struct ata_link *link = qc->dev->link; in ata_sff_qc_issue()
1367 if (ap->flags & ATA_FLAG_PIO_POLLING) in ata_sff_qc_issue()
1368 qc->tf.flags |= ATA_TFLAG_POLLING; in ata_sff_qc_issue()
1371 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_sff_qc_issue()
1374 switch (qc->tf.protocol) { 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); in ata_sff_qc_issue()
1380 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_qc_issue()
1382 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1388 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1391 ata_tf_to_host(ap, &qc->tf); in ata_sff_qc_issue()
1393 if (qc->tf.flags & ATA_TFLAG_WRITE) { in ata_sff_qc_issue()
1395 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1403 ap->hsm_task_state = HSM_ST; in ata_sff_qc_issue()
1405 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1418 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1421 ata_tf_to_host(ap, &qc->tf); in ata_sff_qc_issue()
1423 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1426 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || in ata_sff_qc_issue()
1427 (qc->tf.flags & ATA_TFLAG_POLLING)) in ata_sff_qc_issue()
1440 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
1441 * @qc: qc to fill result TF for
1443 * @qc is finished and result TF needs to be filled. Fill it
1444 * using ->sff_tf_read.
1450 * true indicating that result TF is successfully filled.
1454 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); in ata_sff_qc_fill_rtf()
1461 ap->stats.idle_irq++; in ata_sff_idle_irq()
1464 if ((ap->stats.idle_irq % 1000) == 0) { in ata_sff_idle_irq()
1465 ap->ops->sff_check_status(ap); in ata_sff_idle_irq()
1466 if (ap->ops->sff_irq_clear) in ata_sff_idle_irq()
1467 ap->ops->sff_irq_clear(ap); in ata_sff_idle_irq()
1482 ap->print_id, qc->tf.protocol, ap->hsm_task_state); in __ata_sff_port_intr()
1485 switch (ap->hsm_task_state) { in __ata_sff_port_intr()
1487 /* Some pre-ATAPI-4 devices assert INTRQ in __ata_sff_port_intr()
1493 * need to check ata_is_atapi(qc->tf.protocol) again. in __ata_sff_port_intr()
1495 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in __ata_sff_port_intr()
1509 qc->err_mask |= AC_ERR_HSM; in __ata_sff_port_intr()
1510 ap->hsm_task_state = HSM_ST_ERR; in __ata_sff_port_intr()
1516 if (ap->ops->sff_irq_clear) in __ata_sff_port_intr()
1517 ap->ops->sff_irq_clear(ap); in __ata_sff_port_intr()
1525 * ata_sff_port_intr - Handle SFF port interrupt
1553 spin_lock_irqsave(&host->lock, flags); in __ata_sff_interrupt()
1557 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1558 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1561 qc = ata_qc_from_tag(ap, ap->link.active_tag); in __ata_sff_interrupt()
1563 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) in __ata_sff_interrupt()
1579 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1580 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1585 if (!ap->ops->sff_irq_check || in __ata_sff_interrupt()
1586 !ap->ops->sff_irq_check(ap)) in __ata_sff_interrupt()
1590 ap->ops->sff_check_status(ap); in __ata_sff_interrupt()
1591 if (ap->ops->sff_irq_clear) in __ata_sff_interrupt()
1592 ap->ops->sff_irq_clear(ap); in __ata_sff_interrupt()
1595 if (!(ap->ops->sff_check_status(ap) & ATA_BUSY)) in __ata_sff_interrupt()
1610 spin_unlock_irqrestore(&host->lock, flags); in __ata_sff_interrupt()
1616 * ata_sff_interrupt - Default SFF ATA host interrupt handler
1636 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1654 qc = ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_lost_interrupt()
1655 /* We cannot lose an interrupt on a non-existent or polled command */ in ata_sff_lost_interrupt()
1656 if (!qc || qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_lost_interrupt()
1658 /* See if the controller thinks it is still busy - if so the command in ata_sff_lost_interrupt()
1659 isn't a lost IRQ but is still in progress */ in ata_sff_lost_interrupt()
1664 /* There was a command running, we are no longer busy and we have in ata_sff_lost_interrupt()
1675 * ata_sff_freeze - Freeze SFF controller port
1685 ap->ctl |= ATA_NIEN; in ata_sff_freeze()
1686 ap->last_ctl = ap->ctl; in ata_sff_freeze()
1688 if (ap->ops->sff_set_devctl || ap->ioaddr.ctl_addr) in ata_sff_freeze()
1689 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_freeze()
1695 ap->ops->sff_check_status(ap); in ata_sff_freeze()
1697 if (ap->ops->sff_irq_clear) in ata_sff_freeze()
1698 ap->ops->sff_irq_clear(ap); in ata_sff_freeze()
1703 * ata_sff_thaw - Thaw SFF controller port
1713 /* clear & re-enable interrupts */ in ata_sff_thaw()
1714 ap->ops->sff_check_status(ap); in ata_sff_thaw()
1715 if (ap->ops->sff_irq_clear) in ata_sff_thaw()
1716 ap->ops->sff_irq_clear(ap); in ata_sff_thaw()
1722 * ata_sff_prereset - prepare SFF link for reset
1734 * 0 on success, -errno otherwise.
1738 struct ata_eh_context *ehc = &link->eh_context; in ata_sff_prereset()
1746 if (ehc->i.action & ATA_EH_HARDRESET) in ata_sff_prereset()
1752 if (rc && rc != -ENODEV) { in ata_sff_prereset()
1756 ehc->i.action |= ATA_EH_HARDRESET; in ata_sff_prereset()
1765 * ata_devchk - PATA device presence detection
1770 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1773 * Write a pattern to the ATA shadow registers,
1774 * and if a device is present, it will respond by
1783 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_devchk()
1786 ap->ops->sff_dev_select(ap, device); in ata_devchk()
1788 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1789 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1791 iowrite8(0xaa, ioaddr->nsect_addr); in ata_devchk()
1792 iowrite8(0x55, ioaddr->lbal_addr); in ata_devchk()
1794 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1795 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1797 nsect = ioread8(ioaddr->nsect_addr); in ata_devchk()
1798 lbal = ioread8(ioaddr->lbal_addr); in ata_devchk()
1801 return 1; /* we found a device */ in ata_devchk()
1807 * ata_sff_dev_classify - Parse returned ATA device signature
1812 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1813 * an ATA/ATAPI-defined set of values is placed in the ATA
1819 * and the spec-defined values examined by ata_dev_classify().
1825 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1830 struct ata_port *ap = dev->link->ap; in ata_sff_dev_classify()
1831 struct ata_taskfile tf; in ata_sff_dev_classify() local
1835 ap->ops->sff_dev_select(ap, dev->devno); in ata_sff_dev_classify()
1837 memset(&tf, 0, sizeof(tf)); in ata_sff_dev_classify()
1839 ap->ops->sff_tf_read(ap, &tf); in ata_sff_dev_classify()
1840 err = tf.feature; in ata_sff_dev_classify()
1847 dev->horkage |= ATA_HORKAGE_DIAGNOSTIC; in ata_sff_dev_classify()
1850 else if ((dev->devno == 0) && (err == 0x81)) in ata_sff_dev_classify()
1856 class = ata_dev_classify(&tf); in ata_sff_dev_classify()
1865 if (present && (dev->horkage & ATA_HORKAGE_DIAGNOSTIC)) in ata_sff_dev_classify()
1870 (ap->ops->sff_check_status(ap) == 0)) in ata_sff_dev_classify()
1878 * ata_sff_wait_after_reset - wait for devices to become ready after reset
1884 * reset. It contains preceding 150ms wait to avoid accessing TF
1891 * 0 on success, -ENODEV if some or all of devices in @devmask
1892 * don't seem to exist. -errno on other errors.
1897 struct ata_port *ap = link->ap; in ata_sff_wait_after_reset()
1898 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_wait_after_reset()
1907 /* -ENODEV means the odd clown forgot the D7 pulldown resistor in ata_sff_wait_after_reset()
1908 * and TF status is 0xff, bail out on it too. in ata_sff_wait_after_reset()
1919 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1928 nsect = ioread8(ioaddr->nsect_addr); in ata_sff_wait_after_reset()
1929 lbal = ioread8(ioaddr->lbal_addr); in ata_sff_wait_after_reset()
1932 ata_msleep(ap, 50); /* give drive a breather */ in ata_sff_wait_after_reset()
1937 if (rc != -ENODEV) in ata_sff_wait_after_reset()
1944 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1946 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1948 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1957 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_bus_softreset()
1959 DPRINTK("ata%u: bus reset via SRST\n", ap->print_id); in ata_bus_softreset()
1961 if (ap->ioaddr.ctl_addr) { in ata_bus_softreset()
1963 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1965 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in ata_bus_softreset()
1967 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1968 ap->last_ctl = ap->ctl; in ata_bus_softreset()
1972 return ata_sff_wait_after_reset(&ap->link, devmask, deadline); in ata_bus_softreset()
1976 * ata_sff_softreset - reset host port via ATA SRST
1987 * 0 on success, -errno otherwise.
1992 struct ata_port *ap = link->ap; in ata_sff_softreset()
1993 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ata_sff_softreset()
2007 ap->ops->sff_dev_select(ap, 0); in ata_sff_softreset()
2012 /* if link is occupied, -ENODEV too is an error */ in ata_sff_softreset()
2013 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in ata_sff_softreset()
2019 classes[0] = ata_sff_dev_classify(&link->device[0], in ata_sff_softreset()
2022 classes[1] = ata_sff_dev_classify(&link->device[1], in ata_sff_softreset()
2031 * sata_sff_hardreset - reset host port via SATA phy reset
2036 * SATA phy-reset host port using DET bits of SControl register,
2043 * 0 on success, -errno otherwise.
2048 struct ata_eh_context *ehc = &link->eh_context; in sata_sff_hardreset()
2056 *class = ata_sff_dev_classify(link->device, 1, NULL); in sata_sff_hardreset()
2064 * ata_sff_postreset - SFF postreset callback
2068 * This function is invoked after a successful reset. It first
2077 struct ata_port *ap = link->ap; in ata_sff_postreset()
2081 /* is double-select really necessary? */ in ata_sff_postreset()
2083 ap->ops->sff_dev_select(ap, 1); in ata_sff_postreset()
2085 ap->ops->sff_dev_select(ap, 0); in ata_sff_postreset()
2094 if (ap->ops->sff_set_devctl || ap->ioaddr.ctl_addr) { in ata_sff_postreset()
2095 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_postreset()
2096 ap->last_ctl = ap->ctl; in ata_sff_postreset()
2102 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2105 * Drain the FIFO and device of any stuck data following a command
2106 * failing to complete. In some cases this is necessary before a
2116 /* We only need to flush incoming data when a command was running */ in ata_sff_drain_fifo()
2117 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ata_sff_drain_fifo()
2120 ap = qc->ap; in ata_sff_drain_fifo()
2122 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ata_sff_drain_fifo()
2124 ioread16(ap->ioaddr.data_addr); in ata_sff_drain_fifo()
2134 * ata_sff_error_handler - Stock error handler for SFF controller
2139 * use this EH as-is or with some added handling before and
2147 ata_reset_fn_t softreset = ap->ops->softreset; in ata_sff_error_handler()
2148 ata_reset_fn_t hardreset = ap->ops->hardreset; in ata_sff_error_handler()
2152 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_error_handler()
2153 if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) in ata_sff_error_handler()
2156 spin_lock_irqsave(ap->lock, flags); in ata_sff_error_handler()
2159 * We *MUST* do FIFO draining before we issue a reset as in ata_sff_error_handler()
2165 if (ap->ops->sff_drain_fifo) in ata_sff_error_handler()
2166 ap->ops->sff_drain_fifo(qc); in ata_sff_error_handler()
2168 spin_unlock_irqrestore(ap->lock, flags); in ata_sff_error_handler()
2170 /* ignore built-in hardresets if SCR access is not available */ in ata_sff_error_handler()
2172 hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link)) in ata_sff_error_handler()
2175 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, in ata_sff_error_handler()
2176 ap->ops->postreset); in ata_sff_error_handler()
2181 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
2193 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; in ata_sff_std_ports()
2194 ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; in ata_sff_std_ports()
2195 ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; in ata_sff_std_ports()
2196 ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; in ata_sff_std_ports()
2197 ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; in ata_sff_std_ports()
2198 ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; in ata_sff_std_ports()
2199 ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; in ata_sff_std_ports()
2200 ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; in ata_sff_std_ports()
2201 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; in ata_sff_std_ports()
2202 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; in ata_sff_std_ports()
2223 * ata_pci_sff_init_host - acquire native PCI ATA resources and init host
2238 * 0 if at least one port is initialized, -ENODEV if no port is
2243 struct device *gdev = host->dev; in ata_pci_sff_init_host()
2250 struct ata_port *ap = host->ports[i]; in ata_pci_sff_init_host()
2262 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2272 if (rc == -EBUSY) in ata_pci_sff_init_host()
2274 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2277 host->iomap = iomap = pcim_iomap_table(pdev); in ata_pci_sff_init_host()
2279 ap->ioaddr.cmd_addr = iomap[base]; in ata_pci_sff_init_host()
2280 ap->ioaddr.altstatus_addr = in ata_pci_sff_init_host()
2281 ap->ioaddr.ctl_addr = (void __iomem *) in ata_pci_sff_init_host()
2283 ata_sff_std_ports(&ap->ioaddr); in ata_pci_sff_init_host()
2294 return -ENODEV; in ata_pci_sff_init_host()
2302 * ata_pci_sff_prepare_host - helper to prepare PCI PIO-only SFF ATA host
2307 * Helper to allocate PIO-only SFF ATA host for @pdev, acquire
2314 * 0 on success, -errno otherwise.
2323 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) in ata_pci_sff_prepare_host()
2324 return -ENOMEM; in ata_pci_sff_prepare_host()
2326 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); in ata_pci_sff_prepare_host()
2328 dev_err(&pdev->dev, "failed to allocate ATA host\n"); in ata_pci_sff_prepare_host()
2329 rc = -ENOMEM; in ata_pci_sff_prepare_host()
2337 devres_remove_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2342 devres_release_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2348 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
2361 * 0 on success, -errno otherwise.
2367 struct device *dev = host->dev; in ata_pci_sff_activate_host()
2369 const char *drv_name = dev_driver_string(host->dev); in ata_pci_sff_activate_host()
2376 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { in ata_pci_sff_activate_host()
2388 if (!ata_port_is_dummy(host->ports[0])) in ata_pci_sff_activate_host()
2390 if (!ata_port_is_dummy(host->ports[1])) in ata_pci_sff_activate_host()
2397 return -ENOMEM; in ata_pci_sff_activate_host()
2399 if (!legacy_mode && pdev->irq) { in ata_pci_sff_activate_host()
2402 rc = devm_request_irq(dev, pdev->irq, irq_handler, in ata_pci_sff_activate_host()
2408 if (ata_port_is_dummy(host->ports[i])) in ata_pci_sff_activate_host()
2410 ata_port_desc(host->ports[i], "irq %d", pdev->irq); in ata_pci_sff_activate_host()
2413 if (!ata_port_is_dummy(host->ports[0])) { in ata_pci_sff_activate_host()
2420 ata_port_desc(host->ports[0], "irq %d", in ata_pci_sff_activate_host()
2424 if (!ata_port_is_dummy(host->ports[1])) { in ata_pci_sff_activate_host()
2431 ata_port_desc(host->ports[1], "irq %d", in ata_pci_sff_activate_host()
2454 if (ppi[i]->port_ops != &ata_dummy_port_ops) in ata_sff_find_valid_pi()
2465 struct device *dev = &pdev->dev; in ata_pci_init_one()
2474 dev_err(&pdev->dev, "no valid port_info specified\n"); in ata_pci_init_one()
2475 return -EINVAL; in ata_pci_init_one()
2479 return -ENOMEM; in ata_pci_init_one()
2495 host->private_data = host_priv; in ata_pci_init_one()
2496 host->flags |= hflags; in ata_pci_init_one()
2507 devres_remove_group(&pdev->dev, NULL); in ata_pci_init_one()
2509 devres_release_group(&pdev->dev, NULL); in ata_pci_init_one()
2515 * ata_pci_sff_init_one - Initialize/register PIO-only PCI IDE controller
2522 * This is a helper function which can be called from a driver's
2527 * Nobody makes a single channel controller that appears solely as
2534 * Zero on success, negative on errno-based value on error.
2580 * ata_bmdma_fill_sg - Fill PCI IDE PRD table
2583 * Fill PCI IDE PRD (scatter-gather) table with segments
2592 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg()
2593 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg()
2598 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg()
2603 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg()
2613 len = 0x10000 - offset; in ata_bmdma_fill_sg()
2620 sg_len -= len; in ata_bmdma_fill_sg()
2625 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg()
2629 * ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
2632 * Fill PCI IDE PRD (scatter-gather) table with segments
2643 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg_dumb()
2644 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg_dumb()
2649 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg_dumb()
2654 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg_dumb()
2664 len = 0x10000 - offset; in ata_bmdma_fill_sg_dumb()
2680 sg_len -= len; in ata_bmdma_fill_sg_dumb()
2685 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg_dumb()
2689 * ata_bmdma_qc_prep - Prepare taskfile for submission
2699 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_qc_prep()
2709 * ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
2719 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_dumb_qc_prep()
2729 * ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
2732 * This function issues a PIO, NODATA or DMA command to a
2744 struct ata_port *ap = qc->ap; in ata_bmdma_qc_issue()
2745 struct ata_link *link = qc->dev->link; in ata_bmdma_qc_issue()
2748 if (!ata_is_dma(qc->tf.protocol)) in ata_bmdma_qc_issue()
2752 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_bmdma_qc_issue()
2755 switch (qc->tf.protocol) { in ata_bmdma_qc_issue()
2757 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2759 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2760 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2761 ap->ops->bmdma_start(qc); /* initiate bmdma */ in ata_bmdma_qc_issue()
2762 ap->hsm_task_state = HSM_ST_LAST; in ata_bmdma_qc_issue()
2766 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2768 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2769 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2770 ap->hsm_task_state = HSM_ST_FIRST; in ata_bmdma_qc_issue()
2773 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_bmdma_qc_issue()
2787 * ata_bmdma_port_intr - Handle BMDMA port interrupt
2801 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_bmdma_port_intr()
2806 if (ap->hsm_task_state == HSM_ST_LAST && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_port_intr()
2808 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_port_intr()
2809 VPRINTK("ata%u: host_stat 0x%X\n", ap->print_id, host_stat); in ata_bmdma_port_intr()
2815 /* before we do anything else, clear DMA-Start bit */ in ata_bmdma_port_intr()
2816 ap->ops->bmdma_stop(qc); in ata_bmdma_port_intr()
2821 qc->err_mask |= AC_ERR_HOST_BUS; in ata_bmdma_port_intr()
2822 ap->hsm_task_state = HSM_ST_ERR; in ata_bmdma_port_intr()
2828 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) in ata_bmdma_port_intr()
2836 * ata_bmdma_interrupt - Default BMDMA ATA host interrupt handler
2856 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
2861 * able to use this EH as-is or with some added handling before
2873 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_bmdma_error_handler()
2874 if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) in ata_bmdma_error_handler()
2878 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_error_handler()
2880 if (qc && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_error_handler()
2883 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_error_handler()
2887 * really a timeout event, adjust error mask and in ata_bmdma_error_handler()
2890 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { in ata_bmdma_error_handler()
2891 qc->err_mask = AC_ERR_HOST_BUS; in ata_bmdma_error_handler()
2895 ap->ops->bmdma_stop(qc); in ata_bmdma_error_handler()
2899 ap->ops->sff_check_status(ap); in ata_bmdma_error_handler()
2900 if (ap->ops->sff_irq_clear) in ata_bmdma_error_handler()
2901 ap->ops->sff_irq_clear(ap); in ata_bmdma_error_handler()
2905 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_error_handler()
2915 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
2923 struct ata_port *ap = qc->ap; in ata_bmdma_post_internal_cmd()
2926 if (ata_is_dma(qc->tf.protocol)) { in ata_bmdma_post_internal_cmd()
2927 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2928 ap->ops->bmdma_stop(qc); in ata_bmdma_post_internal_cmd()
2929 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2935 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
2947 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_irq_clear()
2957 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
2965 struct ata_port *ap = qc->ap; in ata_bmdma_setup()
2966 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_bmdma_setup()
2971 iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); in ata_bmdma_setup()
2973 /* specify data direction, triple-check start bit is clear */ in ata_bmdma_setup()
2974 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2978 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2981 ap->ops->sff_exec_command(ap, &qc->tf); in ata_bmdma_setup()
2986 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
2994 struct ata_port *ap = qc->ap; in ata_bmdma_start()
2998 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2999 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
3006 * Further, a read of the DMA status register _immediately_ in ata_bmdma_start()
3008 * is expected, so I think it is best to not add a readb() in ata_bmdma_start()
3019 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
3031 struct ata_port *ap = qc->ap; in ata_bmdma_stop()
3032 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_stop()
3038 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in ata_bmdma_stop()
3044 * ata_bmdma_status - Read PCI IDE BMDMA status
3056 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); in ata_bmdma_status()
3062 * ata_bmdma_port_start - Set port up for bmdma.
3075 if (ap->mwdma_mask || ap->udma_mask) { in ata_bmdma_port_start()
3076 ap->bmdma_prd = in ata_bmdma_port_start()
3077 dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ, in ata_bmdma_port_start()
3078 &ap->bmdma_prd_dma, GFP_KERNEL); in ata_bmdma_port_start()
3079 if (!ap->bmdma_prd) in ata_bmdma_port_start()
3080 return -ENOMEM; in ata_bmdma_port_start()
3088 * ata_bmdma_port_start32 - Set port up for dma.
3103 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; in ata_bmdma_port_start32()
3111 * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex
3117 * have -undefined- behaviour.
3125 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3131 return -EOPNOTSUPP; in ata_pci_bmdma_clear_simplex()
3140 dev_err(host->dev, "BMDMA: %s, falling back to PIO\n", reason); in ata_bmdma_nodma()
3143 host->ports[i]->mwdma_mask = 0; in ata_bmdma_nodma()
3144 host->ports[i]->udma_mask = 0; in ata_bmdma_nodma()
3149 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
3159 struct device *gdev = host->dev; in ata_pci_bmdma_init()
3172 * ->sff_irq_clear method. Try to initialize bmdma_addr in ata_pci_bmdma_init()
3175 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3185 host->iomap = pcim_iomap_table(pdev); in ata_pci_bmdma_init()
3188 struct ata_port *ap = host->ports[i]; in ata_pci_bmdma_init()
3189 void __iomem *bmdma = host->iomap[4] + 8 * i; in ata_pci_bmdma_init()
3194 ap->ioaddr.bmdma_addr = bmdma; in ata_pci_bmdma_init()
3195 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && in ata_pci_bmdma_init()
3197 host->flags |= ATA_HOST_SIMPLEX; in ata_pci_bmdma_init()
3206 * ata_pci_bmdma_prepare_host - helper to prepare PCI BMDMA ATA host
3218 * 0 on success, -errno otherwise.
3236 * ata_pci_bmdma_init_one - Initialize/register BMDMA PCI IDE controller
3250 * Zero on success, negative on errno-based value on error.
3265 * ata_sff_port_init - Initialize SFF/BMDMA ATA port
3276 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task); in ata_sff_port_init()
3277 ap->ctl = ATA_DEVCTL_OBS; in ata_sff_port_init()
3278 ap->last_ctl = 0xFF; in ata_sff_port_init()
3285 return -ENOMEM; in ata_sff_init()