• Home
  • Raw
  • Download

Lines Matching +full:tf +full:- +full:a

2  *  libata-sff.c - helper library for PCI IDE BMDMA
5 * Please ALWAYS copy linux-ide@vger.kernel.org
8 * Copyright 2003-2006 Red Hat, Inc. All rights reserved.
9 * Copyright 2003-2006 Jeff Garzik
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * You should have received a copy of the GNU General Public License
28 * as Documentation/driver-api/libata.rst
31 * http://www.sata-io.org/
74 * ata_sff_check_status - Read device status reg & clear interrupt
77 * Reads ATA taskfile status register for currently-selected device
86 return ioread8(ap->ioaddr.status_addr); in ata_sff_check_status()
91 * ata_sff_altstatus - Read device alternate status reg
95 * currently-selected device and return its value.
105 if (ap->ops->sff_check_altstatus) in ata_sff_altstatus()
106 return ap->ops->sff_check_altstatus(ap); in ata_sff_altstatus()
108 return ioread8(ap->ioaddr.altstatus_addr); in ata_sff_altstatus()
112 * ata_sff_irq_status - Check if the device is busy
127 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) { in ata_sff_irq_status()
134 status = ap->ops->sff_check_status(ap); in ata_sff_irq_status()
139 * ata_sff_sync - Flush writes
152 if (ap->ops->sff_check_altstatus) in ata_sff_sync()
153 ap->ops->sff_check_altstatus(ap); in ata_sff_sync()
154 else if (ap->ioaddr.altstatus_addr) in ata_sff_sync()
155 ioread8(ap->ioaddr.altstatus_addr); in ata_sff_sync()
159 * ata_sff_pause - Flush writes and wait 400nS
178 * ata_sff_dma_pause - Pause before commencing DMA
187 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) { in ata_sff_dma_pause()
201 * ata_sff_busy_sleep - sleep until BSY clears, or timeout
207 * or a timeout occurs.
213 * 0 on success, -errno otherwise.
239 status = ap->ops->sff_check_status(ap); in ata_sff_busy_sleep()
243 return -ENODEV; in ata_sff_busy_sleep()
249 return -EBUSY; in ata_sff_busy_sleep()
258 u8 status = link->ap->ops->sff_check_status(link->ap); in ata_sff_check_ready()
264 * ata_sff_wait_ready - sleep until BSY clears, or timeout
275 * 0 on success, -errno otherwise.
284 * ata_sff_set_devctl - Write device control reg
298 if (ap->ops->sff_set_devctl) in ata_sff_set_devctl()
299 ap->ops->sff_set_devctl(ap, ctl); in ata_sff_set_devctl()
301 iowrite8(ctl, ap->ioaddr.ctl_addr); in ata_sff_set_devctl()
305 * ata_sff_dev_select - Select device 0/1 on ATA bus
327 iowrite8(tmp, ap->ioaddr.device_addr); in ata_sff_dev_select()
333 * ata_dev_select - Select device 0/1 on ATA bus
336 * @wait: non-zero to wait for Status register BSY bit to clear
337 * @can_sleep: non-zero if context allows sleeping
343 * This is a high-level version of ata_sff_dev_select(), which
360 ap->ops->sff_dev_select(ap, device); in ata_dev_select()
363 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) in ata_dev_select()
370 * ata_sff_irq_on - Enable interrupts on a port.
373 * Enable interrupts on a legacy IDE device using MMIO or PIO,
384 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_irq_on()
386 if (ap->ops->sff_irq_on) { in ata_sff_irq_on()
387 ap->ops->sff_irq_on(ap); in ata_sff_irq_on()
391 ap->ctl &= ~ATA_NIEN; in ata_sff_irq_on()
392 ap->last_ctl = ap->ctl; in ata_sff_irq_on()
394 if (ap->ops->sff_set_devctl || ioaddr->ctl_addr) in ata_sff_irq_on()
395 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_irq_on()
398 if (ap->ops->sff_irq_clear) in ata_sff_irq_on()
399 ap->ops->sff_irq_clear(ap); in ata_sff_irq_on()
404 * ata_sff_tf_load - send taskfile registers to host controller
406 * @tf: ATA taskfile register set
413 void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_tf_load() argument
415 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_load()
416 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ata_sff_tf_load()
418 if (tf->ctl != ap->last_ctl) { in ata_sff_tf_load()
419 if (ioaddr->ctl_addr) in ata_sff_tf_load()
420 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_load()
421 ap->last_ctl = tf->ctl; in ata_sff_tf_load()
425 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ata_sff_tf_load()
426 WARN_ON_ONCE(!ioaddr->ctl_addr); in ata_sff_tf_load()
427 iowrite8(tf->hob_feature, ioaddr->feature_addr); in ata_sff_tf_load()
428 iowrite8(tf->hob_nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
429 iowrite8(tf->hob_lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
430 iowrite8(tf->hob_lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
431 iowrite8(tf->hob_lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
433 tf->hob_feature, in ata_sff_tf_load()
434 tf->hob_nsect, in ata_sff_tf_load()
435 tf->hob_lbal, in ata_sff_tf_load()
436 tf->hob_lbam, in ata_sff_tf_load()
437 tf->hob_lbah); in ata_sff_tf_load()
441 iowrite8(tf->feature, ioaddr->feature_addr); in ata_sff_tf_load()
442 iowrite8(tf->nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
443 iowrite8(tf->lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
444 iowrite8(tf->lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
445 iowrite8(tf->lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
447 tf->feature, in ata_sff_tf_load()
448 tf->nsect, in ata_sff_tf_load()
449 tf->lbal, in ata_sff_tf_load()
450 tf->lbam, in ata_sff_tf_load()
451 tf->lbah); in ata_sff_tf_load()
454 if (tf->flags & ATA_TFLAG_DEVICE) { in ata_sff_tf_load()
455 iowrite8(tf->device, ioaddr->device_addr); in ata_sff_tf_load()
456 VPRINTK("device 0x%X\n", tf->device); in ata_sff_tf_load()
464 * ata_sff_tf_read - input device's ATA taskfile shadow registers
466 * @tf: ATA taskfile register set for storing input
468 * Reads ATA taskfile registers for currently-selected device
469 * into @tf. Assumes the device has a fully SFF compliant task file
470 * layout and behaviour. If you device does not (eg has a different
471 * status method) then you will need to provide a replacement tf_read
476 void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf) in ata_sff_tf_read() argument
478 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_read()
480 tf->command = ata_sff_check_status(ap); in ata_sff_tf_read()
481 tf->feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
482 tf->nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
483 tf->lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
484 tf->lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
485 tf->lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
486 tf->device = ioread8(ioaddr->device_addr); in ata_sff_tf_read()
488 if (tf->flags & ATA_TFLAG_LBA48) { in ata_sff_tf_read()
489 if (likely(ioaddr->ctl_addr)) { in ata_sff_tf_read()
490 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in ata_sff_tf_read()
491 tf->hob_feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
492 tf->hob_nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
493 tf->hob_lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
494 tf->hob_lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
495 tf->hob_lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
496 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_read()
497 ap->last_ctl = tf->ctl; in ata_sff_tf_read()
505 * ata_sff_exec_command - issue ATA command to host controller
507 * @tf: ATA taskfile register set
515 void ata_sff_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_exec_command() argument
517 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command); in ata_sff_exec_command()
519 iowrite8(tf->command, ap->ioaddr.command_addr); in ata_sff_exec_command()
525 * ata_tf_to_host - issue ATA taskfile to host controller
527 * @tf: ATA taskfile register set
537 const struct ata_taskfile *tf) in ata_tf_to_host() argument
539 ap->ops->sff_tf_load(ap, tf); in ata_tf_to_host()
540 ap->ops->sff_exec_command(ap, tf); in ata_tf_to_host()
544 * ata_sff_data_xfer - Transfer data by PIO
561 struct ata_port *ap = qc->dev->link->ap; in ata_sff_data_xfer()
562 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer()
576 buf += buflen - 1; in ata_sff_data_xfer()
597 * ata_sff_data_xfer32 - Transfer data by PIO
616 struct ata_device *dev = qc->dev; in ata_sff_data_xfer32()
617 struct ata_port *ap = dev->link->ap; in ata_sff_data_xfer32()
618 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer32()
622 if (!(ap->pflags & ATA_PFLAG_PIO32)) in ata_sff_data_xfer32()
636 buf += buflen - slop; in ata_sff_data_xfer32()
661 * ata_pio_sector - Transfer a sector of data.
664 * Transfer qc->sect_size bytes of data from/to the ATA device.
671 int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_pio_sector()
672 struct ata_port *ap = qc->ap; in ata_pio_sector()
677 if (!qc->cursg) { in ata_pio_sector()
678 qc->curbytes = qc->nbytes; in ata_pio_sector()
681 if (qc->curbytes == qc->nbytes - qc->sect_size) in ata_pio_sector()
682 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
684 page = sg_page(qc->cursg); in ata_pio_sector()
685 offset = qc->cursg->offset + qc->cursg_ofs; in ata_pio_sector()
691 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); in ata_pio_sector()
695 ap->ops->sff_data_xfer(qc, buf + offset, qc->sect_size, do_write); in ata_pio_sector()
701 qc->curbytes += qc->sect_size; in ata_pio_sector()
702 qc->cursg_ofs += qc->sect_size; in ata_pio_sector()
704 if (qc->cursg_ofs == qc->cursg->length) { in ata_pio_sector()
705 qc->cursg = sg_next(qc->cursg); in ata_pio_sector()
706 if (!qc->cursg) in ata_pio_sector()
707 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
708 qc->cursg_ofs = 0; in ata_pio_sector()
713 * ata_pio_sectors - Transfer one or many sectors.
724 if (is_multi_taskfile(&qc->tf)) { in ata_pio_sectors()
728 WARN_ON_ONCE(qc->dev->multi_count == 0); in ata_pio_sectors()
730 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, in ata_pio_sectors()
731 qc->dev->multi_count); in ata_pio_sectors()
732 while (nsect--) in ata_pio_sectors()
737 ata_sff_sync(qc->ap); /* flush */ in ata_pio_sectors()
741 * atapi_send_cdb - Write CDB bytes to hardware
746 * a CDB, this function is called. Send the CDB.
755 WARN_ON_ONCE(qc->dev->cdb_len < 12); in atapi_send_cdb()
757 ap->ops->sff_data_xfer(qc, qc->cdb, qc->dev->cdb_len, 1); in atapi_send_cdb()
761 switch (qc->tf.protocol) { in atapi_send_cdb()
763 ap->hsm_task_state = HSM_ST; in atapi_send_cdb()
766 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
770 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
772 ap->ops->bmdma_start(qc); in atapi_send_cdb()
781 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
793 int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; in __atapi_pio_bytes()
794 struct ata_port *ap = qc->ap; in __atapi_pio_bytes()
795 struct ata_device *dev = qc->dev; in __atapi_pio_bytes()
796 struct ata_eh_info *ehi = &dev->link->eh_info; in __atapi_pio_bytes()
803 sg = qc->cursg; in __atapi_pio_bytes()
807 qc->nbytes, qc->curbytes, bytes); in __atapi_pio_bytes()
808 return -1; in __atapi_pio_bytes()
812 offset = sg->offset + qc->cursg_ofs; in __atapi_pio_bytes()
819 count = min(sg->length - qc->cursg_ofs, bytes); in __atapi_pio_bytes()
822 count = min(count, (unsigned int)PAGE_SIZE - offset); in __atapi_pio_bytes()
824 DPRINTK("data %s\n", qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); in __atapi_pio_bytes()
828 consumed = ap->ops->sff_data_xfer(qc, buf + offset, count, rw); in __atapi_pio_bytes()
831 bytes -= min(bytes, consumed); in __atapi_pio_bytes()
832 qc->curbytes += count; in __atapi_pio_bytes()
833 qc->cursg_ofs += count; in __atapi_pio_bytes()
835 if (qc->cursg_ofs == sg->length) { in __atapi_pio_bytes()
836 qc->cursg = sg_next(qc->cursg); in __atapi_pio_bytes()
837 qc->cursg_ofs = 0; in __atapi_pio_bytes()
841 * There used to be a WARN_ON_ONCE(qc->cursg && count != consumed); in __atapi_pio_bytes()
844 * made. Somebody should implement a proper sanity check. in __atapi_pio_bytes()
852 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
862 struct ata_port *ap = qc->ap; in atapi_pio_bytes()
863 struct ata_device *dev = qc->dev; in atapi_pio_bytes()
864 struct ata_eh_info *ehi = &dev->link->eh_info; in atapi_pio_bytes()
866 int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; in atapi_pio_bytes()
868 /* Abuse qc->result_tf for temp storage of intermediate TF in atapi_pio_bytes()
870 * For normal completion, qc->result_tf is not relevant. For in atapi_pio_bytes()
871 * error, qc->result_tf is later overwritten by ata_qc_complete(). in atapi_pio_bytes()
872 * So, the correctness of qc->result_tf is not affected. in atapi_pio_bytes()
874 ap->ops->sff_tf_read(ap, &qc->result_tf); in atapi_pio_bytes()
875 ireason = qc->result_tf.nsect; in atapi_pio_bytes()
876 bc_lo = qc->result_tf.lbam; in atapi_pio_bytes()
877 bc_hi = qc->result_tf.lbah; in atapi_pio_bytes()
892 VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes); in atapi_pio_bytes()
904 qc->err_mask |= AC_ERR_HSM; in atapi_pio_bytes()
905 ap->hsm_task_state = HSM_ST_ERR; in atapi_pio_bytes()
909 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
919 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_hsm_ok_in_wq()
922 if (ap->hsm_task_state == HSM_ST_FIRST) { in ata_hsm_ok_in_wq()
923 if (qc->tf.protocol == ATA_PROT_PIO && in ata_hsm_ok_in_wq()
924 (qc->tf.flags & ATA_TFLAG_WRITE)) in ata_hsm_ok_in_wq()
927 if (ata_is_atapi(qc->tf.protocol) && in ata_hsm_ok_in_wq()
928 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_hsm_ok_in_wq()
936 * ata_hsm_qc_complete - finish a qc running on standard HSM
948 struct ata_port *ap = qc->ap; in ata_hsm_qc_complete()
950 if (ap->ops->error_handler) { in ata_hsm_qc_complete()
955 qc = ata_qc_from_tag(ap, qc->tag); in ata_hsm_qc_complete()
957 if (likely(!(qc->err_mask & AC_ERR_HSM))) { in ata_hsm_qc_complete()
964 if (likely(!(qc->err_mask & AC_ERR_HSM))) in ata_hsm_qc_complete()
979 * ata_sff_hsm_move - move the HSM to the next state.
991 struct ata_link *link = qc->dev->link; in ata_sff_hsm_move()
992 struct ata_eh_info *ehi = &link->eh_info; in ata_sff_hsm_move()
995 lockdep_assert_held(ap->lock); in ata_sff_hsm_move()
997 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); in ata_sff_hsm_move()
1001 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). in ata_sff_hsm_move()
1007 ap->print_id, qc->tf.protocol, ap->hsm_task_state, status); in ata_sff_hsm_move()
1009 switch (ap->hsm_task_state) { in ata_sff_hsm_move()
1017 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); in ata_sff_hsm_move()
1024 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1029 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1032 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1048 if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) { in ata_sff_hsm_move()
1052 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1053 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1058 if (qc->tf.protocol == ATA_PROT_PIO) { in ata_sff_hsm_move()
1067 ap->hsm_task_state = HSM_ST; in ata_sff_hsm_move()
1080 if (qc->tf.protocol == ATAPI_PROT_PIO) { in ata_sff_hsm_move()
1086 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_hsm_move()
1097 ata_ehi_push_desc(ehi, "ST-ATAPI: " in ata_sff_hsm_move()
1100 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1101 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1107 if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) in ata_sff_hsm_move()
1117 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1120 * IDENTIFY, it's likely a phantom in ata_sff_hsm_move()
1123 if (qc->dev->horkage & in ata_sff_hsm_move()
1125 qc->err_mask |= in ata_sff_hsm_move()
1132 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1135 qc->err_mask |= AC_ERR_HSM | in ata_sff_hsm_move()
1139 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1155 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1157 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { in ata_sff_hsm_move()
1163 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1166 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1177 qc->err_mask |= AC_ERR_NODEV_HINT; in ata_sff_hsm_move()
1183 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1189 if (ap->hsm_task_state == HSM_ST_LAST && in ata_sff_hsm_move()
1190 (!(qc->tf.flags & ATA_TFLAG_WRITE))) { in ata_sff_hsm_move()
1202 qc->err_mask |= __ac_err_mask(status); in ata_sff_hsm_move()
1203 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1209 ap->print_id, qc->dev->devno, status); in ata_sff_hsm_move()
1211 WARN_ON_ONCE(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)); in ata_sff_hsm_move()
1213 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1222 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1232 ap->print_id, ap->hsm_task_state); in ata_sff_hsm_move()
1253 struct ata_port *ap = link->ap; in ata_sff_queue_pio_task()
1255 WARN_ON((ap->sff_pio_task_link != NULL) && in ata_sff_queue_pio_task()
1256 (ap->sff_pio_task_link != link)); in ata_sff_queue_pio_task()
1257 ap->sff_pio_task_link = link; in ata_sff_queue_pio_task()
1260 ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay)); in ata_sff_queue_pio_task()
1268 cancel_delayed_work_sync(&ap->sff_pio_task); in ata_sff_flush_pio_task()
1278 spin_lock_irq(ap->lock); in ata_sff_flush_pio_task()
1279 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_flush_pio_task()
1280 spin_unlock_irq(ap->lock); in ata_sff_flush_pio_task()
1282 ap->sff_pio_task_link = NULL; in ata_sff_flush_pio_task()
1292 struct ata_link *link = ap->sff_pio_task_link; in ata_sff_pio_task()
1297 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1299 BUG_ON(ap->sff_pio_task_link == NULL); in ata_sff_pio_task()
1301 qc = ata_qc_from_tag(ap, link->active_tag); in ata_sff_pio_task()
1303 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1308 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); in ata_sff_pio_task()
1311 * This is purely heuristic. This is a fast path. in ata_sff_pio_task()
1313 * a chk-status or two. If not, the drive is probably seeking in ata_sff_pio_task()
1314 * or something. Snooze for a couple msecs, then in ata_sff_pio_task()
1315 * chk-status again. If still busy, queue delayed work. in ata_sff_pio_task()
1319 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1321 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1334 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1344 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1348 * ata_sff_qc_issue - issue taskfile to a SFF controller
1351 * This function issues a PIO or NODATA command to a SFF
1362 struct ata_port *ap = qc->ap; in ata_sff_qc_issue()
1363 struct ata_link *link = qc->dev->link; in ata_sff_qc_issue()
1368 if (ap->flags & ATA_FLAG_PIO_POLLING) in ata_sff_qc_issue()
1369 qc->tf.flags |= ATA_TFLAG_POLLING; in ata_sff_qc_issue()
1372 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_sff_qc_issue()
1375 switch (qc->tf.protocol) { in ata_sff_qc_issue()
1377 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1380 ata_tf_to_host(ap, &qc->tf); in ata_sff_qc_issue()
1381 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_qc_issue()
1383 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1389 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1392 ata_tf_to_host(ap, &qc->tf); in ata_sff_qc_issue()
1394 if (qc->tf.flags & ATA_TFLAG_WRITE) { in ata_sff_qc_issue()
1396 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1404 ap->hsm_task_state = HSM_ST; in ata_sff_qc_issue()
1406 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1419 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1422 ata_tf_to_host(ap, &qc->tf); in ata_sff_qc_issue()
1424 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1427 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || in ata_sff_qc_issue()
1428 (qc->tf.flags & ATA_TFLAG_POLLING)) in ata_sff_qc_issue()
1441 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
1442 * @qc: qc to fill result TF for
1444 * @qc is finished and result TF needs to be filled. Fill it
1445 * using ->sff_tf_read.
1451 * true indicating that result TF is successfully filled.
1455 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); in ata_sff_qc_fill_rtf()
1462 ap->stats.idle_irq++; in ata_sff_idle_irq()
1465 if ((ap->stats.idle_irq % 1000) == 0) { in ata_sff_idle_irq()
1466 ap->ops->sff_check_status(ap); in ata_sff_idle_irq()
1467 if (ap->ops->sff_irq_clear) in ata_sff_idle_irq()
1468 ap->ops->sff_irq_clear(ap); in ata_sff_idle_irq()
1483 ap->print_id, qc->tf.protocol, ap->hsm_task_state); in __ata_sff_port_intr()
1486 switch (ap->hsm_task_state) { in __ata_sff_port_intr()
1488 /* Some pre-ATAPI-4 devices assert INTRQ in __ata_sff_port_intr()
1494 * need to check ata_is_atapi(qc->tf.protocol) again. in __ata_sff_port_intr()
1496 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in __ata_sff_port_intr()
1510 qc->err_mask |= AC_ERR_HSM; in __ata_sff_port_intr()
1511 ap->hsm_task_state = HSM_ST_ERR; in __ata_sff_port_intr()
1517 if (ap->ops->sff_irq_clear) in __ata_sff_port_intr()
1518 ap->ops->sff_irq_clear(ap); in __ata_sff_port_intr()
1526 * ata_sff_port_intr - Handle SFF port interrupt
1554 spin_lock_irqsave(&host->lock, flags); in __ata_sff_interrupt()
1558 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1559 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1562 qc = ata_qc_from_tag(ap, ap->link.active_tag); in __ata_sff_interrupt()
1564 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) in __ata_sff_interrupt()
1580 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1581 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1586 if (!ap->ops->sff_irq_check || in __ata_sff_interrupt()
1587 !ap->ops->sff_irq_check(ap)) in __ata_sff_interrupt()
1591 ap->ops->sff_check_status(ap); in __ata_sff_interrupt()
1592 if (ap->ops->sff_irq_clear) in __ata_sff_interrupt()
1593 ap->ops->sff_irq_clear(ap); in __ata_sff_interrupt()
1596 if (!(ap->ops->sff_check_status(ap) & ATA_BUSY)) in __ata_sff_interrupt()
1611 spin_unlock_irqrestore(&host->lock, flags); in __ata_sff_interrupt()
1617 * ata_sff_interrupt - Default SFF ATA host interrupt handler
1637 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1655 qc = ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_lost_interrupt()
1656 /* We cannot lose an interrupt on a non-existent or polled command */ in ata_sff_lost_interrupt()
1657 if (!qc || qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_lost_interrupt()
1659 /* See if the controller thinks it is still busy - if so the command in ata_sff_lost_interrupt()
1660 isn't a lost IRQ but is still in progress */ in ata_sff_lost_interrupt()
1665 /* There was a command running, we are no longer busy and we have in ata_sff_lost_interrupt()
1676 * ata_sff_freeze - Freeze SFF controller port
1686 ap->ctl |= ATA_NIEN; in ata_sff_freeze()
1687 ap->last_ctl = ap->ctl; in ata_sff_freeze()
1689 if (ap->ops->sff_set_devctl || ap->ioaddr.ctl_addr) in ata_sff_freeze()
1690 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_freeze()
1696 ap->ops->sff_check_status(ap); in ata_sff_freeze()
1698 if (ap->ops->sff_irq_clear) in ata_sff_freeze()
1699 ap->ops->sff_irq_clear(ap); in ata_sff_freeze()
1704 * ata_sff_thaw - Thaw SFF controller port
1714 /* clear & re-enable interrupts */ in ata_sff_thaw()
1715 ap->ops->sff_check_status(ap); in ata_sff_thaw()
1716 if (ap->ops->sff_irq_clear) in ata_sff_thaw()
1717 ap->ops->sff_irq_clear(ap); in ata_sff_thaw()
1723 * ata_sff_prereset - prepare SFF link for reset
1735 * 0 on success, -errno otherwise.
1739 struct ata_eh_context *ehc = &link->eh_context; in ata_sff_prereset()
1747 if (ehc->i.action & ATA_EH_HARDRESET) in ata_sff_prereset()
1753 if (rc && rc != -ENODEV) { in ata_sff_prereset()
1757 ehc->i.action |= ATA_EH_HARDRESET; in ata_sff_prereset()
1766 * ata_devchk - PATA device presence detection
1771 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1774 * Write a pattern to the ATA shadow registers,
1775 * and if a device is present, it will respond by
1784 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_devchk()
1787 ap->ops->sff_dev_select(ap, device); in ata_devchk()
1789 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1790 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1792 iowrite8(0xaa, ioaddr->nsect_addr); in ata_devchk()
1793 iowrite8(0x55, ioaddr->lbal_addr); in ata_devchk()
1795 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1796 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1798 nsect = ioread8(ioaddr->nsect_addr); in ata_devchk()
1799 lbal = ioread8(ioaddr->lbal_addr); in ata_devchk()
1802 return 1; /* we found a device */ in ata_devchk()
1808 * ata_sff_dev_classify - Parse returned ATA device signature
1813 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1814 * an ATA/ATAPI-defined set of values is placed in the ATA
1820 * and the spec-defined values examined by ata_dev_classify().
1826 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1831 struct ata_port *ap = dev->link->ap; in ata_sff_dev_classify()
1832 struct ata_taskfile tf; in ata_sff_dev_classify() local
1836 ap->ops->sff_dev_select(ap, dev->devno); in ata_sff_dev_classify()
1838 memset(&tf, 0, sizeof(tf)); in ata_sff_dev_classify()
1840 ap->ops->sff_tf_read(ap, &tf); in ata_sff_dev_classify()
1841 err = tf.feature; in ata_sff_dev_classify()
1848 dev->horkage |= ATA_HORKAGE_DIAGNOSTIC; in ata_sff_dev_classify()
1851 else if ((dev->devno == 0) && (err == 0x81)) in ata_sff_dev_classify()
1857 class = ata_dev_classify(&tf); in ata_sff_dev_classify()
1866 if (present && (dev->horkage & ATA_HORKAGE_DIAGNOSTIC)) in ata_sff_dev_classify()
1871 (ap->ops->sff_check_status(ap) == 0)) in ata_sff_dev_classify()
1879 * ata_sff_wait_after_reset - wait for devices to become ready after reset
1885 * reset. It contains preceding 150ms wait to avoid accessing TF
1892 * 0 on success, -ENODEV if some or all of devices in @devmask
1893 * don't seem to exist. -errno on other errors.
1898 struct ata_port *ap = link->ap; in ata_sff_wait_after_reset()
1899 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_wait_after_reset()
1908 /* -ENODEV means the odd clown forgot the D7 pulldown resistor in ata_sff_wait_after_reset()
1909 * and TF status is 0xff, bail out on it too. in ata_sff_wait_after_reset()
1920 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1929 nsect = ioread8(ioaddr->nsect_addr); in ata_sff_wait_after_reset()
1930 lbal = ioread8(ioaddr->lbal_addr); in ata_sff_wait_after_reset()
1933 ata_msleep(ap, 50); /* give drive a breather */ in ata_sff_wait_after_reset()
1938 if (rc != -ENODEV) in ata_sff_wait_after_reset()
1945 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1947 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1949 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1958 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_bus_softreset()
1960 DPRINTK("ata%u: bus reset via SRST\n", ap->print_id); in ata_bus_softreset()
1962 if (ap->ioaddr.ctl_addr) { in ata_bus_softreset()
1964 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1966 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in ata_bus_softreset()
1968 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1969 ap->last_ctl = ap->ctl; in ata_bus_softreset()
1973 return ata_sff_wait_after_reset(&ap->link, devmask, deadline); in ata_bus_softreset()
1977 * ata_sff_softreset - reset host port via ATA SRST
1988 * 0 on success, -errno otherwise.
1993 struct ata_port *ap = link->ap; in ata_sff_softreset()
1994 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ata_sff_softreset()
2008 ap->ops->sff_dev_select(ap, 0); in ata_sff_softreset()
2013 /* if link is occupied, -ENODEV too is an error */ in ata_sff_softreset()
2014 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in ata_sff_softreset()
2020 classes[0] = ata_sff_dev_classify(&link->device[0], in ata_sff_softreset()
2023 classes[1] = ata_sff_dev_classify(&link->device[1], in ata_sff_softreset()
2032 * sata_sff_hardreset - reset host port via SATA phy reset
2037 * SATA phy-reset host port using DET bits of SControl register,
2044 * 0 on success, -errno otherwise.
2049 struct ata_eh_context *ehc = &link->eh_context; in sata_sff_hardreset()
2057 *class = ata_sff_dev_classify(link->device, 1, NULL); in sata_sff_hardreset()
2065 * ata_sff_postreset - SFF postreset callback
2069 * This function is invoked after a successful reset. It first
2078 struct ata_port *ap = link->ap; in ata_sff_postreset()
2082 /* is double-select really necessary? */ in ata_sff_postreset()
2084 ap->ops->sff_dev_select(ap, 1); in ata_sff_postreset()
2086 ap->ops->sff_dev_select(ap, 0); in ata_sff_postreset()
2095 if (ap->ops->sff_set_devctl || ap->ioaddr.ctl_addr) { in ata_sff_postreset()
2096 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_postreset()
2097 ap->last_ctl = ap->ctl; in ata_sff_postreset()
2103 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2106 * Drain the FIFO and device of any stuck data following a command
2107 * failing to complete. In some cases this is necessary before a
2117 /* We only need to flush incoming data when a command was running */ in ata_sff_drain_fifo()
2118 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ata_sff_drain_fifo()
2121 ap = qc->ap; in ata_sff_drain_fifo()
2123 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ata_sff_drain_fifo()
2125 ioread16(ap->ioaddr.data_addr); in ata_sff_drain_fifo()
2135 * ata_sff_error_handler - Stock error handler for SFF controller
2140 * use this EH as-is or with some added handling before and
2148 ata_reset_fn_t softreset = ap->ops->softreset; in ata_sff_error_handler()
2149 ata_reset_fn_t hardreset = ap->ops->hardreset; in ata_sff_error_handler()
2153 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_error_handler()
2154 if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) in ata_sff_error_handler()
2157 spin_lock_irqsave(ap->lock, flags); in ata_sff_error_handler()
2160 * We *MUST* do FIFO draining before we issue a reset as in ata_sff_error_handler()
2166 if (ap->ops->sff_drain_fifo) in ata_sff_error_handler()
2167 ap->ops->sff_drain_fifo(qc); in ata_sff_error_handler()
2169 spin_unlock_irqrestore(ap->lock, flags); in ata_sff_error_handler()
2171 /* ignore built-in hardresets if SCR access is not available */ in ata_sff_error_handler()
2173 hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link)) in ata_sff_error_handler()
2176 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, in ata_sff_error_handler()
2177 ap->ops->postreset); in ata_sff_error_handler()
2182 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
2194 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; in ata_sff_std_ports()
2195 ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; in ata_sff_std_ports()
2196 ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; in ata_sff_std_ports()
2197 ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; in ata_sff_std_ports()
2198 ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; in ata_sff_std_ports()
2199 ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; in ata_sff_std_ports()
2200 ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; in ata_sff_std_ports()
2201 ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; in ata_sff_std_ports()
2202 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; in ata_sff_std_ports()
2203 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; in ata_sff_std_ports()
2224 * ata_pci_sff_init_host - acquire native PCI ATA resources and init host
2239 * 0 if at least one port is initialized, -ENODEV if no port is
2244 struct device *gdev = host->dev; in ata_pci_sff_init_host()
2251 struct ata_port *ap = host->ports[i]; in ata_pci_sff_init_host()
2263 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2273 if (rc == -EBUSY) in ata_pci_sff_init_host()
2275 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2278 host->iomap = iomap = pcim_iomap_table(pdev); in ata_pci_sff_init_host()
2280 ap->ioaddr.cmd_addr = iomap[base]; in ata_pci_sff_init_host()
2281 ap->ioaddr.altstatus_addr = in ata_pci_sff_init_host()
2282 ap->ioaddr.ctl_addr = (void __iomem *) in ata_pci_sff_init_host()
2284 ata_sff_std_ports(&ap->ioaddr); in ata_pci_sff_init_host()
2295 return -ENODEV; in ata_pci_sff_init_host()
2303 * ata_pci_sff_prepare_host - helper to prepare PCI PIO-only SFF ATA host
2308 * Helper to allocate PIO-only SFF ATA host for @pdev, acquire
2315 * 0 on success, -errno otherwise.
2324 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) in ata_pci_sff_prepare_host()
2325 return -ENOMEM; in ata_pci_sff_prepare_host()
2327 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); in ata_pci_sff_prepare_host()
2329 dev_err(&pdev->dev, "failed to allocate ATA host\n"); in ata_pci_sff_prepare_host()
2330 rc = -ENOMEM; in ata_pci_sff_prepare_host()
2338 devres_remove_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2343 devres_release_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2349 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
2362 * 0 on success, -errno otherwise.
2368 struct device *dev = host->dev; in ata_pci_sff_activate_host()
2370 const char *drv_name = dev_driver_string(host->dev); in ata_pci_sff_activate_host()
2377 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { in ata_pci_sff_activate_host()
2389 if (!ata_port_is_dummy(host->ports[0])) in ata_pci_sff_activate_host()
2391 if (!ata_port_is_dummy(host->ports[1])) in ata_pci_sff_activate_host()
2398 return -ENOMEM; in ata_pci_sff_activate_host()
2400 if (!legacy_mode && pdev->irq) { in ata_pci_sff_activate_host()
2403 rc = devm_request_irq(dev, pdev->irq, irq_handler, in ata_pci_sff_activate_host()
2409 if (ata_port_is_dummy(host->ports[i])) in ata_pci_sff_activate_host()
2411 ata_port_desc(host->ports[i], "irq %d", pdev->irq); in ata_pci_sff_activate_host()
2414 if (!ata_port_is_dummy(host->ports[0])) { in ata_pci_sff_activate_host()
2421 ata_port_desc(host->ports[0], "irq %d", in ata_pci_sff_activate_host()
2425 if (!ata_port_is_dummy(host->ports[1])) { in ata_pci_sff_activate_host()
2432 ata_port_desc(host->ports[1], "irq %d", in ata_pci_sff_activate_host()
2455 if (ppi[i]->port_ops != &ata_dummy_port_ops) in ata_sff_find_valid_pi()
2466 struct device *dev = &pdev->dev; in ata_pci_init_one()
2475 dev_err(&pdev->dev, "no valid port_info specified\n"); in ata_pci_init_one()
2476 return -EINVAL; in ata_pci_init_one()
2480 return -ENOMEM; in ata_pci_init_one()
2496 host->private_data = host_priv; in ata_pci_init_one()
2497 host->flags |= hflags; in ata_pci_init_one()
2508 devres_remove_group(&pdev->dev, NULL); in ata_pci_init_one()
2510 devres_release_group(&pdev->dev, NULL); in ata_pci_init_one()
2516 * ata_pci_sff_init_one - Initialize/register PIO-only PCI IDE controller
2523 * This is a helper function which can be called from a driver's
2528 * Nobody makes a single channel controller that appears solely as
2535 * Zero on success, negative on errno-based value on error.
2581 * ata_bmdma_fill_sg - Fill PCI IDE PRD table
2584 * Fill PCI IDE PRD (scatter-gather) table with segments
2593 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg()
2594 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg()
2599 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg()
2604 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg()
2614 len = 0x10000 - offset; in ata_bmdma_fill_sg()
2621 sg_len -= len; in ata_bmdma_fill_sg()
2626 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg()
2630 * ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
2633 * Fill PCI IDE PRD (scatter-gather) table with segments
2644 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg_dumb()
2645 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg_dumb()
2650 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg_dumb()
2655 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg_dumb()
2665 len = 0x10000 - offset; in ata_bmdma_fill_sg_dumb()
2681 sg_len -= len; in ata_bmdma_fill_sg_dumb()
2686 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg_dumb()
2690 * ata_bmdma_qc_prep - Prepare taskfile for submission
2700 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_qc_prep()
2710 * ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
2720 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_dumb_qc_prep()
2730 * ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
2733 * This function issues a PIO, NODATA or DMA command to a
2745 struct ata_port *ap = qc->ap; in ata_bmdma_qc_issue()
2746 struct ata_link *link = qc->dev->link; in ata_bmdma_qc_issue()
2749 if (!ata_is_dma(qc->tf.protocol)) in ata_bmdma_qc_issue()
2753 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_bmdma_qc_issue()
2756 switch (qc->tf.protocol) { in ata_bmdma_qc_issue()
2758 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2760 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2761 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2762 ap->ops->bmdma_start(qc); /* initiate bmdma */ in ata_bmdma_qc_issue()
2763 ap->hsm_task_state = HSM_ST_LAST; in ata_bmdma_qc_issue()
2767 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2769 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2770 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2771 ap->hsm_task_state = HSM_ST_FIRST; in ata_bmdma_qc_issue()
2774 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_bmdma_qc_issue()
2788 * ata_bmdma_port_intr - Handle BMDMA port interrupt
2802 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_bmdma_port_intr()
2807 if (ap->hsm_task_state == HSM_ST_LAST && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_port_intr()
2809 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_port_intr()
2810 VPRINTK("ata%u: host_stat 0x%X\n", ap->print_id, host_stat); in ata_bmdma_port_intr()
2816 /* before we do anything else, clear DMA-Start bit */ in ata_bmdma_port_intr()
2817 ap->ops->bmdma_stop(qc); in ata_bmdma_port_intr()
2822 qc->err_mask |= AC_ERR_HOST_BUS; in ata_bmdma_port_intr()
2823 ap->hsm_task_state = HSM_ST_ERR; in ata_bmdma_port_intr()
2829 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) in ata_bmdma_port_intr()
2837 * ata_bmdma_interrupt - Default BMDMA ATA host interrupt handler
2857 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
2862 * able to use this EH as-is or with some added handling before
2874 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_bmdma_error_handler()
2875 if (qc && !(qc->flags & ATA_QCFLAG_FAILED)) in ata_bmdma_error_handler()
2879 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_error_handler()
2881 if (qc && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_error_handler()
2884 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_error_handler()
2888 * really a timeout event, adjust error mask and in ata_bmdma_error_handler()
2891 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { in ata_bmdma_error_handler()
2892 qc->err_mask = AC_ERR_HOST_BUS; in ata_bmdma_error_handler()
2896 ap->ops->bmdma_stop(qc); in ata_bmdma_error_handler()
2900 ap->ops->sff_check_status(ap); in ata_bmdma_error_handler()
2901 if (ap->ops->sff_irq_clear) in ata_bmdma_error_handler()
2902 ap->ops->sff_irq_clear(ap); in ata_bmdma_error_handler()
2906 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_error_handler()
2916 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
2924 struct ata_port *ap = qc->ap; in ata_bmdma_post_internal_cmd()
2927 if (ata_is_dma(qc->tf.protocol)) { in ata_bmdma_post_internal_cmd()
2928 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2929 ap->ops->bmdma_stop(qc); in ata_bmdma_post_internal_cmd()
2930 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2936 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
2948 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_irq_clear()
2958 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
2966 struct ata_port *ap = qc->ap; in ata_bmdma_setup()
2967 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_bmdma_setup()
2972 iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); in ata_bmdma_setup()
2974 /* specify data direction, triple-check start bit is clear */ in ata_bmdma_setup()
2975 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2979 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2982 ap->ops->sff_exec_command(ap, &qc->tf); in ata_bmdma_setup()
2987 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
2995 struct ata_port *ap = qc->ap; in ata_bmdma_start()
2999 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
3000 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
3007 * Further, a read of the DMA status register _immediately_ in ata_bmdma_start()
3009 * is expected, so I think it is best to not add a readb() in ata_bmdma_start()
3020 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
3032 struct ata_port *ap = qc->ap; in ata_bmdma_stop()
3033 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_stop()
3039 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in ata_bmdma_stop()
3045 * ata_bmdma_status - Read PCI IDE BMDMA status
3057 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); in ata_bmdma_status()
3063 * ata_bmdma_port_start - Set port up for bmdma.
3076 if (ap->mwdma_mask || ap->udma_mask) { in ata_bmdma_port_start()
3077 ap->bmdma_prd = in ata_bmdma_port_start()
3078 dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ, in ata_bmdma_port_start()
3079 &ap->bmdma_prd_dma, GFP_KERNEL); in ata_bmdma_port_start()
3080 if (!ap->bmdma_prd) in ata_bmdma_port_start()
3081 return -ENOMEM; in ata_bmdma_port_start()
3089 * ata_bmdma_port_start32 - Set port up for dma.
3104 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; in ata_bmdma_port_start32()
3112 * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex
3118 * have -undefined- behaviour.
3126 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3132 return -EOPNOTSUPP; in ata_pci_bmdma_clear_simplex()
3141 dev_err(host->dev, "BMDMA: %s, falling back to PIO\n", reason); in ata_bmdma_nodma()
3144 host->ports[i]->mwdma_mask = 0; in ata_bmdma_nodma()
3145 host->ports[i]->udma_mask = 0; in ata_bmdma_nodma()
3150 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
3160 struct device *gdev = host->dev; in ata_pci_bmdma_init()
3173 * ->sff_irq_clear method. Try to initialize bmdma_addr in ata_pci_bmdma_init()
3176 rc = dma_set_mask(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3180 rc = dma_set_coherent_mask(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3192 host->iomap = pcim_iomap_table(pdev); in ata_pci_bmdma_init()
3195 struct ata_port *ap = host->ports[i]; in ata_pci_bmdma_init()
3196 void __iomem *bmdma = host->iomap[4] + 8 * i; in ata_pci_bmdma_init()
3201 ap->ioaddr.bmdma_addr = bmdma; in ata_pci_bmdma_init()
3202 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && in ata_pci_bmdma_init()
3204 host->flags |= ATA_HOST_SIMPLEX; in ata_pci_bmdma_init()
3213 * ata_pci_bmdma_prepare_host - helper to prepare PCI BMDMA ATA host
3225 * 0 on success, -errno otherwise.
3243 * ata_pci_bmdma_init_one - Initialize/register BMDMA PCI IDE controller
3257 * Zero on success, negative on errno-based value on error.
3272 * ata_sff_port_init - Initialize SFF/BMDMA ATA port
3283 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task); in ata_sff_port_init()
3284 ap->ctl = ATA_DEVCTL_OBS; in ata_sff_port_init()
3285 ap->last_ctl = 0xFF; in ata_sff_port_init()
3292 return -ENOMEM; in ata_sff_init()