Lines Matching +full:ignore +full:- +full:power +full:- +full:on +full:- +full:sel
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
25 * Do not depend on ABI/API stability.
65 #include "libata-transport.h"
115 …ing cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst …
120 MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on [default])");
124 MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off [default], 1=on)");
128 MODULE_PARM_DESC(atapi_passthru16, "Enable ATA_16 passthru for ATAPI devices (0=off, 1=on [default]…
132 MODULE_PARM_DESC(fua, "FUA support (0=off [default], 1=on)");
136 MODULE_PARM_DESC(ignore_hpa, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full dis…
148 MODULE_PARM_DESC(noacpi, "Disable the use of ACPI in probe/suspend/resume (0=off [default], 1=on)");
152 MODULE_PARM_DESC(allow_tpm, "Permit the use of TPM commands (0=off [default], 1=on)");
156 MODULE_PARM_DESC(atapi_an, "Enable ATAPI AN media presence notification (0=0ff [default], 1=on)");
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()
683 * bit on completion. 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
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()
1035 * signatures for ATA and ATAPI devices attached on SerialATA, 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
1493 * command on entry and result on return. Timeout and error
1502 * Zero on success, AC_ERR_* mask on failure
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
1672 * Zero on success, AC_ERR_* mask on failure
1694 * ata_pio_need_iordy - check if iordy needed
1703 * lead to controller lock up on certain controllers if the in ata_pio_need_iordy()
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()
1713 /* CF spec. r4.1 Table 22 says no iordy on PIO5 and PIO6. */ 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()
1720 /* We turn it on when possible */ 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
1776 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
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()
1828 /* Device presence detection is unreliable on some 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()
1846 "IDENTIFY failed on device w/ SEMB sig, disabled\n"); 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()
1907 "host indicates ignore ATA devices, ignored\n"); 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()
1979 if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) in ata_dev_power_init_tf()
1983 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_dev_power_init_tf()
1984 tf->protocol = ATA_PROT_NODATA; in ata_dev_power_init_tf()
1988 tf->command = ATA_CMD_VERIFY; in ata_dev_power_init_tf()
1989 tf->nsect = 1; in ata_dev_power_init_tf()
1990 if (dev->flags & ATA_DFLAG_LBA) { in ata_dev_power_init_tf()
1991 tf->flags |= ATA_TFLAG_LBA; in ata_dev_power_init_tf()
1992 tf->device |= ATA_LBA; in ata_dev_power_init_tf()
1995 tf->lbal = 0x1; /* sect */ in ata_dev_power_init_tf()
1998 tf->command = ATA_CMD_STANDBYNOW1; in ata_dev_power_init_tf()
2016 ata_dev_err(dev, "Check power mode failed (err_mask=0x%x)\n", in ata_dev_power_is_active()
2025 ata_dev_dbg(dev, "Power mode: 0x%02x\n", tf.nsect); in ata_dev_power_is_active()
2032 * ata_dev_power_set_standby - Set a device power mode to standby
2035 * Issue a STANDBY IMMEDIATE command to set a device power mode to standby.
2043 unsigned long ap_flags = dev->link->ap->flags; in ata_dev_power_set_standby()
2048 if ((dev->flags & ATA_DFLAG_SLEEPING) || in ata_dev_power_set_standby()
2053 * Some odd clown BIOSes issue spindown on power off (ACPI S4 or S5) in ata_dev_power_set_standby()
2055 * if we are being called on shutdown. in ata_dev_power_set_standby()
2069 ata_dev_notice(dev, "Entering standby power mode\n"); in ata_dev_power_set_standby()
2078 * ata_dev_power_set_active - Set a device power mode to active
2082 * active power mode. For a spun-down HDD (standby or idle power mode),
2101 * Check the device power state & condition and force a spinup with in ata_dev_power_set_active()
2107 ata_dev_notice(dev, "Entering active power mode\n"); in ata_dev_power_set_active()
2116 * ata_read_log_page - read a specific log page
2129 * 0 on success, AC_ERR_* mask otherwise.
2134 unsigned long ap_flags = dev->link->ap->flags; in ata_read_log_page()
2139 ata_dev_dbg(dev, "read log page - log 0x%x, page 0x%x\n", log, page); in ata_read_log_page()
2142 * Return error without actually issuing the command on controllers in ata_read_log_page()
2143 * which e.g. lockup on a read log page. in ata_read_log_page()
2150 if (ata_dma_enabled(dev) && ata_id_has_read_log_dma_ext(dev->id) && in ata_read_log_page()
2151 !(dev->horkage & ATA_HORKAGE_NO_DMA_LOG)) { in ata_read_log_page()
2171 dev->horkage |= ATA_HORKAGE_NO_DMA_LOG; in ata_read_log_page()
2172 if (!ata_port_is_frozen(dev->link->ap)) in ata_read_log_page()
2185 struct ata_port *ap = dev->link->ap; in ata_log_supported()
2187 if (dev->horkage & ATA_HORKAGE_NO_LOG_DIR) in ata_log_supported()
2190 if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, ap->sector_buf, 1)) in ata_log_supported()
2192 return get_unaligned_le16(&ap->sector_buf[log * 2]); in ata_log_supported()
2197 struct ata_port *ap = dev->link->ap; in ata_identify_page_supported()
2200 if (dev->horkage & ATA_HORKAGE_NO_ID_DEV_LOG) in ata_identify_page_supported()
2206 * with ACS-3 (ATA version 10). Warn about the missing log in ata_identify_page_supported()
2209 if (ata_id_major_version(dev->id) >= 10) in ata_identify_page_supported()
2212 dev->horkage |= ATA_HORKAGE_NO_ID_DEV_LOG; in ata_identify_page_supported()
2220 err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf, in ata_identify_page_supported()
2225 for (i = 0; i < ap->sector_buf[8]; i++) { in ata_identify_page_supported()
2226 if (ap->sector_buf[9 + i] == page) in ata_identify_page_supported()
2241 if (dev->horkage & ATA_HORKAGE_1_5_GBPS) in ata_do_link_spd_horkage()
2246 target_limit = (1 << target) - 1; in ata_do_link_spd_horkage()
2248 /* if already on stricter limit, no need to push further */ in ata_do_link_spd_horkage()
2249 if (plink->sata_spd_limit <= target_limit) in ata_do_link_spd_horkage()
2252 plink->sata_spd_limit = target_limit; in ata_do_link_spd_horkage()
2254 /* Request another EH round by returning -EAGAIN if link is in ata_do_link_spd_horkage()
2258 if (plink->sata_spd > target) { in ata_do_link_spd_horkage()
2261 return -EAGAIN; in ata_do_link_spd_horkage()
2268 struct ata_port *ap = dev->link->ap; in ata_dev_knobble()
2273 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); in ata_dev_knobble()
2278 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_send_recv()
2286 0, ap->sector_buf, 1); in ata_dev_config_ncq_send_recv()
2288 u8 *cmds = dev->ncq_send_recv_cmds; in ata_dev_config_ncq_send_recv()
2290 dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; in ata_dev_config_ncq_send_recv()
2291 memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE); in ata_dev_config_ncq_send_recv()
2293 if (dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) { in ata_dev_config_ncq_send_recv()
2303 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_non_data()
2312 0, ap->sector_buf, 1); in ata_dev_config_ncq_non_data()
2314 u8 *cmds = dev->ncq_non_data_cmds; in ata_dev_config_ncq_non_data()
2316 memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE); in ata_dev_config_ncq_non_data()
2322 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_prio()
2331 ap->sector_buf, in ata_dev_config_ncq_prio()
2336 if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) in ata_dev_config_ncq_prio()
2339 dev->flags |= ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2344 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLED; in ata_dev_config_ncq_prio()
2345 dev->flags &= ~ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2354 for (parent_dev = dev->tdev.parent; parent_dev != NULL; in ata_dev_check_adapter()
2355 parent_dev = parent_dev->parent) { in ata_dev_check_adapter()
2358 if (pcidev->vendor == vendor_id) in ata_dev_check_adapter()
2370 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq()
2371 int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); in ata_dev_config_ncq()
2375 if (!ata_id_has_ncq(dev->id)) { in ata_dev_config_ncq()
2381 if (dev->horkage & ATA_HORKAGE_NONCQ) { in ata_dev_config_ncq()
2386 if (dev->horkage & ATA_HORKAGE_NO_NCQ_ON_ATI && in ata_dev_config_ncq()
2392 if (ap->flags & ATA_FLAG_NCQ) { in ata_dev_config_ncq()
2393 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE); in ata_dev_config_ncq()
2394 dev->flags |= ATA_DFLAG_NCQ; in ata_dev_config_ncq()
2397 if (!(dev->horkage & ATA_HORKAGE_BROKEN_FPDMA_AA) && in ata_dev_config_ncq()
2398 (ap->flags & ATA_FLAG_FPDMA_AA) && in ata_dev_config_ncq()
2399 ata_id_has_fpdma_aa(dev->id)) { in ata_dev_config_ncq()
2407 dev->horkage |= ATA_HORKAGE_BROKEN_FPDMA_AA; in ata_dev_config_ncq()
2408 return -EIO; in ata_dev_config_ncq()
2420 if ((ap->flags & ATA_FLAG_FPDMA_AUX)) { in ata_dev_config_ncq()
2421 if (ata_id_has_ncq_send_and_recv(dev->id)) in ata_dev_config_ncq()
2423 if (ata_id_has_ncq_non_data(dev->id)) in ata_dev_config_ncq()
2425 if (ata_id_has_ncq_prio(dev->id)) in ata_dev_config_ncq()
2436 if (!ata_id_has_sense_reporting(dev->id)) in ata_dev_config_sense_reporting()
2439 if (ata_id_sense_reporting_enabled(dev->id)) in ata_dev_config_sense_reporting()
2452 struct ata_port *ap = dev->link->ap; in ata_dev_config_zac()
2454 u8 *identify_buf = ap->sector_buf; in ata_dev_config_zac()
2456 dev->zac_zones_optimal_open = U32_MAX; in ata_dev_config_zac()
2457 dev->zac_zones_optimal_nonseq = U32_MAX; in ata_dev_config_zac()
2458 dev->zac_zones_max_open = U32_MAX; in ata_dev_config_zac()
2461 * Always set the 'ZAC' flag for Host-managed devices. in ata_dev_config_zac()
2463 if (dev->class == ATA_DEV_ZAC) in ata_dev_config_zac()
2464 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2465 else if (ata_id_zoned_cap(dev->id) == 0x01) in ata_dev_config_zac()
2467 * Check for host-aware devices. in ata_dev_config_zac()
2469 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2471 if (!(dev->flags & ATA_DFLAG_ZAC)) in ata_dev_config_zac()
2481 * Read IDENTIFY DEVICE data log, page 9 (Zoned-device information) in ata_dev_config_zac()
2491 dev->zac_zoned_cap = (zoned_cap & 1); in ata_dev_config_zac()
2494 dev->zac_zones_optimal_open = (u32)opt_open; in ata_dev_config_zac()
2497 dev->zac_zones_optimal_nonseq = (u32)opt_nonseq; in ata_dev_config_zac()
2500 dev->zac_zones_max_open = (u32)max_open; in ata_dev_config_zac()
2506 struct ata_port *ap = dev->link->ap; in ata_dev_config_trusted()
2510 if (!ata_id_has_trusted(dev->id)) in ata_dev_config_trusted()
2520 ap->sector_buf, 1); in ata_dev_config_trusted()
2524 trusted_cap = get_unaligned_le64(&ap->sector_buf[40]); in ata_dev_config_trusted()
2532 dev->flags |= ATA_DFLAG_TRUSTED; in ata_dev_config_trusted()
2537 struct ata_port *ap = dev->link->ap; in ata_dev_config_cdl()
2542 if (ata_id_major_version(dev->id) < 12) in ata_dev_config_cdl()
2552 ap->sector_buf, 1); in ata_dev_config_cdl()
2557 val = get_unaligned_le64(&ap->sector_buf[168]); in ata_dev_config_cdl()
2570 val = get_unaligned_le64(&ap->sector_buf[8]); in ata_dev_config_cdl()
2578 if (!ata_id_has_ncq_autosense(dev->id)) { in ata_dev_config_cdl()
2590 ap->sector_buf, 1); in ata_dev_config_cdl()
2594 val = get_unaligned_le64(&ap->sector_buf[8]); in ata_dev_config_cdl()
2596 if (dev->flags & ATA_DFLAG_CDL_ENABLED) { in ata_dev_config_cdl()
2598 /* Enable CDL on the device */ in ata_dev_config_cdl()
2608 /* Disable CDL on the device */ in ata_dev_config_cdl()
2641 if (!ap->ncq_sense_buf) { in ata_dev_config_cdl()
2642 ap->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); in ata_dev_config_cdl()
2643 if (!ap->ncq_sense_buf) in ata_dev_config_cdl()
2651 err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1); in ata_dev_config_cdl()
2657 memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE); in ata_dev_config_cdl()
2658 dev->flags |= ATA_DFLAG_CDL; in ata_dev_config_cdl()
2663 dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); in ata_dev_config_cdl()
2664 kfree(ap->ncq_sense_buf); in ata_dev_config_cdl()
2665 ap->ncq_sense_buf = NULL; in ata_dev_config_cdl()
2670 const u16 *id = dev->id; in ata_dev_config_lba()
2675 dev->flags |= ATA_DFLAG_LBA; in ata_dev_config_lba()
2679 dev->flags |= ATA_DFLAG_LBA48; in ata_dev_config_lba()
2680 if (dev->n_sectors >= (1UL << 28) && in ata_dev_config_lba()
2682 dev->flags |= ATA_DFLAG_FLUSH_EXT; in ata_dev_config_lba()
2694 (unsigned long long)dev->n_sectors, in ata_dev_config_lba()
2695 dev->multi_count, lba_desc, ncq_desc); in ata_dev_config_lba()
2702 const u16 *id = dev->id; in ata_dev_config_chs()
2706 dev->cylinders = id[54]; in ata_dev_config_chs()
2707 dev->heads = id[55]; in ata_dev_config_chs()
2708 dev->sectors = id[56]; in ata_dev_config_chs()
2711 dev->cylinders = id[1]; in ata_dev_config_chs()
2712 dev->heads = id[3]; in ata_dev_config_chs()
2713 dev->sectors = id[6]; in ata_dev_config_chs()
2720 (unsigned long long)dev->n_sectors, in ata_dev_config_chs()
2721 dev->multi_count, dev->cylinders, in ata_dev_config_chs()
2722 dev->heads, dev->sectors); in ata_dev_config_chs()
2727 /* Ignore FUA support if its use is disabled globally */ in ata_dev_config_fua()
2731 /* Ignore devices without support for WRITE DMA FUA EXT */ in ata_dev_config_fua()
2732 if (!(dev->flags & ATA_DFLAG_LBA48) || !ata_id_has_fua(dev->id)) in ata_dev_config_fua()
2735 /* Ignore known bad devices and devices that lack NCQ support */ in ata_dev_config_fua()
2736 if (!ata_ncq_supported(dev) || (dev->horkage & ATA_HORKAGE_NO_FUA)) in ata_dev_config_fua()
2739 dev->flags |= ATA_DFLAG_FUA; in ata_dev_config_fua()
2744 dev->flags &= ~ATA_DFLAG_FUA; in ata_dev_config_fua()
2749 u8 *sata_setting = dev->link->ap->sector_buf; in ata_dev_config_devslp()
2757 if (!ata_id_has_devslp(dev->id) || in ata_dev_config_devslp()
2768 dev->flags |= ATA_DFLAG_DEVSLP; in ata_dev_config_devslp()
2771 dev->devslp_timing[i] = sata_setting[j]; in ata_dev_config_devslp()
2783 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cpr()
2814 cpr_log->nr_cpr = nr_cpr; in ata_dev_config_cpr()
2817 cpr_log->cpr[i].num = desc[0]; in ata_dev_config_cpr()
2818 cpr_log->cpr[i].num_storage_elements = desc[1]; in ata_dev_config_cpr()
2819 cpr_log->cpr[i].start_lba = get_unaligned_le64(&desc[8]); in ata_dev_config_cpr()
2820 cpr_log->cpr[i].num_lbas = get_unaligned_le64(&desc[16]); in ata_dev_config_cpr()
2824 swap(dev->cpr_log, cpr_log); in ata_dev_config_cpr()
2831 if (!(dev->flags & ATA_DFLAG_FEATURES_MASK)) in ata_dev_print_features()
2836 dev->flags & ATA_DFLAG_FUA ? " FUA" : "", in ata_dev_print_features()
2837 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", in ata_dev_print_features()
2838 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", in ata_dev_print_features()
2839 dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", in ata_dev_print_features()
2840 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", in ata_dev_print_features()
2841 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "", in ata_dev_print_features()
2842 dev->flags & ATA_DFLAG_CDL ? " CDL" : "", in ata_dev_print_features()
2843 dev->cpr_log ? " CPR" : ""); in ata_dev_print_features()
2847 * ata_dev_configure - Configure the specified ATA/ATAPI device
2850 * Configure @dev according to @dev->id. Generic and low-level
2857 * 0 on success, -errno otherwise
2861 struct ata_port *ap = dev->link->ap; in ata_dev_configure()
2863 const u16 *id = dev->id; in ata_dev_configure()
2866 char revbuf[7]; /* XYZ-99\0 */ in ata_dev_configure()
2877 dev->horkage |= ata_dev_blacklisted(dev); in ata_dev_configure()
2880 if (dev->horkage & ATA_HORKAGE_DISABLE) { in ata_dev_configure()
2886 if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) && in ata_dev_configure()
2887 dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2899 /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */ in ata_dev_configure()
2900 if ((dev->horkage & ATA_HORKAGE_WD_BROKEN_LPM) && in ata_dev_configure()
2902 dev->horkage |= ATA_HORKAGE_NOLPM; in ata_dev_configure()
2904 if (ap->flags & ATA_FLAG_NO_LPM) in ata_dev_configure()
2905 dev->horkage |= ATA_HORKAGE_NOLPM; in ata_dev_configure()
2907 if (dev->horkage & ATA_HORKAGE_NOLPM) { in ata_dev_configure()
2909 dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER; in ata_dev_configure()
2930 /* initialize to-be-configured parameters */ in ata_dev_configure()
2931 dev->flags &= ~ATA_DFLAG_CFG_MASK; in ata_dev_configure()
2932 dev->max_sectors = 0; in ata_dev_configure()
2933 dev->cdb_len = 0; in ata_dev_configure()
2934 dev->n_sectors = 0; in ata_dev_configure()
2935 dev->cylinders = 0; in ata_dev_configure()
2936 dev->heads = 0; in ata_dev_configure()
2937 dev->sectors = 0; in ata_dev_configure()
2938 dev->multi_count = 0; in ata_dev_configure()
2949 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ in ata_dev_configure()
2950 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, in ata_dev_configure()
2953 ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, in ata_dev_configure()
2956 /* ATA-specific feature tests */ in ata_dev_configure()
2957 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in ata_dev_configure()
2965 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); in ata_dev_configure()
2972 dev->n_sectors = ata_id_n_sectors(id); in ata_dev_configure()
2975 if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) { in ata_dev_configure()
2976 unsigned int max = dev->id[47] & 0xff; in ata_dev_configure()
2977 unsigned int cnt = dev->id[59] & 0xff; in ata_dev_configure()
2981 dev->multi_count = cnt; in ata_dev_configure()
3005 dev->cdb_len = 32; in ata_dev_configure()
3011 /* ATAPI-specific feature tests */ in ata_dev_configure()
3012 else if (dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
3021 rc = -EINVAL; in ata_dev_configure()
3024 dev->cdb_len = (unsigned int) rc; in ata_dev_configure()
3032 (ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && in ata_dev_configure()
3034 sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { in ata_dev_configure()
3035 /* issue SET feature command to turn this on */ in ata_dev_configure()
3043 dev->flags |= ATA_DFLAG_AN; in ata_dev_configure()
3048 if (ata_id_cdb_intr(dev->id)) { in ata_dev_configure()
3049 dev->flags |= ATA_DFLAG_CDB_INTR; in ata_dev_configure()
3053 if (atapi_dmadir || (dev->horkage & ATA_HORKAGE_ATAPI_DMADIR) || atapi_id_dmadir(dev->id)) { in ata_dev_configure()
3054 dev->flags |= ATA_DFLAG_DMADIR; in ata_dev_configure()
3058 if (ata_id_has_da(dev->id)) { in ata_dev_configure()
3059 dev->flags |= ATA_DFLAG_DA; in ata_dev_configure()
3074 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3075 if (dev->flags & ATA_DFLAG_LBA48) in ata_dev_configure()
3076 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3078 /* Limit PATA drive on SATA cable bridge transfers to udma5, in ata_dev_configure()
3083 dev->udma_mask &= ATA_UDMA5; in ata_dev_configure()
3084 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3087 if ((dev->class == ATA_DEV_ATAPI) && in ata_dev_configure()
3089 dev->max_sectors = ATA_MAX_SECTORS_TAPE; in ata_dev_configure()
3090 dev->horkage |= ATA_HORKAGE_STUCK_ERR; in ata_dev_configure()
3093 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) in ata_dev_configure()
3094 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, in ata_dev_configure()
3095 dev->max_sectors); in ata_dev_configure()
3097 if (dev->horkage & ATA_HORKAGE_MAX_SEC_1024) in ata_dev_configure()
3098 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_1024, in ata_dev_configure()
3099 dev->max_sectors); in ata_dev_configure()
3101 if (dev->horkage & ATA_HORKAGE_MAX_SEC_LBA48) in ata_dev_configure()
3102 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3104 if (ap->ops->dev_config) in ata_dev_configure()
3105 ap->ops->dev_config(dev); in ata_dev_configure()
3107 if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { in ata_dev_configure()
3122 if ((dev->horkage & ATA_HORKAGE_FIRMWARE_WARN) && print_info) { in ata_dev_configure()
3134 * ata_cable_40wire - return 40 wire cable type
3148 * ata_cable_80wire - return 80 wire cable type
3162 * ata_cable_unknown - return unknown PATA cable.
3175 * ata_cable_ignore - return ignored PATA cable.
3188 * ata_cable_sata - return SATA cable type
3201 * sata_print_link_status - Print SATA link status
3229 * ata_dev_pair - return other device on cable
3232 * Obtain the other device on the same cable, or if none is
3238 struct ata_link *link = adev->link; in ata_dev_pair()
3239 struct ata_device *pair = &link->device[1 - adev->devno]; in ata_dev_pair()
3247 * sata_down_spd_limit - adjust SATA spd limit downward
3255 * If @spd_limit is non-zero, the speed is limited to equal to or
3264 * 0 on success, negative errno on failure
3272 return -EOPNOTSUPP; in sata_down_spd_limit()
3275 * If not, use cached value in link->sata_spd. in sata_down_spd_limit()
3281 spd = link->sata_spd; in sata_down_spd_limit()
3283 mask = link->sata_spd_limit; in sata_down_spd_limit()
3285 return -EINVAL; in sata_down_spd_limit()
3288 bit = fls(mask) - 1; in sata_down_spd_limit()
3296 * Otherwise, we should not force 1.5Gbps on a link where we have in sata_down_spd_limit()
3301 mask &= (1 << (spd - 1)) - 1; in sata_down_spd_limit()
3302 else if (link->sata_spd) in sata_down_spd_limit()
3303 return -EINVAL; in sata_down_spd_limit()
3307 return -EINVAL; in sata_down_spd_limit()
3310 if (mask & ((1 << spd_limit) - 1)) in sata_down_spd_limit()
3311 mask &= (1 << spd_limit) - 1; in sata_down_spd_limit()
3313 bit = ffs(mask) - 1; in sata_down_spd_limit()
3318 link->sata_spd_limit = mask; in sata_down_spd_limit()
3328 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration
3349 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_timing_cycle2mode()
3350 if (ent->shift == xfer_shift) in ata_timing_cycle2mode()
3351 base_mode = ent->base; in ata_timing_cycle2mode()
3354 t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { in ata_timing_cycle2mode()
3360 this_cycle = t->cycle; in ata_timing_cycle2mode()
3363 this_cycle = t->udma; in ata_timing_cycle2mode()
3372 last_mode = t->mode; in ata_timing_cycle2mode()
3380 * ata_down_xfermask_limit - adjust dev xfer masks downward
3382 * @sel: ATA_DNXFER_* selector
3392 * 0 on success, negative errno on failure
3394 int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel) in ata_down_xfermask_limit() argument
3401 quiet = !!(sel & ATA_DNXFER_QUIET); in ata_down_xfermask_limit()
3402 sel &= ~ATA_DNXFER_QUIET; in ata_down_xfermask_limit()
3404 xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, in ata_down_xfermask_limit()
3405 dev->mwdma_mask, in ata_down_xfermask_limit()
3406 dev->udma_mask); in ata_down_xfermask_limit()
3409 switch (sel) { in ata_down_xfermask_limit()
3411 highbit = fls(pio_mask) - 1; in ata_down_xfermask_limit()
3417 highbit = fls(udma_mask) - 1; in ata_down_xfermask_limit()
3420 return -ENOENT; in ata_down_xfermask_limit()
3422 highbit = fls(mwdma_mask) - 1; in ata_down_xfermask_limit()
3425 return -ENOENT; in ata_down_xfermask_limit()
3448 return -ENOENT; in ata_down_xfermask_limit()
3462 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, in ata_down_xfermask_limit()
3463 &dev->udma_mask); in ata_down_xfermask_limit()
3470 struct ata_port *ap = dev->link->ap; in ata_dev_set_mode()
3471 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_set_mode()
3472 const bool nosetxfer = dev->horkage & ATA_HORKAGE_NOSETXFER; in ata_dev_set_mode()
3478 dev->flags &= ~ATA_DFLAG_PIO; in ata_dev_set_mode()
3479 if (dev->xfer_shift == ATA_SHIFT_PIO) in ata_dev_set_mode()
3480 dev->flags |= ATA_DFLAG_PIO; in ata_dev_set_mode()
3482 if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id)) in ata_dev_set_mode()
3487 "NOSETXFER but PATA detected - can't " in ata_dev_set_mode()
3496 ehc->i.flags |= ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3498 ehc->i.flags &= ~ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3502 if (dev->xfer_shift == ATA_SHIFT_PIO) { in ata_dev_set_mode()
3504 if (ata_id_is_cfa(dev->id)) in ata_dev_set_mode()
3508 if (ata_id_major_version(dev->id) == 0 && in ata_dev_set_mode()
3509 dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3512 any kind of SET_XFERMODE request but support PIO0-2 in ata_dev_set_mode()
3514 if (!ata_id_has_iordy(dev->id) && dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3519 if (dev->xfer_shift == ATA_SHIFT_MWDMA && in ata_dev_set_mode()
3520 dev->dma_mode == XFER_MW_DMA_0 && in ata_dev_set_mode()
3521 (dev->id[63] >> 8) & 1) in ata_dev_set_mode()
3524 /* if the device is actually configured correctly, ignore dev err */ in ata_dev_set_mode()
3525 if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) in ata_dev_set_mode()
3536 dev->xfer_shift, (int)dev->xfer_mode); in ata_dev_set_mode()
3538 if (!(ehc->i.flags & ATA_EHI_QUIET) || in ata_dev_set_mode()
3539 ehc->i.flags & ATA_EHI_DID_HARDRESET) in ata_dev_set_mode()
3541 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), in ata_dev_set_mode()
3548 return -EIO; in ata_dev_set_mode()
3552 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
3553 * @link: link on which timings will be programmed
3565 * 0 on success, negative errno otherwise
3570 struct ata_port *ap = link->ap; in ata_do_set_mode()
3580 if (dev->class == ATA_DEV_ATAPI) in ata_do_set_mode()
3582 else if (ata_id_is_cfa(dev->id)) in ata_do_set_mode()
3588 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); in ata_do_set_mode()
3591 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, in ata_do_set_mode()
3592 dev->udma_mask); in ata_do_set_mode()
3596 dev->pio_mode = ata_xfer_mask2mode(pio_mask); in ata_do_set_mode()
3597 dev->dma_mode = ata_xfer_mask2mode(dma_mask); in ata_do_set_mode()
3608 if (dev->pio_mode == 0xff) { in ata_do_set_mode()
3610 rc = -EINVAL; in ata_do_set_mode()
3614 dev->xfer_mode = dev->pio_mode; in ata_do_set_mode()
3615 dev->xfer_shift = ATA_SHIFT_PIO; in ata_do_set_mode()
3616 if (ap->ops->set_piomode) in ata_do_set_mode()
3617 ap->ops->set_piomode(ap, dev); in ata_do_set_mode()
3625 dev->xfer_mode = dev->dma_mode; in ata_do_set_mode()
3626 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); in ata_do_set_mode()
3627 if (ap->ops->set_dmamode) in ata_do_set_mode()
3628 ap->ops->set_dmamode(ap, dev); in ata_do_set_mode()
3641 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) in ata_do_set_mode()
3642 ap->host->simplex_claimed = ap; in ata_do_set_mode()
3652 * ata_wait_ready - wait for link to become ready
3653 * @link: link to be waited on
3658 * positive number if @link is ready, 0 if it isn't, -ENODEV if
3662 * Transient -ENODEV conditions are allowed for
3669 * 0 if @link is ready before @deadline; otherwise, -errno.
3679 if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN) in ata_wait_ready()
3684 /* Slave readiness can't be tested separately from master. On in ata_wait_ready()
3686 * only on the master and it will handle both master and slave. in ata_wait_ready()
3688 WARN_ON(link == link->ap->slave_link); in ata_wait_ready()
3702 * -ENODEV could be transient. Ignore -ENODEV if link in ata_wait_ready()
3705 * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't in ata_wait_ready()
3712 if (ready == -ENODEV) { in ata_wait_ready()
3715 else if ((link->ap->flags & ATA_FLAG_SATA) && in ata_wait_ready()
3724 return -EBUSY; in ata_wait_ready()
3727 (deadline - now > 3 * HZ)) { in ata_wait_ready()
3734 ata_msleep(link->ap, 50); in ata_wait_ready()
3739 * ata_wait_after_reset - wait for link to become ready after reset
3740 * @link: link to be waited on
3750 * 0 if @link is ready before @deadline; otherwise, -errno.
3755 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); in ata_wait_after_reset()
3762 * ata_std_prereset - prepare for reset
3768 * that port, so prereset should be best-effort. It does its
3780 struct ata_port *ap = link->ap; in ata_std_prereset()
3781 struct ata_eh_context *ehc = &link->eh_context; in ata_std_prereset()
3786 if (ehc->i.action & ATA_EH_HARDRESET) in ata_std_prereset()
3790 if (ap->flags & ATA_FLAG_SATA) { in ata_std_prereset()
3793 if (rc && rc != -EOPNOTSUPP) in ata_std_prereset()
3799 /* no point in trying softreset on offline link */ in ata_std_prereset()
3801 ehc->i.action &= ~ATA_EH_SOFTRESET; in ata_std_prereset()
3808 * sata_std_hardreset - COMRESET w/o waiting or classification
3819 * 0 if link offline, -EAGAIN if link online, -errno on errors.
3824 const unsigned int *timing = sata_ehc_deb_timing(&link->eh_context); in sata_std_hardreset()
3830 return online ? -EAGAIN : rc; in sata_std_hardreset()
3835 * ata_std_postreset - standard postreset callback
3860 * ata_dev_same_device - Determine whether new ID matches configured device
3878 const u16 *old_id = dev->id; in ata_dev_same_device()
3882 if (dev->class != new_class) { in ata_dev_same_device()
3884 dev->class, new_class); in ata_dev_same_device()
3909 * ata_dev_reread_id - Re-read IDENTIFY data
3913 * Re-read IDENTIFY page and make sure @dev is still attached to
3920 * 0 on success, negative errno otherwise
3924 unsigned int class = dev->class; in ata_dev_reread_id()
3925 u16 *id = (void *)dev->link->ap->sector_buf; in ata_dev_reread_id()
3935 return -ENODEV; in ata_dev_reread_id()
3937 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); in ata_dev_reread_id()
3942 * ata_dev_revalidate - Revalidate ATA device
3947 * Re-read IDENTIFY page, make sure @dev is still attached to the
3954 * 0 on success, negative errno otherwise
3959 u64 n_sectors = dev->n_sectors; in ata_dev_revalidate()
3960 u64 n_native_sectors = dev->n_native_sectors; in ata_dev_revalidate()
3964 return -ENODEV; in ata_dev_revalidate()
3969 dev->class, new_class); in ata_dev_revalidate()
3970 rc = -ENODEV; in ata_dev_revalidate()
3974 /* re-read ID */ in ata_dev_revalidate()
3985 if (dev->class != ATA_DEV_ATA || !n_sectors || in ata_dev_revalidate()
3986 dev->n_sectors == n_sectors) in ata_dev_revalidate()
3992 (unsigned long long)dev->n_sectors); in ata_dev_revalidate()
3999 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
4000 dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) { in ata_dev_revalidate()
4014 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
4015 dev->n_sectors < n_sectors && n_sectors == n_native_sectors && in ata_dev_revalidate()
4016 !(dev->horkage & ATA_HORKAGE_BROKEN_HPA)) { in ata_dev_revalidate()
4021 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_dev_revalidate()
4022 rc = -EIO; in ata_dev_revalidate()
4024 rc = -ENODEV; in ata_dev_revalidate()
4027 dev->n_native_sectors = n_native_sectors; in ata_dev_revalidate()
4028 dev->n_sectors = n_sectors; in ata_dev_revalidate()
4049 { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA },
4050 { "CRD-8400B", NULL, ATA_HORKAGE_NODMA },
4051 { "CRD-848[02]B", NULL, ATA_HORKAGE_NODMA },
4052 { "CRD-84", NULL, ATA_HORKAGE_NODMA },
4054 { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA },
4055 { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA },
4056 { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA },
4057 { "HITACHI CDR-8[34]35",NULL, ATA_HORKAGE_NODMA },
4058 { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA },
4059 { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA },
4060 { "CD-532E-A", NULL, ATA_HORKAGE_NODMA },
4061 { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA },
4062 { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA },
4063 { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA },
4064 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA },
4065 { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA },
4066 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
4068 { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA },
4071 { "VRFDFC22048UCHC-TE*", NULL, ATA_HORKAGE_NODMA },
4072 /* Odd clown on sil3726/4726 PMPs */
4075 { "ASMT109x- Config", NULL, ATA_HORKAGE_DISABLE },
4078 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 },
4079 { "QUANTUM DAT DAT72-000", NULL, ATA_HORKAGE_ATAPI_MOD16_DMA },
4093 { "LITEON CX1-JB*-HP", NULL, ATA_HORKAGE_MAX_SEC_1024 },
4094 { "LITEON EP1-*", NULL, ATA_HORKAGE_MAX_SEC_1024 },
4100 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ },
4101 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ },
4112 { "ST31500341AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4115 { "ST31000333AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4118 { "ST3640[36]23AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4121 { "ST3320[68]13AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
4126 { "ST1000LM024 HN-M101MBB", NULL, ATA_HORKAGE_BROKEN_FPDMA_AA |
4131 Windows driver .inf file - also several Linux problem reports */
4137 { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ },
4139 /* Sandisk SD7/8/9s lock up hard on large trims */
4142 /* devices which puke on READ_NATIVE_MAX */
4144 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
4145 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA },
4148 /* this one allows HPA unlocking but fails IOs on the area */
4149 { "OCZ-VERTEX", "1.30", ATA_HORKAGE_BROKEN_HPA },
4159 { "TSSTcorp CDDVDW SH-S202[HJN]", "SB0[01]", ATA_HORKAGE_IVB },
4162 { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK },
4163 { "BUFFALO HD-QSU2/R5", NULL, ATA_HORKAGE_BRIDGE_OK },
4170 * Devices which choke on SETXFER. Applies only if both the
4173 { "PIONEER DVD-RW DVRTD08", NULL, ATA_HORKAGE_NOSETXFER },
4174 { "PIONEER DVD-RW DVRTD08A", NULL, ATA_HORKAGE_NOSETXFER },
4175 { "PIONEER DVD-RW DVR-215", NULL, ATA_HORKAGE_NOSETXFER },
4176 { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER },
4177 { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER },
4180 { "PIONEER BD-RW BDR-207M", NULL, ATA_HORKAGE_NOLPM },
4181 { "PIONEER BD-RW BDR-205", NULL, ATA_HORKAGE_NOLPM },
4202 /* These specific Samsung models/firmware-revs do not handle LPM well */
4203 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM },
4205 { "SAMSUNG MZ7TD256HAFV-000L9", NULL, ATA_HORKAGE_NOLPM },
4206 { "SAMSUNG MZ7TE512HMHP-000L1", "EXT06L0Q", ATA_HORKAGE_NOLPM },
4252 * ignore all or parts of the request.
4274 * Some WD SATA-I drives spin up and down erratically when the link
4277 * known prefixes and is SATA-1. As a side effect LPM partial is
4282 { "WDC WD800JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4283 { "WDC WD1200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4284 { "WDC WD1600JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4285 { "WDC WD2000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4286 { "WDC WD2500JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4287 { "WDC WD3000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4288 { "WDC WD3200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4291 * This sata dom device goes on a walkabout when the ATA_LOG_DIRECTORY
4295 { "SATADOM-ML 3ME", NULL, ATA_HORKAGE_NO_LOG_DIR },
4300 { "OCZ-VERTEX*", NULL, ATA_HORKAGE_NO_FUA },
4313 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); in ata_dev_blacklisted()
4314 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); in ata_dev_blacklisted()
4316 while (ad->model_num) { in ata_dev_blacklisted()
4317 if (glob_match(ad->model_num, model_num)) { in ata_dev_blacklisted()
4318 if (ad->model_rev == NULL) in ata_dev_blacklisted()
4319 return ad->horkage; in ata_dev_blacklisted()
4320 if (glob_match(ad->model_rev, model_rev)) in ata_dev_blacklisted()
4321 return ad->horkage; in ata_dev_blacklisted()
4331 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO) in ata_dma_blacklisted()
4334 if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && in ata_dma_blacklisted()
4335 (dev->flags & ATA_DFLAG_CDB_INTR)) in ata_dma_blacklisted()
4337 return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0; in ata_dma_blacklisted()
4341 * ata_is_40wire - check drive side detection
4350 if (dev->horkage & ATA_HORKAGE_IVB) in ata_is_40wire()
4351 return ata_drive_40wire_relaxed(dev->id); in ata_is_40wire()
4352 return ata_drive_40wire(dev->id); in ata_is_40wire()
4356 * cable_is_40wire - 40/80/SATA decider
4361 * there is a good case for setting ap->cbl to the result when
4374 if (ap->cbl == ATA_CBL_PATA40) in cable_is_40wire()
4378 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) in cable_is_40wire()
4385 if (ap->cbl == ATA_CBL_PATA40_SHORT) in cable_is_40wire()
4392 * - in many setups only the one drive (slave if present) will in cable_is_40wire()
4394 * - if you have a non detect capable drive you don't want it in cable_is_40wire()
4407 * ata_dev_xfermask - Compute supported xfermask of the given device
4411 * dev->*_mask. This function is responsible for applying all
4420 struct ata_link *link = dev->link; in ata_dev_xfermask()
4421 struct ata_port *ap = link->ap; in ata_dev_xfermask()
4422 struct ata_host *host = ap->host; in ata_dev_xfermask()
4426 xfer_mask = ata_pack_xfermask(ap->pio_mask, in ata_dev_xfermask()
4427 ap->mwdma_mask, ap->udma_mask); in ata_dev_xfermask()
4430 xfer_mask &= ata_pack_xfermask(dev->pio_mask, in ata_dev_xfermask()
4431 dev->mwdma_mask, dev->udma_mask); in ata_dev_xfermask()
4432 xfer_mask &= ata_id_xfermask(dev->id); in ata_dev_xfermask()
4435 * CFA Advanced TrueIDE timings are not allowed on a shared in ata_dev_xfermask()
4448 "device is on DMA blacklist, disabling DMA\n"); in ata_dev_xfermask()
4451 if ((host->flags & ATA_HOST_SIMPLEX) && in ata_dev_xfermask()
4452 host->simplex_claimed && host->simplex_claimed != ap) { in ata_dev_xfermask()
4458 if (ap->flags & ATA_FLAG_NO_IORDY) in ata_dev_xfermask()
4461 if (ap->ops->mode_filter) in ata_dev_xfermask()
4462 xfer_mask = ap->ops->mode_filter(dev, xfer_mask); in ata_dev_xfermask()
4476 "limited to UDMA/33 due to 40-wire cable\n"); in ata_dev_xfermask()
4480 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, in ata_dev_xfermask()
4481 &dev->mwdma_mask, &dev->udma_mask); in ata_dev_xfermask()
4485 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
4488 * Issue SET FEATURES - XFER MODE command to device @dev
4489 * on port @ap.
4495 * 0 on success, AC_ERR_* mask otherwise.
4502 /* set up set-features taskfile */ in ata_dev_set_xfermode()
4503 ata_dev_dbg(dev, "set features - xfer mode\n"); in ata_dev_set_xfermode()
4515 tf.nsect = dev->xfer_mode; in ata_dev_set_xfermode()
4516 /* If the device has IORDY and the controller does not - turn it off */ in ata_dev_set_xfermode()
4517 else if (ata_id_has_iordy(dev->id)) in ata_dev_set_xfermode()
4519 else /* In the ancient relic department - skip all of this */ in ata_dev_set_xfermode()
4523 * On some disks, this command causes spin-up, so we need longer in ata_dev_set_xfermode()
4530 * ata_dev_set_feature - Issue SET FEATURES
4535 * Issue SET FEATURES command to device @dev on port @ap with sector count
4541 * 0 on success, AC_ERR_* mask otherwise.
4548 /* set up set-features taskfile */ in ata_dev_set_feature()
4567 * ata_dev_init_params - Issue INIT DEV PARAMS command
4576 * 0 on success, AC_ERR_* mask otherwise.
4584 /* Number of sectors per track 1-255. Number of heads 1-16 */ in ata_dev_init_params()
4596 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ in ata_dev_init_params()
4600 and we should continue as we issue the setup based on the in ata_dev_init_params()
4609 * atapi_check_dma - Check whether ATAPI DMA can be supported
4612 * Allow low-level driver to filter ATA PACKET commands, returning
4624 struct ata_port *ap = qc->ap; in atapi_check_dma()
4627 * few ATAPI devices choke on such DMA requests. in atapi_check_dma()
4629 if (!(qc->dev->horkage & ATA_HORKAGE_ATAPI_MOD16_DMA) && in atapi_check_dma()
4630 unlikely(qc->nbytes & 15)) in atapi_check_dma()
4633 if (ap->ops->check_atapi_dma) in atapi_check_dma()
4634 return ap->ops->check_atapi_dma(qc); in atapi_check_dma()
4640 * ata_std_qc_defer - Check whether a qc needs to be deferred
4643 * Non-NCQ commands cannot run with any other command, NCQ or
4656 struct ata_link *link = qc->dev->link; in ata_std_qc_defer()
4658 if (ata_is_ncq(qc->tf.protocol)) { in ata_std_qc_defer()
4659 if (!ata_tag_valid(link->active_tag)) in ata_std_qc_defer()
4662 if (!ata_tag_valid(link->active_tag) && !link->sactive) in ata_std_qc_defer()
4677 * ata_sg_init - Associate command with scatter-gather table.
4679 * @sg: Scatter-gather table.
4682 * Initialize the data-related elements of queued_cmd @qc
4683 * to point to a scatter-gather table @sg, containing @n_elem
4692 qc->sg = sg; in ata_sg_init()
4693 qc->n_elem = n_elem; in ata_sg_init()
4694 qc->cursg = qc->sg; in ata_sg_init()
4700 * ata_sg_clean - Unmap DMA memory associated with command
4710 struct ata_port *ap = qc->ap; in ata_sg_clean()
4711 struct scatterlist *sg = qc->sg; in ata_sg_clean()
4712 int dir = qc->dma_dir; in ata_sg_clean()
4716 if (qc->n_elem) in ata_sg_clean()
4717 dma_unmap_sg(ap->dev, sg, qc->orig_n_elem, dir); in ata_sg_clean()
4719 qc->flags &= ~ATA_QCFLAG_DMAMAP; in ata_sg_clean()
4720 qc->sg = NULL; in ata_sg_clean()
4724 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
4725 * @qc: Command with scatter-gather table to be mapped.
4727 * DMA-map the scatter-gather table associated with queued_cmd @qc.
4733 * Zero on success, negative on error.
4738 struct ata_port *ap = qc->ap; in ata_sg_setup()
4741 n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); in ata_sg_setup()
4743 return -1; in ata_sg_setup()
4745 qc->orig_n_elem = qc->n_elem; in ata_sg_setup()
4746 qc->n_elem = n_elem; in ata_sg_setup()
4747 qc->flags |= ATA_QCFLAG_DMAMAP; in ata_sg_setup()
4755 static inline int ata_sg_setup(struct ata_queued_cmd *qc) { return -1; } in ata_sg_setup()
4760 * swap_buf_le16 - swap halves of 16-bit words in place
4762 * @buf_words: Number of 16-bit words in buffer.
4764 * Swap halves of 16-bit words if needed to convert from
4765 * little-endian byte order to native cpu byte order, or
4766 * vice-versa.
4782 * ata_qc_free - free unused ata_queued_cmd
4793 qc->flags = 0; in ata_qc_free()
4794 if (ata_tag_valid(qc->tag)) in ata_qc_free()
4795 qc->tag = ATA_TAG_POISON; in ata_qc_free()
4804 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)); in __ata_qc_complete()
4805 ap = qc->ap; in __ata_qc_complete()
4806 link = qc->dev->link; in __ata_qc_complete()
4808 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) in __ata_qc_complete()
4812 if (ata_is_ncq(qc->tf.protocol)) { in __ata_qc_complete()
4813 link->sactive &= ~(1 << qc->hw_tag); in __ata_qc_complete()
4814 if (!link->sactive) in __ata_qc_complete()
4815 ap->nr_active_links--; in __ata_qc_complete()
4817 link->active_tag = ATA_TAG_POISON; in __ata_qc_complete()
4818 ap->nr_active_links--; in __ata_qc_complete()
4822 if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && in __ata_qc_complete()
4823 ap->excl_link == link)) in __ata_qc_complete()
4824 ap->excl_link = NULL; in __ata_qc_complete()
4830 qc->flags &= ~ATA_QCFLAG_ACTIVE; in __ata_qc_complete()
4831 ap->qc_active &= ~(1ULL << qc->tag); in __ata_qc_complete()
4834 qc->complete_fn(qc); in __ata_qc_complete()
4839 struct ata_port *ap = qc->ap; in fill_result_tf()
4841 qc->result_tf.flags = qc->tf.flags; in fill_result_tf()
4842 ap->ops->qc_fill_rtf(qc); in fill_result_tf()
4847 struct ata_device *dev = qc->dev; in ata_verify_xfer()
4849 if (!ata_is_data(qc->tf.protocol)) in ata_verify_xfer()
4852 if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) in ata_verify_xfer()
4855 dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; in ata_verify_xfer()
4859 * ata_qc_complete - Complete an active ATA command
4863 * completed, with either an ok or not-ok status.
4875 struct ata_port *ap = qc->ap; in ata_qc_complete()
4876 struct ata_device *dev = qc->dev; in ata_qc_complete()
4877 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_qc_complete()
4880 ledtrig_disk_activity(!!(qc->tf.flags & ATA_TFLAG_WRITE)); in ata_qc_complete()
4890 if (unlikely(qc->err_mask)) in ata_qc_complete()
4891 qc->flags |= ATA_QCFLAG_EH; in ata_qc_complete()
4897 if (unlikely(ata_tag_internal(qc->tag))) { in ata_qc_complete()
4904 /* Non-internal qc has failed. Fill the result TF and summon EH. */ in ata_qc_complete()
4905 if (unlikely(qc->flags & ATA_QCFLAG_EH)) { in ata_qc_complete()
4915 if (qc->flags & ATA_QCFLAG_RESULT_TF) in ata_qc_complete()
4926 if (qc->flags & ATA_QCFLAG_HAS_CDL && in ata_qc_complete()
4927 qc->result_tf.status & ATA_SENSE) { in ata_qc_complete()
4929 * Tell SCSI EH to not overwrite scmd->result even if this in ata_qc_complete()
4932 qc->scsicmd->flags |= SCMD_FORCE_EH_SUCCESS; in ata_qc_complete()
4933 qc->flags |= ATA_QCFLAG_EH_SUCCESS_CMD; in ata_qc_complete()
4934 ehi->dev_action[dev->devno] |= ATA_EH_GET_SUCCESS_SENSE; in ata_qc_complete()
4940 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_qc_complete()
4945 /* Some commands need post-processing after successful completion. */ in ata_qc_complete()
4946 switch (qc->tf.command) { in ata_qc_complete()
4948 if (qc->tf.feature != SETFEATURES_WC_ON && in ata_qc_complete()
4949 qc->tf.feature != SETFEATURES_WC_OFF && in ata_qc_complete()
4950 qc->tf.feature != SETFEATURES_RA_ON && in ata_qc_complete()
4951 qc->tf.feature != SETFEATURES_RA_OFF) in ata_qc_complete()
4957 ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; in ata_qc_complete()
4962 dev->flags |= ATA_DFLAG_SLEEPING; in ata_qc_complete()
4966 if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) in ata_qc_complete()
4974 * ata_qc_get_active - get bitmask of active qcs
4985 u64 qc_active = ap->qc_active; in ata_qc_get_active()
4998 * ata_qc_issue - issue taskfile to device
5002 * This includes mapping the data into a DMA-able
5011 struct ata_port *ap = qc->ap; in ata_qc_issue()
5012 struct ata_link *link = qc->dev->link; in ata_qc_issue()
5013 u8 prot = qc->tf.protocol; in ata_qc_issue()
5015 /* Make sure only one non-NCQ command is outstanding. */ in ata_qc_issue()
5016 WARN_ON_ONCE(ata_tag_valid(link->active_tag)); in ata_qc_issue()
5019 WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag)); in ata_qc_issue()
5021 if (!link->sactive) in ata_qc_issue()
5022 ap->nr_active_links++; in ata_qc_issue()
5023 link->sactive |= 1 << qc->hw_tag; in ata_qc_issue()
5025 WARN_ON_ONCE(link->sactive); in ata_qc_issue()
5027 ap->nr_active_links++; in ata_qc_issue()
5028 link->active_tag = qc->tag; in ata_qc_issue()
5031 qc->flags |= ATA_QCFLAG_ACTIVE; in ata_qc_issue()
5032 ap->qc_active |= 1ULL << qc->tag; in ata_qc_issue()
5036 * non-zero sg if the command is a data command. in ata_qc_issue()
5038 if (ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)) in ata_qc_issue()
5042 (ap->flags & ATA_FLAG_PIO_DMA))) in ata_qc_issue()
5047 if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { in ata_qc_issue()
5048 link->eh_info.action |= ATA_EH_RESET; in ata_qc_issue()
5049 ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); in ata_qc_issue()
5055 qc->err_mask |= ap->ops->qc_prep(qc); in ata_qc_issue()
5056 if (unlikely(qc->err_mask)) in ata_qc_issue()
5059 qc->err_mask |= ap->ops->qc_issue(qc); in ata_qc_issue()
5060 if (unlikely(qc->err_mask)) in ata_qc_issue()
5065 qc->err_mask |= AC_ERR_SYSTEM; in ata_qc_issue()
5071 * ata_phys_link_online - test whether the given link is online
5095 * ata_phys_link_offline - test whether the given link is offline
5119 * ata_link_online - test whether the given link is online
5124 * there's a slave link, this function should only be called on
5136 struct ata_link *slave = link->ap->slave_link; in ata_link_online()
5138 WARN_ON(link == slave); /* shouldn't be called on slave link */ in ata_link_online()
5146 * ata_link_offline - test whether the given link is offline
5151 * there's a slave link, this function should only be called on
5163 struct ata_link *slave = link->ap->slave_link; in ata_link_offline()
5165 WARN_ON(link == slave); /* shouldn't be called on slave link */ in ata_link_offline()
5180 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5186 if (ap->pflags & ATA_PFLAG_PM_PENDING) { in ata_port_request_pm()
5187 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5189 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5193 ap->pm_mesg = mesg; in ata_port_request_pm()
5194 ap->pflags |= ATA_PFLAG_PM_PENDING; in ata_port_request_pm()
5196 link->eh_info.action |= action; in ata_port_request_pm()
5197 link->eh_info.flags |= ehi_flags; in ata_port_request_pm()
5202 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5217 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_suspend()
5220 * On some hardware, device fails to respond after spun down for in ata_port_suspend()
5282 * So the idle callback here will not proceed to suspend if a non-ZPODD capable
5293 if (adev->class == ATA_DEV_ATAPI && in ata_port_runtime_idle()
5295 return -EBUSY; in ata_port_runtime_idle()
5327 * and need to resume ata devices at the domain level, not the per-port
5344 * ata_host_suspend - suspend host
5352 host->dev->power.power_state = mesg; in ata_host_suspend()
5357 * ata_host_resume - resume host
5364 host->dev->power.power_state = PMSG_ON; in ata_host_resume()
5377 * ata_dev_init - Initialize an ata_device structure
5388 struct ata_port *ap = link->ap; in ata_dev_init()
5392 link->sata_spd_limit = link->hw_sata_spd_limit; in ata_dev_init()
5393 link->sata_spd = 0; in ata_dev_init()
5395 /* High bits of dev->flags are used to record warm plug in ata_dev_init()
5399 spin_lock_irqsave(ap->lock, flags); in ata_dev_init()
5400 dev->flags &= ~ATA_DFLAG_INIT_MASK; in ata_dev_init()
5401 dev->horkage = 0; in ata_dev_init()
5402 spin_unlock_irqrestore(ap->lock, flags); in ata_dev_init()
5405 ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); in ata_dev_init()
5406 dev->pio_mask = UINT_MAX; in ata_dev_init()
5407 dev->mwdma_mask = UINT_MAX; in ata_dev_init()
5408 dev->udma_mask = UINT_MAX; in ata_dev_init()
5412 * ata_link_init - Initialize an ata_link structure
5428 ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); in ata_link_init()
5430 link->ap = ap; in ata_link_init()
5431 link->pmp = pmp; in ata_link_init()
5432 link->active_tag = ATA_TAG_POISON; in ata_link_init()
5433 link->hw_sata_spd_limit = UINT_MAX; in ata_link_init()
5437 struct ata_device *dev = &link->device[i]; in ata_link_init()
5439 dev->link = link; in ata_link_init()
5440 dev->devno = dev - link->device; in ata_link_init()
5442 dev->gtf_filter = ata_acpi_gtf_filter; in ata_link_init()
5449 * sata_link_init_spd - Initialize link->sata_spd_limit
5452 * Initialize ``link->[hw_]sata_spd_limit`` to the currently
5459 * 0 on success, -errno on failure.
5466 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); in sata_link_init_spd()
5470 spd = (link->saved_scontrol >> 4) & 0xf; in sata_link_init_spd()
5472 link->hw_sata_spd_limit &= (1 << spd) - 1; in sata_link_init_spd()
5476 link->sata_spd_limit = link->hw_sata_spd_limit; in sata_link_init_spd()
5482 * ata_port_alloc - allocate and initialize basic ATA port resources
5488 * Allocate ATA port on success, NULL on failure.
5501 ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; in ata_port_alloc()
5502 ap->lock = &host->lock; in ata_port_alloc()
5503 ap->print_id = -1; in ata_port_alloc()
5504 ap->local_port_no = -1; in ata_port_alloc()
5505 ap->host = host; in ata_port_alloc()
5506 ap->dev = host->dev; in ata_port_alloc()
5508 mutex_init(&ap->scsi_scan_mutex); in ata_port_alloc()
5509 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); in ata_port_alloc()
5510 INIT_DELAYED_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); in ata_port_alloc()
5511 INIT_LIST_HEAD(&ap->eh_done_q); in ata_port_alloc()
5512 init_waitqueue_head(&ap->eh_wait_q); in ata_port_alloc()
5513 init_completion(&ap->park_req_pending); in ata_port_alloc()
5514 timer_setup(&ap->fastdrain_timer, ata_eh_fastdrain_timerfn, in ata_port_alloc()
5517 ap->cbl = ATA_CBL_NONE; in ata_port_alloc()
5519 ata_link_init(ap, &ap->link, 0); in ata_port_alloc()
5522 ap->stats.unhandled_irq = 1; in ata_port_alloc()
5523 ap->stats.idle_irq = 1; in ata_port_alloc()
5535 for (i = 0; i < host->n_ports; i++) { in ata_devres_release()
5536 struct ata_port *ap = host->ports[i]; in ata_devres_release()
5541 if (ap->scsi_host) in ata_devres_release()
5542 scsi_host_put(ap->scsi_host); in ata_devres_release()
5555 for (i = 0; i < host->n_ports; i++) { in ata_host_release()
5556 struct ata_port *ap = host->ports[i]; in ata_host_release()
5558 kfree(ap->pmp_link); in ata_host_release()
5559 kfree(ap->slave_link); in ata_host_release()
5560 kfree(ap->ncq_sense_buf); in ata_host_release()
5562 host->ports[i] = NULL; in ata_host_release()
5569 kref_get(&host->kref); in ata_host_get()
5574 kref_put(&host->kref, ata_host_release); in ata_host_put()
5579 * ata_host_alloc - allocate and init basic ATA host resources
5587 * @max_ports ports are allocated and host->n_ports is
5589 * host->n_ports before calling ata_host_register(). The unused
5590 * ports will be automatically freed on registration.
5593 * Allocate ATA host on success, NULL on failure.
5621 spin_lock_init(&host->lock); in ata_host_alloc()
5622 mutex_init(&host->eh_mutex); in ata_host_alloc()
5623 host->dev = dev; in ata_host_alloc()
5624 host->n_ports = max_ports; in ata_host_alloc()
5625 kref_init(&host->kref); in ata_host_alloc()
5635 ap->port_no = i; in ata_host_alloc()
5636 host->ports[i] = ap; in ata_host_alloc()
5651 * ata_host_alloc_pinfo - alloc host and init with port_info array
5661 * Allocate ATA host on success, NULL on failure.
5678 for (i = 0, j = 0; i < host->n_ports; i++) { in ata_host_alloc_pinfo()
5679 struct ata_port *ap = host->ports[i]; in ata_host_alloc_pinfo()
5684 ap->pio_mask = pi->pio_mask; in ata_host_alloc_pinfo()
5685 ap->mwdma_mask = pi->mwdma_mask; in ata_host_alloc_pinfo()
5686 ap->udma_mask = pi->udma_mask; in ata_host_alloc_pinfo()
5687 ap->flags |= pi->flags; in ata_host_alloc_pinfo()
5688 ap->link.flags |= pi->link_flags; in ata_host_alloc_pinfo()
5689 ap->ops = pi->port_ops; in ata_host_alloc_pinfo()
5691 if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) in ata_host_alloc_pinfo()
5692 host->ops = pi->port_ops; in ata_host_alloc_pinfo()
5704 WARN_ON(!(host->flags & ATA_HOST_STARTED)); in ata_host_stop()
5706 for (i = 0; i < host->n_ports; i++) { in ata_host_stop()
5707 struct ata_port *ap = host->ports[i]; in ata_host_stop()
5709 if (ap->ops->port_stop) in ata_host_stop()
5710 ap->ops->port_stop(ap); in ata_host_stop()
5713 if (host->ops->host_stop) in ata_host_stop()
5714 host->ops->host_stop(host); in ata_host_stop()
5718 * ata_finalize_port_ops - finalize ata_port_operations
5722 * ops can again inherit from another. This can go on as many
5730 * methods and ->inherits is no longer necessary and cleared.
5742 void **end = (void **)&ops->inherits; in ata_finalize_port_ops()
5745 if (!ops || !ops->inherits) in ata_finalize_port_ops()
5750 for (cur = ops->inherits; cur; cur = cur->inherits) { in ata_finalize_port_ops()
5762 ops->inherits = NULL; in ata_finalize_port_ops()
5768 * ata_host_start - start and freeze ports of an ATA host
5772 * recorded in host->flags, so this function can be called
5774 * once. If host->ops is not initialized yet, it is set to the
5775 * first non-dummy port ops.
5781 * 0 if all ports are started successfully, -errno otherwise.
5789 if (host->flags & ATA_HOST_STARTED) in ata_host_start()
5792 ata_finalize_port_ops(host->ops); in ata_host_start()
5794 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5795 struct ata_port *ap = host->ports[i]; in ata_host_start()
5797 ata_finalize_port_ops(ap->ops); in ata_host_start()
5799 if (!host->ops && !ata_port_is_dummy(ap)) in ata_host_start()
5800 host->ops = ap->ops; in ata_host_start()
5802 if (ap->ops->port_stop) in ata_host_start()
5806 if (host->ops && host->ops->host_stop) in ata_host_start()
5812 return -ENOMEM; in ata_host_start()
5815 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5816 struct ata_port *ap = host->ports[i]; in ata_host_start()
5818 if (ap->ops->port_start) { in ata_host_start()
5819 rc = ap->ops->port_start(ap); in ata_host_start()
5821 if (rc != -ENODEV) in ata_host_start()
5822 dev_err(host->dev, in ata_host_start()
5832 devres_add(host->dev, start_dr); in ata_host_start()
5833 host->flags |= ATA_HOST_STARTED; in ata_host_start()
5837 while (--i >= 0) { in ata_host_start()
5838 struct ata_port *ap = host->ports[i]; in ata_host_start()
5840 if (ap->ops->port_stop) in ata_host_start()
5841 ap->ops->port_stop(ap); in ata_host_start()
5849 * ata_host_init - Initialize a host struct for sas (ipr, libsas)
5858 spin_lock_init(&host->lock); in ata_host_init()
5859 mutex_init(&host->eh_mutex); in ata_host_init()
5860 host->n_tags = ATA_MAX_QUEUE; in ata_host_init()
5861 host->dev = dev; in ata_host_init()
5862 host->ops = ops; in ata_host_init()
5863 kref_init(&host->kref); in ata_host_init()
5869 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_port_probe()
5873 spin_lock_irqsave(ap->lock, flags); in ata_port_probe()
5875 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_port_probe()
5876 ehi->action |= ATA_EH_RESET; in ata_port_probe()
5877 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; in ata_port_probe()
5879 ap->pflags &= ~ATA_PFLAG_INITIALIZING; in ata_port_probe()
5880 ap->pflags |= ATA_PFLAG_LOADING; in ata_port_probe()
5883 spin_unlock_irqrestore(ap->lock, flags); in ata_port_probe()
5898 if (!(ap->host->flags & ATA_HOST_PARALLEL_SCAN) && ap->port_no != 0) in async_port_probe()
5911 * ata_host_register - register initialized ATA host
5924 * 0 on success, -errno otherwise.
5930 host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE); in ata_host_register()
5933 if (!(host->flags & ATA_HOST_STARTED)) { in ata_host_register()
5934 dev_err(host->dev, "BUG: trying to register unstarted host\n"); in ata_host_register()
5936 return -EINVAL; in ata_host_register()
5943 for (i = host->n_ports; host->ports[i]; i++) in ata_host_register()
5944 kfree(host->ports[i]); in ata_host_register()
5947 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5948 host->ports[i]->print_id = atomic_inc_return(&ata_print_id); in ata_host_register()
5949 host->ports[i]->local_port_no = i + 1; in ata_host_register()
5953 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5954 rc = ata_tport_add(host->dev,host->ports[i]); in ata_host_register()
5965 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5966 struct ata_port *ap = host->ports[i]; in ata_host_register()
5970 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) in ata_host_register()
5971 ap->cbl = ATA_CBL_SATA; in ata_host_register()
5974 sata_link_init_spd(&ap->link); in ata_host_register()
5975 if (ap->slave_link) in ata_host_register()
5976 sata_link_init_spd(ap->slave_link); in ata_host_register()
5978 /* print per-port info to dmesg */ in ata_host_register()
5979 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, in ata_host_register()
5980 ap->udma_mask); in ata_host_register()
5984 (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', in ata_host_register()
5986 ap->link.eh_info.desc); in ata_host_register()
5987 ata_ehi_clear_desc(&ap->link.eh_info); in ata_host_register()
5993 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5994 struct ata_port *ap = host->ports[i]; in ata_host_register()
5995 ap->cookie = async_schedule(async_port_probe, ap); in ata_host_register()
6001 while (--i >= 0) { in ata_host_register()
6002 ata_tport_delete(host->ports[i]); in ata_host_register()
6010 * ata_host_activate - start host, request IRQ and register it
6018 * LLDs perform three steps to activate the host - start host,
6023 * have set polling mode on the port. In this case, @irq_handler
6030 * 0 on success, -errno otherwise.
6049 irq_desc = devm_kasprintf(host->dev, GFP_KERNEL, "%s[%s]", in ata_host_activate()
6050 dev_driver_string(host->dev), in ata_host_activate()
6051 dev_name(host->dev)); in ata_host_activate()
6053 return -ENOMEM; in ata_host_activate()
6055 rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, in ata_host_activate()
6060 for (i = 0; i < host->n_ports; i++) in ata_host_activate()
6061 ata_port_desc_misc(host->ports[i], irq); in ata_host_activate()
6066 devm_free_irq(host->dev, irq, host); in ata_host_activate()
6073 * ata_port_detach - Detach ATA port in preparation of device removal
6078 * be quiescent on return from this function.
6090 async_synchronize_cookie(ap->cookie + 1); in ata_port_detach()
6095 mutex_lock(&ap->scsi_scan_mutex); in ata_port_detach()
6096 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6101 if (dev->sdev) { in ata_port_detach()
6102 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6103 scsi_remove_device(dev->sdev); in ata_port_detach()
6104 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6105 dev->sdev = NULL; in ata_port_detach()
6111 ap->pflags |= ATA_PFLAG_UNLOADING; in ata_port_detach()
6114 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6115 mutex_unlock(&ap->scsi_scan_mutex); in ata_port_detach()
6121 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED)); in ata_port_detach()
6123 cancel_delayed_work_sync(&ap->hotplug_task); in ata_port_detach()
6124 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_detach()
6126 /* clean up zpodd on port removal */ in ata_port_detach()
6133 if (ap->pmp_link) { in ata_port_detach()
6136 ata_tlink_delete(&ap->pmp_link[i]); in ata_port_detach()
6139 scsi_remove_host(ap->scsi_host); in ata_port_detach()
6144 * ata_host_detach - Detach all ports of an ATA host
6156 for (i = 0; i < host->n_ports; i++) in ata_host_detach()
6157 ata_port_detach(host->ports[i]); in ata_host_detach()
6167 * ata_pci_remove_one - PCI layer callback for device removal
6170 * PCI layer indicates to libata via this hook that hot-unplug or
6190 for (i = 0; i < host->n_ports; i++) { in ata_pci_shutdown_one()
6191 struct ata_port *ap = host->ports[i]; in ata_pci_shutdown_one()
6193 ap->pflags |= ATA_PFLAG_FROZEN; in ata_pci_shutdown_one()
6196 if (ap->ops->freeze) in ata_pci_shutdown_one()
6197 ap->ops->freeze(ap); in ata_pci_shutdown_one()
6200 if (ap->ops->port_stop) in ata_pci_shutdown_one()
6201 ap->ops->port_stop(ap); in ata_pci_shutdown_one()
6211 switch (bits->width) { in pci_test_config_bits()
6214 pci_read_config_byte(pdev, bits->reg, &tmp8); in pci_test_config_bits()
6220 pci_read_config_word(pdev, bits->reg, &tmp16); in pci_test_config_bits()
6226 pci_read_config_dword(pdev, bits->reg, &tmp32); in pci_test_config_bits()
6232 return -EINVAL; in pci_test_config_bits()
6235 tmp &= bits->mask; in pci_test_config_bits()
6237 return (tmp == bits->val) ? 1 : 0; in pci_test_config_bits()
6261 dev_err(&pdev->dev, in ata_pci_device_do_resume()
6298 * ata_platform_remove_one - Platform layer callback for device removal
6301 * Platform layer indicates to libata via this hook that hot-unplug or
6456 force_ent->device = simple_strtoul(p, &endp, 10); in ata_parse_force_one()
6459 return -EINVAL; in ata_parse_force_one()
6463 force_ent->port = simple_strtoul(id, &endp, 10); in ata_parse_force_one()
6466 return -EINVAL; in ata_parse_force_one()
6474 if (strncasecmp(val, fp->name, strlen(val))) in ata_parse_force_one()
6480 if (strcasecmp(val, fp->name) == 0) { in ata_parse_force_one()
6488 return -EINVAL; in ata_parse_force_one()
6492 return -EINVAL; in ata_parse_force_one()
6495 force_ent->param = *match_fp; in ata_parse_force_one()
6503 int last_port = -1, last_device = -1; in ata_parse_force_param()
6521 struct ata_force_ent te = { .port = -1, .device = -1 }; in ata_parse_force_param()
6531 if (te.port == -1) { in ata_parse_force_param()
6570 rc = -ENOMEM; in ata_init()
6601 * ata_msleep - ATA EH owner aware msleep
6608 * @ap->host will be allowed to own the EH while this task is
6616 bool owns_eh = ap && ap->host->eh_owner == current; in ata_msleep()
6634 * ata_wait_register - wait until register value changes
6636 * @reg: IO-mapped register
6644 * IO-mapped register @reg and tests for the following condition.