1c82ee6d3SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
3af36d7f0SJeff Garzik * Copyright 2003-2005 Red Hat, Inc. All rights reserved.
4af36d7f0SJeff Garzik * Copyright 2003-2005 Jeff Garzik
5af36d7f0SJeff Garzik *
6af36d7f0SJeff Garzik * libata documentation is available via 'make {ps|pdf}docs',
79bb9a39cSMauro Carvalho Chehab * as Documentation/driver-api/libata.rst
81da177e4SLinus Torvalds */
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds #ifndef __LINUX_LIBATA_H__
111da177e4SLinus Torvalds #define __LINUX_LIBATA_H__
121da177e4SLinus Torvalds
131da177e4SLinus Torvalds #include <linux/delay.h>
14341c2c95STejun Heo #include <linux/jiffies.h>
151da177e4SLinus Torvalds #include <linux/interrupt.h>
161c72d8d9SAndrew Morton #include <linux/dma-mapping.h>
1787260216SJens Axboe #include <linux/scatterlist.h>
18f0d36efdSTejun Heo #include <linux/io.h>
191da177e4SLinus Torvalds #include <linux/ata.h>
201da177e4SLinus Torvalds #include <linux/workqueue.h>
2135bb94b1SJeff Garzik #include <scsi/scsi_host.h>
2211ef697bSKristen Carlson Accardi #include <linux/acpi.h>
23ceb0c642STejun Heo #include <linux/cdrom.h>
24c0c362b6STejun Heo #include <linux/sched.h>
25b5292111SKai-Heng Feng #include <linux/async.h>
261da177e4SLinus Torvalds
27a6d967a4SJeff Garzik /*
28a6d967a4SJeff Garzik * Define if arch has non-standard setup. This is a _PCI_ standard
29a6d967a4SJeff Garzik * not a legacy or ISA standard.
30a6d967a4SJeff Garzik */
31a6d967a4SJeff Garzik #ifdef CONFIG_ATA_NONSTANDARD
322ec7df04SAlan Cox #include <asm/libata-portmap.h>
33a6d967a4SJeff Garzik #else
34dcd3ea81SChristoph Hellwig #define ATA_PRIMARY_IRQ(dev) 14
35dcd3ea81SChristoph Hellwig #define ATA_SECONDARY_IRQ(dev) 15
36a6d967a4SJeff Garzik #endif
372ec7df04SAlan Cox
381da177e4SLinus Torvalds /*
39bfd60579SRandy Dunlap * compile-time options: to be removed as soon as all the drivers are
40bfd60579SRandy Dunlap * converted to the new debugging mechanism
411da177e4SLinus Torvalds */
421da177e4SLinus Torvalds #undef ATA_IRQ_TRAP /* define to ack screaming irqs */
431da177e4SLinus Torvalds
441da177e4SLinus Torvalds
4506296a1eSJoe Perches #define ata_print_version_once(dev, version) \
4606296a1eSJoe Perches ({ \
4706296a1eSJoe Perches static bool __print_once; \
4806296a1eSJoe Perches \
4906296a1eSJoe Perches if (!__print_once) { \
5006296a1eSJoe Perches __print_once = true; \
5106296a1eSJoe Perches ata_print_version(dev, version); \
5206296a1eSJoe Perches } \
5306296a1eSJoe Perches })
5406296a1eSJoe Perches
551da177e4SLinus Torvalds /* defines only for the constants which don't work well as enums */
561da177e4SLinus Torvalds #define ATA_TAG_POISON 0xfafbfcfdU
571da177e4SLinus Torvalds
5858157d60SDamien Le Moal /*
5958157d60SDamien Le Moal * Quirk flags bits.
6058157d60SDamien Le Moal * ata_device->quirks is an unsigned int, so __ATA_QUIRK_MAX must not exceed 32.
6158157d60SDamien Le Moal */
6258157d60SDamien Le Moal enum ata_quirks {
6358157d60SDamien Le Moal __ATA_QUIRK_DIAGNOSTIC, /* Failed boot diag */
6458157d60SDamien Le Moal __ATA_QUIRK_NODMA, /* DMA problems */
6558157d60SDamien Le Moal __ATA_QUIRK_NONCQ, /* Don't use NCQ */
6658157d60SDamien Le Moal __ATA_QUIRK_MAX_SEC_128, /* Limit max sects to 128 */
6758157d60SDamien Le Moal __ATA_QUIRK_BROKEN_HPA, /* Broken HPA */
6858157d60SDamien Le Moal __ATA_QUIRK_DISABLE, /* Disable it */
6958157d60SDamien Le Moal __ATA_QUIRK_HPA_SIZE, /* Native size off by one */
7058157d60SDamien Le Moal __ATA_QUIRK_IVB, /* cbl det validity bit bugs */
7158157d60SDamien Le Moal __ATA_QUIRK_STUCK_ERR, /* Stuck ERR on next PACKET */
7258157d60SDamien Le Moal __ATA_QUIRK_BRIDGE_OK, /* No bridge limits */
7358157d60SDamien Le Moal __ATA_QUIRK_ATAPI_MOD16_DMA, /* Use ATAPI DMA for commands that */
7458157d60SDamien Le Moal /* are not a multiple of 16 bytes */
7558157d60SDamien Le Moal __ATA_QUIRK_FIRMWARE_WARN, /* Firmware update warning */
7658157d60SDamien Le Moal __ATA_QUIRK_1_5_GBPS, /* Force 1.5 Gbps */
7758157d60SDamien Le Moal __ATA_QUIRK_NOSETXFER, /* Skip SETXFER, SATA only */
7858157d60SDamien Le Moal __ATA_QUIRK_BROKEN_FPDMA_AA, /* Skip AA */
7958157d60SDamien Le Moal __ATA_QUIRK_DUMP_ID, /* Dump IDENTIFY data */
8058157d60SDamien Le Moal __ATA_QUIRK_MAX_SEC_LBA48, /* Set max sects to 65535 */
8158157d60SDamien Le Moal __ATA_QUIRK_ATAPI_DMADIR, /* Device requires dmadir */
8258157d60SDamien Le Moal __ATA_QUIRK_NO_NCQ_TRIM, /* Do not use queued TRIM */
8358157d60SDamien Le Moal __ATA_QUIRK_NOLPM, /* Do not use LPM */
8458157d60SDamien Le Moal __ATA_QUIRK_WD_BROKEN_LPM, /* Some WDs have broken LPM */
8558157d60SDamien Le Moal __ATA_QUIRK_ZERO_AFTER_TRIM, /* Guarantees zero after trim */
8658157d60SDamien Le Moal __ATA_QUIRK_NO_DMA_LOG, /* Do not use DMA for log read */
8758157d60SDamien Le Moal __ATA_QUIRK_NOTRIM, /* Do not use TRIM */
8858157d60SDamien Le Moal __ATA_QUIRK_MAX_SEC_1024, /* Limit max sects to 1024 */
8958157d60SDamien Le Moal __ATA_QUIRK_MAX_TRIM_128M, /* Limit max trim size to 128M */
9058157d60SDamien Le Moal __ATA_QUIRK_NO_NCQ_ON_ATI, /* Disable NCQ on ATI chipset */
91*f2aac4c7SNiklas Cassel __ATA_QUIRK_NO_LPM_ON_ATI, /* Disable LPM on ATI chipset */
9258157d60SDamien Le Moal __ATA_QUIRK_NO_ID_DEV_LOG, /* Identify device log missing */
9358157d60SDamien Le Moal __ATA_QUIRK_NO_LOG_DIR, /* Do not read log directory */
9458157d60SDamien Le Moal __ATA_QUIRK_NO_FUA, /* Do not use FUA */
9558157d60SDamien Le Moal
9658157d60SDamien Le Moal __ATA_QUIRK_MAX,
9758157d60SDamien Le Moal };
9858157d60SDamien Le Moal
991da177e4SLinus Torvalds enum {
1001da177e4SLinus Torvalds /* various global constants */
1011da177e4SLinus Torvalds LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
102d26fc955SAlan Cox LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4, /* Worst case */
1031da177e4SLinus Torvalds ATA_DEF_QUEUE = 1,
104a6e6ce8eSTejun Heo ATA_MAX_QUEUE = 32,
10528361c40SJens Axboe ATA_TAG_INTERNAL = ATA_MAX_QUEUE,
106341c2c95STejun Heo ATA_SHORT_PAUSE = 16,
1071da177e4SLinus Torvalds
108140b5e59STejun Heo ATAPI_MAX_DRAIN = 16 << 10,
109140b5e59STejun Heo
110b558edddSTejun Heo ATA_ALL_DEVICES = (1 << ATA_MAX_DEVICES) - 1,
111b558edddSTejun Heo
1121da177e4SLinus Torvalds ATA_SHT_EMULATED = 1,
1131da177e4SLinus Torvalds ATA_SHT_THIS_ID = -1,
1141da177e4SLinus Torvalds
115dc34e7e1SSergei Shtylyov /* struct ata_taskfile flags */
116dc34e7e1SSergei Shtylyov ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */
117dc34e7e1SSergei Shtylyov ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */
118dc34e7e1SSergei Shtylyov ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */
119dc34e7e1SSergei Shtylyov ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
120dc34e7e1SSergei Shtylyov ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
121dc34e7e1SSergei Shtylyov ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
122dc34e7e1SSergei Shtylyov ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
123dc34e7e1SSergei Shtylyov
1241da177e4SLinus Torvalds /* struct ata_device stuff */
125949b38afSTejun Heo ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
126949b38afSTejun Heo ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
127029f5468SJeff Garzik ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
12888e49034STejun Heo ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
1296fc49adbSTejun Heo ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */
1306746544cSTejun Heo ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */
1316746544cSTejun Heo ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */
1327d77b247STejun Heo ATA_DFLAG_AN = (1 << 7), /* AN configured */
133818831c8SChristoph Hellwig ATA_DFLAG_TRUSTED = (1 << 8), /* device supports trusted send/recv */
1344d2e4980SDamien Le Moal ATA_DFLAG_FUA = (1 << 9), /* device supports FUA */
13591163006STejun Heo ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */
13687aab3c4SNiklas Cassel ATA_DFLAG_NCQ_SEND_RECV = (1 << 11), /* device supports NCQ SEND and RECV */
13787aab3c4SNiklas Cassel ATA_DFLAG_NCQ_PRIO = (1 << 12), /* device supports NCQ priority */
13862e4a60eSDamien Le Moal ATA_DFLAG_CDL = (1 << 13), /* supports cmd duration limits */
13962e4a60eSDamien Le Moal ATA_DFLAG_CFG_MASK = (1 << 14) - 1,
140949b38afSTejun Heo
14162e4a60eSDamien Le Moal ATA_DFLAG_PIO = (1 << 14), /* device limited to PIO mode */
14262e4a60eSDamien Le Moal ATA_DFLAG_NCQ_OFF = (1 << 15), /* device limited to non-NCQ mode */
14362e4a60eSDamien Le Moal ATA_DFLAG_SLEEPING = (1 << 16), /* device is sleeping */
14462e4a60eSDamien Le Moal ATA_DFLAG_DUBIOUS_XFER = (1 << 17), /* data transfer not verified */
14562e4a60eSDamien Le Moal ATA_DFLAG_NO_UNLOAD = (1 << 18), /* device doesn't support unload */
14662e4a60eSDamien Le Moal ATA_DFLAG_UNLOCK_HPA = (1 << 19), /* unlock HPA */
14762e4a60eSDamien Le Moal ATA_DFLAG_INIT_MASK = (1 << 20) - 1,
1481da177e4SLinus Torvalds
14962e4a60eSDamien Le Moal ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 20), /* Priority cmds sent to dev */
150df60f9c6SDamien Le Moal ATA_DFLAG_CDL_ENABLED = (1 << 21), /* cmd duration limits is enabled */
1510c76106cSDamien Le Moal ATA_DFLAG_RESUMING = (1 << 22), /* Device is resuming */
152f20ded38STejun Heo ATA_DFLAG_DETACH = (1 << 24),
153f20ded38STejun Heo ATA_DFLAG_DETACHED = (1 << 25),
154b1354cbbSLin Ming ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */
15565fe1f0fSShane Huang ATA_DFLAG_DEVSLP = (1 << 27), /* device supports Device Sleep */
1560d0cdb02SAaron Lu ATA_DFLAG_ACPI_DISABLED = (1 << 28), /* ACPI for the device is disabled */
15706dbde5fSHannes Reinecke ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */
1586d1003aeSHannes Reinecke ATA_DFLAG_ZAC = (1 << 30), /* ZAC device */
159b1354cbbSLin Ming
1604d2e4980SDamien Le Moal ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
161d633b8a7SDamien Le Moal ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
16262e4a60eSDamien Le Moal ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \
16362e4a60eSDamien Le Moal ATA_DFLAG_CDL),
164d633b8a7SDamien Le Moal
1651da177e4SLinus Torvalds ATA_DEV_UNKNOWN = 0, /* unknown device */
1661da177e4SLinus Torvalds ATA_DEV_ATA = 1, /* ATA device */
1671da177e4SLinus Torvalds ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */
1681da177e4SLinus Torvalds ATA_DEV_ATAPI = 3, /* ATAPI device */
1691da177e4SLinus Torvalds ATA_DEV_ATAPI_UNSUP = 4, /* ATAPI device (unsupported) */
170e0a71752STejun Heo ATA_DEV_PMP = 5, /* SATA port multiplier */
171e0a71752STejun Heo ATA_DEV_PMP_UNSUP = 6, /* SATA port multiplier (unsupported) */
172e0a71752STejun Heo ATA_DEV_SEMB = 7, /* SEMB */
173e0a71752STejun Heo ATA_DEV_SEMB_UNSUP = 8, /* SEMB (unsupported) */
1749162c657SHannes Reinecke ATA_DEV_ZAC = 9, /* ZAC device */
1753a92945bSHannes Reinecke ATA_DEV_ZAC_UNSUP = 10, /* ZAC device (unsupported) */
1763a92945bSHannes Reinecke ATA_DEV_NONE = 11, /* no device */
1771da177e4SLinus Torvalds
1780c88758bSTejun Heo /* struct ata_link flags */
1798ba5a45cSBartlomiej Zolnierkiewicz /* NOTE: struct ata_force_param currently stores lflags in u16 */
18005944bdfSTejun Heo ATA_LFLAG_NO_HRST = (1 << 1), /* avoid hardreset */
181ae791c05STejun Heo ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
182ae791c05STejun Heo ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
183ae791c05STejun Heo ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */
184ae791c05STejun Heo ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
185fd995f70STejun Heo ATA_LFLAG_NO_RETRY = (1 << 5), /* don't retry this link */
186f9df58cbSTejun Heo ATA_LFLAG_DISABLED = (1 << 6), /* link is disabled */
18718f7ba4cSKristen Carlson Accardi ATA_LFLAG_SW_ACTIVITY = (1 << 7), /* keep activity stats */
1886b7ae954STejun Heo ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */
189ca6d43b0SDan Williams ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */
19009c5b480SGabriele Mazzotta ATA_LFLAG_CHANGED = (1 << 10), /* LPM state changed on this link */
191b9ba367cSPaul Menzel ATA_LFLAG_NO_DEBOUNCE_DELAY = (1 << 11), /* no debounce delay on link resume */
1920c88758bSTejun Heo
1931da177e4SLinus Torvalds /* struct ata_port flags */
194949b38afSTejun Heo ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
1951da177e4SLinus Torvalds /* (doesn't imply presence) */
196949b38afSTejun Heo ATA_FLAG_SATA = (1 << 1),
197240630e6SHans de Goede ATA_FLAG_NO_LPM = (1 << 2), /* host not happy with LPM */
198ea013a9bSAndreas Werner ATA_FLAG_NO_LOG_PAGE = (1 << 5), /* do not issue log page read */
199949b38afSTejun Heo ATA_FLAG_NO_ATAPI = (1 << 6), /* No ATAPI support */
200949b38afSTejun Heo ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */
201949b38afSTejun Heo ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */
2027395acb2STejun Heo ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
203e50362ecSAlbert Lee * doesn't handle PIO interrupts */
2047395acb2STejun Heo ATA_FLAG_NCQ = (1 << 10), /* host supports NCQ */
2052a6e58d2SRafael J. Wysocki ATA_FLAG_NO_POWEROFF_SPINDOWN = (1 << 11), /* don't spindown before poweroff */
2062a6e58d2SRafael J. Wysocki ATA_FLAG_NO_HIBERNATE_SPINDOWN = (1 << 12), /* don't spindown before hibernation */
2077395acb2STejun Heo ATA_FLAG_DEBUGMSG = (1 << 13),
208388539f3SShaohua Li ATA_FLAG_FPDMA_AA = (1 << 14), /* driver supports Auto-Activate */
209b2a8bbe6STejun Heo ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
210f834e49fSAlan Cox ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */
2113cadbcc0STejun Heo ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */
2129f45cbd3SKristen Carlson Accardi ATA_FLAG_AN = (1 << 18), /* controller supports AN */
213e0a71752STejun Heo ATA_FLAG_PMP = (1 << 19), /* controller supports PMP */
21440fb59e7SMarc Carino ATA_FLAG_FPDMA_AUX = (1 << 20), /* controller supports H2DFIS aux field */
21518f7ba4cSKristen Carlson Accardi ATA_FLAG_EM = (1 << 21), /* driver supports enclosure
21618f7ba4cSKristen Carlson Accardi * management */
21718f7ba4cSKristen Carlson Accardi ATA_FLAG_SW_ACTIVITY = (1 << 22), /* driver supports sw activity
21818f7ba4cSKristen Carlson Accardi * led */
219ae01b249STejun Heo ATA_FLAG_NO_DIPM = (1 << 23), /* host not happy with DIPM */
220a1480a16SLinus Torvalds ATA_FLAG_SAS_HOST = (1 << 24), /* SAS host */
2211da177e4SLinus Torvalds
222b51e9e5dSTejun Heo /* bits 24:31 of ap->flags are reserved for LLD specific flags */
2239b847548SJens Axboe
224e3cf95ddSAlan Cox
225b51e9e5dSTejun Heo /* struct ata_port pflags */
226b51e9e5dSTejun Heo ATA_PFLAG_EH_PENDING = (1 << 0), /* EH pending */
227b51e9e5dSTejun Heo ATA_PFLAG_EH_IN_PROGRESS = (1 << 1), /* EH in progress */
228b51e9e5dSTejun Heo ATA_PFLAG_FROZEN = (1 << 2), /* port is frozen */
229b51e9e5dSTejun Heo ATA_PFLAG_RECOVERED = (1 << 3), /* recovery action performed */
230b51e9e5dSTejun Heo ATA_PFLAG_LOADING = (1 << 4), /* boot/loading probe */
231b51e9e5dSTejun Heo ATA_PFLAG_SCSI_HOTPLUG = (1 << 6), /* SCSI hotplug scheduled */
232f4d6d004STejun Heo ATA_PFLAG_INITIALIZING = (1 << 7), /* being initialized, don't touch */
233afaa5c37STejun Heo ATA_PFLAG_RESETTING = (1 << 8), /* reset in progress */
234ece180d1STejun Heo ATA_PFLAG_UNLOADING = (1 << 9), /* driver is being unloaded */
235ece180d1STejun Heo ATA_PFLAG_UNLOADED = (1 << 10), /* driver is unloaded */
236b51e9e5dSTejun Heo
237aa3998dbSDamien Le Moal ATA_PFLAG_RESUMING = (1 << 16), /* port is being resumed */
238b51e9e5dSTejun Heo ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */
239500530f6STejun Heo ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */
240c05e6ff0STejun Heo ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */
2418d238e01SAlan Cox
242e3cf95ddSAlan Cox ATA_PFLAG_PIO32 = (1 << 20), /* 32bit PIO */
243e3cf95ddSAlan Cox ATA_PFLAG_PIO32CHANGE = (1 << 21), /* 32bit PIO can be turned on/off */
2448a3e33cfSManuel Lauss ATA_PFLAG_EXTERNAL = (1 << 22), /* eSATA/external port */
245e3cf95ddSAlan Cox
246949b38afSTejun Heo /* struct ata_queued_cmd flags */
247949b38afSTejun Heo ATA_QCFLAG_ACTIVE = (1 << 0), /* cmd not yet ack'd to scsi lyer */
248001102d7STejun Heo ATA_QCFLAG_DMAMAP = (1 << 1), /* SG table is DMA mapped */
24993c4aa44SNiklas Cassel ATA_QCFLAG_RTF_FILLED = (1 << 2), /* result TF has been filled */
25027197367STejun Heo ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
251e61e0672STejun Heo ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
252da917d69STejun Heo ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */
253e027bd36STejun Heo ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */
25403faab78STejun Heo ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */
255eafe804bSDamien Le Moal ATA_QCFLAG_HAS_CDL = (1 << 8), /* qc has CDL a descriptor set */
256e61e0672STejun Heo
25787629312SNiklas Cassel ATA_QCFLAG_EH = (1 << 16), /* cmd aborted and owned by EH */
2589ec957f2STejun Heo ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
2599ec957f2STejun Heo ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
26018bd7718SNiklas Cassel ATA_QCFLAG_EH_SUCCESS_CMD = (1 << 19), /* EH should fetch sense for this successful cmd */
2611da177e4SLinus Torvalds
2624e5ec5dbSAlan Cox /* host set flags */
263cca3974eSJeff Garzik ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */
264ecef7253STejun Heo ATA_HOST_STARTED = (1 << 1), /* Host started */
265886ad09fSArjan van de Ven ATA_HOST_PARALLEL_SCAN = (1 << 2), /* Ports on this host can be scanned in parallel */
266db63a4c8SAndy Whitcroft ATA_HOST_IGNORE_ATA = (1 << 3), /* Ignore ATA devices on this host. */
2674e5ec5dbSAlan Cox
26824e0e61dSNiklas Cassel ATA_HOST_NO_PART = (1 << 4), /* Host does not support partial */
26924e0e61dSNiklas Cassel ATA_HOST_NO_SSC = (1 << 5), /* Host does not support slumber */
27024e0e61dSNiklas Cassel ATA_HOST_NO_DEVSLP = (1 << 6), /* Host does not support devslp */
27124e0e61dSNiklas Cassel
272b8b275efSTejun Heo /* bits 24:31 of host->flags are reserved for LLD specific flags */
273b8b275efSTejun Heo
274f7a870d0SDamien Le Moal /* Various lengths of time */
275341c2c95STejun Heo ATA_TMOUT_INTERNAL_QUICK = 5000,
27645fabbb7SElias Oltmanns ATA_TMOUT_MAX_PARK = 30000,
2771da177e4SLinus Torvalds
278b48d58f5STejun Heo /*
279b48d58f5STejun Heo * GoVault needs 2s and iVDR disk HHD424020F7SV00 800ms. 2s
280b48d58f5STejun Heo * is too much without parallel probing. Use 2s if parallel
281b48d58f5STejun Heo * probing is available, 800ms otherwise.
28288ff6eafSTejun Heo */
283b48d58f5STejun Heo ATA_TMOUT_FF_WAIT_LONG = 2000,
284341c2c95STejun Heo ATA_TMOUT_FF_WAIT = 800,
28588ff6eafSTejun Heo
286705e76beSTejun Heo /* Spec mandates to wait for ">= 2ms" before checking status
287705e76beSTejun Heo * after reset. We wait 150ms, because that was the magic
288705e76beSTejun Heo * delay used for ATAPI devices in Hale Landis's ATADRVR, for
289705e76beSTejun Heo * the period of time between when the ATA command register is
290705e76beSTejun Heo * written, and then status is checked. Because waiting for
291705e76beSTejun Heo * "a while" before checking status is fine, post SRST, we
292705e76beSTejun Heo * perform this magic delay here as well.
293705e76beSTejun Heo *
294705e76beSTejun Heo * Old drivers/ide uses the 2mS rule and then waits for ready.
295705e76beSTejun Heo */
296341c2c95STejun Heo ATA_WAIT_AFTER_RESET = 150,
297705e76beSTejun Heo
2989dadd45bSTejun Heo /* If PMP is supported, we have to do follow-up SRST. As some
2999dadd45bSTejun Heo * PMPs don't send D2H Reg FIS after hardreset, LLDs are
3009dadd45bSTejun Heo * advised to wait only for the following duration before
3019dadd45bSTejun Heo * doing SRST.
3029dadd45bSTejun Heo */
303753a4d53SMatthias Schiffer ATA_TMOUT_PMP_SRST_WAIT = 10000,
3049dadd45bSTejun Heo
30509c5b480SGabriele Mazzotta /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might
30609c5b480SGabriele Mazzotta * be a spurious PHY event, so ignore the first PHY event that
30709c5b480SGabriele Mazzotta * occurs within 10s after the policy change.
30809c5b480SGabriele Mazzotta */
30909c5b480SGabriele Mazzotta ATA_TMOUT_SPURIOUS_PHY = 10000,
31009c5b480SGabriele Mazzotta
3111da177e4SLinus Torvalds /* ATA bus states */
3121da177e4SLinus Torvalds BUS_UNKNOWN = 0,
3131da177e4SLinus Torvalds BUS_DMA = 1,
3141da177e4SLinus Torvalds BUS_IDLE = 2,
3151da177e4SLinus Torvalds BUS_NOINTR = 3,
3161da177e4SLinus Torvalds BUS_NODATA = 4,
3171da177e4SLinus Torvalds BUS_TIMER = 5,
3181da177e4SLinus Torvalds BUS_PIO = 6,
3191da177e4SLinus Torvalds BUS_EDD = 7,
3201da177e4SLinus Torvalds BUS_IDENTIFY = 8,
3211da177e4SLinus Torvalds BUS_PACKET = 9,
3221da177e4SLinus Torvalds
3231da177e4SLinus Torvalds /* SATA port states */
3241da177e4SLinus Torvalds PORT_UNKNOWN = 0,
3251da177e4SLinus Torvalds PORT_ENABLED = 1,
3261da177e4SLinus Torvalds PORT_DISABLED = 2,
3271da177e4SLinus Torvalds
3281da177e4SLinus Torvalds /* encoding various smaller bitmaps into a single
329f0a6d77bSSergey Shtylyov * unsigned int bitmap
3301da177e4SLinus Torvalds */
33170cd071eSTejun Heo ATA_NR_PIO_MODES = 7,
33270cd071eSTejun Heo ATA_NR_MWDMA_MODES = 5,
33370cd071eSTejun Heo ATA_NR_UDMA_MODES = 8,
3341da7b0d0STejun Heo
3351da7b0d0STejun Heo ATA_SHIFT_PIO = 0,
33670cd071eSTejun Heo ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
33770cd071eSTejun Heo ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
3388e061784SAdam Manzanares ATA_SHIFT_PRIO = 6,
3391da7b0d0STejun Heo
3408e061784SAdam Manzanares ATA_PRIO_HIGH = 2,
341cedc9a47SJeff Garzik /* size of buffer to pad xfers ending on unaligned boundaries */
342cedc9a47SJeff Garzik ATA_DMA_PAD_SZ = 4,
343c4052da6SJeff Garzik
3440c247c55STejun Heo /* ering size */
3450c247c55STejun Heo ATA_ERING_SIZE = 32,
3460c247c55STejun Heo
34731cc23b3STejun Heo /* return values for ->qc_defer */
34831cc23b3STejun Heo ATA_DEFER_LINK = 1,
34931cc23b3STejun Heo ATA_DEFER_PORT = 2,
35031cc23b3STejun Heo
351f3e81b19STejun Heo /* desc_len for ata_eh_info and context */
352f3e81b19STejun Heo ATA_EH_DESC_LEN = 80,
353f3e81b19STejun Heo
3549be1e979STejun Heo /* reset / recovery action types */
3559be1e979STejun Heo ATA_EH_REVALIDATE = (1 << 0),
356cf480626STejun Heo ATA_EH_SOFTRESET = (1 << 1), /* meaningful only in ->prereset */
357cf480626STejun Heo ATA_EH_HARDRESET = (1 << 2), /* meaningful only in ->prereset */
358cf480626STejun Heo ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
359f9df58cbSTejun Heo ATA_EH_ENABLE_LINK = (1 << 3),
36045fabbb7SElias Oltmanns ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */
36118bd7718SNiklas Cassel ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */
362aa3998dbSDamien Le Moal ATA_EH_SET_ACTIVE = (1 << 7), /* Set a device to active power mode */
3639be1e979STejun Heo
36418bd7718SNiklas Cassel ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK |
365aa3998dbSDamien Le Moal ATA_EH_GET_SUCCESS_SENSE | ATA_EH_SET_ACTIVE,
366b5b3fa38STejun Heo ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET |
3676b7ae954STejun Heo ATA_EH_ENABLE_LINK,
3689be1e979STejun Heo
369f3e81b19STejun Heo /* ata_eh_info->flags */
370abdda733STejun Heo ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
3711cdaf534STejun Heo ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
3721cdaf534STejun Heo ATA_EHI_QUIET = (1 << 3), /* be quiet */
373e2f3d75fSTejun Heo ATA_EHI_NO_RECOVERY = (1 << 4), /* no recovery */
374abdda733STejun Heo
3750d64a233STejun Heo ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */
3760d64a233STejun Heo ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */
3770d64a233STejun Heo ATA_EHI_PRINTINFO = (1 << 18), /* print configuration info */
3780d64a233STejun Heo ATA_EHI_SETMODE = (1 << 19), /* configure transfer mode */
37989692c03SAndrea Gelmini ATA_EHI_POST_SETMODE = (1 << 20), /* revalidating after setmode */
380bf1807c6SDamien Le Moal ATA_EHI_DID_PRINT_QUIRKS = (1 << 21), /* already printed quirks info */
381f3e81b19STejun Heo
3820d64a233STejun Heo ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
38313abf50dSTejun Heo
384848e4c68STejun Heo /* mask of flags to transfer *to* the slave link */
385848e4c68STejun Heo ATA_EHI_TO_SLAVE_MASK = ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET,
386848e4c68STejun Heo
387a1e10f7eSTejun Heo /* max tries if error condition is still set after ->error_handler */
388a1e10f7eSTejun Heo ATA_EH_MAX_TRIES = 5,
389ad9e2762STejun Heo
3905040ab67STejun Heo /* sometimes resuming a link requires several retries */
3915040ab67STejun Heo ATA_LINK_RESUME_TRIES = 5,
3925040ab67STejun Heo
39314d2bac1STejun Heo /* how hard are we gonna try to probe/recover devices */
394022bdb07STejun Heo ATA_EH_DEV_TRIES = 3,
395e0a71752STejun Heo ATA_EH_PMP_TRIES = 5,
396e0a71752STejun Heo ATA_EH_PMP_LINK_TRIES = 3,
397e0a71752STejun Heo
398bf1bff6fSTejun Heo SATA_PMP_RW_TIMEOUT = 3000, /* PMP read/write timeout */
399f5914a46STejun Heo
40087fbc5a0STejun Heo /* This should match the actual table size of
40187fbc5a0STejun Heo * ata_eh_cmd_timeout_table in libata-eh.c.
40287fbc5a0STejun Heo */
403aa3998dbSDamien Le Moal ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 8,
40487fbc5a0STejun Heo
4057ebd8c5aSDamien Le Moal /*
4067ebd8c5aSDamien Le Moal * Quirk flags: may be set by libata or controller drivers on drives.
4077ebd8c5aSDamien Le Moal * Some quirks may be drive/controller pair dependent.
4087ebd8c5aSDamien Le Moal */
40958157d60SDamien Le Moal ATA_QUIRK_DIAGNOSTIC = (1U << __ATA_QUIRK_DIAGNOSTIC),
41058157d60SDamien Le Moal ATA_QUIRK_NODMA = (1U << __ATA_QUIRK_NODMA),
41158157d60SDamien Le Moal ATA_QUIRK_NONCQ = (1U << __ATA_QUIRK_NONCQ),
41258157d60SDamien Le Moal ATA_QUIRK_MAX_SEC_128 = (1U << __ATA_QUIRK_MAX_SEC_128),
41358157d60SDamien Le Moal ATA_QUIRK_BROKEN_HPA = (1U << __ATA_QUIRK_BROKEN_HPA),
41458157d60SDamien Le Moal ATA_QUIRK_DISABLE = (1U << __ATA_QUIRK_DISABLE),
41558157d60SDamien Le Moal ATA_QUIRK_HPA_SIZE = (1U << __ATA_QUIRK_HPA_SIZE),
41658157d60SDamien Le Moal ATA_QUIRK_IVB = (1U << __ATA_QUIRK_IVB),
41758157d60SDamien Le Moal ATA_QUIRK_STUCK_ERR = (1U << __ATA_QUIRK_STUCK_ERR),
41858157d60SDamien Le Moal ATA_QUIRK_BRIDGE_OK = (1U << __ATA_QUIRK_BRIDGE_OK),
41958157d60SDamien Le Moal ATA_QUIRK_ATAPI_MOD16_DMA = (1U << __ATA_QUIRK_ATAPI_MOD16_DMA),
42058157d60SDamien Le Moal ATA_QUIRK_FIRMWARE_WARN = (1U << __ATA_QUIRK_FIRMWARE_WARN),
42158157d60SDamien Le Moal ATA_QUIRK_1_5_GBPS = (1U << __ATA_QUIRK_1_5_GBPS),
42258157d60SDamien Le Moal ATA_QUIRK_NOSETXFER = (1U << __ATA_QUIRK_NOSETXFER),
42358157d60SDamien Le Moal ATA_QUIRK_BROKEN_FPDMA_AA = (1U << __ATA_QUIRK_BROKEN_FPDMA_AA),
42458157d60SDamien Le Moal ATA_QUIRK_DUMP_ID = (1U << __ATA_QUIRK_DUMP_ID),
42558157d60SDamien Le Moal ATA_QUIRK_MAX_SEC_LBA48 = (1U << __ATA_QUIRK_MAX_SEC_LBA48),
42658157d60SDamien Le Moal ATA_QUIRK_ATAPI_DMADIR = (1U << __ATA_QUIRK_ATAPI_DMADIR),
42758157d60SDamien Le Moal ATA_QUIRK_NO_NCQ_TRIM = (1U << __ATA_QUIRK_NO_NCQ_TRIM),
42858157d60SDamien Le Moal ATA_QUIRK_NOLPM = (1U << __ATA_QUIRK_NOLPM),
42958157d60SDamien Le Moal ATA_QUIRK_WD_BROKEN_LPM = (1U << __ATA_QUIRK_WD_BROKEN_LPM),
43058157d60SDamien Le Moal ATA_QUIRK_ZERO_AFTER_TRIM = (1U << __ATA_QUIRK_ZERO_AFTER_TRIM),
43158157d60SDamien Le Moal ATA_QUIRK_NO_DMA_LOG = (1U << __ATA_QUIRK_NO_DMA_LOG),
43258157d60SDamien Le Moal ATA_QUIRK_NOTRIM = (1U << __ATA_QUIRK_NOTRIM),
43358157d60SDamien Le Moal ATA_QUIRK_MAX_SEC_1024 = (1U << __ATA_QUIRK_MAX_SEC_1024),
43458157d60SDamien Le Moal ATA_QUIRK_MAX_TRIM_128M = (1U << __ATA_QUIRK_MAX_TRIM_128M),
43558157d60SDamien Le Moal ATA_QUIRK_NO_NCQ_ON_ATI = (1U << __ATA_QUIRK_NO_NCQ_ON_ATI),
436*f2aac4c7SNiklas Cassel ATA_QUIRK_NO_LPM_ON_ATI = (1U << __ATA_QUIRK_NO_LPM_ON_ATI),
43758157d60SDamien Le Moal ATA_QUIRK_NO_ID_DEV_LOG = (1U << __ATA_QUIRK_NO_ID_DEV_LOG),
43858157d60SDamien Le Moal ATA_QUIRK_NO_LOG_DIR = (1U << __ATA_QUIRK_NO_LOG_DIR),
43958157d60SDamien Le Moal ATA_QUIRK_NO_FUA = (1U << __ATA_QUIRK_NO_FUA),
440b3a70601SAlan Cox
44158157d60SDamien Le Moal /* User visible DMA mask for DMA control. DO NOT renumber. */
442b3a70601SAlan Cox ATA_DMA_MASK_ATA = (1 << 0), /* DMA on ATA Disk */
443b3a70601SAlan Cox ATA_DMA_MASK_ATAPI = (1 << 1), /* DMA on ATAPI */
444b3a70601SAlan Cox ATA_DMA_MASK_CFA = (1 << 2), /* DMA on CF Card */
445ceb0c642STejun Heo
446ceb0c642STejun Heo /* ATAPI command types */
447ceb0c642STejun Heo ATAPI_READ = 0, /* READs */
448ceb0c642STejun Heo ATAPI_WRITE = 1, /* WRITEs */
449ceb0c642STejun Heo ATAPI_READ_CD = 2, /* READ CD [MSF] */
450e52dcc48STejun Heo ATAPI_PASS_THRU = 3, /* SAT pass-thru */
451e52dcc48STejun Heo ATAPI_MISC = 4, /* the rest */
452624d5c51STejun Heo
453624d5c51STejun Heo /* Timing constants */
454624d5c51STejun Heo ATA_TIMING_SETUP = (1 << 0),
455624d5c51STejun Heo ATA_TIMING_ACT8B = (1 << 1),
456624d5c51STejun Heo ATA_TIMING_REC8B = (1 << 2),
457624d5c51STejun Heo ATA_TIMING_CYC8B = (1 << 3),
458624d5c51STejun Heo ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
459624d5c51STejun Heo ATA_TIMING_CYC8B,
460624d5c51STejun Heo ATA_TIMING_ACTIVE = (1 << 4),
461624d5c51STejun Heo ATA_TIMING_RECOVER = (1 << 5),
4623ada9c12SDavid Daney ATA_TIMING_DMACK_HOLD = (1 << 6),
4633ada9c12SDavid Daney ATA_TIMING_CYCLE = (1 << 7),
4643ada9c12SDavid Daney ATA_TIMING_UDMA = (1 << 8),
465624d5c51STejun Heo ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
466624d5c51STejun Heo ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
467624d5c51STejun Heo ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
4683ada9c12SDavid Daney ATA_TIMING_DMACK_HOLD | ATA_TIMING_CYCLE |
4693ada9c12SDavid Daney ATA_TIMING_UDMA,
470f1bce7f8STejun Heo
471f1bce7f8STejun Heo /* ACPI constants */
472f1bce7f8STejun Heo ATA_ACPI_FILTER_SETXFER = 1 << 0,
473f1bce7f8STejun Heo ATA_ACPI_FILTER_LOCK = 1 << 1,
474f1bce7f8STejun Heo ATA_ACPI_FILTER_DIPM = 1 << 2,
475fa5b561cSTejun Heo ATA_ACPI_FILTER_FPDMA_OFFSET = 1 << 3, /* FPDMA non-zero offset */
476fa5b561cSTejun Heo ATA_ACPI_FILTER_FPDMA_AA = 1 << 4, /* FPDMA auto activate */
477f1bce7f8STejun Heo
478f1bce7f8STejun Heo ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER |
479f1bce7f8STejun Heo ATA_ACPI_FILTER_LOCK |
480f1bce7f8STejun Heo ATA_ACPI_FILTER_DIPM,
4811da177e4SLinus Torvalds };
4821da177e4SLinus Torvalds
4837dc951aeSTejun Heo enum ata_xfer_mask {
484f0a6d77bSSergey Shtylyov ATA_MASK_PIO = ((1U << ATA_NR_PIO_MODES) - 1) << ATA_SHIFT_PIO,
485f0a6d77bSSergey Shtylyov ATA_MASK_MWDMA = ((1U << ATA_NR_MWDMA_MODES) - 1) << ATA_SHIFT_MWDMA,
486f0a6d77bSSergey Shtylyov ATA_MASK_UDMA = ((1U << ATA_NR_UDMA_MODES) - 1) << ATA_SHIFT_UDMA,
4877dc951aeSTejun Heo };
4887dc951aeSTejun Heo
48914be71f4SAlbert Lee enum hsm_task_states {
490c56b14d2SAlbert Lee HSM_ST_IDLE, /* no command on going */
49171527647SAlbert Lee HSM_ST_FIRST, /* (waiting the device to)
49271527647SAlbert Lee write CDB or first data block */
493c56b14d2SAlbert Lee HSM_ST, /* (waiting the device to) transfer data */
494c56b14d2SAlbert Lee HSM_ST_LAST, /* (waiting the device to) complete command */
495c56b14d2SAlbert Lee HSM_ST_ERR, /* error */
4961da177e4SLinus Torvalds };
4971da177e4SLinus Torvalds
498a7dac447SJeff Garzik enum ata_completion_errors {
49925937580SJiri Slaby AC_ERR_OK = 0, /* no error */
50011a56d24STejun Heo AC_ERR_DEV = (1 << 0), /* device reported error */
50111a56d24STejun Heo AC_ERR_HSM = (1 << 1), /* host state machine violation */
50211a56d24STejun Heo AC_ERR_TIMEOUT = (1 << 2), /* timeout */
50311a56d24STejun Heo AC_ERR_MEDIA = (1 << 3), /* media error */
50411a56d24STejun Heo AC_ERR_ATA_BUS = (1 << 4), /* ATA bus error */
50511a56d24STejun Heo AC_ERR_HOST_BUS = (1 << 5), /* host bus error */
50611a56d24STejun Heo AC_ERR_SYSTEM = (1 << 6), /* system error */
50711a56d24STejun Heo AC_ERR_INVALID = (1 << 7), /* invalid argument */
50811a56d24STejun Heo AC_ERR_OTHER = (1 << 8), /* unknown */
50955a8e2c8STejun Heo AC_ERR_NODEV_HINT = (1 << 9), /* polling device detection hint */
5105335b729STejun Heo AC_ERR_NCQ = (1 << 10), /* marker for offending NCQ qc */
511a7dac447SJeff Garzik };
512a7dac447SJeff Garzik
513c93b263eSTejun Heo /*
514c93b263eSTejun Heo * Link power management policy: If you alter this, you also need to
51573ae7e1cSNiklas Cassel * alter libata-sata.c (for the ascii descriptions)
516c93b263eSTejun Heo */
517c93b263eSTejun Heo enum ata_lpm_policy {
518c93b263eSTejun Heo ATA_LPM_UNKNOWN,
519c93b263eSTejun Heo ATA_LPM_MAX_POWER,
520c93b263eSTejun Heo ATA_LPM_MED_POWER,
521f4ac6476SHans de Goede ATA_LPM_MED_POWER_WITH_DIPM, /* Med power + DIPM as win IRST does */
522a5ec5a7bSSrinivas Pandruvada ATA_LPM_MIN_POWER_WITH_PARTIAL, /* Min Power + partial and slumber */
523a5ec5a7bSSrinivas Pandruvada ATA_LPM_MIN_POWER, /* Min power + no partial (slumber only) */
524c93b263eSTejun Heo };
525c93b263eSTejun Heo
5266b7ae954STejun Heo enum ata_lpm_hints {
5276b7ae954STejun Heo ATA_LPM_EMPTY = (1 << 0), /* port empty/probing */
5286b7ae954STejun Heo ATA_LPM_HIPM = (1 << 1), /* may use HIPM */
529fb329633SDanesh Petigara ATA_LPM_WAKE_ONLY = (1 << 2), /* only wake up link */
5306b7ae954STejun Heo };
5316b7ae954STejun Heo
5321da177e4SLinus Torvalds /* forward declarations */
5331da177e4SLinus Torvalds struct scsi_device;
5341da177e4SLinus Torvalds struct ata_port_operations;
5351da177e4SLinus Torvalds struct ata_port;
536cc0680a5STejun Heo struct ata_link;
5371da177e4SLinus Torvalds struct ata_queued_cmd;
5381da177e4SLinus Torvalds
5391da177e4SLinus Torvalds /* typedefs */
54077853bf2STejun Heo typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
541cc0680a5STejun Heo typedef int (*ata_prereset_fn_t)(struct ata_link *link, unsigned long deadline);
542cc0680a5STejun Heo typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
543d4b2bab4STejun Heo unsigned long deadline);
544cc0680a5STejun Heo typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
5451da177e4SLinus Torvalds
54645fabbb7SElias Oltmanns extern struct device_attribute dev_attr_unload_heads;
547ec811a94SBartlomiej Zolnierkiewicz #ifdef CONFIG_SATA_HOST
548ec811a94SBartlomiej Zolnierkiewicz extern struct device_attribute dev_attr_link_power_management_policy;
5495f91b8f5SDamien Le Moal extern struct device_attribute dev_attr_ncq_prio_supported;
55084f95243SAdam Manzanares extern struct device_attribute dev_attr_ncq_prio_enable;
55118f7ba4cSKristen Carlson Accardi extern struct device_attribute dev_attr_em_message_type;
55218f7ba4cSKristen Carlson Accardi extern struct device_attribute dev_attr_em_message;
55318f7ba4cSKristen Carlson Accardi extern struct device_attribute dev_attr_sw_activity;
554ec811a94SBartlomiej Zolnierkiewicz #endif
55518f7ba4cSKristen Carlson Accardi
55618f7ba4cSKristen Carlson Accardi enum sw_activity {
55718f7ba4cSKristen Carlson Accardi OFF,
55818f7ba4cSKristen Carlson Accardi BLINK_ON,
55918f7ba4cSKristen Carlson Accardi BLINK_OFF,
56018f7ba4cSKristen Carlson Accardi };
561ca77329fSKristen Carlson Accardi
562dc34e7e1SSergei Shtylyov struct ata_taskfile {
563dc34e7e1SSergei Shtylyov unsigned long flags; /* ATA_TFLAG_xxx */
564dc34e7e1SSergei Shtylyov u8 protocol; /* ATA_PROT_xxx */
565dc34e7e1SSergei Shtylyov
566dc34e7e1SSergei Shtylyov u8 ctl; /* control reg */
567dc34e7e1SSergei Shtylyov
568dc34e7e1SSergei Shtylyov u8 hob_feature; /* additional data */
569dc34e7e1SSergei Shtylyov u8 hob_nsect; /* to support LBA48 */
570dc34e7e1SSergei Shtylyov u8 hob_lbal;
571dc34e7e1SSergei Shtylyov u8 hob_lbam;
572dc34e7e1SSergei Shtylyov u8 hob_lbah;
573dc34e7e1SSergei Shtylyov
574efcef265SSergey Shtylyov union {
575efcef265SSergey Shtylyov u8 error;
576dc34e7e1SSergei Shtylyov u8 feature;
577efcef265SSergey Shtylyov };
578dc34e7e1SSergei Shtylyov u8 nsect;
579dc34e7e1SSergei Shtylyov u8 lbal;
580dc34e7e1SSergei Shtylyov u8 lbam;
581dc34e7e1SSergei Shtylyov u8 lbah;
582dc34e7e1SSergei Shtylyov
583dc34e7e1SSergei Shtylyov u8 device;
584dc34e7e1SSergei Shtylyov
585efcef265SSergey Shtylyov union {
586efcef265SSergey Shtylyov u8 status;
587efcef265SSergey Shtylyov u8 command;
588efcef265SSergey Shtylyov };
5898be5ad9aSMarc Carino
5908be5ad9aSMarc Carino u32 auxiliary; /* auxiliary field */
5918be5ad9aSMarc Carino /* from SATA 3.1 and */
5928be5ad9aSMarc Carino /* ATA-8 ACS-3 */
593dc34e7e1SSergei Shtylyov };
594dc34e7e1SSergei Shtylyov
595127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
5961da177e4SLinus Torvalds struct ata_ioports {
5970d5ff566STejun Heo void __iomem *cmd_addr;
5980d5ff566STejun Heo void __iomem *data_addr;
5990d5ff566STejun Heo void __iomem *error_addr;
6000d5ff566STejun Heo void __iomem *feature_addr;
6010d5ff566STejun Heo void __iomem *nsect_addr;
6020d5ff566STejun Heo void __iomem *lbal_addr;
6030d5ff566STejun Heo void __iomem *lbam_addr;
6040d5ff566STejun Heo void __iomem *lbah_addr;
6050d5ff566STejun Heo void __iomem *device_addr;
6060d5ff566STejun Heo void __iomem *status_addr;
6070d5ff566STejun Heo void __iomem *command_addr;
6080d5ff566STejun Heo void __iomem *altstatus_addr;
6090d5ff566STejun Heo void __iomem *ctl_addr;
6109a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
6110d5ff566STejun Heo void __iomem *bmdma_addr;
6129a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
6130d5ff566STejun Heo void __iomem *scr_addr;
6141da177e4SLinus Torvalds };
615127102aeSTejun Heo #endif /* CONFIG_ATA_SFF */
6161da177e4SLinus Torvalds
617cca3974eSJeff Garzik struct ata_host {
6181da177e4SLinus Torvalds spinlock_t lock;
6191da177e4SLinus Torvalds struct device *dev;
6200d5ff566STejun Heo void __iomem * const *iomap;
6211da177e4SLinus Torvalds unsigned int n_ports;
6221a112d10STejun Heo unsigned int n_tags; /* nr of NCQ tags */
6231da177e4SLinus Torvalds void *private_data;
624029cfd6bSTejun Heo struct ata_port_operations *ops;
6255444a6f4SAlan Cox unsigned long flags;
6262623c7a5STaras Kondratiuk struct kref kref;
627c0c362b6STejun Heo
628c0c362b6STejun Heo struct mutex eh_mutex;
629c0c362b6STejun Heo struct task_struct *eh_owner;
630c0c362b6STejun Heo
631032af1ceSAlan struct ata_port *simplex_claimed; /* channel owning the DMA */
6329c5fbf05SGustavo A. R. Silva struct ata_port *ports[];
6331da177e4SLinus Torvalds };
6341da177e4SLinus Torvalds
6351da177e4SLinus Torvalds struct ata_queued_cmd {
6361da177e4SLinus Torvalds struct ata_port *ap;
6371da177e4SLinus Torvalds struct ata_device *dev;
6381da177e4SLinus Torvalds
6391da177e4SLinus Torvalds struct scsi_cmnd *scsicmd;
6401da177e4SLinus Torvalds void (*scsidone)(struct scsi_cmnd *);
6411da177e4SLinus Torvalds
6421da177e4SLinus Torvalds struct ata_taskfile tf;
6431da177e4SLinus Torvalds u8 cdb[ATAPI_CDB_LEN];
6441da177e4SLinus Torvalds
6451da177e4SLinus Torvalds unsigned long flags; /* ATA_QCFLAG_xxx */
6465ac40790SJens Axboe unsigned int tag; /* libata core tag */
6475ac40790SJens Axboe unsigned int hw_tag; /* driver tag */
6481da177e4SLinus Torvalds unsigned int n_elem;
6495825627cSFUJITA Tomonori unsigned int orig_n_elem;
6501da177e4SLinus Torvalds
6511da177e4SLinus Torvalds int dma_dir;
6521da177e4SLinus Torvalds
6535a5dbd18SMark Lord unsigned int sect_size;
654cedc9a47SJeff Garzik
6551da177e4SLinus Torvalds unsigned int nbytes;
656aacda375STejun Heo unsigned int extrabytes;
6571da177e4SLinus Torvalds unsigned int curbytes;
6581da177e4SLinus Torvalds
6591da177e4SLinus Torvalds struct scatterlist sgent;
6601da177e4SLinus Torvalds
661ff2aeb1eSTejun Heo struct scatterlist *sg;
6621da177e4SLinus Torvalds
663b34e9042SRichard Kennedy struct scatterlist *cursg;
664b34e9042SRichard Kennedy unsigned int cursg_ofs;
665b34e9042SRichard Kennedy
666a22e2eb0SAlbert Lee unsigned int err_mask;
667e61e0672STejun Heo struct ata_taskfile result_tf;
6681da177e4SLinus Torvalds ata_qc_cb_t complete_fn;
6691da177e4SLinus Torvalds
6701da177e4SLinus Torvalds void *private_data;
6711c50dc83SDarrick J. Wong void *lldd_task;
6721da177e4SLinus Torvalds };
6731da177e4SLinus Torvalds
674cca3974eSJeff Garzik struct ata_port_stats {
6751da177e4SLinus Torvalds unsigned long unhandled_irq;
6761da177e4SLinus Torvalds unsigned long idle_irq;
6771da177e4SLinus Torvalds unsigned long rw_reqbuf;
6781da177e4SLinus Torvalds };
6791da177e4SLinus Torvalds
6800c247c55STejun Heo struct ata_ering_entry {
6813884f7b0STejun Heo unsigned int eflags;
6820c247c55STejun Heo unsigned int err_mask;
6830c247c55STejun Heo u64 timestamp;
6840c247c55STejun Heo };
6850c247c55STejun Heo
6860c247c55STejun Heo struct ata_ering {
6870c247c55STejun Heo int cursor;
6880c247c55STejun Heo struct ata_ering_entry ring[ATA_ERING_SIZE];
6890c247c55STejun Heo };
6900c247c55STejun Heo
691fe22e1c2SDamien Le Moal struct ata_cpr {
692fe22e1c2SDamien Le Moal u8 num;
693fe22e1c2SDamien Le Moal u8 num_storage_elements;
694fe22e1c2SDamien Le Moal u64 start_lba;
695fe22e1c2SDamien Le Moal u64 num_lbas;
696fe22e1c2SDamien Le Moal };
697fe22e1c2SDamien Le Moal
698fe22e1c2SDamien Le Moal struct ata_cpr_log {
699fe22e1c2SDamien Le Moal u8 nr_cpr;
7000e195481SKees Cook struct ata_cpr cpr[] __counted_by(nr_cpr);
701fe22e1c2SDamien Le Moal };
702fe22e1c2SDamien Le Moal
703602bcf21SDamien Le Moal struct ata_cdl {
704602bcf21SDamien Le Moal /*
705602bcf21SDamien Le Moal * Buffer to cache the CDL log page 18h (command duration descriptors)
706602bcf21SDamien Le Moal * for SCSI-ATA translation.
707602bcf21SDamien Le Moal */
708602bcf21SDamien Le Moal u8 desc_log_buf[ATA_LOG_CDL_SIZE];
709602bcf21SDamien Le Moal
710602bcf21SDamien Le Moal /*
711602bcf21SDamien Le Moal * Buffer to handle reading the sense data for successful NCQ Commands
712602bcf21SDamien Le Moal * log page for commands using a CDL with one of the limits policy set
713602bcf21SDamien Le Moal * to 0xD (successful completion with sense data available bit set).
714602bcf21SDamien Le Moal */
715602bcf21SDamien Le Moal u8 ncq_sense_log_buf[ATA_LOG_SENSE_NCQ_SIZE];
716602bcf21SDamien Le Moal };
717602bcf21SDamien Le Moal
7181da177e4SLinus Torvalds struct ata_device {
7199af5c9c9STejun Heo struct ata_link *link;
7201da177e4SLinus Torvalds unsigned int devno; /* 0 or 1 */
7217ebd8c5aSDamien Le Moal unsigned int quirks; /* List of broken features */
7226866e7bcSRichard Kennedy unsigned long flags; /* ATA_DFLAG_xxx */
7233edebac4STejun Heo struct scsi_device *sdev; /* attached SCSI device */
72495514fd8SBartlomiej Zolnierkiewicz void *private_data;
725fafbae87STejun Heo #ifdef CONFIG_ATA_ACPI
726398e0782STejun Heo union acpi_object *gtf_cache;
727110f66d2STejun Heo unsigned int gtf_filter;
728fafbae87STejun Heo #endif
729afe75951SAaron Lu #ifdef CONFIG_SATA_ZPODD
730afe75951SAaron Lu void *zpodd;
731afe75951SAaron Lu #endif
732d9027470SGwendal Grignou struct device tdev;
73399cf610aSTejun Heo /* n_sector is CLEAR_BEGIN, read comment above CLEAR_BEGIN */
73472fa4b74STejun Heo u64 n_sectors; /* size of device, if ATA */
7355920dadfSTejun Heo u64 n_native_sectors; /* native size, if ATA */
73672fa4b74STejun Heo unsigned int class; /* ATA_DEV_xxx */
73745fabbb7SElias Oltmanns unsigned long unpark_deadline;
738e0a71752STejun Heo
7391da177e4SLinus Torvalds u8 pio_mode;
7401da177e4SLinus Torvalds u8 dma_mode;
7411da177e4SLinus Torvalds u8 xfer_mode;
7421da177e4SLinus Torvalds unsigned int xfer_shift; /* ATA_SHIFT_xxx */
7431da177e4SLinus Torvalds
7448cbd6df1SAlbert Lee unsigned int multi_count; /* sectors count for
7458cbd6df1SAlbert Lee READ/WRITE MULTIPLE */
746b00eec1dSTejun Heo unsigned int max_sectors; /* per-device max sectors */
7476e7846e9STejun Heo unsigned int cdb_len;
7488bf62eceSAlbert Lee
749acf356b1STejun Heo /* per-dev xfer mask */
750f0a6d77bSSergey Shtylyov unsigned int pio_mask;
751f0a6d77bSSergey Shtylyov unsigned int mwdma_mask;
752f0a6d77bSSergey Shtylyov unsigned int udma_mask;
753acf356b1STejun Heo
7548bf62eceSAlbert Lee /* for CHS addressing */
7558bf62eceSAlbert Lee u16 cylinders; /* Number of cylinders */
7568bf62eceSAlbert Lee u16 heads; /* Number of heads */
7578bf62eceSAlbert Lee u16 sectors; /* Number of sectors per track */
7580c247c55STejun Heo
759f7e98930SJeff Garzik union {
760f7e98930SJeff Garzik u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
761f7e98930SJeff Garzik u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
7624ee34ea3SHarvey Hunt } ____cacheline_aligned;
76399cf610aSTejun Heo
764803739d2SShane Huang /* DEVSLP Timing Variables from Identify Device Data Log */
765803739d2SShane Huang u8 devslp_timing[ATA_LOG_DEVSLP_SIZE];
76665fe1f0fSShane Huang
767ed36911cSMarc Carino /* NCQ send and receive log subcommand support */
768ed36911cSMarc Carino u8 ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_SIZE];
769284b3b77SHannes Reinecke u8 ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_SIZE];
770ed36911cSMarc Carino
7716d1003aeSHannes Reinecke /* ZAC zone configuration */
7726d1003aeSHannes Reinecke u32 zac_zoned_cap;
7736d1003aeSHannes Reinecke u32 zac_zones_optimal_open;
7746d1003aeSHannes Reinecke u32 zac_zones_optimal_nonseq;
7756d1003aeSHannes Reinecke u32 zac_zones_max_open;
7766d1003aeSHannes Reinecke
777fe22e1c2SDamien Le Moal /* Concurrent positioning ranges */
778fe22e1c2SDamien Le Moal struct ata_cpr_log *cpr_log;
779fe22e1c2SDamien Le Moal
780602bcf21SDamien Le Moal /* Command Duration Limits support */
781602bcf21SDamien Le Moal struct ata_cdl *cdl;
78262e4a60eSDamien Le Moal
78399cf610aSTejun Heo /* error history */
78499cf610aSTejun Heo int spdn_cnt;
78599cf610aSTejun Heo /* ering is CLEAR_END, read comment above CLEAR_END */
78699cf610aSTejun Heo struct ata_ering ering;
787da65bbddSDamien Le Moal
788da65bbddSDamien Le Moal /* For EH */
789da65bbddSDamien Le Moal u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
7901da177e4SLinus Torvalds };
7911da177e4SLinus Torvalds
79299cf610aSTejun Heo /* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
79399cf610aSTejun Heo * cleared to zero on ata_dev_init().
79472fa4b74STejun Heo */
79599cf610aSTejun Heo #define ATA_DEVICE_CLEAR_BEGIN offsetof(struct ata_device, n_sectors)
79699cf610aSTejun Heo #define ATA_DEVICE_CLEAR_END offsetof(struct ata_device, ering)
79772fa4b74STejun Heo
798f3e81b19STejun Heo struct ata_eh_info {
799f3e81b19STejun Heo struct ata_device *dev; /* offending device */
800f3e81b19STejun Heo u32 serror; /* SError from LLDD */
801f3e81b19STejun Heo unsigned int err_mask; /* port-wide err_mask */
802f3e81b19STejun Heo unsigned int action; /* ATA_EH_* action mask */
80347005f25STejun Heo unsigned int dev_action[ATA_MAX_DEVICES]; /* dev EH action */
804f3e81b19STejun Heo unsigned int flags; /* ATA_EHI_* flags */
805abdda733STejun Heo
806abdda733STejun Heo unsigned int probe_mask;
807abdda733STejun Heo
808f3e81b19STejun Heo char desc[ATA_EH_DESC_LEN];
809f3e81b19STejun Heo int desc_len;
810f3e81b19STejun Heo };
811f3e81b19STejun Heo
812f3e81b19STejun Heo struct ata_eh_context {
813f3e81b19STejun Heo struct ata_eh_info i;
814f3e81b19STejun Heo int tries[ATA_MAX_DEVICES];
81587fbc5a0STejun Heo int cmd_timeout_idx[ATA_MAX_DEVICES]
81687fbc5a0STejun Heo [ATA_EH_CMD_TIMEOUT_TABLE_SIZE];
817abdda733STejun Heo unsigned int classes[ATA_MAX_DEVICES];
818abdda733STejun Heo unsigned int did_probe_mask;
81945fabbb7SElias Oltmanns unsigned int unloaded_mask;
82000115e0fSTejun Heo unsigned int saved_ncq_enabled;
82100115e0fSTejun Heo u8 saved_xfer_mode[ATA_MAX_DEVICES];
8220a2c0f56STejun Heo /* timestamp for the last reset attempt or success */
8230a2c0f56STejun Heo unsigned long last_reset;
824f3e81b19STejun Heo };
825f3e81b19STejun Heo
82664578a3dSTejun Heo struct ata_acpi_drive
82764578a3dSTejun Heo {
82864578a3dSTejun Heo u32 pio;
82964578a3dSTejun Heo u32 dma;
83064578a3dSTejun Heo } __packed;
83164578a3dSTejun Heo
83264578a3dSTejun Heo struct ata_acpi_gtm {
83364578a3dSTejun Heo struct ata_acpi_drive drive[2];
83464578a3dSTejun Heo u32 flags;
83564578a3dSTejun Heo } __packed;
83664578a3dSTejun Heo
8379af5c9c9STejun Heo struct ata_link {
8389af5c9c9STejun Heo struct ata_port *ap;
8398989805dSTejun Heo int pmp; /* port multiplier port # */
8409af5c9c9STejun Heo
841d9027470SGwendal Grignou struct device tdev;
8429af5c9c9STejun Heo unsigned int active_tag; /* active tag on this link */
8439af5c9c9STejun Heo u32 sactive; /* active NCQ commands */
8449af5c9c9STejun Heo
8450c88758bSTejun Heo unsigned int flags; /* ATA_LFLAG_xxx */
8460c88758bSTejun Heo
847d127ea7bSTejun Heo u32 saved_scontrol; /* SControl on probe */
8489af5c9c9STejun Heo unsigned int hw_sata_spd_limit;
8499af5c9c9STejun Heo unsigned int sata_spd_limit;
8509af5c9c9STejun Heo unsigned int sata_spd; /* current SATA PHY speed */
8516b7ae954STejun Heo enum ata_lpm_policy lpm_policy;
8529af5c9c9STejun Heo
8539af5c9c9STejun Heo /* record runtime error info, protected by host_set lock */
8549af5c9c9STejun Heo struct ata_eh_info eh_info;
8559af5c9c9STejun Heo /* EH context */
8569af5c9c9STejun Heo struct ata_eh_context eh_context;
8579af5c9c9STejun Heo
8589af5c9c9STejun Heo struct ata_device device[ATA_MAX_DEVICES];
85909c5b480SGabriele Mazzotta
86009c5b480SGabriele Mazzotta unsigned long last_lpm_change; /* when last LPM change happened */
8619af5c9c9STejun Heo };
862d9027470SGwendal Grignou #define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
863d9027470SGwendal Grignou #define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
8649af5c9c9STejun Heo
8651da177e4SLinus Torvalds struct ata_port {
866cca3974eSJeff Garzik struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
867029cfd6bSTejun Heo struct ata_port_operations *ops;
868ba6a1308SJeff Garzik spinlock_t *lock;
869e3cf95ddSAlan Cox /* Flags owned by the EH context. Only EH should touch these once the
870e3cf95ddSAlan Cox port is active */
8711da177e4SLinus Torvalds unsigned long flags; /* ATA_FLAG_xxx */
872e3cf95ddSAlan Cox /* Flags that change dynamically, protected by ap->lock */
873b51e9e5dSTejun Heo unsigned int pflags; /* ATA_PFLAG_xxx */
87444877b4eSTejun Heo unsigned int print_id; /* user visible unique port ID */
87544877b4eSTejun Heo unsigned int port_no; /* 0 based port no. inside the host */
8761da177e4SLinus Torvalds
877127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
8781da177e4SLinus Torvalds struct ata_ioports ioaddr; /* ATA cmd/ctl/dma register blocks */
8791da177e4SLinus Torvalds u8 ctl; /* cache of ATA control register */
8801da177e4SLinus Torvalds u8 last_ctl; /* Cache last written value */
881ea3c6450SGwendal Grignou struct ata_link* sff_pio_task_link; /* link currently used */
882c429137aSTejun Heo struct delayed_work sff_pio_task;
8839a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
884f60d7011STejun Heo struct ata_bmdma_prd *bmdma_prd; /* BMDMA SG list */
885f60d7011STejun Heo dma_addr_t bmdma_prd_dma; /* and its DMA mapping */
8869a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
8875fe7454aSTejun Heo #endif /* CONFIG_ATA_SFF */
8885fe7454aSTejun Heo
8891da177e4SLinus Torvalds unsigned int pio_mask;
8901da177e4SLinus Torvalds unsigned int mwdma_mask;
8911da177e4SLinus Torvalds unsigned int udma_mask;
8921da177e4SLinus Torvalds unsigned int cbl; /* cable type; ATA_CBL_xxx */
8931da177e4SLinus Torvalds
89428361c40SJens Axboe struct ata_queued_cmd qcmd[ATA_MAX_QUEUE + 1];
895e3ed8939SJens Axboe u64 qc_active;
896da917d69STejun Heo int nr_active_links; /* #links with active qcs */
897dedaf2b0STejun Heo
8989af5c9c9STejun Heo struct ata_link link; /* host default link */
899b1c72916STejun Heo struct ata_link *slave_link; /* see ata_slave_link_init() */
9001da177e4SLinus Torvalds
9018989805dSTejun Heo int nr_pmp_links; /* nr of available PMP links */
9028989805dSTejun Heo struct ata_link *pmp_link; /* array of PMP links */
903da917d69STejun Heo struct ata_link *excl_link; /* for PMP qc exclusion */
9048989805dSTejun Heo
905cca3974eSJeff Garzik struct ata_port_stats stats;
906cca3974eSJeff Garzik struct ata_host *host;
9072f1f610bSBrian King struct device *dev;
908d9027470SGwendal Grignou struct device tdev;
9091da177e4SLinus Torvalds
910ad72cf98STejun Heo struct mutex scsi_scan_mutex;
91152bad64dSDavid Howells struct delayed_work hotplug_task;
9126aa0365aSDamien Le Moal struct delayed_work scsi_rescan_task;
91386e45b6bSTejun Heo
91414be71f4SAlbert Lee unsigned int hsm_task_state;
9151da177e4SLinus Torvalds
916a72ec4ceSTejun Heo struct list_head eh_done_q;
917c6cf9e99STejun Heo wait_queue_head_t eh_wait_q;
918a1e10f7eSTejun Heo int eh_tries;
91945fabbb7SElias Oltmanns struct completion park_req_pending;
920bfd60579SRandy Dunlap
921500530f6STejun Heo pm_message_t pm_mesg;
9226b7ae954STejun Heo enum ata_lpm_policy target_lpm_policy;
923500530f6STejun Heo
9245ddf24c5STejun Heo struct timer_list fastdrain_timer;
9252e0aee8fSSergey Shtylyov unsigned int fastdrain_cnt;
9265ddf24c5STejun Heo
927b5292111SKai-Heng Feng async_cookie_t cookie;
928b5292111SKai-Heng Feng
92918f7ba4cSKristen Carlson Accardi int em_message_type;
9301da177e4SLinus Torvalds void *private_data;
931fe635c7eSTejun Heo
932fafbae87STejun Heo #ifdef CONFIG_ATA_ACPI
933c05e6ff0STejun Heo struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
934fafbae87STejun Heo #endif
9351da177e4SLinus Torvalds };
9361da177e4SLinus Torvalds
937029cfd6bSTejun Heo /* The following initializer overrides a method to NULL whether one of
938029cfd6bSTejun Heo * its parent has the method defined or not. This is equivalent to
939029cfd6bSTejun Heo * ERR_PTR(-ENOENT). Unfortunately, ERR_PTR doesn't render a constant
940029cfd6bSTejun Heo * expression and thus can't be used as an initializer.
941029cfd6bSTejun Heo */
942029cfd6bSTejun Heo #define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
943029cfd6bSTejun Heo
9441da177e4SLinus Torvalds struct ata_port_operations {
945c1bc899fSTejun Heo /*
946c1bc899fSTejun Heo * Command execution
947c1bc899fSTejun Heo */
94831cc23b3STejun Heo int (*qc_defer)(struct ata_queued_cmd *qc);
949c1bc899fSTejun Heo int (*check_atapi_dma)(struct ata_queued_cmd *qc);
95095364f36SJiri Slaby enum ata_completion_errors (*qc_prep)(struct ata_queued_cmd *qc);
9519a3d9eb0STejun Heo unsigned int (*qc_issue)(struct ata_queued_cmd *qc);
952931139afSDamien Le Moal void (*qc_fill_rtf)(struct ata_queued_cmd *qc);
95393c4aa44SNiklas Cassel void (*qc_ncq_fill_rtf)(struct ata_port *ap, u64 done_mask);
9541da177e4SLinus Torvalds
955c1bc899fSTejun Heo /*
956c1bc899fSTejun Heo * Configuration and exception handling
9579ec957f2STejun Heo */
958c1bc899fSTejun Heo int (*cable_detect)(struct ata_port *ap);
959f0a6d77bSSergey Shtylyov unsigned int (*mode_filter)(struct ata_device *dev, unsigned int xfer_mask);
960c1bc899fSTejun Heo void (*set_piomode)(struct ata_port *ap, struct ata_device *dev);
961c1bc899fSTejun Heo void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev);
962c1bc899fSTejun Heo int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev);
9630561e514SDamien Le Moal unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf,
9640561e514SDamien Le Moal __le16 *id);
965c1bc899fSTejun Heo
966c1bc899fSTejun Heo void (*dev_config)(struct ata_device *dev);
9679ec957f2STejun Heo
9689ec957f2STejun Heo void (*freeze)(struct ata_port *ap);
9699ec957f2STejun Heo void (*thaw)(struct ata_port *ap);
970a1efdabaSTejun Heo ata_prereset_fn_t prereset;
971a1efdabaSTejun Heo ata_reset_fn_t softreset;
972a1efdabaSTejun Heo ata_reset_fn_t hardreset;
973a1efdabaSTejun Heo ata_postreset_fn_t postreset;
974a1efdabaSTejun Heo ata_prereset_fn_t pmp_prereset;
975a1efdabaSTejun Heo ata_reset_fn_t pmp_softreset;
976a1efdabaSTejun Heo ata_reset_fn_t pmp_hardreset;
977a1efdabaSTejun Heo ata_postreset_fn_t pmp_postreset;
9789ec957f2STejun Heo void (*error_handler)(struct ata_port *ap);
979c96f1732SAlan Cox void (*lost_interrupt)(struct ata_port *ap);
9809ec957f2STejun Heo void (*post_internal_cmd)(struct ata_queued_cmd *qc);
981e4a9c373SDan Williams void (*sched_eh)(struct ata_port *ap);
982e4a9c373SDan Williams void (*end_eh)(struct ata_port *ap);
9831da177e4SLinus Torvalds
984c1bc899fSTejun Heo /*
985c1bc899fSTejun Heo * Optional features
986c1bc899fSTejun Heo */
98782ef04fbSTejun Heo int (*scr_read)(struct ata_link *link, unsigned int sc_reg, u32 *val);
98882ef04fbSTejun Heo int (*scr_write)(struct ata_link *link, unsigned int sc_reg, u32 val);
989c1bc899fSTejun Heo void (*pmp_attach)(struct ata_port *ap);
990c1bc899fSTejun Heo void (*pmp_detach)(struct ata_port *ap);
9916b7ae954STejun Heo int (*set_lpm)(struct ata_link *link, enum ata_lpm_policy policy,
9926b7ae954STejun Heo unsigned hints);
993c1bc899fSTejun Heo
994c1bc899fSTejun Heo /*
995c1bc899fSTejun Heo * Start, stop, suspend and resume
996c1bc899fSTejun Heo */
997c1bc899fSTejun Heo int (*port_suspend)(struct ata_port *ap, pm_message_t mesg);
998c1bc899fSTejun Heo int (*port_resume)(struct ata_port *ap);
9991da177e4SLinus Torvalds int (*port_start)(struct ata_port *ap);
10001da177e4SLinus Torvalds void (*port_stop)(struct ata_port *ap);
1001cca3974eSJeff Garzik void (*host_stop)(struct ata_host *host);
10021da177e4SLinus Torvalds
1003127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
1004c1bc899fSTejun Heo /*
1005c1bc899fSTejun Heo * SFF / taskfile oriented ops
1006c1bc899fSTejun Heo */
10075682ed33STejun Heo void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
100841dec29bSSergei Shtylyov void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
10095682ed33STejun Heo u8 (*sff_check_status)(struct ata_port *ap);
10105682ed33STejun Heo u8 (*sff_check_altstatus)(struct ata_port *ap);
10115682ed33STejun Heo void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
10125682ed33STejun Heo void (*sff_tf_read)(struct ata_port *ap, struct ata_taskfile *tf);
10135682ed33STejun Heo void (*sff_exec_command)(struct ata_port *ap,
10145682ed33STejun Heo const struct ata_taskfile *tf);
1015989e0aacSBartlomiej Zolnierkiewicz unsigned int (*sff_data_xfer)(struct ata_queued_cmd *qc,
10165682ed33STejun Heo unsigned char *buf, unsigned int buflen, int rw);
1017e42a542bSSergei Shtylyov void (*sff_irq_on)(struct ata_port *);
101827943620STejun Heo bool (*sff_irq_check)(struct ata_port *);
10195682ed33STejun Heo void (*sff_irq_clear)(struct ata_port *);
10208244cd05STejun Heo void (*sff_drain_fifo)(struct ata_queued_cmd *qc);
1021c1bc899fSTejun Heo
10229a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
1023c1bc899fSTejun Heo void (*bmdma_setup)(struct ata_queued_cmd *qc);
1024c1bc899fSTejun Heo void (*bmdma_start)(struct ata_queued_cmd *qc);
1025b73fc89fSAlan Cox void (*bmdma_stop)(struct ata_queued_cmd *qc);
10261da177e4SLinus Torvalds u8 (*bmdma_status)(struct ata_port *ap);
10279a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
1028127102aeSTejun Heo #endif /* CONFIG_ATA_SFF */
1029c1bc899fSTejun Heo
103018f7ba4cSKristen Carlson Accardi ssize_t (*em_show)(struct ata_port *ap, char *buf);
103118f7ba4cSKristen Carlson Accardi ssize_t (*em_store)(struct ata_port *ap, const char *message,
103218f7ba4cSKristen Carlson Accardi size_t size);
103318f7ba4cSKristen Carlson Accardi ssize_t (*sw_activity_show)(struct ata_device *dev, char *buf);
103418f7ba4cSKristen Carlson Accardi ssize_t (*sw_activity_store)(struct ata_device *dev,
103518f7ba4cSKristen Carlson Accardi enum sw_activity val);
1036439d7a35SMark Langsdorf ssize_t (*transmit_led_message)(struct ata_port *ap, u32 state,
1037439d7a35SMark Langsdorf ssize_t size);
1038439d7a35SMark Langsdorf
1039c1bc899fSTejun Heo /*
1040029cfd6bSTejun Heo * ->inherits must be the last field and all the preceding
1041029cfd6bSTejun Heo * fields must be pointers.
1042029cfd6bSTejun Heo */
1043029cfd6bSTejun Heo const struct ata_port_operations *inherits;
10441da177e4SLinus Torvalds };
10451da177e4SLinus Torvalds
10461da177e4SLinus Torvalds struct ata_port_info {
1047cca3974eSJeff Garzik unsigned long flags;
10480c88758bSTejun Heo unsigned long link_flags;
1049f0a6d77bSSergey Shtylyov unsigned int pio_mask;
1050f0a6d77bSSergey Shtylyov unsigned int mwdma_mask;
1051f0a6d77bSSergey Shtylyov unsigned int udma_mask;
1052029cfd6bSTejun Heo struct ata_port_operations *port_ops;
1053e99f8b5eSAlan Cox void *private_data;
10541da177e4SLinus Torvalds };
10551da177e4SLinus Torvalds
1056452503f9SAlan Cox struct ata_timing {
1057452503f9SAlan Cox unsigned short mode; /* ATA mode */
1058452503f9SAlan Cox unsigned short setup; /* t1 */
1059452503f9SAlan Cox unsigned short act8b; /* t2 for 8-bit I/O */
1060452503f9SAlan Cox unsigned short rec8b; /* t2i for 8-bit I/O */
1061452503f9SAlan Cox unsigned short cyc8b; /* t0 for 8-bit I/O */
1062452503f9SAlan Cox unsigned short active; /* t2 or tD */
1063452503f9SAlan Cox unsigned short recover; /* t2i or tK */
10643ada9c12SDavid Daney unsigned short dmack_hold; /* tj */
1065452503f9SAlan Cox unsigned short cycle; /* t0 */
1066452503f9SAlan Cox unsigned short udma; /* t2CYCTYP/2 */
1067452503f9SAlan Cox };
1068452503f9SAlan Cox
1069624d5c51STejun Heo /*
1070624d5c51STejun Heo * Core layer - drivers/ata/libata-core.c
1071624d5c51STejun Heo */
1072029cfd6bSTejun Heo extern struct ata_port_operations ata_dummy_port_ops;
107321b0ad4fSTejun Heo extern const struct ata_port_info ata_dummy_port_info;
1074dd5b06c4STejun Heo
ata_is_atapi(u8 prot)1075b1c04e80SChristoph Hellwig static inline bool ata_is_atapi(u8 prot)
1076dc34e7e1SSergei Shtylyov {
107737f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_ATAPI;
1078dc34e7e1SSergei Shtylyov }
1079dc34e7e1SSergei Shtylyov
ata_is_pio(u8 prot)1080b1c04e80SChristoph Hellwig static inline bool ata_is_pio(u8 prot)
1081dc34e7e1SSergei Shtylyov {
108237f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_PIO;
1083dc34e7e1SSergei Shtylyov }
1084dc34e7e1SSergei Shtylyov
ata_is_dma(u8 prot)1085b1c04e80SChristoph Hellwig static inline bool ata_is_dma(u8 prot)
1086dc34e7e1SSergei Shtylyov {
108737f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_DMA;
1088dc34e7e1SSergei Shtylyov }
1089dc34e7e1SSergei Shtylyov
ata_is_ncq(u8 prot)1090b1c04e80SChristoph Hellwig static inline bool ata_is_ncq(u8 prot)
1091dc34e7e1SSergei Shtylyov {
109237f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_NCQ;
1093dc34e7e1SSergei Shtylyov }
1094dc34e7e1SSergei Shtylyov
ata_is_data(u8 prot)1095b1c04e80SChristoph Hellwig static inline bool ata_is_data(u8 prot)
1096dc34e7e1SSergei Shtylyov {
109737f92d77SChristoph Hellwig return prot & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA);
1098dc34e7e1SSergei Shtylyov }
1099dc34e7e1SSergei Shtylyov
is_multi_taskfile(struct ata_taskfile * tf)1100dc34e7e1SSergei Shtylyov static inline int is_multi_taskfile(struct ata_taskfile *tf)
1101dc34e7e1SSergei Shtylyov {
1102dc34e7e1SSergei Shtylyov return (tf->command == ATA_CMD_READ_MULTI) ||
1103dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_WRITE_MULTI) ||
1104dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_READ_MULTI_EXT) ||
1105dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
1106dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
1107dc34e7e1SSergei Shtylyov }
1108dc34e7e1SSergei Shtylyov
ata_port_is_dummy(struct ata_port * ap)1109dd5b06c4STejun Heo static inline int ata_port_is_dummy(struct ata_port *ap)
1110dd5b06c4STejun Heo {
1111dd5b06c4STejun Heo return ap->ops == &ata_dummy_port_ops;
1112dd5b06c4STejun Heo }
1113dd5b06c4STejun Heo
ata_port_is_frozen(const struct ata_port * ap)1114fddb1a64SNiklas Cassel static inline bool ata_port_is_frozen(const struct ata_port *ap)
1115fddb1a64SNiklas Cassel {
1116fddb1a64SNiklas Cassel return ap->pflags & ATA_PFLAG_FROZEN;
1117fddb1a64SNiklas Cassel }
1118fddb1a64SNiklas Cassel
11190aa1113dSTejun Heo extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
1120aa2731adSTejun Heo extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
1121aa2731adSTejun Heo int (*check_ready)(struct ata_link *link));
1122203c75b8STejun Heo extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
11232855568bSJeff Garzik
112423262cceSNiklas Cassel extern struct ata_host *ata_host_alloc(struct device *dev, int n_ports);
1125f5cda257STejun Heo extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
1126f5cda257STejun Heo const struct ata_port_info * const * ppi, int n_ports);
11272fa4a326SJason Yan extern void ata_host_get(struct ata_host *host);
11282fa4a326SJason Yan extern void ata_host_put(struct ata_host *host);
1129ecef7253STejun Heo extern int ata_host_start(struct ata_host *host);
1130f3187195STejun Heo extern int ata_host_register(struct ata_host *host,
113125df73d9SBart Van Assche const struct scsi_host_template *sht);
1132f5cda257STejun Heo extern int ata_host_activate(struct ata_host *host, int irq,
1133f5cda257STejun Heo irq_handler_t irq_handler, unsigned long irq_flags,
113425df73d9SBart Van Assche const struct scsi_host_template *sht);
11350529c159STejun Heo extern void ata_host_detach(struct ata_host *host);
11368d8e7d13SDan Williams extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
11376f4e626fSNathan Chancellor extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
11386f4e626fSNathan Chancellor void __user *arg);
113975c0b0e1SArnd Bergmann #ifdef CONFIG_COMPAT
114075c0b0e1SArnd Bergmann #define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
114175c0b0e1SArnd Bergmann #else
114275c0b0e1SArnd Bergmann #define ATA_SCSI_COMPAT_IOCTL /* empty */
114375c0b0e1SArnd Bergmann #endif
1144f281233dSJeff Garzik extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1145aad4b4d1SChristoph Hellwig #if IS_REACHABLE(CONFIG_ATA)
1146cc97923aSChristoph Hellwig bool ata_scsi_dma_need_drain(struct request *rq);
11477bb7ee87SChristoph Hellwig #else
11487bb7ee87SChristoph Hellwig #define ata_scsi_dma_need_drain NULL
11497bb7ee87SChristoph Hellwig #endif
115094be9a58SJeff Garzik extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
11516f4e626fSNathan Chancellor unsigned int cmd, void __user *arg);
1152b5b3fa38STejun Heo extern bool ata_link_online(struct ata_link *link);
1153b5b3fa38STejun Heo extern bool ata_link_offline(struct ata_link *link);
11546ffa01d8STejun Heo #ifdef CONFIG_PM
1155ec87cf37SSergey Shtylyov extern void ata_host_suspend(struct ata_host *host, pm_message_t mesg);
1156cca3974eSJeff Garzik extern void ata_host_resume(struct ata_host *host);
1157bc6e7c4bSDan Williams extern void ata_sas_port_suspend(struct ata_port *ap);
1158bc6e7c4bSDan Williams extern void ata_sas_port_resume(struct ata_port *ap);
11592fcbdcb4SDan Williams #else
ata_sas_port_suspend(struct ata_port * ap)1160bc6e7c4bSDan Williams static inline void ata_sas_port_suspend(struct ata_port *ap)
11612fcbdcb4SDan Williams {
11622fcbdcb4SDan Williams }
ata_sas_port_resume(struct ata_port * ap)1163a5a65699SRandy Dunlap static inline void ata_sas_port_resume(struct ata_port *ap)
1164a5a65699SRandy Dunlap {
1165a5a65699SRandy Dunlap }
11666ffa01d8STejun Heo #endif
116767846b30SJeff Garzik extern int ata_ratelimit(void);
116897750cebSTejun Heo extern void ata_msleep(struct ata_port *ap, unsigned int msecs);
116997750cebSTejun Heo extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
117084abed36SSergey Shtylyov u32 val, unsigned int interval, unsigned int timeout);
1171436d34b3STejun Heo extern int atapi_cmd_type(u8 opcode);
1172f0a6d77bSSergey Shtylyov extern unsigned int ata_pack_xfermask(unsigned int pio_mask,
1173f0a6d77bSSergey Shtylyov unsigned int mwdma_mask,
1174f0a6d77bSSergey Shtylyov unsigned int udma_mask);
1175f0a6d77bSSergey Shtylyov extern void ata_unpack_xfermask(unsigned int xfer_mask,
1176f0a6d77bSSergey Shtylyov unsigned int *pio_mask,
1177f0a6d77bSSergey Shtylyov unsigned int *mwdma_mask,
1178f0a6d77bSSergey Shtylyov unsigned int *udma_mask);
1179f0a6d77bSSergey Shtylyov extern u8 ata_xfer_mask2mode(unsigned int xfer_mask);
1180f0a6d77bSSergey Shtylyov extern unsigned int ata_xfer_mode2mask(u8 xfer_mode);
1181a28c1ab3SSergey Shtylyov extern int ata_xfer_mode2shift(u8 xfer_mode);
1182f0a6d77bSSergey Shtylyov extern const char *ata_mode_string(unsigned int xfer_mask);
1183f0a6d77bSSergey Shtylyov extern unsigned int ata_id_xfermask(const u16 *id);
118431cc23b3STejun Heo extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
11851da177e4SLinus Torvalds extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
11861da177e4SLinus Torvalds unsigned int n_elem);
1187057ace5eSJeff Garzik extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
11886c952a0dSHannes Reinecke extern unsigned int ata_port_classify(struct ata_port *ap,
11896c952a0dSHannes Reinecke const struct ata_taskfile *tf);
119010305f0fSAlan extern void ata_dev_disable(struct ata_device *adev);
11916a62a04dSTejun Heo extern void ata_id_string(const u16 *id, unsigned char *s,
11921da177e4SLinus Torvalds unsigned int ofs, unsigned int len);
11936a62a04dSTejun Heo extern void ata_id_c_string(const u16 *id, unsigned char *s,
11940e949ff3STejun Heo unsigned int ofs, unsigned int len);
1195963e4975SAlan Cox extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
11960561e514SDamien Le Moal struct ata_taskfile *tf, __le16 *id);
1197f686bcb8STejun Heo extern void ata_qc_complete(struct ata_queued_cmd *qc);
11988385d756SSascha Hauer extern u64 ata_qc_get_active(struct ata_port *ap);
1199b27dcfb0SJeff Garzik extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
12001da177e4SLinus Torvalds extern int ata_std_bios_param(struct scsi_device *sdev,
12011da177e4SLinus Torvalds struct block_device *bdev,
12021da177e4SLinus Torvalds sector_t capacity, int geom[]);
1203d8d9129eSTejun Heo extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
1204fb99ef17SDamien Le Moal extern int ata_scsi_sdev_init(struct scsi_device *sdev);
1205a25a9c85SChristoph Hellwig int ata_scsi_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim);
1206a25a9c85SChristoph Hellwig extern void ata_scsi_sdev_destroy(struct scsi_device *sdev);
120783c47bcbSTejun Heo extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
1208a6e6ce8eSTejun Heo int queue_depth);
1209db5ed4dfSChristoph Hellwig extern int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1210371b74c8SDamien Le Moal int queue_depth);
1211371b74c8SDamien Le Moal extern int ata_ncq_prio_supported(struct ata_port *ap, struct scsi_device *sdev,
1212abeded46SIgor Pylypiv bool *supported);
1213abeded46SIgor Pylypiv extern int ata_ncq_prio_enabled(struct ata_port *ap, struct scsi_device *sdev,
1214abeded46SIgor Pylypiv bool *enabled);
1215abeded46SIgor Pylypiv extern int ata_ncq_prio_enable(struct ata_port *ap, struct scsi_device *sdev,
1216abeded46SIgor Pylypiv bool enable);
1217abeded46SIgor Pylypiv extern struct ata_device *ata_dev_pair(struct ata_device *adev);
12183373efd8STejun Heo extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
12190260731fSTejun Heo extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
12200e0b494cSJames Bottomley extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
12210e0b494cSJames Bottomley
12227fe183c7SBartlomiej Zolnierkiewicz /*
12237fe183c7SBartlomiej Zolnierkiewicz * SATA specific code - drivers/ata/libata-sata.c
12247fe183c7SBartlomiej Zolnierkiewicz */
12257fe183c7SBartlomiej Zolnierkiewicz #ifdef CONFIG_SATA_HOST
12266eab1bc0SBartlomiej Zolnierkiewicz extern const unsigned int sata_deb_timing_normal[];
1227d14d41ccSSergey Shtylyov extern const unsigned int sata_deb_timing_hotplug[];
1228d14d41ccSSergey Shtylyov extern const unsigned int sata_deb_timing_long[];
1229d14d41ccSSergey Shtylyov
12302b384edeSBartlomiej Zolnierkiewicz static inline const unsigned int *
sata_ehc_deb_timing(struct ata_eh_context * ehc)1231d14d41ccSSergey Shtylyov sata_ehc_deb_timing(struct ata_eh_context *ehc)
12322b384edeSBartlomiej Zolnierkiewicz {
12332b384edeSBartlomiej Zolnierkiewicz if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
12342b384edeSBartlomiej Zolnierkiewicz return sata_deb_timing_hotplug;
12352b384edeSBartlomiej Zolnierkiewicz else
12362b384edeSBartlomiej Zolnierkiewicz return sata_deb_timing_normal;
12372b384edeSBartlomiej Zolnierkiewicz }
12382b384edeSBartlomiej Zolnierkiewicz
12392b384edeSBartlomiej Zolnierkiewicz extern int sata_scr_valid(struct ata_link *link);
12406eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
12416eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
12426eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
12436eab1bc0SBartlomiej Zolnierkiewicz extern int sata_set_spd(struct ata_link *link);
1244ab4117cfSBartlomiej Zolnierkiewicz int sata_std_hardreset(struct ata_link *link, unsigned int *class,
124578f76b09SDamien Le Moal unsigned long deadline);
124678f76b09SDamien Le Moal extern int sata_link_hardreset(struct ata_link *link,
124778c97c80SBartlomiej Zolnierkiewicz const unsigned int *timing, unsigned long deadline,
1248d14d41ccSSergey Shtylyov bool *online, int (*check_ready)(struct ata_link *));
124978c97c80SBartlomiej Zolnierkiewicz extern int sata_link_resume(struct ata_link *link, const unsigned int *params,
1250d14d41ccSSergey Shtylyov unsigned long deadline);
12519d3158f5SBartlomiej Zolnierkiewicz extern void ata_eh_analyze_ncq_error(struct ata_link *link);
1252a0ccd251SBartlomiej Zolnierkiewicz #else
12536eab1bc0SBartlomiej Zolnierkiewicz static inline const unsigned int *
sata_ehc_deb_timing(struct ata_eh_context * ehc)1254d14d41ccSSergey Shtylyov sata_ehc_deb_timing(struct ata_eh_context *ehc)
12552b384edeSBartlomiej Zolnierkiewicz {
12562b384edeSBartlomiej Zolnierkiewicz return NULL;
12572b384edeSBartlomiej Zolnierkiewicz }
sata_scr_valid(struct ata_link * link)12582b384edeSBartlomiej Zolnierkiewicz static inline int sata_scr_valid(struct ata_link *link) { return 0; }
sata_scr_read(struct ata_link * link,int reg,u32 * val)12596eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
12606eab1bc0SBartlomiej Zolnierkiewicz {
12616eab1bc0SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12626eab1bc0SBartlomiej Zolnierkiewicz }
sata_scr_write(struct ata_link * link,int reg,u32 val)12636eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
12646eab1bc0SBartlomiej Zolnierkiewicz {
12656eab1bc0SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12666eab1bc0SBartlomiej Zolnierkiewicz }
sata_scr_write_flush(struct ata_link * link,int reg,u32 val)12676eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
12686eab1bc0SBartlomiej Zolnierkiewicz {
12696eab1bc0SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12706eab1bc0SBartlomiej Zolnierkiewicz }
sata_set_spd(struct ata_link * link)12716eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
sata_std_hardreset(struct ata_link * link,unsigned int * class,unsigned long deadline)1272ab4117cfSBartlomiej Zolnierkiewicz static inline int sata_std_hardreset(struct ata_link *link, unsigned int *class,
127378f76b09SDamien Le Moal unsigned long deadline)
127478f76b09SDamien Le Moal {
127578f76b09SDamien Le Moal return -EOPNOTSUPP;
127678f76b09SDamien Le Moal }
sata_link_hardreset(struct ata_link * link,const unsigned int * timing,unsigned long deadline,bool * online,int (* check_ready)(struct ata_link *))127778f76b09SDamien Le Moal static inline int sata_link_hardreset(struct ata_link *link,
127878c97c80SBartlomiej Zolnierkiewicz const unsigned int *timing,
1279d14d41ccSSergey Shtylyov unsigned long deadline,
128078c97c80SBartlomiej Zolnierkiewicz bool *online,
128178c97c80SBartlomiej Zolnierkiewicz int (*check_ready)(struct ata_link *))
128278c97c80SBartlomiej Zolnierkiewicz {
128378c97c80SBartlomiej Zolnierkiewicz if (online)
128478c97c80SBartlomiej Zolnierkiewicz *online = false;
128578c97c80SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
128678c97c80SBartlomiej Zolnierkiewicz }
sata_link_resume(struct ata_link * link,const unsigned int * params,unsigned long deadline)128778c97c80SBartlomiej Zolnierkiewicz static inline int sata_link_resume(struct ata_link *link,
12889d3158f5SBartlomiej Zolnierkiewicz const unsigned int *params,
1289d14d41ccSSergey Shtylyov unsigned long deadline)
12909d3158f5SBartlomiej Zolnierkiewicz {
12919d3158f5SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12929d3158f5SBartlomiej Zolnierkiewicz }
ata_eh_analyze_ncq_error(struct ata_link * link)12939d3158f5SBartlomiej Zolnierkiewicz static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
1294a0ccd251SBartlomiej Zolnierkiewicz #endif
12956eab1bc0SBartlomiej Zolnierkiewicz extern int sata_link_debounce(struct ata_link *link,
12969d3158f5SBartlomiej Zolnierkiewicz const unsigned int *params, unsigned long deadline);
1297d14d41ccSSergey Shtylyov extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
12987fe183c7SBartlomiej Zolnierkiewicz bool spm_wakeup);
12997fe183c7SBartlomiej Zolnierkiewicz extern int ata_slave_link_init(struct ata_port *ap);
13007fe183c7SBartlomiej Zolnierkiewicz extern void ata_port_probe(struct ata_port *ap);
1301a76f1b63SHannes Reinecke extern struct ata_port *ata_port_alloc(struct ata_host *host);
13020d3603acSNiklas Cassel extern void ata_port_free(struct ata_port *ap);
1303f6549f53SNiklas Cassel extern int ata_tport_add(struct device *parent, struct ata_port *ap);
1304c10bc561SNiklas Cassel extern void ata_tport_delete(struct ata_port *ap);
1305c10bc561SNiklas Cassel int ata_sas_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim,
1306a25a9c85SChristoph Hellwig struct ata_port *ap);
1307a25a9c85SChristoph Hellwig extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
130815964ff7SBartlomiej Zolnierkiewicz extern void ata_tf_to_fis(const struct ata_taskfile *tf,
13097fe183c7SBartlomiej Zolnierkiewicz u8 pmp, int is_cmd, u8 *fis);
13107fe183c7SBartlomiej Zolnierkiewicz extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
13117fe183c7SBartlomiej Zolnierkiewicz extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
131261a11986SBartlomiej Zolnierkiewicz extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
13138393b811SGabriele Mazzotta extern int sata_async_notification(struct ata_port *ap);
1314a695de27SBartlomiej Zolnierkiewicz
13151da177e4SLinus Torvalds extern int ata_cable_40wire(struct ata_port *ap);
1316be0d18dfSAlan Cox extern int ata_cable_80wire(struct ata_port *ap);
1317be0d18dfSAlan Cox extern int ata_cable_sata(struct ata_port *ap);
1318be0d18dfSAlan Cox extern int ata_cable_ignore(struct ata_port *ap);
1319c88f90c3STejun Heo extern int ata_cable_unknown(struct ata_port *ap);
1320be0d18dfSAlan Cox
1321be0d18dfSAlan Cox /* Timing helpers */
1322624d5c51STejun Heo extern unsigned int ata_pio_need_iordy(const struct ata_device *);
13231bc4ccffSAlan Cox extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
1324a0f79b92STejun Heo
1325452503f9SAlan Cox /* PCI */
1326624d5c51STejun Heo #ifdef CONFIG_PCI
1327624d5c51STejun Heo struct pci_dev;
1328624d5c51STejun Heo
1329624d5c51STejun Heo struct pci_bits {
1330624d5c51STejun Heo unsigned int reg; /* PCI config register to read */
1331624d5c51STejun Heo unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
1332624d5c51STejun Heo unsigned long mask;
1333624d5c51STejun Heo unsigned long val;
1334624d5c51STejun Heo };
1335452503f9SAlan Cox
1336452503f9SAlan Cox extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
1337624d5c51STejun Heo extern void ata_pci_shutdown_one(struct pci_dev *pdev);
133810a663a1SPrabhakar Kushwaha extern void ata_pci_remove_one(struct pci_dev *pdev);
1339624d5c51STejun Heo
1340624d5c51STejun Heo #ifdef CONFIG_PM
1341624d5c51STejun Heo extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
1342624d5c51STejun Heo extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
1343624d5c51STejun Heo extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
1344624d5c51STejun Heo extern int ata_pci_device_resume(struct pci_dev *pdev);
1345624d5c51STejun Heo #endif /* CONFIG_PM */
1346624d5c51STejun Heo #endif /* CONFIG_PCI */
1347624d5c51STejun Heo
1348624d5c51STejun Heo struct platform_device;
1349b7db04d9SBrian Norris
1350b7db04d9SBrian Norris extern void ata_platform_remove_one(struct platform_device *pdev);
1351a7eb54d4SUwe Kleine-König
1352b7db04d9SBrian Norris /*
1353624d5c51STejun Heo * ACPI - drivers/ata/libata-acpi.c
1354624d5c51STejun Heo */
1355624d5c51STejun Heo #ifdef CONFIG_ATA_ACPI
ata_acpi_init_gtm(struct ata_port * ap)1356e1ddb4b6SAlan Cox static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1357c05e6ff0STejun Heo {
1358c05e6ff0STejun Heo if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID)
1359c05e6ff0STejun Heo return &ap->__acpi_init_gtm;
1360c05e6ff0STejun Heo return NULL;
1361c05e6ff0STejun Heo }
1362c05e6ff0STejun Heo int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
13630d02f0b2STejun Heo int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
13640d02f0b2STejun Heo unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
1365f0a6d77bSSergey Shtylyov const struct ata_acpi_gtm *gtm);
13667c77fa4dSTejun Heo int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
1367021ee9a6STejun Heo #else
ata_acpi_init_gtm(struct ata_port * ap)1368e1ddb4b6SAlan Cox static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1369c05e6ff0STejun Heo {
1370c05e6ff0STejun Heo return NULL;
1371c05e6ff0STejun Heo }
1372c05e6ff0STejun Heo
ata_acpi_stm(const struct ata_port * ap,struct ata_acpi_gtm * stm)13737c77fa4dSTejun Heo static inline int ata_acpi_stm(const struct ata_port *ap,
13747c77fa4dSTejun Heo struct ata_acpi_gtm *stm)
13757c77fa4dSTejun Heo {
13767c77fa4dSTejun Heo return -ENOSYS;
13777c77fa4dSTejun Heo }
13787c77fa4dSTejun Heo
ata_acpi_gtm(const struct ata_port * ap,struct ata_acpi_gtm * stm)13797c77fa4dSTejun Heo static inline int ata_acpi_gtm(const struct ata_port *ap,
13807c77fa4dSTejun Heo struct ata_acpi_gtm *stm)
13817c77fa4dSTejun Heo {
13827c77fa4dSTejun Heo return -ENOSYS;
13837c77fa4dSTejun Heo }
13847c77fa4dSTejun Heo
ata_acpi_gtm_xfermask(struct ata_device * dev,const struct ata_acpi_gtm * gtm)13857c77fa4dSTejun Heo static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
13867c77fa4dSTejun Heo const struct ata_acpi_gtm *gtm)
13877c77fa4dSTejun Heo {
13887c77fa4dSTejun Heo return 0;
13897c77fa4dSTejun Heo }
13907c77fa4dSTejun Heo
ata_acpi_cbl_80wire(struct ata_port * ap,const struct ata_acpi_gtm * gtm)1391021ee9a6STejun Heo static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
1392021ee9a6STejun Heo const struct ata_acpi_gtm *gtm)
1393021ee9a6STejun Heo {
1394021ee9a6STejun Heo return 0;
1395021ee9a6STejun Heo }
1396021ee9a6STejun Heo #endif
1397e1ddb4b6SAlan Cox
13981da177e4SLinus Torvalds /*
1399ece1d636STejun Heo * EH - drivers/ata/libata-eh.c
1400624d5c51STejun Heo */
1401ece1d636STejun Heo extern void ata_port_schedule_eh(struct ata_port *ap);
14027b70fc03STejun Heo extern void ata_port_wait_eh(struct ata_port *ap);
140381c757bcSDan Williams extern int ata_link_abort(struct ata_link *link);
1404dbd82616STejun Heo extern int ata_port_abort(struct ata_port *ap);
14057b70fc03STejun Heo extern int ata_port_freeze(struct ata_port *ap);
1406e3180499STejun Heo
1407e3180499STejun Heo extern void ata_eh_freeze_port(struct ata_port *ap);
1408e3180499STejun Heo extern void ata_eh_thaw_port(struct ata_port *ap);
1409e3180499STejun Heo
14107b70fc03STejun Heo extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
1411ece1d636STejun Heo extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1412ece1d636STejun Heo
1413ece1d636STejun Heo extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1414f5914a46STejun Heo ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1415f5914a46STejun Heo ata_postreset_fn_t postreset);
1416f5914a46STejun Heo extern void ata_std_error_handler(struct ata_port *ap);
1417a1efdabaSTejun Heo extern void ata_std_sched_eh(struct ata_port *ap);
1418e4a9c373SDan Williams extern void ata_std_end_eh(struct ata_port *ap);
1419e4a9c373SDan Williams extern int ata_link_nr_enabled(struct ata_link *link);
14208a745f1fSKristen Carlson Accardi
1421022bdb07STejun Heo /*
142261440db6STejun Heo * Base operations to inherit from and initializers for sht
142368d1d07bSTejun Heo *
142468d1d07bSTejun Heo * Operations
142568d1d07bSTejun Heo *
142668d1d07bSTejun Heo * base : Common to all libata drivers.
142768d1d07bSTejun Heo * sata : SATA controllers w/ native interface.
142868d1d07bSTejun Heo * pmp : SATA controllers w/ PMP support.
142968d1d07bSTejun Heo * sff : SFF ATA controllers w/o BMDMA support.
143068d1d07bSTejun Heo * bmdma : SFF ATA controllers w/ BMDMA support.
143168d1d07bSTejun Heo *
143268d1d07bSTejun Heo * sht initializers
143368d1d07bSTejun Heo *
143468d1d07bSTejun Heo * BASE : Common to all libata drivers. The user must set
143568d1d07bSTejun Heo * sg_tablesize and dma_boundary.
143668d1d07bSTejun Heo * PIO : SFF ATA controllers w/ only PIO support.
143768d1d07bSTejun Heo * BMDMA : SFF ATA controllers w/ BMDMA support. sg_tablesize and
143868d1d07bSTejun Heo * dma_boundary are set to BMDMA limits.
143968d1d07bSTejun Heo * NCQ : SATA controllers supporting NCQ. The user must set
144068d1d07bSTejun Heo * sg_tablesize, dma_boundary and can_queue.
144168d1d07bSTejun Heo */
144268d1d07bSTejun Heo extern const struct ata_port_operations ata_base_port_ops;
144368d1d07bSTejun Heo extern const struct ata_port_operations sata_port_ops;
144468d1d07bSTejun Heo extern const struct attribute_group *ata_common_sdev_groups[];
1445c3f69c7fSBart Van Assche
144668d1d07bSTejun Heo /*
1447018d5ef2SAkinobu Mita * All sht initializers (BASE, PIO, BMDMA, NCQ) must be instantiated
1448018d5ef2SAkinobu Mita * by the edge drivers. Because the 'module' field of sht must be the
1449018d5ef2SAkinobu Mita * edge driver's module reference, otherwise the driver can be unloaded
1450018d5ef2SAkinobu Mita * even if the scsi_device is being accessed.
1451018d5ef2SAkinobu Mita */
1452018d5ef2SAkinobu Mita #define __ATA_BASE_SHT(drv_name) \
14536f09eae3SBartlomiej Zolnierkiewicz .module = THIS_MODULE, \
145468d1d07bSTejun Heo .name = drv_name, \
145568d1d07bSTejun Heo .ioctl = ata_scsi_ioctl, \
145668d1d07bSTejun Heo ATA_SCSI_COMPAT_IOCTL \
145775c0b0e1SArnd Bergmann .queuecommand = ata_scsi_queuecmd, \
145868d1d07bSTejun Heo .dma_need_drain = ata_scsi_dma_need_drain, \
1459cc97923aSChristoph Hellwig .this_id = ATA_SHT_THIS_ID, \
146068d1d07bSTejun Heo .emulated = ATA_SHT_EMULATED, \
146168d1d07bSTejun Heo .proc_name = drv_name, \
146268d1d07bSTejun Heo .sdev_init = ata_scsi_sdev_init, \
1463fb99ef17SDamien Le Moal .sdev_destroy = ata_scsi_sdev_destroy, \
146468d1d07bSTejun Heo .bios_param = ata_std_bios_param, \
146545fabbb7SElias Oltmanns .unlock_native_capacity = ata_scsi_unlock_native_capacity,\
1466a357f7b4SJohn Garry .max_sectors = ATA_MAX_SECTORS_LBA48
1467a357f7b4SJohn Garry
14686f09eae3SBartlomiej Zolnierkiewicz #define ATA_SUBBASE_SHT(drv_name) \
14694e7dba07SLee Jones __ATA_BASE_SHT(drv_name), \
14706f09eae3SBartlomiej Zolnierkiewicz .can_queue = ATA_DEF_QUEUE, \
14714e7dba07SLee Jones .tag_alloc_policy_rr = true, \
14724e7dba07SLee Jones .sdev_configure = ata_scsi_sdev_configure
1473a25a9c85SChristoph Hellwig
14744e7dba07SLee Jones #define ATA_SUBBASE_SHT_QD(drv_name, drv_qd) \
1475e5b48ee3SDamien Le Moal __ATA_BASE_SHT(drv_name), \
1476e5b48ee3SDamien Le Moal .can_queue = drv_qd, \
1477e5b48ee3SDamien Le Moal .tag_alloc_policy_rr = true, \
1478e5b48ee3SDamien Le Moal .sdev_configure = ata_scsi_sdev_configure
1479a25a9c85SChristoph Hellwig
1480e5b48ee3SDamien Le Moal #define ATA_BASE_SHT(drv_name) \
14814e7dba07SLee Jones ATA_SUBBASE_SHT(drv_name), \
14824e7dba07SLee Jones .sdev_groups = ata_common_sdev_groups
1483c3f69c7fSBart Van Assche
148468d1d07bSTejun Heo #ifdef CONFIG_SATA_HOST
1485ec811a94SBartlomiej Zolnierkiewicz extern const struct attribute_group *ata_ncq_sdev_groups[];
1486c3f69c7fSBart Van Assche
1487ec811a94SBartlomiej Zolnierkiewicz #define ATA_NCQ_SHT(drv_name) \
148868d1d07bSTejun Heo ATA_SUBBASE_SHT(drv_name), \
14894e7dba07SLee Jones .sdev_groups = ata_ncq_sdev_groups, \
1490c3f69c7fSBart Van Assche .change_queue_depth = ata_scsi_change_queue_depth
149168d1d07bSTejun Heo
1492e5b48ee3SDamien Le Moal #define ATA_NCQ_SHT_QD(drv_name, drv_qd) \
1493e5b48ee3SDamien Le Moal ATA_SUBBASE_SHT_QD(drv_name, drv_qd), \
1494e5b48ee3SDamien Le Moal .sdev_groups = ata_ncq_sdev_groups, \
1495e5b48ee3SDamien Le Moal .change_queue_depth = ata_scsi_change_queue_depth
1496e5b48ee3SDamien Le Moal #endif
1497ec811a94SBartlomiej Zolnierkiewicz
149868d1d07bSTejun Heo /*
149968d1d07bSTejun Heo * PMP helpers
1500071f44b1STejun Heo */
1501071f44b1STejun Heo #ifdef CONFIG_SATA_PMP
sata_pmp_supported(struct ata_port * ap)150288fcd562STejun Heo static inline bool sata_pmp_supported(struct ata_port *ap)
1503071f44b1STejun Heo {
1504071f44b1STejun Heo return ap->flags & ATA_FLAG_PMP;
1505071f44b1STejun Heo }
1506071f44b1STejun Heo
sata_pmp_attached(struct ata_port * ap)1507071f44b1STejun Heo static inline bool sata_pmp_attached(struct ata_port *ap)
1508071f44b1STejun Heo {
1509071f44b1STejun Heo return ap->nr_pmp_links != 0;
1510071f44b1STejun Heo }
1511071f44b1STejun Heo
ata_is_host_link(const struct ata_link * link)1512071f44b1STejun Heo static inline bool ata_is_host_link(const struct ata_link *link)
1513b1c04e80SChristoph Hellwig {
1514071f44b1STejun Heo return link == &link->ap->link || link == link->ap->slave_link;
1515b1c72916STejun Heo }
1516071f44b1STejun Heo #else /* CONFIG_SATA_PMP */
sata_pmp_supported(struct ata_port * ap)151788fcd562STejun Heo static inline bool sata_pmp_supported(struct ata_port *ap)
151888fcd562STejun Heo {
151988fcd562STejun Heo return false;
152088fcd562STejun Heo }
152188fcd562STejun Heo
sata_pmp_attached(struct ata_port * ap)152288fcd562STejun Heo static inline bool sata_pmp_attached(struct ata_port *ap)
152388fcd562STejun Heo {
152488fcd562STejun Heo return false;
152588fcd562STejun Heo }
152688fcd562STejun Heo
ata_is_host_link(const struct ata_link * link)152788fcd562STejun Heo static inline bool ata_is_host_link(const struct ata_link *link)
1528b1c04e80SChristoph Hellwig {
152988fcd562STejun Heo return true;
153062283c6cSJing Yangyang }
153188fcd562STejun Heo #endif /* CONFIG_SATA_PMP */
153288fcd562STejun Heo
sata_srst_pmp(struct ata_link * link)1533071f44b1STejun Heo static inline int sata_srst_pmp(struct ata_link *link)
1534071f44b1STejun Heo {
1535071f44b1STejun Heo if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
1536071f44b1STejun Heo return SATA_PMP_CTRL_PORT;
1537071f44b1STejun Heo return link->pmp;
1538071f44b1STejun Heo }
1539071f44b1STejun Heo
1540071f44b1STejun Heo #define ata_port_printk(level, ap, fmt, ...) \
1541742bef47SHannes Reinecke pr_ ## level ("ata%u: " fmt, (ap)->print_id, ##__VA_ARGS__)
1542742bef47SHannes Reinecke
15431da177e4SLinus Torvalds #define ata_port_err(ap, fmt, ...) \
1544a9a79dfeSJoe Perches ata_port_printk(err, ap, fmt, ##__VA_ARGS__)
1545742bef47SHannes Reinecke #define ata_port_warn(ap, fmt, ...) \
1546a9a79dfeSJoe Perches ata_port_printk(warn, ap, fmt, ##__VA_ARGS__)
1547742bef47SHannes Reinecke #define ata_port_notice(ap, fmt, ...) \
1548a9a79dfeSJoe Perches ata_port_printk(notice, ap, fmt, ##__VA_ARGS__)
1549742bef47SHannes Reinecke #define ata_port_info(ap, fmt, ...) \
1550a9a79dfeSJoe Perches ata_port_printk(info, ap, fmt, ##__VA_ARGS__)
1551742bef47SHannes Reinecke #define ata_port_dbg(ap, fmt, ...) \
1552a9a79dfeSJoe Perches ata_port_printk(debug, ap, fmt, ##__VA_ARGS__)
1553742bef47SHannes Reinecke
1554742bef47SHannes Reinecke #define ata_link_printk(level, link, fmt, ...) \
1555742bef47SHannes Reinecke do { \
1556742bef47SHannes Reinecke if (sata_pmp_attached((link)->ap) || \
1557742bef47SHannes Reinecke (link)->ap->slave_link) \
1558742bef47SHannes Reinecke pr_ ## level ("ata%u.%02u: " fmt, \
1559742bef47SHannes Reinecke (link)->ap->print_id, \
1560742bef47SHannes Reinecke (link)->pmp, \
1561742bef47SHannes Reinecke ##__VA_ARGS__); \
1562742bef47SHannes Reinecke else \
1563742bef47SHannes Reinecke pr_ ## level ("ata%u: " fmt, \
1564742bef47SHannes Reinecke (link)->ap->print_id, \
1565742bef47SHannes Reinecke ##__VA_ARGS__); \
1566742bef47SHannes Reinecke } while (0)
1567742bef47SHannes Reinecke
15689af5c9c9STejun Heo #define ata_link_err(link, fmt, ...) \
1569a9a79dfeSJoe Perches ata_link_printk(err, link, fmt, ##__VA_ARGS__)
1570742bef47SHannes Reinecke #define ata_link_warn(link, fmt, ...) \
1571a9a79dfeSJoe Perches ata_link_printk(warn, link, fmt, ##__VA_ARGS__)
1572742bef47SHannes Reinecke #define ata_link_notice(link, fmt, ...) \
1573a9a79dfeSJoe Perches ata_link_printk(notice, link, fmt, ##__VA_ARGS__)
1574742bef47SHannes Reinecke #define ata_link_info(link, fmt, ...) \
1575a9a79dfeSJoe Perches ata_link_printk(info, link, fmt, ##__VA_ARGS__)
1576742bef47SHannes Reinecke #define ata_link_dbg(link, fmt, ...) \
1577a9a79dfeSJoe Perches ata_link_printk(debug, link, fmt, ##__VA_ARGS__)
1578742bef47SHannes Reinecke
1579742bef47SHannes Reinecke #define ata_dev_printk(level, dev, fmt, ...) \
1580742bef47SHannes Reinecke pr_ ## level("ata%u.%02u: " fmt, \
1581742bef47SHannes Reinecke (dev)->link->ap->print_id, \
1582742bef47SHannes Reinecke (dev)->link->pmp + (dev)->devno, \
1583742bef47SHannes Reinecke ##__VA_ARGS__)
1584742bef47SHannes Reinecke
1585a9a79dfeSJoe Perches #define ata_dev_err(dev, fmt, ...) \
1586a9a79dfeSJoe Perches ata_dev_printk(err, dev, fmt, ##__VA_ARGS__)
1587742bef47SHannes Reinecke #define ata_dev_warn(dev, fmt, ...) \
1588a9a79dfeSJoe Perches ata_dev_printk(warn, dev, fmt, ##__VA_ARGS__)
1589742bef47SHannes Reinecke #define ata_dev_notice(dev, fmt, ...) \
1590a9a79dfeSJoe Perches ata_dev_printk(notice, dev, fmt, ##__VA_ARGS__)
1591742bef47SHannes Reinecke #define ata_dev_info(dev, fmt, ...) \
1592a9a79dfeSJoe Perches ata_dev_printk(info, dev, fmt, ##__VA_ARGS__)
1593742bef47SHannes Reinecke #define ata_dev_dbg(dev, fmt, ...) \
1594a9a79dfeSJoe Perches ata_dev_printk(debug, dev, fmt, ##__VA_ARGS__)
1595742bef47SHannes Reinecke
159661440db6STejun Heo void ata_print_version(const struct device *dev, const char *version);
159706296a1eSJoe Perches
159806296a1eSJoe Perches /*
159961440db6STejun Heo * ata_eh_info helpers
1600f3e81b19STejun Heo */
1601f3e81b19STejun Heo extern __printf(2, 3)
1602b9075fa9SJoe Perches void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1603b9075fa9SJoe Perches extern __printf(2, 3)
1604b9075fa9SJoe Perches void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1605b9075fa9SJoe Perches extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
1606b64bbc39STejun Heo
ata_ehi_hotplugged(struct ata_eh_info * ehi)1607f3e81b19STejun Heo static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
1608c0b6c037STejun Heo {
1609c0b6c037STejun Heo ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
1610b558edddSTejun Heo ehi->flags |= ATA_EHI_HOTPLUGGED;
1611f8f1e1ccSTejun Heo ehi->action |= ATA_EH_RESET | ATA_EH_ENABLE_LINK;
1612b558edddSTejun Heo ehi->err_mask |= AC_ERR_ATA_BUS;
1613c0b6c037STejun Heo }
1614c0b6c037STejun Heo
1615c0b6c037STejun Heo /*
1616f3e81b19STejun Heo * port description helpers
1617cbcdd875STejun Heo */
1618cbcdd875STejun Heo extern __printf(2, 3)
1619b9075fa9SJoe Perches void ata_port_desc(struct ata_port *ap, const char *fmt, ...);
1620b9075fa9SJoe Perches #ifdef CONFIG_PCI
1621cbcdd875STejun Heo extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
1622cbcdd875STejun Heo const char *name);
1623cbcdd875STejun Heo #endif
ata_port_desc_misc(struct ata_port * ap,int irq)1624cbcdd875STejun Heo static inline void ata_port_desc_misc(struct ata_port *ap, int irq)
1625affccb16SNiklas Cassel {
1626affccb16SNiklas Cassel ata_port_desc(ap, "irq %d", irq);
1627affccb16SNiklas Cassel ata_port_desc(ap, "lpm-pol %d", ap->target_lpm_policy);
1628affccb16SNiklas Cassel }
1629affccb16SNiklas Cassel
ata_tag_internal(unsigned int tag)1630cbcdd875STejun Heo static inline bool ata_tag_internal(unsigned int tag)
16312e2cc676SJens Axboe {
16322ab7db1fSTejun Heo return tag == ATA_TAG_INTERNAL;
163383c063ddSYoichi Yuasa }
16342ab7db1fSTejun Heo
ata_tag_valid(unsigned int tag)16352ab7db1fSTejun Heo static inline bool ata_tag_valid(unsigned int tag)
163628361c40SJens Axboe {
163728361c40SJens Axboe return tag < ATA_MAX_QUEUE || ata_tag_internal(tag);
163828361c40SJens Axboe }
163928361c40SJens Axboe
164028361c40SJens Axboe #define __ata_qc_for_each(ap, qc, tag, max_tag, fn) \
16416362f0a2SJens Axboe for ((tag) = 0; (tag) < (max_tag) && \
16426362f0a2SJens Axboe ({ qc = fn((ap), (tag)); 1; }); (tag)++) \
16436362f0a2SJens Axboe
16446362f0a2SJens Axboe /*
16456362f0a2SJens Axboe * Internal use only, iterate commands ignoring error handling and
16466362f0a2SJens Axboe * status of 'qc'.
16476362f0a2SJens Axboe */
16486362f0a2SJens Axboe #define ata_qc_for_each_raw(ap, qc, tag) \
16496362f0a2SJens Axboe __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, __ata_qc_from_tag)
16506362f0a2SJens Axboe
16516362f0a2SJens Axboe /*
16526362f0a2SJens Axboe * Iterate all potential commands that can be queued
16536362f0a2SJens Axboe */
16546362f0a2SJens Axboe #define ata_qc_for_each(ap, qc, tag) \
16556362f0a2SJens Axboe __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, ata_qc_from_tag)
16566362f0a2SJens Axboe
16576362f0a2SJens Axboe /*
16586362f0a2SJens Axboe * Like ata_qc_for_each, but with the internal tag included
16596362f0a2SJens Axboe */
16606362f0a2SJens Axboe #define ata_qc_for_each_with_internal(ap, qc, tag) \
16616362f0a2SJens Axboe __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE + 1, ata_qc_from_tag)
16626362f0a2SJens Axboe
16636362f0a2SJens Axboe /*
16645806db22STejun Heo * device helpers
16655806db22STejun Heo */
ata_class_enabled(unsigned int class)16665806db22STejun Heo static inline unsigned int ata_class_enabled(unsigned int class)
1667e1211e3fSTejun Heo {
1668597afd21STejun Heo return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI ||
1669e0a71752STejun Heo class == ATA_DEV_PMP || class == ATA_DEV_SEMB ||
16709162c657SHannes Reinecke class == ATA_DEV_ZAC;
16719162c657SHannes Reinecke }
1672597afd21STejun Heo
ata_class_disabled(unsigned int class)1673597afd21STejun Heo static inline unsigned int ata_class_disabled(unsigned int class)
1674e1211e3fSTejun Heo {
16751da177e4SLinus Torvalds return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP ||
1676e0a71752STejun Heo class == ATA_DEV_PMP_UNSUP || class == ATA_DEV_SEMB_UNSUP ||
16773a92945bSHannes Reinecke class == ATA_DEV_ZAC_UNSUP;
16783a92945bSHannes Reinecke }
1679e1211e3fSTejun Heo
ata_class_absent(unsigned int class)1680e1211e3fSTejun Heo static inline unsigned int ata_class_absent(unsigned int class)
1681002c8054STejun Heo {
1682002c8054STejun Heo return !ata_class_enabled(class) && !ata_class_disabled(class);
1683002c8054STejun Heo }
1684002c8054STejun Heo
ata_dev_enabled(const struct ata_device * dev)1685002c8054STejun Heo static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
1686e1211e3fSTejun Heo {
1687e1211e3fSTejun Heo return ata_class_enabled(dev->class);
1688e1211e3fSTejun Heo }
1689e1211e3fSTejun Heo
ata_dev_disabled(const struct ata_device * dev)1690e1211e3fSTejun Heo static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
1691e1211e3fSTejun Heo {
1692e1211e3fSTejun Heo return ata_class_disabled(dev->class);
1693e1211e3fSTejun Heo }
16941da177e4SLinus Torvalds
ata_dev_absent(const struct ata_device * dev)16951da177e4SLinus Torvalds static inline unsigned int ata_dev_absent(const struct ata_device *dev)
1696002c8054STejun Heo {
1697002c8054STejun Heo return ata_class_absent(dev->class);
1698002c8054STejun Heo }
1699002c8054STejun Heo
1700002c8054STejun Heo /*
17015806db22STejun Heo * link helpers
1702f58229f8STejun Heo */
ata_link_max_devices(const struct ata_link * link)17035806db22STejun Heo static inline int ata_link_max_devices(const struct ata_link *link)
1704f58229f8STejun Heo {
17055806db22STejun Heo if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
17068989805dSTejun Heo return 2;
17075806db22STejun Heo return 1;
17085806db22STejun Heo }
17095806db22STejun Heo
ata_link_active(struct ata_link * link)17105806db22STejun Heo static inline int ata_link_active(struct ata_link *link)
1711da917d69STejun Heo {
1712da917d69STejun Heo return ata_tag_valid(link->active_tag) || link->sactive;
1713da917d69STejun Heo }
1714da917d69STejun Heo
1715da917d69STejun Heo /*
17161eca4365STejun Heo * Iterators
17171eca4365STejun Heo *
17181eca4365STejun Heo * ATA_LITER_* constants are used to select link iteration mode and
17191eca4365STejun Heo * ATA_DITER_* device iteration mode.
17201eca4365STejun Heo *
17211eca4365STejun Heo * For a custom iteration directly using ata_{link|dev}_next(), if
17221eca4365STejun Heo * @link or @dev, respectively, is NULL, the first element is
17231eca4365STejun Heo * returned. @dev and @link can be any valid device or link and the
17241eca4365STejun Heo * next element according to the iteration mode will be returned.
17251eca4365STejun Heo * After the last element, NULL is returned.
17261eca4365STejun Heo */
17271eca4365STejun Heo enum ata_link_iter_mode {
17281eca4365STejun Heo ATA_LITER_EDGE, /* if present, PMP links only; otherwise,
17291eca4365STejun Heo * host link. no slave link */
17301eca4365STejun Heo ATA_LITER_HOST_FIRST, /* host link followed by PMP or slave links */
17311eca4365STejun Heo ATA_LITER_PMP_FIRST, /* PMP links followed by host link,
17321eca4365STejun Heo * slave link still comes after host link */
17331eca4365STejun Heo };
17341eca4365STejun Heo
17351eca4365STejun Heo enum ata_dev_iter_mode {
17361eca4365STejun Heo ATA_DITER_ENABLED,
17371eca4365STejun Heo ATA_DITER_ENABLED_REVERSE,
17381eca4365STejun Heo ATA_DITER_ALL,
17391eca4365STejun Heo ATA_DITER_ALL_REVERSE,
17401eca4365STejun Heo };
17411eca4365STejun Heo
17421eca4365STejun Heo extern struct ata_link *ata_link_next(struct ata_link *link,
17431eca4365STejun Heo struct ata_port *ap,
17441eca4365STejun Heo enum ata_link_iter_mode mode);
17451eca4365STejun Heo
17461eca4365STejun Heo extern struct ata_device *ata_dev_next(struct ata_device *dev,
17471eca4365STejun Heo struct ata_link *link,
1748aadffb68STejun Heo enum ata_dev_iter_mode mode);
17491eca4365STejun Heo
17508989805dSTejun Heo /*
17511eca4365STejun Heo * Shortcut notation for iterations
17521eca4365STejun Heo *
17531eca4365STejun Heo * ata_for_each_link() iterates over each link of @ap according to
17541eca4365STejun Heo * @mode. @link points to the current link in the loop. @link is
17551eca4365STejun Heo * NULL after loop termination. ata_for_each_dev() works the same way
17561eca4365STejun Heo * except that it iterates over each device of @link.
17571eca4365STejun Heo *
17581eca4365STejun Heo * Note that the mode prefixes ATA_{L|D}ITER_ shouldn't need to be
17591eca4365STejun Heo * specified when using the following shorthand notations. Only the
17601eca4365STejun Heo * mode itself (EDGE, HOST_FIRST, ENABLED, etc...) should be
17611eca4365STejun Heo * specified. This not only increases brevity but also makes it
17621eca4365STejun Heo * impossible to use ATA_LITER_* for device iteration or vice-versa.
17631eca4365STejun Heo */
17641eca4365STejun Heo #define ata_for_each_link(link, ap, mode) \
17651eca4365STejun Heo for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
17661eca4365STejun Heo (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
17671eca4365STejun Heo
17688989805dSTejun Heo #define ata_for_each_dev(dev, link, mode) \
17691eca4365STejun Heo for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
17701eca4365STejun Heo (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
17711eca4365STejun Heo
17725806db22STejun Heo /**
17736d1245bfSTejun Heo * ata_ncq_supported - Test whether NCQ is supported
1774fa5bde13SDamien Le Moal * @dev: ATA device to test
1775fa5bde13SDamien Le Moal *
17766d1245bfSTejun Heo * LOCKING:
17776d1245bfSTejun Heo * spin_lock_irqsave(host lock)
17786d1245bfSTejun Heo *
17796d1245bfSTejun Heo * RETURNS:
17806d1245bfSTejun Heo * true if @dev supports NCQ, false otherwise.
1781fa5bde13SDamien Le Moal */
ata_ncq_supported(struct ata_device * dev)17826d1245bfSTejun Heo static inline bool ata_ncq_supported(struct ata_device *dev)
1783fa5bde13SDamien Le Moal {
17846d1245bfSTejun Heo if (!IS_ENABLED(CONFIG_SATA_HOST))
17857caa30eaSBartlomiej Zolnierkiewicz return false;
1786fa5bde13SDamien Le Moal return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
1787fa5bde13SDamien Le Moal }
1788fa5bde13SDamien Le Moal
1789fa5bde13SDamien Le Moal /**
1790fa5bde13SDamien Le Moal * ata_ncq_enabled - Test whether NCQ is enabled
1791fa5bde13SDamien Le Moal * @dev: ATA device to test
1792fa5bde13SDamien Le Moal *
1793fa5bde13SDamien Le Moal * LOCKING:
1794fa5bde13SDamien Le Moal * spin_lock_irqsave(host lock)
1795fa5bde13SDamien Le Moal *
1796fa5bde13SDamien Le Moal * RETURNS:
1797fa5bde13SDamien Le Moal * true if NCQ is enabled for @dev, false otherwise.
1798fa5bde13SDamien Le Moal */
ata_ncq_enabled(struct ata_device * dev)1799fa5bde13SDamien Le Moal static inline bool ata_ncq_enabled(struct ata_device *dev)
1800fa5bde13SDamien Le Moal {
1801fa5bde13SDamien Le Moal return ata_ncq_supported(dev) && !(dev->flags & ATA_DFLAG_NCQ_OFF);
1802fa5bde13SDamien Le Moal }
18036d1245bfSTejun Heo
ata_fpdma_dsm_supported(struct ata_device * dev)18040baab86bSEdward Falk static inline bool ata_fpdma_dsm_supported(struct ata_device *dev)
180587fb6c31SMarc Carino {
180687fb6c31SMarc Carino return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
180787fb6c31SMarc Carino (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &
180887fb6c31SMarc Carino ATA_LOG_NCQ_SEND_RECV_DSM_TRIM);
180987fb6c31SMarc Carino }
181087fb6c31SMarc Carino
ata_fpdma_read_log_supported(struct ata_device * dev)181187fb6c31SMarc Carino static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
18125c65d8bbSHannes Reinecke {
18135c65d8bbSHannes Reinecke return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
18145c65d8bbSHannes Reinecke (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &
18155c65d8bbSHannes Reinecke ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
18165c65d8bbSHannes Reinecke }
18175c65d8bbSHannes Reinecke
ata_fpdma_zac_mgmt_in_supported(struct ata_device * dev)18185c65d8bbSHannes Reinecke static inline bool ata_fpdma_zac_mgmt_in_supported(struct ata_device *dev)
181928a3fc22SHannes Reinecke {
182028a3fc22SHannes Reinecke return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
182128a3fc22SHannes Reinecke (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET] &
182228a3fc22SHannes Reinecke ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED);
182328a3fc22SHannes Reinecke }
182428a3fc22SHannes Reinecke
ata_fpdma_zac_mgmt_out_supported(struct ata_device * dev)182528a3fc22SHannes Reinecke static inline bool ata_fpdma_zac_mgmt_out_supported(struct ata_device *dev)
1826284b3b77SHannes Reinecke {
1827284b3b77SHannes Reinecke return (dev->ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OFFSET] &
1828284b3b77SHannes Reinecke ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OUT);
1829284b3b77SHannes Reinecke }
1830284b3b77SHannes Reinecke
ata_qc_set_polling(struct ata_queued_cmd * qc)1831284b3b77SHannes Reinecke static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
18321da177e4SLinus Torvalds {
18331da177e4SLinus Torvalds qc->tf.ctl |= ATA_NIEN;
18341da177e4SLinus Torvalds }
18351da177e4SLinus Torvalds
__ata_qc_from_tag(struct ata_port * ap,unsigned int tag)18361da177e4SLinus Torvalds static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
1837f69499f4STejun Heo unsigned int tag)
18381da177e4SLinus Torvalds {
18391da177e4SLinus Torvalds if (ata_tag_valid(tag))
184028361c40SJens Axboe return &ap->qcmd[tag];
18411da177e4SLinus Torvalds return NULL;
18421da177e4SLinus Torvalds }
18431da177e4SLinus Torvalds
ata_qc_from_tag(struct ata_port * ap,unsigned int tag)18441da177e4SLinus Torvalds static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
1845f69499f4STejun Heo unsigned int tag)
1846f69499f4STejun Heo {
1847f69499f4STejun Heo struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1848f69499f4STejun Heo
1849f69499f4STejun Heo if (unlikely(!qc))
1850ff8072d5SHannes Reinecke return qc;
1851f69499f4STejun Heo
1852f69499f4STejun Heo if ((qc->flags & (ATA_QCFLAG_ACTIVE |
1853f69499f4STejun Heo ATA_QCFLAG_EH)) == ATA_QCFLAG_ACTIVE)
185487629312SNiklas Cassel return qc;
1855f69499f4STejun Heo
1856f69499f4STejun Heo return NULL;
1857f69499f4STejun Heo }
1858f69499f4STejun Heo
ata_qc_raw_nbytes(struct ata_queued_cmd * qc)1859f69499f4STejun Heo static inline unsigned int ata_qc_raw_nbytes(struct ata_queued_cmd *qc)
1860aacda375STejun Heo {
1861aacda375STejun Heo return qc->nbytes - min(qc->extrabytes, qc->nbytes);
1862aacda375STejun Heo }
1863aacda375STejun Heo
ata_tf_init(struct ata_device * dev,struct ata_taskfile * tf)1864aacda375STejun Heo static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
18653373efd8STejun Heo {
18661da177e4SLinus Torvalds memset(tf, 0, sizeof(*tf));
18671da177e4SLinus Torvalds
18681da177e4SLinus Torvalds #ifdef CONFIG_ATA_SFF
18695fe7454aSTejun Heo tf->ctl = dev->link->ap->ctl;
18709af5c9c9STejun Heo #else
18715fe7454aSTejun Heo tf->ctl = ATA_DEVCTL_OBS;
18725fe7454aSTejun Heo #endif
18735fe7454aSTejun Heo if (dev->devno == 0)
18743373efd8STejun Heo tf->device = ATA_DEVICE_OBS;
18751da177e4SLinus Torvalds else
18761da177e4SLinus Torvalds tf->device = ATA_DEVICE_OBS | ATA_DEV1;
18771da177e4SLinus Torvalds }
18781da177e4SLinus Torvalds
ata_qc_reinit(struct ata_queued_cmd * qc)18791da177e4SLinus Torvalds static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
18802c13b7ceSJeff Garzik {
18812c13b7ceSJeff Garzik qc->dma_dir = DMA_NONE;
1882501e0c50STejun Heo qc->sg = NULL;
1883ff2aeb1eSTejun Heo qc->flags = 0;
18842c13b7ceSJeff Garzik qc->cursg = NULL;
188587260216SJens Axboe qc->cursg_ofs = 0;
188687260216SJens Axboe qc->nbytes = qc->extrabytes = qc->curbytes = 0;
1887aacda375STejun Heo qc->n_elem = 0;
18887a801184SBrian King qc->err_mask = 0;
1889a22e2eb0SAlbert Lee qc->sect_size = ATA_SECT_SIZE;
18905a5dbd18SMark Lord
18912c13b7ceSJeff Garzik ata_tf_init(qc->dev, &qc->tf);
18923373efd8STejun Heo
1893e61e0672STejun Heo /* init result_tf such that it indicates normal completion */
1894e61e0672STejun Heo qc->result_tf.command = ATA_DRDY;
1895e61e0672STejun Heo qc->result_tf.feature = 0;
1896e61e0672STejun Heo }
18972c13b7ceSJeff Garzik
ata_try_flush_cache(const struct ata_device * dev)18982c13b7ceSJeff Garzik static inline int ata_try_flush_cache(const struct ata_device *dev)
1899057ace5eSJeff Garzik {
19001da177e4SLinus Torvalds return ata_id_wcache_enabled(dev->id) ||
19011da177e4SLinus Torvalds ata_id_has_flush(dev->id) ||
19021da177e4SLinus Torvalds ata_id_has_flush_ext(dev->id);
19031da177e4SLinus Torvalds }
19041da177e4SLinus Torvalds
ac_err_mask(u8 status)19051da177e4SLinus Torvalds static inline unsigned int ac_err_mask(u8 status)
1906a7dac447SJeff Garzik {
1907a7dac447SJeff Garzik if (status & (ATA_BUSY | ATA_DRQ))
19083655d1d3SAlbert Lee return AC_ERR_HSM;
190911a56d24STejun Heo if (status & (ATA_ERR | ATA_DF))
1910a7dac447SJeff Garzik return AC_ERR_DEV;
1911a7dac447SJeff Garzik return 0;
1912a7dac447SJeff Garzik }
1913a7dac447SJeff Garzik
__ac_err_mask(u8 status)1914a7dac447SJeff Garzik static inline unsigned int __ac_err_mask(u8 status)
1915a7dac447SJeff Garzik {
1916a7dac447SJeff Garzik unsigned int mask = ac_err_mask(status);
1917a7dac447SJeff Garzik if (mask == 0)
1918a7dac447SJeff Garzik return AC_ERR_OTHER;
1919a7dac447SJeff Garzik return mask;
1920a7dac447SJeff Garzik }
1921a7dac447SJeff Garzik
ata_shost_to_port(struct Scsi_Host * host)1922a7dac447SJeff Garzik static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
192335bb94b1SJeff Garzik {
192435bb94b1SJeff Garzik return *(struct ata_port **)&host->hostdata[0];
19254911487aSTejun Heo }
192635bb94b1SJeff Garzik
ata_check_ready(u8 status)192735bb94b1SJeff Garzik static inline int ata_check_ready(u8 status)
192878ab88f0STejun Heo {
192978ab88f0STejun Heo if (!(status & ATA_BUSY))
1930005b1f74SJeff Garzik return 1;
1931005b1f74SJeff Garzik
193278ab88f0STejun Heo /* 0xff indicates either no device or device not ready */
193378ab88f0STejun Heo if (status == 0xff)
193478ab88f0STejun Heo return -ENODEV;
193578ab88f0STejun Heo
193678ab88f0STejun Heo return 0;
1937005b1f74SJeff Garzik }
193878ab88f0STejun Heo
ata_deadline(unsigned long from_jiffies,unsigned int timeout_msecs)193978ab88f0STejun Heo static inline unsigned long ata_deadline(unsigned long from_jiffies,
1940341c2c95STejun Heo unsigned int timeout_msecs)
194163b93099SSergey Shtylyov {
1942341c2c95STejun Heo return from_jiffies + msecs_to_jiffies(timeout_msecs);
1943341c2c95STejun Heo }
1944341c2c95STejun Heo
1945341c2c95STejun Heo /* Don't open code these in drivers as there are traps. Firstly the range may
1946b15b3ebaSAlan Cox change in future hardware and specs, secondly 0xFF means 'no DMA' but is
1947b15b3ebaSAlan Cox > UDMA_0. Dyma ddreigiau */
1948b15b3ebaSAlan Cox
ata_using_mwdma(struct ata_device * adev)1949b15b3ebaSAlan Cox static inline bool ata_using_mwdma(struct ata_device *adev)
19501b947279SDamien Le Moal {
1951b15b3ebaSAlan Cox return adev->dma_mode >= XFER_MW_DMA_0 &&
19521b947279SDamien Le Moal adev->dma_mode <= XFER_MW_DMA_4;
19531b947279SDamien Le Moal }
1954b15b3ebaSAlan Cox
ata_using_udma(struct ata_device * adev)1955b15b3ebaSAlan Cox static inline bool ata_using_udma(struct ata_device *adev)
19561b947279SDamien Le Moal {
1957b15b3ebaSAlan Cox return adev->dma_mode >= XFER_UDMA_0 &&
19581b947279SDamien Le Moal adev->dma_mode <= XFER_UDMA_7;
19591b947279SDamien Le Moal }
1960b15b3ebaSAlan Cox
ata_dma_enabled(struct ata_device * adev)1961b15b3ebaSAlan Cox static inline bool ata_dma_enabled(struct ata_device *adev)
19621b947279SDamien Le Moal {
1963b15b3ebaSAlan Cox return adev->dma_mode != 0xFF;
19641b947279SDamien Le Moal }
1965b15b3ebaSAlan Cox
196648515f6cSTejun Heo /**************************************************************************
196748515f6cSTejun Heo * PATA timings - drivers/ata/libata-pata-timings.c
1968a9b2c120SBartlomiej Zolnierkiewicz */
1969a9b2c120SBartlomiej Zolnierkiewicz extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1970a9b2c120SBartlomiej Zolnierkiewicz extern int ata_timing_compute(struct ata_device *, unsigned short,
1971a9b2c120SBartlomiej Zolnierkiewicz struct ata_timing *, int, int);
1972a9b2c120SBartlomiej Zolnierkiewicz extern void ata_timing_merge(const struct ata_timing *,
1973a9b2c120SBartlomiej Zolnierkiewicz const struct ata_timing *, struct ata_timing *,
1974a9b2c120SBartlomiej Zolnierkiewicz unsigned int);
1975a9b2c120SBartlomiej Zolnierkiewicz
1976a9b2c120SBartlomiej Zolnierkiewicz /**************************************************************************
1977a9b2c120SBartlomiej Zolnierkiewicz * PMP - drivers/ata/libata-pmp.c
197848515f6cSTejun Heo */
197948515f6cSTejun Heo #ifdef CONFIG_SATA_PMP
198088fcd562STejun Heo
198188fcd562STejun Heo extern const struct ata_port_operations sata_pmp_port_ops;
198248515f6cSTejun Heo
198348515f6cSTejun Heo extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
198448515f6cSTejun Heo extern void sata_pmp_error_handler(struct ata_port *ap);
198548515f6cSTejun Heo
198648515f6cSTejun Heo #else /* CONFIG_SATA_PMP */
198788fcd562STejun Heo
198888fcd562STejun Heo #define sata_pmp_port_ops sata_port_ops
198988fcd562STejun Heo #define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
199088fcd562STejun Heo #define sata_pmp_error_handler ata_std_error_handler
199188fcd562STejun Heo
199288fcd562STejun Heo #endif /* CONFIG_SATA_PMP */
199388fcd562STejun Heo
199488fcd562STejun Heo
199548515f6cSTejun Heo /**************************************************************************
1996624d5c51STejun Heo * SFF - drivers/ata/libata-sff.c
1997624d5c51STejun Heo */
1998624d5c51STejun Heo #ifdef CONFIG_ATA_SFF
1999127102aeSTejun Heo
2000127102aeSTejun Heo extern const struct ata_port_operations ata_sff_port_ops;
2001624d5c51STejun Heo extern const struct ata_port_operations ata_bmdma32_port_ops;
2002871af121SAlan Cox
2003624d5c51STejun Heo /* PIO only, sg_tablesize and dma_boundary limits can be removed */
2004624d5c51STejun Heo #define ATA_PIO_SHT(drv_name) \
2005624d5c51STejun Heo ATA_BASE_SHT(drv_name), \
2006624d5c51STejun Heo .sg_tablesize = LIBATA_MAX_PRD, \
2007624d5c51STejun Heo .dma_boundary = ATA_DMA_BOUNDARY
2008624d5c51STejun Heo
2009624d5c51STejun Heo extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
20109363c382STejun Heo extern u8 ata_sff_check_status(struct ata_port *ap);
20119363c382STejun Heo extern void ata_sff_pause(struct ata_port *ap);
2012a57c1badSAlan Cox extern void ata_sff_dma_pause(struct ata_port *ap);
2013a57c1badSAlan Cox extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline);
2014705e76beSTejun Heo extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
20159363c382STejun Heo extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
20169363c382STejun Heo extern void ata_sff_exec_command(struct ata_port *ap,
20179363c382STejun Heo const struct ata_taskfile *tf);
20189363c382STejun Heo extern unsigned int ata_sff_data_xfer(struct ata_queued_cmd *qc,
2019989e0aacSBartlomiej Zolnierkiewicz unsigned char *buf, unsigned int buflen, int rw);
2020624d5c51STejun Heo extern unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc,
2021989e0aacSBartlomiej Zolnierkiewicz unsigned char *buf, unsigned int buflen, int rw);
2022871af121SAlan Cox extern void ata_sff_irq_on(struct ata_port *ap);
2023e42a542bSSergei Shtylyov extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
20249363c382STejun Heo u8 status, int in_wq);
2025624d5c51STejun Heo extern void ata_sff_queue_work(struct work_struct *work);
202664b97594SViresh Kumar extern void ata_sff_queue_delayed_work(struct delayed_work *dwork,
202764b97594SViresh Kumar unsigned long delay);
202864b97594SViresh Kumar extern void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay);
2029ea3c6450SGwendal Grignou extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
20309363c382STejun Heo extern void ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
2031931139afSDamien Le Moal extern unsigned int ata_sff_port_intr(struct ata_port *ap,
2032c3b28894STejun Heo struct ata_queued_cmd *qc);
20339363c382STejun Heo extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
20349363c382STejun Heo extern void ata_sff_lost_interrupt(struct ata_port *ap);
2035c96f1732SAlan Cox extern void ata_sff_freeze(struct ata_port *ap);
20369363c382STejun Heo extern void ata_sff_thaw(struct ata_port *ap);
20379363c382STejun Heo extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
20389363c382STejun Heo extern unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
20399363c382STejun Heo u8 *r_err);
2040624d5c51STejun Heo extern int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
2041705e76beSTejun Heo unsigned long deadline);
2042624d5c51STejun Heo extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
20439363c382STejun Heo unsigned long deadline);
2044624d5c51STejun Heo extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
20459363c382STejun Heo unsigned long deadline);
20469363c382STejun Heo extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
20479363c382STejun Heo extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
20483d47aa8eSAlan Cox extern void ata_sff_error_handler(struct ata_port *ap);
20499363c382STejun Heo extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
20509363c382STejun Heo #ifdef CONFIG_PCI
2051624d5c51STejun Heo extern int ata_pci_sff_init_host(struct ata_host *host);
20529363c382STejun Heo extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
20539363c382STejun Heo const struct ata_port_info * const * ppi,
2054624d5c51STejun Heo struct ata_host **r_host);
2055624d5c51STejun Heo extern int ata_pci_sff_activate_host(struct ata_host *host,
20569363c382STejun Heo irq_handler_t irq_handler,
2057624d5c51STejun Heo const struct scsi_host_template *sht);
205825df73d9SBart Van Assche extern int ata_pci_sff_init_one(struct pci_dev *pdev,
20599363c382STejun Heo const struct ata_port_info * const * ppi,
2060624d5c51STejun Heo const struct scsi_host_template *sht, void *host_priv, int hflags);
206125df73d9SBart Van Assche #endif /* CONFIG_PCI */
2062624d5c51STejun Heo
2063624d5c51STejun Heo #ifdef CONFIG_ATA_BMDMA
20649a7780c9STejun Heo
20659a7780c9STejun Heo extern const struct ata_port_operations ata_bmdma_port_ops;
20669a7780c9STejun Heo
20679a7780c9STejun Heo #define ATA_BMDMA_SHT(drv_name) \
20689a7780c9STejun Heo ATA_BASE_SHT(drv_name), \
20699a7780c9STejun Heo .sg_tablesize = LIBATA_MAX_PRD, \
20709a7780c9STejun Heo .dma_boundary = ATA_DMA_BOUNDARY
20719a7780c9STejun Heo
20729a7780c9STejun Heo extern enum ata_completion_errors ata_bmdma_qc_prep(struct ata_queued_cmd *qc);
207395364f36SJiri Slaby extern unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc);
2074360ff783STejun Heo extern enum ata_completion_errors ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc);
207595364f36SJiri Slaby extern unsigned int ata_bmdma_port_intr(struct ata_port *ap,
2076c3b28894STejun Heo struct ata_queued_cmd *qc);
2077c3b28894STejun Heo extern irqreturn_t ata_bmdma_interrupt(int irq, void *dev_instance);
2078c3b28894STejun Heo extern void ata_bmdma_error_handler(struct ata_port *ap);
2079fe06e5f9STejun Heo extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
2080fe06e5f9STejun Heo extern void ata_bmdma_irq_clear(struct ata_port *ap);
208137f65b8bSTejun Heo extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
20829f2f7210STejun Heo extern void ata_bmdma_start(struct ata_queued_cmd *qc);
20839f2f7210STejun Heo extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
20849f2f7210STejun Heo extern u8 ata_bmdma_status(struct ata_port *ap);
20859f2f7210STejun Heo extern int ata_bmdma_port_start(struct ata_port *ap);
2086c7087652STejun Heo extern int ata_bmdma_port_start32(struct ata_port *ap);
2087c7087652STejun Heo
20889f2f7210STejun Heo #ifdef CONFIG_PCI
20899f2f7210STejun Heo extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
20909f2f7210STejun Heo extern void ata_pci_bmdma_init(struct ata_host *host);
2091c7087652STejun Heo extern int ata_pci_bmdma_prepare_host(struct pci_dev *pdev,
20921c5afdf7STejun Heo const struct ata_port_info * const * ppi,
20931c5afdf7STejun Heo struct ata_host **r_host);
20941c5afdf7STejun Heo extern int ata_pci_bmdma_init_one(struct pci_dev *pdev,
20951c5afdf7STejun Heo const struct ata_port_info * const * ppi,
20961c5afdf7STejun Heo const struct scsi_host_template *sht,
209725df73d9SBart Van Assche void *host_priv, int hflags);
20981c5afdf7STejun Heo #endif /* CONFIG_PCI */
20999f2f7210STejun Heo #endif /* CONFIG_ATA_BMDMA */
21009a7780c9STejun Heo
21019f2f7210STejun Heo /**
2102624d5c51STejun Heo * ata_sff_busy_wait - Wait for a port status register
21039363c382STejun Heo * @ap: Port to wait for.
2104624d5c51STejun Heo * @bits: bits that must be clear
2105624d5c51STejun Heo * @max: number of 10uS waits to perform
2106624d5c51STejun Heo *
2107624d5c51STejun Heo * Waits up to max*10 microseconds for the selected bits in the port's
2108624d5c51STejun Heo * status register to be cleared.
2109624d5c51STejun Heo * Returns final value of status register.
2110624d5c51STejun Heo *
2111624d5c51STejun Heo * LOCKING:
2112624d5c51STejun Heo * Inherited from caller.
2113624d5c51STejun Heo */
ata_sff_busy_wait(struct ata_port * ap,unsigned int bits,unsigned int max)2114624d5c51STejun Heo static inline u8 ata_sff_busy_wait(struct ata_port *ap, unsigned int bits,
21159363c382STejun Heo unsigned int max)
2116624d5c51STejun Heo {
2117624d5c51STejun Heo u8 status;
2118624d5c51STejun Heo
2119624d5c51STejun Heo do {
2120624d5c51STejun Heo udelay(10);
2121624d5c51STejun Heo status = ap->ops->sff_check_status(ap);
21225682ed33STejun Heo max--;
2123624d5c51STejun Heo } while (status != 0xff && (status & bits) && (max > 0));
2124624d5c51STejun Heo
2125624d5c51STejun Heo return status;
2126624d5c51STejun Heo }
2127624d5c51STejun Heo
2128624d5c51STejun Heo /**
2129624d5c51STejun Heo * ata_wait_idle - Wait for a port to be idle.
2130624d5c51STejun Heo * @ap: Port to wait for.
2131624d5c51STejun Heo *
2132624d5c51STejun Heo * Waits up to 10ms for port's BUSY and DRQ signals to clear.
2133624d5c51STejun Heo * Returns final value of status register.
2134624d5c51STejun Heo *
2135624d5c51STejun Heo * LOCKING:
2136624d5c51STejun Heo * Inherited from caller.
2137624d5c51STejun Heo */
ata_wait_idle(struct ata_port * ap)2138624d5c51STejun Heo static inline u8 ata_wait_idle(struct ata_port *ap)
2139624d5c51STejun Heo {
2140624d5c51STejun Heo u8 status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
21419363c382STejun Heo
2142624d5c51STejun Heo if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
2143624d5c51STejun Heo ata_port_dbg(ap, "abnormal Status 0x%X\n", status);
2144742bef47SHannes Reinecke
2145624d5c51STejun Heo return status;
2146624d5c51STejun Heo }
2147624d5c51STejun Heo #endif /* CONFIG_ATA_SFF */
2148127102aeSTejun Heo
2149624d5c51STejun Heo #endif /* __LINUX_LIBATA_H__ */
21501da177e4SLinus Torvalds