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
581da177e4SLinus Torvalds enum {
591da177e4SLinus Torvalds /* various global constants */
601da177e4SLinus Torvalds LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
61d26fc955SAlan Cox LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4, /* Worst case */
621da177e4SLinus Torvalds ATA_DEF_QUEUE = 1,
63a6e6ce8eSTejun Heo ATA_MAX_QUEUE = 32,
6428361c40SJens Axboe ATA_TAG_INTERNAL = ATA_MAX_QUEUE,
65341c2c95STejun Heo ATA_SHORT_PAUSE = 16,
661da177e4SLinus Torvalds
67140b5e59STejun Heo ATAPI_MAX_DRAIN = 16 << 10,
68140b5e59STejun Heo
69b558edddSTejun Heo ATA_ALL_DEVICES = (1 << ATA_MAX_DEVICES) - 1,
70b558edddSTejun Heo
711da177e4SLinus Torvalds ATA_SHT_EMULATED = 1,
721da177e4SLinus Torvalds ATA_SHT_THIS_ID = -1,
731da177e4SLinus Torvalds
74dc34e7e1SSergei Shtylyov /* struct ata_taskfile flags */
75dc34e7e1SSergei Shtylyov ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */
76dc34e7e1SSergei Shtylyov ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */
77dc34e7e1SSergei Shtylyov ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */
78dc34e7e1SSergei Shtylyov ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
79dc34e7e1SSergei Shtylyov ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
80dc34e7e1SSergei Shtylyov ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
81dc34e7e1SSergei Shtylyov ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
82dc34e7e1SSergei Shtylyov
831da177e4SLinus Torvalds /* struct ata_device stuff */
84949b38afSTejun Heo ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
85949b38afSTejun Heo ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
86029f5468SJeff Garzik ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
8788e49034STejun Heo ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
886fc49adbSTejun Heo ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */
896746544cSTejun Heo ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */
906746544cSTejun Heo ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */
917d77b247STejun Heo ATA_DFLAG_AN = (1 << 7), /* AN configured */
92818831c8SChristoph Hellwig ATA_DFLAG_TRUSTED = (1 << 8), /* device supports trusted send/recv */
934d2e4980SDamien Le Moal ATA_DFLAG_FUA = (1 << 9), /* device supports FUA */
9491163006STejun Heo ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */
9587aab3c4SNiklas Cassel ATA_DFLAG_NCQ_SEND_RECV = (1 << 11), /* device supports NCQ SEND and RECV */
9687aab3c4SNiklas Cassel ATA_DFLAG_NCQ_PRIO = (1 << 12), /* device supports NCQ priority */
9762e4a60eSDamien Le Moal ATA_DFLAG_CDL = (1 << 13), /* supports cmd duration limits */
9862e4a60eSDamien Le Moal ATA_DFLAG_CFG_MASK = (1 << 14) - 1,
99949b38afSTejun Heo
10062e4a60eSDamien Le Moal ATA_DFLAG_PIO = (1 << 14), /* device limited to PIO mode */
10162e4a60eSDamien Le Moal ATA_DFLAG_NCQ_OFF = (1 << 15), /* device limited to non-NCQ mode */
10262e4a60eSDamien Le Moal ATA_DFLAG_SLEEPING = (1 << 16), /* device is sleeping */
10362e4a60eSDamien Le Moal ATA_DFLAG_DUBIOUS_XFER = (1 << 17), /* data transfer not verified */
10462e4a60eSDamien Le Moal ATA_DFLAG_NO_UNLOAD = (1 << 18), /* device doesn't support unload */
10562e4a60eSDamien Le Moal ATA_DFLAG_UNLOCK_HPA = (1 << 19), /* unlock HPA */
10662e4a60eSDamien Le Moal ATA_DFLAG_INIT_MASK = (1 << 20) - 1,
1071da177e4SLinus Torvalds
10862e4a60eSDamien Le Moal ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 20), /* Priority cmds sent to dev */
109df60f9c6SDamien Le Moal ATA_DFLAG_CDL_ENABLED = (1 << 21), /* cmd duration limits is enabled */
110a1f506afSDamien Le Moal ATA_DFLAG_RESUMING = (1 << 22), /* Device is resuming */
111f20ded38STejun Heo ATA_DFLAG_DETACH = (1 << 24),
112f20ded38STejun Heo ATA_DFLAG_DETACHED = (1 << 25),
113b1354cbbSLin Ming ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */
11465fe1f0fSShane Huang ATA_DFLAG_DEVSLP = (1 << 27), /* device supports Device Sleep */
1150d0cdb02SAaron Lu ATA_DFLAG_ACPI_DISABLED = (1 << 28), /* ACPI for the device is disabled */
11606dbde5fSHannes Reinecke ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */
1176d1003aeSHannes Reinecke ATA_DFLAG_ZAC = (1 << 30), /* ZAC device */
118b1354cbbSLin Ming
1194d2e4980SDamien Le Moal ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
120d633b8a7SDamien Le Moal ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
12162e4a60eSDamien Le Moal ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \
12262e4a60eSDamien Le Moal ATA_DFLAG_CDL),
123d633b8a7SDamien Le Moal
1241da177e4SLinus Torvalds ATA_DEV_UNKNOWN = 0, /* unknown device */
1251da177e4SLinus Torvalds ATA_DEV_ATA = 1, /* ATA device */
1261da177e4SLinus Torvalds ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */
1271da177e4SLinus Torvalds ATA_DEV_ATAPI = 3, /* ATAPI device */
1281da177e4SLinus Torvalds ATA_DEV_ATAPI_UNSUP = 4, /* ATAPI device (unsupported) */
129e0a71752STejun Heo ATA_DEV_PMP = 5, /* SATA port multiplier */
130e0a71752STejun Heo ATA_DEV_PMP_UNSUP = 6, /* SATA port multiplier (unsupported) */
131e0a71752STejun Heo ATA_DEV_SEMB = 7, /* SEMB */
132e0a71752STejun Heo ATA_DEV_SEMB_UNSUP = 8, /* SEMB (unsupported) */
1339162c657SHannes Reinecke ATA_DEV_ZAC = 9, /* ZAC device */
1343a92945bSHannes Reinecke ATA_DEV_ZAC_UNSUP = 10, /* ZAC device (unsupported) */
1353a92945bSHannes Reinecke ATA_DEV_NONE = 11, /* no device */
1361da177e4SLinus Torvalds
1370c88758bSTejun Heo /* struct ata_link flags */
1388ba5a45cSBartlomiej Zolnierkiewicz /* NOTE: struct ata_force_param currently stores lflags in u16 */
13905944bdfSTejun Heo ATA_LFLAG_NO_HRST = (1 << 1), /* avoid hardreset */
140ae791c05STejun Heo ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
141ae791c05STejun Heo ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
142ae791c05STejun Heo ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */
143ae791c05STejun Heo ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
144fd995f70STejun Heo ATA_LFLAG_NO_RETRY = (1 << 5), /* don't retry this link */
145f9df58cbSTejun Heo ATA_LFLAG_DISABLED = (1 << 6), /* link is disabled */
14618f7ba4cSKristen Carlson Accardi ATA_LFLAG_SW_ACTIVITY = (1 << 7), /* keep activity stats */
1476b7ae954STejun Heo ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */
148ca6d43b0SDan Williams ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */
14909c5b480SGabriele Mazzotta ATA_LFLAG_CHANGED = (1 << 10), /* LPM state changed on this link */
150b9ba367cSPaul Menzel ATA_LFLAG_NO_DEBOUNCE_DELAY = (1 << 11), /* no debounce delay on link resume */
1510c88758bSTejun Heo
1521da177e4SLinus Torvalds /* struct ata_port flags */
153949b38afSTejun Heo ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
1541da177e4SLinus Torvalds /* (doesn't imply presence) */
155949b38afSTejun Heo ATA_FLAG_SATA = (1 << 1),
156240630e6SHans de Goede ATA_FLAG_NO_LPM = (1 << 2), /* host not happy with LPM */
157ea013a9bSAndreas Werner ATA_FLAG_NO_LOG_PAGE = (1 << 5), /* do not issue log page read */
158949b38afSTejun Heo ATA_FLAG_NO_ATAPI = (1 << 6), /* No ATAPI support */
159949b38afSTejun Heo ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */
160949b38afSTejun Heo ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */
1617395acb2STejun Heo ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
162e50362ecSAlbert Lee * doesn't handle PIO interrupts */
1637395acb2STejun Heo ATA_FLAG_NCQ = (1 << 10), /* host supports NCQ */
1642a6e58d2SRafael J. Wysocki ATA_FLAG_NO_POWEROFF_SPINDOWN = (1 << 11), /* don't spindown before poweroff */
1652a6e58d2SRafael J. Wysocki ATA_FLAG_NO_HIBERNATE_SPINDOWN = (1 << 12), /* don't spindown before hibernation */
1667395acb2STejun Heo ATA_FLAG_DEBUGMSG = (1 << 13),
167388539f3SShaohua Li ATA_FLAG_FPDMA_AA = (1 << 14), /* driver supports Auto-Activate */
168b2a8bbe6STejun Heo ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
169f834e49fSAlan Cox ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */
1703cadbcc0STejun Heo ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */
1719f45cbd3SKristen Carlson Accardi ATA_FLAG_AN = (1 << 18), /* controller supports AN */
172e0a71752STejun Heo ATA_FLAG_PMP = (1 << 19), /* controller supports PMP */
17340fb59e7SMarc Carino ATA_FLAG_FPDMA_AUX = (1 << 20), /* controller supports H2DFIS aux field */
17418f7ba4cSKristen Carlson Accardi ATA_FLAG_EM = (1 << 21), /* driver supports enclosure
17518f7ba4cSKristen Carlson Accardi * management */
17618f7ba4cSKristen Carlson Accardi ATA_FLAG_SW_ACTIVITY = (1 << 22), /* driver supports sw activity
17718f7ba4cSKristen Carlson Accardi * led */
178ae01b249STejun Heo ATA_FLAG_NO_DIPM = (1 << 23), /* host not happy with DIPM */
179a1480a16SLinus Torvalds ATA_FLAG_SAS_HOST = (1 << 24), /* SAS host */
1801da177e4SLinus Torvalds
181b51e9e5dSTejun Heo /* bits 24:31 of ap->flags are reserved for LLD specific flags */
1829b847548SJens Axboe
183e3cf95ddSAlan Cox
184b51e9e5dSTejun Heo /* struct ata_port pflags */
185b51e9e5dSTejun Heo ATA_PFLAG_EH_PENDING = (1 << 0), /* EH pending */
186b51e9e5dSTejun Heo ATA_PFLAG_EH_IN_PROGRESS = (1 << 1), /* EH in progress */
187b51e9e5dSTejun Heo ATA_PFLAG_FROZEN = (1 << 2), /* port is frozen */
188b51e9e5dSTejun Heo ATA_PFLAG_RECOVERED = (1 << 3), /* recovery action performed */
189b51e9e5dSTejun Heo ATA_PFLAG_LOADING = (1 << 4), /* boot/loading probe */
190b51e9e5dSTejun Heo ATA_PFLAG_SCSI_HOTPLUG = (1 << 6), /* SCSI hotplug scheduled */
191f4d6d004STejun Heo ATA_PFLAG_INITIALIZING = (1 << 7), /* being initialized, don't touch */
192afaa5c37STejun Heo ATA_PFLAG_RESETTING = (1 << 8), /* reset in progress */
193ece180d1STejun Heo ATA_PFLAG_UNLOADING = (1 << 9), /* driver is being unloaded */
194ece180d1STejun Heo ATA_PFLAG_UNLOADED = (1 << 10), /* driver is unloaded */
195b51e9e5dSTejun Heo
196aa3998dbSDamien Le Moal ATA_PFLAG_RESUMING = (1 << 16), /* port is being resumed */
197b51e9e5dSTejun Heo ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */
198500530f6STejun Heo ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */
199c05e6ff0STejun Heo ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */
2008d238e01SAlan Cox
201e3cf95ddSAlan Cox ATA_PFLAG_PIO32 = (1 << 20), /* 32bit PIO */
202e3cf95ddSAlan Cox ATA_PFLAG_PIO32CHANGE = (1 << 21), /* 32bit PIO can be turned on/off */
2038a3e33cfSManuel Lauss ATA_PFLAG_EXTERNAL = (1 << 22), /* eSATA/external port */
204e3cf95ddSAlan Cox
205949b38afSTejun Heo /* struct ata_queued_cmd flags */
206949b38afSTejun Heo ATA_QCFLAG_ACTIVE = (1 << 0), /* cmd not yet ack'd to scsi lyer */
207001102d7STejun Heo ATA_QCFLAG_DMAMAP = (1 << 1), /* SG table is DMA mapped */
20893c4aa44SNiklas Cassel ATA_QCFLAG_RTF_FILLED = (1 << 2), /* result TF has been filled */
20927197367STejun Heo ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
210e61e0672STejun Heo ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
211da917d69STejun Heo ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */
212e027bd36STejun Heo ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */
21303faab78STejun Heo ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */
214eafe804bSDamien Le Moal ATA_QCFLAG_HAS_CDL = (1 << 8), /* qc has CDL a descriptor set */
215e61e0672STejun Heo
21687629312SNiklas Cassel ATA_QCFLAG_EH = (1 << 16), /* cmd aborted and owned by EH */
2179ec957f2STejun Heo ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
2189ec957f2STejun Heo ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
21918bd7718SNiklas Cassel ATA_QCFLAG_EH_SUCCESS_CMD = (1 << 19), /* EH should fetch sense for this successful cmd */
2201da177e4SLinus Torvalds
2214e5ec5dbSAlan Cox /* host set flags */
222cca3974eSJeff Garzik ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */
223ecef7253STejun Heo ATA_HOST_STARTED = (1 << 1), /* Host started */
224886ad09fSArjan van de Ven ATA_HOST_PARALLEL_SCAN = (1 << 2), /* Ports on this host can be scanned in parallel */
225db63a4c8SAndy Whitcroft ATA_HOST_IGNORE_ATA = (1 << 3), /* Ignore ATA devices on this host. */
2264e5ec5dbSAlan Cox
22724e0e61dSNiklas Cassel ATA_HOST_NO_PART = (1 << 4), /* Host does not support partial */
22824e0e61dSNiklas Cassel ATA_HOST_NO_SSC = (1 << 5), /* Host does not support slumber */
22924e0e61dSNiklas Cassel ATA_HOST_NO_DEVSLP = (1 << 6), /* Host does not support devslp */
23024e0e61dSNiklas Cassel
231b8b275efSTejun Heo /* bits 24:31 of host->flags are reserved for LLD specific flags */
232b8b275efSTejun Heo
2331da177e4SLinus Torvalds /* various lengths of time */
234341c2c95STejun Heo ATA_TMOUT_BOOT = 30000, /* heuristic */
235341c2c95STejun Heo ATA_TMOUT_BOOT_QUICK = 7000, /* heuristic */
236341c2c95STejun Heo ATA_TMOUT_INTERNAL_QUICK = 5000,
23745fabbb7SElias Oltmanns ATA_TMOUT_MAX_PARK = 30000,
2381da177e4SLinus Torvalds
239b48d58f5STejun Heo /*
240b48d58f5STejun Heo * GoVault needs 2s and iVDR disk HHD424020F7SV00 800ms. 2s
241b48d58f5STejun Heo * is too much without parallel probing. Use 2s if parallel
242b48d58f5STejun Heo * probing is available, 800ms otherwise.
24388ff6eafSTejun Heo */
244b48d58f5STejun Heo ATA_TMOUT_FF_WAIT_LONG = 2000,
245341c2c95STejun Heo ATA_TMOUT_FF_WAIT = 800,
24688ff6eafSTejun Heo
247705e76beSTejun Heo /* Spec mandates to wait for ">= 2ms" before checking status
248705e76beSTejun Heo * after reset. We wait 150ms, because that was the magic
249705e76beSTejun Heo * delay used for ATAPI devices in Hale Landis's ATADRVR, for
250705e76beSTejun Heo * the period of time between when the ATA command register is
251705e76beSTejun Heo * written, and then status is checked. Because waiting for
252705e76beSTejun Heo * "a while" before checking status is fine, post SRST, we
253705e76beSTejun Heo * perform this magic delay here as well.
254705e76beSTejun Heo *
255705e76beSTejun Heo * Old drivers/ide uses the 2mS rule and then waits for ready.
256705e76beSTejun Heo */
257341c2c95STejun Heo ATA_WAIT_AFTER_RESET = 150,
258705e76beSTejun Heo
2599dadd45bSTejun Heo /* If PMP is supported, we have to do follow-up SRST. As some
2609dadd45bSTejun Heo * PMPs don't send D2H Reg FIS after hardreset, LLDs are
2619dadd45bSTejun Heo * advised to wait only for the following duration before
2629dadd45bSTejun Heo * doing SRST.
2639dadd45bSTejun Heo */
264753a4d53SMatthias Schiffer ATA_TMOUT_PMP_SRST_WAIT = 10000,
2659dadd45bSTejun Heo
26609c5b480SGabriele Mazzotta /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might
26709c5b480SGabriele Mazzotta * be a spurious PHY event, so ignore the first PHY event that
26809c5b480SGabriele Mazzotta * occurs within 10s after the policy change.
26909c5b480SGabriele Mazzotta */
27009c5b480SGabriele Mazzotta ATA_TMOUT_SPURIOUS_PHY = 10000,
27109c5b480SGabriele Mazzotta
2721da177e4SLinus Torvalds /* ATA bus states */
2731da177e4SLinus Torvalds BUS_UNKNOWN = 0,
2741da177e4SLinus Torvalds BUS_DMA = 1,
2751da177e4SLinus Torvalds BUS_IDLE = 2,
2761da177e4SLinus Torvalds BUS_NOINTR = 3,
2771da177e4SLinus Torvalds BUS_NODATA = 4,
2781da177e4SLinus Torvalds BUS_TIMER = 5,
2791da177e4SLinus Torvalds BUS_PIO = 6,
2801da177e4SLinus Torvalds BUS_EDD = 7,
2811da177e4SLinus Torvalds BUS_IDENTIFY = 8,
2821da177e4SLinus Torvalds BUS_PACKET = 9,
2831da177e4SLinus Torvalds
2841da177e4SLinus Torvalds /* SATA port states */
2851da177e4SLinus Torvalds PORT_UNKNOWN = 0,
2861da177e4SLinus Torvalds PORT_ENABLED = 1,
2871da177e4SLinus Torvalds PORT_DISABLED = 2,
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds /* encoding various smaller bitmaps into a single
290f0a6d77bSSergey Shtylyov * unsigned int bitmap
2911da177e4SLinus Torvalds */
29270cd071eSTejun Heo ATA_NR_PIO_MODES = 7,
29370cd071eSTejun Heo ATA_NR_MWDMA_MODES = 5,
29470cd071eSTejun Heo ATA_NR_UDMA_MODES = 8,
2951da7b0d0STejun Heo
2961da7b0d0STejun Heo ATA_SHIFT_PIO = 0,
29770cd071eSTejun Heo ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
29870cd071eSTejun Heo ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
2998e061784SAdam Manzanares ATA_SHIFT_PRIO = 6,
3001da7b0d0STejun Heo
3018e061784SAdam Manzanares ATA_PRIO_HIGH = 2,
302cedc9a47SJeff Garzik /* size of buffer to pad xfers ending on unaligned boundaries */
303cedc9a47SJeff Garzik ATA_DMA_PAD_SZ = 4,
304c4052da6SJeff Garzik
3050c247c55STejun Heo /* ering size */
3060c247c55STejun Heo ATA_ERING_SIZE = 32,
3070c247c55STejun Heo
30831cc23b3STejun Heo /* return values for ->qc_defer */
30931cc23b3STejun Heo ATA_DEFER_LINK = 1,
31031cc23b3STejun Heo ATA_DEFER_PORT = 2,
31131cc23b3STejun Heo
312f3e81b19STejun Heo /* desc_len for ata_eh_info and context */
313f3e81b19STejun Heo ATA_EH_DESC_LEN = 80,
314f3e81b19STejun Heo
3159be1e979STejun Heo /* reset / recovery action types */
3169be1e979STejun Heo ATA_EH_REVALIDATE = (1 << 0),
317cf480626STejun Heo ATA_EH_SOFTRESET = (1 << 1), /* meaningful only in ->prereset */
318cf480626STejun Heo ATA_EH_HARDRESET = (1 << 2), /* meaningful only in ->prereset */
319cf480626STejun Heo ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
320f9df58cbSTejun Heo ATA_EH_ENABLE_LINK = (1 << 3),
32145fabbb7SElias Oltmanns ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */
32218bd7718SNiklas Cassel ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */
323aa3998dbSDamien Le Moal ATA_EH_SET_ACTIVE = (1 << 7), /* Set a device to active power mode */
3249be1e979STejun Heo
32518bd7718SNiklas Cassel ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK |
326aa3998dbSDamien Le Moal ATA_EH_GET_SUCCESS_SENSE | ATA_EH_SET_ACTIVE,
327b5b3fa38STejun Heo ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET |
3286b7ae954STejun Heo ATA_EH_ENABLE_LINK,
3299be1e979STejun Heo
330f3e81b19STejun Heo /* ata_eh_info->flags */
331abdda733STejun Heo ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
3321cdaf534STejun Heo ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
3331cdaf534STejun Heo ATA_EHI_QUIET = (1 << 3), /* be quiet */
334e2f3d75fSTejun Heo ATA_EHI_NO_RECOVERY = (1 << 4), /* no recovery */
335abdda733STejun Heo
3360d64a233STejun Heo ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */
3370d64a233STejun Heo ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */
3380d64a233STejun Heo ATA_EHI_PRINTINFO = (1 << 18), /* print configuration info */
3390d64a233STejun Heo ATA_EHI_SETMODE = (1 << 19), /* configure transfer mode */
34089692c03SAndrea Gelmini ATA_EHI_POST_SETMODE = (1 << 20), /* revalidating after setmode */
341f3e81b19STejun Heo
3420d64a233STejun Heo ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
34313abf50dSTejun Heo
344848e4c68STejun Heo /* mask of flags to transfer *to* the slave link */
345848e4c68STejun Heo ATA_EHI_TO_SLAVE_MASK = ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET,
346848e4c68STejun Heo
347a1e10f7eSTejun Heo /* max tries if error condition is still set after ->error_handler */
348a1e10f7eSTejun Heo ATA_EH_MAX_TRIES = 5,
349ad9e2762STejun Heo
3505040ab67STejun Heo /* sometimes resuming a link requires several retries */
3515040ab67STejun Heo ATA_LINK_RESUME_TRIES = 5,
3525040ab67STejun Heo
35314d2bac1STejun Heo /* how hard are we gonna try to probe/recover devices */
354022bdb07STejun Heo ATA_EH_DEV_TRIES = 3,
355e0a71752STejun Heo ATA_EH_PMP_TRIES = 5,
356e0a71752STejun Heo ATA_EH_PMP_LINK_TRIES = 3,
357e0a71752STejun Heo
358bf1bff6fSTejun Heo SATA_PMP_RW_TIMEOUT = 3000, /* PMP read/write timeout */
359f5914a46STejun Heo
36087fbc5a0STejun Heo /* This should match the actual table size of
36187fbc5a0STejun Heo * ata_eh_cmd_timeout_table in libata-eh.c.
36287fbc5a0STejun Heo */
363aa3998dbSDamien Le Moal ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 8,
36487fbc5a0STejun Heo
36593590859SAlan Cox /* Horkage types. May be set by libata or controller on drives
36625985edcSLucas De Marchi (some horkage may be drive/controller pair dependent */
36793590859SAlan Cox
36893590859SAlan Cox ATA_HORKAGE_DIAGNOSTIC = (1 << 0), /* Failed boot diag */
3696919a0a6SAlan Cox ATA_HORKAGE_NODMA = (1 << 1), /* DMA problems */
3706919a0a6SAlan Cox ATA_HORKAGE_NONCQ = (1 << 2), /* Don't use NCQ */
37118d6e9d5SAlbert Lee ATA_HORKAGE_MAX_SEC_128 = (1 << 3), /* Limit max sects to 128 */
37216c55b03STejun Heo ATA_HORKAGE_BROKEN_HPA = (1 << 4), /* Broken HPA */
37350af2fa1STejun Heo ATA_HORKAGE_DISABLE = (1 << 5), /* Disable it */
37493328e11SAlan Cox ATA_HORKAGE_HPA_SIZE = (1 << 6), /* native size off by one */
3756bbfd53dSAlan Cox ATA_HORKAGE_IVB = (1 << 8), /* cbl det validity bit bugs */
3762d3b8eeaSAlbert Lee ATA_HORKAGE_STUCK_ERR = (1 << 9), /* stuck ERR on next PACKET */
3779ce8e307SJens Axboe ATA_HORKAGE_BRIDGE_OK = (1 << 10), /* no bridge limits */
3786a87e42eSTejun Heo ATA_HORKAGE_ATAPI_MOD16_DMA = (1 << 11), /* use ATAPI DMA for commands
3796a87e42eSTejun Heo not multiple of 16 bytes */
380877d0310SNick Andrew ATA_HORKAGE_FIRMWARE_WARN = (1 << 12), /* firmware update warning */
3819062712fSTejun Heo ATA_HORKAGE_1_5_GBPS = (1 << 13), /* force 1.5 Gbps */
382d0cb43b3STejun Heo ATA_HORKAGE_NOSETXFER = (1 << 14), /* skip SETXFER, SATA only */
383388539f3SShaohua Li ATA_HORKAGE_BROKEN_FPDMA_AA = (1 << 15), /* skip AA */
38443c9c591STejun Heo ATA_HORKAGE_DUMP_ID = (1 << 16), /* dump IDENTIFY data */
385a32450e1SShan Hai ATA_HORKAGE_MAX_SEC_LBA48 = (1 << 17), /* Set max sects to 65535 */
386966fbe19SVincent Pelletier ATA_HORKAGE_ATAPI_DMADIR = (1 << 18), /* device requires dmadir */
387f78dea06SMarc Carino ATA_HORKAGE_NO_NCQ_TRIM = (1 << 19), /* don't use queued TRIM */
388ecd75ad5STejun Heo ATA_HORKAGE_NOLPM = (1 << 20), /* don't use LPM */
389ecd75ad5STejun Heo ATA_HORKAGE_WD_BROKEN_LPM = (1 << 21), /* some WDs have broken LPM */
390e61f7d1cSMartin K. Petersen ATA_HORKAGE_ZERO_AFTER_TRIM = (1 << 22),/* guarantees zero after trim */
3917cfdfdc8SDamien Le Moal ATA_HORKAGE_NO_DMA_LOG = (1 << 23), /* don't use DMA for log read */
39271d126fdSArne Fitzenreiter ATA_HORKAGE_NOTRIM = (1 << 24), /* don't use TRIM */
393af34d637SDavid Milburn ATA_HORKAGE_MAX_SEC_1024 = (1 << 25), /* Limit max sects to 1024 */
3943b545563STejun Heo ATA_HORKAGE_MAX_TRIM_128M = (1 << 26), /* Limit max trim size to 128M */
3957a8526a5SKate Hsuan ATA_HORKAGE_NO_NCQ_ON_ATI = (1 << 27), /* Disable NCQ on ATI chipset */
396636f6e2aSDamien Le Moal ATA_HORKAGE_NO_ID_DEV_LOG = (1 << 28), /* Identify device log missing */
397ac9f0c81SAnton Lundin ATA_HORKAGE_NO_LOG_DIR = (1 << 29), /* Do not read log directory */
3984d2e4980SDamien Le Moal ATA_HORKAGE_NO_FUA = (1 << 30), /* Do not use FUA */
399b3a70601SAlan Cox
400b3a70601SAlan Cox /* DMA mask for user DMA control: User visible values; DO NOT
401b3a70601SAlan Cox renumber */
402b3a70601SAlan Cox ATA_DMA_MASK_ATA = (1 << 0), /* DMA on ATA Disk */
403b3a70601SAlan Cox ATA_DMA_MASK_ATAPI = (1 << 1), /* DMA on ATAPI */
404b3a70601SAlan Cox ATA_DMA_MASK_CFA = (1 << 2), /* DMA on CF Card */
405ceb0c642STejun Heo
406ceb0c642STejun Heo /* ATAPI command types */
407ceb0c642STejun Heo ATAPI_READ = 0, /* READs */
408ceb0c642STejun Heo ATAPI_WRITE = 1, /* WRITEs */
409ceb0c642STejun Heo ATAPI_READ_CD = 2, /* READ CD [MSF] */
410e52dcc48STejun Heo ATAPI_PASS_THRU = 3, /* SAT pass-thru */
411e52dcc48STejun Heo ATAPI_MISC = 4, /* the rest */
412624d5c51STejun Heo
413624d5c51STejun Heo /* Timing constants */
414624d5c51STejun Heo ATA_TIMING_SETUP = (1 << 0),
415624d5c51STejun Heo ATA_TIMING_ACT8B = (1 << 1),
416624d5c51STejun Heo ATA_TIMING_REC8B = (1 << 2),
417624d5c51STejun Heo ATA_TIMING_CYC8B = (1 << 3),
418624d5c51STejun Heo ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
419624d5c51STejun Heo ATA_TIMING_CYC8B,
420624d5c51STejun Heo ATA_TIMING_ACTIVE = (1 << 4),
421624d5c51STejun Heo ATA_TIMING_RECOVER = (1 << 5),
4223ada9c12SDavid Daney ATA_TIMING_DMACK_HOLD = (1 << 6),
4233ada9c12SDavid Daney ATA_TIMING_CYCLE = (1 << 7),
4243ada9c12SDavid Daney ATA_TIMING_UDMA = (1 << 8),
425624d5c51STejun Heo ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
426624d5c51STejun Heo ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
427624d5c51STejun Heo ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
4283ada9c12SDavid Daney ATA_TIMING_DMACK_HOLD | ATA_TIMING_CYCLE |
4293ada9c12SDavid Daney ATA_TIMING_UDMA,
430f1bce7f8STejun Heo
431f1bce7f8STejun Heo /* ACPI constants */
432f1bce7f8STejun Heo ATA_ACPI_FILTER_SETXFER = 1 << 0,
433f1bce7f8STejun Heo ATA_ACPI_FILTER_LOCK = 1 << 1,
434f1bce7f8STejun Heo ATA_ACPI_FILTER_DIPM = 1 << 2,
435fa5b561cSTejun Heo ATA_ACPI_FILTER_FPDMA_OFFSET = 1 << 3, /* FPDMA non-zero offset */
436fa5b561cSTejun Heo ATA_ACPI_FILTER_FPDMA_AA = 1 << 4, /* FPDMA auto activate */
437f1bce7f8STejun Heo
438f1bce7f8STejun Heo ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER |
439f1bce7f8STejun Heo ATA_ACPI_FILTER_LOCK |
440f1bce7f8STejun Heo ATA_ACPI_FILTER_DIPM,
4411da177e4SLinus Torvalds };
4421da177e4SLinus Torvalds
4437dc951aeSTejun Heo enum ata_xfer_mask {
444f0a6d77bSSergey Shtylyov ATA_MASK_PIO = ((1U << ATA_NR_PIO_MODES) - 1) << ATA_SHIFT_PIO,
445f0a6d77bSSergey Shtylyov ATA_MASK_MWDMA = ((1U << ATA_NR_MWDMA_MODES) - 1) << ATA_SHIFT_MWDMA,
446f0a6d77bSSergey Shtylyov ATA_MASK_UDMA = ((1U << ATA_NR_UDMA_MODES) - 1) << ATA_SHIFT_UDMA,
4477dc951aeSTejun Heo };
4487dc951aeSTejun Heo
44914be71f4SAlbert Lee enum hsm_task_states {
450c56b14d2SAlbert Lee HSM_ST_IDLE, /* no command on going */
45171527647SAlbert Lee HSM_ST_FIRST, /* (waiting the device to)
45271527647SAlbert Lee write CDB or first data block */
453c56b14d2SAlbert Lee HSM_ST, /* (waiting the device to) transfer data */
454c56b14d2SAlbert Lee HSM_ST_LAST, /* (waiting the device to) complete command */
455c56b14d2SAlbert Lee HSM_ST_ERR, /* error */
4561da177e4SLinus Torvalds };
4571da177e4SLinus Torvalds
458a7dac447SJeff Garzik enum ata_completion_errors {
45925937580SJiri Slaby AC_ERR_OK = 0, /* no error */
46011a56d24STejun Heo AC_ERR_DEV = (1 << 0), /* device reported error */
46111a56d24STejun Heo AC_ERR_HSM = (1 << 1), /* host state machine violation */
46211a56d24STejun Heo AC_ERR_TIMEOUT = (1 << 2), /* timeout */
46311a56d24STejun Heo AC_ERR_MEDIA = (1 << 3), /* media error */
46411a56d24STejun Heo AC_ERR_ATA_BUS = (1 << 4), /* ATA bus error */
46511a56d24STejun Heo AC_ERR_HOST_BUS = (1 << 5), /* host bus error */
46611a56d24STejun Heo AC_ERR_SYSTEM = (1 << 6), /* system error */
46711a56d24STejun Heo AC_ERR_INVALID = (1 << 7), /* invalid argument */
46811a56d24STejun Heo AC_ERR_OTHER = (1 << 8), /* unknown */
46955a8e2c8STejun Heo AC_ERR_NODEV_HINT = (1 << 9), /* polling device detection hint */
4705335b729STejun Heo AC_ERR_NCQ = (1 << 10), /* marker for offending NCQ qc */
471a7dac447SJeff Garzik };
472a7dac447SJeff Garzik
473c93b263eSTejun Heo /*
474c93b263eSTejun Heo * Link power management policy: If you alter this, you also need to
475c93b263eSTejun Heo * alter libata-scsi.c (for the ascii descriptions)
476c93b263eSTejun Heo */
477c93b263eSTejun Heo enum ata_lpm_policy {
478c93b263eSTejun Heo ATA_LPM_UNKNOWN,
479c93b263eSTejun Heo ATA_LPM_MAX_POWER,
480c93b263eSTejun Heo ATA_LPM_MED_POWER,
481f4ac6476SHans de Goede ATA_LPM_MED_POWER_WITH_DIPM, /* Med power + DIPM as win IRST does */
482a5ec5a7bSSrinivas Pandruvada ATA_LPM_MIN_POWER_WITH_PARTIAL, /* Min Power + partial and slumber */
483a5ec5a7bSSrinivas Pandruvada ATA_LPM_MIN_POWER, /* Min power + no partial (slumber only) */
484c93b263eSTejun Heo };
485c93b263eSTejun Heo
4866b7ae954STejun Heo enum ata_lpm_hints {
4876b7ae954STejun Heo ATA_LPM_EMPTY = (1 << 0), /* port empty/probing */
4886b7ae954STejun Heo ATA_LPM_HIPM = (1 << 1), /* may use HIPM */
489fb329633SDanesh Petigara ATA_LPM_WAKE_ONLY = (1 << 2), /* only wake up link */
4906b7ae954STejun Heo };
4916b7ae954STejun Heo
4921da177e4SLinus Torvalds /* forward declarations */
4931da177e4SLinus Torvalds struct scsi_device;
4941da177e4SLinus Torvalds struct ata_port_operations;
4951da177e4SLinus Torvalds struct ata_port;
496cc0680a5STejun Heo struct ata_link;
4971da177e4SLinus Torvalds struct ata_queued_cmd;
4981da177e4SLinus Torvalds
4991da177e4SLinus Torvalds /* typedefs */
50077853bf2STejun Heo typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
501cc0680a5STejun Heo typedef int (*ata_prereset_fn_t)(struct ata_link *link, unsigned long deadline);
502cc0680a5STejun Heo typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
503d4b2bab4STejun Heo unsigned long deadline);
504cc0680a5STejun Heo typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
5051da177e4SLinus Torvalds
50645fabbb7SElias Oltmanns extern struct device_attribute dev_attr_unload_heads;
507ec811a94SBartlomiej Zolnierkiewicz #ifdef CONFIG_SATA_HOST
508ec811a94SBartlomiej Zolnierkiewicz extern struct device_attribute dev_attr_link_power_management_policy;
5095f91b8f5SDamien Le Moal extern struct device_attribute dev_attr_ncq_prio_supported;
51084f95243SAdam Manzanares extern struct device_attribute dev_attr_ncq_prio_enable;
51118f7ba4cSKristen Carlson Accardi extern struct device_attribute dev_attr_em_message_type;
51218f7ba4cSKristen Carlson Accardi extern struct device_attribute dev_attr_em_message;
51318f7ba4cSKristen Carlson Accardi extern struct device_attribute dev_attr_sw_activity;
514ec811a94SBartlomiej Zolnierkiewicz #endif
51518f7ba4cSKristen Carlson Accardi
51618f7ba4cSKristen Carlson Accardi enum sw_activity {
51718f7ba4cSKristen Carlson Accardi OFF,
51818f7ba4cSKristen Carlson Accardi BLINK_ON,
51918f7ba4cSKristen Carlson Accardi BLINK_OFF,
52018f7ba4cSKristen Carlson Accardi };
521ca77329fSKristen Carlson Accardi
522dc34e7e1SSergei Shtylyov struct ata_taskfile {
523dc34e7e1SSergei Shtylyov unsigned long flags; /* ATA_TFLAG_xxx */
524dc34e7e1SSergei Shtylyov u8 protocol; /* ATA_PROT_xxx */
525dc34e7e1SSergei Shtylyov
526dc34e7e1SSergei Shtylyov u8 ctl; /* control reg */
527dc34e7e1SSergei Shtylyov
528dc34e7e1SSergei Shtylyov u8 hob_feature; /* additional data */
529dc34e7e1SSergei Shtylyov u8 hob_nsect; /* to support LBA48 */
530dc34e7e1SSergei Shtylyov u8 hob_lbal;
531dc34e7e1SSergei Shtylyov u8 hob_lbam;
532dc34e7e1SSergei Shtylyov u8 hob_lbah;
533dc34e7e1SSergei Shtylyov
534efcef265SSergey Shtylyov union {
535efcef265SSergey Shtylyov u8 error;
536dc34e7e1SSergei Shtylyov u8 feature;
537efcef265SSergey Shtylyov };
538dc34e7e1SSergei Shtylyov u8 nsect;
539dc34e7e1SSergei Shtylyov u8 lbal;
540dc34e7e1SSergei Shtylyov u8 lbam;
541dc34e7e1SSergei Shtylyov u8 lbah;
542dc34e7e1SSergei Shtylyov
543dc34e7e1SSergei Shtylyov u8 device;
544dc34e7e1SSergei Shtylyov
545efcef265SSergey Shtylyov union {
546efcef265SSergey Shtylyov u8 status;
547efcef265SSergey Shtylyov u8 command;
548efcef265SSergey Shtylyov };
5498be5ad9aSMarc Carino
5508be5ad9aSMarc Carino u32 auxiliary; /* auxiliary field */
5518be5ad9aSMarc Carino /* from SATA 3.1 and */
5528be5ad9aSMarc Carino /* ATA-8 ACS-3 */
553dc34e7e1SSergei Shtylyov };
554dc34e7e1SSergei Shtylyov
555127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
5561da177e4SLinus Torvalds struct ata_ioports {
5570d5ff566STejun Heo void __iomem *cmd_addr;
5580d5ff566STejun Heo void __iomem *data_addr;
5590d5ff566STejun Heo void __iomem *error_addr;
5600d5ff566STejun Heo void __iomem *feature_addr;
5610d5ff566STejun Heo void __iomem *nsect_addr;
5620d5ff566STejun Heo void __iomem *lbal_addr;
5630d5ff566STejun Heo void __iomem *lbam_addr;
5640d5ff566STejun Heo void __iomem *lbah_addr;
5650d5ff566STejun Heo void __iomem *device_addr;
5660d5ff566STejun Heo void __iomem *status_addr;
5670d5ff566STejun Heo void __iomem *command_addr;
5680d5ff566STejun Heo void __iomem *altstatus_addr;
5690d5ff566STejun Heo void __iomem *ctl_addr;
5709a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
5710d5ff566STejun Heo void __iomem *bmdma_addr;
5729a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
5730d5ff566STejun Heo void __iomem *scr_addr;
5741da177e4SLinus Torvalds };
575127102aeSTejun Heo #endif /* CONFIG_ATA_SFF */
5761da177e4SLinus Torvalds
577cca3974eSJeff Garzik struct ata_host {
5781da177e4SLinus Torvalds spinlock_t lock;
5791da177e4SLinus Torvalds struct device *dev;
5800d5ff566STejun Heo void __iomem * const *iomap;
5811da177e4SLinus Torvalds unsigned int n_ports;
5821a112d10STejun Heo unsigned int n_tags; /* nr of NCQ tags */
5831da177e4SLinus Torvalds void *private_data;
584029cfd6bSTejun Heo struct ata_port_operations *ops;
5855444a6f4SAlan Cox unsigned long flags;
5862623c7a5STaras Kondratiuk struct kref kref;
587c0c362b6STejun Heo
588c0c362b6STejun Heo struct mutex eh_mutex;
589c0c362b6STejun Heo struct task_struct *eh_owner;
590c0c362b6STejun Heo
591032af1ceSAlan struct ata_port *simplex_claimed; /* channel owning the DMA */
5929c5fbf05SGustavo A. R. Silva struct ata_port *ports[];
5931da177e4SLinus Torvalds };
5941da177e4SLinus Torvalds
5951da177e4SLinus Torvalds struct ata_queued_cmd {
5961da177e4SLinus Torvalds struct ata_port *ap;
5971da177e4SLinus Torvalds struct ata_device *dev;
5981da177e4SLinus Torvalds
5991da177e4SLinus Torvalds struct scsi_cmnd *scsicmd;
6001da177e4SLinus Torvalds void (*scsidone)(struct scsi_cmnd *);
6011da177e4SLinus Torvalds
6021da177e4SLinus Torvalds struct ata_taskfile tf;
6031da177e4SLinus Torvalds u8 cdb[ATAPI_CDB_LEN];
6041da177e4SLinus Torvalds
6051da177e4SLinus Torvalds unsigned long flags; /* ATA_QCFLAG_xxx */
6065ac40790SJens Axboe unsigned int tag; /* libata core tag */
6075ac40790SJens Axboe unsigned int hw_tag; /* driver tag */
6081da177e4SLinus Torvalds unsigned int n_elem;
6095825627cSFUJITA Tomonori unsigned int orig_n_elem;
6101da177e4SLinus Torvalds
6111da177e4SLinus Torvalds int dma_dir;
6121da177e4SLinus Torvalds
6135a5dbd18SMark Lord unsigned int sect_size;
614cedc9a47SJeff Garzik
6151da177e4SLinus Torvalds unsigned int nbytes;
616aacda375STejun Heo unsigned int extrabytes;
6171da177e4SLinus Torvalds unsigned int curbytes;
6181da177e4SLinus Torvalds
6191da177e4SLinus Torvalds struct scatterlist sgent;
6201da177e4SLinus Torvalds
621ff2aeb1eSTejun Heo struct scatterlist *sg;
6221da177e4SLinus Torvalds
623b34e9042SRichard Kennedy struct scatterlist *cursg;
624b34e9042SRichard Kennedy unsigned int cursg_ofs;
625b34e9042SRichard Kennedy
626a22e2eb0SAlbert Lee unsigned int err_mask;
627e61e0672STejun Heo struct ata_taskfile result_tf;
6281da177e4SLinus Torvalds ata_qc_cb_t complete_fn;
6291da177e4SLinus Torvalds
6301da177e4SLinus Torvalds void *private_data;
6311c50dc83SDarrick J. Wong void *lldd_task;
6321da177e4SLinus Torvalds };
6331da177e4SLinus Torvalds
634cca3974eSJeff Garzik struct ata_port_stats {
6351da177e4SLinus Torvalds unsigned long unhandled_irq;
6361da177e4SLinus Torvalds unsigned long idle_irq;
6371da177e4SLinus Torvalds unsigned long rw_reqbuf;
6381da177e4SLinus Torvalds };
6391da177e4SLinus Torvalds
6400c247c55STejun Heo struct ata_ering_entry {
6413884f7b0STejun Heo unsigned int eflags;
6420c247c55STejun Heo unsigned int err_mask;
6430c247c55STejun Heo u64 timestamp;
6440c247c55STejun Heo };
6450c247c55STejun Heo
6460c247c55STejun Heo struct ata_ering {
6470c247c55STejun Heo int cursor;
6480c247c55STejun Heo struct ata_ering_entry ring[ATA_ERING_SIZE];
6490c247c55STejun Heo };
6500c247c55STejun Heo
651fe22e1c2SDamien Le Moal struct ata_cpr {
652fe22e1c2SDamien Le Moal u8 num;
653fe22e1c2SDamien Le Moal u8 num_storage_elements;
654fe22e1c2SDamien Le Moal u64 start_lba;
655fe22e1c2SDamien Le Moal u64 num_lbas;
656fe22e1c2SDamien Le Moal };
657fe22e1c2SDamien Le Moal
658fe22e1c2SDamien Le Moal struct ata_cpr_log {
659fe22e1c2SDamien Le Moal u8 nr_cpr;
660fe22e1c2SDamien Le Moal struct ata_cpr cpr[];
661fe22e1c2SDamien Le Moal };
662fe22e1c2SDamien Le Moal
6631da177e4SLinus Torvalds struct ata_device {
6649af5c9c9STejun Heo struct ata_link *link;
6651da177e4SLinus Torvalds unsigned int devno; /* 0 or 1 */
66675683fe7STejun Heo unsigned int horkage; /* List of broken features */
6676866e7bcSRichard Kennedy unsigned long flags; /* ATA_DFLAG_xxx */
6683edebac4STejun Heo struct scsi_device *sdev; /* attached SCSI device */
66995514fd8SBartlomiej Zolnierkiewicz void *private_data;
670fafbae87STejun Heo #ifdef CONFIG_ATA_ACPI
671398e0782STejun Heo union acpi_object *gtf_cache;
672110f66d2STejun Heo unsigned int gtf_filter;
673fafbae87STejun Heo #endif
674afe75951SAaron Lu #ifdef CONFIG_SATA_ZPODD
675afe75951SAaron Lu void *zpodd;
676afe75951SAaron Lu #endif
677d9027470SGwendal Grignou struct device tdev;
67899cf610aSTejun Heo /* n_sector is CLEAR_BEGIN, read comment above CLEAR_BEGIN */
67972fa4b74STejun Heo u64 n_sectors; /* size of device, if ATA */
6805920dadfSTejun Heo u64 n_native_sectors; /* native size, if ATA */
68172fa4b74STejun Heo unsigned int class; /* ATA_DEV_xxx */
68245fabbb7SElias Oltmanns unsigned long unpark_deadline;
683e0a71752STejun Heo
6841da177e4SLinus Torvalds u8 pio_mode;
6851da177e4SLinus Torvalds u8 dma_mode;
6861da177e4SLinus Torvalds u8 xfer_mode;
6871da177e4SLinus Torvalds unsigned int xfer_shift; /* ATA_SHIFT_xxx */
6881da177e4SLinus Torvalds
6898cbd6df1SAlbert Lee unsigned int multi_count; /* sectors count for
6908cbd6df1SAlbert Lee READ/WRITE MULTIPLE */
691b00eec1dSTejun Heo unsigned int max_sectors; /* per-device max sectors */
6926e7846e9STejun Heo unsigned int cdb_len;
6938bf62eceSAlbert Lee
694acf356b1STejun Heo /* per-dev xfer mask */
695f0a6d77bSSergey Shtylyov unsigned int pio_mask;
696f0a6d77bSSergey Shtylyov unsigned int mwdma_mask;
697f0a6d77bSSergey Shtylyov unsigned int udma_mask;
698acf356b1STejun Heo
6998bf62eceSAlbert Lee /* for CHS addressing */
7008bf62eceSAlbert Lee u16 cylinders; /* Number of cylinders */
7018bf62eceSAlbert Lee u16 heads; /* Number of heads */
7028bf62eceSAlbert Lee u16 sectors; /* Number of sectors per track */
7030c247c55STejun Heo
704f7e98930SJeff Garzik union {
705f7e98930SJeff Garzik u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
706f7e98930SJeff Garzik u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
7074ee34ea3SHarvey Hunt } ____cacheline_aligned;
70899cf610aSTejun Heo
709803739d2SShane Huang /* DEVSLP Timing Variables from Identify Device Data Log */
710803739d2SShane Huang u8 devslp_timing[ATA_LOG_DEVSLP_SIZE];
71165fe1f0fSShane Huang
712ed36911cSMarc Carino /* NCQ send and receive log subcommand support */
713ed36911cSMarc Carino u8 ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_SIZE];
714284b3b77SHannes Reinecke u8 ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_SIZE];
715ed36911cSMarc Carino
7166d1003aeSHannes Reinecke /* ZAC zone configuration */
7176d1003aeSHannes Reinecke u32 zac_zoned_cap;
7186d1003aeSHannes Reinecke u32 zac_zones_optimal_open;
7196d1003aeSHannes Reinecke u32 zac_zones_optimal_nonseq;
7206d1003aeSHannes Reinecke u32 zac_zones_max_open;
7216d1003aeSHannes Reinecke
722fe22e1c2SDamien Le Moal /* Concurrent positioning ranges */
723fe22e1c2SDamien Le Moal struct ata_cpr_log *cpr_log;
724fe22e1c2SDamien Le Moal
72562e4a60eSDamien Le Moal /* Command Duration Limits log support */
72662e4a60eSDamien Le Moal u8 cdl[ATA_LOG_CDL_SIZE];
72762e4a60eSDamien Le Moal
72899cf610aSTejun Heo /* error history */
72999cf610aSTejun Heo int spdn_cnt;
73099cf610aSTejun Heo /* ering is CLEAR_END, read comment above CLEAR_END */
73199cf610aSTejun Heo struct ata_ering ering;
7321da177e4SLinus Torvalds };
7331da177e4SLinus Torvalds
73499cf610aSTejun Heo /* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
73599cf610aSTejun Heo * cleared to zero on ata_dev_init().
73672fa4b74STejun Heo */
73799cf610aSTejun Heo #define ATA_DEVICE_CLEAR_BEGIN offsetof(struct ata_device, n_sectors)
73899cf610aSTejun Heo #define ATA_DEVICE_CLEAR_END offsetof(struct ata_device, ering)
73972fa4b74STejun Heo
740f3e81b19STejun Heo struct ata_eh_info {
741f3e81b19STejun Heo struct ata_device *dev; /* offending device */
742f3e81b19STejun Heo u32 serror; /* SError from LLDD */
743f3e81b19STejun Heo unsigned int err_mask; /* port-wide err_mask */
744f3e81b19STejun Heo unsigned int action; /* ATA_EH_* action mask */
74547005f25STejun Heo unsigned int dev_action[ATA_MAX_DEVICES]; /* dev EH action */
746f3e81b19STejun Heo unsigned int flags; /* ATA_EHI_* flags */
747abdda733STejun Heo
748abdda733STejun Heo unsigned int probe_mask;
749abdda733STejun Heo
750f3e81b19STejun Heo char desc[ATA_EH_DESC_LEN];
751f3e81b19STejun Heo int desc_len;
752f3e81b19STejun Heo };
753f3e81b19STejun Heo
754f3e81b19STejun Heo struct ata_eh_context {
755f3e81b19STejun Heo struct ata_eh_info i;
756f3e81b19STejun Heo int tries[ATA_MAX_DEVICES];
75787fbc5a0STejun Heo int cmd_timeout_idx[ATA_MAX_DEVICES]
75887fbc5a0STejun Heo [ATA_EH_CMD_TIMEOUT_TABLE_SIZE];
759abdda733STejun Heo unsigned int classes[ATA_MAX_DEVICES];
760abdda733STejun Heo unsigned int did_probe_mask;
76145fabbb7SElias Oltmanns unsigned int unloaded_mask;
76200115e0fSTejun Heo unsigned int saved_ncq_enabled;
76300115e0fSTejun Heo u8 saved_xfer_mode[ATA_MAX_DEVICES];
7640a2c0f56STejun Heo /* timestamp for the last reset attempt or success */
7650a2c0f56STejun Heo unsigned long last_reset;
766f3e81b19STejun Heo };
767f3e81b19STejun Heo
76864578a3dSTejun Heo struct ata_acpi_drive
76964578a3dSTejun Heo {
77064578a3dSTejun Heo u32 pio;
77164578a3dSTejun Heo u32 dma;
77264578a3dSTejun Heo } __packed;
77364578a3dSTejun Heo
77464578a3dSTejun Heo struct ata_acpi_gtm {
77564578a3dSTejun Heo struct ata_acpi_drive drive[2];
77664578a3dSTejun Heo u32 flags;
77764578a3dSTejun Heo } __packed;
77864578a3dSTejun Heo
7799af5c9c9STejun Heo struct ata_link {
7809af5c9c9STejun Heo struct ata_port *ap;
7818989805dSTejun Heo int pmp; /* port multiplier port # */
7829af5c9c9STejun Heo
783d9027470SGwendal Grignou struct device tdev;
7849af5c9c9STejun Heo unsigned int active_tag; /* active tag on this link */
7859af5c9c9STejun Heo u32 sactive; /* active NCQ commands */
7869af5c9c9STejun Heo
7870c88758bSTejun Heo unsigned int flags; /* ATA_LFLAG_xxx */
7880c88758bSTejun Heo
789d127ea7bSTejun Heo u32 saved_scontrol; /* SControl on probe */
7909af5c9c9STejun Heo unsigned int hw_sata_spd_limit;
7919af5c9c9STejun Heo unsigned int sata_spd_limit;
7929af5c9c9STejun Heo unsigned int sata_spd; /* current SATA PHY speed */
7936b7ae954STejun Heo enum ata_lpm_policy lpm_policy;
7949af5c9c9STejun Heo
7959af5c9c9STejun Heo /* record runtime error info, protected by host_set lock */
7969af5c9c9STejun Heo struct ata_eh_info eh_info;
7979af5c9c9STejun Heo /* EH context */
7989af5c9c9STejun Heo struct ata_eh_context eh_context;
7999af5c9c9STejun Heo
8009af5c9c9STejun Heo struct ata_device device[ATA_MAX_DEVICES];
80109c5b480SGabriele Mazzotta
80209c5b480SGabriele Mazzotta unsigned long last_lpm_change; /* when last LPM change happened */
8039af5c9c9STejun Heo };
804d9027470SGwendal Grignou #define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
805d9027470SGwendal Grignou #define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
8069af5c9c9STejun Heo
8071da177e4SLinus Torvalds struct ata_port {
808cca3974eSJeff Garzik struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
809029cfd6bSTejun Heo struct ata_port_operations *ops;
810ba6a1308SJeff Garzik spinlock_t *lock;
811e3cf95ddSAlan Cox /* Flags owned by the EH context. Only EH should touch these once the
812e3cf95ddSAlan Cox port is active */
8131da177e4SLinus Torvalds unsigned long flags; /* ATA_FLAG_xxx */
814e3cf95ddSAlan Cox /* Flags that change dynamically, protected by ap->lock */
815b51e9e5dSTejun Heo unsigned int pflags; /* ATA_PFLAG_xxx */
81644877b4eSTejun Heo unsigned int print_id; /* user visible unique port ID */
817e628dc99SDavid Milburn unsigned int local_port_no; /* host local port num */
81844877b4eSTejun Heo unsigned int port_no; /* 0 based port no. inside the host */
8191da177e4SLinus Torvalds
820127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
8211da177e4SLinus Torvalds struct ata_ioports ioaddr; /* ATA cmd/ctl/dma register blocks */
8221da177e4SLinus Torvalds u8 ctl; /* cache of ATA control register */
8231da177e4SLinus Torvalds u8 last_ctl; /* Cache last written value */
824ea3c6450SGwendal Grignou struct ata_link* sff_pio_task_link; /* link currently used */
825c429137aSTejun Heo struct delayed_work sff_pio_task;
8269a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
827f60d7011STejun Heo struct ata_bmdma_prd *bmdma_prd; /* BMDMA SG list */
828f60d7011STejun Heo dma_addr_t bmdma_prd_dma; /* and its DMA mapping */
8299a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
8305fe7454aSTejun Heo #endif /* CONFIG_ATA_SFF */
8315fe7454aSTejun Heo
8321da177e4SLinus Torvalds unsigned int pio_mask;
8331da177e4SLinus Torvalds unsigned int mwdma_mask;
8341da177e4SLinus Torvalds unsigned int udma_mask;
8351da177e4SLinus Torvalds unsigned int cbl; /* cable type; ATA_CBL_xxx */
8361da177e4SLinus Torvalds
83728361c40SJens Axboe struct ata_queued_cmd qcmd[ATA_MAX_QUEUE + 1];
838e3ed8939SJens Axboe u64 qc_active;
839da917d69STejun Heo int nr_active_links; /* #links with active qcs */
840dedaf2b0STejun Heo
8419af5c9c9STejun Heo struct ata_link link; /* host default link */
842b1c72916STejun Heo struct ata_link *slave_link; /* see ata_slave_link_init() */
8431da177e4SLinus Torvalds
8448989805dSTejun Heo int nr_pmp_links; /* nr of available PMP links */
8458989805dSTejun Heo struct ata_link *pmp_link; /* array of PMP links */
846da917d69STejun Heo struct ata_link *excl_link; /* for PMP qc exclusion */
8478989805dSTejun Heo
848cca3974eSJeff Garzik struct ata_port_stats stats;
849cca3974eSJeff Garzik struct ata_host *host;
8502f1f610bSBrian King struct device *dev;
851d9027470SGwendal Grignou struct device tdev;
8521da177e4SLinus Torvalds
853ad72cf98STejun Heo struct mutex scsi_scan_mutex;
85452bad64dSDavid Howells struct delayed_work hotplug_task;
8556aa0365aSDamien Le Moal struct delayed_work scsi_rescan_task;
85686e45b6bSTejun Heo
85714be71f4SAlbert Lee unsigned int hsm_task_state;
8581da177e4SLinus Torvalds
859a72ec4ceSTejun Heo struct list_head eh_done_q;
860c6cf9e99STejun Heo wait_queue_head_t eh_wait_q;
861a1e10f7eSTejun Heo int eh_tries;
86245fabbb7SElias Oltmanns struct completion park_req_pending;
863bfd60579SRandy Dunlap
864500530f6STejun Heo pm_message_t pm_mesg;
8656b7ae954STejun Heo enum ata_lpm_policy target_lpm_policy;
866500530f6STejun Heo
8675ddf24c5STejun Heo struct timer_list fastdrain_timer;
8682e0aee8fSSergey Shtylyov unsigned int fastdrain_cnt;
8695ddf24c5STejun Heo
870b5292111SKai-Heng Feng async_cookie_t cookie;
871b5292111SKai-Heng Feng
87218f7ba4cSKristen Carlson Accardi int em_message_type;
8731da177e4SLinus Torvalds void *private_data;
874fe635c7eSTejun Heo
875fafbae87STejun Heo #ifdef CONFIG_ATA_ACPI
876c05e6ff0STejun Heo struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
877fafbae87STejun Heo #endif
87884bda12aSTejun Heo /* owned by EH */
87918bd7718SNiklas Cassel u8 *ncq_sense_buf;
88084bda12aSTejun Heo u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
8811da177e4SLinus Torvalds };
8821da177e4SLinus Torvalds
883029cfd6bSTejun Heo /* The following initializer overrides a method to NULL whether one of
884029cfd6bSTejun Heo * its parent has the method defined or not. This is equivalent to
885029cfd6bSTejun Heo * ERR_PTR(-ENOENT). Unfortunately, ERR_PTR doesn't render a constant
886029cfd6bSTejun Heo * expression and thus can't be used as an initializer.
887029cfd6bSTejun Heo */
888029cfd6bSTejun Heo #define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
889029cfd6bSTejun Heo
8901da177e4SLinus Torvalds struct ata_port_operations {
891c1bc899fSTejun Heo /*
892c1bc899fSTejun Heo * Command execution
893c1bc899fSTejun Heo */
89431cc23b3STejun Heo int (*qc_defer)(struct ata_queued_cmd *qc);
895c1bc899fSTejun Heo int (*check_atapi_dma)(struct ata_queued_cmd *qc);
89695364f36SJiri Slaby enum ata_completion_errors (*qc_prep)(struct ata_queued_cmd *qc);
8979a3d9eb0STejun Heo unsigned int (*qc_issue)(struct ata_queued_cmd *qc);
898931139afSDamien Le Moal void (*qc_fill_rtf)(struct ata_queued_cmd *qc);
89993c4aa44SNiklas Cassel void (*qc_ncq_fill_rtf)(struct ata_port *ap, u64 done_mask);
9001da177e4SLinus Torvalds
901c1bc899fSTejun Heo /*
902c1bc899fSTejun Heo * Configuration and exception handling
9039ec957f2STejun Heo */
904c1bc899fSTejun Heo int (*cable_detect)(struct ata_port *ap);
905f0a6d77bSSergey Shtylyov unsigned int (*mode_filter)(struct ata_device *dev, unsigned int xfer_mask);
906c1bc899fSTejun Heo void (*set_piomode)(struct ata_port *ap, struct ata_device *dev);
907c1bc899fSTejun Heo void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev);
908c1bc899fSTejun Heo int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev);
9090561e514SDamien Le Moal unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf,
9100561e514SDamien Le Moal __le16 *id);
911c1bc899fSTejun Heo
912c1bc899fSTejun Heo void (*dev_config)(struct ata_device *dev);
9139ec957f2STejun Heo
9149ec957f2STejun Heo void (*freeze)(struct ata_port *ap);
9159ec957f2STejun Heo void (*thaw)(struct ata_port *ap);
916a1efdabaSTejun Heo ata_prereset_fn_t prereset;
917a1efdabaSTejun Heo ata_reset_fn_t softreset;
918a1efdabaSTejun Heo ata_reset_fn_t hardreset;
919a1efdabaSTejun Heo ata_postreset_fn_t postreset;
920a1efdabaSTejun Heo ata_prereset_fn_t pmp_prereset;
921a1efdabaSTejun Heo ata_reset_fn_t pmp_softreset;
922a1efdabaSTejun Heo ata_reset_fn_t pmp_hardreset;
923a1efdabaSTejun Heo ata_postreset_fn_t pmp_postreset;
9249ec957f2STejun Heo void (*error_handler)(struct ata_port *ap);
925c96f1732SAlan Cox void (*lost_interrupt)(struct ata_port *ap);
9269ec957f2STejun Heo void (*post_internal_cmd)(struct ata_queued_cmd *qc);
927e4a9c373SDan Williams void (*sched_eh)(struct ata_port *ap);
928e4a9c373SDan Williams void (*end_eh)(struct ata_port *ap);
9291da177e4SLinus Torvalds
930c1bc899fSTejun Heo /*
931c1bc899fSTejun Heo * Optional features
932c1bc899fSTejun Heo */
93382ef04fbSTejun Heo int (*scr_read)(struct ata_link *link, unsigned int sc_reg, u32 *val);
93482ef04fbSTejun Heo int (*scr_write)(struct ata_link *link, unsigned int sc_reg, u32 val);
935c1bc899fSTejun Heo void (*pmp_attach)(struct ata_port *ap);
936c1bc899fSTejun Heo void (*pmp_detach)(struct ata_port *ap);
9376b7ae954STejun Heo int (*set_lpm)(struct ata_link *link, enum ata_lpm_policy policy,
9386b7ae954STejun Heo unsigned hints);
939c1bc899fSTejun Heo
940c1bc899fSTejun Heo /*
941c1bc899fSTejun Heo * Start, stop, suspend and resume
942c1bc899fSTejun Heo */
943c1bc899fSTejun Heo int (*port_suspend)(struct ata_port *ap, pm_message_t mesg);
944c1bc899fSTejun Heo int (*port_resume)(struct ata_port *ap);
9451da177e4SLinus Torvalds int (*port_start)(struct ata_port *ap);
9461da177e4SLinus Torvalds void (*port_stop)(struct ata_port *ap);
947cca3974eSJeff Garzik void (*host_stop)(struct ata_host *host);
9481da177e4SLinus Torvalds
949127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
950c1bc899fSTejun Heo /*
951c1bc899fSTejun Heo * SFF / taskfile oriented ops
952c1bc899fSTejun Heo */
9535682ed33STejun Heo void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
95441dec29bSSergei Shtylyov void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
9555682ed33STejun Heo u8 (*sff_check_status)(struct ata_port *ap);
9565682ed33STejun Heo u8 (*sff_check_altstatus)(struct ata_port *ap);
9575682ed33STejun Heo void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
9585682ed33STejun Heo void (*sff_tf_read)(struct ata_port *ap, struct ata_taskfile *tf);
9595682ed33STejun Heo void (*sff_exec_command)(struct ata_port *ap,
9605682ed33STejun Heo const struct ata_taskfile *tf);
961989e0aacSBartlomiej Zolnierkiewicz unsigned int (*sff_data_xfer)(struct ata_queued_cmd *qc,
9625682ed33STejun Heo unsigned char *buf, unsigned int buflen, int rw);
963e42a542bSSergei Shtylyov void (*sff_irq_on)(struct ata_port *);
96427943620STejun Heo bool (*sff_irq_check)(struct ata_port *);
9655682ed33STejun Heo void (*sff_irq_clear)(struct ata_port *);
9668244cd05STejun Heo void (*sff_drain_fifo)(struct ata_queued_cmd *qc);
967c1bc899fSTejun Heo
9689a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
969c1bc899fSTejun Heo void (*bmdma_setup)(struct ata_queued_cmd *qc);
970c1bc899fSTejun Heo void (*bmdma_start)(struct ata_queued_cmd *qc);
971b73fc89fSAlan Cox void (*bmdma_stop)(struct ata_queued_cmd *qc);
9721da177e4SLinus Torvalds u8 (*bmdma_status)(struct ata_port *ap);
9739a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
974127102aeSTejun Heo #endif /* CONFIG_ATA_SFF */
975c1bc899fSTejun Heo
97618f7ba4cSKristen Carlson Accardi ssize_t (*em_show)(struct ata_port *ap, char *buf);
97718f7ba4cSKristen Carlson Accardi ssize_t (*em_store)(struct ata_port *ap, const char *message,
97818f7ba4cSKristen Carlson Accardi size_t size);
97918f7ba4cSKristen Carlson Accardi ssize_t (*sw_activity_show)(struct ata_device *dev, char *buf);
98018f7ba4cSKristen Carlson Accardi ssize_t (*sw_activity_store)(struct ata_device *dev,
98118f7ba4cSKristen Carlson Accardi enum sw_activity val);
982439d7a35SMark Langsdorf ssize_t (*transmit_led_message)(struct ata_port *ap, u32 state,
983439d7a35SMark Langsdorf ssize_t size);
984439d7a35SMark Langsdorf
985c1bc899fSTejun Heo /*
986029cfd6bSTejun Heo * ->inherits must be the last field and all the preceding
987029cfd6bSTejun Heo * fields must be pointers.
988029cfd6bSTejun Heo */
989029cfd6bSTejun Heo const struct ata_port_operations *inherits;
9901da177e4SLinus Torvalds };
9911da177e4SLinus Torvalds
9921da177e4SLinus Torvalds struct ata_port_info {
993cca3974eSJeff Garzik unsigned long flags;
9940c88758bSTejun Heo unsigned long link_flags;
995f0a6d77bSSergey Shtylyov unsigned int pio_mask;
996f0a6d77bSSergey Shtylyov unsigned int mwdma_mask;
997f0a6d77bSSergey Shtylyov unsigned int udma_mask;
998029cfd6bSTejun Heo struct ata_port_operations *port_ops;
999e99f8b5eSAlan Cox void *private_data;
10001da177e4SLinus Torvalds };
10011da177e4SLinus Torvalds
1002452503f9SAlan Cox struct ata_timing {
1003452503f9SAlan Cox unsigned short mode; /* ATA mode */
1004452503f9SAlan Cox unsigned short setup; /* t1 */
1005452503f9SAlan Cox unsigned short act8b; /* t2 for 8-bit I/O */
1006452503f9SAlan Cox unsigned short rec8b; /* t2i for 8-bit I/O */
1007452503f9SAlan Cox unsigned short cyc8b; /* t0 for 8-bit I/O */
1008452503f9SAlan Cox unsigned short active; /* t2 or tD */
1009452503f9SAlan Cox unsigned short recover; /* t2i or tK */
10103ada9c12SDavid Daney unsigned short dmack_hold; /* tj */
1011452503f9SAlan Cox unsigned short cycle; /* t0 */
1012452503f9SAlan Cox unsigned short udma; /* t2CYCTYP/2 */
1013452503f9SAlan Cox };
1014452503f9SAlan Cox
1015624d5c51STejun Heo /*
1016624d5c51STejun Heo * Core layer - drivers/ata/libata-core.c
1017624d5c51STejun Heo */
1018029cfd6bSTejun Heo extern struct ata_port_operations ata_dummy_port_ops;
101921b0ad4fSTejun Heo extern const struct ata_port_info ata_dummy_port_info;
1020dd5b06c4STejun Heo
ata_is_atapi(u8 prot)1021b1c04e80SChristoph Hellwig static inline bool ata_is_atapi(u8 prot)
1022dc34e7e1SSergei Shtylyov {
102337f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_ATAPI;
1024dc34e7e1SSergei Shtylyov }
1025dc34e7e1SSergei Shtylyov
ata_is_pio(u8 prot)1026b1c04e80SChristoph Hellwig static inline bool ata_is_pio(u8 prot)
1027dc34e7e1SSergei Shtylyov {
102837f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_PIO;
1029dc34e7e1SSergei Shtylyov }
1030dc34e7e1SSergei Shtylyov
ata_is_dma(u8 prot)1031b1c04e80SChristoph Hellwig static inline bool ata_is_dma(u8 prot)
1032dc34e7e1SSergei Shtylyov {
103337f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_DMA;
1034dc34e7e1SSergei Shtylyov }
1035dc34e7e1SSergei Shtylyov
ata_is_ncq(u8 prot)1036b1c04e80SChristoph Hellwig static inline bool ata_is_ncq(u8 prot)
1037dc34e7e1SSergei Shtylyov {
103837f92d77SChristoph Hellwig return prot & ATA_PROT_FLAG_NCQ;
1039dc34e7e1SSergei Shtylyov }
1040dc34e7e1SSergei Shtylyov
ata_is_data(u8 prot)1041b1c04e80SChristoph Hellwig static inline bool ata_is_data(u8 prot)
1042dc34e7e1SSergei Shtylyov {
104337f92d77SChristoph Hellwig return prot & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA);
1044dc34e7e1SSergei Shtylyov }
1045dc34e7e1SSergei Shtylyov
is_multi_taskfile(struct ata_taskfile * tf)1046dc34e7e1SSergei Shtylyov static inline int is_multi_taskfile(struct ata_taskfile *tf)
1047dc34e7e1SSergei Shtylyov {
1048dc34e7e1SSergei Shtylyov return (tf->command == ATA_CMD_READ_MULTI) ||
1049dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_WRITE_MULTI) ||
1050dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_READ_MULTI_EXT) ||
1051dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
1052dc34e7e1SSergei Shtylyov (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
1053dc34e7e1SSergei Shtylyov }
1054dc34e7e1SSergei Shtylyov
ata_port_is_dummy(struct ata_port * ap)1055dd5b06c4STejun Heo static inline int ata_port_is_dummy(struct ata_port *ap)
1056dd5b06c4STejun Heo {
1057dd5b06c4STejun Heo return ap->ops == &ata_dummy_port_ops;
1058dd5b06c4STejun Heo }
1059dd5b06c4STejun Heo
ata_port_is_frozen(const struct ata_port * ap)1060fddb1a64SNiklas Cassel static inline bool ata_port_is_frozen(const struct ata_port *ap)
1061fddb1a64SNiklas Cassel {
1062fddb1a64SNiklas Cassel return ap->pflags & ATA_PFLAG_FROZEN;
1063fddb1a64SNiklas Cassel }
1064fddb1a64SNiklas Cassel
10650aa1113dSTejun Heo extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
1066aa2731adSTejun Heo extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
1067aa2731adSTejun Heo int (*check_ready)(struct ata_link *link));
106857c9efdfSTejun Heo extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
106957c9efdfSTejun Heo unsigned long deadline);
1070203c75b8STejun Heo extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
10712855568bSJeff Garzik
1072f3187195STejun Heo extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
1073f5cda257STejun Heo extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
1074f5cda257STejun Heo const struct ata_port_info * const * ppi, int n_ports);
10752fa4a326SJason Yan extern void ata_host_get(struct ata_host *host);
10762fa4a326SJason Yan extern void ata_host_put(struct ata_host *host);
1077ecef7253STejun Heo extern int ata_host_start(struct ata_host *host);
1078f3187195STejun Heo extern int ata_host_register(struct ata_host *host,
107925df73d9SBart Van Assche const struct scsi_host_template *sht);
1080f5cda257STejun Heo extern int ata_host_activate(struct ata_host *host, int irq,
1081f5cda257STejun Heo irq_handler_t irq_handler, unsigned long irq_flags,
108225df73d9SBart Van Assche const struct scsi_host_template *sht);
10830529c159STejun Heo extern void ata_host_detach(struct ata_host *host);
10848d8e7d13SDan Williams extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
1085193515d5SJeff Garzik extern int ata_scsi_detect(struct scsi_host_template *sht);
10866f4e626fSNathan Chancellor extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
10876f4e626fSNathan Chancellor void __user *arg);
108875c0b0e1SArnd Bergmann #ifdef CONFIG_COMPAT
108975c0b0e1SArnd Bergmann #define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
109075c0b0e1SArnd Bergmann #else
109175c0b0e1SArnd Bergmann #define ATA_SCSI_COMPAT_IOCTL /* empty */
109275c0b0e1SArnd Bergmann #endif
1093f281233dSJeff Garzik extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1094aad4b4d1SChristoph Hellwig #if IS_REACHABLE(CONFIG_ATA)
1095cc97923aSChristoph Hellwig bool ata_scsi_dma_need_drain(struct request *rq);
10967bb7ee87SChristoph Hellwig #else
10977bb7ee87SChristoph Hellwig #define ata_scsi_dma_need_drain NULL
10987bb7ee87SChristoph Hellwig #endif
109994be9a58SJeff Garzik extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
11006f4e626fSNathan Chancellor unsigned int cmd, void __user *arg);
1101b5b3fa38STejun Heo extern bool ata_link_online(struct ata_link *link);
1102b5b3fa38STejun Heo extern bool ata_link_offline(struct ata_link *link);
11036ffa01d8STejun Heo #ifdef CONFIG_PM
1104ec87cf37SSergey Shtylyov extern void ata_host_suspend(struct ata_host *host, pm_message_t mesg);
1105cca3974eSJeff Garzik extern void ata_host_resume(struct ata_host *host);
1106bc6e7c4bSDan Williams extern void ata_sas_port_suspend(struct ata_port *ap);
1107bc6e7c4bSDan Williams extern void ata_sas_port_resume(struct ata_port *ap);
11082fcbdcb4SDan Williams #else
ata_sas_port_suspend(struct ata_port * ap)1109bc6e7c4bSDan Williams static inline void ata_sas_port_suspend(struct ata_port *ap)
11102fcbdcb4SDan Williams {
11112fcbdcb4SDan Williams }
ata_sas_port_resume(struct ata_port * ap)1112a5a65699SRandy Dunlap static inline void ata_sas_port_resume(struct ata_port *ap)
1113a5a65699SRandy Dunlap {
1114a5a65699SRandy Dunlap }
11156ffa01d8STejun Heo #endif
111667846b30SJeff Garzik extern int ata_ratelimit(void);
111797750cebSTejun Heo extern void ata_msleep(struct ata_port *ap, unsigned int msecs);
111897750cebSTejun Heo extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
111984abed36SSergey Shtylyov u32 val, unsigned int interval, unsigned int timeout);
1120436d34b3STejun Heo extern int atapi_cmd_type(u8 opcode);
1121f0a6d77bSSergey Shtylyov extern unsigned int ata_pack_xfermask(unsigned int pio_mask,
1122f0a6d77bSSergey Shtylyov unsigned int mwdma_mask,
1123f0a6d77bSSergey Shtylyov unsigned int udma_mask);
1124f0a6d77bSSergey Shtylyov extern void ata_unpack_xfermask(unsigned int xfer_mask,
1125f0a6d77bSSergey Shtylyov unsigned int *pio_mask,
1126f0a6d77bSSergey Shtylyov unsigned int *mwdma_mask,
1127f0a6d77bSSergey Shtylyov unsigned int *udma_mask);
1128f0a6d77bSSergey Shtylyov extern u8 ata_xfer_mask2mode(unsigned int xfer_mask);
1129f0a6d77bSSergey Shtylyov extern unsigned int ata_xfer_mode2mask(u8 xfer_mode);
1130a28c1ab3SSergey Shtylyov extern int ata_xfer_mode2shift(u8 xfer_mode);
1131f0a6d77bSSergey Shtylyov extern const char *ata_mode_string(unsigned int xfer_mask);
1132f0a6d77bSSergey Shtylyov extern unsigned int ata_id_xfermask(const u16 *id);
113331cc23b3STejun Heo extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
113495364f36SJiri Slaby extern enum ata_completion_errors ata_noop_qc_prep(struct ata_queued_cmd *qc);
11351da177e4SLinus Torvalds extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
11361da177e4SLinus Torvalds unsigned int n_elem);
1137057ace5eSJeff Garzik extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
11386c952a0dSHannes Reinecke extern unsigned int ata_port_classify(struct ata_port *ap,
11396c952a0dSHannes Reinecke const struct ata_taskfile *tf);
114010305f0fSAlan extern void ata_dev_disable(struct ata_device *adev);
11416a62a04dSTejun Heo extern void ata_id_string(const u16 *id, unsigned char *s,
11421da177e4SLinus Torvalds unsigned int ofs, unsigned int len);
11436a62a04dSTejun Heo extern void ata_id_c_string(const u16 *id, unsigned char *s,
11440e949ff3STejun Heo unsigned int ofs, unsigned int len);
1145963e4975SAlan Cox extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
11460561e514SDamien Le Moal struct ata_taskfile *tf, __le16 *id);
1147f686bcb8STejun Heo extern void ata_qc_complete(struct ata_queued_cmd *qc);
11488385d756SSascha Hauer extern u64 ata_qc_get_active(struct ata_port *ap);
1149b27dcfb0SJeff Garzik extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
11501da177e4SLinus Torvalds extern int ata_std_bios_param(struct scsi_device *sdev,
11511da177e4SLinus Torvalds struct block_device *bdev,
11521da177e4SLinus Torvalds sector_t capacity, int geom[]);
1153d8d9129eSTejun Heo extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
1154fb99ef17SDamien Le Moal extern int ata_scsi_slave_alloc(struct scsi_device *sdev);
11551da177e4SLinus Torvalds extern int ata_scsi_slave_config(struct scsi_device *sdev);
115683c47bcbSTejun Heo extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
1157a6e6ce8eSTejun Heo extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
1158db5ed4dfSChristoph Hellwig int queue_depth);
1159371b74c8SDamien Le Moal extern int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1160371b74c8SDamien Le Moal int queue_depth);
11613373efd8STejun Heo extern struct ata_device *ata_dev_pair(struct ata_device *adev);
11620260731fSTejun Heo extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
11630e0b494cSJames Bottomley extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
11640e0b494cSJames Bottomley extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
11657fe183c7SBartlomiej Zolnierkiewicz
11667fe183c7SBartlomiej Zolnierkiewicz /*
11677fe183c7SBartlomiej Zolnierkiewicz * SATA specific code - drivers/ata/libata-sata.c
11687fe183c7SBartlomiej Zolnierkiewicz */
11696eab1bc0SBartlomiej Zolnierkiewicz #ifdef CONFIG_SATA_HOST
1170d14d41ccSSergey Shtylyov extern const unsigned int sata_deb_timing_normal[];
1171d14d41ccSSergey Shtylyov extern const unsigned int sata_deb_timing_hotplug[];
1172d14d41ccSSergey Shtylyov extern const unsigned int sata_deb_timing_long[];
11732b384edeSBartlomiej Zolnierkiewicz
1174d14d41ccSSergey Shtylyov static inline const unsigned int *
sata_ehc_deb_timing(struct ata_eh_context * ehc)11752b384edeSBartlomiej Zolnierkiewicz sata_ehc_deb_timing(struct ata_eh_context *ehc)
11762b384edeSBartlomiej Zolnierkiewicz {
11772b384edeSBartlomiej Zolnierkiewicz if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
11782b384edeSBartlomiej Zolnierkiewicz return sata_deb_timing_hotplug;
11792b384edeSBartlomiej Zolnierkiewicz else
11802b384edeSBartlomiej Zolnierkiewicz return sata_deb_timing_normal;
11812b384edeSBartlomiej Zolnierkiewicz }
11822b384edeSBartlomiej Zolnierkiewicz
11836eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_valid(struct ata_link *link);
11846eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
11856eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
11866eab1bc0SBartlomiej Zolnierkiewicz extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
1187ab4117cfSBartlomiej Zolnierkiewicz extern int sata_set_spd(struct ata_link *link);
118878c97c80SBartlomiej Zolnierkiewicz extern int sata_link_hardreset(struct ata_link *link,
1189d14d41ccSSergey Shtylyov const unsigned int *timing, unsigned long deadline,
119078c97c80SBartlomiej Zolnierkiewicz bool *online, int (*check_ready)(struct ata_link *));
1191d14d41ccSSergey Shtylyov extern int sata_link_resume(struct ata_link *link, const unsigned int *params,
11929d3158f5SBartlomiej Zolnierkiewicz unsigned long deadline);
119318bd7718SNiklas Cassel extern int ata_eh_read_sense_success_ncq_log(struct ata_link *link);
1194a0ccd251SBartlomiej Zolnierkiewicz extern void ata_eh_analyze_ncq_error(struct ata_link *link);
11956eab1bc0SBartlomiej Zolnierkiewicz #else
1196d14d41ccSSergey Shtylyov static inline const unsigned int *
sata_ehc_deb_timing(struct ata_eh_context * ehc)11972b384edeSBartlomiej Zolnierkiewicz sata_ehc_deb_timing(struct ata_eh_context *ehc)
11982b384edeSBartlomiej Zolnierkiewicz {
11992b384edeSBartlomiej Zolnierkiewicz return NULL;
12002b384edeSBartlomiej Zolnierkiewicz }
sata_scr_valid(struct ata_link * link)12016eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_valid(struct ata_link *link) { return 0; }
sata_scr_read(struct ata_link * link,int reg,u32 * val)12026eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
12036eab1bc0SBartlomiej Zolnierkiewicz {
12046eab1bc0SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12056eab1bc0SBartlomiej Zolnierkiewicz }
sata_scr_write(struct ata_link * link,int reg,u32 val)12066eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
12076eab1bc0SBartlomiej Zolnierkiewicz {
12086eab1bc0SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12096eab1bc0SBartlomiej Zolnierkiewicz }
sata_scr_write_flush(struct ata_link * link,int reg,u32 val)12106eab1bc0SBartlomiej Zolnierkiewicz static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
12116eab1bc0SBartlomiej Zolnierkiewicz {
12126eab1bc0SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12136eab1bc0SBartlomiej Zolnierkiewicz }
sata_set_spd(struct ata_link * link)1214ab4117cfSBartlomiej Zolnierkiewicz static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
sata_link_hardreset(struct ata_link * link,const unsigned int * timing,unsigned long deadline,bool * online,int (* check_ready)(struct ata_link *))121578c97c80SBartlomiej Zolnierkiewicz static inline int sata_link_hardreset(struct ata_link *link,
1216d14d41ccSSergey Shtylyov const unsigned int *timing,
121778c97c80SBartlomiej Zolnierkiewicz unsigned long deadline,
121878c97c80SBartlomiej Zolnierkiewicz bool *online,
121978c97c80SBartlomiej Zolnierkiewicz int (*check_ready)(struct ata_link *))
122078c97c80SBartlomiej Zolnierkiewicz {
122178c97c80SBartlomiej Zolnierkiewicz if (online)
122278c97c80SBartlomiej Zolnierkiewicz *online = false;
122378c97c80SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
122478c97c80SBartlomiej Zolnierkiewicz }
sata_link_resume(struct ata_link * link,const unsigned int * params,unsigned long deadline)12259d3158f5SBartlomiej Zolnierkiewicz static inline int sata_link_resume(struct ata_link *link,
1226d14d41ccSSergey Shtylyov const unsigned int *params,
12279d3158f5SBartlomiej Zolnierkiewicz unsigned long deadline)
12289d3158f5SBartlomiej Zolnierkiewicz {
12299d3158f5SBartlomiej Zolnierkiewicz return -EOPNOTSUPP;
12309d3158f5SBartlomiej Zolnierkiewicz }
ata_eh_read_sense_success_ncq_log(struct ata_link * link)123118bd7718SNiklas Cassel static inline int ata_eh_read_sense_success_ncq_log(struct ata_link *link)
123218bd7718SNiklas Cassel {
123318bd7718SNiklas Cassel return -EOPNOTSUPP;
123418bd7718SNiklas Cassel }
ata_eh_analyze_ncq_error(struct ata_link * link)1235a0ccd251SBartlomiej Zolnierkiewicz static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
12366eab1bc0SBartlomiej Zolnierkiewicz #endif
12379d3158f5SBartlomiej Zolnierkiewicz extern int sata_link_debounce(struct ata_link *link,
1238d14d41ccSSergey Shtylyov const unsigned int *params, unsigned long deadline);
12397fe183c7SBartlomiej Zolnierkiewicz extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
12407fe183c7SBartlomiej Zolnierkiewicz bool spm_wakeup);
12417fe183c7SBartlomiej Zolnierkiewicz extern int ata_slave_link_init(struct ata_port *ap);
124215964ff7SBartlomiej Zolnierkiewicz extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
124315964ff7SBartlomiej Zolnierkiewicz struct ata_port_info *, struct Scsi_Host *);
1244a76f1b63SHannes Reinecke extern void ata_port_probe(struct ata_port *ap);
124515964ff7SBartlomiej Zolnierkiewicz extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
124615964ff7SBartlomiej Zolnierkiewicz extern void ata_sas_tport_delete(struct ata_port *ap);
124715964ff7SBartlomiej Zolnierkiewicz extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
124815964ff7SBartlomiej Zolnierkiewicz extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
12497fe183c7SBartlomiej Zolnierkiewicz extern void ata_tf_to_fis(const struct ata_taskfile *tf,
12507fe183c7SBartlomiej Zolnierkiewicz u8 pmp, int is_cmd, u8 *fis);
12517fe183c7SBartlomiej Zolnierkiewicz extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
125261a11986SBartlomiej Zolnierkiewicz extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
12538393b811SGabriele Mazzotta extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
1254a695de27SBartlomiej Zolnierkiewicz extern int sata_async_notification(struct ata_port *ap);
12551da177e4SLinus Torvalds
1256be0d18dfSAlan Cox extern int ata_cable_40wire(struct ata_port *ap);
1257be0d18dfSAlan Cox extern int ata_cable_80wire(struct ata_port *ap);
1258be0d18dfSAlan Cox extern int ata_cable_sata(struct ata_port *ap);
1259c88f90c3STejun Heo extern int ata_cable_ignore(struct ata_port *ap);
1260be0d18dfSAlan Cox extern int ata_cable_unknown(struct ata_port *ap);
1261be0d18dfSAlan Cox
1262624d5c51STejun Heo /* Timing helpers */
12631bc4ccffSAlan Cox extern unsigned int ata_pio_need_iordy(const struct ata_device *);
1264a0f79b92STejun Heo extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
1265452503f9SAlan Cox
1266624d5c51STejun Heo /* PCI */
1267624d5c51STejun Heo #ifdef CONFIG_PCI
1268624d5c51STejun Heo struct pci_dev;
1269624d5c51STejun Heo
1270624d5c51STejun Heo struct pci_bits {
1271624d5c51STejun Heo unsigned int reg; /* PCI config register to read */
1272624d5c51STejun Heo unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
1273624d5c51STejun Heo unsigned long mask;
1274624d5c51STejun Heo unsigned long val;
1275452503f9SAlan Cox };
1276452503f9SAlan Cox
1277624d5c51STejun Heo extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
127810a663a1SPrabhakar Kushwaha extern void ata_pci_shutdown_one(struct pci_dev *pdev);
1279624d5c51STejun Heo extern void ata_pci_remove_one(struct pci_dev *pdev);
1280624d5c51STejun Heo
1281624d5c51STejun Heo #ifdef CONFIG_PM
1282624d5c51STejun Heo extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
1283624d5c51STejun Heo extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
1284624d5c51STejun Heo extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
1285624d5c51STejun Heo extern int ata_pci_device_resume(struct pci_dev *pdev);
1286624d5c51STejun Heo #endif /* CONFIG_PM */
1287624d5c51STejun Heo #endif /* CONFIG_PCI */
1288624d5c51STejun Heo
1289b7db04d9SBrian Norris struct platform_device;
1290b7db04d9SBrian Norris
1291a7eb54d4SUwe Kleine-König extern void ata_platform_remove_one(struct platform_device *pdev);
1292b7db04d9SBrian Norris
1293624d5c51STejun Heo /*
1294624d5c51STejun Heo * ACPI - drivers/ata/libata-acpi.c
1295624d5c51STejun Heo */
1296e1ddb4b6SAlan Cox #ifdef CONFIG_ATA_ACPI
ata_acpi_init_gtm(struct ata_port * ap)1297c05e6ff0STejun Heo static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1298c05e6ff0STejun Heo {
1299c05e6ff0STejun Heo if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID)
1300c05e6ff0STejun Heo return &ap->__acpi_init_gtm;
1301c05e6ff0STejun Heo return NULL;
1302c05e6ff0STejun Heo }
13030d02f0b2STejun Heo int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
13040d02f0b2STejun Heo int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
1305f0a6d77bSSergey Shtylyov unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
13067c77fa4dSTejun Heo const struct ata_acpi_gtm *gtm);
1307021ee9a6STejun Heo int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
1308e1ddb4b6SAlan Cox #else
ata_acpi_init_gtm(struct ata_port * ap)1309c05e6ff0STejun Heo static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1310c05e6ff0STejun Heo {
1311c05e6ff0STejun Heo return NULL;
1312c05e6ff0STejun Heo }
13137c77fa4dSTejun Heo
ata_acpi_stm(const struct ata_port * ap,struct ata_acpi_gtm * stm)13147c77fa4dSTejun Heo static inline int ata_acpi_stm(const struct ata_port *ap,
13157c77fa4dSTejun Heo struct ata_acpi_gtm *stm)
13167c77fa4dSTejun Heo {
13177c77fa4dSTejun Heo return -ENOSYS;
13187c77fa4dSTejun Heo }
13197c77fa4dSTejun Heo
ata_acpi_gtm(const struct ata_port * ap,struct ata_acpi_gtm * stm)13207c77fa4dSTejun Heo static inline int ata_acpi_gtm(const struct ata_port *ap,
13217c77fa4dSTejun Heo struct ata_acpi_gtm *stm)
13227c77fa4dSTejun Heo {
13237c77fa4dSTejun Heo return -ENOSYS;
13247c77fa4dSTejun Heo }
13257c77fa4dSTejun Heo
ata_acpi_gtm_xfermask(struct ata_device * dev,const struct ata_acpi_gtm * gtm)13267c77fa4dSTejun Heo static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
13277c77fa4dSTejun Heo const struct ata_acpi_gtm *gtm)
13287c77fa4dSTejun Heo {
13297c77fa4dSTejun Heo return 0;
13307c77fa4dSTejun Heo }
1331021ee9a6STejun Heo
ata_acpi_cbl_80wire(struct ata_port * ap,const struct ata_acpi_gtm * gtm)1332021ee9a6STejun Heo static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
1333021ee9a6STejun Heo const struct ata_acpi_gtm *gtm)
1334021ee9a6STejun Heo {
1335021ee9a6STejun Heo return 0;
1336021ee9a6STejun Heo }
1337e1ddb4b6SAlan Cox #endif
13381da177e4SLinus Torvalds
1339ece1d636STejun Heo /*
1340624d5c51STejun Heo * EH - drivers/ata/libata-eh.c
1341ece1d636STejun Heo */
13427b70fc03STejun Heo extern void ata_port_schedule_eh(struct ata_port *ap);
134381c757bcSDan Williams extern void ata_port_wait_eh(struct ata_port *ap);
1344dbd82616STejun Heo extern int ata_link_abort(struct ata_link *link);
13457b70fc03STejun Heo extern int ata_port_abort(struct ata_port *ap);
1346e3180499STejun Heo extern int ata_port_freeze(struct ata_port *ap);
1347e3180499STejun Heo
1348e3180499STejun Heo extern void ata_eh_freeze_port(struct ata_port *ap);
1349e3180499STejun Heo extern void ata_eh_thaw_port(struct ata_port *ap);
13507b70fc03STejun Heo
1351ece1d636STejun Heo extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
1352ece1d636STejun Heo extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1353ece1d636STejun Heo
1354f5914a46STejun Heo extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1355f5914a46STejun Heo ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1356f5914a46STejun Heo ata_postreset_fn_t postreset);
1357a1efdabaSTejun Heo extern void ata_std_error_handler(struct ata_port *ap);
1358e4a9c373SDan Williams extern void ata_std_sched_eh(struct ata_port *ap);
1359e4a9c373SDan Williams extern void ata_std_end_eh(struct ata_port *ap);
13608a745f1fSKristen Carlson Accardi extern int ata_link_nr_enabled(struct ata_link *link);
1361022bdb07STejun Heo
136261440db6STejun Heo /*
136368d1d07bSTejun Heo * Base operations to inherit from and initializers for sht
136468d1d07bSTejun Heo *
136568d1d07bSTejun Heo * Operations
136668d1d07bSTejun Heo *
136768d1d07bSTejun Heo * base : Common to all libata drivers.
136868d1d07bSTejun Heo * sata : SATA controllers w/ native interface.
136968d1d07bSTejun Heo * pmp : SATA controllers w/ PMP support.
137068d1d07bSTejun Heo * sff : SFF ATA controllers w/o BMDMA support.
137168d1d07bSTejun Heo * bmdma : SFF ATA controllers w/ BMDMA support.
137268d1d07bSTejun Heo *
137368d1d07bSTejun Heo * sht initializers
137468d1d07bSTejun Heo *
137568d1d07bSTejun Heo * BASE : Common to all libata drivers. The user must set
137668d1d07bSTejun Heo * sg_tablesize and dma_boundary.
137768d1d07bSTejun Heo * PIO : SFF ATA controllers w/ only PIO support.
137868d1d07bSTejun Heo * BMDMA : SFF ATA controllers w/ BMDMA support. sg_tablesize and
137968d1d07bSTejun Heo * dma_boundary are set to BMDMA limits.
138068d1d07bSTejun Heo * NCQ : SATA controllers supporting NCQ. The user must set
138168d1d07bSTejun Heo * sg_tablesize, dma_boundary and can_queue.
138268d1d07bSTejun Heo */
138368d1d07bSTejun Heo extern const struct ata_port_operations ata_base_port_ops;
138468d1d07bSTejun Heo extern const struct ata_port_operations sata_port_ops;
1385c3f69c7fSBart Van Assche extern const struct attribute_group *ata_common_sdev_groups[];
138668d1d07bSTejun Heo
1387018d5ef2SAkinobu Mita /*
1388018d5ef2SAkinobu Mita * All sht initializers (BASE, PIO, BMDMA, NCQ) must be instantiated
1389018d5ef2SAkinobu Mita * by the edge drivers. Because the 'module' field of sht must be the
1390018d5ef2SAkinobu Mita * edge driver's module reference, otherwise the driver can be unloaded
1391018d5ef2SAkinobu Mita * even if the scsi_device is being accessed.
1392018d5ef2SAkinobu Mita */
13936f09eae3SBartlomiej Zolnierkiewicz #define __ATA_BASE_SHT(drv_name) \
139468d1d07bSTejun Heo .module = THIS_MODULE, \
139568d1d07bSTejun Heo .name = drv_name, \
139668d1d07bSTejun Heo .ioctl = ata_scsi_ioctl, \
139775c0b0e1SArnd Bergmann ATA_SCSI_COMPAT_IOCTL \
139868d1d07bSTejun Heo .queuecommand = ata_scsi_queuecmd, \
1399cc97923aSChristoph Hellwig .dma_need_drain = ata_scsi_dma_need_drain, \
140068d1d07bSTejun Heo .this_id = ATA_SHT_THIS_ID, \
140168d1d07bSTejun Heo .emulated = ATA_SHT_EMULATED, \
140268d1d07bSTejun Heo .proc_name = drv_name, \
1403fb99ef17SDamien Le Moal .slave_alloc = ata_scsi_slave_alloc, \
140468d1d07bSTejun Heo .slave_destroy = ata_scsi_slave_destroy, \
140545fabbb7SElias Oltmanns .bios_param = ata_std_bios_param, \
1406a357f7b4SJohn Garry .unlock_native_capacity = ata_scsi_unlock_native_capacity,\
1407a357f7b4SJohn Garry .max_sectors = ATA_MAX_SECTORS_LBA48
14086f09eae3SBartlomiej Zolnierkiewicz
14094e7dba07SLee Jones #define ATA_SUBBASE_SHT(drv_name) \
14106f09eae3SBartlomiej Zolnierkiewicz __ATA_BASE_SHT(drv_name), \
14114e7dba07SLee Jones .can_queue = ATA_DEF_QUEUE, \
14124e7dba07SLee Jones .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
14134e7dba07SLee Jones .slave_configure = ata_scsi_slave_config
14144e7dba07SLee Jones
1415e5b48ee3SDamien Le Moal #define ATA_SUBBASE_SHT_QD(drv_name, drv_qd) \
1416e5b48ee3SDamien Le Moal __ATA_BASE_SHT(drv_name), \
1417e5b48ee3SDamien Le Moal .can_queue = drv_qd, \
1418e5b48ee3SDamien Le Moal .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
1419e5b48ee3SDamien Le Moal .slave_configure = ata_scsi_slave_config
1420e5b48ee3SDamien Le Moal
14214e7dba07SLee Jones #define ATA_BASE_SHT(drv_name) \
14224e7dba07SLee Jones ATA_SUBBASE_SHT(drv_name), \
1423c3f69c7fSBart Van Assche .sdev_groups = ata_common_sdev_groups
142468d1d07bSTejun Heo
1425ec811a94SBartlomiej Zolnierkiewicz #ifdef CONFIG_SATA_HOST
1426c3f69c7fSBart Van Assche extern const struct attribute_group *ata_ncq_sdev_groups[];
1427ec811a94SBartlomiej Zolnierkiewicz
142868d1d07bSTejun Heo #define ATA_NCQ_SHT(drv_name) \
14294e7dba07SLee Jones ATA_SUBBASE_SHT(drv_name), \
1430c3f69c7fSBart Van Assche .sdev_groups = ata_ncq_sdev_groups, \
143168d1d07bSTejun Heo .change_queue_depth = ata_scsi_change_queue_depth
1432e5b48ee3SDamien Le Moal
1433e5b48ee3SDamien Le Moal #define ATA_NCQ_SHT_QD(drv_name, drv_qd) \
1434e5b48ee3SDamien Le Moal ATA_SUBBASE_SHT_QD(drv_name, drv_qd), \
1435e5b48ee3SDamien Le Moal .sdev_groups = ata_ncq_sdev_groups, \
1436e5b48ee3SDamien Le Moal .change_queue_depth = ata_scsi_change_queue_depth
1437ec811a94SBartlomiej Zolnierkiewicz #endif
143868d1d07bSTejun Heo
143968d1d07bSTejun Heo /*
1440071f44b1STejun Heo * PMP helpers
1441071f44b1STejun Heo */
144288fcd562STejun Heo #ifdef CONFIG_SATA_PMP
sata_pmp_supported(struct ata_port * ap)1443071f44b1STejun Heo static inline bool sata_pmp_supported(struct ata_port *ap)
1444071f44b1STejun Heo {
1445071f44b1STejun Heo return ap->flags & ATA_FLAG_PMP;
1446071f44b1STejun Heo }
1447071f44b1STejun Heo
sata_pmp_attached(struct ata_port * ap)1448071f44b1STejun Heo static inline bool sata_pmp_attached(struct ata_port *ap)
1449071f44b1STejun Heo {
1450071f44b1STejun Heo return ap->nr_pmp_links != 0;
1451071f44b1STejun Heo }
1452071f44b1STejun Heo
ata_is_host_link(const struct ata_link * link)1453b1c04e80SChristoph Hellwig static inline bool ata_is_host_link(const struct ata_link *link)
1454071f44b1STejun Heo {
1455b1c72916STejun Heo return link == &link->ap->link || link == link->ap->slave_link;
1456071f44b1STejun Heo }
145788fcd562STejun Heo #else /* CONFIG_SATA_PMP */
sata_pmp_supported(struct ata_port * ap)145888fcd562STejun Heo static inline bool sata_pmp_supported(struct ata_port *ap)
145988fcd562STejun Heo {
146088fcd562STejun Heo return false;
146188fcd562STejun Heo }
146288fcd562STejun Heo
sata_pmp_attached(struct ata_port * ap)146388fcd562STejun Heo static inline bool sata_pmp_attached(struct ata_port *ap)
146488fcd562STejun Heo {
146588fcd562STejun Heo return false;
146688fcd562STejun Heo }
146788fcd562STejun Heo
ata_is_host_link(const struct ata_link * link)1468b1c04e80SChristoph Hellwig static inline bool ata_is_host_link(const struct ata_link *link)
146988fcd562STejun Heo {
147062283c6cSJing Yangyang return true;
147188fcd562STejun Heo }
147288fcd562STejun Heo #endif /* CONFIG_SATA_PMP */
1473071f44b1STejun Heo
sata_srst_pmp(struct ata_link * link)1474071f44b1STejun Heo static inline int sata_srst_pmp(struct ata_link *link)
1475071f44b1STejun Heo {
1476071f44b1STejun Heo if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
1477071f44b1STejun Heo return SATA_PMP_CTRL_PORT;
1478071f44b1STejun Heo return link->pmp;
1479071f44b1STejun Heo }
1480071f44b1STejun Heo
1481742bef47SHannes Reinecke #define ata_port_printk(level, ap, fmt, ...) \
1482742bef47SHannes Reinecke pr_ ## level ("ata%u: " fmt, (ap)->print_id, ##__VA_ARGS__)
14831da177e4SLinus Torvalds
1484a9a79dfeSJoe Perches #define ata_port_err(ap, fmt, ...) \
1485742bef47SHannes Reinecke ata_port_printk(err, ap, fmt, ##__VA_ARGS__)
1486a9a79dfeSJoe Perches #define ata_port_warn(ap, fmt, ...) \
1487742bef47SHannes Reinecke ata_port_printk(warn, ap, fmt, ##__VA_ARGS__)
1488a9a79dfeSJoe Perches #define ata_port_notice(ap, fmt, ...) \
1489742bef47SHannes Reinecke ata_port_printk(notice, ap, fmt, ##__VA_ARGS__)
1490a9a79dfeSJoe Perches #define ata_port_info(ap, fmt, ...) \
1491742bef47SHannes Reinecke ata_port_printk(info, ap, fmt, ##__VA_ARGS__)
1492a9a79dfeSJoe Perches #define ata_port_dbg(ap, fmt, ...) \
1493742bef47SHannes Reinecke ata_port_printk(debug, ap, fmt, ##__VA_ARGS__)
1494742bef47SHannes Reinecke
1495742bef47SHannes Reinecke #define ata_link_printk(level, link, fmt, ...) \
1496742bef47SHannes Reinecke do { \
1497742bef47SHannes Reinecke if (sata_pmp_attached((link)->ap) || \
1498742bef47SHannes Reinecke (link)->ap->slave_link) \
1499742bef47SHannes Reinecke pr_ ## level ("ata%u.%02u: " fmt, \
1500742bef47SHannes Reinecke (link)->ap->print_id, \
1501742bef47SHannes Reinecke (link)->pmp, \
1502742bef47SHannes Reinecke ##__VA_ARGS__); \
1503742bef47SHannes Reinecke else \
1504742bef47SHannes Reinecke pr_ ## level ("ata%u: " fmt, \
1505742bef47SHannes Reinecke (link)->ap->print_id, \
1506742bef47SHannes Reinecke ##__VA_ARGS__); \
1507742bef47SHannes Reinecke } while (0)
15089af5c9c9STejun Heo
1509a9a79dfeSJoe Perches #define ata_link_err(link, fmt, ...) \
1510742bef47SHannes Reinecke ata_link_printk(err, link, fmt, ##__VA_ARGS__)
1511a9a79dfeSJoe Perches #define ata_link_warn(link, fmt, ...) \
1512742bef47SHannes Reinecke ata_link_printk(warn, link, fmt, ##__VA_ARGS__)
1513a9a79dfeSJoe Perches #define ata_link_notice(link, fmt, ...) \
1514742bef47SHannes Reinecke ata_link_printk(notice, link, fmt, ##__VA_ARGS__)
1515a9a79dfeSJoe Perches #define ata_link_info(link, fmt, ...) \
1516742bef47SHannes Reinecke ata_link_printk(info, link, fmt, ##__VA_ARGS__)
1517a9a79dfeSJoe Perches #define ata_link_dbg(link, fmt, ...) \
1518742bef47SHannes Reinecke ata_link_printk(debug, link, fmt, ##__VA_ARGS__)
1519742bef47SHannes Reinecke
1520742bef47SHannes Reinecke #define ata_dev_printk(level, dev, fmt, ...) \
1521742bef47SHannes Reinecke pr_ ## level("ata%u.%02u: " fmt, \
1522742bef47SHannes Reinecke (dev)->link->ap->print_id, \
1523742bef47SHannes Reinecke (dev)->link->pmp + (dev)->devno, \
1524742bef47SHannes Reinecke ##__VA_ARGS__)
1525a9a79dfeSJoe Perches
1526a9a79dfeSJoe Perches #define ata_dev_err(dev, fmt, ...) \
1527742bef47SHannes Reinecke ata_dev_printk(err, dev, fmt, ##__VA_ARGS__)
1528a9a79dfeSJoe Perches #define ata_dev_warn(dev, fmt, ...) \
1529742bef47SHannes Reinecke ata_dev_printk(warn, dev, fmt, ##__VA_ARGS__)
1530a9a79dfeSJoe Perches #define ata_dev_notice(dev, fmt, ...) \
1531742bef47SHannes Reinecke ata_dev_printk(notice, dev, fmt, ##__VA_ARGS__)
1532a9a79dfeSJoe Perches #define ata_dev_info(dev, fmt, ...) \
1533742bef47SHannes Reinecke ata_dev_printk(info, dev, fmt, ##__VA_ARGS__)
1534a9a79dfeSJoe Perches #define ata_dev_dbg(dev, fmt, ...) \
1535742bef47SHannes Reinecke ata_dev_printk(debug, dev, fmt, ##__VA_ARGS__)
153661440db6STejun Heo
153706296a1eSJoe Perches void ata_print_version(const struct device *dev, const char *version);
153806296a1eSJoe Perches
153961440db6STejun Heo /*
1540f3e81b19STejun Heo * ata_eh_info helpers
1541f3e81b19STejun Heo */
1542b9075fa9SJoe Perches extern __printf(2, 3)
1543b9075fa9SJoe Perches void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1544b9075fa9SJoe Perches extern __printf(2, 3)
1545b9075fa9SJoe Perches void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1546b64bbc39STejun Heo extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
1547f3e81b19STejun Heo
ata_ehi_hotplugged(struct ata_eh_info * ehi)1548c0b6c037STejun Heo static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
1549c0b6c037STejun Heo {
1550b558edddSTejun Heo ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
1551f8f1e1ccSTejun Heo ehi->flags |= ATA_EHI_HOTPLUGGED;
1552b558edddSTejun Heo ehi->action |= ATA_EH_RESET | ATA_EH_ENABLE_LINK;
1553c0b6c037STejun Heo ehi->err_mask |= AC_ERR_ATA_BUS;
1554c0b6c037STejun Heo }
1555c0b6c037STejun Heo
1556f3e81b19STejun Heo /*
1557cbcdd875STejun Heo * port description helpers
1558cbcdd875STejun Heo */
1559b9075fa9SJoe Perches extern __printf(2, 3)
1560b9075fa9SJoe Perches void ata_port_desc(struct ata_port *ap, const char *fmt, ...);
1561cbcdd875STejun Heo #ifdef CONFIG_PCI
1562cbcdd875STejun Heo extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
1563cbcdd875STejun Heo const char *name);
1564cbcdd875STejun Heo #endif
1565cbcdd875STejun Heo
ata_tag_internal(unsigned int tag)15662e2cc676SJens Axboe static inline bool ata_tag_internal(unsigned int tag)
15672ab7db1fSTejun Heo {
156883c063ddSYoichi Yuasa return tag == ATA_TAG_INTERNAL;
15692ab7db1fSTejun Heo }
15702ab7db1fSTejun Heo
ata_tag_valid(unsigned int tag)157128361c40SJens Axboe static inline bool ata_tag_valid(unsigned int tag)
157228361c40SJens Axboe {
157328361c40SJens Axboe return tag < ATA_MAX_QUEUE || ata_tag_internal(tag);
157428361c40SJens Axboe }
157528361c40SJens Axboe
15766362f0a2SJens Axboe #define __ata_qc_for_each(ap, qc, tag, max_tag, fn) \
15776362f0a2SJens Axboe for ((tag) = 0; (tag) < (max_tag) && \
15786362f0a2SJens Axboe ({ qc = fn((ap), (tag)); 1; }); (tag)++) \
15796362f0a2SJens Axboe
15806362f0a2SJens Axboe /*
15816362f0a2SJens Axboe * Internal use only, iterate commands ignoring error handling and
15826362f0a2SJens Axboe * status of 'qc'.
15836362f0a2SJens Axboe */
15846362f0a2SJens Axboe #define ata_qc_for_each_raw(ap, qc, tag) \
15856362f0a2SJens Axboe __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, __ata_qc_from_tag)
15866362f0a2SJens Axboe
15876362f0a2SJens Axboe /*
15886362f0a2SJens Axboe * Iterate all potential commands that can be queued
15896362f0a2SJens Axboe */
15906362f0a2SJens Axboe #define ata_qc_for_each(ap, qc, tag) \
15916362f0a2SJens Axboe __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, ata_qc_from_tag)
15926362f0a2SJens Axboe
15936362f0a2SJens Axboe /*
15946362f0a2SJens Axboe * Like ata_qc_for_each, but with the internal tag included
15956362f0a2SJens Axboe */
15966362f0a2SJens Axboe #define ata_qc_for_each_with_internal(ap, qc, tag) \
15976362f0a2SJens Axboe __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE + 1, ata_qc_from_tag)
15986362f0a2SJens Axboe
15995806db22STejun Heo /*
16005806db22STejun Heo * device helpers
16015806db22STejun Heo */
ata_class_enabled(unsigned int class)1602e1211e3fSTejun Heo static inline unsigned int ata_class_enabled(unsigned int class)
1603597afd21STejun Heo {
1604e0a71752STejun Heo return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI ||
16059162c657SHannes Reinecke class == ATA_DEV_PMP || class == ATA_DEV_SEMB ||
16069162c657SHannes Reinecke class == ATA_DEV_ZAC;
1607597afd21STejun Heo }
1608597afd21STejun Heo
ata_class_disabled(unsigned int class)1609e1211e3fSTejun Heo static inline unsigned int ata_class_disabled(unsigned int class)
16101da177e4SLinus Torvalds {
1611e0a71752STejun Heo return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP ||
16123a92945bSHannes Reinecke class == ATA_DEV_PMP_UNSUP || class == ATA_DEV_SEMB_UNSUP ||
16133a92945bSHannes Reinecke class == ATA_DEV_ZAC_UNSUP;
1614e1211e3fSTejun Heo }
1615e1211e3fSTejun Heo
ata_class_absent(unsigned int class)1616002c8054STejun Heo static inline unsigned int ata_class_absent(unsigned int class)
1617002c8054STejun Heo {
1618002c8054STejun Heo return !ata_class_enabled(class) && !ata_class_disabled(class);
1619002c8054STejun Heo }
1620002c8054STejun Heo
ata_dev_enabled(const struct ata_device * dev)1621e1211e3fSTejun Heo static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
1622e1211e3fSTejun Heo {
1623e1211e3fSTejun Heo return ata_class_enabled(dev->class);
1624e1211e3fSTejun Heo }
1625e1211e3fSTejun Heo
ata_dev_disabled(const struct ata_device * dev)1626e1211e3fSTejun Heo static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
1627e1211e3fSTejun Heo {
1628e1211e3fSTejun Heo return ata_class_disabled(dev->class);
16291da177e4SLinus Torvalds }
16301da177e4SLinus Torvalds
ata_dev_absent(const struct ata_device * dev)1631002c8054STejun Heo static inline unsigned int ata_dev_absent(const struct ata_device *dev)
1632002c8054STejun Heo {
1633002c8054STejun Heo return ata_class_absent(dev->class);
1634002c8054STejun Heo }
1635002c8054STejun Heo
16365806db22STejun Heo /*
1637f58229f8STejun Heo * link helpers
16385806db22STejun Heo */
ata_link_max_devices(const struct ata_link * link)1639f58229f8STejun Heo static inline int ata_link_max_devices(const struct ata_link *link)
16405806db22STejun Heo {
16418989805dSTejun Heo if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
16425806db22STejun Heo return 2;
16435806db22STejun Heo return 1;
16445806db22STejun Heo }
16455806db22STejun Heo
ata_link_active(struct ata_link * link)1646da917d69STejun Heo static inline int ata_link_active(struct ata_link *link)
1647da917d69STejun Heo {
1648da917d69STejun Heo return ata_tag_valid(link->active_tag) || link->sactive;
1649da917d69STejun Heo }
1650da917d69STejun Heo
16511eca4365STejun Heo /*
16521eca4365STejun Heo * Iterators
16531eca4365STejun Heo *
16541eca4365STejun Heo * ATA_LITER_* constants are used to select link iteration mode and
16551eca4365STejun Heo * ATA_DITER_* device iteration mode.
16561eca4365STejun Heo *
16571eca4365STejun Heo * For a custom iteration directly using ata_{link|dev}_next(), if
16581eca4365STejun Heo * @link or @dev, respectively, is NULL, the first element is
16591eca4365STejun Heo * returned. @dev and @link can be any valid device or link and the
16601eca4365STejun Heo * next element according to the iteration mode will be returned.
16611eca4365STejun Heo * After the last element, NULL is returned.
16621eca4365STejun Heo */
16631eca4365STejun Heo enum ata_link_iter_mode {
16641eca4365STejun Heo ATA_LITER_EDGE, /* if present, PMP links only; otherwise,
16651eca4365STejun Heo * host link. no slave link */
16661eca4365STejun Heo ATA_LITER_HOST_FIRST, /* host link followed by PMP or slave links */
16671eca4365STejun Heo ATA_LITER_PMP_FIRST, /* PMP links followed by host link,
16681eca4365STejun Heo * slave link still comes after host link */
16691eca4365STejun Heo };
16701eca4365STejun Heo
16711eca4365STejun Heo enum ata_dev_iter_mode {
16721eca4365STejun Heo ATA_DITER_ENABLED,
16731eca4365STejun Heo ATA_DITER_ENABLED_REVERSE,
16741eca4365STejun Heo ATA_DITER_ALL,
16751eca4365STejun Heo ATA_DITER_ALL_REVERSE,
16761eca4365STejun Heo };
16771eca4365STejun Heo
16781eca4365STejun Heo extern struct ata_link *ata_link_next(struct ata_link *link,
16791eca4365STejun Heo struct ata_port *ap,
16801eca4365STejun Heo enum ata_link_iter_mode mode);
16811eca4365STejun Heo
16821eca4365STejun Heo extern struct ata_device *ata_dev_next(struct ata_device *dev,
1683aadffb68STejun Heo struct ata_link *link,
16841eca4365STejun Heo enum ata_dev_iter_mode mode);
16858989805dSTejun Heo
16861eca4365STejun Heo /*
16871eca4365STejun Heo * Shortcut notation for iterations
16881eca4365STejun Heo *
16891eca4365STejun Heo * ata_for_each_link() iterates over each link of @ap according to
16901eca4365STejun Heo * @mode. @link points to the current link in the loop. @link is
16911eca4365STejun Heo * NULL after loop termination. ata_for_each_dev() works the same way
16921eca4365STejun Heo * except that it iterates over each device of @link.
16931eca4365STejun Heo *
16941eca4365STejun Heo * Note that the mode prefixes ATA_{L|D}ITER_ shouldn't need to be
16951eca4365STejun Heo * specified when using the following shorthand notations. Only the
16961eca4365STejun Heo * mode itself (EDGE, HOST_FIRST, ENABLED, etc...) should be
16971eca4365STejun Heo * specified. This not only increases brevity but also makes it
16981eca4365STejun Heo * impossible to use ATA_LITER_* for device iteration or vice-versa.
16991eca4365STejun Heo */
17001eca4365STejun Heo #define ata_for_each_link(link, ap, mode) \
17011eca4365STejun Heo for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
17021eca4365STejun Heo (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
17038989805dSTejun Heo
17041eca4365STejun Heo #define ata_for_each_dev(dev, link, mode) \
17051eca4365STejun Heo for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
17061eca4365STejun Heo (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
17075806db22STejun Heo
17086d1245bfSTejun Heo /**
1709fa5bde13SDamien Le Moal * ata_ncq_supported - Test whether NCQ is supported
1710fa5bde13SDamien Le Moal * @dev: ATA device to test
17116d1245bfSTejun Heo *
17126d1245bfSTejun Heo * LOCKING:
17136d1245bfSTejun Heo * spin_lock_irqsave(host lock)
17146d1245bfSTejun Heo *
17156d1245bfSTejun Heo * RETURNS:
1716fa5bde13SDamien Le Moal * true if @dev supports NCQ, false otherwise.
17176d1245bfSTejun Heo */
ata_ncq_supported(struct ata_device * dev)1718fa5bde13SDamien Le Moal static inline bool ata_ncq_supported(struct ata_device *dev)
17196d1245bfSTejun Heo {
17207caa30eaSBartlomiej Zolnierkiewicz if (!IS_ENABLED(CONFIG_SATA_HOST))
1721fa5bde13SDamien Le Moal return false;
1722fa5bde13SDamien Le Moal return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
1723fa5bde13SDamien Le Moal }
1724fa5bde13SDamien Le Moal
1725fa5bde13SDamien Le Moal /**
1726fa5bde13SDamien Le Moal * ata_ncq_enabled - Test whether NCQ is enabled
1727fa5bde13SDamien Le Moal * @dev: ATA device to test
1728fa5bde13SDamien Le Moal *
1729fa5bde13SDamien Le Moal * LOCKING:
1730fa5bde13SDamien Le Moal * spin_lock_irqsave(host lock)
1731fa5bde13SDamien Le Moal *
1732fa5bde13SDamien Le Moal * RETURNS:
1733fa5bde13SDamien Le Moal * true if NCQ is enabled for @dev, false otherwise.
1734fa5bde13SDamien Le Moal */
ata_ncq_enabled(struct ata_device * dev)1735fa5bde13SDamien Le Moal static inline bool ata_ncq_enabled(struct ata_device *dev)
1736fa5bde13SDamien Le Moal {
1737fa5bde13SDamien Le Moal return ata_ncq_supported(dev) && !(dev->flags & ATA_DFLAG_NCQ_OFF);
17386d1245bfSTejun Heo }
17390baab86bSEdward Falk
ata_fpdma_dsm_supported(struct ata_device * dev)174087fb6c31SMarc Carino static inline bool ata_fpdma_dsm_supported(struct ata_device *dev)
174187fb6c31SMarc Carino {
174287fb6c31SMarc Carino return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
174387fb6c31SMarc Carino (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &
174487fb6c31SMarc Carino ATA_LOG_NCQ_SEND_RECV_DSM_TRIM);
174587fb6c31SMarc Carino }
174687fb6c31SMarc Carino
ata_fpdma_read_log_supported(struct ata_device * dev)17475c65d8bbSHannes Reinecke static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
17485c65d8bbSHannes Reinecke {
17495c65d8bbSHannes Reinecke return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
17505c65d8bbSHannes Reinecke (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &
17515c65d8bbSHannes Reinecke ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
17525c65d8bbSHannes Reinecke }
17535c65d8bbSHannes Reinecke
ata_fpdma_zac_mgmt_in_supported(struct ata_device * dev)175428a3fc22SHannes Reinecke static inline bool ata_fpdma_zac_mgmt_in_supported(struct ata_device *dev)
175528a3fc22SHannes Reinecke {
175628a3fc22SHannes Reinecke return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
175728a3fc22SHannes Reinecke (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET] &
175828a3fc22SHannes Reinecke ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED);
175928a3fc22SHannes Reinecke }
176028a3fc22SHannes Reinecke
ata_fpdma_zac_mgmt_out_supported(struct ata_device * dev)1761284b3b77SHannes Reinecke static inline bool ata_fpdma_zac_mgmt_out_supported(struct ata_device *dev)
1762284b3b77SHannes Reinecke {
1763284b3b77SHannes Reinecke return (dev->ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OFFSET] &
1764284b3b77SHannes Reinecke ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OUT);
1765284b3b77SHannes Reinecke }
1766284b3b77SHannes Reinecke
ata_qc_set_polling(struct ata_queued_cmd * qc)17671da177e4SLinus Torvalds static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
17681da177e4SLinus Torvalds {
17691da177e4SLinus Torvalds qc->tf.ctl |= ATA_NIEN;
17701da177e4SLinus Torvalds }
17711da177e4SLinus Torvalds
__ata_qc_from_tag(struct ata_port * ap,unsigned int tag)1772f69499f4STejun Heo static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
17731da177e4SLinus Torvalds unsigned int tag)
17741da177e4SLinus Torvalds {
177528361c40SJens Axboe if (ata_tag_valid(tag))
17761da177e4SLinus Torvalds return &ap->qcmd[tag];
17771da177e4SLinus Torvalds return NULL;
17781da177e4SLinus Torvalds }
17791da177e4SLinus Torvalds
ata_qc_from_tag(struct ata_port * ap,unsigned int tag)1780f69499f4STejun Heo static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
1781f69499f4STejun Heo unsigned int tag)
1782f69499f4STejun Heo {
1783f69499f4STejun Heo struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1784f69499f4STejun Heo
1785ff8072d5SHannes Reinecke if (unlikely(!qc))
1786f69499f4STejun Heo return qc;
1787f69499f4STejun Heo
1788f69499f4STejun Heo if ((qc->flags & (ATA_QCFLAG_ACTIVE |
178987629312SNiklas Cassel ATA_QCFLAG_EH)) == ATA_QCFLAG_ACTIVE)
1790f69499f4STejun Heo return qc;
1791f69499f4STejun Heo
1792f69499f4STejun Heo return NULL;
1793f69499f4STejun Heo }
1794f69499f4STejun Heo
ata_qc_raw_nbytes(struct ata_queued_cmd * qc)1795aacda375STejun Heo static inline unsigned int ata_qc_raw_nbytes(struct ata_queued_cmd *qc)
1796aacda375STejun Heo {
1797aacda375STejun Heo return qc->nbytes - min(qc->extrabytes, qc->nbytes);
1798aacda375STejun Heo }
1799aacda375STejun Heo
ata_tf_init(struct ata_device * dev,struct ata_taskfile * tf)18003373efd8STejun Heo static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
18011da177e4SLinus Torvalds {
18021da177e4SLinus Torvalds memset(tf, 0, sizeof(*tf));
18031da177e4SLinus Torvalds
18045fe7454aSTejun Heo #ifdef CONFIG_ATA_SFF
18059af5c9c9STejun Heo tf->ctl = dev->link->ap->ctl;
18065fe7454aSTejun Heo #else
18075fe7454aSTejun Heo tf->ctl = ATA_DEVCTL_OBS;
18085fe7454aSTejun Heo #endif
18093373efd8STejun Heo if (dev->devno == 0)
18101da177e4SLinus Torvalds tf->device = ATA_DEVICE_OBS;
18111da177e4SLinus Torvalds else
18121da177e4SLinus Torvalds tf->device = ATA_DEVICE_OBS | ATA_DEV1;
18131da177e4SLinus Torvalds }
18141da177e4SLinus Torvalds
ata_qc_reinit(struct ata_queued_cmd * qc)18152c13b7ceSJeff Garzik static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
18162c13b7ceSJeff Garzik {
1817501e0c50STejun Heo qc->dma_dir = DMA_NONE;
1818ff2aeb1eSTejun Heo qc->sg = NULL;
18192c13b7ceSJeff Garzik qc->flags = 0;
182087260216SJens Axboe qc->cursg = NULL;
182187260216SJens Axboe qc->cursg_ofs = 0;
1822aacda375STejun Heo qc->nbytes = qc->extrabytes = qc->curbytes = 0;
18237a801184SBrian King qc->n_elem = 0;
1824a22e2eb0SAlbert Lee qc->err_mask = 0;
18255a5dbd18SMark Lord qc->sect_size = ATA_SECT_SIZE;
18262c13b7ceSJeff Garzik
18273373efd8STejun Heo ata_tf_init(qc->dev, &qc->tf);
1828e61e0672STejun Heo
1829e61e0672STejun Heo /* init result_tf such that it indicates normal completion */
1830e61e0672STejun Heo qc->result_tf.command = ATA_DRDY;
1831e61e0672STejun Heo qc->result_tf.feature = 0;
18322c13b7ceSJeff Garzik }
18332c13b7ceSJeff Garzik
ata_try_flush_cache(const struct ata_device * dev)1834057ace5eSJeff Garzik static inline int ata_try_flush_cache(const struct ata_device *dev)
18351da177e4SLinus Torvalds {
18361da177e4SLinus Torvalds return ata_id_wcache_enabled(dev->id) ||
18371da177e4SLinus Torvalds ata_id_has_flush(dev->id) ||
18381da177e4SLinus Torvalds ata_id_has_flush_ext(dev->id);
18391da177e4SLinus Torvalds }
18401da177e4SLinus Torvalds
ac_err_mask(u8 status)1841a7dac447SJeff Garzik static inline unsigned int ac_err_mask(u8 status)
1842a7dac447SJeff Garzik {
18433655d1d3SAlbert Lee if (status & (ATA_BUSY | ATA_DRQ))
184411a56d24STejun Heo return AC_ERR_HSM;
1845a7dac447SJeff Garzik if (status & (ATA_ERR | ATA_DF))
1846a7dac447SJeff Garzik return AC_ERR_DEV;
1847a7dac447SJeff Garzik return 0;
1848a7dac447SJeff Garzik }
1849a7dac447SJeff Garzik
__ac_err_mask(u8 status)1850a7dac447SJeff Garzik static inline unsigned int __ac_err_mask(u8 status)
1851a7dac447SJeff Garzik {
1852a7dac447SJeff Garzik unsigned int mask = ac_err_mask(status);
1853a7dac447SJeff Garzik if (mask == 0)
1854a7dac447SJeff Garzik return AC_ERR_OTHER;
1855a7dac447SJeff Garzik return mask;
1856a7dac447SJeff Garzik }
1857a7dac447SJeff Garzik
ata_shost_to_port(struct Scsi_Host * host)185835bb94b1SJeff Garzik static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
185935bb94b1SJeff Garzik {
18604911487aSTejun Heo return *(struct ata_port **)&host->hostdata[0];
186135bb94b1SJeff Garzik }
186235bb94b1SJeff Garzik
ata_check_ready(u8 status)186378ab88f0STejun Heo static inline int ata_check_ready(u8 status)
186478ab88f0STejun Heo {
1865005b1f74SJeff Garzik if (!(status & ATA_BUSY))
1866005b1f74SJeff Garzik return 1;
186778ab88f0STejun Heo
186878ab88f0STejun Heo /* 0xff indicates either no device or device not ready */
186978ab88f0STejun Heo if (status == 0xff)
187078ab88f0STejun Heo return -ENODEV;
187178ab88f0STejun Heo
1872005b1f74SJeff Garzik return 0;
187378ab88f0STejun Heo }
187478ab88f0STejun Heo
ata_deadline(unsigned long from_jiffies,unsigned int timeout_msecs)1875341c2c95STejun Heo static inline unsigned long ata_deadline(unsigned long from_jiffies,
187663b93099SSergey Shtylyov unsigned int timeout_msecs)
1877341c2c95STejun Heo {
1878341c2c95STejun Heo return from_jiffies + msecs_to_jiffies(timeout_msecs);
1879341c2c95STejun Heo }
1880341c2c95STejun Heo
1881b15b3ebaSAlan Cox /* Don't open code these in drivers as there are traps. Firstly the range may
1882b15b3ebaSAlan Cox change in future hardware and specs, secondly 0xFF means 'no DMA' but is
1883b15b3ebaSAlan Cox > UDMA_0. Dyma ddreigiau */
1884b15b3ebaSAlan Cox
ata_using_mwdma(struct ata_device * adev)1885b15b3ebaSAlan Cox static inline int ata_using_mwdma(struct ata_device *adev)
1886b15b3ebaSAlan Cox {
1887b15b3ebaSAlan Cox if (adev->dma_mode >= XFER_MW_DMA_0 && adev->dma_mode <= XFER_MW_DMA_4)
1888b15b3ebaSAlan Cox return 1;
1889b15b3ebaSAlan Cox return 0;
1890b15b3ebaSAlan Cox }
1891b15b3ebaSAlan Cox
ata_using_udma(struct ata_device * adev)1892b15b3ebaSAlan Cox static inline int ata_using_udma(struct ata_device *adev)
1893b15b3ebaSAlan Cox {
1894b15b3ebaSAlan Cox if (adev->dma_mode >= XFER_UDMA_0 && adev->dma_mode <= XFER_UDMA_7)
1895b15b3ebaSAlan Cox return 1;
1896b15b3ebaSAlan Cox return 0;
1897b15b3ebaSAlan Cox }
1898b15b3ebaSAlan Cox
ata_dma_enabled(struct ata_device * adev)1899b15b3ebaSAlan Cox static inline int ata_dma_enabled(struct ata_device *adev)
1900b15b3ebaSAlan Cox {
1901b15b3ebaSAlan Cox return (adev->dma_mode == 0xFF ? 0 : 1);
1902b15b3ebaSAlan Cox }
190348515f6cSTejun Heo
190448515f6cSTejun Heo /**************************************************************************
1905a9b2c120SBartlomiej Zolnierkiewicz * PATA timings - drivers/ata/libata-pata-timings.c
1906a9b2c120SBartlomiej Zolnierkiewicz */
1907a9b2c120SBartlomiej Zolnierkiewicz extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1908a9b2c120SBartlomiej Zolnierkiewicz extern int ata_timing_compute(struct ata_device *, unsigned short,
1909a9b2c120SBartlomiej Zolnierkiewicz struct ata_timing *, int, int);
1910a9b2c120SBartlomiej Zolnierkiewicz extern void ata_timing_merge(const struct ata_timing *,
1911a9b2c120SBartlomiej Zolnierkiewicz const struct ata_timing *, struct ata_timing *,
1912a9b2c120SBartlomiej Zolnierkiewicz unsigned int);
1913a9b2c120SBartlomiej Zolnierkiewicz
1914a9b2c120SBartlomiej Zolnierkiewicz /**************************************************************************
191548515f6cSTejun Heo * PMP - drivers/ata/libata-pmp.c
191648515f6cSTejun Heo */
191788fcd562STejun Heo #ifdef CONFIG_SATA_PMP
191888fcd562STejun Heo
191948515f6cSTejun Heo extern const struct ata_port_operations sata_pmp_port_ops;
192048515f6cSTejun Heo
192148515f6cSTejun Heo extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
192248515f6cSTejun Heo extern void sata_pmp_error_handler(struct ata_port *ap);
192348515f6cSTejun Heo
192488fcd562STejun Heo #else /* CONFIG_SATA_PMP */
192588fcd562STejun Heo
192688fcd562STejun Heo #define sata_pmp_port_ops sata_port_ops
192788fcd562STejun Heo #define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
192888fcd562STejun Heo #define sata_pmp_error_handler ata_std_error_handler
192988fcd562STejun Heo
193088fcd562STejun Heo #endif /* CONFIG_SATA_PMP */
193188fcd562STejun Heo
193248515f6cSTejun Heo
1933624d5c51STejun Heo /**************************************************************************
1934624d5c51STejun Heo * SFF - drivers/ata/libata-sff.c
1935624d5c51STejun Heo */
1936127102aeSTejun Heo #ifdef CONFIG_ATA_SFF
1937127102aeSTejun Heo
1938624d5c51STejun Heo extern const struct ata_port_operations ata_sff_port_ops;
1939871af121SAlan Cox extern const struct ata_port_operations ata_bmdma32_port_ops;
1940624d5c51STejun Heo
1941624d5c51STejun Heo /* PIO only, sg_tablesize and dma_boundary limits can be removed */
1942624d5c51STejun Heo #define ATA_PIO_SHT(drv_name) \
1943624d5c51STejun Heo ATA_BASE_SHT(drv_name), \
1944624d5c51STejun Heo .sg_tablesize = LIBATA_MAX_PRD, \
1945624d5c51STejun Heo .dma_boundary = ATA_DMA_BOUNDARY
1946624d5c51STejun Heo
19479363c382STejun Heo extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
19489363c382STejun Heo extern u8 ata_sff_check_status(struct ata_port *ap);
1949a57c1badSAlan Cox extern void ata_sff_pause(struct ata_port *ap);
1950a57c1badSAlan Cox extern void ata_sff_dma_pause(struct ata_port *ap);
1951705e76beSTejun Heo extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline);
19529363c382STejun Heo extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
19539363c382STejun Heo extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
19549363c382STejun Heo extern void ata_sff_exec_command(struct ata_port *ap,
19559363c382STejun Heo const struct ata_taskfile *tf);
1956989e0aacSBartlomiej Zolnierkiewicz extern unsigned int ata_sff_data_xfer(struct ata_queued_cmd *qc,
1957624d5c51STejun Heo unsigned char *buf, unsigned int buflen, int rw);
1958989e0aacSBartlomiej Zolnierkiewicz extern unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc,
1959871af121SAlan Cox unsigned char *buf, unsigned int buflen, int rw);
1960e42a542bSSergei Shtylyov extern void ata_sff_irq_on(struct ata_port *ap);
19619363c382STejun Heo extern void ata_sff_irq_clear(struct ata_port *ap);
19629363c382STejun Heo extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
1963624d5c51STejun Heo u8 status, int in_wq);
196464b97594SViresh Kumar extern void ata_sff_queue_work(struct work_struct *work);
196564b97594SViresh Kumar extern void ata_sff_queue_delayed_work(struct delayed_work *dwork,
196664b97594SViresh Kumar unsigned long delay);
1967ea3c6450SGwendal Grignou extern void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay);
19689363c382STejun Heo extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
1969931139afSDamien Le Moal extern void ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
1970c3b28894STejun Heo extern unsigned int ata_sff_port_intr(struct ata_port *ap,
19719363c382STejun Heo struct ata_queued_cmd *qc);
19729363c382STejun Heo extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
1973c96f1732SAlan Cox extern void ata_sff_lost_interrupt(struct ata_port *ap);
19749363c382STejun Heo extern void ata_sff_freeze(struct ata_port *ap);
19759363c382STejun Heo extern void ata_sff_thaw(struct ata_port *ap);
19769363c382STejun Heo extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
19779363c382STejun Heo extern unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
1978624d5c51STejun Heo u8 *r_err);
1979705e76beSTejun Heo extern int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
1980624d5c51STejun Heo unsigned long deadline);
19819363c382STejun Heo extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
1982624d5c51STejun Heo unsigned long deadline);
19839363c382STejun Heo extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
19849363c382STejun Heo unsigned long deadline);
19859363c382STejun Heo extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
19863d47aa8eSAlan Cox extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
19879363c382STejun Heo extern void ata_sff_error_handler(struct ata_port *ap);
19889363c382STejun Heo extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
1989624d5c51STejun Heo #ifdef CONFIG_PCI
19909363c382STejun Heo extern int ata_pci_sff_init_host(struct ata_host *host);
19919363c382STejun Heo extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
1992624d5c51STejun Heo const struct ata_port_info * const * ppi,
1993624d5c51STejun Heo struct ata_host **r_host);
19949363c382STejun Heo extern int ata_pci_sff_activate_host(struct ata_host *host,
1995624d5c51STejun Heo irq_handler_t irq_handler,
199625df73d9SBart Van Assche const struct scsi_host_template *sht);
19979363c382STejun Heo extern int ata_pci_sff_init_one(struct pci_dev *pdev,
1998624d5c51STejun Heo const struct ata_port_info * const * ppi,
199925df73d9SBart Van Assche const struct scsi_host_template *sht, void *host_priv, int hflags);
2000624d5c51STejun Heo #endif /* CONFIG_PCI */
2001624d5c51STejun Heo
20029a7780c9STejun Heo #ifdef CONFIG_ATA_BMDMA
20039a7780c9STejun Heo
20049a7780c9STejun Heo extern const struct ata_port_operations ata_bmdma_port_ops;
20059a7780c9STejun Heo
20069a7780c9STejun Heo #define ATA_BMDMA_SHT(drv_name) \
20079a7780c9STejun Heo ATA_BASE_SHT(drv_name), \
20089a7780c9STejun Heo .sg_tablesize = LIBATA_MAX_PRD, \
20099a7780c9STejun Heo .dma_boundary = ATA_DMA_BOUNDARY
20109a7780c9STejun Heo
201195364f36SJiri Slaby extern enum ata_completion_errors ata_bmdma_qc_prep(struct ata_queued_cmd *qc);
2012360ff783STejun Heo extern unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc);
201395364f36SJiri Slaby extern enum ata_completion_errors ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc);
2014c3b28894STejun Heo extern unsigned int ata_bmdma_port_intr(struct ata_port *ap,
2015c3b28894STejun Heo struct ata_queued_cmd *qc);
2016c3b28894STejun Heo extern irqreturn_t ata_bmdma_interrupt(int irq, void *dev_instance);
2017fe06e5f9STejun Heo extern void ata_bmdma_error_handler(struct ata_port *ap);
2018fe06e5f9STejun Heo extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
201937f65b8bSTejun Heo extern void ata_bmdma_irq_clear(struct ata_port *ap);
20209f2f7210STejun Heo extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
20219f2f7210STejun Heo extern void ata_bmdma_start(struct ata_queued_cmd *qc);
20229f2f7210STejun Heo extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
20239f2f7210STejun Heo extern u8 ata_bmdma_status(struct ata_port *ap);
2024c7087652STejun Heo extern int ata_bmdma_port_start(struct ata_port *ap);
2025c7087652STejun Heo extern int ata_bmdma_port_start32(struct ata_port *ap);
20269f2f7210STejun Heo
20279f2f7210STejun Heo #ifdef CONFIG_PCI
20289f2f7210STejun Heo extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
2029c7087652STejun Heo extern void ata_pci_bmdma_init(struct ata_host *host);
20301c5afdf7STejun Heo extern int ata_pci_bmdma_prepare_host(struct pci_dev *pdev,
20311c5afdf7STejun Heo const struct ata_port_info * const * ppi,
20321c5afdf7STejun Heo struct ata_host **r_host);
20331c5afdf7STejun Heo extern int ata_pci_bmdma_init_one(struct pci_dev *pdev,
20341c5afdf7STejun Heo const struct ata_port_info * const * ppi,
203525df73d9SBart Van Assche const struct scsi_host_template *sht,
20361c5afdf7STejun Heo void *host_priv, int hflags);
20379f2f7210STejun Heo #endif /* CONFIG_PCI */
20389a7780c9STejun Heo #endif /* CONFIG_ATA_BMDMA */
20399f2f7210STejun Heo
2040624d5c51STejun Heo /**
20419363c382STejun Heo * ata_sff_busy_wait - Wait for a port status register
2042624d5c51STejun Heo * @ap: Port to wait for.
2043624d5c51STejun Heo * @bits: bits that must be clear
2044624d5c51STejun Heo * @max: number of 10uS waits to perform
2045624d5c51STejun Heo *
2046624d5c51STejun Heo * Waits up to max*10 microseconds for the selected bits in the port's
2047624d5c51STejun Heo * status register to be cleared.
2048624d5c51STejun Heo * Returns final value of status register.
2049624d5c51STejun Heo *
2050624d5c51STejun Heo * LOCKING:
2051624d5c51STejun Heo * Inherited from caller.
2052624d5c51STejun Heo */
ata_sff_busy_wait(struct ata_port * ap,unsigned int bits,unsigned int max)20539363c382STejun Heo static inline u8 ata_sff_busy_wait(struct ata_port *ap, unsigned int bits,
2054624d5c51STejun Heo unsigned int max)
2055624d5c51STejun Heo {
2056624d5c51STejun Heo u8 status;
2057624d5c51STejun Heo
2058624d5c51STejun Heo do {
2059624d5c51STejun Heo udelay(10);
20605682ed33STejun Heo status = ap->ops->sff_check_status(ap);
2061624d5c51STejun Heo max--;
2062624d5c51STejun Heo } while (status != 0xff && (status & bits) && (max > 0));
2063624d5c51STejun Heo
2064624d5c51STejun Heo return status;
2065624d5c51STejun Heo }
2066624d5c51STejun Heo
2067624d5c51STejun Heo /**
2068624d5c51STejun Heo * ata_wait_idle - Wait for a port to be idle.
2069624d5c51STejun Heo * @ap: Port to wait for.
2070624d5c51STejun Heo *
2071624d5c51STejun Heo * Waits up to 10ms for port's BUSY and DRQ signals to clear.
2072624d5c51STejun Heo * Returns final value of status register.
2073624d5c51STejun Heo *
2074624d5c51STejun Heo * LOCKING:
2075624d5c51STejun Heo * Inherited from caller.
2076624d5c51STejun Heo */
ata_wait_idle(struct ata_port * ap)2077624d5c51STejun Heo static inline u8 ata_wait_idle(struct ata_port *ap)
2078624d5c51STejun Heo {
20799363c382STejun Heo u8 status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
2080624d5c51STejun Heo
2081624d5c51STejun Heo if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
2082742bef47SHannes Reinecke ata_port_dbg(ap, "abnormal Status 0x%X\n", status);
2083624d5c51STejun Heo
2084624d5c51STejun Heo return status;
2085624d5c51STejun Heo }
2086127102aeSTejun Heo #endif /* CONFIG_ATA_SFF */
2087624d5c51STejun Heo
20881da177e4SLinus Torvalds #endif /* __LINUX_LIBATA_H__ */
2089