1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright 2003-2005 Red Hat, Inc. All rights reserved.
4 * Copyright 2003-2005 Jeff Garzik
5 *
6 * libata documentation is available via 'make {ps|pdf}docs',
7 * as Documentation/driver-api/libata.rst
8 */
9
10 #ifndef __LINUX_LIBATA_H__
11 #define __LINUX_LIBATA_H__
12
13 #include <linux/delay.h>
14 #include <linux/jiffies.h>
15 #include <linux/interrupt.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/scatterlist.h>
18 #include <linux/io.h>
19 #include <linux/ata.h>
20 #include <linux/workqueue.h>
21 #include <scsi/scsi_host.h>
22 #include <linux/acpi.h>
23 #include <linux/cdrom.h>
24 #include <linux/sched.h>
25 #include <linux/async.h>
26
27 /*
28 * Define if arch has non-standard setup. This is a _PCI_ standard
29 * not a legacy or ISA standard.
30 */
31 #ifdef CONFIG_ATA_NONSTANDARD
32 #include <asm/libata-portmap.h>
33 #else
34 #define ATA_PRIMARY_IRQ(dev) 14
35 #define ATA_SECONDARY_IRQ(dev) 15
36 #endif
37
38 /*
39 * compile-time options: to be removed as soon as all the drivers are
40 * converted to the new debugging mechanism
41 */
42 #undef ATA_IRQ_TRAP /* define to ack screaming irqs */
43
44
45 #define ata_print_version_once(dev, version) \
46 ({ \
47 static bool __print_once; \
48 \
49 if (!__print_once) { \
50 __print_once = true; \
51 ata_print_version(dev, version); \
52 } \
53 })
54
55 /* defines only for the constants which don't work well as enums */
56 #define ATA_TAG_POISON 0xfafbfcfdU
57
58 /*
59 * Quirk flags bits.
60 * ata_device->quirks is an unsigned int, so __ATA_QUIRK_MAX must not exceed 32.
61 */
62 enum ata_quirks {
63 __ATA_QUIRK_DIAGNOSTIC, /* Failed boot diag */
64 __ATA_QUIRK_NODMA, /* DMA problems */
65 __ATA_QUIRK_NONCQ, /* Don't use NCQ */
66 __ATA_QUIRK_MAX_SEC_128, /* Limit max sects to 128 */
67 __ATA_QUIRK_BROKEN_HPA, /* Broken HPA */
68 __ATA_QUIRK_DISABLE, /* Disable it */
69 __ATA_QUIRK_HPA_SIZE, /* Native size off by one */
70 __ATA_QUIRK_IVB, /* cbl det validity bit bugs */
71 __ATA_QUIRK_STUCK_ERR, /* Stuck ERR on next PACKET */
72 __ATA_QUIRK_BRIDGE_OK, /* No bridge limits */
73 __ATA_QUIRK_ATAPI_MOD16_DMA, /* Use ATAPI DMA for commands that */
74 /* are not a multiple of 16 bytes */
75 __ATA_QUIRK_FIRMWARE_WARN, /* Firmware update warning */
76 __ATA_QUIRK_1_5_GBPS, /* Force 1.5 Gbps */
77 __ATA_QUIRK_NOSETXFER, /* Skip SETXFER, SATA only */
78 __ATA_QUIRK_BROKEN_FPDMA_AA, /* Skip AA */
79 __ATA_QUIRK_DUMP_ID, /* Dump IDENTIFY data */
80 __ATA_QUIRK_MAX_SEC_LBA48, /* Set max sects to 65535 */
81 __ATA_QUIRK_ATAPI_DMADIR, /* Device requires dmadir */
82 __ATA_QUIRK_NO_NCQ_TRIM, /* Do not use queued TRIM */
83 __ATA_QUIRK_NOLPM, /* Do not use LPM */
84 __ATA_QUIRK_WD_BROKEN_LPM, /* Some WDs have broken LPM */
85 __ATA_QUIRK_ZERO_AFTER_TRIM, /* Guarantees zero after trim */
86 __ATA_QUIRK_NO_DMA_LOG, /* Do not use DMA for log read */
87 __ATA_QUIRK_NOTRIM, /* Do not use TRIM */
88 __ATA_QUIRK_MAX_SEC_1024, /* Limit max sects to 1024 */
89 __ATA_QUIRK_MAX_TRIM_128M, /* Limit max trim size to 128M */
90 __ATA_QUIRK_NO_NCQ_ON_ATI, /* Disable NCQ on ATI chipset */
91 __ATA_QUIRK_NO_LPM_ON_ATI, /* Disable LPM on ATI chipset */
92 __ATA_QUIRK_NO_ID_DEV_LOG, /* Identify device log missing */
93 __ATA_QUIRK_NO_LOG_DIR, /* Do not read log directory */
94 __ATA_QUIRK_NO_FUA, /* Do not use FUA */
95
96 __ATA_QUIRK_MAX,
97 };
98
99 enum {
100 /* various global constants */
101 LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
102 LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4, /* Worst case */
103 ATA_DEF_QUEUE = 1,
104 ATA_MAX_QUEUE = 32,
105 ATA_TAG_INTERNAL = ATA_MAX_QUEUE,
106 ATA_SHORT_PAUSE = 16,
107
108 ATAPI_MAX_DRAIN = 16 << 10,
109
110 ATA_ALL_DEVICES = (1 << ATA_MAX_DEVICES) - 1,
111
112 ATA_SHT_EMULATED = 1,
113 ATA_SHT_THIS_ID = -1,
114
115 /* struct ata_taskfile flags */
116 ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */
117 ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */
118 ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */
119 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
120 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
121 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
122 ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
123
124 /* struct ata_device stuff */
125 ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
126 ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
127 ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
128 ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
129 ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */
130 ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */
131 ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */
132 ATA_DFLAG_AN = (1 << 7), /* AN configured */
133 ATA_DFLAG_TRUSTED = (1 << 8), /* device supports trusted send/recv */
134 ATA_DFLAG_FUA = (1 << 9), /* device supports FUA */
135 ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */
136 ATA_DFLAG_NCQ_SEND_RECV = (1 << 11), /* device supports NCQ SEND and RECV */
137 ATA_DFLAG_NCQ_PRIO = (1 << 12), /* device supports NCQ priority */
138 ATA_DFLAG_CDL = (1 << 13), /* supports cmd duration limits */
139 ATA_DFLAG_CFG_MASK = (1 << 14) - 1,
140
141 ATA_DFLAG_PIO = (1 << 14), /* device limited to PIO mode */
142 ATA_DFLAG_NCQ_OFF = (1 << 15), /* device limited to non-NCQ mode */
143 ATA_DFLAG_SLEEPING = (1 << 16), /* device is sleeping */
144 ATA_DFLAG_DUBIOUS_XFER = (1 << 17), /* data transfer not verified */
145 ATA_DFLAG_NO_UNLOAD = (1 << 18), /* device doesn't support unload */
146 ATA_DFLAG_UNLOCK_HPA = (1 << 19), /* unlock HPA */
147 ATA_DFLAG_INIT_MASK = (1 << 20) - 1,
148
149 ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 20), /* Priority cmds sent to dev */
150 ATA_DFLAG_CDL_ENABLED = (1 << 21), /* cmd duration limits is enabled */
151 ATA_DFLAG_RESUMING = (1 << 22), /* Device is resuming */
152 ATA_DFLAG_DETACH = (1 << 24),
153 ATA_DFLAG_DETACHED = (1 << 25),
154 ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */
155 ATA_DFLAG_DEVSLP = (1 << 27), /* device supports Device Sleep */
156 ATA_DFLAG_ACPI_DISABLED = (1 << 28), /* ACPI for the device is disabled */
157 ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */
158 ATA_DFLAG_ZAC = (1 << 30), /* ZAC device */
159
160 ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
161 ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
162 ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \
163 ATA_DFLAG_CDL),
164
165 ATA_DEV_UNKNOWN = 0, /* unknown device */
166 ATA_DEV_ATA = 1, /* ATA device */
167 ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */
168 ATA_DEV_ATAPI = 3, /* ATAPI device */
169 ATA_DEV_ATAPI_UNSUP = 4, /* ATAPI device (unsupported) */
170 ATA_DEV_PMP = 5, /* SATA port multiplier */
171 ATA_DEV_PMP_UNSUP = 6, /* SATA port multiplier (unsupported) */
172 ATA_DEV_SEMB = 7, /* SEMB */
173 ATA_DEV_SEMB_UNSUP = 8, /* SEMB (unsupported) */
174 ATA_DEV_ZAC = 9, /* ZAC device */
175 ATA_DEV_ZAC_UNSUP = 10, /* ZAC device (unsupported) */
176 ATA_DEV_NONE = 11, /* no device */
177
178 /* struct ata_link flags */
179 /* NOTE: struct ata_force_param currently stores lflags in u16 */
180 ATA_LFLAG_NO_HRST = (1 << 1), /* avoid hardreset */
181 ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
182 ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
183 ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */
184 ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
185 ATA_LFLAG_NO_RETRY = (1 << 5), /* don't retry this link */
186 ATA_LFLAG_DISABLED = (1 << 6), /* link is disabled */
187 ATA_LFLAG_SW_ACTIVITY = (1 << 7), /* keep activity stats */
188 ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */
189 ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */
190 ATA_LFLAG_CHANGED = (1 << 10), /* LPM state changed on this link */
191 ATA_LFLAG_NO_DEBOUNCE_DELAY = (1 << 11), /* no debounce delay on link resume */
192
193 /* struct ata_port flags */
194 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
195 /* (doesn't imply presence) */
196 ATA_FLAG_SATA = (1 << 1),
197 ATA_FLAG_NO_LPM = (1 << 2), /* host not happy with LPM */
198 ATA_FLAG_NO_LOG_PAGE = (1 << 5), /* do not issue log page read */
199 ATA_FLAG_NO_ATAPI = (1 << 6), /* No ATAPI support */
200 ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */
201 ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */
202 ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
203 * doesn't handle PIO interrupts */
204 ATA_FLAG_NCQ = (1 << 10), /* host supports NCQ */
205 ATA_FLAG_NO_POWEROFF_SPINDOWN = (1 << 11), /* don't spindown before poweroff */
206 ATA_FLAG_NO_HIBERNATE_SPINDOWN = (1 << 12), /* don't spindown before hibernation */
207 ATA_FLAG_DEBUGMSG = (1 << 13),
208 ATA_FLAG_FPDMA_AA = (1 << 14), /* driver supports Auto-Activate */
209 ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
210 ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */
211 ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */
212 ATA_FLAG_AN = (1 << 18), /* controller supports AN */
213 ATA_FLAG_PMP = (1 << 19), /* controller supports PMP */
214 ATA_FLAG_FPDMA_AUX = (1 << 20), /* controller supports H2DFIS aux field */
215 ATA_FLAG_EM = (1 << 21), /* driver supports enclosure
216 * management */
217 ATA_FLAG_SW_ACTIVITY = (1 << 22), /* driver supports sw activity
218 * led */
219 ATA_FLAG_NO_DIPM = (1 << 23), /* host not happy with DIPM */
220 ATA_FLAG_SAS_HOST = (1 << 24), /* SAS host */
221
222 /* bits 24:31 of ap->flags are reserved for LLD specific flags */
223
224
225 /* struct ata_port pflags */
226 ATA_PFLAG_EH_PENDING = (1 << 0), /* EH pending */
227 ATA_PFLAG_EH_IN_PROGRESS = (1 << 1), /* EH in progress */
228 ATA_PFLAG_FROZEN = (1 << 2), /* port is frozen */
229 ATA_PFLAG_RECOVERED = (1 << 3), /* recovery action performed */
230 ATA_PFLAG_LOADING = (1 << 4), /* boot/loading probe */
231 ATA_PFLAG_SCSI_HOTPLUG = (1 << 6), /* SCSI hotplug scheduled */
232 ATA_PFLAG_INITIALIZING = (1 << 7), /* being initialized, don't touch */
233 ATA_PFLAG_RESETTING = (1 << 8), /* reset in progress */
234 ATA_PFLAG_UNLOADING = (1 << 9), /* driver is being unloaded */
235 ATA_PFLAG_UNLOADED = (1 << 10), /* driver is unloaded */
236
237 ATA_PFLAG_RESUMING = (1 << 16), /* port is being resumed */
238 ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */
239 ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */
240 ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */
241
242 ATA_PFLAG_PIO32 = (1 << 20), /* 32bit PIO */
243 ATA_PFLAG_PIO32CHANGE = (1 << 21), /* 32bit PIO can be turned on/off */
244 ATA_PFLAG_EXTERNAL = (1 << 22), /* eSATA/external port */
245
246 /* struct ata_queued_cmd flags */
247 ATA_QCFLAG_ACTIVE = (1 << 0), /* cmd not yet ack'd to scsi lyer */
248 ATA_QCFLAG_DMAMAP = (1 << 1), /* SG table is DMA mapped */
249 ATA_QCFLAG_RTF_FILLED = (1 << 2), /* result TF has been filled */
250 ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
251 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
252 ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */
253 ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */
254 ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */
255 ATA_QCFLAG_HAS_CDL = (1 << 8), /* qc has CDL a descriptor set */
256
257 ATA_QCFLAG_EH = (1 << 16), /* cmd aborted and owned by EH */
258 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
259 ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
260 ATA_QCFLAG_EH_SUCCESS_CMD = (1 << 19), /* EH should fetch sense for this successful cmd */
261
262 /* host set flags */
263 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */
264 ATA_HOST_STARTED = (1 << 1), /* Host started */
265 ATA_HOST_PARALLEL_SCAN = (1 << 2), /* Ports on this host can be scanned in parallel */
266 ATA_HOST_IGNORE_ATA = (1 << 3), /* Ignore ATA devices on this host. */
267
268 ATA_HOST_NO_PART = (1 << 4), /* Host does not support partial */
269 ATA_HOST_NO_SSC = (1 << 5), /* Host does not support slumber */
270 ATA_HOST_NO_DEVSLP = (1 << 6), /* Host does not support devslp */
271
272 /* bits 24:31 of host->flags are reserved for LLD specific flags */
273
274 /* Various lengths of time */
275 ATA_TMOUT_INTERNAL_QUICK = 5000,
276 ATA_TMOUT_MAX_PARK = 30000,
277
278 /*
279 * GoVault needs 2s and iVDR disk HHD424020F7SV00 800ms. 2s
280 * is too much without parallel probing. Use 2s if parallel
281 * probing is available, 800ms otherwise.
282 */
283 ATA_TMOUT_FF_WAIT_LONG = 2000,
284 ATA_TMOUT_FF_WAIT = 800,
285
286 /* Spec mandates to wait for ">= 2ms" before checking status
287 * after reset. We wait 150ms, because that was the magic
288 * delay used for ATAPI devices in Hale Landis's ATADRVR, for
289 * the period of time between when the ATA command register is
290 * written, and then status is checked. Because waiting for
291 * "a while" before checking status is fine, post SRST, we
292 * perform this magic delay here as well.
293 *
294 * Old drivers/ide uses the 2mS rule and then waits for ready.
295 */
296 ATA_WAIT_AFTER_RESET = 150,
297
298 /* If PMP is supported, we have to do follow-up SRST. As some
299 * PMPs don't send D2H Reg FIS after hardreset, LLDs are
300 * advised to wait only for the following duration before
301 * doing SRST.
302 */
303 ATA_TMOUT_PMP_SRST_WAIT = 10000,
304
305 /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might
306 * be a spurious PHY event, so ignore the first PHY event that
307 * occurs within 10s after the policy change.
308 */
309 ATA_TMOUT_SPURIOUS_PHY = 10000,
310
311 /* ATA bus states */
312 BUS_UNKNOWN = 0,
313 BUS_DMA = 1,
314 BUS_IDLE = 2,
315 BUS_NOINTR = 3,
316 BUS_NODATA = 4,
317 BUS_TIMER = 5,
318 BUS_PIO = 6,
319 BUS_EDD = 7,
320 BUS_IDENTIFY = 8,
321 BUS_PACKET = 9,
322
323 /* SATA port states */
324 PORT_UNKNOWN = 0,
325 PORT_ENABLED = 1,
326 PORT_DISABLED = 2,
327
328 /* encoding various smaller bitmaps into a single
329 * unsigned int bitmap
330 */
331 ATA_NR_PIO_MODES = 7,
332 ATA_NR_MWDMA_MODES = 5,
333 ATA_NR_UDMA_MODES = 8,
334
335 ATA_SHIFT_PIO = 0,
336 ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
337 ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
338 ATA_SHIFT_PRIO = 6,
339
340 ATA_PRIO_HIGH = 2,
341 /* size of buffer to pad xfers ending on unaligned boundaries */
342 ATA_DMA_PAD_SZ = 4,
343
344 /* ering size */
345 ATA_ERING_SIZE = 32,
346
347 /* return values for ->qc_defer */
348 ATA_DEFER_LINK = 1,
349 ATA_DEFER_PORT = 2,
350
351 /* desc_len for ata_eh_info and context */
352 ATA_EH_DESC_LEN = 80,
353
354 /* reset / recovery action types */
355 ATA_EH_REVALIDATE = (1 << 0),
356 ATA_EH_SOFTRESET = (1 << 1), /* meaningful only in ->prereset */
357 ATA_EH_HARDRESET = (1 << 2), /* meaningful only in ->prereset */
358 ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
359 ATA_EH_ENABLE_LINK = (1 << 3),
360 ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */
361 ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */
362 ATA_EH_SET_ACTIVE = (1 << 7), /* Set a device to active power mode */
363
364 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK |
365 ATA_EH_GET_SUCCESS_SENSE | ATA_EH_SET_ACTIVE,
366 ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET |
367 ATA_EH_ENABLE_LINK,
368
369 /* ata_eh_info->flags */
370 ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
371 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
372 ATA_EHI_QUIET = (1 << 3), /* be quiet */
373 ATA_EHI_NO_RECOVERY = (1 << 4), /* no recovery */
374
375 ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */
376 ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */
377 ATA_EHI_PRINTINFO = (1 << 18), /* print configuration info */
378 ATA_EHI_SETMODE = (1 << 19), /* configure transfer mode */
379 ATA_EHI_POST_SETMODE = (1 << 20), /* revalidating after setmode */
380 ATA_EHI_DID_PRINT_QUIRKS = (1 << 21), /* already printed quirks info */
381
382 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
383
384 /* mask of flags to transfer *to* the slave link */
385 ATA_EHI_TO_SLAVE_MASK = ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET,
386
387 /* max tries if error condition is still set after ->error_handler */
388 ATA_EH_MAX_TRIES = 5,
389
390 /* sometimes resuming a link requires several retries */
391 ATA_LINK_RESUME_TRIES = 5,
392
393 /* how hard are we gonna try to probe/recover devices */
394 ATA_EH_DEV_TRIES = 3,
395 ATA_EH_PMP_TRIES = 5,
396 ATA_EH_PMP_LINK_TRIES = 3,
397
398 SATA_PMP_RW_TIMEOUT = 3000, /* PMP read/write timeout */
399
400 /* This should match the actual table size of
401 * ata_eh_cmd_timeout_table in libata-eh.c.
402 */
403 ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 8,
404
405 /*
406 * Quirk flags: may be set by libata or controller drivers on drives.
407 * Some quirks may be drive/controller pair dependent.
408 */
409 ATA_QUIRK_DIAGNOSTIC = (1U << __ATA_QUIRK_DIAGNOSTIC),
410 ATA_QUIRK_NODMA = (1U << __ATA_QUIRK_NODMA),
411 ATA_QUIRK_NONCQ = (1U << __ATA_QUIRK_NONCQ),
412 ATA_QUIRK_MAX_SEC_128 = (1U << __ATA_QUIRK_MAX_SEC_128),
413 ATA_QUIRK_BROKEN_HPA = (1U << __ATA_QUIRK_BROKEN_HPA),
414 ATA_QUIRK_DISABLE = (1U << __ATA_QUIRK_DISABLE),
415 ATA_QUIRK_HPA_SIZE = (1U << __ATA_QUIRK_HPA_SIZE),
416 ATA_QUIRK_IVB = (1U << __ATA_QUIRK_IVB),
417 ATA_QUIRK_STUCK_ERR = (1U << __ATA_QUIRK_STUCK_ERR),
418 ATA_QUIRK_BRIDGE_OK = (1U << __ATA_QUIRK_BRIDGE_OK),
419 ATA_QUIRK_ATAPI_MOD16_DMA = (1U << __ATA_QUIRK_ATAPI_MOD16_DMA),
420 ATA_QUIRK_FIRMWARE_WARN = (1U << __ATA_QUIRK_FIRMWARE_WARN),
421 ATA_QUIRK_1_5_GBPS = (1U << __ATA_QUIRK_1_5_GBPS),
422 ATA_QUIRK_NOSETXFER = (1U << __ATA_QUIRK_NOSETXFER),
423 ATA_QUIRK_BROKEN_FPDMA_AA = (1U << __ATA_QUIRK_BROKEN_FPDMA_AA),
424 ATA_QUIRK_DUMP_ID = (1U << __ATA_QUIRK_DUMP_ID),
425 ATA_QUIRK_MAX_SEC_LBA48 = (1U << __ATA_QUIRK_MAX_SEC_LBA48),
426 ATA_QUIRK_ATAPI_DMADIR = (1U << __ATA_QUIRK_ATAPI_DMADIR),
427 ATA_QUIRK_NO_NCQ_TRIM = (1U << __ATA_QUIRK_NO_NCQ_TRIM),
428 ATA_QUIRK_NOLPM = (1U << __ATA_QUIRK_NOLPM),
429 ATA_QUIRK_WD_BROKEN_LPM = (1U << __ATA_QUIRK_WD_BROKEN_LPM),
430 ATA_QUIRK_ZERO_AFTER_TRIM = (1U << __ATA_QUIRK_ZERO_AFTER_TRIM),
431 ATA_QUIRK_NO_DMA_LOG = (1U << __ATA_QUIRK_NO_DMA_LOG),
432 ATA_QUIRK_NOTRIM = (1U << __ATA_QUIRK_NOTRIM),
433 ATA_QUIRK_MAX_SEC_1024 = (1U << __ATA_QUIRK_MAX_SEC_1024),
434 ATA_QUIRK_MAX_TRIM_128M = (1U << __ATA_QUIRK_MAX_TRIM_128M),
435 ATA_QUIRK_NO_NCQ_ON_ATI = (1U << __ATA_QUIRK_NO_NCQ_ON_ATI),
436 ATA_QUIRK_NO_LPM_ON_ATI = (1U << __ATA_QUIRK_NO_LPM_ON_ATI),
437 ATA_QUIRK_NO_ID_DEV_LOG = (1U << __ATA_QUIRK_NO_ID_DEV_LOG),
438 ATA_QUIRK_NO_LOG_DIR = (1U << __ATA_QUIRK_NO_LOG_DIR),
439 ATA_QUIRK_NO_FUA = (1U << __ATA_QUIRK_NO_FUA),
440
441 /* User visible DMA mask for DMA control. DO NOT renumber. */
442 ATA_DMA_MASK_ATA = (1 << 0), /* DMA on ATA Disk */
443 ATA_DMA_MASK_ATAPI = (1 << 1), /* DMA on ATAPI */
444 ATA_DMA_MASK_CFA = (1 << 2), /* DMA on CF Card */
445
446 /* ATAPI command types */
447 ATAPI_READ = 0, /* READs */
448 ATAPI_WRITE = 1, /* WRITEs */
449 ATAPI_READ_CD = 2, /* READ CD [MSF] */
450 ATAPI_PASS_THRU = 3, /* SAT pass-thru */
451 ATAPI_MISC = 4, /* the rest */
452
453 /* Timing constants */
454 ATA_TIMING_SETUP = (1 << 0),
455 ATA_TIMING_ACT8B = (1 << 1),
456 ATA_TIMING_REC8B = (1 << 2),
457 ATA_TIMING_CYC8B = (1 << 3),
458 ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
459 ATA_TIMING_CYC8B,
460 ATA_TIMING_ACTIVE = (1 << 4),
461 ATA_TIMING_RECOVER = (1 << 5),
462 ATA_TIMING_DMACK_HOLD = (1 << 6),
463 ATA_TIMING_CYCLE = (1 << 7),
464 ATA_TIMING_UDMA = (1 << 8),
465 ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
466 ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
467 ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
468 ATA_TIMING_DMACK_HOLD | ATA_TIMING_CYCLE |
469 ATA_TIMING_UDMA,
470
471 /* ACPI constants */
472 ATA_ACPI_FILTER_SETXFER = 1 << 0,
473 ATA_ACPI_FILTER_LOCK = 1 << 1,
474 ATA_ACPI_FILTER_DIPM = 1 << 2,
475 ATA_ACPI_FILTER_FPDMA_OFFSET = 1 << 3, /* FPDMA non-zero offset */
476 ATA_ACPI_FILTER_FPDMA_AA = 1 << 4, /* FPDMA auto activate */
477
478 ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER |
479 ATA_ACPI_FILTER_LOCK |
480 ATA_ACPI_FILTER_DIPM,
481 };
482
483 enum ata_xfer_mask {
484 ATA_MASK_PIO = ((1U << ATA_NR_PIO_MODES) - 1) << ATA_SHIFT_PIO,
485 ATA_MASK_MWDMA = ((1U << ATA_NR_MWDMA_MODES) - 1) << ATA_SHIFT_MWDMA,
486 ATA_MASK_UDMA = ((1U << ATA_NR_UDMA_MODES) - 1) << ATA_SHIFT_UDMA,
487 };
488
489 enum hsm_task_states {
490 HSM_ST_IDLE, /* no command on going */
491 HSM_ST_FIRST, /* (waiting the device to)
492 write CDB or first data block */
493 HSM_ST, /* (waiting the device to) transfer data */
494 HSM_ST_LAST, /* (waiting the device to) complete command */
495 HSM_ST_ERR, /* error */
496 };
497
498 enum ata_completion_errors {
499 AC_ERR_OK = 0, /* no error */
500 AC_ERR_DEV = (1 << 0), /* device reported error */
501 AC_ERR_HSM = (1 << 1), /* host state machine violation */
502 AC_ERR_TIMEOUT = (1 << 2), /* timeout */
503 AC_ERR_MEDIA = (1 << 3), /* media error */
504 AC_ERR_ATA_BUS = (1 << 4), /* ATA bus error */
505 AC_ERR_HOST_BUS = (1 << 5), /* host bus error */
506 AC_ERR_SYSTEM = (1 << 6), /* system error */
507 AC_ERR_INVALID = (1 << 7), /* invalid argument */
508 AC_ERR_OTHER = (1 << 8), /* unknown */
509 AC_ERR_NODEV_HINT = (1 << 9), /* polling device detection hint */
510 AC_ERR_NCQ = (1 << 10), /* marker for offending NCQ qc */
511 };
512
513 /*
514 * Link power management policy: If you alter this, you also need to
515 * alter libata-sata.c (for the ascii descriptions)
516 */
517 enum ata_lpm_policy {
518 ATA_LPM_UNKNOWN,
519 ATA_LPM_MAX_POWER,
520 ATA_LPM_MED_POWER,
521 ATA_LPM_MED_POWER_WITH_DIPM, /* Med power + DIPM as win IRST does */
522 ATA_LPM_MIN_POWER_WITH_PARTIAL, /* Min Power + partial and slumber */
523 ATA_LPM_MIN_POWER, /* Min power + no partial (slumber only) */
524 };
525
526 enum ata_lpm_hints {
527 ATA_LPM_EMPTY = (1 << 0), /* port empty/probing */
528 ATA_LPM_HIPM = (1 << 1), /* may use HIPM */
529 ATA_LPM_WAKE_ONLY = (1 << 2), /* only wake up link */
530 };
531
532 /* forward declarations */
533 struct scsi_device;
534 struct ata_port_operations;
535 struct ata_port;
536 struct ata_link;
537 struct ata_queued_cmd;
538
539 /* typedefs */
540 typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
541 typedef int (*ata_prereset_fn_t)(struct ata_link *link, unsigned long deadline);
542 typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
543 unsigned long deadline);
544 typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
545
546 extern struct device_attribute dev_attr_unload_heads;
547 #ifdef CONFIG_SATA_HOST
548 extern struct device_attribute dev_attr_link_power_management_policy;
549 extern struct device_attribute dev_attr_ncq_prio_supported;
550 extern struct device_attribute dev_attr_ncq_prio_enable;
551 extern struct device_attribute dev_attr_em_message_type;
552 extern struct device_attribute dev_attr_em_message;
553 extern struct device_attribute dev_attr_sw_activity;
554 #endif
555
556 enum sw_activity {
557 OFF,
558 BLINK_ON,
559 BLINK_OFF,
560 };
561
562 struct ata_taskfile {
563 unsigned long flags; /* ATA_TFLAG_xxx */
564 u8 protocol; /* ATA_PROT_xxx */
565
566 u8 ctl; /* control reg */
567
568 u8 hob_feature; /* additional data */
569 u8 hob_nsect; /* to support LBA48 */
570 u8 hob_lbal;
571 u8 hob_lbam;
572 u8 hob_lbah;
573
574 union {
575 u8 error;
576 u8 feature;
577 };
578 u8 nsect;
579 u8 lbal;
580 u8 lbam;
581 u8 lbah;
582
583 u8 device;
584
585 union {
586 u8 status;
587 u8 command;
588 };
589
590 u32 auxiliary; /* auxiliary field */
591 /* from SATA 3.1 and */
592 /* ATA-8 ACS-3 */
593 };
594
595 #ifdef CONFIG_ATA_SFF
596 struct ata_ioports {
597 void __iomem *cmd_addr;
598 void __iomem *data_addr;
599 void __iomem *error_addr;
600 void __iomem *feature_addr;
601 void __iomem *nsect_addr;
602 void __iomem *lbal_addr;
603 void __iomem *lbam_addr;
604 void __iomem *lbah_addr;
605 void __iomem *device_addr;
606 void __iomem *status_addr;
607 void __iomem *command_addr;
608 void __iomem *altstatus_addr;
609 void __iomem *ctl_addr;
610 #ifdef CONFIG_ATA_BMDMA
611 void __iomem *bmdma_addr;
612 #endif /* CONFIG_ATA_BMDMA */
613 void __iomem *scr_addr;
614 };
615 #endif /* CONFIG_ATA_SFF */
616
617 struct ata_host {
618 spinlock_t lock;
619 struct device *dev;
620 void __iomem * const *iomap;
621 unsigned int n_ports;
622 unsigned int n_tags; /* nr of NCQ tags */
623 void *private_data;
624 struct ata_port_operations *ops;
625 unsigned long flags;
626 struct kref kref;
627
628 struct mutex eh_mutex;
629 struct task_struct *eh_owner;
630
631 struct ata_port *simplex_claimed; /* channel owning the DMA */
632 struct ata_port *ports[];
633 };
634
635 struct ata_queued_cmd {
636 struct ata_port *ap;
637 struct ata_device *dev;
638
639 struct scsi_cmnd *scsicmd;
640 void (*scsidone)(struct scsi_cmnd *);
641
642 struct ata_taskfile tf;
643 u8 cdb[ATAPI_CDB_LEN];
644
645 unsigned long flags; /* ATA_QCFLAG_xxx */
646 unsigned int tag; /* libata core tag */
647 unsigned int hw_tag; /* driver tag */
648 unsigned int n_elem;
649 unsigned int orig_n_elem;
650
651 int dma_dir;
652
653 unsigned int sect_size;
654
655 unsigned int nbytes;
656 unsigned int extrabytes;
657 unsigned int curbytes;
658
659 struct scatterlist sgent;
660
661 struct scatterlist *sg;
662
663 struct scatterlist *cursg;
664 unsigned int cursg_ofs;
665
666 unsigned int err_mask;
667 struct ata_taskfile result_tf;
668 ata_qc_cb_t complete_fn;
669
670 void *private_data;
671 void *lldd_task;
672 };
673
674 struct ata_port_stats {
675 unsigned long unhandled_irq;
676 unsigned long idle_irq;
677 unsigned long rw_reqbuf;
678 };
679
680 struct ata_ering_entry {
681 unsigned int eflags;
682 unsigned int err_mask;
683 u64 timestamp;
684 };
685
686 struct ata_ering {
687 int cursor;
688 struct ata_ering_entry ring[ATA_ERING_SIZE];
689 };
690
691 struct ata_cpr {
692 u8 num;
693 u8 num_storage_elements;
694 u64 start_lba;
695 u64 num_lbas;
696 };
697
698 struct ata_cpr_log {
699 u8 nr_cpr;
700 struct ata_cpr cpr[] __counted_by(nr_cpr);
701 };
702
703 struct ata_cdl {
704 /*
705 * Buffer to cache the CDL log page 18h (command duration descriptors)
706 * for SCSI-ATA translation.
707 */
708 u8 desc_log_buf[ATA_LOG_CDL_SIZE];
709
710 /*
711 * Buffer to handle reading the sense data for successful NCQ Commands
712 * log page for commands using a CDL with one of the limits policy set
713 * to 0xD (successful completion with sense data available bit set).
714 */
715 u8 ncq_sense_log_buf[ATA_LOG_SENSE_NCQ_SIZE];
716 };
717
718 struct ata_device {
719 struct ata_link *link;
720 unsigned int devno; /* 0 or 1 */
721 unsigned int quirks; /* List of broken features */
722 unsigned long flags; /* ATA_DFLAG_xxx */
723 struct scsi_device *sdev; /* attached SCSI device */
724 void *private_data;
725 #ifdef CONFIG_ATA_ACPI
726 union acpi_object *gtf_cache;
727 unsigned int gtf_filter;
728 #endif
729 #ifdef CONFIG_SATA_ZPODD
730 void *zpodd;
731 #endif
732 struct device tdev;
733 /* n_sector is CLEAR_BEGIN, read comment above CLEAR_BEGIN */
734 u64 n_sectors; /* size of device, if ATA */
735 u64 n_native_sectors; /* native size, if ATA */
736 unsigned int class; /* ATA_DEV_xxx */
737 unsigned long unpark_deadline;
738
739 u8 pio_mode;
740 u8 dma_mode;
741 u8 xfer_mode;
742 unsigned int xfer_shift; /* ATA_SHIFT_xxx */
743
744 unsigned int multi_count; /* sectors count for
745 READ/WRITE MULTIPLE */
746 unsigned int max_sectors; /* per-device max sectors */
747 unsigned int cdb_len;
748
749 /* per-dev xfer mask */
750 unsigned int pio_mask;
751 unsigned int mwdma_mask;
752 unsigned int udma_mask;
753
754 /* for CHS addressing */
755 u16 cylinders; /* Number of cylinders */
756 u16 heads; /* Number of heads */
757 u16 sectors; /* Number of sectors per track */
758
759 union {
760 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
761 u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
762 } ____cacheline_aligned;
763
764 /* DEVSLP Timing Variables from Identify Device Data Log */
765 u8 devslp_timing[ATA_LOG_DEVSLP_SIZE];
766
767 /* NCQ send and receive log subcommand support */
768 u8 ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_SIZE];
769 u8 ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_SIZE];
770
771 /* ZAC zone configuration */
772 u32 zac_zoned_cap;
773 u32 zac_zones_optimal_open;
774 u32 zac_zones_optimal_nonseq;
775 u32 zac_zones_max_open;
776
777 /* Concurrent positioning ranges */
778 struct ata_cpr_log *cpr_log;
779
780 /* Command Duration Limits support */
781 struct ata_cdl *cdl;
782
783 /* error history */
784 int spdn_cnt;
785 /* ering is CLEAR_END, read comment above CLEAR_END */
786 struct ata_ering ering;
787
788 /* For EH */
789 u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
790 };
791
792 /* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
793 * cleared to zero on ata_dev_init().
794 */
795 #define ATA_DEVICE_CLEAR_BEGIN offsetof(struct ata_device, n_sectors)
796 #define ATA_DEVICE_CLEAR_END offsetof(struct ata_device, ering)
797
798 struct ata_eh_info {
799 struct ata_device *dev; /* offending device */
800 u32 serror; /* SError from LLDD */
801 unsigned int err_mask; /* port-wide err_mask */
802 unsigned int action; /* ATA_EH_* action mask */
803 unsigned int dev_action[ATA_MAX_DEVICES]; /* dev EH action */
804 unsigned int flags; /* ATA_EHI_* flags */
805
806 unsigned int probe_mask;
807
808 char desc[ATA_EH_DESC_LEN];
809 int desc_len;
810 };
811
812 struct ata_eh_context {
813 struct ata_eh_info i;
814 int tries[ATA_MAX_DEVICES];
815 int cmd_timeout_idx[ATA_MAX_DEVICES]
816 [ATA_EH_CMD_TIMEOUT_TABLE_SIZE];
817 unsigned int classes[ATA_MAX_DEVICES];
818 unsigned int did_probe_mask;
819 unsigned int unloaded_mask;
820 unsigned int saved_ncq_enabled;
821 u8 saved_xfer_mode[ATA_MAX_DEVICES];
822 /* timestamp for the last reset attempt or success */
823 unsigned long last_reset;
824 };
825
826 struct ata_acpi_drive
827 {
828 u32 pio;
829 u32 dma;
830 } __packed;
831
832 struct ata_acpi_gtm {
833 struct ata_acpi_drive drive[2];
834 u32 flags;
835 } __packed;
836
837 struct ata_link {
838 struct ata_port *ap;
839 int pmp; /* port multiplier port # */
840
841 struct device tdev;
842 unsigned int active_tag; /* active tag on this link */
843 u32 sactive; /* active NCQ commands */
844
845 unsigned int flags; /* ATA_LFLAG_xxx */
846
847 u32 saved_scontrol; /* SControl on probe */
848 unsigned int hw_sata_spd_limit;
849 unsigned int sata_spd_limit;
850 unsigned int sata_spd; /* current SATA PHY speed */
851 enum ata_lpm_policy lpm_policy;
852
853 /* record runtime error info, protected by host_set lock */
854 struct ata_eh_info eh_info;
855 /* EH context */
856 struct ata_eh_context eh_context;
857
858 struct ata_device device[ATA_MAX_DEVICES];
859
860 unsigned long last_lpm_change; /* when last LPM change happened */
861 };
862 #define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
863 #define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
864
865 struct ata_port {
866 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
867 struct ata_port_operations *ops;
868 spinlock_t *lock;
869 /* Flags owned by the EH context. Only EH should touch these once the
870 port is active */
871 unsigned long flags; /* ATA_FLAG_xxx */
872 /* Flags that change dynamically, protected by ap->lock */
873 unsigned int pflags; /* ATA_PFLAG_xxx */
874 unsigned int print_id; /* user visible unique port ID */
875 unsigned int port_no; /* 0 based port no. inside the host */
876
877 #ifdef CONFIG_ATA_SFF
878 struct ata_ioports ioaddr; /* ATA cmd/ctl/dma register blocks */
879 u8 ctl; /* cache of ATA control register */
880 u8 last_ctl; /* Cache last written value */
881 struct ata_link* sff_pio_task_link; /* link currently used */
882 struct delayed_work sff_pio_task;
883 #ifdef CONFIG_ATA_BMDMA
884 struct ata_bmdma_prd *bmdma_prd; /* BMDMA SG list */
885 dma_addr_t bmdma_prd_dma; /* and its DMA mapping */
886 #endif /* CONFIG_ATA_BMDMA */
887 #endif /* CONFIG_ATA_SFF */
888
889 unsigned int pio_mask;
890 unsigned int mwdma_mask;
891 unsigned int udma_mask;
892 unsigned int cbl; /* cable type; ATA_CBL_xxx */
893
894 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE + 1];
895 u64 qc_active;
896 int nr_active_links; /* #links with active qcs */
897
898 struct ata_link link; /* host default link */
899 struct ata_link *slave_link; /* see ata_slave_link_init() */
900
901 int nr_pmp_links; /* nr of available PMP links */
902 struct ata_link *pmp_link; /* array of PMP links */
903 struct ata_link *excl_link; /* for PMP qc exclusion */
904
905 struct ata_port_stats stats;
906 struct ata_host *host;
907 struct device *dev;
908 struct device tdev;
909
910 struct mutex scsi_scan_mutex;
911 struct delayed_work hotplug_task;
912 struct delayed_work scsi_rescan_task;
913
914 unsigned int hsm_task_state;
915
916 struct list_head eh_done_q;
917 wait_queue_head_t eh_wait_q;
918 int eh_tries;
919 struct completion park_req_pending;
920
921 pm_message_t pm_mesg;
922 enum ata_lpm_policy target_lpm_policy;
923
924 struct timer_list fastdrain_timer;
925 unsigned int fastdrain_cnt;
926
927 async_cookie_t cookie;
928
929 int em_message_type;
930 void *private_data;
931
932 #ifdef CONFIG_ATA_ACPI
933 struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
934 #endif
935 };
936
937 /* The following initializer overrides a method to NULL whether one of
938 * its parent has the method defined or not. This is equivalent to
939 * ERR_PTR(-ENOENT). Unfortunately, ERR_PTR doesn't render a constant
940 * expression and thus can't be used as an initializer.
941 */
942 #define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
943
944 struct ata_port_operations {
945 /*
946 * Command execution
947 */
948 int (*qc_defer)(struct ata_queued_cmd *qc);
949 int (*check_atapi_dma)(struct ata_queued_cmd *qc);
950 enum ata_completion_errors (*qc_prep)(struct ata_queued_cmd *qc);
951 unsigned int (*qc_issue)(struct ata_queued_cmd *qc);
952 void (*qc_fill_rtf)(struct ata_queued_cmd *qc);
953 void (*qc_ncq_fill_rtf)(struct ata_port *ap, u64 done_mask);
954
955 /*
956 * Configuration and exception handling
957 */
958 int (*cable_detect)(struct ata_port *ap);
959 unsigned int (*mode_filter)(struct ata_device *dev, unsigned int xfer_mask);
960 void (*set_piomode)(struct ata_port *ap, struct ata_device *dev);
961 void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev);
962 int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev);
963 unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf,
964 __le16 *id);
965
966 void (*dev_config)(struct ata_device *dev);
967
968 void (*freeze)(struct ata_port *ap);
969 void (*thaw)(struct ata_port *ap);
970 ata_prereset_fn_t prereset;
971 ata_reset_fn_t softreset;
972 ata_reset_fn_t hardreset;
973 ata_postreset_fn_t postreset;
974 ata_prereset_fn_t pmp_prereset;
975 ata_reset_fn_t pmp_softreset;
976 ata_reset_fn_t pmp_hardreset;
977 ata_postreset_fn_t pmp_postreset;
978 void (*error_handler)(struct ata_port *ap);
979 void (*lost_interrupt)(struct ata_port *ap);
980 void (*post_internal_cmd)(struct ata_queued_cmd *qc);
981 void (*sched_eh)(struct ata_port *ap);
982 void (*end_eh)(struct ata_port *ap);
983
984 /*
985 * Optional features
986 */
987 int (*scr_read)(struct ata_link *link, unsigned int sc_reg, u32 *val);
988 int (*scr_write)(struct ata_link *link, unsigned int sc_reg, u32 val);
989 void (*pmp_attach)(struct ata_port *ap);
990 void (*pmp_detach)(struct ata_port *ap);
991 int (*set_lpm)(struct ata_link *link, enum ata_lpm_policy policy,
992 unsigned hints);
993
994 /*
995 * Start, stop, suspend and resume
996 */
997 int (*port_suspend)(struct ata_port *ap, pm_message_t mesg);
998 int (*port_resume)(struct ata_port *ap);
999 int (*port_start)(struct ata_port *ap);
1000 void (*port_stop)(struct ata_port *ap);
1001 void (*host_stop)(struct ata_host *host);
1002
1003 #ifdef CONFIG_ATA_SFF
1004 /*
1005 * SFF / taskfile oriented ops
1006 */
1007 void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
1008 void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
1009 u8 (*sff_check_status)(struct ata_port *ap);
1010 u8 (*sff_check_altstatus)(struct ata_port *ap);
1011 void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
1012 void (*sff_tf_read)(struct ata_port *ap, struct ata_taskfile *tf);
1013 void (*sff_exec_command)(struct ata_port *ap,
1014 const struct ata_taskfile *tf);
1015 unsigned int (*sff_data_xfer)(struct ata_queued_cmd *qc,
1016 unsigned char *buf, unsigned int buflen, int rw);
1017 void (*sff_irq_on)(struct ata_port *);
1018 bool (*sff_irq_check)(struct ata_port *);
1019 void (*sff_irq_clear)(struct ata_port *);
1020 void (*sff_drain_fifo)(struct ata_queued_cmd *qc);
1021
1022 #ifdef CONFIG_ATA_BMDMA
1023 void (*bmdma_setup)(struct ata_queued_cmd *qc);
1024 void (*bmdma_start)(struct ata_queued_cmd *qc);
1025 void (*bmdma_stop)(struct ata_queued_cmd *qc);
1026 u8 (*bmdma_status)(struct ata_port *ap);
1027 #endif /* CONFIG_ATA_BMDMA */
1028 #endif /* CONFIG_ATA_SFF */
1029
1030 ssize_t (*em_show)(struct ata_port *ap, char *buf);
1031 ssize_t (*em_store)(struct ata_port *ap, const char *message,
1032 size_t size);
1033 ssize_t (*sw_activity_show)(struct ata_device *dev, char *buf);
1034 ssize_t (*sw_activity_store)(struct ata_device *dev,
1035 enum sw_activity val);
1036 ssize_t (*transmit_led_message)(struct ata_port *ap, u32 state,
1037 ssize_t size);
1038
1039 /*
1040 * ->inherits must be the last field and all the preceding
1041 * fields must be pointers.
1042 */
1043 const struct ata_port_operations *inherits;
1044 };
1045
1046 struct ata_port_info {
1047 unsigned long flags;
1048 unsigned long link_flags;
1049 unsigned int pio_mask;
1050 unsigned int mwdma_mask;
1051 unsigned int udma_mask;
1052 struct ata_port_operations *port_ops;
1053 void *private_data;
1054 };
1055
1056 struct ata_timing {
1057 unsigned short mode; /* ATA mode */
1058 unsigned short setup; /* t1 */
1059 unsigned short act8b; /* t2 for 8-bit I/O */
1060 unsigned short rec8b; /* t2i for 8-bit I/O */
1061 unsigned short cyc8b; /* t0 for 8-bit I/O */
1062 unsigned short active; /* t2 or tD */
1063 unsigned short recover; /* t2i or tK */
1064 unsigned short dmack_hold; /* tj */
1065 unsigned short cycle; /* t0 */
1066 unsigned short udma; /* t2CYCTYP/2 */
1067 };
1068
1069 /*
1070 * Core layer - drivers/ata/libata-core.c
1071 */
1072 extern struct ata_port_operations ata_dummy_port_ops;
1073 extern const struct ata_port_info ata_dummy_port_info;
1074
ata_is_atapi(u8 prot)1075 static inline bool ata_is_atapi(u8 prot)
1076 {
1077 return prot & ATA_PROT_FLAG_ATAPI;
1078 }
1079
ata_is_pio(u8 prot)1080 static inline bool ata_is_pio(u8 prot)
1081 {
1082 return prot & ATA_PROT_FLAG_PIO;
1083 }
1084
ata_is_dma(u8 prot)1085 static inline bool ata_is_dma(u8 prot)
1086 {
1087 return prot & ATA_PROT_FLAG_DMA;
1088 }
1089
ata_is_ncq(u8 prot)1090 static inline bool ata_is_ncq(u8 prot)
1091 {
1092 return prot & ATA_PROT_FLAG_NCQ;
1093 }
1094
ata_is_data(u8 prot)1095 static inline bool ata_is_data(u8 prot)
1096 {
1097 return prot & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA);
1098 }
1099
is_multi_taskfile(struct ata_taskfile * tf)1100 static inline int is_multi_taskfile(struct ata_taskfile *tf)
1101 {
1102 return (tf->command == ATA_CMD_READ_MULTI) ||
1103 (tf->command == ATA_CMD_WRITE_MULTI) ||
1104 (tf->command == ATA_CMD_READ_MULTI_EXT) ||
1105 (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
1106 (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
1107 }
1108
ata_port_is_dummy(struct ata_port * ap)1109 static inline int ata_port_is_dummy(struct ata_port *ap)
1110 {
1111 return ap->ops == &ata_dummy_port_ops;
1112 }
1113
ata_port_is_frozen(const struct ata_port * ap)1114 static inline bool ata_port_is_frozen(const struct ata_port *ap)
1115 {
1116 return ap->pflags & ATA_PFLAG_FROZEN;
1117 }
1118
1119 extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
1120 extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
1121 int (*check_ready)(struct ata_link *link));
1122 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
1123
1124 extern struct ata_host *ata_host_alloc(struct device *dev, int n_ports);
1125 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
1126 const struct ata_port_info * const * ppi, int n_ports);
1127 extern void ata_host_get(struct ata_host *host);
1128 extern void ata_host_put(struct ata_host *host);
1129 extern int ata_host_start(struct ata_host *host);
1130 extern int ata_host_register(struct ata_host *host,
1131 const struct scsi_host_template *sht);
1132 extern int ata_host_activate(struct ata_host *host, int irq,
1133 irq_handler_t irq_handler, unsigned long irq_flags,
1134 const struct scsi_host_template *sht);
1135 extern void ata_host_detach(struct ata_host *host);
1136 extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
1137 extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
1138 void __user *arg);
1139 #ifdef CONFIG_COMPAT
1140 #define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
1141 #else
1142 #define ATA_SCSI_COMPAT_IOCTL /* empty */
1143 #endif
1144 extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
1145 #if IS_REACHABLE(CONFIG_ATA)
1146 bool ata_scsi_dma_need_drain(struct request *rq);
1147 #else
1148 #define ata_scsi_dma_need_drain NULL
1149 #endif
1150 extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
1151 unsigned int cmd, void __user *arg);
1152 extern bool ata_link_online(struct ata_link *link);
1153 extern bool ata_link_offline(struct ata_link *link);
1154 #ifdef CONFIG_PM
1155 extern void ata_host_suspend(struct ata_host *host, pm_message_t mesg);
1156 extern void ata_host_resume(struct ata_host *host);
1157 extern void ata_sas_port_suspend(struct ata_port *ap);
1158 extern void ata_sas_port_resume(struct ata_port *ap);
1159 #else
ata_sas_port_suspend(struct ata_port * ap)1160 static inline void ata_sas_port_suspend(struct ata_port *ap)
1161 {
1162 }
ata_sas_port_resume(struct ata_port * ap)1163 static inline void ata_sas_port_resume(struct ata_port *ap)
1164 {
1165 }
1166 #endif
1167 extern int ata_ratelimit(void);
1168 extern void ata_msleep(struct ata_port *ap, unsigned int msecs);
1169 extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
1170 u32 val, unsigned int interval, unsigned int timeout);
1171 extern int atapi_cmd_type(u8 opcode);
1172 extern unsigned int ata_pack_xfermask(unsigned int pio_mask,
1173 unsigned int mwdma_mask,
1174 unsigned int udma_mask);
1175 extern void ata_unpack_xfermask(unsigned int xfer_mask,
1176 unsigned int *pio_mask,
1177 unsigned int *mwdma_mask,
1178 unsigned int *udma_mask);
1179 extern u8 ata_xfer_mask2mode(unsigned int xfer_mask);
1180 extern unsigned int ata_xfer_mode2mask(u8 xfer_mode);
1181 extern int ata_xfer_mode2shift(u8 xfer_mode);
1182 extern const char *ata_mode_string(unsigned int xfer_mask);
1183 extern unsigned int ata_id_xfermask(const u16 *id);
1184 extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
1185 extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
1186 unsigned int n_elem);
1187 extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
1188 extern unsigned int ata_port_classify(struct ata_port *ap,
1189 const struct ata_taskfile *tf);
1190 extern void ata_dev_disable(struct ata_device *adev);
1191 extern void ata_id_string(const u16 *id, unsigned char *s,
1192 unsigned int ofs, unsigned int len);
1193 extern void ata_id_c_string(const u16 *id, unsigned char *s,
1194 unsigned int ofs, unsigned int len);
1195 extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
1196 struct ata_taskfile *tf, __le16 *id);
1197 extern void ata_qc_complete(struct ata_queued_cmd *qc);
1198 extern u64 ata_qc_get_active(struct ata_port *ap);
1199 extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
1200 extern int ata_std_bios_param(struct scsi_device *sdev,
1201 struct block_device *bdev,
1202 sector_t capacity, int geom[]);
1203 extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
1204 extern int ata_scsi_sdev_init(struct scsi_device *sdev);
1205 int ata_scsi_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim);
1206 extern void ata_scsi_sdev_destroy(struct scsi_device *sdev);
1207 extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
1208 int queue_depth);
1209 extern int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1210 int queue_depth);
1211 extern int ata_ncq_prio_supported(struct ata_port *ap, struct scsi_device *sdev,
1212 bool *supported);
1213 extern int ata_ncq_prio_enabled(struct ata_port *ap, struct scsi_device *sdev,
1214 bool *enabled);
1215 extern int ata_ncq_prio_enable(struct ata_port *ap, struct scsi_device *sdev,
1216 bool enable);
1217 extern struct ata_device *ata_dev_pair(struct ata_device *adev);
1218 extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
1219 extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
1220 extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
1221
1222 /*
1223 * SATA specific code - drivers/ata/libata-sata.c
1224 */
1225 #ifdef CONFIG_SATA_HOST
1226 extern const unsigned int sata_deb_timing_normal[];
1227 extern const unsigned int sata_deb_timing_hotplug[];
1228 extern const unsigned int sata_deb_timing_long[];
1229
1230 static inline const unsigned int *
sata_ehc_deb_timing(struct ata_eh_context * ehc)1231 sata_ehc_deb_timing(struct ata_eh_context *ehc)
1232 {
1233 if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
1234 return sata_deb_timing_hotplug;
1235 else
1236 return sata_deb_timing_normal;
1237 }
1238
1239 extern int sata_scr_valid(struct ata_link *link);
1240 extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
1241 extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
1242 extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
1243 extern int sata_set_spd(struct ata_link *link);
1244 int sata_std_hardreset(struct ata_link *link, unsigned int *class,
1245 unsigned long deadline);
1246 extern int sata_link_hardreset(struct ata_link *link,
1247 const unsigned int *timing, unsigned long deadline,
1248 bool *online, int (*check_ready)(struct ata_link *));
1249 extern int sata_link_resume(struct ata_link *link, const unsigned int *params,
1250 unsigned long deadline);
1251 extern void ata_eh_analyze_ncq_error(struct ata_link *link);
1252 #else
1253 static inline const unsigned int *
sata_ehc_deb_timing(struct ata_eh_context * ehc)1254 sata_ehc_deb_timing(struct ata_eh_context *ehc)
1255 {
1256 return NULL;
1257 }
sata_scr_valid(struct ata_link * link)1258 static inline int sata_scr_valid(struct ata_link *link) { return 0; }
sata_scr_read(struct ata_link * link,int reg,u32 * val)1259 static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
1260 {
1261 return -EOPNOTSUPP;
1262 }
sata_scr_write(struct ata_link * link,int reg,u32 val)1263 static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
1264 {
1265 return -EOPNOTSUPP;
1266 }
sata_scr_write_flush(struct ata_link * link,int reg,u32 val)1267 static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
1268 {
1269 return -EOPNOTSUPP;
1270 }
sata_set_spd(struct ata_link * link)1271 static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
sata_std_hardreset(struct ata_link * link,unsigned int * class,unsigned long deadline)1272 static inline int sata_std_hardreset(struct ata_link *link, unsigned int *class,
1273 unsigned long deadline)
1274 {
1275 return -EOPNOTSUPP;
1276 }
sata_link_hardreset(struct ata_link * link,const unsigned int * timing,unsigned long deadline,bool * online,int (* check_ready)(struct ata_link *))1277 static inline int sata_link_hardreset(struct ata_link *link,
1278 const unsigned int *timing,
1279 unsigned long deadline,
1280 bool *online,
1281 int (*check_ready)(struct ata_link *))
1282 {
1283 if (online)
1284 *online = false;
1285 return -EOPNOTSUPP;
1286 }
sata_link_resume(struct ata_link * link,const unsigned int * params,unsigned long deadline)1287 static inline int sata_link_resume(struct ata_link *link,
1288 const unsigned int *params,
1289 unsigned long deadline)
1290 {
1291 return -EOPNOTSUPP;
1292 }
ata_eh_analyze_ncq_error(struct ata_link * link)1293 static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
1294 #endif
1295 extern int sata_link_debounce(struct ata_link *link,
1296 const unsigned int *params, unsigned long deadline);
1297 extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
1298 bool spm_wakeup);
1299 extern int ata_slave_link_init(struct ata_port *ap);
1300 extern void ata_port_probe(struct ata_port *ap);
1301 extern struct ata_port *ata_port_alloc(struct ata_host *host);
1302 extern void ata_port_free(struct ata_port *ap);
1303 extern int ata_tport_add(struct device *parent, struct ata_port *ap);
1304 extern void ata_tport_delete(struct ata_port *ap);
1305 int ata_sas_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim,
1306 struct ata_port *ap);
1307 extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
1308 extern void ata_tf_to_fis(const struct ata_taskfile *tf,
1309 u8 pmp, int is_cmd, u8 *fis);
1310 extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
1311 extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
1312 extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
1313 extern int sata_async_notification(struct ata_port *ap);
1314
1315 extern int ata_cable_40wire(struct ata_port *ap);
1316 extern int ata_cable_80wire(struct ata_port *ap);
1317 extern int ata_cable_sata(struct ata_port *ap);
1318 extern int ata_cable_ignore(struct ata_port *ap);
1319 extern int ata_cable_unknown(struct ata_port *ap);
1320
1321 /* Timing helpers */
1322 extern unsigned int ata_pio_need_iordy(const struct ata_device *);
1323 extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
1324
1325 /* PCI */
1326 #ifdef CONFIG_PCI
1327 struct pci_dev;
1328
1329 struct pci_bits {
1330 unsigned int reg; /* PCI config register to read */
1331 unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
1332 unsigned long mask;
1333 unsigned long val;
1334 };
1335
1336 extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
1337 extern void ata_pci_shutdown_one(struct pci_dev *pdev);
1338 extern void ata_pci_remove_one(struct pci_dev *pdev);
1339
1340 #ifdef CONFIG_PM
1341 extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
1342 extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
1343 extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
1344 extern int ata_pci_device_resume(struct pci_dev *pdev);
1345 #endif /* CONFIG_PM */
1346 #endif /* CONFIG_PCI */
1347
1348 struct platform_device;
1349
1350 extern void ata_platform_remove_one(struct platform_device *pdev);
1351
1352 /*
1353 * ACPI - drivers/ata/libata-acpi.c
1354 */
1355 #ifdef CONFIG_ATA_ACPI
ata_acpi_init_gtm(struct ata_port * ap)1356 static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1357 {
1358 if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID)
1359 return &ap->__acpi_init_gtm;
1360 return NULL;
1361 }
1362 int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
1363 int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
1364 unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
1365 const struct ata_acpi_gtm *gtm);
1366 int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
1367 #else
ata_acpi_init_gtm(struct ata_port * ap)1368 static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
1369 {
1370 return NULL;
1371 }
1372
ata_acpi_stm(const struct ata_port * ap,struct ata_acpi_gtm * stm)1373 static inline int ata_acpi_stm(const struct ata_port *ap,
1374 struct ata_acpi_gtm *stm)
1375 {
1376 return -ENOSYS;
1377 }
1378
ata_acpi_gtm(const struct ata_port * ap,struct ata_acpi_gtm * stm)1379 static inline int ata_acpi_gtm(const struct ata_port *ap,
1380 struct ata_acpi_gtm *stm)
1381 {
1382 return -ENOSYS;
1383 }
1384
ata_acpi_gtm_xfermask(struct ata_device * dev,const struct ata_acpi_gtm * gtm)1385 static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
1386 const struct ata_acpi_gtm *gtm)
1387 {
1388 return 0;
1389 }
1390
ata_acpi_cbl_80wire(struct ata_port * ap,const struct ata_acpi_gtm * gtm)1391 static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
1392 const struct ata_acpi_gtm *gtm)
1393 {
1394 return 0;
1395 }
1396 #endif
1397
1398 /*
1399 * EH - drivers/ata/libata-eh.c
1400 */
1401 extern void ata_port_schedule_eh(struct ata_port *ap);
1402 extern void ata_port_wait_eh(struct ata_port *ap);
1403 extern int ata_link_abort(struct ata_link *link);
1404 extern int ata_port_abort(struct ata_port *ap);
1405 extern int ata_port_freeze(struct ata_port *ap);
1406
1407 extern void ata_eh_freeze_port(struct ata_port *ap);
1408 extern void ata_eh_thaw_port(struct ata_port *ap);
1409
1410 extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
1411 extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
1412
1413 extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
1414 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1415 ata_postreset_fn_t postreset);
1416 extern void ata_std_error_handler(struct ata_port *ap);
1417 extern void ata_std_sched_eh(struct ata_port *ap);
1418 extern void ata_std_end_eh(struct ata_port *ap);
1419 extern int ata_link_nr_enabled(struct ata_link *link);
1420
1421 /*
1422 * Base operations to inherit from and initializers for sht
1423 *
1424 * Operations
1425 *
1426 * base : Common to all libata drivers.
1427 * sata : SATA controllers w/ native interface.
1428 * pmp : SATA controllers w/ PMP support.
1429 * sff : SFF ATA controllers w/o BMDMA support.
1430 * bmdma : SFF ATA controllers w/ BMDMA support.
1431 *
1432 * sht initializers
1433 *
1434 * BASE : Common to all libata drivers. The user must set
1435 * sg_tablesize and dma_boundary.
1436 * PIO : SFF ATA controllers w/ only PIO support.
1437 * BMDMA : SFF ATA controllers w/ BMDMA support. sg_tablesize and
1438 * dma_boundary are set to BMDMA limits.
1439 * NCQ : SATA controllers supporting NCQ. The user must set
1440 * sg_tablesize, dma_boundary and can_queue.
1441 */
1442 extern const struct ata_port_operations ata_base_port_ops;
1443 extern const struct ata_port_operations sata_port_ops;
1444 extern const struct attribute_group *ata_common_sdev_groups[];
1445
1446 /*
1447 * All sht initializers (BASE, PIO, BMDMA, NCQ) must be instantiated
1448 * by the edge drivers. Because the 'module' field of sht must be the
1449 * edge driver's module reference, otherwise the driver can be unloaded
1450 * even if the scsi_device is being accessed.
1451 */
1452 #define __ATA_BASE_SHT(drv_name) \
1453 .module = THIS_MODULE, \
1454 .name = drv_name, \
1455 .ioctl = ata_scsi_ioctl, \
1456 ATA_SCSI_COMPAT_IOCTL \
1457 .queuecommand = ata_scsi_queuecmd, \
1458 .dma_need_drain = ata_scsi_dma_need_drain, \
1459 .this_id = ATA_SHT_THIS_ID, \
1460 .emulated = ATA_SHT_EMULATED, \
1461 .proc_name = drv_name, \
1462 .sdev_init = ata_scsi_sdev_init, \
1463 .sdev_destroy = ata_scsi_sdev_destroy, \
1464 .bios_param = ata_std_bios_param, \
1465 .unlock_native_capacity = ata_scsi_unlock_native_capacity,\
1466 .max_sectors = ATA_MAX_SECTORS_LBA48
1467
1468 #define ATA_SUBBASE_SHT(drv_name) \
1469 __ATA_BASE_SHT(drv_name), \
1470 .can_queue = ATA_DEF_QUEUE, \
1471 .tag_alloc_policy_rr = true, \
1472 .sdev_configure = ata_scsi_sdev_configure
1473
1474 #define ATA_SUBBASE_SHT_QD(drv_name, drv_qd) \
1475 __ATA_BASE_SHT(drv_name), \
1476 .can_queue = drv_qd, \
1477 .tag_alloc_policy_rr = true, \
1478 .sdev_configure = ata_scsi_sdev_configure
1479
1480 #define ATA_BASE_SHT(drv_name) \
1481 ATA_SUBBASE_SHT(drv_name), \
1482 .sdev_groups = ata_common_sdev_groups
1483
1484 #ifdef CONFIG_SATA_HOST
1485 extern const struct attribute_group *ata_ncq_sdev_groups[];
1486
1487 #define ATA_NCQ_SHT(drv_name) \
1488 ATA_SUBBASE_SHT(drv_name), \
1489 .sdev_groups = ata_ncq_sdev_groups, \
1490 .change_queue_depth = ata_scsi_change_queue_depth
1491
1492 #define ATA_NCQ_SHT_QD(drv_name, drv_qd) \
1493 ATA_SUBBASE_SHT_QD(drv_name, drv_qd), \
1494 .sdev_groups = ata_ncq_sdev_groups, \
1495 .change_queue_depth = ata_scsi_change_queue_depth
1496 #endif
1497
1498 /*
1499 * PMP helpers
1500 */
1501 #ifdef CONFIG_SATA_PMP
sata_pmp_supported(struct ata_port * ap)1502 static inline bool sata_pmp_supported(struct ata_port *ap)
1503 {
1504 return ap->flags & ATA_FLAG_PMP;
1505 }
1506
sata_pmp_attached(struct ata_port * ap)1507 static inline bool sata_pmp_attached(struct ata_port *ap)
1508 {
1509 return ap->nr_pmp_links != 0;
1510 }
1511
ata_is_host_link(const struct ata_link * link)1512 static inline bool ata_is_host_link(const struct ata_link *link)
1513 {
1514 return link == &link->ap->link || link == link->ap->slave_link;
1515 }
1516 #else /* CONFIG_SATA_PMP */
sata_pmp_supported(struct ata_port * ap)1517 static inline bool sata_pmp_supported(struct ata_port *ap)
1518 {
1519 return false;
1520 }
1521
sata_pmp_attached(struct ata_port * ap)1522 static inline bool sata_pmp_attached(struct ata_port *ap)
1523 {
1524 return false;
1525 }
1526
ata_is_host_link(const struct ata_link * link)1527 static inline bool ata_is_host_link(const struct ata_link *link)
1528 {
1529 return true;
1530 }
1531 #endif /* CONFIG_SATA_PMP */
1532
sata_srst_pmp(struct ata_link * link)1533 static inline int sata_srst_pmp(struct ata_link *link)
1534 {
1535 if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
1536 return SATA_PMP_CTRL_PORT;
1537 return link->pmp;
1538 }
1539
1540 #define ata_port_printk(level, ap, fmt, ...) \
1541 pr_ ## level ("ata%u: " fmt, (ap)->print_id, ##__VA_ARGS__)
1542
1543 #define ata_port_err(ap, fmt, ...) \
1544 ata_port_printk(err, ap, fmt, ##__VA_ARGS__)
1545 #define ata_port_warn(ap, fmt, ...) \
1546 ata_port_printk(warn, ap, fmt, ##__VA_ARGS__)
1547 #define ata_port_notice(ap, fmt, ...) \
1548 ata_port_printk(notice, ap, fmt, ##__VA_ARGS__)
1549 #define ata_port_info(ap, fmt, ...) \
1550 ata_port_printk(info, ap, fmt, ##__VA_ARGS__)
1551 #define ata_port_dbg(ap, fmt, ...) \
1552 ata_port_printk(debug, ap, fmt, ##__VA_ARGS__)
1553
1554 #define ata_link_printk(level, link, fmt, ...) \
1555 do { \
1556 if (sata_pmp_attached((link)->ap) || \
1557 (link)->ap->slave_link) \
1558 pr_ ## level ("ata%u.%02u: " fmt, \
1559 (link)->ap->print_id, \
1560 (link)->pmp, \
1561 ##__VA_ARGS__); \
1562 else \
1563 pr_ ## level ("ata%u: " fmt, \
1564 (link)->ap->print_id, \
1565 ##__VA_ARGS__); \
1566 } while (0)
1567
1568 #define ata_link_err(link, fmt, ...) \
1569 ata_link_printk(err, link, fmt, ##__VA_ARGS__)
1570 #define ata_link_warn(link, fmt, ...) \
1571 ata_link_printk(warn, link, fmt, ##__VA_ARGS__)
1572 #define ata_link_notice(link, fmt, ...) \
1573 ata_link_printk(notice, link, fmt, ##__VA_ARGS__)
1574 #define ata_link_info(link, fmt, ...) \
1575 ata_link_printk(info, link, fmt, ##__VA_ARGS__)
1576 #define ata_link_dbg(link, fmt, ...) \
1577 ata_link_printk(debug, link, fmt, ##__VA_ARGS__)
1578
1579 #define ata_dev_printk(level, dev, fmt, ...) \
1580 pr_ ## level("ata%u.%02u: " fmt, \
1581 (dev)->link->ap->print_id, \
1582 (dev)->link->pmp + (dev)->devno, \
1583 ##__VA_ARGS__)
1584
1585 #define ata_dev_err(dev, fmt, ...) \
1586 ata_dev_printk(err, dev, fmt, ##__VA_ARGS__)
1587 #define ata_dev_warn(dev, fmt, ...) \
1588 ata_dev_printk(warn, dev, fmt, ##__VA_ARGS__)
1589 #define ata_dev_notice(dev, fmt, ...) \
1590 ata_dev_printk(notice, dev, fmt, ##__VA_ARGS__)
1591 #define ata_dev_info(dev, fmt, ...) \
1592 ata_dev_printk(info, dev, fmt, ##__VA_ARGS__)
1593 #define ata_dev_dbg(dev, fmt, ...) \
1594 ata_dev_printk(debug, dev, fmt, ##__VA_ARGS__)
1595
1596 void ata_print_version(const struct device *dev, const char *version);
1597
1598 /*
1599 * ata_eh_info helpers
1600 */
1601 extern __printf(2, 3)
1602 void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1603 extern __printf(2, 3)
1604 void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
1605 extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
1606
ata_ehi_hotplugged(struct ata_eh_info * ehi)1607 static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
1608 {
1609 ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
1610 ehi->flags |= ATA_EHI_HOTPLUGGED;
1611 ehi->action |= ATA_EH_RESET | ATA_EH_ENABLE_LINK;
1612 ehi->err_mask |= AC_ERR_ATA_BUS;
1613 }
1614
1615 /*
1616 * port description helpers
1617 */
1618 extern __printf(2, 3)
1619 void ata_port_desc(struct ata_port *ap, const char *fmt, ...);
1620 #ifdef CONFIG_PCI
1621 extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
1622 const char *name);
1623 #endif
ata_port_desc_misc(struct ata_port * ap,int irq)1624 static inline void ata_port_desc_misc(struct ata_port *ap, int irq)
1625 {
1626 ata_port_desc(ap, "irq %d", irq);
1627 ata_port_desc(ap, "lpm-pol %d", ap->target_lpm_policy);
1628 }
1629
ata_tag_internal(unsigned int tag)1630 static inline bool ata_tag_internal(unsigned int tag)
1631 {
1632 return tag == ATA_TAG_INTERNAL;
1633 }
1634
ata_tag_valid(unsigned int tag)1635 static inline bool ata_tag_valid(unsigned int tag)
1636 {
1637 return tag < ATA_MAX_QUEUE || ata_tag_internal(tag);
1638 }
1639
1640 #define __ata_qc_for_each(ap, qc, tag, max_tag, fn) \
1641 for ((tag) = 0; (tag) < (max_tag) && \
1642 ({ qc = fn((ap), (tag)); 1; }); (tag)++) \
1643
1644 /*
1645 * Internal use only, iterate commands ignoring error handling and
1646 * status of 'qc'.
1647 */
1648 #define ata_qc_for_each_raw(ap, qc, tag) \
1649 __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, __ata_qc_from_tag)
1650
1651 /*
1652 * Iterate all potential commands that can be queued
1653 */
1654 #define ata_qc_for_each(ap, qc, tag) \
1655 __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, ata_qc_from_tag)
1656
1657 /*
1658 * Like ata_qc_for_each, but with the internal tag included
1659 */
1660 #define ata_qc_for_each_with_internal(ap, qc, tag) \
1661 __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE + 1, ata_qc_from_tag)
1662
1663 /*
1664 * device helpers
1665 */
ata_class_enabled(unsigned int class)1666 static inline unsigned int ata_class_enabled(unsigned int class)
1667 {
1668 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI ||
1669 class == ATA_DEV_PMP || class == ATA_DEV_SEMB ||
1670 class == ATA_DEV_ZAC;
1671 }
1672
ata_class_disabled(unsigned int class)1673 static inline unsigned int ata_class_disabled(unsigned int class)
1674 {
1675 return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP ||
1676 class == ATA_DEV_PMP_UNSUP || class == ATA_DEV_SEMB_UNSUP ||
1677 class == ATA_DEV_ZAC_UNSUP;
1678 }
1679
ata_class_absent(unsigned int class)1680 static inline unsigned int ata_class_absent(unsigned int class)
1681 {
1682 return !ata_class_enabled(class) && !ata_class_disabled(class);
1683 }
1684
ata_dev_enabled(const struct ata_device * dev)1685 static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
1686 {
1687 return ata_class_enabled(dev->class);
1688 }
1689
ata_dev_disabled(const struct ata_device * dev)1690 static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
1691 {
1692 return ata_class_disabled(dev->class);
1693 }
1694
ata_dev_absent(const struct ata_device * dev)1695 static inline unsigned int ata_dev_absent(const struct ata_device *dev)
1696 {
1697 return ata_class_absent(dev->class);
1698 }
1699
1700 /*
1701 * link helpers
1702 */
ata_link_max_devices(const struct ata_link * link)1703 static inline int ata_link_max_devices(const struct ata_link *link)
1704 {
1705 if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
1706 return 2;
1707 return 1;
1708 }
1709
ata_link_active(struct ata_link * link)1710 static inline int ata_link_active(struct ata_link *link)
1711 {
1712 return ata_tag_valid(link->active_tag) || link->sactive;
1713 }
1714
1715 /*
1716 * Iterators
1717 *
1718 * ATA_LITER_* constants are used to select link iteration mode and
1719 * ATA_DITER_* device iteration mode.
1720 *
1721 * For a custom iteration directly using ata_{link|dev}_next(), if
1722 * @link or @dev, respectively, is NULL, the first element is
1723 * returned. @dev and @link can be any valid device or link and the
1724 * next element according to the iteration mode will be returned.
1725 * After the last element, NULL is returned.
1726 */
1727 enum ata_link_iter_mode {
1728 ATA_LITER_EDGE, /* if present, PMP links only; otherwise,
1729 * host link. no slave link */
1730 ATA_LITER_HOST_FIRST, /* host link followed by PMP or slave links */
1731 ATA_LITER_PMP_FIRST, /* PMP links followed by host link,
1732 * slave link still comes after host link */
1733 };
1734
1735 enum ata_dev_iter_mode {
1736 ATA_DITER_ENABLED,
1737 ATA_DITER_ENABLED_REVERSE,
1738 ATA_DITER_ALL,
1739 ATA_DITER_ALL_REVERSE,
1740 };
1741
1742 extern struct ata_link *ata_link_next(struct ata_link *link,
1743 struct ata_port *ap,
1744 enum ata_link_iter_mode mode);
1745
1746 extern struct ata_device *ata_dev_next(struct ata_device *dev,
1747 struct ata_link *link,
1748 enum ata_dev_iter_mode mode);
1749
1750 /*
1751 * Shortcut notation for iterations
1752 *
1753 * ata_for_each_link() iterates over each link of @ap according to
1754 * @mode. @link points to the current link in the loop. @link is
1755 * NULL after loop termination. ata_for_each_dev() works the same way
1756 * except that it iterates over each device of @link.
1757 *
1758 * Note that the mode prefixes ATA_{L|D}ITER_ shouldn't need to be
1759 * specified when using the following shorthand notations. Only the
1760 * mode itself (EDGE, HOST_FIRST, ENABLED, etc...) should be
1761 * specified. This not only increases brevity but also makes it
1762 * impossible to use ATA_LITER_* for device iteration or vice-versa.
1763 */
1764 #define ata_for_each_link(link, ap, mode) \
1765 for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
1766 (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
1767
1768 #define ata_for_each_dev(dev, link, mode) \
1769 for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
1770 (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
1771
1772 /**
1773 * ata_ncq_supported - Test whether NCQ is supported
1774 * @dev: ATA device to test
1775 *
1776 * LOCKING:
1777 * spin_lock_irqsave(host lock)
1778 *
1779 * RETURNS:
1780 * true if @dev supports NCQ, false otherwise.
1781 */
ata_ncq_supported(struct ata_device * dev)1782 static inline bool ata_ncq_supported(struct ata_device *dev)
1783 {
1784 if (!IS_ENABLED(CONFIG_SATA_HOST))
1785 return false;
1786 return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
1787 }
1788
1789 /**
1790 * ata_ncq_enabled - Test whether NCQ is enabled
1791 * @dev: ATA device to test
1792 *
1793 * LOCKING:
1794 * spin_lock_irqsave(host lock)
1795 *
1796 * RETURNS:
1797 * true if NCQ is enabled for @dev, false otherwise.
1798 */
ata_ncq_enabled(struct ata_device * dev)1799 static inline bool ata_ncq_enabled(struct ata_device *dev)
1800 {
1801 return ata_ncq_supported(dev) && !(dev->flags & ATA_DFLAG_NCQ_OFF);
1802 }
1803
ata_fpdma_dsm_supported(struct ata_device * dev)1804 static inline bool ata_fpdma_dsm_supported(struct ata_device *dev)
1805 {
1806 return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1807 (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &
1808 ATA_LOG_NCQ_SEND_RECV_DSM_TRIM);
1809 }
1810
ata_fpdma_read_log_supported(struct ata_device * dev)1811 static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
1812 {
1813 return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1814 (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &
1815 ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
1816 }
1817
ata_fpdma_zac_mgmt_in_supported(struct ata_device * dev)1818 static inline bool ata_fpdma_zac_mgmt_in_supported(struct ata_device *dev)
1819 {
1820 return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
1821 (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET] &
1822 ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED);
1823 }
1824
ata_fpdma_zac_mgmt_out_supported(struct ata_device * dev)1825 static inline bool ata_fpdma_zac_mgmt_out_supported(struct ata_device *dev)
1826 {
1827 return (dev->ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OFFSET] &
1828 ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OUT);
1829 }
1830
ata_qc_set_polling(struct ata_queued_cmd * qc)1831 static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
1832 {
1833 qc->tf.ctl |= ATA_NIEN;
1834 }
1835
__ata_qc_from_tag(struct ata_port * ap,unsigned int tag)1836 static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
1837 unsigned int tag)
1838 {
1839 if (ata_tag_valid(tag))
1840 return &ap->qcmd[tag];
1841 return NULL;
1842 }
1843
ata_qc_from_tag(struct ata_port * ap,unsigned int tag)1844 static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
1845 unsigned int tag)
1846 {
1847 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1848
1849 if (unlikely(!qc))
1850 return qc;
1851
1852 if ((qc->flags & (ATA_QCFLAG_ACTIVE |
1853 ATA_QCFLAG_EH)) == ATA_QCFLAG_ACTIVE)
1854 return qc;
1855
1856 return NULL;
1857 }
1858
ata_qc_raw_nbytes(struct ata_queued_cmd * qc)1859 static inline unsigned int ata_qc_raw_nbytes(struct ata_queued_cmd *qc)
1860 {
1861 return qc->nbytes - min(qc->extrabytes, qc->nbytes);
1862 }
1863
ata_tf_init(struct ata_device * dev,struct ata_taskfile * tf)1864 static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
1865 {
1866 memset(tf, 0, sizeof(*tf));
1867
1868 #ifdef CONFIG_ATA_SFF
1869 tf->ctl = dev->link->ap->ctl;
1870 #else
1871 tf->ctl = ATA_DEVCTL_OBS;
1872 #endif
1873 if (dev->devno == 0)
1874 tf->device = ATA_DEVICE_OBS;
1875 else
1876 tf->device = ATA_DEVICE_OBS | ATA_DEV1;
1877 }
1878
ata_qc_reinit(struct ata_queued_cmd * qc)1879 static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
1880 {
1881 qc->dma_dir = DMA_NONE;
1882 qc->sg = NULL;
1883 qc->flags = 0;
1884 qc->cursg = NULL;
1885 qc->cursg_ofs = 0;
1886 qc->nbytes = qc->extrabytes = qc->curbytes = 0;
1887 qc->n_elem = 0;
1888 qc->err_mask = 0;
1889 qc->sect_size = ATA_SECT_SIZE;
1890
1891 ata_tf_init(qc->dev, &qc->tf);
1892
1893 /* init result_tf such that it indicates normal completion */
1894 qc->result_tf.command = ATA_DRDY;
1895 qc->result_tf.feature = 0;
1896 }
1897
ata_try_flush_cache(const struct ata_device * dev)1898 static inline int ata_try_flush_cache(const struct ata_device *dev)
1899 {
1900 return ata_id_wcache_enabled(dev->id) ||
1901 ata_id_has_flush(dev->id) ||
1902 ata_id_has_flush_ext(dev->id);
1903 }
1904
ac_err_mask(u8 status)1905 static inline unsigned int ac_err_mask(u8 status)
1906 {
1907 if (status & (ATA_BUSY | ATA_DRQ))
1908 return AC_ERR_HSM;
1909 if (status & (ATA_ERR | ATA_DF))
1910 return AC_ERR_DEV;
1911 return 0;
1912 }
1913
__ac_err_mask(u8 status)1914 static inline unsigned int __ac_err_mask(u8 status)
1915 {
1916 unsigned int mask = ac_err_mask(status);
1917 if (mask == 0)
1918 return AC_ERR_OTHER;
1919 return mask;
1920 }
1921
ata_shost_to_port(struct Scsi_Host * host)1922 static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
1923 {
1924 return *(struct ata_port **)&host->hostdata[0];
1925 }
1926
ata_check_ready(u8 status)1927 static inline int ata_check_ready(u8 status)
1928 {
1929 if (!(status & ATA_BUSY))
1930 return 1;
1931
1932 /* 0xff indicates either no device or device not ready */
1933 if (status == 0xff)
1934 return -ENODEV;
1935
1936 return 0;
1937 }
1938
ata_deadline(unsigned long from_jiffies,unsigned int timeout_msecs)1939 static inline unsigned long ata_deadline(unsigned long from_jiffies,
1940 unsigned int timeout_msecs)
1941 {
1942 return from_jiffies + msecs_to_jiffies(timeout_msecs);
1943 }
1944
1945 /* Don't open code these in drivers as there are traps. Firstly the range may
1946 change in future hardware and specs, secondly 0xFF means 'no DMA' but is
1947 > UDMA_0. Dyma ddreigiau */
1948
ata_using_mwdma(struct ata_device * adev)1949 static inline bool ata_using_mwdma(struct ata_device *adev)
1950 {
1951 return adev->dma_mode >= XFER_MW_DMA_0 &&
1952 adev->dma_mode <= XFER_MW_DMA_4;
1953 }
1954
ata_using_udma(struct ata_device * adev)1955 static inline bool ata_using_udma(struct ata_device *adev)
1956 {
1957 return adev->dma_mode >= XFER_UDMA_0 &&
1958 adev->dma_mode <= XFER_UDMA_7;
1959 }
1960
ata_dma_enabled(struct ata_device * adev)1961 static inline bool ata_dma_enabled(struct ata_device *adev)
1962 {
1963 return adev->dma_mode != 0xFF;
1964 }
1965
1966 /**************************************************************************
1967 * PATA timings - drivers/ata/libata-pata-timings.c
1968 */
1969 extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
1970 extern int ata_timing_compute(struct ata_device *, unsigned short,
1971 struct ata_timing *, int, int);
1972 extern void ata_timing_merge(const struct ata_timing *,
1973 const struct ata_timing *, struct ata_timing *,
1974 unsigned int);
1975
1976 /**************************************************************************
1977 * PMP - drivers/ata/libata-pmp.c
1978 */
1979 #ifdef CONFIG_SATA_PMP
1980
1981 extern const struct ata_port_operations sata_pmp_port_ops;
1982
1983 extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
1984 extern void sata_pmp_error_handler(struct ata_port *ap);
1985
1986 #else /* CONFIG_SATA_PMP */
1987
1988 #define sata_pmp_port_ops sata_port_ops
1989 #define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
1990 #define sata_pmp_error_handler ata_std_error_handler
1991
1992 #endif /* CONFIG_SATA_PMP */
1993
1994
1995 /**************************************************************************
1996 * SFF - drivers/ata/libata-sff.c
1997 */
1998 #ifdef CONFIG_ATA_SFF
1999
2000 extern const struct ata_port_operations ata_sff_port_ops;
2001 extern const struct ata_port_operations ata_bmdma32_port_ops;
2002
2003 /* PIO only, sg_tablesize and dma_boundary limits can be removed */
2004 #define ATA_PIO_SHT(drv_name) \
2005 ATA_BASE_SHT(drv_name), \
2006 .sg_tablesize = LIBATA_MAX_PRD, \
2007 .dma_boundary = ATA_DMA_BOUNDARY
2008
2009 extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
2010 extern u8 ata_sff_check_status(struct ata_port *ap);
2011 extern void ata_sff_pause(struct ata_port *ap);
2012 extern void ata_sff_dma_pause(struct ata_port *ap);
2013 extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline);
2014 extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
2015 extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
2016 extern void ata_sff_exec_command(struct ata_port *ap,
2017 const struct ata_taskfile *tf);
2018 extern unsigned int ata_sff_data_xfer(struct ata_queued_cmd *qc,
2019 unsigned char *buf, unsigned int buflen, int rw);
2020 extern unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc,
2021 unsigned char *buf, unsigned int buflen, int rw);
2022 extern void ata_sff_irq_on(struct ata_port *ap);
2023 extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
2024 u8 status, int in_wq);
2025 extern void ata_sff_queue_work(struct work_struct *work);
2026 extern void ata_sff_queue_delayed_work(struct delayed_work *dwork,
2027 unsigned long delay);
2028 extern void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay);
2029 extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
2030 extern void ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
2031 extern unsigned int ata_sff_port_intr(struct ata_port *ap,
2032 struct ata_queued_cmd *qc);
2033 extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
2034 extern void ata_sff_lost_interrupt(struct ata_port *ap);
2035 extern void ata_sff_freeze(struct ata_port *ap);
2036 extern void ata_sff_thaw(struct ata_port *ap);
2037 extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
2038 extern unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
2039 u8 *r_err);
2040 extern int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
2041 unsigned long deadline);
2042 extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
2043 unsigned long deadline);
2044 extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
2045 unsigned long deadline);
2046 extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
2047 extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
2048 extern void ata_sff_error_handler(struct ata_port *ap);
2049 extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
2050 #ifdef CONFIG_PCI
2051 extern int ata_pci_sff_init_host(struct ata_host *host);
2052 extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
2053 const struct ata_port_info * const * ppi,
2054 struct ata_host **r_host);
2055 extern int ata_pci_sff_activate_host(struct ata_host *host,
2056 irq_handler_t irq_handler,
2057 const struct scsi_host_template *sht);
2058 extern int ata_pci_sff_init_one(struct pci_dev *pdev,
2059 const struct ata_port_info * const * ppi,
2060 const struct scsi_host_template *sht, void *host_priv, int hflags);
2061 #endif /* CONFIG_PCI */
2062
2063 #ifdef CONFIG_ATA_BMDMA
2064
2065 extern const struct ata_port_operations ata_bmdma_port_ops;
2066
2067 #define ATA_BMDMA_SHT(drv_name) \
2068 ATA_BASE_SHT(drv_name), \
2069 .sg_tablesize = LIBATA_MAX_PRD, \
2070 .dma_boundary = ATA_DMA_BOUNDARY
2071
2072 extern enum ata_completion_errors ata_bmdma_qc_prep(struct ata_queued_cmd *qc);
2073 extern unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc);
2074 extern enum ata_completion_errors ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc);
2075 extern unsigned int ata_bmdma_port_intr(struct ata_port *ap,
2076 struct ata_queued_cmd *qc);
2077 extern irqreturn_t ata_bmdma_interrupt(int irq, void *dev_instance);
2078 extern void ata_bmdma_error_handler(struct ata_port *ap);
2079 extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
2080 extern void ata_bmdma_irq_clear(struct ata_port *ap);
2081 extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
2082 extern void ata_bmdma_start(struct ata_queued_cmd *qc);
2083 extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
2084 extern u8 ata_bmdma_status(struct ata_port *ap);
2085 extern int ata_bmdma_port_start(struct ata_port *ap);
2086 extern int ata_bmdma_port_start32(struct ata_port *ap);
2087
2088 #ifdef CONFIG_PCI
2089 extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
2090 extern void ata_pci_bmdma_init(struct ata_host *host);
2091 extern int ata_pci_bmdma_prepare_host(struct pci_dev *pdev,
2092 const struct ata_port_info * const * ppi,
2093 struct ata_host **r_host);
2094 extern int ata_pci_bmdma_init_one(struct pci_dev *pdev,
2095 const struct ata_port_info * const * ppi,
2096 const struct scsi_host_template *sht,
2097 void *host_priv, int hflags);
2098 #endif /* CONFIG_PCI */
2099 #endif /* CONFIG_ATA_BMDMA */
2100
2101 /**
2102 * ata_sff_busy_wait - Wait for a port status register
2103 * @ap: Port to wait for.
2104 * @bits: bits that must be clear
2105 * @max: number of 10uS waits to perform
2106 *
2107 * Waits up to max*10 microseconds for the selected bits in the port's
2108 * status register to be cleared.
2109 * Returns final value of status register.
2110 *
2111 * LOCKING:
2112 * Inherited from caller.
2113 */
ata_sff_busy_wait(struct ata_port * ap,unsigned int bits,unsigned int max)2114 static inline u8 ata_sff_busy_wait(struct ata_port *ap, unsigned int bits,
2115 unsigned int max)
2116 {
2117 u8 status;
2118
2119 do {
2120 udelay(10);
2121 status = ap->ops->sff_check_status(ap);
2122 max--;
2123 } while (status != 0xff && (status & bits) && (max > 0));
2124
2125 return status;
2126 }
2127
2128 /**
2129 * ata_wait_idle - Wait for a port to be idle.
2130 * @ap: Port to wait for.
2131 *
2132 * Waits up to 10ms for port's BUSY and DRQ signals to clear.
2133 * Returns final value of status register.
2134 *
2135 * LOCKING:
2136 * Inherited from caller.
2137 */
ata_wait_idle(struct ata_port * ap)2138 static inline u8 ata_wait_idle(struct ata_port *ap)
2139 {
2140 u8 status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
2141
2142 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
2143 ata_port_dbg(ap, "abnormal Status 0x%X\n", status);
2144
2145 return status;
2146 }
2147 #endif /* CONFIG_ATA_SFF */
2148
2149 #endif /* __LINUX_LIBATA_H__ */
2150