Lines Matching +full:tf +full:- +full:a
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2004 Jeff Garzik
17 #include "libata-transport.h"
28 * sata_scr_valid - test whether SCRs are accessible
41 struct ata_port *ap = link->ap; in sata_scr_valid()
43 return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read; in sata_scr_valid()
48 * sata_scr_read - read SCR register of the specified port
54 * guaranteed to succeed if @link is ap->link, the cable type of
55 * the port is SATA and the port implements ->scr_read.
58 * None if @link is ap->link. Kernel thread context otherwise.
67 return link->ap->ops->scr_read(link, reg, val); in sata_scr_read()
68 return -EOPNOTSUPP; in sata_scr_read()
76 * sata_scr_write - write SCR register of the specified port
82 * guaranteed to succeed if @link is ap->link, the cable type of
83 * the port is SATA and the port implements ->scr_read.
86 * None if @link is ap->link. Kernel thread context otherwise.
95 return link->ap->ops->scr_write(link, reg, val); in sata_scr_write()
96 return -EOPNOTSUPP; in sata_scr_write()
104 * sata_scr_write_flush - write SCR register of the specified port and flush
113 * None if @link is ap->link. Kernel thread context otherwise.
124 rc = link->ap->ops->scr_write(link, reg, val); in sata_scr_write_flush()
126 rc = link->ap->ops->scr_read(link, reg, &val); in sata_scr_write_flush()
129 return -EOPNOTSUPP; in sata_scr_write_flush()
137 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
138 * @tf: Taskfile to convert
143 * Converts a standard ATA taskfile to a Serial ATA
144 * FIS structure (Register - Host to Device).
149 void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis) in ata_tf_to_fis() argument
151 fis[0] = 0x27; /* Register - Host to Device FIS */ in ata_tf_to_fis()
156 fis[2] = tf->command; in ata_tf_to_fis()
157 fis[3] = tf->feature; in ata_tf_to_fis()
159 fis[4] = tf->lbal; in ata_tf_to_fis()
160 fis[5] = tf->lbam; in ata_tf_to_fis()
161 fis[6] = tf->lbah; in ata_tf_to_fis()
162 fis[7] = tf->device; in ata_tf_to_fis()
164 fis[8] = tf->hob_lbal; in ata_tf_to_fis()
165 fis[9] = tf->hob_lbam; in ata_tf_to_fis()
166 fis[10] = tf->hob_lbah; in ata_tf_to_fis()
167 fis[11] = tf->hob_feature; in ata_tf_to_fis()
169 fis[12] = tf->nsect; in ata_tf_to_fis()
170 fis[13] = tf->hob_nsect; in ata_tf_to_fis()
172 fis[15] = tf->ctl; in ata_tf_to_fis()
174 fis[16] = tf->auxiliary & 0xff; in ata_tf_to_fis()
175 fis[17] = (tf->auxiliary >> 8) & 0xff; in ata_tf_to_fis()
176 fis[18] = (tf->auxiliary >> 16) & 0xff; in ata_tf_to_fis()
177 fis[19] = (tf->auxiliary >> 24) & 0xff; in ata_tf_to_fis()
182 * ata_tf_from_fis - Convert SATA FIS to ATA taskfile
184 * @tf: Taskfile to output
186 * Converts a serial ATA FIS structure to a standard ATA taskfile.
192 void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf) in ata_tf_from_fis() argument
194 tf->command = fis[2]; /* status */ in ata_tf_from_fis()
195 tf->feature = fis[3]; /* error */ in ata_tf_from_fis()
197 tf->lbal = fis[4]; in ata_tf_from_fis()
198 tf->lbam = fis[5]; in ata_tf_from_fis()
199 tf->lbah = fis[6]; in ata_tf_from_fis()
200 tf->device = fis[7]; in ata_tf_from_fis()
202 tf->hob_lbal = fis[8]; in ata_tf_from_fis()
203 tf->hob_lbam = fis[9]; in ata_tf_from_fis()
204 tf->hob_lbah = fis[10]; in ata_tf_from_fis()
206 tf->nsect = fis[12]; in ata_tf_from_fis()
207 tf->hob_nsect = fis[13]; in ata_tf_from_fis()
212 * sata_link_debounce - debounce SATA phy status
231 * 0 on success, -errno on failure.
254 ata_msleep(link->ap, interval); in sata_link_debounce()
274 * -EPIPE to tell upper layer to lower link speed. in sata_link_debounce()
277 return -EPIPE; in sata_link_debounce()
283 * sata_link_resume - resume SATA link
294 * 0 on success, -errno on failure.
320 if (!(link->flags & ATA_LFLAG_NO_DB_DELAY)) in sata_link_resume()
321 ata_msleep(link->ap, 200); in sata_link_resume()
326 } while ((scontrol & 0xf0f) != 0x300 && --tries); in sata_link_resume()
336 ATA_LINK_RESUME_TRIES - tries); in sata_link_resume()
345 return rc != -EINVAL ? rc : 0; in sata_link_resume()
350 * sata_link_scr_lpm - manipulate SControl IPM and SPM fields
365 * 0 on success, -errno otherwise.
370 struct ata_eh_context *ehc = &link->eh_context; in sata_link_scr_lpm()
419 ehc->i.serror &= ~SERR_PHYRDY_CHG; in sata_link_scr_lpm()
426 struct ata_link *host_link = &link->ap->link; in __sata_set_spd_needed()
429 limit = link->sata_spd_limit; in __sata_set_spd_needed()
435 if (!ata_is_host_link(link) && host_link->sata_spd) in __sata_set_spd_needed()
436 limit &= (1 << host_link->sata_spd) - 1; in __sata_set_spd_needed()
450 * sata_set_spd_needed - is SATA spd configuration needed
454 * @link->sata_spd_limit. This function is used to determine
475 * sata_set_spd - set SATA spd according to spd limit
506 * sata_link_hardreset - reset link via SATA phy reset
513 * SATA phy-reset @link using DET bits of SControl register.
527 * 0 on success, -errno otherwise.
567 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 in sata_link_hardreset()
570 ata_msleep(link->ap, 1); in sata_link_hardreset()
580 /* Link is online. From this point, -ENODEV too is an error. */ in sata_link_hardreset()
584 if (sata_pmp_supported(link->ap) && ata_is_host_link(link)) { in sata_link_hardreset()
585 /* If PMP is supported, we have to do follow-up SRST. in sata_link_hardreset()
599 rc = -EAGAIN; in sata_link_hardreset()
607 if (rc && rc != -EAGAIN) { in sata_link_hardreset()
619 * ata_qc_complete_multiple - Complete multiple qcs successfully
623 * Complete in-flight commands. This functions is meant to be
624 * called from low-level driver's interrupt routine to complete
625 * requests normally. ap->qc_active and @qc_active is compared
636 * Number of completed commands on success, -errno otherwise.
640 u64 done_mask, ap_qc_active = ap->qc_active; in ata_qc_complete_multiple()
644 * If the internal tag is set on ap->qc_active, then we care about in ata_qc_complete_multiple()
656 ata_port_err(ap, "illegal qc_active transition (%08llx->%08llx)\n", in ata_qc_complete_multiple()
657 ap->qc_active, qc_active); in ata_qc_complete_multiple()
658 return -EINVAL; in ata_qc_complete_multiple()
678 * ata_slave_link_init - initialize slave link
684 * In libata, a port contains links and a link contains devices.
685 * There is single host link but if a PMP is attached to it,
686 * there can be multiple fan-out links. On SATA, there's usually
687 * a single device connected to a link but PATA and SATA
688 * controllers emulating TF based interface can have two - master
691 * However, there are a few controllers which don't fit into this
692 * abstraction too well - SATA controllers which emulate TF
696 * (e.g. onlineness, link speed) but should be treated like a
704 * handling, separate @ap->slave_link is used. All dirty details
710 * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
711 * softreset(M) -> postreset(M) -> postreset(S)
721 * 0 on success, -errno on failure.
727 WARN_ON(ap->slave_link); in ata_slave_link_init()
728 WARN_ON(ap->flags & ATA_FLAG_PMP); in ata_slave_link_init()
732 return -ENOMEM; in ata_slave_link_init()
735 ap->slave_link = link; in ata_slave_link_init()
741 * sata_lpm_ignore_phy_events - test if PHY event should be ignored
754 unsigned long lpm_timeout = link->last_lpm_change + in sata_lpm_ignore_phy_events()
758 if (link->lpm_policy > ATA_LPM_MAX_POWER) in sata_lpm_ignore_phy_events()
764 if ((link->flags & ATA_LFLAG_CHANGED) && in sata_lpm_ignore_phy_events()
801 return -EINVAL; in ata_scsi_lpm_store()
803 spin_lock_irqsave(ap->lock, flags); in ata_scsi_lpm_store()
806 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_scsi_lpm_store()
807 if (dev->horkage & ATA_HORKAGE_NOLPM) { in ata_scsi_lpm_store()
808 count = -EOPNOTSUPP; in ata_scsi_lpm_store()
814 ap->target_lpm_policy = policy; in ata_scsi_lpm_store()
817 spin_unlock_irqrestore(ap->lock, flags); in ata_scsi_lpm_store()
827 if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names)) in ata_scsi_lpm_show()
828 return -EINVAL; in ata_scsi_lpm_show()
831 ata_lpm_policy_names[ap->target_lpm_policy]); in ata_scsi_lpm_show()
842 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_ncq_prio_supported_show()
847 spin_lock_irq(ap->lock); in ata_ncq_prio_supported_show()
850 rc = -ENODEV; in ata_ncq_prio_supported_show()
852 ncq_prio_supported = dev->flags & ATA_DFLAG_NCQ_PRIO; in ata_ncq_prio_supported_show()
853 spin_unlock_irq(ap->lock); in ata_ncq_prio_supported_show()
866 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_ncq_prio_enable_show()
871 spin_lock_irq(ap->lock); in ata_ncq_prio_enable_show()
874 rc = -ENODEV; in ata_ncq_prio_enable_show()
876 ncq_prio_enable = dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_show()
877 spin_unlock_irq(ap->lock); in ata_ncq_prio_enable_show()
896 return -EINVAL; in ata_ncq_prio_enable_store()
898 ap = ata_shost_to_port(sdev->host); in ata_ncq_prio_enable_store()
901 return -ENODEV; in ata_ncq_prio_enable_store()
903 spin_lock_irq(ap->lock); in ata_ncq_prio_enable_store()
905 if (!(dev->flags & ATA_DFLAG_NCQ_PRIO)) { in ata_ncq_prio_enable_store()
906 rc = -EINVAL; in ata_ncq_prio_enable_store()
911 dev->flags |= ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_store()
913 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_ncq_prio_enable_store()
916 spin_unlock_irq(ap->lock); in ata_ncq_prio_enable_store()
939 if (ap->ops->em_store && (ap->flags & ATA_FLAG_EM)) in ata_scsi_em_message_store()
940 return ap->ops->em_store(ap, buf, count); in ata_scsi_em_message_store()
941 return -EINVAL; in ata_scsi_em_message_store()
951 if (ap->ops->em_show && (ap->flags & ATA_FLAG_EM)) in ata_scsi_em_message_show()
952 return ap->ops->em_show(ap, buf); in ata_scsi_em_message_show()
953 return -EINVAL; in ata_scsi_em_message_show()
966 return snprintf(buf, 23, "%d\n", ap->em_message_type); in ata_scsi_em_message_type_show()
977 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_activity_show()
980 if (atadev && ap->ops->sw_activity_show && in ata_scsi_activity_show()
981 (ap->flags & ATA_FLAG_SW_ACTIVITY)) in ata_scsi_activity_show()
982 return ap->ops->sw_activity_show(atadev, buf); in ata_scsi_activity_show()
983 return -EINVAL; in ata_scsi_activity_show()
991 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_activity_store()
996 if (atadev && ap->ops->sw_activity_store && in ata_scsi_activity_store()
997 (ap->flags & ATA_FLAG_SW_ACTIVITY)) { in ata_scsi_activity_store()
1001 rc = ap->ops->sw_activity_store(atadev, val); in ata_scsi_activity_store()
1008 return -EINVAL; in ata_scsi_activity_store()
1015 * __ata_change_queue_depth - helper for ata_scsi_change_queue_depth
1020 * libsas and libata have different approaches for associating a sdev to
1030 if (queue_depth < 1 || queue_depth == sdev->queue_depth) in __ata_change_queue_depth()
1031 return sdev->queue_depth; in __ata_change_queue_depth()
1035 return sdev->queue_depth; in __ata_change_queue_depth()
1038 spin_lock_irqsave(ap->lock, flags); in __ata_change_queue_depth()
1039 dev->flags &= ~ATA_DFLAG_NCQ_OFF; in __ata_change_queue_depth()
1041 dev->flags |= ATA_DFLAG_NCQ_OFF; in __ata_change_queue_depth()
1044 spin_unlock_irqrestore(ap->lock, flags); in __ata_change_queue_depth()
1047 queue_depth = min(queue_depth, sdev->host->can_queue); in __ata_change_queue_depth()
1048 queue_depth = min(queue_depth, ata_id_queue_depth(dev->id)); in __ata_change_queue_depth()
1051 if (sdev->queue_depth == queue_depth) in __ata_change_queue_depth()
1052 return -EINVAL; in __ata_change_queue_depth()
1059 * ata_scsi_change_queue_depth - SCSI callback for queue depth config
1063 * This is libata standard hostt->change_queue_depth callback.
1075 struct ata_port *ap = ata_shost_to_port(sdev->host); in ata_scsi_change_queue_depth()
1082 * ata_sas_port_alloc - Allocate port for a SAS attached SATA device
1084 * @port_info: Information from low-level host driver
1104 ap->port_no = 0; in ata_sas_port_alloc()
1105 ap->lock = &host->lock; in ata_sas_port_alloc()
1106 ap->pio_mask = port_info->pio_mask; in ata_sas_port_alloc()
1107 ap->mwdma_mask = port_info->mwdma_mask; in ata_sas_port_alloc()
1108 ap->udma_mask = port_info->udma_mask; in ata_sas_port_alloc()
1109 ap->flags |= port_info->flags; in ata_sas_port_alloc()
1110 ap->ops = port_info->port_ops; in ata_sas_port_alloc()
1111 ap->cbl = ATA_CBL_SATA; in ata_sas_port_alloc()
1118 * ata_sas_port_start - Set port up for dma.
1135 if (!ap->ops->error_handler) in ata_sas_port_start()
1136 ap->pflags &= ~ATA_PFLAG_FROZEN; in ata_sas_port_start()
1142 * ata_sas_port_stop - Undo ata_sas_port_start()
1157 * ata_sas_async_probe - simply schedule probing and return
1177 * ata_sas_port_init - Initialize a SATA device
1184 * Zero on success, non-zero on error.
1189 int rc = ap->ops->port_start(ap); in ata_sas_port_init()
1193 ap->print_id = atomic_inc_return(&ata_print_id); in ata_sas_port_init()
1211 * ata_sas_port_destroy - Destroy a SATA port allocated by ata_sas_port_alloc
1218 if (ap->ops->port_stop) in ata_sas_port_destroy()
1219 ap->ops->port_stop(ap); in ata_sas_port_destroy()
1225 * ata_sas_slave_configure - Default slave_config routine for libata devices
1236 ata_scsi_dev_config(sdev, ap->link.device); in ata_sas_slave_configure()
1242 * ata_sas_queuecmd - Issue SCSI cdb to libata-managed device
1257 if (likely(ata_dev_enabled(ap->link.device))) in ata_sas_queuecmd()
1258 rc = __ata_scsi_queuecmd(cmd, ap->link.device); in ata_sas_queuecmd()
1260 cmd->result = (DID_BAD_TARGET << 16); in ata_sas_queuecmd()
1261 cmd->scsi_done(cmd); in ata_sas_queuecmd()
1269 unsigned int max_queue = ap->host->n_tags; in ata_sas_allocate_tag()
1272 for (i = 0, tag = ap->sas_last_tag + 1; i < max_queue; i++, tag++) { in ata_sas_allocate_tag()
1279 if (!test_and_set_bit(tag, &ap->sas_tag_allocated)) { in ata_sas_allocate_tag()
1280 ap->sas_last_tag = tag; in ata_sas_allocate_tag()
1284 return -1; in ata_sas_allocate_tag()
1289 clear_bit(tag, &ap->sas_tag_allocated); in ata_sas_free_tag()
1293 * sata_async_notification - SATA async notification handler
1310 if (!(ap->flags & ATA_FLAG_AN)) in sata_async_notification()
1313 rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf); in sata_async_notification()
1315 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); in sata_async_notification()
1324 struct ata_device *dev = ap->link.device; in sata_async_notification()
1326 if ((dev->class == ATA_DEV_ATAPI) && in sata_async_notification()
1327 (dev->flags & ATA_DFLAG_AN)) in sata_async_notification()
1345 if (!(sntf & (1 << link->pmp))) in sata_async_notification()
1348 if ((link->device->class == ATA_DEV_ATAPI) && in sata_async_notification()
1349 (link->device->flags & ATA_DFLAG_AN)) in sata_async_notification()
1350 ata_scsi_media_change_notify(link->device); in sata_async_notification()
1367 * ata_eh_read_log_10h - Read log page 10h for NCQ error details
1370 * @tf: Resulting taskfile registers of the failed command
1379 * 0 on success, -errno otherwise.
1382 int *tag, struct ata_taskfile *tf) in ata_eh_read_log_10h() argument
1384 u8 *buf = dev->link->ap->sector_buf; in ata_eh_read_log_10h()
1391 return -EIO; in ata_eh_read_log_10h()
1401 return -ENOENT; in ata_eh_read_log_10h()
1405 tf->command = buf[2]; in ata_eh_read_log_10h()
1406 tf->feature = buf[3]; in ata_eh_read_log_10h()
1407 tf->lbal = buf[4]; in ata_eh_read_log_10h()
1408 tf->lbam = buf[5]; in ata_eh_read_log_10h()
1409 tf->lbah = buf[6]; in ata_eh_read_log_10h()
1410 tf->device = buf[7]; in ata_eh_read_log_10h()
1411 tf->hob_lbal = buf[8]; in ata_eh_read_log_10h()
1412 tf->hob_lbam = buf[9]; in ata_eh_read_log_10h()
1413 tf->hob_lbah = buf[10]; in ata_eh_read_log_10h()
1414 tf->nsect = buf[12]; in ata_eh_read_log_10h()
1415 tf->hob_nsect = buf[13]; in ata_eh_read_log_10h()
1416 if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id)) in ata_eh_read_log_10h()
1417 tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16]; in ata_eh_read_log_10h()
1423 * ata_eh_analyze_ncq_error - analyze NCQ error
1427 * error status TF. For NCQ device errors, all LLDDs have to do
1428 * is setting AC_ERR_DEV in ehi->err_mask. This function takes
1436 struct ata_port *ap = link->ap; in ata_eh_analyze_ncq_error()
1437 struct ata_eh_context *ehc = &link->eh_context; in ata_eh_analyze_ncq_error()
1438 struct ata_device *dev = link->device; in ata_eh_analyze_ncq_error()
1440 struct ata_taskfile tf; in ata_eh_analyze_ncq_error() local
1444 if (ap->pflags & ATA_PFLAG_FROZEN) in ata_eh_analyze_ncq_error()
1448 if (!link->sactive || !(ehc->i.err_mask & AC_ERR_DEV)) in ata_eh_analyze_ncq_error()
1453 if (!(qc->flags & ATA_QCFLAG_FAILED)) in ata_eh_analyze_ncq_error()
1456 if (qc->err_mask) in ata_eh_analyze_ncq_error()
1461 memset(&tf, 0, sizeof(tf)); in ata_eh_analyze_ncq_error()
1462 rc = ata_eh_read_log_10h(dev, &tag, &tf); in ata_eh_analyze_ncq_error()
1469 if (!(link->sactive & (1 << tag))) { in ata_eh_analyze_ncq_error()
1477 memcpy(&qc->result_tf, &tf, sizeof(tf)); in ata_eh_analyze_ncq_error()
1478 qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48; in ata_eh_analyze_ncq_error()
1479 qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ; in ata_eh_analyze_ncq_error()
1480 if (dev->class == ATA_DEV_ZAC && in ata_eh_analyze_ncq_error()
1481 ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) { in ata_eh_analyze_ncq_error()
1484 sense_key = (qc->result_tf.auxiliary >> 16) & 0xff; in ata_eh_analyze_ncq_error()
1485 asc = (qc->result_tf.auxiliary >> 8) & 0xff; in ata_eh_analyze_ncq_error()
1486 ascq = qc->result_tf.auxiliary & 0xff; in ata_eh_analyze_ncq_error()
1487 ata_scsi_set_sense(dev, qc->scsicmd, sense_key, asc, ascq); in ata_eh_analyze_ncq_error()
1488 ata_scsi_set_sense_information(dev, qc->scsicmd, in ata_eh_analyze_ncq_error()
1489 &qc->result_tf); in ata_eh_analyze_ncq_error()
1490 qc->flags |= ATA_QCFLAG_SENSE_VALID; in ata_eh_analyze_ncq_error()
1493 ehc->i.err_mask &= ~AC_ERR_DEV; in ata_eh_analyze_ncq_error()