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

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)
22 * libata is essentially a library of internal helper functions for
23 * low-level ATA host controller drivers. As such, the API/ABI is
65 #include "libata-transport.h"
114 …ing cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst …
164 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_print_info()
166 return ehc->i.flags & ATA_EHI_PRINTINFO; in ata_dev_print_info()
175 * ata_link_next - link iteration helper
198 return ap->pmp_link; in ata_link_next()
201 return &ap->link; in ata_link_next()
205 if (link == &ap->link) in ata_link_next()
209 return ap->pmp_link; in ata_link_next()
212 if (unlikely(ap->slave_link)) in ata_link_next()
213 return ap->slave_link; in ata_link_next()
220 if (unlikely(link == ap->slave_link)) in ata_link_next()
223 /* we were over a PMP link */ in ata_link_next()
224 if (++link < ap->pmp_link + ap->nr_pmp_links) in ata_link_next()
228 return &ap->link; in ata_link_next()
235 * ata_dev_next - device iteration helper
257 dev = link->device; in ata_dev_next()
261 dev = link->device + ata_link_max_devices(link) - 1; in ata_dev_next()
270 if (++dev < link->device + ata_link_max_devices(link)) in ata_dev_next()
275 if (--dev >= link->device) in ata_dev_next()
289 * ata_dev_phys_link - find physical link for a device
293 * this is different from @dev->link only when @dev is on slave
294 * link. For all other cases, it's the same as @dev->link.
304 struct ata_port *ap = dev->link->ap; in ata_dev_phys_link()
306 if (!ap->slave_link) in ata_dev_phys_link()
307 return dev->link; in ata_dev_phys_link()
308 if (!dev->devno) in ata_dev_phys_link()
309 return &ap->link; in ata_dev_phys_link()
310 return ap->slave_link; in ata_dev_phys_link()
315 * ata_force_cbl - force cable type according to libata.force
321 * example, both "a:40c,1.00:udma4" and "1.00:40c,udma4" have the
331 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_cbl()
334 if (fe->port != -1 && fe->port != ap->print_id) in ata_force_cbl()
337 if (fe->param.cbl == ATA_CBL_NONE) in ata_force_cbl()
340 ap->cbl = fe->param.cbl; in ata_force_cbl()
341 ata_port_notice(ap, "FORCE: cable set to %s\n", fe->param.name); in ata_force_cbl()
347 * ata_force_link_limits - force link limits according to libata.force
353 * the host link and all fan-out ports connected via PMP. If the
355 * first fan-out link not the host link. Device number 15 always
365 int linkno = link->pmp; in ata_force_link_limits()
371 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_link_limits()
374 if (fe->port != -1 && fe->port != link->ap->print_id) in ata_force_link_limits()
377 if (fe->device != -1 && fe->device != linkno) in ata_force_link_limits()
381 if (!did_spd && fe->param.spd_limit) { in ata_force_link_limits()
382 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; in ata_force_link_limits()
384 fe->param.name); in ata_force_link_limits()
389 if (fe->param.lflags) { in ata_force_link_limits()
390 link->flags |= fe->param.lflags; in ata_force_link_limits()
392 "FORCE: link flag 0x%x forced -> 0x%x\n", in ata_force_link_limits()
393 fe->param.lflags, link->flags); in ata_force_link_limits()
399 * ata_force_xfermask - force xfermask according to libata.force
411 int devno = dev->link->pmp + dev->devno; in ata_force_xfermask()
416 if (ata_is_host_link(dev->link)) in ata_force_xfermask()
419 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_xfermask()
423 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_xfermask()
426 if (fe->device != -1 && fe->device != devno && in ata_force_xfermask()
427 fe->device != alt_devno) in ata_force_xfermask()
430 if (!fe->param.xfer_mask) in ata_force_xfermask()
433 ata_unpack_xfermask(fe->param.xfer_mask, in ata_force_xfermask()
436 dev->udma_mask = udma_mask; in ata_force_xfermask()
438 dev->udma_mask = 0; in ata_force_xfermask()
439 dev->mwdma_mask = mwdma_mask; in ata_force_xfermask()
441 dev->udma_mask = 0; in ata_force_xfermask()
442 dev->mwdma_mask = 0; in ata_force_xfermask()
443 dev->pio_mask = pio_mask; in ata_force_xfermask()
447 fe->param.name); in ata_force_xfermask()
453 * ata_force_horkage - force horkage according to libata.force
465 int devno = dev->link->pmp + dev->devno; in ata_force_horkage()
470 if (ata_is_host_link(dev->link)) in ata_force_horkage()
476 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_horkage()
479 if (fe->device != -1 && fe->device != devno && in ata_force_horkage()
480 fe->device != alt_devno) in ata_force_horkage()
483 if (!(~dev->horkage & fe->param.horkage_on) && in ata_force_horkage()
484 !(dev->horkage & fe->param.horkage_off)) in ata_force_horkage()
487 dev->horkage |= fe->param.horkage_on; in ata_force_horkage()
488 dev->horkage &= ~fe->param.horkage_off; in ata_force_horkage()
491 fe->param.name); in ata_force_horkage()
501 * atapi_cmd_type - Determine ATAPI command type from SCSI opcode
570 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
571 * @tf: command to examine and configure
572 * @dev: device tf belongs to
574 * Examine the device configuration and tf->flags to calculate
580 static int ata_rwcmd_protocol(struct ata_taskfile *tf, struct ata_device *dev) in ata_rwcmd_protocol() argument
586 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; in ata_rwcmd_protocol()
587 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; in ata_rwcmd_protocol()
588 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; in ata_rwcmd_protocol()
590 if (dev->flags & ATA_DFLAG_PIO) { in ata_rwcmd_protocol()
591 tf->protocol = ATA_PROT_PIO; in ata_rwcmd_protocol()
592 index = dev->multi_count ? 0 : 8; in ata_rwcmd_protocol()
593 } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { in ata_rwcmd_protocol()
595 tf->protocol = ATA_PROT_PIO; in ata_rwcmd_protocol()
596 index = dev->multi_count ? 0 : 8; in ata_rwcmd_protocol()
598 tf->protocol = ATA_PROT_DMA; in ata_rwcmd_protocol()
604 tf->command = cmd; in ata_rwcmd_protocol()
607 return -1; in ata_rwcmd_protocol()
611 * ata_tf_read_block - Read block address from ATA taskfile
612 * @tf: ATA taskfile of interest
613 * @dev: ATA device @tf belongs to
618 * Read block address from @tf. This function can handle all
619 * three address formats - LBA, LBA48 and CHS. tf->protocol and
623 * Block address read from @tf.
625 u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) in ata_tf_read_block() argument
629 if (tf->flags & ATA_TFLAG_LBA) { in ata_tf_read_block()
630 if (tf->flags & ATA_TFLAG_LBA48) { in ata_tf_read_block()
631 block |= (u64)tf->hob_lbah << 40; in ata_tf_read_block()
632 block |= (u64)tf->hob_lbam << 32; in ata_tf_read_block()
633 block |= (u64)tf->hob_lbal << 24; in ata_tf_read_block()
635 block |= (tf->device & 0xf) << 24; in ata_tf_read_block()
637 block |= tf->lbah << 16; in ata_tf_read_block()
638 block |= tf->lbam << 8; in ata_tf_read_block()
639 block |= tf->lbal; in ata_tf_read_block()
643 cyl = tf->lbam | (tf->lbah << 8); in ata_tf_read_block()
644 head = tf->device & 0xf; in ata_tf_read_block()
645 sect = tf->lbal; in ata_tf_read_block()
653 block = (cyl * dev->heads + head) * dev->sectors + sect - 1; in ata_tf_read_block()
660 * ata_build_rw_tf - Build ATA taskfile for given read/write request
661 * @tf: Target ATA taskfile
662 * @dev: ATA device @tf belongs to
672 * Build ATA taskfile @tf for read/write request described by
677 * 0 on success, -ERANGE if the request is too large for @dev,
678 * -EINVAL if the request is invalid.
680 int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev, in ata_build_rw_tf() argument
684 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_build_rw_tf()
685 tf->flags |= tf_flags; in ata_build_rw_tf()
690 return -ERANGE; in ata_build_rw_tf()
692 tf->protocol = ATA_PROT_NCQ; in ata_build_rw_tf()
693 tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; in ata_build_rw_tf()
695 if (tf->flags & ATA_TFLAG_WRITE) in ata_build_rw_tf()
696 tf->command = ATA_CMD_FPDMA_WRITE; in ata_build_rw_tf()
698 tf->command = ATA_CMD_FPDMA_READ; in ata_build_rw_tf()
700 tf->nsect = tag << 3; in ata_build_rw_tf()
701 tf->hob_feature = (n_block >> 8) & 0xff; in ata_build_rw_tf()
702 tf->feature = n_block & 0xff; in ata_build_rw_tf()
704 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
705 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
706 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
707 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
708 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
709 tf->lbal = block & 0xff; in ata_build_rw_tf()
711 tf->device = ATA_LBA; in ata_build_rw_tf()
712 if (tf->flags & ATA_TFLAG_FUA) in ata_build_rw_tf()
713 tf->device |= 1 << 7; in ata_build_rw_tf()
715 if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLE && in ata_build_rw_tf()
717 tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; in ata_build_rw_tf()
718 } else if (dev->flags & ATA_DFLAG_LBA) { in ata_build_rw_tf()
719 tf->flags |= ATA_TFLAG_LBA; in ata_build_rw_tf()
723 tf->device |= (block >> 24) & 0xf; in ata_build_rw_tf()
725 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_build_rw_tf()
726 return -ERANGE; in ata_build_rw_tf()
729 tf->flags |= ATA_TFLAG_LBA48; in ata_build_rw_tf()
731 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_build_rw_tf()
733 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
734 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
735 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
738 return -ERANGE; in ata_build_rw_tf()
740 if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) in ata_build_rw_tf()
741 return -EINVAL; in ata_build_rw_tf()
743 tf->nsect = n_block & 0xff; in ata_build_rw_tf()
745 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
746 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
747 tf->lbal = block & 0xff; in ata_build_rw_tf()
749 tf->device |= ATA_LBA; in ata_build_rw_tf()
754 /* The request -may- be too large for CHS addressing. */ in ata_build_rw_tf()
756 return -ERANGE; in ata_build_rw_tf()
758 if (unlikely(ata_rwcmd_protocol(tf, dev) < 0)) in ata_build_rw_tf()
759 return -EINVAL; in ata_build_rw_tf()
762 track = (u32)block / dev->sectors; in ata_build_rw_tf()
763 cyl = track / dev->heads; in ata_build_rw_tf()
764 head = track % dev->heads; in ata_build_rw_tf()
765 sect = (u32)block % dev->sectors + 1; in ata_build_rw_tf()
771 Cylinder: 0-65535 in ata_build_rw_tf()
772 Head: 0-15 in ata_build_rw_tf()
773 Sector: 1-255*/ in ata_build_rw_tf()
775 return -ERANGE; in ata_build_rw_tf()
777 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_build_rw_tf()
778 tf->lbal = sect; in ata_build_rw_tf()
779 tf->lbam = cyl; in ata_build_rw_tf()
780 tf->lbah = cyl >> 8; in ata_build_rw_tf()
781 tf->device |= head; in ata_build_rw_tf()
788 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
793 * Pack @pio_mask, @mwdma_mask and @udma_mask into a single
813 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
840 { -1, },
844 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
858 int highbit = fls(xfer_mask) - 1; in ata_xfer_mask2mode()
861 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mask2mode()
862 if (highbit >= ent->shift && highbit < ent->shift + ent->bits) in ata_xfer_mask2mode()
863 return ent->base + highbit - ent->shift; in ata_xfer_mask2mode()
869 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
884 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2mask()
885 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2mask()
886 return ((2 << (ent->shift + xfer_mode - ent->base)) - 1) in ata_xfer_mode2mask()
887 & ~((1 << ent->shift) - 1); in ata_xfer_mode2mask()
893 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
902 * Matching xfer_shift, -1 if no match found.
908 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2shift()
909 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2shift()
910 return ent->shift; in ata_xfer_mode2shift()
911 return -1; in ata_xfer_mode2shift()
916 * ata_mode_string - convert xfer_mask to string
927 * @mode_mask, or the constant C string "<n/a>".
955 highbit = fls(xfer_mask) - 1; in ata_mode_string()
958 return "<n/a>"; in ata_mode_string()
970 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) in sata_spd_string()
972 return spd_str[spd - 1]; in sata_spd_string()
976 * ata_dev_classify - determine device type based on ATA-spec signature
977 * @tf: ATA taskfile register set for device to be identified
979 * Determine from taskfile register contents whether a device is
990 unsigned int ata_dev_classify(const struct ata_taskfile *tf) in ata_dev_classify() argument
993 * put a proper signature into the LBA mid/high registers, in ata_dev_classify()
996 * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate in ata_dev_classify()
1003 * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and in ata_dev_classify()
1008 * identifies a port multiplier and 0x3c/0xc3 a SEMB device. in ata_dev_classify()
1009 * Unfortunately, WDC WD1600JS-62MHB5 (a hard drive) reports in ata_dev_classify()
1013 if ((tf->lbam == 0) && (tf->lbah == 0)) { in ata_dev_classify()
1018 if ((tf->lbam == 0x14) && (tf->lbah == 0xeb)) { in ata_dev_classify()
1023 if ((tf->lbam == 0x69) && (tf->lbah == 0x96)) { in ata_dev_classify()
1028 if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) { in ata_dev_classify()
1033 if ((tf->lbam == 0xcd) && (tf->lbah == 0xab)) { in ata_dev_classify()
1044 * ata_id_string - Convert IDENTIFY DEVICE page into string
1051 * 16-bit chunks. Run through the string, and output each
1052 * 8-bit chunk linearly, regardless of platform.
1075 len -= 2; in ata_id_string()
1081 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
1099 ata_id_string(id, s, ofs, len - 1); in ata_id_c_string()
1101 p = s + strnlen(s, len - 1); in ata_id_c_string()
1102 while (p > s && p[-1] == ' ') in ata_id_c_string()
1103 p--; in ata_id_c_string()
1125 u64 ata_tf_to_lba48(const struct ata_taskfile *tf) in ata_tf_to_lba48() argument
1129 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; in ata_tf_to_lba48()
1130 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; in ata_tf_to_lba48()
1131 sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24; in ata_tf_to_lba48()
1132 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba48()
1133 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba48()
1134 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba48()
1139 u64 ata_tf_to_lba(const struct ata_taskfile *tf) in ata_tf_to_lba() argument
1143 sectors |= (tf->device & 0x0f) << 24; in ata_tf_to_lba()
1144 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba()
1145 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba()
1146 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba()
1152 * ata_read_native_max_address - Read native max address
1160 * 0 on success, -EACCES if command is aborted by the drive.
1161 * -EIO on other errors.
1166 struct ata_taskfile tf; in ata_read_native_max_address() local
1167 int lba48 = ata_id_has_lba48(dev->id); in ata_read_native_max_address()
1169 ata_tf_init(dev, &tf); in ata_read_native_max_address()
1172 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_read_native_max_address()
1175 tf.command = ATA_CMD_READ_NATIVE_MAX_EXT; in ata_read_native_max_address()
1176 tf.flags |= ATA_TFLAG_LBA48; in ata_read_native_max_address()
1178 tf.command = ATA_CMD_READ_NATIVE_MAX; in ata_read_native_max_address()
1180 tf.protocol = ATA_PROT_NODATA; in ata_read_native_max_address()
1181 tf.device |= ATA_LBA; in ata_read_native_max_address()
1183 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); in ata_read_native_max_address()
1188 if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) in ata_read_native_max_address()
1189 return -EACCES; in ata_read_native_max_address()
1190 return -EIO; in ata_read_native_max_address()
1194 *max_sectors = ata_tf_to_lba48(&tf) + 1; in ata_read_native_max_address()
1196 *max_sectors = ata_tf_to_lba(&tf) + 1; in ata_read_native_max_address()
1197 if (dev->horkage & ATA_HORKAGE_HPA_SIZE) in ata_read_native_max_address()
1198 (*max_sectors)--; in ata_read_native_max_address()
1203 * ata_set_max_sectors - Set max sectors
1210 * 0 on success, -EACCES if command is aborted or denied (due to
1211 * previous non-volatile SET_MAX) by the drive. -EIO on other
1217 struct ata_taskfile tf; in ata_set_max_sectors() local
1218 int lba48 = ata_id_has_lba48(dev->id); in ata_set_max_sectors()
1220 new_sectors--; in ata_set_max_sectors()
1222 ata_tf_init(dev, &tf); in ata_set_max_sectors()
1224 tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_set_max_sectors()
1227 tf.command = ATA_CMD_SET_MAX_EXT; in ata_set_max_sectors()
1228 tf.flags |= ATA_TFLAG_LBA48; in ata_set_max_sectors()
1230 tf.hob_lbal = (new_sectors >> 24) & 0xff; in ata_set_max_sectors()
1231 tf.hob_lbam = (new_sectors >> 32) & 0xff; in ata_set_max_sectors()
1232 tf.hob_lbah = (new_sectors >> 40) & 0xff; in ata_set_max_sectors()
1234 tf.command = ATA_CMD_SET_MAX; in ata_set_max_sectors()
1236 tf.device |= (new_sectors >> 24) & 0xf; in ata_set_max_sectors()
1239 tf.protocol = ATA_PROT_NODATA; in ata_set_max_sectors()
1240 tf.device |= ATA_LBA; in ata_set_max_sectors()
1242 tf.lbal = (new_sectors >> 0) & 0xff; in ata_set_max_sectors()
1243 tf.lbam = (new_sectors >> 8) & 0xff; in ata_set_max_sectors()
1244 tf.lbah = (new_sectors >> 16) & 0xff; in ata_set_max_sectors()
1246 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); in ata_set_max_sectors()
1252 (tf.feature & (ATA_ABORTED | ATA_IDNF))) in ata_set_max_sectors()
1253 return -EACCES; in ata_set_max_sectors()
1254 return -EIO; in ata_set_max_sectors()
1261 * ata_hpa_resize - Resize a device with an HPA set
1269 * 0 on success, -errno on failure.
1274 bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA; in ata_hpa_resize()
1275 u64 sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1280 if ((dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) || in ata_hpa_resize()
1281 !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || in ata_hpa_resize()
1282 (dev->horkage & ATA_HORKAGE_BROKEN_HPA)) in ata_hpa_resize()
1291 if (rc == -EACCES || !unlock_hpa) { in ata_hpa_resize()
1294 dev->horkage |= ATA_HORKAGE_BROKEN_HPA; in ata_hpa_resize()
1297 if (rc == -EACCES) in ata_hpa_resize()
1303 dev->n_native_sectors = native_sectors; in ata_hpa_resize()
1325 if (rc == -EACCES) { in ata_hpa_resize()
1328 "device aborted resize (%llu -> %llu), skipping HPA handling\n", in ata_hpa_resize()
1331 dev->horkage |= ATA_HORKAGE_BROKEN_HPA; in ata_hpa_resize()
1336 /* re-read IDENTIFY data */ in ata_hpa_resize()
1340 "failed to re-read IDENTIFY data after HPA resizing\n"); in ata_hpa_resize()
1345 u64 new_sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1347 "HPA unlocked: %llu -> %llu, native %llu\n", in ata_hpa_resize()
1357 * ata_dump_id - IDENTIFY DEVICE info debugging output
1360 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1396 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1422 * a mask. in ata_id_xfermask()
1426 pio_mask = (2 << mode) - 1; in ata_id_xfermask()
1431 * committee and you too can get a free iordy field to in ata_id_xfermask()
1467 struct completion *waiting = qc->private_data; in ata_qc_complete_internal()
1473 * ata_exec_internal_sg - execute libata internal command
1475 * @tf: Taskfile registers for the command and the result
1482 * Executes libata internal command with timeout. @tf contains
1485 * is taken after a command times out. It's caller's duty to
1495 struct ata_taskfile *tf, const u8 *cdb, in ata_exec_internal_sg() argument
1499 struct ata_link *link = dev->link; in ata_exec_internal_sg()
1500 struct ata_port *ap = link->ap; in ata_exec_internal_sg()
1501 u8 command = tf->command; in ata_exec_internal_sg()
1513 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal_sg()
1516 if (ap->pflags & ATA_PFLAG_FROZEN) { in ata_exec_internal_sg()
1517 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1524 qc->tag = ATA_TAG_INTERNAL; in ata_exec_internal_sg()
1525 qc->hw_tag = 0; in ata_exec_internal_sg()
1526 qc->scsicmd = NULL; in ata_exec_internal_sg()
1527 qc->ap = ap; in ata_exec_internal_sg()
1528 qc->dev = dev; in ata_exec_internal_sg()
1531 preempted_tag = link->active_tag; in ata_exec_internal_sg()
1532 preempted_sactive = link->sactive; in ata_exec_internal_sg()
1533 preempted_qc_active = ap->qc_active; in ata_exec_internal_sg()
1534 preempted_nr_active_links = ap->nr_active_links; in ata_exec_internal_sg()
1535 link->active_tag = ATA_TAG_POISON; in ata_exec_internal_sg()
1536 link->sactive = 0; in ata_exec_internal_sg()
1537 ap->qc_active = 0; in ata_exec_internal_sg()
1538 ap->nr_active_links = 0; in ata_exec_internal_sg()
1541 qc->tf = *tf; in ata_exec_internal_sg()
1543 memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); in ata_exec_internal_sg()
1546 if (tf->protocol == ATAPI_PROT_DMA && (dev->flags & ATA_DFLAG_DMADIR) && in ata_exec_internal_sg()
1548 qc->tf.feature |= ATAPI_DMADIR; in ata_exec_internal_sg()
1550 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_exec_internal_sg()
1551 qc->dma_dir = dma_dir; in ata_exec_internal_sg()
1557 buflen += sg->length; in ata_exec_internal_sg()
1560 qc->nbytes = buflen; in ata_exec_internal_sg()
1563 qc->private_data = &wait; in ata_exec_internal_sg()
1564 qc->complete_fn = ata_qc_complete_internal; in ata_exec_internal_sg()
1568 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1579 if (ap->ops->error_handler) in ata_exec_internal_sg()
1584 if (ap->ops->error_handler) in ata_exec_internal_sg()
1590 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal_sg()
1595 * cleaned up by ->post_internal_cmd(). in ata_exec_internal_sg()
1597 if (qc->flags & ATA_QCFLAG_ACTIVE) { in ata_exec_internal_sg()
1598 qc->err_mask |= AC_ERR_TIMEOUT; in ata_exec_internal_sg()
1600 if (ap->ops->error_handler) in ata_exec_internal_sg()
1610 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1614 if (ap->ops->post_internal_cmd) in ata_exec_internal_sg()
1615 ap->ops->post_internal_cmd(qc); in ata_exec_internal_sg()
1618 if (qc->flags & ATA_QCFLAG_FAILED) { in ata_exec_internal_sg()
1619 if (qc->result_tf.command & (ATA_ERR | ATA_DF)) in ata_exec_internal_sg()
1620 qc->err_mask |= AC_ERR_DEV; in ata_exec_internal_sg()
1622 if (!qc->err_mask) in ata_exec_internal_sg()
1623 qc->err_mask |= AC_ERR_OTHER; in ata_exec_internal_sg()
1625 if (qc->err_mask & ~AC_ERR_OTHER) in ata_exec_internal_sg()
1626 qc->err_mask &= ~AC_ERR_OTHER; in ata_exec_internal_sg()
1627 } else if (qc->tf.command == ATA_CMD_REQ_SENSE_DATA) { in ata_exec_internal_sg()
1628 qc->result_tf.command |= ATA_SENSE; in ata_exec_internal_sg()
1632 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal_sg()
1634 *tf = qc->result_tf; in ata_exec_internal_sg()
1635 err_mask = qc->err_mask; in ata_exec_internal_sg()
1638 link->active_tag = preempted_tag; in ata_exec_internal_sg()
1639 link->sactive = preempted_sactive; in ata_exec_internal_sg()
1640 ap->qc_active = preempted_qc_active; in ata_exec_internal_sg()
1641 ap->nr_active_links = preempted_nr_active_links; in ata_exec_internal_sg()
1643 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal_sg()
1652 * ata_exec_internal - execute libata internal command
1654 * @tf: Taskfile registers for the command and the result
1671 struct ata_taskfile *tf, const u8 *cdb, in ata_exec_internal() argument
1685 return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem, in ata_exec_internal()
1690 * ata_pio_need_iordy - check if iordy needed
1702 if (adev->link->ap->pflags & ATA_PFLAG_RESETTING) in ata_pio_need_iordy()
1704 /* Controller doesn't support IORDY. Probably a pointless in ata_pio_need_iordy()
1707 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) in ata_pio_need_iordy()
1710 if (ata_id_is_cfa(adev->id) in ata_pio_need_iordy()
1711 && (adev->pio_mode == XFER_PIO_5 || adev->pio_mode == XFER_PIO_6)) in ata_pio_need_iordy()
1714 if (adev->pio_mode > XFER_PIO_2) in ata_pio_need_iordy()
1717 if (ata_id_has_iordy(adev->id)) in ata_pio_need_iordy()
1724 * ata_pio_mask_no_iordy - Return the non IORDY mask
1728 * -1 if no iordy mode is available.
1733 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ in ata_pio_mask_no_iordy()
1734 u16 pio = adev->id[ATA_ID_EIDE_PIO]; in ata_pio_mask_no_iordy()
1737 /* This is cycle times not frequency - watch the logic! */ in ata_pio_mask_no_iordy()
1747 * ata_do_dev_read_id - default ID read method
1749 * @tf: proposed taskfile
1757 struct ata_taskfile *tf, u16 *id) in ata_do_dev_read_id() argument
1759 return ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE, in ata_do_dev_read_id()
1765 * ata_dev_read_id - Read ID data from the specified device
1774 * for pre-ATA4 drives.
1783 * 0 on success, -errno otherwise.
1788 struct ata_port *ap = dev->link->ap; in ata_dev_read_id()
1790 struct ata_taskfile tf; in ata_dev_read_id() local
1801 ata_tf_init(dev, &tf); in ata_dev_read_id()
1809 tf.command = ATA_CMD_ID_ATA; in ata_dev_read_id()
1812 tf.command = ATA_CMD_ID_ATAPI; in ata_dev_read_id()
1815 rc = -ENODEV; in ata_dev_read_id()
1820 tf.protocol = ATA_PROT_PIO; in ata_dev_read_id()
1822 /* Some devices choke if TF registers contain garbage. Make in ata_dev_read_id()
1825 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_dev_read_id()
1830 tf.flags |= ATA_TFLAG_POLLING; in ata_dev_read_id()
1832 if (ap->ops->read_id) in ata_dev_read_id()
1833 err_mask = ap->ops->read_id(dev, &tf, id); in ata_dev_read_id()
1835 err_mask = ata_do_dev_read_id(dev, &tf, id); in ata_dev_read_id()
1840 return -ENOENT; in ata_dev_read_id()
1851 if ((err_mask == AC_ERR_DEV) && (tf.feature & ATA_ABORTED)) { in ata_dev_read_id()
1853 * the wrong device class. Give a shot at the in ata_dev_read_id()
1873 return -ENOENT; in ata_dev_read_id()
1876 rc = -EIO; in ata_dev_read_id()
1881 if (dev->horkage & ATA_HORKAGE_DUMP_ID) { in ata_dev_read_id()
1897 rc = -EINVAL; in ata_dev_read_id()
1903 if (ap->host->flags & ATA_HOST_IGNORE_ATA && in ata_dev_read_id()
1907 return -ENOENT; in ata_dev_read_id()
1917 * Drive powered-up in standby mode, and requires a specific in ata_dev_read_id()
1918 * SET_FEATURES spin-up subcommand before it will accept in ata_dev_read_id()
1923 rc = -EIO; in ata_dev_read_id()
1938 * The exact sequence expected by certain pre-ATA4 drives is: in ata_dev_read_id()
1951 rc = -EIO; in ata_dev_read_id()
1956 /* current CHS translation info (id[53-58]) might be in ata_dev_read_id()
1976 * ata_read_log_page - read a specific log page
1994 unsigned long ap_flags = dev->link->ap->flags; in ata_read_log_page()
1995 struct ata_taskfile tf; in ata_read_log_page() local
1999 DPRINTK("read log page - log 0x%x, page 0x%x\n", log, page); in ata_read_log_page()
2003 * which e.g. lockup on a read log page. in ata_read_log_page()
2009 ata_tf_init(dev, &tf); in ata_read_log_page()
2010 if (dev->dma_mode && ata_id_has_read_log_dma_ext(dev->id) && in ata_read_log_page()
2011 !(dev->horkage & ATA_HORKAGE_NO_DMA_LOG)) { in ata_read_log_page()
2012 tf.command = ATA_CMD_READ_LOG_DMA_EXT; in ata_read_log_page()
2013 tf.protocol = ATA_PROT_DMA; in ata_read_log_page()
2016 tf.command = ATA_CMD_READ_LOG_EXT; in ata_read_log_page()
2017 tf.protocol = ATA_PROT_PIO; in ata_read_log_page()
2020 tf.lbal = log; in ata_read_log_page()
2021 tf.lbam = page; in ata_read_log_page()
2022 tf.nsect = sectors; in ata_read_log_page()
2023 tf.hob_nsect = sectors >> 8; in ata_read_log_page()
2024 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_LBA48 | ATA_TFLAG_DEVICE; in ata_read_log_page()
2026 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE, in ata_read_log_page()
2031 dev->horkage |= ATA_HORKAGE_NO_DMA_LOG; in ata_read_log_page()
2043 struct ata_port *ap = dev->link->ap; in ata_log_supported()
2045 if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, ap->sector_buf, 1)) in ata_log_supported()
2047 return get_unaligned_le16(&ap->sector_buf[log * 2]) ? true : false; in ata_log_supported()
2052 struct ata_port *ap = dev->link->ap; in ata_identify_page_supported()
2064 err = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, 0, ap->sector_buf, in ata_identify_page_supported()
2069 for (i = 0; i < ap->sector_buf[8]; i++) { in ata_identify_page_supported()
2070 if (ap->sector_buf[9 + i] == page) in ata_identify_page_supported()
2085 if (dev->horkage & ATA_HORKAGE_1_5_GBPS) in ata_do_link_spd_horkage()
2090 target_limit = (1 << target) - 1; in ata_do_link_spd_horkage()
2093 if (plink->sata_spd_limit <= target_limit) in ata_do_link_spd_horkage()
2096 plink->sata_spd_limit = target_limit; in ata_do_link_spd_horkage()
2098 /* Request another EH round by returning -EAGAIN if link is in ata_do_link_spd_horkage()
2102 if (plink->sata_spd > target) { in ata_do_link_spd_horkage()
2105 return -EAGAIN; in ata_do_link_spd_horkage()
2112 struct ata_port *ap = dev->link->ap; in ata_dev_knobble()
2117 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); in ata_dev_knobble()
2122 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_send_recv()
2130 0, ap->sector_buf, 1); in ata_dev_config_ncq_send_recv()
2132 u8 *cmds = dev->ncq_send_recv_cmds; in ata_dev_config_ncq_send_recv()
2134 dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; in ata_dev_config_ncq_send_recv()
2135 memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE); in ata_dev_config_ncq_send_recv()
2137 if (dev->horkage & ATA_HORKAGE_NO_NCQ_TRIM) { in ata_dev_config_ncq_send_recv()
2147 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_non_data()
2156 0, ap->sector_buf, 1); in ata_dev_config_ncq_non_data()
2158 u8 *cmds = dev->ncq_non_data_cmds; in ata_dev_config_ncq_non_data()
2160 memcpy(cmds, ap->sector_buf, ATA_LOG_NCQ_NON_DATA_SIZE); in ata_dev_config_ncq_non_data()
2166 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq_prio()
2172 ap->sector_buf, in ata_dev_config_ncq_prio()
2177 if (!(ap->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) in ata_dev_config_ncq_prio()
2180 dev->flags |= ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2185 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLE; in ata_dev_config_ncq_prio()
2186 dev->flags &= ~ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2195 for (parent_dev = dev->tdev.parent; parent_dev != NULL; in ata_dev_check_adapter()
2196 parent_dev = parent_dev->parent) { in ata_dev_check_adapter()
2199 if (pcidev->vendor == vendor_id) in ata_dev_check_adapter()
2211 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq()
2212 int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); in ata_dev_config_ncq()
2216 if (!ata_id_has_ncq(dev->id)) { in ata_dev_config_ncq()
2222 if (dev->horkage & ATA_HORKAGE_NONCQ) { in ata_dev_config_ncq()
2227 if (dev->horkage & ATA_HORKAGE_NO_NCQ_ON_ATI && in ata_dev_config_ncq()
2233 if (ap->flags & ATA_FLAG_NCQ) { in ata_dev_config_ncq()
2234 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE); in ata_dev_config_ncq()
2235 dev->flags |= ATA_DFLAG_NCQ; in ata_dev_config_ncq()
2238 if (!(dev->horkage & ATA_HORKAGE_BROKEN_FPDMA_AA) && in ata_dev_config_ncq()
2239 (ap->flags & ATA_FLAG_FPDMA_AA) && in ata_dev_config_ncq()
2240 ata_id_has_fpdma_aa(dev->id)) { in ata_dev_config_ncq()
2248 dev->horkage |= ATA_HORKAGE_BROKEN_FPDMA_AA; in ata_dev_config_ncq()
2249 return -EIO; in ata_dev_config_ncq()
2261 if ((ap->flags & ATA_FLAG_FPDMA_AUX)) { in ata_dev_config_ncq()
2262 if (ata_id_has_ncq_send_and_recv(dev->id)) in ata_dev_config_ncq()
2264 if (ata_id_has_ncq_non_data(dev->id)) in ata_dev_config_ncq()
2266 if (ata_id_has_ncq_prio(dev->id)) in ata_dev_config_ncq()
2277 if (!ata_id_has_sense_reporting(dev->id)) in ata_dev_config_sense_reporting()
2280 if (ata_id_sense_reporting_enabled(dev->id)) in ata_dev_config_sense_reporting()
2293 struct ata_port *ap = dev->link->ap; in ata_dev_config_zac()
2295 u8 *identify_buf = ap->sector_buf; in ata_dev_config_zac()
2297 dev->zac_zones_optimal_open = U32_MAX; in ata_dev_config_zac()
2298 dev->zac_zones_optimal_nonseq = U32_MAX; in ata_dev_config_zac()
2299 dev->zac_zones_max_open = U32_MAX; in ata_dev_config_zac()
2302 * Always set the 'ZAC' flag for Host-managed devices. in ata_dev_config_zac()
2304 if (dev->class == ATA_DEV_ZAC) in ata_dev_config_zac()
2305 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2306 else if (ata_id_zoned_cap(dev->id) == 0x01) in ata_dev_config_zac()
2308 * Check for host-aware devices. in ata_dev_config_zac()
2310 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2312 if (!(dev->flags & ATA_DFLAG_ZAC)) in ata_dev_config_zac()
2322 * Read IDENTIFY DEVICE data log, page 9 (Zoned-device information) in ata_dev_config_zac()
2332 dev->zac_zoned_cap = (zoned_cap & 1); in ata_dev_config_zac()
2335 dev->zac_zones_optimal_open = (u32)opt_open; in ata_dev_config_zac()
2338 dev->zac_zones_optimal_nonseq = (u32)opt_nonseq; in ata_dev_config_zac()
2341 dev->zac_zones_max_open = (u32)max_open; in ata_dev_config_zac()
2347 struct ata_port *ap = dev->link->ap; in ata_dev_config_trusted()
2351 if (!ata_id_has_trusted(dev->id)) in ata_dev_config_trusted()
2361 ap->sector_buf, 1); in ata_dev_config_trusted()
2365 trusted_cap = get_unaligned_le64(&ap->sector_buf[40]); in ata_dev_config_trusted()
2373 dev->flags |= ATA_DFLAG_TRUSTED; in ata_dev_config_trusted()
2378 struct ata_port *ap = dev->link->ap; in ata_dev_config_lba()
2379 const u16 *id = dev->id; in ata_dev_config_lba()
2384 dev->flags |= ATA_DFLAG_LBA; in ata_dev_config_lba()
2388 dev->flags |= ATA_DFLAG_LBA48; in ata_dev_config_lba()
2389 if (dev->n_sectors >= (1UL << 28) && in ata_dev_config_lba()
2391 dev->flags |= ATA_DFLAG_FLUSH_EXT; in ata_dev_config_lba()
2403 (unsigned long long)dev->n_sectors, in ata_dev_config_lba()
2404 dev->multi_count, lba_desc, ncq_desc); in ata_dev_config_lba()
2411 struct ata_port *ap = dev->link->ap; in ata_dev_config_chs()
2412 const u16 *id = dev->id; in ata_dev_config_chs()
2416 dev->cylinders = id[54]; in ata_dev_config_chs()
2417 dev->heads = id[55]; in ata_dev_config_chs()
2418 dev->sectors = id[56]; in ata_dev_config_chs()
2421 dev->cylinders = id[1]; in ata_dev_config_chs()
2422 dev->heads = id[3]; in ata_dev_config_chs()
2423 dev->sectors = id[6]; in ata_dev_config_chs()
2430 (unsigned long long)dev->n_sectors, in ata_dev_config_chs()
2431 dev->multi_count, dev->cylinders, in ata_dev_config_chs()
2432 dev->heads, dev->sectors); in ata_dev_config_chs()
2437 u8 *sata_setting = dev->link->ap->sector_buf; in ata_dev_config_devslp()
2445 if (!ata_id_has_devslp(dev->id)) in ata_dev_config_devslp()
2455 dev->flags |= ATA_DFLAG_DEVSLP; in ata_dev_config_devslp()
2458 dev->devslp_timing[i] = sata_setting[j]; in ata_dev_config_devslp()
2464 if (!(dev->flags & ATA_DFLAG_FEATURES_MASK)) in ata_dev_print_features()
2469 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", in ata_dev_print_features()
2470 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", in ata_dev_print_features()
2471 dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", in ata_dev_print_features()
2472 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", in ata_dev_print_features()
2473 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : ""); in ata_dev_print_features()
2477 * ata_dev_configure - Configure the specified ATA/ATAPI device
2480 * Configure @dev according to @dev->id. Generic and low-level
2487 * 0 on success, -errno otherwise
2491 struct ata_port *ap = dev->link->ap; in ata_dev_configure()
2493 const u16 *id = dev->id; in ata_dev_configure()
2496 char revbuf[7]; /* XYZ-99\0 */ in ata_dev_configure()
2502 ata_dev_info(dev, "%s: ENTER/EXIT -- nodev\n", __func__); in ata_dev_configure()
2510 dev->horkage |= ata_dev_blacklisted(dev); in ata_dev_configure()
2513 if (dev->horkage & ATA_HORKAGE_DISABLE) { in ata_dev_configure()
2519 if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) && in ata_dev_configure()
2520 dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2532 /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */ in ata_dev_configure()
2533 if ((dev->horkage & ATA_HORKAGE_WD_BROKEN_LPM) && in ata_dev_configure()
2535 dev->horkage |= ATA_HORKAGE_NOLPM; in ata_dev_configure()
2537 if (ap->flags & ATA_FLAG_NO_LPM) in ata_dev_configure()
2538 dev->horkage |= ATA_HORKAGE_NOLPM; in ata_dev_configure()
2540 if (dev->horkage & ATA_HORKAGE_NOLPM) { in ata_dev_configure()
2542 dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER; in ata_dev_configure()
2564 /* initialize to-be-configured parameters */ in ata_dev_configure()
2565 dev->flags &= ~ATA_DFLAG_CFG_MASK; in ata_dev_configure()
2566 dev->max_sectors = 0; in ata_dev_configure()
2567 dev->cdb_len = 0; in ata_dev_configure()
2568 dev->n_sectors = 0; in ata_dev_configure()
2569 dev->cylinders = 0; in ata_dev_configure()
2570 dev->heads = 0; in ata_dev_configure()
2571 dev->sectors = 0; in ata_dev_configure()
2572 dev->multi_count = 0; in ata_dev_configure()
2584 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ in ata_dev_configure()
2585 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, in ata_dev_configure()
2588 ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, in ata_dev_configure()
2591 /* ATA-specific feature tests */ in ata_dev_configure()
2592 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in ata_dev_configure()
2600 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); in ata_dev_configure()
2607 dev->n_sectors = ata_id_n_sectors(id); in ata_dev_configure()
2610 if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) { in ata_dev_configure()
2611 unsigned int max = dev->id[47] & 0xff; in ata_dev_configure()
2612 unsigned int cnt = dev->id[59] & 0xff; in ata_dev_configure()
2616 dev->multi_count = cnt; in ata_dev_configure()
2637 dev->cdb_len = 32; in ata_dev_configure()
2643 /* ATAPI-specific feature tests */ in ata_dev_configure()
2644 else if (dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2654 rc = -EINVAL; in ata_dev_configure()
2657 dev->cdb_len = (unsigned int) rc; in ata_dev_configure()
2665 (ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && in ata_dev_configure()
2667 sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { in ata_dev_configure()
2676 dev->flags |= ATA_DFLAG_AN; in ata_dev_configure()
2681 if (ata_id_cdb_intr(dev->id)) { in ata_dev_configure()
2682 dev->flags |= ATA_DFLAG_CDB_INTR; in ata_dev_configure()
2686 if (atapi_dmadir || (dev->horkage & ATA_HORKAGE_ATAPI_DMADIR) || atapi_id_dmadir(dev->id)) { in ata_dev_configure()
2687 dev->flags |= ATA_DFLAG_DMADIR; in ata_dev_configure()
2691 if (ata_id_has_da(dev->id)) { in ata_dev_configure()
2692 dev->flags |= ATA_DFLAG_DA; in ata_dev_configure()
2707 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
2708 if (dev->flags & ATA_DFLAG_LBA48) in ata_dev_configure()
2709 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
2716 dev->udma_mask &= ATA_UDMA5; in ata_dev_configure()
2717 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
2720 if ((dev->class == ATA_DEV_ATAPI) && in ata_dev_configure()
2722 dev->max_sectors = ATA_MAX_SECTORS_TAPE; in ata_dev_configure()
2723 dev->horkage |= ATA_HORKAGE_STUCK_ERR; in ata_dev_configure()
2726 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) in ata_dev_configure()
2727 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, in ata_dev_configure()
2728 dev->max_sectors); in ata_dev_configure()
2730 if (dev->horkage & ATA_HORKAGE_MAX_SEC_1024) in ata_dev_configure()
2731 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_1024, in ata_dev_configure()
2732 dev->max_sectors); in ata_dev_configure()
2734 if (dev->horkage & ATA_HORKAGE_MAX_SEC_LBA48) in ata_dev_configure()
2735 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
2737 if (ap->ops->dev_config) in ata_dev_configure()
2738 ap->ops->dev_config(dev); in ata_dev_configure()
2740 if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) { in ata_dev_configure()
2742 rescue purposes, or in case the vendor is just a blithering in ata_dev_configure()
2749 "Drive reports diagnostics failure. This may indicate a drive\n"); in ata_dev_configure()
2755 if ((dev->horkage & ATA_HORKAGE_FIRMWARE_WARN) && print_info) { in ata_dev_configure()
2769 * ata_cable_40wire - return 40 wire cable type
2783 * ata_cable_80wire - return 80 wire cable type
2797 * ata_cable_unknown - return unknown PATA cable.
2810 * ata_cable_ignore - return ignored PATA cable.
2823 * ata_cable_sata - return SATA cable type
2836 * ata_bus_probe - Reset and probe ATA bus
2839 * Master ATA bus probing function. Initiates a hardware-dependent
2857 ata_for_each_dev(dev, &ap->link, ALL) in ata_bus_probe()
2858 tries[dev->devno] = ATA_PROBE_MAX_TRIES; in ata_bus_probe()
2861 ata_for_each_dev(dev, &ap->link, ALL) { in ata_bus_probe()
2864 * we do a hard reset (or are coming from power on) in ata_bus_probe()
2865 * this is true for ATA or ATAPI. Until we've set a in ata_bus_probe()
2869 dev->pio_mode = XFER_PIO_0; in ata_bus_probe()
2870 dev->dma_mode = 0xff; in ata_bus_probe()
2872 /* If the controller has a pio mode setup function in ata_bus_probe()
2877 if (ap->ops->set_piomode) in ata_bus_probe()
2878 ap->ops->set_piomode(ap, dev); in ata_bus_probe()
2882 ap->ops->phy_reset(ap); in ata_bus_probe()
2884 ata_for_each_dev(dev, &ap->link, ALL) { in ata_bus_probe()
2885 if (dev->class != ATA_DEV_UNKNOWN) in ata_bus_probe()
2886 classes[dev->devno] = dev->class; in ata_bus_probe()
2888 classes[dev->devno] = ATA_DEV_NONE; in ata_bus_probe()
2890 dev->class = ATA_DEV_UNKNOWN; in ata_bus_probe()
2894 specific sequence bass-ackwards so that PDIAG- is released by in ata_bus_probe()
2897 ata_for_each_dev(dev, &ap->link, ALL_REVERSE) { in ata_bus_probe()
2898 if (tries[dev->devno]) in ata_bus_probe()
2899 dev->class = classes[dev->devno]; in ata_bus_probe()
2904 rc = ata_dev_read_id(dev, &dev->class, ATA_READID_POSTRESET, in ata_bus_probe()
2905 dev->id); in ata_bus_probe()
2910 /* Now ask for the cable type as PDIAG- should have been released */ in ata_bus_probe()
2911 if (ap->ops->cable_detect) in ata_bus_probe()
2912 ap->cbl = ap->ops->cable_detect(ap); in ata_bus_probe()
2916 * drives indicate we have a bridge, we don't know which end in ata_bus_probe()
2917 * of the link the bridge is which is a problem. in ata_bus_probe()
2919 ata_for_each_dev(dev, &ap->link, ENABLED) in ata_bus_probe()
2920 if (ata_id_is_sata(dev->id)) in ata_bus_probe()
2921 ap->cbl = ATA_CBL_SATA; in ata_bus_probe()
2926 ata_for_each_dev(dev, &ap->link, ENABLED) { in ata_bus_probe()
2927 ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO; in ata_bus_probe()
2929 ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO; in ata_bus_probe()
2935 rc = ata_set_mode(&ap->link, &dev); in ata_bus_probe()
2939 ata_for_each_dev(dev, &ap->link, ENABLED) in ata_bus_probe()
2942 return -ENODEV; in ata_bus_probe()
2945 tries[dev->devno]--; in ata_bus_probe()
2948 case -EINVAL: in ata_bus_probe()
2950 tries[dev->devno] = 0; in ata_bus_probe()
2953 case -ENODEV: in ata_bus_probe()
2955 tries[dev->devno] = min(tries[dev->devno], 1); in ata_bus_probe()
2957 case -EIO: in ata_bus_probe()
2958 if (tries[dev->devno] == 1) { in ata_bus_probe()
2962 sata_down_spd_limit(&ap->link, 0); in ata_bus_probe()
2967 if (!tries[dev->devno]) in ata_bus_probe()
2974 * sata_print_link_status - Print SATA link status
2977 * This function prints link speed and status of a SATA link.
3001 * ata_dev_pair - return other device on cable
3010 struct ata_link *link = adev->link; in ata_dev_pair()
3011 struct ata_device *pair = &link->device[1 - adev->devno]; in ata_dev_pair()
3019 * sata_down_spd_limit - adjust SATA spd limit downward
3027 * If @spd_limit is non-zero, the speed is limited to equal to or
3044 return -EOPNOTSUPP; in sata_down_spd_limit()
3047 * If not, use cached value in link->sata_spd. in sata_down_spd_limit()
3053 spd = link->sata_spd; in sata_down_spd_limit()
3055 mask = link->sata_spd_limit; in sata_down_spd_limit()
3057 return -EINVAL; in sata_down_spd_limit()
3060 bit = fls(mask) - 1; in sata_down_spd_limit()
3068 * Otherwise, we should not force 1.5Gbps on a link where we have in sata_down_spd_limit()
3073 mask &= (1 << (spd - 1)) - 1; in sata_down_spd_limit()
3075 return -EINVAL; in sata_down_spd_limit()
3079 return -EINVAL; in sata_down_spd_limit()
3082 if (mask & ((1 << spd_limit) - 1)) in sata_down_spd_limit()
3083 mask &= (1 << spd_limit) - 1; in sata_down_spd_limit()
3085 bit = ffs(mask) - 1; in sata_down_spd_limit()
3090 link->sata_spd_limit = mask; in sata_down_spd_limit()
3100 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration
3121 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_timing_cycle2mode()
3122 if (ent->shift == xfer_shift) in ata_timing_cycle2mode()
3123 base_mode = ent->base; in ata_timing_cycle2mode()
3126 t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { in ata_timing_cycle2mode()
3132 this_cycle = t->cycle; in ata_timing_cycle2mode()
3135 this_cycle = t->udma; in ata_timing_cycle2mode()
3144 last_mode = t->mode; in ata_timing_cycle2mode()
3152 * ata_down_xfermask_limit - adjust dev xfer masks downward
3176 xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, in ata_down_xfermask_limit()
3177 dev->mwdma_mask, in ata_down_xfermask_limit()
3178 dev->udma_mask); in ata_down_xfermask_limit()
3183 highbit = fls(pio_mask) - 1; in ata_down_xfermask_limit()
3189 highbit = fls(udma_mask) - 1; in ata_down_xfermask_limit()
3192 return -ENOENT; in ata_down_xfermask_limit()
3194 highbit = fls(mwdma_mask) - 1; in ata_down_xfermask_limit()
3197 return -ENOENT; in ata_down_xfermask_limit()
3220 return -ENOENT; in ata_down_xfermask_limit()
3234 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, in ata_down_xfermask_limit()
3235 &dev->udma_mask); in ata_down_xfermask_limit()
3242 struct ata_port *ap = dev->link->ap; in ata_dev_set_mode()
3243 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_set_mode()
3244 const bool nosetxfer = dev->horkage & ATA_HORKAGE_NOSETXFER; in ata_dev_set_mode()
3250 dev->flags &= ~ATA_DFLAG_PIO; in ata_dev_set_mode()
3251 if (dev->xfer_shift == ATA_SHIFT_PIO) in ata_dev_set_mode()
3252 dev->flags |= ATA_DFLAG_PIO; in ata_dev_set_mode()
3254 if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id)) in ata_dev_set_mode()
3259 "NOSETXFER but PATA detected - can't " in ata_dev_set_mode()
3268 ehc->i.flags |= ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3270 ehc->i.flags &= ~ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3274 if (dev->xfer_shift == ATA_SHIFT_PIO) { in ata_dev_set_mode()
3276 if (ata_id_is_cfa(dev->id)) in ata_dev_set_mode()
3280 if (ata_id_major_version(dev->id) == 0 && in ata_dev_set_mode()
3281 dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3284 any kind of SET_XFERMODE request but support PIO0-2 in ata_dev_set_mode()
3286 if (!ata_id_has_iordy(dev->id) && dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3291 if (dev->xfer_shift == ATA_SHIFT_MWDMA && in ata_dev_set_mode()
3292 dev->dma_mode == XFER_MW_DMA_0 && in ata_dev_set_mode()
3293 (dev->id[63] >> 8) & 1) in ata_dev_set_mode()
3297 if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) in ata_dev_set_mode()
3308 dev->xfer_shift, (int)dev->xfer_mode); in ata_dev_set_mode()
3310 if (!(ehc->i.flags & ATA_EHI_QUIET) || in ata_dev_set_mode()
3311 ehc->i.flags & ATA_EHI_DID_HARDRESET) in ata_dev_set_mode()
3313 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), in ata_dev_set_mode()
3320 return -EIO; in ata_dev_set_mode()
3324 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
3342 struct ata_port *ap = link->ap; in ata_do_set_mode()
3352 if (dev->class == ATA_DEV_ATAPI) in ata_do_set_mode()
3354 else if (ata_id_is_cfa(dev->id)) in ata_do_set_mode()
3360 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); in ata_do_set_mode()
3363 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, in ata_do_set_mode()
3364 dev->udma_mask); in ata_do_set_mode()
3368 dev->pio_mode = ata_xfer_mask2mode(pio_mask); in ata_do_set_mode()
3369 dev->dma_mode = ata_xfer_mask2mode(dma_mask); in ata_do_set_mode()
3380 if (dev->pio_mode == 0xff) { in ata_do_set_mode()
3382 rc = -EINVAL; in ata_do_set_mode()
3386 dev->xfer_mode = dev->pio_mode; in ata_do_set_mode()
3387 dev->xfer_shift = ATA_SHIFT_PIO; in ata_do_set_mode()
3388 if (ap->ops->set_piomode) in ata_do_set_mode()
3389 ap->ops->set_piomode(ap, dev); in ata_do_set_mode()
3397 dev->xfer_mode = dev->dma_mode; in ata_do_set_mode()
3398 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); in ata_do_set_mode()
3399 if (ap->ops->set_dmamode) in ata_do_set_mode()
3400 ap->ops->set_dmamode(ap, dev); in ata_do_set_mode()
3413 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) in ata_do_set_mode()
3414 ap->host->simplex_claimed = ap; in ata_do_set_mode()
3424 * ata_wait_ready - wait for link to become ready
3430 * positive number if @link is ready, 0 if it isn't, -ENODEV if
3434 * Transient -ENODEV conditions are allowed for
3441 * 0 if @link is ready before @deadline; otherwise, -errno.
3451 if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN) in ata_wait_ready()
3460 WARN_ON(link == link->ap->slave_link); in ata_wait_ready()
3474 * -ENODEV could be transient. Ignore -ENODEV if link in ata_wait_ready()
3475 * is online. Also, some SATA devices take a long in ata_wait_ready()
3477 * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't in ata_wait_ready()
3484 if (ready == -ENODEV) { in ata_wait_ready()
3487 else if ((link->ap->flags & ATA_FLAG_SATA) && in ata_wait_ready()
3496 return -EBUSY; in ata_wait_ready()
3499 (deadline - now > 3 * HZ)) { in ata_wait_ready()
3506 ata_msleep(link->ap, 50); in ata_wait_ready()
3511 * ata_wait_after_reset - wait for link to become ready after reset
3522 * 0 if @link is ready before @deadline; otherwise, -errno.
3527 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); in ata_wait_after_reset()
3534 * ata_std_prereset - prepare for reset
3540 * that port, so prereset should be best-effort. It does its
3548 * 0 on success, -errno otherwise.
3552 struct ata_port *ap = link->ap; in ata_std_prereset()
3553 struct ata_eh_context *ehc = &link->eh_context; in ata_std_prereset()
3558 if (ehc->i.action & ATA_EH_HARDRESET) in ata_std_prereset()
3562 if (ap->flags & ATA_FLAG_SATA) { in ata_std_prereset()
3565 if (rc && rc != -EOPNOTSUPP) in ata_std_prereset()
3573 ehc->i.action &= ~ATA_EH_SOFTRESET; in ata_std_prereset()
3580 * sata_std_hardreset - COMRESET w/o waiting or classification
3591 * 0 if link offline, -EAGAIN if link online, -errno on errors.
3596 const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context); in sata_std_hardreset()
3602 return online ? -EAGAIN : rc; in sata_std_hardreset()
3607 * ata_std_postreset - standard postreset callback
3611 * This function is invoked after a successful reset. Note that
3636 * ata_dev_same_device - Determine whether new ID matches configured device
3654 const u16 *old_id = dev->id; in ata_dev_same_device()
3658 if (dev->class != new_class) { in ata_dev_same_device()
3660 dev->class, new_class); in ata_dev_same_device()
3685 * ata_dev_reread_id - Re-read IDENTIFY data
3689 * Re-read IDENTIFY page and make sure @dev is still attached to
3700 unsigned int class = dev->class; in ata_dev_reread_id()
3701 u16 *id = (void *)dev->link->ap->sector_buf; in ata_dev_reread_id()
3711 return -ENODEV; in ata_dev_reread_id()
3713 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); in ata_dev_reread_id()
3718 * ata_dev_revalidate - Revalidate ATA device
3723 * Re-read IDENTIFY page, make sure @dev is still attached to the
3735 u64 n_sectors = dev->n_sectors; in ata_dev_revalidate()
3736 u64 n_native_sectors = dev->n_native_sectors; in ata_dev_revalidate()
3740 return -ENODEV; in ata_dev_revalidate()
3749 dev->class, new_class); in ata_dev_revalidate()
3750 rc = -ENODEV; in ata_dev_revalidate()
3754 /* re-read ID */ in ata_dev_revalidate()
3765 if (dev->class != ATA_DEV_ATA || !n_sectors || in ata_dev_revalidate()
3766 dev->n_sectors == n_sectors) in ata_dev_revalidate()
3772 (unsigned long long)dev->n_sectors); in ata_dev_revalidate()
3779 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3780 dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) { in ata_dev_revalidate()
3794 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3795 dev->n_sectors < n_sectors && n_sectors == n_native_sectors && in ata_dev_revalidate()
3796 !(dev->horkage & ATA_HORKAGE_BROKEN_HPA)) { in ata_dev_revalidate()
3801 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_dev_revalidate()
3802 rc = -EIO; in ata_dev_revalidate()
3804 rc = -ENODEV; in ata_dev_revalidate()
3807 dev->n_native_sectors = n_native_sectors; in ata_dev_revalidate()
3808 dev->n_sectors = n_sectors; in ata_dev_revalidate()
3829 { "Compaq CRD-8241B", NULL, ATA_HORKAGE_NODMA },
3830 { "CRD-8400B", NULL, ATA_HORKAGE_NODMA },
3831 { "CRD-848[02]B", NULL, ATA_HORKAGE_NODMA },
3832 { "CRD-84", NULL, ATA_HORKAGE_NODMA },
3834 { "SanDisk SDP3B-64", NULL, ATA_HORKAGE_NODMA },
3835 { "SANYO CD-ROM CRD", NULL, ATA_HORKAGE_NODMA },
3836 { "HITACHI CDR-8", NULL, ATA_HORKAGE_NODMA },
3837 { "HITACHI CDR-8[34]35",NULL, ATA_HORKAGE_NODMA },
3838 { "Toshiba CD-ROM XM-6202B", NULL, ATA_HORKAGE_NODMA },
3839 { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_HORKAGE_NODMA },
3840 { "CD-532E-A", NULL, ATA_HORKAGE_NODMA },
3841 { "E-IDE CD-ROM CR-840",NULL, ATA_HORKAGE_NODMA },
3842 { "CD-ROM Drive/F5A", NULL, ATA_HORKAGE_NODMA },
3843 { "WPI CDD-820", NULL, ATA_HORKAGE_NODMA },
3844 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_HORKAGE_NODMA },
3845 { "SAMSUNG CD-ROM SC", NULL, ATA_HORKAGE_NODMA },
3846 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
3848 { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA },
3851 { "VRFDFC22048UCHC-TE*", NULL, ATA_HORKAGE_NODMA },
3856 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 },
3857 { "QUANTUM DAT DAT72-000", NULL, ATA_HORKAGE_ATAPI_MOD16_DMA },
3858 { "Slimtype DVD A DS8A8SH", NULL, ATA_HORKAGE_MAX_SEC_LBA48 },
3859 { "Slimtype DVD A DS8A9SH", NULL, ATA_HORKAGE_MAX_SEC_LBA48 },
3871 { "LITEON CX1-JB*-HP", NULL, ATA_HORKAGE_MAX_SEC_1024 },
3872 { "LITEON EP1-*", NULL, ATA_HORKAGE_MAX_SEC_1024 },
3878 { "WDC WD740ADFD-00", NULL, ATA_HORKAGE_NONCQ },
3879 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, },
3890 { "ST31500341AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
3893 { "ST31000333AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
3896 { "ST3640[36]23AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
3899 { "ST3320[68]13AS", "SD1[5-9]", ATA_HORKAGE_NONCQ |
3904 { "ST1000LM024 HN-M101MBB", NULL, ATA_HORKAGE_BROKEN_FPDMA_AA |
3909 Windows driver .inf file - also several Linux problem reports */
3915 { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, },
3922 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
3923 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA },
3927 { "OCZ-VERTEX", "1.30", ATA_HORKAGE_BROKEN_HPA },
3937 { "TSSTcorp CDDVDW SH-S202[HJN]", "SB0[01]", ATA_HORKAGE_IVB, },
3940 { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK, },
3941 { "BUFFALO HD-QSU2/R5", NULL, ATA_HORKAGE_BRIDGE_OK, },
3951 { "PIONEER DVD-RW DVRTD08", NULL, ATA_HORKAGE_NOSETXFER },
3952 { "PIONEER DVD-RW DVRTD08A", NULL, ATA_HORKAGE_NOSETXFER },
3953 { "PIONEER DVD-RW DVR-215", NULL, ATA_HORKAGE_NOSETXFER },
3954 { "PIONEER DVD-RW DVR-212D", NULL, ATA_HORKAGE_NOSETXFER },
3955 { "PIONEER DVD-RW DVR-216D", NULL, ATA_HORKAGE_NOSETXFER },
3976 /* These specific Samsung models/firmware-revs do not handle LPM well */
3977 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_HORKAGE_NOLPM, },
3979 { "SAMSUNG MZ7TD256HAFV-000L9", NULL, ATA_HORKAGE_NOLPM, },
3980 { "SAMSUNG MZ7TE512HMHP-000L1", "EXT06L0Q", ATA_HORKAGE_NOLPM, },
4039 * Some WD SATA-I drives spin up and down erratically when the link
4042 * known prefixes and is SATA-1. As a side effect LPM partial is
4047 { "WDC WD800JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4048 { "WDC WD1200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4049 { "WDC WD1600JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4050 { "WDC WD2000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4051 { "WDC WD2500JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4052 { "WDC WD3000JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4053 { "WDC WD3200JD-*", NULL, ATA_HORKAGE_WD_BROKEN_LPM },
4065 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); in ata_dev_blacklisted()
4066 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); in ata_dev_blacklisted()
4068 while (ad->model_num) { in ata_dev_blacklisted()
4069 if (glob_match(ad->model_num, model_num)) { in ata_dev_blacklisted()
4070 if (ad->model_rev == NULL) in ata_dev_blacklisted()
4071 return ad->horkage; in ata_dev_blacklisted()
4072 if (glob_match(ad->model_rev, model_rev)) in ata_dev_blacklisted()
4073 return ad->horkage; in ata_dev_blacklisted()
4083 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO) in ata_dma_blacklisted()
4086 if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && in ata_dma_blacklisted()
4087 (dev->flags & ATA_DFLAG_CDB_INTR)) in ata_dma_blacklisted()
4089 return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0; in ata_dma_blacklisted()
4093 * ata_is_40wire - check drive side detection
4102 if (dev->horkage & ATA_HORKAGE_IVB) in ata_is_40wire()
4103 return ata_drive_40wire_relaxed(dev->id); in ata_is_40wire()
4104 return ata_drive_40wire(dev->id); in ata_is_40wire()
4108 * cable_is_40wire - 40/80/SATA decider
4113 * there is a good case for setting ap->cbl to the result when
4126 if (ap->cbl == ATA_CBL_PATA40) in cable_is_40wire()
4130 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) in cable_is_40wire()
4137 if (ap->cbl == ATA_CBL_PATA40_SHORT) in cable_is_40wire()
4144 * - in many setups only the one drive (slave if present) will in cable_is_40wire()
4145 * give a valid detect in cable_is_40wire()
4146 * - if you have a non detect capable drive you don't want it in cable_is_40wire()
4159 * ata_dev_xfermask - Compute supported xfermask of the given device
4163 * dev->*_mask. This function is responsible for applying all
4172 struct ata_link *link = dev->link; in ata_dev_xfermask()
4173 struct ata_port *ap = link->ap; in ata_dev_xfermask()
4174 struct ata_host *host = ap->host; in ata_dev_xfermask()
4178 xfer_mask = ata_pack_xfermask(ap->pio_mask, in ata_dev_xfermask()
4179 ap->mwdma_mask, ap->udma_mask); in ata_dev_xfermask()
4182 xfer_mask &= ata_pack_xfermask(dev->pio_mask, in ata_dev_xfermask()
4183 dev->mwdma_mask, dev->udma_mask); in ata_dev_xfermask()
4184 xfer_mask &= ata_id_xfermask(dev->id); in ata_dev_xfermask()
4187 * CFA Advanced TrueIDE timings are not allowed on a shared in ata_dev_xfermask()
4203 if ((host->flags & ATA_HOST_SIMPLEX) && in ata_dev_xfermask()
4204 host->simplex_claimed && host->simplex_claimed != ap) { in ata_dev_xfermask()
4210 if (ap->flags & ATA_FLAG_NO_IORDY) in ata_dev_xfermask()
4213 if (ap->ops->mode_filter) in ata_dev_xfermask()
4214 xfer_mask = ap->ops->mode_filter(dev, xfer_mask); in ata_dev_xfermask()
4221 * drive side as well. Cases where we know a 40wire cable in ata_dev_xfermask()
4228 "limited to UDMA/33 due to 40-wire cable\n"); in ata_dev_xfermask()
4232 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, in ata_dev_xfermask()
4233 &dev->mwdma_mask, &dev->udma_mask); in ata_dev_xfermask()
4237 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
4240 * Issue SET FEATURES - XFER MODE command to device @dev
4252 struct ata_taskfile tf; in ata_dev_set_xfermode() local
4255 /* set up set-features taskfile */ in ata_dev_set_xfermode()
4256 DPRINTK("set features - xfer mode\n"); in ata_dev_set_xfermode()
4261 ata_tf_init(dev, &tf); in ata_dev_set_xfermode()
4262 tf.command = ATA_CMD_SET_FEATURES; in ata_dev_set_xfermode()
4263 tf.feature = SETFEATURES_XFER; in ata_dev_set_xfermode()
4264 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_POLLING; in ata_dev_set_xfermode()
4265 tf.protocol = ATA_PROT_NODATA; in ata_dev_set_xfermode()
4268 tf.nsect = dev->xfer_mode; in ata_dev_set_xfermode()
4269 /* If the device has IORDY and the controller does not - turn it off */ in ata_dev_set_xfermode()
4270 else if (ata_id_has_iordy(dev->id)) in ata_dev_set_xfermode()
4271 tf.nsect = 0x01; in ata_dev_set_xfermode()
4272 else /* In the ancient relic department - skip all of this */ in ata_dev_set_xfermode()
4275 /* On some disks, this command causes spin-up, so we need longer timeout */ in ata_dev_set_xfermode()
4276 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 15000); in ata_dev_set_xfermode()
4283 * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES
4288 * Issue SET FEATURES - SATA FEATURES command to device @dev
4299 struct ata_taskfile tf; in ata_dev_set_feature() local
4303 /* set up set-features taskfile */ in ata_dev_set_feature()
4304 DPRINTK("set features - SATA features\n"); in ata_dev_set_feature()
4306 ata_tf_init(dev, &tf); in ata_dev_set_feature()
4307 tf.command = ATA_CMD_SET_FEATURES; in ata_dev_set_feature()
4308 tf.feature = enable; in ata_dev_set_feature()
4309 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_dev_set_feature()
4310 tf.protocol = ATA_PROT_NODATA; in ata_dev_set_feature()
4311 tf.nsect = feature; in ata_dev_set_feature()
4316 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, timeout); in ata_dev_set_feature()
4324 * ata_dev_init_params - Issue INIT DEV PARAMS command
4338 struct ata_taskfile tf; in ata_dev_init_params() local
4341 /* Number of sectors per track 1-255. Number of heads 1-16 */ in ata_dev_init_params()
4348 ata_tf_init(dev, &tf); in ata_dev_init_params()
4349 tf.command = ATA_CMD_INIT_DEV_PARAMS; in ata_dev_init_params()
4350 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_dev_init_params()
4351 tf.protocol = ATA_PROT_NODATA; in ata_dev_init_params()
4352 tf.nsect = sectors; in ata_dev_init_params()
4353 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ in ata_dev_init_params()
4355 err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0); in ata_dev_init_params()
4356 /* A clean abort indicates an original or just out of spec drive in ata_dev_init_params()
4359 if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED)) in ata_dev_init_params()
4367 * atapi_check_dma - Check whether ATAPI DMA can be supported
4370 * Allow low-level driver to filter ATA PACKET commands, returning
4371 * a status indicating whether or not it is OK to use DMA for the
4382 struct ata_port *ap = qc->ap; in atapi_check_dma()
4384 /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a in atapi_check_dma()
4387 if (!(qc->dev->horkage & ATA_HORKAGE_ATAPI_MOD16_DMA) && in atapi_check_dma()
4388 unlikely(qc->nbytes & 15)) in atapi_check_dma()
4391 if (ap->ops->check_atapi_dma) in atapi_check_dma()
4392 return ap->ops->check_atapi_dma(qc); in atapi_check_dma()
4398 * ata_std_qc_defer - Check whether a qc needs to be deferred
4401 * Non-NCQ commands cannot run with any other command, NCQ or
4404 * whether a new command @qc can be issued.
4414 struct ata_link *link = qc->dev->link; in ata_std_qc_defer()
4416 if (ata_is_ncq(qc->tf.protocol)) { in ata_std_qc_defer()
4417 if (!ata_tag_valid(link->active_tag)) in ata_std_qc_defer()
4420 if (!ata_tag_valid(link->active_tag) && !link->sactive) in ata_std_qc_defer()
4435 * ata_sg_init - Associate command with scatter-gather table.
4437 * @sg: Scatter-gather table.
4440 * Initialize the data-related elements of queued_cmd @qc
4441 * to point to a scatter-gather table @sg, containing @n_elem
4450 qc->sg = sg; in ata_sg_init()
4451 qc->n_elem = n_elem; in ata_sg_init()
4452 qc->cursg = qc->sg; in ata_sg_init()
4458 * ata_sg_clean - Unmap DMA memory associated with command
4468 struct ata_port *ap = qc->ap; in ata_sg_clean()
4469 struct scatterlist *sg = qc->sg; in ata_sg_clean()
4470 int dir = qc->dma_dir; in ata_sg_clean()
4474 VPRINTK("unmapping %u sg elements\n", qc->n_elem); in ata_sg_clean()
4476 if (qc->n_elem) in ata_sg_clean()
4477 dma_unmap_sg(ap->dev, sg, qc->orig_n_elem, dir); in ata_sg_clean()
4479 qc->flags &= ~ATA_QCFLAG_DMAMAP; in ata_sg_clean()
4480 qc->sg = NULL; in ata_sg_clean()
4484 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
4485 * @qc: Command with scatter-gather table to be mapped.
4487 * DMA-map the scatter-gather table associated with queued_cmd @qc.
4498 struct ata_port *ap = qc->ap; in ata_sg_setup()
4501 VPRINTK("ENTER, ata%u\n", ap->print_id); in ata_sg_setup()
4503 n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); in ata_sg_setup()
4505 return -1; in ata_sg_setup()
4508 qc->orig_n_elem = qc->n_elem; in ata_sg_setup()
4509 qc->n_elem = n_elem; in ata_sg_setup()
4510 qc->flags |= ATA_QCFLAG_DMAMAP; in ata_sg_setup()
4518 static inline int ata_sg_setup(struct ata_queued_cmd *qc) { return -1; } in ata_sg_setup()
4523 * swap_buf_le16 - swap halves of 16-bit words in place
4525 * @buf_words: Number of 16-bit words in buffer.
4527 * Swap halves of 16-bit words if needed to convert from
4528 * little-endian byte order to native cpu byte order, or
4529 * vice-versa.
4545 * ata_qc_new_init - Request an available ATA command, and initialize it
4555 struct ata_port *ap = dev->link->ap; in ata_qc_new_init()
4559 if (unlikely(ap->pflags & ATA_PFLAG_FROZEN)) in ata_qc_new_init()
4563 if (ap->flags & ATA_FLAG_SAS_HOST) { in ata_qc_new_init()
4570 qc->tag = qc->hw_tag = tag; in ata_qc_new_init()
4571 qc->scsicmd = NULL; in ata_qc_new_init()
4572 qc->ap = ap; in ata_qc_new_init()
4573 qc->dev = dev; in ata_qc_new_init()
4581 * ata_qc_free - free unused ata_queued_cmd
4596 ap = qc->ap; in ata_qc_free()
4598 qc->flags = 0; in ata_qc_free()
4599 tag = qc->tag; in ata_qc_free()
4601 qc->tag = ATA_TAG_POISON; in ata_qc_free()
4602 if (ap->flags & ATA_FLAG_SAS_HOST) in ata_qc_free()
4613 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE)); in __ata_qc_complete()
4614 ap = qc->ap; in __ata_qc_complete()
4615 link = qc->dev->link; in __ata_qc_complete()
4617 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) in __ata_qc_complete()
4621 if (ata_is_ncq(qc->tf.protocol)) { in __ata_qc_complete()
4622 link->sactive &= ~(1 << qc->hw_tag); in __ata_qc_complete()
4623 if (!link->sactive) in __ata_qc_complete()
4624 ap->nr_active_links--; in __ata_qc_complete()
4626 link->active_tag = ATA_TAG_POISON; in __ata_qc_complete()
4627 ap->nr_active_links--; in __ata_qc_complete()
4631 if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && in __ata_qc_complete()
4632 ap->excl_link == link)) in __ata_qc_complete()
4633 ap->excl_link = NULL; in __ata_qc_complete()
4639 qc->flags &= ~ATA_QCFLAG_ACTIVE; in __ata_qc_complete()
4640 ap->qc_active &= ~(1ULL << qc->tag); in __ata_qc_complete()
4643 qc->complete_fn(qc); in __ata_qc_complete()
4648 struct ata_port *ap = qc->ap; in fill_result_tf()
4650 qc->result_tf.flags = qc->tf.flags; in fill_result_tf()
4651 ap->ops->qc_fill_rtf(qc); in fill_result_tf()
4656 struct ata_device *dev = qc->dev; in ata_verify_xfer()
4658 if (!ata_is_data(qc->tf.protocol)) in ata_verify_xfer()
4661 if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) in ata_verify_xfer()
4664 dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; in ata_verify_xfer()
4668 * ata_qc_complete - Complete an active ATA command
4672 * completed, with either an ok or not-ok status.
4684 struct ata_port *ap = qc->ap; in ata_qc_complete()
4687 ledtrig_disk_activity(!!(qc->tf.flags & ATA_TFLAG_WRITE)); in ata_qc_complete()
4692 * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED. in ata_qc_complete()
4693 * Normal execution path is responsible for not accessing a in ata_qc_complete()
4702 if (ap->ops->error_handler) { in ata_qc_complete()
4703 struct ata_device *dev = qc->dev; in ata_qc_complete()
4704 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_qc_complete()
4706 if (unlikely(qc->err_mask)) in ata_qc_complete()
4707 qc->flags |= ATA_QCFLAG_FAILED; in ata_qc_complete()
4711 * and always with the result TF filled. in ata_qc_complete()
4713 if (unlikely(ata_tag_internal(qc->tag))) { in ata_qc_complete()
4721 * Non-internal qc has failed. Fill the result TF and in ata_qc_complete()
4724 if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) { in ata_qc_complete()
4731 WARN_ON_ONCE(ap->pflags & ATA_PFLAG_FROZEN); in ata_qc_complete()
4733 /* read result TF if requested */ in ata_qc_complete()
4734 if (qc->flags & ATA_QCFLAG_RESULT_TF) in ata_qc_complete()
4738 /* Some commands need post-processing after successful in ata_qc_complete()
4741 switch (qc->tf.command) { in ata_qc_complete()
4743 if (qc->tf.feature != SETFEATURES_WC_ON && in ata_qc_complete()
4744 qc->tf.feature != SETFEATURES_WC_OFF && in ata_qc_complete()
4745 qc->tf.feature != SETFEATURES_RA_ON && in ata_qc_complete()
4746 qc->tf.feature != SETFEATURES_RA_OFF) in ata_qc_complete()
4752 ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; in ata_qc_complete()
4757 dev->flags |= ATA_DFLAG_SLEEPING; in ata_qc_complete()
4761 if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) in ata_qc_complete()
4766 if (qc->flags & ATA_QCFLAG_EH_SCHEDULED) in ata_qc_complete()
4769 /* read result TF if failed or requested */ in ata_qc_complete()
4770 if (qc->err_mask || qc->flags & ATA_QCFLAG_RESULT_TF) in ata_qc_complete()
4779 * ata_qc_get_active - get bitmask of active qcs
4790 u64 qc_active = ap->qc_active; in ata_qc_get_active()
4803 * ata_qc_issue - issue taskfile to device
4807 * This includes mapping the data into a DMA-able
4816 struct ata_port *ap = qc->ap; in ata_qc_issue()
4817 struct ata_link *link = qc->dev->link; in ata_qc_issue()
4818 u8 prot = qc->tf.protocol; in ata_qc_issue()
4820 /* Make sure only one non-NCQ command is outstanding. The in ata_qc_issue()
4824 WARN_ON_ONCE(ap->ops->error_handler && ata_tag_valid(link->active_tag)); in ata_qc_issue()
4827 WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag)); in ata_qc_issue()
4829 if (!link->sactive) in ata_qc_issue()
4830 ap->nr_active_links++; in ata_qc_issue()
4831 link->sactive |= 1 << qc->hw_tag; in ata_qc_issue()
4833 WARN_ON_ONCE(link->sactive); in ata_qc_issue()
4835 ap->nr_active_links++; in ata_qc_issue()
4836 link->active_tag = qc->tag; in ata_qc_issue()
4839 qc->flags |= ATA_QCFLAG_ACTIVE; in ata_qc_issue()
4840 ap->qc_active |= 1ULL << qc->tag; in ata_qc_issue()
4844 * non-zero sg if the command is a data command. in ata_qc_issue()
4846 if (ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)) in ata_qc_issue()
4850 (ap->flags & ATA_FLAG_PIO_DMA))) in ata_qc_issue()
4855 if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { in ata_qc_issue()
4856 link->eh_info.action |= ATA_EH_RESET; in ata_qc_issue()
4857 ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); in ata_qc_issue()
4862 qc->err_mask |= ap->ops->qc_prep(qc); in ata_qc_issue()
4863 if (unlikely(qc->err_mask)) in ata_qc_issue()
4866 qc->err_mask |= ap->ops->qc_issue(qc); in ata_qc_issue()
4867 if (unlikely(qc->err_mask)) in ata_qc_issue()
4872 qc->err_mask |= AC_ERR_SYSTEM; in ata_qc_issue()
4878 * ata_phys_link_online - test whether the given link is online
4902 * ata_phys_link_offline - test whether the given link is offline
4926 * ata_link_online - test whether the given link is online
4931 * there's a slave link, this function should only be called on
4943 struct ata_link *slave = link->ap->slave_link; in ata_link_online()
4953 * ata_link_offline - test whether the given link is offline
4958 * there's a slave link, this function should only be called on
4970 struct ata_link *slave = link->ap->slave_link; in ata_link_offline()
4990 if (ap->pflags & ATA_PFLAG_PM_PENDING) { in ata_port_request_pm()
4992 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); in ata_port_request_pm()
4996 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
4998 ap->pm_mesg = mesg; in ata_port_request_pm()
4999 ap->pflags |= ATA_PFLAG_PM_PENDING; in ata_port_request_pm()
5001 link->eh_info.action |= action; in ata_port_request_pm()
5002 link->eh_info.flags |= ehi_flags; in ata_port_request_pm()
5007 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5011 WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); in ata_port_request_pm()
5089 * as each suspend will cause a hard/soft reset, the gain of runtime suspend
5091 * So the idle callback here will not proceed to suspend if a non-ZPODD capable
5102 if (adev->class == ATA_DEV_ATAPI && in ata_port_runtime_idle()
5104 return -EBUSY; in ata_port_runtime_idle()
5136 * and need to resume ata devices at the domain level, not the per-port
5153 * ata_host_suspend - suspend host
5161 host->dev->power.power_state = mesg; in ata_host_suspend()
5167 * ata_host_resume - resume host
5174 host->dev->power.power_state = PMSG_ON; in ata_host_resume()
5187 * ata_dev_init - Initialize an ata_device structure
5198 struct ata_port *ap = link->ap; in ata_dev_init()
5202 link->sata_spd_limit = link->hw_sata_spd_limit; in ata_dev_init()
5203 link->sata_spd = 0; in ata_dev_init()
5205 /* High bits of dev->flags are used to record warm plug in ata_dev_init()
5209 spin_lock_irqsave(ap->lock, flags); in ata_dev_init()
5210 dev->flags &= ~ATA_DFLAG_INIT_MASK; in ata_dev_init()
5211 dev->horkage = 0; in ata_dev_init()
5212 spin_unlock_irqrestore(ap->lock, flags); in ata_dev_init()
5215 ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); in ata_dev_init()
5216 dev->pio_mask = UINT_MAX; in ata_dev_init()
5217 dev->mwdma_mask = UINT_MAX; in ata_dev_init()
5218 dev->udma_mask = UINT_MAX; in ata_dev_init()
5222 * ata_link_init - Initialize an ata_link structure
5238 ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); in ata_link_init()
5240 link->ap = ap; in ata_link_init()
5241 link->pmp = pmp; in ata_link_init()
5242 link->active_tag = ATA_TAG_POISON; in ata_link_init()
5243 link->hw_sata_spd_limit = UINT_MAX; in ata_link_init()
5247 struct ata_device *dev = &link->device[i]; in ata_link_init()
5249 dev->link = link; in ata_link_init()
5250 dev->devno = dev - link->device; in ata_link_init()
5252 dev->gtf_filter = ata_acpi_gtf_filter; in ata_link_init()
5259 * sata_link_init_spd - Initialize link->sata_spd_limit
5262 * Initialize ``link->[hw_]sata_spd_limit`` to the currently
5269 * 0 on success, -errno on failure.
5276 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); in sata_link_init_spd()
5280 spd = (link->saved_scontrol >> 4) & 0xf; in sata_link_init_spd()
5282 link->hw_sata_spd_limit &= (1 << spd) - 1; in sata_link_init_spd()
5286 link->sata_spd_limit = link->hw_sata_spd_limit; in sata_link_init_spd()
5292 * ata_port_alloc - allocate and initialize basic ATA port resources
5313 ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; in ata_port_alloc()
5314 ap->lock = &host->lock; in ata_port_alloc()
5315 ap->print_id = -1; in ata_port_alloc()
5316 ap->local_port_no = -1; in ata_port_alloc()
5317 ap->host = host; in ata_port_alloc()
5318 ap->dev = host->dev; in ata_port_alloc()
5322 ap->msg_enable = 0x00FF; in ata_port_alloc()
5324 ap->msg_enable = ATA_MSG_DRV | ATA_MSG_INFO | ATA_MSG_CTL | ATA_MSG_WARN | ATA_MSG_ERR; in ata_port_alloc()
5326 ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN; in ata_port_alloc()
5329 mutex_init(&ap->scsi_scan_mutex); in ata_port_alloc()
5330 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); in ata_port_alloc()
5331 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); in ata_port_alloc()
5332 INIT_LIST_HEAD(&ap->eh_done_q); in ata_port_alloc()
5333 init_waitqueue_head(&ap->eh_wait_q); in ata_port_alloc()
5334 init_completion(&ap->park_req_pending); in ata_port_alloc()
5335 timer_setup(&ap->fastdrain_timer, ata_eh_fastdrain_timerfn, in ata_port_alloc()
5338 ap->cbl = ATA_CBL_NONE; in ata_port_alloc()
5340 ata_link_init(ap, &ap->link, 0); in ata_port_alloc()
5343 ap->stats.unhandled_irq = 1; in ata_port_alloc()
5344 ap->stats.idle_irq = 1; in ata_port_alloc()
5356 for (i = 0; i < host->n_ports; i++) { in ata_devres_release()
5357 struct ata_port *ap = host->ports[i]; in ata_devres_release()
5362 if (ap->scsi_host) in ata_devres_release()
5363 scsi_host_put(ap->scsi_host); in ata_devres_release()
5376 for (i = 0; i < host->n_ports; i++) { in ata_host_release()
5377 struct ata_port *ap = host->ports[i]; in ata_host_release()
5379 kfree(ap->pmp_link); in ata_host_release()
5380 kfree(ap->slave_link); in ata_host_release()
5382 host->ports[i] = NULL; in ata_host_release()
5389 kref_get(&host->kref); in ata_host_get()
5394 kref_put(&host->kref, ata_host_release); in ata_host_put()
5399 * ata_host_alloc - allocate and init basic ATA host resources
5404 * this function to allocate a host, initializes it fully and
5407 * @max_ports ports are allocated and host->n_ports is
5409 * host->n_ports before calling ata_host_register(). The unused
5427 /* alloc a container for our list of ATA ports (buses) */ in ata_host_alloc()
5443 spin_lock_init(&host->lock); in ata_host_alloc()
5444 mutex_init(&host->eh_mutex); in ata_host_alloc()
5445 host->dev = dev; in ata_host_alloc()
5446 host->n_ports = max_ports; in ata_host_alloc()
5447 kref_init(&host->kref); in ata_host_alloc()
5457 ap->port_no = i; in ata_host_alloc()
5458 host->ports[i] = ap; in ata_host_alloc()
5473 * ata_host_alloc_pinfo - alloc host and init with port_info array
5500 for (i = 0, j = 0, pi = NULL; i < host->n_ports; i++) { in ata_host_alloc_pinfo()
5501 struct ata_port *ap = host->ports[i]; in ata_host_alloc_pinfo()
5506 ap->pio_mask = pi->pio_mask; in ata_host_alloc_pinfo()
5507 ap->mwdma_mask = pi->mwdma_mask; in ata_host_alloc_pinfo()
5508 ap->udma_mask = pi->udma_mask; in ata_host_alloc_pinfo()
5509 ap->flags |= pi->flags; in ata_host_alloc_pinfo()
5510 ap->link.flags |= pi->link_flags; in ata_host_alloc_pinfo()
5511 ap->ops = pi->port_ops; in ata_host_alloc_pinfo()
5513 if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) in ata_host_alloc_pinfo()
5514 host->ops = pi->port_ops; in ata_host_alloc_pinfo()
5526 WARN_ON(!(host->flags & ATA_HOST_STARTED)); in ata_host_stop()
5528 for (i = 0; i < host->n_ports; i++) { in ata_host_stop()
5529 struct ata_port *ap = host->ports[i]; in ata_host_stop()
5531 if (ap->ops->port_stop) in ata_host_stop()
5532 ap->ops->port_stop(ap); in ata_host_stop()
5535 if (host->ops->host_stop) in ata_host_stop()
5536 host->ops->host_stop(host); in ata_host_stop()
5540 * ata_finalize_port_ops - finalize ata_port_operations
5552 * methods and ->inherits is no longer necessary and cleared.
5554 * Using ATA_OP_NULL, inheriting ops can force a method to NULL.
5564 void **end = (void **)&ops->inherits; in ata_finalize_port_ops()
5567 if (!ops || !ops->inherits) in ata_finalize_port_ops()
5572 for (cur = ops->inherits; cur; cur = cur->inherits) { in ata_finalize_port_ops()
5584 ops->inherits = NULL; in ata_finalize_port_ops()
5590 * ata_host_start - start and freeze ports of an ATA host
5594 * recorded in host->flags, so this function can be called
5596 * once. If host->ops isn't initialized yet, its set to the
5597 * first non-dummy port ops.
5603 * 0 if all ports are started successfully, -errno otherwise.
5611 if (host->flags & ATA_HOST_STARTED) in ata_host_start()
5614 ata_finalize_port_ops(host->ops); in ata_host_start()
5616 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5617 struct ata_port *ap = host->ports[i]; in ata_host_start()
5619 ata_finalize_port_ops(ap->ops); in ata_host_start()
5621 if (!host->ops && !ata_port_is_dummy(ap)) in ata_host_start()
5622 host->ops = ap->ops; in ata_host_start()
5624 if (ap->ops->port_stop) in ata_host_start()
5628 if (host->ops && host->ops->host_stop) in ata_host_start()
5634 return -ENOMEM; in ata_host_start()
5637 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5638 struct ata_port *ap = host->ports[i]; in ata_host_start()
5640 if (ap->ops->port_start) { in ata_host_start()
5641 rc = ap->ops->port_start(ap); in ata_host_start()
5643 if (rc != -ENODEV) in ata_host_start()
5644 dev_err(host->dev, in ata_host_start()
5654 devres_add(host->dev, start_dr); in ata_host_start()
5655 host->flags |= ATA_HOST_STARTED; in ata_host_start()
5659 while (--i >= 0) { in ata_host_start()
5660 struct ata_port *ap = host->ports[i]; in ata_host_start()
5662 if (ap->ops->port_stop) in ata_host_start()
5663 ap->ops->port_stop(ap); in ata_host_start()
5671 * ata_host_init - Initialize a host struct for sas (ipr, libsas)
5680 spin_lock_init(&host->lock); in ata_host_init()
5681 mutex_init(&host->eh_mutex); in ata_host_init()
5682 host->n_tags = ATA_MAX_QUEUE; in ata_host_init()
5683 host->dev = dev; in ata_host_init()
5684 host->ops = ops; in ata_host_init()
5685 kref_init(&host->kref); in ata_host_init()
5691 struct ata_eh_info *ehi = &ap->link.eh_info; in __ata_port_probe()
5695 spin_lock_irqsave(ap->lock, flags); in __ata_port_probe()
5697 ehi->probe_mask |= ATA_ALL_DEVICES; in __ata_port_probe()
5698 ehi->action |= ATA_EH_RESET; in __ata_port_probe()
5699 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; in __ata_port_probe()
5701 ap->pflags &= ~ATA_PFLAG_INITIALIZING; in __ata_port_probe()
5702 ap->pflags |= ATA_PFLAG_LOADING; in __ata_port_probe()
5705 spin_unlock_irqrestore(ap->lock, flags); in __ata_port_probe()
5712 if (ap->ops->error_handler) { in ata_port_probe()
5716 DPRINTK("ata%u: bus probe begin\n", ap->print_id); in ata_port_probe()
5718 DPRINTK("ata%u: bus probe end\n", ap->print_id); in ata_port_probe()
5732 * Jeff Garzik says this is only within a controller, so we in async_port_probe()
5735 if (!(ap->host->flags & ATA_HOST_PARALLEL_SCAN) && ap->port_no != 0) in async_port_probe()
5747 * ata_host_register - register initialized ATA host
5760 * 0 on success, -errno otherwise.
5766 host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE); in ata_host_register()
5769 if (!(host->flags & ATA_HOST_STARTED)) { in ata_host_register()
5770 dev_err(host->dev, "BUG: trying to register unstarted host\n"); in ata_host_register()
5772 return -EINVAL; in ata_host_register()
5779 for (i = host->n_ports; host->ports[i]; i++) in ata_host_register()
5780 kfree(host->ports[i]); in ata_host_register()
5783 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5784 host->ports[i]->print_id = atomic_inc_return(&ata_print_id); in ata_host_register()
5785 host->ports[i]->local_port_no = i + 1; in ata_host_register()
5789 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5790 rc = ata_tport_add(host->dev,host->ports[i]); in ata_host_register()
5801 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5802 struct ata_port *ap = host->ports[i]; in ata_host_register()
5806 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) in ata_host_register()
5807 ap->cbl = ATA_CBL_SATA; in ata_host_register()
5810 sata_link_init_spd(&ap->link); in ata_host_register()
5811 if (ap->slave_link) in ata_host_register()
5812 sata_link_init_spd(ap->slave_link); in ata_host_register()
5814 /* print per-port info to dmesg */ in ata_host_register()
5815 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, in ata_host_register()
5816 ap->udma_mask); in ata_host_register()
5820 (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', in ata_host_register()
5822 ap->link.eh_info.desc); in ata_host_register()
5823 ata_ehi_clear_desc(&ap->link.eh_info); in ata_host_register()
5829 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5830 struct ata_port *ap = host->ports[i]; in ata_host_register()
5831 ap->cookie = async_schedule(async_port_probe, ap); in ata_host_register()
5837 while (--i >= 0) { in ata_host_register()
5838 ata_tport_delete(host->ports[i]); in ata_host_register()
5846 * ata_host_activate - start host, request IRQ and register it
5854 * LLDs perform three steps to activate the host - start host,
5866 * 0 on success, -errno otherwise.
5885 irq_desc = devm_kasprintf(host->dev, GFP_KERNEL, "%s[%s]", in ata_host_activate()
5886 dev_driver_string(host->dev), in ata_host_activate()
5887 dev_name(host->dev)); in ata_host_activate()
5889 return -ENOMEM; in ata_host_activate()
5891 rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, in ata_host_activate()
5896 for (i = 0; i < host->n_ports; i++) in ata_host_activate()
5897 ata_port_desc(host->ports[i], "irq %d", irq); in ata_host_activate()
5902 devm_free_irq(host->dev, irq, host); in ata_host_activate()
5909 * ata_port_detach - Detach ATA port in preparation of device removal
5925 if (!ap->ops->error_handler) in ata_port_detach()
5929 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
5930 ap->pflags |= ATA_PFLAG_UNLOADING; in ata_port_detach()
5932 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
5938 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED)); in ata_port_detach()
5940 cancel_delayed_work_sync(&ap->hotplug_task); in ata_port_detach()
5950 if (ap->pmp_link) { in ata_port_detach()
5953 ata_tlink_delete(&ap->pmp_link[i]); in ata_port_detach()
5956 scsi_remove_host(ap->scsi_host); in ata_port_detach()
5961 * ata_host_detach - Detach all ports of an ATA host
5973 for (i = 0; i < host->n_ports; i++) { in ata_host_detach()
5975 async_synchronize_cookie(host->ports[i]->cookie + 1); in ata_host_detach()
5976 ata_port_detach(host->ports[i]); in ata_host_detach()
5987 * ata_pci_remove_one - PCI layer callback for device removal
5990 * PCI layer indicates to libata via this hook that hot-unplug or
6010 for (i = 0; i < host->n_ports; i++) { in ata_pci_shutdown_one()
6011 struct ata_port *ap = host->ports[i]; in ata_pci_shutdown_one()
6013 ap->pflags |= ATA_PFLAG_FROZEN; in ata_pci_shutdown_one()
6016 if (ap->ops->freeze) in ata_pci_shutdown_one()
6017 ap->ops->freeze(ap); in ata_pci_shutdown_one()
6020 if (ap->ops->port_stop) in ata_pci_shutdown_one()
6021 ap->ops->port_stop(ap); in ata_pci_shutdown_one()
6031 switch (bits->width) { in pci_test_config_bits()
6034 pci_read_config_byte(pdev, bits->reg, &tmp8); in pci_test_config_bits()
6040 pci_read_config_word(pdev, bits->reg, &tmp16); in pci_test_config_bits()
6046 pci_read_config_dword(pdev, bits->reg, &tmp32); in pci_test_config_bits()
6052 return -EINVAL; in pci_test_config_bits()
6055 tmp &= bits->mask; in pci_test_config_bits()
6057 return (tmp == bits->val) ? 1 : 0; in pci_test_config_bits()
6081 dev_err(&pdev->dev, in ata_pci_device_do_resume()
6121 * ata_platform_remove_one - Platform layer callback for device removal
6124 * Platform layer indicates to libata via this hook that hot-unplug or
6234 force_ent->device = simple_strtoul(p, &endp, 10); in ata_parse_force_one()
6237 return -EINVAL; in ata_parse_force_one()
6241 force_ent->port = simple_strtoul(id, &endp, 10); in ata_parse_force_one()
6244 return -EINVAL; in ata_parse_force_one()
6252 if (strncasecmp(val, fp->name, strlen(val))) in ata_parse_force_one()
6258 if (strcasecmp(val, fp->name) == 0) { in ata_parse_force_one()
6266 return -EINVAL; in ata_parse_force_one()
6270 return -EINVAL; in ata_parse_force_one()
6273 force_ent->param = *match_fp; in ata_parse_force_one()
6281 int last_port = -1, last_device = -1; in ata_parse_force_param()
6299 struct ata_force_ent te = { .port = -1, .device = -1 }; in ata_parse_force_param()
6309 if (te.port == -1) { in ata_parse_force_param()
6348 rc = -ENOMEM; in ata_init()
6379 * ata_msleep - ATA EH owner aware msleep
6386 * @ap->host will be allowed to own the EH while this task is
6394 bool owns_eh = ap && ap->host->eh_owner == current; in ata_msleep()
6412 * ata_wait_register - wait until register value changes
6414 * @reg: IO-mapped register
6420 * Waiting for some bits of register to change is a common
6422 * IO-mapped register @reg and tests for the following condition.
6499 printk("%sata%u: %pV", level, ap->print_id, &vaf); in ata_port_printk()
6516 if (sata_pmp_attached(link->ap) || link->ap->slave_link) in ata_link_printk()
6518 level, link->ap->print_id, link->pmp, &vaf); in ata_link_printk()
6521 level, link->ap->print_id, &vaf); in ata_link_printk()
6539 level, dev->link->ap->print_id, dev->link->pmp + dev->devno, in ata_dev_printk()