Lines Matching +full:tf +full:- +full:a
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-sff.c - helper library for PCI IDE BMDMA
5 * Copyright 2003-2006 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2006 Jeff Garzik
9 * as Documentation/driver-api/libata.rst
12 * http://www.sata-io.org/
53 * ata_sff_check_status - Read device status reg & clear interrupt
56 * Reads ATA taskfile status register for currently-selected device
65 return ioread8(ap->ioaddr.status_addr); in ata_sff_check_status()
70 * ata_sff_altstatus - Read device alternate status reg
72 * @status: pointer to a status value
74 * Reads ATA alternate status register for currently-selected device
87 if (ap->ops->sff_check_altstatus) { in ata_sff_altstatus()
88 tmp = ap->ops->sff_check_altstatus(ap); in ata_sff_altstatus()
91 if (ap->ioaddr.altstatus_addr) { in ata_sff_altstatus()
92 tmp = ioread8(ap->ioaddr.altstatus_addr); in ata_sff_altstatus()
104 * ata_sff_irq_status - Check if the device is busy
123 status = ap->ops->sff_check_status(ap); in ata_sff_irq_status()
128 * ata_sff_sync - Flush writes
145 * ata_sff_pause - Flush writes and wait 400nS
164 * ata_sff_dma_pause - Pause before commencing DMA
188 u8 status = link->ap->ops->sff_check_status(link->ap); in ata_sff_check_ready()
194 * ata_sff_wait_ready - sleep until BSY clears, or timeout
205 * 0 on success, -errno otherwise.
214 * ata_sff_set_devctl - Write device control reg
228 if (ap->ops->sff_set_devctl) { in ata_sff_set_devctl()
229 ap->ops->sff_set_devctl(ap, ctl); in ata_sff_set_devctl()
232 if (ap->ioaddr.ctl_addr) { in ata_sff_set_devctl()
233 iowrite8(ctl, ap->ioaddr.ctl_addr); in ata_sff_set_devctl()
241 * ata_sff_dev_select - Select device 0/1 on ATA bus
263 iowrite8(tmp, ap->ioaddr.device_addr); in ata_sff_dev_select()
269 * ata_dev_select - Select device 0/1 on ATA bus
272 * @wait: non-zero to wait for Status register BSY bit to clear
273 * @can_sleep: non-zero if context allows sleeping
279 * This is a high-level version of ata_sff_dev_select(), which
292 ap->ops->sff_dev_select(ap, device); in ata_dev_select()
295 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) in ata_dev_select()
302 * ata_sff_irq_on - Enable interrupts on a port.
305 * Enable interrupts on a legacy IDE device using MMIO or PIO,
316 if (ap->ops->sff_irq_on) { in ata_sff_irq_on()
317 ap->ops->sff_irq_on(ap); in ata_sff_irq_on()
321 ap->ctl &= ~ATA_NIEN; in ata_sff_irq_on()
322 ap->last_ctl = ap->ctl; in ata_sff_irq_on()
324 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_irq_on()
327 if (ap->ops->sff_irq_clear) in ata_sff_irq_on()
328 ap->ops->sff_irq_clear(ap); in ata_sff_irq_on()
333 * ata_sff_tf_load - send taskfile registers to host controller
335 * @tf: ATA taskfile register set
342 void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_tf_load() argument
344 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_load()
345 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ata_sff_tf_load()
347 if (tf->ctl != ap->last_ctl) { in ata_sff_tf_load()
348 if (ioaddr->ctl_addr) in ata_sff_tf_load()
349 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_load()
350 ap->last_ctl = tf->ctl; in ata_sff_tf_load()
354 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ata_sff_tf_load()
355 WARN_ON_ONCE(!ioaddr->ctl_addr); in ata_sff_tf_load()
356 iowrite8(tf->hob_feature, ioaddr->feature_addr); in ata_sff_tf_load()
357 iowrite8(tf->hob_nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
358 iowrite8(tf->hob_lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
359 iowrite8(tf->hob_lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
360 iowrite8(tf->hob_lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
364 iowrite8(tf->feature, ioaddr->feature_addr); in ata_sff_tf_load()
365 iowrite8(tf->nsect, ioaddr->nsect_addr); in ata_sff_tf_load()
366 iowrite8(tf->lbal, ioaddr->lbal_addr); in ata_sff_tf_load()
367 iowrite8(tf->lbam, ioaddr->lbam_addr); in ata_sff_tf_load()
368 iowrite8(tf->lbah, ioaddr->lbah_addr); in ata_sff_tf_load()
371 if (tf->flags & ATA_TFLAG_DEVICE) in ata_sff_tf_load()
372 iowrite8(tf->device, ioaddr->device_addr); in ata_sff_tf_load()
379 * ata_sff_tf_read - input device's ATA taskfile shadow registers
381 * @tf: ATA taskfile register set for storing input
383 * Reads ATA taskfile registers for currently-selected device
384 * into @tf. Assumes the device has a fully SFF compliant task file
385 * layout and behaviour. If you device does not (eg has a different
386 * status method) then you will need to provide a replacement tf_read
391 void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf) in ata_sff_tf_read() argument
393 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_tf_read()
395 tf->status = ata_sff_check_status(ap); in ata_sff_tf_read()
396 tf->error = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
397 tf->nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
398 tf->lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
399 tf->lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
400 tf->lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
401 tf->device = ioread8(ioaddr->device_addr); in ata_sff_tf_read()
403 if (tf->flags & ATA_TFLAG_LBA48) { in ata_sff_tf_read()
404 if (likely(ioaddr->ctl_addr)) { in ata_sff_tf_read()
405 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr); in ata_sff_tf_read()
406 tf->hob_feature = ioread8(ioaddr->error_addr); in ata_sff_tf_read()
407 tf->hob_nsect = ioread8(ioaddr->nsect_addr); in ata_sff_tf_read()
408 tf->hob_lbal = ioread8(ioaddr->lbal_addr); in ata_sff_tf_read()
409 tf->hob_lbam = ioread8(ioaddr->lbam_addr); in ata_sff_tf_read()
410 tf->hob_lbah = ioread8(ioaddr->lbah_addr); in ata_sff_tf_read()
411 iowrite8(tf->ctl, ioaddr->ctl_addr); in ata_sff_tf_read()
412 ap->last_ctl = tf->ctl; in ata_sff_tf_read()
420 * ata_sff_exec_command - issue ATA command to host controller
422 * @tf: ATA taskfile register set
430 void ata_sff_exec_command(struct ata_port *ap, const struct ata_taskfile *tf) in ata_sff_exec_command() argument
432 iowrite8(tf->command, ap->ioaddr.command_addr); in ata_sff_exec_command()
438 * ata_tf_to_host - issue ATA taskfile to host controller
440 * @tf: ATA taskfile register set
451 const struct ata_taskfile *tf, in ata_tf_to_host() argument
454 trace_ata_tf_load(ap, tf); in ata_tf_to_host()
455 ap->ops->sff_tf_load(ap, tf); in ata_tf_to_host()
456 trace_ata_exec_command(ap, tf, tag); in ata_tf_to_host()
457 ap->ops->sff_exec_command(ap, tf); in ata_tf_to_host()
461 * ata_sff_data_xfer - Transfer data by PIO
478 struct ata_port *ap = qc->dev->link->ap; in ata_sff_data_xfer()
479 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer()
493 buf += buflen - 1; in ata_sff_data_xfer()
514 * ata_sff_data_xfer32 - Transfer data by PIO
533 struct ata_device *dev = qc->dev; in ata_sff_data_xfer32()
534 struct ata_port *ap = dev->link->ap; in ata_sff_data_xfer32()
535 void __iomem *data_addr = ap->ioaddr.data_addr; in ata_sff_data_xfer32()
539 if (!(ap->pflags & ATA_PFLAG_PIO32)) in ata_sff_data_xfer32()
553 buf += buflen - slop; in ata_sff_data_xfer32()
580 bool do_write = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_pio_xfer()
584 qc->ap->ops->sff_data_xfer(qc, buf + offset, xfer_size, do_write); in ata_pio_xfer()
592 * ata_pio_sector - Transfer a sector of data.
595 * Transfer qc->sect_size bytes of data from/to the ATA device.
602 struct ata_port *ap = qc->ap; in ata_pio_sector()
606 if (!qc->cursg) { in ata_pio_sector()
607 qc->curbytes = qc->nbytes; in ata_pio_sector()
610 if (qc->curbytes == qc->nbytes - qc->sect_size) in ata_pio_sector()
611 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
613 page = sg_page(qc->cursg); in ata_pio_sector()
614 offset = qc->cursg->offset + qc->cursg_ofs; in ata_pio_sector()
621 count = min(qc->cursg->length - qc->cursg_ofs, qc->sect_size); in ata_pio_sector()
626 * Split the transfer when it splits a page boundary. Note that the in ata_pio_sector()
631 unsigned int split_len = PAGE_SIZE - offset; in ata_pio_sector()
634 ata_pio_xfer(qc, nth_page(page, 1), 0, count - split_len); in ata_pio_sector()
639 qc->curbytes += count; in ata_pio_sector()
640 qc->cursg_ofs += count; in ata_pio_sector()
642 if (qc->cursg_ofs == qc->cursg->length) { in ata_pio_sector()
643 qc->cursg = sg_next(qc->cursg); in ata_pio_sector()
644 if (!qc->cursg) in ata_pio_sector()
645 ap->hsm_task_state = HSM_ST_LAST; in ata_pio_sector()
646 qc->cursg_ofs = 0; in ata_pio_sector()
651 * ata_pio_sectors - Transfer one or many sectors.
662 if (is_multi_taskfile(&qc->tf)) { in ata_pio_sectors()
666 WARN_ON_ONCE(qc->dev->multi_count == 0); in ata_pio_sectors()
668 nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size, in ata_pio_sectors()
669 qc->dev->multi_count); in ata_pio_sectors()
670 while (nsect--) in ata_pio_sectors()
675 ata_sff_sync(qc->ap); /* flush */ in ata_pio_sectors()
679 * atapi_send_cdb - Write CDB bytes to hardware
684 * a CDB, this function is called. Send the CDB.
692 trace_atapi_send_cdb(qc, 0, qc->dev->cdb_len); in atapi_send_cdb()
693 WARN_ON_ONCE(qc->dev->cdb_len < 12); in atapi_send_cdb()
695 ap->ops->sff_data_xfer(qc, qc->cdb, qc->dev->cdb_len, 1); in atapi_send_cdb()
699 switch (qc->tf.protocol) { in atapi_send_cdb()
701 ap->hsm_task_state = HSM_ST; in atapi_send_cdb()
704 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
708 ap->hsm_task_state = HSM_ST_LAST; in atapi_send_cdb()
710 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in atapi_send_cdb()
711 ap->ops->bmdma_start(qc); in atapi_send_cdb()
720 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
732 int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ; in __atapi_pio_bytes()
733 struct ata_port *ap = qc->ap; in __atapi_pio_bytes()
734 struct ata_device *dev = qc->dev; in __atapi_pio_bytes()
735 struct ata_eh_info *ehi = &dev->link->eh_info; in __atapi_pio_bytes()
742 sg = qc->cursg; in __atapi_pio_bytes()
746 qc->nbytes, qc->curbytes, bytes); in __atapi_pio_bytes()
747 return -1; in __atapi_pio_bytes()
751 offset = sg->offset + qc->cursg_ofs; in __atapi_pio_bytes()
758 count = min(sg->length - qc->cursg_ofs, bytes); in __atapi_pio_bytes()
761 count = min(count, (unsigned int)PAGE_SIZE - offset); in __atapi_pio_bytes()
767 consumed = ap->ops->sff_data_xfer(qc, buf + offset, count, rw); in __atapi_pio_bytes()
770 bytes -= min(bytes, consumed); in __atapi_pio_bytes()
771 qc->curbytes += count; in __atapi_pio_bytes()
772 qc->cursg_ofs += count; in __atapi_pio_bytes()
774 if (qc->cursg_ofs == sg->length) { in __atapi_pio_bytes()
775 qc->cursg = sg_next(qc->cursg); in __atapi_pio_bytes()
776 qc->cursg_ofs = 0; in __atapi_pio_bytes()
780 * There used to be a WARN_ON_ONCE(qc->cursg && count != consumed); in __atapi_pio_bytes()
783 * made. Somebody should implement a proper sanity check. in __atapi_pio_bytes()
791 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
801 struct ata_port *ap = qc->ap; in atapi_pio_bytes()
802 struct ata_device *dev = qc->dev; in atapi_pio_bytes()
803 struct ata_eh_info *ehi = &dev->link->eh_info; in atapi_pio_bytes()
805 int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0; in atapi_pio_bytes()
807 /* Abuse qc->result_tf for temp storage of intermediate TF in atapi_pio_bytes()
809 * For normal completion, qc->result_tf is not relevant. For in atapi_pio_bytes()
810 * error, qc->result_tf is later overwritten by ata_qc_complete(). in atapi_pio_bytes()
811 * So, the correctness of qc->result_tf is not affected. in atapi_pio_bytes()
813 ap->ops->sff_tf_read(ap, &qc->result_tf); in atapi_pio_bytes()
814 ireason = qc->result_tf.nsect; in atapi_pio_bytes()
815 bc_lo = qc->result_tf.lbam; in atapi_pio_bytes()
816 bc_hi = qc->result_tf.lbah; in atapi_pio_bytes()
841 qc->err_mask |= AC_ERR_HSM; in atapi_pio_bytes()
842 ap->hsm_task_state = HSM_ST_ERR; in atapi_pio_bytes()
846 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
856 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_hsm_ok_in_wq()
859 if (ap->hsm_task_state == HSM_ST_FIRST) { in ata_hsm_ok_in_wq()
860 if (qc->tf.protocol == ATA_PROT_PIO && in ata_hsm_ok_in_wq()
861 (qc->tf.flags & ATA_TFLAG_WRITE)) in ata_hsm_ok_in_wq()
864 if (ata_is_atapi(qc->tf.protocol) && in ata_hsm_ok_in_wq()
865 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_hsm_ok_in_wq()
873 * ata_hsm_qc_complete - finish a qc running on standard HSM
885 struct ata_port *ap = qc->ap; in ata_hsm_qc_complete()
889 qc = ata_qc_from_tag(ap, qc->tag); in ata_hsm_qc_complete()
891 if (likely(!(qc->err_mask & AC_ERR_HSM))) { in ata_hsm_qc_complete()
898 if (likely(!(qc->err_mask & AC_ERR_HSM))) in ata_hsm_qc_complete()
906 * ata_sff_hsm_move - move the HSM to the next state.
918 struct ata_link *link = qc->dev->link; in ata_sff_hsm_move()
919 struct ata_eh_info *ehi = &link->eh_info; in ata_sff_hsm_move()
922 lockdep_assert_held(ap->lock); in ata_sff_hsm_move()
924 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); in ata_sff_hsm_move()
928 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING). in ata_sff_hsm_move()
935 switch (ap->hsm_task_state) { in ata_sff_hsm_move()
943 poll_next = (qc->tf.flags & ATA_TFLAG_POLLING); in ata_sff_hsm_move()
950 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
955 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
958 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
974 if (!(qc->dev->quirks & ATA_QUIRK_STUCK_ERR)) { in ata_sff_hsm_move()
978 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
979 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
984 if (qc->tf.protocol == ATA_PROT_PIO) { in ata_sff_hsm_move()
993 ap->hsm_task_state = HSM_ST; in ata_sff_hsm_move()
1006 if (qc->tf.protocol == ATAPI_PROT_PIO) { in ata_sff_hsm_move()
1012 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_hsm_move()
1023 ata_ehi_push_desc(ehi, "ST-ATAPI: " in ata_sff_hsm_move()
1026 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1027 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1033 if (unlikely(ap->hsm_task_state == HSM_ST_ERR)) in ata_sff_hsm_move()
1043 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1046 * IDENTIFY, it's likely a phantom in ata_sff_hsm_move()
1049 if (qc->dev->quirks & in ata_sff_hsm_move()
1051 qc->err_mask |= in ata_sff_hsm_move()
1058 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1061 qc->err_mask |= AC_ERR_HSM | in ata_sff_hsm_move()
1065 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1081 qc->err_mask |= AC_ERR_DEV; in ata_sff_hsm_move()
1083 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) { in ata_sff_hsm_move()
1089 ata_ehi_push_desc(ehi, "ST-ATA: " in ata_sff_hsm_move()
1092 qc->err_mask |= AC_ERR_HSM; in ata_sff_hsm_move()
1103 qc->err_mask |= AC_ERR_NODEV_HINT; in ata_sff_hsm_move()
1109 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1115 if (ap->hsm_task_state == HSM_ST_LAST && in ata_sff_hsm_move()
1116 (!(qc->tf.flags & ATA_TFLAG_WRITE))) { in ata_sff_hsm_move()
1128 qc->err_mask |= __ac_err_mask(status); in ata_sff_hsm_move()
1129 ap->hsm_task_state = HSM_ST_ERR; in ata_sff_hsm_move()
1136 WARN_ON_ONCE(qc->err_mask & (AC_ERR_DEV | AC_ERR_HSM)); in ata_sff_hsm_move()
1138 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1147 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_hsm_move()
1157 ap->print_id, ap->hsm_task_state); in ata_sff_hsm_move()
1178 struct ata_port *ap = link->ap; in ata_sff_queue_pio_task()
1180 WARN_ON((ap->sff_pio_task_link != NULL) && in ata_sff_queue_pio_task()
1181 (ap->sff_pio_task_link != link)); in ata_sff_queue_pio_task()
1182 ap->sff_pio_task_link = link; in ata_sff_queue_pio_task()
1185 ata_sff_queue_delayed_work(&ap->sff_pio_task, msecs_to_jiffies(delay)); in ata_sff_queue_pio_task()
1193 cancel_delayed_work_sync(&ap->sff_pio_task); in ata_sff_flush_pio_task()
1203 spin_lock_irq(ap->lock); in ata_sff_flush_pio_task()
1204 ap->hsm_task_state = HSM_ST_IDLE; in ata_sff_flush_pio_task()
1205 spin_unlock_irq(ap->lock); in ata_sff_flush_pio_task()
1207 ap->sff_pio_task_link = NULL; in ata_sff_flush_pio_task()
1214 struct ata_link *link = ap->sff_pio_task_link; in ata_sff_pio_task()
1219 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1221 BUG_ON(ap->sff_pio_task_link == NULL); in ata_sff_pio_task()
1223 qc = ata_qc_from_tag(ap, link->active_tag); in ata_sff_pio_task()
1225 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1230 WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE); in ata_sff_pio_task()
1233 * This is purely heuristic. This is a fast path. in ata_sff_pio_task()
1235 * a chk-status or two. If not, the drive is probably seeking in ata_sff_pio_task()
1236 * or something. Snooze for a couple msecs, then in ata_sff_pio_task()
1237 * chk-status again. If still busy, queue delayed work. in ata_sff_pio_task()
1241 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1243 spin_lock_irq(ap->lock); in ata_sff_pio_task()
1256 ap->sff_pio_task_link = NULL; in ata_sff_pio_task()
1266 spin_unlock_irq(ap->lock); in ata_sff_pio_task()
1270 * ata_sff_qc_issue - issue taskfile to a SFF controller
1273 * This function issues a PIO or NODATA command to a SFF
1284 struct ata_port *ap = qc->ap; in ata_sff_qc_issue()
1285 struct ata_link *link = qc->dev->link; in ata_sff_qc_issue()
1290 if (ap->flags & ATA_FLAG_PIO_POLLING) in ata_sff_qc_issue()
1291 qc->tf.flags |= ATA_TFLAG_POLLING; in ata_sff_qc_issue()
1294 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_sff_qc_issue()
1297 switch (qc->tf.protocol) { in ata_sff_qc_issue()
1299 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1302 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1303 ap->hsm_task_state = HSM_ST_LAST; in ata_sff_qc_issue()
1305 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1311 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1314 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1316 if (qc->tf.flags & ATA_TFLAG_WRITE) { in ata_sff_qc_issue()
1318 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1326 ap->hsm_task_state = HSM_ST; in ata_sff_qc_issue()
1328 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1341 if (qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_qc_issue()
1344 ata_tf_to_host(ap, &qc->tf, qc->tag); in ata_sff_qc_issue()
1346 ap->hsm_task_state = HSM_ST_FIRST; in ata_sff_qc_issue()
1349 if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) || in ata_sff_qc_issue()
1350 (qc->tf.flags & ATA_TFLAG_POLLING)) in ata_sff_qc_issue()
1363 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
1364 * @qc: qc to fill result TF for
1366 * @qc is finished and result TF needs to be filled. Fill it
1367 * using ->sff_tf_read.
1374 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); in ata_sff_qc_fill_rtf()
1380 ap->stats.idle_irq++; in ata_sff_idle_irq()
1383 if ((ap->stats.idle_irq % 1000) == 0) { in ata_sff_idle_irq()
1384 ap->ops->sff_check_status(ap); in ata_sff_idle_irq()
1385 if (ap->ops->sff_irq_clear) in ata_sff_idle_irq()
1386 ap->ops->sff_irq_clear(ap); in ata_sff_idle_irq()
1403 switch (ap->hsm_task_state) { in __ata_sff_port_intr()
1405 /* Some pre-ATAPI-4 devices assert INTRQ in __ata_sff_port_intr()
1411 * need to check ata_is_atapi(qc->tf.protocol) again. in __ata_sff_port_intr()
1413 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in __ata_sff_port_intr()
1427 qc->err_mask |= AC_ERR_HSM; in __ata_sff_port_intr()
1428 ap->hsm_task_state = HSM_ST_ERR; in __ata_sff_port_intr()
1434 if (ap->ops->sff_irq_clear) in __ata_sff_port_intr()
1435 ap->ops->sff_irq_clear(ap); in __ata_sff_port_intr()
1443 * ata_sff_port_intr - Handle SFF port interrupt
1471 spin_lock_irqsave(&host->lock, flags); in __ata_sff_interrupt()
1475 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1476 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1479 qc = ata_qc_from_tag(ap, ap->link.active_tag); in __ata_sff_interrupt()
1481 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) in __ata_sff_interrupt()
1497 for (i = 0; i < host->n_ports; i++) { in __ata_sff_interrupt()
1498 struct ata_port *ap = host->ports[i]; in __ata_sff_interrupt()
1503 if (!ap->ops->sff_irq_check || in __ata_sff_interrupt()
1504 !ap->ops->sff_irq_check(ap)) in __ata_sff_interrupt()
1508 ap->ops->sff_check_status(ap); in __ata_sff_interrupt()
1509 if (ap->ops->sff_irq_clear) in __ata_sff_interrupt()
1510 ap->ops->sff_irq_clear(ap); in __ata_sff_interrupt()
1513 if (!(ap->ops->sff_check_status(ap) & ATA_BUSY)) in __ata_sff_interrupt()
1528 spin_unlock_irqrestore(&host->lock, flags); in __ata_sff_interrupt()
1534 * ata_sff_interrupt - Default SFF ATA host interrupt handler
1554 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1572 qc = ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_lost_interrupt()
1573 /* We cannot lose an interrupt on a non-existent or polled command */ in ata_sff_lost_interrupt()
1574 if (!qc || qc->tf.flags & ATA_TFLAG_POLLING) in ata_sff_lost_interrupt()
1576 /* See if the controller thinks it is still busy - if so the command in ata_sff_lost_interrupt()
1577 isn't a lost IRQ but is still in progress */ in ata_sff_lost_interrupt()
1583 /* There was a command running, we are no longer busy and we have in ata_sff_lost_interrupt()
1593 * ata_sff_freeze - Freeze SFF controller port
1603 ap->ctl |= ATA_NIEN; in ata_sff_freeze()
1604 ap->last_ctl = ap->ctl; in ata_sff_freeze()
1606 ata_sff_set_devctl(ap, ap->ctl); in ata_sff_freeze()
1612 ap->ops->sff_check_status(ap); in ata_sff_freeze()
1614 if (ap->ops->sff_irq_clear) in ata_sff_freeze()
1615 ap->ops->sff_irq_clear(ap); in ata_sff_freeze()
1620 * ata_sff_thaw - Thaw SFF controller port
1630 /* clear & re-enable interrupts */ in ata_sff_thaw()
1631 ap->ops->sff_check_status(ap); in ata_sff_thaw()
1632 if (ap->ops->sff_irq_clear) in ata_sff_thaw()
1633 ap->ops->sff_irq_clear(ap); in ata_sff_thaw()
1639 * ata_sff_prereset - prepare SFF link for reset
1655 struct ata_eh_context *ehc = &link->eh_context; in ata_sff_prereset()
1658 /* The standard prereset is best-effort and always returns 0 */ in ata_sff_prereset()
1662 if (ehc->i.action & ATA_EH_HARDRESET) in ata_sff_prereset()
1668 if (rc && rc != -ENODEV) { in ata_sff_prereset()
1672 ehc->i.action |= ATA_EH_HARDRESET; in ata_sff_prereset()
1681 * ata_devchk - PATA device presence detection
1686 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1689 * Write a pattern to the ATA shadow registers,
1690 * and if a device is present, it will respond by
1702 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_devchk()
1705 ap->ops->sff_dev_select(ap, device); in ata_devchk()
1707 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1708 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1710 iowrite8(0xaa, ioaddr->nsect_addr); in ata_devchk()
1711 iowrite8(0x55, ioaddr->lbal_addr); in ata_devchk()
1713 iowrite8(0x55, ioaddr->nsect_addr); in ata_devchk()
1714 iowrite8(0xaa, ioaddr->lbal_addr); in ata_devchk()
1716 nsect = ioread8(ioaddr->nsect_addr); in ata_devchk()
1717 lbal = ioread8(ioaddr->lbal_addr); in ata_devchk()
1720 return true; /* we found a device */ in ata_devchk()
1726 * ata_sff_dev_classify - Parse returned ATA device signature
1731 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1732 * an ATA/ATAPI-defined set of values is placed in the ATA
1738 * and the spec-defined values examined by ata_dev_classify().
1744 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1749 struct ata_port *ap = dev->link->ap; in ata_sff_dev_classify()
1750 struct ata_taskfile tf; in ata_sff_dev_classify() local
1754 ap->ops->sff_dev_select(ap, dev->devno); in ata_sff_dev_classify()
1756 memset(&tf, 0, sizeof(tf)); in ata_sff_dev_classify()
1758 ap->ops->sff_tf_read(ap, &tf); in ata_sff_dev_classify()
1759 err = tf.error; in ata_sff_dev_classify()
1766 dev->quirks |= ATA_QUIRK_DIAGNOSTIC; in ata_sff_dev_classify()
1769 else if ((dev->devno == 0) && (err == 0x81)) in ata_sff_dev_classify()
1775 class = ata_port_classify(ap, &tf); in ata_sff_dev_classify()
1785 if (present && (dev->quirks & ATA_QUIRK_DIAGNOSTIC)) in ata_sff_dev_classify()
1791 if (ap->ops->sff_check_status(ap) == 0) in ata_sff_dev_classify()
1800 * ata_sff_wait_after_reset - wait for devices to become ready after reset
1806 * reset. It contains preceding 150ms wait to avoid accessing TF
1813 * 0 on success, -ENODEV if some or all of devices in @devmask
1814 * don't seem to exist. -errno on other errors.
1819 struct ata_port *ap = link->ap; in ata_sff_wait_after_reset()
1820 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_sff_wait_after_reset()
1829 /* -ENODEV means the odd clown forgot the D7 pulldown resistor in ata_sff_wait_after_reset()
1830 * and TF status is 0xff, bail out on it too. in ata_sff_wait_after_reset()
1841 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1850 nsect = ioread8(ioaddr->nsect_addr); in ata_sff_wait_after_reset()
1851 lbal = ioread8(ioaddr->lbal_addr); in ata_sff_wait_after_reset()
1854 ata_msleep(ap, 50); /* give drive a breather */ in ata_sff_wait_after_reset()
1859 if (rc != -ENODEV) in ata_sff_wait_after_reset()
1866 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1868 ap->ops->sff_dev_select(ap, 1); in ata_sff_wait_after_reset()
1870 ap->ops->sff_dev_select(ap, 0); in ata_sff_wait_after_reset()
1879 struct ata_ioports *ioaddr = &ap->ioaddr; in ata_bus_softreset()
1881 if (ap->ioaddr.ctl_addr) { in ata_bus_softreset()
1883 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1885 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr); in ata_bus_softreset()
1887 iowrite8(ap->ctl, ioaddr->ctl_addr); in ata_bus_softreset()
1888 ap->last_ctl = ap->ctl; in ata_bus_softreset()
1892 return ata_sff_wait_after_reset(&ap->link, devmask, deadline); in ata_bus_softreset()
1896 * ata_sff_softreset - reset host port via ATA SRST
1907 * 0 on success, -errno otherwise.
1912 struct ata_port *ap = link->ap; in ata_sff_softreset()
1913 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ata_sff_softreset()
1925 ap->ops->sff_dev_select(ap, 0); in ata_sff_softreset()
1929 /* if link is occupied, -ENODEV too is an error */ in ata_sff_softreset()
1930 if (rc && (rc != -ENODEV || sata_scr_valid(link))) { in ata_sff_softreset()
1936 classes[0] = ata_sff_dev_classify(&link->device[0], in ata_sff_softreset()
1939 classes[1] = ata_sff_dev_classify(&link->device[1], in ata_sff_softreset()
1947 * sata_sff_hardreset - reset host port via SATA phy reset
1952 * SATA phy-reset host port using DET bits of SControl register,
1959 * 0 on success, -errno otherwise.
1964 struct ata_eh_context *ehc = &link->eh_context; in sata_sff_hardreset()
1972 *class = ata_sff_dev_classify(link->device, 1, NULL); in sata_sff_hardreset()
1979 * ata_sff_postreset - SFF postreset callback
1983 * This function is invoked after a successful reset. It first
1992 struct ata_port *ap = link->ap; in ata_sff_postreset()
1996 /* is double-select really necessary? */ in ata_sff_postreset()
1998 ap->ops->sff_dev_select(ap, 1); in ata_sff_postreset()
2000 ap->ops->sff_dev_select(ap, 0); in ata_sff_postreset()
2007 if (ata_sff_set_devctl(ap, ap->ctl)) in ata_sff_postreset()
2008 ap->last_ctl = ap->ctl; in ata_sff_postreset()
2013 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2016 * Drain the FIFO and device of any stuck data following a command
2017 * failing to complete. In some cases this is necessary before a
2027 /* We only need to flush incoming data when a command was running */ in ata_sff_drain_fifo()
2028 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ata_sff_drain_fifo()
2031 ap = qc->ap; in ata_sff_drain_fifo()
2033 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ata_sff_drain_fifo()
2035 ioread16(ap->ioaddr.data_addr); in ata_sff_drain_fifo()
2044 * ata_sff_error_handler - Stock error handler for SFF controller
2049 * use this EH as-is or with some added handling before and
2057 ata_reset_fn_t softreset = ap->ops->softreset; in ata_sff_error_handler()
2058 ata_reset_fn_t hardreset = ap->ops->hardreset; in ata_sff_error_handler()
2062 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_sff_error_handler()
2063 if (qc && !(qc->flags & ATA_QCFLAG_EH)) in ata_sff_error_handler()
2066 spin_lock_irqsave(ap->lock, flags); in ata_sff_error_handler()
2069 * We *MUST* do FIFO draining before we issue a reset as in ata_sff_error_handler()
2075 if (ap->ops->sff_drain_fifo) in ata_sff_error_handler()
2076 ap->ops->sff_drain_fifo(qc); in ata_sff_error_handler()
2078 spin_unlock_irqrestore(ap->lock, flags); in ata_sff_error_handler()
2080 /* ignore built-in hardresets if SCR access is not available */ in ata_sff_error_handler()
2082 hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link)) in ata_sff_error_handler()
2085 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, in ata_sff_error_handler()
2086 ap->ops->postreset); in ata_sff_error_handler()
2091 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
2103 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; in ata_sff_std_ports()
2104 ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR; in ata_sff_std_ports()
2105 ioaddr->feature_addr = ioaddr->cmd_addr + ATA_REG_FEATURE; in ata_sff_std_ports()
2106 ioaddr->nsect_addr = ioaddr->cmd_addr + ATA_REG_NSECT; in ata_sff_std_ports()
2107 ioaddr->lbal_addr = ioaddr->cmd_addr + ATA_REG_LBAL; in ata_sff_std_ports()
2108 ioaddr->lbam_addr = ioaddr->cmd_addr + ATA_REG_LBAM; in ata_sff_std_ports()
2109 ioaddr->lbah_addr = ioaddr->cmd_addr + ATA_REG_LBAH; in ata_sff_std_ports()
2110 ioaddr->device_addr = ioaddr->cmd_addr + ATA_REG_DEVICE; in ata_sff_std_ports()
2111 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; in ata_sff_std_ports()
2112 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; in ata_sff_std_ports()
2133 * ata_pci_sff_init_host - acquire native PCI ATA resources and init host
2148 * 0 if at least one port is initialized, -ENODEV if no port is
2153 struct device *gdev = host->dev; in ata_pci_sff_init_host()
2160 struct ata_port *ap = host->ports[i]; in ata_pci_sff_init_host()
2172 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2182 if (rc == -EBUSY) in ata_pci_sff_init_host()
2184 ap->ops = &ata_dummy_port_ops; in ata_pci_sff_init_host()
2187 host->iomap = iomap = pcim_iomap_table(pdev); in ata_pci_sff_init_host()
2189 ap->ioaddr.cmd_addr = iomap[base]; in ata_pci_sff_init_host()
2190 ap->ioaddr.altstatus_addr = in ata_pci_sff_init_host()
2191 ap->ioaddr.ctl_addr = (void __iomem *) in ata_pci_sff_init_host()
2193 ata_sff_std_ports(&ap->ioaddr); in ata_pci_sff_init_host()
2204 return -ENODEV; in ata_pci_sff_init_host()
2212 * ata_pci_sff_prepare_host - helper to prepare PCI PIO-only SFF ATA host
2217 * Helper to allocate PIO-only SFF ATA host for @pdev, acquire
2224 * 0 on success, -errno otherwise.
2233 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) in ata_pci_sff_prepare_host()
2234 return -ENOMEM; in ata_pci_sff_prepare_host()
2236 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2); in ata_pci_sff_prepare_host()
2238 dev_err(&pdev->dev, "failed to allocate ATA host\n"); in ata_pci_sff_prepare_host()
2239 rc = -ENOMEM; in ata_pci_sff_prepare_host()
2247 devres_remove_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2252 devres_release_group(&pdev->dev, NULL); in ata_pci_sff_prepare_host()
2258 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
2271 * 0 on success, -errno otherwise.
2277 struct device *dev = host->dev; in ata_pci_sff_activate_host()
2279 const char *drv_name = dev_driver_string(host->dev); in ata_pci_sff_activate_host()
2286 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { in ata_pci_sff_activate_host()
2298 if (!ata_port_is_dummy(host->ports[0])) in ata_pci_sff_activate_host()
2300 if (!ata_port_is_dummy(host->ports[1])) in ata_pci_sff_activate_host()
2307 return -ENOMEM; in ata_pci_sff_activate_host()
2309 if (!legacy_mode && pdev->irq) { in ata_pci_sff_activate_host()
2312 rc = devm_request_irq(dev, pdev->irq, irq_handler, in ata_pci_sff_activate_host()
2318 if (ata_port_is_dummy(host->ports[i])) in ata_pci_sff_activate_host()
2320 ata_port_desc_misc(host->ports[i], pdev->irq); in ata_pci_sff_activate_host()
2323 if (!ata_port_is_dummy(host->ports[0])) { in ata_pci_sff_activate_host()
2330 ata_port_desc_misc(host->ports[0], in ata_pci_sff_activate_host()
2334 if (!ata_port_is_dummy(host->ports[1])) { in ata_pci_sff_activate_host()
2341 ata_port_desc_misc(host->ports[1], in ata_pci_sff_activate_host()
2364 if (ppi[i]->port_ops != &ata_dummy_port_ops) in ata_sff_find_valid_pi()
2375 struct device *dev = &pdev->dev; in ata_pci_init_one()
2382 dev_err(&pdev->dev, "no valid port_info specified\n"); in ata_pci_init_one()
2383 return -EINVAL; in ata_pci_init_one()
2387 return -ENOMEM; in ata_pci_init_one()
2403 host->private_data = host_priv; in ata_pci_init_one()
2404 host->flags |= hflags; in ata_pci_init_one()
2415 devres_remove_group(&pdev->dev, NULL); in ata_pci_init_one()
2417 devres_release_group(&pdev->dev, NULL); in ata_pci_init_one()
2423 * ata_pci_sff_init_one - Initialize/register PIO-only PCI IDE controller
2430 * This is a helper function which can be called from a driver's
2435 * Nobody makes a single channel controller that appears solely as
2442 * Zero on success, negative on errno-based value on error.
2488 * ata_bmdma_fill_sg - Fill PCI IDE PRD table
2491 * Fill PCI IDE PRD (scatter-gather) table with segments
2500 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg()
2501 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg()
2506 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg()
2511 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg()
2521 len = 0x10000 - offset; in ata_bmdma_fill_sg()
2527 sg_len -= len; in ata_bmdma_fill_sg()
2532 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg()
2536 * ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
2539 * Fill PCI IDE PRD (scatter-gather) table with segments
2550 struct ata_port *ap = qc->ap; in ata_bmdma_fill_sg_dumb()
2551 struct ata_bmdma_prd *prd = ap->bmdma_prd; in ata_bmdma_fill_sg_dumb()
2556 for_each_sg(qc->sg, sg, qc->n_elem, si) { in ata_bmdma_fill_sg_dumb()
2561 * Note h/w doesn't support 64-bit, so we unconditionally in ata_bmdma_fill_sg_dumb()
2571 len = 0x10000 - offset; in ata_bmdma_fill_sg_dumb()
2586 sg_len -= len; in ata_bmdma_fill_sg_dumb()
2591 prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT); in ata_bmdma_fill_sg_dumb()
2595 * ata_bmdma_qc_prep - Prepare taskfile for submission
2605 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_qc_prep()
2615 * ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
2625 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) in ata_bmdma_dumb_qc_prep()
2635 * ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
2638 * This function issues a PIO, NODATA or DMA command to a
2650 struct ata_port *ap = qc->ap; in ata_bmdma_qc_issue()
2651 struct ata_link *link = qc->dev->link; in ata_bmdma_qc_issue()
2654 if (!ata_is_dma(qc->tf.protocol)) in ata_bmdma_qc_issue()
2658 ata_dev_select(ap, qc->dev->devno, 1, 0); in ata_bmdma_qc_issue()
2661 switch (qc->tf.protocol) { in ata_bmdma_qc_issue()
2663 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2665 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2666 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2667 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2668 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2669 trace_ata_bmdma_start(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2670 ap->ops->bmdma_start(qc); /* initiate bmdma */ in ata_bmdma_qc_issue()
2671 ap->hsm_task_state = HSM_ST_LAST; in ata_bmdma_qc_issue()
2675 WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING); in ata_bmdma_qc_issue()
2677 trace_ata_tf_load(ap, &qc->tf); in ata_bmdma_qc_issue()
2678 ap->ops->sff_tf_load(ap, &qc->tf); /* load tf registers */ in ata_bmdma_qc_issue()
2679 trace_ata_bmdma_setup(ap, &qc->tf, qc->tag); in ata_bmdma_qc_issue()
2680 ap->ops->bmdma_setup(qc); /* set up bmdma */ in ata_bmdma_qc_issue()
2681 ap->hsm_task_state = HSM_ST_FIRST; in ata_bmdma_qc_issue()
2684 if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) in ata_bmdma_qc_issue()
2698 * ata_bmdma_port_intr - Handle BMDMA port interrupt
2712 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_bmdma_port_intr()
2717 if (ap->hsm_task_state == HSM_ST_LAST && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_port_intr()
2719 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_port_intr()
2726 /* before we do anything else, clear DMA-Start bit */ in ata_bmdma_port_intr()
2727 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_port_intr()
2728 ap->ops->bmdma_stop(qc); in ata_bmdma_port_intr()
2733 qc->err_mask |= AC_ERR_HOST_BUS; in ata_bmdma_port_intr()
2734 ap->hsm_task_state = HSM_ST_ERR; in ata_bmdma_port_intr()
2740 if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) in ata_bmdma_port_intr()
2748 * ata_bmdma_interrupt - Default BMDMA ATA host interrupt handler
2768 * ata_bmdma_error_handler - Stock error handler for BMDMA controller
2773 * able to use this EH as-is or with some added handling before
2785 qc = __ata_qc_from_tag(ap, ap->link.active_tag); in ata_bmdma_error_handler()
2786 if (qc && !(qc->flags & ATA_QCFLAG_EH)) in ata_bmdma_error_handler()
2790 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_error_handler()
2792 if (qc && ata_is_dma(qc->tf.protocol)) { in ata_bmdma_error_handler()
2795 host_stat = ap->ops->bmdma_status(ap); in ata_bmdma_error_handler()
2800 * really a timeout event, adjust error mask and in ata_bmdma_error_handler()
2803 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { in ata_bmdma_error_handler()
2804 qc->err_mask = AC_ERR_HOST_BUS; in ata_bmdma_error_handler()
2808 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_error_handler()
2809 ap->ops->bmdma_stop(qc); in ata_bmdma_error_handler()
2813 ap->ops->sff_check_status(ap); in ata_bmdma_error_handler()
2814 if (ap->ops->sff_irq_clear) in ata_bmdma_error_handler()
2815 ap->ops->sff_irq_clear(ap); in ata_bmdma_error_handler()
2819 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_error_handler()
2829 * ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
2837 struct ata_port *ap = qc->ap; in ata_bmdma_post_internal_cmd()
2840 if (ata_is_dma(qc->tf.protocol)) { in ata_bmdma_post_internal_cmd()
2841 spin_lock_irqsave(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2842 trace_ata_bmdma_stop(ap, &qc->tf, qc->tag); in ata_bmdma_post_internal_cmd()
2843 ap->ops->bmdma_stop(qc); in ata_bmdma_post_internal_cmd()
2844 spin_unlock_irqrestore(ap->lock, flags); in ata_bmdma_post_internal_cmd()
2850 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
2862 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_irq_clear()
2872 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
2880 struct ata_port *ap = qc->ap; in ata_bmdma_setup()
2881 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); in ata_bmdma_setup()
2886 iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); in ata_bmdma_setup()
2888 /* specify data direction, triple-check start bit is clear */ in ata_bmdma_setup()
2889 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2893 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_setup()
2896 ap->ops->sff_exec_command(ap, &qc->tf); in ata_bmdma_setup()
2901 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
2909 struct ata_port *ap = qc->ap; in ata_bmdma_start()
2913 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2914 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); in ata_bmdma_start()
2921 * Further, a read of the DMA status register _immediately_ in ata_bmdma_start()
2923 * is expected, so I think it is best to not add a readb() in ata_bmdma_start()
2934 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
2946 struct ata_port *ap = qc->ap; in ata_bmdma_stop()
2947 void __iomem *mmio = ap->ioaddr.bmdma_addr; in ata_bmdma_stop()
2953 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ in ata_bmdma_stop()
2959 * ata_bmdma_status - Read PCI IDE BMDMA status
2971 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); in ata_bmdma_status()
2977 * ata_bmdma_port_start - Set port up for bmdma.
2990 if (ap->mwdma_mask || ap->udma_mask) { in ata_bmdma_port_start()
2991 ap->bmdma_prd = in ata_bmdma_port_start()
2992 dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ, in ata_bmdma_port_start()
2993 &ap->bmdma_prd_dma, GFP_KERNEL); in ata_bmdma_port_start()
2994 if (!ap->bmdma_prd) in ata_bmdma_port_start()
2995 return -ENOMEM; in ata_bmdma_port_start()
3003 * ata_bmdma_port_start32 - Set port up for dma.
3018 ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE; in ata_bmdma_port_start32()
3026 * ata_pci_bmdma_clear_simplex - attempt to kick device out of simplex
3032 * have -undefined- behaviour.
3041 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3047 return -EOPNOTSUPP; in ata_pci_bmdma_clear_simplex()
3050 return -ENOENT; in ata_pci_bmdma_clear_simplex()
3059 dev_err(host->dev, "BMDMA: %s, falling back to PIO\n", reason); in ata_bmdma_nodma()
3062 host->ports[i]->mwdma_mask = 0; in ata_bmdma_nodma()
3063 host->ports[i]->udma_mask = 0; in ata_bmdma_nodma()
3068 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
3078 struct device *gdev = host->dev; in ata_pci_bmdma_init()
3091 * ->sff_irq_clear method. Try to initialize bmdma_addr in ata_pci_bmdma_init()
3094 rc = dma_set_mask_and_coherent(&pdev->dev, ATA_DMA_MASK); in ata_pci_bmdma_init()
3104 host->iomap = pcim_iomap_table(pdev); in ata_pci_bmdma_init()
3107 struct ata_port *ap = host->ports[i]; in ata_pci_bmdma_init()
3108 void __iomem *bmdma = host->iomap[4] + 8 * i; in ata_pci_bmdma_init()
3113 ap->ioaddr.bmdma_addr = bmdma; in ata_pci_bmdma_init()
3114 if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) && in ata_pci_bmdma_init()
3116 host->flags |= ATA_HOST_SIMPLEX; in ata_pci_bmdma_init()
3125 * ata_pci_bmdma_prepare_host - helper to prepare PCI BMDMA ATA host
3137 * 0 on success, -errno otherwise.
3155 * ata_pci_bmdma_init_one - Initialize/register BMDMA PCI IDE controller
3169 * Zero on success, negative on errno-based value on error.
3184 * ata_sff_port_init - Initialize SFF/BMDMA ATA port
3195 INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task); in ata_sff_port_init()
3196 ap->ctl = ATA_DEVCTL_OBS; in ata_sff_port_init()
3197 ap->last_ctl = 0xFF; in ata_sff_port_init()
3204 return -ENOMEM; in ata_sff_init()