Lines Matching +full:build +full:- +full:system +full:- +full:flaky

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-core.c - helper library for ATA
5 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2004 Jeff Garzik
9 * as Documentation/driver-api/libata.rst
12 * http://www.sata-io.org/
16 * http://www.t10.org (SCSI MMC - for ATAPI MMC)
17 * http://www.sata-io.org (SATA)
19 * http://www.qic.org (QIC157 - Tape and DSC)
20 * http://www.ce-ata.org (CE-ATA: not supported)
23 * low-level ATA host controller drivers. As such, the API/ABI is
65 #include "libata-transport.h"
115 …ing cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst …
165 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_print_info()
167 return ehc->i.flags & ATA_EHI_PRINTINFO; in ata_dev_print_info()
176 * ata_link_next - link iteration helper
199 return ap->pmp_link; in ata_link_next()
202 return &ap->link; in ata_link_next()
206 if (link == &ap->link) in ata_link_next()
210 return ap->pmp_link; in ata_link_next()
213 if (unlikely(ap->slave_link)) in ata_link_next()
214 return ap->slave_link; in ata_link_next()
221 if (unlikely(link == ap->slave_link)) in ata_link_next()
225 if (++link < ap->pmp_link + ap->nr_pmp_links) in ata_link_next()
229 return &ap->link; in ata_link_next()
236 * ata_dev_next - device iteration helper
258 dev = link->device; in ata_dev_next()
262 dev = link->device + ata_link_max_devices(link) - 1; in ata_dev_next()
271 if (++dev < link->device + ata_link_max_devices(link)) in ata_dev_next()
276 if (--dev >= link->device) in ata_dev_next()
290 * ata_dev_phys_link - find physical link for a device
294 * this is different from @dev->link only when @dev is on slave
295 * link. For all other cases, it's the same as @dev->link.
305 struct ata_port *ap = dev->link->ap; in ata_dev_phys_link()
307 if (!ap->slave_link) in ata_dev_phys_link()
308 return dev->link; in ata_dev_phys_link()
309 if (!dev->devno) in ata_dev_phys_link()
310 return &ap->link; in ata_dev_phys_link()
311 return ap->slave_link; in ata_dev_phys_link()
316 * ata_force_cbl - force cable type according to libata.force
332 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_cbl()
335 if (fe->port != -1 && fe->port != ap->print_id) in ata_force_cbl()
338 if (fe->param.cbl == ATA_CBL_NONE) in ata_force_cbl()
341 ap->cbl = fe->param.cbl; in ata_force_cbl()
342 ata_port_notice(ap, "FORCE: cable set to %s\n", fe->param.name); in ata_force_cbl()
348 * ata_force_link_limits - force link limits according to libata.force
354 * the host link and all fan-out ports connected via PMP. If the
356 * first fan-out link not the host link. Device number 15 always
366 int linkno = link->pmp; in ata_force_link_limits()
372 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_link_limits()
375 if (fe->port != -1 && fe->port != link->ap->print_id) in ata_force_link_limits()
378 if (fe->device != -1 && fe->device != linkno) in ata_force_link_limits()
382 if (!did_spd && fe->param.spd_limit) { in ata_force_link_limits()
383 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; in ata_force_link_limits()
385 fe->param.name); in ata_force_link_limits()
390 if (fe->param.lflags_on) { in ata_force_link_limits()
391 link->flags |= fe->param.lflags_on; in ata_force_link_limits()
393 "FORCE: link flag 0x%x forced -> 0x%x\n", in ata_force_link_limits()
394 fe->param.lflags_on, link->flags); in ata_force_link_limits()
396 if (fe->param.lflags_off) { in ata_force_link_limits()
397 link->flags &= ~fe->param.lflags_off; in ata_force_link_limits()
399 "FORCE: link flag 0x%x cleared -> 0x%x\n", in ata_force_link_limits()
400 fe->param.lflags_off, link->flags); in ata_force_link_limits()
406 * ata_force_xfermask - force xfermask according to libata.force
418 int devno = dev->link->pmp + dev->devno; in ata_force_xfermask()
423 if (ata_is_host_link(dev->link)) in ata_force_xfermask()
426 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_xfermask()
430 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_xfermask()
433 if (fe->device != -1 && fe->device != devno && in ata_force_xfermask()
434 fe->device != alt_devno) in ata_force_xfermask()
437 if (!fe->param.xfer_mask) in ata_force_xfermask()
440 ata_unpack_xfermask(fe->param.xfer_mask, in ata_force_xfermask()
443 dev->udma_mask = udma_mask; in ata_force_xfermask()
445 dev->udma_mask = 0; in ata_force_xfermask()
446 dev->mwdma_mask = mwdma_mask; in ata_force_xfermask()
448 dev->udma_mask = 0; in ata_force_xfermask()
449 dev->mwdma_mask = 0; in ata_force_xfermask()
450 dev->pio_mask = pio_mask; in ata_force_xfermask()
454 fe->param.name); in ata_force_xfermask()
460 * ata_force_horkage - force horkage according to libata.force
472 int devno = dev->link->pmp + dev->devno; in ata_force_horkage()
477 if (ata_is_host_link(dev->link)) in ata_force_horkage()
483 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_horkage()
486 if (fe->device != -1 && fe->device != devno && in ata_force_horkage()
487 fe->device != alt_devno) in ata_force_horkage()
490 if (!(~dev->horkage & fe->param.horkage_on) && in ata_force_horkage()
491 !(dev->horkage & fe->param.horkage_off)) in ata_force_horkage()
494 dev->horkage |= fe->param.horkage_on; in ata_force_horkage()
495 dev->horkage &= ~fe->param.horkage_off; in ata_force_horkage()
498 fe->param.name); in ata_force_horkage()
508 * atapi_cmd_type - Determine ATAPI command type from SCSI opcode
577 * ata_set_rwcmd_protocol - set taskfile r/w command and protocol
581 * Examine the device configuration and tf->flags to determine
594 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; in ata_set_rwcmd_protocol()
595 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; in ata_set_rwcmd_protocol()
596 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; in ata_set_rwcmd_protocol()
598 if (dev->flags & ATA_DFLAG_PIO) { in ata_set_rwcmd_protocol()
599 tf->protocol = ATA_PROT_PIO; in ata_set_rwcmd_protocol()
600 index = dev->multi_count ? 0 : 8; in ata_set_rwcmd_protocol()
601 } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { in ata_set_rwcmd_protocol()
603 tf->protocol = ATA_PROT_PIO; in ata_set_rwcmd_protocol()
604 index = dev->multi_count ? 0 : 8; in ata_set_rwcmd_protocol()
606 tf->protocol = ATA_PROT_DMA; in ata_set_rwcmd_protocol()
614 tf->command = cmd; in ata_set_rwcmd_protocol()
620 * ata_tf_read_block - Read block address from ATA taskfile
628 * three address formats - LBA, LBA48 and CHS. tf->protocol and
638 if (tf->flags & ATA_TFLAG_LBA) { in ata_tf_read_block()
639 if (tf->flags & ATA_TFLAG_LBA48) { in ata_tf_read_block()
640 block |= (u64)tf->hob_lbah << 40; in ata_tf_read_block()
641 block |= (u64)tf->hob_lbam << 32; in ata_tf_read_block()
642 block |= (u64)tf->hob_lbal << 24; in ata_tf_read_block()
644 block |= (tf->device & 0xf) << 24; in ata_tf_read_block()
646 block |= tf->lbah << 16; in ata_tf_read_block()
647 block |= tf->lbam << 8; in ata_tf_read_block()
648 block |= tf->lbal; in ata_tf_read_block()
652 cyl = tf->lbam | (tf->lbah << 8); in ata_tf_read_block()
653 head = tf->device & 0xf; in ata_tf_read_block()
654 sect = tf->lbal; in ata_tf_read_block()
662 block = (cyl * dev->heads + head) * dev->sectors + sect - 1; in ata_tf_read_block()
673 struct ata_taskfile *tf = &qc->tf; in ata_set_tf_cdl()
675 if (tf->protocol == ATA_PROT_NCQ) in ata_set_tf_cdl()
676 tf->auxiliary |= cdl; in ata_set_tf_cdl()
678 tf->feature |= cdl; in ata_set_tf_cdl()
685 qc->flags |= ATA_QCFLAG_HAS_CDL | ATA_QCFLAG_RESULT_TF; in ata_set_tf_cdl()
689 * ata_build_rw_tf - Build ATA taskfile for given read/write request
690 * @qc: Metadata associated with the taskfile to build
700 * Build ATA taskfile for the command @qc for read/write request described
705 * 0 on success, -ERANGE if the request is too large for @dev,
706 * -EINVAL if the request is invalid.
711 struct ata_taskfile *tf = &qc->tf; in ata_build_rw_tf()
712 struct ata_device *dev = qc->dev; in ata_build_rw_tf()
714 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_build_rw_tf()
715 tf->flags |= tf_flags; in ata_build_rw_tf()
720 return -ERANGE; in ata_build_rw_tf()
722 tf->protocol = ATA_PROT_NCQ; in ata_build_rw_tf()
723 tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; in ata_build_rw_tf()
725 if (tf->flags & ATA_TFLAG_WRITE) in ata_build_rw_tf()
726 tf->command = ATA_CMD_FPDMA_WRITE; in ata_build_rw_tf()
728 tf->command = ATA_CMD_FPDMA_READ; in ata_build_rw_tf()
730 tf->nsect = qc->hw_tag << 3; in ata_build_rw_tf()
731 tf->hob_feature = (n_block >> 8) & 0xff; in ata_build_rw_tf()
732 tf->feature = n_block & 0xff; in ata_build_rw_tf()
734 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
735 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
736 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
737 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
738 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
739 tf->lbal = block & 0xff; in ata_build_rw_tf()
741 tf->device = ATA_LBA; in ata_build_rw_tf()
742 if (tf->flags & ATA_TFLAG_FUA) in ata_build_rw_tf()
743 tf->device |= 1 << 7; in ata_build_rw_tf()
745 if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED && in ata_build_rw_tf()
747 tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; in ata_build_rw_tf()
749 if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) in ata_build_rw_tf()
752 } else if (dev->flags & ATA_DFLAG_LBA) { in ata_build_rw_tf()
753 tf->flags |= ATA_TFLAG_LBA; in ata_build_rw_tf()
755 if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) in ata_build_rw_tf()
758 /* Both FUA writes and a CDL index require 48-bit commands */ in ata_build_rw_tf()
759 if (!(tf->flags & ATA_TFLAG_FUA) && in ata_build_rw_tf()
760 !(qc->flags & ATA_QCFLAG_HAS_CDL) && in ata_build_rw_tf()
763 tf->device |= (block >> 24) & 0xf; in ata_build_rw_tf()
765 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_build_rw_tf()
766 return -ERANGE; in ata_build_rw_tf()
769 tf->flags |= ATA_TFLAG_LBA48; in ata_build_rw_tf()
771 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_build_rw_tf()
773 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
774 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
775 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
778 return -ERANGE; in ata_build_rw_tf()
782 return -EINVAL; in ata_build_rw_tf()
784 tf->nsect = n_block & 0xff; in ata_build_rw_tf()
786 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
787 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
788 tf->lbal = block & 0xff; in ata_build_rw_tf()
790 tf->device |= ATA_LBA; in ata_build_rw_tf()
795 /* The request -may- be too large for CHS addressing. */ in ata_build_rw_tf()
797 return -ERANGE; in ata_build_rw_tf()
800 return -EINVAL; in ata_build_rw_tf()
803 track = (u32)block / dev->sectors; in ata_build_rw_tf()
804 cyl = track / dev->heads; in ata_build_rw_tf()
805 head = track % dev->heads; in ata_build_rw_tf()
806 sect = (u32)block % dev->sectors + 1; in ata_build_rw_tf()
809 Cylinder: 0-65535 in ata_build_rw_tf()
810 Head: 0-15 in ata_build_rw_tf()
811 Sector: 1-255*/ in ata_build_rw_tf()
813 return -ERANGE; in ata_build_rw_tf()
815 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_build_rw_tf()
816 tf->lbal = sect; in ata_build_rw_tf()
817 tf->lbam = cyl; in ata_build_rw_tf()
818 tf->lbah = cyl >> 8; in ata_build_rw_tf()
819 tf->device |= head; in ata_build_rw_tf()
826 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
851 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
878 { -1, },
882 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
896 int highbit = fls(xfer_mask) - 1; in ata_xfer_mask2mode()
899 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mask2mode()
900 if (highbit >= ent->shift && highbit < ent->shift + ent->bits) in ata_xfer_mask2mode()
901 return ent->base + highbit - ent->shift; in ata_xfer_mask2mode()
907 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
922 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2mask()
923 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2mask()
924 return ((2 << (ent->shift + xfer_mode - ent->base)) - 1) in ata_xfer_mode2mask()
925 & ~((1 << ent->shift) - 1); in ata_xfer_mode2mask()
931 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
940 * Matching xfer_shift, -1 if no match found.
946 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2shift()
947 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2shift()
948 return ent->shift; in ata_xfer_mode2shift()
949 return -1; in ata_xfer_mode2shift()
954 * ata_mode_string - convert xfer_mask to string
993 highbit = fls(xfer_mask) - 1; in ata_mode_string()
1008 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) in sata_spd_string()
1010 return spd_str[spd - 1]; in sata_spd_string()
1014 * ata_dev_classify - determine device type based on ATA-spec signature
1034 * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate in ata_dev_classify()
1041 * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and in ata_dev_classify()
1047 * Unfortunately, WDC WD1600JS-62MHB5 (a hard drive) reports in ata_dev_classify()
1051 if (tf->lbam == 0 && tf->lbah == 0) in ata_dev_classify()
1054 if (tf->lbam == 0x14 && tf->lbah == 0xeb) in ata_dev_classify()
1057 if (tf->lbam == 0x69 && tf->lbah == 0x96) in ata_dev_classify()
1060 if (tf->lbam == 0x3c && tf->lbah == 0xc3) in ata_dev_classify()
1063 if (tf->lbam == 0xcd && tf->lbah == 0xab) in ata_dev_classify()
1071 * ata_id_string - Convert IDENTIFY DEVICE page into string
1078 * 16-bit chunks. Run through the string, and output each
1079 * 8-bit chunk linearly, regardless of platform.
1102 len -= 2; in ata_id_string()
1108 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
1126 ata_id_string(id, s, ofs, len - 1); in ata_id_c_string()
1128 p = s + strnlen(s, len - 1); in ata_id_c_string()
1129 while (p > s && p[-1] == ' ') in ata_id_c_string()
1130 p--; in ata_id_c_string()
1156 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; in ata_tf_to_lba48()
1157 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; in ata_tf_to_lba48()
1158 sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24; in ata_tf_to_lba48()
1159 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba48()
1160 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba48()
1161 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba48()
1170 sectors |= (tf->device & 0x0f) << 24; in ata_tf_to_lba()
1171 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba()
1172 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba()
1173 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba()
1179 * ata_read_native_max_address - Read native max address
1187 * 0 on success, -EACCES if command is aborted by the drive.
1188 * -EIO on other errors.
1194 int lba48 = ata_id_has_lba48(dev->id); in ata_read_native_max_address()
1216 return -EACCES; in ata_read_native_max_address()
1217 return -EIO; in ata_read_native_max_address()
1224 if (dev->horkage & ATA_HORKAGE_HPA_SIZE) in ata_read_native_max_address()
1225 (*max_sectors)--; in ata_read_native_max_address()
1230 * ata_set_max_sectors - Set max sectors
1237 * 0 on success, -EACCES if command is aborted or denied (due to
1238 * previous non-volatile SET_MAX) by the drive. -EIO on other
1245 int lba48 = ata_id_has_lba48(dev->id); in ata_set_max_sectors()
1247 new_sectors--; in ata_set_max_sectors()
1280 return -EACCES; in ata_set_max_sectors()
1281 return -EIO; in ata_set_max_sectors()
1288 * ata_hpa_resize - Resize a device with an HPA set
1296 * 0 on success, -errno on failure.
1301 bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA; in ata_hpa_resize()
1302 u64 sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1307 if ((dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) || in ata_hpa_resize()
1308 !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || in ata_hpa_resize()
1309 (dev->horkage & ATA_HORKAGE_BROKEN_HPA)) in ata_hpa_resize()
1318 if (rc == -EACCES || !unlock_hpa) { in ata_hpa_resize()
1321 dev->horkage |= ATA_HORKAGE_BROKEN_HPA; in ata_hpa_resize()
1324 if (rc == -EACCES) in ata_hpa_resize()
1330 dev->n_native_sectors = native_sectors; in ata_hpa_resize()
1352 if (rc == -EACCES) { in ata_hpa_resize()
1355 "device aborted resize (%llu -> %llu), skipping HPA handling\n", in ata_hpa_resize()
1358 dev->horkage |= ATA_HORKAGE_BROKEN_HPA; in ata_hpa_resize()
1363 /* re-read IDENTIFY data */ in ata_hpa_resize()
1367 "failed to re-read IDENTIFY data after HPA resizing\n"); in ata_hpa_resize()
1372 u64 new_sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1374 "HPA unlocked: %llu -> %llu, native %llu\n", in ata_hpa_resize()
1384 * ata_dump_id - IDENTIFY DEVICE info debugging output
1388 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1406 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1436 pio_mask = (2 << mode) - 1; in ata_id_xfermask()
1477 struct completion *waiting = qc->private_data; in ata_qc_complete_internal()
1483 * ata_exec_internal_sg - execute libata internal command
1509 struct ata_link *link = dev->link; in ata_exec_internal_sg()
1510 struct ata_port *ap = link->ap; in ata_exec_internal_sg()
1511 u8 command = tf->command; in ata_exec_internal_sg()
1523 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal_sg()
1527 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1534 qc->tag = ATA_TAG_INTERNAL; in ata_exec_internal_sg()
1535 qc->hw_tag = 0; in ata_exec_internal_sg()
1536 qc->scsicmd = NULL; in ata_exec_internal_sg()
1537 qc->ap = ap; in ata_exec_internal_sg()
1538 qc->dev = dev; in ata_exec_internal_sg()
1541 preempted_tag = link->active_tag; in ata_exec_internal_sg()
1542 preempted_sactive = link->sactive; in ata_exec_internal_sg()
1543 preempted_qc_active = ap->qc_active; in ata_exec_internal_sg()
1544 preempted_nr_active_links = ap->nr_active_links; in ata_exec_internal_sg()
1545 link->active_tag = ATA_TAG_POISON; in ata_exec_internal_sg()
1546 link->sactive = 0; in ata_exec_internal_sg()
1547 ap->qc_active = 0; in ata_exec_internal_sg()
1548 ap->nr_active_links = 0; in ata_exec_internal_sg()
1551 qc->tf = *tf; in ata_exec_internal_sg()
1553 memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); in ata_exec_internal_sg()
1556 if (tf->protocol == ATAPI_PROT_DMA && (dev->flags & ATA_DFLAG_DMADIR) && in ata_exec_internal_sg()
1558 qc->tf.feature |= ATAPI_DMADIR; in ata_exec_internal_sg()
1560 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_exec_internal_sg()
1561 qc->dma_dir = dma_dir; in ata_exec_internal_sg()
1567 buflen += sg->length; in ata_exec_internal_sg()
1570 qc->nbytes = buflen; in ata_exec_internal_sg()
1573 qc->private_data = &wait; in ata_exec_internal_sg()
1574 qc->complete_fn = ata_qc_complete_internal; in ata_exec_internal_sg()
1578 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1598 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal_sg()
1603 * cleaned up by ->post_internal_cmd(). in ata_exec_internal_sg()
1605 if (qc->flags & ATA_QCFLAG_ACTIVE) { in ata_exec_internal_sg()
1606 qc->err_mask |= AC_ERR_TIMEOUT; in ata_exec_internal_sg()
1614 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1618 if (ap->ops->post_internal_cmd) in ata_exec_internal_sg()
1619 ap->ops->post_internal_cmd(qc); in ata_exec_internal_sg()
1622 if (qc->flags & ATA_QCFLAG_EH) { in ata_exec_internal_sg()
1623 if (qc->result_tf.status & (ATA_ERR | ATA_DF)) in ata_exec_internal_sg()
1624 qc->err_mask |= AC_ERR_DEV; in ata_exec_internal_sg()
1626 if (!qc->err_mask) in ata_exec_internal_sg()
1627 qc->err_mask |= AC_ERR_OTHER; in ata_exec_internal_sg()
1629 if (qc->err_mask & ~AC_ERR_OTHER) in ata_exec_internal_sg()
1630 qc->err_mask &= ~AC_ERR_OTHER; in ata_exec_internal_sg()
1631 } else if (qc->tf.command == ATA_CMD_REQ_SENSE_DATA) { in ata_exec_internal_sg()
1632 qc->result_tf.status |= ATA_SENSE; in ata_exec_internal_sg()
1636 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal_sg()
1638 *tf = qc->result_tf; in ata_exec_internal_sg()
1639 err_mask = qc->err_mask; in ata_exec_internal_sg()
1642 link->active_tag = preempted_tag; in ata_exec_internal_sg()
1643 link->sactive = preempted_sactive; in ata_exec_internal_sg()
1644 ap->qc_active = preempted_qc_active; in ata_exec_internal_sg()
1645 ap->nr_active_links = preempted_nr_active_links; in ata_exec_internal_sg()
1647 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1656 * ata_exec_internal - execute libata internal command
1694 * ata_pio_need_iordy - check if iordy needed
1706 if (adev->link->ap->pflags & ATA_PFLAG_RESETTING) in ata_pio_need_iordy()
1711 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) in ata_pio_need_iordy()
1714 if (ata_id_is_cfa(adev->id) in ata_pio_need_iordy()
1715 && (adev->pio_mode == XFER_PIO_5 || adev->pio_mode == XFER_PIO_6)) in ata_pio_need_iordy()
1718 if (adev->pio_mode > XFER_PIO_2) in ata_pio_need_iordy()
1721 if (ata_id_has_iordy(adev->id)) in ata_pio_need_iordy()
1728 * ata_pio_mask_no_iordy - Return the non IORDY mask
1732 * -1 if no iordy mode is available.
1737 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ in ata_pio_mask_no_iordy()
1738 u16 pio = adev->id[ATA_ID_EIDE_PIO]; in ata_pio_mask_no_iordy()
1741 /* This is cycle times not frequency - watch the logic! */ in ata_pio_mask_no_iordy()
1751 * ata_do_dev_read_id - default ID read method
1769 * ata_dev_read_id - Read ID data from the specified device
1778 * for pre-ATA4 drives.
1787 * 0 on success, -errno otherwise.
1792 struct ata_port *ap = dev->link->ap; in ata_dev_read_id()
1816 rc = -ENODEV; in ata_dev_read_id()
1833 if (ap->ops->read_id) in ata_dev_read_id()
1834 err_mask = ap->ops->read_id(dev, &tf, (__le16 *)id); in ata_dev_read_id()
1841 return -ENOENT; in ata_dev_read_id()
1874 return -ENOENT; in ata_dev_read_id()
1877 rc = -EIO; in ata_dev_read_id()
1882 if (dev->horkage & ATA_HORKAGE_DUMP_ID) { in ata_dev_read_id()
1898 rc = -EINVAL; in ata_dev_read_id()
1904 if (ap->host->flags & ATA_HOST_IGNORE_ATA && in ata_dev_read_id()
1908 return -ENOENT; in ata_dev_read_id()
1918 * Drive powered-up in standby mode, and requires a specific in ata_dev_read_id()
1919 * SET_FEATURES spin-up subcommand before it will accept in ata_dev_read_id()
1924 rc = -EIO; in ata_dev_read_id()
1939 * The exact sequence expected by certain pre-ATA4 drives is: in ata_dev_read_id()
1952 rc = -EIO; in ata_dev_read_id()
1957 /* current CHS translation info (id[53-58]) might be in ata_dev_read_id()
1976 * ata_dev_power_set_standby - Set a device power mode to standby
1987 unsigned long ap_flags = dev->link->ap->flags; in ata_dev_power_set_standby()
1992 if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) in ata_dev_power_set_standby()
2022 * ata_dev_power_set_active - Set a device power mode to active
2026 * active power mode. For a spun-down HDD (standby or idle power mode),
2038 if (dev->flags & ATA_DFLAG_SLEEPING) in ata_dev_power_set_active()
2045 if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) in ata_dev_power_set_active()
2053 if (dev->flags & ATA_DFLAG_LBA) { in ata_dev_power_set_active()
2070 * ata_read_log_page - read a specific log page
2088 unsigned long ap_flags = dev->link->ap->flags; in ata_read_log_page()
2093 ata_dev_dbg(dev, "read log page - log 0x%x, page 0x%x\n", log, page); in ata_read_log_page()
2104 if (ata_dma_enabled(dev) && ata_id_has_read_log_dma_ext(dev->id) && in ata_read_log_page()
2105 !(dev->horkage & ATA_HORKAGE_NO_DMA_LOG)) { in ata_read_log_page()
2125 dev->horkage |= ATA_HORKAGE_NO_DMA_LOG; in ata_read_log_page()
2126 if (!ata_port_is_frozen(dev->link->ap)) in ata_read_log_page()
2139 struct ata_port *ap = dev->link->ap; in ata_log_supported()
2141 if (dev->horkage & ATA_HORKAGE_NO_LOG_DIR) in ata_log_supported()
2144 if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, ap->sector_buf, 1)) in ata_log_supported()
2146 return get_unaligned_le16(&ap->sector_buf[log * 2]); in ata_log_supported()
2151 struct ata_port *ap = dev->link->ap; in ata_identify_page_supported()
2154 if (dev->horkage & ATA_HORKAGE_NO_ID_DEV_LOG) in ata_identify_page_supported()
2160 * with ACS-3 (ATA version 10). Warn about the missing log in ata_identify_page_supported()
2163 if (ata_id_major_version(dev->id) >= 10) in ata_identify_page_supported()
2166 dev->horkage |= ATA_HORKAGE_NO_ID_DEV_LOG; in ata_identify_page_supported()
2174 err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf, in ata_identify_page_supported()
2179 for (i = 0; i < ap->sector_buf[8]; i++) { in ata_identify_page_supported()
2180 if (ap->sector_buf[9 + i] == page) in ata_identify_page_supported()
2195 if (dev->horkage & ATA_HORKAGE_1_5_GBPS) in ata_do_link_spd_horkage()
2200 target_limit = (1 << target) - 1; in ata_do_link_spd_horkage()
2203 if (plink->sata_spd_limit <= target_limit) in ata_do_link_spd_horkage()
2206 plink->sata_spd_limit = target_limit; in ata_do_link_spd_horkage()
2208 /* Request another EH round by returning -EAGAIN if link is in ata_do_link_spd_horkage()
2212 if (plink->sata_spd > target) { in ata_do_link_spd_horkage()
2215 return -EAGAIN; in ata_do_link_spd_horkage()
2222 struct ata_port *ap = dev->link->ap; in ata_dev_knobble()
2227 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); in ata_dev_knobble()
2232 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_send_recv()
2240 0, ap->sector_buf, 1); in ata_dev_config_ncq_send_recv()
2242 u8 *cmds = dev->ncq_send_recv_cmds; in ata_dev_config_ncq_send_recv()
2244 dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; in ata_dev_config_ncq_send_recv()
2245 memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE); in ata_dev_config_ncq_send_recv()
2247 if (dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) { in ata_dev_config_ncq_send_recv()
2257 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_non_data()
2266 0, ap->sector_buf, 1); in ata_dev_config_ncq_non_data()
2268 u8 *cmds = dev->ncq_non_data_cmds; in ata_dev_config_ncq_non_data()
2270 memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE); in ata_dev_config_ncq_non_data()
2276 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_prio()
2285 ap->sector_buf, in ata_dev_config_ncq_prio()
2290 if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) in ata_dev_config_ncq_prio()
2293 dev->flags |= ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2298 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLED; in ata_dev_config_ncq_prio()
2299 dev->flags &= ~ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2308 for (parent_dev = dev->tdev.parent; parent_dev != NULL; in ata_dev_check_adapter()
2309 parent_dev = parent_dev->parent) { in ata_dev_check_adapter()
2312 if (pcidev->vendor == vendor_id) in ata_dev_check_adapter()
2324 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq()
2325 int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); in ata_dev_config_ncq()
2329 if (!ata_id_has_ncq(dev->id)) { in ata_dev_config_ncq()
2335 if (dev->horkage & ATA_HORKAGE_NONCQ) { in ata_dev_config_ncq()
2340 if (dev->horkage & ATA_HORKAGE_NO_NCQ_ON_ATI && in ata_dev_config_ncq()
2346 if (ap->flags & ATA_FLAG_NCQ) { in ata_dev_config_ncq()
2347 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE); in ata_dev_config_ncq()
2348 dev->flags |= ATA_DFLAG_NCQ; in ata_dev_config_ncq()
2351 if (!(dev->horkage & ATA_HORKAGE_BROKEN_FPDMA_AA) && in ata_dev_config_ncq()
2352 (ap->flags & ATA_FLAG_FPDMA_AA) && in ata_dev_config_ncq()
2353 ata_id_has_fpdma_aa(dev->id)) { in ata_dev_config_ncq()
2361 dev->horkage |= ATA_HORKAGE_BROKEN_FPDMA_AA; in ata_dev_config_ncq()
2362 return -EIO; in ata_dev_config_ncq()
2374 if ((ap->flags & ATA_FLAG_FPDMA_AUX)) { in ata_dev_config_ncq()
2375 if (ata_id_has_ncq_send_and_recv(dev->id)) in ata_dev_config_ncq()
2377 if (ata_id_has_ncq_non_data(dev->id)) in ata_dev_config_ncq()
2379 if (ata_id_has_ncq_prio(dev->id)) in ata_dev_config_ncq()
2390 if (!ata_id_has_sense_reporting(dev->id)) in ata_dev_config_sense_reporting()
2393 if (ata_id_sense_reporting_enabled(dev->id)) in ata_dev_config_sense_reporting()
2406 struct ata_port *ap = dev->link->ap; in ata_dev_config_zac()
2408 u8 *identify_buf = ap->sector_buf; in ata_dev_config_zac()
2410 dev->zac_zones_optimal_open = U32_MAX; in ata_dev_config_zac()
2411 dev->zac_zones_optimal_nonseq = U32_MAX; in ata_dev_config_zac()
2412 dev->zac_zones_max_open = U32_MAX; in ata_dev_config_zac()
2415 * Always set the 'ZAC' flag for Host-managed devices. in ata_dev_config_zac()
2417 if (dev->class == ATA_DEV_ZAC) in ata_dev_config_zac()
2418 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2419 else if (ata_id_zoned_cap(dev->id) == 0x01) in ata_dev_config_zac()
2421 * Check for host-aware devices. in ata_dev_config_zac()
2423 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2425 if (!(dev->flags & ATA_DFLAG_ZAC)) in ata_dev_config_zac()
2435 * Read IDENTIFY DEVICE data log, page 9 (Zoned-device information) in ata_dev_config_zac()
2445 dev->zac_zoned_cap = (zoned_cap & 1); in ata_dev_config_zac()
2448 dev->zac_zones_optimal_open = (u32)opt_open; in ata_dev_config_zac()
2451 dev->zac_zones_optimal_nonseq = (u32)opt_nonseq; in ata_dev_config_zac()
2454 dev->zac_zones_max_open = (u32)max_open; in ata_dev_config_zac()
2460 struct ata_port *ap = dev->link->ap; in ata_dev_config_trusted()
2464 if (!ata_id_has_trusted(dev->id)) in ata_dev_config_trusted()
2474 ap->sector_buf, 1); in ata_dev_config_trusted()
2478 trusted_cap = get_unaligned_le64(&ap->sector_buf[40]); in ata_dev_config_trusted()
2486 dev->flags |= ATA_DFLAG_TRUSTED; in ata_dev_config_trusted()
2491 struct ata_port *ap = dev->link->ap; in ata_dev_config_cdl()
2496 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cdl()
2506 ap->sector_buf, 1); in ata_dev_config_cdl()
2511 val = get_unaligned_le64(&ap->sector_buf[168]); in ata_dev_config_cdl()
2524 val = get_unaligned_le64(&ap->sector_buf[8]); in ata_dev_config_cdl()
2532 if (!ata_id_has_ncq_autosense(dev->id)) { in ata_dev_config_cdl()
2544 ap->sector_buf, 1); in ata_dev_config_cdl()
2548 val = get_unaligned_le64(&ap->sector_buf[8]); in ata_dev_config_cdl()
2550 if (dev->flags & ATA_DFLAG_CDL_ENABLED) { in ata_dev_config_cdl()
2595 if (!ap->ncq_sense_buf) { in ata_dev_config_cdl()
2596 ap->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); in ata_dev_config_cdl()
2597 if (!ap->ncq_sense_buf) in ata_dev_config_cdl()
2605 err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1); in ata_dev_config_cdl()
2611 memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE); in ata_dev_config_cdl()
2612 dev->flags |= ATA_DFLAG_CDL; in ata_dev_config_cdl()
2617 dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); in ata_dev_config_cdl()
2618 kfree(ap->ncq_sense_buf); in ata_dev_config_cdl()
2619 ap->ncq_sense_buf = NULL; in ata_dev_config_cdl()
2624 const u16 *id = dev->id; in ata_dev_config_lba()
2629 dev->flags |= ATA_DFLAG_LBA; in ata_dev_config_lba()
2633 dev->flags |= ATA_DFLAG_LBA48; in ata_dev_config_lba()
2634 if (dev->n_sectors >= (1UL << 28) && in ata_dev_config_lba()
2636 dev->flags |= ATA_DFLAG_FLUSH_EXT; in ata_dev_config_lba()
2648 (unsigned long long)dev->n_sectors, in ata_dev_config_lba()
2649 dev->multi_count, lba_desc, ncq_desc); in ata_dev_config_lba()
2656 const u16 *id = dev->id; in ata_dev_config_chs()
2660 dev->cylinders = id[54]; in ata_dev_config_chs()
2661 dev->heads = id[55]; in ata_dev_config_chs()
2662 dev->sectors = id[56]; in ata_dev_config_chs()
2665 dev->cylinders = id[1]; in ata_dev_config_chs()
2666 dev->heads = id[3]; in ata_dev_config_chs()
2667 dev->sectors = id[6]; in ata_dev_config_chs()
2674 (unsigned long long)dev->n_sectors, in ata_dev_config_chs()
2675 dev->multi_count, dev->cylinders, in ata_dev_config_chs()
2676 dev->heads, dev->sectors); in ata_dev_config_chs()
2686 if (!(dev->flags & ATA_DFLAG_LBA48) || !ata_id_has_fua(dev->id)) in ata_dev_config_fua()
2690 if (!ata_ncq_supported(dev) || (dev->horkage & ATA_HORKAGE_NO_FUA)) in ata_dev_config_fua()
2693 dev->flags |= ATA_DFLAG_FUA; in ata_dev_config_fua()
2698 dev->flags &= ~ATA_DFLAG_FUA; in ata_dev_config_fua()
2703 u8 *sata_setting = dev->link->ap->sector_buf; in ata_dev_config_devslp()
2711 if (!ata_id_has_devslp(dev->id) || in ata_dev_config_devslp()
2722 dev->flags |= ATA_DFLAG_DEVSLP; in ata_dev_config_devslp()
2725 dev->devslp_timing[i] = sata_setting[j]; in ata_dev_config_devslp()
2737 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cpr()
2768 cpr_log->nr_cpr = nr_cpr; in ata_dev_config_cpr()
2771 cpr_log->cpr[i].num = desc[0]; in ata_dev_config_cpr()
2772 cpr_log->cpr[i].num_storage_elements = desc[1]; in ata_dev_config_cpr()
2773 cpr_log->cpr[i].start_lba = get_unaligned_le64(&desc[8]); in ata_dev_config_cpr()
2774 cpr_log->cpr[i].num_lbas = get_unaligned_le64(&desc[16]); in ata_dev_config_cpr()
2778 swap(dev->cpr_log, cpr_log); in ata_dev_config_cpr()
2785 if (!(dev->flags & ATA_DFLAG_FEATURES_MASK)) in ata_dev_print_features()
2790 dev->flags & ATA_DFLAG_FUA ? " FUA" : "", in ata_dev_print_features()
2791 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", in ata_dev_print_features()
2792 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", in ata_dev_print_features()
2793 dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", in ata_dev_print_features()
2794 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", in ata_dev_print_features()
2795 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "", in ata_dev_print_features()
2796 dev->flags & ATA_DFLAG_CDL ? " CDL" : "", in ata_dev_print_features()
2797 dev->cpr_log ? " CPR" : ""); in ata_dev_print_features()
2801 * ata_dev_configure - Configure the specified ATA/ATAPI device
2804 * Configure @dev according to @dev->id. Generic and low-level
2811 * 0 on success, -errno otherwise
2815 struct ata_port *ap = dev->link->ap; in ata_dev_configure()
2817 const u16 *id = dev->id; in ata_dev_configure()
2820 char revbuf[7]; /* XYZ-99\0 */ in ata_dev_configure()
2831 dev->horkage |= ata_dev_blacklisted(dev); in ata_dev_configure()
2834 if (dev->horkage & ATA_HORKAGE_DISABLE) { in ata_dev_configure()
2840 if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) && in ata_dev_configure()
2841 dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2853 /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */ in ata_dev_configure()
2854 if ((dev->horkage & ATA_HORKAGE_WD_BROKEN_LPM) && in ata_dev_configure()
2856 dev->horkage |= ATA_HORKAGE_NOLPM; in ata_dev_configure()
2858 if (ap->flags & ATA_FLAG_NO_LPM) in ata_dev_configure()
2859 dev->horkage |= ATA_HORKAGE_NOLPM; in ata_dev_configure()
2861 if (dev->horkage & ATA_HORKAGE_NOLPM) { in ata_dev_configure()
2863 dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER; in ata_dev_configure()
2884 /* initialize to-be-configured parameters */ in ata_dev_configure()
2885 dev->flags &= ~ATA_DFLAG_CFG_MASK; in ata_dev_configure()
2886 dev->max_sectors = 0; in ata_dev_configure()
2887 dev->cdb_len = 0; in ata_dev_configure()
2888 dev->n_sectors = 0; in ata_dev_configure()
2889 dev->cylinders = 0; in ata_dev_configure()
2890 dev->heads = 0; in ata_dev_configure()
2891 dev->sectors = 0; in ata_dev_configure()
2892 dev->multi_count = 0; in ata_dev_configure()
2903 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ in ata_dev_configure()
2904 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, in ata_dev_configure()
2907 ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, in ata_dev_configure()
2910 /* ATA-specific feature tests */ in ata_dev_configure()
2911 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in ata_dev_configure()
2919 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); in ata_dev_configure()
2926 dev->n_sectors = ata_id_n_sectors(id); in ata_dev_configure()
2929 if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) { in ata_dev_configure()
2930 unsigned int max = dev->id[47] & 0xff; in ata_dev_configure()
2931 unsigned int cnt = dev->id[59] & 0xff; in ata_dev_configure()
2935 dev->multi_count = cnt; in ata_dev_configure()
2959 dev->cdb_len = 32; in ata_dev_configure()
2965 /* ATAPI-specific feature tests */ in ata_dev_configure()
2966 else if (dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2975 rc = -EINVAL; in ata_dev_configure()
2978 dev->cdb_len = (unsigned int) rc; in ata_dev_configure()
2986 (ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && in ata_dev_configure()
2988 sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { in ata_dev_configure()
2997 dev->flags |= ATA_DFLAG_AN; in ata_dev_configure()
3002 if (ata_id_cdb_intr(dev->id)) { in ata_dev_configure()
3003 dev->flags |= ATA_DFLAG_CDB_INTR; in ata_dev_configure()
3007 if (atapi_dmadir || (dev->horkage & ATA_HORKAGE_ATAPI_DMADIR) || atapi_id_dmadir(dev->id)) { in ata_dev_configure()
3008 dev->flags |= ATA_DFLAG_DMADIR; in ata_dev_configure()
3012 if (ata_id_has_da(dev->id)) { in ata_dev_configure()
3013 dev->flags |= ATA_DFLAG_DA; in ata_dev_configure()
3028 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3029 if (dev->flags & ATA_DFLAG_LBA48) in ata_dev_configure()
3030 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3037 dev->udma_mask &= ATA_UDMA5; in ata_dev_configure()
3038 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3041 if ((dev->class == ATA_DEV_ATAPI) && in ata_dev_configure()
3043 dev->max_sectors = ATA_MAX_SECTORS_TAPE; in ata_dev_configure()
3044 dev->horkage |= ATA_HORKAGE_STUCK_ERR; in ata_dev_configure()
3047 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) in ata_dev_configure()
3048 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, in ata_dev_configure()
3049 dev->max_sectors); in ata_dev_configure()
3051 if (dev->horkage & ATA_HORKAGE_MAX_SEC_1024) in ata_dev_configure()
3052 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_1024, in ata_dev_configure()
3053 dev->max_sectors); in ata_dev_configure()
3055 if (dev->horkage & ATA_HORKAGE_MAX_SEC_LBA48) in ata_dev_configure()
3056 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3058 if (ap->ops->dev_config) in ata_dev_configure()
3059 ap->ops->dev_config(dev); in ata_dev_configure()
3061 if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { in ata_dev_configure()
3076 if ((dev->horkage & ATA_HORKAGE_FIRMWARE_WARN) && print_info) { in ata_dev_configure()
3088 * ata_cable_40wire - return 40 wire cable type
3102 * ata_cable_80wire - return 80 wire cable type
3116 * ata_cable_unknown - return unknown PATA cable.
3129 * ata_cable_ignore - return ignored PATA cable.
3142 * ata_cable_sata - return SATA cable type
3155 * sata_print_link_status - Print SATA link status
3183 * ata_dev_pair - return other device on cable
3192 struct ata_link *link = adev->link; in ata_dev_pair()
3193 struct ata_device *pair = &link->device[1 - adev->devno]; in ata_dev_pair()
3201 * sata_down_spd_limit - adjust SATA spd limit downward
3209 * If @spd_limit is non-zero, the speed is limited to equal to or
3226 return -EOPNOTSUPP; in sata_down_spd_limit()
3229 * If not, use cached value in link->sata_spd. in sata_down_spd_limit()
3235 spd = link->sata_spd; in sata_down_spd_limit()
3237 mask = link->sata_spd_limit; in sata_down_spd_limit()
3239 return -EINVAL; in sata_down_spd_limit()
3242 bit = fls(mask) - 1; in sata_down_spd_limit()
3255 mask &= (1 << (spd - 1)) - 1; in sata_down_spd_limit()
3256 else if (link->sata_spd) in sata_down_spd_limit()
3257 return -EINVAL; in sata_down_spd_limit()
3261 return -EINVAL; in sata_down_spd_limit()
3264 if (mask & ((1 << spd_limit) - 1)) in sata_down_spd_limit()
3265 mask &= (1 << spd_limit) - 1; in sata_down_spd_limit()
3267 bit = ffs(mask) - 1; in sata_down_spd_limit()
3272 link->sata_spd_limit = mask; in sata_down_spd_limit()
3282 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration
3303 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_timing_cycle2mode()
3304 if (ent->shift == xfer_shift) in ata_timing_cycle2mode()
3305 base_mode = ent->base; in ata_timing_cycle2mode()
3308 t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { in ata_timing_cycle2mode()
3314 this_cycle = t->cycle; in ata_timing_cycle2mode()
3317 this_cycle = t->udma; in ata_timing_cycle2mode()
3326 last_mode = t->mode; in ata_timing_cycle2mode()
3334 * ata_down_xfermask_limit - adjust dev xfer masks downward
3358 xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, in ata_down_xfermask_limit()
3359 dev->mwdma_mask, in ata_down_xfermask_limit()
3360 dev->udma_mask); in ata_down_xfermask_limit()
3365 highbit = fls(pio_mask) - 1; in ata_down_xfermask_limit()
3371 highbit = fls(udma_mask) - 1; in ata_down_xfermask_limit()
3374 return -ENOENT; in ata_down_xfermask_limit()
3376 highbit = fls(mwdma_mask) - 1; in ata_down_xfermask_limit()
3379 return -ENOENT; in ata_down_xfermask_limit()
3402 return -ENOENT; in ata_down_xfermask_limit()
3416 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, in ata_down_xfermask_limit()
3417 &dev->udma_mask); in ata_down_xfermask_limit()
3424 struct ata_port *ap = dev->link->ap; in ata_dev_set_mode()
3425 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_set_mode()
3426 const bool nosetxfer = dev->horkage & ATA_HORKAGE_NOSETXFER; in ata_dev_set_mode()
3432 dev->flags &= ~ATA_DFLAG_PIO; in ata_dev_set_mode()
3433 if (dev->xfer_shift == ATA_SHIFT_PIO) in ata_dev_set_mode()
3434 dev->flags |= ATA_DFLAG_PIO; in ata_dev_set_mode()
3436 if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id)) in ata_dev_set_mode()
3441 "NOSETXFER but PATA detected - can't " in ata_dev_set_mode()
3450 ehc->i.flags |= ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3452 ehc->i.flags &= ~ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3456 if (dev->xfer_shift == ATA_SHIFT_PIO) { in ata_dev_set_mode()
3458 if (ata_id_is_cfa(dev->id)) in ata_dev_set_mode()
3462 if (ata_id_major_version(dev->id) == 0 && in ata_dev_set_mode()
3463 dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3466 any kind of SET_XFERMODE request but support PIO0-2 in ata_dev_set_mode()
3468 if (!ata_id_has_iordy(dev->id) && dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3473 if (dev->xfer_shift == ATA_SHIFT_MWDMA && in ata_dev_set_mode()
3474 dev->dma_mode == XFER_MW_DMA_0 && in ata_dev_set_mode()
3475 (dev->id[63] >> 8) & 1) in ata_dev_set_mode()
3479 if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) in ata_dev_set_mode()
3490 dev->xfer_shift, (int)dev->xfer_mode); in ata_dev_set_mode()
3492 if (!(ehc->i.flags & ATA_EHI_QUIET) || in ata_dev_set_mode()
3493 ehc->i.flags & ATA_EHI_DID_HARDRESET) in ata_dev_set_mode()
3495 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), in ata_dev_set_mode()
3502 return -EIO; in ata_dev_set_mode()
3506 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
3524 struct ata_port *ap = link->ap; in ata_do_set_mode()
3534 if (dev->class == ATA_DEV_ATAPI) in ata_do_set_mode()
3536 else if (ata_id_is_cfa(dev->id)) in ata_do_set_mode()
3542 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); in ata_do_set_mode()
3545 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, in ata_do_set_mode()
3546 dev->udma_mask); in ata_do_set_mode()
3550 dev->pio_mode = ata_xfer_mask2mode(pio_mask); in ata_do_set_mode()
3551 dev->dma_mode = ata_xfer_mask2mode(dma_mask); in ata_do_set_mode()
3562 if (dev->pio_mode == 0xff) { in ata_do_set_mode()
3564 rc = -EINVAL; in ata_do_set_mode()
3568 dev->xfer_mode = dev->pio_mode; in ata_do_set_mode()
3569 dev->xfer_shift = ATA_SHIFT_PIO; in ata_do_set_mode()
3570 if (ap->ops->set_piomode) in ata_do_set_mode()
3571 ap->ops->set_piomode(ap, dev); in ata_do_set_mode()
3579 dev->xfer_mode = dev->dma_mode; in ata_do_set_mode()
3580 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); in ata_do_set_mode()
3581 if (ap->ops->set_dmamode) in ata_do_set_mode()
3582 ap->ops->set_dmamode(ap, dev); in ata_do_set_mode()
3595 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) in ata_do_set_mode()
3596 ap->host->simplex_claimed = ap; in ata_do_set_mode()
3606 * ata_wait_ready - wait for link to become ready
3612 * positive number if @link is ready, 0 if it isn't, -ENODEV if
3616 * Transient -ENODEV conditions are allowed for
3623 * 0 if @link is ready before @deadline; otherwise, -errno.
3633 if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN) in ata_wait_ready()
3642 WARN_ON(link == link->ap->slave_link); in ata_wait_ready()
3656 * -ENODEV could be transient. Ignore -ENODEV if link in ata_wait_ready()
3659 * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't in ata_wait_ready()
3666 if (ready == -ENODEV) { in ata_wait_ready()
3669 else if ((link->ap->flags & ATA_FLAG_SATA) && in ata_wait_ready()
3678 return -EBUSY; in ata_wait_ready()
3681 (deadline - now > 3 * HZ)) { in ata_wait_ready()
3688 ata_msleep(link->ap, 50); in ata_wait_ready()
3693 * ata_wait_after_reset - wait for link to become ready after reset
3704 * 0 if @link is ready before @deadline; otherwise, -errno.
3709 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); in ata_wait_after_reset()
3716 * ata_std_prereset - prepare for reset
3722 * that port, so prereset should be best-effort. It does its
3734 struct ata_port *ap = link->ap; in ata_std_prereset()
3735 struct ata_eh_context *ehc = &link->eh_context; in ata_std_prereset()
3740 if (ehc->i.action & ATA_EH_HARDRESET) in ata_std_prereset()
3744 if (ap->flags & ATA_FLAG_SATA) { in ata_std_prereset()
3747 if (rc && rc != -EOPNOTSUPP) in ata_std_prereset()
3755 ehc->i.action &= ~ATA_EH_SOFTRESET; in ata_std_prereset()
3762 * sata_std_hardreset - COMRESET w/o waiting or classification
3773 * 0 if link offline, -EAGAIN if link online, -errno on errors.
3778 const unsigned int *timing = sata_ehc_deb_timing(&link->eh_context); in sata_std_hardreset()
3784 return online ? -EAGAIN : rc; in sata_std_hardreset()
3789 * ata_std_postreset - standard postreset callback
3814 * ata_dev_same_device - Determine whether new ID matches configured device
3832 const u16 *old_id = dev->id; in ata_dev_same_device()
3836 if (dev->class != new_class) { in ata_dev_same_device()
3838 dev->class, new_class); in ata_dev_same_device()
3863 * ata_dev_reread_id - Re-read IDENTIFY data
3867 * Re-read IDENTIFY page and make sure @dev is still attached to
3878 unsigned int class = dev->class; in ata_dev_reread_id()
3879 u16 *id = (void *)dev->link->ap->sector_buf; in ata_dev_reread_id()
3889 return -ENODEV; in ata_dev_reread_id()
3891 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); in ata_dev_reread_id()
3896 * ata_dev_revalidate - Revalidate ATA device
3901 * Re-read IDENTIFY page, make sure @dev is still attached to the
3913 u64 n_sectors = dev->n_sectors; in ata_dev_revalidate()
3914 u64 n_native_sectors = dev->n_native_sectors; in ata_dev_revalidate()
3918 return -ENODEV; in ata_dev_revalidate()
3923 dev->class, new_class); in ata_dev_revalidate()
3924 rc = -ENODEV; in ata_dev_revalidate()
3928 /* re-read ID */ in ata_dev_revalidate()
3939 if (dev->class != ATA_DEV_ATA || !n_sectors || in ata_dev_revalidate()
3940 dev->n_sectors == n_sectors) in ata_dev_revalidate()
3946 (unsigned long long)dev->n_sectors); in ata_dev_revalidate()
3953 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3954 dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) { in ata_dev_revalidate()
3968 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3969 dev->n_sectors < n_sectors && n_sectors == n_native_sectors && in ata_dev_revalidate()
3970 !(dev->horkage & ATA_HORKAGE_BROKEN_HPA)) { in ata_dev_revalidate()
3975 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_dev_revalidate()
3976 rc = -EIO; in ata_dev_revalidate()
3978 rc = -ENODEV; in ata_dev_revalidate()
3981 dev->n_native_sectors = n_native_sectors; in ata_dev_revalidate()
3982 dev->n_sectors = n_sectors; in ata_dev_revalidate()
4003 { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA },
4004 { "CRD-8400B", NULL, ATA_HORKAGE_NODMA },
4005 { "CRD-848[02]B", NULL, ATA_HORKAGE_NODMA },
4006 { "CRD-84", NULL, ATA_HORKAGE_NODMA },
4008 { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA },
4009 { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA },
4010 { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA },
4011 { "HITACHI CDR-8[34]35",NULL, ATA_HORKAGE_NODMA },
4012 { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA },
4013 { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA },
4014 { "CD-532E-A", NULL, ATA_HORKAGE_NODMA },
4015 { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA },
4016 { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA },
4017 { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA },
4018 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA },
4019 { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA },
4020 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
4022 { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA },
4025 { "VRFDFC22048UCHC-TE*", NULL, ATA_HORKAGE_NODMA },
4029 { "ASMT109x- Config", NULL, ATA_HORKAGE_DISABLE },
4032 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 },
4033 { "QUANTUM DAT DAT72-000", NULL, ATA_HORKAGE_ATAPI_MOD16_DMA },
4047 { "LITEON CX1-JB*-HP", NULL, ATA_HORKAGE_MAX_SEC_1024 },
4048 { "LITEON EP1-*", NULL, ATA_HORKAGE_MAX_SEC_1024 },
4054 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ },
4055 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ },
4066 { "ST31500341AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4069 { "ST31000333AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4072 { "ST3640[36]23AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4075 { "ST3320[68]13AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4080 { "ST1000LM024 HN-M101MBB", NULL, ATA_HORKAGE_BROKEN_FPDMA_AA |
4085 Windows driver .inf file - also several Linux problem reports */
4091 { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ },
4098 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
4099 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA },
4103 { "OCZ-VERTEX", "1.30", ATA_HORKAGE_BROKEN_HPA },
4113 { "TSSTcorp CDDVDW SH-S202[HJN]", "SB0[01]", ATA_HORKAGE_IVB },
4116 { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK },
4117 { "BUFFALO HD-QSU2/R5", NULL, ATA_HORKAGE_BRIDGE_OK },
4127 { "PIONEER DVD-RW DVRTD08", NULL, ATA_HORKAGE_NOSETXFER },
4128 { "PIONEER DVD-RW DVRTD08A", NULL, ATA_HORKAGE_NOSETXFER },
4129 { "PIONEER DVD-RW DVR-215", NULL, ATA_HORKAGE_NOSETXFER },
4130 { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER },
4131 { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER },
4134 { "PIONEER BD-RW BDR-207M", NULL, ATA_HORKAGE_NOLPM },
4135 { "PIONEER BD-RW BDR-205", NULL, ATA_HORKAGE_NOLPM },
4156 /* These specific Samsung models/firmware-revs do not handle LPM well */
4157 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM },
4159 { "SAMSUNG MZ7TD256HAFV-000L9", NULL, ATA_HORKAGE_NOLPM },
4160 { "SAMSUNG MZ7TE512HMHP-000L1", "EXT06L0Q", ATA_HORKAGE_NOLPM },
4228 * Some WD SATA-I drives spin up and down erratically when the link
4231 * known prefixes and is SATA-1. As a side effect LPM partial is
4236 { "WDC WD800JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4237 { "WDC WD1200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4238 { "WDC WD1600JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4239 { "WDC WD2000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4240 { "WDC WD2500JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4241 { "WDC WD3000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4242 { "WDC WD3200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4249 { "SATADOM-ML 3ME", NULL, ATA_HORKAGE_NO_LOG_DIR },
4254 { "OCZ-VERTEX*", NULL, ATA_HORKAGE_NO_FUA },
4267 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); in ata_dev_blacklisted()
4268 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); in ata_dev_blacklisted()
4270 while (ad->model_num) { in ata_dev_blacklisted()
4271 if (glob_match(ad->model_num, model_num)) { in ata_dev_blacklisted()
4272 if (ad->model_rev == NULL) in ata_dev_blacklisted()
4273 return ad->horkage; in ata_dev_blacklisted()
4274 if (glob_match(ad->model_rev, model_rev)) in ata_dev_blacklisted()
4275 return ad->horkage; in ata_dev_blacklisted()
4285 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO) in ata_dma_blacklisted()
4288 if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && in ata_dma_blacklisted()
4289 (dev->flags & ATA_DFLAG_CDB_INTR)) in ata_dma_blacklisted()
4291 return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0; in ata_dma_blacklisted()
4295 * ata_is_40wire - check drive side detection
4304 if (dev->horkage & ATA_HORKAGE_IVB) in ata_is_40wire()
4305 return ata_drive_40wire_relaxed(dev->id); in ata_is_40wire()
4306 return ata_drive_40wire(dev->id); in ata_is_40wire()
4310 * cable_is_40wire - 40/80/SATA decider
4315 * there is a good case for setting ap->cbl to the result when
4328 if (ap->cbl == ATA_CBL_PATA40) in cable_is_40wire()
4332 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) in cable_is_40wire()
4335 /* If the system is known to be 40 wire short cable (eg in cable_is_40wire()
4339 if (ap->cbl == ATA_CBL_PATA40_SHORT) in cable_is_40wire()
4346 * - in many setups only the one drive (slave if present) will in cable_is_40wire()
4348 * - if you have a non detect capable drive you don't want it in cable_is_40wire()
4361 * ata_dev_xfermask - Compute supported xfermask of the given device
4365 * dev->*_mask. This function is responsible for applying all
4374 struct ata_link *link = dev->link; in ata_dev_xfermask()
4375 struct ata_port *ap = link->ap; in ata_dev_xfermask()
4376 struct ata_host *host = ap->host; in ata_dev_xfermask()
4380 xfer_mask = ata_pack_xfermask(ap->pio_mask, in ata_dev_xfermask()
4381 ap->mwdma_mask, ap->udma_mask); in ata_dev_xfermask()
4384 xfer_mask &= ata_pack_xfermask(dev->pio_mask, in ata_dev_xfermask()
4385 dev->mwdma_mask, dev->udma_mask); in ata_dev_xfermask()
4386 xfer_mask &= ata_id_xfermask(dev->id); in ata_dev_xfermask()
4405 if ((host->flags & ATA_HOST_SIMPLEX) && in ata_dev_xfermask()
4406 host->simplex_claimed && host->simplex_claimed != ap) { in ata_dev_xfermask()
4412 if (ap->flags & ATA_FLAG_NO_IORDY) in ata_dev_xfermask()
4415 if (ap->ops->mode_filter) in ata_dev_xfermask()
4416 xfer_mask = ap->ops->mode_filter(dev, xfer_mask); in ata_dev_xfermask()
4430 "limited to UDMA/33 due to 40-wire cable\n"); in ata_dev_xfermask()
4434 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, in ata_dev_xfermask()
4435 &dev->mwdma_mask, &dev->udma_mask); in ata_dev_xfermask()
4439 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
4442 * Issue SET FEATURES - XFER MODE command to device @dev
4456 /* set up set-features taskfile */ in ata_dev_set_xfermode()
4457 ata_dev_dbg(dev, "set features - xfer mode\n"); in ata_dev_set_xfermode()
4459 /* Some controllers and ATAPI devices show flaky interrupt in ata_dev_set_xfermode()
4469 tf.nsect = dev->xfer_mode; in ata_dev_set_xfermode()
4470 /* If the device has IORDY and the controller does not - turn it off */ in ata_dev_set_xfermode()
4471 else if (ata_id_has_iordy(dev->id)) in ata_dev_set_xfermode()
4473 else /* In the ancient relic department - skip all of this */ in ata_dev_set_xfermode()
4477 * On some disks, this command causes spin-up, so we need longer in ata_dev_set_xfermode()
4484 * ata_dev_set_feature - Issue SET FEATURES
4502 /* set up set-features taskfile */ in ata_dev_set_feature()
4521 * ata_dev_init_params - Issue INIT DEV PARAMS command
4538 /* Number of sectors per track 1-255. Number of heads 1-16 */ in ata_dev_init_params()
4550 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ in ata_dev_init_params()
4563 * atapi_check_dma - Check whether ATAPI DMA can be supported
4566 * Allow low-level driver to filter ATA PACKET commands, returning
4578 struct ata_port *ap = qc->ap; in atapi_check_dma()
4583 if (!(qc->dev->horkage & ATA_HORKAGE_ATAPI_MOD16_DMA) && in atapi_check_dma()
4584 unlikely(qc->nbytes & 15)) in atapi_check_dma()
4587 if (ap->ops->check_atapi_dma) in atapi_check_dma()
4588 return ap->ops->check_atapi_dma(qc); in atapi_check_dma()
4594 * ata_std_qc_defer - Check whether a qc needs to be deferred
4597 * Non-NCQ commands cannot run with any other command, NCQ or
4610 struct ata_link *link = qc->dev->link; in ata_std_qc_defer()
4612 if (ata_is_ncq(qc->tf.protocol)) { in ata_std_qc_defer()
4613 if (!ata_tag_valid(link->active_tag)) in ata_std_qc_defer()
4616 if (!ata_tag_valid(link->active_tag) && !link->sactive) in ata_std_qc_defer()
4631 * ata_sg_init - Associate command with scatter-gather table.
4633 * @sg: Scatter-gather table.
4636 * Initialize the data-related elements of queued_cmd @qc
4637 * to point to a scatter-gather table @sg, containing @n_elem
4646 qc->sg = sg; in ata_sg_init()
4647 qc->n_elem = n_elem; in ata_sg_init()
4648 qc->cursg = qc->sg; in ata_sg_init()
4654 * ata_sg_clean - Unmap DMA memory associated with command
4664 struct ata_port *ap = qc->ap; in ata_sg_clean()
4665 struct scatterlist *sg = qc->sg; in ata_sg_clean()
4666 int dir = qc->dma_dir; in ata_sg_clean()
4670 if (qc->n_elem) in ata_sg_clean()
4671 dma_unmap_sg(ap->dev, sg, qc->orig_n_elem, dir); in ata_sg_clean()
4673 qc->flags &= ~ATA_QCFLAG_DMAMAP; in ata_sg_clean()
4674 qc->sg = NULL; in ata_sg_clean()
4678 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
4679 * @qc: Command with scatter-gather table to be mapped.
4681 * DMA-map the scatter-gather table associated with queued_cmd @qc.
4692 struct ata_port *ap = qc->ap; in ata_sg_setup()
4695 n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); in ata_sg_setup()
4697 return -1; in ata_sg_setup()
4699 qc->orig_n_elem = qc->n_elem; in ata_sg_setup()
4700 qc->n_elem = n_elem; in ata_sg_setup()
4701 qc->flags |= ATA_QCFLAG_DMAMAP; in ata_sg_setup()
4709 static inline int ata_sg_setup(struct ata_queued_cmd *qc) { return -1; } in ata_sg_setup()
4714 * swap_buf_le16 - swap halves of 16-bit words in place
4716 * @buf_words: Number of 16-bit words in buffer.
4718 * Swap halves of 16-bit words if needed to convert from
4719 * little-endian byte order to native cpu byte order, or
4720 * vice-versa.
4736 * ata_qc_free - free unused ata_queued_cmd
4747 qc->flags = 0; in ata_qc_free()
4748 if (ata_tag_valid(qc->tag)) in ata_qc_free()
4749 qc->tag = ATA_TAG_POISON; in ata_qc_free()
4758 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)); in __ata_qc_complete()
4759 ap = qc->ap; in __ata_qc_complete()
4760 link = qc->dev->link; in __ata_qc_complete()
4762 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) in __ata_qc_complete()
4766 if (ata_is_ncq(qc->tf.protocol)) { in __ata_qc_complete()
4767 link->sactive &= ~(1 << qc->hw_tag); in __ata_qc_complete()
4768 if (!link->sactive) in __ata_qc_complete()
4769 ap->nr_active_links--; in __ata_qc_complete()
4771 link->active_tag = ATA_TAG_POISON; in __ata_qc_complete()
4772 ap->nr_active_links--; in __ata_qc_complete()
4776 if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && in __ata_qc_complete()
4777 ap->excl_link == link)) in __ata_qc_complete()
4778 ap->excl_link = NULL; in __ata_qc_complete()
4784 qc->flags &= ~ATA_QCFLAG_ACTIVE; in __ata_qc_complete()
4785 ap->qc_active &= ~(1ULL << qc->tag); in __ata_qc_complete()
4788 qc->complete_fn(qc); in __ata_qc_complete()
4793 struct ata_port *ap = qc->ap; in fill_result_tf()
4795 qc->result_tf.flags = qc->tf.flags; in fill_result_tf()
4796 ap->ops->qc_fill_rtf(qc); in fill_result_tf()
4801 struct ata_device *dev = qc->dev; in ata_verify_xfer()
4803 if (!ata_is_data(qc->tf.protocol)) in ata_verify_xfer()
4806 if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) in ata_verify_xfer()
4809 dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; in ata_verify_xfer()
4813 * ata_qc_complete - Complete an active ATA command
4817 * completed, with either an ok or not-ok status.
4829 struct ata_port *ap = qc->ap; in ata_qc_complete()
4830 struct ata_device *dev = qc->dev; in ata_qc_complete()
4831 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_qc_complete()
4834 ledtrig_disk_activity(!!(qc->tf.flags & ATA_TFLAG_WRITE)); in ata_qc_complete()
4844 if (unlikely(qc->err_mask)) in ata_qc_complete()
4845 qc->flags |= ATA_QCFLAG_EH; in ata_qc_complete()
4851 if (unlikely(ata_tag_internal(qc->tag))) { in ata_qc_complete()
4858 /* Non-internal qc has failed. Fill the result TF and summon EH. */ in ata_qc_complete()
4859 if (unlikely(qc->flags & ATA_QCFLAG_EH)) { in ata_qc_complete()
4869 if (qc->flags & ATA_QCFLAG_RESULT_TF) in ata_qc_complete()
4880 if (qc->flags & ATA_QCFLAG_HAS_CDL && in ata_qc_complete()
4881 qc->result_tf.status & ATA_SENSE) { in ata_qc_complete()
4883 * Tell SCSI EH to not overwrite scmd->result even if this in ata_qc_complete()
4886 qc->scsicmd->flags |= SCMD_FORCE_EH_SUCCESS; in ata_qc_complete()
4887 qc->flags |= ATA_QCFLAG_EH_SUCCESS_CMD; in ata_qc_complete()
4888 ehi->dev_action[dev->devno] |= ATA_EH_GET_SUCCESS_SENSE; in ata_qc_complete()
4894 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_qc_complete()
4899 /* Some commands need post-processing after successful completion. */ in ata_qc_complete()
4900 switch (qc->tf.command) { in ata_qc_complete()
4902 if (qc->tf.feature != SETFEATURES_WC_ON && in ata_qc_complete()
4903 qc->tf.feature != SETFEATURES_WC_OFF && in ata_qc_complete()
4904 qc->tf.feature != SETFEATURES_RA_ON && in ata_qc_complete()
4905 qc->tf.feature != SETFEATURES_RA_OFF) in ata_qc_complete()
4911 ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; in ata_qc_complete()
4916 dev->flags |= ATA_DFLAG_SLEEPING; in ata_qc_complete()
4920 if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) in ata_qc_complete()
4928 * ata_qc_get_active - get bitmask of active qcs
4939 u64 qc_active = ap->qc_active; in ata_qc_get_active()
4952 * ata_qc_issue - issue taskfile to device
4956 * This includes mapping the data into a DMA-able
4965 struct ata_port *ap = qc->ap; in ata_qc_issue()
4966 struct ata_link *link = qc->dev->link; in ata_qc_issue()
4967 u8 prot = qc->tf.protocol; in ata_qc_issue()
4969 /* Make sure only one non-NCQ command is outstanding. */ in ata_qc_issue()
4970 WARN_ON_ONCE(ata_tag_valid(link->active_tag)); in ata_qc_issue()
4973 WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag)); in ata_qc_issue()
4975 if (!link->sactive) in ata_qc_issue()
4976 ap->nr_active_links++; in ata_qc_issue()
4977 link->sactive |= 1 << qc->hw_tag; in ata_qc_issue()
4979 WARN_ON_ONCE(link->sactive); in ata_qc_issue()
4981 ap->nr_active_links++; in ata_qc_issue()
4982 link->active_tag = qc->tag; in ata_qc_issue()
4985 qc->flags |= ATA_QCFLAG_ACTIVE; in ata_qc_issue()
4986 ap->qc_active |= 1ULL << qc->tag; in ata_qc_issue()
4990 * non-zero sg if the command is a data command. in ata_qc_issue()
4992 if (ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)) in ata_qc_issue()
4996 (ap->flags & ATA_FLAG_PIO_DMA))) in ata_qc_issue()
5001 if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { in ata_qc_issue()
5002 link->eh_info.action |= ATA_EH_RESET; in ata_qc_issue()
5003 ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); in ata_qc_issue()
5009 qc->err_mask |= ap->ops->qc_prep(qc); in ata_qc_issue()
5010 if (unlikely(qc->err_mask)) in ata_qc_issue()
5013 qc->err_mask |= ap->ops->qc_issue(qc); in ata_qc_issue()
5014 if (unlikely(qc->err_mask)) in ata_qc_issue()
5019 qc->err_mask |= AC_ERR_SYSTEM; in ata_qc_issue()
5025 * ata_phys_link_online - test whether the given link is online
5049 * ata_phys_link_offline - test whether the given link is offline
5073 * ata_link_online - test whether the given link is online
5090 struct ata_link *slave = link->ap->slave_link; in ata_link_online()
5100 * ata_link_offline - test whether the given link is offline
5117 struct ata_link *slave = link->ap->slave_link; in ata_link_offline()
5134 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5140 if (ap->pflags & ATA_PFLAG_PM_PENDING) { in ata_port_request_pm()
5141 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5143 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5147 ap->pm_mesg = mesg; in ata_port_request_pm()
5148 ap->pflags |= ATA_PFLAG_PM_PENDING; in ata_port_request_pm()
5150 link->eh_info.action |= action; in ata_port_request_pm()
5151 link->eh_info.flags |= ehi_flags; in ata_port_request_pm()
5156 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5181 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_suspend()
5194 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_suspend_async()
5254 * So the idle callback here will not proceed to suspend if a non-ZPODD capable
5265 if (adev->class == ATA_DEV_ATAPI && in ata_port_runtime_idle()
5267 return -EBUSY; in ata_port_runtime_idle()
5299 * and need to resume ata devices at the domain level, not the per-port
5316 * ata_host_suspend - suspend host
5324 host->dev->power.power_state = mesg; in ata_host_suspend()
5329 * ata_host_resume - resume host
5336 host->dev->power.power_state = PMSG_ON; in ata_host_resume()
5349 * ata_dev_init - Initialize an ata_device structure
5360 struct ata_port *ap = link->ap; in ata_dev_init()
5364 link->sata_spd_limit = link->hw_sata_spd_limit; in ata_dev_init()
5365 link->sata_spd = 0; in ata_dev_init()
5367 /* High bits of dev->flags are used to record warm plug in ata_dev_init()
5371 spin_lock_irqsave(ap->lock, flags); in ata_dev_init()
5372 dev->flags &= ~ATA_DFLAG_INIT_MASK; in ata_dev_init()
5373 dev->horkage = 0; in ata_dev_init()
5374 spin_unlock_irqrestore(ap->lock, flags); in ata_dev_init()
5377 ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); in ata_dev_init()
5378 dev->pio_mask = UINT_MAX; in ata_dev_init()
5379 dev->mwdma_mask = UINT_MAX; in ata_dev_init()
5380 dev->udma_mask = UINT_MAX; in ata_dev_init()
5384 * ata_link_init - Initialize an ata_link structure
5400 ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); in ata_link_init()
5402 link->ap = ap; in ata_link_init()
5403 link->pmp = pmp; in ata_link_init()
5404 link->active_tag = ATA_TAG_POISON; in ata_link_init()
5405 link->hw_sata_spd_limit = UINT_MAX; in ata_link_init()
5409 struct ata_device *dev = &link->device[i]; in ata_link_init()
5411 dev->link = link; in ata_link_init()
5412 dev->devno = dev - link->device; in ata_link_init()
5414 dev->gtf_filter = ata_acpi_gtf_filter; in ata_link_init()
5421 * sata_link_init_spd - Initialize link->sata_spd_limit
5424 * Initialize ``link->[hw_]sata_spd_limit`` to the currently
5431 * 0 on success, -errno on failure.
5438 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); in sata_link_init_spd()
5442 spd = (link->saved_scontrol >> 4) & 0xf; in sata_link_init_spd()
5444 link->hw_sata_spd_limit &= (1 << spd) - 1; in sata_link_init_spd()
5448 link->sata_spd_limit = link->hw_sata_spd_limit; in sata_link_init_spd()
5454 * ata_port_alloc - allocate and initialize basic ATA port resources
5473 ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; in ata_port_alloc()
5474 ap->lock = &host->lock; in ata_port_alloc()
5475 ap->print_id = -1; in ata_port_alloc()
5476 ap->local_port_no = -1; in ata_port_alloc()
5477 ap->host = host; in ata_port_alloc()
5478 ap->dev = host->dev; in ata_port_alloc()
5480 mutex_init(&ap->scsi_scan_mutex); in ata_port_alloc()
5481 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); in ata_port_alloc()
5482 INIT_DELAYED_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); in ata_port_alloc()
5483 INIT_LIST_HEAD(&ap->eh_done_q); in ata_port_alloc()
5484 init_waitqueue_head(&ap->eh_wait_q); in ata_port_alloc()
5485 init_completion(&ap->park_req_pending); in ata_port_alloc()
5486 timer_setup(&ap->fastdrain_timer, ata_eh_fastdrain_timerfn, in ata_port_alloc()
5489 ap->cbl = ATA_CBL_NONE; in ata_port_alloc()
5491 ata_link_init(ap, &ap->link, 0); in ata_port_alloc()
5494 ap->stats.unhandled_irq = 1; in ata_port_alloc()
5495 ap->stats.idle_irq = 1; in ata_port_alloc()
5507 kfree(ap->pmp_link); in ata_port_free()
5508 kfree(ap->slave_link); in ata_port_free()
5509 kfree(ap->ncq_sense_buf); in ata_port_free()
5519 for (i = 0; i < host->n_ports; i++) { in ata_devres_release()
5520 struct ata_port *ap = host->ports[i]; in ata_devres_release()
5525 if (ap->scsi_host) in ata_devres_release()
5526 scsi_host_put(ap->scsi_host); in ata_devres_release()
5539 for (i = 0; i < host->n_ports; i++) { in ata_host_release()
5540 ata_port_free(host->ports[i]); in ata_host_release()
5541 host->ports[i] = NULL; in ata_host_release()
5548 kref_get(&host->kref); in ata_host_get()
5553 kref_put(&host->kref, ata_host_release); in ata_host_put()
5558 * ata_host_alloc - allocate and init basic ATA host resources
5566 * @max_ports ports are allocated and host->n_ports is
5568 * host->n_ports before calling ata_host_register(). The unused
5604 spin_lock_init(&host->lock); in ata_host_alloc()
5605 mutex_init(&host->eh_mutex); in ata_host_alloc()
5606 host->dev = dev; in ata_host_alloc()
5607 host->n_ports = max_ports; in ata_host_alloc()
5608 kref_init(&host->kref); in ata_host_alloc()
5618 ap->port_no = i; in ata_host_alloc()
5619 host->ports[i] = ap; in ata_host_alloc()
5632 * ata_host_alloc_pinfo - alloc host and init with port_info array
5659 for (i = 0, j = 0; i < host->n_ports; i++) { in ata_host_alloc_pinfo()
5660 struct ata_port *ap = host->ports[i]; in ata_host_alloc_pinfo()
5665 ap->pio_mask = pi->pio_mask; in ata_host_alloc_pinfo()
5666 ap->mwdma_mask = pi->mwdma_mask; in ata_host_alloc_pinfo()
5667 ap->udma_mask = pi->udma_mask; in ata_host_alloc_pinfo()
5668 ap->flags |= pi->flags; in ata_host_alloc_pinfo()
5669 ap->link.flags |= pi->link_flags; in ata_host_alloc_pinfo()
5670 ap->ops = pi->port_ops; in ata_host_alloc_pinfo()
5672 if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) in ata_host_alloc_pinfo()
5673 host->ops = pi->port_ops; in ata_host_alloc_pinfo()
5685 WARN_ON(!(host->flags & ATA_HOST_STARTED)); in ata_host_stop()
5687 for (i = 0; i < host->n_ports; i++) { in ata_host_stop()
5688 struct ata_port *ap = host->ports[i]; in ata_host_stop()
5690 if (ap->ops->port_stop) in ata_host_stop()
5691 ap->ops->port_stop(ap); in ata_host_stop()
5694 if (host->ops->host_stop) in ata_host_stop()
5695 host->ops->host_stop(host); in ata_host_stop()
5699 * ata_finalize_port_ops - finalize ata_port_operations
5711 * methods and ->inherits is no longer necessary and cleared.
5723 void **end = (void **)&ops->inherits; in ata_finalize_port_ops()
5726 if (!ops || !ops->inherits) in ata_finalize_port_ops()
5731 for (cur = ops->inherits; cur; cur = cur->inherits) { in ata_finalize_port_ops()
5743 ops->inherits = NULL; in ata_finalize_port_ops()
5749 * ata_host_start - start and freeze ports of an ATA host
5753 * recorded in host->flags, so this function can be called
5755 * once. If host->ops is not initialized yet, it is set to the
5756 * first non-dummy port ops.
5762 * 0 if all ports are started successfully, -errno otherwise.
5770 if (host->flags & ATA_HOST_STARTED) in ata_host_start()
5773 ata_finalize_port_ops(host->ops); in ata_host_start()
5775 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5776 struct ata_port *ap = host->ports[i]; in ata_host_start()
5778 ata_finalize_port_ops(ap->ops); in ata_host_start()
5780 if (!host->ops && !ata_port_is_dummy(ap)) in ata_host_start()
5781 host->ops = ap->ops; in ata_host_start()
5783 if (ap->ops->port_stop) in ata_host_start()
5787 if (host->ops && host->ops->host_stop) in ata_host_start()
5793 return -ENOMEM; in ata_host_start()
5796 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5797 struct ata_port *ap = host->ports[i]; in ata_host_start()
5799 if (ap->ops->port_start) { in ata_host_start()
5800 rc = ap->ops->port_start(ap); in ata_host_start()
5802 if (rc != -ENODEV) in ata_host_start()
5803 dev_err(host->dev, in ata_host_start()
5813 devres_add(host->dev, start_dr); in ata_host_start()
5814 host->flags |= ATA_HOST_STARTED; in ata_host_start()
5818 while (--i >= 0) { in ata_host_start()
5819 struct ata_port *ap = host->ports[i]; in ata_host_start()
5821 if (ap->ops->port_stop) in ata_host_start()
5822 ap->ops->port_stop(ap); in ata_host_start()
5830 * ata_host_init - Initialize a host struct for sas (ipr, libsas)
5839 spin_lock_init(&host->lock); in ata_host_init()
5840 mutex_init(&host->eh_mutex); in ata_host_init()
5841 host->n_tags = ATA_MAX_QUEUE; in ata_host_init()
5842 host->dev = dev; in ata_host_init()
5843 host->ops = ops; in ata_host_init()
5844 kref_init(&host->kref); in ata_host_init()
5850 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_port_probe()
5854 spin_lock_irqsave(ap->lock, flags); in ata_port_probe()
5856 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_port_probe()
5857 ehi->action |= ATA_EH_RESET; in ata_port_probe()
5858 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; in ata_port_probe()
5860 ap->pflags &= ~ATA_PFLAG_INITIALIZING; in ata_port_probe()
5861 ap->pflags |= ATA_PFLAG_LOADING; in ata_port_probe()
5864 spin_unlock_irqrestore(ap->lock, flags); in ata_port_probe()
5879 if (!(ap->host->flags & ATA_HOST_PARALLEL_SCAN) && ap->port_no != 0) in async_port_probe()
5892 * ata_host_register - register initialized ATA host
5905 * 0 on success, -errno otherwise.
5911 host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE); in ata_host_register()
5914 if (!(host->flags & ATA_HOST_STARTED)) { in ata_host_register()
5915 dev_err(host->dev, "BUG: trying to register unstarted host\n"); in ata_host_register()
5917 return -EINVAL; in ata_host_register()
5924 for (i = host->n_ports; host->ports[i]; i++) in ata_host_register()
5925 ata_port_free(host->ports[i]); in ata_host_register()
5928 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5929 host->ports[i]->print_id = atomic_inc_return(&ata_print_id); in ata_host_register()
5930 host->ports[i]->local_port_no = i + 1; in ata_host_register()
5934 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5935 rc = ata_tport_add(host->dev,host->ports[i]); in ata_host_register()
5946 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5947 struct ata_port *ap = host->ports[i]; in ata_host_register()
5951 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) in ata_host_register()
5952 ap->cbl = ATA_CBL_SATA; in ata_host_register()
5955 sata_link_init_spd(&ap->link); in ata_host_register()
5956 if (ap->slave_link) in ata_host_register()
5957 sata_link_init_spd(ap->slave_link); in ata_host_register()
5959 /* print per-port info to dmesg */ in ata_host_register()
5960 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, in ata_host_register()
5961 ap->udma_mask); in ata_host_register()
5965 (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', in ata_host_register()
5967 ap->link.eh_info.desc); in ata_host_register()
5968 ata_ehi_clear_desc(&ap->link.eh_info); in ata_host_register()
5974 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5975 struct ata_port *ap = host->ports[i]; in ata_host_register()
5976 ap->cookie = async_schedule(async_port_probe, ap); in ata_host_register()
5982 while (--i >= 0) { in ata_host_register()
5983 ata_tport_delete(host->ports[i]); in ata_host_register()
5991 * ata_host_activate - start host, request IRQ and register it
5999 * LLDs perform three steps to activate the host - start host,
6011 * 0 on success, -errno otherwise.
6030 irq_desc = devm_kasprintf(host->dev, GFP_KERNEL, "%s[%s]", in ata_host_activate()
6031 dev_driver_string(host->dev), in ata_host_activate()
6032 dev_name(host->dev)); in ata_host_activate()
6034 return -ENOMEM; in ata_host_activate()
6036 rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, in ata_host_activate()
6041 for (i = 0; i < host->n_ports; i++) in ata_host_activate()
6042 ata_port_desc(host->ports[i], "irq %d", irq); in ata_host_activate()
6047 devm_free_irq(host->dev, irq, host); in ata_host_activate()
6054 * ata_port_detach - Detach ATA port in preparation of device removal
6073 mutex_lock(&ap->scsi_scan_mutex); in ata_port_detach()
6074 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6079 if (dev->sdev) { in ata_port_detach()
6080 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6081 scsi_remove_device(dev->sdev); in ata_port_detach()
6082 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6083 dev->sdev = NULL; in ata_port_detach()
6089 ap->pflags |= ATA_PFLAG_UNLOADING; in ata_port_detach()
6092 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6093 mutex_unlock(&ap->scsi_scan_mutex); in ata_port_detach()
6099 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED)); in ata_port_detach()
6101 cancel_delayed_work_sync(&ap->hotplug_task); in ata_port_detach()
6102 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_detach()
6111 if (ap->pmp_link) { in ata_port_detach()
6114 ata_tlink_delete(&ap->pmp_link[i]); in ata_port_detach()
6117 scsi_remove_host(ap->scsi_host); in ata_port_detach()
6122 * ata_host_detach - Detach all ports of an ATA host
6134 for (i = 0; i < host->n_ports; i++) { in ata_host_detach()
6136 async_synchronize_cookie(host->ports[i]->cookie + 1); in ata_host_detach()
6137 ata_port_detach(host->ports[i]); in ata_host_detach()
6148 * ata_pci_remove_one - PCI layer callback for device removal
6151 * PCI layer indicates to libata via this hook that hot-unplug or
6171 for (i = 0; i < host->n_ports; i++) { in ata_pci_shutdown_one()
6172 struct ata_port *ap = host->ports[i]; in ata_pci_shutdown_one()
6174 ap->pflags |= ATA_PFLAG_FROZEN; in ata_pci_shutdown_one()
6177 if (ap->ops->freeze) in ata_pci_shutdown_one()
6178 ap->ops->freeze(ap); in ata_pci_shutdown_one()
6181 if (ap->ops->port_stop) in ata_pci_shutdown_one()
6182 ap->ops->port_stop(ap); in ata_pci_shutdown_one()
6192 switch (bits->width) { in pci_test_config_bits()
6195 pci_read_config_byte(pdev, bits->reg, &tmp8); in pci_test_config_bits()
6201 pci_read_config_word(pdev, bits->reg, &tmp16); in pci_test_config_bits()
6207 pci_read_config_dword(pdev, bits->reg, &tmp32); in pci_test_config_bits()
6213 return -EINVAL; in pci_test_config_bits()
6216 tmp &= bits->mask; in pci_test_config_bits()
6218 return (tmp == bits->val) ? 1 : 0; in pci_test_config_bits()
6242 dev_err(&pdev->dev, in ata_pci_device_do_resume()
6279 * ata_platform_remove_one - Platform layer callback for device removal
6282 * Platform layer indicates to libata via this hook that hot-unplug or
6437 force_ent->device = simple_strtoul(p, &endp, 10); in ata_parse_force_one()
6440 return -EINVAL; in ata_parse_force_one()
6444 force_ent->port = simple_strtoul(id, &endp, 10); in ata_parse_force_one()
6447 return -EINVAL; in ata_parse_force_one()
6455 if (strncasecmp(val, fp->name, strlen(val))) in ata_parse_force_one()
6461 if (strcasecmp(val, fp->name) == 0) { in ata_parse_force_one()
6469 return -EINVAL; in ata_parse_force_one()
6473 return -EINVAL; in ata_parse_force_one()
6476 force_ent->param = *match_fp; in ata_parse_force_one()
6484 int last_port = -1, last_device = -1; in ata_parse_force_param()
6502 struct ata_force_ent te = { .port = -1, .device = -1 }; in ata_parse_force_param()
6512 if (te.port == -1) { in ata_parse_force_param()
6551 rc = -ENOMEM; in ata_init()
6582 * ata_msleep - ATA EH owner aware msleep
6589 * @ap->host will be allowed to own the EH while this task is
6597 bool owns_eh = ap && ap->host->eh_owner == current; in ata_msleep()
6615 * ata_wait_register - wait until register value changes
6617 * @reg: IO-mapped register
6625 * IO-mapped register @reg and tests for the following condition.