Lines Matching +full:standby +full:- +full:idle +full:- +full:ns
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"
108 …ing cable type, link speed and transfer mode (see Documentation/admin-guide/kernel-parameters.rst …
158 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_print_info()
160 return ehc->i.flags & ATA_EHI_PRINTINFO; in ata_dev_print_info()
164 * ata_link_next - link iteration helper
187 return ap->pmp_link; in ata_link_next()
190 return &ap->link; in ata_link_next()
194 if (link == &ap->link) in ata_link_next()
198 return ap->pmp_link; in ata_link_next()
201 if (unlikely(ap->slave_link)) in ata_link_next()
202 return ap->slave_link; in ata_link_next()
209 if (unlikely(link == ap->slave_link)) in ata_link_next()
213 if (++link < ap->pmp_link + ap->nr_pmp_links) in ata_link_next()
217 return &ap->link; in ata_link_next()
224 * ata_dev_next - device iteration helper
246 dev = link->device; in ata_dev_next()
250 dev = link->device + ata_link_max_devices(link) - 1; in ata_dev_next()
259 if (++dev < link->device + ata_link_max_devices(link)) in ata_dev_next()
264 if (--dev >= link->device) in ata_dev_next()
278 * ata_dev_phys_link - find physical link for a device
282 * this is different from @dev->link only when @dev is on slave
283 * link. For all other cases, it's the same as @dev->link.
293 struct ata_port *ap = dev->link->ap; in ata_dev_phys_link()
295 if (!ap->slave_link) in ata_dev_phys_link()
296 return dev->link; in ata_dev_phys_link()
297 if (!dev->devno) in ata_dev_phys_link()
298 return &ap->link; in ata_dev_phys_link()
299 return ap->slave_link; in ata_dev_phys_link()
304 * ata_force_cbl - force cable type according to libata.force
320 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_cbl()
323 if (fe->port != -1 && fe->port != ap->print_id) in ata_force_cbl()
326 if (fe->param.cbl == ATA_CBL_NONE) in ata_force_cbl()
329 ap->cbl = fe->param.cbl; in ata_force_cbl()
330 ata_port_notice(ap, "FORCE: cable set to %s\n", fe->param.name); in ata_force_cbl()
336 * ata_force_pflags - force port flags according to libata.force
348 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_pflags()
351 if (fe->port != -1 && fe->port != ap->print_id) in ata_force_pflags()
355 if (fe->param.pflags_on) { in ata_force_pflags()
356 ap->pflags |= fe->param.pflags_on; in ata_force_pflags()
358 "FORCE: port flag 0x%x forced -> 0x%x\n", in ata_force_pflags()
359 fe->param.pflags_on, ap->pflags); in ata_force_pflags()
365 * ata_force_link_limits - force link limits according to libata.force
371 * the host link and all fan-out ports connected via PMP. If the
373 * first fan-out link not the host link. Device number 15 always
383 int linkno = link->pmp; in ata_force_link_limits()
389 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_link_limits()
392 if (fe->port != -1 && fe->port != link->ap->print_id) in ata_force_link_limits()
395 if (fe->device != -1 && fe->device != linkno) in ata_force_link_limits()
399 if (!did_spd && fe->param.spd_limit) { in ata_force_link_limits()
400 link->hw_sata_spd_limit = (1 << fe->param.spd_limit) - 1; in ata_force_link_limits()
402 fe->param.name); in ata_force_link_limits()
407 if (fe->param.lflags_on) { in ata_force_link_limits()
408 link->flags |= fe->param.lflags_on; in ata_force_link_limits()
410 "FORCE: link flag 0x%x forced -> 0x%x\n", in ata_force_link_limits()
411 fe->param.lflags_on, link->flags); in ata_force_link_limits()
413 if (fe->param.lflags_off) { in ata_force_link_limits()
414 link->flags &= ~fe->param.lflags_off; in ata_force_link_limits()
416 "FORCE: link flag 0x%x cleared -> 0x%x\n", in ata_force_link_limits()
417 fe->param.lflags_off, link->flags); in ata_force_link_limits()
423 * ata_force_xfermask - force xfermask according to libata.force
435 int devno = dev->link->pmp + dev->devno; in ata_force_xfermask()
440 if (ata_is_host_link(dev->link)) in ata_force_xfermask()
443 for (i = ata_force_tbl_size - 1; i >= 0; i--) { in ata_force_xfermask()
447 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_xfermask()
450 if (fe->device != -1 && fe->device != devno && in ata_force_xfermask()
451 fe->device != alt_devno) in ata_force_xfermask()
454 if (!fe->param.xfer_mask) in ata_force_xfermask()
457 ata_unpack_xfermask(fe->param.xfer_mask, in ata_force_xfermask()
460 dev->udma_mask = udma_mask; in ata_force_xfermask()
462 dev->udma_mask = 0; in ata_force_xfermask()
463 dev->mwdma_mask = mwdma_mask; in ata_force_xfermask()
465 dev->udma_mask = 0; in ata_force_xfermask()
466 dev->mwdma_mask = 0; in ata_force_xfermask()
467 dev->pio_mask = pio_mask; in ata_force_xfermask()
471 fe->param.name); in ata_force_xfermask()
477 * ata_force_quirks - force quirks according to libata.force
489 int devno = dev->link->pmp + dev->devno; in ata_force_quirks()
494 if (ata_is_host_link(dev->link)) in ata_force_quirks()
500 if (fe->port != -1 && fe->port != dev->link->ap->print_id) in ata_force_quirks()
503 if (fe->device != -1 && fe->device != devno && in ata_force_quirks()
504 fe->device != alt_devno) in ata_force_quirks()
507 if (!(~dev->quirks & fe->param.quirk_on) && in ata_force_quirks()
508 !(dev->quirks & fe->param.quirk_off)) in ata_force_quirks()
511 dev->quirks |= fe->param.quirk_on; in ata_force_quirks()
512 dev->quirks &= ~fe->param.quirk_off; in ata_force_quirks()
515 fe->param.name); in ata_force_quirks()
526 * atapi_cmd_type - Determine ATAPI command type from SCSI opcode
595 * ata_set_rwcmd_protocol - set taskfile r/w command and protocol
599 * Examine the device configuration and tf->flags to determine
612 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; in ata_set_rwcmd_protocol()
613 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; in ata_set_rwcmd_protocol()
614 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; in ata_set_rwcmd_protocol()
616 if (dev->flags & ATA_DFLAG_PIO) { in ata_set_rwcmd_protocol()
617 tf->protocol = ATA_PROT_PIO; in ata_set_rwcmd_protocol()
618 index = dev->multi_count ? 0 : 8; in ata_set_rwcmd_protocol()
619 } else if (lba48 && (dev->link->ap->flags & ATA_FLAG_PIO_LBA48)) { in ata_set_rwcmd_protocol()
621 tf->protocol = ATA_PROT_PIO; in ata_set_rwcmd_protocol()
622 index = dev->multi_count ? 0 : 8; in ata_set_rwcmd_protocol()
624 tf->protocol = ATA_PROT_DMA; in ata_set_rwcmd_protocol()
632 tf->command = cmd; in ata_set_rwcmd_protocol()
638 * ata_tf_read_block - Read block address from ATA taskfile
646 * three address formats - LBA, LBA48 and CHS. tf->protocol and
656 if (tf->flags & ATA_TFLAG_LBA) { in ata_tf_read_block()
657 if (tf->flags & ATA_TFLAG_LBA48) { in ata_tf_read_block()
658 block |= (u64)tf->hob_lbah << 40; in ata_tf_read_block()
659 block |= (u64)tf->hob_lbam << 32; in ata_tf_read_block()
660 block |= (u64)tf->hob_lbal << 24; in ata_tf_read_block()
662 block |= (tf->device & 0xf) << 24; in ata_tf_read_block()
664 block |= tf->lbah << 16; in ata_tf_read_block()
665 block |= tf->lbam << 8; in ata_tf_read_block()
666 block |= tf->lbal; in ata_tf_read_block()
670 cyl = tf->lbam | (tf->lbah << 8); in ata_tf_read_block()
671 head = tf->device & 0xf; in ata_tf_read_block()
672 sect = tf->lbal; in ata_tf_read_block()
680 block = (cyl * dev->heads + head) * dev->sectors + sect - 1; in ata_tf_read_block()
691 struct ata_taskfile *tf = &qc->tf; in ata_set_tf_cdl()
693 if (tf->protocol == ATA_PROT_NCQ) in ata_set_tf_cdl()
694 tf->auxiliary |= cdl; in ata_set_tf_cdl()
696 tf->feature |= cdl; in ata_set_tf_cdl()
703 qc->flags |= ATA_QCFLAG_HAS_CDL | ATA_QCFLAG_RESULT_TF; in ata_set_tf_cdl()
707 * ata_build_rw_tf - Build ATA taskfile for given read/write request
723 * 0 on success, -ERANGE if the request is too large for @dev,
724 * -EINVAL if the request is invalid.
729 struct ata_taskfile *tf = &qc->tf; in ata_build_rw_tf()
730 struct ata_device *dev = qc->dev; in ata_build_rw_tf()
732 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; in ata_build_rw_tf()
733 tf->flags |= tf_flags; in ata_build_rw_tf()
738 return -ERANGE; in ata_build_rw_tf()
740 tf->protocol = ATA_PROT_NCQ; in ata_build_rw_tf()
741 tf->flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48; in ata_build_rw_tf()
743 if (tf->flags & ATA_TFLAG_WRITE) in ata_build_rw_tf()
744 tf->command = ATA_CMD_FPDMA_WRITE; in ata_build_rw_tf()
746 tf->command = ATA_CMD_FPDMA_READ; in ata_build_rw_tf()
748 tf->nsect = qc->hw_tag << 3; in ata_build_rw_tf()
749 tf->hob_feature = (n_block >> 8) & 0xff; in ata_build_rw_tf()
750 tf->feature = n_block & 0xff; in ata_build_rw_tf()
752 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
753 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
754 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
755 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
756 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
757 tf->lbal = block & 0xff; in ata_build_rw_tf()
759 tf->device = ATA_LBA; in ata_build_rw_tf()
760 if (tf->flags & ATA_TFLAG_FUA) in ata_build_rw_tf()
761 tf->device |= 1 << 7; in ata_build_rw_tf()
763 if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED && in ata_build_rw_tf()
765 tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; in ata_build_rw_tf()
767 if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) in ata_build_rw_tf()
770 } else if (dev->flags & ATA_DFLAG_LBA) { in ata_build_rw_tf()
771 tf->flags |= ATA_TFLAG_LBA; in ata_build_rw_tf()
773 if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) in ata_build_rw_tf()
776 /* Both FUA writes and a CDL index require 48-bit commands */ in ata_build_rw_tf()
777 if (!(tf->flags & ATA_TFLAG_FUA) && in ata_build_rw_tf()
778 !(qc->flags & ATA_QCFLAG_HAS_CDL) && in ata_build_rw_tf()
781 tf->device |= (block >> 24) & 0xf; in ata_build_rw_tf()
783 if (!(dev->flags & ATA_DFLAG_LBA48)) in ata_build_rw_tf()
784 return -ERANGE; in ata_build_rw_tf()
787 tf->flags |= ATA_TFLAG_LBA48; in ata_build_rw_tf()
789 tf->hob_nsect = (n_block >> 8) & 0xff; in ata_build_rw_tf()
791 tf->hob_lbah = (block >> 40) & 0xff; in ata_build_rw_tf()
792 tf->hob_lbam = (block >> 32) & 0xff; in ata_build_rw_tf()
793 tf->hob_lbal = (block >> 24) & 0xff; in ata_build_rw_tf()
796 return -ERANGE; in ata_build_rw_tf()
800 return -EINVAL; in ata_build_rw_tf()
802 tf->nsect = n_block & 0xff; in ata_build_rw_tf()
804 tf->lbah = (block >> 16) & 0xff; in ata_build_rw_tf()
805 tf->lbam = (block >> 8) & 0xff; in ata_build_rw_tf()
806 tf->lbal = block & 0xff; in ata_build_rw_tf()
808 tf->device |= ATA_LBA; in ata_build_rw_tf()
813 /* The request -may- be too large for CHS addressing. */ in ata_build_rw_tf()
815 return -ERANGE; in ata_build_rw_tf()
818 return -EINVAL; in ata_build_rw_tf()
821 track = (u32)block / dev->sectors; in ata_build_rw_tf()
822 cyl = track / dev->heads; in ata_build_rw_tf()
823 head = track % dev->heads; in ata_build_rw_tf()
824 sect = (u32)block % dev->sectors + 1; in ata_build_rw_tf()
827 Cylinder: 0-65535 in ata_build_rw_tf()
828 Head: 0-15 in ata_build_rw_tf()
829 Sector: 1-255*/ in ata_build_rw_tf()
831 return -ERANGE; in ata_build_rw_tf()
833 tf->nsect = n_block & 0xff; /* Sector count 0 means 256 sectors */ in ata_build_rw_tf()
834 tf->lbal = sect; in ata_build_rw_tf()
835 tf->lbam = cyl; in ata_build_rw_tf()
836 tf->lbah = cyl >> 8; in ata_build_rw_tf()
837 tf->device |= head; in ata_build_rw_tf()
844 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
869 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
896 { -1, },
900 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
914 int highbit = fls(xfer_mask) - 1; in ata_xfer_mask2mode()
917 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mask2mode()
918 if (highbit >= ent->shift && highbit < ent->shift + ent->bits) in ata_xfer_mask2mode()
919 return ent->base + highbit - ent->shift; in ata_xfer_mask2mode()
925 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
940 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2mask()
941 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2mask()
942 return ((2 << (ent->shift + xfer_mode - ent->base)) - 1) in ata_xfer_mode2mask()
943 & ~((1 << ent->shift) - 1); in ata_xfer_mode2mask()
949 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
958 * Matching xfer_shift, -1 if no match found.
964 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_xfer_mode2shift()
965 if (xfer_mode >= ent->base && xfer_mode < ent->base + ent->bits) in ata_xfer_mode2shift()
966 return ent->shift; in ata_xfer_mode2shift()
967 return -1; in ata_xfer_mode2shift()
972 * ata_mode_string - convert xfer_mask to string
1011 highbit = fls(xfer_mask) - 1; in ata_mode_string()
1026 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) in sata_spd_string()
1028 return spd_str[spd - 1]; in sata_spd_string()
1032 * ata_dev_classify - determine device type based on ATA-spec signature
1052 * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate in ata_dev_classify()
1059 * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and in ata_dev_classify()
1065 * Unfortunately, WDC WD1600JS-62MHB5 (a hard drive) reports in ata_dev_classify()
1069 if (tf->lbam == 0 && tf->lbah == 0) in ata_dev_classify()
1072 if (tf->lbam == 0x14 && tf->lbah == 0xeb) in ata_dev_classify()
1075 if (tf->lbam == 0x69 && tf->lbah == 0x96) in ata_dev_classify()
1078 if (tf->lbam == 0x3c && tf->lbah == 0xc3) in ata_dev_classify()
1081 if (tf->lbam == 0xcd && tf->lbah == 0xab) in ata_dev_classify()
1089 * ata_id_string - Convert IDENTIFY DEVICE page into string
1096 * 16-bit chunks. Run through the string, and output each
1097 * 8-bit chunk linearly, regardless of platform.
1120 len -= 2; in ata_id_string()
1126 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
1144 ata_id_string(id, s, ofs, len - 1); in ata_id_c_string()
1146 p = s + strnlen(s, len - 1); in ata_id_c_string()
1147 while (p > s && p[-1] == ' ') in ata_id_c_string()
1148 p--; in ata_id_c_string()
1174 sectors |= ((u64)(tf->hob_lbah & 0xff)) << 40; in ata_tf_to_lba48()
1175 sectors |= ((u64)(tf->hob_lbam & 0xff)) << 32; in ata_tf_to_lba48()
1176 sectors |= ((u64)(tf->hob_lbal & 0xff)) << 24; in ata_tf_to_lba48()
1177 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba48()
1178 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba48()
1179 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba48()
1188 sectors |= (tf->device & 0x0f) << 24; in ata_tf_to_lba()
1189 sectors |= (tf->lbah & 0xff) << 16; in ata_tf_to_lba()
1190 sectors |= (tf->lbam & 0xff) << 8; in ata_tf_to_lba()
1191 sectors |= (tf->lbal & 0xff); in ata_tf_to_lba()
1197 * ata_read_native_max_address - Read native max address
1205 * 0 on success, -EACCES if command is aborted by the drive.
1206 * -EIO on other errors.
1212 int lba48 = ata_id_has_lba48(dev->id); in ata_read_native_max_address()
1234 return -EACCES; in ata_read_native_max_address()
1235 return -EIO; in ata_read_native_max_address()
1242 if (dev->quirks & ATA_QUIRK_HPA_SIZE) in ata_read_native_max_address()
1243 (*max_sectors)--; in ata_read_native_max_address()
1248 * ata_set_max_sectors - Set max sectors
1255 * 0 on success, -EACCES if command is aborted or denied (due to
1256 * previous non-volatile SET_MAX) by the drive. -EIO on other
1263 int lba48 = ata_id_has_lba48(dev->id); in ata_set_max_sectors()
1265 new_sectors--; in ata_set_max_sectors()
1298 return -EACCES; in ata_set_max_sectors()
1299 return -EIO; in ata_set_max_sectors()
1306 * ata_hpa_resize - Resize a device with an HPA set
1314 * 0 on success, -errno on failure.
1319 bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA; in ata_hpa_resize()
1320 u64 sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1325 if ((dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) || in ata_hpa_resize()
1326 !ata_id_has_lba(dev->id) || !ata_id_hpa_enabled(dev->id) || in ata_hpa_resize()
1327 (dev->quirks & ATA_QUIRK_BROKEN_HPA)) in ata_hpa_resize()
1336 if (rc == -EACCES || !unlock_hpa) { in ata_hpa_resize()
1339 dev->quirks |= ATA_QUIRK_BROKEN_HPA; in ata_hpa_resize()
1342 if (rc == -EACCES) in ata_hpa_resize()
1348 dev->n_native_sectors = native_sectors; in ata_hpa_resize()
1370 if (rc == -EACCES) { in ata_hpa_resize()
1373 "device aborted resize (%llu -> %llu), skipping HPA handling\n", in ata_hpa_resize()
1376 dev->quirks |= ATA_QUIRK_BROKEN_HPA; in ata_hpa_resize()
1381 /* re-read IDENTIFY data */ in ata_hpa_resize()
1385 "failed to re-read IDENTIFY data after HPA resizing\n"); in ata_hpa_resize()
1390 u64 new_sectors = ata_id_n_sectors(dev->id); in ata_hpa_resize()
1392 "HPA unlocked: %llu -> %llu, native %llu\n", in ata_hpa_resize()
1402 * ata_dump_id - IDENTIFY DEVICE info debugging output
1406 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1424 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1454 pio_mask = (2 << mode) - 1; in ata_id_xfermask()
1495 struct completion *waiting = qc->private_data; in ata_qc_complete_internal()
1501 * ata_exec_internal - execute libata internal command
1527 struct ata_link *link = dev->link; in ata_exec_internal()
1528 struct ata_port *ap = link->ap; in ata_exec_internal()
1529 u8 command = tf->command; in ata_exec_internal()
1545 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal()
1549 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1556 qc->tag = ATA_TAG_INTERNAL; in ata_exec_internal()
1557 qc->hw_tag = 0; in ata_exec_internal()
1558 qc->scsicmd = NULL; in ata_exec_internal()
1559 qc->ap = ap; in ata_exec_internal()
1560 qc->dev = dev; in ata_exec_internal()
1563 preempted_tag = link->active_tag; in ata_exec_internal()
1564 preempted_sactive = link->sactive; in ata_exec_internal()
1565 preempted_qc_active = ap->qc_active; in ata_exec_internal()
1566 preempted_nr_active_links = ap->nr_active_links; in ata_exec_internal()
1567 link->active_tag = ATA_TAG_POISON; in ata_exec_internal()
1568 link->sactive = 0; in ata_exec_internal()
1569 ap->qc_active = 0; in ata_exec_internal()
1570 ap->nr_active_links = 0; in ata_exec_internal()
1573 qc->tf = *tf; in ata_exec_internal()
1575 memcpy(qc->cdb, cdb, ATAPI_CDB_LEN); in ata_exec_internal()
1578 if (tf->protocol == ATAPI_PROT_DMA && (dev->flags & ATA_DFLAG_DMADIR) && in ata_exec_internal()
1580 qc->tf.feature |= ATAPI_DMADIR; in ata_exec_internal()
1582 qc->flags |= ATA_QCFLAG_RESULT_TF; in ata_exec_internal()
1583 qc->dma_dir = dma_dir; in ata_exec_internal()
1587 qc->nbytes = buflen; in ata_exec_internal()
1590 qc->private_data = &wait; in ata_exec_internal()
1591 qc->complete_fn = ata_qc_complete_internal; in ata_exec_internal()
1595 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1618 * is frozen and will be cleaned up by ->post_internal_cmd(). in ata_exec_internal()
1620 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal()
1621 if (qc->flags & ATA_QCFLAG_ACTIVE) { in ata_exec_internal()
1622 qc->err_mask |= AC_ERR_TIMEOUT; in ata_exec_internal()
1627 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1630 if (ap->ops->post_internal_cmd) in ata_exec_internal()
1631 ap->ops->post_internal_cmd(qc); in ata_exec_internal()
1634 if (qc->flags & ATA_QCFLAG_EH) { in ata_exec_internal()
1635 if (qc->result_tf.status & (ATA_ERR | ATA_DF)) in ata_exec_internal()
1636 qc->err_mask |= AC_ERR_DEV; in ata_exec_internal()
1638 if (!qc->err_mask) in ata_exec_internal()
1639 qc->err_mask |= AC_ERR_OTHER; in ata_exec_internal()
1641 if (qc->err_mask & ~AC_ERR_OTHER) in ata_exec_internal()
1642 qc->err_mask &= ~AC_ERR_OTHER; in ata_exec_internal()
1643 } else if (qc->tf.command == ATA_CMD_REQ_SENSE_DATA) { in ata_exec_internal()
1644 qc->result_tf.status |= ATA_SENSE; in ata_exec_internal()
1648 spin_lock_irqsave(ap->lock, flags); in ata_exec_internal()
1650 *tf = qc->result_tf; in ata_exec_internal()
1651 err_mask = qc->err_mask; in ata_exec_internal()
1654 link->active_tag = preempted_tag; in ata_exec_internal()
1655 link->sactive = preempted_sactive; in ata_exec_internal()
1656 ap->qc_active = preempted_qc_active; in ata_exec_internal()
1657 ap->nr_active_links = preempted_nr_active_links; in ata_exec_internal()
1659 spin_unlock_irqrestore(ap->lock, flags); in ata_exec_internal()
1668 * ata_pio_need_iordy - check if iordy needed
1680 if (adev->link->ap->pflags & ATA_PFLAG_RESETTING) in ata_pio_need_iordy()
1685 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) in ata_pio_need_iordy()
1688 if (ata_id_is_cfa(adev->id) in ata_pio_need_iordy()
1689 && (adev->pio_mode == XFER_PIO_5 || adev->pio_mode == XFER_PIO_6)) in ata_pio_need_iordy()
1692 if (adev->pio_mode > XFER_PIO_2) in ata_pio_need_iordy()
1695 if (ata_id_has_iordy(adev->id)) in ata_pio_need_iordy()
1702 * ata_pio_mask_no_iordy - Return the non IORDY mask
1706 * -1 if no iordy mode is available.
1711 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ in ata_pio_mask_no_iordy()
1712 u16 pio = adev->id[ATA_ID_EIDE_PIO]; in ata_pio_mask_no_iordy()
1715 /* This is cycle times not frequency - watch the logic! */ in ata_pio_mask_no_iordy()
1716 if (pio > 240) /* PIO2 is 240nS per cycle */ in ata_pio_mask_no_iordy()
1725 * ata_do_dev_read_id - default ID read method
1743 * ata_dev_read_id - Read ID data from the specified device
1752 * for pre-ATA4 drives.
1761 * 0 on success, -errno otherwise.
1766 struct ata_port *ap = dev->link->ap; in ata_dev_read_id()
1790 rc = -ENODEV; in ata_dev_read_id()
1807 if (ap->ops->read_id) in ata_dev_read_id()
1808 err_mask = ap->ops->read_id(dev, &tf, (__le16 *)id); in ata_dev_read_id()
1815 return -ENOENT; in ata_dev_read_id()
1848 return -ENOENT; in ata_dev_read_id()
1851 rc = -EIO; in ata_dev_read_id()
1856 if (dev->quirks & ATA_QUIRK_DUMP_ID) { in ata_dev_read_id()
1872 rc = -EINVAL; in ata_dev_read_id()
1878 if (ap->host->flags & ATA_HOST_IGNORE_ATA && in ata_dev_read_id()
1882 return -ENOENT; in ata_dev_read_id()
1892 * Drive powered-up in standby mode, and requires a specific in ata_dev_read_id()
1893 * SET_FEATURES spin-up subcommand before it will accept in ata_dev_read_id()
1898 rc = -EIO; in ata_dev_read_id()
1913 * The exact sequence expected by certain pre-ATA4 drives is: in ata_dev_read_id()
1926 rc = -EIO; in ata_dev_read_id()
1931 /* current CHS translation info (id[53-58]) might be in ata_dev_read_id()
1953 if (dev->class != ATA_DEV_ATA && dev->class != ATA_DEV_ZAC) in ata_dev_power_init_tf()
1957 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; in ata_dev_power_init_tf()
1958 tf->protocol = ATA_PROT_NODATA; in ata_dev_power_init_tf()
1962 tf->command = ATA_CMD_VERIFY; in ata_dev_power_init_tf()
1963 tf->nsect = 1; in ata_dev_power_init_tf()
1964 if (dev->flags & ATA_DFLAG_LBA) { in ata_dev_power_init_tf()
1965 tf->flags |= ATA_TFLAG_LBA; in ata_dev_power_init_tf()
1966 tf->device |= ATA_LBA; in ata_dev_power_init_tf()
1969 tf->lbal = 0x1; /* sect */ in ata_dev_power_init_tf()
1972 tf->command = ATA_CMD_STANDBYNOW1; in ata_dev_power_init_tf()
1993 * Assume we are in standby mode so that we always force a in ata_dev_power_is_active()
2001 /* Active or idle */ in ata_dev_power_is_active()
2006 * ata_dev_power_set_standby - Set a device power mode to standby
2009 * Issue a STANDBY IMMEDIATE command to set a device power mode to standby.
2017 unsigned long ap_flags = dev->link->ap->flags; in ata_dev_power_set_standby()
2021 /* If the device is already sleeping or in standby, do nothing. */ in ata_dev_power_set_standby()
2022 if ((dev->flags & ATA_DFLAG_SLEEPING) || in ata_dev_power_set_standby()
2039 /* Issue STANDBY IMMEDIATE command only if supported by the device */ in ata_dev_power_set_standby()
2043 ata_dev_notice(dev, "Entering standby power mode\n"); in ata_dev_power_set_standby()
2047 ata_dev_err(dev, "STANDBY IMMEDIATE failed (err_mask=0x%x)\n", in ata_dev_power_set_standby()
2052 * ata_dev_power_set_active - Set a device power mode to active
2056 * active power mode. For a spun-down HDD (standby or idle power mode),
2076 * VERIFY command only if the drive is not already ACTIVE or IDLE. in ata_dev_power_set_active()
2090 * ata_read_log_page - read a specific log page
2108 unsigned long ap_flags = dev->link->ap->flags; in ata_read_log_page()
2113 ata_dev_dbg(dev, "read log page - log 0x%x, page 0x%x\n", log, page); in ata_read_log_page()
2124 if (ata_dma_enabled(dev) && ata_id_has_read_log_dma_ext(dev->id) && in ata_read_log_page()
2125 !(dev->quirks & ATA_QUIRK_NO_DMA_LOG)) { in ata_read_log_page()
2145 dev->quirks |= ATA_QUIRK_NO_DMA_LOG; in ata_read_log_page()
2146 if (!ata_port_is_frozen(dev->link->ap)) in ata_read_log_page()
2159 if (dev->quirks & ATA_QUIRK_NO_LOG_DIR) in ata_log_supported()
2162 if (ata_read_log_page(dev, ATA_LOG_DIRECTORY, 0, dev->sector_buf, 1)) in ata_log_supported()
2164 return get_unaligned_le16(&dev->sector_buf[log * 2]); in ata_log_supported()
2171 if (dev->quirks & ATA_QUIRK_NO_ID_DEV_LOG) in ata_identify_page_supported()
2177 * with ACS-3 (ATA version 10). Warn about the missing log in ata_identify_page_supported()
2180 if (ata_id_major_version(dev->id) >= 10) in ata_identify_page_supported()
2183 dev->quirks |= ATA_QUIRK_NO_ID_DEV_LOG; in ata_identify_page_supported()
2192 dev->sector_buf, 1); in ata_identify_page_supported()
2196 for (i = 0; i < dev->sector_buf[8]; i++) { in ata_identify_page_supported()
2197 if (dev->sector_buf[9 + i] == page) in ata_identify_page_supported()
2212 if (dev->quirks & ATA_QUIRK_1_5_GBPS) in ata_do_link_spd_quirk()
2217 target_limit = (1 << target) - 1; in ata_do_link_spd_quirk()
2220 if (plink->sata_spd_limit <= target_limit) in ata_do_link_spd_quirk()
2223 plink->sata_spd_limit = target_limit; in ata_do_link_spd_quirk()
2225 /* Request another EH round by returning -EAGAIN if link is in ata_do_link_spd_quirk()
2229 if (plink->sata_spd > target) { in ata_do_link_spd_quirk()
2232 return -EAGAIN; in ata_do_link_spd_quirk()
2239 struct ata_port *ap = dev->link->ap; in ata_dev_knobble()
2244 return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id))); in ata_dev_knobble()
2256 0, dev->sector_buf, 1); in ata_dev_config_ncq_send_recv()
2258 u8 *cmds = dev->ncq_send_recv_cmds; in ata_dev_config_ncq_send_recv()
2260 dev->flags |= ATA_DFLAG_NCQ_SEND_RECV; in ata_dev_config_ncq_send_recv()
2261 memcpy(cmds, dev->sector_buf, ATA_LOG_NCQ_SEND_RECV_SIZE); in ata_dev_config_ncq_send_recv()
2263 if (dev->quirks & ATA_QUIRK_NO_NCQ_TRIM) { in ata_dev_config_ncq_send_recv()
2277 "NCQ Non-Data Log not supported\n"); in ata_dev_config_ncq_non_data()
2281 0, dev->sector_buf, 1); in ata_dev_config_ncq_non_data()
2283 memcpy(dev->ncq_non_data_cmds, dev->sector_buf, in ata_dev_config_ncq_non_data()
2297 dev->sector_buf, 1); in ata_dev_config_ncq_prio()
2301 if (!(dev->sector_buf[ATA_LOG_NCQ_PRIO_OFFSET] & BIT(3))) in ata_dev_config_ncq_prio()
2304 dev->flags |= ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2309 dev->flags &= ~ATA_DFLAG_NCQ_PRIO_ENABLED; in ata_dev_config_ncq_prio()
2310 dev->flags &= ~ATA_DFLAG_NCQ_PRIO; in ata_dev_config_ncq_prio()
2319 for (parent_dev = dev->tdev.parent; parent_dev != NULL; in ata_dev_check_adapter()
2320 parent_dev = parent_dev->parent) { in ata_dev_check_adapter()
2323 if (pcidev->vendor == vendor_id) in ata_dev_check_adapter()
2335 struct ata_port *ap = dev->link->ap; in ata_dev_config_ncq()
2336 int hdepth = 0, ddepth = ata_id_queue_depth(dev->id); in ata_dev_config_ncq()
2340 if (!ata_id_has_ncq(dev->id)) { in ata_dev_config_ncq()
2346 if (dev->quirks & ATA_QUIRK_NONCQ) { in ata_dev_config_ncq()
2351 if (dev->quirks & ATA_QUIRK_NO_NCQ_ON_ATI && in ata_dev_config_ncq()
2357 if (ap->flags & ATA_FLAG_NCQ) { in ata_dev_config_ncq()
2358 hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE); in ata_dev_config_ncq()
2359 dev->flags |= ATA_DFLAG_NCQ; in ata_dev_config_ncq()
2362 if (!(dev->quirks & ATA_QUIRK_BROKEN_FPDMA_AA) && in ata_dev_config_ncq()
2363 (ap->flags & ATA_FLAG_FPDMA_AA) && in ata_dev_config_ncq()
2364 ata_id_has_fpdma_aa(dev->id)) { in ata_dev_config_ncq()
2372 dev->quirks |= ATA_QUIRK_BROKEN_FPDMA_AA; in ata_dev_config_ncq()
2373 return -EIO; in ata_dev_config_ncq()
2385 if ((ap->flags & ATA_FLAG_FPDMA_AUX)) { in ata_dev_config_ncq()
2386 if (ata_id_has_ncq_send_and_recv(dev->id)) in ata_dev_config_ncq()
2388 if (ata_id_has_ncq_non_data(dev->id)) in ata_dev_config_ncq()
2390 if (ata_id_has_ncq_prio(dev->id)) in ata_dev_config_ncq()
2401 if (!ata_id_has_sense_reporting(dev->id)) in ata_dev_config_sense_reporting()
2404 if (ata_id_sense_reporting_enabled(dev->id)) in ata_dev_config_sense_reporting()
2418 u8 *identify_buf = dev->sector_buf; in ata_dev_config_zac()
2420 dev->zac_zones_optimal_open = U32_MAX; in ata_dev_config_zac()
2421 dev->zac_zones_optimal_nonseq = U32_MAX; in ata_dev_config_zac()
2422 dev->zac_zones_max_open = U32_MAX; in ata_dev_config_zac()
2425 * Always set the 'ZAC' flag for Host-managed devices. in ata_dev_config_zac()
2427 if (dev->class == ATA_DEV_ZAC) in ata_dev_config_zac()
2428 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2429 else if (ata_id_zoned_cap(dev->id) == 0x01) in ata_dev_config_zac()
2431 * Check for host-aware devices. in ata_dev_config_zac()
2433 dev->flags |= ATA_DFLAG_ZAC; in ata_dev_config_zac()
2435 if (!(dev->flags & ATA_DFLAG_ZAC)) in ata_dev_config_zac()
2445 * Read IDENTIFY DEVICE data log, page 9 (Zoned-device information) in ata_dev_config_zac()
2455 dev->zac_zoned_cap = (zoned_cap & 1); in ata_dev_config_zac()
2458 dev->zac_zones_optimal_open = (u32)opt_open; in ata_dev_config_zac()
2461 dev->zac_zones_optimal_nonseq = (u32)opt_nonseq; in ata_dev_config_zac()
2464 dev->zac_zones_max_open = (u32)max_open; in ata_dev_config_zac()
2473 if (!ata_id_has_trusted(dev->id)) in ata_dev_config_trusted()
2483 dev->sector_buf, 1); in ata_dev_config_trusted()
2487 trusted_cap = get_unaligned_le64(&dev->sector_buf[40]); in ata_dev_config_trusted()
2495 dev->flags |= ATA_DFLAG_TRUSTED; in ata_dev_config_trusted()
2500 kfree(dev->cdl); in ata_dev_cleanup_cdl_resources()
2501 dev->cdl = NULL; in ata_dev_cleanup_cdl_resources()
2506 struct ata_cdl *cdl = dev->cdl; in ata_dev_init_cdl_resources()
2512 return -ENOMEM; in ata_dev_init_cdl_resources()
2513 dev->cdl = cdl; in ata_dev_init_cdl_resources()
2516 err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, cdl->desc_log_buf, in ata_dev_init_cdl_resources()
2521 return -EIO; in ata_dev_init_cdl_resources()
2534 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cdl()
2544 dev->sector_buf, 1); in ata_dev_config_cdl()
2549 val = get_unaligned_le64(&dev->sector_buf[168]); in ata_dev_config_cdl()
2562 val = get_unaligned_le64(&dev->sector_buf[8]); in ata_dev_config_cdl()
2570 if (!ata_id_has_ncq_autosense(dev->id)) { in ata_dev_config_cdl()
2582 dev->sector_buf, 1); in ata_dev_config_cdl()
2586 val = get_unaligned_le64(&dev->sector_buf[8]); in ata_dev_config_cdl()
2588 if (dev->flags & ATA_DFLAG_CDL_ENABLED) { in ata_dev_config_cdl()
2634 dev->flags |= ATA_DFLAG_CDL; in ata_dev_config_cdl()
2639 dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); in ata_dev_config_cdl()
2645 const u16 *id = dev->id; in ata_dev_config_lba()
2650 dev->flags |= ATA_DFLAG_LBA; in ata_dev_config_lba()
2654 dev->flags |= ATA_DFLAG_LBA48; in ata_dev_config_lba()
2655 if (dev->n_sectors >= (1UL << 28) && in ata_dev_config_lba()
2657 dev->flags |= ATA_DFLAG_FLUSH_EXT; in ata_dev_config_lba()
2669 (unsigned long long)dev->n_sectors, in ata_dev_config_lba()
2670 dev->multi_count, lba_desc, ncq_desc); in ata_dev_config_lba()
2677 const u16 *id = dev->id; in ata_dev_config_chs()
2681 dev->cylinders = id[54]; in ata_dev_config_chs()
2682 dev->heads = id[55]; in ata_dev_config_chs()
2683 dev->sectors = id[56]; in ata_dev_config_chs()
2686 dev->cylinders = id[1]; in ata_dev_config_chs()
2687 dev->heads = id[3]; in ata_dev_config_chs()
2688 dev->sectors = id[6]; in ata_dev_config_chs()
2695 (unsigned long long)dev->n_sectors, in ata_dev_config_chs()
2696 dev->multi_count, dev->cylinders, in ata_dev_config_chs()
2697 dev->heads, dev->sectors); in ata_dev_config_chs()
2707 if (!(dev->flags & ATA_DFLAG_LBA48) || !ata_id_has_fua(dev->id)) in ata_dev_config_fua()
2711 if (!ata_ncq_supported(dev) || (dev->quirks & ATA_QUIRK_NO_FUA)) in ata_dev_config_fua()
2714 dev->flags |= ATA_DFLAG_FUA; in ata_dev_config_fua()
2719 dev->flags &= ~ATA_DFLAG_FUA; in ata_dev_config_fua()
2724 u8 *sata_setting = dev->sector_buf; in ata_dev_config_devslp()
2732 if (!ata_id_has_devslp(dev->id) || in ata_dev_config_devslp()
2743 dev->flags |= ATA_DFLAG_DEVSLP; in ata_dev_config_devslp()
2746 dev->devslp_timing[i] = sata_setting[j]; in ata_dev_config_devslp()
2758 if (ata_id_major_version(dev->id) < 11) in ata_dev_config_cpr()
2789 cpr_log->nr_cpr = nr_cpr; in ata_dev_config_cpr()
2792 cpr_log->cpr[i].num = desc[0]; in ata_dev_config_cpr()
2793 cpr_log->cpr[i].num_storage_elements = desc[1]; in ata_dev_config_cpr()
2794 cpr_log->cpr[i].start_lba = get_unaligned_le64(&desc[8]); in ata_dev_config_cpr()
2795 cpr_log->cpr[i].num_lbas = get_unaligned_le64(&desc[16]); in ata_dev_config_cpr()
2799 swap(dev->cpr_log, cpr_log); in ata_dev_config_cpr()
2806 if (!(dev->flags & ATA_DFLAG_FEATURES_MASK)) in ata_dev_print_features()
2811 dev->flags & ATA_DFLAG_FUA ? " FUA" : "", in ata_dev_print_features()
2812 dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", in ata_dev_print_features()
2813 dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", in ata_dev_print_features()
2814 dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", in ata_dev_print_features()
2815 dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", in ata_dev_print_features()
2816 dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "", in ata_dev_print_features()
2817 dev->flags & ATA_DFLAG_CDL ? " CDL" : "", in ata_dev_print_features()
2818 dev->cpr_log ? " CPR" : ""); in ata_dev_print_features()
2822 * ata_dev_configure - Configure the specified ATA/ATAPI device
2825 * Configure @dev according to @dev->id. Generic and low-level
2832 * 0 on success, -errno otherwise
2836 struct ata_port *ap = dev->link->ap; in ata_dev_configure()
2838 const u16 *id = dev->id; in ata_dev_configure()
2841 char revbuf[7]; /* XYZ-99\0 */ in ata_dev_configure()
2852 dev->quirks |= ata_dev_quirks(dev); in ata_dev_configure()
2855 if (dev->quirks & ATA_QUIRK_DISABLE) { in ata_dev_configure()
2861 if ((!atapi_enabled || (ap->flags & ATA_FLAG_NO_ATAPI)) && in ata_dev_configure()
2862 dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
2874 /* some WD SATA-1 drives have issues with LPM, turn on NOLPM for them */ in ata_dev_configure()
2875 if ((dev->quirks & ATA_QUIRK_WD_BROKEN_LPM) && in ata_dev_configure()
2877 dev->quirks |= ATA_QUIRK_NOLPM; in ata_dev_configure()
2879 if (dev->quirks & ATA_QUIRK_NO_LPM_ON_ATI && in ata_dev_configure()
2881 dev->quirks |= ATA_QUIRK_NOLPM; in ata_dev_configure()
2883 if (ap->flags & ATA_FLAG_NO_LPM) in ata_dev_configure()
2884 dev->quirks |= ATA_QUIRK_NOLPM; in ata_dev_configure()
2886 if (dev->quirks & ATA_QUIRK_NOLPM) { in ata_dev_configure()
2888 dev->link->ap->target_lpm_policy = ATA_LPM_MAX_POWER; in ata_dev_configure()
2909 /* initialize to-be-configured parameters */ in ata_dev_configure()
2910 dev->flags &= ~ATA_DFLAG_CFG_MASK; in ata_dev_configure()
2911 dev->max_sectors = 0; in ata_dev_configure()
2912 dev->cdb_len = 0; in ata_dev_configure()
2913 dev->n_sectors = 0; in ata_dev_configure()
2914 dev->cylinders = 0; in ata_dev_configure()
2915 dev->heads = 0; in ata_dev_configure()
2916 dev->sectors = 0; in ata_dev_configure()
2917 dev->multi_count = 0; in ata_dev_configure()
2928 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ in ata_dev_configure()
2929 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, in ata_dev_configure()
2932 ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD, in ata_dev_configure()
2935 /* ATA-specific feature tests */ in ata_dev_configure()
2936 if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) { in ata_dev_configure()
2944 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); in ata_dev_configure()
2951 dev->n_sectors = ata_id_n_sectors(id); in ata_dev_configure()
2954 if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) { in ata_dev_configure()
2955 unsigned int max = dev->id[47] & 0xff; in ata_dev_configure()
2956 unsigned int cnt = dev->id[59] & 0xff; in ata_dev_configure()
2960 dev->multi_count = cnt; in ata_dev_configure()
2984 dev->cdb_len = 32; in ata_dev_configure()
2990 /* ATAPI-specific feature tests */ in ata_dev_configure()
2991 else if (dev->class == ATA_DEV_ATAPI) { in ata_dev_configure()
3000 rc = -EINVAL; in ata_dev_configure()
3003 dev->cdb_len = (unsigned int) rc; in ata_dev_configure()
3011 (ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) && in ata_dev_configure()
3013 sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) { in ata_dev_configure()
3022 dev->flags |= ATA_DFLAG_AN; in ata_dev_configure()
3027 if (ata_id_cdb_intr(dev->id)) { in ata_dev_configure()
3028 dev->flags |= ATA_DFLAG_CDB_INTR; in ata_dev_configure()
3032 if (atapi_dmadir || (dev->quirks & ATA_QUIRK_ATAPI_DMADIR) || in ata_dev_configure()
3033 atapi_id_dmadir(dev->id)) { in ata_dev_configure()
3034 dev->flags |= ATA_DFLAG_DMADIR; in ata_dev_configure()
3038 if (ata_id_has_da(dev->id)) { in ata_dev_configure()
3039 dev->flags |= ATA_DFLAG_DA; in ata_dev_configure()
3054 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3055 if (dev->flags & ATA_DFLAG_LBA48) in ata_dev_configure()
3056 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3063 dev->udma_mask &= ATA_UDMA5; in ata_dev_configure()
3064 dev->max_sectors = ATA_MAX_SECTORS; in ata_dev_configure()
3067 if ((dev->class == ATA_DEV_ATAPI) && in ata_dev_configure()
3069 dev->max_sectors = ATA_MAX_SECTORS_TAPE; in ata_dev_configure()
3070 dev->quirks |= ATA_QUIRK_STUCK_ERR; in ata_dev_configure()
3073 if (dev->quirks & ATA_QUIRK_MAX_SEC_128) in ata_dev_configure()
3074 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, in ata_dev_configure()
3075 dev->max_sectors); in ata_dev_configure()
3077 if (dev->quirks & ATA_QUIRK_MAX_SEC_1024) in ata_dev_configure()
3078 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_1024, in ata_dev_configure()
3079 dev->max_sectors); in ata_dev_configure()
3081 if (dev->quirks & ATA_QUIRK_MAX_SEC_LBA48) in ata_dev_configure()
3082 dev->max_sectors = ATA_MAX_SECTORS_LBA48; in ata_dev_configure()
3084 if (ap->ops->dev_config) in ata_dev_configure()
3085 ap->ops->dev_config(dev); in ata_dev_configure()
3087 if (dev->quirks & ATA_QUIRK_DIAGNOSTIC) { in ata_dev_configure()
3102 if ((dev->quirks & ATA_QUIRK_FIRMWARE_WARN) && print_info) { in ata_dev_configure()
3114 * ata_cable_40wire - return 40 wire cable type
3128 * ata_cable_80wire - return 80 wire cable type
3142 * ata_cable_unknown - return unknown PATA cable.
3155 * ata_cable_ignore - return ignored PATA cable.
3168 * ata_cable_sata - return SATA cable type
3181 * sata_print_link_status - Print SATA link status
3209 * ata_dev_pair - return other device on cable
3218 struct ata_link *link = adev->link; in ata_dev_pair()
3219 struct ata_device *pair = &link->device[1 - adev->devno]; in ata_dev_pair()
3228 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration
3230 * @cycle: cycle duration in ns
3249 for (ent = ata_xfer_tbl; ent->shift >= 0; ent++) in ata_timing_cycle2mode()
3250 if (ent->shift == xfer_shift) in ata_timing_cycle2mode()
3251 base_mode = ent->base; in ata_timing_cycle2mode()
3254 t && ata_xfer_mode2shift(t->mode) == xfer_shift; t++) { in ata_timing_cycle2mode()
3260 this_cycle = t->cycle; in ata_timing_cycle2mode()
3263 this_cycle = t->udma; in ata_timing_cycle2mode()
3272 last_mode = t->mode; in ata_timing_cycle2mode()
3280 * ata_down_xfermask_limit - adjust dev xfer masks downward
3304 xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask, in ata_down_xfermask_limit()
3305 dev->mwdma_mask, in ata_down_xfermask_limit()
3306 dev->udma_mask); in ata_down_xfermask_limit()
3311 highbit = fls(pio_mask) - 1; in ata_down_xfermask_limit()
3317 highbit = fls(udma_mask) - 1; in ata_down_xfermask_limit()
3320 return -ENOENT; in ata_down_xfermask_limit()
3322 highbit = fls(mwdma_mask) - 1; in ata_down_xfermask_limit()
3325 return -ENOENT; in ata_down_xfermask_limit()
3348 return -ENOENT; in ata_down_xfermask_limit()
3362 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, in ata_down_xfermask_limit()
3363 &dev->udma_mask); in ata_down_xfermask_limit()
3370 struct ata_port *ap = dev->link->ap; in ata_dev_set_mode()
3371 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_set_mode()
3372 const bool nosetxfer = dev->quirks & ATA_QUIRK_NOSETXFER; in ata_dev_set_mode()
3378 dev->flags &= ~ATA_DFLAG_PIO; in ata_dev_set_mode()
3379 if (dev->xfer_shift == ATA_SHIFT_PIO) in ata_dev_set_mode()
3380 dev->flags |= ATA_DFLAG_PIO; in ata_dev_set_mode()
3382 if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id)) in ata_dev_set_mode()
3387 "NOSETXFER but PATA detected - can't " in ata_dev_set_mode()
3396 ehc->i.flags |= ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3398 ehc->i.flags &= ~ATA_EHI_POST_SETMODE; in ata_dev_set_mode()
3402 if (dev->xfer_shift == ATA_SHIFT_PIO) { in ata_dev_set_mode()
3404 if (ata_id_is_cfa(dev->id)) in ata_dev_set_mode()
3408 if (ata_id_major_version(dev->id) == 0 && in ata_dev_set_mode()
3409 dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3412 any kind of SET_XFERMODE request but support PIO0-2 in ata_dev_set_mode()
3414 if (!ata_id_has_iordy(dev->id) && dev->pio_mode <= XFER_PIO_2) in ata_dev_set_mode()
3419 if (dev->xfer_shift == ATA_SHIFT_MWDMA && in ata_dev_set_mode()
3420 dev->dma_mode == XFER_MW_DMA_0 && in ata_dev_set_mode()
3421 (dev->id[63] >> 8) & 1) in ata_dev_set_mode()
3425 if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id))) in ata_dev_set_mode()
3436 dev->xfer_shift, (int)dev->xfer_mode); in ata_dev_set_mode()
3438 if (!(ehc->i.flags & ATA_EHI_QUIET) || in ata_dev_set_mode()
3439 ehc->i.flags & ATA_EHI_DID_HARDRESET) in ata_dev_set_mode()
3441 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)), in ata_dev_set_mode()
3448 return -EIO; in ata_dev_set_mode()
3452 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
3470 struct ata_port *ap = link->ap; in ata_do_set_mode()
3480 if (dev->class == ATA_DEV_ATAPI) in ata_do_set_mode()
3482 else if (ata_id_is_cfa(dev->id)) in ata_do_set_mode()
3488 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0); in ata_do_set_mode()
3491 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, in ata_do_set_mode()
3492 dev->udma_mask); in ata_do_set_mode()
3496 dev->pio_mode = ata_xfer_mask2mode(pio_mask); in ata_do_set_mode()
3497 dev->dma_mode = ata_xfer_mask2mode(dma_mask); in ata_do_set_mode()
3508 if (dev->pio_mode == 0xff) { in ata_do_set_mode()
3510 rc = -EINVAL; in ata_do_set_mode()
3514 dev->xfer_mode = dev->pio_mode; in ata_do_set_mode()
3515 dev->xfer_shift = ATA_SHIFT_PIO; in ata_do_set_mode()
3516 if (ap->ops->set_piomode) in ata_do_set_mode()
3517 ap->ops->set_piomode(ap, dev); in ata_do_set_mode()
3525 dev->xfer_mode = dev->dma_mode; in ata_do_set_mode()
3526 dev->xfer_shift = ata_xfer_mode2shift(dev->dma_mode); in ata_do_set_mode()
3527 if (ap->ops->set_dmamode) in ata_do_set_mode()
3528 ap->ops->set_dmamode(ap, dev); in ata_do_set_mode()
3541 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) in ata_do_set_mode()
3542 ap->host->simplex_claimed = ap; in ata_do_set_mode()
3552 * ata_wait_ready - wait for link to become ready
3558 * positive number if @link is ready, 0 if it isn't, -ENODEV if
3562 * Transient -ENODEV conditions are allowed for
3569 * 0 if @link is ready before @deadline; otherwise, -errno.
3579 if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN) in ata_wait_ready()
3588 WARN_ON(link == link->ap->slave_link); in ata_wait_ready()
3602 * -ENODEV could be transient. Ignore -ENODEV if link in ata_wait_ready()
3605 * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't in ata_wait_ready()
3612 if (ready == -ENODEV) { in ata_wait_ready()
3615 else if ((link->ap->flags & ATA_FLAG_SATA) && in ata_wait_ready()
3624 return -EBUSY; in ata_wait_ready()
3627 (deadline - now > 3 * HZ)) { in ata_wait_ready()
3634 ata_msleep(link->ap, 50); in ata_wait_ready()
3639 * ata_wait_after_reset - wait for link to become ready after reset
3650 * 0 if @link is ready before @deadline; otherwise, -errno.
3655 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET); in ata_wait_after_reset()
3662 * ata_std_prereset - prepare for reset
3668 * that port, so prereset should be best-effort. It does its
3680 struct ata_port *ap = link->ap; in ata_std_prereset()
3681 struct ata_eh_context *ehc = &link->eh_context; in ata_std_prereset()
3686 if (ehc->i.action & ATA_EH_HARDRESET) in ata_std_prereset()
3690 if (ap->flags & ATA_FLAG_SATA) { in ata_std_prereset()
3693 if (rc && rc != -EOPNOTSUPP) in ata_std_prereset()
3701 ehc->i.action &= ~ATA_EH_SOFTRESET; in ata_std_prereset()
3708 * ata_std_postreset - standard postreset callback
3733 * ata_dev_same_device - Determine whether new ID matches configured device
3751 const u16 *old_id = dev->id; in ata_dev_same_device()
3755 if (dev->class != new_class) { in ata_dev_same_device()
3757 dev->class, new_class); in ata_dev_same_device()
3782 * ata_dev_reread_id - Re-read IDENTIFY data
3786 * Re-read IDENTIFY page and make sure @dev is still attached to
3797 unsigned int class = dev->class; in ata_dev_reread_id()
3798 u16 *id = (void *)dev->sector_buf; in ata_dev_reread_id()
3808 return -ENODEV; in ata_dev_reread_id()
3810 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); in ata_dev_reread_id()
3815 * ata_dev_revalidate - Revalidate ATA device
3820 * Re-read IDENTIFY page, make sure @dev is still attached to the
3832 u64 n_sectors = dev->n_sectors; in ata_dev_revalidate()
3833 u64 n_native_sectors = dev->n_native_sectors; in ata_dev_revalidate()
3837 return -ENODEV; in ata_dev_revalidate()
3842 dev->class, new_class); in ata_dev_revalidate()
3843 rc = -ENODEV; in ata_dev_revalidate()
3847 /* re-read ID */ in ata_dev_revalidate()
3858 if (dev->class != ATA_DEV_ATA || !n_sectors || in ata_dev_revalidate()
3859 dev->n_sectors == n_sectors) in ata_dev_revalidate()
3865 (unsigned long long)dev->n_sectors); in ata_dev_revalidate()
3872 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3873 dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) { in ata_dev_revalidate()
3887 if (dev->n_native_sectors == n_native_sectors && in ata_dev_revalidate()
3888 dev->n_sectors < n_sectors && n_sectors == n_native_sectors && in ata_dev_revalidate()
3889 !(dev->quirks & ATA_QUIRK_BROKEN_HPA)) { in ata_dev_revalidate()
3894 dev->flags |= ATA_DFLAG_UNLOCK_HPA; in ata_dev_revalidate()
3895 rc = -EIO; in ata_dev_revalidate()
3897 rc = -ENODEV; in ata_dev_revalidate()
3900 dev->n_native_sectors = n_native_sectors; in ata_dev_revalidate()
3901 dev->n_sectors = n_sectors; in ata_dev_revalidate()
3945 struct ata_eh_context *ehc = &dev->link->eh_context; in ata_dev_print_quirks()
3950 if (!ata_dev_print_info(dev) || ehc->i.flags & ATA_EHI_DID_PRINT_QUIRKS) in ata_dev_print_quirks()
3953 ehc->i.flags |= ATA_EHI_DID_PRINT_QUIRKS; in ata_dev_print_quirks()
3968 n += snprintf(str + n, sz - n, in ata_dev_print_quirks()
3992 { "Compaq CRD-8241B", NULL, ATA_QUIRK_NODMA },
3993 { "CRD-8400B", NULL, ATA_QUIRK_NODMA },
3994 { "CRD-848[02]B", NULL, ATA_QUIRK_NODMA },
3995 { "CRD-84", NULL, ATA_QUIRK_NODMA },
3997 { "SanDisk SDP3B-64", NULL, ATA_QUIRK_NODMA },
3998 { "SANYO CD-ROM CRD", NULL, ATA_QUIRK_NODMA },
3999 { "HITACHI CDR-8", NULL, ATA_QUIRK_NODMA },
4000 { "HITACHI CDR-8[34]35", NULL, ATA_QUIRK_NODMA },
4001 { "Toshiba CD-ROM XM-6202B", NULL, ATA_QUIRK_NODMA },
4002 { "TOSHIBA CD-ROM XM-1702BC", NULL, ATA_QUIRK_NODMA },
4003 { "CD-532E-A", NULL, ATA_QUIRK_NODMA },
4004 { "E-IDE CD-ROM CR-840", NULL, ATA_QUIRK_NODMA },
4005 { "CD-ROM Drive/F5A", NULL, ATA_QUIRK_NODMA },
4006 { "WPI CDD-820", NULL, ATA_QUIRK_NODMA },
4007 { "SAMSUNG CD-ROM SC-148C", NULL, ATA_QUIRK_NODMA },
4008 { "SAMSUNG CD-ROM SC", NULL, ATA_QUIRK_NODMA },
4009 { "ATAPI CD-ROM DRIVE 40X MAXIMUM", NULL, ATA_QUIRK_NODMA },
4011 { "SAMSUNG CD-ROM SN-124", "N001", ATA_QUIRK_NODMA },
4014 { "VRFDFC22048UCHC-TE*", NULL, ATA_QUIRK_NODMA },
4018 { "ASMT109x- Config", NULL, ATA_QUIRK_DISABLE },
4021 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_QUIRK_MAX_SEC_128 },
4022 { "QUANTUM DAT DAT72-000", NULL, ATA_QUIRK_ATAPI_MOD16_DMA },
4036 { "LITEON CX1-JB*-HP", NULL, ATA_QUIRK_MAX_SEC_1024 },
4037 { "LITEON EP1-*", NULL, ATA_QUIRK_MAX_SEC_1024 },
4043 { "WDC WD740ADFD-00", NULL, ATA_QUIRK_NONCQ },
4044 { "WDC WD740ADFD-00NLR1", NULL, ATA_QUIRK_NONCQ },
4055 { "ST31500341AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4058 { "ST31000333AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4061 { "ST3640[36]23AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4064 { "ST3320[68]13AS", "SD1[5-9]", ATA_QUIRK_NONCQ |
4069 { "ST1000LM024 HN-M101MBB", NULL, ATA_QUIRK_BROKEN_FPDMA_AA |
4074 Windows driver .inf file - also several Linux problem reports */
4080 { "C300-CTFDDAC128MAG", "0001", ATA_QUIRK_NONCQ },
4087 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_QUIRK_BROKEN_HPA },
4088 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_QUIRK_BROKEN_HPA },
4092 { "OCZ-VERTEX", "1.30", ATA_QUIRK_BROKEN_HPA },
4102 { "TSSTcorp CDDVDW SH-S202[HJN]", "SB0[01]", ATA_QUIRK_IVB },
4105 { "MTRON MSP-SATA*", NULL, ATA_QUIRK_BRIDGE_OK },
4106 { "BUFFALO HD-QSU2/R5", NULL, ATA_QUIRK_BRIDGE_OK },
4116 { "PIONEER DVD-RW DVRTD08", NULL, ATA_QUIRK_NOSETXFER },
4117 { "PIONEER DVD-RW DVRTD08A", NULL, ATA_QUIRK_NOSETXFER },
4118 { "PIONEER DVD-RW DVR-215", NULL, ATA_QUIRK_NOSETXFER },
4119 { "PIONEER DVD-RW DVR-212D", NULL, ATA_QUIRK_NOSETXFER },
4120 { "PIONEER DVD-RW DVR-216D", NULL, ATA_QUIRK_NOSETXFER },
4123 { "PIONEER BD-RW BDR-207M", NULL, ATA_QUIRK_NOLPM },
4124 { "PIONEER BD-RW BDR-205", NULL, ATA_QUIRK_NOLPM },
4151 /* These specific Samsung models/firmware-revs do not handle LPM well */
4152 { "SAMSUNG MZMPC128HBFU-000MV", "CXM14M1Q", ATA_QUIRK_NOLPM },
4154 { "SAMSUNG MZ7TD256HAFV-000L9", NULL, ATA_QUIRK_NOLPM },
4155 { "SAMSUNG MZ7TE512HMHP-000L1", "EXT06L0Q", ATA_QUIRK_NOLPM },
4226 * Some WD SATA-I drives spin up and down erratically when the link
4229 * known prefixes and is SATA-1. As a side effect LPM partial is
4234 { "WDC WD800JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4235 { "WDC WD1200JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4236 { "WDC WD1600JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4237 { "WDC WD2000JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4238 { "WDC WD2500JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4239 { "WDC WD3000JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4240 { "WDC WD3200JD-*", NULL, ATA_QUIRK_WD_BROKEN_LPM },
4247 { "SATADOM-ML 3ME", NULL, ATA_QUIRK_NO_LOG_DIR },
4252 { "OCZ-VERTEX*", NULL, ATA_QUIRK_NO_FUA },
4265 /* dev->quirks is an unsigned int. */ in ata_dev_quirks()
4268 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); in ata_dev_quirks()
4269 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); in ata_dev_quirks()
4271 while (ad->model_num) { in ata_dev_quirks()
4272 if (glob_match(ad->model_num, model_num) && in ata_dev_quirks()
4273 (!ad->model_rev || glob_match(ad->model_rev, model_rev))) { in ata_dev_quirks()
4275 ad->quirks); in ata_dev_quirks()
4276 return ad->quirks; in ata_dev_quirks()
4287 * with CDB-intr (and use PIO) if the LLDD handles only interrupts in in ata_dev_nodma()
4290 if ((dev->link->ap->flags & ATA_FLAG_PIO_POLLING) && in ata_dev_nodma()
4291 (dev->flags & ATA_DFLAG_CDB_INTR)) in ata_dev_nodma()
4293 return dev->quirks & ATA_QUIRK_NODMA; in ata_dev_nodma()
4297 * ata_is_40wire - check drive side detection
4306 if (dev->quirks & ATA_QUIRK_IVB) in ata_is_40wire()
4307 return ata_drive_40wire_relaxed(dev->id); in ata_is_40wire()
4308 return ata_drive_40wire(dev->id); in ata_is_40wire()
4312 * cable_is_40wire - 40/80/SATA decider
4317 * there is a good case for setting ap->cbl to the result when
4330 if (ap->cbl == ATA_CBL_PATA40) in cable_is_40wire()
4334 if (ap->cbl == ATA_CBL_PATA80 || ap->cbl == ATA_CBL_SATA) in cable_is_40wire()
4341 if (ap->cbl == ATA_CBL_PATA40_SHORT) in cable_is_40wire()
4348 * - in many setups only the one drive (slave if present) will in cable_is_40wire()
4350 * - if you have a non detect capable drive you don't want it in cable_is_40wire()
4363 * ata_dev_xfermask - Compute supported xfermask of the given device
4367 * dev->*_mask. This function is responsible for applying all
4375 struct ata_link *link = dev->link; in ata_dev_xfermask()
4376 struct ata_port *ap = link->ap; in ata_dev_xfermask()
4377 struct ata_host *host = ap->host; in ata_dev_xfermask()
4381 xfer_mask = ata_pack_xfermask(ap->pio_mask, in ata_dev_xfermask()
4382 ap->mwdma_mask, ap->udma_mask); in ata_dev_xfermask()
4385 xfer_mask &= ata_pack_xfermask(dev->pio_mask, in ata_dev_xfermask()
4386 dev->mwdma_mask, dev->udma_mask); in ata_dev_xfermask()
4387 xfer_mask &= ata_id_xfermask(dev->id); in ata_dev_xfermask()
4406 if ((host->flags & ATA_HOST_SIMPLEX) && in ata_dev_xfermask()
4407 host->simplex_claimed && host->simplex_claimed != ap) { in ata_dev_xfermask()
4413 if (ap->flags & ATA_FLAG_NO_IORDY) in ata_dev_xfermask()
4416 if (ap->ops->mode_filter) in ata_dev_xfermask()
4417 xfer_mask = ap->ops->mode_filter(dev, xfer_mask); in ata_dev_xfermask()
4431 "limited to UDMA/33 due to 40-wire cable\n"); in ata_dev_xfermask()
4435 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, in ata_dev_xfermask()
4436 &dev->mwdma_mask, &dev->udma_mask); in ata_dev_xfermask()
4440 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
4443 * Issue SET FEATURES - XFER MODE command to device @dev
4457 /* set up set-features taskfile */ in ata_dev_set_xfermode()
4458 ata_dev_dbg(dev, "set features - xfer mode\n"); in ata_dev_set_xfermode()
4470 tf.nsect = dev->xfer_mode; in ata_dev_set_xfermode()
4471 /* If the device has IORDY and the controller does not - turn it off */ in ata_dev_set_xfermode()
4472 else if (ata_id_has_iordy(dev->id)) in ata_dev_set_xfermode()
4474 else /* In the ancient relic department - skip all of this */ in ata_dev_set_xfermode()
4478 * On some disks, this command causes spin-up, so we need longer in ata_dev_set_xfermode()
4485 * ata_dev_set_feature - Issue SET FEATURES
4503 /* set up set-features taskfile */ in ata_dev_set_feature()
4522 * ata_dev_init_params - Issue INIT DEV PARAMS command
4539 /* Number of sectors per track 1-255. Number of heads 1-16 */ in ata_dev_init_params()
4551 tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */ in ata_dev_init_params()
4564 * atapi_check_dma - Check whether ATAPI DMA can be supported
4567 * Allow low-level driver to filter ATA PACKET commands, returning
4579 struct ata_port *ap = qc->ap; in atapi_check_dma()
4584 if (!(qc->dev->quirks & ATA_QUIRK_ATAPI_MOD16_DMA) && in atapi_check_dma()
4585 unlikely(qc->nbytes & 15)) in atapi_check_dma()
4586 return -EOPNOTSUPP; in atapi_check_dma()
4588 if (ap->ops->check_atapi_dma) in atapi_check_dma()
4589 return ap->ops->check_atapi_dma(qc); in atapi_check_dma()
4595 * ata_std_qc_defer - Check whether a qc needs to be deferred
4598 * Non-NCQ commands cannot run with any other command, NCQ or
4611 struct ata_link *link = qc->dev->link; in ata_std_qc_defer()
4613 if (ata_is_ncq(qc->tf.protocol)) { in ata_std_qc_defer()
4614 if (!ata_tag_valid(link->active_tag)) in ata_std_qc_defer()
4617 if (!ata_tag_valid(link->active_tag) && !link->sactive) in ata_std_qc_defer()
4626 * ata_sg_init - Associate command with scatter-gather table.
4628 * @sg: Scatter-gather table.
4631 * Initialize the data-related elements of queued_cmd @qc
4632 * to point to a scatter-gather table @sg, containing @n_elem
4641 qc->sg = sg; in ata_sg_init()
4642 qc->n_elem = n_elem; in ata_sg_init()
4643 qc->cursg = qc->sg; in ata_sg_init()
4649 * ata_sg_clean - Unmap DMA memory associated with command
4659 struct ata_port *ap = qc->ap; in ata_sg_clean()
4660 struct scatterlist *sg = qc->sg; in ata_sg_clean()
4661 int dir = qc->dma_dir; in ata_sg_clean()
4665 if (qc->n_elem) in ata_sg_clean()
4666 dma_unmap_sg(ap->dev, sg, qc->orig_n_elem, dir); in ata_sg_clean()
4668 qc->flags &= ~ATA_QCFLAG_DMAMAP; in ata_sg_clean()
4669 qc->sg = NULL; in ata_sg_clean()
4673 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
4674 * @qc: Command with scatter-gather table to be mapped.
4676 * DMA-map the scatter-gather table associated with queued_cmd @qc.
4687 struct ata_port *ap = qc->ap; in ata_sg_setup()
4690 n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir); in ata_sg_setup()
4692 return -1; in ata_sg_setup()
4694 qc->orig_n_elem = qc->n_elem; in ata_sg_setup()
4695 qc->n_elem = n_elem; in ata_sg_setup()
4696 qc->flags |= ATA_QCFLAG_DMAMAP; in ata_sg_setup()
4704 static inline int ata_sg_setup(struct ata_queued_cmd *qc) { return -1; } in ata_sg_setup()
4709 * swap_buf_le16 - swap halves of 16-bit words in place
4711 * @buf_words: Number of 16-bit words in buffer.
4713 * Swap halves of 16-bit words if needed to convert from
4714 * little-endian byte order to native cpu byte order, or
4715 * vice-versa.
4731 * ata_qc_free - free unused ata_queued_cmd
4742 qc->flags = 0; in ata_qc_free()
4743 if (ata_tag_valid(qc->tag)) in ata_qc_free()
4744 qc->tag = ATA_TAG_POISON; in ata_qc_free()
4752 if (WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE))) in __ata_qc_complete()
4755 ap = qc->ap; in __ata_qc_complete()
4756 link = qc->dev->link; in __ata_qc_complete()
4758 if (likely(qc->flags & ATA_QCFLAG_DMAMAP)) in __ata_qc_complete()
4762 if (ata_is_ncq(qc->tf.protocol)) { in __ata_qc_complete()
4763 link->sactive &= ~(1 << qc->hw_tag); in __ata_qc_complete()
4764 if (!link->sactive) in __ata_qc_complete()
4765 ap->nr_active_links--; in __ata_qc_complete()
4767 link->active_tag = ATA_TAG_POISON; in __ata_qc_complete()
4768 ap->nr_active_links--; in __ata_qc_complete()
4772 if (unlikely(qc->flags & ATA_QCFLAG_CLEAR_EXCL && in __ata_qc_complete()
4773 ap->excl_link == link)) in __ata_qc_complete()
4774 ap->excl_link = NULL; in __ata_qc_complete()
4781 qc->flags &= ~ATA_QCFLAG_ACTIVE; in __ata_qc_complete()
4782 ap->qc_active &= ~(1ULL << qc->tag); in __ata_qc_complete()
4785 qc->complete_fn(qc); in __ata_qc_complete()
4790 struct ata_port *ap = qc->ap; in fill_result_tf()
4796 if (qc->flags & ATA_QCFLAG_RTF_FILLED) in fill_result_tf()
4799 qc->result_tf.flags = qc->tf.flags; in fill_result_tf()
4800 ap->ops->qc_fill_rtf(qc); in fill_result_tf()
4801 qc->flags |= ATA_QCFLAG_RTF_FILLED; in fill_result_tf()
4806 struct ata_device *dev = qc->dev; in ata_verify_xfer()
4808 if (!ata_is_data(qc->tf.protocol)) in ata_verify_xfer()
4811 if ((dev->mwdma_mask || dev->udma_mask) && ata_is_pio(qc->tf.protocol)) in ata_verify_xfer()
4814 dev->flags &= ~ATA_DFLAG_DUBIOUS_XFER; in ata_verify_xfer()
4818 * ata_qc_complete - Complete an active ATA command
4822 * completed, with either an ok or not-ok status.
4834 struct ata_port *ap = qc->ap; in ata_qc_complete()
4835 struct ata_device *dev = qc->dev; in ata_qc_complete()
4836 struct ata_eh_info *ehi = &dev->link->eh_info; in ata_qc_complete()
4839 ledtrig_disk_activity(!!(qc->tf.flags & ATA_TFLAG_WRITE)); in ata_qc_complete()
4849 if (unlikely(qc->err_mask)) in ata_qc_complete()
4850 qc->flags |= ATA_QCFLAG_EH; in ata_qc_complete()
4856 if (unlikely(ata_tag_internal(qc->tag))) { in ata_qc_complete()
4863 /* Non-internal qc has failed. Fill the result TF and summon EH. */ in ata_qc_complete()
4864 if (unlikely(qc->flags & ATA_QCFLAG_EH)) { in ata_qc_complete()
4874 if (qc->flags & ATA_QCFLAG_RESULT_TF) in ata_qc_complete()
4885 if (qc->flags & ATA_QCFLAG_HAS_CDL && in ata_qc_complete()
4886 qc->result_tf.status & ATA_SENSE) { in ata_qc_complete()
4888 * Tell SCSI EH to not overwrite scmd->result even if this in ata_qc_complete()
4891 qc->scsicmd->flags |= SCMD_FORCE_EH_SUCCESS; in ata_qc_complete()
4892 qc->flags |= ATA_QCFLAG_EH_SUCCESS_CMD; in ata_qc_complete()
4893 ehi->dev_action[dev->devno] |= ATA_EH_GET_SUCCESS_SENSE; in ata_qc_complete()
4899 ap->pflags |= ATA_PFLAG_EH_PENDING; in ata_qc_complete()
4904 /* Some commands need post-processing after successful completion. */ in ata_qc_complete()
4905 switch (qc->tf.command) { in ata_qc_complete()
4907 if (qc->tf.feature != SETFEATURES_WC_ON && in ata_qc_complete()
4908 qc->tf.feature != SETFEATURES_WC_OFF && in ata_qc_complete()
4909 qc->tf.feature != SETFEATURES_RA_ON && in ata_qc_complete()
4910 qc->tf.feature != SETFEATURES_RA_OFF) in ata_qc_complete()
4916 ehi->dev_action[dev->devno] |= ATA_EH_REVALIDATE; in ata_qc_complete()
4921 dev->flags |= ATA_DFLAG_SLEEPING; in ata_qc_complete()
4925 if (unlikely(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) in ata_qc_complete()
4933 * ata_qc_get_active - get bitmask of active qcs
4944 u64 qc_active = ap->qc_active; in ata_qc_get_active()
4957 * ata_qc_issue - issue taskfile to device
4961 * This includes mapping the data into a DMA-able
4970 struct ata_port *ap = qc->ap; in ata_qc_issue()
4971 struct ata_link *link = qc->dev->link; in ata_qc_issue()
4972 u8 prot = qc->tf.protocol; in ata_qc_issue()
4974 /* Make sure only one non-NCQ command is outstanding. */ in ata_qc_issue()
4975 WARN_ON_ONCE(ata_tag_valid(link->active_tag)); in ata_qc_issue()
4978 WARN_ON_ONCE(link->sactive & (1 << qc->hw_tag)); in ata_qc_issue()
4980 if (!link->sactive) in ata_qc_issue()
4981 ap->nr_active_links++; in ata_qc_issue()
4982 link->sactive |= 1 << qc->hw_tag; in ata_qc_issue()
4984 WARN_ON_ONCE(link->sactive); in ata_qc_issue()
4986 ap->nr_active_links++; in ata_qc_issue()
4987 link->active_tag = qc->tag; in ata_qc_issue()
4990 qc->flags |= ATA_QCFLAG_ACTIVE; in ata_qc_issue()
4991 ap->qc_active |= 1ULL << qc->tag; in ata_qc_issue()
4995 * non-zero sg if the command is a data command. in ata_qc_issue()
4997 if (ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes)) in ata_qc_issue()
5001 (ap->flags & ATA_FLAG_PIO_DMA))) in ata_qc_issue()
5006 if (unlikely(qc->dev->flags & ATA_DFLAG_SLEEPING)) { in ata_qc_issue()
5007 link->eh_info.action |= ATA_EH_RESET; in ata_qc_issue()
5008 ata_ehi_push_desc(&link->eh_info, "waking up from sleep"); in ata_qc_issue()
5013 if (ap->ops->qc_prep) { in ata_qc_issue()
5015 qc->err_mask |= ap->ops->qc_prep(qc); in ata_qc_issue()
5016 if (unlikely(qc->err_mask)) in ata_qc_issue()
5021 qc->err_mask |= ap->ops->qc_issue(qc); in ata_qc_issue()
5022 if (unlikely(qc->err_mask)) in ata_qc_issue()
5027 qc->err_mask |= AC_ERR_SYSTEM; in ata_qc_issue()
5033 * ata_phys_link_online - test whether the given link is online
5057 * ata_phys_link_offline - test whether the given link is offline
5081 * ata_link_online - test whether the given link is online
5098 struct ata_link *slave = link->ap->slave_link; in ata_link_online()
5108 * ata_link_offline - test whether the given link is offline
5125 struct ata_link *slave = link->ap->slave_link; in ata_link_offline()
5142 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5148 if (ap->pflags & ATA_PFLAG_PM_PENDING) { in ata_port_request_pm()
5149 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5151 spin_lock_irqsave(ap->lock, flags); in ata_port_request_pm()
5155 ap->pm_mesg = mesg; in ata_port_request_pm()
5156 ap->pflags |= ATA_PFLAG_PM_PENDING; in ata_port_request_pm()
5158 link->eh_info.action |= action; in ata_port_request_pm()
5159 link->eh_info.flags |= ehi_flags; in ata_port_request_pm()
5164 spin_unlock_irqrestore(ap->lock, flags); in ata_port_request_pm()
5179 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_suspend()
5244 * So the idle callback here will not proceed to suspend if a non-ZPODD capable
5255 if (adev->class == ATA_DEV_ATAPI && in ata_port_runtime_idle()
5257 return -EBUSY; in ata_port_runtime_idle()
5289 * and need to resume ata devices at the domain level, not the per-port
5306 * ata_host_suspend - suspend host
5314 host->dev->power.power_state = mesg; in ata_host_suspend()
5319 * ata_host_resume - resume host
5326 host->dev->power.power_state = PMSG_ON; in ata_host_resume()
5339 * ata_dev_init - Initialize an ata_device structure
5350 struct ata_port *ap = link->ap; in ata_dev_init()
5354 link->sata_spd_limit = link->hw_sata_spd_limit; in ata_dev_init()
5355 link->sata_spd = 0; in ata_dev_init()
5357 /* High bits of dev->flags are used to record warm plug in ata_dev_init()
5361 spin_lock_irqsave(ap->lock, flags); in ata_dev_init()
5362 dev->flags &= ~ATA_DFLAG_INIT_MASK; in ata_dev_init()
5363 dev->quirks = 0; in ata_dev_init()
5364 spin_unlock_irqrestore(ap->lock, flags); in ata_dev_init()
5367 ATA_DEVICE_CLEAR_END - ATA_DEVICE_CLEAR_BEGIN); in ata_dev_init()
5368 dev->pio_mask = UINT_MAX; in ata_dev_init()
5369 dev->mwdma_mask = UINT_MAX; in ata_dev_init()
5370 dev->udma_mask = UINT_MAX; in ata_dev_init()
5374 * ata_link_init - Initialize an ata_link structure
5390 ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN); in ata_link_init()
5392 link->ap = ap; in ata_link_init()
5393 link->pmp = pmp; in ata_link_init()
5394 link->active_tag = ATA_TAG_POISON; in ata_link_init()
5395 link->hw_sata_spd_limit = UINT_MAX; in ata_link_init()
5399 struct ata_device *dev = &link->device[i]; in ata_link_init()
5401 dev->link = link; in ata_link_init()
5402 dev->devno = dev - link->device; in ata_link_init()
5404 dev->gtf_filter = ata_acpi_gtf_filter; in ata_link_init()
5411 * sata_link_init_spd - Initialize link->sata_spd_limit
5414 * Initialize ``link->[hw_]sata_spd_limit`` to the currently
5421 * 0 on success, -errno on failure.
5428 rc = sata_scr_read(link, SCR_CONTROL, &link->saved_scontrol); in sata_link_init_spd()
5432 spd = (link->saved_scontrol >> 4) & 0xf; in sata_link_init_spd()
5434 link->hw_sata_spd_limit &= (1 << spd) - 1; in sata_link_init_spd()
5438 link->sata_spd_limit = link->hw_sata_spd_limit; in sata_link_init_spd()
5444 * ata_port_alloc - allocate and initialize basic ATA port resources
5464 ap->pflags |= ATA_PFLAG_INITIALIZING | ATA_PFLAG_FROZEN; in ata_port_alloc()
5465 ap->lock = &host->lock; in ata_port_alloc()
5471 ap->print_id = id; in ata_port_alloc()
5472 ap->host = host; in ata_port_alloc()
5473 ap->dev = host->dev; in ata_port_alloc()
5475 mutex_init(&ap->scsi_scan_mutex); in ata_port_alloc()
5476 INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug); in ata_port_alloc()
5477 INIT_DELAYED_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); in ata_port_alloc()
5478 INIT_LIST_HEAD(&ap->eh_done_q); in ata_port_alloc()
5479 init_waitqueue_head(&ap->eh_wait_q); in ata_port_alloc()
5480 init_completion(&ap->park_req_pending); in ata_port_alloc()
5481 timer_setup(&ap->fastdrain_timer, ata_eh_fastdrain_timerfn, in ata_port_alloc()
5484 ap->cbl = ATA_CBL_NONE; in ata_port_alloc()
5486 ata_link_init(ap, &ap->link, 0); in ata_port_alloc()
5489 ap->stats.unhandled_irq = 1; in ata_port_alloc()
5490 ap->stats.idle_irq = 1; in ata_port_alloc()
5505 kfree(ap->pmp_link); in ata_port_free()
5506 kfree(ap->slave_link); in ata_port_free()
5507 ida_free(&ata_ida, ap->print_id); in ata_port_free()
5517 for (i = 0; i < host->n_ports; i++) { in ata_devres_release()
5518 struct ata_port *ap = host->ports[i]; in ata_devres_release()
5523 if (ap->scsi_host) in ata_devres_release()
5524 scsi_host_put(ap->scsi_host); in ata_devres_release()
5537 for (i = 0; i < host->n_ports; i++) { in ata_host_release()
5538 ata_port_free(host->ports[i]); in ata_host_release()
5539 host->ports[i] = NULL; in ata_host_release()
5546 kref_get(&host->kref); in ata_host_get()
5551 kref_put(&host->kref, ata_host_release); in ata_host_put()
5556 * ata_host_alloc - allocate and init basic ATA host resources
5597 spin_lock_init(&host->lock); in ata_host_alloc()
5598 mutex_init(&host->eh_mutex); in ata_host_alloc()
5599 host->dev = dev; in ata_host_alloc()
5600 host->n_ports = n_ports; in ata_host_alloc()
5601 kref_init(&host->kref); in ata_host_alloc()
5611 ap->port_no = i; in ata_host_alloc()
5612 host->ports[i] = ap; in ata_host_alloc()
5625 * ata_host_alloc_pinfo - alloc host and init with port_info array
5652 for (i = 0, j = 0; i < host->n_ports; i++) { in ata_host_alloc_pinfo()
5653 struct ata_port *ap = host->ports[i]; in ata_host_alloc_pinfo()
5658 ap->pio_mask = pi->pio_mask; in ata_host_alloc_pinfo()
5659 ap->mwdma_mask = pi->mwdma_mask; in ata_host_alloc_pinfo()
5660 ap->udma_mask = pi->udma_mask; in ata_host_alloc_pinfo()
5661 ap->flags |= pi->flags; in ata_host_alloc_pinfo()
5662 ap->link.flags |= pi->link_flags; in ata_host_alloc_pinfo()
5663 ap->ops = pi->port_ops; in ata_host_alloc_pinfo()
5665 if (!host->ops && (pi->port_ops != &ata_dummy_port_ops)) in ata_host_alloc_pinfo()
5666 host->ops = pi->port_ops; in ata_host_alloc_pinfo()
5678 WARN_ON(!(host->flags & ATA_HOST_STARTED)); in ata_host_stop()
5680 for (i = 0; i < host->n_ports; i++) { in ata_host_stop()
5681 struct ata_port *ap = host->ports[i]; in ata_host_stop()
5683 if (ap->ops->port_stop) in ata_host_stop()
5684 ap->ops->port_stop(ap); in ata_host_stop()
5687 if (host->ops->host_stop) in ata_host_stop()
5688 host->ops->host_stop(host); in ata_host_stop()
5692 * ata_finalize_port_ops - finalize ata_port_operations
5704 * methods and ->inherits is no longer necessary and cleared.
5716 void **end = (void **)&ops->inherits; in ata_finalize_port_ops()
5719 if (!ops || !ops->inherits) in ata_finalize_port_ops()
5724 for (cur = ops->inherits; cur; cur = cur->inherits) { in ata_finalize_port_ops()
5736 ops->inherits = NULL; in ata_finalize_port_ops()
5742 * ata_host_start - start and freeze ports of an ATA host
5746 * recorded in host->flags, so this function can be called
5748 * once. If host->ops is not initialized yet, it is set to the
5749 * first non-dummy port ops.
5755 * 0 if all ports are started successfully, -errno otherwise.
5763 if (host->flags & ATA_HOST_STARTED) in ata_host_start()
5766 ata_finalize_port_ops(host->ops); in ata_host_start()
5768 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5769 struct ata_port *ap = host->ports[i]; in ata_host_start()
5771 ata_finalize_port_ops(ap->ops); in ata_host_start()
5773 if (!host->ops && !ata_port_is_dummy(ap)) in ata_host_start()
5774 host->ops = ap->ops; in ata_host_start()
5776 if (ap->ops->port_stop) in ata_host_start()
5780 if (host->ops && host->ops->host_stop) in ata_host_start()
5786 return -ENOMEM; in ata_host_start()
5789 for (i = 0; i < host->n_ports; i++) { in ata_host_start()
5790 struct ata_port *ap = host->ports[i]; in ata_host_start()
5792 if (ap->ops->port_start) { in ata_host_start()
5793 rc = ap->ops->port_start(ap); in ata_host_start()
5795 if (rc != -ENODEV) in ata_host_start()
5796 dev_err(host->dev, in ata_host_start()
5806 devres_add(host->dev, start_dr); in ata_host_start()
5807 host->flags |= ATA_HOST_STARTED; in ata_host_start()
5811 while (--i >= 0) { in ata_host_start()
5812 struct ata_port *ap = host->ports[i]; in ata_host_start()
5814 if (ap->ops->port_stop) in ata_host_start()
5815 ap->ops->port_stop(ap); in ata_host_start()
5823 * ata_host_init - Initialize a host struct for sas (ipr, libsas)
5832 spin_lock_init(&host->lock); in ata_host_init()
5833 mutex_init(&host->eh_mutex); in ata_host_init()
5834 host->n_tags = ATA_MAX_QUEUE; in ata_host_init()
5835 host->dev = dev; in ata_host_init()
5836 host->ops = ops; in ata_host_init()
5837 kref_init(&host->kref); in ata_host_init()
5843 struct ata_eh_info *ehi = &ap->link.eh_info; in ata_port_probe()
5847 spin_lock_irqsave(ap->lock, flags); in ata_port_probe()
5849 ehi->probe_mask |= ATA_ALL_DEVICES; in ata_port_probe()
5850 ehi->action |= ATA_EH_RESET; in ata_port_probe()
5851 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; in ata_port_probe()
5853 ap->pflags &= ~ATA_PFLAG_INITIALIZING; in ata_port_probe()
5854 ap->pflags |= ATA_PFLAG_LOADING; in ata_port_probe()
5857 spin_unlock_irqrestore(ap->lock, flags); in ata_port_probe()
5872 if (!(ap->host->flags & ATA_HOST_PARALLEL_SCAN) && ap->port_no != 0) in async_port_probe()
5885 * ata_host_register - register initialized ATA host
5898 * 0 on success, -errno otherwise.
5904 host->n_tags = clamp(sht->can_queue, 1, ATA_MAX_QUEUE); in ata_host_register()
5907 if (!(host->flags & ATA_HOST_STARTED)) { in ata_host_register()
5908 dev_err(host->dev, "BUG: trying to register unstarted host\n"); in ata_host_register()
5910 return -EINVAL; in ata_host_register()
5914 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5915 rc = ata_tport_add(host->dev,host->ports[i]); in ata_host_register()
5926 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5927 struct ata_port *ap = host->ports[i]; in ata_host_register()
5931 if (ap->cbl == ATA_CBL_NONE && (ap->flags & ATA_FLAG_SATA)) in ata_host_register()
5932 ap->cbl = ATA_CBL_SATA; in ata_host_register()
5935 sata_link_init_spd(&ap->link); in ata_host_register()
5936 if (ap->slave_link) in ata_host_register()
5937 sata_link_init_spd(ap->slave_link); in ata_host_register()
5939 /* print per-port info to dmesg */ in ata_host_register()
5940 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, in ata_host_register()
5941 ap->udma_mask); in ata_host_register()
5945 (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P', in ata_host_register()
5947 ap->link.eh_info.desc); in ata_host_register()
5948 ata_ehi_clear_desc(&ap->link.eh_info); in ata_host_register()
5954 for (i = 0; i < host->n_ports; i++) { in ata_host_register()
5955 struct ata_port *ap = host->ports[i]; in ata_host_register()
5956 ap->cookie = async_schedule(async_port_probe, ap); in ata_host_register()
5962 while (--i >= 0) { in ata_host_register()
5963 ata_tport_delete(host->ports[i]); in ata_host_register()
5971 * ata_host_activate - start host, request IRQ and register it
5979 * LLDs perform three steps to activate the host - start host,
5991 * 0 on success, -errno otherwise.
6010 irq_desc = devm_kasprintf(host->dev, GFP_KERNEL, "%s[%s]", in ata_host_activate()
6011 dev_driver_string(host->dev), in ata_host_activate()
6012 dev_name(host->dev)); in ata_host_activate()
6014 return -ENOMEM; in ata_host_activate()
6016 rc = devm_request_irq(host->dev, irq, irq_handler, irq_flags, in ata_host_activate()
6021 for (i = 0; i < host->n_ports; i++) in ata_host_activate()
6022 ata_port_desc_misc(host->ports[i], irq); in ata_host_activate()
6027 devm_free_irq(host->dev, irq, host); in ata_host_activate()
6034 * ata_dev_free_resources - Free a device resources
6051 * ata_port_detach - Detach ATA port in preparation of device removal
6068 async_synchronize_cookie(ap->cookie + 1); in ata_port_detach()
6073 mutex_lock(&ap->scsi_scan_mutex); in ata_port_detach()
6074 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6079 if (dev->sdev) { in ata_port_detach()
6080 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6081 scsi_remove_device(dev->sdev); in ata_port_detach()
6082 spin_lock_irqsave(ap->lock, flags); in ata_port_detach()
6083 dev->sdev = NULL; in ata_port_detach()
6089 ap->pflags |= ATA_PFLAG_UNLOADING; in ata_port_detach()
6092 spin_unlock_irqrestore(ap->lock, flags); in ata_port_detach()
6093 mutex_unlock(&ap->scsi_scan_mutex); in ata_port_detach()
6099 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED)); in ata_port_detach()
6101 cancel_delayed_work_sync(&ap->hotplug_task); in ata_port_detach()
6102 cancel_delayed_work_sync(&ap->scsi_rescan_task); in ata_port_detach()
6105 if (ap->pmp_link) { in ata_port_detach()
6109 ata_tlink_delete(&ap->pmp_link[i]); in ata_port_detach()
6113 scsi_remove_host(ap->scsi_host); in ata_port_detach()
6118 * ata_host_detach - Detach all ports of an ATA host
6130 for (i = 0; i < host->n_ports; i++) in ata_host_detach()
6131 ata_port_detach(host->ports[i]); in ata_host_detach()
6141 * ata_pci_remove_one - PCI layer callback for device removal
6144 * PCI layer indicates to libata via this hook that hot-unplug or
6164 for (i = 0; i < host->n_ports; i++) { in ata_pci_shutdown_one()
6165 struct ata_port *ap = host->ports[i]; in ata_pci_shutdown_one()
6167 ap->pflags |= ATA_PFLAG_FROZEN; in ata_pci_shutdown_one()
6170 if (ap->ops->freeze) in ata_pci_shutdown_one()
6171 ap->ops->freeze(ap); in ata_pci_shutdown_one()
6174 if (ap->ops->port_stop) in ata_pci_shutdown_one()
6175 ap->ops->port_stop(ap); in ata_pci_shutdown_one()
6185 switch (bits->width) { in pci_test_config_bits()
6188 pci_read_config_byte(pdev, bits->reg, &tmp8); in pci_test_config_bits()
6194 pci_read_config_word(pdev, bits->reg, &tmp16); in pci_test_config_bits()
6200 pci_read_config_dword(pdev, bits->reg, &tmp32); in pci_test_config_bits()
6206 return -EINVAL; in pci_test_config_bits()
6209 tmp &= bits->mask; in pci_test_config_bits()
6211 return (tmp == bits->val) ? 1 : 0; in pci_test_config_bits()
6235 dev_err(&pdev->dev, in ata_pci_device_do_resume()
6272 * ata_platform_remove_one - Platform layer callback for device removal
6275 * Platform layer indicates to libata via this hook that hot-unplug or
6435 force_ent->device = simple_strtoul(p, &endp, 10); in ata_parse_force_one()
6438 return -EINVAL; in ata_parse_force_one()
6442 force_ent->port = simple_strtoul(id, &endp, 10); in ata_parse_force_one()
6445 return -EINVAL; in ata_parse_force_one()
6453 if (strncasecmp(val, fp->name, strlen(val))) in ata_parse_force_one()
6459 if (strcasecmp(val, fp->name) == 0) { in ata_parse_force_one()
6467 return -EINVAL; in ata_parse_force_one()
6471 return -EINVAL; in ata_parse_force_one()
6474 force_ent->param = *match_fp; in ata_parse_force_one()
6482 int last_port = -1, last_device = -1; in ata_parse_force_param()
6500 struct ata_force_ent te = { .port = -1, .device = -1 }; in ata_parse_force_param()
6510 if (te.port == -1) { in ata_parse_force_param()
6549 rc = -ENOMEM; in ata_init()
6580 * ata_msleep - ATA EH owner aware msleep
6587 * @ap->host will be allowed to own the EH while this task is
6595 bool owns_eh = ap && ap->host->eh_owner == current; in ata_msleep()
6613 * ata_wait_register - wait until register value changes
6615 * @reg: IO-mapped register
6623 * IO-mapped register @reg and tests for the following condition.