Lines Matching +full:freeze +full:- +full:bridge +full:- +full:controller

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * libata-core.c - helper library for ATA
5 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
6 * Copyright 2003-2004 Jeff Garzik
9 * as Documentation/driver-api/libata.rst
12 * http://www.sata-io.org/
16 * http://www.t10.org (SCSI MMC - for ATAPI MMC)
17 * http://www.sata-io.org (SATA)
19 * http://www.qic.org (QIC157 - Tape and DSC)
20 * http://www.ce-ata.org (CE-ATA: not supported)
23 * low-level ATA host controller drivers. As such, the API/ABI is
65 #include "libata-transport.h"
107 …ing cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst …
116 MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off [default], 1=on)");
157 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_print_info()
159 return ehc->i.flags & ATA_EHI_PRINTINFO; in ata_dev_print_info()
163 * ata_link_next - link iteration helper
186 return ap->pmp_link; in ata_link_next()
189 return &ap->link; in ata_link_next()
193 if (link == &ap->link) in ata_link_next()
197 return ap->pmp_link; in ata_link_next()
200 if (unlikely(ap->slave_link)) in ata_link_next()
201 return ap->slave_link; in ata_link_next()
208 if (unlikely(link == ap->slave_link)) in ata_link_next()
212 if (++link < ap->pmp_link + ap->nr_pmp_links) in ata_link_next()
216 return &ap->link; in ata_link_next()
223 * ata_dev_next - device iteration helper
245 dev = link->device; in ata_dev_next()
249 dev = link->device + ata_link_max_devices(link) - 1; in ata_dev_next()
258 if (++dev < link->device + ata_link_max_devices(link)) in ata_dev_next()
263 if (--dev >= link->device) in ata_dev_next()
277 * ata_dev_phys_link - find physical link for a device
281 * this is different from @dev->link only when @dev is on slave
282 * link. For all other cases, it's the same as @dev->link.
292 struct ata_port *ap = dev->link->ap; in ata_dev_phys_link()
294 if (!ap->slave_link) in ata_dev_phys_link()
295 return dev->link; in ata_dev_phys_link()
296 if (!dev->devno) in ata_dev_phys_link()
297 return &ap->link; in ata_dev_phys_link()
298 return ap->slave_link; in ata_dev_phys_link()
303 * ata_force_cbl - force cable type according to libata.force
319 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_cbl()
322 if (fe->port != -1 && fe->port != ap->print_id) in ata_force_cbl()
325 if (fe->param.cbl == ATA_CBL_NONE) in ata_force_cbl()
328 ap->cbl = fe->param.cbl; in ata_force_cbl()
329 ata_port_notice(ap, "FORCE: cable set to %s\n", fe->param.name); in ata_force_cbl()
335 * ata_force_link_limits - force link limits according to libata.force
341 * the host link and all fan-out ports connected via PMP. If the
343 * first fan-out link not the host link. Device number 15 always
345 * controller has slave link, device number 16 points to it.
353 int linkno = link->pmp; in ata_force_link_limits()
359 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_link_limits()
362 if (fe->port != -1 && fe->port != link->ap->print_id) in ata_force_link_limits()
365 if (fe->device != -1 && fe->device != linkno) in ata_force_link_limits()
369 if (!did_spd && fe->param.spd_limit) { in ata_force_link_limits()
370 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; in ata_force_link_limits()
372 fe->param.name); in ata_force_link_limits()
377 if (fe->param.lflags_on) { in ata_force_link_limits()
378 link->flags |= fe->param.lflags_on; in ata_force_link_limits()
380 "FORCE: link flag 0x%x forced -> 0x%x\n", in ata_force_link_limits()
381 fe->param.lflags_on, link->flags); in ata_force_link_limits()
383 if (fe->param.lflags_off) { in ata_force_link_limits()
384 link->flags &= ~fe->param.lflags_off; in ata_force_link_limits()
386 "FORCE: link flag 0x%x cleared -> 0x%x\n", in ata_force_link_limits()
387 fe->param.lflags_off, link->flags); in ata_force_link_limits()
393 * ata_force_xfermask - force xfermask according to libata.force
405 int devno = dev->link->pmp + dev->devno; in ata_force_xfermask()
410 if (ata_is_host_link(dev->link)) in ata_force_xfermask()
413 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_xfermask()
417 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_xfermask()
420 if (fe->device != -1 && fe->device != devno && in ata_force_xfermask()
421 fe->device != alt_devno) in ata_force_xfermask()
424 if (!fe->param.xfer_mask) in ata_force_xfermask()
427 ata_unpack_xfermask(fe->param.xfer_mask, in ata_force_xfermask()
430 dev->udma_mask = udma_mask; in ata_force_xfermask()
432 dev->udma_mask = 0; in ata_force_xfermask()
433 dev->mwdma_mask = mwdma_mask; in ata_force_xfermask()
435 dev->udma_mask = 0; in ata_force_xfermask()
436 dev->mwdma_mask = 0; in ata_force_xfermask()
437 dev->pio_mask = pio_mask; in ata_force_xfermask()
441 fe->param.name); in ata_force_xfermask()
447 * ata_force_quirks - force quirks according to libata.force
459 int devno = dev->link->pmp + dev->devno; in ata_force_quirks()
464 if (ata_is_host_link(dev->link)) in ata_force_quirks()
470 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_quirks()
473 if (fe->device != -1 && fe->device != devno && in ata_force_quirks()
474 fe->device != alt_devno) in ata_force_quirks()
477 if (!(~dev->quirks & fe->param.quirk_on) && in ata_force_quirks()
478 !(dev->quirks & fe->param.quirk_off)) in ata_force_quirks()
481 dev->quirks |= fe->param.quirk_on; in ata_force_quirks()
482 dev->quirks &= ~fe->param.quirk_off; in ata_force_quirks()
485 fe->param.name); in ata_force_quirks()
495 * atapi_cmd_type - Determine ATAPI command type from SCSI opcode
564 * ata_set_rwcmd_protocol - set taskfile r/w command and protocol
568 * Examine the device configuration and tf->flags to determine
581 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; in ata_set_rwcmd_protocol()
582 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; in ata_set_rwcmd_protocol()
583 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; in ata_set_rwcmd_protocol()
585 if (dev->flags & ATA_DFLAG_PIO) { in ata_set_rwcmd_protocol()
586 tf->protocol = ATA_PROT_PIO; in ata_set_rwcmd_protocol()
587 index = dev->multi_count ? 0 : 8; in ata_set_rwcmd_protocol()
588 } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { in ata_set_rwcmd_protocol()
590 tf->protocol = ATA_PROT_PIO; in ata_set_rwcmd_protocol()
591 index = dev->multi_count ? 0 : 8; in ata_set_rwcmd_protocol()
593 tf->protocol = ATA_PROT_DMA; in ata_set_rwcmd_protocol()
601 tf->command = cmd; in ata_set_rwcmd_protocol()
607 * ata_tf_read_block - Read block address from ATA taskfile
615 * three address formats - LBA, LBA48 and CHS. tf->protocol and
625 if (tf->flags & ATA_TFLAG_LBA) { in ata_tf_read_block()
626 if (tf->flags & ATA_TFLAG_LBA48) { in ata_tf_read_block()
627 block |= (u64)tf->hob_lbah << 40; in ata_tf_read_block()
628 block |= (u64)tf->hob_lbam << 32; in ata_tf_read_block()
629 block |= (u64)tf->hob_lbal << 24; in ata_tf_read_block()
631 block |= (tf->device & 0xf) << 24; in ata_tf_read_block()
633 block |= tf->lbah << 16; in ata_tf_read_block()
634 block |= tf->lbam << 8; in ata_tf_read_block()
635 block |= tf->lbal; in ata_tf_read_block()
639 cyl = tf->lbam | (tf->lbah << 8); in ata_tf_read_block()
640 head = tf->device & 0xf; in ata_tf_read_block()
641 sect = tf->lbal; in ata_tf_read_block()
649 block = (cyl * dev->heads + head) * dev->sectors + sect - 1; in ata_tf_read_block()
660 struct ata_taskfile *tf = &qc->tf; in ata_set_tf_cdl()
662 if (tf->protocol == ATA_PROT_NCQ) in ata_set_tf_cdl()
663 tf->auxiliary |= cdl; in ata_set_tf_cdl()
665 tf->feature |= cdl; in ata_set_tf_cdl()
672 qc->flags |= ATA_QCFLAG_HAS_CDL | ATA_QCFLAG_RESULT_TF; in ata_set_tf_cdl()
676 * ata_build_rw_tf - Build ATA taskfile for given read/write request
692 * 0 on success, -ERANGE if the request is too large for @dev,
693 * -EINVAL if the request is invalid.
698 struct ata_taskfile *tf = &qc->tf; in ata_build_rw_tf()
699 struct ata_device *dev = qc->dev; in ata_build_rw_tf()
701 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_build_rw_tf()
702 tf->flags |= tf_flags; in ata_build_rw_tf()
707 return -ERANGE; in ata_build_rw_tf()
709 tf->protocol = ATA_PROT_NCQ; in ata_build_rw_tf()
710 tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; in ata_build_rw_tf()
712 if (tf->flags & ATA_TFLAG_WRITE) in ata_build_rw_tf()
713 tf->command = ATA_CMD_FPDMA_WRITE; in ata_build_rw_tf()
715 tf->command = ATA_CMD_FPDMA_READ; in ata_build_rw_tf()
717 tf->nsect = qc->hw_tag << 3; in ata_build_rw_tf()
718 tf->hob_feature = (n_block >> 8) & 0xff; in ata_build_rw_tf()
719 tf->feature = n_block & 0xff; in ata_build_rw_tf()
721 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
722 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
723 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
724 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
725 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
726 tf->lbal = block & 0xff; in ata_build_rw_tf()
728 tf->device = ATA_LBA; in ata_build_rw_tf()
729 if (tf->flags & ATA_TFLAG_FUA) in ata_build_rw_tf()
730 tf->device |= 1 << 7; in ata_build_rw_tf()
732 if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED && in ata_build_rw_tf()
734 tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; in ata_build_rw_tf()
736 if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) in ata_build_rw_tf()
739 } else if (dev->flags & ATA_DFLAG_LBA) { in ata_build_rw_tf()
740 tf->flags |= ATA_TFLAG_LBA; in ata_build_rw_tf()
742 if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) in ata_build_rw_tf()
745 /* Both FUA writes and a CDL index require 48-bit commands */ in ata_build_rw_tf()
746 if (!(tf->flags & ATA_TFLAG_FUA) && in ata_build_rw_tf()
747 !(qc->flags & ATA_QCFLAG_HAS_CDL) && in ata_build_rw_tf()
750 tf->device |= (block >> 24) & 0xf; in ata_build_rw_tf()
752 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_build_rw_tf()
753 return -ERANGE; in ata_build_rw_tf()
756 tf->flags |= ATA_TFLAG_LBA48; in ata_build_rw_tf()
758 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_build_rw_tf()
760 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
761 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
762 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
765 return -ERANGE; in ata_build_rw_tf()
769 return -EINVAL; in ata_build_rw_tf()
771 tf->nsect = n_block & 0xff; in ata_build_rw_tf()
773 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
774 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
775 tf->lbal = block & 0xff; in ata_build_rw_tf()
777 tf->device |= ATA_LBA; in ata_build_rw_tf()
782 /* The request -may- be too large for CHS addressing. */ in ata_build_rw_tf()
784 return -ERANGE; in ata_build_rw_tf()
787 return -EINVAL; in ata_build_rw_tf()
790 track = (u32)block / dev->sectors; in ata_build_rw_tf()
791 cyl = track / dev->heads; in ata_build_rw_tf()
792 head = track % dev->heads; in ata_build_rw_tf()
793 sect = (u32)block % dev->sectors + 1; in ata_build_rw_tf()
796 Cylinder: 0-65535 in ata_build_rw_tf()
797 Head: 0-15 in ata_build_rw_tf()
798 Sector: 1-255*/ in ata_build_rw_tf()
800 return -ERANGE; in ata_build_rw_tf()
802 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_build_rw_tf()
803 tf->lbal = sect; in ata_build_rw_tf()
804 tf->lbam = cyl; in ata_build_rw_tf()
805 tf->lbah = cyl >> 8; in ata_build_rw_tf()
806 tf->device |= head; in ata_build_rw_tf()
813 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
838 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
865 { -1, },
869 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
883 int highbit = fls(xfer_mask) - 1; in ata_xfer_mask2mode()
886 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mask2mode()
887 if (highbit >= ent->shift && highbit < ent->shift + ent->bits) in ata_xfer_mask2mode()
888 return ent->base + highbit - ent->shift; in ata_xfer_mask2mode()
894 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
909 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2mask()
910 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2mask()
911 return ((2 << (ent->shift + xfer_mode - ent->base)) - 1) in ata_xfer_mode2mask()
912 & ~((1 << ent->shift) - 1); in ata_xfer_mode2mask()
918 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
927 * Matching xfer_shift, -1 if no match found.
933 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2shift()
934 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2shift()
935 return ent->shift; in ata_xfer_mode2shift()
936 return -1; in ata_xfer_mode2shift()
941 * ata_mode_string - convert xfer_mask to string
980 highbit = fls(xfer_mask) - 1; in ata_mode_string()
995 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) in sata_spd_string()
997 return spd_str[spd - 1]; in sata_spd_string()
1001 * ata_dev_classify - determine device type based on ATA-spec signature
1021 * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate in ata_dev_classify()
1028 * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and in ata_dev_classify()
1034 * Unfortunately, WDC WD1600JS-62MHB5 (a hard drive) reports in ata_dev_classify()
1038 if (tf->lbam == 0 && tf->lbah == 0) in ata_dev_classify()
1041 if (tf->lbam == 0x14 && tf->lbah == 0xeb) in ata_dev_classify()
1044 if (tf->lbam == 0x69 && tf->lbah == 0x96) in ata_dev_classify()
1047 if (tf->lbam == 0x3c && tf->lbah == 0xc3) in ata_dev_classify()
1050 if (tf->lbam == 0xcd && tf->lbah == 0xab) in ata_dev_classify()
1058 * ata_id_string - Convert IDENTIFY DEVICE page into string
1065 * 16-bit chunks. Run through the string, and output each
1066 * 8-bit chunk linearly, regardless of platform.
1089 len -= 2; in ata_id_string()
1095 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
1113 ata_id_string(id, s, ofs, len - 1); in ata_id_c_string()
1115 p = s + strnlen(s, len - 1); in ata_id_c_string()
1116 while (p > s && p[-1] == ' ') in ata_id_c_string()
1117 p--; in ata_id_c_string()
1143 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; in ata_tf_to_lba48()
1144 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; in ata_tf_to_lba48()
1145 sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24; in ata_tf_to_lba48()
1146 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba48()
1147 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba48()
1148 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba48()
1157 sectors |= (tf->device & 0x0f) << 24; in ata_tf_to_lba()
1158 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba()
1159 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba()
1160 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba()
1166 * ata_read_native_max_address - Read native max address
1174 * 0 on success, -EACCES if command is aborted by the drive.
1175 * -EIO on other errors.
1181 int lba48 = ata_id_has_lba48(dev->id); in ata_read_native_max_address()
1203 return -EACCES; in ata_read_native_max_address()
1204 return -EIO; in ata_read_native_max_address()
1211 if (dev->quirks & ATA_QUIRK_HPA_SIZE) in ata_read_native_max_address()
1212 (*max_sectors)--; in ata_read_native_max_address()
1217 * ata_set_max_sectors - Set max sectors
1224 * 0 on success, -EACCES if command is aborted or denied (due to
1225 * previous non-volatile SET_MAX) by the drive. -EIO on other
1232 int lba48 = ata_id_has_lba48(dev->id); in ata_set_max_sectors()
1234 new_sectors--; in ata_set_max_sectors()
1267 return -EACCES; in ata_set_max_sectors()
1268 return -EIO; in ata_set_max_sectors()
1275 * ata_hpa_resize - Resize a device with an HPA set
1283 * 0 on success, -errno on failure.
1288 bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA; in ata_hpa_resize()
1289 u64 sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1294 if ((dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) || in ata_hpa_resize()
1295 !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || in ata_hpa_resize()
1296 (dev->quirks & ATA_QUIRK_BROKEN_HPA)) in ata_hpa_resize()
1305 if (rc == -EACCES || !unlock_hpa) { in ata_hpa_resize()
1308 dev->quirks |= ATA_QUIRK_BROKEN_HPA; in ata_hpa_resize()
1311 if (rc == -EACCES) in ata_hpa_resize()
1317 dev->n_native_sectors = native_sectors; in ata_hpa_resize()
1339 if (rc == -EACCES) { in ata_hpa_resize()
1342 "device aborted resize (%llu -> %llu), skipping HPA handling\n", in ata_hpa_resize()
1345 dev->quirks |= ATA_QUIRK_BROKEN_HPA; in ata_hpa_resize()
1350 /* re-read IDENTIFY data */ in ata_hpa_resize()
1354 "failed to re-read IDENTIFY data after HPA resizing\n"); in ata_hpa_resize()
1359 u64 new_sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1361 "HPA unlocked: %llu -> %llu, native %llu\n", in ata_hpa_resize()
1371 * ata_dump_id - IDENTIFY DEVICE info debugging output
1375 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1393 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1423 pio_mask = (2 << mode) - 1; in ata_id_xfermask()
1464 struct completion *waiting = qc->private_data; in ata_qc_complete_internal()
1470 * ata_exec_internal - execute libata internal command
1496 struct ata_link *link = dev->link; in ata_exec_internal()
1497 struct ata_port *ap = link->ap; in ata_exec_internal()
1498 u8 command = tf->command; in ata_exec_internal()
1514 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal()
1518 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1525 qc->tag = ATA_TAG_INTERNAL; in ata_exec_internal()
1526 qc->hw_tag = 0; in ata_exec_internal()
1527 qc->scsicmd = NULL; in ata_exec_internal()
1528 qc->ap = ap; in ata_exec_internal()
1529 qc->dev = dev; in ata_exec_internal()
1532 preempted_tag = link->active_tag; in ata_exec_internal()
1533 preempted_sactive = link->sactive; in ata_exec_internal()
1534 preempted_qc_active = ap->qc_active; in ata_exec_internal()
1535 preempted_nr_active_links = ap->nr_active_links; in ata_exec_internal()
1536 link->active_tag = ATA_TAG_POISON; in ata_exec_internal()
1537 link->sactive = 0; in ata_exec_internal()
1538 ap->qc_active = 0; in ata_exec_internal()
1539 ap->nr_active_links = 0; in ata_exec_internal()
1542 qc->tf = *tf; in ata_exec_internal()
1544 memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); in ata_exec_internal()
1547 if (tf->protocol == ATAPI_PROT_DMA && (dev->flags & ATA_DFLAG_DMADIR) && in ata_exec_internal()
1549 qc->tf.feature |= ATAPI_DMADIR; in ata_exec_internal()
1551 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_exec_internal()
1552 qc->dma_dir = dma_dir; in ata_exec_internal()
1556 qc->nbytes = buflen; in ata_exec_internal()
1559 qc->private_data = &wait; in ata_exec_internal()
1560 qc->complete_fn = ata_qc_complete_internal; in ata_exec_internal()
1564 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1587 * is frozen and will be cleaned up by ->post_internal_cmd(). in ata_exec_internal()
1589 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal()
1590 if (qc->flags & ATA_QCFLAG_ACTIVE) { in ata_exec_internal()
1591 qc->err_mask |= AC_ERR_TIMEOUT; in ata_exec_internal()
1596 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1599 if (ap->ops->post_internal_cmd) in ata_exec_internal()
1600 ap->ops->post_internal_cmd(qc); in ata_exec_internal()
1603 if (qc->flags & ATA_QCFLAG_EH) { in ata_exec_internal()
1604 if (qc->result_tf.status & (ATA_ERR | ATA_DF)) in ata_exec_internal()
1605 qc->err_mask |= AC_ERR_DEV; in ata_exec_internal()
1607 if (!qc->err_mask) in ata_exec_internal()
1608 qc->err_mask |= AC_ERR_OTHER; in ata_exec_internal()
1610 if (qc->err_mask & ~AC_ERR_OTHER) in ata_exec_internal()
1611 qc->err_mask &= ~AC_ERR_OTHER; in ata_exec_internal()
1612 } else if (qc->tf.command == ATA_CMD_REQ_SENSE_DATA) { in ata_exec_internal()
1613 qc->result_tf.status |= ATA_SENSE; in ata_exec_internal()
1617 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal()
1619 *tf = qc->result_tf; in ata_exec_internal()
1620 err_mask = qc->err_mask; in ata_exec_internal()
1623 link->active_tag = preempted_tag; in ata_exec_internal()
1624 link->sactive = preempted_sactive; in ata_exec_internal()
1625 ap->qc_active = preempted_qc_active; in ata_exec_internal()
1626 ap->nr_active_links = preempted_nr_active_links; in ata_exec_internal()
1628 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1637 * ata_pio_need_iordy - check if iordy needed
1646 * lead to controller lock up on certain controllers if the in ata_pio_need_iordy()
1649 if (adev->link->ap->pflags & ATA_PFLAG_RESETTING) in ata_pio_need_iordy()
1651 /* Controller doesn't support IORDY. Probably a pointless in ata_pio_need_iordy()
1654 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) in ata_pio_need_iordy()
1657 if (ata_id_is_cfa(adev->id) in ata_pio_need_iordy()
1658 && (adev->pio_mode == XFER_PIO_5 || adev->pio_mode == XFER_PIO_6)) in ata_pio_need_iordy()
1661 if (adev->pio_mode > XFER_PIO_2) in ata_pio_need_iordy()
1664 if (ata_id_has_iordy(adev->id)) in ata_pio_need_iordy()
1671 * ata_pio_mask_no_iordy - Return the non IORDY mask
1675 * -1 if no iordy mode is available.
1680 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ in ata_pio_mask_no_iordy()
1681 u16 pio = adev->id[ATA_ID_EIDE_PIO]; in ata_pio_mask_no_iordy()
1684 /* This is cycle times not frequency - watch the logic! */ in ata_pio_mask_no_iordy()
1694 * ata_do_dev_read_id - default ID read method
1712 * ata_dev_read_id - Read ID data from the specified device
1721 * for pre-ATA4 drives.
1730 * 0 on success, -errno otherwise.
1735 struct ata_port *ap = dev->link->ap; in ata_dev_read_id()
1759 rc = -ENODEV; in ata_dev_read_id()
1776 if (ap->ops->read_id) in ata_dev_read_id()
1777 err_mask = ap->ops->read_id(dev, &tf, (__le16 *)id); in ata_dev_read_id()
1784 return -ENOENT; in ata_dev_read_id()
1796 /* Device or controller might have reported in ata_dev_read_id()
1817 return -ENOENT; in ata_dev_read_id()
1820 rc = -EIO; in ata_dev_read_id()
1825 if (dev->quirks & ATA_QUIRK_DUMP_ID) { in ata_dev_read_id()
1841 rc = -EINVAL; in ata_dev_read_id()
1847 if (ap->host->flags & ATA_HOST_IGNORE_ATA && in ata_dev_read_id()
1851 return -ENOENT; in ata_dev_read_id()
1861 * Drive powered-up in standby mode, and requires a specific in ata_dev_read_id()
1862 * SET_FEATURES spin-up subcommand before it will accept in ata_dev_read_id()
1867 rc = -EIO; in ata_dev_read_id()
1882 * The exact sequence expected by certain pre-ATA4 drives is: in ata_dev_read_id()
1895 rc = -EIO; in ata_dev_read_id()
1900 /* current CHS translation info (id[53-58]) might be in ata_dev_read_id()
1922 if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) in ata_dev_power_init_tf()
1926 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_dev_power_init_tf()
1927 tf->protocol = ATA_PROT_NODATA; in ata_dev_power_init_tf()
1931 tf->command = ATA_CMD_VERIFY; in ata_dev_power_init_tf()
1932 tf->nsect = 1; in ata_dev_power_init_tf()
1933 if (dev->flags & ATA_DFLAG_LBA) { in ata_dev_power_init_tf()
1934 tf->flags |= ATA_TFLAG_LBA; in ata_dev_power_init_tf()
1935 tf->device |= ATA_LBA; in ata_dev_power_init_tf()
1938 tf->lbal = 0x1; /* sect */ in ata_dev_power_init_tf()
1941 tf->command = ATA_CMD_STANDBYNOW1; in ata_dev_power_init_tf()
1975 * ata_dev_power_set_standby - Set a device power mode to standby
1986 unsigned long ap_flags = dev->link->ap->flags; in ata_dev_power_set_standby()
1991 if ((dev->flags & ATA_DFLAG_SLEEPING) || in ata_dev_power_set_standby()
2021 * ata_dev_power_set_active - Set a device power mode to active
2025 * active power mode. For a spun-down HDD (standby or idle power mode),
2059 * ata_read_log_page - read a specific log page
2077 unsigned long ap_flags = dev->link->ap->flags; in ata_read_log_page()
2082 ata_dev_dbg(dev, "read log page - log 0x%x, page 0x%x\n", log, page); in ata_read_log_page()
2093 if (ata_dma_enabled(dev) && ata_id_has_read_log_dma_ext(dev->id) && in ata_read_log_page()
2094 !(dev->quirks & ATA_QUIRK_NO_DMA_LOG)) { in ata_read_log_page()
2114 dev->quirks |= ATA_QUIRK_NO_DMA_LOG; in ata_read_log_page()
2115 if (!ata_port_is_frozen(dev->link->ap)) in ata_read_log_page()
2128 if (dev->quirks & ATA_QUIRK_NO_LOG_DIR) in ata_log_supported()
2131 if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, dev->sector_buf, 1)) in ata_log_supported()
2133 return get_unaligned_le16(&dev->sector_buf[log * 2]); in ata_log_supported()
2140 if (dev->quirks & ATA_QUIRK_NO_ID_DEV_LOG) in ata_identify_page_supported()
2146 * with ACS-3 (ATA version 10). Warn about the missing log in ata_identify_page_supported()
2149 if (ata_id_major_version(dev->id) >= 10) in ata_identify_page_supported()
2152 dev->quirks |= ATA_QUIRK_NO_ID_DEV_LOG; in ata_identify_page_supported()
2161 dev->sector_buf, 1); in ata_identify_page_supported()
2165 for (i = 0; i < dev->sector_buf[8]; i++) { in ata_identify_page_supported()
2166 if (dev->sector_buf[9 + i] == page) in ata_identify_page_supported()
2181 if (dev->quirks & ATA_QUIRK_1_5_GBPS) in ata_do_link_spd_quirk()
2186 target_limit = (1 << target) - 1; in ata_do_link_spd_quirk()
2189 if (plink->sata_spd_limit <= target_limit) in ata_do_link_spd_quirk()
2192 plink->sata_spd_limit = target_limit; in ata_do_link_spd_quirk()
2194 /* Request another EH round by returning -EAGAIN if link is in ata_do_link_spd_quirk()
2198 if (plink->sata_spd > target) { in ata_do_link_spd_quirk()
2201 return -EAGAIN; in ata_do_link_spd_quirk()
2208 struct ata_port *ap = dev->link->ap; in ata_dev_knobble()
2213 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); in ata_dev_knobble()
2225 0, dev->sector_buf, 1); in ata_dev_config_ncq_send_recv()
2227 u8 *cmds = dev->ncq_send_recv_cmds; in ata_dev_config_ncq_send_recv()
2229 dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; in ata_dev_config_ncq_send_recv()
2230 memcpy(cmds, dev->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE); in ata_dev_config_ncq_send_recv()
2232 if (dev->quirks & ATA_QUIRK_NO_NCQ_TRIM) { in ata_dev_config_ncq_send_recv()
2250 0, dev->sector_buf, 1); in ata_dev_config_ncq_non_data()
2252 memcpy(dev->ncq_non_data_cmds, dev->sector_buf, in ata_dev_config_ncq_non_data()
2266 dev->sector_buf, 1); in ata_dev_config_ncq_prio()
2270 if (!(dev->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) in ata_dev_config_ncq_prio()
2273 dev->flags |= ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2278 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLED; in ata_dev_config_ncq_prio()
2279 dev->flags &= ~ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2288 for (parent_dev = dev->tdev.parent; parent_dev != NULL; in ata_dev_check_adapter()
2289 parent_dev = parent_dev->parent) { in ata_dev_check_adapter()
2292 if (pcidev->vendor == vendor_id) in ata_dev_check_adapter()
2304 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq()
2305 int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); in ata_dev_config_ncq()
2309 if (!ata_id_has_ncq(dev->id)) { in ata_dev_config_ncq()
2315 if (dev->quirks & ATA_QUIRK_NONCQ) { in ata_dev_config_ncq()
2320 if (dev->quirks & ATA_QUIRK_NO_NCQ_ON_ATI && in ata_dev_config_ncq()
2326 if (ap->flags & ATA_FLAG_NCQ) { in ata_dev_config_ncq()
2327 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE); in ata_dev_config_ncq()
2328 dev->flags |= ATA_DFLAG_NCQ; in ata_dev_config_ncq()
2331 if (!(dev->quirks & ATA_QUIRK_BROKEN_FPDMA_AA) && in ata_dev_config_ncq()
2332 (ap->flags & ATA_FLAG_FPDMA_AA) && in ata_dev_config_ncq()
2333 ata_id_has_fpdma_aa(dev->id)) { in ata_dev_config_ncq()
2341 dev->quirks |= ATA_QUIRK_BROKEN_FPDMA_AA; in ata_dev_config_ncq()
2342 return -EIO; in ata_dev_config_ncq()
2354 if ((ap->flags & ATA_FLAG_FPDMA_AUX)) { in ata_dev_config_ncq()
2355 if (ata_id_has_ncq_send_and_recv(dev->id)) in ata_dev_config_ncq()
2357 if (ata_id_has_ncq_non_data(dev->id)) in ata_dev_config_ncq()
2359 if (ata_id_has_ncq_prio(dev->id)) in ata_dev_config_ncq()
2370 if (!ata_id_has_sense_reporting(dev->id)) in ata_dev_config_sense_reporting()
2373 if (ata_id_sense_reporting_enabled(dev->id)) in ata_dev_config_sense_reporting()
2387 u8 *identify_buf = dev->sector_buf; in ata_dev_config_zac()
2389 dev->zac_zones_optimal_open = U32_MAX; in ata_dev_config_zac()
2390 dev->zac_zones_optimal_nonseq = U32_MAX; in ata_dev_config_zac()
2391 dev->zac_zones_max_open = U32_MAX; in ata_dev_config_zac()
2394 * Always set the 'ZAC' flag for Host-managed devices. in ata_dev_config_zac()
2396 if (dev->class == ATA_DEV_ZAC) in ata_dev_config_zac()
2397 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2398 else if (ata_id_zoned_cap(dev->id) == 0x01) in ata_dev_config_zac()
2400 * Check for host-aware devices. in ata_dev_config_zac()
2402 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2404 if (!(dev->flags & ATA_DFLAG_ZAC)) in ata_dev_config_zac()
2414 * Read IDENTIFY DEVICE data log, page 9 (Zoned-device information) in ata_dev_config_zac()
2424 dev->zac_zoned_cap = (zoned_cap & 1); in ata_dev_config_zac()
2427 dev->zac_zones_optimal_open = (u32)opt_open; in ata_dev_config_zac()
2430 dev->zac_zones_optimal_nonseq = (u32)opt_nonseq; in ata_dev_config_zac()
2433 dev->zac_zones_max_open = (u32)max_open; in ata_dev_config_zac()
2442 if (!ata_id_has_trusted(dev->id)) in ata_dev_config_trusted()
2452 dev->sector_buf, 1); in ata_dev_config_trusted()
2456 trusted_cap = get_unaligned_le64(&dev->sector_buf[40]); in ata_dev_config_trusted()
2464 dev->flags |= ATA_DFLAG_TRUSTED; in ata_dev_config_trusted()
2469 kfree(dev->cdl); in ata_dev_cleanup_cdl_resources()
2470 dev->cdl = NULL; in ata_dev_cleanup_cdl_resources()
2475 struct ata_cdl *cdl = dev->cdl; in ata_dev_init_cdl_resources()
2481 return -ENOMEM; in ata_dev_init_cdl_resources()
2482 dev->cdl = cdl; in ata_dev_init_cdl_resources()
2485 err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, cdl->desc_log_buf, in ata_dev_init_cdl_resources()
2490 return -EIO; in ata_dev_init_cdl_resources()
2503 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cdl()
2513 dev->sector_buf, 1); in ata_dev_config_cdl()
2518 val = get_unaligned_le64(&dev->sector_buf[168]); in ata_dev_config_cdl()
2531 val = get_unaligned_le64(&dev->sector_buf[8]); in ata_dev_config_cdl()
2539 if (!ata_id_has_ncq_autosense(dev->id)) { in ata_dev_config_cdl()
2551 dev->sector_buf, 1); in ata_dev_config_cdl()
2555 val = get_unaligned_le64(&dev->sector_buf[8]); in ata_dev_config_cdl()
2557 if (dev->flags & ATA_DFLAG_CDL_ENABLED) { in ata_dev_config_cdl()
2603 dev->flags |= ATA_DFLAG_CDL; in ata_dev_config_cdl()
2608 dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); in ata_dev_config_cdl()
2614 const u16 *id = dev->id; in ata_dev_config_lba()
2619 dev->flags |= ATA_DFLAG_LBA; in ata_dev_config_lba()
2623 dev->flags |= ATA_DFLAG_LBA48; in ata_dev_config_lba()
2624 if (dev->n_sectors >= (1UL << 28) && in ata_dev_config_lba()
2626 dev->flags |= ATA_DFLAG_FLUSH_EXT; in ata_dev_config_lba()
2638 (unsigned long long)dev->n_sectors, in ata_dev_config_lba()
2639 dev->multi_count, lba_desc, ncq_desc); in ata_dev_config_lba()
2646 const u16 *id = dev->id; in ata_dev_config_chs()
2650 dev->cylinders = id[54]; in ata_dev_config_chs()
2651 dev->heads = id[55]; in ata_dev_config_chs()
2652 dev->sectors = id[56]; in ata_dev_config_chs()
2655 dev->cylinders = id[1]; in ata_dev_config_chs()
2656 dev->heads = id[3]; in ata_dev_config_chs()
2657 dev->sectors = id[6]; in ata_dev_config_chs()
2664 (unsigned long long)dev->n_sectors, in ata_dev_config_chs()
2665 dev->multi_count, dev->cylinders, in ata_dev_config_chs()
2666 dev->heads, dev->sectors); in ata_dev_config_chs()
2676 if (!(dev->flags & ATA_DFLAG_LBA48) || !ata_id_has_fua(dev->id)) in ata_dev_config_fua()
2680 if (!ata_ncq_supported(dev) || (dev->quirks & ATA_QUIRK_NO_FUA)) in ata_dev_config_fua()
2683 dev->flags |= ATA_DFLAG_FUA; in ata_dev_config_fua()
2688 dev->flags &= ~ATA_DFLAG_FUA; in ata_dev_config_fua()
2693 u8 *sata_setting = dev->sector_buf; in ata_dev_config_devslp()
2701 if (!ata_id_has_devslp(dev->id) || in ata_dev_config_devslp()
2712 dev->flags |= ATA_DFLAG_DEVSLP; in ata_dev_config_devslp()
2715 dev->devslp_timing[i] = sata_setting[j]; in ata_dev_config_devslp()
2727 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cpr()
2758 cpr_log->nr_cpr = nr_cpr; in ata_dev_config_cpr()
2761 cpr_log->cpr[i].num = desc[0]; in ata_dev_config_cpr()
2762 cpr_log->cpr[i].num_storage_elements = desc[1]; in ata_dev_config_cpr()
2763 cpr_log->cpr[i].start_lba = get_unaligned_le64(&desc[8]); in ata_dev_config_cpr()
2764 cpr_log->cpr[i].num_lbas = get_unaligned_le64(&desc[16]); in ata_dev_config_cpr()
2768 swap(dev->cpr_log, cpr_log); in ata_dev_config_cpr()
2775 if (!(dev->flags & ATA_DFLAG_FEATURES_MASK)) in ata_dev_print_features()
2780 dev->flags & ATA_DFLAG_FUA ? " FUA" : "", in ata_dev_print_features()
2781 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", in ata_dev_print_features()
2782 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", in ata_dev_print_features()
2783 dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", in ata_dev_print_features()
2784 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", in ata_dev_print_features()
2785 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "", in ata_dev_print_features()
2786 dev->flags & ATA_DFLAG_CDL ? " CDL" : "", in ata_dev_print_features()
2787 dev->cpr_log ? " CPR" : ""); in ata_dev_print_features()
2791 * ata_dev_configure - Configure the specified ATA/ATAPI device
2794 * Configure @dev according to @dev->id. Generic and low-level
2801 * 0 on success, -errno otherwise
2805 struct ata_port *ap = dev->link->ap; in ata_dev_configure()
2807 const u16 *id = dev->id; in ata_dev_configure()
2810 char revbuf[7]; /* XYZ-99\0 */ in ata_dev_configure()
2821 dev->quirks |= ata_dev_quirks(dev); in ata_dev_configure()
2824 if (dev->quirks & ATA_QUIRK_DISABLE) { in ata_dev_configure()
2830 if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) && in ata_dev_configure()
2831 dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2843 /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */ in ata_dev_configure()
2844 if ((dev->quirks & ATA_QUIRK_WD_BROKEN_LPM) && in ata_dev_configure()
2846 dev->quirks |= ATA_QUIRK_NOLPM; in ata_dev_configure()
2848 if (ap->flags & ATA_FLAG_NO_LPM) in ata_dev_configure()
2849 dev->quirks |= ATA_QUIRK_NOLPM; in ata_dev_configure()
2851 if (dev->quirks & ATA_QUIRK_NOLPM) { in ata_dev_configure()
2853 dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER; in ata_dev_configure()
2874 /* initialize to-be-configured parameters */ in ata_dev_configure()
2875 dev->flags &= ~ATA_DFLAG_CFG_MASK; in ata_dev_configure()
2876 dev->max_sectors = 0; in ata_dev_configure()
2877 dev->cdb_len = 0; in ata_dev_configure()
2878 dev->n_sectors = 0; in ata_dev_configure()
2879 dev->cylinders = 0; in ata_dev_configure()
2880 dev->heads = 0; in ata_dev_configure()
2881 dev->sectors = 0; in ata_dev_configure()
2882 dev->multi_count = 0; in ata_dev_configure()
2893 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ in ata_dev_configure()
2894 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, in ata_dev_configure()
2897 ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, in ata_dev_configure()
2900 /* ATA-specific feature tests */ in ata_dev_configure()
2901 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in ata_dev_configure()
2909 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); in ata_dev_configure()
2916 dev->n_sectors = ata_id_n_sectors(id); in ata_dev_configure()
2919 if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) { in ata_dev_configure()
2920 unsigned int max = dev->id[47] & 0xff; in ata_dev_configure()
2921 unsigned int cnt = dev->id[59] & 0xff; in ata_dev_configure()
2925 dev->multi_count = cnt; in ata_dev_configure()
2949 dev->cdb_len = 32; in ata_dev_configure()
2955 /* ATAPI-specific feature tests */ in ata_dev_configure()
2956 else if (dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2965 rc = -EINVAL; in ata_dev_configure()
2968 dev->cdb_len = (unsigned int) rc; in ata_dev_configure()
2976 (ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && in ata_dev_configure()
2978 sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { in ata_dev_configure()
2987 dev->flags |= ATA_DFLAG_AN; in ata_dev_configure()
2992 if (ata_id_cdb_intr(dev->id)) { in ata_dev_configure()
2993 dev->flags |= ATA_DFLAG_CDB_INTR; in ata_dev_configure()
2997 if (atapi_dmadir || (dev->quirks & ATA_QUIRK_ATAPI_DMADIR) || in ata_dev_configure()
2998 atapi_id_dmadir(dev->id)) { in ata_dev_configure()
2999 dev->flags |= ATA_DFLAG_DMADIR; in ata_dev_configure()
3003 if (ata_id_has_da(dev->id)) { in ata_dev_configure()
3004 dev->flags |= ATA_DFLAG_DA; in ata_dev_configure()
3019 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3020 if (dev->flags & ATA_DFLAG_LBA48) in ata_dev_configure()
3021 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3023 /* Limit PATA drive on SATA cable bridge transfers to udma5, in ata_dev_configure()
3027 ata_dev_info(dev, "applying bridge limits\n"); in ata_dev_configure()
3028 dev->udma_mask &= ATA_UDMA5; in ata_dev_configure()
3029 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3032 if ((dev->class == ATA_DEV_ATAPI) && in ata_dev_configure()
3034 dev->max_sectors = ATA_MAX_SECTORS_TAPE; in ata_dev_configure()
3035 dev->quirks |= ATA_QUIRK_STUCK_ERR; in ata_dev_configure()
3038 if (dev->quirks & ATA_QUIRK_MAX_SEC_128) in ata_dev_configure()
3039 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, in ata_dev_configure()
3040 dev->max_sectors); in ata_dev_configure()
3042 if (dev->quirks & ATA_QUIRK_MAX_SEC_1024) in ata_dev_configure()
3043 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_1024, in ata_dev_configure()
3044 dev->max_sectors); in ata_dev_configure()
3046 if (dev->quirks & ATA_QUIRK_MAX_SEC_LBA48) in ata_dev_configure()
3047 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3049 if (ap->ops->dev_config) in ata_dev_configure()
3050 ap->ops->dev_config(dev); in ata_dev_configure()
3052 if (dev->quirks & ATA_QUIRK_DIAGNOSTIC) { in ata_dev_configure()
3067 if ((dev->quirks & ATA_QUIRK_FIRMWARE_WARN) && print_info) { in ata_dev_configure()
3079 * ata_cable_40wire - return 40 wire cable type
3093 * ata_cable_80wire - return 80 wire cable type
3107 * ata_cable_unknown - return unknown PATA cable.
3120 * ata_cable_ignore - return ignored PATA cable.
3133 * ata_cable_sata - return SATA cable type
3146 * sata_print_link_status - Print SATA link status
3174 * ata_dev_pair - return other device on cable
3183 struct ata_link *link = adev->link; in ata_dev_pair()
3184 struct ata_device *pair = &link->device[1 - adev->devno]; in ata_dev_pair()
3193 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration
3214 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_timing_cycle2mode()
3215 if (ent->shift == xfer_shift) in ata_timing_cycle2mode()
3216 base_mode = ent->base; in ata_timing_cycle2mode()
3219 t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { in ata_timing_cycle2mode()
3225 this_cycle = t->cycle; in ata_timing_cycle2mode()
3228 this_cycle = t->udma; in ata_timing_cycle2mode()
3237 last_mode = t->mode; in ata_timing_cycle2mode()
3245 * ata_down_xfermask_limit - adjust dev xfer masks downward
3269 xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, in ata_down_xfermask_limit()
3270 dev->mwdma_mask, in ata_down_xfermask_limit()
3271 dev->udma_mask); in ata_down_xfermask_limit()
3276 highbit = fls(pio_mask) - 1; in ata_down_xfermask_limit()
3282 highbit = fls(udma_mask) - 1; in ata_down_xfermask_limit()
3285 return -ENOENT; in ata_down_xfermask_limit()
3287 highbit = fls(mwdma_mask) - 1; in ata_down_xfermask_limit()
3290 return -ENOENT; in ata_down_xfermask_limit()
3313 return -ENOENT; in ata_down_xfermask_limit()
3327 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, in ata_down_xfermask_limit()
3328 &dev->udma_mask); in ata_down_xfermask_limit()
3335 struct ata_port *ap = dev->link->ap; in ata_dev_set_mode()
3336 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_set_mode()
3337 const bool nosetxfer = dev->quirks & ATA_QUIRK_NOSETXFER; in ata_dev_set_mode()
3343 dev->flags &= ~ATA_DFLAG_PIO; in ata_dev_set_mode()
3344 if (dev->xfer_shift == ATA_SHIFT_PIO) in ata_dev_set_mode()
3345 dev->flags |= ATA_DFLAG_PIO; in ata_dev_set_mode()
3347 if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id)) in ata_dev_set_mode()
3352 "NOSETXFER but PATA detected - can't " in ata_dev_set_mode()
3361 ehc->i.flags |= ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3363 ehc->i.flags &= ~ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3367 if (dev->xfer_shift == ATA_SHIFT_PIO) { in ata_dev_set_mode()
3369 if (ata_id_is_cfa(dev->id)) in ata_dev_set_mode()
3373 if (ata_id_major_version(dev->id) == 0 && in ata_dev_set_mode()
3374 dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3377 any kind of SET_XFERMODE request but support PIO0-2 in ata_dev_set_mode()
3379 if (!ata_id_has_iordy(dev->id) && dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3384 if (dev->xfer_shift == ATA_SHIFT_MWDMA && in ata_dev_set_mode()
3385 dev->dma_mode == XFER_MW_DMA_0 && in ata_dev_set_mode()
3386 (dev->id[63] >> 8) & 1) in ata_dev_set_mode()
3390 if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) in ata_dev_set_mode()
3401 dev->xfer_shift, (int)dev->xfer_mode); in ata_dev_set_mode()
3403 if (!(ehc->i.flags & ATA_EHI_QUIET) || in ata_dev_set_mode()
3404 ehc->i.flags & ATA_EHI_DID_HARDRESET) in ata_dev_set_mode()
3406 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), in ata_dev_set_mode()
3413 return -EIO; in ata_dev_set_mode()
3417 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
3435 struct ata_port *ap = link->ap; in ata_do_set_mode()
3445 if (dev->class == ATA_DEV_ATAPI) in ata_do_set_mode()
3447 else if (ata_id_is_cfa(dev->id)) in ata_do_set_mode()
3453 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); in ata_do_set_mode()
3456 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, in ata_do_set_mode()
3457 dev->udma_mask); in ata_do_set_mode()
3461 dev->pio_mode = ata_xfer_mask2mode(pio_mask); in ata_do_set_mode()
3462 dev->dma_mode = ata_xfer_mask2mode(dma_mask); in ata_do_set_mode()
3473 if (dev->pio_mode == 0xff) { in ata_do_set_mode()
3475 rc = -EINVAL; in ata_do_set_mode()
3479 dev->xfer_mode = dev->pio_mode; in ata_do_set_mode()
3480 dev->xfer_shift = ATA_SHIFT_PIO; in ata_do_set_mode()
3481 if (ap->ops->set_piomode) in ata_do_set_mode()
3482 ap->ops->set_piomode(ap, dev); in ata_do_set_mode()
3490 dev->xfer_mode = dev->dma_mode; in ata_do_set_mode()
3491 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); in ata_do_set_mode()
3492 if (ap->ops->set_dmamode) in ata_do_set_mode()
3493 ap->ops->set_dmamode(ap, dev); in ata_do_set_mode()
3506 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) in ata_do_set_mode()
3507 ap->host->simplex_claimed = ap; in ata_do_set_mode()
3517 * ata_wait_ready - wait for link to become ready
3523 * positive number if @link is ready, 0 if it isn't, -ENODEV if
3527 * Transient -ENODEV conditions are allowed for
3534 * 0 if @link is ready before @deadline; otherwise, -errno.
3544 if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN) in ata_wait_ready()
3553 WARN_ON(link == link->ap->slave_link); in ata_wait_ready()
3567 * -ENODEV could be transient. Ignore -ENODEV if link in ata_wait_ready()
3570 * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't in ata_wait_ready()
3577 if (ready == -ENODEV) { in ata_wait_ready()
3580 else if ((link->ap->flags & ATA_FLAG_SATA) && in ata_wait_ready()
3589 return -EBUSY; in ata_wait_ready()
3592 (deadline - now > 3 * HZ)) { in ata_wait_ready()
3599 ata_msleep(link->ap, 50); in ata_wait_ready()
3604 * ata_wait_after_reset - wait for link to become ready after reset
3615 * 0 if @link is ready before @deadline; otherwise, -errno.
3620 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); in ata_wait_after_reset()
3627 * ata_std_prereset - prepare for reset
3633 * that port, so prereset should be best-effort. It does its
3645 struct ata_port *ap = link->ap; in ata_std_prereset()
3646 struct ata_eh_context *ehc = &link->eh_context; in ata_std_prereset()
3651 if (ehc->i.action & ATA_EH_HARDRESET) in ata_std_prereset()
3655 if (ap->flags & ATA_FLAG_SATA) { in ata_std_prereset()
3658 if (rc && rc != -EOPNOTSUPP) in ata_std_prereset()
3666 ehc->i.action &= ~ATA_EH_SOFTRESET; in ata_std_prereset()
3673 * ata_std_postreset - standard postreset callback
3698 * ata_dev_same_device - Determine whether new ID matches configured device
3716 const u16 *old_id = dev->id; in ata_dev_same_device()
3720 if (dev->class != new_class) { in ata_dev_same_device()
3722 dev->class, new_class); in ata_dev_same_device()
3747 * ata_dev_reread_id - Re-read IDENTIFY data
3751 * Re-read IDENTIFY page and make sure @dev is still attached to
3762 unsigned int class = dev->class; in ata_dev_reread_id()
3763 u16 *id = (void *)dev->sector_buf; in ata_dev_reread_id()
3773 return -ENODEV; in ata_dev_reread_id()
3775 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); in ata_dev_reread_id()
3780 * ata_dev_revalidate - Revalidate ATA device
3785 * Re-read IDENTIFY page, make sure @dev is still attached to the
3797 u64 n_sectors = dev->n_sectors; in ata_dev_revalidate()
3798 u64 n_native_sectors = dev->n_native_sectors; in ata_dev_revalidate()
3802 return -ENODEV; in ata_dev_revalidate()
3807 dev->class, new_class); in ata_dev_revalidate()
3808 rc = -ENODEV; in ata_dev_revalidate()
3812 /* re-read ID */ in ata_dev_revalidate()
3823 if (dev->class != ATA_DEV_ATA || !n_sectors || in ata_dev_revalidate()
3824 dev->n_sectors == n_sectors) in ata_dev_revalidate()
3830 (unsigned long long)dev->n_sectors); in ata_dev_revalidate()
3837 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3838 dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) { in ata_dev_revalidate()
3852 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3853 dev->n_sectors < n_sectors && n_sectors == n_native_sectors && in ata_dev_revalidate()
3854 !(dev->quirks & ATA_QUIRK_BROKEN_HPA)) { in ata_dev_revalidate()
3859 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_dev_revalidate()
3860 rc = -EIO; in ata_dev_revalidate()
3862 rc = -ENODEV; in ata_dev_revalidate()
3865 dev->n_native_sectors = n_native_sectors; in ata_dev_revalidate()
3866 dev->n_sectors = n_sectors; in ata_dev_revalidate()
3909 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_print_quirks()
3914 if (!ata_dev_print_info(dev) || ehc->i.flags & ATA_EHI_DID_PRINT_QUIRKS) in ata_dev_print_quirks()
3917 ehc->i.flags |= ATA_EHI_DID_PRINT_QUIRKS; in ata_dev_print_quirks()
3932 n += snprintf(str + n, sz - n, in ata_dev_print_quirks()
3956 { "Compaq CRD-8241B", NULL, ATA_QUIRK_NODMA },
3957 { "CRD-8400B", NULL, ATA_QUIRK_NODMA },
3958 { "CRD-848[02]B", NULL, ATA_QUIRK_NODMA },
3959 { "CRD-84", NULL, ATA_QUIRK_NODMA },
3961 { "SanDisk SDP3B-64", NULL, ATA_QUIRK_NODMA },
3962 { "SANYO CD-ROM CRD", NULL, ATA_QUIRK_NODMA },
3963 { "HITACHI CDR-8", NULL, ATA_QUIRK_NODMA },
3964 { "HITACHI CDR-8[34]35", NULL, ATA_QUIRK_NODMA },
3965 { "Toshiba CD-ROM XM-6202B", NULL, ATA_QUIRK_NODMA },
3966 { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_QUIRK_NODMA },
3967 { "CD-532E-A", NULL, ATA_QUIRK_NODMA },
3968 { "E-IDE CD-ROM CR-840", NULL, ATA_QUIRK_NODMA },
3969 { "CD-ROM Drive/F5A", NULL, ATA_QUIRK_NODMA },
3970 { "WPI CDD-820", NULL, ATA_QUIRK_NODMA },
3971 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_QUIRK_NODMA },
3972 { "SAMSUNG CD-ROM SC", NULL, ATA_QUIRK_NODMA },
3973 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", NULL, ATA_QUIRK_NODMA },
3975 { "SAMSUNG CD-ROM SN-124", "N001", ATA_QUIRK_NODMA },
3978 { "VRFDFC22048UCHC-TE*", NULL, ATA_QUIRK_NODMA },
3982 { "ASMT109x- Config", NULL, ATA_QUIRK_DISABLE },
3985 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_QUIRK_MAX_SEC_128 },
3986 { "QUANTUM DAT DAT72-000", NULL, ATA_QUIRK_ATAPI_MOD16_DMA },
4000 { "LITEON CX1-JB*-HP", NULL, ATA_QUIRK_MAX_SEC_1024 },
4001 { "LITEON EP1-*", NULL, ATA_QUIRK_MAX_SEC_1024 },
4007 { "WDC WD740ADFD-00", NULL, ATA_QUIRK_NONCQ },
4008 { "WDC WD740ADFD-00NLR1", NULL, ATA_QUIRK_NONCQ },
4019 { "ST31500341AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4022 { "ST31000333AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4025 { "ST3640[36]23AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4028 { "ST3320[68]13AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4031 /* drives which fail FPDMA_AA activation (some may freeze afterwards)
4033 { "ST1000LM024 HN-M101MBB", NULL, ATA_QUIRK_BROKEN_FPDMA_AA |
4038 Windows driver .inf file - also several Linux problem reports */
4044 { "C300-CTFDDAC128MAG", "0001", ATA_QUIRK_NONCQ },
4051 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_QUIRK_BROKEN_HPA },
4052 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_QUIRK_BROKEN_HPA },
4056 { "OCZ-VERTEX", "1.30", ATA_QUIRK_BROKEN_HPA },
4066 { "TSSTcorp CDDVDW SH-S202[HJN]", "SB0[01]", ATA_QUIRK_IVB },
4069 { "MTRON MSP-SATA*", NULL, ATA_QUIRK_BRIDGE_OK },
4070 { "BUFFALO HD-QSU2/R5", NULL, ATA_QUIRK_BRIDGE_OK },
4078 * device and controller are SATA.
4080 { "PIONEER DVD-RW DVRTD08", NULL, ATA_QUIRK_NOSETXFER },
4081 { "PIONEER DVD-RW DVRTD08A", NULL, ATA_QUIRK_NOSETXFER },
4082 { "PIONEER DVD-RW DVR-215", NULL, ATA_QUIRK_NOSETXFER },
4083 { "PIONEER DVD-RW DVR-212D", NULL, ATA_QUIRK_NOSETXFER },
4084 { "PIONEER DVD-RW DVR-216D", NULL, ATA_QUIRK_NOSETXFER },
4087 { "PIONEER BD-RW BDR-207M", NULL, ATA_QUIRK_NOLPM },
4088 { "PIONEER BD-RW BDR-205", NULL, ATA_QUIRK_NOLPM },
4115 /* These specific Samsung models/firmware-revs do not handle LPM well */
4116 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_QUIRK_NOLPM },
4118 { "SAMSUNG MZ7TD256HAFV-000L9", NULL, ATA_QUIRK_NOLPM },
4119 { "SAMSUNG MZ7TE512HMHP-000L1", "EXT06L0Q", ATA_QUIRK_NOLPM },
4187 * Some WD SATA-I drives spin up and down erratically when the link
4190 * known prefixes and is SATA-1. As a side effect LPM partial is
4195 { "WDC WD800JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4196 { "WDC WD1200JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4197 { "WDC WD1600JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4198 { "WDC WD2000JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4199 { "WDC WD2500JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4200 { "WDC WD3000JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4201 { "WDC WD3200JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4208 { "SATADOM-ML 3ME", NULL, ATA_QUIRK_NO_LOG_DIR },
4213 { "OCZ-VERTEX*", NULL, ATA_QUIRK_NO_FUA },
4226 /* dev->quirks is an unsigned int. */ in ata_dev_quirks()
4229 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); in ata_dev_quirks()
4230 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); in ata_dev_quirks()
4232 while (ad->model_num) { in ata_dev_quirks()
4233 if (glob_match(ad->model_num, model_num) && in ata_dev_quirks()
4234 (!ad->model_rev || glob_match(ad->model_rev, model_rev))) { in ata_dev_quirks()
4236 ad->quirks); in ata_dev_quirks()
4237 return ad->quirks; in ata_dev_quirks()
4248 * with CDB-intr (and use PIO) if the LLDD handles only interrupts in in ata_dev_nodma()
4251 if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && in ata_dev_nodma()
4252 (dev->flags & ATA_DFLAG_CDB_INTR)) in ata_dev_nodma()
4254 return dev->quirks & ATA_QUIRK_NODMA; in ata_dev_nodma()
4258 * ata_is_40wire - check drive side detection
4267 if (dev->quirks & ATA_QUIRK_IVB) in ata_is_40wire()
4268 return ata_drive_40wire_relaxed(dev->id); in ata_is_40wire()
4269 return ata_drive_40wire(dev->id); in ata_is_40wire()
4273 * cable_is_40wire - 40/80/SATA decider
4278 * there is a good case for setting ap->cbl to the result when
4290 /* If the controller thinks we are 40 wire, we are. */ in cable_is_40wire()
4291 if (ap->cbl == ATA_CBL_PATA40) in cable_is_40wire()
4294 /* If the controller thinks we are 80 wire, we are. */ in cable_is_40wire()
4295 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) in cable_is_40wire()
4302 if (ap->cbl == ATA_CBL_PATA40_SHORT) in cable_is_40wire()
4305 /* If the controller doesn't know, we scan. in cable_is_40wire()
4309 * - in many setups only the one drive (slave if present) will in cable_is_40wire()
4311 * - if you have a non detect capable drive you don't want it in cable_is_40wire()
4324 * ata_dev_xfermask - Compute supported xfermask of the given device
4328 * dev->*_mask. This function is responsible for applying all
4329 * known limits including host controller limits, device quirks, etc...
4336 struct ata_link *link = dev->link; in ata_dev_xfermask()
4337 struct ata_port *ap = link->ap; in ata_dev_xfermask()
4338 struct ata_host *host = ap->host; in ata_dev_xfermask()
4341 /* controller modes available */ in ata_dev_xfermask()
4342 xfer_mask = ata_pack_xfermask(ap->pio_mask, in ata_dev_xfermask()
4343 ap->mwdma_mask, ap->udma_mask); in ata_dev_xfermask()
4346 xfer_mask &= ata_pack_xfermask(dev->pio_mask, in ata_dev_xfermask()
4347 dev->mwdma_mask, dev->udma_mask); in ata_dev_xfermask()
4348 xfer_mask &= ata_id_xfermask(dev->id); in ata_dev_xfermask()
4367 if ((host->flags & ATA_HOST_SIMPLEX) && in ata_dev_xfermask()
4368 host->simplex_claimed && host->simplex_claimed != ap) { in ata_dev_xfermask()
4374 if (ap->flags & ATA_FLAG_NO_IORDY) in ata_dev_xfermask()
4377 if (ap->ops->mode_filter) in ata_dev_xfermask()
4378 xfer_mask = ap->ops->mode_filter(dev, xfer_mask); in ata_dev_xfermask()
4392 "limited to UDMA/33 due to 40-wire cable\n"); in ata_dev_xfermask()
4396 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, in ata_dev_xfermask()
4397 &dev->mwdma_mask, &dev->udma_mask); in ata_dev_xfermask()
4401 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
4404 * Issue SET FEATURES - XFER MODE command to device @dev
4418 /* set up set-features taskfile */ in ata_dev_set_xfermode()
4419 ata_dev_dbg(dev, "set features - xfer mode\n"); in ata_dev_set_xfermode()
4431 tf.nsect = dev->xfer_mode; in ata_dev_set_xfermode()
4432 /* If the device has IORDY and the controller does not - turn it off */ in ata_dev_set_xfermode()
4433 else if (ata_id_has_iordy(dev->id)) in ata_dev_set_xfermode()
4435 else /* In the ancient relic department - skip all of this */ in ata_dev_set_xfermode()
4439 * On some disks, this command causes spin-up, so we need longer in ata_dev_set_xfermode()
4446 * ata_dev_set_feature - Issue SET FEATURES
4464 /* set up set-features taskfile */ in ata_dev_set_feature()
4483 * ata_dev_init_params - Issue INIT DEV PARAMS command
4500 /* Number of sectors per track 1-255. Number of heads 1-16 */ in ata_dev_init_params()
4512 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ in ata_dev_init_params()
4525 * atapi_check_dma - Check whether ATAPI DMA can be supported
4528 * Allow low-level driver to filter ATA PACKET commands, returning
4540 struct ata_port *ap = qc->ap; in atapi_check_dma()
4545 if (!(qc->dev->quirks & ATA_QUIRK_ATAPI_MOD16_DMA) && in atapi_check_dma()
4546 unlikely(qc->nbytes & 15)) in atapi_check_dma()
4549 if (ap->ops->check_atapi_dma) in atapi_check_dma()
4550 return ap->ops->check_atapi_dma(qc); in atapi_check_dma()
4556 * ata_std_qc_defer - Check whether a qc needs to be deferred
4559 * Non-NCQ commands cannot run with any other command, NCQ or
4572 struct ata_link *link = qc->dev->link; in ata_std_qc_defer()
4574 if (ata_is_ncq(qc->tf.protocol)) { in ata_std_qc_defer()
4575 if (!ata_tag_valid(link->active_tag)) in ata_std_qc_defer()
4578 if (!ata_tag_valid(link->active_tag) && !link->sactive) in ata_std_qc_defer()
4587 * ata_sg_init - Associate command with scatter-gather table.
4589 * @sg: Scatter-gather table.
4592 * Initialize the data-related elements of queued_cmd @qc
4593 * to point to a scatter-gather table @sg, containing @n_elem
4602 qc->sg = sg; in ata_sg_init()
4603 qc->n_elem = n_elem; in ata_sg_init()
4604 qc->cursg = qc->sg; in ata_sg_init()
4610 * ata_sg_clean - Unmap DMA memory associated with command
4620 struct ata_port *ap = qc->ap; in ata_sg_clean()
4621 struct scatterlist *sg = qc->sg; in ata_sg_clean()
4622 int dir = qc->dma_dir; in ata_sg_clean()
4626 if (qc->n_elem) in ata_sg_clean()
4627 dma_unmap_sg(ap->dev, sg, qc->orig_n_elem, dir); in ata_sg_clean()
4629 qc->flags &= ~ATA_QCFLAG_DMAMAP; in ata_sg_clean()
4630 qc->sg = NULL; in ata_sg_clean()
4634 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
4635 * @qc: Command with scatter-gather table to be mapped.
4637 * DMA-map the scatter-gather table associated with queued_cmd @qc.
4648 struct ata_port *ap = qc->ap; in ata_sg_setup()
4651 n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); in ata_sg_setup()
4653 return -1; in ata_sg_setup()
4655 qc->orig_n_elem = qc->n_elem; in ata_sg_setup()
4656 qc->n_elem = n_elem; in ata_sg_setup()
4657 qc->flags |= ATA_QCFLAG_DMAMAP; in ata_sg_setup()
4665 static inline int ata_sg_setup(struct ata_queued_cmd *qc) { return -1; } in ata_sg_setup()
4670 * swap_buf_le16 - swap halves of 16-bit words in place
4672 * @buf_words: Number of 16-bit words in buffer.
4674 * Swap halves of 16-bit words if needed to convert from
4675 * little-endian byte order to native cpu byte order, or
4676 * vice-versa.
4692 * ata_qc_free - free unused ata_queued_cmd
4703 qc->flags = 0; in ata_qc_free()
4704 if (ata_tag_valid(qc->tag)) in ata_qc_free()
4705 qc->tag = ATA_TAG_POISON; in ata_qc_free()
4713 if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE))) in __ata_qc_complete()
4716 ap = qc->ap; in __ata_qc_complete()
4717 link = qc->dev->link; in __ata_qc_complete()
4719 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) in __ata_qc_complete()
4723 if (ata_is_ncq(qc->tf.protocol)) { in __ata_qc_complete()
4724 link->sactive &= ~(1 << qc->hw_tag); in __ata_qc_complete()
4725 if (!link->sactive) in __ata_qc_complete()
4726 ap->nr_active_links--; in __ata_qc_complete()
4728 link->active_tag = ATA_TAG_POISON; in __ata_qc_complete()
4729 ap->nr_active_links--; in __ata_qc_complete()
4733 if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && in __ata_qc_complete()
4734 ap->excl_link == link)) in __ata_qc_complete()
4735 ap->excl_link = NULL; in __ata_qc_complete()
4742 qc->flags &= ~ATA_QCFLAG_ACTIVE; in __ata_qc_complete()
4743 ap->qc_active &= ~(1ULL << qc->tag); in __ata_qc_complete()
4746 qc->complete_fn(qc); in __ata_qc_complete()
4751 struct ata_port *ap = qc->ap; in fill_result_tf()
4757 if (qc->flags & ATA_QCFLAG_RTF_FILLED) in fill_result_tf()
4760 qc->result_tf.flags = qc->tf.flags; in fill_result_tf()
4761 ap->ops->qc_fill_rtf(qc); in fill_result_tf()
4762 qc->flags |= ATA_QCFLAG_RTF_FILLED; in fill_result_tf()
4767 struct ata_device *dev = qc->dev; in ata_verify_xfer()
4769 if (!ata_is_data(qc->tf.protocol)) in ata_verify_xfer()
4772 if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) in ata_verify_xfer()
4775 dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; in ata_verify_xfer()
4779 * ata_qc_complete - Complete an active ATA command
4783 * completed, with either an ok or not-ok status.
4795 struct ata_port *ap = qc->ap; in ata_qc_complete()
4796 struct ata_device *dev = qc->dev; in ata_qc_complete()
4797 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_qc_complete()
4800 ledtrig_disk_activity(!!(qc->tf.flags & ATA_TFLAG_WRITE)); in ata_qc_complete()
4810 if (unlikely(qc->err_mask)) in ata_qc_complete()
4811 qc->flags |= ATA_QCFLAG_EH; in ata_qc_complete()
4817 if (unlikely(ata_tag_internal(qc->tag))) { in ata_qc_complete()
4824 /* Non-internal qc has failed. Fill the result TF and summon EH. */ in ata_qc_complete()
4825 if (unlikely(qc->flags & ATA_QCFLAG_EH)) { in ata_qc_complete()
4835 if (qc->flags & ATA_QCFLAG_RESULT_TF) in ata_qc_complete()
4846 if (qc->flags & ATA_QCFLAG_HAS_CDL && in ata_qc_complete()
4847 qc->result_tf.status & ATA_SENSE) { in ata_qc_complete()
4849 * Tell SCSI EH to not overwrite scmd->result even if this in ata_qc_complete()
4852 qc->scsicmd->flags |= SCMD_FORCE_EH_SUCCESS; in ata_qc_complete()
4853 qc->flags |= ATA_QCFLAG_EH_SUCCESS_CMD; in ata_qc_complete()
4854 ehi->dev_action[dev->devno] |= ATA_EH_GET_SUCCESS_SENSE; in ata_qc_complete()
4858 * fast drain, and freeze the port. in ata_qc_complete()
4860 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_qc_complete()
4865 /* Some commands need post-processing after successful completion. */ in ata_qc_complete()
4866 switch (qc->tf.command) { in ata_qc_complete()
4868 if (qc->tf.feature != SETFEATURES_WC_ON && in ata_qc_complete()
4869 qc->tf.feature != SETFEATURES_WC_OFF && in ata_qc_complete()
4870 qc->tf.feature != SETFEATURES_RA_ON && in ata_qc_complete()
4871 qc->tf.feature != SETFEATURES_RA_OFF) in ata_qc_complete()
4877 ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; in ata_qc_complete()
4882 dev->flags |= ATA_DFLAG_SLEEPING; in ata_qc_complete()
4886 if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) in ata_qc_complete()
4894 * ata_qc_get_active - get bitmask of active qcs
4905 u64 qc_active = ap->qc_active; in ata_qc_get_active()
4918 * ata_qc_issue - issue taskfile to device
4922 * This includes mapping the data into a DMA-able
4931 struct ata_port *ap = qc->ap; in ata_qc_issue()
4932 struct ata_link *link = qc->dev->link; in ata_qc_issue()
4933 u8 prot = qc->tf.protocol; in ata_qc_issue()
4935 /* Make sure only one non-NCQ command is outstanding. */ in ata_qc_issue()
4936 WARN_ON_ONCE(ata_tag_valid(link->active_tag)); in ata_qc_issue()
4939 WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag)); in ata_qc_issue()
4941 if (!link->sactive) in ata_qc_issue()
4942 ap->nr_active_links++; in ata_qc_issue()
4943 link->sactive |= 1 << qc->hw_tag; in ata_qc_issue()
4945 WARN_ON_ONCE(link->sactive); in ata_qc_issue()
4947 ap->nr_active_links++; in ata_qc_issue()
4948 link->active_tag = qc->tag; in ata_qc_issue()
4951 qc->flags |= ATA_QCFLAG_ACTIVE; in ata_qc_issue()
4952 ap->qc_active |= 1ULL << qc->tag; in ata_qc_issue()
4956 * non-zero sg if the command is a data command. in ata_qc_issue()
4958 if (ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)) in ata_qc_issue()
4962 (ap->flags & ATA_FLAG_PIO_DMA))) in ata_qc_issue()
4967 if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { in ata_qc_issue()
4968 link->eh_info.action |= ATA_EH_RESET; in ata_qc_issue()
4969 ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); in ata_qc_issue()
4974 if (ap->ops->qc_prep) { in ata_qc_issue()
4976 qc->err_mask |= ap->ops->qc_prep(qc); in ata_qc_issue()
4977 if (unlikely(qc->err_mask)) in ata_qc_issue()
4982 qc->err_mask |= ap->ops->qc_issue(qc); in ata_qc_issue()
4983 if (unlikely(qc->err_mask)) in ata_qc_issue()
4988 qc->err_mask |= AC_ERR_SYSTEM; in ata_qc_issue()
4994 * ata_phys_link_online - test whether the given link is online
5018 * ata_phys_link_offline - test whether the given link is offline
5042 * ata_link_online - test whether the given link is online
5059 struct ata_link *slave = link->ap->slave_link; in ata_link_online()
5069 * ata_link_offline - test whether the given link is offline
5086 struct ata_link *slave = link->ap->slave_link; in ata_link_offline()
5103 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5109 if (ap->pflags & ATA_PFLAG_PM_PENDING) { in ata_port_request_pm()
5110 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5112 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5116 ap->pm_mesg = mesg; in ata_port_request_pm()
5117 ap->pflags |= ATA_PFLAG_PM_PENDING; in ata_port_request_pm()
5119 link->eh_info.action |= action; in ata_port_request_pm()
5120 link->eh_info.flags |= ehi_flags; in ata_port_request_pm()
5125 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5140 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_suspend()
5205 * So the idle callback here will not proceed to suspend if a non-ZPODD capable
5216 if (adev->class == ATA_DEV_ATAPI && in ata_port_runtime_idle()
5218 return -EBUSY; in ata_port_runtime_idle()
5239 .freeze = ata_port_pm_freeze,
5250 * and need to resume ata devices at the domain level, not the per-port
5267 * ata_host_suspend - suspend host
5275 host->dev->power.power_state = mesg; in ata_host_suspend()
5280 * ata_host_resume - resume host
5287 host->dev->power.power_state = PMSG_ON; in ata_host_resume()
5300 * ata_dev_init - Initialize an ata_device structure
5311 struct ata_port *ap = link->ap; in ata_dev_init()
5315 link->sata_spd_limit = link->hw_sata_spd_limit; in ata_dev_init()
5316 link->sata_spd = 0; in ata_dev_init()
5318 /* High bits of dev->flags are used to record warm plug in ata_dev_init()
5322 spin_lock_irqsave(ap->lock, flags); in ata_dev_init()
5323 dev->flags &= ~ATA_DFLAG_INIT_MASK; in ata_dev_init()
5324 dev->quirks = 0; in ata_dev_init()
5325 spin_unlock_irqrestore(ap->lock, flags); in ata_dev_init()
5328 ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); in ata_dev_init()
5329 dev->pio_mask = UINT_MAX; in ata_dev_init()
5330 dev->mwdma_mask = UINT_MAX; in ata_dev_init()
5331 dev->udma_mask = UINT_MAX; in ata_dev_init()
5335 * ata_link_init - Initialize an ata_link structure
5351 ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); in ata_link_init()
5353 link->ap = ap; in ata_link_init()
5354 link->pmp = pmp; in ata_link_init()
5355 link->active_tag = ATA_TAG_POISON; in ata_link_init()
5356 link->hw_sata_spd_limit = UINT_MAX; in ata_link_init()
5360 struct ata_device *dev = &link->device[i]; in ata_link_init()
5362 dev->link = link; in ata_link_init()
5363 dev->devno = dev - link->device; in ata_link_init()
5365 dev->gtf_filter = ata_acpi_gtf_filter; in ata_link_init()
5372 * sata_link_init_spd - Initialize link->sata_spd_limit
5375 * Initialize ``link->[hw_]sata_spd_limit`` to the currently
5382 * 0 on success, -errno on failure.
5389 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); in sata_link_init_spd()
5393 spd = (link->saved_scontrol >> 4) & 0xf; in sata_link_init_spd()
5395 link->hw_sata_spd_limit &= (1 << spd) - 1; in sata_link_init_spd()
5399 link->sata_spd_limit = link->hw_sata_spd_limit; in sata_link_init_spd()
5405 * ata_port_alloc - allocate and initialize basic ATA port resources
5425 ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; in ata_port_alloc()
5426 ap->lock = &host->lock; in ata_port_alloc()
5432 ap->print_id = id; in ata_port_alloc()
5433 ap->host = host; in ata_port_alloc()
5434 ap->dev = host->dev; in ata_port_alloc()
5436 mutex_init(&ap->scsi_scan_mutex); in ata_port_alloc()
5437 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); in ata_port_alloc()
5438 INIT_DELAYED_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); in ata_port_alloc()
5439 INIT_LIST_HEAD(&ap->eh_done_q); in ata_port_alloc()
5440 init_waitqueue_head(&ap->eh_wait_q); in ata_port_alloc()
5441 init_completion(&ap->park_req_pending); in ata_port_alloc()
5442 timer_setup(&ap->fastdrain_timer, ata_eh_fastdrain_timerfn, in ata_port_alloc()
5445 ap->cbl = ATA_CBL_NONE; in ata_port_alloc()
5447 ata_link_init(ap, &ap->link, 0); in ata_port_alloc()
5450 ap->stats.unhandled_irq = 1; in ata_port_alloc()
5451 ap->stats.idle_irq = 1; in ata_port_alloc()
5464 kfree(ap->pmp_link); in ata_port_free()
5465 kfree(ap->slave_link); in ata_port_free()
5466 ida_free(&ata_ida, ap->print_id); in ata_port_free()
5476 for (i = 0; i < host->n_ports; i++) { in ata_devres_release()
5477 struct ata_port *ap = host->ports[i]; in ata_devres_release()
5482 if (ap->scsi_host) in ata_devres_release()
5483 scsi_host_put(ap->scsi_host); in ata_devres_release()
5496 for (i = 0; i < host->n_ports; i++) { in ata_host_release()
5497 ata_port_free(host->ports[i]); in ata_host_release()
5498 host->ports[i] = NULL; in ata_host_release()
5505 kref_get(&host->kref); in ata_host_get()
5510 kref_put(&host->kref, ata_host_release); in ata_host_put()
5515 * ata_host_alloc - allocate and init basic ATA host resources
5556 spin_lock_init(&host->lock); in ata_host_alloc()
5557 mutex_init(&host->eh_mutex); in ata_host_alloc()
5558 host->dev = dev; in ata_host_alloc()
5559 host->n_ports = n_ports; in ata_host_alloc()
5560 kref_init(&host->kref); in ata_host_alloc()
5570 ap->port_no = i; in ata_host_alloc()
5571 host->ports[i] = ap; in ata_host_alloc()
5584 * ata_host_alloc_pinfo - alloc host and init with port_info array
5611 for (i = 0, j = 0; i < host->n_ports; i++) { in ata_host_alloc_pinfo()
5612 struct ata_port *ap = host->ports[i]; in ata_host_alloc_pinfo()
5617 ap->pio_mask = pi->pio_mask; in ata_host_alloc_pinfo()
5618 ap->mwdma_mask = pi->mwdma_mask; in ata_host_alloc_pinfo()
5619 ap->udma_mask = pi->udma_mask; in ata_host_alloc_pinfo()
5620 ap->flags |= pi->flags; in ata_host_alloc_pinfo()
5621 ap->link.flags |= pi->link_flags; in ata_host_alloc_pinfo()
5622 ap->ops = pi->port_ops; in ata_host_alloc_pinfo()
5624 if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) in ata_host_alloc_pinfo()
5625 host->ops = pi->port_ops; in ata_host_alloc_pinfo()
5637 WARN_ON(!(host->flags & ATA_HOST_STARTED)); in ata_host_stop()
5639 for (i = 0; i < host->n_ports; i++) { in ata_host_stop()
5640 struct ata_port *ap = host->ports[i]; in ata_host_stop()
5642 if (ap->ops->port_stop) in ata_host_stop()
5643 ap->ops->port_stop(ap); in ata_host_stop()
5646 if (host->ops->host_stop) in ata_host_stop()
5647 host->ops->host_stop(host); in ata_host_stop()
5651 * ata_finalize_port_ops - finalize ata_port_operations
5663 * methods and ->inherits is no longer necessary and cleared.
5675 void **end = (void **)&ops->inherits; in ata_finalize_port_ops()
5678 if (!ops || !ops->inherits) in ata_finalize_port_ops()
5683 for (cur = ops->inherits; cur; cur = cur->inherits) { in ata_finalize_port_ops()
5695 ops->inherits = NULL; in ata_finalize_port_ops()
5701 * ata_host_start - start and freeze ports of an ATA host
5704 * Start and then freeze ports of @host. Started status is
5705 * recorded in host->flags, so this function can be called
5707 * once. If host->ops is not initialized yet, it is set to the
5708 * first non-dummy port ops.
5714 * 0 if all ports are started successfully, -errno otherwise.
5722 if (host->flags & ATA_HOST_STARTED) in ata_host_start()
5725 ata_finalize_port_ops(host->ops); in ata_host_start()
5727 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5728 struct ata_port *ap = host->ports[i]; in ata_host_start()
5730 ata_finalize_port_ops(ap->ops); in ata_host_start()
5732 if (!host->ops && !ata_port_is_dummy(ap)) in ata_host_start()
5733 host->ops = ap->ops; in ata_host_start()
5735 if (ap->ops->port_stop) in ata_host_start()
5739 if (host->ops && host->ops->host_stop) in ata_host_start()
5745 return -ENOMEM; in ata_host_start()
5748 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5749 struct ata_port *ap = host->ports[i]; in ata_host_start()
5751 if (ap->ops->port_start) { in ata_host_start()
5752 rc = ap->ops->port_start(ap); in ata_host_start()
5754 if (rc != -ENODEV) in ata_host_start()
5755 dev_err(host->dev, in ata_host_start()
5765 devres_add(host->dev, start_dr); in ata_host_start()
5766 host->flags |= ATA_HOST_STARTED; in ata_host_start()
5770 while (--i >= 0) { in ata_host_start()
5771 struct ata_port *ap = host->ports[i]; in ata_host_start()
5773 if (ap->ops->port_stop) in ata_host_start()
5774 ap->ops->port_stop(ap); in ata_host_start()
5782 * ata_host_init - Initialize a host struct for sas (ipr, libsas)
5791 spin_lock_init(&host->lock); in ata_host_init()
5792 mutex_init(&host->eh_mutex); in ata_host_init()
5793 host->n_tags = ATA_MAX_QUEUE; in ata_host_init()
5794 host->dev = dev; in ata_host_init()
5795 host->ops = ops; in ata_host_init()
5796 kref_init(&host->kref); in ata_host_init()
5802 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_port_probe()
5806 spin_lock_irqsave(ap->lock, flags); in ata_port_probe()
5808 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_port_probe()
5809 ehi->action |= ATA_EH_RESET; in ata_port_probe()
5810 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; in ata_port_probe()
5812 ap->pflags &= ~ATA_PFLAG_INITIALIZING; in ata_port_probe()
5813 ap->pflags |= ATA_PFLAG_LOADING; in ata_port_probe()
5816 spin_unlock_irqrestore(ap->lock, flags); in ata_port_probe()
5828 * Jeff Garzik says this is only within a controller, so we in async_port_probe()
5831 if (!(ap->host->flags & ATA_HOST_PARALLEL_SCAN) && ap->port_no != 0) in async_port_probe()
5844 * ata_host_register - register initialized ATA host
5857 * 0 on success, -errno otherwise.
5863 host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE); in ata_host_register()
5866 if (!(host->flags & ATA_HOST_STARTED)) { in ata_host_register()
5867 dev_err(host->dev, "BUG: trying to register unstarted host\n"); in ata_host_register()
5869 return -EINVAL; in ata_host_register()
5873 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5874 rc = ata_tport_add(host->dev,host->ports[i]); in ata_host_register()
5885 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5886 struct ata_port *ap = host->ports[i]; in ata_host_register()
5890 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) in ata_host_register()
5891 ap->cbl = ATA_CBL_SATA; in ata_host_register()
5894 sata_link_init_spd(&ap->link); in ata_host_register()
5895 if (ap->slave_link) in ata_host_register()
5896 sata_link_init_spd(ap->slave_link); in ata_host_register()
5898 /* print per-port info to dmesg */ in ata_host_register()
5899 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, in ata_host_register()
5900 ap->udma_mask); in ata_host_register()
5904 (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', in ata_host_register()
5906 ap->link.eh_info.desc); in ata_host_register()
5907 ata_ehi_clear_desc(&ap->link.eh_info); in ata_host_register()
5913 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5914 struct ata_port *ap = host->ports[i]; in ata_host_register()
5915 ap->cookie = async_schedule(async_port_probe, ap); in ata_host_register()
5921 while (--i >= 0) { in ata_host_register()
5922 ata_tport_delete(host->ports[i]); in ata_host_register()
5930 * ata_host_activate - start host, request IRQ and register it
5938 * LLDs perform three steps to activate the host - start host,
5950 * 0 on success, -errno otherwise.
5969 irq_desc = devm_kasprintf(host->dev, GFP_KERNEL, "%s[%s]", in ata_host_activate()
5970 dev_driver_string(host->dev), in ata_host_activate()
5971 dev_name(host->dev)); in ata_host_activate()
5973 return -ENOMEM; in ata_host_activate()
5975 rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, in ata_host_activate()
5980 for (i = 0; i < host->n_ports; i++) in ata_host_activate()
5981 ata_port_desc_misc(host->ports[i], irq); in ata_host_activate()
5986 devm_free_irq(host->dev, irq, host); in ata_host_activate()
5993 * ata_dev_free_resources - Free a device resources
6010 * ata_port_detach - Detach ATA port in preparation of device removal
6027 async_synchronize_cookie(ap->cookie + 1); in ata_port_detach()
6032 mutex_lock(&ap->scsi_scan_mutex); in ata_port_detach()
6033 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6038 if (dev->sdev) { in ata_port_detach()
6039 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6040 scsi_remove_device(dev->sdev); in ata_port_detach()
6041 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6042 dev->sdev = NULL; in ata_port_detach()
6048 ap->pflags |= ATA_PFLAG_UNLOADING; in ata_port_detach()
6051 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6052 mutex_unlock(&ap->scsi_scan_mutex); in ata_port_detach()
6058 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED)); in ata_port_detach()
6060 cancel_delayed_work_sync(&ap->hotplug_task); in ata_port_detach()
6061 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_detach()
6064 if (ap->pmp_link) { in ata_port_detach()
6068 ata_tlink_delete(&ap->pmp_link[i]); in ata_port_detach()
6072 scsi_remove_host(ap->scsi_host); in ata_port_detach()
6077 * ata_host_detach - Detach all ports of an ATA host
6089 for (i = 0; i < host->n_ports; i++) in ata_host_detach()
6090 ata_port_detach(host->ports[i]); in ata_host_detach()
6100 * ata_pci_remove_one - PCI layer callback for device removal
6103 * PCI layer indicates to libata via this hook that hot-unplug or
6123 for (i = 0; i < host->n_ports; i++) { in ata_pci_shutdown_one()
6124 struct ata_port *ap = host->ports[i]; in ata_pci_shutdown_one()
6126 ap->pflags |= ATA_PFLAG_FROZEN; in ata_pci_shutdown_one()
6129 if (ap->ops->freeze) in ata_pci_shutdown_one()
6130 ap->ops->freeze(ap); in ata_pci_shutdown_one()
6133 if (ap->ops->port_stop) in ata_pci_shutdown_one()
6134 ap->ops->port_stop(ap); in ata_pci_shutdown_one()
6144 switch (bits->width) { in pci_test_config_bits()
6147 pci_read_config_byte(pdev, bits->reg, &tmp8); in pci_test_config_bits()
6153 pci_read_config_word(pdev, bits->reg, &tmp16); in pci_test_config_bits()
6159 pci_read_config_dword(pdev, bits->reg, &tmp32); in pci_test_config_bits()
6165 return -EINVAL; in pci_test_config_bits()
6168 tmp &= bits->mask; in pci_test_config_bits()
6170 return (tmp == bits->val) ? 1 : 0; in pci_test_config_bits()
6194 dev_err(&pdev->dev, in ata_pci_device_do_resume()
6231 * ata_platform_remove_one - Platform layer callback for device removal
6234 * Platform layer indicates to libata via this hook that hot-unplug or
6389 force_ent->device = simple_strtoul(p, &endp, 10); in ata_parse_force_one()
6392 return -EINVAL; in ata_parse_force_one()
6396 force_ent->port = simple_strtoul(id, &endp, 10); in ata_parse_force_one()
6399 return -EINVAL; in ata_parse_force_one()
6407 if (strncasecmp(val, fp->name, strlen(val))) in ata_parse_force_one()
6413 if (strcasecmp(val, fp->name) == 0) { in ata_parse_force_one()
6421 return -EINVAL; in ata_parse_force_one()
6425 return -EINVAL; in ata_parse_force_one()
6428 force_ent->param = *match_fp; in ata_parse_force_one()
6436 int last_port = -1, last_device = -1; in ata_parse_force_param()
6454 struct ata_force_ent te = { .port = -1, .device = -1 }; in ata_parse_force_param()
6464 if (te.port == -1) { in ata_parse_force_param()
6503 rc = -ENOMEM; in ata_init()
6534 * ata_msleep - ATA EH owner aware msleep
6541 * @ap->host will be allowed to own the EH while this task is
6549 bool owns_eh = ap && ap->host->eh_owner == current; in ata_msleep()
6567 * ata_wait_register - wait until register value changes
6569 * @reg: IO-mapped register
6577 * IO-mapped register @reg and tests for the following condition.
6599 * preceding writes reach the controller before starting to in ata_wait_register()